wangxichen 5 днів тому
батько
коміт
78609a677a

+ 20 - 12
src/com/mes/ui/DataUtil.java

@@ -60,7 +60,6 @@ public class DataUtil {
         try{
             String msgType = "AQDW";
             String gy = "100000";
-            // op 参数现在传的是完整 oprno(OP060A)
             Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,"",user,"00","",op);
             return aqdw_str;
         }catch (Exception e){
@@ -113,34 +112,43 @@ public class DataUtil {
         }
     }
 
-    public static Boolean sendQuality(NettyClient nettyClient,String sn,String ret,String user,String oprno){
+    public static Boolean sendQuality(NettyClient nettyClient,String sn,String ret,String user,String op){
         try{
             String msgType = "MQDW";
             String gy = "100000";
             String paramNums = "01";
-            String params = rightPad("Y"+MesClient.programNoB, 12);
-            // oprno 参数现在直接传完整工序号(OP060A),不再拼接
-            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,ret,user,paramNums,params,oprno);
+            String params = "";
+            if(op.equals("A")){
+                params = rightPad("Y"+MesClient.programNoA, 12);
+            }else{
+                params = rightPad("Y"+MesClient.programNoB, 12);
+            }
+            Boolean aqdw_str = sendMessage(nettyClient,msgType,gy,"",sn,ret,user,paramNums,params,op);
             return aqdw_str;
         }catch (Exception e){
             return false;
         }
     }
 
