Selaa lähdekoodia

气密泄露点位模块

17491 2 viikkoa sitten
vanhempi
commit
39e7abe8a9

+ 24 - 9
src/com/mes/netty/MesMsgUtils.java

@@ -2,14 +2,15 @@ package com.mes.netty;
 
 public class MesMsgUtils {
 
-    public static int SYNR_LEN = 46;
-    public static int AXTW_LEN = 46;
-    public static int ACLW_LEN = 46;
-    public static int MCJW_LEN = 96;
-    public static int AQDW_LEN = 96;
-    public static int MBDW_LEN = 96;
-    public static int MJBW_LEN = 96;
-    public static int MQDW_LEN = 96;
+    // V2 将工位号扩展为 8 字符;V3 将 AQDW/MQDW 的 LX 扩展为 3 字符。
+    public static int SYNR_LEN = 48;
+    public static int AXTW_LEN = 48;
+    public static int ACLW_LEN = 48;
+    public static int MCJW_LEN = 98;
+    public static int AQDW_LEN = 99;
+    public static int MBDW_LEN = 98;
+    public static int MJBW_LEN = 98;
+    public static int MQDW_LEN = 99;
     public static int MKSW_LEN = 96;
     public static int MSBW_LEN = 96;
     public static int MCSW_LEN = 96;
@@ -50,13 +51,27 @@ public class MesMsgUtils {
                     ret = 2;
                 }
                 break;
-            default:
+            case "AQDW":
                 if(len==AQDW_LEN) {
                     ret = 0;
                 }else {
                     ret = 2;
                 }
                 break;
+            case "MQDW":
+                if(len==MQDW_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
+            default:
+                if(len==MCJW_LEN) {
+                    ret = 0;
+                }else {
+                    ret = 2;
+                }
+                break;
         }
         return ret;
     }

+ 17 - 17
src/com/mes/netty/ProtocolParam.java

@@ -2,9 +2,9 @@ package com.mes.netty;
 
 
 // 固定格式报文各参数获取方法
