保养定时任务

highway
zhaoxiaolin 1 year ago
parent 52b3bc3a83
commit 24fe8b0b83

@ -21,4 +21,10 @@ public interface RemoteDeviceService {
@PostMapping("/deviceTask/createSpotCheckPlanTask") @PostMapping("/deviceTask/createSpotCheckPlanTask")
public R createSpotCheckPlanTask(); public R createSpotCheckPlanTask();
@PostMapping("/deviceTask/createPatrolCheckPlanTask")
public R createPatrolCheckPlanTask();
@PostMapping("/deviceTask/createMaintenancePlanTask")
public R createMaintenancePlanTask();
} }

@ -27,6 +27,16 @@ public class RemoteDeviceFallbackFactory implements FallbackFactory<RemoteDevice
public R createSpotCheckPlanTask() { public R createSpotCheckPlanTask() {
return R.fail("点检计划创建失败:" + throwable.getMessage()); return R.fail("点检计划创建失败:" + throwable.getMessage());
} }
@Override
public R createPatrolCheckPlanTask() {
return R.fail("巡检计划创建失败:" + throwable.getMessage());
}
@Override
public R createMaintenancePlanTask() {
return R.fail("保养计划创建失败:" + throwable.getMessage());
}
}; };
} }
} }

@ -38,5 +38,29 @@ public class DeviceTaskController {
return R.fail("点检计划生成失败"); return R.fail("点检计划生成失败");
} }
/**
*
* @return
*/
@PostMapping("/createPatrolCheckPlanTask")
public R createPatrolCheckPlanTask() {
AjaxResult result = taskService.createPatrolCheckPlanTask();
if(result.isSuccess()){
return R.ok("巡检计划生成成功");
}
return R.fail("巡检计划生成失败");
}
/**
*
* @return
*/
@PostMapping("/createMaintenancePlanTask")
public R createMaintenancePlanTask() {
AjaxResult result = taskService.createMaintenancePlanTask();
if(result.isSuccess()){
return R.ok("保养计划生成成功");
}
return R.fail("保养计划生成失败");
}
} }

@ -21,4 +21,6 @@ public interface DeviceTaskMapper {
List<EquPlan> getPlans(EquPlan equPlan); List<EquPlan> getPlans(EquPlan equPlan);
EquOrder getNewTaskOrder(EquPlan quPlan); EquOrder getNewTaskOrder(EquPlan quPlan);
EquOrder getNewTaskOrder0(EquPlan plan);
} }

@ -3,6 +3,8 @@ package com.op.device.mapper;
import java.util.List; import java.util.List;
import com.op.device.domain.EquOrderEquSpare; import com.op.device.domain.EquOrderEquSpare;
import com.op.device.domain.EquPlanEquSpare;
import org.apache.ibatis.annotations.Param;
/** /**
* Mapper * Mapper
@ -72,4 +74,6 @@ public interface EquOrderEquSpareMapper {
* @return * @return
*/ */
List<EquOrderEquSpare> selectEquOrderEquSpareByOrderCode(String orderCode); List<EquOrderEquSpare> selectEquOrderEquSpareByOrderCode(String orderCode);
int insertEquOrderEquSpares(@Param("list") List<EquPlanEquSpare> spares);
} }

@ -13,4 +13,8 @@ import com.op.device.domain.EquPlan;
public interface IDeviceTaskService { public interface IDeviceTaskService {
AjaxResult createSpotCheckPlanTask(); AjaxResult createSpotCheckPlanTask();
AjaxResult createPatrolCheckPlanTask();
AjaxResult createMaintenancePlanTask();
} }

