ProductGh.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.jeesite.modules.scheduling;
  2. import com.jeesite.common.config.Global;
  3. import com.jeesite.common.lang.ObjectUtils;
  4. import com.jeesite.common.mybatis.mapper.query.QueryType;
  5. import com.jeesite.modules.mes.entity.MesDeviceTime;
  6. import com.jeesite.modules.mes.entity.MesProductRecord;
  7. import com.jeesite.modules.mes.service.MesDeviceTimeService;
  8. import com.jeesite.modules.mes.service.MesProductRecordService;
  9. import com.jeesite.modules.mes.util.CommonUitl;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.context.annotation.Configuration;
  14. import org.springframework.scheduling.annotation.EnableScheduling;
  15. import org.springframework.scheduling.annotation.Scheduled;
  16. import java.util.Date;
  17. import java.util.List;
  18. @Configuration
  19. @EnableScheduling
  20. public class ProductGh {
  21. Logger logger = LoggerFactory.getLogger(this.getClass());
  22. @Autowired
  23. private MesDeviceTimeService mesDeviceTimeService;
  24. @Autowired
  25. private MesProductRecordService mesProductRecordService;
  26. @Scheduled(fixedRate=30000)
  27. private void configureTasks() { //OP310
  28. try{
  29. MesDeviceTime mesDeviceTime = new MesDeviceTime();
  30. mesDeviceTime.setProductCate("XT");
  31. String[] states = new String[6];
  32. states[0] = "OP340"; // 恒温静置
  33. states[1] = "OP340A";
  34. states[2] = "OP370";
  35. states[3] = "OP370A";
  36. states[4] = "OP410";
  37. states[5] = "OP410A";
  38. mesDeviceTime.getSqlMap().getWhere().and("oprno", QueryType.IN,states).and("interval",QueryType.EQ,0);
  39. //查询到结束时间为null
  40. List<MesDeviceTime> list = mesDeviceTimeService.findList(mesDeviceTime);
  41. MesProductRecord mesProductRecord;
  42. for (MesDeviceTime deviceTime : list) {
  43. Date startDate = deviceTime.getStartDate();
  44. Date now = new Date();
  45. long differenceInMillis = now.getTime() - startDate.getTime();
  46. String guHuatTime = "150";//默认设置为150分钟
  47. if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP340")) {
  48. guHuatTime = Global.getConfig("OP340.guHuaTime");
  49. } else if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP370")) {
  50. guHuatTime = Global.getConfig("OP370.guHuaTime");
  51. } else if (CommonUitl.formatOprno(deviceTime.getOprno()).equals("OP410")) {
  52. guHuatTime = Global.getConfig("OP410.guHuaTime");
  53. }
  54. //现在时间大于开始时间两小时
  55. long twoHoursInMillis = Integer.parseInt(guHuatTime) * 60 * 1000;
  56. if (differenceInMillis >= twoHoursInMillis) {
  57. //修改结束时间
  58. deviceTime.setEndDate(now);
  59. // long time = (deviceTime.getEndDate().getTime() - startDate.getTime()) / 1000;
  60. long time = differenceInMillis / 1000;
  61. deviceTime.setInterval(Integer.parseInt(String.valueOf(time)));
  62. mesDeviceTimeService.update(deviceTime);
  63. //差别时间转化为秒
  64. mesProductRecord = new MesProductRecord();
  65. mesProductRecord.setSn(deviceTime.getSn());
  66. mesProductRecord.setOprno(CommonUitl.formatOprno(deviceTime.getOprno()));
  67. mesProductRecord.setLineSn(deviceTime.getProductCate());
  68. mesProductRecord.setCraft("100000");
  69. MesProductRecord mesProductRecord1 = mesProductRecordService.findInfo(mesProductRecord);
  70. if(!ObjectUtils.isEmpty(mesProductRecord1)){
  71. //修改生产记录固化时间
  72. mesProductRecord1.setContent("OK");
  73. mesProductRecord1.setMaterielSn(String.valueOf(time));
  74. mesProductRecord1.setOprno(deviceTime.getOprno());
  75. mesProductRecordService.update(mesProductRecord1);
  76. }
  77. }
  78. }
  79. }catch (Exception e){ }
  80. }
  81. }