Forráskód Böngészése

pms 调拨同步保养计划

zhangcl 1 hete
szülő
commit
3277353193

+ 2 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotrddailyreport/IotRdDailyReportController.java

@@ -593,6 +593,7 @@ public class IotRdDailyReportController {
         // 日报任务对应的平台井列表
         if (1 == dailyReport.getPlatformWell()) {
             // 查询未施工完成的平台井 关联井列表
+            // 20260408 施工完成的平台井 也需要显示到 platforms 因为查询详情时需要显示
             IotProjectTaskPageReqVO pageReqVO = new IotProjectTaskPageReqVO();
             pageReqVO.setPlatformGroup(dailyReport.getTaskPlatform());
             pageReqVO.setJobFlag("Y");
@@ -629,8 +630,7 @@ public class IotRdDailyReportController {
                 }
 
                 // 查询多个日报对应的生产动态明细
-                // 查询日报生产动态明细
-                // 当前井及平台井的 taskId 依次查询有无 生产动态明细 哪个井有明细 用哪个任务井
+                // 当前井及平台井的 taskId 依次查询有无 生产动态明细 哪个井有明细 用哪个任务井的生产动态明细
                 IotRdDailyReportDetailPageReqVO relatedDetailReqVO = new IotRdDailyReportDetailPageReqVO();
                 relatedDetailReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
                 relatedDetailReqVO.setReportIds(reportIds);

+ 5 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdeviceallotlog/IotDeviceAllotLogServiceImpl.java

@@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.pms.service.iotdeviceperson.IotDevicePersonServic
 import cn.iocoder.yudao.module.pms.service.iotmainworkorder.IotMainWorkOrderService;
 import cn.iocoder.yudao.module.pms.service.iotopeationfill.IotOpeationFillService;
 import cn.iocoder.yudao.module.pms.service.maintain.IotMaintainService;
+import cn.iocoder.yudao.module.pms.service.maintenance.IotMaintenancePlanService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
@@ -63,6 +64,8 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
     private IotInspectOrderService iotInspectOrderService;
     @Resource
     private IotMainWorkOrderService iotMainWorkOrderService;
+    @Resource
+    private IotMaintenancePlanService iotMaintenancePlanService;
     @Resource(name = PMS_THREAD_POOL_TASK_EXECUTOR)
     private ThreadPoolTaskExecutor pmsThreadPoolTaskExecutor;
     @Resource
@@ -202,9 +205,8 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
                 // 修改 执行中 的保养工单
                 iotMainWorkOrderService.syncRunningWorkOrder(changedDeviceIds, deptId.get(), reqVOS.get(0).getPersonIds(), oldDeptPair);
             }
-            // 修改正在执行的保养工单的部门 如果修改了 责任人 同时修改正在执行的保养工单的 责任人 创建人
-            // 工单备注标注 设备调拨 从A->B
-
+            // 修改 保养计划 单独处理保养计划中当前调拨设备对应的保养项
+            iotMaintenancePlanService.syncMaintenancePlan(changedDeviceIds, deptId.get(), reqVOS.get(0).getPersonIds(), oldDeptPair);
             // 修改历史设备资料库
             iotTreeService.deviceAllotTree(changedDeviceIds, deptId.get());
         });

+ 12 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintenance/IotMaintenancePlanService.java

@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.maintenance.IotMaintenancePlan
 
 import javax.validation.Valid;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 保养计划 Service 接口
@@ -83,4 +84,15 @@ public interface IotMaintenancePlanService {
      * @return
      */
     void updatePlanStatus(Long id, Integer status);
+
+    /**
+     * 设备调拨后同步 保养 计划
+     * 修改计划的 deptId 创建人 责任人
+     * @param deviceIds 发生调拨的设备id 列表
+     * @param deptId 调拨后部门id
+     * @param personIds 调拨时设置的责任人列表
+     * @param oldDeptPair key设备id  value设备调拨前所属部门id
+     * @return
+     */
+    void syncMaintenancePlan(List<Long> deviceIds, Long deptId, List<Long> personIds, Map<Long, Long> oldDeptPair);
 }

+ 79 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/maintenance/IotMaintenancePlanServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.pms.service.maintenance;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -21,12 +22,16 @@ import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBom
 import cn.iocoder.yudao.module.pms.dal.mysql.maintenance.IotMaintenancePlanMapper;
 import cn.iocoder.yudao.module.pms.dal.redis.BizNoRedisDAO;
 import cn.iocoder.yudao.module.pms.service.IotDeviceService;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
 import cn.iocoder.yudao.module.system.service.dept.DeptService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -43,6 +48,7 @@ import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
 @Validated
 public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService {
 
+    private static final Logger log = LoggerFactory.getLogger(IotMaintenancePlanServiceImpl.class);
     @Resource
     private IotMaintenancePlanMapper iotMaintenancePlanMapper;
     @Resource
@@ -273,4 +279,77 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
         iotMaintenancePlanMapper.updateById(planDO);
     }
 
