Bladeren bron

新增气密泄露点位记

yutianhao 2 dagen geleden
bovenliggende
commit
aa7d9a1826
3 gewijzigde bestanden met toevoegingen van 254 en 29 verwijderingen
  1. 5 0
      src/com/mes/ui/DataUtil.java
  2. 148 0
      src/com/mes/ui/LeakNgPointDialog.java
  3. 101 29
      src/com/mes/ui/MesClient.java

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

@@ -47,6 +47,10 @@ public class DataUtil {
     }
 
     public static JSONObject sendQmResult(String sn, String user, QmPlcPoint.QmTestData testData){
+        return sendQmResult(sn, user, testData, null);
+    }
+
+    public static JSONObject sendQmResult(String sn, String user, QmPlcPoint.QmTestData testData, String ngLeakPoints){
         try{
             String mes_server_ip = MesClient.mes_server_ip;
             String oprno = MesClient.mes_gw == null ? "" : MesClient.mes_gw.trim();
@@ -87,6 +91,7 @@ public class DataUtil {
             appendUrlParam(params, "title", titleBase64);
             appendUrlParam(params, "remark", remark);
             appendUrlParam(params, "deviceType", "S7-200SMART");
+            appendUrlParam(params, "ngLeakPoints", ngLeakPoints);
 
             log.info("qmresult params="+params);
             String response = doPost(url, params.toString());

+ 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;
+    }
+}

+ 101 - 29
src/com/mes/ui/MesClient.java

@@ -112,6 +112,9 @@ public class MesClient extends JFrame {
     public static Timer plcMonitorTimer;
     private static boolean lastDataReady = false;
     private static boolean jobSubmitting = false;
+    /** 气密仪器判 NG 后缓存,待工人点 NG 并填写漏点后再上传 */
+    private static String pendingQmSn = null;
+    private static QmPlcPoint.QmTestData pendingQmTestData = null;
 
     public static void main(String[] args) {
         if (ClientUpgrade.handleInstallArgs(args)) {
@@ -443,6 +446,7 @@ public class MesClient extends JFrame {
         check_quality_result = false;
         jobSubmitting = false;
         lastDataReady = false;
+        clearPendingQmNg();
         PlcService.setMesConnected(false);
         PlcService.setCollectComplete(false);
         PlcService.clearScanCode();
@@ -523,7 +527,7 @@ public class MesClient extends JFrame {
     }
 
     private static void pollPlcSignals() {
-        if (work_status != 1 || jobSubmitting) {
+        if (work_status != 1 || jobSubmitting || hasPendingQmNg()) {
             return;
         }
         try {
@@ -554,7 +558,7 @@ public class MesClient extends JFrame {
             return;
         }
         jobSubmitting = true;
-        SwingUtilities.invokeLater(() -> setMenuStatus("气密测试完成,正在上传结果...", 0));
+        SwingUtilities.invokeLater(() -> setMenuStatus("气密测试完成,正在处理结果...", 0));
 
         try {
             String rawData = PlcService.readMesData();
@@ -566,37 +570,24 @@ public class MesClient extends JFrame {
                 return;
             }
 
-            getUser();
-            JSONObject retObj = DataUtil.sendQmResult(sn, user20, testData);
-            if (retObj == null) {
+            String result = testData.result == null ? "NG" : testData.result.trim();
+            // 仪器判 NG:直接弹出漏点页
+            if (!"OK".equalsIgnoreCase(result)) {
+                pendingQmSn = sn;
+                pendingQmTestData = testData;
                 jobSubmitting = false;
-                SwingUtilities.invokeLater(() -> setMenuStatus("气密结果上传失败,请重试", -1));
-                return;
-            }
-            if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
-                if (!PlcService.pulseCollectComplete()) {
-                    jobSubmitting = false;
-                    SwingUtilities.invokeLater(() -> setMenuStatus("结果已上传,但V2800.3脉冲写入失败", -1));
-                    return;
-                }
-                lastDataReady = false;
-                if (!PlcService.setMesConnected(false)) {
-                    jobSubmitting = false;
-                    SwingUtilities.invokeLater(() -> setMenuStatus("结果已上传,但V2800.7写入失败", -1));
-                    return;
-                }
                 SwingUtilities.invokeLater(() -> {
-                    resetScanA();
-                    setMenuStatus("气密结果提交成功,请扫下一件", 0);
-                    scan_type = 1;
-                    scanBarcode();
+                    finish_ok_bt.setEnabled(false);
+                    finish_ng_bt.setEnabled(true);
+                    setMenuStatus("气密 NG,请选择漏点点位", -1);
+                    submitPendingQmNgWithLeakPoints();
                 });
-            } else {
-                jobSubmitting = false;
-                String message = retObj.getString("message");
-                SwingUtilities.invokeLater(() -> setMenuStatus(
-                        message == null || message.isEmpty() ? "气密结果上传失败" : message, -1));
+                return;
             }
+
+            getUser();
+            JSONObject retObj = DataUtil.sendQmResult(sn, user20, testData);
+            finishQmUpload(retObj);
         } catch (Exception e) {
             jobSubmitting = false;
             log.info("处理气密数据异常: {}", e.getMessage());
@@ -604,6 +595,83 @@ public class MesClient extends JFrame {
         }
     }
 
+    private static void clearPendingQmNg() {
+        pendingQmSn = null;
+        pendingQmTestData = null;
+    }
+
+    private static boolean hasPendingQmNg() {
+        return pendingQmSn != null && pendingQmTestData != null;
+    }
+
+    /** 上传气密结果后的公共收尾:PLC 脉冲、复位扫码 */
+    private static void finishQmUpload(JSONObject retObj) {
+        if (retObj == null) {
+            jobSubmitting = false;
+            SwingUtilities.invokeLater(() -> setMenuStatus("气密结果上传失败,请重试", -1));
+            return;
+        }
+        if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
+            if (!PlcService.pulseCollectComplete()) {
+                jobSubmitting = false;
+                SwingUtilities.invokeLater(() -> setMenuStatus("结果已上传,但V2800.3脉冲写入失败", -1));
+                return;
+            }
+            lastDataReady = false;
+            if (!PlcService.setMesConnected(false)) {
+                jobSubmitting = false;
+                SwingUtilities.invokeLater(() -> setMenuStatus("结果已上传,但V2800.7写入失败", -1));
+                return;
+            }
+            clearPendingQmNg();
+            SwingUtilities.invokeLater(() -> {
+                resetScanA();
+                setMenuStatus("气密结果提交成功,请扫下一件", 0);
+                scan_type = 1;
+                scanBarcode();
+            });
+        } else {
+            jobSubmitting = false;
+            String message = retObj.getString("message");
+            SwingUtilities.invokeLater(() -> setMenuStatus(
+                    message == null || message.isEmpty() ? "气密结果上传失败" : message, -1));
+        }
+    }
+
+    /** 打开漏点页并上传(仪器 NG 后直接调用,或取消后点 NG 重开) */
+    private static void submitPendingQmNgWithLeakPoints() {
+        if (!hasPendingQmNg()) {
+            setMenuStatus("无待填写的气密NG数据", -1);
+            return;
+        }
+        if (jobSubmitting) {
+            return;
+        }
+        String ngLeakPoints = LeakNgPointDialog.showDialog(mesClientFrame);
+        if (ngLeakPoints == null) {
+            finish_ng_bt.setEnabled(true);
+            setMenuStatus("气密 NG,请选择漏点点位", -1);
+            return;
+        }
+
+        jobSubmitting = true;
+        setMenuStatus("气密NG结果上传中...", 0);
+        final String sn = pendingQmSn;
+        final QmPlcPoint.QmTestData testData = pendingQmTestData;
+        final String leakPoints = ngLeakPoints;
+        Executors.newSingleThreadExecutor().execute(() -> {
+            try {
+                getUser();
+                JSONObject retObj = DataUtil.sendQmResult(sn, user20, testData, leakPoints);
+                finishQmUpload(retObj);
+            } catch (Exception e) {
+                jobSubmitting = false;
+                log.info("上传气密NG漏点异常: {}", e.getMessage());
+                SwingUtilities.invokeLater(() -> setMenuStatus("上传气密NG漏点异常: " + e.getMessage(), -1));
+            }
+        });
+    }
+
     //获取用户20位
     public static void getUser() {
         user20 = user_menu.getText().toString();
@@ -1001,6 +1069,10 @@ public class MesClient extends JFrame {
         finish_ng_bt.setEnabled(false);
         finish_ng_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                if (hasPendingQmNg()) {
+                    submitPendingQmNgWithLeakPoints();
+                    return;
+                }
                 if(work_status == 1 && check_quality_result){
                     getUser();
                     String sn = MesClient.product_sn.getText().trim();