Selaa lähdekoodia

大屏优化和cnc出库过站

sunxianglong 2 viikkoa sitten
vanhempi
commit
bfbb03f43d

+ 38 - 0
src/main/java/com/jeesite/modules/mes/service/MesProductRecordService.java

@@ -102,6 +102,12 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 	private MesProductCheckFirstService mesProductCheckFirstService;
 
 	@Autowired
+	private MesProductSampleService mesProductSampleService;
+
+	@Autowired
+	private MesProductSampleRecordService mesProductSampleRecordService;
+
+	@Autowired
 	private MesToolReplaceRecordService mesToolReplaceRecordService;
 
 	@Autowired
@@ -790,6 +796,9 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 			}
 		}
 
+		// 主结果提交时:若为检测样件则写入 mes_product_sample_record
+		saveSampleCheckRecordIfNeeded(sn, oldOprno, lineSn, content, craft);
+
 		// 生成首次检查记录
 		String gjoprnos = Global.getConfig("mes.oprno.important");
 		Boolean checkFirstRet = false;
@@ -901,6 +910,35 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 //		}
 	}
 
+	/**
+	 * 若当前工件是检测样件,则写入样件检测记录(与 updateQualityCommon 原逻辑一致)。
+	 * 仅主结果 craft=100000 时写入,避免过程参数多次提交重复落表。
+	 */
+	public void saveSampleCheckRecordIfNeeded(String sn, String oldOprno, String lineSn, String content, String craft) {
+		if (!"100000".equals(craft) || StringUtils.isBlank(sn) || StringUtils.isBlank(oldOprno) || StringUtils.isBlank(lineSn)) {
+			return;
+		}
+		MesProductSample mesProductSample = new MesProductSample();
+		mesProductSample.setSn(sn);
+		mesProductSample.setOprno(CommonUitl.formatOprno(oldOprno));
+		mesProductSample.setLineSn(lineSn);
+		mesProductSample.setStatus("0");
+		MesProductSample mesProductSample1 = mesProductSampleService.findInfo(mesProductSample);
+		if (ObjectUtils.isEmpty(mesProductSample1)) {
+			return;
+		}
+		MesProductSampleRecord mesProductSampleRecord = new MesProductSampleRecord();
+		mesProductSampleRecord.setSn(sn);
+		// 与 checkRecord 一致:用工位父码(OP360)落库,避免 OP360A 查不到
+		mesProductSampleRecord.setOprno(CommonUitl.formatOprno(oldOprno));
+		mesProductSampleRecord.setLineSn(lineSn);
+		mesProductSampleRecord.setType(mesProductSample1.getType());
+		mesProductSampleRecord.setSampleId(mesProductSample1.getId());
+		// 存实际提交结果:OK样件需 OK、NG样件需 NG,供开班样件点检 checkRecord 匹配
+		mesProductSampleRecord.setResult("OK".equals(content) ? "OK" : "NG");
+		mesProductSampleRecordService.save(mesProductSampleRecord);
+	}
+
 	// 查询班次内的首件记录
 	public Boolean checkFirstProduct(String sn,String oprno,String lineSn){
 		MesShiftDataResp mesShiftDataResp = mesShiftService.getCurShift();

+ 3 - 24
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -2127,30 +2127,7 @@ public class MesProductRecordController extends BaseController {
 			}
 
 
-			// 判断是否是OK/NG样件
-			MesProductSample mesProductSample = new MesProductSample();
-			mesProductSample.setSn(sn);
-			mesProductSample.setOprno(CommonUitl.formatOprno(oprno));
-			mesProductSample.setLineSn(lineSn);
-			mesProductSample.setStatus("0");
-			MesProductSample mesProductSample1 = mesProductSampleService.findInfo(mesProductSample);
-			if(!ObjectUtils.isEmpty(mesProductSample1)){
-				MesProductSampleRecord mesProductSampleRecord = new MesProductSampleRecord();
-				mesProductSampleRecord.setSn(sn);
-				mesProductSampleRecord.setOprno(oprno);
-				mesProductSampleRecord.setLineSn(lineSn);
-				mesProductSampleRecord.setType(mesProductSample1.getType());
-				mesProductSampleRecord.setSampleId(mesProductSample1.getId());
-				String testResult = "OK";
-				if(mesProductSample1.getType().equals("1") && content.equals("NG")){ // OK样件
-					testResult = "NG";
-				}else if(mesProductSample1.getType().equals("2") && content.equals("OK")){ // NG样件
-					testResult = "NG";
-				}
-				mesProductSampleRecord.setResult(testResult);
-				mesProductSampleRecordService.save(mesProductSampleRecord);
-			}
-
+			// 样件检测记录:正常提交走 updateRecordResult;多次OK未达次数(isFlag=false)时在此补写
 			if(isFlag){
 				// 2.判断物料批次是否符合绑定
 				List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(oprno, lineSn);
@@ -2158,6 +2135,8 @@ public class MesProductRecordController extends BaseController {
 					oprno += "A";
 				}
 				mesProductRecordService.updateRecordResult(sn,oprno,craft,"",content,userCode,params,lineSn,true,bmlists,remark);
+			} else {
+				mesProductRecordService.saveSampleCheckRecordIfNeeded(sn, oprno, lineSn, content, craft);
 			}
 
 		}

