Преглед изворни кода

添加定时任务定时获取工件码

dkk пре 2 недеља
родитељ
комит
906ba35cfa
2 измењених фајлова са 33 додато и 1 уклоњено
  1. 1 1
      src/com/mes/ui/DataUtil.java
  2. 32 0
      src/com/mes/ui/WorkStationPanel.java

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

@@ -23,7 +23,7 @@ public class DataUtil {
             String url = "http://"+serverIp+":8980/js/a/mes/mesProductRecord/getCurSn";
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&__sid="+MesClient.sessionid;
             JSONObject result = JSONObject.parseObject(doPost(url, params));
-            log.info("请求参数:"+params);
+//            log.info("请求参数:"+params);
             return result;
         } catch (Exception e) {
             log.info("e="+e.getMessage());

+ 32 - 0
src/com/mes/ui/WorkStationPanel.java

@@ -35,6 +35,8 @@ public class WorkStationPanel extends JPanel {
     public static Object[][] rowData = null;
     
     private Timer heartBeatTimer;
+    private Timer getSnBeatTimer;
+
     private boolean iconREDFlag = true;
 
     public WorkStationPanel(String gw, String gwDes, String lineSn, String serverIp) {
@@ -44,6 +46,7 @@ public class WorkStationPanel extends JPanel {
         this.serverIp = serverIp;
         initUI();
         startHeartBeatTimer();
+        startGetCurSn();
     }
 
     private void initUI() {
@@ -332,6 +335,35 @@ public class WorkStationPanel extends JPanel {
                     iconREDFlag = true;
                 }
             }
+
+        }, 100, 1000);
+    }
+
+    private void startGetCurSn(){
+        if (getSnBeatTimer != null) {
+            getSnBeatTimer.cancel();
+        }
+        getSnBeatTimer = new Timer();
+        getSnBeatTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                if (workStatus == 1) {
+                    return;
+                } else if (workStatus == 0) {
+                    JSONObject result = DataUtil.getCurSn(gw, serverIp, lineSn);
+                    // 正常处理结果
+                    if (result.containsKey("data")) {
+                        String data = result.getString("data");
+                        if (data != null && !data.isEmpty()) {
+                            productSnField.setText(data);
+                            checkQuality(data);
+                        } else {
+                            JOptionPane.showMessageDialog(WorkStationPanel.this, "获取工件码为空", "提示", JOptionPane.INFORMATION_MESSAGE);
+                        }
+                    }
+                }
+            }
+
         }, 100, 1000);
     }