瀏覽代碼

pms 临时保养工单 保存后 更新 保养计划中的 对应保养项的 上次保养时长/公里数/日期

zhangcl 2 周之前
父節點
當前提交
a66c8eecba

+ 2 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotmaintenancebom/vo/IotMaintenanceBomPageReqVO.java

@@ -117,4 +117,6 @@ public class IotMaintenanceBomPageReqVO extends PageParam {
     private List<Long> deviceIds;
     @Schema(description = "保养项节点id集合")
     private List<Long> bomNodeIds;
+    @Schema(description = "保养项节点名称集合")
+    private List<String> bomNodeNames;
 }

+ 1 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotmaintenancebom/IotMaintenanceBomMapper.java

@@ -73,6 +73,7 @@ public interface IotMaintenanceBomMapper extends BaseMapperX<IotMaintenanceBomDO
                 .eqIfPresent(IotMaintenanceBomDO::getNextNaturalDate, reqVO.getNextNaturalDate())
                 .inIfPresent(IotMaintenanceBomDO::getBomNodeId, reqVO.getBomNodeIds())
                 .likeIfPresent(IotMaintenanceBomDO::getName, reqVO.getName())
+                .inIfPresent(IotMaintenanceBomDO::getName, reqVO.getBomNodeNames())
                 .eqIfPresent(IotMaintenanceBomDO::getCode, reqVO.getCode())
                 .eqIfPresent(IotMaintenanceBomDO::getParentId, reqVO.getParentId())
                 .eqIfPresent(IotMaintenanceBomDO::getChildIds, reqVO.getChildIds())

+ 65 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -1436,12 +1436,19 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         order.setOrderNumber(createWorkOrderNumber());
         order.setType(2);
         order.setResult(2);
-        // order.setActualStartTime(LocalDateTime.now());
-        // order.setActualEndTime(LocalDateTime.now());
         iotMainWorkOrderMapper.insert(order);
         // 保养工单明细
+        Set<Long> bomNodeIds = new HashSet<>();
+        Set<Long> deviceIds = new HashSet<>();
+        Set<String> bomNodeNames = new HashSet<>();
+        // key设备id-保养项id   value保养工单明细对象(包含累计公里/时长)
+        Map<String, IotMainWorkOrderBomSaveReqVO> bomAccumulatedValuePair = new HashMap<>();
+        // key设备id-保养项名称   value保养工单明细对象(包含累计公里/时长)
+        Map<String, IotMainWorkOrderBomSaveReqVO> bomNameAccumulatedValuePair = new HashMap<>();
         List<IotMainWorkOrderBomDO> workOrderBomDOS = new ArrayList<>();
         workOrderBOMs.forEach(bom -> {
+            bomAccumulatedValuePair.put(StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId()), bom);
+            bomNameAccumulatedValuePair.put(StrUtil.join("-", bom.getDeviceId(), bom.getName()), bom);
             IotMainWorkOrderBomDO tempBom = BeanUtils.toBean(bom, IotMainWorkOrderBomDO.class);
             tempBom.setWorkOrderId(order.getId());
             tempBom.setLastRunningTime(bom.getTotalRunTime());
@@ -1450,8 +1457,63 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             tempBom.setDeviceCategoryId(bom.getAssetClass());
             tempBom.setStatus(1);
             workOrderBomDOS.add(tempBom);
+            bomNodeIds.add(bom.getBomNodeId());
+            deviceIds.add(bom.getDeviceId());
+            bomNodeNames.add(bom.getName());
         });
         iotMainWorkOrderBomMapper.insertBatch(workOrderBomDOS);
+        // 查找各保养项对应的保养计划中的保养项 根据保养计划中的保养规则 更新 上次保养里程 or 上次保养时长 or 上次保养时间
+        if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(bomNodeIds) && CollUtil.isNotEmpty(bomNodeNames)
+                && CollUtil.isNotEmpty(bomAccumulatedValuePair)) {
+            IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
+            reqVO.setDeviceIds(new ArrayList<>(deviceIds));
+            reqVO.setBomNodeIds(new ArrayList<>(bomNodeIds));   // 保养项id 可能变化 重新生成设备BOM
+            List<IotMaintenanceBomDO> planBomS = iotMaintenanceBomService.getIotMainPlanBomList(reqVO);
+            if (CollUtil.isNotEmpty(planBomS)) {
+                planBomS.forEach(bom -> {
+                    String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getBomNodeId());
+                    if (bomAccumulatedValuePair.containsKey(uniqueKey)) {
+                        IotMainWorkOrderBomSaveReqVO saveReqVO = bomAccumulatedValuePair.get(uniqueKey);
+                        if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0==bom.getRunningTimeRule()) {
+                            bom.setLastRunningTime(saveReqVO.getTotalRunTime());
+                        }
+                        if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0==bom.getMileageRule()) {
+                            bom.setLastRunningKilometers(saveReqVO.getTotalMileage());
+                        }
+                        if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0==bom.getNaturalDateRule()) {
+                            bom.setLastNaturalDate(LocalDateTime.now());
+                        }
+                    }
+                });
+                // 批量更新保养计划明细
+                iotMaintenanceBomMapper.updateBatch(planBomS);
+            }
+            // 根据保养项名称更新上次保养 公里数 时长
+            IotMaintenanceBomPageReqVO bomReqVO = new IotMaintenanceBomPageReqVO();
+            bomReqVO.setDeviceIds(new ArrayList<>(deviceIds));
+            bomReqVO.setBomNodeNames(new ArrayList<>(bomNodeNames));   // 保养项id 可能变化 重新生成设备BOM
+            List<IotMaintenanceBomDO> planBomNames = iotMaintenanceBomService.getIotMainPlanBomList(bomReqVO);
+            if (CollUtil.isNotEmpty(planBomNames)) {
+                planBomNames.forEach(bom -> {
+                    String uniqueKey = StrUtil.join("-", bom.getDeviceId(), bom.getName());
+                    if (bomNameAccumulatedValuePair.containsKey(uniqueKey)) {
+                        IotMainWorkOrderBomSaveReqVO saveReqVO = bomNameAccumulatedValuePair.get(uniqueKey);
+                        if (ObjUtil.isNotEmpty(bom.getRunningTimeRule()) && 0==bom.getRunningTimeRule()) {
+                            bom.setLastRunningTime(saveReqVO.getTotalRunTime());
+                        }
+                        if (ObjUtil.isNotEmpty(bom.getMileageRule()) && 0==bom.getMileageRule()) {
+                            bom.setLastRunningKilometers(saveReqVO.getTotalMileage());
+                        }
+                        if (ObjUtil.isNotEmpty(bom.getNaturalDateRule()) && 0==bom.getNaturalDateRule()) {
+                            bom.setLastNaturalDate(LocalDateTime.now());
+                        }
+                    }
+                });
+                // 批量更新保养计划明细
+                iotMaintenanceBomMapper.updateBatch(planBomNames);
+            }
+        }
+
         // 保养工单 bom 明细关联的物料消耗
         List<IotMainWorkOrderBomMaterialDO> workOrderBomMaterialDOS = new ArrayList<>();
         Set<Long> factoryIds = new HashSet<>();
@@ -1495,6 +1557,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
             reqVO.setCostCenterIds(costCenterIds);
             reqVO.setMaterialCodes(materialCodes);
             processLockStock(reqVO, lockStockPair);
+            // 记录出库
         }
     }