فهرست منبع

添加修改工位功能

dkk 1 هفته پیش
والد
کامیت
727d2e9dad

+ 10 - 0
src/com/mes/component/MesWebView.java

@@ -46,4 +46,14 @@ public class MesWebView extends JFXPanel {
     public void reloadWeb(){
         engine.reload();
     }
+
+    //加载新的URL(用于切换工位后刷新页面)
+    public void loadUrl(final String url){
+        Platform.runLater(() -> {
+            log.info(url);
+            if(engine != null){
+                engine.load(url);
+            }
+        });
+    }
 }

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

@@ -124,15 +124,11 @@ public class DataUtil {
             String paramNums = "00";
             String params = "";
 
-            InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
-            Properties pro = new Properties();
-            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-            pro.load(br);
-            String gw = "GW"+rightPad(pro.getProperty("mes.gw"), 6);
+            String gw = "GW"+rightPad(MesClient.mes_gw, 6);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             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 da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
@@ -150,16 +146,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){
         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"), 6);
+            String gw = "GW"+rightPad(MesClient.mes_gw, 6);
             String start = "aaaabbbbbABW";
             String gy = "GY" + rightPad(craft, 6);
             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 da = "DA" + DateLocalUtils.getCurrentDate();
             String zt = "ZT" + DateLocalUtils.getCurrentTimeHMS();
@@ -188,15 +179,9 @@ public class DataUtil {
 
     public static JSONObject getBindMaterail() {
         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 url = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.mes_line_sn.trim();
+            String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesLineProcessMaterial/materials";
             String params = "__ajax=json&oprno="+oprno+"&lineSn="+lineSn;
             log.info("params="+params);
             String result = doPost(url,params);
@@ -214,15 +199,9 @@ public class DataUtil {
 
     public static JSONObject saveBindMaterail(String batchSn,String craft,String materialId,String type) {
         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 url = "http://"+mes_server_ip+":8980/js/a/mes/mesMaterialPrebind/bind";
+            String oprno = MesClient.mes_gw.trim();
+            String lineSn = MesClient.mes_line_sn.trim();
+            String url = "http://"+MesClient.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;
             log.info("params="+params);
             String result = doPost(url,params);

+ 214 - 5
src/com/mes/ui/MesClient.java

@@ -25,6 +25,9 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.image.BufferedImage;
 import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -107,6 +110,12 @@ public class MesClient extends JFrame {
                     //读文件配置
                     readProperty();
 
+                    // 用户手动选择工位
+                    if(!selectWorkstation()){
+                        System.exit(0);
+                        return;
+                    }
+
                     // 显示界面
                     mesClientFrame = new MesClient();
                     mesClientFrame.setVisible(false);
@@ -127,6 +136,197 @@ public class MesClient extends JFrame {
         });
     }
 
+    // 工位持久化配置文件目录(用户家目录下)
+    private static final String GW_CONFIG_DIR = System.getProperty("user.home") + File.separator + ".mesclient";
+
+    // 按产线编号生成配置文件路径(不同产线工位表不同,分别保存)
+    private static String getGwConfigFile(){
+        return GW_CONFIG_DIR + File.separator + "gw_" + mes_line_sn + ".properties";
+    }
+
+    // 保存工位到本地文件
+    public static void saveWorkstation(String gw){
+        try {
+            File dir = new File(GW_CONFIG_DIR);
+            if(!dir.exists()){
+                dir.mkdirs();
+            }
+            Properties pro = new Properties();
+            pro.setProperty("mes.gw", gw);
+            pro.setProperty("mes.line_sn", mes_line_sn);
+            try(FileOutputStream fos = new FileOutputStream(getGwConfigFile())){
+                pro.store(fos, "MES Client Workstation");
+            }
+        } catch (Exception e) {
+            log.error("保存工位失败", e);
+        }
+    }
+
+    // 从本地文件读取上次保存的工位
+    public static String loadSavedWorkstation(){
+        try {
+            File file = new File(getGwConfigFile());
+            if(!file.exists()){
+                return "";
+            }
+            Properties pro = new Properties();
+            try(FileInputStream fis = new FileInputStream(file)){
+                pro.load(fis);
+                return pro.getProperty("mes.gw", "");
+            }
+        } catch (Exception e) {
+            log.error("读取已保存工位失败", e);
+            return "";
+        }
+    }
+
+    // 启动后加载工位:已保存则静默加载,未保存则弹窗让用户选择
+    public static boolean selectWorkstation(){
+        String[] oprnos;
+        String[] oprnodes;
+        if("LB".equals(mes_line_sn)){
+            oprnos = OprnoUtil.lboprnos;
+            oprnodes = OprnoUtil.lboprnodes;
+        }else{
+            oprnos = OprnoUtil.xtoprnos;
+            oprnodes = OprnoUtil.xtoprnodes;
+        }
+
+        // 若已有保存的工位,则静默加载,不再弹窗
+        String savedGw = loadSavedWorkstation();
+        if(!savedGw.isEmpty()){
+            for(int i=0;i<oprnos.length;i++){
+                if(oprnos[i].equals(savedGw)){
+                    mes_gw = oprnos[i];
+                    mes_gw_des = oprnodes[i];
+                    log.info("自动加载上次工位: " + mes_gw + " - " + mes_gw_des);
+                    return true;
+                }
+            }
+        }
+
+        // 无保存工位,弹窗让用户选择
+        String[] selections = new String[oprnos.length];
+        for(int i=0;i<oprnos.length;i++){
+            selections[i] = oprnos[i] + " - " + oprnodes[i];
+        }
+
+        JComboBox<String> combo = new JComboBox<>(selections);
+        combo.setSelectedIndex(0);
+        combo.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        int result = JOptionPane.showConfirmDialog(null, combo, "请选择工位("+mes_line_sn+"线)",
+                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
+
+        if(result == JOptionPane.OK_OPTION){
+            int idx = combo.getSelectedIndex();
+            mes_gw = oprnos[idx];
+            mes_gw_des = oprnodes[idx];
+            log.info("用户选择工位: " + mes_gw + " - " + mes_gw_des);
+            // 持久化保存
+            saveWorkstation(mes_gw);
+            return true;
+        }
+        return false;
+    }
+
+    // 登录后在软件内切换工位
+    public static void changeWorkstation(){
+        String[] oprnos;
+        String[] oprnodes;
+        if("LB".equals(mes_line_sn)){
+            oprnos = OprnoUtil.lboprnos;
+            oprnodes = OprnoUtil.lboprnodes;
+        }else{
+            oprnos = OprnoUtil.xtoprnos;
+            oprnodes = OprnoUtil.xtoprnodes;
+        }
+
+        String[] selections = new String[oprnos.length];
+        for(int i=0;i<oprnos.length;i++){
+            selections[i] = oprnos[i] + " - " + oprnodes[i];
+        }
+
+        JComboBox<String> combo = new JComboBox<>(selections);
+        //默认选中当前工位
+        for(int i=0;i<oprnos.length;i++){
+            if(oprnos[i].equals(mes_gw)){
+                combo.setSelectedIndex(i);
+                break;
+            }
+        }
+        combo.setFont(new Font("微软雅黑", Font.PLAIN, 18));
+        int result = JOptionPane.showConfirmDialog(mesClientFrame, combo, "请选择工位("+mes_line_sn+"线)",
+                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
+
+        if(result == JOptionPane.OK_OPTION){
+            int idx = combo.getSelectedIndex();
+            String newGw = oprnos[idx];
+            String newGwDes = oprnodes[idx];
+
+            if(newGw.equals(mes_gw)){
+                JOptionPane.showMessageDialog(mesClientFrame,"工位未变更","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+
+            mes_gw = newGw;
+            mes_gw_des = newGwDes;
+            log.info("切换工位: " + mes_gw + " - " + mes_gw_des);
+            // 持久化保存
+            saveWorkstation(mes_gw);
+
+            //更新标题栏
+            mesClientFrame.setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
+
+            //重新请求该工位的权限
+            String url_authority = "http://"+mes_server_ip+":8980/js/a/mes/mesLineProcess/userAuth?__ajax=json&type=0&__sid="+sessionid+"&oprno="+mes_gw+"&lineSn="+mes_line_sn;
+            String authorityResult = HttpUtils.sendRequest(url_authority);
+            log.info("authorityResult="+authorityResult);
+            JSONObject authorityObj = JSONObject.parseObject(authorityResult);
+            if(authorityObj.get("result")!=null&&authorityObj.get("result").toString().equalsIgnoreCase("true")) {
+                JSONObject authObjTmp = JSONObject.parseObject(authorityObj.get("data").toString());
+                mes_auth = Integer.parseInt(authObjTmp.getString("auth").toString());
+                if(mes_auth==0) {
+                    JOptionPane.showMessageDialog(mesClientFrame,"您无权操作该工位:"+mes_gw,"提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+            }else{
+                JOptionPane.showMessageDialog(mesClientFrame,"权限校验失败","提示窗口", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+
+            //重新初始化TCP连接
+            try {
+                if(nettyClient!=null){
+                    nettyClient.future.channel().close();
+                    nettyClient = null;
+                }
+            } catch (Exception e) {
+                log.error("关闭TCP连接异常", e);
+            }
+            tcp_connect_flag = false;
+            connect_request_flag = false;
+            initTcpConnection();
+
+            //刷新工作面板网页
+            String userId = user_menu.getText();
+            if(jfxPanel != null){
+                String url = "http://"+ mes_server_ip+":8980/js/a/mes/mesProductRecord/work?oprno="+mes_gw+"&lineSn="+mes_line_sn;
+                jfxPanel.loadUrl(url);
+            }
+            if(jfxPanel2 != null){
+                String url = "http://"+ mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+userId+"&oprno="+mes_gw+"&lineSn="+mes_line_sn;
+                jfxPanel2.loadUrl(url);
+            }
+
+            //刷新物料绑定数据
+            resetScanA();
+            getMaterailData();
+
+            setMenuStatus("已切换工位:"+mes_gw,0);
+            JOptionPane.showMessageDialog(mesClientFrame,"工位已切换为:"+mes_gw+" - "+mes_gw_des,"提示窗口", JOptionPane.INFORMATION_MESSAGE);
+        }
+    }
+
     //读配置文件
     private static void readProperty() throws IOException{
         String enconding = "UTF-8";
@@ -134,17 +334,14 @@ public class MesClient extends JFrame {
         Properties pro = new Properties();
         BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
         pro.load(br);
-        mes_gw =  pro.getProperty("mes.gw");
 
-//        mes_gw_des = pro.getProperty("mes.gw_des");
         mes_server_ip = pro.getProperty("mes.server_ip");
         mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
         mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
         mes_line_sn = pro.getProperty("mes.line_sn");
+        // mes_gw、mes_gw_des 由用户启动后从OprnoUtil工位表中手动选择
 
-        mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
-
-        log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
+        log.info(mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle + ";" + mes_line_sn);
     }
 
     // 初始化TCP
@@ -428,6 +625,18 @@ public class MesClient extends JFrame {
         });
         settingMenu.add(resetTcpMenu_1);
 
+        JMenuItem setGwMenu = new JMenuItem("设置工位");
+        setGwMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/company_setting_logo.png")));
+        setGwMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
+        setGwMenu.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent e) {
+                super.mouseClicked(e);
+                changeWorkstation();
+            }
+        });
+        settingMenu.add(setGwMenu);
+
         contentPane = new JPanel();
         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
         setContentPane(contentPane);

+ 2 - 2
src/com/mes/ui/OprnoUtil.java

@@ -6,7 +6,7 @@ import java.util.Map;
 
 public class OprnoUtil {
     public static String[] xtoprnos = new String[]{
-            "OP040","OP050","OP060","OP070","OP080","OP090","OP100","OP110",
+            "OP050","OP060","OP070","OP080","OP090","OP100","OP110",
             "OP120","OP130","OP140","OP150","OP160","OP170","OP180","OP190",
             "OP200","OP210","OP220","OP230","OP240","OP250","OP260","OP270",
             "OP280","OP290","OP300","OP310","OP320","OP330","OP340","OP350",
@@ -15,7 +15,7 @@ public class OprnoUtil {
     };
 
     public static String[] xtoprnodes = new String[]{
-            "镭雕二维码", "牙套安装", "后侧梁左小总成焊接", "后侧梁找漏", "边梁压铆", "框架CMT焊接",
+            "牙套安装", "后侧梁左小总成焊接", "后侧梁找漏", "边梁压铆", "框架CMT焊接",
             "人工补焊", "焊道打磨", "焊道检查", "框架找漏", "框架正面CNC", "框架反面CNC", "框架去毛刺+清洁",
             "封堵片焊接", "封堵片打磨+清洁", "框架涂胶", "液冷板装配", "中吊点安装+正面清理溢胶", "液冷板FSW",
             "匙孔补焊", "焊道打磨、清洁", "总成反面紧固件安装", "边梁套筒涂胶+压合", "总成正面拉铆", "封堵",

+ 3 - 3
src/resources/config/config.properties

@@ -1,6 +1,6 @@
-mes.gw=OP040
-mes.server_ip=127.0.0.1
-#mes.server_ip=192.168.11.99
+#mes.gw=OP450
+#mes.server_ip=127.0.0.1
+mes.server_ip=192.168.13.99
 mes.tcp_port=3000
 mes.heart_beat_cycle=60
 mes.line_sn=XT