Forráskód Böngészése

修改,不走质量,本地计件,扫码启动设备

wangxichen 4 napja
szülő
commit
1ced823091

+ 1 - 24
src/com/mes/netty/NettyClientHandler.java

@@ -1,8 +1,6 @@
 package com.mes.netty;
 
 import com.mes.ui.MesClient;
-import com.mes.ui.MesRevice;
-import com.mes.util.HttpUtils;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -49,28 +47,7 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter {
         String processMsgRet = MesMsgUtils.processMsg(mes_msg, msg_type);
         log.info("| TCP返回报文结果: {}", processMsgRet);
         log.info("==============================================================================");
-        switch(msg_type) {
-            case "AQDW": // 查询质量
-                MesRevice.checkQualityRevice(processMsgRet,mes_msg);
-                break;
-            case "MKSW":
-                MesRevice.startRevice(processMsgRet,mes_msg);
-                break;
-            case "MBDW":
-                MesRevice.bindRevice(processMsgRet,mes_msg);
-                break;
-            case "MJBW":
-                MesRevice.unbindRevice(processMsgRet,mes_msg);
-                break;
-            case "VLDW":
-                MesRevice.validateColdPlateRevice(processMsgRet,mes_msg);
-                break;
-            case "MQDW":
-                MesRevice.updateResultRevice(processMsgRet,mes_msg);
-                break;
-        }
-
-
+        // 只保留同步/心跳,业务报文(质量查询、工位结果)已去掉,无需回调处理
     }
 
     @Override

+ 0 - 122
src/com/mes/ui/DataUtil.java

@@ -101,128 +101,6 @@ public class DataUtil {
         }
     }
 
