瀏覽代碼

切换工位号

wangxichen 1 天之前
父節點
當前提交
a190867cc1
共有 5 個文件被更改,包括 168 次插入43 次删除
  1. 3 0
      config/runtime.properties
  2. 10 31
      src/com/mes/ui/DataUtil.java
  3. 81 2
      src/com/mes/ui/MesClient.java
  4. 9 10
      src/com/mes/ui/OprnoUtil.java
  5. 65 0
      src/com/mes/ui/StationConfig.java

+ 3 - 0
config/runtime.properties

@@ -0,0 +1,3 @@
+#runtime station config
+#Mon Jul 13 14:26:33 CST 2026
+mes.gw=OP130B

+ 10 - 31
src/com/mes/ui/DataUtil.java

@@ -9,7 +9,6 @@ import java.io.*;
 import java.net.HttpURLConnection;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URL;
-import java.util.Properties;
 
 
 public class DataUtil {
 public class DataUtil {
 
 
@@ -129,16 +128,11 @@ public class DataUtil {
             String msgType = "MQDW";
             String msgType = "MQDW";
             String craft = "100000";
             String craft = "100000";
             String params = "";
             String params = "";
-            String enconding = "UTF-8";
-            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
-            Properties pro = new Properties();
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
-            pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
+            String gw = "GW"+rightPad(MesClient.mes_gw, 8);
             String start = "aaaabbbbbABW";
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad("", 2);
             String reslx = "LX" + rightPad("", 2);
-            String id = pro.getProperty("mes.line_sn") + rightPad(sn, 36);
+            String id = MesClient.mes_line_sn + rightPad(sn, 36);
             String rs = "RS"+ rightPad(ret, 2);
             String rs = "RS"+ rightPad(ret, 2);
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
@@ -154,16 +148,11 @@ 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){
     public static Boolean sendMessage(NettyClient nettyClient,String msgType,String craft,String lx,String sn,String result,String user,String paramNums,String params){
         try{
         try{
-            String enconding = "UTF-8";
-            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
-            Properties pro = new Properties();
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
-            pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 8);
+            String gw = "GW"+rightPad(MesClient.mes_gw, 8);
             String start = "aaaabbbbbABW";
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             String gy = "GY" + rightPad(craft, 6);
             String reslx = "LX" + rightPad(lx, 2);
             String reslx = "LX" + rightPad(lx, 2);
-            String id = pro.getProperty("mes.line_sn") + rightPad(sn, 36);
+            String id = MesClient.mes_line_sn + rightPad(sn, 36);
             String rs = "RS"+ rightPad(result, 2);
             String rs = "RS"+ rightPad(result, 2);
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
@@ -192,14 +181,9 @@ public class DataUtil {
 
 
     public static JSONObject getBindMaterail() {
     public static JSONObject getBindMaterail() {
         try{
         try{
-            String enconding = "UTF-8";
-            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
-            Properties pro = new Properties();
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
-            pro.load(br);
-            String mes_server_ip = pro.getProperty("mes.server_ip");
-            String oprno = pro.getProperty("mes.gw").trim();
-            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String mes_server_ip = MesClient.mes_server_ip;
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.mes_line_sn.trim();
             String url = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
             String url = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
             System.out.println("params="+params);
             System.out.println("params="+params);
@@ -218,14 +202,9 @@ public class DataUtil {
 
 
     public static JSONObject saveBindMaterail(String batchSn,String craft,String materialId,String type) {
     public static JSONObject saveBindMaterail(String batchSn,String craft,String materialId,String type) {
         try{
         try{
-            String enconding = "UTF-8";
-            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
-            Properties pro = new Properties();
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
-            pro.load(br);
-            String mes_server_ip = pro.getProperty("mes.server_ip");
-            String oprno = pro.getProperty("mes.gw").trim();
-            String lineSn = pro.getProperty("mes.line_sn").trim();
+            String mes_server_ip = MesClient.mes_server_ip;
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.mes_line_sn.trim();
             String url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
             String url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&batchSn="+batchSn+"&craft="+craft+"&materialId="+materialId+"&type="+type;
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn+"&batchSn="+batchSn+"&craft="+craft+"&materialId="+materialId+"&type="+type;
             System.out.println("params="+params);
             System.out.println("params="+params);

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

@@ -141,7 +141,7 @@ public class MesClient extends JFrame {
         Properties pro = new Properties();
         Properties pro = new Properties();
         BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
         BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
         pro.load(br);
         pro.load(br);
-        mes_gw =  pro.getProperty("mes.gw");
+        mes_gw =  StationConfig.loadRuntimeGw(pro.getProperty("mes.gw"));
         mes_server_ip = pro.getProperty("mes.server_ip");
         mes_server_ip = pro.getProperty("mes.server_ip");
         mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
         mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
         mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
         mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
@@ -440,7 +440,15 @@ public class MesClient extends JFrame {
             }
             }
         });
         });
         settingMenu.add(resetTcpMenu_1);
         settingMenu.add(resetTcpMenu_1);
-
+        JMenuItem switchStationMenu = new JMenuItem("切换工位");
+        switchStationMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
+        switchStationMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        switchStationMenu.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                showStationSwitchDialog();
+            }
+        });
+        settingMenu.add(switchStationMenu);
         contentPane = new JPanel();
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);
         setContentPane(contentPane);
@@ -669,6 +677,77 @@ public class MesClient extends JFrame {
         MesClient.status_menu.setText(msg);
         MesClient.status_menu.setText(msg);
     }
     }
 
 
+
+    private static void showStationSwitchDialog() {
+        String[] stations = new String[OprnoUtil.t9oprnos.length];
+        int selectedStationIndex = 0;
+        for (int i = 0; i < OprnoUtil.t9oprnos.length; i++) {
+            String oprno = OprnoUtil.t9oprnos[i];
+            stations[i] = oprno + " - " + OprnoUtil.t9oprnodes[i];
+            if (mes_gw != null && mes_gw.startsWith(oprno)) {
+                selectedStationIndex = i;
+            }
+        }
+
+        String currentSuffix = "A";
+        if (mes_gw != null && mes_gw.length() > 0) {
+            String suffix = mes_gw.substring(mes_gw.length() - 1);
+            if ("B".equalsIgnoreCase(suffix)) {
+                currentSuffix = "B";
+            }
+        }
+
+        JComboBox<String> stationComboBox = new JComboBox<String>(stations);
+        stationComboBox.setSelectedIndex(selectedStationIndex);
+        stationComboBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+
+        JComboBox<String> suffixComboBox = new JComboBox<String>(new String[]{"A", "B"});
+        suffixComboBox.setSelectedItem(currentSuffix);
+        suffixComboBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+
+        JPanel panel = new JPanel(new GridLayout(2, 2, 10, 10));
+        panel.add(new JLabel("工序:"));
+        panel.add(stationComboBox);
+        panel.add(new JLabel("后缀:"));
+        panel.add(suffixComboBox);
+
+        int result = JOptionPane.showConfirmDialog(mesClientFrame, panel, "切换工位", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
+        if (result == JOptionPane.OK_OPTION) {
+            String oprno = OprnoUtil.t9oprnos[stationComboBox.getSelectedIndex()];
+            String suffix = suffixComboBox.getSelectedItem().toString();
+            switchStation(oprno + suffix);
+        }
+    }
+
+    public static void switchStation(String station) {
+        if (work_status == 1) {
+            JOptionPane.showMessageDialog(mesClientFrame, "当前正在加工中,不能切换工位", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        if (station == null || station.equalsIgnoreCase(mes_gw)) {
+            return;
+        }
+
+        mes_gw = station;
+        mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
+
+        try {
+            StationConfig.saveRuntimeGw(mes_gw);
+        } catch (IOException e) {
+            JOptionPane.showMessageDialog(mesClientFrame, "工位保存失败:" + e.getMessage(), "提示窗口", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+
+        if (mesClientFrame != null) {
+            mesClientFrame.setTitle("MES系统客户端:" + mes_gw + "- " + mes_gw_des);
+        }
+        if (welcomeWin != null) {
+            welcomeWin.setTitle("MES系统客户端:" + mes_gw + " - " + mes_gw_des);
+        }
+        resetScanA();
+        setMenuStatus("已切换工位:" + mes_gw + " - " + mes_gw_des, 0);
+        log.info("switch station to " + mes_gw + ";" + mes_gw_des);
+    }
     public static void getMaterailData(){
     public static void getMaterailData(){
         try{
         try{
             JSONObject retObj = DataUtil.getBindMaterail();
             JSONObject retObj = DataUtil.getBindMaterail();

+ 9 - 10
src/com/mes/ui/OprnoUtil.java

@@ -1,8 +1,7 @@
 package com.mes.ui;
 package com.mes.ui;
 
 
 /**
 /**
- * 工位描述工具:硬编码工位列表,避免每台客户端都依赖服务端接口
- * 数据来源 2026-06-24:T09 产线 mesLineProcess(lineSn=T9)
+ * 工位描述工具:硬编码工位列表,避免每台客户端都依赖服务端接口。
  */
  */
 public class OprnoUtil {
 public class OprnoUtil {
 
 
@@ -11,7 +10,8 @@ public class OprnoUtil {
             "OP040", "OP050", "OP060", "OP070", "INSP030",
             "OP040", "OP050", "OP060", "OP070", "INSP030",
             "OP090", "OP100", "OP120", "OP130", "INSP050",
             "OP090", "OP100", "OP120", "OP130", "INSP050",
             "INSP060", "OP170", "OP190", "OP200", "INSP080",
             "INSP060", "OP170", "OP190", "OP200", "INSP080",
-            "OP230", "INSP090", "INSP100", "INSP130", "INSP110"
+            "OP230", "INSP090", "INSP100", "INSP130", "INSP110",
+            "OP250"
     };
     };
 
 
     /** T9 产线工位名(与 t9oprnos 一一对应) */
     /** T9 产线工位名(与 t9oprnos 一一对应) */
@@ -19,13 +19,13 @@ public class OprnoUtil {
             "激光打码", "框架总成焊接1", "框架总成焊接2", "人工补焊1", "框架气密",
             "激光打码", "框架总成焊接1", "框架总成焊接2", "人工补焊1", "框架气密",
             "框架激光切割正面", "框架激光切割反面", "套筒焊接", "人工补焊2", "总成检具检验",
             "框架激光切割正面", "框架激光切割反面", "套筒焊接", "人工补焊2", "总成检具检验",
             "黑件入库", "紧固件装配正面/反面", "框架涂胶", "冷板装配", "半成品气密",
             "黑件入库", "紧固件装配正面/反面", "框架涂胶", "冷板装配", "半成品气密",
-            "安装密封垫底护板", "整包气密", "液冷板气密", "等电位电阻测试", "CCD检测"
+            "安装密封垫底护板(没底护板)", "整包气密", "液冷板气密", "等电位电阻测试", "CCD检测",
+            "包装入库"
     };
     };
 
 
     /**
     /**
-     * 根据工位号查工位描述
-     * 子工位号自动转父工位(OP040A → OP040、INSP030A → INSP030)
-     * 注:lineSn 已不再区分,此客户端固定为 T09 产线
+     * 根据工位号查工位描述。
+     * 子工位号自动转父工位(OP040A -> OP040、INSP030A -> INSP030)。
      */
      */
     public static String getGwDes(String lineSn, String oprno) {
     public static String getGwDes(String lineSn, String oprno) {
         if (oprno == null) return "";
         if (oprno == null) return "";
@@ -37,9 +37,8 @@ public class OprnoUtil {
     }
     }
 
 
     /**
     /**
-     * 子工位号 → 父工位号
-     * 规则:去除末尾连续字母(前提是字母前是数字),如 OP040A → OP040、INSP030B → INSP030
-     * 不动 OP/INSP 这种前缀字母
+     * 子工位号 -> 父工位号。
+     * 规则:去除末尾连续字母,前提是字母前是数字,如 OP040A -> OP040、INSP030B -> INSP030。
      */
      */
     public static String formatOprno(String oprno) {
     public static String formatOprno(String oprno) {
         if (oprno == null) return "";
         if (oprno == null) return "";

+ 65 - 0
src/com/mes/ui/StationConfig.java

@@ -0,0 +1,65 @@
+package com.mes.ui;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.Properties;
+
+public class StationConfig {
+
+    private static final String RUNTIME_CONFIG_PATH = "config/runtime.properties";
+
+    public static String loadRuntimeGw(String defaultGw) {
+        File file = new File(RUNTIME_CONFIG_PATH);
+        if (!file.exists()) {
+            return defaultGw;
+        }
+
+        Properties pro = new Properties();
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+            pro.load(br);
+            String runtimeGw = pro.getProperty("mes.gw");
+            if (runtimeGw == null || runtimeGw.trim().equalsIgnoreCase("")) {
+                return defaultGw;
+            }
+            return runtimeGw.trim();
+        } catch (Exception e) {
+            return defaultGw;
+        } finally {
+            if (br != null) {
+                try {
+                    br.close();
+                } catch (IOException ignored) {
+                }
+            }
+        }
+    }
+
+    public static void saveRuntimeGw(String gw) throws IOException {
+        File file = new File(RUNTIME_CONFIG_PATH);
+        File parent = file.getParentFile();
+        if (parent != null && !parent.exists()) {
+            parent.mkdirs();
+        }
+
+        Properties pro = new Properties();
+        pro.setProperty("mes.gw", gw);
+
+        BufferedWriter bw = null;
+        try {
+            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
+            pro.store(bw, "runtime station config");
+        } finally {
+            if (bw != null) {
+                bw.close();
+            }
+        }
+    }
+}