|
|
@@ -5,6 +5,7 @@ import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
import com.mes.netty.ProtocolParam;
|
|
|
+import com.mes.util.ConfigUtil;
|
|
|
import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.ErrorMsg;
|
|
|
import com.mes.util.HttpUtils;
|
|
|
@@ -71,6 +72,16 @@ public class MesClient extends JFrame {
|
|
|
public static JButton status_menu;
|
|
|
public static JButton user_menu;
|
|
|
|
|
|
+ // 隐藏入口:双击「心跳」值后再双击「登录用户」值,设置菜单出现「更改工位」
|
|
|
+ private static JMenuItem changeStationMenu;
|
|
|
+ private static boolean stationGestureHeartClicked = false;
|
|
|
+ private static long stationGestureHeartAt = 0L;
|
|
|
+ private static final long STATION_GESTURE_TIMEOUT_MS = 15000L;
|
|
|
+
|
|
|
+ public static JLabel gwLabel; // 顶部工位号/名称
|
|
|
+ public static JTabbedPane workRecordTabbedPane;
|
|
|
+ public static WorkRecordPanel workRecordPanelCurrent;
|
|
|
+
|
|
|
public static int scan_type = 0;
|
|
|
public static JButton finish_ok_bt;
|
|
|
public static JButton finish_ng_bt;
|
|
|
@@ -136,13 +147,9 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //读配置文件
|
|
|
+ //读配置文件(外部 config/config.properties 优先,其次 jar 内置)
|
|
|
private static void readProperty() throws IOException{
|
|
|
- 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);
|
|
|
+ Properties pro = ConfigUtil.loadProperties();
|
|
|
mes_gw = pro.getProperty("mes.gw");
|
|
|
mes_server_ip = pro.getProperty("mes.server_ip");
|
|
|
mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
|
|
|
@@ -394,7 +401,7 @@ public class MesClient extends JFrame {
|
|
|
setJMenuBar(menuBar);
|
|
|
|
|
|
// 左侧:工位号和名称
|
|
|
- JLabel gwLabel = new JLabel("工位:" + mes_gw + " - " + mes_gw_des);
|
|
|
+ gwLabel = new JLabel("工位:" + mes_gw + " - " + mes_gw_des);
|
|
|
gwLabel.setFont(new Font("微软雅黑", Font.BOLD, 22));
|
|
|
gwLabel.setForeground(new Color(0, 102, 204));
|
|
|
gwLabel.setBorder(new EmptyBorder(0, 10, 0, 20));
|
|
|
@@ -467,6 +474,18 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu_1);
|
|
|
|
|
|
+ // 默认隐藏;双击「心跳」→ 双击「登录用户」后出现
|
|
|
+ changeStationMenu = new JMenuItem("更改工位");
|
|
|
+ changeStationMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
|
|
|
+ changeStationMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ changeStationMenu.setVisible(false);
|
|
|
+ changeStationMenu.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ showChangeStationDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ settingMenu.add(changeStationMenu);
|
|
|
+
|
|
|
contentPane = new JPanel();
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
|
setContentPane(contentPane);
|
|
|
@@ -527,6 +546,12 @@ public class MesClient extends JFrame {
|
|
|
user_menu.setBackground(Color.BLACK);
|
|
|
toolBar.add(user_menu);
|
|
|
|
|
|
+ // 隐藏解锁入口:心跳(文字/值)双击,然后登录用户(文字/值)双击
|
|
|
+ bindStationGesture(heart_beat_status_label, true);
|
|
|
+ bindStationGesture(heart_beat_menu, true);
|
|
|
+ bindStationGesture(user_status_label, false);
|
|
|
+ bindStationGesture(user_menu, false);
|
|
|
+
|
|
|
JLabel space_3 = new JLabel(" ");
|
|
|
toolBar.add(space_3);
|
|
|
|
|
|
@@ -754,7 +779,7 @@ public class MesClient extends JFrame {
|
|
|
// tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
|
|
|
|
|
|
// 创建工作记录的子 TabbedPane
|
|
|
- JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
+ workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
|
|
|
// OP80 工位:当前工位 + 所有工位
|
|
|
@@ -762,6 +787,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
// 当前工位Tab(使用配置文件中的 mes.gw)
|
|
|
workRecordPanels[0] = new WorkRecordPanel(mes_gw, mes_line_sn);
|
|
|
+ workRecordPanelCurrent = workRecordPanels[0];
|
|
|
workRecordTabbedPane.addTab(mes_gw, null, workRecordPanels[0], "查询" + mes_gw + "的工作记录");
|
|
|
|
|
|
// 所有工位Tab(查询整条产线所有工位)
|
|
|
@@ -816,6 +842,187 @@ public class MesClient extends JFrame {
|
|
|
MesClient.status_menu.setText(msg);
|
|
|
}
|
|
|
|
|
|
+ /** 工位变化后刷新顶部工位标签和窗口标题。 */
|
|
|
+ private static void refreshStationUi() {
|
|
|
+ String gwText = mes_gw + (mes_gw_des == null || mes_gw_des.trim().isEmpty() ? "" : " - " + mes_gw_des);
|
|
|
+ if (gwLabel != null) {
|
|
|
+ gwLabel.setText("工位:" + gwText);
|
|
|
+ }
|
|
|
+ String title = "MES系统客户端:" + gwText;
|
|
|
+ if (mesClientFrame != null) {
|
|
|
+ mesClientFrame.setTitle(title);
|
|
|
+ }
|
|
|
+ if (welcomeWin != null) {
|
|
|
+ welcomeWin.setTitle(title);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 按当前工位/当前登录用户刷新开班点检页面,不重启也能看到新工位的数据。 */
|
|
|
+ public static void reloadCheckPage() {
|
|
|
+ if (jfxPanel2 == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String ucode = user_menu == null ? "" : user_menu.getText();
|
|
|
+ String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProcessCheckRecord/ulist"
|
|
|
+ + "?ucode=" + ucode + "&oprno=" + mes_gw + "&lineSn=" + mes_line_sn
|
|
|
+ + (sessionid == null || sessionid.trim().isEmpty() ? "" : "&__sid=" + sessionid);
|
|
|
+ jfxPanel2.loadUrl(url);
|
|
|
+ log.info("开班点检页面已按工位刷新: {}", url);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更改工位。工位号同时用于:扫码校验/结果上传等 HTTP 接口、开班点检页面、工作记录查询。
|
|
|
+ * 先写回 config/config.properties,成功后才切换内存和界面,避免界面与实际请求工位不一致。
|
|
|
+ */
|
|
|
+ public static boolean changeStation(String newGw) {
|
|
|
+ if (newGw == null || newGw.trim().isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ final String gw = newGw.trim().toUpperCase(java.util.Locale.ROOT);
|
|
|
+ if (!ConfigUtil.saveProperty("mes.gw", gw)) {
|
|
|
+ log.error("更改工位失败:写入 config/config.properties 失败, gw={}", gw);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ mes_gw = gw;
|
|
|
+ String des = OprnoUtil.getGwDes(mes_line_sn, gw);
|
|
|
+ mes_gw_des = des == null ? "" : des;
|
|
|
+
|
|
|
+ refreshStationUi();
|
|
|
+ reloadCheckPage();
|
|
|
+
|
|
|
+ // 当前工位的工作记录查询条件同步
|
|
|
+ if (workRecordPanelCurrent != null) {
|
|
|
+ workRecordPanelCurrent.changeOprno(gw);
|
|
|
+ }
|
|
|
+ if (workRecordTabbedPane != null && workRecordTabbedPane.getTabCount() > 0) {
|
|
|
+ workRecordTabbedPane.setTitleAt(0, gw);
|
|
|
+ workRecordTabbedPane.setToolTipTextAt(0, "查询" + gw + "的工作记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清空当前加工状态,物料绑定按新工位重新拉取
|
|
|
+ resetScanA();
|
|
|
+ setMenuStatus("工位已切换为 " + gw + (mes_gw_des.isEmpty() ? "" : "(" + mes_gw_des + ")"), 0);
|
|
|
+ log.info("工位已更改: gw={}, des={}, config={}", gw, mes_gw_des, ConfigUtil.findConfigFile());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 设置菜单里的「更改工位」入口。 */
|
|
|
+ public static void showChangeStationDialog() {
|
|
|
+ if (work_status != null && work_status != 0) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,
|
|
|
+ "当前有工件正在加工/等待结果,不能更改工位。\n"
|
|
|
+ + "请先完成当前工件,或点「设置-刷新工件」复位后再试。",
|
|
|
+ "更改工位", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String oldGw = mes_gw == null ? "" : mes_gw.trim();
|
|
|
+ String line = mes_line_sn == null ? "" : mes_line_sn.trim();
|
|
|
+ String input = (String) JOptionPane.showInputDialog(mesClientFrame,
|
|
|
+ "当前工位:" + oldGw + "\n产线编号:" + line
|
|
|
+ + "\n\n请输入新的工位号(最多 8 位字母/数字,例如 OP040、INSP030A):",
|
|
|
+ "更改工位", JOptionPane.QUESTION_MESSAGE, null, null, oldGw);
|
|
|
+ if (input == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String gw = input.trim().toUpperCase(java.util.Locale.ROOT);
|
|
|
+ if (gw.isEmpty()) {
|
|
|
+ setMenuStatus("工位号不能为空", -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!gw.matches("[A-Z0-9_-]{1,8}")) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,
|
|
|
+ "工位号格式不正确:只允许 1~8 位字母、数字、下划线或短横线。",
|
|
|
+ "更改工位", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (gw.equals(oldGw)) {
|
|
|
+ setMenuStatus("工位号未变化", 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String des = OprnoUtil.getGwDes(line, gw);
|
|
|
+ if (des == null || des.isEmpty()) {
|
|
|
+ int unknown = JOptionPane.showConfirmDialog(mesClientFrame,
|
|
|
+ "本地工位表未匹配到工位 " + gw + " 的名称。\n"
|
|
|
+ + "请确认 MES 后台该产线已配置此工位,否则扫码/点检会失败。\n\n仍要设置为该工位吗?",
|
|
|
+ "更改工位", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
|
|
|
+ if (unknown != JOptionPane.OK_OPTION) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ des = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ int confirm = JOptionPane.showConfirmDialog(mesClientFrame,
|
|
|
+ "确认更改工位?\n\n工位号:" + oldGw + " → " + gw
|
|
|
+ + "\n工位名称:" + (des.isEmpty() ? "(未匹配)" : des)
|
|
|
+ + "\n\n更改后会立即写入 config/config.properties,"
|
|
|
+ + "并同步刷新开班点检、工作记录和物料绑定,无需重启客户端。",
|
|
|
+ "确认更改工位", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
|
|
|
+ if (confirm != JOptionPane.OK_OPTION) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (changeStation(gw)) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,
|
|
|
+ "工位已更改:" + gw + (des.isEmpty() ? "" : "(" + des + ")")
|
|
|
+ + "\n配置文件已更新,开班点检已按新工位刷新。",
|
|
|
+ "更改工位", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ } else {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame,
|
|
|
+ "写入 config/config.properties 失败,工位未更改。\n"
|
|
|
+ + "请检查程序目录下 config 目录是否可写。",
|
|
|
+ "更改工位", JOptionPane.WARNING_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 隐藏解锁:先双击「心跳」值,15 秒内再双击「登录用户」值,
|
|
|
+ * 设置菜单才显示「更改工位」。文字标签和值按钮都支持。
|
|
|
+ */
|
|
|
+ private static void bindStationGesture(JComponent comp, final boolean heartbeatStep) {
|
|
|
+ if (comp == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ comp.addMouseListener(new MouseAdapter() {
|
|
|
+ private long lastClickAt = 0L;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ if (!SwingUtilities.isLeftMouseButton(e)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ // 兼容标准双击,也兼容两次稍慢的单击(现场“点两下”)
|
|
|
+ boolean clickedTwice = e.getClickCount() >= 2 || (now - lastClickAt <= 700L);
|
|
|
+ lastClickAt = now;
|
|
|
+ if (!clickedTwice) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (heartbeatStep) {
|
|
|
+ stationGestureHeartClicked = true;
|
|
|
+ stationGestureHeartAt = System.currentTimeMillis();
|
|
|
+ log.info("工位菜单解锁: 心跳双击 1/2");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!stationGestureHeartClicked) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ stationGestureHeartClicked = false;
|
|
|
+ if (System.currentTimeMillis() - stationGestureHeartAt > STATION_GESTURE_TIMEOUT_MS) {
|
|
|
+ log.info("工位菜单解锁: 超时,请重新双击「心跳」");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (changeStationMenu != null) {
|
|
|
+ changeStationMenu.setVisible(true);
|
|
|
+ log.info("工位菜单已解锁");
|
|
|
+ setMenuStatus("已解锁「设置-更改工位」", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public static void getMaterailData(){
|
|
|
try{
|
|
|
JSONObject retObj = DataUtil.getBindMaterail();
|