-    public static Boolean sendQuality2(String sn,String result,String user,String oprno){
+    public static Boolean sendQuality2(String sn,String result,String user,String op){
         try{
             String msgType = "MQDW";
             String craft = "100000";
             String lx = "";
             String paramNums = "01";
-            String params = rightPad("Y"+MesClient.programNoB, 12);
+            String params = "";
+            if(op.equals("A")){
+                params = rightPad("Y"+MesClient.programNoA, 12);
+            }else{
+                params = rightPad("Y"+MesClient.programNoB, 12);
+            }
 
+            // 单工位:op 传进来的就是本机面别,不再做 A/B→C/D 重映射
             InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
             Properties pro = new Properties();
             BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
             pro.load(br);
-            // oprno 直接使用传入值,不再拼接和重映射
-            String gw = "GW"+rightPad(oprno, 8);
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw")+op, 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);
@@ -158,7 +166,7 @@ public class DataUtil {
         }
     }
 
-    public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params,String oprno){
+    public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params,String op){
         try{
             String enconding = "UTF-8";
             InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
@@ -166,8 +174,8 @@ public class DataUtil {
             BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
             pro.load(br);
 
-            // oprno 直接使用传入值,不再进行字母重映射
-            String gw = "GW"+rightPad(oprno, 8);
+            // 单工位:op 传进来的就是本机面别(等于 mes.gwflag),直接拼工序号,不再做 A/B→C/D 重映射
+            String gw = "GW"+rightPad(pro.getProperty("mes.gw")+op, 8);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);

+ 102 - 281
src/com/mes/ui/MesClient.java

@@ -191,9 +191,6 @@ public class MesClient extends JFrame {
 
                     textFocus();
 
-                    // 预热打印模块(后台异步,不阻塞启动)
-                    com.mes.print.PrintHelper.warmUpAsync();
-
                 }catch (Exception e){
                     e.printStackTrace();
                 }
@@ -240,9 +237,13 @@ public class MesClient extends JFrame {
         cjTimer.schedule(new TimerTask() {
             public void run() {
                 try{
-                    // 只监控 B 
+                    // 只轮询本机负责的
                     if(!MesClient.sessionid.isEmpty()){
-                        PlcUtil.getStatusB(s7PLC);
+                        if("B".equals(side())){
+                            PlcUtil.getStatusB(s7PLC);
+                        }else{
+                            PlcUtil.getStatusA(s7PLC);
+                        }
                     }
                 }catch (Exception e){
                     e.printStackTrace();
@@ -259,28 +260,8 @@ public class MesClient extends JFrame {
         cjTimerText = new Timer();
         cjTimerText.schedule(new TimerTask() {
             public void run() {
+                // 面别由配置固定,不再读转台到位信号,这里只保持扫码框焦点
                 textField.requestFocusInWindow();
-
-                String page = PlcUtil.getCurAside(s7PLC);
-                if(page != null && page.equals("B")){
-                    // B 面可扫码:绿色背景
-                    lblNewLabel_5.setText("当前:B面(可扫码)");
-                    lblNewLabel_5.setForeground(new Color(0, 128, 0));
-                    if(product_sn2.getText().isEmpty() || product_sn2.getText().contains("请等待")){
-                        product_sn2.setText("OP060 - 请扫码");
-                        product_sn2.setBackground(new Color(144, 238, 144));  // 浅绿色
-                        product_sn2.setForeground(Color.BLACK);
-                    }
-                }else{
-                    // A 面等待转台:灰色背景
-                    lblNewLabel_5.setText("当前:A面(等待转台)");
-                    lblNewLabel_5.setForeground(Color.GRAY);
-                    if(product_sn2.getText().isEmpty() || product_sn2.getText().contains("请扫码") || product_sn2.getText().contains("请等待")){
-                        product_sn2.setText("请等待转到B面扫码");
-                        product_sn2.setBackground(Color.LIGHT_GRAY);
-                        product_sn2.setForeground(Color.DARK_GRAY);
-                    }
-                }
             }
         }, 1000,1000);
     }
@@ -323,6 +304,14 @@ public class MesClient extends JFrame {
         System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
     }
 
+    /**
+     * 本机负责的面:由 config 的 mes.gwflag 决定,只认 A / B
+     * 该值同时是 PLC 点位面别和 MES 工序号后缀(OP120A / OP120B)
+     */
+    public static String side() {
+        return "B".equals(mes_gwflag) ? "B" : "A";
+    }
+
     // 閸掓繂顫愰崠鏈P
     public static void initTcpConnection() {
         try {
@@ -414,7 +403,41 @@ public class MesClient extends JFrame {
     }
 
     public static void initWarehouseData(){
-        resetScanB();
+        // 只复位本机负责的面
+        if("B".equals(side())){
+            resetScanB();
+        }else{
+            resetScanA();
+        }
+    }
+
+    public static void resetScanA() {
+        work_status = 0;
+        check_quality_result = false;
+        MesClient.finish_ok_bt.setEnabled(true);
+        MesClient.mesQualityFlagA = false;
+        product_sn.setText("");
+
+        MesClient.pxstatus1.setText("A");
+        MesClient.param1.setText("");
+        MesClient.param2.setText("");
+        MesClient.param3.setText("");
+        MesClient.param4.setText("");
+        MesClient.param5.setText("");
+
+        MesClient.param21.setText("");
+        MesClient.param22.setText("");
+        MesClient.param23.setText("");
+        MesClient.param24.setText("");
+        MesClient.param25.setText("");
+        MesClient.curFlag = "";
+        MesClient.curSna = "";
+        MesClient.tjFlaga = 0;
+        PlcUtil.changeEnable(s7PLC, false, "A");
+
+        updateMaterailData(); // 更新物料
+
+        shiftUserCheck();
     }
 
     public static int userLoginHours;//用户登录所处小时
@@ -442,18 +465,7 @@ public class MesClient extends JFrame {
         check_quality_result2 = false;
         MesClient.finish_ng_bt.setEnabled(true);
         MesClient.mesQualityFlagB = false;
-
-        // 清空后根据转台位置恢复提示
-        String page = PlcUtil.getCurAside(s7PLC);
-        if(page != null && page.equals("B")){
-            product_sn2.setText("OP060 - 请扫码");
-            product_sn2.setBackground(new Color(144, 238, 144));  // 浅绿色
-            product_sn2.setForeground(Color.BLACK);
-        }else{
-            product_sn2.setText("请等待转到B面扫码");
-            product_sn2.setBackground(Color.LIGHT_GRAY);
-            product_sn2.setForeground(Color.DARK_GRAY);
-        }
+        product_sn2.setText("");
 
         MesClient.pxstatus2.setText("B");
 
@@ -566,6 +578,18 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(resetTcpMenu);
 
+        JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
+        resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
+        resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
+        resetTcpMenu_1.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                resetScanA();
+            }
+        });
+        settingMenu.add(resetTcpMenu_1);
+        
         JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
         resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
         resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
@@ -614,8 +638,7 @@ public class MesClient extends JFrame {
 
                     if(!sn.isEmpty()){
                         String qret = "OK";
-                        String oprno = mes_gw + mes_gwflag;  // OP060A
-                        Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,oprno);
+                        Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
                         if(!sendret){
                             MesClient.setMenuStatus("上传MES失败,请重试",-1);
                         }
@@ -625,43 +648,6 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(resetTcpMenu_1_1sd);
 
-        // 打印机设置菜单
-        JMenuItem printerSettingMenu = new JMenuItem("打印机设置");
-        printerSettingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
-        printerSettingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
-        printerSettingMenu.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
-                super.mouseClicked(e);
-                try {
-                    // 调用打印机设置对话框
-                    com.mes.print.ui.PrinterSettingDialog dialog =
-                        new com.mes.print.ui.PrinterSettingDialog(MesClient.this);
-                    dialog.setVisible(true);
-                } catch (Exception ex) {
-                    JOptionPane.showMessageDialog(MesClient.this,
-                        "打开打印机设置失败: " + ex.getMessage(),
-                        "错误",
-                        JOptionPane.ERROR_MESSAGE);
-                    ex.printStackTrace();
-                }
-            }
-        });
-        settingMenu.add(printerSettingMenu);
-
-        // 测试打印菜单
-        JMenuItem testPrintMenu = new JMenuItem("测试打印");
-        testPrintMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
-        testPrintMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
-        testPrintMenu.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent e) {
-                super.mouseClicked(e);
-                showTestPrintDialog();
-            }
-        });
-        settingMenu.add(testPrintMenu);
-
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);
@@ -743,13 +729,21 @@ public class MesClient extends JFrame {
         indexPanelA.setLayout(null);
 
         product_sn = new JTextField();
-        product_sn.setText("OP050工位(不监控)");
+        product_sn.setText("");
         product_sn.setHorizontalAlignment(SwingConstants.CENTER);
         product_sn.setEditable(false);
-        product_sn.setEnabled(false);  // 禁用
-        product_sn.setBackground(Color.LIGHT_GRAY);  // 灰色背景
-        product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
+        product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
         product_sn.setBounds(26, 144, 446, 70);
+        // 添加鼠标点击事件,点击显示二维码
+        product_sn.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent e) {
+                String sn = product_sn.getText();
+                if(sn != null && !sn.trim().isEmpty()){
+                    new com.mes.component.QRCodeDialog(mesClientFrame, "A面工件码二维码", sn);
+                }
+            }
+        });
         indexPanelA.add(product_sn);
         product_sn.setColumns(10);
 
