|
|
@@ -73,6 +73,7 @@ public class MesClient extends JFrame {
|
|
|
public static int mes_heart_beat_cycle = 10; // 心跳周期
|
|
|
public static int mes_heart_icon_cycle = 1;
|
|
|
public static String mes_line_sn = ""; // 产线编号
|
|
|
+ public static java.util.List<String> mes_barcode_prefixes = new java.util.ArrayList<String>(); // 工件码前缀白名单(空=不校验)
|
|
|
|
|
|
//TCP连接
|
|
|
public static NettyClient nettyClient;
|
|
|
@@ -175,6 +176,7 @@ public class MesClient extends JFrame {
|
|
|
mes_line_sn = pro.getProperty("mes.line_sn");
|
|
|
|
|
|
mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
|
|
|
+ mes_barcode_prefixes = StationConfig.loadBarcodePrefixes();
|
|
|
|
|
|
log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
|
|
|
}
|
|
|
@@ -360,6 +362,20 @@ public class MesClient extends JFrame {
|
|
|
//弹窗扫工件码
|
|
|
String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
|
|
|
if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
|
|
|
+ // 前缀校验(多前缀,匹配任一即通过)
|
|
|
+ if (mes_barcode_prefixes != null && !mes_barcode_prefixes.isEmpty()) {
|
|
|
+ boolean matched = false;
|
|
|
+ for (String prefix : mes_barcode_prefixes) {
|
|
|
+ if (scanBarcode.startsWith(prefix)) {
|
|
|
+ matched = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!matched) {
|
|
|
+ MesClient.setMenuStatus("工件码前缀不匹配,允许的前缀:" + mes_barcode_prefixes, -1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
//获取用户
|
|
|
getUser();
|
|
|
//获取扫码内容36位
|
|
|
@@ -480,6 +496,17 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
});
|
|
|
settingMenu.add(switchStationMenu);
|
|
|
+
|
|
|
+ JMenuItem prefixConfigMenu = new JMenuItem("前缀校验配置");
|
|
|
+ prefixConfigMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
|
|
|
+ prefixConfigMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ prefixConfigMenu.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ showPrefixConfigDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ settingMenu.add(prefixConfigMenu);
|
|
|
+
|
|
|
contentPane = new JPanel();
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
|
setContentPane(contentPane);
|
|
|
@@ -709,6 +736,68 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /** 前缀校验配置(密码保护) */
|
|
|
+ private static void showPrefixConfigDialog() {
|
|
|
+ // 先验证密码 503833
|
|
|
+ JPasswordField pwdField = new JPasswordField(15);
|
|
|
+ pwdField.setFont(new Font("微软雅黑", Font.PLAIN, 18));
|
|
|
+ int pwdOk = JOptionPane.showConfirmDialog(mesClientFrame, pwdField, "请输入设置密码", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
+ if (pwdOk != JOptionPane.OK_OPTION) return;
|
|
|
+ String pwd = new String(pwdField.getPassword());
|
|
|
+ if (!"503833".equals(pwd)) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "密码错误", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 密码正确,显示前缀列表配置界面
|
|
|
+ DefaultListModel<String> listModel = new DefaultListModel<String>();
|
|
|
+ for (String p : mes_barcode_prefixes) listModel.addElement(p);
|
|
|
+ JList<String> prefixList = new JList<String>(listModel);
|
|
|
+ prefixList.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ JScrollPane scrollPane = new JScrollPane(prefixList);
|
|
|
+ scrollPane.setPreferredSize(new Dimension(300, 150));
|
|
|
+
|
|
|
+ JButton addBtn = new JButton("添加");
|
|
|
+ addBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ addBtn.addActionListener(e -> {
|
|
|
+ String newPrefix = JOptionPane.showInputDialog(mesClientFrame, "输入新前缀:");
|
|
|
+ if (newPrefix != null && !newPrefix.trim().isEmpty()) {
|
|
|
+ String t = newPrefix.trim();
|
|
|
+ if (!listModel.contains(t)) listModel.addElement(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ JButton delBtn = new JButton("删除");
|
|
|
+ delBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ delBtn.addActionListener(e -> {
|
|
|
+ int idx = prefixList.getSelectedIndex();
|
|
|
+ if (idx >= 0) listModel.remove(idx);
|
|
|
+ });
|
|
|
+
|
|
|
+ JPanel btnPanel = new JPanel();
|
|
|
+ btnPanel.add(addBtn);
|
|
|
+ btnPanel.add(delBtn);
|
|
|
+
|
|
|
+ JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
|
|
|
+ mainPanel.add(new JLabel("工件码前缀白名单(为空则不校验):"), BorderLayout.NORTH);
|
|
|
+ mainPanel.add(scrollPane, BorderLayout.CENTER);
|
|
|
+ mainPanel.add(btnPanel, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ int ok = JOptionPane.showConfirmDialog(mesClientFrame, mainPanel, "前缀校验配置", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
+ if (ok == JOptionPane.OK_OPTION) {
|
|
|
+ java.util.List<String> newList = new java.util.ArrayList<String>();
|
|
|
+ for (int i = 0; i < listModel.size(); i++) newList.add(listModel.getElementAt(i));
|
|
|
+ try {
|
|
|
+ StationConfig.saveBarcodePrefixes(newList);
|
|
|
+ mes_barcode_prefixes = newList;
|
|
|
+ String msg = newList.isEmpty() ? "已清空前缀,不再校验" : "前缀已更新:" + newList;
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, msg, "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ } catch (IOException ex) {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "保存失败:" + ex.getMessage(), "提示", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static void showStationSwitchDialog() {
|
|
|
String[] stations = new String[OprnoUtil.t9oprnos.length];
|
|
|
int selectedStationIndex = 0;
|