|
|
|
@ -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<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){
|
|
|
|
|
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<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();
|
|
|
|
|
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<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*******************************************************/
|
|
|
|
|
EquPlanDetail itqo = new EquPlanDetail();
|
|
|
|
|
itqo.setParentCode(plan.getPlanEquId());
|
|
|
|
|