点/巡检、保养加小时逻辑

master
wws 1 year ago
parent 830afcd157
commit 4fa7fb9222

@ -31,6 +31,7 @@ public class DeviceTaskController {
*/
@PostMapping("/createSpotCheckPlanTask")
public R createSpotCheckPlanTask() {
System.out.println("点检判断");
AjaxResult result = taskService.createSpotCheckPlanTask();
if(result.isSuccess()){
return R.ok("点检计划生成成功");
@ -57,6 +58,7 @@ public class DeviceTaskController {
*/
@PostMapping("/createMaintenancePlanTask")
public R createMaintenancePlanTask() {
System.out.println("保养判断");
AjaxResult result = taskService.createMaintenancePlanTask();
if(result.isSuccess()){
return R.ok("保养计划生成成功");

@ -102,33 +102,41 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
List<EquOrder> handleList = new ArrayList<>();
long nowTime = DateUtils.getNowDate().getTime();
long dayMs = 86400000l;
if (orderList!=null) {
long hourMs = 1000 * 60 * 60;
if (orderList != null) {
for (EquOrder order : orderList) {
long diff = nowTime - order.getCreateTime().getTime();
if (order.getPlanLoopType().equals("day")){
if (diff < (dayMs * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
}
if (order.getPlanLoopType().equals("week")){
if (diff < (dayMs*7 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
}
if (order.getPlanLoopType().equals("month")){
if (diff < (dayMs*30 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
}
if (order.getPlanLoopType().equals("season")){
if (diff < (dayMs*30*3 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
}
if (order.getPlanLoopType().equals("year")){
if (diff < (dayMs*365 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
switch (order.getPlanLoopType()) {
case "hour":
if (diff < 1000 * 60 * 60 * Long.valueOf(order.getPlanLoop())) {
handleList.add(order);
}
break;
case "day":
if (diff < (dayMs * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
break;
case "week":
if (diff < (dayMs * 7 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
break;
case "month":
if (diff < (dayMs * 30 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
break;
case "season":
if (diff < (dayMs * 30 * 3 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
break;
case "year":
if (diff < (dayMs * 365 * Long.valueOf(order.getPlanLoop()))) {
handleList.add(order);
}
break;
}
}
}
@ -395,7 +403,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
equOrder.setOrderEnd(DateUtils.getNowDate());
// 用时(分钟)
long diff = equOrder.getOrderEnd().getTime() - equOrder.getOrderStart().getTime();
equOrder.setOrderCostTime(String.valueOf(diff/60000));
equOrder.setOrderCostTime(String.valueOf(diff / 60000));
// 创建设备对象用于更新设备状态
Equipment equ = new Equipment();
equ.setEquipmentCode(equOrder.getEquipmentCode());
@ -403,10 +411,10 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
// 费用
BigDecimal sparePartsCost = equSpareApplyMapper.getSparePartsCost(equOrder.getOrderCode());
BigDecimal orderCost = equOrder.getOrderCost();
if (orderCost!=null) {
if (sparePartsCost==null) {
if (orderCost != null) {
if (sparePartsCost == null) {
equOrder.setOrderCost(orderCost);
}else {
} else {
equOrder.setOrderCost(sparePartsCost.add(orderCost));
}
}
@ -664,6 +672,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
/**
*
*
* @param equipmentCode
* @return
*/
@ -703,7 +712,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
for (EquOrderStandard standardList : standardLists) {
//每个检查标准里面的照片
String imageType = "4";
List<BaseFileData> files = equOrderStandardMapper.getBaseFileBatch(standardList.getId(),imageType);
List<BaseFileData> files = equOrderStandardMapper.getBaseFileBatch(standardList.getId(), imageType);
if (!CollectionUtils.isEmpty(files)) {
standardList.setPicturePaths(files);
}
@ -752,7 +761,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
equRepairWorkOrder.setWorkEndTime(DateUtils.getNowDate());
//2.计算维修工单用时
if(list.getWorkStartTime()!= null && equRepairWorkOrder.getWorkEndTime()!= null){
if (list.getWorkStartTime() != null && equRepairWorkOrder.getWorkEndTime() != null) {
//2.1计算日期差值
ZoneId zoneId = ZoneId.systemDefault();
@ -769,18 +778,18 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
double hours = tempDateTime.until(end, ChronoUnit.HOURS);
// tempDateTime = tempDateTime.plusHours(hours);
double minutes = ((tempDateTime.until(end, ChronoUnit.MINUTES)*1.0)%60)/60;
double minutes = ((tempDateTime.until(end, ChronoUnit.MINUTES) * 1.0) % 60) / 60;
// tempDateTime = tempDateTime.plusMinutes(minutes);
double seconds = ((tempDateTime.until(end, ChronoUnit.SECONDS)*1.0)%3600)/3600;
double seconds = ((tempDateTime.until(end, ChronoUnit.SECONDS) * 1.0) % 3600) / 3600;
double hour = BigDecimal.valueOf(hours + minutes + seconds).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//2.2查询完好率报表
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String time = sdf.format(equRepairWorkOrder.getWorkEndTime());
EquOperation equOperation = equOperationMapper.selectEquipmentIntegrityRate(time,equRepairWorkOrder.getEquipmentCode());
EquOperation equOperation = equOperationMapper.selectEquipmentIntegrityRate(time, equRepairWorkOrder.getEquipmentCode());
//2.3修改完好率报表
if(equOperation != null){
if (equOperation != null) {
if (list.getWorkDownMachine().equals("1")) {
DecimalFormat df = new DecimalFormat("#.##");
//实际运行时间 = 实际运行时间 - 故障时间
@ -791,10 +800,10 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
BigDecimal operationTimeBD = new BigDecimal(equOperation.getOperationTime());//运行时间
equOperation.setActualOperationTime(String.valueOf(df.format(result)));//实际运行时间
equOperation.setFaultTime(String.valueOf(faultTime));//故障时间
equOperation.setFailureRate(faultTimeBD.multiply(new BigDecimal(100)).divide(operationTimeBD,2, RoundingMode.HALF_UP).toString()+"%");
equOperation.setShutdownTimes(equOperation.getShutdownTimes()+1);//停机次数加1
equOperation.setFailureRate(faultTimeBD.multiply(new BigDecimal(100)).divide(operationTimeBD, 2, RoundingMode.HALF_UP).toString() + "%");
equOperation.setShutdownTimes(equOperation.getShutdownTimes() + 1);//停机次数加1
}
equOperation.setFailureTimes(equOperation.getFailureTimes()+1);//故障次数加1
equOperation.setFailureTimes(equOperation.getFailureTimes() + 1);//故障次数加1
equOperation.setUpdateBy(SecurityUtils.getUsername());
equOperation.setUpdateTime(DateUtils.getNowDate());
equOperationMapper.updateEquOperation(equOperation);
@ -803,7 +812,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
////3.更新每一项点检/巡检检查项信息
//判空
if(StringUtils.isNotEmpty(equRepairWorkOrder.getDetailList())){
if (StringUtils.isNotEmpty(equRepairWorkOrder.getDetailList())) {
List<EquOrder> checkLists = equRepairWorkOrder.getDetailList();
for (EquOrder checkList : checkLists) {
checkList.setUpdateBy(SecurityUtils.getUsername());
@ -812,7 +821,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
for (EquOrderStandard standardList : standardLists) {
//先删除每个检查项标准图片
String imageType = "4";
equOrderStandardMapper.deleteBaseFileBySourceId(standardList.getId(),imageType);
equOrderStandardMapper.deleteBaseFileBySourceId(standardList.getId(), imageType);
//图片批量新增
if (StringUtils.isNotEmpty(standardList.getPicturePath())) {
String[] ids = standardList.getPicturePath().split(",");
@ -844,7 +853,7 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
////4.新建申领单
//判空
if(StringUtils.isNotEmpty(equRepairWorkOrder.getApplyList())){
if (StringUtils.isNotEmpty(equRepairWorkOrder.getApplyList())) {
List<EquSpareApply> equSpareApplies = equRepairWorkOrder.getApplyList();
for (EquSpareApply equSpareApply : equSpareApplies) {
//生成领料单code
@ -954,26 +963,26 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
List<EquFaultTypeTree> firstTree = new ArrayList<>();
// 判空
if (!CollectionUtils.isEmpty(firstLevel)) {
for(EquFaultType equFaultType : firstLevel){
EquFaultTypeTree equFaultTypeParentTree = new EquFaultTypeTree();
equFaultTypeParentTree.setValue(equFaultType.getDictValue());
equFaultTypeParentTree.setLabel(equFaultType.getDictLabel());
//二级
List <EquFaultType> secondLevel = equFaultTypeMapper.selectSecondLevelList(equFaultType.getDictValue());
// 二级list
List<EquFaultTypeTree> secondTree = new ArrayList<>();
// 判空
if (!CollectionUtils.isEmpty(secondLevel)) {
for(EquFaultType second : secondLevel) {
EquFaultTypeTree equFaultTypeChildTree = new EquFaultTypeTree();
equFaultTypeChildTree.setValue(second.getFaultCode());
equFaultTypeChildTree.setLabel(second.getFaultSubclass());
secondTree.add(equFaultTypeChildTree);
}
}
equFaultTypeParentTree.setChildren(secondTree);
firstTree.add(equFaultTypeParentTree);
}
for (EquFaultType equFaultType : firstLevel) {
EquFaultTypeTree equFaultTypeParentTree = new EquFaultTypeTree();
equFaultTypeParentTree.setValue(equFaultType.getDictValue());
equFaultTypeParentTree.setLabel(equFaultType.getDictLabel());
//二级
List<EquFaultType> secondLevel = equFaultTypeMapper.selectSecondLevelList(equFaultType.getDictValue());
// 二级list
List<EquFaultTypeTree> secondTree = new ArrayList<>();
// 判空
if (!CollectionUtils.isEmpty(secondLevel)) {
for (EquFaultType second : secondLevel) {
EquFaultTypeTree equFaultTypeChildTree = new EquFaultTypeTree();
equFaultTypeChildTree.setValue(second.getFaultCode());
equFaultTypeChildTree.setLabel(second.getFaultSubclass());
secondTree.add(equFaultTypeChildTree);
}
}
equFaultTypeParentTree.setChildren(secondTree);
firstTree.add(equFaultTypeParentTree);
}
}
return success(firstTree);
}
@ -992,11 +1001,12 @@ public class DevicePDAServiceImpl implements IDevicePDAService {
/**
*
*
* @param equipmentCode
* @param operationType /
* @param type /
* @param type /
*/
private void updateOperationRecord(String equipmentCode,String operationType,String type) {
private void updateOperationRecord(String equipmentCode, String operationType, String type) {
// 设备最后一条运行记录
EquOperationRecord lastRecord = equOperationRecordMapper.selectLastOperationRecordByEquipmentCode(equipmentCode);
// 如果在维修中则不添加运行记录

@ -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);
}
}

@ -38,12 +38,12 @@
</select>
<select id="getNewTaskOrder" resultType="com.op.device.domain.EquOrder">
select top 1 order_code orderCode,
create_time createTime,
<if test='planLoopType=="day"'> DATEDIFF (day, create_time, GETDATE()) days </if>
<if test='planLoopType=="week"'> DATEDIFF (week, create_time, GETDATE()) days </if>
<if test='planLoopType=="month"'> DATEDIFF (month, create_time, GETDATE()) days </if>
<if test='planLoopType=="season"'> DATEDIFF (month, create_time, GETDATE())/3 days </if>
<if test='planLoopType=="year"'> DATEDIFF (year, create_time, GETDATE()) days </if>
create_time createTime
<if test="planLoopType=='day'">, DATEDIFF (day, create_time, GETDATE()) days </if>
<if test="planLoopType=='week'">, DATEDIFF (week, create_time, GETDATE()) days </if>
<if test="planLoopType=='month'">, DATEDIFF (month, create_time, GETDATE()) days </if>
<if test="planLoopType=='season'">, DATEDIFF (month, create_time, GETDATE())/3 days </if>
<if test="planLoopType=='year'">, DATEDIFF (year, create_time, GETDATE()) days </if>
from equ_order
where plan_type = #{planType} and plan_code = #{planCode} and equipment_code = #{equipmentCode}
order by create_time desc

@ -177,7 +177,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="spareInventoryFloor != null and spareInventoryFloor != ''"> and womsn.spare_inventory_floor = #{spareInventoryFloor}</if>
<if test="spareInventoryUpper != null and spareInventoryUpper != ''"> and womsn.spare_inventory_upper = #{spareInventoryUpper}</if>
<if test="spareType != null and spareType != ''"> and womsn.spare_type = #{spareType}</if>
<if test="ownEquipmentName != null and ownEquipmentName != ''"> and womsna.own_equipment_name like concat('%', #{ownEquipmentName}, '%')</if>
and womsn.del_flag = '0'
</where>

Loading…
Cancel
Save