+    @Override
+    public void syncMaintenancePlan(List<Long> deviceIds, Long deptId, List<Long> personIds, Map<Long, Long> oldDeptPair) {
+        // 查询当前调拨的设备相关的保养计划 保养计划明细
+        IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
+        reqVO.setDeviceIds(deviceIds);
+        List<IotMaintenanceBomDO> planBoms = iotMaintenanceBomMapper.selectList(reqVO);
+        // 以设备为维度组装保养项列表
+        List<IotMaintenanceBomDO> relatedDeviceBoms = new ArrayList<>();
+        if (CollUtil.isNotEmpty(planBoms)) {
+            planBoms.forEach(bom -> {
+                relatedDeviceBoms.add(bom);
+            });
+        }
+        // 查询调拨后的部门是否已经存在保养计划 如果 保养后的部门没有保养计划 则新建保养计划并添加保养项
+        // 如果调拨后的部门有多个保养计划 随机取1个保养计划 将保养项 添加进去
+        IotMaintenancePlanPageReqVO planReqVO = new IotMaintenancePlanPageReqVO();
+        planReqVO.setDeptId(deptId);
+        List<IotMaintenancePlanDO> plans = iotMaintenancePlanMapper.selectList(planReqVO);
+        // 需要新增的保养项集合
+        List<IotMaintenanceBomDO> tobeAddedBoms = new ArrayList<>();
+        if (CollUtil.isNotEmpty(plans)) {
+            IotMaintenancePlanDO specifiedPlan = plans.get(0);
+            // 将集合 relatedDeviceBoms 中的保养项与 新保养计划 建立关联
+            if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
+                relatedDeviceBoms.forEach(bom -> {
+                    IotMaintenanceBomDO copy = BeanUtils.toBean(bom, IotMaintenanceBomDO.class);
+                    copy.setId(null);
+                    copy.setPlanId(specifiedPlan.getId());
+                    copy.setDeleted(false);
+                    tobeAddedBoms.add(copy);
+                });
+            }
+        } else {
+            DeptDO dept = deptService.getDept(deptId);
+            String no = bizNoRedisDAO.generate(BizNoRedisDAO.MAIN_PLAN_NO_PREFIX);
+            // 调拨后的部门没有保养计划 新增保养计划
+            IotMaintenancePlanDO newPlan = new IotMaintenancePlanDO();
+            newPlan.setDeptId(deptId);
+            newPlan.setSerialNumber(no);
+            newPlan.setName(ObjUtil.isNotEmpty(dept) ? dept.getName() : StrUtil.EMPTY + " - " + "保养计划");
+            newPlan.setResponsiblePerson(CollUtil.isNotEmpty(personIds) ? String.valueOf(personIds.get(0)) : StrUtil.EMPTY);
+            newPlan.setCreator(CollUtil.isNotEmpty(personIds) ? String.valueOf(personIds.get(0)) : StrUtil.EMPTY);
+            newPlan.setCreateTime(LocalDateTime.now());
+            iotMaintenancePlanMapper.insert(newPlan);
+            // 将集合 relatedDeviceBoms 中的保养项与 新保养计划 建立关联
+            if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
+                relatedDeviceBoms.forEach(bom -> {
+                    IotMaintenanceBomDO copy = BeanUtils.toBean(bom, IotMaintenanceBomDO.class);
+                    copy.setId(null);
+                    copy.setPlanId(newPlan.getId());
+                    copy.setDeleted(false);
+                    tobeAddedBoms.add(copy);
+                });
+            }
+        }
+        // 删除设备调拨前保养计划中的保养项 新增调拨后部门保养计划的保养项
+        // 需要修改(删除)的保养项集合
+        if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
+            relatedDeviceBoms.forEach(bom -> {
+                // 执行数据 删除 操作
+                List<Long> deleteIds = relatedDeviceBoms.stream()
+                        .map(IotMaintenanceBomDO::getId)
+                        .collect(Collectors.toList());
+                iotMaintenanceBomMapper.deleteBatchIds(deleteIds);
+            });
+        }
+        // 执行数据 新增 操作
+        if (CollUtil.isNotEmpty(tobeAddedBoms)) {
+            iotMaintenanceBomMapper.insertBatch(tobeAddedBoms);
+        }
+
+    }
+
 }