@@ -883,19 +877,18 @@ public class MesClient extends JFrame {
         indexPanelA.add(lblNewLabel_1_1_1);
         
         product_sn2 = new JTextField();
-        product_sn2.setText("请等待转到B面扫码");
+        product_sn2.setText("");
         product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
-        product_sn2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
+        product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
         product_sn2.setEditable(false);
         product_sn2.setColumns(10);
         product_sn2.setBounds(517, 144, 446, 70);
-        product_sn2.setBackground(Color.LIGHT_GRAY);  // 默认灰色,等待转台
         // 添加鼠标点击事件,点击显示二维码
         product_sn2.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent e) {
                 String sn = product_sn2.getText();
-                if(sn != null && !sn.trim().isEmpty() && !sn.contains("请等待")){
+                if(sn != null && !sn.trim().isEmpty()){
                     new com.mes.component.QRCodeDialog(mesClientFrame, "B面工件码二维码", sn);
                 }
             }
@@ -1021,18 +1014,18 @@ public class MesClient extends JFrame {
         textField.setHorizontalAlignment(SwingConstants.LEFT);
         textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
         textField.setColumns(10);
-        textField.setBounds(400, 10, 510, 50);  // 向右移动,给状态标签留空间
+        textField.setBounds(264, 10, 510, 50);
         textField.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 scanBarcode();
             }
         });
         indexPanelA.add(textField);
-
-        lblNewLabel_5 = new JLabel("等待检测转台位置...");
-        lblNewLabel_5.setForeground(Color.GRAY);
-        lblNewLabel_5.setFont(new Font("微软雅黑", Font.BOLD, 20));
-        lblNewLabel_5.setBounds(126, 10, 360, 50);
+        
+        lblNewLabel_5 = new JLabel("本机:" + side() + "面");
+        lblNewLabel_5.setForeground(new Color(0, 128, 64));
+        lblNewLabel_5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        lblNewLabel_5.setBounds(136, 10, 113, 50);
         indexPanelA.add(lblNewLabel_5);
 
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
@@ -1312,32 +1305,29 @@ public class MesClient extends JFrame {
             return;
         }
 
