Quellcode durchsuchen

支持 INSPXXX 质量校验结果显示

wangxichen vor 1 Tag
Ursprung
Commit
a7f4abc292

+ 21 - 1
src/main/java/com/jeesite/modules/mes/web/MesProductRecordController.java

@@ -2178,7 +2178,7 @@ public class MesProductRecordController extends BaseController {
 		}
 
 			if(!StringUtils.isEmpty(op)){
-				bs = op.substring(2,4);
+				bs = buildQualityLx(op);
 			}
 
 			ret = bs+lxres;
@@ -2199,6 +2199,26 @@ public class MesProductRecordController extends BaseController {
 	//上传质量结果
 	//msg=aaaabbbbbABWMQDWGWOP040 GY100000ID151245P00000106200123062900001      RSOKDA2023-08-18ZT14:32:33YHjinjushijinjushi1111
 	//msg=aaaabbbbbABWMQDWGWOP080 GY100000LX  ID151245P00000106200123062900001      RSOKDA2023-08-18ZT14:32:33YHjinjushijinjushi111105Y11111111N22222222Y33333333Y44444444Y55555555
+
+	private String buildQualityLx(String oprno) {
+		if (StringUtils.isEmpty(oprno)) {
+			return "RS";
+		}
+		String code = CommonUitl.formatOprno(oprno).trim();
+		try {
+			if (code.startsWith("INSP")) {
+				int num = Integer.parseInt(code.substring(4));
+				return "I" + (num / 10);
+			}
+			if (code.startsWith("OP")) {
+				int num = Integer.parseInt(code.substring(2));
+				return String.format("%02d", num / 10);
+			}
+		} catch (Exception e) {
+			logger.warn("format quality lx failed, oprno={}", oprno, e);
+		}
+		return code.length() > 2 ? code.substring(0, 2) : code;
+	}
 	private String updateQuality(String msg){
 		String ret = "";
 		String oprno = ProtocolParam.getOprno(msg).trim();

+ 32 - 2
src/main/java/com/jeesite/modules/utils/MesMsgUtils.java

@@ -427,10 +427,10 @@ public class MesMsgUtils {
 		String mes_rs = "    ";
 		if(!ret.equalsIgnoreCase("")) {
 			//保存成功
-			mes_rs = ret;//"RSOK";
+			mes_rs = isQualityResultMsg(reMsgType) ? formatReturnResult(ret) : ret;//"RSOK";
 		}else {
 			//未保存成功
-			mes_rs = mes_lx+"NS";
+			mes_rs = isQualityResultMsg(reMsgType) ? formatReturnResult(mes_lx+"NS") : mes_lx+"NS";
 		}
 		String da = "DA" + DateLocalUtils.getCurrentDate();
 		String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
@@ -461,6 +461,36 @@ public class MesMsgUtils {
 		return start + msgType + mes_gw + mes_gy + mes_id + mes_rs + da + zt;
 	}
 
+
+
+	private static boolean isQualityResultMsg(String msgType) {
+		return "AQDW".equalsIgnoreCase(msgType) || "MQDW".equalsIgnoreCase(msgType);
+	}
+	private static String formatReturnResult(String ret) {
+		if (ret == null) {
+			ret = "";
+		}
+		ret = ret.trim();
+		if (ret.length() < 2) {
+			return rightPad("RS", 3) + rightPad(ret, 2);
+		}
+		String result = ret.substring(ret.length() - 2);
+		String lx = ret.substring(0, ret.length() - 2).trim();
+		if (lx.length() == 0) {
+			lx = "RS";
+		}
+		return rightPad(lx, 3) + rightPad(result, 2);
+	}
+
+	private static String rightPad(String str, int size) {
+		if (str == null) {
+			str = "";
+		}
+		if (str.length() > size) {
+			return str.substring(0, size);
+		}
+		return String.format("%-" + size + "s", str);
+	}
 	private static String productRecordPost(String msg,String channel_ip,String msg_type){
 //		msg = msg.replaceAll("_", " ");
 		int lastIndex = msg.lastIndexOf("_");