@ -59,6 +59,11 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
@Autowired @Autowired
private EquOrderEquMapper equOrderEquMapper; private EquOrderEquMapper equOrderEquMapper;
@Autowired
private EquPlanEquSpareMapper equPlanEquSpareMapper;
@Autowired
private EquOrderEquSpareMapper equOrderEquSpareMapper;
@Autowired @Autowired
private EquPlanStandardMapper equPlanStandardMapper; private EquPlanStandardMapper equPlanStandardMapper;
@Autowired @Autowired
@ -74,7 +79,6 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
* *
* **/ * **/
@Override @Override
public AjaxResult createSpotCheckPlanTask() { public AjaxResult createSpotCheckPlanTask() {
// 加载sf-cloud库的sys_datasource // 加载sf-cloud库的sys_datasource
@ -104,6 +108,72 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
return success(); return success();
} }
/**
*
* **/
@Override
public AjaxResult createPatrolCheckPlanTask() {
// 加载sf-cloud库的sys_datasource
SysUser sysUser = new SysUser();
sysUser.setUserId(1L);
R<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
List<Map<String, String>> dateSources = dateSources0.getData();
ExecutorService executorService = new ThreadPoolExecutor(
dateSources.size(),
dateSources.size(),
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
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<List<Map<String, String>>> dateSources0 = remoteUserService.getPoolNameList(sysUser);
List<Map<String, String>> dateSources = dateSources0.getData();
ExecutorService executorService = new ThreadPoolExecutor(
dateSources.size(),
dateSources.size(),
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
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){ public void createSpotCheckPlanFunc(String poolName){
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
/**equ_plan equ_plan_equ**/ /**equ_plan equ_plan_equ**/
@ -115,7 +185,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan); EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan);
if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){ if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){
//生成点检计划 //生成点检计划
int m = this.createSpotCheckPlan(plan); int m = this.createOrderPlan(plan);
if(m==0){ if(m==0){
error("equ_order相关添加失败"); error("equ_order相关添加失败");
} }
@ -124,7 +194,55 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
logger.info("++++++++++++" + poolName + "++++点检结束++++++++++"); 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<EquPlan> 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<EquPlan> 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(); Date nowtime = DateUtils.getNowDate();
String createBy = SecurityUtils.getUsername(); String createBy = SecurityUtils.getUsername();
int sce = 0; int sce = 0;
@ -161,6 +279,23 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
} }
sce = equOrderEquMapper.insertEquOrderEqus(equs); sce = equOrderEquMapper.insertEquOrderEqus(equs);
System.out.println(plan.getPlanCode()+"========equ_order_equ:"+sce); 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<EquPlanEquSpare> 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*******************************************************/ /**equ_plan_detail->equ_order_detail*******************************************************/
EquPlanDetail itqo = new EquPlanDetail(); EquPlanDetail itqo = new EquPlanDetail();
itqo.setParentCode(plan.getPlanEquId()); itqo.setParentCode(plan.getPlanEquId());

@ -15,6 +15,8 @@
ep.plan_restrict planRestrict, ep.plan_restrict planRestrict,
ep.plan_type planType, ep.plan_type planType,
ep.plan_outsource planOutsource, ep.plan_outsource planOutsource,
ep.calculation_rule calculationRule,
ep.shut_down as 'shutDown',
epe.equipment_code equipmentCode, epe.equipment_code equipmentCode,
epe.equipment_name equipmentName, epe.equipment_name equipmentName,
epe.id planEquId epe.id planEquId
@ -23,6 +25,9 @@
where ep.del_flag = '0' and epe.del_flag = '0' and ep.plan_status = '0' where ep.del_flag = '0' and epe.del_flag = '0' and ep.plan_status = '0'
and ep.plan_type = #{planType} and ep.plan_type = #{planType}
and CONVERT(varchar(10),GETDATE(), 120) >= CONVERT(varchar(10),ep.plan_loop_start, 120) and CONVERT(varchar(10),GETDATE(), 120) >= CONVERT(varchar(10),ep.plan_loop_start, 120)
<if test='planType=="inspection" or (planType=="maintenance" and calculationRule=="0")'>
and CONVERT(varchar(10),ep.plan_loop_end, 120) >= CONVERT(varchar(10),GETDATE(), 120)
</if>
</select> </select>
<select id="getNewTaskOrder" resultType="com.op.device.domain.EquOrder"> <select id="getNewTaskOrder" resultType="com.op.device.domain.EquOrder">
select top 1 order_code orderCode, select top 1 order_code orderCode,
@ -36,4 +41,16 @@
where plan_type = #{planType} and plan_code = #{planCode} where plan_type = #{planType} and plan_code = #{planCode}
order by create_time desc order by create_time desc
</select> </select>
<select id="getNewTaskOrder0" resultType="com.op.device.domain.EquOrder">
select top 1 order_code orderCode,
order_start orderStart,
<if test='planLoopType=="day"'> DATEDIFF (day, order_start, GETDATE()) days </if>
<if test='planLoopType=="week"'> DATEDIFF (week, order_start, GETDATE()) days </if>
<if test='planLoopType=="month"'> DATEDIFF (month, order_start, GETDATE()) days </if>
<if test='planLoopType=="season"'> DATEDIFF (month, order_start, GETDATE())/3 days </if>
<if test='planLoopType=="year"'> DATEDIFF (year, order_start, GETDATE()) days </if>
from equ_order
where plan_type = #{planType} and plan_code = #{planCode}
order by create_time desc
</select>
</mapper> </mapper>

