wangxichen 6 日 前
親
コミット
1df9cda183
1 ファイル変更、54 行追加、13 行削除
  1. 54 13
      src/com/mes/ui/MesClient.java

+ 54 - 13
src/com/mes/ui/MesClient.java

@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -527,12 +528,18 @@ public class MesClient extends JFrame {
         op100QtyLabel.setBounds(520, 15, 210, 40);
         indexPanelA.add(op100QtyLabel);
 
-        remainingQtyLabel = new JLabel("差值:0(已打完)");
+        remainingQtyLabel = new JLabel("差值:0");
         remainingQtyLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
         remainingQtyLabel.setForeground(Color.GREEN);
-        remainingQtyLabel.setBounds(730, 15, 270, 40);
+        remainingQtyLabel.setBounds(730, 15, 150, 40);
         indexPanelA.add(remainingQtyLabel);
 
+        JButton refreshQtyButton = new JButton("刷新");
+        refreshQtyButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        refreshQtyButton.setBounds(880, 19, 90, 32);
+        refreshQtyButton.addActionListener(e -> refreshPlanQty(refreshQtyButton));
+        indexPanelA.add(refreshQtyButton);
+
         f_scan_data_bt_1 = new JButton("扫码");
         f_scan_data_bt_1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
@@ -740,6 +747,43 @@ public class MesClient extends JFrame {
         }, 500, 3000);
     }
 
+    private static void refreshPlanQty(JButton button) {
+        button.setEnabled(false);
+        button.setText("刷新中");
+        button.setToolTipText(null);
+        new SwingWorker<JSONObject, Void>() {
+            @Override
+            protected JSONObject doInBackground() {
+                return DataUtil.getHmbPlanQty();
+            }
+
+            @Override
+            protected void done() {
+                String message = "计划数量刷新失败";
+                try {
+                    JSONObject result = get();
+                    if (result != null) {
+                        JSONObject qty = result.getJSONObject("planQty");
+                        if (qty != null) {
+                            displayPlanQty(qty);
+                            message = null;
+                        } else if (result.getString("message") != null) {
+                            message = result.getString("message");
+                        }
+                    }
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                } catch (ExecutionException e) {
+                    log.error("计划数量刷新异常", e);
+                } finally {
+                    button.setText(message == null ? "刷新" : "重试");
+                    button.setToolTipText(message);
+                    button.setEnabled(true);
+                }
+            }
+        }.execute();
+    }
+
     public static void updatePlanQty(JSONObject retObj) {
         JSONObject qty = retObj.getJSONObject("planQty");
         if(qty == null) {
@@ -754,20 +798,17 @@ public class MesClient extends JFrame {
         }
         planStop = false;
         nextRetryTime = 0;
+        SwingUtilities.invokeLater(() -> displayPlanQty(qty));
+    }
+
+    private static void displayPlanQty(JSONObject qty) {
         int op035Qty = qty.getIntValue("op035Qty");
         int op100Qty = qty.getIntValue("op100Qty");
         int remainingQty = qty.getIntValue("remainingQty");
-        SwingUtilities.invokeLater(() -> {
-            op035QtyLabel.setText("OP035上线:" + op035Qty);
-            op100QtyLabel.setText("OP100已打码:" + op100Qty);
-            if(remainingQty > 0) {
-                remainingQtyLabel.setText("差值:" + remainingQty + "(要打完)");
-                remainingQtyLabel.setForeground(Color.RED);
-            } else {
-                remainingQtyLabel.setText("差值:0(已打完)");
-                remainingQtyLabel.setForeground(Color.GREEN);
-            }
-        });
+        op035QtyLabel.setText("OP035上线:" + op035Qty);
+        op100QtyLabel.setText("OP100已打码:" + op100Qty);
+        remainingQtyLabel.setText("差值:" + remainingQty);
+        remainingQtyLabel.setForeground(remainingQty > 0 ? Color.RED : Color.GREEN);
     }
 
     public static void setMenuStatus(String msg,int error){