+ 3 - 3
src/main/resources/views/modules/mes/mesScreen4.html

@@ -203,9 +203,9 @@
 			border-bottom: 2px solid rgba(77, 201, 245, 0.35);
 		}
 		.op-table tbody tr:hover td { background: rgba(0, 200, 255, 0.06); }
-		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 26px; }
-		.op-table td.op-name { color: #FFDD00; text-align: center; font-size: 22px; }
-		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 28px; }
+		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 20px; }
+		.op-table td.op-name { color: #4DC9F5; text-align: center; font-size: 20px; }
+		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 20px; }
 
 		/* ===== 产线阶段数据总览(对齐原 UI 四宫格框) ===== */
 		.overview-wrap {

+ 4 - 4
src/main/resources/views/modules/mes/mesScreen5.html

@@ -225,10 +225,10 @@
 			margin-bottom: 2px;
 			letter-spacing: 1px;
 		}
-		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 26px; }
-		.op-table td.op-name { color: #FFDD00; text-align: center; font-size: 22px; }
-		.op-table td.op-line { color: #FFDD00; text-align: center; font-size: 20px; font-weight: bold; }
-		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 28px; }
+		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 20px; }
+		.op-table td.op-name { color: #4DC9F5; text-align: center; font-size: 20px; }
+		.op-table td.op-line { color: #4DC9F5; text-align: center; font-size: 20px; font-weight: bold; }
+		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 20px; }
 
 		/* ===== 产线阶段数据总览 (按模板排布) ===== */
 		.overview-wrap {

+ 3 - 3
src/main/resources/views/modules/mes/mesScreen7.html

@@ -225,9 +225,9 @@
 			margin-bottom: 2px;
 			letter-spacing: 1px;
 		}
-		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 26px; }
-		.op-table td.op-name { color: #FFDD00; text-align: center; font-size: 22px; }
-		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 28px; }
+		.op-table td.op-col  { color: #00C8FF; font-weight: bold; font-size: 20px; }
+		.op-table td.op-name { color: #4DC9F5; text-align: center; font-size: 20px; }
+		.op-table td.op-val  { color: #00F7FF; font-weight: bold; font-size: 20px; }
 
 		/* ===== 产线阶段数据总览 (按模板排布) ===== */
 		.overview-wrap {

+ 110 - 10
src/test/java/com/jeesite/test/FrameworkQmQualityCheckTest.java

@@ -6,10 +6,14 @@ import com.jeesite.common.lang.StringUtils;
 import com.jeesite.common.tests.BaseSpringContextTests;
 import com.jeesite.modules.Application;
 import com.jeesite.modules.mes.entity.MesLineProcess;
+import com.jeesite.modules.mes.entity.MesProductRecord;
 import com.jeesite.modules.mes.entity.MesProductSample;
 import com.jeesite.modules.mes.entity.MesProductSampleRecord;
+import com.jeesite.modules.mes.resp.BindMaterialResp;
 import com.jeesite.modules.mes.resp.MesShiftDataResp;
+import com.jeesite.modules.mes.resp.ParamsResp;
 import com.jeesite.modules.mes.service.MesLineProcessService;
+import com.jeesite.modules.mes.service.MesProductRecordService;
 import com.jeesite.modules.mes.service.MesProductSampleRecordService;
 import com.jeesite.modules.mes.service.MesProductSampleService;
 import com.jeesite.modules.mes.service.MesShiftService;
@@ -22,17 +26,20 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.annotation.Rollback;
 import org.springframework.test.context.ActiveProfiles;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 框架气密(OP360 / FrameworkQmScheduling)质量校验联调测试。
+ * 框架气密(OP360 / FrameworkQmScheduling)质量校验与结果提交联调测试。
  * <p>
- * 与定时任务一致:调用 {@link MesProductRecordController#checkQualityCommon},
- * 返回码第 4~5 位为 {@code UD} 视为可进站。
+ * 质量校验:{@link MesProductRecordController#checkQualityCommon},返回码第 4~5 位 {@code UD} 可进站。<br>
+ * 结果提交:与定时任务相同,走 {@link MesProductRecordService#updateRecordResult}(失败可补模板后重试)。
  * <p>
- * 使用方式:填写下方 TEST_SN 后,IDE 中右键运行对应 {@code @Test},或运行 {@code main}。
+ * 使用方式:填写下方 TEST_SN / TEST_RESULT 后,IDE 中右键运行对应 {@code @Test},或运行 {@code main}。
  */
 @ActiveProfiles("test")
 @SpringBootTest(classes = Application.class)
@@ -41,7 +48,10 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 	// ===================== 自行填写 =====================
 
 	/** 待测工件码(必填;普通件 / 样件码均可) */
-	private static final String TEST_SN = "0050010200173E5240017069091B40";
+	private static final String TEST_SN = "0050010200173FAAAB706A232A21";
+
+	/** 提交结果:OK / NG */
+	private static final String TEST_RESULT = "NG";
 
 	/** 产线编号;留空则读 mes.framework.qm.lineSn,再默认 XT */
 	private static final String TEST_LINE_SN = "";
@@ -52,11 +62,13 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 	// ===================== 自行填写结束 =====================
 
 	private static final String DEFAULT_OPRNO = "OP360";
-	private static final String DEFAULT_LINE_SN = "XT";
+	private static final String DEFAULT_LINE_SN = "NG";
 
 	@Autowired
 	private MesProductRecordController mesProductRecordController;
 	@Autowired
+	private MesProductRecordService mesProductRecordService;
+	@Autowired
 	private MesLineProcessService mesLineProcessService;
 	@Autowired
 	private MesProductSampleService mesProductSampleService;
@@ -66,15 +78,29 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 	private MesShiftService mesShiftService;
 
 	/**
-	 * 与 FrameworkQmScheduling#doQualityCheck 相同调用链。
+	 * OP360 质量校验(与 FrameworkQmScheduling#doQualityCheck 相同调用链)。
 	 */
 	@Test
-	public void testFrameworkQmQualityCheck() {
+	public void testOp360QualityCheck() {
 		Assume.assumeTrue("请先填写 TEST_SN", StringUtils.isNotBlank(TEST_SN));
 		runCheck(resolveOprno(), TEST_SN.trim(), resolveLineSn());
 	}
 
 	/**
+	 * OP360 提交工位结果(与 FrameworkQmScheduling 报工逻辑一致;失败时补建模板后二次提交)。
+	 */
+	@Test
+	@Transactional
+	@Rollback(false)
+	public void testOp360SubmitResult() {
+		Assume.assumeTrue("请先填写 TEST_SN", StringUtils.isNotBlank(TEST_SN));
+		Assume.assumeTrue("TEST_RESULT 只能是 OK 或 NG",
+				"OK".equalsIgnoreCase(TEST_RESULT) || "NG".equalsIgnoreCase(TEST_RESULT));
+		boolean ok = runSubmit(resolveOprno(), TEST_SN.trim(), resolveLineSn(), TEST_RESULT.trim().toUpperCase());
+		org.junit.Assert.assertTrue("OP360 提交工位结果失败", ok);
+	}
+
+	/**
 	 * 打印防呆/班次/样件配置诊断,便于排查「配了样件仍放行」。
 	 */
 	@Test
@@ -84,16 +110,23 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 		runCheck(resolveOprno(), TEST_SN.trim(), resolveLineSn());
 	}
 
+	/** @deprecated 请使用 {@link #testOp360QualityCheck()} */
+	@Test
+	public void testFrameworkQmQualityCheck() {
+		testOp360QualityCheck();
+	}
+
 	public static void main(String[] args) {
 		if (StringUtils.isBlank(TEST_SN)) {
 			System.out.println("请先填写 TEST_SN");
 			return;
 		}
-		System.out.println("========== FrameworkQmScheduling 质量校验联调 ==========");
+		System.out.println("========== OP360 质量校验 / 结果提交联调 ==========");
 		ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
 		try {
 			FrameworkQmQualityCheckTest bean = new FrameworkQmQualityCheckTest();
 			bean.mesProductRecordController = ctx.getBean(MesProductRecordController.class);
+			bean.mesProductRecordService = ctx.getBean(MesProductRecordService.class);
 			bean.mesLineProcessService = ctx.getBean(MesLineProcessService.class);
 			bean.mesProductSampleService = ctx.getBean(MesProductSampleService.class);
 			bean.mesProductSampleRecordService = ctx.getBean(MesProductSampleRecordService.class);
@@ -104,14 +137,17 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 			String sn = TEST_SN.trim();
 			bean.printDiagnose(oprno, sn, lineSn);
 			bean.runCheck(oprno, sn, lineSn);
+			String result = StringUtils.isBlank(TEST_RESULT) ? "OK" : TEST_RESULT.trim().toUpperCase();
+			bean.runSubmit(oprno, sn, lineSn, result);
 		} finally {
 			ctx.close();
 		}
 	}
 
+	/** OP360 质量校验 */
 	private void runCheck(String oprno, String sn, String lineSn) {
 		String oldOprno = oprno.length() == 5 ? oprno + "A" : oprno;
-		System.out.println("--- checkQualityCommon ---");
+		System.out.println("--- OP360 checkQualityCommon ---");
 		System.out.println("oprno=" + oprno + " oldOprno=" + oldOprno
 				+ " sn=" + sn + " lineSn=" + lineSn);
 
@@ -130,6 +166,70 @@ public class FrameworkQmQualityCheckTest extends BaseSpringContextTests {
 		System.out.println("(FrameworkQmScheduling 判定:pass == \"UD\".equals(ret.substring(3,5)))");
 	}
 
+	/**
+	 * OP360 提交结果(对齐 FrameworkQmScheduling#submitStationResultWithTemplateRetry)。
+	 * @return true=提交成功
+	 */
+	private boolean runSubmit(String oprno, String sn, String lineSn, String result) {
+		String oldOprno = oprno.length() == 5 ? oprno + "A" : oprno;
+		String fOprno = CommonUitl.formatOprno(oldOprno);
+		System.out.println("--- OP360 updateRecordResult ---");
+		System.out.println("oprno=" + oprno + " oldOprno=" + oldOprno
+				+ " sn=" + sn + " lineSn=" + lineSn + " result=" + result);
+
+		MesProductRecord before = findStationMainResult(sn, fOprno, lineSn);
+		System.out.println("提交前 craft=100000 content="
+				+ (before == null ? "无记录" : before.getContent())
+				+ " oprno=" + (before == null ? "-" : before.getOprno()));
+
+		boolean ok = submitStationResult(oldOprno, sn, lineSn, result);
+		if (!ok) {
+			try {
+				System.out.println("首次提交失败,补建工位模板后二次提交...");
+				mesProductRecordController.ensureOprnoTemplateRecords(sn, oldOprno, lineSn);
+				ok = submitStationResult(oldOprno, sn, lineSn, result);
+			} catch (Exception e) {
+				System.out.println("补建工位模板失败: " + e.getMessage());
+				e.printStackTrace();
+				return false;
+			}
+		}
+
+		MesProductRecord after = findStationMainResult(sn, fOprno, lineSn);
+		System.out.println("提交后 craft=100000 content="
+				+ (after == null ? "无记录" : after.getContent())
+				+ " oprno=" + (after == null ? "-" : after.getOprno())
+				+ " success=" + ok);
+		return ok;
+	}
+
+	private boolean submitStationResult(String oldOprno, String sn, String lineSn, String result) {
+		try {
+			List<ParamsResp> params = new ArrayList<>();
+			List<BindMaterialResp> bmlists = new ArrayList<>();
+			mesProductRecordService.updateRecordResult(sn, oldOprno, "100000", "", result,
+					"", params, lineSn, true, bmlists, null);
+			return true;
+		} catch (Exception e) {
+			System.out.println("updateRecordResult 异常: " + e.getMessage());
+			e.printStackTrace();
+			return false;
+		}
+	}
+
+	private MesProductRecord findStationMainResult(String sn, String oprnoLike, String lineSn) {
+		MesProductRecord query = new MesProductRecord();
+		query.setSn(sn);
+		query.setOprno(oprnoLike);
+		query.setCraft("100000");
+		query.setLineSn(lineSn);
+		List<MesProductRecord> list = mesProductRecordService.findList(query);
+		if (list == null || list.isEmpty()) {
+			return null;
+		}
+		return list.get(0);
+	}
+
 	private void printDiagnose(String oprno, String sn, String lineSn) {
 		String oldOprno = oprno.length() == 5 ? oprno + "A" : oprno;
 		String fOprno = CommonUitl.formatOprno(oldOprno);