@ -25,7 +25,10 @@
</resultMap> </resultMap>
<sql id="selectEquOrderEquSpareVo"> <sql id="selectEquOrderEquSpareVo">
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
</sql> </sql>
<select id="selectEquOrderEquSpareList" parameterType="EquOrderEquSpare" resultMap="EquOrderEquSpareResult"> <select id="selectEquOrderEquSpareList" parameterType="EquOrderEquSpare" resultMap="EquOrderEquSpareResult">
@ -102,6 +105,26 @@
<if test="updateTime != null">#{updateTime},</if> <if test="updateTime != null">#{updateTime},</if>
</trim> </trim>
</insert> </insert>
<insert id="insertEquOrderEquSpares">
insert into equ_order_equ_spare(
id, order_code, parent_code, material_code, material_desc,
spare_type, apply_num, factory_code, del_flag,
create_by, create_time,
)values
<foreach collection="list" index="index" item="item" separator=",">
(
#{item.id},#{item.code},#{item.parentCode},#{item.materialCode},#{item.materialDesc},
#{item.spareType},#{item.applyNum},#{item.factoryCode},#{item.delFlag},
#{item.createBy},#{item.createTime}
)
</foreach>
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
</insert>
<update id="updateEquOrderEquSpare" parameterType="EquOrderEquSpare"> <update id="updateEquOrderEquSpare" parameterType="EquOrderEquSpare">
update equ_order_equ_spare update equ_order_equ_spare

@ -178,7 +178,7 @@
<if test="repairCode != null">repair_code,</if> <if test="repairCode != null">repair_code,</if>
<if test="workCode != null">work_code,</if> <if test="workCode != null">work_code,</if>
<if test="planRestrict != null">plan_restrict,</if> <if test="planRestrict != null">plan_restrict,</if>
<if test="shutDown != null">shut_down,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderId != null">#{orderId},</if> <if test="orderId != null">#{orderId},</if>
@ -216,6 +216,7 @@
<if test="repairCode != null">#{repairCode},</if> <if test="repairCode != null">#{repairCode},</if>
<if test="workCode != null">#{workCode},</if> <if test="workCode != null">#{workCode},</if>
<if test="planRestrict != null">#{planRestrict},</if> <if test="planRestrict != null">#{planRestrict},</if>
<if test="shutDown != null">#{shutDown},</if>
</trim> </trim>
</insert> </insert>

@ -25,7 +25,10 @@
</resultMap> </resultMap>
<sql id="selectEquPlanEquSpareVo"> <sql id="selectEquPlanEquSpareVo">
select id, code, plan_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_plan_equ_spare select id, code, plan_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_plan_equ_spare
</sql> </sql>
<select id="selectEquPlanEquSpareList" parameterType="EquPlanEquSpare" resultMap="EquPlanEquSpareResult"> <select id="selectEquPlanEquSpareList" parameterType="EquPlanEquSpare" resultMap="EquPlanEquSpareResult">

@ -122,9 +122,20 @@ public class RyTask {
remoteMesService.dataBKTask(); remoteMesService.dataBKTask();
} }
/**每日点检计划生成**/ /**点检计划生成**/
public void createSpotCheckPlanTask(){ public void createSpotCheckPlanTask(){
logger.info("++点检计划+开始++createSpotCheckPlanTask+++++"); logger.info("++点检计划+开始++createSpotCheckPlanTask+++++");
remoteDeviceService.createSpotCheckPlanTask(); remoteDeviceService.createSpotCheckPlanTask();
} }
/**巡检计划生成**/
public void createPatrolCheckPlanTask(){
logger.info("++巡检计划+开始++createPatrolCheckPlanTask+++++");
remoteDeviceService.createPatrolCheckPlanTask();
}
/**保养计划生成**/
public void createMaintenancePlanTask(){
logger.info("++保养计划+开始++createMaintenancePlanTask+++++");
remoteDeviceService.createMaintenancePlanTask();
}
} }

@ -101,7 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from mes_report_work mrw from mes_report_work mrw
left join pro_order_workorder pow on mrw.workorder_code = pow.workorder_code left join pro_order_workorder pow on mrw.workorder_code = pow.workorder_code
<where> <where>
and mrw.del_flag = '0' and mrw.del_flag = '0' and pow.del_flag = '0'
<if test="reportCode != null and reportCode != ''"> and mrw.report_code like concat('%', #{reportCode}, '%')</if> <if test="reportCode != null and reportCode != ''"> and mrw.report_code like concat('%', #{reportCode}, '%')</if>
<if test="workorderCode != null and workorderCode != ''"> and mrw.workorder_code like concat('%', #{workorderCode}, '%')</if> <if test="workorderCode != null and workorderCode != ''"> and mrw.workorder_code like concat('%', #{workorderCode}, '%')</if>
<if test="productCode != null and productCode != ''"> and mrw.product_code like concat('%', #{productCode}, '%')</if> <if test="productCode != null and productCode != ''"> and mrw.product_code like concat('%', #{productCode}, '%')</if>

Loading…
Cancel
Save