|
|
@@ -0,0 +1,278 @@
|
|
|
+package com.jeesite.test;
|
|
|
+
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.common.tests.BaseSpringContextTests;
|
|
|
+import com.jeesite.modules.Application;
|
|
|
+import com.jeesite.modules.mes.web.MesProductRecordController;
|
|
|
+import org.junit.Assume;
|
|
|
+import org.junit.Test;
|
|
|
+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.context.ActiveProfiles;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 涂胶 / FSW 定时任务质量校验联调测试。
|
|
|
+ * <p>
|
|
|
+ * 覆盖以下类的 {@code checkQualityCommon} 调用逻辑,不连接 PLC/Modbus:
|
|
|
+ * <ul>
|
|
|
+ * <li>{@link com.jeesite.modules.scheduling.ProductTjScheduling}(OP220)</li>
|
|
|
+ * <li>{@link com.jeesite.modules.scheduling.ProductTjBScheduling}(mes.tj.b.oprno)</li>
|
|
|
+ * <li>{@link com.jeesite.modules.scheduling.FswModbusScheduling}(mes.fsw.modbus.oprno)</li>
|
|
|
+ * </ul>
|
|
|
+ * <p>
|
|
|
+ * 使用方式:
|
|
|
+ * <ul>
|
|
|
+ * <li>JUnit:填写下方 TEST_SN 后运行 test 方法</li>
|
|
|
+ * <li>main:右键运行 main,需先启动数据库等服务</li>
|
|
|
+ * </ul>
|
|
|
+ */
|
|
|
+@ActiveProfiles("test")
|
|
|
+@SpringBootTest(classes = Application.class)
|
|
|
+public class ProductTjQualityCheckTest extends BaseSpringContextTests {
|
|
|
+
|
|
|
+ // ===================== 自行填写 =====================
|
|
|
+
|
|
|
+ /** 待测工件码(必填) */
|
|
|
+ private static final String TEST_SN = "0050010200173E5240017067171A02";
|
|
|
+
|
|
|
+ /** 产线编号,与 application.yml 中 mes.tj.lineSn / mes.tj.b.lineSn 一致 */
|
|
|
+ private static final String TEST_LINE_SN = "XT";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * B 侧工位号;留空则读取 mes.tj.b.oprno,仍为空时使用 OP240B(与 ProductTjBScheduling 默认一致)
|
|
|
+ */
|
|
|
+ private static final String TJ_B_OPRNO = "";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * FSW 工位号;留空则读取 mes.fsw.modbus.oprno(与 FswModbusScheduling 一致,未配置则校验失败)
|
|
|
+ */
|
|
|
+ private static final String FSW_OPRNO = "OP230";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * FSW 产线编号;留空则读取 mes.fsw.modbus.lineSn,仍为空则使用 TEST_LINE_SN
|
|
|
+ */
|
|
|
+ private static final String FSW_LINE_SN = "XT";
|
|
|
+
|
|
|
+ // ===================== 自行填写结束 =====================
|
|
|
+
|
|
|
+ /** ProductTjScheduling 固定工位号 */
|
|
|
+ private static final String TJ_A_OPRNO = "OP220";
|
|
|
+
|
|
|
+ private static final String DEFAULT_TJ_B_OPRNO = "OP240B";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MesProductRecordController mesProductRecordController;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testProductTjSchedulingQualityCheck() {
|
|
|
+ Assume.assumeTrue("请先在类顶部填写 TEST_SN", StringUtils.isNotBlank(TEST_SN));
|
|
|
+
|
|
|
+ QualityCheckResult result = checkQualityLikeTjScheduling(TEST_SN.trim(), TEST_LINE_SN.trim());
|
|
|
+ printResult("ProductTjScheduling", TJ_A_OPRNO, result);
|
|
|
+
|
|
|
+ org.junit.Assert.assertNotNull(result.ret);
|
|
|
+ org.junit.Assert.assertTrue("返回码长度不足: " + result.ret, result.ret.length() >= 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testProductTjBSchedulingQualityCheck() {
|
|
|
+ Assume.assumeTrue("请先在类顶部填写 TEST_SN", StringUtils.isNotBlank(TEST_SN));
|
|
|
+
|
|
|
+ String oprno = resolveTjBOprno();
|
|
|
+ QualityCheckResult result = checkQualityLikeTjBScheduling(TEST_SN.trim(), TEST_LINE_SN.trim(), oprno);
|
|
|
+ printResult("ProductTjBScheduling", oprno, result);
|
|
|
+
|
|
|
+ org.junit.Assert.assertNotNull(result.ret);
|
|
|
+ org.junit.Assert.assertTrue("返回码长度不足: " + result.ret, result.ret.length() >= 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFswModbusSchedulingQualityCheck() {
|
|
|
+ Assume.assumeTrue("请先在类顶部填写 TEST_SN", StringUtils.isNotBlank(TEST_SN));
|
|
|
+
|
|
|
+ String oprno = resolveFswOprno();
|
|
|
+ Assume.assumeTrue("请配置 mes.fsw.modbus.oprno 或填写 FSW_OPRNO", StringUtils.isNotBlank(oprno));
|
|
|
+
|
|
|
+ String lineSn = resolveFswLineSn();
|
|
|
+ QualityCheckResult result = checkQualityLikeFswModbusScheduling(TEST_SN.trim(), lineSn, oprno);
|
|
|
+ printResult("FswModbusScheduling", oprno, result, lineSn);
|
|
|
+
|
|
|
+ org.junit.Assert.assertNotNull(result.ret);
|
|
|
+ org.junit.Assert.assertTrue("返回码长度不足: " + result.ret, result.ret.length() >= 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动联调:依次执行涂胶 A/B 与 FSW 质量校验。
|
|
|
+ */
|
|
|
+ public static void main(String[] args) {
|
|
|
+ if (StringUtils.isBlank(TEST_SN)) {
|
|
|
+ System.out.println("请先在 ProductTjQualityCheckTest 类顶部填写 TEST_SN 后再运行。");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("========== 涂胶/FSW 质量校验联调(不连 PLC/Modbus)==========");
|
|
|
+ ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
|
|
|
+ try {
|
|
|
+ MesProductRecordController controller = ctx.getBean(MesProductRecordController.class);
|
|
|
+ ProductTjQualityCheckTest tester = new ProductTjQualityCheckTest();
|
|
|
+ tester.mesProductRecordController = controller;
|
|
|
+
|
|
|
+ String sn = TEST_SN.trim();
|
|
|
+ String lineSn = TEST_LINE_SN.trim();
|
|
|
+
|
|
|
+ System.out.println("\n--- ProductTjScheduling (OP220) ---");
|
|
|
+ QualityCheckResult aResult = tester.checkQualityLikeTjScheduling(sn, lineSn);
|
|
|
+ printResult("ProductTjScheduling", TJ_A_OPRNO, aResult, lineSn);
|
|
|
+
|
|
|
+ String bOprno = resolveTjBOprnoStatic();
|
|
|
+ System.out.println("\n--- ProductTjBScheduling (" + bOprno + ") ---");
|
|
|
+ QualityCheckResult bResult = tester.checkQualityLikeTjBScheduling(sn, lineSn, bOprno);
|
|
|
+ printResult("ProductTjBScheduling", bOprno, bResult, lineSn);
|
|
|
+
|
|
|
+ String fswOprno = resolveFswOprnoStatic();
|
|
|
+ if (StringUtils.isBlank(fswOprno)) {
|
|
|
+ System.out.println("\n--- FswModbusScheduling:未配置 mes.fsw.modbus.oprno,跳过 ---");
|
|
|
+ } else {
|
|
|
+ String fswLineSn = resolveFswLineSnStatic();
|
|
|
+ System.out.println("\n--- FswModbusScheduling (" + fswOprno + ") ---");
|
|
|
+ QualityCheckResult fswResult = tester.checkQualityLikeFswModbusScheduling(sn, fswLineSn, fswOprno);
|
|
|
+ printResult("FswModbusScheduling", fswOprno, fswResult, fswLineSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("\n完成。");
|
|
|
+ } finally {
|
|
|
+ ctx.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 与 ProductTjScheduling.doQualityCheck 相同:固定 OP220,校验工位 OP220A。
|
|
|
+ */
|
|
|
+ QualityCheckResult checkQualityLikeTjScheduling(String sn, String lineSn) {
|
|
|
+ String checkOprno = TJ_A_OPRNO + "A";
|
|
|
+ return invokeQualityCheck(checkOprno, sn, lineSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 与 ProductTjBScheduling.doQualityCheck 相同:5 位工位号补 A,6 位及以上原样传入。
|
|
|
+ */
|
|
|
+ QualityCheckResult checkQualityLikeTjBScheduling(String sn, String lineSn, String oprno) {
|
|
|
+ String checkOprno = oprno.length() == 5 ? oprno + "A" : oprno;
|
|
|
+ return invokeQualityCheck(checkOprno, sn, lineSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 与 FswModbusScheduling.doQualityCheck 相同:读 mes.fsw.modbus.oprno,5 位工位号补 A。
|
|
|
+ */
|
|
|
+ QualityCheckResult checkQualityLikeFswModbusScheduling(String sn, String lineSn, String oprno) {
|
|
|
+ if (StringUtils.isBlank(oprno)) {
|
|
|
+ return QualityCheckResult.error(null, "未配置 mes.fsw.modbus.oprno");
|
|
|
+ }
|
|
|
+ String checkOprno = oprno;
|
|
|
+ if (checkOprno.length() == 5) {
|
|
|
+ checkOprno = checkOprno + "A";
|
|
|
+ }
|
|
|
+ return invokeQualityCheck(checkOprno, sn, lineSn);
|
|
|
+ }
|
|
|
+
|
|
|
+ private QualityCheckResult invokeQualityCheck(String checkOprno, String sn, String lineSn) {
|
|
|
+ if (StringUtils.isBlank(lineSn)) {
|
|
|
+ return QualityCheckResult.fail(checkOprno, "产线编号为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String ret = mesProductRecordController.checkQualityCommon(checkOprno, sn, lineSn, "");
|
|
|
+ if (StringUtils.isBlank(ret) || ret.length() < 5) {
|
|
|
+ return QualityCheckResult.fail(checkOprno, ret);
|
|
|
+ }
|
|
|
+ boolean pass = "UD".equals(ret.substring(3, 5));
|
|
|
+ return new QualityCheckResult(checkOprno, ret, pass);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return QualityCheckResult.error(checkOprno, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveTjBOprno() {
|
|
|
+ return resolveTjBOprnoStatic();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String resolveTjBOprnoStatic() {
|
|
|
+ if (StringUtils.isNotBlank(TJ_B_OPRNO)) {
|
|
|
+ return TJ_B_OPRNO.trim();
|
|
|
+ }
|
|
|
+ String oprno = Global.getConfig("mes.tj.b.oprno");
|
|
|
+ return StringUtils.isBlank(oprno) ? DEFAULT_TJ_B_OPRNO : oprno.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveFswOprno() {
|
|
|
+ return resolveFswOprnoStatic();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String resolveFswOprnoStatic() {
|
|
|
+ if (StringUtils.isNotBlank(FSW_OPRNO)) {
|
|
|
+ return FSW_OPRNO.trim();
|
|
|
+ }
|
|
|
+ String oprno = Global.getConfig("mes.fsw.modbus.oprno");
|
|
|
+ return StringUtils.isBlank(oprno) ? null : oprno.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveFswLineSn() {
|
|
|
+ return resolveFswLineSnStatic();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String resolveFswLineSnStatic() {
|
|
|
+ if (StringUtils.isNotBlank(FSW_LINE_SN)) {
|
|
|
+ return FSW_LINE_SN.trim();
|
|
|
+ }
|
|
|
+ String lineSn = Global.getConfig("mes.fsw.modbus.lineSn");
|
|
|
+ if (StringUtils.isNotBlank(lineSn)) {
|
|
|
+ return lineSn.trim();
|
|
|
+ }
|
|
|
+ return StringUtils.isBlank(TEST_LINE_SN) ? null : TEST_LINE_SN.trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printResult(String taskName, String configuredOprno, QualityCheckResult result) {
|
|
|
+ printResult(taskName, configuredOprno, result, TEST_LINE_SN);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void printResult(String taskName, String configuredOprno, QualityCheckResult result, String lineSn) {
|
|
|
+ System.out.println("任务类 : " + taskName);
|
|
|
+ System.out.println("配置工位号 : " + configuredOprno);
|
|
|
+ System.out.println("校验工位号 : " + result.checkOprno);
|
|
|
+ System.out.println("工件码 : " + TEST_SN);
|
|
|
+ System.out.println("产线 : " + lineSn);
|
|
|
+ System.out.println("返回码 : " + result.ret);
|
|
|
+ System.out.println("是否通过 : " + (result.pass ? "是 (UD)" : "否"));
|
|
|
+ if (result.error != null) {
|
|
|
+ System.out.println("异常信息 : " + result.error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final class QualityCheckResult {
|
|
|
+ private final String checkOprno;
|
|
|
+ private final String ret;
|
|
|
+ private final boolean pass;
|
|
|
+ private final String error;
|
|
|
+
|
|
|
+ private QualityCheckResult(String checkOprno, String ret, boolean pass) {
|
|
|
+ this(checkOprno, ret, pass, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private QualityCheckResult(String checkOprno, String ret, boolean pass, String error) {
|
|
|
+ this.checkOprno = checkOprno;
|
|
|
+ this.ret = ret;
|
|
|
+ this.pass = pass;
|
|
|
+ this.error = error;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static QualityCheckResult fail(String checkOprno, String ret) {
|
|
|
+ return new QualityCheckResult(checkOprno, ret, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static QualityCheckResult error(String checkOprno, String error) {
|
|
|
+ return new QualityCheckResult(checkOprno, null, false, error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|