-        // 检查转台位置,只有在 B 面才允许扫码
-        String page = PlcUtil.getCurAside(s7PLC);
-        if(page == null || !page.equals("B")){
-            MesClient.setMenuStatus("请等待转到 B 面",1);
-            return;
-        }
-
-        // 固定走 B 面逻辑
-        if(!product_sn2.getText().isEmpty() && !product_sn2.getText().contains("请扫码") && !product_sn2.getText().contains("请等待") && mesQualityFlagB){
-            MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
-            return;
+        // 面别由配置固定,扫到的码只落本机负责的面
+        String page = side();
+        if(page.equals("A")){
+            if(!product_sn.getText().isEmpty() && mesQualityFlagA){
+                MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
+                return;
+            }
+            product_sn.setText(sn);
+        }else{
+            if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
+                MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
+                return;
+            }
+            product_sn2.setText(sn);
         }
 
-        // 显示工件码,恢复白色背景
-        product_sn2.setText(sn);
-        product_sn2.setBackground(Color.WHITE);
-        product_sn2.setForeground(Color.BLACK);
-
         MesClient.setMenuStatus("扫码成功",0);
 
         //刷新界面
         mesClientFrame.repaint();
         getUser();
-        // 查询工件质量,传入完整工序号
-        String oprno = mes_gw + mes_gwflag;  // OP060A
-        Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,oprno);
+        // 查询工件质量
+        Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,page);
         if(!sendret){
             MesClient.setMenuStatus("消息发送失败,请重试",1);
         }