-    public static Boolean checkQuality(NettyClient nettyClient, String sn, String user, String mes_gw){
-        try{
-            String msgType = "AQDW";
-            String gy = "100000";
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","", mes_gw);
-            return aqdw_str;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean startWork(NettyClient nettyClient,String sn,String user, String mes_gw){
-        try{
-            String msgType = "MKSW";
-            String gy = "";
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","", mes_gw);
-            return aqdw_str;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean bindUser(NettyClient nettyClient,String sn,String user, String mes_gw){
-        try{
-            String msgType = "MBDW";
-            String gy = "400001";
-            String param = rightPad(user, 36);
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"01",param, mes_gw);
-            return aqdw_str;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean bindWarehouse(NettyClient nettyClient,String sn,String wsn,String user,String craft, String mes_gw){
-        try{
-            String msgType = "MBDW";
-            String param = rightPad(wsn, 36);
-            String gwWithoutSuffix = mes_gw.replaceAll("[A-Z]$", "");
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,craft,"",sn,"",user,"01",param, gwWithoutSuffix);
-            return aqdw_str;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean validateColdPlate(NettyClient nettyClient,String sn,String wsn,String user,String craft, String mes_gw){
-        try{
-            String msgType = "VLDW"; // 校验消息类型
-            String param = rightPad(wsn, 36);
-            Boolean validation_result = sendMessage(nettyClient,msgType,craft,"",sn,"",user,"01",param, mes_gw);
-            return validation_result;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean unBindWarehouse(NettyClient nettyClient,String sn,String wsn,String user,String craft, String mes_gw){
-        try{
-            String msgType = "MJBW";
-            String param = rightPad(wsn, 36);
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,craft,"",sn,"",user,"01",param, mes_gw);
-            return aqdw_str;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean sendQuality(NettyClient nettyClient,String sn,String result,String user, String mes_gw){
-        try{
-            String msgType = "MQDW";
-            String craft = "100000";
-            String lx = "";
-            String paramNums = "00";
-            String params = "";
-
-            String gw = "GW"+rightPad(mes_gw, 6);
-            String start = "aaaabbbbbABW";
-            String gy = "GY" + rightPad(craft, 6);
-            String reslx = "LX" + rightPad(lx, 2);
-            String id = Config.line_sn + rightPad(sn, 36);
-            String rs = "RS"+ rightPad(result, 2);
-            String da = "DA" + DateLocalUtils.getCurrentDate();
-            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
-            String yh = "YH" + rightPad(user, 20);
-            String aqdw_str = start + msgType + gw + gy + reslx + id + rs + da + zt + yh + paramNums + params;
-            log.info("向submit_record表中插入更新质量报文: {}", aqdw_str);
-            JdbcUtils.insertData(gw, gy, aqdw_str, msgType, sn);
-            JdbcUtils.insertSubmitRecord(gw, sn, aqdw_str);
-            nettyClient.future.channel().writeAndFlush(aqdw_str);
-            return true;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
-    public static Boolean bindLeakValue(String sn, String leakValue, String gw) {
-        return sendMessage(MesClient.nettyClient, "MBDW", "300001", "",
-                sn, "", MesClient.user20, "01", rightPad(leakValue, 36), gw);
-    }
-
-    public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params, String mes_gw){
-        try{
-            String gw = "GW"+rightPad(mes_gw, 6);
-            String start = "aaaabbbbbABW";
-            String gy = "GY" + rightPad(craft, 6);
-            String reslx = "LX" + rightPad(lx, 2);
-            String id = Config.line_sn + rightPad(sn, 36);
-            String rs = "RS"+ rightPad(result, 2);
-            String da = "DA" + DateLocalUtils.getCurrentDate();
-            String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
-            String yh = "YH" + rightPad(user, 20);
-            String aqdw_str = start + msgType + gw + gy + reslx + id + rs + da + zt + yh + paramNums + params;
-            log.info("向服务端发送TCP报文: {}", aqdw_str);
-            JdbcUtils.insertData(gw, gy, aqdw_str, msgType, sn);
-            nettyClient.future.channel().writeAndFlush(aqdw_str);
-            return true;
-        }catch (Exception e){
-            return false;
-        }
-    }
-
     public static String rightPad(final String str, final int size) {
         if (str == null) {
             return null;

+ 5 - 16
src/com/mes/ui/LoginFrame.java

@@ -1,7 +1,6 @@
 package com.mes.ui;
 
 import com.alibaba.fastjson2.JSONObject;
-import com.mes.component.MesWebView;
 import com.mes.util.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -24,7 +23,7 @@ public class LoginFrame extends JFrame {
     static JButton scanLoginButton = new JButton("扫  码  登  录");
 
     public LoginFrame() {
-        setTitle("MES系统客户端:OP150" + " - " + Config.gw_des_1);
+        setTitle("MES系统客户端:OP245" + " - " + Config.gw_des_1);
 
         ImageIcon bg = new ImageIcon(Objects.requireNonNull(MesClient.class.getResource("/background.png")));
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -164,20 +163,10 @@ public class LoginFrame extends JFrame {
                     MesClient.mesClientFrame.setVisible(true);
                     MesClient.getUser();
 
-
-                    String url1 = "http://" + Config.server_ip + ":8980/js/a/mes/mesProductRecord/work?" + "oprno=OP150" + "&lineSn=" + Config.line_sn;
-                    MesWebView jfxPanel = new MesWebView(url1);
-                    jfxPanel.setSize(990, 550);
-                    MesClient.indexPanelB.add(jfxPanel);
-
-
-                    String url2 = "http://" + Config.server_ip + ":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode=" + user_id + "&oprno=OP150" + "&lineSn=" + Config.line_sn;
-                    MesWebView jfxPanel2 = new MesWebView(url2);
-                    jfxPanel2.setSize(990, 550);
-                    MesClient.indexPanelC.add(jfxPanel2);
-
-
-
+                    // 工作记录改为本地计件,登录后刷新一次
+                    if (MesClient.workRecordPanel != null) {
+                        MesClient.workRecordPanel.reload();
+                    }
 
                     MesClient.initWarehouseData();
 //                    UpdateQualityTimer.start();  // 开启更新质量的定时任务

+ 57 - 359
src/com/mes/ui/MesClient.java

@@ -10,7 +10,6 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
 import com.google.zxing.common.BitMatrix;
 import com.google.zxing.qrcode.QRCodeWriter;
 import com.mes.component.MesRadio;
-import com.mes.component.MesWebView;
 import com.mes.netty.NettyClient;
 import com.mes.util.*;
 import org.slf4j.Logger;
@@ -43,33 +42,12 @@ public class MesClient extends JFrame {
     public static String sessionid = "";
     public static NettyClient nettyClient;
 
-    public static Boolean check_quality_result1 = false;
     public static Integer work_status1 = 0;
-    public static Boolean check_quality_result2 = false;
     public static Integer work_status2 = 0;
     
     public static Boolean isSubmitting1 = false; // 150A是否正在提交结果到MES
     public static Boolean isSubmitting2 = false; // 150B是否正在提交结果到MES
 
-    // 工位1冷板相关变量
-    public static JTextField product_sn_lb_1;  // 冷板码输入框
-    public static JButton f_scan_data_bt_lb_1;  // 扫冷板码按钮
-    public static JButton btnUnbindLb_1;  // 解绑按钮
-    public static boolean coldPlateValidated_1 = false;  // 冷板是否校验通过
-    public static String coldPlateCode_1 = "";  // 存储冷板码
-    public static boolean bindLbStatus_1 = false;  // 冷板绑定状态
-    public static boolean scan_status_1 = false;  // 是否已扫码,防止重复扫码
-
-    // 工位2冷板相关变量
-    public static JTextField product_sn_lb_2;  // 冷板码输入框
-    public static JButton f_scan_data_bt_lb_2;  // 扫冷板码按钮
-    public static JButton btnUnbindLb_2;  // 解绑按钮
-    public static boolean coldPlateValidated_2 = false;  // 冷板是否校验通过
-    public static String coldPlateCode_2 = "";  // 存储冷板码
-    public static boolean bindLbStatus_2 = false;  // 冷板绑定状态
-    public static boolean scan_status_2 = false;  // 是否已扫码,防止重复扫码
-
-
     public static JButton finish_ok_bt_1;
     public static JButton finish_ng_bt_1;
     public static JTextField product_sn_1;
@@ -91,18 +69,13 @@ public class MesClient extends JFrame {
     public static MesClient mesClientFrame;
     public static JTabbedPane tabbedPane;
     public static JScrollPane indexScrollPaneA;
-    public static JScrollPane searchScrollPane;
-    public static JScrollPane searchScrollPaneDj;
 
 
 
     public static JButton heart_beat_menu;
     public static JButton user_menu;
     public static JFrame welcomeWin;
-    public static JPanel indexPanelB;
-    public static MesWebView jfxPanel = null;
-    public static JPanel indexPanelC;
-    public static MesWebView jfxPanel2 = null;
+    public static WorkRecordPanel workRecordPanel;   // 本地工作记录面板
     public static MesRadio mesRadioHj;
     public static JTable table;
     public static Object[] columnNames = {"物料名称", "绑定批次", "剩余次数", "操作"};
@@ -422,8 +395,6 @@ public class MesClient extends JFrame {
         MesClient.finish_ng_bt_1.setEnabled(false);
         MesClient.f_scan_data_bt_1.setEnabled(true);
         work_status1 = 0;
-        check_quality_result1 = false;
-        scan_status_1 = false;
         
         //停止心跳,设备将自动停止
         heartBeatFlag = false;
@@ -431,14 +402,6 @@ public class MesClient extends JFrame {
         log.info("resetScanA 清空工件码");
         product_sn_1.setText("");
 
-        // 重置冷板相关状态
-        bindLbStatus_1 = false;
-        coldPlateValidated_1 = false;
-        coldPlateCode_1 = "";
-        product_sn_lb_1.setText("");
-        f_scan_data_bt_lb_1.setEnabled(false);
-        btnUnbindLb_1.setEnabled(false);
-
         // 重置拉铆数量
         MesClient.aMax = 0;
         MesClient.aFinish = 0;
@@ -470,8 +433,6 @@ public class MesClient extends JFrame {
         MesClient.finish_ng_bt_2.setEnabled(false);
         MesClient.f_scan_data_bt_2.setEnabled(true);
         work_status2 = 0;
-        check_quality_result2 = false;
-        scan_status_2 = false;
         
         //停止心跳,设备将自动停止
         heartBeatFlag2 = false;
@@ -479,14 +440,6 @@ public class MesClient extends JFrame {
         log.info("resetScanB 清空工件码");
         product_sn_2.setText("");
 
-        // 重置冷板相关状态
-        bindLbStatus_2 = false;
-        coldPlateValidated_2 = false;
-        coldPlateCode_2 = "";
-        product_sn_lb_2.setText("");
-        f_scan_data_bt_lb_2.setEnabled(false);
-        btnUnbindLb_2.setEnabled(false);
-
         // 重置拉铆数量
         MesClient.bMax = 0;
         MesClient.bFinish = 0;
@@ -593,26 +546,6 @@ public class MesClient extends JFrame {
         return sb.toString();
     }
 
-    // 校验冷板码是否以任一允许的前缀开头
-    private static boolean matchColdplatePrefix(String barcode) {
-        for (String prefix : Config.coldplate_prefix) {
-            if (barcode.startsWith(prefix.trim())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    // 拼接所有允许的冷板前缀,用于错误提示
-    private static String coldplatePrefixHint() {
-        StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < Config.coldplate_prefix.length; i++) {
-            if (i > 0) sb.append("/");
-            sb.append(Config.coldplate_prefix[i].trim());
-        }
-        return sb.toString();
-    }
-
     public static void scanBarcode1() {
         if (work_status1 == 1) {
             JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
@@ -642,16 +575,8 @@ public class MesClient extends JFrame {
             //刷新界面
             mesClientFrame.repaint();
 
-            if (!tcp_connect_flag) {
-                JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                return;
-            }
-
-            // 查询工件质量
-            Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_1);
-            if (!sendret) {
-                JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
-            }
+            // 不做MES质量检查,前缀校验通过即启动
+            startWorkA(scanBarcode.trim());
         } else {
             JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
         }
@@ -686,19 +611,55 @@ public class MesClient extends JFrame {
             //刷新界面
             mesClientFrame.repaint();
 
-            if (!tcp_connect_flag) {
-                JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
-                return;
+            // 不做MES质量检查,前缀校验通过即启动
+            startWorkB(scanBarcode.trim());
+        } else {
+            JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+        }
+    }
+
+    // 工位1开工:不做MES质量检查,扫码通过前缀校验即启动设备
+    public static void startWorkA(String barcode) {
+        if (work_status1 != 0) {
+            return;
+        }
+        getUser();
+        work_status1 = 1;
+        f_scan_data_bt_1.setEnabled(false);
+
+        // 给PLC地址8写1并启动心跳,设备可以运行
+        try {
+            if (plcA != null) {
+                plcA.writeInt16(8, (short) 1);
+                log.info("A工位扫码完成,向地址8写入1,读取验证值:" + plcA.readInt16(8));
             }
+        } catch (Exception e) {
+            log.error("A工位向地址8写入1失败:" + e.getMessage());
+        }
+        heartBeatFlag = true;
+        setMenuState_1("设备已启动,拉铆中", 0);
+    }
 
-            // 查询工件质量
-            Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_2);
-            if (!sendret) {
-                JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+    // 工位2开工
+    public static void startWorkB(String barcode) {
+        if (work_status2 != 0) {
+            return;
+        }
+        getUser();
+        work_status2 = 1;
+        f_scan_data_bt_2.setEnabled(false);
+
+        // 给PLC地址8写1并启动心跳,设备可以运行
+        try {
+            if (plcB != null) {
+                plcB.writeInt16(8, (short) 1);
+                log.info("B工位扫码完成,向地址8写入1,读取验证值:" + plcB.readInt16(8));
             }
-        } else {
-            JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+        } catch (Exception e) {
+            log.error("B工位向地址8写入1失败:" + e.getMessage());
         }
+        heartBeatFlag2 = true;
+        setMenuState_2("设备已启动,拉铆中", 0);
     }
 
     public static void logoff() {
@@ -738,7 +699,7 @@ public class MesClient extends JFrame {
 
     public MesClient() {
         setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
-        setTitle("MES系统客户端:OP150- " + Config.gw_des_1);
+        setTitle("MES系统客户端:OP245- " + Config.gw_des_1);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setBounds(0, 0, 1024, 768);
 
@@ -1066,7 +1027,7 @@ public class MesClient extends JFrame {
         status_menu_1.setBounds(100, 38, 369, 53);
         indexPanelA.add(status_menu_1);
 
-        JLabel state_label_1 = new JLabel("OP150A");
+        JLabel state_label_1 = new JLabel("OP245A");
         state_label_1.setHorizontalAlignment(SwingConstants.LEFT);
         state_label_1.setForeground(Color.BLACK);
         state_label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
@@ -1113,61 +1074,6 @@ public class MesClient extends JFrame {
         param2.setColumns(10);
 //8.30//
 
-        // 工位1冷板相关UI
-        JLabel lbLabel_1 = new JLabel("冷板码:");
-        lbLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        lbLabel_1.setBounds(10, 185, 70, 50);
-        indexPanelA.add(lbLabel_1);
-        
-        product_sn_lb_1 = new JTextField();
-        product_sn_lb_1.setHorizontalAlignment(SwingConstants.CENTER);
-        product_sn_lb_1.setEditable(false);
-        product_sn_lb_1.setFont(new Font("微软雅黑", Font.PLAIN, 18));
-        product_sn_lb_1.setBounds(73, 185, 277, 50);
-        indexPanelA.add(product_sn_lb_1);
-        product_sn_lb_1.setColumns(10);
-
-        f_scan_data_bt_lb_1 = new JButton("");//扫码
-        f_scan_data_bt_lb_1.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                if (!scan_status_1){
-                    setMenuState_1("请在工件上料完成后扫码!",1);
-                    return;
-                }
-                if (work_status1 == 1 && check_quality_result1){
-                    scanBarcodeLb1();
-                }else{
-                    setMenuState_1("请在工件质量检测合格后扫码!",1);
-                }
-            }
-        });
-        f_scan_data_bt_lb_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
-        f_scan_data_bt_lb_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
-        f_scan_data_bt_lb_1.setBounds(348, 185, 70, 50);
-        f_scan_data_bt_lb_1.setEnabled(false);
-        indexPanelA.add(f_scan_data_bt_lb_1);
-
-        btnUnbindLb_1 = new JButton("");//解绑
-        btnUnbindLb_1.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                // 检查是否有冷板码需要处理
-                if (!coldPlateValidated_1 && coldPlateCode_1.isEmpty()){
-                    setMenuState_1("没有冷板码需要清除!",1);
-                    return;
-                }
-                // 直接重置冷板相关的所有状态
-                // 停止心跳,拉铆枪停止工作
-                heartBeatFlag = false;
-                resetlb1();
-                setMenuState_1("冷板状态已重置,拉铆枪已停止",0);
-            }
-        });
-        btnUnbindLb_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
-        btnUnbindLb_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
-        btnUnbindLb_1.setBounds(420, 185, 70, 50);
-        btnUnbindLb_1.setEnabled(false);
-        indexPanelA.add(btnUnbindLb_1);
-
         // 工位2
 
         //8.30
@@ -1202,61 +1108,6 @@ public class MesClient extends JFrame {
         param4.setColumns(10);
 //8.30//
 
-        // 工位2冷板相关UI
-        JLabel lbLabel_2 = new JLabel("冷板码:");
-        lbLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
-        lbLabel_2.setBounds(502, 185, 70, 50);
-        indexPanelA.add(lbLabel_2);
-        
-        product_sn_lb_2 = new JTextField();
-        product_sn_lb_2.setHorizontalAlignment(SwingConstants.CENTER);
-        product_sn_lb_2.setEditable(false);
-        product_sn_lb_2.setFont(new Font("微软雅黑", Font.PLAIN, 18));
-        product_sn_lb_2.setBounds(565, 185, 287, 50);
-        indexPanelA.add(product_sn_lb_2);
-        product_sn_lb_2.setColumns(10);
-
-        f_scan_data_bt_lb_2 = new JButton("");//扫码
-        f_scan_data_bt_lb_2.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                if (!scan_status_2){
-                    setMenuState_2("请在工件上料完成后扫码!",1);
-                    return;
-                }
-                if (work_status2 == 1 && check_quality_result2){
-                    scanBarcodeLb2();
-                }else{
-                    setMenuState_2("请在工件质量检测合格后扫码!",1);
-                }
-            }
-        });
-        f_scan_data_bt_lb_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
-        f_scan_data_bt_lb_2.setFont(new Font("微软雅黑", Font.PLAIN, 24));
-        f_scan_data_bt_lb_2.setBounds(850, 185, 70, 50);
-        f_scan_data_bt_lb_2.setEnabled(false);
-        indexPanelA.add(f_scan_data_bt_lb_2);
-
-        btnUnbindLb_2 = new JButton("");//解绑
-        btnUnbindLb_2.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                // 检查是否有冷板码需要处理
-                if (!coldPlateValidated_2 && coldPlateCode_2.isEmpty()){
-                    setMenuState_2("没有冷板码需要清除!",1);
-                    return;
-                }
-                // 直接重置冷板相关的所有状态
-                // 停止心跳,拉铆枪停止工作
-                heartBeatFlag2 = false;
-                resetlb2();
-                setMenuState_2("冷板状态已重置,拉铆枪已停止",0);
-            }
-        });
-        btnUnbindLb_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
-        btnUnbindLb_2.setFont(new Font("微软雅黑", Font.PLAIN, 24));
-        btnUnbindLb_2.setBounds(922, 185, 70, 50);
-        btnUnbindLb_2.setEnabled(false);
-        indexPanelA.add(btnUnbindLb_2);
-
         product_sn_2 = new JTextField();
         product_sn_2.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn_2.setEditable(false);
@@ -1312,7 +1163,7 @@ public class MesClient extends JFrame {
         status_menu_2.setBounds(597, 38, 369, 53);
         indexPanelA.add(status_menu_2);
 
-        JLabel state_label_2 = new JLabel("OP150B");
+        JLabel state_label_2 = new JLabel("OP245B");
         state_label_2.setHorizontalAlignment(SwingConstants.LEFT);
         state_label_2.setForeground(Color.BLACK);
         state_label_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
@@ -1333,27 +1184,17 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
 
-        indexPanelC = new JPanel();
-        searchScrollPaneDj = new JScrollPane(indexPanelC);
-        indexPanelC.setLayout(null);
-        tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
-
-        indexPanelB = new JPanel();
-        searchScrollPane = new JScrollPane(indexPanelB);
-        indexPanelB.setLayout(null);
-        tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
-
-
-
-
+        // 工作记录改为读本地SQLite,不再加载MES网页
+        workRecordPanel = new WorkRecordPanel();
+        tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), workRecordPanel, null);
 
         tabbedPane.addChangeListener(new ChangeListener() {
             @Override
             public void stateChanged(ChangeEvent e) {
                 JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
-                int selectedIndex = tabbedPane.getSelectedIndex();
-                if (selectedIndex == 1) {
-
+                // 切到工作记录页时刷新本地数据
+                if (tabbedPane.getSelectedComponent() == workRecordPanel && workRecordPanel != null) {
+                    workRecordPanel.reload();
                 }
             }
         });
@@ -1473,147 +1314,4 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
     }
 
-    // 工位1扫冷板码
-    public static void scanBarcodeLb1() {
-        String scanBarcodeTitle = "";
-        product_sn_lb_1.setText("");
-        scanBarcodeTitle = "请扫冷板码";
-        
-        //弹窗扫工件码
-        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
-        log.info("工位1冷板码=" + scanBarcode);
-        
-        if(scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
-            // 校验冷板码前缀
-            if(!matchColdplatePrefix(scanBarcode)) {
-                setMenuState_1("冷板前缀错误,必须以" + coldplatePrefixHint() + "开头", 1);
-                product_sn_lb_1.setText("");
-                // 前缀错误,自动重新弹出扫码框
-                scanBarcodeLb1();
-                return;
-            }
-            
-            //获取用户
-            getUser();
-            //获取扫码内容36位
-            String barcode36 = getBarcode(scanBarcode);//处理36为码
-            product_sn_lb_1.setText(scanBarcode);
-
-            //刷新界面
-            mesClientFrame.repaint();
-
-            if(!scanBarcode.isEmpty()) {
-                if(tcp_connect_flag) {
-                    // 发送冷板校验请求到服务端
-                    String warehouseSn = getBarcode(product_sn_lb_1.getText());
-                    String sn = getBarcode(product_sn_1.getText());
-                    getUser();
-                    
-                    // 保存冷板码,等待服务端校验结果
-                    coldPlateCode_1 = scanBarcode;
-                    setMenuState_1("正在校验冷板...", 0);
-                    
-                    // 调用服务端校验冷板绑定状态
-                    Boolean sendResult = DataUtil.validateColdPlate(nettyClient, sn, warehouseSn, user20, "400004", Config.gw_1);
-                    if(!sendResult) {
-                        setMenuState_1("校验请求发送失败,请重试", 1);
-                        coldPlateCode_1 = "";
-                        return;
-                    }
-                }else{
-                    setMenuState_1("设备未连接Mes服务器",1);
-                    return;
-                }
-            }else {
-                setMenuState_1("冷板码为空,请重新扫码",1);
-                return;
-            }
-        }else {
-            setMenuState_1("冷板码为空,请重新扫码",1);
-            return;
-        }
-    }
-
-    // 工位2扫冷板码
-    public static void scanBarcodeLb2() {
-        String scanBarcodeTitle = "";
-        product_sn_lb_2.setText("");
-        scanBarcodeTitle = "请扫冷板码";
-        
-        //弹窗扫工件码
-        String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
-        log.info("工位2冷板码=" + scanBarcode);
-        
-        if(scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) {
-            // 校验冷板码前缀
-            if(!matchColdplatePrefix(scanBarcode)) {
-                setMenuState_2("冷板前缀错误,必须以" + coldplatePrefixHint() + "开头", 1);
-                product_sn_lb_2.setText("");
-                // 前缀错误,自动重新弹出扫码框
-                scanBarcodeLb2();
-                return;
-            }
-            
-            //获取用户
-            getUser();
-            //获取扫码内容36位
-            String barcode36 = getBarcode(scanBarcode);//处理36为码
-            product_sn_lb_2.setText(scanBarcode);
-
-            //刷新界面
-            mesClientFrame.repaint();
-
-            if(!scanBarcode.isEmpty()) {
-                if(tcp_connect_flag) {
-                    // 发送冷板校验请求到服务端
-                    String warehouseSn = getBarcode(product_sn_lb_2.getText());
-                    String sn = getBarcode(product_sn_2.getText());
-                    getUser();
-                    
-                    // 保存冷板码,等待服务端校验结果
-                    coldPlateCode_2 = scanBarcode;
-                    setMenuState_2("正在校验冷板...", 0);
-                    
-                    // 调用服务端校验冷板绑定状态
-                    Boolean sendResult = DataUtil.validateColdPlate(nettyClient, sn, warehouseSn, user20, "400004", Config.gw_2);
-                    if(!sendResult) {
-                        setMenuState_2("校验请求发送失败,请重试", 1);
-                        coldPlateCode_2 = "";
-                        return;
-                    }
-                }else{
-                    setMenuState_2("设备未连接Mes服务器",1);
-                    return;
-                }
-            }else {
-                setMenuState_2("冷板码为空,请重新扫码",1);
-                return;
-            }
-        }else {
-            setMenuState_2("冷板码为空,请重新扫码",1);
-            return;
-        }
-    }
-
-    // 工位1重置冷板
-    public static void resetlb1() {
-        product_sn_lb_1.setText("");
-        f_scan_data_bt_lb_1.setEnabled(true);
-        btnUnbindLb_1.setEnabled(false);
-        bindLbStatus_1 = false;
-        coldPlateValidated_1 = false;
-        coldPlateCode_1 = "";
-        heartBeatFlag = false; // 停止心跳,设备将自动停止
-    }
-
-    // 工位2重置冷板
-    public static void resetlb2() {
-        product_sn_lb_2.setText("");
-        f_scan_data_bt_lb_2.setEnabled(true);
-        btnUnbindLb_2.setEnabled(false);
-        bindLbStatus_2 = false;
-        coldPlateValidated_2 = false;
-        coldPlateCode_2 = "";
-        heartBeatFlag2 = false; // 停止心跳,设备将自动停止
-    }
 }

+ 0 - 261
src/com/mes/ui/MesRevice.java

@@ -1,261 +0,0 @@
-package com.mes.ui;
-
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
-import com.mes.netty.ProtocolParam;
-import com.mes.util.Config;
-import com.mes.util.ErrorMsg;
-import com.mes.util.HttpUtils;
-import com.mes.util.ModbusUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MesRevice {
-    private static final Logger log = LoggerFactory.getLogger(MesRevice.class);
-
-    // 质量查询
-    public static void checkQualityRevice(String processMsgRet,String mes_msg){
-        try{
-            String oprno = ProtocolParam.getOprno(mes_msg).trim();
-            if (Config.gw_1.equalsIgnoreCase(oprno)) {
-                if(processMsgRet.equalsIgnoreCase("UD")) {
-                    MesClient.check_quality_result1 = true;  //质量合格,可以绑定加工
-                    MesClient.setMenuState_1("该工件可以加工", 0);
-                    if(MesClient.work_status1 == 0 ){
-                        String barcode = MesClient.getBarcode(MesClient.product_sn_1.getText());//处理36为码
-                        DataUtil.startWork(MesClient.nettyClient, barcode,MesClient.user20, Config.gw_1);
-
-                    MesClient.work_status1 = 1;
-                    MesClient.f_scan_data_bt_1.setEnabled(false);
-                    // 启用扫冷板码按钮
-                    MesClient.f_scan_data_bt_lb_1.setEnabled(true);
-                    // 扫码状态可以扫码防止重复扫码
-                    MesClient.scan_status_1 = true;
-                    // 注释掉:质量检测合格时不启动心跳,改为冷板校验通过时启动
-                    // MesClient.heartBeatFlag = true;
-                    
-                    // MES扫码成功合格后,给PLC地址8写1
-                        try {
-                            if (MesClient.plcA != null) {
-                                MesClient.plcA.writeInt16(8, (short) 1);
-                                log.info("A工位MES扫码合格,向地址8写入1");
-                                // 读取验证写入是否成功
-                                Short readValue8 = MesClient.plcA.readInt16(8);
-                                log.info("A工位地址8读取验证值:" + readValue8);
-                            }
-                        } catch (Exception e) {
-                            log.error("A工位向地址8写入1失败:" + e.getMessage());
-                        }
-                        
-                        // 工件码合格后自动弹出冷板码扫码框
-                        MesClient.scanBarcodeLb1();
-                    }
-                }else {
-                    MesClient.check_quality_result1 = false;
-                    String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
-                    if("QD".equals(processMsgRet) && "20".equals(ProtocolParam.getLx(mes_msg))){
-                        JSONObject json = new JSONObject().fluentPut("sn", MesClient.product_sn_1.getText().trim());
-                        String response = HttpUtils.sendJsonPost(String.format("http://%s:8980/js/a/mes/mesProductRecord/checkOP200State", Config.server_ip), json.toJSONString(), 2000);
-                        JSONObject jsonObject = JSON.parseObject(response);
-                        log.info("{}检查OP200状态接口响应: {}", Config.gw_1, response);
-                        if (jsonObject != null && jsonObject.getBoolean("result")) {
-                            lmsg = "恒温静置还有" + jsonObject.getInteger("data") + "分钟";
-                        }
-                    }
-                    MesClient.setMenuState_1(lmsg,-1);
-                }
-            } else if(Config.gw_2.equalsIgnoreCase(oprno)){
-                if(processMsgRet.equalsIgnoreCase("UD")) {
-                    MesClient.check_quality_result2 = true;  //质量合格,可以绑定加工
-                    MesClient.setMenuState_2("该工件可以加工", 0);
-                    if(MesClient.work_status2 == 0 ){
-                        String barcode = MesClient.getBarcode(MesClient.product_sn_2.getText());//处理36为码
-                        DataUtil.startWork(MesClient.nettyClient, barcode,MesClient.user20, Config.gw_2);
-
-                    MesClient.work_status2 = 1;
-                    MesClient.f_scan_data_bt_2.setEnabled(false);
-                    // 启用扫冷板码按钮
-                    MesClient.f_scan_data_bt_lb_2.setEnabled(true);
-                    // 扫码状态可以扫码防止重复扫码
-                    MesClient.scan_status_2 = true;
-                    // 注释掉:质量检测合格时不启动心跳,改为冷板校验通过时启动
-                    // MesClient.heartBeatFlag2 = true;
-                    
-                    // MES扫码成功合格后,给PLC地址8写1
-                        try {
-                            if (MesClient.plcB != null) {
-                                MesClient.plcB.writeInt16(8, (short) 1);
-                                log.info("B工位MES扫码合格,向地址8写入1");
-                                // 读取验证写入是否成功
-                                Short readValue8 = MesClient.plcB.readInt16(8);
-                                log.info("B工位地址8读取验证值:" + readValue8);
-                            }
-                        } catch (Exception e) {
-                            log.error("B工位向地址8写入1失败:" + e.getMessage());
-                        }
-                        
-                        // 工件码合格后自动弹出冷板码扫码框
-                        MesClient.scanBarcodeLb2();
-                    }
-                }else {
-                    MesClient.check_quality_result2 = false;
-                    String lmsg = ErrorMsg.getErrorMsg(processMsgRet, ProtocolParam.getLx(mes_msg));
-                    if("QD".equals(processMsgRet) && "20".equals(ProtocolParam.getLx(mes_msg))){
-                        JSONObject json = new JSONObject().fluentPut("sn", MesClient.product_sn_2.getText().trim());
-                        String response = HttpUtils.sendJsonPost(String.format("http://%s:8980/js/a/mes/mesProductRecord/checkOP200State", Config.server_ip), json.toJSONString(), 2000);
-                        JSONObject jsonObject = JSON.parseObject(response);
-                        log.info("{}检查OP200状态接口响应: {}", Config.gw_2, response);
-                        if (jsonObject != null && jsonObject.getBoolean("result")) {
-                            lmsg = "恒温静置还有" + jsonObject.getInteger("data") + "分钟";
-                        }
-                    }
-                    MesClient.setMenuState_2(lmsg,-1);
-                }
-            }
-        }catch (Exception e){
-            log.error("质量查询报文回调出现错误", e);
-        }
-    }
-
-    // 开始回复处理
-    public static void startRevice(String processMsgRet,String mes_msg){
-//        try{
-//            String oprno = ProtocolParam.getOprno(mes_msg).trim();
-//            if (Config.gw_1.equalsIgnoreCase(oprno)) {
-//                if(processMsgRet.equalsIgnoreCase("OK")) {
-//                    MesClient.work_status1 = 1;
-//                    MesClient.f_scan_data_bt_1.setEnabled(false);
-////                    MesClient.finish_ok_bt_1.setEnabled(true);
-////                    MesClient.finish_ng_bt_1.setEnabled(true);
-//
-//
-//                }
-//            } else if(Config.gw_2.equalsIgnoreCase(oprno)){
-//                if(processMsgRet.equalsIgnoreCase("OK")) {
-//                    MesClient.work_status2 = 1;
-//                    MesClient.f_scan_data_bt_2.setEnabled(false);
-////                    MesClient.finish_ok_bt_2.setEnabled(true);
-////                    MesClient.finish_ng_bt_2.setEnabled(true);
-//
-//
-//                }
-//            }
-//        }catch (Exception e){
-//            e.printStackTrace();
-//        }
-    }
-
-    // 绑定
-    public static void bindRevice(String processMsgRet,String mes_msg){
-        try{
-            if(processMsgRet.equalsIgnoreCase("OK")) {
-
-            }else{
-
-            }
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
-
-    // 解绑
-    public static void unbindRevice(String processMsgRet,String mes_msg){
-        try{
-            if(processMsgRet.equalsIgnoreCase("OK")) {
-
-            }else{
-
-            }
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
-
-    // 上传质量
-    public static void updateResultRevice(String processMsgRet,String mes_msg){
-        try{
-            String oprno = ProtocolParam.getOprno(mes_msg).trim();
-            if(processMsgRet.equalsIgnoreCase("OK")) {
-                if (Config.gw_1.equalsIgnoreCase(oprno)) {
-                    MesClient.isSubmitting1 = false;
-                    MesClient.resetScanA();
-                    MesClient.setMenuState_1("结果提交成功,请扫下一件",0);
-                    // 自动提交成功后弹出工件码扫码框
-                    MesClient.scanBarcode1();
-                } else if(Config.gw_2.equalsIgnoreCase(oprno)){
-                    MesClient.isSubmitting2 = false;
-                    MesClient.resetScanB();
-                    MesClient.setMenuState_2("结果提交成功,请扫下一件",0);
-                    // 自动提交成功后弹出工件码扫码框
-                    MesClient.scanBarcode2();
-                }
-            }else{
-                if (Config.gw_1.equalsIgnoreCase(oprno)) {
-                    MesClient.isSubmitting1 = false;
-                    MesClient.setMenuState_1("结果提交失败,请重试",-1);
-                } else if(Config.gw_2.equalsIgnoreCase(oprno)){
-                    MesClient.isSubmitting2 = false;
-                    MesClient.setMenuState_2("结果提交失败,请重试",-1);
-                }
-            }
-        }catch (Exception e){
-            e.printStackTrace();
-        }
-    }
-
-    // 冷板校验响应处理
-    public static void validateColdPlateRevice(String processMsgRet,String mes_msg){
-        try{
-            String oprno = ProtocolParam.getOprno(mes_msg).trim();
-            // 从完整消息中提取结果码(2位)
-            String resultCode = ProtocolParam.getResult(mes_msg);
-            log.info("冷板校验结果码: " + resultCode + ", 工位: " + oprno);
-            
-            if (Config.gw_1.equalsIgnoreCase(oprno)) {
-                // 工位1的冷板校验
-                if(resultCode.equalsIgnoreCase("OK")) {
-                    // 校验通过,设置状态等待拉铆
-                    MesClient.coldPlateValidated_1 = true;
-                    MesClient.f_scan_data_bt_lb_1.setEnabled(false); // 禁用扫码按钮
-                    MesClient.btnUnbindLb_1.setEnabled(true); // 启用解绑按钮
-                    // 冷板校验通过后启动拉铆枪心跳
-                    MesClient.heartBeatFlag = true;
-                    log.info("工位A:冷板校验通过,启动拉铆枪心跳");
-                    MesClient.setMenuState_1("冷板校验通过,拉铆枪已启动", 0);
-                }else{
-                    // 校验失败,清空状态
-                    MesClient.coldPlateValidated_1 = false;
-                    MesClient.coldPlateCode_1 = "";
-                    MesClient.product_sn_lb_1.setText(""); // 清空冷板码显示
-                    String lmsg = ErrorMsg.getErrorMsg(resultCode, ProtocolParam.getLx(mes_msg));
-                    MesClient.setMenuState_1(lmsg, 1);
-                    // 校验失败后自动弹出扫码框重新扫描
-                    MesClient.scanBarcodeLb1();
-                }
-            } else if(Config.gw_2.equalsIgnoreCase(oprno)){
-                // 工位2的冷板校验
-                if(resultCode.equalsIgnoreCase("OK")) {
-                    // 校验通过,设置状态等待拉铆
-                    MesClient.coldPlateValidated_2 = true;
-                    MesClient.f_scan_data_bt_lb_2.setEnabled(false); // 禁用扫码按钮
-                    MesClient.btnUnbindLb_2.setEnabled(true); // 启用解绑按钮
-                    // 冷板校验通过后启动拉铆枪心跳
-                    MesClient.heartBeatFlag2 = true;
-                    log.info("工位B:冷板校验通过,启动拉铆枪心跳");
-                    MesClient.setMenuState_2("冷板校验通过,拉铆枪已启动", 0);
-                }else{
-                    // 校验失败,清空状态
-                    MesClient.coldPlateValidated_2 = false;
-                    MesClient.coldPlateCode_2 = "";
-                    MesClient.product_sn_lb_2.setText(""); // 清空冷板码显示
-                    String lmsg = ErrorMsg.getErrorMsg(resultCode, ProtocolParam.getLx(mes_msg));
-                    MesClient.setMenuState_2(lmsg, 1);
-                    // 校验失败后自动弹出扫码框重新扫描
-                    MesClient.scanBarcodeLb2();
-                }
-            }
-        }catch (Exception e){
-            log.error("冷板校验响应处理异常", e);
-        }
-    }
-}

+ 2 - 2
src/com/mes/ui/OprnoUtil.java

@@ -8,7 +8,7 @@ public class OprnoUtil {
     public static String[] xtoprnos = new String[]{
             "OP040","OP050","OP060","OP070","OP080","OP090","OP100",
             "OP110","OP120","OP130","OP140","OP150","OP170","OP190",
-            "OP200","OP210","OP220","OP230","OP240","OP250","OP260",
+            "OP200","OP210","OP220","OP230","OP240","OP245","OP250","OP260",
             "OP270","OP280","OP290","OP300","OP310","OP320","OP340",
             "OP350","OP360","OP370","OP370","OP380","OP390","OP400","OP410","OP420"
     };
@@ -16,7 +16,7 @@ public class OprnoUtil {
             "镭雕二维码","前边梁压铆,单部件拉铆","框架CMT焊接","人工补焊",
             "焊道检查","焊道打磨","","框架气密","框架反面CNC加工+去毛刺","框架反面,吹铝屑+清洁",
             "框架涂胶","液冷板安装+水冷板点焊","液冷板FSW","匙孔补焊+匙孔补焊打磨",
-            "总成正面CNC+去毛刺","总成正面,吹铝屑+清洁","总成正面装配","套筒涂胶","封堵片焊接",
+            "总成正面CNC+去毛刺","总成正面,吹铝屑+清洁","总成正面装配","套筒涂胶","中吊点拉铆","封堵片焊接",
             "左右边梁封堵","半成品气密","VHB胶带粘贴+冷板泡棉粘贴","冷板背面涂胶",
             "底护板清洗","安装底护板","成品气密","液冷板气密","总成检具检验","箱体封堵",
             "总成清洁","粘贴云母片","CCD","终检","GP12正面","后梁底涂镭雕","GP12反面","包装"

+ 4 - 24
src/com/mes/ui/SettingDialog.java

@@ -17,7 +17,6 @@ public class SettingDialog extends JDialog {
     private static final Logger log = LoggerFactory.getLogger(SettingDialog.class);
 
     private JTextField prefixField;
-    private JTextField coldplatePrefixField;
     private boolean saved = false;
 
     public SettingDialog(Frame owner) {
@@ -26,7 +25,7 @@ public class SettingDialog extends JDialog {
     }
 
     private void initUI() {
-        setSize(500, 260);
+        setSize(500, 200);
         setLocationRelativeTo(getOwner());
         setResizable(false);
 
@@ -35,7 +34,7 @@ public class SettingDialog extends JDialog {
         mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
 
         // 中间面板 - 配置项
-        JPanel centerPanel = new JPanel(new GridLayout(2, 2, 10, 10));
+        JPanel centerPanel = new JPanel(new GridLayout(1, 2, 10, 10));
 
         JLabel prefixLabel = new JLabel("工件前缀(用逗号分隔):");
         prefixLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
@@ -47,15 +46,6 @@ public class SettingDialog extends JDialog {
         prefixField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
         centerPanel.add(prefixField);
 
-        JLabel coldplatePrefixLabel = new JLabel("冷板前缀(用逗号分隔):");
-        coldplatePrefixLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        centerPanel.add(coldplatePrefixLabel);
-
-        String currentColdplatePrefix = String.join(",", Config.coldplate_prefix);
-        coldplatePrefixField = new JTextField(currentColdplatePrefix);
-        coldplatePrefixField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        centerPanel.add(coldplatePrefixField);
-
         mainPanel.add(centerPanel, BorderLayout.CENTER);
 
         // 底部按钮面板
@@ -86,17 +76,8 @@ public class SettingDialog extends JDialog {
             return;
         }
 
-        String coldplatePrefix = coldplatePrefixField.getText().trim();
-        if (coldplatePrefix.isEmpty()) {
-            JOptionPane.showMessageDialog(this,
-                "冷板前缀不能为空",
-                "输入错误",
-                JOptionPane.ERROR_MESSAGE);
-            return;
-        }
-
         // 验证格式
-        if (!checkPrefixFormat(prefix, "工件") || !checkPrefixFormat(coldplatePrefix, "冷板")) {
+        if (!checkPrefixFormat(prefix, "工件")) {
             return;
         }
 
@@ -106,7 +87,6 @@ public class SettingDialog extends JDialog {
 
             // 更新配置
             prop.setProperty("mes.workpiece_prefix", prefix);
-            prop.setProperty("mes.coldplate_prefix", coldplatePrefix);
 
             // 写入jar同级的外部配置文件
             File configFile = Config.getExternalConfigFile();
@@ -125,7 +105,7 @@ public class SettingDialog extends JDialog {
                 "保存成功",
                 JOptionPane.INFORMATION_MESSAGE);
 
-            log.info("前缀配置已更新: 工件={}, 冷板={}", prefix, coldplatePrefix);
+            log.info("前缀配置已更新: 工件={}", prefix);
             dispose();
 
         } catch (Exception ex) {

+ 0 - 2
src/com/mes/util/Config.java

@@ -28,7 +28,6 @@ public class Config {
     public static final Integer heart_icon_cycle = 1;
     public static final Boolean plc_timeout_enabled;
     public static final String[] workpiece_prefix;
-    public static final String[] coldplate_prefix;
 
 
 
@@ -89,7 +88,6 @@ public class Config {
         heart_beat_cycle = Integer.parseInt(prop.getProperty("mes.heart_beat_cycle"));
         plc_timeout_enabled = Boolean.parseBoolean(prop.getProperty("mes.plc_timeout_enabled"));
         workpiece_prefix = prop.getProperty("mes.workpiece_prefix", "KA99").split(",");
-        coldplate_prefix = prop.getProperty("mes.coldplate_prefix", "KB004").split(",");
 
 
     }

+ 178 - 1
src/com/mes/util/JdbcUtils.java

@@ -76,6 +76,22 @@ public class JdbcUtils {
 				")";
 		statement.executeUpdate(bwProdTable);
 
+		// 创建 本地工作记录表(计件用)
+		String workRecordTable = "CREATE TABLE if not exists work_record(\n" +
+				"   id INTEGER PRIMARY KEY AUTOINCREMENT, -- 自增ID\n" +
+				"   gw VARCHAR(20),                       -- 工位号\n" +
+				"   sn VARCHAR(48),                       -- 工件码\n" +
+				"   set_num INTEGER,                      -- 预设数量\n" +
+				"   finish_num INTEGER,                   -- 合格数量\n" +
+				"   result VARCHAR(4),                    -- 结果 OK/NG\n" +
+				"   ucode VARCHAR(100),                   -- 操作工\n" +
+				"   record_time DATETIME                  -- 完成时间\n" +
+				")";
+		statement.executeUpdate(workRecordTable);
+		// 工件码查重 + 时间范围查询用
+		statement.executeUpdate("CREATE INDEX if not exists idx_work_record_sn on work_record(sn)");
+		statement.executeUpdate("CREATE INDEX if not exists idx_work_record_time on work_record(record_time)");
+
 //		QMParamsDAO.createTable();
 
         log.info("表创建成功!");
@@ -220,8 +236,169 @@ public class JdbcUtils {
 		return ret;
 	}
 
-	// 向 qm_params表 插入数据
+	// 该工件码是否已有本地工作记录(用于计件防重)
+	public static boolean existsWorkRecord(String sn) {
+		String v = trimText(sn);
+		if (v.isEmpty()) {
+			return false;
+		}
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement(
+					"select 1 from work_record where trim(sn) = ? limit 1");
+			ps.setString(1, v);
+			ResultSet rs = ps.executeQuery();
+			boolean exists = rs.next();
+			rs.close();
+			ps.close();
+			return exists;
+		} catch (SQLException e) {
+			// 查不出来就当没记过,宁可多记一条也不能漏计件
+			log.error("查询工件码是否已计件失败: " + e.getMessage());
+			return false;
+		}
+	}
+
+	// 工件拉铆完成后写一条本地工作记录(计件),同一工件码只记一次
+	public static boolean insertWorkRecord(String gw, String sn,
+										   int setNum, int finishNum, String result, String ucode) {
+		if (existsWorkRecord(sn)) {
+			log.info("工件码已有本地工作记录,跳过计件: {}", sn);
+			return false;
+		}
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement(
+					"insert into work_record (gw,sn,set_num,finish_num,result,ucode,record_time)"
+							+ " values (?,?,?,?,?,?,?)");
+			ps.setString(1, trimText(gw));
+			ps.setString(2, trimText(sn));
+			ps.setInt(3, setNum);
+			ps.setInt(4, finishNum);
+			ps.setString(5, trimText(result));
+			ps.setString(6, trimText(ucode));
+			ps.setString(7, DateLocalUtils.getCurrentTime());
+			ps.executeUpdate();
+			ps.close();
+			log.info("本地工作记录已写入: gw={} sn={} result={}", gw, sn, result);
+			return true;
+		} catch (SQLException e) {
+			log.error("写入本地工作记录失败: " + e.getMessage());
+			return false;
+		}
+	}
+
+	/**
+	 * 查询本地工作记录明细(按时间范围)
+	 * @param from 开始时间,支持 yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss,为空不限
+	 * @param to 结束时间,同上,为空不限
+	 * @param limit 最多返回条数
+	 * @return 行数据:工件码/结果/完成时间
+	 */
+	public static List<Object[]> getWorkRecords(String from, String to, int limit) {
+		List<Object[]> rows = new ArrayList<>();
+		String begin = normalizeFrom(from);
+		String end = normalizeTo(to);
+		String sql = "select sn,result,record_time from work_record"
+				+ buildTimeWhere(begin, end)
+				+ " order by id desc limit ?";
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement(sql);
+			int idx = bindTimeRange(ps, begin, end);
+			ps.setInt(idx, limit);
+			ResultSet rs = ps.executeQuery();
+			while (rs.next()) {
+				rows.add(new Object[]{
+						trimText(rs.getString(1)),
+						trimText(rs.getString(2)),
+						trimText(rs.getString(3))
+				});
+			}
+			rs.close();
+			ps.close();
+		} catch (SQLException e) {
+			log.error("查询本地工作记录失败: " + e.getMessage());
+		}
+		return rows;
+	}
+
+	/**
+	 * 按工位统计时间范围内的计件数
+	 * @return [工位, 总数, OK数] 列表
+	 */
+	public static List<Object[]> countWorkRecords(String from, String to) {
+		List<Object[]> rows = new ArrayList<>();
+		String begin = normalizeFrom(from);
+		String end = normalizeTo(to);
+		String sql = "select gw, count(1), sum(case when result = 'OK' then 1 else 0 end) from work_record"
+				+ buildTimeWhere(begin, end)
+				+ " group by gw order by gw";
+		try {
+			if (conn == null || conn.isClosed()) {
+				getConn();
+			}
+			PreparedStatement ps = conn.prepareStatement(sql);
+			bindTimeRange(ps, begin, end);
+			ResultSet rs = ps.executeQuery();
+			while (rs.next()) {
+				rows.add(new Object[]{trimText(rs.getString(1)), rs.getInt(2), rs.getInt(3)});
+			}
+			rs.close();
+			ps.close();
+		} catch (SQLException e) {
+			log.error("统计本地计件失败: " + e.getMessage());
+		}
+		return rows;
+	}
+
+	// record_time 是 yyyy-MM-dd HH:mm:ss 文本,字典序即时间序,直接用字符串比较
+	private static String buildTimeWhere(String begin, String end) {
+		if (!begin.isEmpty() && !end.isEmpty()) {
+			return " where record_time between ? and ?";
+		}
+		if (!begin.isEmpty()) {
+			return " where record_time >= ?";
+		}
+		if (!end.isEmpty()) {
+			return " where record_time <= ?";
+		}
+		return "";
+	}
 
+	// 返回下一个可用的占位符下标
+	private static int bindTimeRange(PreparedStatement ps, String begin, String end) throws SQLException {
+		int idx = 1;
+		if (!begin.isEmpty()) {
+			ps.setString(idx++, begin);
+		}
+		if (!end.isEmpty()) {
+			ps.setString(idx++, end);
+		}
+		return idx;
+	}
+
+	// 只填日期时补全为当天起点
+	private static String normalizeFrom(String s) {
+		String v = trimText(s);
+		return v.length() == 10 ? v + " 00:00:00" : v;
+	}
+
+	// 只填日期时补全为当天终点
+	private static String normalizeTo(String s) {
+		String v = trimText(s);
+		return v.length() == 10 ? v + " 23:59:59" : v;
+	}
+
+	private static String trimText(String s) {
+		return s == null ? "" : s.trim();
+	}
 
 	public static void close(){
 		log.info("SQLite数据库连接关闭!");

+ 76 - 165
src/com/mes/util/ModbusUtil.java

@@ -1,7 +1,6 @@
 package com.mes.util;
 
 import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
-import com.mes.ui.DataUtil;
 import com.mes.ui.MesClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,10 +45,6 @@ public class ModbusUtil {
                 log.info("从PLC读取预设数量:" + MesClient.aMax);
             }
 
-            // if(MesClient.sortA >0 ){
-            //     MesClient.btnUnbindLb_1.setEnabled(false);
-            // }
-
             if(MesClient.sortA < cur){
                 MesClient.sortA = cur;
                 MesClient.aFinish = plc.readInt16(68);//合格数量
@@ -100,10 +95,6 @@ public class ModbusUtil {
                 log.info("从PLC读取B预设数量:" + MesClient.bMax);
             }
 
-            // if(MesClient.sortB >0 ){
-            //     MesClient.btnUnbindLb_2.setEnabled(false);
-            // }
-
             if(MesClient.sortB < cur){
                 MesClient.sortB = cur;
                 MesClient.bFinish = plc.readInt16(68);//合格数量
@@ -133,167 +124,87 @@ public class ModbusUtil {
         }
     }
 
-    // 上传总结果
-    public static String upResultA(){
-        String retf = "NG";
-        // 降低日志频率:只在状态变化时打印,避免每500ms打两行
-        log.debug("冷板校验状态:"+MesClient.coldPlateValidated_1);
-        log.debug("冷板绑定状态:"+MesClient.bindLbStatus_1);
-        
-        // 检查自动提交条件:工件码不为空 && 预设数量>0 && 已打数量>=预设数量 && 冷板已校验
-        if(!MesClient.product_sn_1.getText().isEmpty() && MesClient.aMax > 0 && MesClient.aMax <= MesClient.sortA && MesClient.coldPlateValidated_1){
-            
-            // 如果冷板还未绑定到数据库,先进行绑定
-            if(!MesClient.bindLbStatus_1 && !MesClient.coldPlateCode_1.isEmpty()){
-                MesClient.setMenuState_1("正在绑定冷板",0);
-                String warehouseSn = MesClient.getBarcode(MesClient.coldPlateCode_1);
-                String sn = MesClient.getBarcode(MesClient.product_sn_1.getText());
-                MesClient.getUser();
-                Boolean bindResult = DataUtil.bindWarehouse(MesClient.nettyClient, sn, warehouseSn, MesClient.user20, "400004", Config.gw_1);
-
-                if(bindResult) {
-                    MesClient.bindLbStatus_1 = true;
-                    MesClient.setMenuState_1("冷板绑定成功",0);
-                } else {
-                    MesClient.setMenuState_1("冷板绑定失败,自动提交中止",1);
-                    return retf;
-                }
-            }
-            
-            // 冷板绑定成功后,提交质量结果
-            if(MesClient.bindLbStatus_1) {
-                MesClient.setMenuState_1("正在提交结果",0);
-                MesClient.btnUnbindLb_1.setEnabled(false);//上传结果此时不能点击解绑
-                
-                if(MesClient.aFinish == MesClient.aMax){//合格数量等于预设数量
-                    retf = "OK";
-                }
-                Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn_1.getText(),retf, MesClient.user20, Config.gw_1);
-                if(!ret){
-                    MesClient.setMenuState_1(MesClient.tjFlagTextErr,-1);
-                } else {
-                    MesClient.setMenuState_1("结果提交成功",0);
-                    MesClient.heartBeatFlag = false;
-                    
-                    // 将PLC已打数量、合格数量和不合格数量地址写为0
-                    try {
-                        if (MesClient.plcA != null) {
-                            MesClient.plcA.writeInt16(66, (short) 0);
-                            MesClient.plcA.writeInt16(68, (short) 0);
-                            MesClient.plcA.writeInt16(70, (short) 0);
-                            log.info("A工位已打数量、合格数量和不合格数量地址已清零");
-                        }
-                    } catch (Exception e) {
-                        log.error("A工位清零数量失败:" + e.getMessage());
-                    }
-                    
-                    // 重置提交参数
-                    MesClient.aFinish = 0;
-                    MesClient.aMax = 0;
-                    MesClient.sortA = 0;
-                    MesClient.bindLbStatus_1 = false;
-                    MesClient.coldPlateValidated_1 = false;
-                    MesClient.coldPlateCode_1 = "";
-                    MesClient.product_sn_1.setText("");
-                    MesClient.product_sn_lb_1.setText("");
-                    MesClient.f_scan_data_bt_1.setEnabled(true);
-                    MesClient.btnUnbindLb_1.setEnabled(false);
-                }
-            }
-            
-        } else if(!MesClient.product_sn_1.getText().isEmpty() && MesClient.aMax > 0 && MesClient.aMax <= MesClient.sortA) {
-            // 检查各种阻止自动提交的条件
-            if(MesClient.coldPlateCode_1.isEmpty()) {
-                MesClient.setMenuState_1("冷板为空,无法自动提交", 1);
-            } else if(!MesClient.coldPlateValidated_1) {
-                MesClient.setMenuState_1("冷板校验未通过,无法自动提交", 1);
-            } else {
-                MesClient.setMenuState_1("等待冷板绑定完成", 1);
-            }
-            log.info("自动提交被阻止 - 冷板校验状态: " + MesClient.coldPlateValidated_1 + ", 冷板码: " + MesClient.coldPlateCode_1);
+    // 拉铆完成:只写本地工作记录计件,不向MES提交工位结果(拉铆参数由定时任务另行上传)
+    public static void upResultA(){
+        if(MesClient.product_sn_1.getText().isEmpty() || MesClient.aMax <= 0 || MesClient.sortA < MesClient.aMax){
+            return;
         }
-        return retf;
+
+        String sn = MesClient.product_sn_1.getText();
+        String result = MesClient.aFinish == MesClient.aMax ? "OK" : "NG";
+        // 拉铆参数照常上传,本地计件按工件码防重
+        boolean counted = JdbcUtils.insertWorkRecord(Config.gw_1, sn,
+                MesClient.aMax, MesClient.aFinish, result, MesClient.user_menu.getText());
+
+        MesClient.heartBeatFlag = false;   // 停心跳,设备停止
+        clearCount(MesClient.plcA, "A");
+        resetStationA();
+        MesClient.setMenuState_1(counted
+                ? "已完成计件(" + result + "),请扫下一件"
+                : "工件码重复,不重复计件,请扫下一件", 0);
+        refreshWorkRecord();
     }
 
-    // 上传总结果
-    public static String upResultB(){
-        String retf = "NG";
-        log.debug("冷板校验状态:"+MesClient.coldPlateValidated_2);
-        log.debug("冷板绑定状态:"+MesClient.bindLbStatus_2);
-        
-        // 检查自动提交条件:工件码不为空 && 预设数量>0 && 已打数量>=预设数量 && 冷板已校验
-        if(!MesClient.product_sn_2.getText().isEmpty() && MesClient.bMax > 0 && MesClient.bMax <= MesClient.sortB && MesClient.coldPlateValidated_2){
-            
-            // 如果冷板还未绑定到数据库,先进行绑定
-            if(!MesClient.bindLbStatus_2 && !MesClient.coldPlateCode_2.isEmpty()){
-                MesClient.setMenuState_2("正在绑定冷板",0);
-                String warehouseSn = MesClient.getBarcode(MesClient.coldPlateCode_2);
-                String sn = MesClient.getBarcode(MesClient.product_sn_2.getText());
-                MesClient.getUser();
-                Boolean bindResult = DataUtil.bindWarehouse(MesClient.nettyClient, sn, warehouseSn, MesClient.user20, "400004", Config.gw_2);
-
-                if(bindResult) {
-                    MesClient.bindLbStatus_2 = true;
-                    MesClient.setMenuState_2("冷板绑定成功",0);
-                } else {
-                    MesClient.setMenuState_2("冷板绑定失败,自动提交中止",1);
-                    return retf;
-                }
-            }
-            
-            // 冷板绑定成功后,提交质量结果
-            if(MesClient.bindLbStatus_2) {
-                MesClient.setMenuState_2("正在提交结果",0);
-                MesClient.btnUnbindLb_2.setEnabled(false);//上传结果此时不能点击解绑
-                
-                if(MesClient.bFinish == MesClient.bMax){//合格数量等于预设数量
-                    retf = "OK";
-                }
-                Boolean ret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn_2.getText(),retf, MesClient.user20, Config.gw_2);
-                if(!ret){
-                    MesClient.setMenuState_2(MesClient.tjFlagTextErr,-1);
-                } else {
-                    MesClient.setMenuState_2("结果提交成功",0);
-                    MesClient.heartBeatFlag2 = false;
-                    
-                    // 将PLC已打数量、合格数量和不合格数量地址写为0
-                    try {
-                        if (MesClient.plcB != null) {
-                            MesClient.plcB.writeInt16(66, (short) 0);
-                            MesClient.plcB.writeInt16(68, (short) 0);
-                            MesClient.plcB.writeInt16(70, (short) 0);
-                            log.info("B工位已打数量、合格数量和不合格数量地址已清零");
-                        }
-                    } catch (Exception e) {
-                        log.error("B工位清零数量失败:" + e.getMessage());
-                    }
-                    
-                    // 重置提交参数
-                    MesClient.bFinish = 0;
-                    MesClient.bMax = 0;
-                    MesClient.sortB = 0;
-                    MesClient.bindLbStatus_2 = false;
-                    MesClient.coldPlateValidated_2 = false;
-                    MesClient.coldPlateCode_2 = "";
-                    MesClient.product_sn_2.setText("");
-                    MesClient.product_sn_lb_2.setText("");
-                    MesClient.f_scan_data_bt_2.setEnabled(true);
-                    MesClient.btnUnbindLb_2.setEnabled(false);
-                }
-            }
-            
-        } else if(!MesClient.product_sn_2.getText().isEmpty() && MesClient.bMax > 0 && MesClient.bMax <= MesClient.sortB) {
-            // 检查各种阻止自动提交的条件
-            if(MesClient.coldPlateCode_2.isEmpty()) {
-                MesClient.setMenuState_2("冷板为空,无法自动提交", 1);
-            } else if(!MesClient.coldPlateValidated_2) {
-                MesClient.setMenuState_2("冷板校验未通过,无法自动提交", 1);
-            } else {
-                MesClient.setMenuState_2("等待冷板绑定完成", 1);
+    // 拉铆完成:只写本地工作记录计件
+    public static void upResultB(){
+        if(MesClient.product_sn_2.getText().isEmpty() || MesClient.bMax <= 0 || MesClient.sortB < MesClient.bMax){
+            return;
+        }
+
+        String sn = MesClient.product_sn_2.getText();
+        String result = MesClient.bFinish == MesClient.bMax ? "OK" : "NG";
+        // 拉铆参数照常上传,本地计件按工件码防重
+        boolean counted = JdbcUtils.insertWorkRecord(Config.gw_2, sn,
+                MesClient.bMax, MesClient.bFinish, result, MesClient.user_menu.getText());
+
+        MesClient.heartBeatFlag2 = false;  // 停心跳,设备停止
+        clearCount(MesClient.plcB, "B");
+        resetStationB();
+        MesClient.setMenuState_2(counted
+                ? "已完成计件(" + result + "),请扫下一件"
+                : "工件码重复,不重复计件,请扫下一件", 0);
+        refreshWorkRecord();
+    }
+
+    // 清零PLC已打数量/合格数量/不合格数量
+    private static void clearCount(ModbusTcp plc, String tag){
+        try {
+            if (plc != null) {
+                plc.writeInt16(66, (short) 0);
+                plc.writeInt16(68, (short) 0);
+                plc.writeInt16(70, (short) 0);
+                log.info(tag + "工位已打数量、合格数量和不合格数量地址已清零");
             }
-            log.info("自动提交被阻止 - 冷板校验状态: " + MesClient.coldPlateValidated_2 + ", 冷板码: " + MesClient.coldPlateCode_2);
+        } catch (Exception e) {
+            log.error(tag + "工位清零数量失败:" + e.getMessage());
+        }
+    }
+
+    // 工位1完成后复位,等待扫下一件
+    private static void resetStationA(){
+        MesClient.aFinish = 0;
+        MesClient.aMax = 0;
+        MesClient.sortA = 0;
+        MesClient.work_status1 = 0;
+        MesClient.product_sn_1.setText("");
+        MesClient.f_scan_data_bt_1.setEnabled(true);
+    }
+
+    // 工位2完成后复位,等待扫下一件
+    private static void resetStationB(){
+        MesClient.bFinish = 0;
+        MesClient.bMax = 0;
+        MesClient.sortB = 0;
+        MesClient.work_status2 = 0;
+        MesClient.product_sn_2.setText("");
+        MesClient.f_scan_data_bt_2.setEnabled(true);
+    }
+
+    private static void refreshWorkRecord(){
+        if (MesClient.workRecordPanel != null) {
+            // PLC定时线程里刷新表格,切回EDT
+            SwingUtilities.invokeLater(() -> MesClient.workRecordPanel.reload());
         }
-        return retf;
     }
 
     // 获取控制模式

+ 2 - 3
src/resources/config/config.properties

@@ -2,10 +2,9 @@
 #Thu Aug 06 17:48:19 CST 2026
 mes.workpiece_prefix=+KA99,+KC14,+KB98
 mes.heart_beat_cycle=60
-mes.gw_2=OP150B
-mes.gw_1=OP150A
+mes.gw_2=OP240A
+mes.gw_1=OP240B
 mes.line_sn=XT
-mes.coldplate_prefix=+KB004,2510
 mes.tcp_port=3000
 mes.plc_timeout_enabled=true
 mes.server_ip=192.168.110.99