|
|
@@ -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);
|