소스 검색

pms 定时任务保养计划生成工单 过滤掉 停用的保养计划

zhangcl 1 개월 전
부모
커밋
e5c2253f5f

+ 8 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/maintenance/IotMaintenancePlanController.java

@@ -97,6 +97,14 @@ public class IotMaintenancePlanController {
         return success(new PageResult<>(buildMaintenancePlanList(pageResult.getList()), pageResult.getTotal()));
     }
 
+    @PutMapping("/update-status")
+    @Operation(summary = "修改保养计划状态")
+    @PreAuthorize("@ss.hasPermission('rq:iot-maintenance-plan:update')")
+    public CommonResult<Boolean> updatePlanStatus(@Valid @RequestBody IotMaintenancePlanSaveReqVO reqVO) {
+        iotMaintenancePlanService.updatePlanStatus(reqVO.getId(), reqVO.getStatus());
+        return success(true);
+    }
+
     @GetMapping("/export-excel")
     @Operation(summary = "导出保养计划 Excel")
     @PreAuthorize("@ss.hasPermission('rq:iot-maintenance-plan:export')")

+ 18 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pms.job.mainworkorder;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
@@ -79,16 +80,30 @@ public class CreateMainWorkOrderJob implements JobHandler {
     public String execute(String param) throws Exception {
         // 查询所有 保养计划明细
         IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
-        List<IotMaintenanceBomDO> mainBomList = iotMaintenanceBomService.getIotMainPlanBomList(reqVO);
+        List<IotMaintenanceBomDO> originMainBomList = iotMaintenanceBomService.getIotMainPlanBomList(reqVO);
         // 查询所有保养计划 保养工单会复制保养计划的部分信息
         IotMaintenancePlanPageReqVO planReqVO = new IotMaintenancePlanPageReqVO();
+        // 只查询开启状态的保养计划
+        planReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
         List<IotMaintenancePlanDO> plans = iotMaintenancePlanService.maintenancePlans(planReqVO);
         if (CollUtil.isEmpty(plans)) {
             return "没有待保养项";
         }
-        if (CollUtil.isEmpty(mainBomList)) {
+        if (CollUtil.isEmpty(originMainBomList)) {
             return "没有待保养项";
         }
+        // 过滤掉停用的保养计划
+        List<IotMaintenanceBomDO> mainBomList = new ArrayList<>();
+        Set<Long> enabledPlanIds = new HashSet<>();
+        plans.forEach(plan -> {
+            enabledPlanIds.add(plan.getId());
+        });
+        originMainBomList.forEach(bom -> {
+            if (enabledPlanIds.contains(bom.getPlanId())) {
+                mainBomList.add(bom);
+            }
+        });
+
         List<Long> deviceIds = new ArrayList<>();
         // 运行记录模板中 多种 累计时长 公里数 属性名称集合
         Set<String> boundedMultiAttrNames = new HashSet<>();
@@ -261,6 +276,7 @@ public class CreateMainWorkOrderJob implements JobHandler {
                     workOrderBom.setBomNodeId(bom.getBomNodeId());
                     workOrderBom.setName(bom.getName());
                     workOrderBom.setCode(bom.getCode());
+                    workOrderBom.setType(bom.getType());
                     workOrderBOMs.add(workOrderBom);
                 }
             });

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

@@ -76,4 +76,11 @@ public interface IotMaintenancePlanService {
      * @return
      */
     Long updatePlan(IotMaintenanceSaveVO updateReqVO);
+
+    /**
+     * 修改保养计划 状态
+     *
+     * @return
+     */
+    void updatePlanStatus(Long id, Integer status);
 }

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

@@ -159,4 +159,10 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
         return iotMaintenancePlan.getId();
     }
 
+    @Override
+    public void updatePlanStatus(Long id, Integer status) {
+        IotMaintenancePlanDO planDO = iotMaintenancePlanMapper.selectById(id).setStatus(status);
+        iotMaintenancePlanMapper.updateById(planDO);
+    }
+
 }