package org.jeecg.modules.mdc.job;
|
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto;
|
import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto;
|
import org.jeecg.modules.mdc.entity.Equipment;
|
import org.jeecg.modules.mdc.entity.EquipmentSpindleStatistical;
|
import org.jeecg.modules.mdc.service.*;
|
import org.jeecg.modules.mdc.util.DateUtils;
|
import org.jeecg.modules.mdc.util.ThrowableUtil;
|
import org.jeecg.modules.quartz.entity.QuartzJob;
|
import org.jeecg.modules.quartz.entity.SysQuartzLog;
|
import org.jeecg.modules.quartz.service.IQuartzJobService;
|
import org.jeecg.modules.quartz.service.ISysQuartzLogService;
|
import org.jeecg.modules.system.service.ISysAnnouncementService;
|
import org.quartz.*;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 设备运行最大主轴负载统计
|
*
|
* @author Lius
|
* @date 2024/7/18 15:59
|
*/
|
@PersistJobDataAfterExecution
|
@DisallowConcurrentExecution
|
@Slf4j
|
public class StatisticalSpindleJob implements Job {
|
|
@Resource
|
private IQuartzJobService quartzJobService;
|
|
@Resource
|
private ISysQuartzLogService sysQuartzLogService;
|
|
@Resource
|
private ISysAnnouncementService sysAnnouncementService;
|
|
@Resource
|
private IEquipmentService equipmentService;
|
|
@Resource
|
private IEquipmentSpindleStatisticalService equipmentSpindleStatisticalService;
|
|
@Resource
|
private IEquipmentMachiningHistoryService equipmentMachiningHistoryService;
|
|
@Resource
|
private IMachineXYZHistoryService machineXYZHistoryService;
|
|
@Resource
|
private IEquipmentWorkLineService equipmentWorkLineService;
|
|
@Resource
|
private IEquipmentXYZService equipmentXYZService;
|
|
@Override
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
SysQuartzLog quartzLog = new SysQuartzLog();
|
quartzLog.setCreateTime(new Date());
|
List<QuartzJob> byJobClassName = this.quartzJobService.findByJobClassName(this.getClass().getName());
|
if (byJobClassName != null && !byJobClassName.isEmpty()) {
|
quartzLog.setJobId(byJobClassName.get(0).getId());
|
}
|
log.info("设备运行最大主轴负载统计 StatisticalSpindleJob start! 时间:" + DateUtils.getNow());
|
long startTime = System.currentTimeMillis();
|
try {
|
List<Equipment> equipmentList = equipmentService.list();
|
if (equipmentList != null && !equipmentList.isEmpty()) {
|
Date initDate = null;
|
EquipmentSpindleStatistical spindleStatistical;
|
List<EquipmentSpindleStatistical> resultList = new ArrayList<>();
|
for (Equipment equipment : equipmentList) {
|
if (!equipment.getDrivetype().equals("CurrentState")) {
|
String saveTableName = equipment.getSavetablename();
|
Date lastDate = equipmentSpindleStatisticalService.getMaxDate(equipment.getEquipmentid());
|
if (lastDate == null) {
|
Date minCollectTime = equipmentWorkLineService.getMinDate(saveTableName);
|
if (minCollectTime == null) {
|
continue;
|
}
|
initDate = DateUtils.removeTime(minCollectTime);
|
} else {
|
initDate = DateUtils.plusTime(lastDate, 1);
|
}
|
|
spindleStatistical = new EquipmentSpindleStatistical();
|
EquipmentMachiningHistoryDto machiningHistoryDto = equipmentWorkLineService.getMaxSpindleLoad(saveTableName, initDate, DateUtils.plusTime(initDate, 1));
|
if(machiningHistoryDto == null || machiningHistoryDto.getEquipmentID() == null || machiningHistoryDto.getCollectTime() == null) {
|
continue;
|
}
|
spindleStatistical.setCreatedate(initDate);
|
spindleStatistical.setSpindlespeed(machiningHistoryDto.getSpindleSpeed());
|
spindleStatistical.setEquipmentid(equipment.getEquipmentid());
|
spindleStatistical.setEquipmentname(equipment.getEquipmentname());
|
spindleStatistical.setSpindleload(machiningHistoryDto.getSpindleLoad());
|
spindleStatistical.setSpindletime(machiningHistoryDto.getCollectTime());
|
MachineXYZHistoryDto machineXYZHistoryDto = equipmentXYZService.getNearAxisType(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), machiningHistoryDto.getCollectTime());
|
if(machineXYZHistoryDto != null) {
|
spindleStatistical.setAxistime(machineXYZHistoryDto.getCollectTime());
|
spindleStatistical.setAxisx(machineXYZHistoryDto.getXMachine());
|
spindleStatistical.setAxisy(machineXYZHistoryDto.getYMachine());
|
spindleStatistical.setAxisz(machineXYZHistoryDto.getZMachine());
|
spindleStatistical.setAxisa(machineXYZHistoryDto.getAMachine());
|
spindleStatistical.setAxisb(machineXYZHistoryDto.getBMachine());
|
}
|
resultList.add(spindleStatistical);
|
}
|
}
|
if (!resultList.isEmpty()) {
|
equipmentSpindleStatisticalService.saveBatch(resultList);
|
}
|
}
|
quartzLog.setIsSuccess(0);
|
} catch (Exception e) {
|
quartzLog.setIsSuccess(-1);
|
quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
|
// 发送消息通知
|
sysAnnouncementService.jobSendMessage("设备运行最大主轴负载统计", quartzLog.getExceptionDetail());
|
}
|
long endTime = System.currentTimeMillis();
|
quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
|
sysQuartzLogService.save(quartzLog);
|
}
|
}
|