Commit bcdb4fffc27b612ef67394451a920050a2871199

Authored by 戈灵虎
1 parent 17a067a4

feat(workorder): 添加事件工单创建和批量结束功能

urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java
... ... @@ -69,8 +69,8 @@ public class EventInfoController {
69 69 @PutMapping("/end")
70 70 @Operation(summary = "结束工单事件")
71 71 @PreAuthorize("@ss.hasPermission('workorder:event-info:end')")
72   - public CommonResult<Boolean> endEventInfo(@Valid @RequestParam("id") Long id) {
73   - eventInfoService.endEventInfo(id);
  72 + public CommonResult<Boolean> endEventInfo(@Valid @RequestParam("id") Long[] ids) {
  73 + eventInfoService.endEventInfo(ids);
74 74 return success(true);
75 75 }
76 76  
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java
... ... @@ -33,6 +33,16 @@ public class EventInfoSaveReqVO {
33 33 @Schema(description = "提交时间")
34 34 private LocalDateTime commitDate;
35 35  
  36 + /**
  37 + * 事件设备
  38 + */
  39 + private String eventDevice;
  40 +
  41 + /**
  42 + * 事件设备编码
  43 + */
  44 + private String eventDeviceCode;
  45 +
36 46 @Schema(description = "完成时间")
37 47 private LocalDateTime finishDate;
38 48  
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java
... ... @@ -73,8 +73,10 @@ public class AppEventInfoController {
73 73 vo.setConfrimImgs(createReqVO.getUserConfrimImgs());
74 74 vo.setCommitDate(LocalDateTime.now());
75 75 vo.setEvetName(createReqVO.getProblemName());
  76 + vo.setEventDeviceCode(createReqVO.getDeviceCode());
  77 + vo.setEventDevice(createReqVO.getDevice());
76 78 vo.setLatLonType(3);
77   - vo.setCreator("设备");
  79 + vo.setCreator(createReqVO.getDeviceCode());
78 80 vo.setRemark(createReqVO.getUserConfrimRemark());
79 81 // 调用高德API根据经纬度查询地址
80 82 if (createReqVO.getUserConfrimLat() != null && createReqVO.getUserConfrimLon() != null) {
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/dataobject/eventinfo/EventInfoDO.java
... ... @@ -80,7 +80,7 @@ public class EventInfoDO extends BaseDO {
80 80 /**
81 81 * 用户提交照片
82 82 */
83   - private String confrimImgs;
  83 + private String[] confrimImgs;
84 84 /**
85 85 * 事件状态
86 86 */
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java
1 1 package com.zteits.urbanops.module.workorder.dal.mysql.eventinfo;
2 2  
3   -import java.util.*;
4   -
5 3 import com.zteits.urbanops.framework.common.pojo.PageResult;
6   -import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX;
7 4 import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX;
  5 +import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoPageReqVO;
8 7 import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO;
  8 +import com.zteits.urbanops.module.workorder.enums.EventStatusEnum;
9 9 import org.apache.ibatis.annotations.Mapper;
10   -import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.*;
11 10  
12 11 /**
13 12 * 工单事件 Mapper
... ... @@ -37,4 +36,7 @@ public interface EventInfoMapper extends BaseMapperX&lt;EventInfoDO&gt; {
37 36 .orderByDesc(EventInfoDO::getId));
38 37 }
39 38  
  39 + default void updateByIds(Long[] ids) {
  40 + update(new EventInfoDO().setEventStatus(EventStatusEnum.FINISHED.getCode()), new LambdaQueryWrapperX<EventInfoDO>().in(EventInfoDO::getId, ids));
  41 + }
40 42 }
41 43 \ No newline at end of file
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java
... ... @@ -44,6 +44,7 @@ public interface ErrorCodeConstants {
44 44 ErrorCode APP_REGIONMGR_USER_ROLE_ERROR = new ErrorCode(1-900-002-007, "该登录人不是 大区经理,无法发起流程!");
45 45  
46 46 ErrorCode EVENT_INFO_NOT_EXISTS = new ErrorCode(1-900-003-001, "工单事件不存在");
  47 + ErrorCode EVENT_WORK_ORDER_CREATE_FAILED = new ErrorCode(1-900-003-002, "事件工单创建失败:{}");
47 48  
48 49 ErrorCode EVENT_MAPPING_INFO_NOT_EXISTS = new ErrorCode(1-900-004-001, "工单事件映射不存在");
49 50  
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java
... ... @@ -64,8 +64,10 @@ public interface EventInfoService {
64 64 *
65 65 * @param id 工单事件编号
66 66 */
67   - void endEventInfo(@Valid Long id);
  67 + void endEventInfo(@Valid Long[] ids);
68 68  
69 69 void createEventOrderInfo(@Valid EventOrderInfoSaveReqVO createReqVO);
70 70  
  71 + boolean bpmAiCallBack(String orderId,Integer status);
  72 +
71 73 }
72 74 \ No newline at end of file
... ...
urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java
1 1 package com.zteits.urbanops.module.workorder.service.eventinfo;
2 2  
3   -import cn.hutool.core.collection.CollUtil;
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.zteits.urbanops.framework.common.exception.ErrorCode;
  5 +import com.zteits.urbanops.framework.common.pojo.PageResult;
  6 +import com.zteits.urbanops.framework.common.util.object.BeanUtils;
  7 +import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils;
  8 +import com.zteits.urbanops.module.bpm.enums.task.BpmTaskStatusEnum;
  9 +import com.zteits.urbanops.module.workorder.api.constant.BpmCommonConstant;
  10 +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoPageReqVO;
  11 +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoSaveReqVO;
  12 +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventOrderInfoSaveReqVO;
  13 +import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO;
  14 +import com.zteits.urbanops.module.workorder.dal.dataobject.eventmappinginfo.EventMappingInfoDO;
  15 +import com.zteits.urbanops.module.workorder.dal.mysql.eventinfo.EventInfoMapper;
  16 +import com.zteits.urbanops.module.workorder.dal.mysql.eventmappinginfo.EventMappingInfoMapper;
  17 +import com.zteits.urbanops.module.workorder.dto.AppGardenWorkOrderAIReqVO;
  18 +import com.zteits.urbanops.module.workorder.enums.EventSourceEnum;
4 19 import com.zteits.urbanops.module.workorder.enums.EventStatusEnum;
  20 +import com.zteits.urbanops.module.workorder.service.garden.BpmAIService;
  21 +import lombok.RequiredArgsConstructor;
  22 +import lombok.extern.slf4j.Slf4j;
5 23 import org.springframework.stereotype.Service;
6   -import jakarta.annotation.Resource;
7   -import org.springframework.validation.annotation.Validated;
8 24 import org.springframework.transaction.annotation.Transactional;
  25 +import org.springframework.util.ObjectUtils;
  26 +import org.springframework.validation.annotation.Validated;
9 27  
10   -import java.util.*;
11   -import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.*;
12   -import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO;
13   -import com.zteits.urbanops.framework.common.pojo.PageResult;
14   -import com.zteits.urbanops.framework.common.pojo.PageParam;
15   -import com.zteits.urbanops.framework.common.util.object.BeanUtils;
16   -
17   -import com.zteits.urbanops.module.workorder.dal.mysql.eventinfo.EventInfoMapper;
  28 +import java.time.LocalDateTime;
  29 +import java.util.ArrayList;
  30 +import java.util.Arrays;
  31 +import java.util.List;
18 32  
19 33 import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception;
20   -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.convertList;
21   -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.diffList;
22   -import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.*;
  34 +import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.EVENT_INFO_NOT_EXISTS;
  35 +import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.EVENT_WORK_ORDER_CREATE_FAILED;
23 36  
24 37 /**
25 38 * 工单事件 Service 实现类
... ... @@ -28,10 +41,16 @@ import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.*;
28 41 */
29 42 @Service
30 43 @Validated
  44 +@RequiredArgsConstructor
  45 +@Slf4j
31 46 public class EventInfoServiceImpl implements EventInfoService {
32 47  
33   - @Resource
34   - private EventInfoMapper eventInfoMapper;
  48 + private final EventInfoMapper eventInfoMapper;
  49 +
  50 + private final BpmAIService bpmAIService;
  51 +
  52 + private final EventMappingInfoMapper eventMappingInfoMapper;
  53 +
35 54  
36 55 @Override
37 56 public Long createEventInfo(EventInfoSaveReqVO createReqVO) {
... ... @@ -61,10 +80,10 @@ public class EventInfoServiceImpl implements EventInfoService {
61 80 }
62 81  
63 82 @Override
64   - public void deleteEventInfoListByIds(List<Long> ids) {
  83 + public void deleteEventInfoListByIds(List<Long> ids) {
65 84 // 删除
66 85 eventInfoMapper.deleteByIds(ids);
67   - }
  86 + }
68 87  
69 88  
70 89 private void validateEventInfoExists(Long id) {
... ... @@ -84,19 +103,148 @@ public class EventInfoServiceImpl implements EventInfoService {
84 103 }
85 104  
86 105 @Override
87   - public void endEventInfo(Long id) {
88   - // 校验存在
89   - validateEventInfoExists(id);
90   - // 更新
91   - EventInfoDO updateObj = new EventInfoDO();
92   - updateObj.setId(id);
93   - updateObj.setEventStatus(EventStatusEnum.FINISHED.getCode());
94   - eventInfoMapper.updateById(updateObj);
  106 + public void endEventInfo(Long[] ids) {
  107 +
  108 + eventInfoMapper.updateByIds(ids);
95 109 }
96 110  
97 111 @Override
  112 + @Transactional(rollbackFor = Exception.class)
98 113 public void createEventOrderInfo(EventOrderInfoSaveReqVO createReqVO) {
99   - //TODO @lesan:工单事件工单创建
  114 +
  115 + EventInfoDO eventInfo = eventInfoMapper.selectById(createReqVO.getId());
  116 + if (!ObjectUtils.isEmpty(eventInfo)) {
  117 + SecurityUserInfo userInfo = getCurrentUserInfo();
  118 +
  119 + // 创建AI工单
  120 + Long orderId = createAIWorkOrder(eventInfo, createReqVO);
  121 +
  122 + // 更新事件状态
  123 + updateEventInfoStatus(eventInfo, userInfo.userId);
  124 +
  125 + // 创建事件映射信息
  126 + createEventMappingInfo(eventInfo, orderId, createReqVO, userInfo);
  127 + }
  128 + }
  129 +
  130 + @Override
  131 + public boolean bpmAiCallBack(String orderId, Integer status) {
  132 + EventMappingInfoDO mappingInfoDO = eventMappingInfoMapper.selectOne(EventMappingInfoDO::getOrderNo, orderId);
  133 + if (ObjectUtils.isEmpty(mappingInfoDO)) {
  134 + throw exception(EVENT_INFO_NOT_EXISTS);
  135 + }
  136 + mappingInfoDO.setStatus(status);
  137 + mappingInfoDO.setUpdateTime(LocalDateTime.now());
  138 + mappingInfoDO.setUpdater(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
  139 + mappingInfoDO.setFinishDate(LocalDateTime.now());
  140 + eventMappingInfoMapper.updateById(mappingInfoDO);
  141 + return true;
  142 + }
  143 +
  144 + /**
  145 + * 获取当前用户信息
  146 + */
  147 + private SecurityUserInfo getCurrentUserInfo() {
  148 + Long currentUserId = SecurityFrameworkUtils.getLoginUserId();
  149 + Long companyId = SecurityFrameworkUtils.getCompanyId();
  150 + Long deptId = SecurityFrameworkUtils.getDeptId();
  151 + String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
  152 +
  153 + // 检查用户信息是否获取成功
  154 + if (currentUserId == null) {
  155 + throw exception(new ErrorCode(1_004_001_000, "用户不存在"));
  156 + }
  157 +
  158 + return new SecurityUserInfo(currentUserId, companyId, deptId, userNickname);
  159 + }
  160 +
  161 + /**
  162 + * 创建AI工单
  163 + */
  164 + private Long createAIWorkOrder(EventInfoDO eventInfo, EventOrderInfoSaveReqVO createReqVO) {
  165 + AppGardenWorkOrderAIReqVO aiReqVO = new AppGardenWorkOrderAIReqVO();
  166 + aiReqVO.setBusiLine(createReqVO.getBusiLine())
  167 + .setLon(eventInfo.getLon())
  168 + .setLat(eventInfo.getLat())
  169 + .setOrderName(eventInfo.getEvetName())
  170 + .setOrderType(BpmCommonConstant.ORDER_TYPE_C)
  171 + .setExpectedFinishDate(createReqVO.getExpectedFinishDate())
  172 + .setLatLonType(3)
  173 + .setLonLatAddress(eventInfo.getLonLatAddress())
  174 + .setPressingType(createReqVO.getPressingType())
  175 + // 处理可能为null的数组,避免Arrays.asList抛出异常
  176 + .setProblemsImgs(eventInfo.getConfrimImgs() != null ? Arrays.asList(eventInfo.getConfrimImgs()) : new ArrayList<>())
  177 + .setRemark(eventInfo.getRemark())
  178 + .setRoadId(createReqVO.getRoadId())
  179 + .setRoadName(createReqVO.getRoadName())
  180 + .setSourceId(EventSourceEnum.AI.getCode())
  181 + .setWoSourceId(eventInfo.getEventDeviceCode())
  182 + .setWoSourceName(eventInfo.getEventDevice())
  183 + .setThirdWorkNo(eventInfo.getEventNo())
  184 + .setSourceName(eventInfo.getEventDevice());
  185 +
  186 + Long orderId;
  187 + try {
  188 + log.info("[createAIWorkOrder][创建AI工单]:{}", JSON.toJSONString(aiReqVO));
  189 + orderId = bpmAIService.createWorkOrder(aiReqVO);
  190 + log.info("[createAIWorkOrder][创建AI工单结果]:{}", orderId);
  191 + } catch (Exception e) {
  192 + log.error("[createAIWorkOrder][创建AI工单时发生异常]", e);
  193 + throw exception(EVENT_WORK_ORDER_CREATE_FAILED, e.getMessage());
  194 + }
  195 +
  196 + return orderId;
  197 + }
  198 +
  199 + /**
  200 + * 更新事件状态
  201 + */
  202 + private void updateEventInfoStatus(EventInfoDO eventInfo, Long userId) {
  203 + eventInfo.setEventStatus(EventStatusEnum.ORDER.getCode());
  204 + eventInfo.setUpdater(String.valueOf(userId))
  205 + .setUpdateTime(LocalDateTime.now());
  206 + eventInfoMapper.updateById(eventInfo);
  207 + }
  208 +
  209 + /**
  210 + * 创建事件映射信息
  211 + */
  212 + private void createEventMappingInfo(EventInfoDO eventInfo, Long orderId, EventOrderInfoSaveReqVO createReqVO, SecurityUserInfo userInfo) {
  213 + EventMappingInfoDO mappingInfoDO = new EventMappingInfoDO();
  214 + mappingInfoDO.setEventNo(eventInfo.getEventNo())
  215 + .setOrderNo(String.valueOf(orderId))
  216 + .setBusiLine(createReqVO.getBusiLine())
  217 + .setCommitDate(LocalDateTime.now())
  218 + .setCompanyId(userInfo.companyId)
  219 + .setDeptId(userInfo.deptId)
  220 + .setExpectedFinishDate(createReqVO.getExpectedFinishDate())
  221 + .setPressingType(createReqVO.getPressingType())
  222 + .setRoadId(createReqVO.getRoadId())
  223 + .setRoadName(createReqVO.getRoadName())
  224 + .setUserId(userInfo.userId)
  225 + .setUserName(userInfo.userNickname)
  226 + .setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
  227 + .setCreator(String.valueOf(userInfo.userId))
  228 + .setCreateTime(LocalDateTime.now());
  229 +
  230 + eventMappingInfoMapper.insert(mappingInfoDO);
  231 + }
  232 +
  233 + /**
  234 + * 安全用户信息封装类
  235 + */
  236 + private static class SecurityUserInfo {
  237 + final Long userId;
  238 + final Long companyId;
  239 + final Long deptId;
  240 + final String userNickname;
  241 +
  242 + SecurityUserInfo(Long userId, Long companyId, Long deptId, String userNickname) {
  243 + this.userId = userId;
  244 + this.companyId = companyId;
  245 + this.deptId = deptId;
  246 + this.userNickname = userNickname;
  247 + }
100 248 }
101 249  
102 250 }
103 251 \ No newline at end of file
... ...