From bcdb4fffc27b612ef67394451a920050a2871199 Mon Sep 17 00:00:00 2001 From: 戈灵虎 <50576256@qq.com> Date: Fri, 2 Jan 2026 13:09:42 +0800 Subject: [PATCH] feat(workorder): 添加事件工单创建和批量结束功能 --- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java | 4 ++-- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java | 10 ++++++++++ urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java | 4 +++- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/dataobject/eventinfo/EventInfoDO.java | 2 +- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java | 10 ++++++---- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java | 1 + urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java | 4 +++- urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- 8 files changed, 201 insertions(+), 36 deletions(-) diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java index e84bc77..c1a6dff 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/EventInfoController.java @@ -69,8 +69,8 @@ public class EventInfoController { @PutMapping("/end") @Operation(summary = "结束工单事件") @PreAuthorize("@ss.hasPermission('workorder:event-info:end')") - public CommonResult endEventInfo(@Valid @RequestParam("id") Long id) { - eventInfoService.endEventInfo(id); + public CommonResult endEventInfo(@Valid @RequestParam("id") Long[] ids) { + eventInfoService.endEventInfo(ids); return success(true); } diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java index ac9d4e9..ee10980 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/admin/eventinfo/vo/EventInfoSaveReqVO.java @@ -33,6 +33,16 @@ public class EventInfoSaveReqVO { @Schema(description = "提交时间") private LocalDateTime commitDate; + /** + * 事件设备 + */ + private String eventDevice; + + /** + * 事件设备编码 + */ + private String eventDeviceCode; + @Schema(description = "完成时间") private LocalDateTime finishDate; diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java index 4381a0e..a107d97 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/controller/app/eventinfo/AppEventInfoController.java @@ -73,8 +73,10 @@ public class AppEventInfoController { vo.setConfrimImgs(createReqVO.getUserConfrimImgs()); vo.setCommitDate(LocalDateTime.now()); vo.setEvetName(createReqVO.getProblemName()); + vo.setEventDeviceCode(createReqVO.getDeviceCode()); + vo.setEventDevice(createReqVO.getDevice()); vo.setLatLonType(3); - vo.setCreator("设备"); + vo.setCreator(createReqVO.getDeviceCode()); vo.setRemark(createReqVO.getUserConfrimRemark()); // 调用高德API根据经纬度查询地址 if (createReqVO.getUserConfrimLat() != null && createReqVO.getUserConfrimLon() != null) { diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/dataobject/eventinfo/EventInfoDO.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/dataobject/eventinfo/EventInfoDO.java index 90ff3c5..175ddc0 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/dataobject/eventinfo/EventInfoDO.java +++ b/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 { /** * 用户提交照片 */ - private String confrimImgs; + private String[] confrimImgs; /** * 事件状态 */ diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java index 9d3b079..ba80886 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/dal/mysql/eventinfo/EventInfoMapper.java @@ -1,13 +1,12 @@ package com.zteits.urbanops.module.workorder.dal.mysql.eventinfo; -import java.util.*; - import com.zteits.urbanops.framework.common.pojo.PageResult; -import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; import com.zteits.urbanops.framework.mybatis.core.mapper.BaseMapperX; +import com.zteits.urbanops.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoPageReqVO; import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO; +import com.zteits.urbanops.module.workorder.enums.EventStatusEnum; import org.apache.ibatis.annotations.Mapper; -import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.*; /** * 工单事件 Mapper @@ -37,4 +36,7 @@ public interface EventInfoMapper extends BaseMapperX { .orderByDesc(EventInfoDO::getId)); } + default void updateByIds(Long[] ids) { + update(new EventInfoDO().setEventStatus(EventStatusEnum.FINISHED.getCode()), new LambdaQueryWrapperX().in(EventInfoDO::getId, ids)); + } } \ No newline at end of file diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java index e771b5b..c74dcee 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/enums/ErrorCodeConstants.java @@ -44,6 +44,7 @@ public interface ErrorCodeConstants { ErrorCode APP_REGIONMGR_USER_ROLE_ERROR = new ErrorCode(1-900-002-007, "该登录人不是 大区经理,无法发起流程!"); ErrorCode EVENT_INFO_NOT_EXISTS = new ErrorCode(1-900-003-001, "工单事件不存在"); + ErrorCode EVENT_WORK_ORDER_CREATE_FAILED = new ErrorCode(1-900-003-002, "事件工单创建失败:{}"); ErrorCode EVENT_MAPPING_INFO_NOT_EXISTS = new ErrorCode(1-900-004-001, "工单事件映射不存在"); diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java index 48d7453..c934885 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoService.java @@ -64,8 +64,10 @@ public interface EventInfoService { * * @param id 工单事件编号 */ - void endEventInfo(@Valid Long id); + void endEventInfo(@Valid Long[] ids); void createEventOrderInfo(@Valid EventOrderInfoSaveReqVO createReqVO); + boolean bpmAiCallBack(String orderId,Integer status); + } \ No newline at end of file diff --git a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java index 217dcdb..5afd2db 100644 --- a/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java +++ b/urbanops-module-workorder/src/main/java/com/zteits/urbanops/module/workorder/service/eventinfo/EventInfoServiceImpl.java @@ -1,25 +1,38 @@ package com.zteits.urbanops.module.workorder.service.eventinfo; -import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.zteits.urbanops.framework.common.exception.ErrorCode; +import com.zteits.urbanops.framework.common.pojo.PageResult; +import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; +import com.zteits.urbanops.module.bpm.enums.task.BpmTaskStatusEnum; +import com.zteits.urbanops.module.workorder.api.constant.BpmCommonConstant; +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoPageReqVO; +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventInfoSaveReqVO; +import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.EventOrderInfoSaveReqVO; +import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO; +import com.zteits.urbanops.module.workorder.dal.dataobject.eventmappinginfo.EventMappingInfoDO; +import com.zteits.urbanops.module.workorder.dal.mysql.eventinfo.EventInfoMapper; +import com.zteits.urbanops.module.workorder.dal.mysql.eventmappinginfo.EventMappingInfoMapper; +import com.zteits.urbanops.module.workorder.dto.AppGardenWorkOrderAIReqVO; +import com.zteits.urbanops.module.workorder.enums.EventSourceEnum; import com.zteits.urbanops.module.workorder.enums.EventStatusEnum; +import com.zteits.urbanops.module.workorder.service.garden.BpmAIService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; +import org.springframework.validation.annotation.Validated; -import java.util.*; -import com.zteits.urbanops.module.workorder.controller.admin.eventinfo.vo.*; -import com.zteits.urbanops.module.workorder.dal.dataobject.eventinfo.EventInfoDO; -import com.zteits.urbanops.framework.common.pojo.PageResult; -import com.zteits.urbanops.framework.common.pojo.PageParam; -import com.zteits.urbanops.framework.common.util.object.BeanUtils; - -import com.zteits.urbanops.module.workorder.dal.mysql.eventinfo.EventInfoMapper; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import static com.zteits.urbanops.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.convertList; -import static com.zteits.urbanops.framework.common.util.collection.CollectionUtils.diffList; -import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.*; +import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.EVENT_INFO_NOT_EXISTS; +import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.EVENT_WORK_ORDER_CREATE_FAILED; /** * 工单事件 Service 实现类 @@ -28,10 +41,16 @@ import static com.zteits.urbanops.module.workorder.enums.ErrorCodeConstants.*; */ @Service @Validated +@RequiredArgsConstructor +@Slf4j public class EventInfoServiceImpl implements EventInfoService { - @Resource - private EventInfoMapper eventInfoMapper; + private final EventInfoMapper eventInfoMapper; + + private final BpmAIService bpmAIService; + + private final EventMappingInfoMapper eventMappingInfoMapper; + @Override public Long createEventInfo(EventInfoSaveReqVO createReqVO) { @@ -61,10 +80,10 @@ public class EventInfoServiceImpl implements EventInfoService { } @Override - public void deleteEventInfoListByIds(List ids) { + public void deleteEventInfoListByIds(List ids) { // 删除 eventInfoMapper.deleteByIds(ids); - } + } private void validateEventInfoExists(Long id) { @@ -84,19 +103,148 @@ public class EventInfoServiceImpl implements EventInfoService { } @Override - public void endEventInfo(Long id) { - // 校验存在 - validateEventInfoExists(id); - // 更新 - EventInfoDO updateObj = new EventInfoDO(); - updateObj.setId(id); - updateObj.setEventStatus(EventStatusEnum.FINISHED.getCode()); - eventInfoMapper.updateById(updateObj); + public void endEventInfo(Long[] ids) { + + eventInfoMapper.updateByIds(ids); } @Override + @Transactional(rollbackFor = Exception.class) public void createEventOrderInfo(EventOrderInfoSaveReqVO createReqVO) { - //TODO @lesan:工单事件工单创建 + + EventInfoDO eventInfo = eventInfoMapper.selectById(createReqVO.getId()); + if (!ObjectUtils.isEmpty(eventInfo)) { + SecurityUserInfo userInfo = getCurrentUserInfo(); + + // 创建AI工单 + Long orderId = createAIWorkOrder(eventInfo, createReqVO); + + // 更新事件状态 + updateEventInfoStatus(eventInfo, userInfo.userId); + + // 创建事件映射信息 + createEventMappingInfo(eventInfo, orderId, createReqVO, userInfo); + } + } + + @Override + public boolean bpmAiCallBack(String orderId, Integer status) { + EventMappingInfoDO mappingInfoDO = eventMappingInfoMapper.selectOne(EventMappingInfoDO::getOrderNo, orderId); + if (ObjectUtils.isEmpty(mappingInfoDO)) { + throw exception(EVENT_INFO_NOT_EXISTS); + } + mappingInfoDO.setStatus(status); + mappingInfoDO.setUpdateTime(LocalDateTime.now()); + mappingInfoDO.setUpdater(String.valueOf(SecurityFrameworkUtils.getLoginUserId())); + mappingInfoDO.setFinishDate(LocalDateTime.now()); + eventMappingInfoMapper.updateById(mappingInfoDO); + return true; + } + + /** + * 获取当前用户信息 + */ + private SecurityUserInfo getCurrentUserInfo() { + Long currentUserId = SecurityFrameworkUtils.getLoginUserId(); + Long companyId = SecurityFrameworkUtils.getCompanyId(); + Long deptId = SecurityFrameworkUtils.getDeptId(); + String userNickname = SecurityFrameworkUtils.getLoginUserNickname(); + + // 检查用户信息是否获取成功 + if (currentUserId == null) { + throw exception(new ErrorCode(1_004_001_000, "用户不存在")); + } + + return new SecurityUserInfo(currentUserId, companyId, deptId, userNickname); + } + + /** + * 创建AI工单 + */ + private Long createAIWorkOrder(EventInfoDO eventInfo, EventOrderInfoSaveReqVO createReqVO) { + AppGardenWorkOrderAIReqVO aiReqVO = new AppGardenWorkOrderAIReqVO(); + aiReqVO.setBusiLine(createReqVO.getBusiLine()) + .setLon(eventInfo.getLon()) + .setLat(eventInfo.getLat()) + .setOrderName(eventInfo.getEvetName()) + .setOrderType(BpmCommonConstant.ORDER_TYPE_C) + .setExpectedFinishDate(createReqVO.getExpectedFinishDate()) + .setLatLonType(3) + .setLonLatAddress(eventInfo.getLonLatAddress()) + .setPressingType(createReqVO.getPressingType()) + // 处理可能为null的数组,避免Arrays.asList抛出异常 + .setProblemsImgs(eventInfo.getConfrimImgs() != null ? Arrays.asList(eventInfo.getConfrimImgs()) : new ArrayList<>()) + .setRemark(eventInfo.getRemark()) + .setRoadId(createReqVO.getRoadId()) + .setRoadName(createReqVO.getRoadName()) + .setSourceId(EventSourceEnum.AI.getCode()) + .setWoSourceId(eventInfo.getEventDeviceCode()) + .setWoSourceName(eventInfo.getEventDevice()) + .setThirdWorkNo(eventInfo.getEventNo()) + .setSourceName(eventInfo.getEventDevice()); + + Long orderId; + try { + log.info("[createAIWorkOrder][创建AI工单]:{}", JSON.toJSONString(aiReqVO)); + orderId = bpmAIService.createWorkOrder(aiReqVO); + log.info("[createAIWorkOrder][创建AI工单结果]:{}", orderId); + } catch (Exception e) { + log.error("[createAIWorkOrder][创建AI工单时发生异常]", e); + throw exception(EVENT_WORK_ORDER_CREATE_FAILED, e.getMessage()); + } + + return orderId; + } + + /** + * 更新事件状态 + */ + private void updateEventInfoStatus(EventInfoDO eventInfo, Long userId) { + eventInfo.setEventStatus(EventStatusEnum.ORDER.getCode()); + eventInfo.setUpdater(String.valueOf(userId)) + .setUpdateTime(LocalDateTime.now()); + eventInfoMapper.updateById(eventInfo); + } + + /** + * 创建事件映射信息 + */ + private void createEventMappingInfo(EventInfoDO eventInfo, Long orderId, EventOrderInfoSaveReqVO createReqVO, SecurityUserInfo userInfo) { + EventMappingInfoDO mappingInfoDO = new EventMappingInfoDO(); + mappingInfoDO.setEventNo(eventInfo.getEventNo()) + .setOrderNo(String.valueOf(orderId)) + .setBusiLine(createReqVO.getBusiLine()) + .setCommitDate(LocalDateTime.now()) + .setCompanyId(userInfo.companyId) + .setDeptId(userInfo.deptId) + .setExpectedFinishDate(createReqVO.getExpectedFinishDate()) + .setPressingType(createReqVO.getPressingType()) + .setRoadId(createReqVO.getRoadId()) + .setRoadName(createReqVO.getRoadName()) + .setUserId(userInfo.userId) + .setUserName(userInfo.userNickname) + .setStatus(BpmTaskStatusEnum.RUNNING.getStatus()) + .setCreator(String.valueOf(userInfo.userId)) + .setCreateTime(LocalDateTime.now()); + + eventMappingInfoMapper.insert(mappingInfoDO); + } + + /** + * 安全用户信息封装类 + */ + private static class SecurityUserInfo { + final Long userId; + final Long companyId; + final Long deptId; + final String userNickname; + + SecurityUserInfo(Long userId, Long companyId, Long deptId, String userNickname) { + this.userId = userId; + this.companyId = companyId; + this.deptId = deptId; + this.userNickname = userNickname; + } } } \ No newline at end of file -- libgit2 0.21.4