package com.mes.ui; import com.alibaba.fastjson2.JSONObject; import com.google.zxing.BarcodeFormat; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.QRCodeWriter; import com.mes.component.MesRadio; import com.mes.component.MesWebView; import com.mes.netty.NettyClient; import com.mes.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.time.LocalDateTime; import java.util.*; import java.util.List; import java.util.Timer; public class MesClient extends JFrame { public static final Logger log = LoggerFactory.getLogger(MesClient.class); public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员 public static boolean tcp_connect_flag = false; //TCP连接状态 public static boolean allow_connect_again = false; // 是否允许断线重连, true 表示 允许 public static String user20 = ""; public static String sessionid = ""; public static NettyClient nettyClient; public static Boolean check_quality_result1 = false; public static Integer work_status1 = 0; public static Integer canReadResult1 = 0; // 1=可以读取结果 public static Boolean check_quality_result2 = false; public static Integer work_status2 = 0; public static Integer canReadResult2 = 0; // 1=可以读取结果 // 记录扫码工件码的时间,用于限制提交必须在扫码后满30秒 public static long scan_time1 = 0L; public static long scan_time2 = 0L; public static JButton finish_ok_bt_1; public static JButton finish_ng_bt_1; public static JTextField product_sn_1; public static JButton f_scan_data_bt_1; public static JButton status_menu_1; public static JTextField pressureText_1; // 压力值显示文本框 public static JTextField leakText_1; // 压力值显示文本框 public static JButton finish_ok_bt_2; public static JButton finish_ng_bt_2; public static JTextField product_sn_2; public static JButton f_scan_data_bt_2; public static JButton status_menu_2; public static JTextField pressureText_2; // 压力值显示文本框 public static JTextField leakText_2; // 压力值显示文本框 public static JPanel contentPane; public static MesClient mesClientFrame; public static JTabbedPane tabbedPane; public static JScrollPane indexScrollPaneA; public static JScrollPane searchScrollPane; public static JScrollPane searchScrollPaneDjA; public static JScrollPane searchScrollPaneDjB; public static JPanel panel4; public static JScrollPane scrollPane4; public static JPanel panel5; public static JScrollPane scrollPane5; public static JButton heart_beat_menu; public static JButton user_menu; public static JFrame welcomeWin; public static JPanel indexPanelB; public static MesWebView jfxPanel = null; public static JPanel indexPanelDjA; public static JPanel indexPanelDjB; public static MesWebView jfxPanelDjA = null; public static MesWebView jfxPanelDjB = null; public static MesRadio mesRadioHj; public static JTable table; public static Object[] columnNames = {"物料名称", "绑定批次", "剩余次数", "操作"}; public static Object[][] rowData = null; // 记录查询(仿照 OP370-AUTO:工件码/测试日期/压力/泄漏值/结果) public static JTable recordTable_1; public static Object[] recordColumnNames_1 = {"工件码", "测试日期", "压力", "泄漏值", "结果"}; public static Object[][] recordRowData_1 = new Object[12][5]; public static JLabel recordPageLabel_1; public static int recordPageNo_1 = 1; public static int recordTotalPages_1 = 0; public static JTextField recordSearchField_1; public static JTable recordTable_2; public static Object[] recordColumnNames_2 = {"工件码", "测试日期", "压力", "泄漏值", "结果"}; public static Object[][] recordRowData_2 = new Object[12][5]; public static JLabel recordPageLabel_2; public static int recordPageNo_2 = 1; public static int recordTotalPages_2 = 0; public static JTextField recordSearchField_2; public static JTable recordTableOkng; public static Object[] recordColumnNamesOkng = {"工位", "样件", "工件码", "测试日期", "压力", "泄漏值", "结果"}; public static Object[][] recordRowDataOkng = new Object[12][7]; public static JLabel recordPageLabelOkng; public static int recordPageNoOkng = 1; public static int recordTotalPagesOkng = 0; public static JTextField recordSearchFieldOkng; public static JPanel panelOkng; public static JScrollPane scrollPaneOkng; private static final List okngSampleSns = new ArrayList<>(); private static final Map okngSampleType = new HashMap<>(); String currentSerialPort1 = Config.portName1; String currentSerialPort2 = Config.portName2; public static TCPClient tcpClient1 = new TCPClient("192.168.18.184",9004); public static TCPClient tcpClient2 = new TCPClient("192.168.18.183",9004); public static int scanFlag1 = 0; public static int scanFlag2 = 0; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { // 显示界面 mesClientFrame = new MesClient(); mesClientFrame.setVisible(false); JdbcUtils.getConn(); welcomeWin = new LoginFrame(); welcomeWin.setVisible(true); } catch (Exception e) { log.error(e.getMessage()); } } }); } // 初始化TCP public static void initTcpConnection() { try { if (nettyClient == null) { nettyClient = new NettyClient(); tcp_connect_flag = false; //设置TCP连接状态 DataUtil.synrTcp(nettyClient, Config.gw_1); } } catch (Exception e) { log.error("初始化TCP失败", e); } } //启动心跳包程序 public static java.util.Timer heartBeatTimer; public static java.util.Timer heartBeatIconTimer; public static boolean iconREDFlag = true; public static void startHeartBeatTimer() { if (heartBeatTimer != null) { heartBeatTimer.cancel(); } heartBeatTimer = new java.util.Timer(); heartBeatTimer.schedule(new TimerTask() { public void run() { if (nettyClient != null && tcp_connect_flag) { DataUtil.heartBeat(nettyClient, Config.gw_1); heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); } } }, 100, Config.heart_beat_cycle * 1000); //心跳显示图标 if (heartBeatIconTimer != null) { heartBeatIconTimer.cancel(); } heartBeatIconTimer = new Timer(); heartBeatIconTimer.schedule(new TimerTask() { public void run() { if (tcp_connect_flag) { if (iconREDFlag) { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); iconREDFlag = false; } else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"))); iconREDFlag = true; } heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); heart_beat_menu.setForeground(Color.GREEN); heart_beat_menu.repaint(); } else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.setText("Mes连接断开"); heart_beat_menu.setForeground(Color.RED); heart_beat_menu.repaint(); //若未连接则尝试连接 if (nettyClient != null) { //TCP重新同步连接 if (allow_connect_again) { log.info("TCP连接已断开, 在心跳循环中, 发送同步连接请求"); allow_connect_again = false; // 只允许重新同步连接一次 DataUtil.synrTcp(nettyClient, Config.gw_1); } } } } }, 100, Config.heart_icon_cycle * 1000); } public static void initWarehouseData() { resetScanA(); resetScanB(); } public static void resetScanA() { MesClient.finish_ok_bt_1.setEnabled(false); MesClient.finish_ng_bt_1.setEnabled(false); MesClient.f_scan_data_bt_1.setEnabled(true); product_sn_1.setText(""); scan_time1 = 0L; // leakText_1.setText(""); // pressureText_1.setText(""); // MesClient.setMenuState_1("请扫工件码", 0); // WorkTimer.ateq1.resetFIFO(); work_status1 = 0; check_quality_result1 = false; } public static void resetScanB() { MesClient.finish_ok_bt_2.setEnabled(false); MesClient.finish_ng_bt_2.setEnabled(false); MesClient.f_scan_data_bt_2.setEnabled(true); product_sn_2.setText(""); scan_time2 = 0L; // leakText_2.setText(""); // pressureText_2.setText(""); // MesClient.setMenuState_2("请扫工件码", 0); // WorkTimer.ateq2.resetFIFO(); work_status2 = 0; check_quality_result2 = false; } public static int userLoginHours;//用户登录所处小时 //换班用户信息检查 private static void shiftUserCheck() { LocalDateTime now = LocalDateTime.now(); // 判断时间范围 if (userLoginHours >= 8 && userLoginHours < 20) { int hour = now.getHour(); if (hour >= 20 || hour < 8) { logoff(); } } else { int hour = now.getHour(); if (hour >= 8 && hour < 20) { logoff(); } } } //获取用户20位 public static void getUser() { user20 = user_menu.getText(); String space_tmp1 = ""; if (user20.length() < 20) { for (int i = 0; i < 20 - user20.length(); i++) { space_tmp1 = space_tmp1 + " "; } } user20 = user20 + space_tmp1; } //获取barcode内容36位 public static String getBarcode(String barcodeTmp) { String barcodeRet = barcodeTmp; if (barcodeTmp.equalsIgnoreCase("")) { return ""; } else { if (barcodeTmp.length() < 36) { String space = ""; for (int i = 0; i < 36 - barcodeTmp.length(); i++) { space = space + " "; } barcodeRet = barcodeTmp + space; } } return barcodeRet; } public static String getBarcode33(String barcodeTmp) { String barcodeRet = barcodeTmp; if (barcodeTmp.equalsIgnoreCase("")) { return ""; } else { if (barcodeTmp.length() < 33) { String space = ""; for (int i = 0; i < 33 - barcodeTmp.length(); i++) { space = space + " "; } barcodeRet = barcodeTmp + space; } } return barcodeRet; } public static void scanBarcode1() { if (work_status1 == 1) { JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE); return; } WorkTimer.ateq1.resetFIFO(); product_sn_1.setText(""); leakText_1.setText(""); pressureText_1.setText(""); MesClient.setMenuState_1("请扫工件码", 0); //弹窗扫工件码 // String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码"); String scanBarcode = MesClient.scanQrcode1(); if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) { product_sn_1.setText(scanBarcode); scan_time1 = System.currentTimeMillis(); //刷新界面 mesClientFrame.repaint(); if (!tcp_connect_flag) { JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE); return; } // 查询工件质量 Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_1); if (!sendret) { JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE); } } else { JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE); } } public static void scanBarcode2() { if (work_status2 == 1) { JOptionPane.showMessageDialog(mesClientFrame, "工作中,勿扫码", "提示窗口", JOptionPane.INFORMATION_MESSAGE); return; } WorkTimer.ateq2.resetFIFO(); product_sn_2.setText(""); leakText_2.setText(""); pressureText_2.setText(""); MesClient.setMenuState_2("请扫工件码", 0); //弹窗扫工件码 // String scanBarcode = JOptionPane.showInputDialog(null, "请扫工件码"); String scanBarcode = MesClient.scanQrcode2(); if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) { product_sn_2.setText(scanBarcode); scan_time2 = System.currentTimeMillis(); //刷新界面 mesClientFrame.repaint(); if (!tcp_connect_flag) { JOptionPane.showMessageDialog(mesClientFrame, "设备未连接Mes服务器", "提示窗口", JOptionPane.INFORMATION_MESSAGE); return; } // 查询工件质量 Boolean sendret = DataUtil.checkQuality(nettyClient, scanBarcode.trim(), user20, Config.gw_2); if (!sendret) { JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE); } } else { JOptionPane.showMessageDialog(mesClientFrame, "请扫工件码", "提示窗口", JOptionPane.INFORMATION_MESSAGE); } } public static void logoff() { mesClientFrame.setVisible(false); welcomeWin.setVisible(true); nettyClient = null; tcp_connect_flag = false; allow_connect_again = false; mes_auth = 0; UpdateQualityTimer.stop(); // 停止更新质量的定时任务 WorkTimer.stop(); } private static void createQRCode(String s) { log.info("准备生成二维码"); if(s == null || s.isEmpty()){ log.info("生成二维码失败: 工件码为空"); return; } s = s.trim(); try { BitMatrix bitMatrix = new QRCodeWriter().encode(s, BarcodeFormat.QR_CODE, 200, 200); BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix); JDialog qrDialog = new JDialog(mesClientFrame, "", Dialog.ModalityType.APPLICATION_MODAL); qrDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); qrDialog.setSize(250, 250); qrDialog.setLocationRelativeTo(mesClientFrame); qrDialog.setResizable(false); JLabel qrLabel = new JLabel(new ImageIcon(qrImage)); qrDialog.getContentPane().add(qrLabel, BorderLayout.CENTER); qrDialog.setVisible(true); } catch (Exception e) { log.error("生成二维码失败", e); } } public MesClient() { setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png"))); setTitle("MES系统客户端:OP400A/OP400B " + "总成气密检测"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(0, 0, 1024, 768); JMenuBar menuBar = new JMenuBar(); menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26)); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("用户"); fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png"))); fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); menuBar.add(fileMenu); JMenuItem exitMenuItem = new JMenuItem("退出"); exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png"))); exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22)); fileMenu.add(exitMenuItem); exitMenuItem.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件 super.mouseClicked(e); logoff(); } }); JMenu settingMenu = new JMenu("设置"); //settingMenu.setVisible(false); settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png"))); settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); menuBar.add(settingMenu); JMenuItem resetTcpMenu = new JMenuItem("重连MES"); resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetTcpMenu.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); //重连mes nettyClient.future.channel().close(); } }); settingMenu.add(resetTcpMenu); JMenuItem resetTcpMenu_1 = new JMenuItem("刷新" + Config.gw_1); resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetTcpMenu_1.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); setMenuState_1("已手动刷新,请扫码", 0); resetScanA(); } }); settingMenu.add(resetTcpMenu_1); JMenuItem resetTcpMenu_2 = new JMenuItem("刷新" + Config.gw_2); resetTcpMenu_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetTcpMenu_2.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); setMenuState_2("已手动刷新,请扫码", 0); resetScanB(); } }); settingMenu.add(resetTcpMenu_2); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0)); JToolBar toolBar = new JToolBar(); contentPane.add(toolBar, BorderLayout.NORTH); JLabel equipment_statu_label = new JLabel("状态:"); equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER); equipment_statu_label.setForeground(Color.BLACK); equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); equipment_statu_label.setBackground(Color.LIGHT_GRAY); toolBar.add(equipment_statu_label); JButton status_menu = new JButton(""); status_menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); status_menu.setForeground(Color.GREEN); status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); status_menu.setBackground(Color.BLACK); toolBar.add(status_menu); JLabel space_1 = new JLabel(" "); toolBar.add(space_1); JLabel heart_beat_status_label = new JLabel("心跳:"); heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER); heart_beat_status_label.setForeground(Color.BLACK); heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); heart_beat_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(heart_beat_status_label); heart_beat_menu = new JButton(""); heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"))); heart_beat_menu.setForeground(Color.GREEN); heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); heart_beat_menu.setBackground(Color.BLACK); toolBar.add(heart_beat_menu); JLabel space_2 = new JLabel(" "); toolBar.add(space_2); JLabel user_status_label = new JLabel("登录用户:"); user_status_label.setHorizontalAlignment(SwingConstants.CENTER); user_status_label.setForeground(Color.BLACK); user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); user_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(user_status_label); user_menu = new JButton(""); user_menu.setForeground(Color.GREEN); user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22)); user_menu.setBackground(Color.BLACK); toolBar.add(user_menu); JLabel space_3 = new JLabel(" "); toolBar.add(space_3); JLabel space_4 = new JLabel(" "); toolBar.add(space_4); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); tabbedPane.setMinimumSize(new Dimension(400, 50)); tabbedPane.setFont(new Font("宋体", Font.BOLD, 22)); contentPane.add(tabbedPane); //首页 JPanel indexPanelA = new JPanel(); indexScrollPaneA = new JScrollPane(indexPanelA); indexPanelA.setLayout(null); // 工位1 product_sn_1 = new JTextField(); product_sn_1.setHorizontalAlignment(SwingConstants.CENTER); product_sn_1.setEditable(false); product_sn_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); product_sn_1.setBounds(0, 60, 489, 70); indexPanelA.add(product_sn_1); product_sn_1.setColumns(10); product_sn_1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { createQRCode(product_sn_1.getText()); } }); f_scan_data_bt_1 = new JButton("扫码"); f_scan_data_bt_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scanBarcode1();} }); f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png"))); f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32)); f_scan_data_bt_1.setBounds(280, 340, 171, 70); indexPanelA.add(f_scan_data_bt_1); finish_ok_bt_1 = new JButton("OK"); finish_ok_bt_1.setEnabled(false); finish_ok_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ok_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ok_bt_1.setBounds(0, 335, 125, 80); finish_ok_bt_1.setEnabled(false); indexPanelA.add(finish_ok_bt_1); finish_ng_bt_1 = new JButton("NG"); finish_ng_bt_1.setEnabled(false); finish_ng_bt_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); finish_ng_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png"))); finish_ng_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ng_bt_1.setBounds(128, 335, 125, 80); finish_ng_bt_1.setEnabled(false); indexPanelA.add(finish_ng_bt_1); status_menu_1 = new JButton("等待加工信号"); status_menu_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); status_menu_1.setForeground(Color.GREEN); status_menu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); status_menu_1.setBackground(Color.BLACK); status_menu_1.setBounds(100, 8, 340, 35); indexPanelA.add(status_menu_1); JLabel state_label_1 = new JLabel(Config.gw_1); state_label_1.setHorizontalAlignment(SwingConstants.LEFT); state_label_1.setForeground(Color.BLACK); state_label_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); state_label_1.setBackground(Color.LIGHT_GRAY); state_label_1.setBounds(0, 10, 150, 28); indexPanelA.add(state_label_1); JLabel lblNewLabel = new JLabel("压力"); lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 25)); lblNewLabel.setBounds(30, 160, 96, 53); indexPanelA.add(lblNewLabel); pressureText_1 = new JTextField(); pressureText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25)); pressureText_1.setEnabled(false); pressureText_1.setForeground(Color.BLACK); pressureText_1.setBounds(150, 160, 191, 56); indexPanelA.add(pressureText_1); pressureText_1.setColumns(10); JLabel lblNewLabel_1 = new JLabel("泄漏"); lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 25)); lblNewLabel_1.setBounds(30, 235, 96, 53); indexPanelA.add(lblNewLabel_1); leakText_1 = new JTextField(); leakText_1.setFont(new Font("微软雅黑", Font.PLAIN, 25)); leakText_1.setEnabled(false); leakText_1.setColumns(10); leakText_1.setBounds(150, 235, 191, 56); indexPanelA.add(leakText_1); JLabel serialportStr1 = new JLabel("串口:"); serialportStr1.setHorizontalAlignment(SwingConstants.LEFT); serialportStr1.setFont(new Font("微软雅黑", Font.PLAIN, 22)); indexPanelA.add(serialportStr1); serialportStr1.setBounds(338, 490, 100, 45); // 下拉框 JComboBox comboBox1 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12", "COM13", "COM14", "COM15", "COM16", "COM17", "COM18"}); comboBox1.setPreferredSize(new Dimension(90, 45)); comboBox1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); // 设置初始化选中项 comboBox1.setSelectedItem(Config.portName1); // 添加监听 comboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { String selectedItem = (String) e.getItem(); if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort1)) { int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { // 用户确认切换 log.info("============用户切换{}串口至 {}==============", Config.gw_1, selectedItem); currentSerialPort1 = selectedItem; WorkTimer.ateq1.replaceSerialUtil(new SerialUtil(selectedItem)); resetScanA(); setMenuState_1("切换" + Config.gw_1 + "串口至" + selectedItem + ",请扫码", 0); log.info("=============切换{}串口成功===================", Config.gw_1); } else { // 用户取消切换,恢复之前的选项 comboBox1.setSelectedItem(currentSerialPort1); } } } }); comboBox1.setBounds(385, 490, 100, 45); indexPanelA.add(comboBox1); // 工位2 product_sn_2 = new JTextField(); product_sn_2.setHorizontalAlignment(SwingConstants.CENTER); product_sn_2.setEditable(false); product_sn_2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); product_sn_2.setBounds(497, 60, 489, 70); indexPanelA.add(product_sn_2); product_sn_2.setColumns(10); product_sn_2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { createQRCode(product_sn_2.getText()); } }); f_scan_data_bt_2 = new JButton("扫码"); f_scan_data_bt_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scanBarcode2();} }); f_scan_data_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png"))); f_scan_data_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32)); f_scan_data_bt_2.setBounds(280+497, 340, 171, 70); indexPanelA.add(f_scan_data_bt_2); finish_ok_bt_2 = new JButton("OK"); finish_ok_bt_2.setEnabled(false); finish_ok_bt_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); finish_ok_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ok_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ok_bt_2.setBounds(497, 335, 125, 80); finish_ok_bt_2.setEnabled(false); indexPanelA.add(finish_ok_bt_2); finish_ng_bt_2 = new JButton("NG"); finish_ng_bt_2.setEnabled(false); finish_ng_bt_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {} }); finish_ng_bt_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png"))); finish_ng_bt_2.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ng_bt_2.setBounds(128 + 497, 335, 125, 80); finish_ng_bt_2.setEnabled(false); indexPanelA.add(finish_ng_bt_2); status_menu_2 = new JButton("等待加工信号"); status_menu_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); status_menu_2.setForeground(Color.GREEN); status_menu_2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); status_menu_2.setBackground(Color.BLACK); status_menu_2.setBounds(100+497, 8, 340, 35); indexPanelA.add(status_menu_2); JLabel state_label_2 = new JLabel(Config.gw_2); state_label_2.setHorizontalAlignment(SwingConstants.LEFT); state_label_2.setForeground(Color.BLACK); state_label_2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); state_label_2.setBackground(Color.LIGHT_GRAY); state_label_2.setBounds(497, 10, 150, 28); indexPanelA.add(state_label_2); JLabel lblNewLabel_2 = new JLabel("压力"); lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 25)); lblNewLabel_2.setBounds(530, 160, 96, 53); indexPanelA.add(lblNewLabel_2); pressureText_2 = new JTextField(); pressureText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25)); pressureText_2.setEnabled(false); pressureText_2.setForeground(Color.BLACK); pressureText_2.setBounds(650, 160, 191, 56); indexPanelA.add(pressureText_2); pressureText_2.setColumns(10); JLabel lblNewLabel_3 = new JLabel("泄漏"); lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 25)); lblNewLabel_3.setBounds(530, 235, 96, 53); indexPanelA.add(lblNewLabel_3); leakText_2 = new JTextField(); leakText_2.setFont(new Font("微软雅黑", Font.PLAIN, 25)); leakText_2.setEnabled(false); leakText_2.setColumns(10); leakText_2.setBounds(650, 235, 191, 56); indexPanelA.add(leakText_2); JLabel serialportStr2 = new JLabel("串口:"); serialportStr2.setHorizontalAlignment(SwingConstants.LEFT); serialportStr2.setFont(new Font("微软雅黑", Font.PLAIN, 22)); indexPanelA.add(serialportStr2); serialportStr2.setBounds(838, 490, 100, 45); // 下拉框 JComboBox comboBox2 = new JComboBox<>(new String[]{"COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10", "COM11","COM12","COM13", "COM14", "COM15", "COM16", "COM17", "COM18"}); comboBox2.setPreferredSize(new Dimension(90, 45)); comboBox2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); // 设置初始化选中项 comboBox2.setSelectedItem(Config.portName2); // 添加监听 comboBox2.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { String selectedItem = (String) e.getItem(); if (e.getStateChange() == ItemEvent.SELECTED && !Objects.equals(selectedItem, currentSerialPort2)) { int option = JOptionPane.showConfirmDialog(mesClientFrame, "确定切换串口至" + selectedItem + "?", "切换串口", JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { // 用户确认切换 log.info("==============用户切换{}串口至 {}===============", Config.gw_2, selectedItem); currentSerialPort2 = selectedItem; WorkTimer.ateq2.replaceSerialUtil(new SerialUtil(selectedItem)); resetScanB(); setMenuState_2("切换" + Config.gw_2 + "串口至" + selectedItem + ",请扫码", 0); log.info("==============切换{}串口成功=====================", Config.gw_2); } else { // 用户取消切换,恢复之前的选项 comboBox2.setSelectedItem(currentSerialPort2); } } } }); comboBox2.setBounds(885, 490, 100, 45); indexPanelA.add(comboBox2); Panel panel1 = new Panel(); panel1.setEnabled(false); panel1.setBackground(SystemColor.activeCaptionBorder); panel1.setBounds(490, 0, 6, 600); indexPanelA.add(panel1); tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null); tabbedPane.setEnabledAt(0, true); indexPanelDjA = new JPanel(); searchScrollPaneDjA = new JScrollPane(indexPanelDjA); indexPanelDjA.setLayout(null); tabbedPane.addTab(Config.gw_1 + "开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDjA, null); indexPanelDjB = new JPanel(); searchScrollPaneDjB = new JScrollPane(indexPanelDjB); indexPanelDjB.setLayout(null); tabbedPane.addTab(Config.gw_2 + "开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDjB, null); indexPanelB = new JPanel(); searchScrollPane = new JScrollPane(indexPanelB); indexPanelB.setLayout(null); //获取配置文件mes.gw_1值 tabbedPane.addTab(Config.gw_1+"记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null); panel5 = new JPanel(); scrollPane5 = new JScrollPane(panel5); panel5.setLayout(null); tabbedPane.addTab(Config.gw_2+"记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPane5, null); panelOkng = new JPanel(); scrollPaneOkng = new JScrollPane(panelOkng); panelOkng.setLayout(null); tabbedPane.addTab("OKNG样件", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPaneOkng, null); // 员工工作记录 panel4 = new JPanel(); scrollPane4 = new JScrollPane(panel4); panel4.setLayout(null); tabbedPane.addTab("人员记录", scrollPane4); tabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); int selectedIndex = tabbedPane.getSelectedIndex(); if (selectedIndex == 1) { } // 切换 tab 时刷新记录查询(保持与 OP370-AUTO 一致:打开页面自动刷新) // gw_1记录 tab index: 3, gw_2记录 tab index: 4, OKNG样件 tab index: 5 if (selectedIndex == 3) { loadRecordData_1(); } else if (selectedIndex == 4) { loadRecordData_2(); } else if (selectedIndex == 5) { loadOkngRecordData(); } } }); // 初始化两条线的“记录查询”界面 initRecordPanel_1(indexPanelB); initRecordPanel_2(panel5); initOkngRecordPanel(panelOkng); } private static void initRecordPanel_1(JPanel container) { // 顶部搜索栏 JPanel top = new JPanel(); top.setBounds(0, 0, 990, 50); top.setLayout(null); container.add(top); recordSearchField_1 = new JTextField(); recordSearchField_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); recordSearchField_1.setForeground(Color.BLACK); recordSearchField_1.setBounds(10, 5, 371, 40); top.add(recordSearchField_1); JButton searchBtn = new JButton("搜索"); searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); searchBtn.setBounds(385, 5, 90, 40); top.add(searchBtn); searchBtn.addActionListener(e -> { recordPageNo_1 = 1; loadRecordData_1(); }); JButton resetBtn = new JButton("重置"); resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn.setBounds(475, 5, 90, 40); top.add(resetBtn); resetBtn.addActionListener(e -> { recordSearchField_1.setText(""); recordPageNo_1 = 1; loadRecordData_1(); }); JButton btnPrevious = new JButton("上一页"); btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnPrevious.setBounds(680, 5, 100, 40); top.add(btnPrevious); btnPrevious.addActionListener(e -> { if (recordPageNo_1 > 1) { recordPageNo_1--; loadRecordData_1(); } }); recordPageLabel_1 = new JLabel("0/0"); recordPageLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 18)); recordPageLabel_1.setHorizontalAlignment(SwingConstants.CENTER); recordPageLabel_1.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); recordPageLabel_1.setBounds(780, 5, 100, 40); top.add(recordPageLabel_1); JButton btnNext = new JButton("下一页"); btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnNext.setBounds(880, 5, 100, 40); top.add(btnNext); btnNext.addActionListener(e -> { if (recordPageNo_1 < recordTotalPages_1) { recordPageNo_1++; loadRecordData_1(); } }); // 表格区域 JPanel tablePanel = new JPanel(); tablePanel.setBounds(0, 49, 990, 518); tablePanel.setLayout(new GridLayout(0, 1, 0, 0)); container.add(tablePanel); recordTable_1 = new JTable(recordRowData_1, recordColumnNames_1) { public boolean isCellEditable(int row, int column) { return false; } }; recordTable_1.setRowHeight(40); recordTable_1.setEnabled(true); recordTable_1.setFont(new Font("微软雅黑", Font.PLAIN, 14)); javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); recordTable_1.setDefaultRenderer(Object.class, centerRenderer); JScrollPane scrollPane = new JScrollPane(recordTable_1); tablePanel.add(scrollPane); // 初次加载 loadRecordData_1(); } private static void initRecordPanel_2(JPanel container) { JPanel top = new JPanel(); top.setBounds(0, 0, 990, 50); top.setLayout(null); container.add(top); recordSearchField_2 = new JTextField(); recordSearchField_2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); recordSearchField_2.setForeground(Color.BLACK); recordSearchField_2.setBounds(10, 5, 371, 40); top.add(recordSearchField_2); JButton searchBtn = new JButton("搜索"); searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); searchBtn.setBounds(385, 5, 90, 40); top.add(searchBtn); searchBtn.addActionListener(e -> { recordPageNo_2 = 1; loadRecordData_2(); }); JButton resetBtn = new JButton("重置"); resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn.setBounds(475, 5, 90, 40); top.add(resetBtn); resetBtn.addActionListener(e -> { recordSearchField_2.setText(""); recordPageNo_2 = 1; loadRecordData_2(); }); JButton btnPrevious = new JButton("上一页"); btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnPrevious.setBounds(680, 5, 100, 40); top.add(btnPrevious); btnPrevious.addActionListener(e -> { if (recordPageNo_2 > 1) { recordPageNo_2--; loadRecordData_2(); } }); recordPageLabel_2 = new JLabel("0/0"); recordPageLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 18)); recordPageLabel_2.setHorizontalAlignment(SwingConstants.CENTER); recordPageLabel_2.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); recordPageLabel_2.setBounds(780, 5, 100, 40); top.add(recordPageLabel_2); JButton btnNext = new JButton("下一页"); btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnNext.setBounds(880, 5, 100, 40); top.add(btnNext); btnNext.addActionListener(e -> { if (recordPageNo_2 < recordTotalPages_2) { recordPageNo_2++; loadRecordData_2(); } }); JPanel tablePanel = new JPanel(); tablePanel.setBounds(0, 49, 990, 518); tablePanel.setLayout(new GridLayout(0, 1, 0, 0)); container.add(tablePanel); recordTable_2 = new JTable(recordRowData_2, recordColumnNames_2) { public boolean isCellEditable(int row, int column) { return false; } }; recordTable_2.setRowHeight(40); recordTable_2.setEnabled(true); recordTable_2.setFont(new Font("微软雅黑", Font.PLAIN, 14)); javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); recordTable_2.setDefaultRenderer(Object.class, centerRenderer); JScrollPane scrollPane = new JScrollPane(recordTable_2); tablePanel.add(scrollPane); loadRecordData_2(); } private static void initOkngRecordPanel(JPanel container) { JPanel top = new JPanel(); top.setBounds(0, 0, 990, 50); top.setLayout(null); container.add(top); recordSearchFieldOkng = new JTextField(); recordSearchFieldOkng.setFont(new Font("微软雅黑", Font.PLAIN, 16)); recordSearchFieldOkng.setForeground(Color.BLACK); recordSearchFieldOkng.setBounds(10, 5, 371, 40); top.add(recordSearchFieldOkng); JButton searchBtn = new JButton("搜索"); searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); searchBtn.setBounds(385, 5, 90, 40); top.add(searchBtn); searchBtn.addActionListener(e -> { recordPageNoOkng = 1; loadOkngRecordData(); }); JButton resetBtn = new JButton("重置"); resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn.setBounds(475, 5, 90, 40); top.add(resetBtn); resetBtn.addActionListener(e -> { recordSearchFieldOkng.setText(""); recordPageNoOkng = 1; loadOkngRecordData(); }); JButton btnPrevious = new JButton("上一页"); btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnPrevious.setBounds(680, 5, 100, 40); top.add(btnPrevious); btnPrevious.addActionListener(e -> { if (recordPageNoOkng > 1) { recordPageNoOkng--; loadOkngRecordData(); } }); recordPageLabelOkng = new JLabel("0/0"); recordPageLabelOkng.setFont(new Font("微软雅黑", Font.PLAIN, 18)); recordPageLabelOkng.setHorizontalAlignment(SwingConstants.CENTER); recordPageLabelOkng.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); recordPageLabelOkng.setBounds(780, 5, 100, 40); top.add(recordPageLabelOkng); JButton btnNext = new JButton("下一页"); btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnNext.setBounds(880, 5, 100, 40); top.add(btnNext); btnNext.addActionListener(e -> { if (recordPageNoOkng < recordTotalPagesOkng) { recordPageNoOkng++; loadOkngRecordData(); } }); JPanel tablePanel = new JPanel(); tablePanel.setBounds(0, 49, 990, 518); tablePanel.setLayout(new GridLayout(0, 1, 0, 0)); container.add(tablePanel); recordTableOkng = new JTable(recordRowDataOkng, recordColumnNamesOkng) { public boolean isCellEditable(int row, int column) { return false; } }; recordTableOkng.setRowHeight(40); recordTableOkng.setEnabled(true); recordTableOkng.setFont(new Font("微软雅黑", Font.PLAIN, 14)); javax.swing.table.DefaultTableCellRenderer centerRenderer = new javax.swing.table.DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); recordTableOkng.setDefaultRenderer(Object.class, centerRenderer); JScrollPane scrollPane = new JScrollPane(recordTableOkng); tablePanel.add(scrollPane); } private static boolean refreshOkngSamples() { okngSampleSns.clear(); okngSampleType.clear(); JSONObject ret = DataUtil.getQmSampleSns(Config.gw_1, Config.line_sn); if (ret == null || !"true".equalsIgnoreCase(String.valueOf(ret.get("result")))) { return false; } JSONObject data = ret.getJSONObject("data"); if (data == null) { return true; } addOkngSamples(data.getString("ok"), "OK件"); addOkngSamples(data.getString("ng"), "NG件"); return true; } private static void addOkngSamples(String sns, String type) { if (sns == null || sns.trim().isEmpty()) { return; } for (String sn : sns.split(",", -1)) { String code = sn.trim(); if (code.isEmpty()) { continue; } if (!okngSampleSns.contains(code)) { okngSampleSns.add(code); } String old = okngSampleType.get(code); if (old == null) { okngSampleType.put(code, type); } else if (!old.equals(type) && !old.contains(type)) { okngSampleType.put(code, old + "/" + type); } } } private static void loadOkngRecordData() { clearRecordRowData(recordRowDataOkng); boolean loaded = refreshOkngSamples(); int pageSize = 12; String snLike = recordSearchFieldOkng == null ? "" : recordSearchFieldOkng.getText(); List oprnos = new ArrayList<>(); oprnos.add(Config.gw_1); oprnos.add(Config.gw_2); if (!loaded) { recordTotalPagesOkng = 0; if (recordPageLabelOkng != null) recordPageLabelOkng.setText("失败"); if (recordTableOkng != null) recordTableOkng.repaint(); return; } int totalItems = QMParamsDAO.countByOprnosAndSns(oprnos, okngSampleSns, snLike); if (totalItems <= 0) { recordTotalPagesOkng = 0; if (recordPageLabelOkng != null) recordPageLabelOkng.setText(okngSampleSns.isEmpty() ? "未配置" : "0/0"); if (recordTableOkng != null) recordTableOkng.repaint(); return; } recordTotalPagesOkng = (int) Math.ceil((double) totalItems / (double) pageSize); if (recordPageNoOkng > recordTotalPagesOkng) recordPageNoOkng = recordTotalPagesOkng; if (recordPageNoOkng < 1) recordPageNoOkng = 1; if (recordPageLabelOkng != null) recordPageLabelOkng.setText(recordPageNoOkng + "/" + recordTotalPagesOkng); int offset = (recordPageNoOkng - 1) * pageSize; List> rows = QMParamsDAO.queryByOprnosAndSns(oprnos, okngSampleSns, snLike, pageSize, offset); int rowIndex = 0; for (Map r : rows) { if (rowIndex >= recordRowDataOkng.length) break; String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn")).trim(); String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time")); String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value"))) + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit"))); String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value"))) + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit"))); String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result")); String oprno = r.get("oprno") == null ? "" : String.valueOf(r.get("oprno")); recordRowDataOkng[rowIndex][0] = oprno; recordRowDataOkng[rowIndex][1] = okngSampleType.getOrDefault(sn, ""); recordRowDataOkng[rowIndex][2] = sn; recordRowDataOkng[rowIndex][3] = recordTime; recordRowDataOkng[rowIndex][4] = pressure; recordRowDataOkng[rowIndex][5] = leak; recordRowDataOkng[rowIndex][6] = result; rowIndex++; } if (recordTableOkng != null) recordTableOkng.repaint(); } private static void clearRecordRowData(Object[][] rowData) { for (int i = 0; i < rowData.length; i++) { for (int j = 0; j < rowData[i].length; j++) { rowData[i][j] = null; } } } private static void loadRecordData_1() { clearRecordRowData(recordRowData_1); int pageSize = 12; int offset = (recordPageNo_1 - 1) * pageSize; String snLike = recordSearchField_1 == null ? "" : recordSearchField_1.getText(); int totalItems = QMParamsDAO.countByOprnoAndSnLike(Config.gw_1, snLike); if (totalItems <= 0) { recordTotalPages_1 = 0; if (recordPageLabel_1 != null) recordPageLabel_1.setText("0/0"); if (recordTable_1 != null) recordTable_1.repaint(); return; } recordTotalPages_1 = (int) Math.ceil((double) totalItems / (double) pageSize); if (recordPageNo_1 > recordTotalPages_1) recordPageNo_1 = recordTotalPages_1; if (recordPageLabel_1 != null) recordPageLabel_1.setText(recordPageNo_1 + "/" + recordTotalPages_1); java.util.List> rows = QMParamsDAO.queryByOprnoAndSnLike(Config.gw_1, snLike, pageSize, offset); int rowIndex = 0; for (java.util.Map r : rows) { if (rowIndex >= recordRowData_1.length) break; String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn")); String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time")); String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value"))) + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit"))); String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value"))) + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit"))); String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result")); recordRowData_1[rowIndex][0] = sn; recordRowData_1[rowIndex][1] = recordTime; recordRowData_1[rowIndex][2] = pressure; recordRowData_1[rowIndex][3] = leak; recordRowData_1[rowIndex][4] = result; rowIndex++; } if (recordTable_1 != null) recordTable_1.repaint(); } private static void loadRecordData_2() { clearRecordRowData(recordRowData_2); int pageSize = 12; int offset = (recordPageNo_2 - 1) * pageSize; String snLike = recordSearchField_2 == null ? "" : recordSearchField_2.getText(); int totalItems = QMParamsDAO.countByOprnoAndSnLike(Config.gw_2, snLike); if (totalItems <= 0) { recordTotalPages_2 = 0; if (recordPageLabel_2 != null) recordPageLabel_2.setText("0/0"); if (recordTable_2 != null) recordTable_2.repaint(); return; } recordTotalPages_2 = (int) Math.ceil((double) totalItems / (double) pageSize); if (recordPageNo_2 > recordTotalPages_2) recordPageNo_2 = recordTotalPages_2; if (recordPageLabel_2 != null) recordPageLabel_2.setText(recordPageNo_2 + "/" + recordTotalPages_2); java.util.List> rows = QMParamsDAO.queryByOprnoAndSnLike(Config.gw_2, snLike, pageSize, offset); int rowIndex = 0; for (java.util.Map r : rows) { if (rowIndex >= recordRowData_2.length) break; String sn = r.get("sn") == null ? "" : String.valueOf(r.get("sn")); String recordTime = r.get("record_time") == null ? "" : String.valueOf(r.get("record_time")); String pressure = (r.get("pressure_value") == null ? "" : String.valueOf(r.get("pressure_value"))) + (r.get("pressure_unit") == null ? "" : String.valueOf(r.get("pressure_unit"))); String leak = (r.get("leak_value") == null ? "" : String.valueOf(r.get("leak_value"))) + (r.get("leak_unit") == null ? "" : String.valueOf(r.get("leak_unit"))); String result = r.get("test_result") == null ? "" : String.valueOf(r.get("test_result")); recordRowData_2[rowIndex][0] = sn; recordRowData_2[rowIndex][1] = recordTime; recordRowData_2[rowIndex][2] = pressure; recordRowData_2[rowIndex][3] = leak; recordRowData_2[rowIndex][4] = result; rowIndex++; } if (recordTable_2 != null) recordTable_2.repaint(); } public static void setMenuState_1(String msg, int error) { if (error == 0) { MesClient.status_menu_1.setForeground(Color.GREEN); } else { MesClient.status_menu_1.setForeground(Color.RED); } MesClient.status_menu_1.setText(msg); } public static void setMenuState_2(String msg, int error) { if (error == 0) { MesClient.status_menu_2.setForeground(Color.GREEN); } else { MesClient.status_menu_2.setForeground(Color.RED); } MesClient.status_menu_2.setText(msg); } public static void getMaterailData() { JSONObject retObj = DataUtil.getBindMaterail(); if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) { java.util.List arrs = retObj.getList("data", BindMaterialResp.class); int i = 0; rowData = new Object[arrs.size()][7]; for (BindMaterialResp bindMaterialResp : arrs) { rowData[i][0] = bindMaterialResp.getMaterialTitle(); rowData[i][1] = bindMaterialResp.getBatchSn(); rowData[i][2] = bindMaterialResp.getLastTimes(); rowData[i][3] = ""; rowData[i][4] = bindMaterialResp.getCraft(); rowData[i][5] = bindMaterialResp.getMaterialId(); rowData[i][6] = bindMaterialResp.getType(); i++; } bindBatchPanel(); } } public static void updateMaterailData() { JSONObject retObj = DataUtil.getBindMaterail(); if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) { List arrs = retObj.getList("data", BindMaterialResp.class); int i = 0; for (BindMaterialResp bindMaterialResp : arrs) { rowData[i][0] = bindMaterialResp.getMaterialTitle(); rowData[i][1] = bindMaterialResp.getBatchSn(); rowData[i][2] = bindMaterialResp.getLastTimes(); rowData[i][3] = ""; rowData[i][4] = bindMaterialResp.getCraft(); rowData[i][5] = bindMaterialResp.getMaterialId(); rowData[i][6] = bindMaterialResp.getType(); i++; } MesClient.table.repaint(); } } // 绑定物料批次码 public static void scanBatchSn(BindMaterialResp bindMaterialResp) { //弹窗扫工件码 String scanBarcodeTitle = "请扫物料:" + bindMaterialResp.getMaterialTitle(); String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle); if (scanBarcode != null && !scanBarcode.equalsIgnoreCase("")) { JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode, bindMaterialResp.getCraft(), bindMaterialResp.getMaterialId(), bindMaterialResp.getType()); if (retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) { MesClient.setMenuState_1("扫物料:" + bindMaterialResp.getMaterialTitle() + "成功", 0); updateMaterailData(); } else { if (retObj.get("result") == null) { MesClient.setMenuState_1("请求失败,请重试", -1); } else { if (retObj.get("result").toString().equalsIgnoreCase("false")) { MesClient.setMenuState_1(retObj.getString("message"), -1); } } } } } public static void bindBatchPanel() { JPanel indexPanelBB = new JPanel(); JPanel panel = new JPanel(); panel.setBounds(0, 0, 990, 550); // panel.setBounds(81, 50, 810, 479); indexPanelBB.add(panel); panel.setLayout(new GridLayout(0, 1, 0, 0)); table = new JTable(rowData, columnNames) { public boolean isCellEditable(int row, int column) { if (column == 3) { return true; } return false; } }; table.setRowHeight(40); table.setEnabled(true); table.setFont(new Font("微软雅黑", Font.PLAIN, 14)); table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton()); table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton()); JScrollPane scrollPane = new JScrollPane(table); panel.add(scrollPane); JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB); indexPanelBB.setLayout(null); tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null); } public static String scanQrcode1(){ if(scanFlag1 == 1){ return ""; } scanFlag1 = 1; String sn = ""; try{ if (tcpClient1.socket == null || !tcpClient1.socket.isConnected() || tcpClient1.socket.isClosed()) { tcpClient1.connect(); } log.error("扫码枪1正在进行扫码,请勿操作",0); sn = tcpClient1.receiveResponse(); if (sn == null || sn.equals("")) { sn = ""; } tcpClient1.close(); }catch (Exception e) { e.printStackTrace(); log.error("scanQrcode1:"+sn); tcpClient1.close(); } MesClient.setMenuState_1(sn,0); scanFlag1 = 0; return sn; } public static String scanQrcode2(){ if(scanFlag2 == 1){ return ""; } scanFlag2 = 1; String sn = ""; try{ if (tcpClient2.socket == null || !tcpClient2.socket.isConnected() || tcpClient2.socket.isClosed()) { tcpClient2.connect(); } log.error("扫码枪2正在进行扫码,请勿操作",0); sn = tcpClient2.receiveResponse(); if (sn == null || sn.equals("")) { sn = ""; } tcpClient2.close(); }catch (Exception e) { e.printStackTrace(); log.error("scanQrcode2:"+sn); tcpClient2.close(); } MesClient.setMenuState_2(sn,0); scanFlag2 = 0; return sn; } }