+// 协议 V3:8 字符工位号;AQDW/MQDW 响应使用 3 字符 LX 字段。
 public class ProtocolParam {
-    // bbbbfffffARWAQDWGWOP100 GY100000ID151245P00000106200123062900001      RSOKDA2023-09-07ZT10:16:58
-    public static Integer fixedLength = 96; // 固定长度
+    public static Integer fixedLength = 99;
 
     // 获取消息类型  所有报文都可使用
     public static String getMsgType(String msg){
@@ -15,59 +15,59 @@ public class ProtocolParam {
         return msg.substring(12,16);
     }
 
-    // 获取工位号
+    // 获取工位号(8 字符)
     public static String getOprno(String msg){
-        if(msg.length() < 24){
+        if(msg.length() < 26){
             return "";
         }
-        return msg.substring(18,24);
+        return msg.substring(18,26);
     }
 
     // 获取工艺号
     public static String getCraft(String msg){
-        if(msg.length() < 32){
+        if(msg.length() < 34){
             return "";
         }
-        return msg.substring(26,32);
+        return msg.substring(28,34);
     }
 
     // 获取镭雕码或设备报警故障代码
     public static String getSn(String msg){
-        if(msg.length() < 70){
+        if(msg.length() < 72){
             return "";
         }
-        return msg.substring(34,70);
+        return msg.substring(36,72);
     }
 
     public static String getLx(String msg){
-        if(msg.length() < 72){
+        if(msg.length() < 75){
             return "";
         }
-        return msg.substring(70,72);
+        return msg.substring(72,75).trim();
     }
 
     // 获取结果
     public static String getResult(String msg){
-        if(msg.length() < 74){
+        if(msg.length() < 77){
             return "";
         }
-        return msg.substring(72,74);
+        return msg.substring(75,77);
     }
 
     // 获取日期
     public static String getDay(String msg){
-        if(msg.length() < 86){
+        if(msg.length() < 89){
             return "";
         }
-        return msg.substring(76,86);
+        return msg.substring(79,89);
     }
 
     // 获取时间
     public static String getTime(String msg){
-        if(msg.length() < 96){
+        if(msg.length() < 99){
             return "";
         }
-        return msg.substring(88,96);
+        return msg.substring(91,99);
     }
 
 }

+ 13 - 5
src/com/mes/netty/XDecoder.java

@@ -135,18 +135,26 @@ public class XDecoder extends ByteToMessageDecoder {
                     tpsize = MesMsgUtils.ACLW_LEN;
                 }
                 break;
-            case "MCJW":
             case "AQDW":
+                if(str.length() >= MesMsgUtils.AQDW_LEN){
+                    tpsize = MesMsgUtils.AQDW_LEN;
+                }
+                break;
+            case "MQDW":
+                if(str.length() >= MesMsgUtils.MQDW_LEN){
+                    tpsize = MesMsgUtils.MQDW_LEN;
+                }
+                break;
+            case "MCJW":
             case "MBDW":
             case "MJBW":
-            case "MQDW":
             case "MKSW":
             case "MSBW":
             case "MCSW":
             case "AQRW":
-            default: // 默认新报文
-                if(str.length() >= ProtocolParam.fixedLength){ // 大于固定长度
-                    tpsize = ProtocolParam.fixedLength;
+            default:
+                if(str.length() >= MesMsgUtils.MCJW_LEN){
+                    tpsize = MesMsgUtils.MCJW_LEN;
                 }
                 break;
         }

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

@@ -25,7 +25,7 @@ public class DataUtil {
             //TCP连接后,直接先发同步报文
             String start = "aaaabbbbbABW";
             String msgType = "SYNR";
-            String gw = "GW"+DataUtil.rightPad(mes_gw, 6);
+            String gw = "GW"+DataUtil.rightPad(mes_gw, 8);
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
             String synr_str = start + msgType + gw + da + zt;
@@ -47,7 +47,7 @@ public class DataUtil {
             //TCP连接后,直接先发同步报文
             String start = "aaaabbbbbABW";
             String msgType = "AXTW";
-            String gw = "GW"+DataUtil.rightPad(mes_gw, 6);
+            String gw = "GW"+DataUtil.rightPad(mes_gw, 8);
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
             String axtw_str = start + msgType + gw + da + zt;
@@ -141,7 +141,7 @@ 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"), 6);
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad("", 2);
@@ -166,7 +166,7 @@ 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"), 6);
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);
@@ -306,12 +306,12 @@ public class DataUtil {
             String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/pcresult";
 
             String params = "__ajax=json"
-                    + "&sn=" + sn
-                    + "&oprno=" + oprno
-                    + "&lineSn=" + lineSn
-                    + "&ldFlag=" + ldFlag
-                    + "&ucode=" + userCode
-                    + "&result=" + result
+                    + "&sn=" + formEncode(sn)
+                    + "&oprno=" + formEncode(oprno)
+                    + "&lineSn=" + formEncode(lineSn)
+                    + "&ldFlag=" + formEncode(ldFlag)
+                    + "&ucode=" + formEncode(userCode)
+                    + "&result=" + formEncode(result)
                     + "&isRepair=" + isRepair
                     + "&craft="
                     + "&remark="
@@ -351,10 +351,10 @@ public class DataUtil {
             String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/pccheck";
 
             String params = "__ajax=json"
-                    + "&sn=" + sn
-                    + "&oprno=" + oprno
-                    + "&lineSn=" + lineSn
-                    + "&ucode=" + userCode
+                    + "&sn=" + formEncode(sn)
+                    + "&oprno=" + formEncode(oprno)
+                    + "&lineSn=" + formEncode(lineSn)
+                    + "&ucode=" + formEncode(userCode)
                     + "&isRepair=" + isRepair;
 
             System.out.println("params=" + params);
@@ -389,10 +389,17 @@ public class DataUtil {
             connection.setReadTimeout(60000);
             connection.setDoOutput(true);
             connection.setDoInput(true);
-            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
-            connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
+            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
+            String requestParam = param == null ? "" : param;
+            if (MesClient.sessionid != null && !MesClient.sessionid.trim().isEmpty()
+                    && !requestParam.contains("__sid=")) {
+                if (!requestParam.isEmpty()) {
+                    requestParam += "&";
+                }
+                requestParam += "__sid=" + URLEncoder.encode(MesClient.sessionid, "UTF-8");
+            }
             os = connection.getOutputStream();
-            os.write(param.getBytes());
+            os.write(requestParam.getBytes("UTF-8"));
             if (connection.getResponseCode() == 200) {
                 is = connection.getInputStream();
                 br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
@@ -435,6 +442,10 @@ public class DataUtil {
         return result;
     }
 
+    private static String formEncode(String value) throws UnsupportedEncodingException {
+        return URLEncoder.encode(value == null ? "" : value, "UTF-8");
+    }
+
     /**
      * 查询工作记录
      * @param oprno 工位号(空则查所有工位)

+ 1 - 1
src/com/mes/ui/LoginFarme.java

@@ -196,7 +196,7 @@ public class LoginFarme extends JFrame {
 //                    }
 
                     if(MesClient.jfxPanel2 == null){
-                        String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+user_id+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn;
+                        String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+user_id+"&oprno="+MesClient.mes_gw+"&lineSn="+MesClient.mes_line_sn+"&__sid="+MesClient.sessionid;
                         MesClient.jfxPanel2 = new MesWebView(url);
                         MesClient.jfxPanel2.setSize(990, 550);
                         MesClient.indexPanelC.add(MesClient.jfxPanel2);

+ 44 - 37
src/com/mes/ui/MesClient.java

@@ -231,7 +231,10 @@ public class MesClient extends JFrame {
         shiftUserCheck();
         // 重置漏点按钮状态
         closeWeldButton();
-        startRepairButton();
+        closeRepairButton();
+        btnNormal.setBackground(null);
+        btnRepair.setBackground(null);
+        isRepair = 0;
 
         // 重置时自动跳转回第一个标签页 (索引0)
         if (tabbedPane != null) {
@@ -306,10 +309,6 @@ public class MesClient extends JFrame {
         //弹窗扫工件码
         String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
         if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
-            //获取用户
-            getUser();
-            //获取扫码内容36位
-            String barcode36 = getBarcode(scanBarcode);//处理36为码
             //工位号
             String gw = "";
             switch(scan_type) {
@@ -326,28 +325,9 @@ public class MesClient extends JFrame {
 //                return;
 //            }
 
-            // 查询工件质量
-            JSONObject retObj = DataUtil.pcCheck(barcode36,user20,isRepair);
-            if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
-                //模仿报文检查成功逻辑
-                MesClient.status_menu.setForeground(Color.GREEN);
-                MesClient.check_quality_result = true;//质量合格,可以绑定加工
-                MesClient.status_menu.setText("该工件可以加工");
-                MesClient.work_status = 1;
-                MesClient.f_scan_data_bt_1.setEnabled(false);
-                MesClient.finish_ok_bt.setEnabled(true);
-                MesClient.finish_ng_bt.setEnabled(true);
-                MesClient.startWeldButton();
-                MesClient.closeRepairButton();
-            }else{
-                if(retObj.get("result")==null){
-                    MesClient.setMenuStatus("请求失败,请重试",-1);
-                }else{
-                    if(retObj.get("result").toString().equalsIgnoreCase("false")){
-                        MesClient.setMenuStatus(retObj.getString("message"),-1);
-                    }
-                }
-            }
+            MesClient.f_scan_data_bt_1.setEnabled(false);
+            MesClient.startRepairButton();
+            MesClient.setMenuStatus("请选择正常检查或返修检查", 0);
 
         }else {
             MesClient.setMenuStatus("请扫工件码,请重试",-1);
@@ -356,6 +336,37 @@ public class MesClient extends JFrame {
         }
     }
 
+    private static void startInspection(int repairMode) {
+        String barcode = product_sn.getText();
+        if (barcode == null || barcode.trim().isEmpty()) {
+            setMenuStatus("请先扫工件码", -1);
+            return;
+        }
+
+        getUser();
+        JSONObject retObj = DataUtil.pcCheck(barcode, user20, repairMode);
+        if (retObj == null || retObj.get("result") == null) {
+            setMenuStatus("请求失败,请重试", -1);
+            return;
+        }
+        if (!retObj.get("result").toString().equalsIgnoreCase("true")) {
+            setMenuStatus(retObj.getString("message"), -1);
+            return;
+        }
+
+        isRepair = repairMode;
+        btnNormal.setBackground(repairMode == 0 ? Color.GREEN : null);
+        btnRepair.setBackground(repairMode == 1 ? Color.GREEN : null);
+        fxlabel.setVisible(repairMode == 1);
+        check_quality_result = true;
+        work_status = 1;
+        finish_ok_bt.setEnabled(true);
+        finish_ng_bt.setEnabled(true);
+        startWeldButton();
+        closeRepairButton();
+        setMenuStatus("该工件可以加工", 0);
+    }
+
     public static void logoff() {
         welcomeWin.setVisible(true);
         mesClientFrame.setVisible(false);
@@ -551,14 +562,10 @@ public class MesClient extends JFrame {
         btnRepair.setEnabled(false);
 
         btnNormal.addActionListener(e -> {
-            btnNormal.setBackground(Color.GREEN);
-            btnRepair.setBackground(null);
-            isRepair = 0;
+            startInspection(0);
         });
         btnRepair.addActionListener(e -> {
-            btnRepair.setBackground(Color.GREEN);
-            btnNormal.setBackground(null);
-            isRepair = 1;
+            startInspection(1);
         });
 
         modeRow.add(btnNormal);
@@ -677,8 +684,8 @@ public class MesClient extends JFrame {
         finish_ok_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 if(work_status == 1 && check_quality_result){
-                    String sn = getBarcode(product_sn.getText());
-                    if(sn.isEmpty()){
+                    String sn = product_sn.getText();
+                    if(sn == null || sn.trim().isEmpty()){
                         MesClient.setMenuStatus("工件码为空,请重试",-1);
                         return;
                     }
@@ -713,8 +720,8 @@ public class MesClient extends JFrame {
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 if(work_status == 1 && check_quality_result){
-                    String sn = getBarcode(product_sn.getText());
-                    if(sn.isEmpty()){
+                    String sn = product_sn.getText();
+                    if(sn == null || sn.trim().isEmpty()){
                         MesClient.setMenuStatus("工件码为空,请重试",-1);
                         return;
                     }

+ 18 - 2
src/com/mes/util/ErrorMsg.java

@@ -11,9 +11,9 @@ public class ErrorMsg {
             }else if(processMsgRet.equalsIgnoreCase("NN")) {
                 lmsg = "该工件跳过该工位";
             }else if(processMsgRet.equalsIgnoreCase("QN")) {
-                lmsg = "该工件OP"+ lx+"0加工NG";
+                lmsg = "该工件"+ getOprnoName(lx)+"加工NG";
             }else if(processMsgRet.equalsIgnoreCase("QD")) {
-                lmsg = "该工件OP"+ lx+"0未加工";
+                lmsg = "该工件"+ getOprnoName(lx)+"未加工";
             }else if(processMsgRet.equalsIgnoreCase("NF")) {
                 lmsg = "该工件已合格下线";
             }else if(processMsgRet.equalsIgnoreCase("NR")) {
@@ -46,4 +46,20 @@ public class ErrorMsg {
         }catch (Exception e){ }
         return lmsg;
     }
+
+    private static String getOprnoName(String lx) {
+        if (lx == null) {
+            return "OP";
+        }
+        lx = lx.trim();
+        if (lx.startsWith("I")) {
+            try {
+                int num = Integer.parseInt(lx.substring(1)) * 10;
+                return String.format("INSP%03d", num);
+            } catch (Exception e) {
+                return "INSP" + lx.substring(1);
+            }
+        }
+        return "OP" + lx + "0";
+    }
 }