diff --git a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRecordServiceImpl.java b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRecordServiceImpl.java index 454867b..1b5c655 100644 --- a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRecordServiceImpl.java +++ b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRecordServiceImpl.java @@ -37,6 +37,9 @@ public class InspectionRecordServiceImpl implements InspectionRecordService { @Resource private InspectionAttributionService inspectionAttributionService; + @Resource + private InspectionRectificationService inspectionRectificationService; + @Override @Transactional(rollbackFor = Exception.class) public Long submitInspection(InspectionSubmitReqVO submitReqVO, Long inspectorId) { @@ -75,15 +78,23 @@ public class InspectionRecordServiceImpl implements InspectionRecordService { } /** - * 异步触发归属判定 + * 异步触发归属判定 + 整改工单创建 */ @Async public void triggerAttributionAsync(Long recordId, Long areaId) { + // 1. 归属判定 try { inspectionAttributionService.determineAttribution(recordId, areaId); } catch (Exception e) { log.error("[triggerAttributionAsync] 归属判定异常: recordId={}, areaId={}", recordId, areaId, e); } + + // 2. 创建整改工单(不论归属判定结果,不合格即需整改) + try { + inspectionRectificationService.createRectificationOrder(recordId, areaId); + } catch (Exception e) { + log.error("[triggerAttributionAsync] 整改工单创建异常: recordId={}, areaId={}", recordId, areaId, e); + } } } diff --git a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationService.java b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationService.java new file mode 100644 index 0000000..e277d5f --- /dev/null +++ b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationService.java @@ -0,0 +1,22 @@ +package com.viewsh.module.ops.environment.service.inspection; + +/** + * 巡检整改工单 Service 接口 + * + * 当巡检不合格时,自动创建整改工单: + * - source_type = INSPECTION + * - 对接现有保洁工单引擎 + * - 回写 generated_order_id 到巡检记录 + */ +public interface InspectionRectificationService { + + /** + * 创建整改工单 + * + * @param recordId 巡检记录ID + * @param areaId 区域ID + * @return 创建的工单ID + */ + Long createRectificationOrder(Long recordId, Long areaId); + +} diff --git a/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationServiceImpl.java b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationServiceImpl.java new file mode 100644 index 0000000..2c460dc --- /dev/null +++ b/viewsh-module-ops/viewsh-module-environment-biz/src/main/java/com/viewsh/module/ops/environment/service/inspection/InspectionRectificationServiceImpl.java @@ -0,0 +1,68 @@ +package com.viewsh.module.ops.environment.service.inspection; + +import com.viewsh.module.ops.dal.dataobject.area.OpsBusAreaDO; +import com.viewsh.module.ops.dal.mysql.area.OpsBusAreaMapper; +import com.viewsh.module.ops.environment.dal.dataobject.CleanOrderAutoCreateReqDTO; +import com.viewsh.module.ops.environment.dal.dataobject.inspection.OpsInspectionRecordDO; +import com.viewsh.module.ops.environment.dal.mysql.inspection.OpsInspectionRecordMapper; +import com.viewsh.module.ops.environment.service.cleanorder.CleanOrderService; +import com.viewsh.module.ops.enums.PriorityEnum; +import com.viewsh.module.ops.enums.SourceTypeEnum; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * 巡检整改工单 Service 实现 + */ +@Service +@Validated +@Slf4j +public class InspectionRectificationServiceImpl implements InspectionRectificationService { + + @Resource + private CleanOrderService cleanOrderService; + + @Resource + private OpsBusAreaMapper opsBusAreaMapper; + + @Resource + private OpsInspectionRecordMapper inspectionRecordMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public Long createRectificationOrder(Long recordId, Long areaId) { + // 1. 获取区域信息 + OpsBusAreaDO area = opsBusAreaMapper.selectById(areaId); + String areaName = area != null ? area.getAreaName() : "未知区域"; + Integer standardDuration = area != null ? area.getStandardDuration() : 30; + + // 2. 构建整改工单请求 + CleanOrderAutoCreateReqDTO createReq = new CleanOrderAutoCreateReqDTO(); + createReq.setOrderType("CLEAN"); + createReq.setSourceType(SourceTypeEnum.INSPECTION.getType()); + createReq.setTitle("巡检整改:" + areaName); + createReq.setDescription("巡检发现不合格,需重新清洁。巡检记录ID:" + recordId); + createReq.setPriority(PriorityEnum.P1.getPriority()); + createReq.setAreaId(areaId); + createReq.setExpectedDuration(standardDuration != null ? standardDuration : 30); + createReq.setCleaningType("SPOT"); + createReq.setDifficultyLevel(3); + + // 3. 调用现有工单引擎创建工单 + Long orderId = cleanOrderService.createAutoCleanOrder(createReq); + log.info("[createRectificationOrder] 整改工单创建成功: recordId={}, areaId={}, orderId={}", + recordId, areaId, orderId); + + // 4. 回写 generated_order_id 到巡检记录 + OpsInspectionRecordDO update = new OpsInspectionRecordDO(); + update.setId(recordId); + update.setGeneratedOrderId(orderId); + inspectionRecordMapper.updateById(update); + + return orderId; + } + +}