| | |
| | | import xitongshezhi.AdminLoginDialog; |
| | | import xitongshezhi.CardPickupDialog; |
| | | import xitongshezhi.ConfigSet; |
| | | import xitongshezhi.Fkj; |
| | | import chuankou.SerialPortService; |
| | | import chuankou.Sendmsg; |
| | | |
| | |
| | | private JPanel commFaultPanel; |
| | | |
| | | public CardMachineUI() { |
| | | try { |
| | | try { |
| | | // 先初始化系统配置和组件 |
| | | initializeSystem(); |
| | | |
| | | // 初始化串口解析器 |
| | | initializeSerialParser(); |
| | | |
| | | // 然后初始化UI |
| | | initializeUI(); |
| | |
| | | startUIUpdates(); // UI刷新定时器 |
| | | startSerialStatusMonitoring(); // 串口状态监控 |
| | | |
| | | System.out.println("主界面初始化完成"); |
| | | //System.out.println("主界面初始化完成"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | JOptionPane.showMessageDialog(null, |
| | |
| | | if (serialConnected && lunxun.isPolling() && lunxun.isPaused()) { |
| | | // 只有在不在设置页面时才自动恢复 |
| | | if (!isInConfigPage()) { |
| | | lunxun.resumePolling(); |
| | | // lunxun.resumePolling(); |
| | | // System.out.println("尝试自动启动轮询功能"); |
| | | } |
| | | } |
| | | }); |
| | |
| | | try { |
| | | // 初始化卡槽管理器 - 必须首先执行 |
| | | slotManager = new SlotManager(); |
| | | System.out.println("卡槽管理器初始化完成"); |
| | | //System.out.println("卡槽管理器初始化完成"); |
| | | |
| | | // 直接使用已经初始化的配置系统 |
| | | Chushihua configSystem = Chushihua.getInstance(); |
| | |
| | | PICKUP_PASSWORD = configSystem.getMachineConfig().getFetchCardPassword(); |
| | | } |
| | | |
| | | System.out.println("系统配置初始化完成"); |
| | | System.out.println("管理员密码长度: " + (ADMIN_PASSWORD != null ? ADMIN_PASSWORD.length() : "null")); |
| | | System.out.println("取卡密码长度: " + (PICKUP_PASSWORD != null ? PICKUP_PASSWORD.length() : "null")); |
| | | //System.out.println("系统配置初始化完成"); |
| | | //System.out.println("管理员密码长度: " + (ADMIN_PASSWORD != null ? ADMIN_PASSWORD.length() : "null")); |
| | | //System.out.println("取卡密码长度: " + (PICKUP_PASSWORD != null ? PICKUP_PASSWORD.length() : "null")); |
| | | |
| | | } catch (Exception e) { |
| | | System.err.println("系统初始化异常: " + e.getMessage()); |
| | |
| | | } |
| | | |
| | | private void initializeUI() { |
| | | setTitle("UWB人员定位卡发卡机管理系统"); |
| | | setTitle("智能人脸发卡机管理系统"); |
| | | setSize(SCREEN_WIDTH, SCREEN_HEIGHT); |
| | | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| | | setLocationRelativeTo(null); |
| | |
| | | refreshBtn.addActionListener(e -> { |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | lunxun.resumePolling(); |
| | | JOptionPane.showMessageDialog(CardMachineUI.this, |
| | | "手动刷新完成,共刷新 " + TOTAL_SLOTS + " 个卡槽", |
| | | "手动刷新完成,启动轮询,共刷新 " + TOTAL_SLOTS + " 个卡槽", |
| | | "刷新完成", JOptionPane.INFORMATION_MESSAGE); |
| | | }); |
| | | |
| | |
| | | cardSlotsPanel.removeAll(); |
| | | slotButtons.clear(); |
| | | |
| | | int updatedSlots = 0; |
| | | int errorSlots = 0; |
| | | |
| | | for (int i = 1; i <= TOTAL_SLOTS; i++) { |
| | | final int slotId = i; |
| | | SlotStatus status = getSlotStatusFromManager(slotId); |
| | |
| | | // 添加调试信息 |
| | | Fkj slotInfo = slotManager.getSlotInfo(slotId); |
| | | if (slotInfo != null) { |
| | | updatedSlots++; |
| | | } else { |
| | | System.err.println("卡槽 " + slotId + " - 获取信息失败"); |
| | | errorSlots++; |
| | | } |
| | | |
| | | JButton slotButton = new JButton(String.valueOf(slotId)); |
| | |
| | | cardSlotsPanel.revalidate(); |
| | | cardSlotsPanel.repaint(); |
| | | |
| | | System.out.println("卡槽显示更新完成: " + updatedSlots + " 个成功, " + errorSlots + " 个失败"); |
| | | // //System.out.println("卡槽显示更新完成: " + updatedSlots + " 个成功, " + errorSlots + " 个失败"); |
| | | } |
| | | |
| | | private Color brighterColor(Color color) { |
| | |
| | | if (panel.getComponentCount() >= 2) { |
| | | JLabel textLabel = (JLabel) panel.getComponent(1); |
| | | if (textLabel.getText().startsWith("串口:")) { |
| | | String statusText = lunxun.isSerialConnected() ? "正常" : "断开"; |
| | | Color statusColor = lunxun.isSerialConnected() ? |
| | | new Color(52, 152, 219) : new Color(231, 76, 60); |
| | | |
| | |
| | | boolean pickupSuccess = CardPickupDialog.showCardPickup(this, slotId, status); |
| | | |
| | | if (pickupSuccess) { |
| | | // 取卡成功,界面已经在对话框中更新,这里不需要额外操作 |
| | | System.out.println("卡槽 " + slotId + " 取卡成功"); |
| | | // 取卡成功,调用changgehaska方法改变卡槽属性 |
| | | SlotManager.changgehaska(slotId,1); // "1"表示管理员操作 |
| | | //System.out.println("卡槽 " + slotId + " 取卡成功,已更新卡槽状态"); |
| | | } |
| | | } |
| | | |
| | |
| | | // 停止轮询查询 |
| | | if (lunxun.isPolling()) { |
| | | lunxun.stopPolling(); |
| | | System.out.println("应用程序关闭,轮询查询已停止"); |
| | | //System.out.println("应用程序关闭,轮询查询已停止"); |
| | | } |
| | | |
| | | // 停止串口协议解析器(新增) |
| | |
| | | return "串口解析器未初始化"; |
| | | } |
| | | |
| | | /** |
| | | * 创建美化按钮 |
| | | */ |
| | | private JButton createStyledButton(String text, Color color) { |
| | | JButton button = new JButton(text); |
| | | button.setFont(new Font("Microsoft YaHei", Font.BOLD, 14)); |
| | | button.setBackground(color); |
| | | button.setForeground(Color.WHITE); |
| | | button.setFocusPainted(false); |
| | | button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); |
| | | button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
| | | |
| | | // 鼠标悬停效果 |
| | | button.addMouseListener(new java.awt.event.MouseAdapter() { |
| | | public void mouseEntered(java.awt.event.MouseEvent evt) { |
| | | button.setBackground(brighterColor(color)); |
| | | } |
| | | |
| | | public void mouseExited(java.awt.event.MouseEvent evt) { |
| | | button.setBackground(color); |
| | | } |
| | | }); |
| | | |
| | | return button; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 验证取卡密码 |
| | | */ |
| | |
| | | if (lunxun.checkSerialConnection()) { |
| | | boolean resumed = lunxun.setPollingPaused(false); |
| | | if (resumed) { |
| | | System.out.println("切换到主页面,轮询查询已恢复"); |
| | | //System.out.println("切换到主页面,轮询查询已恢复"); |
| | | } |
| | | } else { |
| | | System.err.println("切换到主页面,串口未连接,保持轮询暂停"); |
| | |
| | | /** |
| | | * 启动UI刷新定时器 - 每3秒刷新一次 |
| | | */ |
| | | // 在startUIUpdates()方法中调用 |
| | | private void startUIUpdates() { |
| | | uiUpdateTimer = new Timer(3000, e -> { |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | }); |
| | | uiUpdateTimer.start(); |
| | | uiUpdateTimer = new Timer(3000, e -> { |
| | | ensurePollingRunning(); // 确保轮询运行 |
| | | ensureSerialParserRunning(); // 确保串口解析器运行 |
| | | updateCardSlotsDisplay(); |
| | | updateStatistics(); |
| | | }); |
| | | uiUpdateTimer.start(); |
| | | } |
| | | |
| | | /** |
| | |
| | | public SlotManager getSlotManager() { |
| | | return slotManager; |
| | | } |
| | | |
| | | /** |
| | | * 检查并确保轮询查询正常运行 |
| | | */ |
| | | private void ensurePollingRunning() { |
| | | if (!lunxun.isPolling() && lunxun.checkSerialConnection()) { |
| | | // 如果轮询未运行但串口已连接,自动启动轮询 |
| | | boolean started = lunxun.startPolling(); |
| | | if (started) { |
| | | System.out.println("检测到轮询未运行,已自动启动"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 确保串口解析器正常运行 |
| | | */ |
| | | private void ensureSerialParserRunning() { |
| | | // 如果串口解析器未运行但串口已连接,自动启动 |
| | | if (serialProtocolParser != null && !serialProtocolParser.isRunning() && lunxun.checkSerialConnection()) { |
| | | serialProtocolParser.start(); |
| | | //System.out.println("检测到串口解析器未运行,已自动启动"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化串口解析器 |
| | | */ |
| | | private void initializeSerialParser() { |
| | | try { |
| | | serialProtocolParser = new SerialProtocolParser(); |
| | | serialProtocolParser.start(); |
| | | //System.out.println("串口协议解析器已启动"); |
| | | } catch (Exception e) { |
| | | System.err.println("初始化串口解析器失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |