|
|
|
@ -134,9 +134,9 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
new LinkedBlockingQueue<Runnable>());
|
|
|
|
|
try {
|
|
|
|
|
dateSources.forEach(dateSource -> {
|
|
|
|
|
logger.info("++++++++++++" + dateSource.get("poolName") + "++++巡检开始++++++++++");
|
|
|
|
|
Runnable run = () -> createPatrolCheckPlanFunc(dateSource.get("poolName"));
|
|
|
|
|
executorService.execute(run);
|
|
|
|
|
logger.info("++++++++++++" + dateSource.get("poolName") + "++++巡检开始++++++++++");
|
|
|
|
|
Runnable run = () -> createPatrolCheckPlanFunc(dateSource.get("poolName"));
|
|
|
|
|
executorService.execute(run);
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("service == dataClearTask == exception", e);
|
|
|
|
@ -180,6 +180,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设备运行记录生成
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -213,6 +214,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设备运行记录数据库备份(每年)
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -244,19 +246,19 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createSpotCheckPlanFunc(String poolName){
|
|
|
|
|
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){
|
|
|
|
|
for (EquPlan plan : plans) {
|
|
|
|
|
EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan);
|
|
|
|
|
if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){
|
|
|
|
|
if (hasTask == null || Integer.parseInt(plan.getPlanLoop()) <= hasTask.getDays() || checkHourTask(hasTask, plan)) {
|
|
|
|
|
//生成点检计划
|
|
|
|
|
int m = this.createOrderPlan(plan);
|
|
|
|
|
if(m==0){
|
|
|
|
|
if (m == 0) {
|
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -264,19 +266,19 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
logger.info("++++++++++++" + poolName + "++++点检结束++++++++++");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createPatrolCheckPlanFunc(String poolName){
|
|
|
|
|
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){
|
|
|
|
|
for (EquPlan plan : plans) {
|
|
|
|
|
EquOrder hasTask = deviceTaskMapper.getNewTaskOrder(plan);
|
|
|
|
|
if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){
|
|
|
|
|
if (hasTask == null || Integer.parseInt(plan.getPlanLoop()) <= hasTask.getDays() || checkHourTask(hasTask, plan)) {
|
|
|
|
|
//生成巡检计划
|
|
|
|
|
int m = this.createOrderPlan(plan);
|
|
|
|
|
if(m==0){
|
|
|
|
|
if (m == 0) {
|
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -284,29 +286,29 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
logger.info("++++++++++++" + poolName + "++++巡检结束++++++++++");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createMaintenancePlanFunc(String 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){
|
|
|
|
|
for (EquPlan plan : plans) {
|
|
|
|
|
EquOrder hasTask = null;
|
|
|
|
|
if("1".equals(plan.getCalculationRule())){
|
|
|
|
|
if ("1".equals(plan.getCalculationRule())) {
|
|
|
|
|
//根据order_start//1按上次保养时间
|
|
|
|
|
hasTask = deviceTaskMapper.getNewTaskOrder0(plan);
|
|
|
|
|
}else if("0".equals(plan.getCalculationRule())){
|
|
|
|
|
} else if ("0".equals(plan.getCalculationRule())) {
|
|
|
|
|
//根据createTime//0按固定周期
|
|
|
|
|
hasTask = deviceTaskMapper.getNewTaskOrder(plan);
|
|
|
|
|
}else if("2".equals(plan.getCalculationRule())){
|
|
|
|
|
} else if ("2".equals(plan.getCalculationRule())) {
|
|
|
|
|
//单次生成保养计划
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(hasTask==null || Integer.parseInt(plan.getPlanLoop())<= hasTask.getDays()){
|
|
|
|
|
if (hasTask == null || Integer.parseInt(plan.getPlanLoop()) <= hasTask.getDays() || checkHourTask(hasTask, plan)) {
|
|
|
|
|
//生成保养计划
|
|
|
|
|
int m = this.createOrderPlan(plan);
|
|
|
|
|
if(m==0){
|
|
|
|
|
if (m == 0) {
|
|
|
|
|
error("equ_order相关添加失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -314,7 +316,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
logger.info("++++++++++++" + poolName + "++++保养结束++++++++++");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int createOrderPlan(EquPlan plan){
|
|
|
|
|
private int createOrderPlan(EquPlan plan) {
|
|
|
|
|
Date nowtime = DateUtils.getNowDate();
|
|
|
|
|
String createBy = "job";
|
|
|
|
|
String factory = plan.getFactoryCode();
|
|
|
|
@ -322,21 +324,21 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
/**equ_plan->equ_order********************************************************************/
|
|
|
|
|
EquOrder order = new EquOrder();
|
|
|
|
|
//源->目标
|
|
|
|
|
BeanUtils.copyProperties(plan,order);
|
|
|
|
|
BeanUtils.copyProperties(plan, order);
|
|
|
|
|
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;
|
|
|
|
|
String serialNum = String.format("%03d", equOrderMapper.selectSerialNumber());
|
|
|
|
|
String orderCode = "O" + DateUtils.dateTimeNow(DateUtils.YYYYMMDD) + serialNum;
|
|
|
|
|
order.setOrderCode(orderCode);
|
|
|
|
|
|
|
|
|
|
if("1".equals(plan.getUpkeep())) {//1委外工单
|
|
|
|
|
order.setOutsourceCode("BW"+orderCode);
|
|
|
|
|
if ("1".equals(plan.getUpkeep())) {//1委外工单
|
|
|
|
|
order.setOutsourceCode("BW" + orderCode);
|
|
|
|
|
}
|
|
|
|
|
/**equ_order**/
|
|
|
|
|
sce = equOrderMapper.insertEquOrder(order);
|
|
|
|
|
System.out.println(plan.getPlanCode()+"========equ_order:"+sce);
|
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_order:" + sce);
|
|
|
|
|
/**equ_plan_equ_spare->equ_spare_apply*************************************************************/
|
|
|
|
|
EquPlanEquSpare equPlanEquSpare = new EquPlanEquSpare();
|
|
|
|
|
equPlanEquSpare.setParentCode(plan.getPlanEquId());
|
|
|
|
@ -347,7 +349,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
for (EquPlanEquSpare spare : spares) {
|
|
|
|
|
EquSpareApply apply = new EquSpareApply();
|
|
|
|
|
apply.setApplyId(IdUtils.fastSimpleUUID());
|
|
|
|
|
apply.setApplyCode("A"+orderCode+String.format("%02d",applySerialNum));
|
|
|
|
|
apply.setApplyCode("A" + orderCode + String.format("%02d", applySerialNum));
|
|
|
|
|
applySerialNum++;
|
|
|
|
|
apply.setSpareCode(spare.getMaterialCode());
|
|
|
|
|
apply.setSpareName(spare.getMaterialDesc());
|
|
|
|
@ -381,13 +383,13 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
|
|
|
|
|
List<EquPlanStandard> standards = new ArrayList<>();
|
|
|
|
|
List<EquPlanStandard> standards0 = null;
|
|
|
|
|
for(EquPlanDetail itme:details){
|
|
|
|
|
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) {
|
|
|
|
|
for (EquPlanStandard standard : standards0) {
|
|
|
|
|
standard.setId(IdUtils.fastSimpleUUID());
|
|
|
|
|
standard.setCreateTime(nowtime);
|
|
|
|
|
standard.setCreateBy(createBy);
|
|
|
|
@ -403,19 +405,19 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
itme.setDelFlag("0");
|
|
|
|
|
itme.setParentCode(orderCode);
|
|
|
|
|
}
|
|
|
|
|
if(!CollectionUtils.isEmpty(details)) {
|
|
|
|
|
if (!CollectionUtils.isEmpty(details)) {
|
|
|
|
|
sce = equOrderDetailMapper.insertEquOrderDetails(details);
|
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_order_detail:" + sce);
|
|
|
|
|
}
|
|
|
|
|
/**equ_plan_standard->equ_order_standard*******************************************************/
|
|
|
|
|
if(!CollectionUtils.isEmpty(standards)) {
|
|
|
|
|
if (!CollectionUtils.isEmpty(standards)) {
|
|
|
|
|
sce = equOrderStandardMapper.insertEquOrderStandards(standards);
|
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_order_standard:" + sce);
|
|
|
|
|
}
|
|
|
|
|
/**equ_plan_person->equ_order_standard*********************************************************/
|
|
|
|
|
if("1".equals(plan.getUpkeep())){//1委外
|
|
|
|
|
if ("1".equals(plan.getUpkeep())) {//1委外
|
|
|
|
|
EquOutsourceWork equOutsourceWork = new EquOutsourceWork();
|
|
|
|
|
BeanUtils.copyProperties(plan,equOutsourceWork);
|
|
|
|
|
BeanUtils.copyProperties(plan, equOutsourceWork);
|
|
|
|
|
equOutsourceWork.setWorkId(IdUtils.fastSimpleUUID());
|
|
|
|
|
equOutsourceWork.setWorkCode(order.getOutsourceCode());
|
|
|
|
|
equOutsourceWork.setWorkType("1");//1委外保养0委外维修
|
|
|
|
@ -425,7 +427,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
equOutsourceWork.setRepairCode(orderCode);
|
|
|
|
|
sce = equOutsourceWorkMapper.insertEquOutsourceWork(equOutsourceWork);
|
|
|
|
|
System.out.println(plan.getPlanCode() + "========equ_outsource_work:" + sce);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
EquPlanPerson equPlanPerson = new EquPlanPerson();
|
|
|
|
|
equPlanPerson.setPlanCode(plan.getPlanCode());
|
|
|
|
|
List<EquPlanPerson> persons = equPlanPersonMapper.selectEquPlanPersonList(equPlanPerson);
|
|
|
|
@ -445,7 +447,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
return sce;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createEquipmentOperation(String poolName){
|
|
|
|
|
private void createEquipmentOperation(String poolName) {
|
|
|
|
|
DynamicDataSourceContextHolder.push(poolName);// 这是数据源的key
|
|
|
|
|
// 当天未生成过运行记录
|
|
|
|
|
int checkNum = equOperationMapper.checkInsertOperation();
|
|
|
|
@ -457,7 +459,7 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
// 统一处理数据
|
|
|
|
|
for (EquOperation operation : operationList) {
|
|
|
|
|
operation.setId(IdUtils.fastSimpleUUID());// id
|
|
|
|
|
operation.setFactoryCode(poolName.replace("ds_",""));// 工厂
|
|
|
|
|
operation.setFactoryCode(poolName.replace("ds_", ""));// 工厂
|
|
|
|
|
operation.setOperationTime(DateUtils.getTime());// 日期
|
|
|
|
|
operation.setOperationTime(operationTime);// 运行时间(默认运行时间)
|
|
|
|
|
operation.setActualOperationTime(operationTime);// 实际运行时间(默认运行时间)
|
|
|
|
@ -468,18 +470,18 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
int batchSize = 100;// 批次数量
|
|
|
|
|
|
|
|
|
|
// 分批次处理
|
|
|
|
|
int batchCount = (operationList.size() + batchSize - 1)/batchSize;// 计算批次数量
|
|
|
|
|
for (int i = 0;i < batchCount; i++) {
|
|
|
|
|
int batchCount = (operationList.size() + batchSize - 1) / batchSize;// 计算批次数量
|
|
|
|
|
for (int i = 0; i < batchCount; i++) {
|
|
|
|
|
int startIndex = i * batchSize;// 索引开始值
|
|
|
|
|
int endIndex = Math.min((i + 1)*batchSize,operationList.size());// 索引结束值
|
|
|
|
|
int endIndex = Math.min((i + 1) * batchSize, operationList.size());// 索引结束值
|
|
|
|
|
// 截取列表
|
|
|
|
|
List<EquOperation> subList = operationList.subList(startIndex,endIndex);
|
|
|
|
|
List<EquOperation> subList = operationList.subList(startIndex, endIndex);
|
|
|
|
|
|
|
|
|
|
int num = equOperationMapper.insertEquOperationByBatch(subList);
|
|
|
|
|
System.out.println("数据源:"+poolName+"--->"+"第"+(i+1)+"轮"+"开始索引:"+startIndex+"________结束索引:"+endIndex+"________成功插入数量:"+num);
|
|
|
|
|
System.out.println("数据源:" + poolName + "--->" + "第" + (i + 1) + "轮" + "开始索引:" + startIndex + "________结束索引:" + endIndex + "________成功插入数量:" + num);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("数据源:"+poolName+"当天生成过运行记录");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("数据源:" + poolName + "当天生成过运行记录");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -494,28 +496,43 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
int insertSize = 100;// 新增批次数量
|
|
|
|
|
|
|
|
|
|
// 分批次备份
|
|
|
|
|
int batchCount = (insertNum + insertSize - 1)/insertSize;// 计算批次数量
|
|
|
|
|
for (int i = 0;i < batchCount; i++) {
|
|
|
|
|
int batchCount = (insertNum + insertSize - 1) / insertSize;// 计算批次数量
|
|
|
|
|
for (int i = 0; i < batchCount; i++) {
|
|
|
|
|
int startIndex = i * insertSize;// 索引开始值
|
|
|
|
|
int endIndex = Math.min((i + 1)*insertSize,insertNum);// 索引结束值
|
|
|
|
|
int endIndex = Math.min((i + 1) * insertSize, insertNum);// 索引结束值
|
|
|
|
|
|
|
|
|
|
// 备份至数据库
|
|
|
|
|
int num = equOperationMapper.backupOperation(startIndex,insertSize);
|
|
|
|
|
int num = equOperationMapper.backupOperation(startIndex, insertSize);
|
|
|
|
|
|
|
|
|
|
System.out.println("数据源:"+poolName+"--->"+"第"+(i+1)+"轮备份"+"开始索引:"+startIndex+"________结束索引:"+endIndex+"________成功插入数量:"+num);
|
|
|
|
|
System.out.println("数据源:" + poolName + "--->" + "第" + (i + 1) + "轮备份" + "开始索引:" + startIndex + "________结束索引:" + endIndex + "________成功插入数量:" + num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除源数据库数据
|
|
|
|
|
int delSize = 100;// 删除批次数量
|
|
|
|
|
for (int i = 0; i < insertNum/delSize+1; i++) {
|
|
|
|
|
for (int i = 0; i < insertNum / delSize + 1; i++) {
|
|
|
|
|
// 在源数据库中删除
|
|
|
|
|
int num = equOperationMapper.deleteOperation(delSize);
|
|
|
|
|
System.out.println("数据源:"+poolName+"--->"+"第"+(i+1)+"轮删除"+"------>成功删除数量:"+num);
|
|
|
|
|
System.out.println("数据源:" + poolName + "--->" + "第" + (i + 1) + "轮删除" + "------>成功删除数量:" + num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("数据源:"+poolName+"---->"+"年份:"+( LocalDate.now().getYear()-2) +"--->已备份");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("数据源:" + poolName + "---->" + "年份:" + (LocalDate.now().getYear() - 2) + "--->已备份");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 循环类型为小时
|
|
|
|
|
private boolean checkHourTask(EquOrder order, EquPlan plan) {
|
|
|
|
|
if (order == null) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
Long loop = 1L;
|
|
|
|
|
Long diff = 0L;
|
|
|
|
|
|
|
|
|
|
if (plan.getPlanLoopType().equals("hour")) {
|
|
|
|
|
loop = Long.valueOf(plan.getPlanLoop()) * 60 * 60 * 1000;
|
|
|
|
|
diff = DateUtils.getNowDate().getTime() - order.getCreateTime().getTime();
|
|
|
|
|
}
|
|
|
|
|
return diff >= loop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
@ -523,14 +540,14 @@ public class DeviceTaskServiceImpl implements IDeviceTaskService {
|
|
|
|
|
int batchSize = 200;// 批次数量
|
|
|
|
|
|
|
|
|
|
// 分批次处理
|
|
|
|
|
int batchCount = (500 + batchSize - 1)/batchSize;// 计算批次数量
|
|
|
|
|
for (int i = 0;i < batchCount; i++) {
|
|
|
|
|
int batchCount = (500 + batchSize - 1) / batchSize;// 计算批次数量
|
|
|
|
|
for (int i = 0; i < batchCount; i++) {
|
|
|
|
|
int startIndex = i * batchSize;
|
|
|
|
|
int endIndex = Math.min((i + 1)*batchSize,500);
|
|
|
|
|
System.out.println("第"+i+"轮"+"开始:"+startIndex+"------结束:"+endIndex);
|
|
|
|
|
int endIndex = Math.min((i + 1) * batchSize, 500);
|
|
|
|
|
System.out.println("第" + i + "轮" + "开始:" + startIndex + "------结束:" + endIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("------>"+batchCount);
|
|
|
|
|
System.out.println("------>" + batchCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|