|
|
@@ -0,0 +1,52 @@
|
|
|
+package com.jeesite.modules.mes.service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.jeesite.modules.mes.dao.MesProcessCntDao;
|
|
|
+import com.jeesite.modules.mes.entity.MesProductRecord;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class MesPieceworkService {
|
|
|
+ private final MesProcessCntDao dao;
|
|
|
+
|
|
|
+ public MesPieceworkService(MesProcessCntDao dao) {
|
|
|
+ this.dao = dao;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean supports(String lineSn) {
|
|
|
+ return "CZ060".equals(lineSn) || "CZ061".equals(lineSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String processNo(String oprno) {
|
|
|
+ if (oprno == null || !oprno.trim().matches("(?i)OP[0-9]{2,3}[A-Z]?")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String digits = oprno.trim().substring(2).replaceFirst("(?i)[A-Z]$", "");
|
|
|
+ return String.format(Locale.ROOT, "OP%03d", Integer.parseInt(digits));
|
|
|
+ }
|
|
|
+
|
|
|
+ public String findRepairLine(String sn, String oprno) {
|
|
|
+ String lineSn = dao.findRepairLine(sn, processNo(oprno));
|
|
|
+ return supports(lineSn) ? lineSn : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Called within the result transaction by actual reporting paths.
|
|
|
+ public void recordCompletion(MesProductRecord record, String previousResult, String previousSource) {
|
|
|
+ String process = processNo(record.getOprno());
|
|
|
+ if (!supports(record.getLineSn()) || process == null || !"100000".equals(record.getCraft())
|
|
|
+ || !("OK".equals(record.getContent()) || "NG".equals(record.getContent()))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Date completedAt = new Date();
|
|
|
+ if ("OK".equals(record.getContent())) {
|
|
|
+ dao.confirmRepairs(record, process, completedAt);
|
|
|
+ }
|
|
|
+ if ("UDF".equals(previousResult) || "1".equals(previousSource) || "2".equals(previousSource)) {
|
|
|
+ dao.insertFirstCompletion(record, process, completedAt);
|
|
|
+ dao.setFirstCompletionDate(record, process);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|