@@ -1346,7 +1336,7 @@ public class MesClient extends JFrame {
 
     public static void scanBarcodeOld() {
         String scanBarcodeTitle = "请扫工件码";
-        String page = PlcUtil.getCurAside(s7PLC);
+        String page = side();
         if(page.equals("A")){
             product_sn.setText("");
         }else{
@@ -1475,173 +1465,4 @@ public class MesClient extends JFrame {
             log.info("异步任务执行完毕");
         });
     }
-
-    /**
-     * 显示测试打印对话框
-     */
-    private void showTestPrintDialog() {
-        JDialog dialog = new JDialog(this, "测试打印", true);
-        dialog.setSize(450, 280);
-        dialog.setLocationRelativeTo(this);
-
-        JPanel panel = new JPanel();
-        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-        panel.setBorder(new EmptyBorder(20, 20, 20, 20));
-
-        // 输入框
-        JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
-        JLabel label = new JLabel("客户码(二维码):");
-        label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-        JTextField snField = new JTextField("+KB60IS3031T729002101", 22);
-        snField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-        snField.setPreferredSize(new Dimension(250, 35));
-        inputPanel.add(label);
-        inputPanel.add(snField);
-        panel.add(inputPanel);
-
-        panel.add(Box.createVerticalStrut(15));
-
-        // 结果显示
-        JLabel resultLabel = new JLabel(" ");
-        resultLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14));
-        resultLabel.setForeground(Color.BLUE);
-        panel.add(resultLabel);
-
-        panel.add(Box.createVerticalStrut(25));
-
-        // 按钮面板
-        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0));
-
-        // 查询按钮
-        JButton queryBtn = new JButton("查询钢印码");
-        queryBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-
-        // 预览按钮(初始禁用)
-        JButton previewBtn = new JButton("预览效果");
-        previewBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-        previewBtn.setEnabled(false);
-
-        // 打印按钮(初始禁用)
-        JButton printBtn = new JButton("打印");
-        printBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-        printBtn.setEnabled(false);
-
-        JButton closeBtn = new JButton("关闭");
-        closeBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
-        closeBtn.addActionListener(e -> dialog.dispose());
-
-        // 用于保存查询到的数据
-        final String[] queriedData = new String[2]; // [0]=customerSn, [1]=steelSn
-
-        // 查询按钮逻辑
-        queryBtn.addActionListener(e -> {
-            String customerSn = snField.getText().trim();
-            if (customerSn.isEmpty()) {
-                JOptionPane.showMessageDialog(dialog, "请输入客户码", "提示", JOptionPane.WARNING_MESSAGE);
-                return;
-            }
-
-            queryBtn.setEnabled(false);
-            previewBtn.setEnabled(false);
-            printBtn.setEnabled(false);
-            resultLabel.setText("正在查询钢印码...");
-            resultLabel.setForeground(Color.BLUE);
-
-            new Thread(() -> {
-                try {
-                    String steelSn = DataUtil.getSteelSn(customerSn);
-
-                    javax.swing.SwingUtilities.invokeLater(() -> {
-                        if (steelSn != null && !steelSn.isEmpty()) {
-                            queriedData[0] = customerSn;
-                            queriedData[1] = steelSn;
-                            resultLabel.setText("查询成功!钢印码: " + steelSn);
-                            resultLabel.setForeground(new Color(0, 150, 0));
-                            previewBtn.setEnabled(true);
-                            printBtn.setEnabled(true);
-                        } else {
-                            resultLabel.setText("未找到该客户码对应的钢印码");
-                            resultLabel.setForeground(Color.RED);
-                        }
-                        queryBtn.setEnabled(true);
-                    });
-                } catch (Exception ex) {
-                    javax.swing.SwingUtilities.invokeLater(() -> {
-                        resultLabel.setText("查询失败: " + ex.getMessage());
-                        resultLabel.setForeground(Color.RED);
-                        queryBtn.setEnabled(true);
-                    });
-                }
-            }).start();
-        });
-
-        // 预览按钮逻辑
-        previewBtn.addActionListener(e -> {
-            if (queriedData[0] == null || queriedData[1] == null) {
-                JOptionPane.showMessageDialog(dialog, "请先查询钢印码", "提示", JOptionPane.WARNING_MESSAGE);
-                return;
-            }
-
-            previewBtn.setEnabled(false);
-            resultLabel.setText("正在生成预览 PDF...");
-            resultLabel.setForeground(Color.BLUE);
-
-            new Thread(() -> {
-                try {
-                    com.mes.print.model.FlowCardData previewData = new com.mes.print.model.FlowCardData();
-                    previewData.setSn(queriedData[0]);
-                    previewData.setSteelSn(queriedData[1]);
-                    com.mes.print.Printer.previewFlowCard(previewData);
-
-                    javax.swing.SwingUtilities.invokeLater(() -> {
-                        resultLabel.setText("预览已打开(PDF 文件已用默认程序打开)");
-                        resultLabel.setForeground(new Color(0, 150, 0));
-                        previewBtn.setEnabled(true);
-                    });
-                } catch (Exception ex) {
-                    javax.swing.SwingUtilities.invokeLater(() -> {
-                        resultLabel.setText("预览失败: " + ex.getMessage());
-                        resultLabel.setForeground(Color.RED);
-                        previewBtn.setEnabled(true);
-                        ex.printStackTrace();
-                    });
-                }
-            }).start();
-        });
-
-        // 打印按钮逻辑
-        printBtn.addActionListener(e -> {
-            if (queriedData[0] == null || queriedData[1] == null) {
-                JOptionPane.showMessageDialog(dialog, "请先查询钢印码", "提示", JOptionPane.WARNING_MESSAGE);
-                return;
-            }
-
-            printBtn.setEnabled(false);
-            resultLabel.setText("正在打印...");
-            resultLabel.setForeground(Color.BLUE);
-
-            new Thread(() -> {
-                boolean success = com.mes.print.PrintHelper.printFlowCard(queriedData[0], queriedData[1]);
-                javax.swing.SwingUtilities.invokeLater(() -> {
-                    if (success) {
-                        resultLabel.setText("打印成功!");
-                        resultLabel.setForeground(new Color(0, 150, 0));
-                    } else {
-                        resultLabel.setText("打印失败,请检查打印机");
-                        resultLabel.setForeground(Color.RED);
-                    }
-                    printBtn.setEnabled(true);
-                });
-            }).start();
-        });
-
-        buttonPanel.add(queryBtn);
-        buttonPanel.add(previewBtn);
-        buttonPanel.add(printBtn);
-        buttonPanel.add(closeBtn);
-        panel.add(buttonPanel);
-
-        dialog.add(panel);
-        dialog.setVisible(true);
-    }
 }

+ 49 - 23
src/com/mes/ui/MesRevice.java

