|
|
|
@ -1,18 +1,33 @@
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
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;
|
|
|
|
@ -25,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;
|
|
|
|
@ -32,38 +48,177 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquOrderMapper equOrderMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquOrderDetailMapper equOrderDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquPlanDetailMapper equPlanDetailMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquPlanEquMapper equPlanEquMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquOrderEquMapper equOrderEquMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquPlanStandardMapper equPlanStandardMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EquOrderStandardMapper equOrderStandardMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
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<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**/
|
|
|
|
|
EquPlan equPlan = new EquPlan();
|
|
|
|
|
equPlan.setPlanType("spotInspection");
|
|
|
|
|
List<EquPlan> plans = deviceTaskMapper.getPlans(equPlan);
|
|
|
|
|
|
|
|
|
|
for(EquPlan plan:plans){
|
|
|
|
|
if("day".equals(plan.getPlanLoopType())){
|
|
|
|
|
EquOrder order = new EquOrder();
|
|
|
|
|
order.setPlanType("spotInspection");
|
|
|
|
|
EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(order);
|
|
|
|
|
if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){
|
|
|
|
|
//生成点检计划
|
|
|
|
|
this.createSpotCheckPlan(plan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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){
|
|
|
|
|
/**equ_order**/
|
|
|
|
|
Date nowtime = DateUtils.getNowDate();
|
|
|
|
|
String createBy = SecurityUtils.getUsername();
|
|
|
|
|
int sce = 0;
|
|
|
|
|
/**equ_plan->equ_order********************************************************************/
|
|
|
|
|
EquOrder order = new EquOrder();
|
|
|
|
|
//源->目标
|
|
|
|
|
BeanUtils.copyProperties(plan,order);
|
|
|
|
|
equOrderMapper.insertEquOrder(order);
|
|
|
|
|
/**equ_order_detail**/
|
|
|
|
|
List<EquOrderDetail> details = new ArrayList<>();
|
|
|
|
|
order.setOrderId(IdUtils.fastSimpleUUID());
|
|
|
|
|
order.setCreateBy(createBy);
|
|
|
|
|
order.setCreateTime(nowtime);
|
|
|
|
|
// 流水号
|
|
|
|
|
String serialNum = String.format("%03d",equOrderMapper.selectSerialNumber());
|
|
|
|
|
String orderCode = "O"+DateUtils.dateTimeNow(DateUtils.YYYYMMDD)+serialNum;
|
|
|
|
|
order.setOrderCode(orderCode);
|
|
|
|
|
/**equ_order**/
|
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
|
System.out.println("========equ_order:"+sce);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
/**equ_plan_equ->equ_order_equ*************************************************************/
|
|
|
|
|
EquPlanEqu equPlanEqu = new EquPlanEqu();
|
|
|
|
|
equPlanEqu.setId(plan.getPlanEquId());
|
|
|
|
|
List<EquPlanEqu> equs = equPlanEquMapper.selectEquPlanEquList(equPlanEqu);
|
|
|
|
|
if(CollectionUtils.isEmpty(equs)){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
String orderEquId = IdUtils.fastSimpleUUID();
|
|
|
|
|
//equs一定就一个实值
|
|
|
|
|
for(EquPlanEqu equ:equs){
|
|
|
|
|
equ.setId(orderEquId);
|
|
|
|
|
equ.setCreateTime(nowtime);
|
|
|
|
|
equ.setCreateBy(createBy);
|
|
|
|
|
equ.setDelFlag("0");
|
|
|
|
|
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());
|
|
|
|
|
itqo.setDelFlag("0");
|
|
|
|
|
List<EquPlanDetail> details = equPlanDetailMapper.selectEquPlanDetailList(itqo);
|
|
|
|
|
if(CollectionUtils.isEmpty(details)){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<EquPlanStandard> standards = new ArrayList<>();
|
|
|
|
|
List<EquPlanStandard> standards0 = null;
|
|
|
|
|
for(EquPlanDetail itme:details){
|
|
|
|
|
String detailId = IdUtils.fastSimpleUUID();
|
|
|
|
|
EquPlanStandard standardqo = new EquPlanStandard();
|
|
|
|
|
//equ_plan_detail的id
|
|
|
|
|
standardqo.setParentCode(itme.getId());
|
|
|
|
|
standards0 = equPlanStandardMapper.selectEquPlanStandardList(standardqo);
|
|
|
|
|
for(EquPlanStandard standard:standards0) {
|
|
|
|
|
standard.setId(IdUtils.fastSimpleUUID());
|
|
|
|
|
standard.setCreateTime(nowtime);
|
|
|
|
|
standard.setCreateBy(createBy);
|
|
|
|
|
standard.setDelFlag("0");
|
|
|
|
|
standard.setPlanCode(orderCode);
|
|
|
|
|
standard.setParentCode(detailId);
|
|
|
|
|
}
|
|
|
|
|
standards.addAll(standards0);
|
|
|
|
|
|
|
|
|
|
itme.setId(detailId);
|
|
|
|
|
itme.setCreateTime(nowtime);
|
|
|
|
|
itme.setCreateBy(createBy);
|
|
|
|
|
itme.setDelFlag("0");
|
|
|
|
|
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);
|
|
|
|
|
System.out.println("========equ_order_detail:"+sce);
|
|
|
|
|
/**equ_plan_person->equ_order_standard*********************************************************/
|
|
|
|
|
EquPlanPerson equPlanPerson = new EquPlanPerson();
|
|
|
|
|
equPlanPerson.setPlanCode(plan.getPlanCode());
|
|
|
|
|
List<EquPlanPerson> persons = equPlanPersonMapper.selectEquPlanPersonList(equPlanPerson);
|
|
|
|
|
if(CollectionUtils.isEmpty(persons)){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(EquPlanPerson person:persons){
|
|
|
|
|
person.setId(IdUtils.fastSimpleUUID());
|
|
|
|
|
person.setCreateTime(nowtime);
|
|
|
|
|
person.setCreateBy(createBy);
|
|
|
|
|
person.setDelFlag("0");
|
|
|
|
|
person.setPlanCode(orderCode);
|
|
|
|
|
}
|
|
|
|
|
sce = equOrderPersonMapper.insertEquOrderPlans(persons);
|
|
|
|
|
System.out.println("========equ_order_standard:"+sce);
|
|
|
|
|
return sce;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|