diff --git a/op-modules/op-device/src/main/java/com/op/device/controller/DeviceTaskController.java b/op-modules/op-device/src/main/java/com/op/device/controller/DeviceTaskController.java index 33050ad0..ffe643e9 100644 --- a/op-modules/op-device/src/main/java/com/op/device/controller/DeviceTaskController.java +++ b/op-modules/op-device/src/main/java/com/op/device/controller/DeviceTaskController.java @@ -31,8 +31,7 @@ public class DeviceTaskController { */ @PostMapping("/createSpotCheckPlanTask") public R createSpotCheckPlanTask() { - EquPlan equPlan = new EquPlan(); - AjaxResult result = taskService.createSpotCheckPlanTask(equPlan); + AjaxResult result = taskService.createSpotCheckPlanTask(); if(result.isSuccess()){ return R.ok("点检计划生成成功"); } diff --git a/op-modules/op-device/src/main/java/com/op/device/domain/EquOrder.java b/op-modules/op-device/src/main/java/com/op/device/domain/EquOrder.java index f8cbc97a..c1ac1c74 100644 --- a/op-modules/op-device/src/main/java/com/op/device/domain/EquOrder.java +++ b/op-modules/op-device/src/main/java/com/op/device/domain/EquOrder.java @@ -150,6 +150,15 @@ public class EquOrder extends BaseEntity { private int days; private String equipmentName; + private String planRestrict; + + public String getPlanRestrict() { + return planRestrict; + } + + public void setPlanRestrict(String planRestrict) { + this.planRestrict = planRestrict; + } public String getEquipmentName() { return equipmentName; 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 69e8e9fd..67a2c7a4 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 @@ -12,5 +12,5 @@ import com.op.device.domain.EquPlan; */ public interface IDeviceTaskService { - AjaxResult createSpotCheckPlanTask(EquPlan equPlan); + AjaxResult createSpotCheckPlanTask(); } 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 c9af8a20..187dd8cd 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 @@ -1,6 +1,8 @@ package com.op.device.service.impl; import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import com.op.common.core.domain.R; import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.uuid.IdUtils; import com.op.common.core.web.domain.AjaxResult; @@ -8,6 +10,10 @@ import com.op.common.security.utils.SecurityUtils; import com.op.device.domain.*; import com.op.device.mapper.*; import com.op.device.service.IDeviceTaskService; +import com.op.system.api.RemoteUserService; +import com.op.system.api.domain.SysUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,6 +23,11 @@ import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import static com.op.common.core.web.domain.AjaxResult.error; import static com.op.common.core.web.domain.AjaxResult.success; @@ -29,6 +40,7 @@ import static com.op.common.core.web.domain.AjaxResult.success; */ @Service public class DeviceTaskServiceImpl implements IDeviceTaskService { + protected Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private DeviceTaskMapper deviceTaskMapper; @@ -56,27 +68,60 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { private EquPlanPersonMapper equPlanPersonMapper; @Autowired private EquOrderPersonMapper equOrderPersonMapper; + @Autowired + private RemoteUserService remoteUserService; /** * 根据点检计划生成点检任务 * **/ @Override - @DS("#header.poolName") - public AjaxResult createSpotCheckPlanTask(EquPlan equPlan) { + + public AjaxResult createSpotCheckPlanTask() { + + // 加载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 = () -> createSpotCheckPlanFunc(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**/ + EquPlan equPlan = new EquPlan(); equPlan.setPlanType("spotInspection"); 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.createSpotCheckPlan(plan); - if(m==0){ - error("equ_order相关添加失败"); - } - } + EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan); + if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){ + //生成点检计划 + int m = this.createSpotCheckPlan(plan); + if(m==0){ + error("equ_order相关添加失败"); + } + } } - - return success(); + logger.info("++++++++++++" + poolName + "++++点检结束++++++++++"); } private int createSpotCheckPlan(EquPlan plan){ @@ -96,6 +141,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { order.setOrderCode(orderCode); /**equ_order**/ sce = equOrderMapper.insertEquOrder(order); + System.out.println("========equ_order:"+sce); /**equ_plan_equ->equ_order_equ*************************************************************/ EquPlanEqu equPlanEqu = new EquPlanEqu(); @@ -114,6 +160,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { equ.setCode(orderCode); } sce = equOrderEquMapper.insertEquOrderEqus(equs); + System.out.println("========equ_order_equ:"+sce); /**equ_plan_detail->equ_order_detail*******************************************************/ EquPlanDetail itqo = new EquPlanDetail(); itqo.setParentCode(plan.getPlanEquId()); @@ -148,12 +195,14 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { itme.setParentCode(orderEquId); } sce = equOrderDetailMapper.insertEquOrderDetails(details); + System.out.println("========equ_order_detail:"+sce); /**equ_plan_standard->equ_order_standard*******************************************************/ if(CollectionUtils.isEmpty(standards)){ return 0; } sce = equOrderStandardMapper.insertEquOrderStandards(standards); - /**equ_plan_person->equ_order_person*********************************************************/ + System.out.println("========equ_order_detail:"+sce); + /**equ_plan_person->equ_order_standard*********************************************************/ EquPlanPerson equPlanPerson = new EquPlanPerson(); equPlanPerson.setPlanCode(plan.getPlanCode()); List persons = equPlanPersonMapper.selectEquPlanPersonList(equPlanPerson); @@ -169,6 +218,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService { person.setPlanCode(orderCode); } sce = equOrderPersonMapper.insertEquOrderPlans(persons); + System.out.println("========equ_order_standard:"+sce); return sce; } } diff --git a/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml index f0b80d74..2c34b791 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/EquOrderMapper.xml @@ -177,6 +177,8 @@ repair_code, repair_code, work_code, + plan_restrict, + #{orderId}, @@ -213,6 +215,7 @@ #{orderInspect}, #{repairCode}, #{workCode}, + #{planRestrict}, diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesReportWork.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesReportWork.java index f96f4b22..4420c907 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesReportWork.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesReportWork.java @@ -93,6 +93,9 @@ public class MesReportWork extends BaseEntity { @Excel(name = "工时") private Long workTime; + @Excel(name = "用人") + private Long useMan; + /** 线体编码 */ @Excel(name = "线体编码") private String machineCode; @@ -161,6 +164,14 @@ public class MesReportWork extends BaseEntity { private String feedbackTimeStart; private String feedbackTimeEnd; + public Long getUseMan() { + return useMan; + } + + public void setUseMan(Long useMan) { + this.useMan = useMan; + } + public BigDecimal getQuantitySplit() { return quantitySplit; } 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 dc72daf7..0f9364e6 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 @@ -25,6 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -95,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mrw.feedback_time, mrw.record_user, mrw.status, mrw.remark, mrw.work_time, mrw.machine_code, mrw.machine_name, mrw.team_code, mrw.shift_code, mrw.create_by, mrw.create_time,mrw.upload_time,mrw.upload_status,mrw.upload_msg, + mrw.use_man, pow.order_code,pow.quantity_split from mes_report_work mrw left join pro_order_workorder pow on mrw.workorder_code = pow.workorder_code @@ -455,6 +457,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status, remark, work_time, + use_man, machine_code, machine_name, team_code, @@ -490,6 +493,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{remark}, #{workTime}, + #{useMan}, #{machineCode}, #{machineName}, #{teamCode}, @@ -528,6 +532,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status = #{status}, remark = #{remark}, work_time = #{workTime}, + use_man = #{useMan}, machine_code = #{machineCode}, machine_name = #{machineName}, team_code = #{teamCode},