@@ -14,17 +14,50 @@ public class MesRevice {
     public static void checkQualityRevice(String processMsgRet,String mes_msg){
         try{
             if(processMsgRet.equalsIgnoreCase("UD")) {
+//                MesClient.status_menu.setForeground(Color.GREEN);
+//                MesClient.status_menu.setText("该工件可以加工");
+
                 String oprno = ProtocolParam.getOprno(mes_msg).trim();
                 String sn = ProtocolParam.getSn(mes_msg).trim();
 
                 MesClient.lastpage = 0;
-                // 只有 B 面逻辑
-                MesClient.finish_ng_bt.setEnabled(false);
-                MesClient.mesQualityFlagB = true;
-                MesClient.pxstatus2.setText("B:可以加工,等待设备启动");
-                MesClient.curSnb = MesClient.product_sn2.getText();
-                MesClient.tjFlagb = 1;
-                PlcUtil.changeEnable(MesClient.s7PLC, true, "B");
+                // 面别由配置固定,直接走本机负责的面
+                if("A".equals(MesClient.side())){
+                    MesClient.finish_ok_bt.setEnabled(false);
+                    MesClient.mesQualityFlagA = true;
+                    MesClient.pxstatus1.setText("A:可以加工,等待设备启动");
+                    MesClient.curSna = MesClient.product_sn.getText();
+                    MesClient.tjFlaga = 1;
+                    PlcUtil.changeEnable(MesClient.s7PLC, true, "A");
+
+
+                    // 程序号防错功能已注释
+                    // MesClient.programNoA = PlcUtil.getProgranNoA(MesClient.s7PLC)+"";
+                    // System.err.println(MesClient.programNoA);
+                    // System.err.println(CommonUtils.checkProgramNoSn(sn,MesClient.programNoA));
+                    // if(!CommonUtils.checkProgramNoSn(sn,MesClient.programNoA)){
+                    //     MesClient.pxstatus1.setText("A:当前工件与设备程序不匹配");
+                    //     MesClient.setMenuStatus("A:当前工件与设备程序不匹配",-1);
+                    // }
+
+
+
+                }else{
+                    MesClient.finish_ng_bt.setEnabled(false);
+                    MesClient.mesQualityFlagB = true;
+                    MesClient.pxstatus2.setText("B:可以加工,等待设备启动");
+                    MesClient.curSnb = MesClient.product_sn2.getText();
+                    MesClient.tjFlagb = 1;
+                    PlcUtil.changeEnable(MesClient.s7PLC, true, "B");
+
+                    // 程序号防错功能已注释
+                    // MesClient.programNoB = PlcUtil.getProgranNoB(MesClient.s7PLC)+"";
+//                    PlcUtil.changeEnable(MesClient.s7PLC,true);
+                    // if(!CommonUtils.checkProgramNoSn(sn,MesClient.programNoB)){
+                    //     MesClient.pxstatus2.setText("B:当前工件与设备程序不匹配");
+                    //     MesClient.setMenuStatus("B:当前工件与设备程序不匹配",-1);
+                    // }
+                }
 
             }else {
                 if(MesClient.scan_type == 1){
@@ -85,28 +118,21 @@ public class MesRevice {
     public static void updateResultRevice(String processMsgRet,String mes_msg){
         try{
             String sn = ProtocolParam.getSn(mes_msg).trim();
+            // 面别由配置固定,直接走本机负责的面
+            boolean isB = "B".equals(MesClient.side());
             if(processMsgRet.equalsIgnoreCase("OK")) {
-                // 只有 B 面逻辑
-                if(sn.equals(MesClient.product_sn2.getText())){
+                if(isB){
                     MesClient.pxstatus2.setText("B:提交成功");
-
-                    // 自动打印(后台异步)
-                    new Thread(() -> {
-                        try {
-                            // 查询钢印码
-                            String steelSn = DataUtil.getSteelSn(sn);
-                            com.mes.print.PrintHelper.autoPrint(sn, steelSn);
-                        } catch (Exception e) {
-                            System.err.println("[B面] 打印失败: " + e.getMessage());
-                        }
-                    }, "print-B").start();
-
                     MesClient.resetScanB();
+                }else{
+                    MesClient.pxstatus1.setText("A:提交成功");
+                    MesClient.resetScanA();
                 }
             }else{
-                // 只有 B 面逻辑
-                if(sn.equals(MesClient.product_sn2.getText())){
+                if(isB){
                     MesClient.pxstatus2.setText("B:提交失败");
+                }else{
+                    MesClient.pxstatus1.setText("A:提交失败");
                 }
             }
         }catch (Exception e){

+ 76 - 30
src/com/mes/ui/PlcUtil.java

@@ -11,9 +11,10 @@ import java.util.List;
 public class PlcUtil {
 
     private static final String DB = "DB200";
+    private static final String A_ENABLE = DB + ".0.1";
     private static final String B_ENABLE = DB + ".38.0";
+    private static final String A_STATUS = DB + ".34";
     private static final String B_STATUS = DB + ".72";
-    private static final String B_POSITION = DB + ".156.4";
 
     private static final WeldPoint[] WELD_POINTS = new WeldPoint[]{
             new WeldPoint("R1", 76.1, 78, 80, 84, 88, 92),
@@ -26,7 +27,9 @@ public class PlcUtil {
     private static String lastParamValues = null;
 
     public static void getParamDyDl(S7PLC s7PLC) {
-        if (MesClient.tjFlagb == 2) {
+        // 只在本机负责的面运行中时采集
+        boolean running = "B".equals(MesClient.side()) ? MesClient.tjFlagb == 2 : MesClient.tjFlaga == 2;
+        if (running) {
             List<String> values = readWeldParams(s7PLC);
             String recordTime = DateLocalUtils.getCurrentTime();
             values.add("time=" + recordTime);
@@ -75,12 +78,20 @@ public class PlcUtil {
         float r1WeldSpeed = valueOf(values, "R1:weldSpeed=");
         int r1Seq = (int) valueOf(values, "R1:seq=");
 
-        // 只刷新 B 面控件
-        MesClient.param21.setText(String.valueOf(r1Voltage));
-        MesClient.param22.setText(String.valueOf(r1Current));
-        MesClient.param23.setText(String.valueOf(r1WireSpeed));
-        MesClient.param24.setText(String.valueOf(r1Seq));
-        MesClient.param25.setText(String.valueOf(r1WeldSpeed));
+        // 只刷新本机负责的那一面的控件
+        if ("B".equals(MesClient.side())) {
+            MesClient.param21.setText(String.valueOf(r1Voltage));
+            MesClient.param22.setText(String.valueOf(r1Current));
+            MesClient.param23.setText(String.valueOf(r1WireSpeed));
+            MesClient.param24.setText(String.valueOf(r1Seq));
+            MesClient.param25.setText(String.valueOf(r1WeldSpeed));
+        } else {
+            MesClient.param1.setText(String.valueOf(r1Voltage));
+            MesClient.param2.setText(String.valueOf(r1Current));
+            MesClient.param3.setText(String.valueOf(r1WireSpeed));
+            MesClient.param4.setText(String.valueOf(r1Seq));
+            MesClient.param5.setText(String.valueOf(r1WeldSpeed));
+        }
     }
 
     private static float valueOf(List<String> values, String prefix) {
@@ -98,14 +109,16 @@ public class PlcUtil {
 
     private static void saveCurrentParams() {
         try {
-            String oprno = MesClient.mes_gw + MesClient.mes_gwflag;  // OP060A
-            String sn = MesClient.curSnb;
+            // 工序号后缀和工件码都取本机负责的面
+            String side = MesClient.side();
+            String oprno = MesClient.mes_gw + side;
+            String sn = "B".equals(side) ? MesClient.curSnb : MesClient.curSna;
 
             // 检查工件码和参数列表都不为空
             if (sn != null && !sn.trim().isEmpty()) {
                 if (MesClient.hjparams != null && !MesClient.hjparams.isEmpty()) {
                     JdbcUtils.insertCmtData(oprno, MesClient.mes_line_sn, sn, JSON.toJSONString(MesClient.hjparams));
-                    System.out.println("cmt:B sn:" + sn + " params_count:" + MesClient.hjparams.size());
+                    System.out.println("cmt:" + MesClient.curFlag + " sn:" + sn + " params_count:" + MesClient.hjparams.size());
                 } else {
                     System.out.println("weld params is empty, skip save (sn:" + sn + ")");
                 }
@@ -119,6 +132,48 @@ public class PlcUtil {
         }
     }
 
+    public static Boolean getAStart(S7PLC s7PLC) {
+        return getWeldStatus(s7PLC, "A") == 1;
+    }
+
+    public static Boolean getAFinish(S7PLC s7PLC) {
+        return getWeldStatus(s7PLC, "A") == 2;
+    }
+
+    public static void getStatusA(S7PLC s7PLC) {
+        int status = getWeldStatus(s7PLC, "A");
+        if (MesClient.tjFlaga == 1) {
+            if (status == 1) {
+                MesClient.curFlag = "A";
+                MesClient.tjFlaga = 2;
+                MesClient.pxstatus1.setText("A:\u8bbe\u5907\u8fd0\u884c\u4e2d");
+                if (MesClient.curSna == null || MesClient.curSna.isEmpty()) {
+                    MesClient.curSna = MesClient.product_sn.getText();
+                }
+                changeEnable(s7PLC, false, "A");
+            } else if (!getEnable(s7PLC, "A")) {
+                changeEnable(s7PLC, true, "A");
+            }
+        } else if (MesClient.tjFlaga == 2 && status == 2) {
+            finishA(s7PLC);
+        }
+    }
+
+    private static void finishA(S7PLC s7PLC) {
+        MesClient.tjFlaga = 3;
+        MesClient.pxstatus1.setText("A:\u8bbe\u5907\u8fd0\u884c\u7ed3\u675f,\u63d0\u4ea4\u7ed3\u679c\u4e2d");
+        MesClient.finish_ok_bt.setEnabled(true);
+        changeEnable(s7PLC, false, "A");
+        ackWeldStatus(s7PLC, "A");
+        saveCurrentParams();
+
+        Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn.getText(), "OK", MesClient.user20, MesClient.side());
+        if (!sendret) {
+            MesClient.pxstatus1.setText("A:\u7ed3\u679c\u4e0a\u4f20MES\u5931\u8d25");
+            MesClient.tjStatusa = 1;
+        }
+    }
+
     public static Boolean getBStart(S7PLC s7PLC) {
         return getWeldStatus(s7PLC, "B") == 1;
     }
@@ -133,7 +188,7 @@ public class PlcUtil {
             if (status == 1) {
                 MesClient.curFlag = "B";
                 MesClient.tjFlagb = 2;
-                MesClient.pxstatus2.setText("B:设备运行中");
+                MesClient.pxstatus2.setText("B:\u8bbe\u5907\u8fd0\u884c\u4e2d");
                 if (MesClient.curSnb == null || MesClient.curSnb.isEmpty()) {
                     MesClient.curSnb = MesClient.product_sn2.getText();
                 }
@@ -148,22 +203,21 @@ public class PlcUtil {
 
     private static void finishB(S7PLC s7PLC) {
         MesClient.tjFlagb = 3;
-        MesClient.pxstatus2.setText("B:设备运行结束,提交结果中");
+        MesClient.pxstatus2.setText("B:\u8bbe\u5907\u8fd0\u884c\u7ed3\u675f,\u63d0\u4ea4\u7ed3\u679c\u4e2d");
         MesClient.finish_ng_bt.setEnabled(true);
         changeEnable(s7PLC, false, "B");
         ackWeldStatus(s7PLC, "B");
         saveCurrentParams();
 
-        String oprno = MesClient.mes_gw + MesClient.mes_gwflag;  // OP060A
-        Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn2.getText(), "OK", MesClient.user20, oprno);
+        Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient, MesClient.product_sn2.getText(), "OK", MesClient.user20, MesClient.side());
         if (!sendret) {
-            MesClient.pxstatus2.setText("B:结果上传MES失败");
+            MesClient.pxstatus2.setText("B:\u7ed3\u679c\u4e0a\u4f20MES\u5931\u8d25");
             MesClient.tjStatusb = 1;
         }
     }
 
     public static Boolean changeEnable(S7PLC s7PLC, Boolean result) {
-        return changeEnable(s7PLC, result, "B");
+        return changeEnable(s7PLC, result, MesClient.side());
     }
 
     public static Boolean changeEnable(S7PLC s7PLC, Boolean result, String side) {
@@ -177,23 +231,15 @@ public class PlcUtil {
     }
 
     public static Boolean getEnable(S7PLC s7PLC) {
-        return getEnable(s7PLC, "B");
+        return getEnable(s7PLC, MesClient.side());
     }
 
     public static Boolean getEnable(S7PLC s7PLC, String side) {
         return readBoolean(s7PLC, enableAddress(side));
     }
 
-    public static String getCurAside(S7PLC s7PLC) {
-        try {
-            boolean bPosition = s7PLC.readBoolean(B_POSITION);
-            if (bPosition) {
-                return "B";
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
+    public static int getProgranNoA(S7PLC s7PLC) {
+        return 0;
     }
 
     public static int getProgranNoB(S7PLC s7PLC) {
@@ -213,11 +259,11 @@ public class PlcUtil {
     }
 
     private static String enableAddress(String side) {
-        return B_ENABLE;  // 只有 B 面
+        return "B".equals(side) ? B_ENABLE : A_ENABLE;
     }
 
     private static String statusAddress(String side) {
-        return B_STATUS;  // 只有 B 面
+        return "B".equals(side) ? B_STATUS : A_STATUS;
     }
 
     private static boolean readBoolean(S7PLC s7PLC, String address) {

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

@@ -1,7 +1,7 @@
-mes.gw=OP060
+mes.gw=OP120
 #mes.server_ip=127.0.0.1
 mes.server_ip=192.168.114.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT
-mes.gwflag=B
+mes.gwflag=A