package com.jeesite.modules.scheduling; import cn.hutool.core.collection.ListUtil; import com.jeesite.common.collect.ListUtils; import com.jeesite.common.config.Global; import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.mybatis.mapper.query.QueryType; import com.jeesite.modules.mes.entity.MesDeviceTime; import com.jeesite.modules.mes.entity.MesLineProcess; import com.jeesite.modules.mes.entity.MesProductModifyRecord; import com.jeesite.modules.mes.entity.MesProductRecord; import com.jeesite.modules.mes.service.MesDeviceTimeService; import com.jeesite.modules.mes.service.MesLineProcessService; import com.jeesite.modules.mes.service.MesProductModifyRecordService; import com.jeesite.modules.mes.service.MesProductRecordService; import com.jeesite.modules.mes.util.CommonUitl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.util.Date; import java.util.List; @Configuration @EnableScheduling public class ProductGh { Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private MesDeviceTimeService mesDeviceTimeService; @Autowired private MesProductRecordService mesProductRecordService; @Autowired private MesLineProcessService mesLineProcessService; @Autowired private MesProductModifyRecordService mesProductModifyRecordService; // @Scheduled(fixedRate=30000) private void configureTasks() { //OP310 try{ MesLineProcess mesLineProcess = new MesLineProcess(); mesLineProcess.setStatus("0"); mesLineProcess.setType("2"); // 固化工位 mesLineProcess.getSqlMap().getWhere().and("pid",QueryType.IS_NULL,""); List mesLineProcesses = mesLineProcessService.findList(mesLineProcess); if(!ListUtils.isEmpty(mesLineProcesses)){ for(MesLineProcess mesLineProcess1 : mesLineProcesses){ MesDeviceTime mesDeviceTime = new MesDeviceTime(); mesDeviceTime.setProductCate(mesLineProcess1.getLineSn()); mesDeviceTime.setOprno(mesLineProcess1.getOprno()); mesDeviceTime.setInterval(0); //查询到结束时间为null List list = mesDeviceTimeService.findList(mesDeviceTime); MesProductRecord mesProductRecord; for (MesDeviceTime deviceTime : list) { Date startDate = deviceTime.getStartDate(); Date now = new Date(); long differenceInMillis = now.getTime() - startDate.getTime(); String guHuatTime = String.valueOf(mesLineProcess1.getDuration());//默认设置为150分钟 //现在时间大于开始时间两小时 long twoHoursInMillis = Integer.parseInt(guHuatTime) * 60 * 1000; if (differenceInMillis >= twoHoursInMillis) { //修改结束时间 deviceTime.setEndDate(now); long time = differenceInMillis / 1000; deviceTime.setInterval(Integer.parseInt(String.valueOf(time))); mesDeviceTimeService.update(deviceTime); //差别时间转化为秒 mesProductRecord = new MesProductRecord(); mesProductRecord.setSn(deviceTime.getSn()); mesProductRecord.setOprno(CommonUitl.formatOprno(deviceTime.getOprno())); mesProductRecord.setLineSn(deviceTime.getProductCate()); mesProductRecord.setCraft("100000"); MesProductRecord mesProductRecord1 = mesProductRecordService.findInfo(mesProductRecord); if(!ObjectUtils.isEmpty(mesProductRecord1)){ String oldcontent = mesProductRecord1.getContent(); //修改生产记录固化时间 mesProductRecord1.setContent("OK"); mesProductRecord1.setMaterielSn(String.valueOf(time)); mesProductRecord1.setOprno(deviceTime.getOprno()); mesProductRecordService.update(mesProductRecord1); // 修改记录 MesProductModifyRecord mesProductModifyRecord1 = new MesProductModifyRecord(); mesProductModifyRecord1.setOprno(deviceTime.getOprno()); mesProductModifyRecord1.setSn(mesProductRecord.getSn()); mesProductModifyRecord1.setCraft(mesProductRecord.getCraft()); mesProductModifyRecord1.setLineSn(mesProductRecord.getLineSn()); mesProductModifyRecord1.setContent("OK"); mesProductModifyRecord1.setContentOld(oldcontent); mesProductModifyRecord1.setSource("0"); mesProductModifyRecord1.setMaterielSn(mesProductRecord.getMaterielSn()); mesProductModifyRecord1.setCreateBy(deviceTime.getCreateBy()); mesProductModifyRecord1.setUpdateBy(deviceTime.getUpdateBy()); mesProductModifyRecordService.save(mesProductModifyRecord1); } } } } } }catch (Exception e){ } } }