Ver código fonte

fix: 工位号统一以 mes_db 的 ConfigParam.oprno 为准
问题:jar 内 config.properties 的 mes.gw 与 mes_db 里 ConfigParam.oprno
可能不一致,导致 TCP 报文(SYNR/AXTW/AQDW)用 properties 工位号,
UI 显示和结果上传用 ConfigParam 工位号,服务端按错工位校验,
返回 QD "该工件 INSPxxx 未加工"。

改动:
- MesClient.readProperty 尾部读 mes_db 的 ConfigParam.oprno,
非空则覆盖 mes_gw 静态字段,下游 SYNR/AXTW/HTTP userAuth/
开班点检/ClientRuntimeAgent 心跳 stationCode 全部跟随
- DataUtil.sendMessage / sendQuality 拼报文时通过 resolveGw
优先取 ConfigParam.oprno,properties 保底,作为双保险

wangxichen 1 dia atrás
pai
commit
69cbd5b96c
2 arquivos alterados com 30 adições e 2 exclusões
  1. 17 2
      src/com/mes/ui/DataUtil.java
  2. 13 0
      src/com/mes/ui/MesClient.java

+ 17 - 2
src/com/mes/ui/DataUtil.java

@@ -132,7 +132,8 @@ public class DataUtil {
             Properties pro = new Properties();
             BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
             pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
+            // 与 sendMessage 保持一致,工位号优先取本地 ConfigParam
+            String gw = "GW"+rightPad(resolveGw(pro), 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);
@@ -158,7 +159,8 @@ public class DataUtil {
             Properties pro = new Properties();
             BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
             pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
+            // 工位号优先取本地 ConfigParam(UI 保存到 mes_db),回落到 jar 内 properties
+            String gw = "GW"+rightPad(resolveGw(pro), 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);
@@ -177,6 +179,19 @@ public class DataUtil {
         }
     }
 
+    // 工位号取值:优先本地 ConfigParam(UI 保存到 mes_db),回落 jar 内 properties
+    private static String resolveGw(Properties pro){
+        try{
+            if(MesClient.configParam != null){
+                String op = MesClient.configParam.getOprno();
+                if(op != null && !op.trim().isEmpty()){
+                    return op.trim();
+                }
+            }
+        }catch(Exception ignore){}
+        return pro.getProperty("mes.gw");
+    }
+
     public static String rightPad(final String str, final int size) {
         if (str == null) {
             return null;

+ 13 - 0
src/com/mes/ui/MesClient.java

@@ -214,6 +214,19 @@ public class MesClient extends JFrame {
         mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
         mes_line_sn = pro.getProperty("mes.line_sn");
 
+        // 若 mes_db 里 ConfigParam.oprno 有值,则覆盖 jar 内 properties 默认值
+        // 确保 SYNR/AXTW/AQDW/HTTP/心跳 全用同一工位号,避免会话错乱
+        try {
+            JdbcUtils.getConn();
+            ConfigParam cp = JdbcUtils.getConfig();
+            if (cp != null && cp.getOprno() != null && !cp.getOprno().trim().isEmpty()) {
+                mes_gw = cp.getOprno().trim();
+                log.info("工位号已被本地 ConfigParam 覆盖: " + mes_gw);
+            }
+        } catch (Exception e) {
+            log.warn("读取本地 ConfigParam 失败, 继续使用 properties 工位号: " + e.getMessage());
+        }
+
         mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
 
         log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);