|
|
@@ -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);
|