package com.jeesite.modules.scheduling; 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.MesProductRecord; import com.jeesite.modules.mes.service.MesDeviceTimeService; 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; @Scheduled(fixedRate=30000) private void configureTasks() { //OP310 try{ MesDeviceTime mesDeviceTime = new MesDeviceTime(); mesDeviceTime.setProductCate("XT"); String[] states = new String[6]; states[0] = "OP340"; // 恒温静置 states[1] = "OP340A"; states[2] = "OP370"; states[3] = "OP370A"; states[4] = "OP410"; states[5] = "OP410A"; mesDeviceTime.getSqlMap().getWhere().and("oprno", QueryType.IN,states).and("interval",QueryType.EQ,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 = "150";//默认设置为150分钟 if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP340")) { guHuatTime = Global.getConfig("OP340.guHuaTime"); } else if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP370")) { guHuatTime = Global.getConfig("OP370.guHuaTime"); } else if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP410")) { guHuatTime = Global.getConfig("OP410.guHuaTime"); } //现在时间大于开始时间两小时 long twoHoursInMillis = Integer.parseInt(guHuatTime) * 60 * 1000; if (differenceInMillis >= twoHoursInMillis) { //修改结束时间 deviceTime.setEndDate(now); // long time = (deviceTime.getEndDate().getTime() - startDate.getTime()) / 1000; 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)){ //修改生产记录固化时间 mesProductRecord1.setContent("OK"); mesProductRecord1.setMaterielSn(String.valueOf(time)); mesProductRecord1.setOprno(deviceTime.getOprno()); mesProductRecordService.update(mesProductRecord1); } } } }catch (Exception e){ } } }