|
|
@ -1,6 +1,8 @@
|
|
|
|
package com.op.device.service.impl;
|
|
|
|
package com.op.device.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
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.DateUtils;
|
|
|
|
import com.op.common.core.utils.uuid.IdUtils;
|
|
|
|
import com.op.common.core.utils.uuid.IdUtils;
|
|
|
|
import com.op.common.core.web.domain.AjaxResult;
|
|
|
|
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.domain.*;
|
|
|
|
import com.op.device.mapper.*;
|
|
|
|
import com.op.device.mapper.*;
|
|
|
|
import com.op.device.service.IDeviceTaskService;
|
|
|
|
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.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@ -17,6 +23,11 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
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.error;
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.success;
|
|
|
|
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
|
|
|
|
@Service
|
|
|
|
public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
protected Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private DeviceTaskMapper deviceTaskMapper;
|
|
|
|
private DeviceTaskMapper deviceTaskMapper;
|
|
|
@ -56,27 +68,60 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
private EquPlanPersonMapper equPlanPersonMapper;
|
|
|
|
private EquPlanPersonMapper equPlanPersonMapper;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private EquOrderPersonMapper equOrderPersonMapper;
|
|
|
|
private EquOrderPersonMapper equOrderPersonMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RemoteUserService remoteUserService;
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据点检计划生成点检任务
|
|
|
|
* 根据点检计划生成点检任务
|
|
|
|
* **/
|
|
|
|
* **/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
|
|
|
public AjaxResult createSpotCheckPlanTask(EquPlan equPlan) {
|
|
|
|
public AjaxResult createSpotCheckPlanTask() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 加载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 = () -> 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**/
|
|
|
|
/**equ_plan equ_plan_equ**/
|
|
|
|
|
|
|
|
EquPlan equPlan = new EquPlan();
|
|
|
|
equPlan.setPlanType("spotInspection");
|
|
|
|
equPlan.setPlanType("spotInspection");
|
|
|
|
List<EquPlan> plans = deviceTaskMapper.getPlans(equPlan);
|
|
|
|
List<EquPlan> plans = deviceTaskMapper.getPlans(equPlan);
|
|
|
|
|
|
|
|
|
|
|
|
for(EquPlan plan:plans){
|
|
|
|
for(EquPlan plan:plans){
|
|
|
|
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.createSpotCheckPlan(plan);
|
|
|
|
if(m==0){
|
|
|
|
if(m==0){
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("++++++++++++" + poolName + "++++点检结束++++++++++");
|
|
|
|
return success();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int createSpotCheckPlan(EquPlan plan){
|
|
|
|
private int createSpotCheckPlan(EquPlan plan){
|
|
|
@ -96,6 +141,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
order.setOrderCode(orderCode);
|
|
|
|
order.setOrderCode(orderCode);
|
|
|
|
/**equ_order**/
|
|
|
|
/**equ_order**/
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
|
|
|
|
System.out.println("========equ_order:"+sce);
|
|
|
|
|
|
|
|
|
|
|
|
/**equ_plan_equ->equ_order_equ*************************************************************/
|
|
|
|
/**equ_plan_equ->equ_order_equ*************************************************************/
|
|
|
|
EquPlanEqu equPlanEqu = new EquPlanEqu();
|
|
|
|
EquPlanEqu equPlanEqu = new EquPlanEqu();
|
|
|
@ -114,6 +160,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
equ.setCode(orderCode);
|
|
|
|
equ.setCode(orderCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sce = equOrderEquMapper.insertEquOrderEqus(equs);
|
|
|
|
sce = equOrderEquMapper.insertEquOrderEqus(equs);
|
|
|
|
|
|
|
|
System.out.println("========equ_order_equ:"+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());
|
|
|
@ -148,12 +195,14 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
itme.setParentCode(orderEquId);
|
|
|
|
itme.setParentCode(orderEquId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sce = equOrderDetailMapper.insertEquOrderDetails(details);
|
|
|
|
sce = equOrderDetailMapper.insertEquOrderDetails(details);
|
|
|
|
|
|
|
|
System.out.println("========equ_order_detail:"+sce);
|
|
|
|
/**equ_plan_standard->equ_order_standard*******************************************************/
|
|
|
|
/**equ_plan_standard->equ_order_standard*******************************************************/
|
|
|
|
if(CollectionUtils.isEmpty(standards)){
|
|
|
|
if(CollectionUtils.isEmpty(standards)){
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sce = equOrderStandardMapper.insertEquOrderStandards(standards);
|
|
|
|
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 equPlanPerson = new EquPlanPerson();
|
|
|
|
equPlanPerson.setPlanCode(plan.getPlanCode());
|
|
|
|
equPlanPerson.setPlanCode(plan.getPlanCode());
|
|
|
|
List<EquPlanPerson> persons = equPlanPersonMapper.selectEquPlanPersonList(equPlanPerson);
|
|
|
|
List<EquPlanPerson> persons = equPlanPersonMapper.selectEquPlanPersonList(equPlanPerson);
|
|
|
@ -169,6 +218,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
person.setPlanCode(orderCode);
|
|
|
|
person.setPlanCode(orderCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sce = equOrderPersonMapper.insertEquOrderPlans(persons);
|
|
|
|
sce = equOrderPersonMapper.insertEquOrderPlans(persons);
|
|
|
|
|
|
|
|
System.out.println("========equ_order_standard:"+sce);
|
|
|
|
return sce;
|
|
|
|
return sce;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|