feat(ops): 巡检整改工单自动创建(Task 7)
- InspectionRectificationService + Impl: 不合格巡检自动创建整改工单 - 复用 CleanOrderService.createAutoCleanOrder() 对接现有工单引擎 - sourceType = INSPECTION, priority = P1, cleaningType = SPOT - generated_order_id 回写到巡检记录 - InspectionRecordServiceImpl: 异步流程增加整改工单创建步骤 - 归属判定与整改工单创建独立 try/catch,互不阻塞 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,9 @@ public class InspectionRecordServiceImpl implements InspectionRecordService {
|
|||||||
@Resource
|
@Resource
|
||||||
private InspectionAttributionService inspectionAttributionService;
|
private InspectionAttributionService inspectionAttributionService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private InspectionRectificationService inspectionRectificationService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long submitInspection(InspectionSubmitReqVO submitReqVO, Long inspectorId) {
|
public Long submitInspection(InspectionSubmitReqVO submitReqVO, Long inspectorId) {
|
||||||
@@ -75,15 +78,23 @@ public class InspectionRecordServiceImpl implements InspectionRecordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步触发归属判定
|
* 异步触发归属判定 + 整改工单创建
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
public void triggerAttributionAsync(Long recordId, Long areaId) {
|
public void triggerAttributionAsync(Long recordId, Long areaId) {
|
||||||
|
// 1. 归属判定
|
||||||
try {
|
try {
|
||||||
inspectionAttributionService.determineAttribution(recordId, areaId);
|
inspectionAttributionService.determineAttribution(recordId, areaId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[triggerAttributionAsync] 归属判定异常: recordId={}, areaId={}", recordId, areaId, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user