Browse Source

新增气密泄露点位记

yutianhao 5 giờ trước cách đây
mục cha
commit
56e1824084

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

@@ -230,7 +230,8 @@ public class DataUtil {
                     + "&cs=" + URLEncoder.encode("", "UTF-8")
                     + "&leakRate=" + URLEncoder.encode("", "UTF-8")
                     + "&leakRateUnit=" + URLEncoder.encode("", "UTF-8")
-                    + "&type=" + URLEncoder.encode("", "UTF-8");
+                    + "&type=" + URLEncoder.encode("", "UTF-8")
+                    + "&ngLeakPoints=" + URLEncoder.encode(testParam.getNgLeakPoints() !=    null ? testParam.getNgLeakPoints() : "", "UTF-8");
 
             log.info("params=" + params);
             String result = doPost(url, params);

+ 148 - 0
src/com/mes/ui/LeakNgPointDialog.java

@@ -0,0 +1,148 @@
+package com.mes.ui;
+
+import javax.swing.*;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.TitledBorder;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 漏点NG点位选择对话框:B1-B8 / C1-C21 / D1 多选 + 其它原因。
+ */
+public class LeakNgPointDialog extends JDialog {
+
+    private final List<JCheckBox> pointChecks = new ArrayList<>();
+    private final JTextArea otherReasonArea;
+    private String selectedValue;
+    private boolean confirmed;
+
+    public LeakNgPointDialog(Frame owner) {
+        super(owner, "漏点NG点位", true);
+        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+        setResizable(true);
+
+        JPanel root = new JPanel(new BorderLayout(10, 10));
+        root.setBorder(new EmptyBorder(12, 12, 12, 12));
+
+        JPanel pointsPanel = new JPanel();
+        pointsPanel.setLayout(new BoxLayout(pointsPanel, BoxLayout.Y_AXIS));
+
+        pointsPanel.add(buildPointGroup("B点位", "B", 8));
+        pointsPanel.add(Box.createVerticalStrut(8));
+        pointsPanel.add(buildPointGroup("C点位", "C", 21));
+        pointsPanel.add(Box.createVerticalStrut(8));
+        pointsPanel.add(buildPointGroup("D点位", "D", 1));
+
+        JScrollPane pointsScroll = new JScrollPane(pointsPanel);
+        pointsScroll.setBorder(null);
+        pointsScroll.getVerticalScrollBar().setUnitIncrement(16);
+
+        JPanel otherPanel = new JPanel(new BorderLayout(6, 6));
+        otherPanel.setBorder(new TitledBorder("其它原因"));
+        otherReasonArea = new JTextArea(3, 40);
+        otherReasonArea.setLineWrap(true);
+        otherReasonArea.setWrapStyleWord(true);
+        otherReasonArea.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        otherPanel.add(new JScrollPane(otherReasonArea), BorderLayout.CENTER);
+
+        JPanel center = new JPanel(new BorderLayout(8, 8));
+        center.add(pointsScroll, BorderLayout.CENTER);
+        center.add(otherPanel, BorderLayout.SOUTH);
+
+        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 8));
+        JButton confirmBtn = new JButton("确认");
+        confirmBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        confirmBtn.setPreferredSize(new Dimension(140, 48));
+        confirmBtn.addActionListener(e -> onConfirm());
+
+        JButton cancelBtn = new JButton("取消");
+        cancelBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        cancelBtn.setPreferredSize(new Dimension(140, 48));
+        cancelBtn.addActionListener(e -> {
+            confirmed = false;
+            selectedValue = null;
+            dispose();
+        });
+
+        buttons.add(confirmBtn);
+        buttons.add(cancelBtn);
+
+        JLabel tip = new JLabel("请至少勾选一个点位,或填写其它原因(可多选)");
+        tip.setFont(new Font("微软雅黑", Font.PLAIN, 14));
+        tip.setForeground(new Color(120, 120, 120));
+
+        root.add(tip, BorderLayout.NORTH);
+        root.add(center, BorderLayout.CENTER);
+        root.add(buttons, BorderLayout.SOUTH);
+
+        setContentPane(root);
+        setSize(780, 640);
+        setLocationRelativeTo(owner);
+    }
+
+    private JPanel buildPointGroup(String title, String prefix, int count) {
+        JPanel group = new JPanel(new BorderLayout());
+        group.setBorder(new TitledBorder(title));
+
+        JPanel grid = new JPanel(new GridLayout(0, 7, 8, 6));
+        for (int i = 1; i <= count; i++) {
+            String label = prefix + i;
+            JCheckBox checkBox = new JCheckBox(label);
+            checkBox.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+            checkBox.setActionCommand(label);
+            pointChecks.add(checkBox);
+            grid.add(checkBox);
+        }
+        group.add(grid, BorderLayout.CENTER);
+        return group;
+    }
+
+    private void onConfirm() {
+        List<String> points = new ArrayList<>();
+        for (JCheckBox checkBox : pointChecks) {
+            if (checkBox.isSelected()) {
+                points.add(checkBox.getActionCommand());
+            }
+        }
+        String other = otherReasonArea.getText() == null ? "" : otherReasonArea.getText().trim();
+        if (points.isEmpty() && other.isEmpty()) {
+            JOptionPane.showMessageDialog(this, "请至少勾选一个点位,或填写其它原因", "提示",
+                    JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        StringBuilder sb = new StringBuilder();
+        if (!points.isEmpty()) {
+            sb.append(String.join(",", points));
+        }
+        if (!other.isEmpty()) {
+            if (sb.length() > 0) {
+                sb.append("|");
+            }
+            sb.append(other);
+        }
+        selectedValue = sb.toString();
+        confirmed = true;
+        dispose();
+    }
+
+    public boolean isConfirmed() {
+        return confirmed;
+    }
+
+    public String getSelectedValue() {
+        return selectedValue;
+    }
+
+    /**
+     * 弹出对话框;确认返回拼好的漏点字符串,取消返回 null。
+     */
+    public static String showDialog(Frame owner) {
+        LeakNgPointDialog dialog = new LeakNgPointDialog(owner);
+        dialog.setVisible(true);
+        if (dialog.isConfirmed()) {
+            return dialog.getSelectedValue();
+        }
+        return null;
+    }
+}

+ 48 - 2
src/com/mes/ui/MesClient.java

@@ -70,6 +70,7 @@ public class MesClient extends JFrame {
 
     public static String user20 = "";
     public static boolean mes_enable = true; // true=MES开启
+    private static TestParam pendingNgTestParam = null;
 
     public static JFrame welcomeWin;
 
@@ -304,6 +305,7 @@ public class MesClient extends JFrame {
     public static void resetScanA() {
         work_status = 0;
         check_quality_result = false;
+        pendingNgTestParam = null;
         MesClient.finish_ok_bt.setEnabled(false);
         MesClient.finish_ng_bt.setEnabled(false);
         product_sn.setText("");
@@ -751,10 +753,52 @@ public class MesClient extends JFrame {
     }
 
     /**
+     * 设备测试结束后统一入口:OK 自动存库上传;NG(MES开)先填漏点再存库上传。
+     */
+    public static void onDeviceTestFinished(TestParam testParam) {
+        afterTestSaveAndUpload(testParam);
+    }
+
+    /**
+     * NG 点击后:弹出漏点对话框,确认后带 ngLeakPoints 存库上传。
+     */
+    public static void submitPendingNgWithLeakPoints() {
+        if (pendingNgTestParam == null) {
+            return;
+        }
+        String ngLeakPoints = LeakNgPointDialog.showDialog(mesClientFrame);
+        if (ngLeakPoints == null) {
+            MesClient.finish_ng_bt.setEnabled(true);
+            MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
+            return;
+        }
+        pendingNgTestParam.setNgLeakPoints(ngLeakPoints);
+        afterTestSaveAndUpload(pendingNgTestParam);
+    }
+
+    /**
      * 本地存库后提交MES,成功则复位扫码。
+     * NG 且尚未填写漏点点位时(MES开启)先挂起,不入库不上传。
      */
     public static boolean afterTestSaveAndUpload(TestParam testParam) {
         try {
+            String result = testParam.getResult();
+            String leakPoints = testParam.getNgLeakPoints();
+            boolean isOk = result != null && result.equalsIgnoreCase("OK");
+            boolean hasLeakPoints = leakPoints != null && !leakPoints.trim().isEmpty();
+            if (!isOk && !hasLeakPoints && mes_enable) {
+                pendingNgTestParam = testParam;
+                MesClient.finish_ng_bt.setEnabled(true);
+                MesClient.finish_ok_bt.setEnabled(false);
+                MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
+                if (SwingUtilities.isEventDispatchThread()) {
+                    submitPendingNgWithLeakPoints();
+                } else {
+                    SwingUtilities.invokeLater(MesClient::submitPendingNgWithLeakPoints);
+                }
+                return false;
+            }
+
             String testDate = testParam.getCreateTime();
             if (testDate == null || testDate.isEmpty()) {
                 testDate = DateLocalUtils.getCurrentTime();
@@ -1143,14 +1187,16 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-
+                if (pendingNgTestParam != null) {
+                    submitPendingNgWithLeakPoints();
+                }
             }
         });
         finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
         finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
         finish_ng_bt.setBounds(508, 291, 240, 80);
         finish_ng_bt.setEnabled(false);
-//        indexPanelA.add(finish_ng_bt);
+        indexPanelA.add(finish_ng_bt);
 
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);

+ 1 - 20
src/com/mes/util/SerialPortUtils.java

@@ -1,10 +1,8 @@
 package com.mes.util;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.fazecast.jSerialComm.SerialPort;
 import com.fazecast.jSerialComm.SerialPortDataListener;
 import com.fazecast.jSerialComm.SerialPortEvent;
-import com.mes.ui.DataUtil;
 import com.mes.ui.MesClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -177,24 +175,7 @@ public class SerialPortUtils {
 
                                                         String testDate = DateLocalUtils.getCurrentTime();
                                                         testParam.setCreateTime(testDate);
-                                                        JdbcUtils.insertTestRecord(testParam);
-
-                                                        if(MesClient.mes_enable){ // MES开启
-                                                            JSONObject retObj = DataUtil.qmResultData(testParam);
-                                                            if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
-                                                                MesClient.resetScanA();
-                                                                MesClient.setMenuStatus("测试结果上传成功,请扫下一件",0);
-                                                            }else{
-                                                                MesClient.setMenuStatus("测试结果上传失败,请重试",-1);
-                                                                return;
-                                                            }
-                                                        }else{
-                                                            MesClient.resetScanA();
-                                                        }
-
-                                                        if(MesClient.configParam.getPrintLabel().equals("是") && lastRet.equals("OK")){
-                                                            PrintUtil.printLabel(testParam.getSn(),testParam.getParam1()+testParam.getParam2(),testParam.getParam3()+testParam.getParam4(),testDate);
-                                                        }
+                                                        MesClient.afterTestSaveAndUpload(testParam);
 
                                                     } catch (Exception e) {
                                                         log.info(e.getMessage());

+ 10 - 0
src/com/mes/util/TestParam.java

@@ -17,6 +17,7 @@ public class TestParam {
     public String result;
     public String remark;
     public String deviceType;
+    public String ngLeakPoints;
 
     public Integer getId() {
         return id;
@@ -138,6 +139,14 @@ public class TestParam {
         this.lineSn = lineSn;
     }
 
+    public String getNgLeakPoints() {
+        return ngLeakPoints;
+    }
+
+    public void setNgLeakPoints(String ngLeakPoints) {
+        this.ngLeakPoints = ngLeakPoints;
+    }
+
     @Override
     public String toString() {
         return "TestParam{" +
@@ -156,6 +165,7 @@ public class TestParam {
                 ", result='" + result + '\'' +
                 ", remark='" + remark + '\'' +
                 ", deviceType='" + deviceType + '\'' +
+                ", ngLeakPoints='" + ngLeakPoints + '\'' +
                 '}';
     }
 }

+ 1 - 20
src/com/mes/util/WorkTimer.java

@@ -1,7 +1,5 @@
 package com.mes.util;
 
-import com.alibaba.fastjson2.JSONObject;
-import com.mes.ui.DataUtil;
 import com.mes.ui.MesClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -111,24 +109,7 @@ public class WorkTimer {
                         testParam.setDeviceType("ateq");
                         testParam.setRemark("");
                         testParam.setCreateTime(testDate);
-                        JdbcUtils.insertTestRecord(testParam);
-
-                        if(MesClient.mes_enable){ // MES开启
-                            JSONObject retObj = DataUtil.qmResultData(testParam);
-                            if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
-                                MesClient.resetScanA();
-                                MesClient.setMenuStatus("测试结果上传成功,请扫下一件",0);
-                            }else{
-                                MesClient.setMenuStatus("测试结果上传失败,请重试",-1);
-                                return;
-                            }
-                        }else{
-                            MesClient.resetScanA();
-                        }
-
-                        if(MesClient.configParam.getPrintLabel().equals("是") && lastRet.equals("OK")){
-                            PrintUtil.printLabel(testParam.getSn(),testParam.getParam1()+testParam.getParam2(),testParam.getParam3()+testParam.getParam4(),testDate);
-                        }
+                        MesClient.afterTestSaveAndUpload(testParam);
                     }
                 }
             } catch (Exception e) {