|
|
@@ -0,0 +1,105 @@
|
|
|
+package com.jeesite.modules.scheduling;
|
|
|
+
|
|
|
+import com.jeesite.common.lang.ObjectUtils;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
+import com.jeesite.modules.mes.entity.MesProduct;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductRecord;
|
|
|
+import com.jeesite.modules.mes.entity.MesScrap;
|
|
|
+import com.jeesite.modules.mes.service.MesProductRecordService;
|
|
|
+import com.jeesite.modules.mes.service.MesProductService;
|
|
|
+import com.jeesite.modules.mes.service.MesScrapService;
|
|
|
+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.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * NG超时报废:
|
|
|
+ * 每小时查找最近74小时内的总结果NG记录,若NG时间已超过72小时,
|
|
|
+ * 则将对应工件状态改为报废(3),并写入报废记录。
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@EnableScheduling
|
|
|
+public class ProductNgScrapScheduling {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ProductNgScrapScheduling.class);
|
|
|
+
|
|
|
+ private static final String SCRAP_REASON = "NG超过72小时系统自动报废";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductRecordService mesProductRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductService mesProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesScrapService mesScrapService;
|
|
|
+
|
|
|
+// @Scheduled(fixedRate = 3600000)
|
|
|
+ public void scrapOverdueNgProducts() {
|
|
|
+ try {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ Date from74h = Date.from(now.minusHours(74).atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ MesProductRecord query = new MesProductRecord();
|
|
|
+ query.getSqlMap().getWhere()
|
|
|
+ .and("craft", QueryType.EQ, "100000")
|
|
|
+ .and("content", QueryType.EQ, "NG")
|
|
|
+ .and("update_date", QueryType.GTE, from74h);
|
|
|
+ List<MesProductRecord> ngList = mesProductRecordService.findList(query);
|
|
|
+ if (ngList == null || ngList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> handledSn = new HashSet<>();
|
|
|
+ for (MesProductRecord record : ngList) {
|
|
|
+ if (record == null || StringUtils.isBlank(record.getSn()) || record.getUpdateDate() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String sn = record.getSn().trim();
|
|
|
+ if (!handledSn.add(sn)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime ngTime = record.getUpdateDate().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
+ .toLocalDateTime();
|
|
|
+ long hours = ChronoUnit.HOURS.between(ngTime, now);
|
|
|
+ if (hours < 72) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ MesProduct productQuery = new MesProduct();
|
|
|
+ productQuery.setSn(sn);
|
|
|
+ MesProduct product = mesProductService.findInfo(productQuery);
|
|
|
+ if (ObjectUtils.isEmpty(product) || "3".equals(product.getState())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ product.setState("3");
|
|
|
+ mesProductService.update(product);
|
|
|
+
|
|
|
+ MesScrap scrap = new MesScrap();
|
|
|
+ scrap.setSn(sn);
|
|
|
+ scrap.setReason(SCRAP_REASON);
|
|
|
+ scrap.setProductCate(product.getCate());
|
|
|
+ mesScrapService.save(scrap);
|
|
|
+
|
|
|
+ logger.warn("NG超72小时自动报废:sn={}, ngTime={}, hours={}", sn, ngTime, hours);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("NG超时报废定时任务异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|