From 24fe8b0b83b9708123b917e6e038e2b56d6b6993 Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Wed, 15 Nov 2023 17:28:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=85=BB=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../op/system/api/RemoteDeviceService.java | 6 + .../factory/RemoteDeviceFallbackFactory.java | 10 ++ .../controller/DeviceTaskController.java | 24 +++ .../op/device/mapper/DeviceTaskMapper.java | 2 + .../device/mapper/EquOrderEquSpareMapper.java | 4 + .../op/device/service/IDeviceTaskService.java | 4 + .../service/impl/DeviceTaskServiceImpl.java | 141 +++++++++++++++++- .../mapper/device/DeviceTaskMapper.xml | 17 +++ .../mapper/device/EquOrderEquSpareMapper.xml | 27 +++- .../mapper/device/EquOrderMapper.xml | 3 +- .../mapper/device/EquPlanEquSpareMapper.xml | 7 +- .../src/main/java/com/op/job/task/RyTask.java | 13 +- .../mapper/mes/MesReportWorkMapper.xml | 2 +- 13 files changed, 250 insertions(+), 10 deletions(-) diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteDeviceService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteDeviceService.java index cbdf96f3..2a8dcaa2 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteDeviceService.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteDeviceService.java @@ -21,4 +21,10 @@ public interface RemoteDeviceService { @PostMapping("/deviceTask/createSpotCheckPlanTask") public R createSpotCheckPlanTask(); + + @PostMapping("/deviceTask/createPatrolCheckPlanTask") + public R createPatrolCheckPlanTask(); + + @PostMapping("/deviceTask/createMaintenancePlanTask") + public R createMaintenancePlanTask(); } diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteDeviceFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteDeviceFallbackFactory.java index cdebef4b..593f408b 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteDeviceFallbackFactory.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteDeviceFallbackFactory.java @@ -27,6 +27,16 @@ public class RemoteDeviceFallbackFactory implements FallbackFactory getPlans(EquPlan equPlan); EquOrder getNewTaskOrder(EquPlan quPlan); + + EquOrder getNewTaskOrder0(EquPlan plan); } diff --git a/op-modules/op-device/src/main/java/com/op/device/mapper/EquOrderEquSpareMapper.java b/op-modules/op-device/src/main/java/com/op/device/mapper/EquOrderEquSpareMapper.java index 1d073bb6..7207439d 100644 --- a/op-modules/op-device/src/main/java/com/op/device/mapper/EquOrderEquSpareMapper.java +++ b/op-modules/op-device/src/main/java/com/op/device/mapper/EquOrderEquSpareMapper.java @@ -3,6 +3,8 @@ package com.op.device.mapper; import java.util.List; import com.op.device.domain.EquOrderEquSpare; +import com.op.device.domain.EquPlanEquSpare; +import org.apache.ibatis.annotations.Param; /** * 工单设备备件关联Mapper接口 @@ -72,4 +74,6 @@ public interface EquOrderEquSpareMapper { * @return */ List selectEquOrderEquSpareByOrderCode(String orderCode); + + int insertEquOrderEquSpares(@Param("list") List spares); } diff --git a/op-modules/op-device/src/main/java/com/op/device/service/IDeviceTaskService.java b/op-modules/op-device/src/main/java/com/op/device/service/IDeviceTaskService.java index 67a2c7a4..4cb6b99f 100644 --- a/op-modules/op-device/src/main/java/com/op/device/service/IDeviceTaskService.java +++ b/op-modules/op-device/src/main/java/com/op/device/service/IDeviceTaskService.java @@ -13,4 +13,8 @@ import com.op.device.domain.EquPlan; public interface IDeviceTaskService { AjaxResult createSpotCheckPlanTask(); + + AjaxResult createPatrolCheckPlanTask(); + + AjaxResult createMaintenancePlanTask(); } diff --git a/op-modules/op-device/src/main/java/com/op/device/service/impl/DeviceTaskServiceImpl.java b/op-modules/op-device/src/main/java/com/op/device/service/impl/DeviceTaskServiceImpl.java index 4995ad55..c9f1eecb 100644 --- a/op-modules/op-device/src/main/java/com/op/device/service/impl/DeviceTaskServiceImpl.java +++ b/op-modules/op-device/src/main/java/com/op/device/service/impl/DeviceTaskServiceImpl.java @@ -59,6 +59,11 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { @Autowired private EquOrderEquMapper equOrderEquMapper; + @Autowired + private EquPlanEquSpareMapper equPlanEquSpareMapper; + @Autowired + private EquOrderEquSpareMapper equOrderEquSpareMapper; + @Autowired private EquPlanStandardMapper equPlanStandardMapper; @Autowired @@ -74,7 +79,6 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { * 根据点检计划生成点检任务 * **/ @Override - public AjaxResult createSpotCheckPlanTask() { // 加载sf-cloud库的sys_datasource @@ -104,6 +108,72 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { return success(); } + /** + * 根据巡检计划生成点检任务 + * **/ + @Override + public AjaxResult createPatrolCheckPlanTask() { + + // 加载sf-cloud库的sys_datasource + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + R>> dateSources0 = remoteUserService.getPoolNameList(sysUser); + List> dateSources = dateSources0.getData(); + ExecutorService executorService = new ThreadPoolExecutor( + dateSources.size(), + dateSources.size(), + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue()); + try { + dateSources.forEach(dateSource -> { + if("ds_1000".equals(dateSource.get("poolName"))){//TODO生产去掉 + logger.info("++++++++++++" + dateSource.get("poolName") + "++++巡检开始++++++++++"); + Runnable run = () -> createPatrolCheckPlanFunc(dateSource.get("poolName")); + executorService.execute(run); + } + }); + } catch (Exception e) { + logger.error("service == dataClearTask == exception", e); + return error("service == dataClearTask == exception"); + } finally { + executorService.shutdown(); + } + return success(); + } + + /** + * 根据保养计划生成点检任务 + * **/ + @Override + public AjaxResult createMaintenancePlanTask() { + + // 加载sf-cloud库的sys_datasource + SysUser sysUser = new SysUser(); + sysUser.setUserId(1L); + R>> dateSources0 = remoteUserService.getPoolNameList(sysUser); + List> dateSources = dateSources0.getData(); + ExecutorService executorService = new ThreadPoolExecutor( + dateSources.size(), + dateSources.size(), + 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue()); + try { + dateSources.forEach(dateSource -> { + if("ds_1000".equals(dateSource.get("poolName"))){//TODO生产去掉 + logger.info("++++++++++++" + dateSource.get("poolName") + "++++保养开始++++++++++"); + Runnable run = () -> createMaintenancePlanFunc(dateSource.get("poolName")); + executorService.execute(run); + } + }); + } catch (Exception e) { + logger.error("service == dataClearTask == exception", e); + return error("service == dataClearTask == exception"); + } finally { + executorService.shutdown(); + } + return success(); + } + public void createSpotCheckPlanFunc(String poolName){ DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key /**equ_plan equ_plan_equ**/ @@ -115,7 +185,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan); if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){ //生成点检计划 - int m = this.createSpotCheckPlan(plan); + int m = this.createOrderPlan(plan); if(m==0){ error("equ_order相关添加失败"); } @@ -124,7 +194,55 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { logger.info("++++++++++++" + poolName + "++++点检结束++++++++++"); } - private int createSpotCheckPlan(EquPlan plan){ + public void createPatrolCheckPlanFunc(String poolName){ + DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key + /**equ_plan equ_plan_equ**/ + EquPlan equPlan = new EquPlan(); + equPlan.setPlanType("inspection"); + List plans = deviceTaskMapper.getPlans(equPlan); + + for(EquPlan plan:plans){ + EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan); + if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){ + //生成巡检计划 + int m = this.createOrderPlan(plan); + if(m==0){ + error("equ_order相关添加失败"); + } + } + } + logger.info("++++++++++++" + poolName + "++++巡检结束++++++++++"); + } + + public void createMaintenancePlanFunc(String poolName){ + DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key + /**equ_plan equ_plan_equ**/ + EquPlan equPlan = new EquPlan(); + equPlan.setPlanType("maintenance"); + List plans = deviceTaskMapper.getPlans(equPlan); + + for(EquPlan plan:plans){ + EquOrder hasTask = null; + if("1".equals(plan.getCalculationRule())){ + //根据order_start//1按上次保养时间 + hasTask = deviceTaskMapper.getNewTaskOrder0(plan); + }else if("0".equals(plan.getCalculationRule())){ + //根据createTime//0按固定周期 + hasTask = deviceTaskMapper.getNewTaskOrder(plan); + } + + if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){ + //生成保养计划 + int m = this.createOrderPlan(plan); + if(m==0){ + error("equ_order相关添加失败"); + } + } + } + logger.info("++++++++++++" + poolName + "++++保养结束++++++++++"); + } + + private int createOrderPlan(EquPlan plan){ Date nowtime = DateUtils.getNowDate(); String createBy = SecurityUtils.getUsername(); int sce = 0; @@ -161,6 +279,23 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { } sce = equOrderEquMapper.insertEquOrderEqus(equs); System.out.println(plan.getPlanCode()+"========equ_order_equ:"+sce); + /**equ_plan_equ_spare->equ_order_equ_spare*************************************************************/ + EquPlanEquSpare equPlanEquSpare = new EquPlanEquSpare(); + equPlanEquSpare.setParentCode(plan.getPlanEquId()); + List spares = equPlanEquSpareMapper.selectEquPlanEquSpareList(equPlanEquSpare); + if(CollectionUtils.isEmpty(spares)){ + return 0; + } + for(EquPlanEquSpare spare:spares){ + spare.setId(IdUtils.fastSimpleUUID()); + spare.setCreateTime(nowtime); + spare.setCreateBy(createBy); + spare.setDelFlag("0"); + spare.setCode(orderCode); + spare.setParentCode(plan.getPlanEquId()); + } + sce = equOrderEquSpareMapper.insertEquOrderEquSpares(spares); + System.out.println(plan.getPlanCode()+"========equ_order_equ_spare:"+sce); /**equ_plan_detail->equ_order_detail*******************************************************/ EquPlanDetail itqo = new EquPlanDetail(); itqo.setParentCode(plan.getPlanEquId()); diff --git a/op-modules/op-device/src/main/resources/mapper/device/DeviceTaskMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/DeviceTaskMapper.xml index 29c262a3..f09d1784 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/DeviceTaskMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/DeviceTaskMapper.xml @@ -15,6 +15,8 @@ ep.plan_restrict planRestrict, ep.plan_type planType, ep.plan_outsource planOutsource, + ep.calculation_rule calculationRule, + ep.shut_down as 'shutDown', epe.equipment_code equipmentCode, epe.equipment_name equipmentName, epe.id planEquId @@ -23,6 +25,9 @@ where ep.del_flag = '0' and epe.del_flag = '0' and ep.plan_status = '0' and ep.plan_type = #{planType} and CONVERT(varchar(10),GETDATE(), 120) >= CONVERT(varchar(10),ep.plan_loop_start, 120) + + and CONVERT(varchar(10),ep.plan_loop_end, 120) >= CONVERT(varchar(10),GETDATE(), 120) + + diff --git a/op-modules/op-device/src/main/resources/mapper/device/EquOrderEquSpareMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/EquOrderEquSpareMapper.xml index 33e4447f..f82967f2 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/EquOrderEquSpareMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/EquOrderEquSpareMapper.xml @@ -25,7 +25,10 @@ - select id, code, order_code, parent_code, material_code, material_desc, spare_type, apply_num, factory_code, attr1, attr2, attr3, del_flag, create_by, create_time, update_by, update_time from equ_order_equ_spare + select id, code, order_code, parent_code, material_code, material_desc, + spare_type, apply_num, factory_code, attr1, attr2, attr3, del_flag, + create_by, create_time, update_by, update_time + from equ_order_equ_spare @@ -134,4 +137,4 @@ update equ_plan_equ_spare set del_flag = '1' where plan_code = #{planCode} and del_flag = '0' - \ No newline at end of file + diff --git a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java index 4a26c4cd..79c5d44c 100644 --- a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java +++ b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java @@ -122,9 +122,20 @@ public class RyTask { remoteMesService.dataBKTask(); } - /**每日点检计划生成**/ + /**点检计划生成**/ public void createSpotCheckPlanTask(){ logger.info("++点检计划+开始++createSpotCheckPlanTask+++++"); remoteDeviceService.createSpotCheckPlanTask(); } + /**巡检计划生成**/ + public void createPatrolCheckPlanTask(){ + logger.info("++巡检计划+开始++createPatrolCheckPlanTask+++++"); + remoteDeviceService.createPatrolCheckPlanTask(); + } + + /**保养计划生成**/ + public void createMaintenancePlanTask(){ + logger.info("++保养计划+开始++createMaintenancePlanTask+++++"); + remoteDeviceService.createMaintenancePlanTask(); + } } diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml index 0f9364e6..40ddc366 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml @@ -101,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from mes_report_work mrw left join pro_order_workorder pow on mrw.workorder_code = pow.workorder_code - and mrw.del_flag = '0' + and mrw.del_flag = '0' and pow.del_flag = '0' and mrw.report_code like concat('%', #{reportCode}, '%') and mrw.workorder_code like concat('%', #{workorderCode}, '%') and mrw.product_code like concat('%', #{productCode}, '%')