From d6ed5e0d75183b3c2e7722ef72daca458ce23764 Mon Sep 17 00:00:00 2001 From: bitkylin Date: Thu, 18 May 2017 10:13:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=EF=BC=8C=E5=87=86=E5=A4=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E5=A5=97=E7=9A=84=20GUI=20=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.gitignore | 0 .../pom.xml | 4 ++-- .../src/main/java/cc/bitky/clustermanage/App.java | 0 .../main/java/cc/bitky/clustermanage/netty/NettyServer.java | 0 .../clustermanage/netty/WebMsgDeployEmployeeDepartment2.java | 0 .../netty/handler/CanFrameChannelInboundHandler.java | 0 .../clustermanage/netty/handler/KyChannelInitializer.java | 0 .../bitky/clustermanage/netty/handler/KyOutBoundHandler.java | 0 .../netty/handler/ParsedMessageInBoundHandler.java | 0 .../java/cc/bitky/clustermanage/netty/message/CardType.java | 0 .../java/cc/bitky/clustermanage/netty/message/MsgType.java | 0 .../netty/message/WebMsgDeployFreeCardSpecial.java | 0 .../bitky/clustermanage/netty/message/base/BaseMessage.java | 0 .../clustermanage/netty/message/base/BaseMsgCardNum.java | 0 .../clustermanage/netty/message/base/BaseTcpResponseMsg.java | 0 .../cc/bitky/clustermanage/netty/message/base/IMessage.java | 0 .../clustermanage/netty/message/base/WebMsgBaseEmployee.java | 0 .../clustermanage/netty/message/tcp/MsgErrorMessage.java | 0 .../netty/message/tcp/TcpMsgInitResponseCardNumber.java | 0 .../clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java | 0 .../netty/message/tcp/TcpMsgResponseDeviceStatus.java | 0 .../netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java | 0 .../netty/message/tcp/TcpMsgResponseEmployeeDepartment.java | 0 .../netty/message/tcp/TcpMsgResponseEmployeeName.java | 0 .../netty/message/tcp/TcpMsgResponseFreeCardNumber.java | 0 .../netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java | 0 .../netty/message/tcp/TcpMsgResponseRemainChargeTimes.java | 0 .../netty/message/web/WebMsgDeployEmployeeCardNumber.java | 0 .../netty/message/web/WebMsgDeployEmployeeDepartment.java | 0 .../netty/message/web/WebMsgDeployEmployeeDeviceId.java | 0 .../netty/message/web/WebMsgDeployEmployeeName.java | 0 .../netty/message/web/WebMsgDeployRemainChargeTimes.java | 0 .../netty/message/web/WebMsgInitClearDeviceStatus.java | 0 .../netty/message/web/WebMsgInitMarchConfirmCardResponse.java | 0 .../netty/message/web/WebMsgObtainDeviceStatus.java | 0 .../netty/message/web/WebMsgOperateBoxUnlock.java | 0 .../java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java | 0 .../src/main/java/cc/bitky/clustermanage/utils/KyLog.java | 0 .../java/cc/bitky/clustermanage/utils/SuccessfulListener.java | 0 .../main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java | 0 .../java/cc/bitky/clustermanage/utils/TcpReceiveListener.java | 0 .../java/cc/bitky/clustermanage/utils/TcpSendListener.java | 0 .../src/main/resources/logback.xml | 0 clustermanage-server/pom.xml | 2 +- 44 files changed, 3 insertions(+), 3 deletions(-) rename {clustermanage-client => clustermanage-client-console}/.gitignore (100%) rename {clustermanage-client => clustermanage-client-console}/pom.xml (97%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/App.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/WebMsgDeployEmployeeDepartment2.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/WebMsgDeployFreeCardSpecial.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/KyLog.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java (100%) rename {clustermanage-client => clustermanage-client-console}/src/main/resources/logback.xml (100%) diff --git a/clustermanage-client/.gitignore b/clustermanage-client-console/.gitignore similarity index 100% rename from clustermanage-client/.gitignore rename to clustermanage-client-console/.gitignore diff --git a/clustermanage-client/pom.xml b/clustermanage-client-console/pom.xml similarity index 97% rename from clustermanage-client/pom.xml rename to clustermanage-client-console/pom.xml index 6c536b8..efe3dae 100644 --- a/clustermanage-client/pom.xml +++ b/clustermanage-client-console/pom.xml @@ -5,10 +5,10 @@ cc.bitky.clustermanage clustermanage-client - 0.7.0-SNAPSHOT + 0.8.5-SNAPSHOT jar - clustermanage-client + clustermanage-client-console http://maven.apache.org diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/App.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/App.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/App.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/App.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/WebMsgDeployEmployeeDepartment2.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/WebMsgDeployEmployeeDepartment2.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/WebMsgDeployEmployeeDepartment2.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/WebMsgDeployEmployeeDepartment2.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/WebMsgDeployFreeCardSpecial.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/WebMsgDeployFreeCardSpecial.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/WebMsgDeployFreeCardSpecial.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/WebMsgDeployFreeCardSpecial.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/KyLog.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/KyLog.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/KyLog.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/KyLog.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java diff --git a/clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java b/clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java similarity index 100% rename from clustermanage-client/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java rename to clustermanage-client-console/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java diff --git a/clustermanage-client/src/main/resources/logback.xml b/clustermanage-client-console/src/main/resources/logback.xml similarity index 100% rename from clustermanage-client/src/main/resources/logback.xml rename to clustermanage-client-console/src/main/resources/logback.xml diff --git a/clustermanage-server/pom.xml b/clustermanage-server/pom.xml index ffc589e..db36d44 100644 --- a/clustermanage-server/pom.xml +++ b/clustermanage-server/pom.xml @@ -6,7 +6,7 @@ cc.bitky.clustermanage clustermanage-server - 0.8.1-SNAPSHOT + 0.8.5-SNAPSHOT jar clustermanage-server From 64c1398d2a5d35872efaa62ac22a640e3432376f Mon Sep 17 00:00:00 2001 From: bitkylin Date: Thu, 18 May 2017 10:19:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E5=A5=97?= =?UTF-8?q?=E7=9A=84=20GUI=20=E5=AE=A2=E6=88=B7=E7=AB=AF=EF=BC=8C=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E5=8D=87=E8=87=B3=200.8.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clustermanage-client-javafx/.gitignore | 25 +++ clustermanage-client-javafx/pom.xml | 86 ++++++++ .../main/java/cc/bitky/clustermanage/App.java | 124 +++++++++++ .../cc/bitky/clustermanage/MainLauncher.java | 21 ++ .../clustermanage/netty/NettyServer.java | 67 ++++++ .../CanFrameChannelInboundHandler.java | 156 ++++++++++++++ .../netty/handler/KyChannelInitializer.java | 54 +++++ .../netty/handler/KyOutBoundHandler.java | 37 ++++ .../handler/ParsedMessageInBoundHandler.java | 181 ++++++++++++++++ .../clustermanage/netty/message/CardType.java | 16 ++ .../clustermanage/netty/message/MsgType.java | 112 ++++++++++ .../netty/message/base/BaseMessage.java | 48 +++++ .../netty/message/base/BaseMsgCardNum.java | 16 ++ .../message/base/BaseTcpResponseMsg.java | 16 ++ .../netty/message/base/IMessage.java | 15 ++ .../message/base/WebMsgBaseEmployee.java | 15 ++ .../netty/message/tcp/MsgErrorMessage.java | 28 +++ .../tcp/TcpMsgInitResponseCardNumber.java | 14 ++ .../message/tcp/TcpMsgResponseBoxId.java | 16 ++ .../tcp/TcpMsgResponseDeviceStatus.java | 16 ++ .../tcp/TcpMsgResponseEmployeeCardnumber.java | 16 ++ .../tcp/TcpMsgResponseEmployeeDepartment.java | 15 ++ .../TcpMsgResponseEmployeeDepartment2.java | 15 ++ .../tcp/TcpMsgResponseEmployeeName.java | 16 ++ .../tcp/TcpMsgResponseFreeCardNumber.java | 16 ++ .../tcp/TcpMsgResponseOperateBoxUnlock.java | 16 ++ .../tcp/TcpMsgResponseRemainChargeTimes.java | 16 ++ .../web/WebMsgDeployEmployeeCardNumber.java | 14 ++ .../web/WebMsgDeployEmployeeDepartment.java | 15 ++ .../web/WebMsgDeployEmployeeDepartment2.java | 15 ++ .../web/WebMsgDeployEmployeeDeviceId.java | 22 ++ .../message/web/WebMsgDeployEmployeeName.java | 15 ++ .../web/WebMsgDeployFreeCardSpecial.java | 35 +++ .../web/WebMsgDeployRemainChargeTimes.java | 22 ++ .../web/WebMsgInitClearDeviceStatus.java | 15 ++ .../WebMsgInitMarchConfirmCardResponse.java | 22 ++ .../message/web/WebMsgObtainDeviceStatus.java | 16 ++ .../message/web/WebMsgOperateBoxUnlock.java | 15 ++ .../clustermanage/utils/ChargeStatusEnum.java | 34 +++ .../cc/bitky/clustermanage/utils/KyLog.java | 13 ++ .../utils/SuccessfulListener.java | 7 + .../clustermanage/utils/TcpMsgBuilder.java | 87 ++++++++ .../utils/TcpReceiveListener.java | 5 + .../clustermanage/utils/TcpSendListener.java | 5 + .../bitky/clustermanage/view/Container.java | 13 ++ .../view/KyDeviceViewListener.java | 7 + .../cc/bitky/clustermanage/view/MainView.java | 106 +++++++++ .../bitky/clustermanage/view/bean/Device.java | 106 +++++++++ .../clustermanage/view/bean/DeviceGroup.java | 14 ++ .../clustermanage/view/bean/DeviceKey.java | 29 +++ .../cc/bitky/clustermanage/view/mainview.fxml | 31 +++ .../view/viewbean/DeviceGroupListCell.java | 30 +++ .../view/viewbean/DeviceView.java | 202 ++++++++++++++++++ .../view/viewbean/device_view.fxml | 69 ++++++ .../src/main/resources/logback.xml | 16 ++ .../cc/bitky/clustermanage/ServerSetting.java | 39 ++++ 56 files changed, 2192 insertions(+) create mode 100644 clustermanage-client-javafx/.gitignore create mode 100644 clustermanage-client-javafx/pom.xml create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment2.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment2.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/KyLog.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/Container.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceGroup.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceKey.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml create mode 100644 clustermanage-client-javafx/src/main/resources/logback.xml create mode 100644 clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java diff --git a/clustermanage-client-javafx/.gitignore b/clustermanage-client-javafx/.gitignore new file mode 100644 index 0000000..5ecfb59 --- /dev/null +++ b/clustermanage-client-javafx/.gitignore @@ -0,0 +1,25 @@ +target/ +test/ +.mvn/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/clustermanage-client-javafx/pom.xml b/clustermanage-client-javafx/pom.xml new file mode 100644 index 0000000..d47a193 --- /dev/null +++ b/clustermanage-client-javafx/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + + cc.bitky.clustermanage + clustermanage-client + 0.8.5-SNAPSHOT + jar + + clustermanage-client-javafx + http://maven.apache.org + + + UTF-8 + 4.12 + 4.1.9.Final + 1.8 + 1.8 + + + + + + ch.qos.logback + logback-classic + 1.2.3 + + + + io.netty + netty-all + ${netty.version} + + + + junit + junit + ${junit.version} + test + + + + + + + maven-assembly-plugin + 3.0.0 + + + true + + + + cc.bitky.clustermanage.MainLauncher + + + + + jar-with-dependencies + + + + + make-assembly + + package + + + single + + + + + + + + false + src/main/java + + **/*.fxml + + + + + diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java new file mode 100644 index 0000000..4a66dfc --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java @@ -0,0 +1,124 @@ +package cc.bitky.clustermanage; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Scanner; + +import cc.bitky.clustermanage.netty.NettyServer; +import cc.bitky.clustermanage.netty.handler.KyChannelInitializer; +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; +import cc.bitky.clustermanage.netty.message.base.IMessage; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgInitResponseCardNumber; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import cc.bitky.clustermanage.utils.ChargeStatusEnum; + +public class App { + private static Logger logger = LoggerFactory.getLogger(App.class); + private Scanner scanner = new Scanner(System.in); + private NettyServer nettyServer; + + public App() { + } + + public static void main(String[] args) { + + logger.debug("debug"); + logger.info("info"); + // new App().start(); + + } + + private void welcomeTo() { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("\n* * * * *"); + System.out.println("测试客户端: 请选择想要进行的操作"); + System.out.println(" cs「group」「box」「status」: 改变状态"); + System.out.println(" card「group」「box」「number」: 上传卡号"); + System.out.println(" re[x]「group」「box」「number」: 帧类型"); + System.out.println(" exit: 返回主菜单"); + System.out.print("请输入: "); + } + + public void start() { + nettyServer = new NettyServer(); + nettyServer.setLaunchSuccessfulListener(isSuccess -> keyIn()); + nettyServer.setFinishSuccessfulListener(isSuccess -> System.out.println("客户端优雅关闭成功")); + nettyServer.start(); + } + + private void keyIn() { + + while (true) { + welcomeTo(); + String inputMsg = scanner.next(); + IMessage message; + int groupId; + int boxId; + int status; + switch (inputMsg) { + case "cs": + groupId = scanner.nextInt(); + boxId = scanner.nextInt(); + status = scanner.nextInt(); + if (status < 0 || status > 6) { + status = ChargeStatusEnum.CRASH; + } + message = new TcpMsgResponseDeviceStatus(groupId, boxId, status); + break; + case "card": + groupId = scanner.nextInt(); + boxId = scanner.nextInt(); + long cardNum = scanner.nextLong(); + message = new TcpMsgInitResponseCardNumber(groupId, boxId, cardNum); + break; + case "rest": + message = buildResMsg(MsgType.DEVICE_RESPONSE_REMAIN_CHARGE_TIMES); + break; + case "resb": + message = buildResMsg(MsgType.DEVICE_RESPONSE_DEVICE_ID); + break; + case "resn": + message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_NAME); + break; + case "resd": + message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_1); + break; + case "rese": + message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_CARD_NUMBER); + break; + case "resl": + message = buildResMsg(MsgType.DEVICE_RESPONSE_REMOTE_UNLOCK); + break; + case "resf": + message = buildResMsg(MsgType.DEVICE_RESPONSE_FREE_CARD_NUMBER); + break; + case "err": + message = buildResMsg(0); + break; + case "exit": + nettyServer.shutdown(); + return; + default: + continue; + } + if (message != null) { + KyChannelInitializer.newInstance().getPipeline().write(message); + } + } + } + + private IMessage buildResMsg(int msgId) { + int groupId = scanner.nextInt(); + int boxId = scanner.nextInt(); + int status = scanner.nextInt(); + IMessage message = new BaseTcpResponseMsg(groupId, boxId, status); + message.setMsgId(msgId); + return message; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java new file mode 100644 index 0000000..b3018fb --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java @@ -0,0 +1,21 @@ +package cc.bitky.clustermanage; + +import cc.bitky.clustermanage.view.MainView; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class MainLauncher extends Application { + + @Override + public void start(Stage primaryStage) throws Exception { + + Stage primaryStage1 = primaryStage; + primaryStage1.setTitle("bitkyApp"); + primaryStage.setScene(new Scene(MainView.getInstance())); + primaryStage.setMaximized(true); + primaryStage.show(); + MainView.getInstance().updateGroupCount(1); + // new App().start(); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java new file mode 100644 index 0000000..c8c9479 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java @@ -0,0 +1,67 @@ +package cc.bitky.clustermanage.netty; + +import java.net.InetSocketAddress; + +import cc.bitky.clustermanage.netty.handler.KyChannelInitializer; +import cc.bitky.clustermanage.utils.SuccessfulListener; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.util.concurrent.Future; + +public class NettyServer { + + private SuccessfulListener launchListener; + private SuccessfulListener finishListener; + private EventLoopGroup group; + + + public void start() { + new Thread(() -> { + group = new NioEventLoopGroup(); + Bootstrap bootstrap = new Bootstrap(); + bootstrap.group(group) + .channel(NioSocketChannel.class) + .remoteAddress(new InetSocketAddress(30232)) + .handler(KyChannelInitializer.newInstance()); + ChannelFuture channelFuture = null; + + try { + channelFuture = bootstrap.connect().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + startListenerHandle(channelFuture, launchListener); + }).start(); + } + + private void startListenerHandle(Future future, SuccessfulListener listener) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (!future.isSuccess()) future.cause().printStackTrace(); + if (listener != null) listener.onSuccess(future.isSuccess()); + } + + public void setLaunchSuccessfulListener( + SuccessfulListener successfulListener) { + this.launchListener = successfulListener; + } + + public void setFinishSuccessfulListener( + SuccessfulListener finishListener) { + this.finishListener = finishListener; + } + + public void shutdown() { + if (group != null) { + Future futureShutdown = group.shutdownGracefully(); + futureShutdown.addListener(future -> startListenerHandle(future, finishListener)); + } + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java new file mode 100644 index 0000000..80379a0 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java @@ -0,0 +1,156 @@ +package cc.bitky.clustermanage.netty.handler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.Charset; + +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDepartment2; +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployFreeCardSpecial; +import cc.bitky.clustermanage.netty.message.base.IMessage; +import cc.bitky.clustermanage.netty.message.tcp.MsgErrorMessage; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeCardNumber; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDepartment; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDeviceId; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeName; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployRemainChargeTimes; +import cc.bitky.clustermanage.netty.message.web.WebMsgInitClearDeviceStatus; +import cc.bitky.clustermanage.netty.message.web.WebMsgInitMarchConfirmCardResponse; +import cc.bitky.clustermanage.netty.message.web.WebMsgObtainDeviceStatus; +import cc.bitky.clustermanage.netty.message.web.WebMsgOperateBoxUnlock; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + +public class CanFrameChannelInboundHandler extends SimpleChannelInboundHandler { + private static final int frameHead = 0x80; + private Charset charset_GB2312 = Charset.forName("EUC-CN"); + private Logger logger = LoggerFactory.getLogger(this.getClass()); + private int errorCount = 0; + + @Override + protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) { + if (errorCount != 0) logger.warn("接收到错误的 CAN 帧数量:" + errorCount); + if (msg.readableBytes() % 13 != 0) { + errorCount++; + logger.warn("读取到非整数个 CAN 帧"); + return; + } + + while (msg.readableBytes() >= 13) { + int bodyLength = msg.readByte() & 0x0F; + msg.skipBytes(1); + int msgId = msg.readByte(); + int boxId = msg.readByte(); + int groupId = msg.readByte(); + IMessage message = handleMessage(msgId, groupId, boxId, bodyLength, msg); + ctx.fireChannelRead(message); + } + } + + /** + * 根据CAN帧生成相应的 Java bean + * + * @param msgId CAN帧功能位 + * @param groupId 设备组 Id + * @param boxId 设备 Id + * @param bodyLength 数据部分长度 + * @param msg 数据部分 buffer + * @return 生成的消息 bean + */ + private IMessage handleMessage(int msgId, int groupId, int boxId, int bodyLength, ByteBuf msg) { + + //服务器部署万能卡号 + if (msgId >= 0x70 && msgId <= 0x7F) { + byte[] bytes = new byte[8]; + msg.readBytes(bytes); + long freeCardNumber = byteArrayToLong(bytes); + return new WebMsgDeployFreeCardSpecial(groupId, boxId, freeCardNumber, msgId - 0x70); + } + + switch (msgId) { + //服务器请求设备的状态 + case MsgType.SERVER_REQUSET_STATUS: + msg.skipBytes(8); + return new WebMsgObtainDeviceStatus(groupId, boxId); + //服务器部署剩余充电次数 + case MsgType.SERVER_SET_REMAIN_CHARGE_TIMES: + int times = msg.readByte(); + msg.skipBytes(7); + return new WebMsgDeployRemainChargeTimes(groupId, boxId, times); + //服务器部署设备 Id 更新 + case MsgType.SERVER_SET_DEVICE_ID: + int newBoxId = msg.readByte(); + msg.skipBytes(7); + return new WebMsgDeployEmployeeDeviceId(groupId, boxId, newBoxId); + //服务器部署员工姓名更新 + case MsgType.SERVER_SET_EMPLOYEE_NAME: + String name = readGB2312Body(msg).substring(0, bodyLength / 2); + return new WebMsgDeployEmployeeName(groupId, boxId, name); + //服务器部署员工单位「1」更新 + case MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_1: + String department1 = readGB2312Body(msg).substring(0, bodyLength / 2); + return new WebMsgDeployEmployeeDepartment(groupId, boxId, department1); + //服务器部署员工单位「2」更新 + case MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_2: + String department2 = readGB2312Body(msg).substring(0, bodyLength / 2); + return new WebMsgDeployEmployeeDepartment2(groupId, boxId, department2); + //服务器部署员工卡号更新 + case MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER: + byte[] bytes = new byte[8]; + msg.readBytes(bytes); + long cardNumber = byteArrayToLong(bytes); + return new WebMsgDeployEmployeeCardNumber(groupId, boxId, cardNumber); + //服务器远程开锁 + case MsgType.SERVER_REMOTE_UNLOCK: + msg.skipBytes(8); + return new WebMsgOperateBoxUnlock(groupId, boxId); + //服务器初始化: 匹配确认卡号状态 + case MsgType.INITIALIZE_SERVER_MARCH_CONFIRM_CARD_RESPONSE: + int MarchConfirmCardstatus = msg.readByte(); + msg.skipBytes(7); + if (MarchConfirmCardstatus == 1) { + return new WebMsgInitMarchConfirmCardResponse(groupId, boxId, true); + } else { + return new WebMsgInitMarchConfirmCardResponse(groupId, boxId, false); + } + //服务器初始化: 清除设备的初始化状态 + case MsgType.INITIALIZE_SERVER_CLEAR_INITIALIZE_MESSAGE: + msg.skipBytes(8); + return new WebMsgInitClearDeviceStatus(groupId, boxId); + default: + logger.warn("接收到正确的 CAN 帧,但无法解析"); + errorCount++; + return new MsgErrorMessage("接收到正确的 CAN 帧,但无法解析"); + } + } + + /** + * 读取数据部分为字符串 + * + * @param msg CAN帧 buffer + * @return 读取的字符串 + */ + private String readGB2312Body(ByteBuf msg) { + byte[] bytes = new byte[8]; + msg.readBytes(bytes); + return new String(bytes, charset_GB2312); + } + + long byteArrayToLong(byte[] bytes) { + long num = 0; + for (int i = 0; i <= 7; i++) { + num += (bytes[i] & 0xffL) << ((7 - i) * 8); + } + return num; + } + + private byte[] longToByteArray(long num) { + byte[] bytes = new byte[8]; + for (int i = 0; i <= 7; i++) { + bytes[i] = (byte) ((num >> ((7 - i) * 8)) & 0xff); + } + return bytes; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java new file mode 100644 index 0000000..1f0ac0e --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java @@ -0,0 +1,54 @@ +package cc.bitky.clustermanage.netty.handler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import cc.bitky.clustermanage.view.KyDeviceViewListener; +import cc.bitky.clustermanage.view.MainView; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; + +public class KyChannelInitializer extends ChannelInitializer { + private static KyChannelInitializer kyChannelInitializer; + private final KyOutBoundHandler kyOutBoundHandler; + private final ParsedMessageInBoundHandler parsedMessageInBoundHandler; + private ChannelPipeline pipeline; + private Logger logger = LoggerFactory.getLogger(getClass()); + + private KyChannelInitializer() { + kyOutBoundHandler = new KyOutBoundHandler(); + parsedMessageInBoundHandler = new ParsedMessageInBoundHandler(); + parsedMessageInBoundHandler.setReceiveListener(() -> { + }); + } + + + public static KyChannelInitializer newInstance() { + if (kyChannelInitializer == null) kyChannelInitializer = new KyChannelInitializer(); + return kyChannelInitializer; + } + + @Override + protected void initChannel(SocketChannel ch) throws Exception { + pipeline = ch.pipeline(); + pipeline.addLast(new LoggingHandler("kyOutlineLogger", LogLevel.INFO)); + pipeline.addLast(new CanFrameChannelInboundHandler()); + pipeline.addLast(parsedMessageInBoundHandler); + pipeline.addLast(kyOutBoundHandler); + MainView.getInstance().setListener(new KyDeviceViewListener() { + @Override + public void btnChargeChanged(int groupId, int deviceId, int status) { + pipeline.write(new TcpMsgResponseDeviceStatus(groupId, deviceId, status)); + } + }); + } + + public ChannelPipeline getPipeline() { + return pipeline; + } + +} \ No newline at end of file diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java new file mode 100644 index 0000000..bc6f275 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyOutBoundHandler.java @@ -0,0 +1,37 @@ +package cc.bitky.clustermanage.netty.handler; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; +import cc.bitky.clustermanage.netty.message.base.IMessage; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgInitResponseCardNumber; +import cc.bitky.clustermanage.utils.TcpMsgBuilder; +import cc.bitky.clustermanage.utils.TcpSendListener; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelPromise; + +public class KyOutBoundHandler extends ChannelOutboundHandlerAdapter { + + private final TcpMsgBuilder tcpMsgBuilder = new TcpMsgBuilder(); + private TcpSendListener sendListener; + + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + IMessage message = (IMessage) msg; + if (message.getMsgId() >= 0x40 && message.getMsgId() <= 0x4F) { + ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message))); + } else if (message.getMsgId() >= -128 && message.getMsgId() <= -113) { + ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message))); + } else if (message.getMsgId() == MsgType.INITIALIZE_DEVICE_RESPONSE_CARD) + ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildInitConfirmCardNumber((TcpMsgInitResponseCardNumber) message))); + if (message.getMsgId() == 0x00) { + ctx.writeAndFlush(Unpooled.wrappedBuffer(tcpMsgBuilder.buildResponseMsg((BaseTcpResponseMsg) message))); + } + if (sendListener != null) sendListener.send(); + } + + void setSendListener(TcpSendListener sendListener) { + this.sendListener = sendListener; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java new file mode 100644 index 0000000..b31bbf2 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java @@ -0,0 +1,181 @@ +package cc.bitky.clustermanage.netty.handler; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.IMessage; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseEmployeeCardnumber; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseEmployeeDepartment; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseEmployeeDepartment2; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseEmployeeName; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseFreeCardNumber; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseOperateBoxUnlock; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseRemainChargeTimes; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeCardNumber; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDepartment; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDepartment2; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeDeviceId; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployEmployeeName; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployFreeCardSpecial; +import cc.bitky.clustermanage.netty.message.web.WebMsgDeployRemainChargeTimes; +import cc.bitky.clustermanage.netty.message.web.WebMsgInitMarchConfirmCardResponse; +import cc.bitky.clustermanage.utils.TcpReceiveListener; +import cc.bitky.clustermanage.view.Container; +import cc.bitky.clustermanage.view.MainView; +import cc.bitky.clustermanage.view.bean.Device; +import cc.bitky.clustermanage.view.bean.DeviceKey; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + +public class ParsedMessageInBoundHandler extends SimpleChannelInboundHandler { + + private int sum = 0; + private int errorSum = 0; + + private Logger logger = LoggerFactory.getLogger(this.getClass()); + private TcpReceiveListener receiveListener; + + @Override + protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { + logger.debug("------收到CAN帧「msgId=" + msg.getMsgId() + ", groupId=" + msg.getGroupId() + ", boxId=" + msg.getBoxId() + "」------"); + MainView.getInstance().updateGroupCount(msg.getGroupId()); + logger.warn("#%#%收到帧的数量:" + ++sum); + if (errorSum != 0) + logger.warn("#%#%最终未能解析帧的数量:" + errorSum); + Device device; + + switch (msg.getMsgId()) { + case MsgType.SERVER_REQUSET_STATUS: + logger.debug("收到操作:状态请求"); + break; + + case MsgType.SERVER_SET_REMAIN_CHARGE_TIMES: + WebMsgDeployRemainChargeTimes remainChargeTimes = (WebMsgDeployRemainChargeTimes) msg; + logger.debug("收到剩余充电次数更新: " + remainChargeTimes.getTimes()); + device = getDevice(msg); + addHistory(device, "充电次数:" + remainChargeTimes.getTimes()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseRemainChargeTimes(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_SET_DEVICE_ID: + WebMsgDeployEmployeeDeviceId deployEmployeeDeviceId = (WebMsgDeployEmployeeDeviceId) msg; + logger.debug("收到部署设备 Id 更新: " + deployEmployeeDeviceId.getUpdatedDeviceId()); + DeviceKey deviceKeyOld = new DeviceKey(msg.getGroupId(), msg.getBoxId()); + DeviceKey deviceKeyNew = new DeviceKey(msg.getGroupId(), deployEmployeeDeviceId.getUpdatedDeviceId()); + Device deviceOld = Container.deviceHashMap.remove(deviceKeyNew); + device = Container.deviceHashMap.remove(deviceKeyOld); + if (device == null) { + device = new Device(msg.getGroupId(), deployEmployeeDeviceId.getUpdatedDeviceId()); + } + device.setDeviceId(deployEmployeeDeviceId.getUpdatedDeviceId()); + addHistory(device, "Id:" + deployEmployeeDeviceId.getUpdatedDeviceId()); + Container.deviceHashMap.put(deviceKeyNew, device); + MainView.getInstance().remoteUpdateDevice(deviceOld, device); + break; + + case MsgType.SERVER_SET_EMPLOYEE_NAME: + WebMsgDeployEmployeeName webMsgDeployEmployeeName = (WebMsgDeployEmployeeName) msg; + logger.debug("收到部署员工姓名更新: " + webMsgDeployEmployeeName.getValue()); + device = getDevice(msg); + device.setName(webMsgDeployEmployeeName.getValue()); + addHistory(device, "姓名:" + webMsgDeployEmployeeName.getValue()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeName(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_1: + WebMsgDeployEmployeeDepartment deployEmployeeDepartment1 = (WebMsgDeployEmployeeDepartment) msg; + logger.debug("收到部署员工单位「1」更新: " + deployEmployeeDepartment1.getValue()); + device = getDevice(msg); + device.setDepartment(deployEmployeeDepartment1.getValue()); + addHistory(device, "单位1:" + device.getDepartment()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeDepartment(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_2: + WebMsgDeployEmployeeDepartment2 deployEmployeeDepartment2 = (WebMsgDeployEmployeeDepartment2) msg; + logger.debug("收到部署员工单位「2」更新: " + deployEmployeeDepartment2.getValue()); + device = getDevice(msg); + device.setDepartment(device.getDepartment() + deployEmployeeDepartment2.getValue()); + addHistory(device, "单位2:" + deployEmployeeDepartment2.getValue()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeDepartment2(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER: + WebMsgDeployEmployeeCardNumber deployEmployeeCardNumber = (WebMsgDeployEmployeeCardNumber) msg; + logger.debug("收到部署员工卡号更新: " + deployEmployeeCardNumber.getCardNumber()); + device = getDevice(msg); + device.setCardNumber(deployEmployeeCardNumber.getCardNumber()); + addHistory(device, "卡号:" + deployEmployeeCardNumber.getCardNumber()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeCardnumber(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_REMOTE_UNLOCK: + logger.debug("收到操作:远程开锁"); + device = getDevice(msg); + addHistory(device, "开锁"); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseOperateBoxUnlock(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); + break; + + case MsgType.SERVER_SET_FREE_CARD_NUMBER: + WebMsgDeployFreeCardSpecial deployFreeCardSpecial = (WebMsgDeployFreeCardSpecial) msg; + logger.debug("收到部署万能卡号「『" + deployFreeCardSpecial.getItemId() + "』" + deployFreeCardSpecial.getCardNumber() + "」"); + device = getDevice(msg); + addHistory(device, "万能:" + deployFreeCardSpecial.getItemId()); + MainView.getInstance().remoteUpdateDevice(device); + ctx.channel().writeAndFlush(new TcpMsgResponseFreeCardNumber(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1, deployFreeCardSpecial.getItemId())); + break; + + case MsgType.INITIALIZE_SERVER_MARCH_CONFIRM_CARD_RESPONSE: + WebMsgInitMarchConfirmCardResponse marchConfirmCardResponse = (WebMsgInitMarchConfirmCardResponse) msg; + logger.debug("「初始化」 匹配确认卡号状态: " + marchConfirmCardResponse.isSuccessful()); + device = getDevice(msg); + addHistory(device, "匹配:" + marchConfirmCardResponse.isSuccessful()); + MainView.getInstance().remoteUpdateDevice(device); + break; + + case MsgType.INITIALIZE_SERVER_CLEAR_INITIALIZE_MESSAGE: + logger.debug("「初始化」 清除设备的初始化状态"); + device = getDevice(msg); + device.setName(""); + device.setDepartment(""); + device.setCardNumber(0); + device.setStatus(0); + addHistory(device, "清空设备"); + MainView.getInstance().remoteUpdateDevice(device); + break; + + default: + logger.warn("无法解析正确的 Message"); + errorSum++; + break; + } + if (receiveListener != null) receiveListener.receive(); + } + + private void addHistory(Device device, String addValue) { + String finalStr = (device.getHistoryList().size() + 1) + ". " + addValue; + device.addHistoryList(finalStr); + } + + private Device getDevice(IMessage msg) { + DeviceKey deviceKey = new DeviceKey(msg.getGroupId(), msg.getBoxId()); + Device device = Container.deviceHashMap.get(deviceKey); + if (device == null) { + device = new Device(msg.getGroupId(), msg.getBoxId()); + Container.deviceHashMap.put(deviceKey, device); + } + return device; + } + + void setReceiveListener(TcpReceiveListener receiveListener) { + this.receiveListener = receiveListener; + } +} + diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java new file mode 100644 index 0000000..b5cbf4d --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/CardType.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message; + +public enum CardType { + /** + * 万能卡 + */ + FREE, + /** + * 确认卡 + */ + CONFIRM, + /** + * 员工卡 + */ + EMPLOYEE +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java new file mode 100644 index 0000000..02b5655 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/MsgType.java @@ -0,0 +1,112 @@ +package cc.bitky.clustermanage.netty.message; + +public class MsgType { + public static final byte HEART_BEAT = 0x01; + + public static final byte ERROR = 0x05; + + /** + * 成组地发送消息 + */ + public static final byte SERVER_SEND_GROUPED = 0x0A; + /** + * 紧急发送该消息 + */ + public static final byte SERVER_SEND_SPECIAL = 0x0B; + + + //-------------------服务器下发----------------------- + + /** + * 获取充电状态 + */ + public static final byte SERVER_REQUSET_STATUS = 0x10; + /** + * 设置剩余充电次数 + */ + public static final byte SERVER_SET_REMAIN_CHARGE_TIMES = 0x11; + /** + * 设置设备ID + */ + public static final byte SERVER_SET_DEVICE_ID = 0x15; + /** + * 设置员工姓名 + */ + public static final byte SERVER_SET_EMPLOYEE_NAME = 0x16; + /** + * 设置员工单位第一帧 + */ + public static final byte SERVER_SET_EMPLOYEE_DEPARTMENT_1 = 0x17; + /** + * 设置员工单位第二帧 + */ + public static final byte SERVER_SET_EMPLOYEE_DEPARTMENT_2 = 0x18; + /** + * 设置员工卡号 + */ + public static final byte SERVER_SET_EMPLOYEE_CARD_NUMBER = 0x19; + /** + * 服务器远程开锁 + */ + public static final byte SERVER_REMOTE_UNLOCK = 0x1A; + /** + * 万能卡号设置 + */ + public static final byte SERVER_SET_FREE_CARD_NUMBER = 0x70; + + //-------------------设备回复----------------------- + + /** + * 设备回复自己的状态 + */ + public static final byte DEVICE_RESPONSE_STATUS = 0x40; + /** + * 设置剩余充电次数的回复 + */ + public static final byte DEVICE_RESPONSE_REMAIN_CHARGE_TIMES = 0x41; + /** + * 设置设备ID的回复 + */ + public static final byte DEVICE_RESPONSE_DEVICE_ID = 0x45; + /** + * 设置员工姓名的回复 + */ + public static final byte DEVICE_RESPONSE_EMPLOYEE_NAME = 0x46; + /** + * 设置员工单位的回复「1」 + */ + public static final byte DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_1 = 0x47; + /** + * 设置员工单位的回复「2」 + */ + public static final byte DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_2 = 0x48; + + /** + * 设置员工卡号的回复 + */ + public static final byte DEVICE_RESPONSE_EMPLOYEE_CARD_NUMBER = 0x49; + /** + * 服务器远程开锁的回复 + */ + public static final byte DEVICE_RESPONSE_REMOTE_UNLOCK = 0x4A; + /** + * 万能卡号设置的回复 + */ + public static final byte DEVICE_RESPONSE_FREE_CARD_NUMBER = (byte) 0x80; + + //-------------------初始化流程信息----------------------- + + /** + * 设备主动发送卡号,包括员工卡号和确认卡号 + */ + public static final byte INITIALIZE_DEVICE_RESPONSE_CARD = (byte) 0xAA; + /** + * 服务器匹配确认卡号回复 + */ + public static final byte INITIALIZE_SERVER_MARCH_CONFIRM_CARD_RESPONSE = (byte) 0xAB; + + /** + * 服务器清除设备的初始化状态 + */ + public static final byte INITIALIZE_SERVER_CLEAR_INITIALIZE_MESSAGE = (byte) 0xAD; +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java new file mode 100644 index 0000000..17f4375 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMessage.java @@ -0,0 +1,48 @@ +package cc.bitky.clustermanage.netty.message.base; + +/** + * 基础信息 Message + */ +public class BaseMessage implements IMessage { + private int msgId = -1; + private int groupId = -1; + private int boxId = -1; + + protected BaseMessage(int groupId) { + this.groupId = groupId; + } + + protected BaseMessage(int groupId, int boxId) { + this(groupId); + this.boxId = boxId; + } + + @Override + public int getMsgId() { + return msgId; + } + @Override + public void setMsgId(int msgId) { + this.msgId = msgId; + } + + @Override + public int getGroupId() { + return groupId; + } + + @Override + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + @Override + public int getBoxId() { + return boxId; + } + + @Override + public void setBoxId(int boxId) { + this.boxId = boxId; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java new file mode 100644 index 0000000..1d15419 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.base; + +public class BaseMsgCardNum extends BaseMessage { + + private long cardNumber; + + protected BaseMsgCardNum(int groupId, int boxId, long cardNumber, int msgType) { + super(groupId, boxId); + setMsgId(msgType); + this.cardNumber = cardNumber; + } + + public long getCardNumber() { + return cardNumber; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java new file mode 100644 index 0000000..d98bb3f --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseTcpResponseMsg.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.base; + + +public class BaseTcpResponseMsg extends BaseMessage { + + private final int status; + + public BaseTcpResponseMsg(int groupId, int boxId, int status) { + super(groupId, boxId); + this.status = status; + } + + public int getStatus() { + return status; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java new file mode 100644 index 0000000..b080423 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/IMessage.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.base; + +public interface IMessage { + int getMsgId(); + + void setMsgId(int msgId); + + int getBoxId(); + + void setBoxId(int boxId); + + int getGroupId(); + + void setGroupId(int groupId); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java new file mode 100644 index 0000000..a04209b --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/WebMsgBaseEmployee.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.base; + +public class WebMsgBaseEmployee extends BaseMessage { + + String value; + + protected WebMsgBaseEmployee(int groupId, int boxId, String value) { + super(groupId, boxId); + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java new file mode 100644 index 0000000..47e09b9 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/MsgErrorMessage.java @@ -0,0 +1,28 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +public class MsgErrorMessage extends BaseMessage { + + private String msg; + + public MsgErrorMessage(int groupId) { + super(groupId); + setMsgId(MsgType.ERROR); + } + + public MsgErrorMessage() { + this(-1); + } + + private MsgErrorMessage(int groupId, String msg) { + this(groupId); + this.msg = msg; + } + + public MsgErrorMessage(String msg) { + this(-1, msg); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java new file mode 100644 index 0000000..998e14a --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java @@ -0,0 +1,14 @@ +package cc.bitky.clustermanage.netty.message.tcp; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMsgCardNum; + +/** + * 设备初始化「1, 3」: 发送员工卡号 + */ +public class TcpMsgInitResponseCardNumber extends BaseMsgCardNum { + + public TcpMsgInitResponseCardNumber(int groupId, int boxId, long cardNumber) { + super(groupId, boxId, cardNumber, MsgType.INITIALIZE_DEVICE_RESPONSE_CARD); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java new file mode 100644 index 0000000..c1f8034 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseBoxId.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 设备 Id 更新 + */ +public class TcpMsgResponseBoxId extends BaseTcpResponseMsg { + + public TcpMsgResponseBoxId(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_DEVICE_ID); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java new file mode 100644 index 0000000..4bc7a2a --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseDeviceStatus.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 充电状态 + */ +public class TcpMsgResponseDeviceStatus extends BaseTcpResponseMsg { + + public TcpMsgResponseDeviceStatus(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_STATUS); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java new file mode 100644 index 0000000..a76f873 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeCardnumber.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 员工卡号更新 + */ +public class TcpMsgResponseEmployeeCardnumber extends BaseTcpResponseMsg { + + public TcpMsgResponseEmployeeCardnumber(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_EMPLOYEE_CARD_NUMBER); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java new file mode 100644 index 0000000..6ed54c9 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.tcp; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 员工部门更新 + */ +public class TcpMsgResponseEmployeeDepartment extends BaseTcpResponseMsg { + + public TcpMsgResponseEmployeeDepartment(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_1); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment2.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment2.java new file mode 100644 index 0000000..5f0a8bf --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeDepartment2.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.tcp; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 员工部门更新 + */ +public class TcpMsgResponseEmployeeDepartment2 extends BaseTcpResponseMsg { + + public TcpMsgResponseEmployeeDepartment2(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_2); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java new file mode 100644 index 0000000..90dc2fb --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseEmployeeName.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 员工姓名更新 + */ +public class TcpMsgResponseEmployeeName extends BaseTcpResponseMsg { + + public TcpMsgResponseEmployeeName(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_EMPLOYEE_NAME); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java new file mode 100644 index 0000000..75e5582 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseFreeCardNumber.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 员工部门更新 + */ +public class TcpMsgResponseFreeCardNumber extends BaseTcpResponseMsg { + + public TcpMsgResponseFreeCardNumber(int groupId, int boxId, int status, int item) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_FREE_CARD_NUMBER + item); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java new file mode 100644 index 0000000..67af4c2 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseOperateBoxUnlock.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 开锁成功 + */ +public class TcpMsgResponseOperateBoxUnlock extends BaseTcpResponseMsg { + + public TcpMsgResponseOperateBoxUnlock(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_REMOTE_UNLOCK); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java new file mode 100644 index 0000000..4b5eeb0 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgResponseRemainChargeTimes.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.tcp; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +/** + * 设备回复: 剩余充电次数更新 + */ +public class TcpMsgResponseRemainChargeTimes extends BaseTcpResponseMsg { + + public TcpMsgResponseRemainChargeTimes(int groupId, int boxId, int status) { + super(groupId, boxId, status); + setMsgId(MsgType.DEVICE_RESPONSE_REMAIN_CHARGE_TIMES); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java new file mode 100644 index 0000000..0713728 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java @@ -0,0 +1,14 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMsgCardNum; + +/** + * 服务器部署员工卡号 + */ +public class WebMsgDeployEmployeeCardNumber extends BaseMsgCardNum { + + public WebMsgDeployEmployeeCardNumber(int groupId, int boxId, long cardNumber) { + super(groupId, boxId, cardNumber, MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java new file mode 100644 index 0000000..952c86b --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.web; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.WebMsgBaseEmployee; + +/** + * 服务器部署员工部门 + */ +public class WebMsgDeployEmployeeDepartment extends WebMsgBaseEmployee { + public WebMsgDeployEmployeeDepartment(int groupId, int boxId, String value) { + super(groupId, boxId, value); + setMsgId(MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_1); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment2.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment2.java new file mode 100644 index 0000000..75caee3 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDepartment2.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.web; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.WebMsgBaseEmployee; + +/** + * 服务器部署员工部门 + */ +public class WebMsgDeployEmployeeDepartment2 extends WebMsgBaseEmployee { + public WebMsgDeployEmployeeDepartment2(int groupId, int boxId, String value) { + super(groupId, boxId, value); + setMsgId(MsgType.SERVER_SET_EMPLOYEE_DEPARTMENT_2); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java new file mode 100644 index 0000000..314a105 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeDeviceId.java @@ -0,0 +1,22 @@ +package cc.bitky.clustermanage.netty.message.web; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 服务器部署设备 Id + */ +public class WebMsgDeployEmployeeDeviceId extends BaseMessage { + int updatedDeviceId; + + public WebMsgDeployEmployeeDeviceId(int groupId, int boxId, int updatedDeviceId) { + super(groupId, boxId); + this.updatedDeviceId = updatedDeviceId; + setMsgId(MsgType.SERVER_SET_DEVICE_ID); + } + + public int getUpdatedDeviceId() { + return updatedDeviceId; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java new file mode 100644 index 0000000..a2a65cb --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeName.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.web; + + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.WebMsgBaseEmployee; + +/** + * 服务器部署员工姓名 + */ +public class WebMsgDeployEmployeeName extends WebMsgBaseEmployee { + public WebMsgDeployEmployeeName(int groupId, int boxId, String value) { + super(groupId, boxId, value); + setMsgId(MsgType.SERVER_SET_EMPLOYEE_NAME); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java new file mode 100644 index 0000000..55f6f36 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java @@ -0,0 +1,35 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 服务器部署万能卡号 + */ +public class WebMsgDeployFreeCardSpecial extends BaseMessage { + + private final int itemId; + private long cardNumber; + + /** + * 服务器部署万能卡号 + * + * @param groupId 组号 + * @param boxId 设备号 + * @param cardNumber 万能卡号集合 + */ + public WebMsgDeployFreeCardSpecial(int groupId, int boxId, long cardNumber, int itemId) { + super(groupId, boxId); + this.cardNumber = cardNumber; + this.itemId = itemId; + setMsgId(MsgType.SERVER_SET_FREE_CARD_NUMBER); + } + + public int getItemId() { + return itemId; + } + + public long getCardNumber() { + return cardNumber; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java new file mode 100644 index 0000000..4a003b7 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployRemainChargeTimes.java @@ -0,0 +1,22 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 服务器部署剩余充电次数 + */ +public class WebMsgDeployRemainChargeTimes extends BaseMessage { + + private int times; + + public WebMsgDeployRemainChargeTimes(int groupId, int boxId, int times) { + super(groupId, boxId); + setMsgId(MsgType.SERVER_SET_REMAIN_CHARGE_TIMES); + this.times = times; + } + + public int getTimes() { + return times; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java new file mode 100644 index 0000000..d6820e4 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitClearDeviceStatus.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 设备初始化「3」: 服务器清除设备的初始化状态 + */ +public class WebMsgInitClearDeviceStatus extends BaseMessage { + + public WebMsgInitClearDeviceStatus(int groupId, int boxId) { + super(groupId, boxId); + setMsgId(MsgType.INITIALIZE_SERVER_CLEAR_INITIALIZE_MESSAGE); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java new file mode 100644 index 0000000..d113904 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgInitMarchConfirmCardResponse.java @@ -0,0 +1,22 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 设备初始化「2」: 服务器匹配确认卡号回复 + */ +public class WebMsgInitMarchConfirmCardResponse extends BaseMessage { + + private boolean successful; + + public WebMsgInitMarchConfirmCardResponse(int groupId, int boxId, boolean successful) { + super(groupId, boxId); + this.successful = successful; + setMsgId(MsgType.INITIALIZE_SERVER_MARCH_CONFIRM_CARD_RESPONSE); + } + + public boolean isSuccessful() { + return successful; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java new file mode 100644 index 0000000..f3585b8 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgObtainDeviceStatus.java @@ -0,0 +1,16 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 服务器获取设备的当前状态 + */ +public class WebMsgObtainDeviceStatus extends BaseMessage { + + + public WebMsgObtainDeviceStatus(int groupId, int boxId) { + super(groupId, boxId); + setMsgId(MsgType.SERVER_REQUSET_STATUS); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java new file mode 100644 index 0000000..d21229c --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgOperateBoxUnlock.java @@ -0,0 +1,15 @@ +package cc.bitky.clustermanage.netty.message.web; + +import cc.bitky.clustermanage.netty.message.MsgType; +import cc.bitky.clustermanage.netty.message.base.BaseMessage; + +/** + * 服务器操作远程开锁 + */ +public class WebMsgOperateBoxUnlock extends BaseMessage { + + public WebMsgOperateBoxUnlock(int groupId, int boxId) { + super(groupId, boxId); + setMsgId(MsgType.SERVER_REMOTE_UNLOCK); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java new file mode 100644 index 0000000..e7241a2 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ChargeStatusEnum.java @@ -0,0 +1,34 @@ +package cc.bitky.clustermanage.utils; + +public class ChargeStatusEnum { + /** + * 未初始化 + */ + public static final int UNINIT = 0; + /** + * 使用中 + */ + public static final int USING = 1; + /** + * 充电中 + */ + public static final int CHARGING = 2; + /** + * 已充满 + */ + public static final int FULL = 3; + /** + * 通信故障 + */ + public static final int TRAFFIC_ERROR = 4; + + /** + * 充电故障 + */ + public static final int CHARGE_ERROR = 5; + + /** + * 多种故障 + */ + public static final int CRASH = 6; +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/KyLog.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/KyLog.java new file mode 100644 index 0000000..4685510 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/KyLog.java @@ -0,0 +1,13 @@ +package cc.bitky.clustermanage.utils; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; + +public class KyLog { + public static void LogFrame(ByteBuf byteBuf) { + System.out.println( + "begin:" + byteBuf.readerIndex() + ", end:" + byteBuf.writerIndex() + ", readable:" + + byteBuf.readableBytes() + ", writable:" + byteBuf.writableBytes()); + System.out.println(ByteBufUtil.prettyHexDump(byteBuf)); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java new file mode 100644 index 0000000..6efd0f6 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/SuccessfulListener.java @@ -0,0 +1,7 @@ +package cc.bitky.clustermanage.utils; + +@FunctionalInterface +public interface SuccessfulListener { + + void onSuccess(boolean isSuccess); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java new file mode 100644 index 0000000..080893c --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java @@ -0,0 +1,87 @@ +package cc.bitky.clustermanage.utils; + +import java.nio.charset.Charset; + +import cc.bitky.clustermanage.netty.message.base.BaseMessage; +import cc.bitky.clustermanage.netty.message.base.BaseMsgCardNum; +import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; + +public class TcpMsgBuilder { + Charset charset_GB2312 = Charset.forName("EUC-CN"); + + /** + * 「初始化」构建卡号的 CAN 帧,包括员工卡号和确认卡号 + * + * @param msgCardNum 卡号 bean + * @return 卡号的 CAN 帧 + */ + public byte[] buildInitConfirmCardNumber(BaseMsgCardNum msgCardNum) { + byte[] bytes = buildMsgOutline(msgCardNum); + bytes[0] += 8; + byte[] byteCardNum = longToByteArray(msgCardNum.getCardNumber()); + addMessageBody(bytes, byteCardNum, 0); + return bytes; + } + + /** + * 构建设备状态 CAN 帧 + * + * @param responseMsg 设备状态 bean + * @return 设备状态的 CAN 帧 + */ + public byte[] buildResponseMsg(BaseTcpResponseMsg responseMsg) { + byte[] bytes = buildMsgOutline(responseMsg); + bytes[0] += 1; + bytes[5] = (byte) responseMsg.getStatus(); + return bytes; + } + + /** + * 构建CAN帧的轮廓,只需再填入数据位即可 + * + * @param message 欲构建为CAN帧的bean + * @return 轮廓CAN帧 + */ + private byte[] buildMsgOutline(BaseMessage message) { + byte[] bytes = new byte[13]; + bytes[0] = (byte) 0x80; + bytes[2] = (byte) message.getMsgId(); + bytes[3] = (byte) message.getBoxId(); + bytes[4] = (byte) message.getGroupId(); + return bytes; + } + + /** + * 在轮廓CAN帧中添加数据位 + * + * @param bytes 轮廓CAN帧 + * @param bytesBody 数据位 + * @param offset 数据位的偏移量,offset位开始操作8个字节 + * @return 已构建完成的CAN帧 + */ + private byte[] addMessageBody(byte[] bytes, byte[] bytesBody, int offset) { + int max = (bytesBody.length - offset) > 8 ? 8 : (bytesBody.length - offset); + for (int i = 0; i < max; i++) { + bytes[i + 5] = bytesBody[i + offset]; + } + return bytes; + } + + private long byteArrayToLong(byte[] bytes) { + long num = 0; + for (int i = 0; i <= 7; i++) { + num += (bytes[i] & 0xffL) << ((7 - i) * 8); + } + return num; + } + + private byte[] longToByteArray(long num) { + byte[] bytes = new byte[8]; + for (int i = 0; i <= 7; i++) { + bytes[i] = (byte) ((num >> ((7 - i) * 8)) & 0xff); + } + return bytes; + } + + +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java new file mode 100644 index 0000000..36fa025 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpReceiveListener.java @@ -0,0 +1,5 @@ +package cc.bitky.clustermanage.utils; + +public interface TcpReceiveListener { + void receive(); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java new file mode 100644 index 0000000..79d9d2a --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpSendListener.java @@ -0,0 +1,5 @@ +package cc.bitky.clustermanage.utils; + +public interface TcpSendListener { + void send(); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/Container.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/Container.java new file mode 100644 index 0000000..6df0c4b --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/Container.java @@ -0,0 +1,13 @@ +package cc.bitky.clustermanage.view; + +import java.util.HashMap; + +import cc.bitky.clustermanage.view.bean.Device; +import cc.bitky.clustermanage.view.bean.DeviceKey; +import cc.bitky.clustermanage.view.viewbean.DeviceView; + +public class Container { + + public static final HashMap deviceViewHashMap = new HashMap<>(100); + public static final HashMap deviceHashMap = new HashMap<>(10000); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java new file mode 100644 index 0000000..ed97912 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java @@ -0,0 +1,7 @@ +package cc.bitky.clustermanage.view; + +public interface KyDeviceViewListener { + + void btnChargeChanged(int groupId,int deviceId,int status); + +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java new file mode 100644 index 0000000..b1cb253 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java @@ -0,0 +1,106 @@ +package cc.bitky.clustermanage.view; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import cc.bitky.clustermanage.view.bean.Device; +import cc.bitky.clustermanage.view.bean.DeviceGroup; +import cc.bitky.clustermanage.view.bean.DeviceKey; +import cc.bitky.clustermanage.view.viewbean.DeviceGroupListCell; +import cc.bitky.clustermanage.view.viewbean.DeviceView; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.control.ListView; +import javafx.scene.control.SplitPane; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.FlowPane; + +public class MainView extends AnchorPane implements Initializable { + private static MainView mainView; + ObservableList deviceGroups; + int groupId; + private KyDeviceViewListener listener; + @FXML + private ListView deviceGroupList; + @FXML + private FlowPane deviceFlowPane; + @FXML + private SplitPane splitPane; + + private MainView() throws IOException { + FXMLLoader loader = new FXMLLoader(getClass().getResource("mainview.fxml")); + loader.setRoot(this); + loader.setController(this); + loader.load(); + } + + public static MainView getInstance() { + if (mainView == null) { + try { + mainView = new MainView(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return mainView; + } + + public void setListener(KyDeviceViewListener listener) { + this.listener = listener; + } + + public DeviceView getDevice(int deviceId) { + return Container.deviceViewHashMap.get(deviceId); + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + deviceGroups = FXCollections.observableArrayList(); + deviceGroupList.setCellFactory(param -> new DeviceGroupListCell()); + deviceGroupList.setItems(deviceGroups); + deviceGroupList.getFocusModel().focusedItemProperty().addListener( + (observable, oldValue, newValue) -> { + groupId = newValue.getGroupId(); + for (int i = 1; i <= 100; i++) { + Container.deviceViewHashMap.get(i).initView(Container.deviceHashMap.get(new DeviceKey(groupId, i))); + } + }); + + for (int i = 1; i <= 100; i++) { + DeviceView deviceView = new DeviceView(i); + deviceFlowPane.getChildren().add(deviceView); + Container.deviceViewHashMap.put(i, deviceView); + deviceView.setListener((groupId, deviceId, status) -> { + if (listener != null) listener.btnChargeChanged(groupId, deviceId, status); + }); + } + + + } + + public void updateGroupCount(int groupid) { + if (groupid > deviceGroups.size()) { + for (int i = deviceGroups.size() + 1; i <= groupid; i++) { + deviceGroups.add(new DeviceGroup(i)); + deviceGroupList.setItems(deviceGroups); + } + } + } + + public void remoteUpdateDevice(Device device) { + if (groupId != 0 && device != null && device.getGroupId() == groupId) { + updateGroupCount(device.getGroupId()); + Container.deviceViewHashMap.get(device.getDeviceId()).initView(device); + } + } + + public void remoteUpdateDevice(Device... devices) { + for (Device device : devices) { + remoteUpdateDevice(device); + } + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java new file mode 100644 index 0000000..a16a396 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java @@ -0,0 +1,106 @@ +package cc.bitky.clustermanage.view.bean; + +import java.util.ArrayList; +import java.util.List; + +public class Device { + String name; + String department; + long cardNumber; + private int groupId = -1; + private int deviceId = -1; + private int status = -1; + private boolean wrong = false; + private List historyList = new ArrayList<>(); + + public Device() { + } + + public Device(int groupId, int deviceId) { + this.groupId = groupId; + this.deviceId = deviceId; + status = 0; + } + + public List getHistoryList() { + return historyList; + } + + public void addHistoryList(String value) { + this.historyList.add(value); + } + + public boolean isWrong() { + return wrong; + } + + public void setWrong(boolean wrong) { + this.wrong = wrong; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Device device = (Device) o; + + if (groupId != device.groupId) return false; + return deviceId == device.deviceId; + } + + @Override + public int hashCode() { + int result = groupId; + result = 31 * result + deviceId; + return result; + } + + public int getGroupId() { + return groupId; + } + + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + public int getDeviceId() { + return deviceId; + } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public long getCardNumber() { + return cardNumber; + } + + public void setCardNumber(long cardNumber) { + this.cardNumber = cardNumber; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceGroup.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceGroup.java new file mode 100644 index 0000000..6d77953 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceGroup.java @@ -0,0 +1,14 @@ +package cc.bitky.clustermanage.view.bean; + +public class DeviceGroup { + int groupId; + + + public DeviceGroup(int groupId) { + this.groupId = groupId; + } + + public int getGroupId() { + return groupId; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceKey.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceKey.java new file mode 100644 index 0000000..f4a5574 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/DeviceKey.java @@ -0,0 +1,29 @@ +package cc.bitky.clustermanage.view.bean; + +public class DeviceKey { + private int groupId = -1; + private int deviceId = -1; + + public DeviceKey(int groupId, int deviceId) { + this.groupId = groupId; + this.deviceId = deviceId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + DeviceKey deviceKey = (DeviceKey) o; + + if (groupId != deviceKey.groupId) return false; + return deviceId == deviceKey.deviceId; + } + + @Override + public int hashCode() { + int result = groupId; + result = 31 * result + deviceId; + return result; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml new file mode 100644 index 0000000..dca19c6 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java new file mode 100644 index 0000000..a7d6ad4 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java @@ -0,0 +1,30 @@ +package cc.bitky.clustermanage.view.viewbean; + +import java.net.URL; +import java.util.ResourceBundle; + +import cc.bitky.clustermanage.view.bean.DeviceGroup; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Label; +import javafx.scene.control.ListCell; + +public class DeviceGroupListCell extends ListCell implements Initializable { + + + @FXML + private Label label; + + @Override + protected void updateItem(DeviceGroup item, boolean empty) { + super.updateItem(item, empty); + if (item != null) { + setText("第 " + item.getGroupId() + " 组"); + } + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java new file mode 100644 index 0000000..41bedf1 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java @@ -0,0 +1,202 @@ +package cc.bitky.clustermanage.view.viewbean; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import cc.bitky.clustermanage.view.KyDeviceViewListener; +import cc.bitky.clustermanage.view.bean.Device; +import javafx.application.Platform; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ListView; +import javafx.scene.control.Tab; +import javafx.scene.control.TabPane; + +public class DeviceView extends TabPane implements Initializable { + private static Device deviceDefault = new Device(); + KyDeviceViewListener listener; + @FXML + private Tab tabStatus; + @FXML + private Label name; + @FXML + private Label department; + @FXML + private Label cardNumber; + @FXML + private Button btnCharge; + @FXML + private Button btnWrong; + @FXML + private Tab tabHistory; + @FXML + private ListView historyList; + private int id; + private Device device; + + public DeviceView(int id) { + this.id = id; + loadFxml(); + + } + + public void setListener(KyDeviceViewListener listener) { + this.listener = listener; + } + + public void initView(Device device) { + if (device == null) device = deviceDefault; + this.device = device; + Device finalDevice = device; + Platform.runLater(() -> { + tabStatus.setText(finalDevice.getDeviceId() + "号"); + name.setText(finalDevice.getName()); + department.setText(finalDevice.getDepartment()); + cardNumber.setText(finalDevice.getCardNumber() + ""); + + deployBtnText(finalDevice.getStatus()); + + historyList.getItems().clear(); + historyList.getItems().addAll(finalDevice.getHistoryList()); + }); + } + + private void deployBtnText(int status) { + if (status < 0) { + btnCharge.setDisable(true); + btnWrong.setDisable(true); + } else { + btnCharge.setDisable(false); + btnWrong.setDisable(false); + } + switch (status) { + case -1: + btnCharge.setText("出厂"); + btnWrong.setText("好"); + break; + case 0: + btnCharge.setText("初始化"); + btnWrong.setText("好"); + break; + case 1: + btnCharge.setText("未充电"); + btnWrong.setText("好"); + break; + case 2: + btnCharge.setText("充电中"); + btnWrong.setText("好"); + break; + case 3: + btnCharge.setText("已充满"); + btnWrong.setText("好"); + break; + case 4: + btnCharge.setText("充电X"); + btnWrong.setText("好"); + break; + case 5: + btnCharge.setText("通信X"); + btnWrong.setText("坏"); + break; + case 6: + btnCharge.setText("多种X"); + btnWrong.setText("坏"); + break; + } + } + + + private void loadFxml() { + FXMLLoader loader = new FXMLLoader(getClass().getResource("device_view.fxml")); + loader.setRoot(this); + loader.setController(this); + try { + loader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void addList(String value) { + historyList.getItems().add(value); + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + tabStatus.setText(id + "号"); + } + + @FXML + private void btnChargeAction(ActionEvent event) { + int status = device.getStatus(); + + if (status >= 0 && status <= 2) { + status++; + } else if (status == 3 || status == 4) status = 1; + else if (status == 5) status = 6; + else if (status == 6) status = 5; + else status = 0; + + device.setStatus(status); + deployBtnText(status); + if (listener != null && status < 5) + listener.btnChargeChanged(device.getGroupId(), device.getDeviceId(), device.getStatus()); + + } + + @FXML + private void btnWrongAction(ActionEvent event) { + int status = device.getStatus(); + if (status >= 5) { + status = 0; + } else if (status <= 4) { + status = 5; + } + + device.setStatus(status); + deployBtnText(status); + + if (listener != null && status < 5) + listener.btnChargeChanged(device.getGroupId(), device.getDeviceId(), device.getStatus()); + } + + void setBtnWrongText(String value) { + btnWrong.setText(value); + } + + void setBtnChargeText(String value) { + btnCharge.setText(value); + } + + public void setName(String name) { + this.name.setText(name); + } + + public void setDepartment(String department) { + this.department.setText(department); + } + + public void setCardNumber(String cardNumber) { + this.cardNumber.setText(cardNumber); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + DeviceView that = (DeviceView) o; + + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml new file mode 100644 index 0000000..8078d88 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/clustermanage-client-javafx/src/main/resources/logback.xml b/clustermanage-client-javafx/src/main/resources/logback.xml new file mode 100644 index 0000000..4b07e8b --- /dev/null +++ b/clustermanage-client-javafx/src/main/resources/logback.xml @@ -0,0 +1,16 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java new file mode 100644 index 0000000..dbef9f6 --- /dev/null +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java @@ -0,0 +1,39 @@ +package cc.bitky.clustermanage; + +public class ServerSetting { + + + //-----------------------接收到充电状态帧时的处理策略---------------------------- + /** + * 部署设备信息时,数据库中的设备和员工未初始化时,是否自动部署默认值 + */ + public static final boolean DEPLOY_DEVICES_INIT = true; + /** + * 收到充电状态包时,自动创建相应的默认设备以及相应的员工和考勤表 + */ + public static final boolean AUTO_CREATE_DEVICE_EMPLOYEE = true; + /** + * 当设备中记录的剩余充电次数小于该值时,则向设备发送剩余充电次数 + */ + public static final int DEPLOY_REMAIN_CHARGE_TIMES = 20; + + + //------------------------待发送消息的任务调度策略------------------------------ + /** + * 待发送缓冲双端队列的限定容量,当队列中存在的 Message 大于该值时,使用时间轮延时向队列添加 Message + */ + public static final int LINKED_DEQUE_LIMIT_CAPACITY = 10000; + /** + * 待发送缓冲队列中,帧发送间隔「单位/ms」 + */ + public static final int FRAME_SEND_INTERVAL = 20; + /** + * 已发送帧后,在该间隔时间后,检测接收回复帧的状态,用于检错重发功能「单位/s」 + */ + public static final int FRAME_SENT_TO_DETECT_INTERVAL = 5; + + /** + * 待发送缓冲队列 Message 大于限定容量后,待执行指令的延迟等待执行时间「单位/s」 + */ + public static final int COMMAND_DELAY_WAITING_TIME = 30; +} \ No newline at end of file From e596090c1cf1997a164e160122bf3116cba92f76 Mon Sep 17 00:00:00 2001 From: bitkylin Date: Fri, 19 May 2017 22:04:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?GUI=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=B7=B2?= =?UTF-8?q?=E5=AE=8C=E5=96=84=EF=BC=8C=E5=8D=A1=E5=8F=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=A0=BC=E5=BC=8F=E4=B8=BA=20String?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clustermanage-client-javafx/pom.xml | 2 +- .../main/java/cc/bitky/clustermanage/App.java | 124 -------------- .../cc/bitky/clustermanage/KySetting.java | 10 ++ .../cc/bitky/clustermanage/MainLauncher.java | 10 +- .../cc/bitky/clustermanage/NettyLauncher.java | 42 +++++ .../{NettyServer.java => NettyClient.java} | 11 +- .../CanFrameChannelInboundHandler.java | 21 +-- .../netty/handler/KyChannelInitializer.java | 44 ++--- .../handler/ParsedMessageInBoundHandler.java | 50 ++++-- .../netty/message/base/BaseMsgCardNum.java | 6 +- .../tcp/TcpMsgInitResponseCardNumber.java | 2 +- .../web/WebMsgDeployEmployeeCardNumber.java | 2 +- .../web/WebMsgDeployFreeCardSpecial.java | 6 +- .../clustermanage/utils/TcpMsgBuilder.java | 44 +++-- .../bitky/clustermanage/utils/ViewUtil.java | 158 ++++++++++++++++++ .../view/DeviceStatusChangeListener.java | 8 + .../view/KyDeviceViewListener.java | 7 - .../cc/bitky/clustermanage/view/MainView.java | 124 +++++++++++--- .../view/MainViewActionListener.java | 10 ++ .../view/RootLayoutController.java | 21 +++ .../bitky/clustermanage/view/bean/Device.java | 6 +- .../cc/bitky/clustermanage/view/mainview.fxml | 31 ---- .../view/menu/AboutController.java | 24 +++ .../bitky/clustermanage/view/menu/about.fxml | 13 ++ .../bitky/clustermanage/view/rootLayout.fxml | 94 +++++++++++ .../view/viewbean/DeviceGroupListCell.java | 6 - .../view/viewbean/DeviceView.java | 39 ++--- .../view/viewbean/device_view.fxml | 6 +- clustermanage-server/pom.xml | 2 +- .../ClustermanageServerApplication.java | 2 +- .../cc/bitky/clustermanage/ServerSetting.java | 1 + .../bitky/clustermanage/db/bean/Device.java | 6 +- .../clustermanage/db/bean/KySetting.java | 27 +-- .../db/presenter/DbSettingPresenter.java | 20 +-- .../db/presenter/KyDbPresenter.java | 6 +- .../server/bean/KyServerCenterHandler.java | 8 +- .../server/bean/ServerTcpMessageHandler.java | 2 +- .../server/bean/ServerWebMessageHandler.java | 12 +- .../server/message/base/BaseMsgCardNum.java | 6 +- .../tcp/TcpMsgInitResponseCardNumber.java | 2 +- .../web/WebMsgDeployEmployeeCardNumber.java | 2 +- .../web/WebMsgDeployFreeCardNumber.java | 6 +- .../CanFrameChannelInboundHandler.java | 17 +- .../clustermanage/tcp/util/TcpMsgBuilder.java | 48 +++++- .../clustermanage/web/InfoRestController.java | 6 +- .../web/OperateRestController.java | 2 +- 46 files changed, 716 insertions(+), 380 deletions(-) delete mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/KySetting.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/NettyLauncher.java rename clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/{NettyServer.java => NettyClient.java} (84%) create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ViewUtil.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/DeviceStatusChangeListener.java delete mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainViewActionListener.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/RootLayoutController.java delete mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/AboutController.java create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/about.fxml create mode 100644 clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/rootLayout.fxml diff --git a/clustermanage-client-javafx/pom.xml b/clustermanage-client-javafx/pom.xml index d47a193..41e1217 100644 --- a/clustermanage-client-javafx/pom.xml +++ b/clustermanage-client-javafx/pom.xml @@ -5,7 +5,7 @@ cc.bitky.clustermanage clustermanage-client - 0.8.5-SNAPSHOT + 0.8.6-SNAPSHOT jar clustermanage-client-javafx diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java deleted file mode 100644 index 4a66dfc..0000000 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/App.java +++ /dev/null @@ -1,124 +0,0 @@ -package cc.bitky.clustermanage; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Scanner; - -import cc.bitky.clustermanage.netty.NettyServer; -import cc.bitky.clustermanage.netty.handler.KyChannelInitializer; -import cc.bitky.clustermanage.netty.message.MsgType; -import cc.bitky.clustermanage.netty.message.base.BaseTcpResponseMsg; -import cc.bitky.clustermanage.netty.message.base.IMessage; -import cc.bitky.clustermanage.netty.message.tcp.TcpMsgInitResponseCardNumber; -import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; -import cc.bitky.clustermanage.utils.ChargeStatusEnum; - -public class App { - private static Logger logger = LoggerFactory.getLogger(App.class); - private Scanner scanner = new Scanner(System.in); - private NettyServer nettyServer; - - public App() { - } - - public static void main(String[] args) { - - logger.debug("debug"); - logger.info("info"); - // new App().start(); - - } - - private void welcomeTo() { - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } - System.out.println("\n* * * * *"); - System.out.println("测试客户端: 请选择想要进行的操作"); - System.out.println(" cs「group」「box」「status」: 改变状态"); - System.out.println(" card「group」「box」「number」: 上传卡号"); - System.out.println(" re[x]「group」「box」「number」: 帧类型"); - System.out.println(" exit: 返回主菜单"); - System.out.print("请输入: "); - } - - public void start() { - nettyServer = new NettyServer(); - nettyServer.setLaunchSuccessfulListener(isSuccess -> keyIn()); - nettyServer.setFinishSuccessfulListener(isSuccess -> System.out.println("客户端优雅关闭成功")); - nettyServer.start(); - } - - private void keyIn() { - - while (true) { - welcomeTo(); - String inputMsg = scanner.next(); - IMessage message; - int groupId; - int boxId; - int status; - switch (inputMsg) { - case "cs": - groupId = scanner.nextInt(); - boxId = scanner.nextInt(); - status = scanner.nextInt(); - if (status < 0 || status > 6) { - status = ChargeStatusEnum.CRASH; - } - message = new TcpMsgResponseDeviceStatus(groupId, boxId, status); - break; - case "card": - groupId = scanner.nextInt(); - boxId = scanner.nextInt(); - long cardNum = scanner.nextLong(); - message = new TcpMsgInitResponseCardNumber(groupId, boxId, cardNum); - break; - case "rest": - message = buildResMsg(MsgType.DEVICE_RESPONSE_REMAIN_CHARGE_TIMES); - break; - case "resb": - message = buildResMsg(MsgType.DEVICE_RESPONSE_DEVICE_ID); - break; - case "resn": - message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_NAME); - break; - case "resd": - message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_DEPARTMENT_1); - break; - case "rese": - message = buildResMsg(MsgType.DEVICE_RESPONSE_EMPLOYEE_CARD_NUMBER); - break; - case "resl": - message = buildResMsg(MsgType.DEVICE_RESPONSE_REMOTE_UNLOCK); - break; - case "resf": - message = buildResMsg(MsgType.DEVICE_RESPONSE_FREE_CARD_NUMBER); - break; - case "err": - message = buildResMsg(0); - break; - case "exit": - nettyServer.shutdown(); - return; - default: - continue; - } - if (message != null) { - KyChannelInitializer.newInstance().getPipeline().write(message); - } - } - } - - private IMessage buildResMsg(int msgId) { - int groupId = scanner.nextInt(); - int boxId = scanner.nextInt(); - int status = scanner.nextInt(); - IMessage message = new BaseTcpResponseMsg(groupId, boxId, status); - message.setMsgId(msgId); - return message; - } -} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/KySetting.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/KySetting.java new file mode 100644 index 0000000..fd188c5 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/KySetting.java @@ -0,0 +1,10 @@ +package cc.bitky.clustermanage; + +public class KySetting { + //------------------系统--------------------------- + public static final String VERSION = "v0.8.6"; + + //----------------网络连接-------------------------- + public static final String HOST_NAME = "localhost"; + public static final int PORT = 30232; +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java index b3018fb..f07ce22 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java @@ -9,13 +9,15 @@ public class MainLauncher extends Application { @Override public void start(Stage primaryStage) throws Exception { + startApp(primaryStage); + } - Stage primaryStage1 = primaryStage; - primaryStage1.setTitle("bitkyApp"); + private void startApp(Stage primaryStage) { + primaryStage.setTitle("设备模拟客户端"); primaryStage.setScene(new Scene(MainView.getInstance())); primaryStage.setMaximized(true); + primaryStage.setOnCloseRequest(event -> NettyLauncher.getInstance().shutdown()); primaryStage.show(); - MainView.getInstance().updateGroupCount(1); - // new App().start(); + MainView.getInstance().updateGroupCount(10); } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/NettyLauncher.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/NettyLauncher.java new file mode 100644 index 0000000..e3adabc --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/NettyLauncher.java @@ -0,0 +1,42 @@ +package cc.bitky.clustermanage; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Scanner; + +import cc.bitky.clustermanage.netty.NettyClient; +import cc.bitky.clustermanage.view.MainView; + +public class NettyLauncher { + private static Logger logger = LoggerFactory.getLogger(NettyLauncher.class); + private static NettyLauncher nettyLauncher; + private Scanner scanner = new Scanner(System.in); + private NettyClient nettyClient; + + private NettyLauncher() { + } + + public static NettyLauncher getInstance() { + if (nettyLauncher == null) nettyLauncher = new NettyLauncher(); + return nettyLauncher; + } + + public void start(String hostName, int port) { + nettyClient = new NettyClient(); + nettyClient.setLaunchSuccessfulListener(isSuccess -> { + MainView.getInstance().setLabelConnStatus(isSuccess); + }); + nettyClient.setFinishSuccessfulListener(isSuccess -> { + System.out.println("客户端优雅关闭成功"); + System.exit(0); + }); + nettyClient.start(hostName, port); + } + + void shutdown() { + if (nettyClient != null) + nettyClient.shutdown(); + } + +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyClient.java similarity index 84% rename from clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java rename to clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyClient.java index c8c9479..f53f8d1 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyServer.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyClient.java @@ -11,21 +11,24 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.concurrent.Future; -public class NettyServer { +public class NettyClient { private SuccessfulListener launchListener; private SuccessfulListener finishListener; private EventLoopGroup group; - public void start() { + public void start(String hostName, int port) { new Thread(() -> { group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) - .remoteAddress(new InetSocketAddress(30232)) - .handler(KyChannelInitializer.newInstance()); + .handler(new KyChannelInitializer()); + if (hostName != null && !hostName.equals("")) + bootstrap.remoteAddress(new InetSocketAddress(hostName, port)); + else + bootstrap.remoteAddress(new InetSocketAddress(port)); ChannelFuture channelFuture = null; try { diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java index 80379a0..eed641f 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java @@ -19,6 +19,7 @@ import cc.bitky.clustermanage.netty.message.web.WebMsgInitMarchConfirmCardResponse; import cc.bitky.clustermanage.netty.message.web.WebMsgObtainDeviceStatus; import cc.bitky.clustermanage.netty.message.web.WebMsgOperateBoxUnlock; +import cc.bitky.clustermanage.utils.TcpMsgBuilder; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -65,7 +66,7 @@ private IMessage handleMessage(int msgId, int groupId, int boxId, int bodyLength if (msgId >= 0x70 && msgId <= 0x7F) { byte[] bytes = new byte[8]; msg.readBytes(bytes); - long freeCardNumber = byteArrayToLong(bytes); + String freeCardNumber = TcpMsgBuilder.byteArrayToString(bytes); return new WebMsgDeployFreeCardSpecial(groupId, boxId, freeCardNumber, msgId - 0x70); } @@ -100,7 +101,7 @@ private IMessage handleMessage(int msgId, int groupId, int boxId, int bodyLength case MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER: byte[] bytes = new byte[8]; msg.readBytes(bytes); - long cardNumber = byteArrayToLong(bytes); + String cardNumber = TcpMsgBuilder.byteArrayToString(bytes); return new WebMsgDeployEmployeeCardNumber(groupId, boxId, cardNumber); //服务器远程开锁 case MsgType.SERVER_REMOTE_UNLOCK: @@ -137,20 +138,4 @@ private String readGB2312Body(ByteBuf msg) { msg.readBytes(bytes); return new String(bytes, charset_GB2312); } - - long byteArrayToLong(byte[] bytes) { - long num = 0; - for (int i = 0; i <= 7; i++) { - num += (bytes[i] & 0xffL) << ((7 - i) * 8); - } - return num; - } - - private byte[] longToByteArray(long num) { - byte[] bytes = new byte[8]; - for (int i = 0; i <= 7; i++) { - bytes[i] = (byte) ((num >> ((7 - i) * 8)) & 0xff); - } - return bytes; - } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java index 1f0ac0e..3f24304 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java @@ -1,10 +1,7 @@ package cc.bitky.clustermanage.netty.handler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; -import cc.bitky.clustermanage.view.KyDeviceViewListener; +import cc.bitky.clustermanage.view.MainViewActionListener; import cc.bitky.clustermanage.view.MainView; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; @@ -13,42 +10,25 @@ import io.netty.handler.logging.LoggingHandler; public class KyChannelInitializer extends ChannelInitializer { - private static KyChannelInitializer kyChannelInitializer; - private final KyOutBoundHandler kyOutBoundHandler; - private final ParsedMessageInBoundHandler parsedMessageInBoundHandler; - private ChannelPipeline pipeline; - private Logger logger = LoggerFactory.getLogger(getClass()); - - private KyChannelInitializer() { - kyOutBoundHandler = new KyOutBoundHandler(); - parsedMessageInBoundHandler = new ParsedMessageInBoundHandler(); - parsedMessageInBoundHandler.setReceiveListener(() -> { - }); - } - - - public static KyChannelInitializer newInstance() { - if (kyChannelInitializer == null) kyChannelInitializer = new KyChannelInitializer(); - return kyChannelInitializer; - } + ParsedMessageInBoundHandler parsedMessageInBoundHandler = new ParsedMessageInBoundHandler(); @Override protected void initChannel(SocketChannel ch) throws Exception { - pipeline = ch.pipeline(); + ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new LoggingHandler("kyOutlineLogger", LogLevel.INFO)); pipeline.addLast(new CanFrameChannelInboundHandler()); pipeline.addLast(parsedMessageInBoundHandler); - pipeline.addLast(kyOutBoundHandler); - MainView.getInstance().setListener(new KyDeviceViewListener() { + pipeline.addLast(new KyOutBoundHandler()); + MainView.getInstance().setListener(new MainViewActionListener() { @Override - public void btnChargeChanged(int groupId, int deviceId, int status) { - pipeline.write(new TcpMsgResponseDeviceStatus(groupId, deviceId, status)); + public void btnChargeChanged(TcpMsgResponseDeviceStatus tcpMsgResponseDeviceStatus) { + pipeline.write(tcpMsgResponseDeviceStatus); } - }); - } - public ChannelPipeline getPipeline() { - return pipeline; + @Override + public void clearRecCount(boolean rec, boolean err) { + parsedMessageInBoundHandler.clearRecCount( rec, err); + } + }); } - } \ No newline at end of file diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java index b31bbf2..8a0780b 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java @@ -20,7 +20,6 @@ import cc.bitky.clustermanage.netty.message.web.WebMsgDeployFreeCardSpecial; import cc.bitky.clustermanage.netty.message.web.WebMsgDeployRemainChargeTimes; import cc.bitky.clustermanage.netty.message.web.WebMsgInitMarchConfirmCardResponse; -import cc.bitky.clustermanage.utils.TcpReceiveListener; import cc.bitky.clustermanage.view.Container; import cc.bitky.clustermanage.view.MainView; import cc.bitky.clustermanage.view.bean.Device; @@ -34,13 +33,14 @@ public class ParsedMessageInBoundHandler extends SimpleChannelInboundHandler 4 ? 0 : 1)); break; @@ -72,7 +72,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device.setDeviceId(deployEmployeeDeviceId.getUpdatedDeviceId()); addHistory(device, "Id:" + deployEmployeeDeviceId.getUpdatedDeviceId()); Container.deviceHashMap.put(deviceKeyNew, device); - MainView.getInstance().remoteUpdateDevice(deviceOld, device); + MainView.getInstance().remoteUpdateDevice(sum, deviceOld, device); break; case MsgType.SERVER_SET_EMPLOYEE_NAME: @@ -81,7 +81,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device = getDevice(msg); device.setName(webMsgDeployEmployeeName.getValue()); addHistory(device, "姓名:" + webMsgDeployEmployeeName.getValue()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeName(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); break; @@ -91,7 +91,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device = getDevice(msg); device.setDepartment(deployEmployeeDepartment1.getValue()); addHistory(device, "单位1:" + device.getDepartment()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeDepartment(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); break; @@ -101,7 +101,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device = getDevice(msg); device.setDepartment(device.getDepartment() + deployEmployeeDepartment2.getValue()); addHistory(device, "单位2:" + deployEmployeeDepartment2.getValue()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeDepartment2(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); break; @@ -111,7 +111,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device = getDevice(msg); device.setCardNumber(deployEmployeeCardNumber.getCardNumber()); addHistory(device, "卡号:" + deployEmployeeCardNumber.getCardNumber()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseEmployeeCardnumber(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); break; @@ -119,7 +119,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { logger.debug("收到操作:远程开锁"); device = getDevice(msg); addHistory(device, "开锁"); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseOperateBoxUnlock(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1)); break; @@ -128,7 +128,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { logger.debug("收到部署万能卡号「『" + deployFreeCardSpecial.getItemId() + "』" + deployFreeCardSpecial.getCardNumber() + "」"); device = getDevice(msg); addHistory(device, "万能:" + deployFreeCardSpecial.getItemId()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); ctx.channel().writeAndFlush(new TcpMsgResponseFreeCardNumber(device.getGroupId(), device.getDeviceId(), device.getStatus() > 4 ? 0 : 1, deployFreeCardSpecial.getItemId())); break; @@ -137,7 +137,7 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { logger.debug("「初始化」 匹配确认卡号状态: " + marchConfirmCardResponse.isSuccessful()); device = getDevice(msg); addHistory(device, "匹配:" + marchConfirmCardResponse.isSuccessful()); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); break; case MsgType.INITIALIZE_SERVER_CLEAR_INITIALIZE_MESSAGE: @@ -145,10 +145,10 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { device = getDevice(msg); device.setName(""); device.setDepartment(""); - device.setCardNumber(0); + device.setCardNumber("0"); device.setStatus(0); addHistory(device, "清空设备"); - MainView.getInstance().remoteUpdateDevice(device); + MainView.getInstance().remoteUpdateDevice(sum, device); break; default: @@ -156,14 +156,25 @@ protected void channelRead0(ChannelHandlerContext ctx, IMessage msg) { errorSum++; break; } - if (receiveListener != null) receiveListener.receive(); } + /** + * 在从 HashMap 中读取的设备 bean 中添加历史记录 + * + * @param device 从 HashMap 中读取的设备 bean + * @param addValue 欲添加的信息 + */ private void addHistory(Device device, String addValue) { String finalStr = (device.getHistoryList().size() + 1) + ". " + addValue; device.addHistoryList(finalStr); } + /** + * 获得存储在 HashMap 中的单个设备 bean + * + * @param msg 收到的 Message + * @return 读取到的设备 bean + */ private Device getDevice(IMessage msg) { DeviceKey deviceKey = new DeviceKey(msg.getGroupId(), msg.getBoxId()); Device device = Container.deviceHashMap.get(deviceKey); @@ -174,8 +185,15 @@ private Device getDevice(IMessage msg) { return device; } - void setReceiveListener(TcpReceiveListener receiveListener) { - this.receiveListener = receiveListener; + /** + * 清除接收帧的计数 + * + * @param rec 是否清除全部帧的计数 + * @param err 是否清除错误帧的计数 + */ + void clearRecCount(boolean rec, boolean err) { + if (rec) sum = 0; + if (err) errorSum = 0; } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java index 1d15419..39d892c 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/base/BaseMsgCardNum.java @@ -2,15 +2,15 @@ public class BaseMsgCardNum extends BaseMessage { - private long cardNumber; + private String cardNumber; - protected BaseMsgCardNum(int groupId, int boxId, long cardNumber, int msgType) { + protected BaseMsgCardNum(int groupId, int boxId, String cardNumber, int msgType) { super(groupId, boxId); setMsgId(msgType); this.cardNumber = cardNumber; } - public long getCardNumber() { + public String getCardNumber() { return cardNumber; } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java index 998e14a..06db0bc 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/tcp/TcpMsgInitResponseCardNumber.java @@ -8,7 +8,7 @@ */ public class TcpMsgInitResponseCardNumber extends BaseMsgCardNum { - public TcpMsgInitResponseCardNumber(int groupId, int boxId, long cardNumber) { + public TcpMsgInitResponseCardNumber(int groupId, int boxId, String cardNumber) { super(groupId, boxId, cardNumber, MsgType.INITIALIZE_DEVICE_RESPONSE_CARD); } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java index 0713728..923896f 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployEmployeeCardNumber.java @@ -8,7 +8,7 @@ */ public class WebMsgDeployEmployeeCardNumber extends BaseMsgCardNum { - public WebMsgDeployEmployeeCardNumber(int groupId, int boxId, long cardNumber) { + public WebMsgDeployEmployeeCardNumber(int groupId, int boxId, String cardNumber) { super(groupId, boxId, cardNumber, MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER); } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java index 55f6f36..1f7466f 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/message/web/WebMsgDeployFreeCardSpecial.java @@ -9,7 +9,7 @@ public class WebMsgDeployFreeCardSpecial extends BaseMessage { private final int itemId; - private long cardNumber; + private String cardNumber; /** * 服务器部署万能卡号 @@ -18,7 +18,7 @@ public class WebMsgDeployFreeCardSpecial extends BaseMessage { * @param boxId 设备号 * @param cardNumber 万能卡号集合 */ - public WebMsgDeployFreeCardSpecial(int groupId, int boxId, long cardNumber, int itemId) { + public WebMsgDeployFreeCardSpecial(int groupId, int boxId, String cardNumber, int itemId) { super(groupId, boxId); this.cardNumber = cardNumber; this.itemId = itemId; @@ -29,7 +29,7 @@ public int getItemId() { return itemId; } - public long getCardNumber() { + public String getCardNumber() { return cardNumber; } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java index 080893c..8ddb9d8 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java @@ -18,7 +18,7 @@ public class TcpMsgBuilder { public byte[] buildInitConfirmCardNumber(BaseMsgCardNum msgCardNum) { byte[] bytes = buildMsgOutline(msgCardNum); bytes[0] += 8; - byte[] byteCardNum = longToByteArray(msgCardNum.getCardNumber()); + byte[] byteCardNum = stringToByteArray(msgCardNum.getCardNumber()); addMessageBody(bytes, byteCardNum, 0); return bytes; } @@ -57,31 +57,51 @@ private byte[] buildMsgOutline(BaseMessage message) { * @param bytes 轮廓CAN帧 * @param bytesBody 数据位 * @param offset 数据位的偏移量,offset位开始操作8个字节 - * @return 已构建完成的CAN帧 */ - private byte[] addMessageBody(byte[] bytes, byte[] bytesBody, int offset) { + private void addMessageBody(byte[] bytes, byte[] bytesBody, int offset) { int max = (bytesBody.length - offset) > 8 ? 8 : (bytesBody.length - offset); for (int i = 0; i < max; i++) { bytes[i + 5] = bytesBody[i + offset]; } - return bytes; } - private long byteArrayToLong(byte[] bytes) { - long num = 0; - for (int i = 0; i <= 7; i++) { - num += (bytes[i] & 0xffL) << ((7 - i) * 8); + public static String byteArrayToString(byte[] cards) { + StringBuilder builder = new StringBuilder(); + for (byte b : cards) { + String s = Integer.toHexString(b & 0xFF).toUpperCase(); + if (s.length() == 1) { + builder.append('0').append(s); + } else builder.append(s); } - return num; + return builder.toString(); } - private byte[] longToByteArray(long num) { + public static byte[] stringToByteArray(String cards) { + if (cards.length() > 16) cards = cards.substring(0, 16); + if (cards.length() < 16) { + int count = 16 - cards.length(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < count; i++) { + builder.append("0"); + } + builder.append(cards); + cards = builder.toString(); + } + byte[] bytes = new byte[8]; - for (int i = 0; i <= 7; i++) { - bytes[i] = (byte) ((num >> ((7 - i) * 8)) & 0xff); + cards = cards.toUpperCase(); + char[] hexChars = cards.toCharArray(); + for (int i = 0; i < 8; i++) { + int pos = i * 2; + bytes[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); } return bytes; } + private static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + + } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ViewUtil.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ViewUtil.java new file mode 100644 index 0000000..1c6506e --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/ViewUtil.java @@ -0,0 +1,158 @@ +package cc.bitky.clustermanage.utils; + +import java.util.Optional; +import java.util.Properties; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import javafx.application.Platform; +import javafx.geometry.Insets; +import javafx.scene.Node; +import javafx.scene.control.ButtonBar; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.util.Pair; + + +public class ViewUtil { + /** + * 获取操作系统信息 + * + * @return 生成的信息 + */ + public static String getOsInfo() { + Properties props = System.getProperties(); + return "Java运行时版本: " + props.getProperty("java.runtime.version") + "\n" + + "操作系统: " + props.getProperty("os.name") + "\n" + + "架构: " + props.getProperty("os.arch") + "\n" + + "语言: " + props.getProperty("user.language") + "\n" + + "用户名: " + props.getProperty("user.name") + "\n" + + "系统编码: " + props.getProperty("sun.jnu.encoding") + "\n" + + "文件编码: " + props.getProperty("file.encoding") + "\n"; + } + + public static Optional> ConnDialogResult() { + Dialog> dialog = new Dialog<>(); + dialog.setTitle("建立连接"); + dialog.setHeaderText("请输入服务器的连接信息"); + + + ButtonType loginButtonType = new ButtonType("连接", ButtonBar.ButtonData.OK_DONE); + dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); + + // Create the username and password labels and fields. + GridPane grid = new GridPane(); + grid.setHgap(10); + grid.setVgap(10); + grid.setPadding(new Insets(20, 150, 10, 10)); + + TextField hostName = new TextField(); + hostName.setPromptText("localhost"); + hostName.setText("localhost"); + TextField port = new TextField(); + port.setPromptText("30232"); + port.setText("30232"); + + grid.add(new Label("主机名: "), 0, 0); + grid.add(hostName, 1, 0); + grid.add(new Label("端口号: "), 0, 1); + grid.add(port, 1, 1); + + // Enable/Disable login button depending on whether a username was entered. + // Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); + // loginButton.setDisable(true); + + // Do some validation (using the Java 8 lambda syntax). +// hostName.textProperty().addListener((observable, oldValue, newValue) -> { +// loginButton.setDisable(newValue.trim().isEmpty()); +// }); + + dialog.getDialogPane().setContent(grid); + + // Request focus on the username field by default. + Platform.runLater(() -> hostName.requestFocus()); + + dialog.setResultConverter(dialogButton -> { + if (dialogButton == loginButtonType) { + return new Pair<>(hostName.getText(), port.getText()); + } + return null; + }); + + return dialog.showAndWait(); + } + + public static Optional ResponseDeviceStatusResult() throws NumberFormatException { + Dialog dialog = new Dialog<>(); + dialog.setTitle("发送状态信息"); + dialog.setHeaderText("请设置单个设备的状态"); + + + ButtonType loginButtonType = new ButtonType("发送", ButtonBar.ButtonData.OK_DONE); + dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); + + // Create the username and password labels and fields. + GridPane grid = new GridPane(); + grid.setHgap(10); + grid.setVgap(10); + grid.setPadding(new Insets(20, 150, 10, 10)); + + TextField textFieldGroupId = new TextField(); + textFieldGroupId.setPromptText("1 - 120"); + + TextField textFieldDeviceId = new TextField(); + textFieldDeviceId.setPromptText("1 - 100"); + + TextField textFieldStatus = new TextField(); + textFieldStatus.setPromptText("1 - 6"); + + + grid.add(new Label("组号: "), 0, 0); + grid.add(textFieldGroupId, 1, 0); + grid.add(new Label("设备号: "), 0, 1); + grid.add(textFieldDeviceId, 1, 1); + grid.addRow(2, new Label("状态码: ")); + // grid.add(, 0, 2); + grid.add(textFieldStatus, 1, 2); + + // Enable/Disable login button depending on whether a username was entered. + Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); + loginButton.setDisable(true); + + // Do some validation (using the Java 8 lambda syntax). + textFieldGroupId.textProperty().addListener((observable, oldValue, newValue) -> loginButton.setDisable(fieldisEmpty(textFieldGroupId, textFieldDeviceId, textFieldStatus))); + textFieldDeviceId.textProperty().addListener((observable, oldValue, newValue) -> loginButton.setDisable(fieldisEmpty(textFieldGroupId, textFieldDeviceId, textFieldStatus))); + textFieldStatus.textProperty().addListener((observable, oldValue, newValue) -> loginButton.setDisable(fieldisEmpty(textFieldGroupId, textFieldDeviceId, textFieldStatus))); + + dialog.getDialogPane().setContent(grid); + + // Request focus on the username field by default. + Platform.runLater(textFieldGroupId::requestFocus); + + dialog.setResultConverter(dialogButton -> { + + if (dialogButton == loginButtonType) { + try { + TcpMsgResponseDeviceStatus tcpMsgResponseDeviceStatus = new TcpMsgResponseDeviceStatus(Integer.parseInt( + textFieldGroupId.getText().trim()), + Integer.parseInt(textFieldDeviceId.getText().trim()), + Integer.parseInt(textFieldStatus.getText().trim())); + return tcpMsgResponseDeviceStatus; + } catch (NumberFormatException e) { + System.out.println("空"); + return new TcpMsgResponseDeviceStatus(-1, -1, -1); + } + } + return null; + }); + return dialog.showAndWait(); + } + + private static boolean fieldisEmpty(TextField textFieldGroupId, TextField textFieldDeviceId, TextField textFieldStatus) { + return textFieldGroupId.getText().trim().isEmpty() + || textFieldDeviceId.getText().trim().isEmpty() + || textFieldStatus.getText().trim().isEmpty(); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/DeviceStatusChangeListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/DeviceStatusChangeListener.java new file mode 100644 index 0000000..68169bd --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/DeviceStatusChangeListener.java @@ -0,0 +1,8 @@ +package cc.bitky.clustermanage.view; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; + +public interface DeviceStatusChangeListener { + + void btnChargeChanged(TcpMsgResponseDeviceStatus tcpMsgResponseDeviceStatus); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java deleted file mode 100644 index ed97912..0000000 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/KyDeviceViewListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package cc.bitky.clustermanage.view; - -public interface KyDeviceViewListener { - - void btnChargeChanged(int groupId,int deviceId,int status); - -} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java index b1cb253..91a6c98 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java @@ -4,35 +4,57 @@ import java.net.URL; import java.util.ResourceBundle; +import cc.bitky.clustermanage.KySetting; +import cc.bitky.clustermanage.NettyLauncher; +import cc.bitky.clustermanage.utils.ViewUtil; import cc.bitky.clustermanage.view.bean.Device; import cc.bitky.clustermanage.view.bean.DeviceGroup; import cc.bitky.clustermanage.view.bean.DeviceKey; import cc.bitky.clustermanage.view.viewbean.DeviceGroupListCell; import cc.bitky.clustermanage.view.viewbean.DeviceView; +import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.ListView; -import javafx.scene.control.SplitPane; -import javafx.scene.layout.AnchorPane; +import javafx.scene.control.MenuItem; +import javafx.scene.layout.BorderPane; import javafx.scene.layout.FlowPane; -public class MainView extends AnchorPane implements Initializable { +public class MainView extends BorderPane implements Initializable { private static MainView mainView; ObservableList deviceGroups; - int groupId; - private KyDeviceViewListener listener; + private int groupId; + private MainViewActionListener listener; @FXML private ListView deviceGroupList; @FXML private FlowPane deviceFlowPane; + + @FXML + private Label labelCurrentGroupId; + + @FXML + private Label labelConnStatus; + + @FXML + private Label labelRecCount; + + @FXML + private Button btnCleanRecCount; @FXML - private SplitPane splitPane; + private MenuItem menuItemConn; + @FXML + private MenuItem menuItemSend; private MainView() throws IOException { - FXMLLoader loader = new FXMLLoader(getClass().getResource("mainview.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("rootLayout.fxml")); loader.setRoot(this); loader.setController(this); loader.load(); @@ -49,14 +71,10 @@ public static MainView getInstance() { return mainView; } - public void setListener(KyDeviceViewListener listener) { + public void setListener(MainViewActionListener listener) { this.listener = listener; } - public DeviceView getDevice(int deviceId) { - return Container.deviceViewHashMap.get(deviceId); - } - @Override public void initialize(URL location, ResourceBundle resources) { deviceGroups = FXCollections.observableArrayList(); @@ -65,6 +83,7 @@ public void initialize(URL location, ResourceBundle resources) { deviceGroupList.getFocusModel().focusedItemProperty().addListener( (observable, oldValue, newValue) -> { groupId = newValue.getGroupId(); + labelCurrentGroupId.setText(groupId + "组"); for (int i = 1; i <= 100; i++) { Container.deviceViewHashMap.get(i).initView(Container.deviceHashMap.get(new DeviceKey(groupId, i))); } @@ -74,33 +93,94 @@ public void initialize(URL location, ResourceBundle resources) { DeviceView deviceView = new DeviceView(i); deviceFlowPane.getChildren().add(deviceView); Container.deviceViewHashMap.put(i, deviceView); - deviceView.setListener((groupId, deviceId, status) -> { - if (listener != null) listener.btnChargeChanged(groupId, deviceId, status); - }); + deviceView.setListener((tcpMsgResponseDeviceStatus -> { + if (listener != null) listener.btnChargeChanged(tcpMsgResponseDeviceStatus); + })); } } - public void updateGroupCount(int groupid) { - if (groupid > deviceGroups.size()) { - for (int i = deviceGroups.size() + 1; i <= groupid; i++) { + public void updateGroupCount(int groupId) { + if (groupId > deviceGroups.size()) { + for (int i = deviceGroups.size() + 1; i <= groupId; i++) { deviceGroups.add(new DeviceGroup(i)); deviceGroupList.setItems(deviceGroups); } } } - public void remoteUpdateDevice(Device device) { + public void remoteUpdateDevice(int sum) { + Platform.runLater(() -> labelRecCount.setText(sum + "")); + } + + public void remoteUpdateDevice(int sum, Device device) { if (groupId != 0 && device != null && device.getGroupId() == groupId) { updateGroupCount(device.getGroupId()); - Container.deviceViewHashMap.get(device.getDeviceId()).initView(device); + Platform.runLater(() -> { + labelRecCount.setText(sum + ""); + Container.deviceViewHashMap.get(device.getDeviceId()).initView(device); + }); } } - public void remoteUpdateDevice(Device... devices) { + public void remoteUpdateDevice(int sum, Device... devices) { for (Device device : devices) { - remoteUpdateDevice(device); + remoteUpdateDevice(sum, device); } } + + @FXML + private void onActionMenuItemAbout(ActionEvent event) { + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("关于"); + alert.setHeaderText("集群设备模拟客户端 " + KySetting.VERSION); + alert.setGraphic(null); + alert.setContentText(ViewUtil.getOsInfo()); + alert.showAndWait(); + } + + @FXML + private void onActionMenuItemConn(ActionEvent event) { + ViewUtil.ConnDialogResult().ifPresent(returnMsg -> { + String hostName = returnMsg.getKey(); + String portStr = returnMsg.getValue(); + int port = 30232; + if (hostName == null || hostName.equals("")) hostName = KySetting.HOST_NAME; + try { + if (portStr == null || portStr.equals("")) port = KySetting.PORT; + else port = Integer.parseInt(portStr.trim()); + } catch (NumberFormatException e) { + port = KySetting.PORT; + } + labelConnStatus.setText("连接中"); + NettyLauncher.getInstance().start(hostName, port); + }); + } + + @FXML + void onActionMenuItemSend(ActionEvent event) { + ViewUtil.ResponseDeviceStatusResult().ifPresent(tcpMsgResponseDeviceStatus -> { + if (listener != null) listener.btnChargeChanged(tcpMsgResponseDeviceStatus); + }); + } + + @FXML + private void onActionBtnCleanRecCount(ActionEvent event) { + listener.clearRecCount(true, false); + labelRecCount.setText(0 + ""); + } + + public void setLabelConnStatus(boolean success) { + Platform.runLater(() -> { + if (success) { + labelConnStatus.setText("已连接"); + menuItemConn.setText("已连接"); + menuItemConn.setDisable(true); + menuItemSend.setDisable(false); + } else { + labelConnStatus.setText("已断开"); + } + }); + } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainViewActionListener.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainViewActionListener.java new file mode 100644 index 0000000..584dd19 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainViewActionListener.java @@ -0,0 +1,10 @@ +package cc.bitky.clustermanage.view; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; + +public interface MainViewActionListener { + + void btnChargeChanged(TcpMsgResponseDeviceStatus tcpMsgResponseDeviceStatus); + + void clearRecCount(boolean rec, boolean err); +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/RootLayoutController.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/RootLayoutController.java new file mode 100644 index 0000000..2983ae4 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/RootLayoutController.java @@ -0,0 +1,21 @@ +package cc.bitky.clustermanage.view; + +import javafx.fxml.FXML; +import javafx.scene.control.Alert; +import javafx.scene.control.MenuItem; + +public class RootLayoutController { + @FXML + private MenuItem menuItemClose; + + + @FXML + private void handleAbout() { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setTitle("警告"); + alert.setHeaderText(null); + alert.setContentText("请选择一个条目!"); + + alert.showAndWait(); + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java index a16a396..4e311d9 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/bean/Device.java @@ -6,7 +6,7 @@ public class Device { String name; String department; - long cardNumber; + String cardNumber; private int groupId = -1; private int deviceId = -1; private int status = -1; @@ -96,11 +96,11 @@ public void setDepartment(String department) { this.department = department; } - public long getCardNumber() { + public String getCardNumber() { return cardNumber; } - public void setCardNumber(long cardNumber) { + public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } } diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml deleted file mode 100644 index dca19c6..0000000 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/mainview.fxml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/AboutController.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/AboutController.java new file mode 100644 index 0000000..a9df1eb --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/AboutController.java @@ -0,0 +1,24 @@ +package cc.bitky.clustermanage.view.menu; + +import java.io.IOException; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.MenuItem; +import javafx.scene.layout.AnchorPane; + +public class AboutController extends AnchorPane { + @FXML + private MenuItem menuItemClose; + + public AboutController() { + FXMLLoader loader = new FXMLLoader(getClass().getResource("about.fxml")); + loader.setRoot(this); + loader.setController(this); + try { + loader.load(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/about.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/about.fxml new file mode 100644 index 0000000..fd33361 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/menu/about.fxml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/rootLayout.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/rootLayout.fxml new file mode 100644 index 0000000..6383ca2 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/rootLayout.fxml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java index a7d6ad4..c946211 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java @@ -4,17 +4,11 @@ import java.util.ResourceBundle; import cc.bitky.clustermanage.view.bean.DeviceGroup; -import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.control.Label; import javafx.scene.control.ListCell; public class DeviceGroupListCell extends ListCell implements Initializable { - - @FXML - private Label label; - @Override protected void updateItem(DeviceGroup item, boolean empty) { super.updateItem(item, empty); diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java index 41bedf1..a6d6956 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java @@ -4,9 +4,9 @@ import java.net.URL; import java.util.ResourceBundle; -import cc.bitky.clustermanage.view.KyDeviceViewListener; +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import cc.bitky.clustermanage.view.DeviceStatusChangeListener; import cc.bitky.clustermanage.view.bean.Device; -import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -19,7 +19,7 @@ public class DeviceView extends TabPane implements Initializable { private static Device deviceDefault = new Device(); - KyDeviceViewListener listener; + DeviceStatusChangeListener listener; @FXML private Tab tabStatus; @FXML @@ -42,28 +42,25 @@ public class DeviceView extends TabPane implements Initializable { public DeviceView(int id) { this.id = id; loadFxml(); + initView(null); } - public void setListener(KyDeviceViewListener listener) { + public void setListener(DeviceStatusChangeListener listener) { this.listener = listener; } - public void initView(Device device) { - if (device == null) device = deviceDefault; - this.device = device; - Device finalDevice = device; - Platform.runLater(() -> { - tabStatus.setText(finalDevice.getDeviceId() + "号"); - name.setText(finalDevice.getName()); - department.setText(finalDevice.getDepartment()); - cardNumber.setText(finalDevice.getCardNumber() + ""); - - deployBtnText(finalDevice.getStatus()); - - historyList.getItems().clear(); - historyList.getItems().addAll(finalDevice.getHistoryList()); - }); + public void initView(Device inDevice) { + if (inDevice == null) inDevice = deviceDefault; + this.device = inDevice; + int setid = device.getDeviceId() == -1 ? this.id : device.getDeviceId(); + tabStatus.setText(setid + "号"); + name.setText(device.getName()); + department.setText(device.getDepartment()); + cardNumber.setText(device.getCardNumber() + ""); + deployBtnText(device.getStatus()); + historyList.getItems().clear(); + historyList.getItems().addAll(device.getHistoryList()); } private void deployBtnText(int status) { @@ -145,7 +142,7 @@ private void btnChargeAction(ActionEvent event) { device.setStatus(status); deployBtnText(status); if (listener != null && status < 5) - listener.btnChargeChanged(device.getGroupId(), device.getDeviceId(), device.getStatus()); + listener.btnChargeChanged(new TcpMsgResponseDeviceStatus(device.getGroupId(), device.getDeviceId(), device.getStatus())); } @@ -162,7 +159,7 @@ private void btnWrongAction(ActionEvent event) { deployBtnText(status); if (listener != null && status < 5) - listener.btnChargeChanged(device.getGroupId(), device.getDeviceId(), device.getStatus()); + listener.btnChargeChanged(new TcpMsgResponseDeviceStatus(device.getGroupId(), device.getDeviceId(), device.getStatus())); } void setBtnWrongText(String value) { diff --git a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml index 8078d88..d5c6c3d 100644 --- a/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/device_view.fxml @@ -11,7 +11,7 @@ - + @@ -45,7 +45,7 @@ @@ -57,7 +57,7 @@ - + diff --git a/clustermanage-server/pom.xml b/clustermanage-server/pom.xml index db36d44..e915c9b 100644 --- a/clustermanage-server/pom.xml +++ b/clustermanage-server/pom.xml @@ -6,7 +6,7 @@ cc.bitky.clustermanage clustermanage-server - 0.8.5-SNAPSHOT + 0.8.6-SNAPSHOT jar clustermanage-server diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/ClustermanageServerApplication.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ClustermanageServerApplication.java index d9e1afe..bb4fa2a 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/ClustermanageServerApplication.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ClustermanageServerApplication.java @@ -12,6 +12,6 @@ public class ClustermanageServerApplication { public static void main(String[] args) { SpringApplication.run(ClustermanageServerApplication.class, args); - logger.info("『bitky.cc』「0.8.1」"); + logger.info("『bitky.cc』「"+ServerSetting.VERSION+"」"); } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java index dbef9f6..5d346f9 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java @@ -36,4 +36,5 @@ public class ServerSetting { * 待发送缓冲队列 Message 大于限定容量后,待执行指令的延迟等待执行时间「单位/s」 */ public static final int COMMAND_DELAY_WAITING_TIME = 30; + public static final String VERSION = "0.8.6"; } \ No newline at end of file diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/Device.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/Device.java index a9d4c6d..eed4b7b 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/Device.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/Device.java @@ -10,7 +10,7 @@ public class Device { * 员工卡号 */ // @Field("cn") - long cardNumber; + String cardNumber; @Id private String id; @@ -100,11 +100,11 @@ public void setBoxId(int boxId) { this.boxId = boxId; } - public long getCardNumber() { + public String getCardNumber() { return cardNumber; } - public void setCardNumber(long cardNumber) { + public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/KySetting.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/KySetting.java index 6f0e975..ee9d93c 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/KySetting.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/bean/KySetting.java @@ -8,17 +8,27 @@ public class KySetting { @Id private String id; - private long[] freeCardList; - private long[] confirmCardList; + public String[] getFreeCardList() { + return freeCardList; + } - public long[] getConfirmCardList() { + public void setFreeCardList(String[] freeCardList) { + this.freeCardList = freeCardList; + } + + public String[] getConfirmCardList() { return confirmCardList; } - public void setConfirmCardList(long[] confirmCardList) { + public void setConfirmCardList(String[] confirmCardList) { this.confirmCardList = confirmCardList; } + private String[] freeCardList; + private String[] confirmCardList; + + + public String getId() { return id; } @@ -27,11 +37,4 @@ public void setId(String id) { this.id = id; } - public long[] getFreeCardList() { - return freeCardList; - } - - public void setFreeCardList(long[] freeCardList) { - this.freeCardList = freeCardList; - } -} + } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/DbSettingPresenter.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/DbSettingPresenter.java index 059b62a..d843c84 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/DbSettingPresenter.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/DbSettingPresenter.java @@ -28,7 +28,7 @@ public DbSettingPresenter(SettingRepository settingRepository, MongoOperations o * @param card 卡号类型枚举 * @return 是否保存成功 */ - boolean saveCardArray(long[] cardArray, CardType card) { + boolean saveCardArray(String[] cardArray, CardType card) { KySetting kySetting = settingRepository.findOne("1"); if (kySetting == null) { kySetting = new KySetting(); @@ -51,19 +51,19 @@ boolean saveCardArray(long[] cardArray, CardType card) { * * @return 卡号的集合 */ - long[] getCardArray(CardType card) { + String[] getCardArray(CardType card) { KySetting kyKySettings = settingRepository.findOne("1"); - if (kyKySettings == null) return new long[0]; - long[] longs; + if (kyKySettings == null) return new String[0]; + String[] cards; switch (card) { case FREE: - longs = kyKySettings.getFreeCardList(); - return longs == null ? new long[0] : longs; + cards = kyKySettings.getFreeCardList(); + return cards == null ? new String[0] : cards; case CONFIRM: - longs = kyKySettings.getConfirmCardList(); - return longs == null ? new long[0] : longs; + cards = kyKySettings.getConfirmCardList(); + return cards == null ? new String[0] : cards; } - return new long[0]; + return new String[0]; } /** @@ -72,7 +72,7 @@ long[] getCardArray(CardType card) { * @param cardNumber 待检索的卡号 * @return 是否匹配确认卡号 */ - boolean marchConfirmCard(long cardNumber) { + boolean marchConfirmCard(String cardNumber) { Query query = new Query(Criteria.where("id").is("1").and("confirmCardList").is(cardNumber)); return operations.exists(query, KySetting.class); } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/KyDbPresenter.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/KyDbPresenter.java index da52d84..f364bea 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/KyDbPresenter.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/db/presenter/KyDbPresenter.java @@ -184,7 +184,7 @@ public Employee obtainEmployeeByEmployeeObjectId(String objectId) { * * @return 卡号的集合 */ - public long[] getCardArray(CardType card) { + public String[] getCardArray(CardType card) { return dbSettingPresenter.getCardArray(card); } @@ -195,7 +195,7 @@ public long[] getCardArray(CardType card) { * @param card 卡号类型 * @return 是否保存成功 */ - public boolean saveCardNumber(long[] freecards, CardType card) { + public boolean saveCardNumber(String[] freecards, CardType card) { return dbSettingPresenter.saveCardArray(freecards, card); } @@ -205,7 +205,7 @@ public boolean saveCardNumber(long[] freecards, CardType card) { * @param cardNumber 待检索的卡号 * @return 是否匹配确认卡号 */ - public boolean marchConfirmCard(long cardNumber) { + public boolean marchConfirmCard(String cardNumber) { return dbSettingPresenter.marchConfirmCard(cardNumber); } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/KyServerCenterHandler.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/KyServerCenterHandler.java index 0cf2693..9d64c7e 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/KyServerCenterHandler.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/KyServerCenterHandler.java @@ -50,7 +50,7 @@ private boolean sendMsgToTcpSpecial(IMessage messages, boolean urgent, boolean r * @return 万能卡号获取并写入 TCP 成功 */ boolean deployFreeCard(int groupId, int deviceId, int maxGroupId) { - long[] freeCards = kyDbPresenter.getCardArray(CardType.FREE); + String[] freeCards = kyDbPresenter.getCardArray(CardType.FREE); IMessage CardMsg = new WebMsgDeployFreeCardNumber(groupId, deviceId, freeCards); return deployGroupedMessage(CardMsg, maxGroupId, false, true); } @@ -100,7 +100,7 @@ boolean deployDeviceMsg(IMessage message, int maxGroupId, boolean urgent, boolea * * @return 卡号的集合 */ - long[] getCardArray(CardType card) { + String[] getCardArray(CardType card) { return kyDbPresenter.getCardArray(card); } @@ -111,7 +111,7 @@ long[] getCardArray(CardType card) { * @param card 卡号类型 * @return 是否保存成功 */ - boolean saveCardNumber(long[] freeCards, CardType card) { + boolean saveCardNumber(String[] freeCards, CardType card) { return kyDbPresenter.saveCardNumber(freeCards, card); } @@ -122,7 +122,7 @@ boolean saveCardNumber(long[] freeCards, CardType card) { * @param cardNumber 待检索的卡号 * @return 是否匹配确认卡号 */ - boolean marchConfirmCard(long cardNumber) { + boolean marchConfirmCard(String cardNumber) { return kyDbPresenter.marchConfirmCard(cardNumber); } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerTcpMessageHandler.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerTcpMessageHandler.java index 08d5728..2e3bacc 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerTcpMessageHandler.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerTcpMessageHandler.java @@ -187,7 +187,7 @@ private void handleReceivedCard(IMessage message) { //卡号初始化为 0,故排除掉 0 以避免错误 - if (msgInitCard.getCardNumber() == 0) { + if (msgInitCard.getCardNumber().equals("0000000000000000")) { sendMsgToTcpSpecial(new WebMsgInitMarchConfirmCardResponse(msgInitCard.getGroupId(), msgInitCard.getBoxId(), false), true, false); return; } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerWebMessageHandler.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerWebMessageHandler.java index 652d37e..aebf166 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerWebMessageHandler.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/bean/ServerWebMessageHandler.java @@ -71,7 +71,7 @@ public List getDeviceInfo(int groupId, int deviceId) { * @return 是否成功处理 */ public boolean deployDeviceMsg(IMessage message, int maxgroupId, boolean urgent, boolean responsive) { - return kyServerCenterHandler.deployDeviceMsg(message, maxgroupId, urgent, responsive); + return kyServerCenterHandler.deployDeviceMsg(message, maxgroupId, urgent, responsive); } void setKyServerCenterHandler(KyServerCenterHandler kyServerCenterHandler) { @@ -84,7 +84,7 @@ void setKyServerCenterHandler(KyServerCenterHandler kyServerCenterHandler) { * * @return 万能卡号的集合 */ - public long[] obtainFreeCards() { + public String[] obtainFreeCards() { return kyServerCenterHandler.getCardArray(CardType.FREE); } @@ -93,7 +93,7 @@ public long[] obtainFreeCards() { * * @return 确认卡号的集合 */ - public long[] obtainConfirmCards() { + public String[] obtainConfirmCards() { return kyServerCenterHandler.getCardArray(CardType.CONFIRM); } @@ -104,7 +104,7 @@ public long[] obtainConfirmCards() { * @param card 卡号类型 * @return 是否保存成功 */ - public boolean saveCardNumber(long[] freeCards, CardType card) { + public boolean saveCardNumber(String[] freeCards, CardType card) { return kyServerCenterHandler.saveCardNumber(freeCards, card); } @@ -147,10 +147,10 @@ private void deployEmployeeMsg(boolean name, boolean department, boolean cardNum if (device == null) return; - if (cardNumber && device.getCardNumber() != 0) + if (cardNumber && device.getCardNumber() != null) kyServerCenterHandler.sendMsgTrafficControl(new WebMsgDeployEmployeeCardNumber(device.getGroupId(), device.getBoxId(), device.getCardNumber())); else if (cardNumber && autoInit) - kyServerCenterHandler.sendMsgTrafficControl(new WebMsgDeployEmployeeCardNumber(device.getGroupId(), device.getBoxId(), 0)); + kyServerCenterHandler.sendMsgTrafficControl(new WebMsgDeployEmployeeCardNumber(device.getGroupId(), device.getBoxId(), "0")); if (!(name || department)) return; Employee employee = kyDbPresenter.obtainEmployeeByEmployeeObjectId(device.getEmployeeObjectId()); diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/base/BaseMsgCardNum.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/base/BaseMsgCardNum.java index b4d7c16..309a131 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/base/BaseMsgCardNum.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/base/BaseMsgCardNum.java @@ -2,15 +2,15 @@ public class BaseMsgCardNum extends BaseMessage { - private long cardNumber; + private String cardNumber; - protected BaseMsgCardNum(int groupId, int boxId, long cardNumber, int msgType) { + protected BaseMsgCardNum(int groupId, int boxId, String cardNumber, int msgType) { super(groupId, boxId); setMsgId(msgType); this.cardNumber = cardNumber; } - public long getCardNumber() { + public String getCardNumber() { return cardNumber; } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/tcp/TcpMsgInitResponseCardNumber.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/tcp/TcpMsgInitResponseCardNumber.java index 1f3689e..e2b299a 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/tcp/TcpMsgInitResponseCardNumber.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/tcp/TcpMsgInitResponseCardNumber.java @@ -8,7 +8,7 @@ */ public class TcpMsgInitResponseCardNumber extends BaseMsgCardNum { - public TcpMsgInitResponseCardNumber(int groupId, int boxId, long cardNumber) { + public TcpMsgInitResponseCardNumber(int groupId, int boxId, String cardNumber) { super(groupId, boxId, cardNumber, MsgType.INITIALIZE_DEVICE_RESPONSE_CARD); } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployEmployeeCardNumber.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployEmployeeCardNumber.java index 264f651..b0f9737 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployEmployeeCardNumber.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployEmployeeCardNumber.java @@ -8,7 +8,7 @@ */ public class WebMsgDeployEmployeeCardNumber extends BaseMsgCardNum { - public WebMsgDeployEmployeeCardNumber(int groupId, int boxId, long cardNumber) { + public WebMsgDeployEmployeeCardNumber(int groupId, int boxId, String cardNumber) { super(groupId, boxId, cardNumber, MsgType.SERVER_SET_EMPLOYEE_CARD_NUMBER); } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployFreeCardNumber.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployFreeCardNumber.java index ba46ad6..dbbd79c 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployFreeCardNumber.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/server/message/web/WebMsgDeployFreeCardNumber.java @@ -8,7 +8,7 @@ */ public class WebMsgDeployFreeCardNumber extends BaseMessage { - private long[] cardNumbers; + private String[] cardNumbers; /** * 服务器部署万能卡号 @@ -17,7 +17,7 @@ public class WebMsgDeployFreeCardNumber extends BaseMessage { * @param boxId 设备号 * @param numbers 万能卡号集合 */ - public WebMsgDeployFreeCardNumber(int groupId, int boxId, long[] numbers) { + public WebMsgDeployFreeCardNumber(int groupId, int boxId, String[] numbers) { super(groupId, boxId); setMsgId(MsgType.SERVER_SET_FREE_CARD_NUMBER); if (numbers.length <= 16) { @@ -28,7 +28,7 @@ public WebMsgDeployFreeCardNumber(int groupId, int boxId, long[] numbers) { System.arraycopy(numbers, 0, cardNumbers, 0, length); } - public long[] getCardNumbers() { + public String[] getCardNumbers() { return cardNumbers; } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/server/channelhandler/CanFrameChannelInboundHandler.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/server/channelhandler/CanFrameChannelInboundHandler.java index f3867b4..07b93d4 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/server/channelhandler/CanFrameChannelInboundHandler.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/server/channelhandler/CanFrameChannelInboundHandler.java @@ -17,6 +17,7 @@ import cc.bitky.clustermanage.server.message.tcp.TcpMsgResponseOperateBoxUnlock; import cc.bitky.clustermanage.server.message.tcp.TcpMsgResponseRemainChargeTimes; import cc.bitky.clustermanage.server.message.tcp.TcpMsgResponseStatus; +import cc.bitky.clustermanage.tcp.util.TcpMsgBuilder; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -89,7 +90,7 @@ private IMessage handleMessage(int msgId, int boxId, int groupId, ByteBuf msg) { case MsgType.INITIALIZE_DEVICE_RESPONSE_CARD: byte[] cardArray = new byte[8]; msg.readBytes(cardArray); - long cardNum = byteArrayToLong(cardArray); + String cardNum = TcpMsgBuilder.byteArrayToString(cardArray); return new TcpMsgInitResponseCardNumber(groupId, boxId, cardNum); default: @@ -100,11 +101,11 @@ private IMessage handleMessage(int msgId, int boxId, int groupId, ByteBuf msg) { } - private long byteArrayToLong(byte[] bytes) { - long num = 0; - for (int i = 0; i <= 7; i++) { - num += (bytes[i] & 0xffL) << ((7 - i) * 8); - } - return num; - } +// private long byteArrayToLong(byte[] bytes) { +// long num = 0; +// for (int i = 0; i <= 7; i++) { +// num += (bytes[i] & 0xffL) << ((7 - i) * 8); +// } +// return num; +// } } diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/util/TcpMsgBuilder.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/util/TcpMsgBuilder.java index ec68f31..402a030 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/util/TcpMsgBuilder.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/tcp/util/TcpMsgBuilder.java @@ -20,6 +20,43 @@ public class TcpMsgBuilder { Charset charset_GB2312 = Charset.forName("EUC-CN"); + public static String byteArrayToString(byte[] cards) { + StringBuilder builder = new StringBuilder(); + for (byte b : cards) { + String s = Integer.toHexString(b & 0xFF).toUpperCase(); + if (s.length() == 1) { + builder.append('0').append(s); + } else builder.append(s); + } + return builder.toString(); + } + + public static byte[] stringToByteArray(String cards) { + if (cards.length() > 16) cards = cards.substring(0, 16); + if (cards.length() < 16) { + int count = 16 - cards.length(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < count; i++) { + builder.append("0"); + } + builder.append(cards); + cards = builder.toString(); + } + + byte[] bytes = new byte[8]; + cards = cards.toUpperCase(); + char[] hexChars = cards.toCharArray(); + for (int i = 0; i < 8; i++) { + int pos = i * 2; + bytes[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + } + return bytes; + } + + private static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + /** * 构建获取设备状态的 CAN 帧 * @@ -108,12 +145,11 @@ public byte[] buildEmployeeDepartment(WebMsgDeployEmployeeDepartment webMsgDeplo public byte[] buildEmployeeCardNumber(WebMsgDeployEmployeeCardNumber webMsgDeployEmployeeCardNumber) { byte[] bytes = buildMsgOutline(webMsgDeployEmployeeCardNumber); bytes[0] += 8; - byte[] byteCardNum = longToByteArray(webMsgDeployEmployeeCardNumber.getCardNumber()); + byte[] byteCardNum = stringToByteArray(webMsgDeployEmployeeCardNumber.getCardNumber()); addMessageBody(bytes, byteCardNum, 0); return bytes; } - /** * 构建开锁用的 CAN 帧 * @@ -131,14 +167,14 @@ public byte[] buildWebUnlock(WebMsgOperateBoxUnlock webMsgOperateBoxUnlock) { * @return 万能卡号的 CAN 帧 */ public byte[] buildFreeCardNumber(WebMsgDeployFreeCardNumber webMsgDeployFreeCardNumber) { - long[] cards = webMsgDeployFreeCardNumber.getCardNumbers(); + String[] cards = webMsgDeployFreeCardNumber.getCardNumbers(); int count = cards.length < 16 ? cards.length : 16; byte[] bytesSend = new byte[13 * count]; for (int i = 0; i < count; i++) { byte[] bytes = buildMsgOutline(webMsgDeployFreeCardNumber); bytes[2] += i; - addMessageBody(bytes, longToByteArray(cards[i]), 0); + addMessageBody(bytes, stringToByteArray(cards[i]), 0); System.arraycopy(bytes, 0, bytesSend, 13 * i, 13); } return bytesSend; @@ -189,14 +225,12 @@ private byte[] buildMsgOutline(BaseMessage message) { * @param bytes 轮廓CAN帧 * @param bytesBody 数据位 * @param offset 数据位的偏移量,offset位开始操作8个字节 - * @return 已构建完成的CAN帧 */ - private byte[] addMessageBody(byte[] bytes, byte[] bytesBody, int offset) { + private void addMessageBody(byte[] bytes, byte[] bytesBody, int offset) { int max = (bytesBody.length - offset) > 8 ? 8 : (bytesBody.length - offset); for (int i = 0; i < max; i++) { bytes[i + 5] = bytesBody[i + offset]; } - return bytes; } private long byteArrayToLong(byte[] bytes) { diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/InfoRestController.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/InfoRestController.java index b36f1d0..cc6a382 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/InfoRestController.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/InfoRestController.java @@ -50,7 +50,7 @@ public List getDevices(@PathVariable int groupId, @PathVariable int devi * @return 万能卡号的集合 */ @RequestMapping(value = "/freecard", method = RequestMethod.GET) - public long[] obtainFreeCards() { + public String[] obtainFreeCards() { return serverWebMessageHandler.obtainFreeCards(); } @@ -60,7 +60,7 @@ public long[] obtainFreeCards() { * @return 确认卡号的集合 */ @RequestMapping(value = "/confirmcard", method = RequestMethod.GET) - public long[] obtainConfirmCard() { + public String[] obtainConfirmCard() { return serverWebMessageHandler.obtainConfirmCards(); } @@ -71,7 +71,7 @@ public long[] obtainConfirmCard() { * @return @return "保存确认卡号成功"消息 */ @RequestMapping(value = "/confirmcard", method = RequestMethod.POST, consumes = "application/json") - public String saveConfirmCard(@RequestBody long[] confirmCards) { + public String saveConfirmCard(@RequestBody String[] confirmCards) { if (serverWebMessageHandler.saveCardNumber(confirmCards, CardType.CONFIRM)) return "success"; return "error"; diff --git a/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/OperateRestController.java b/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/OperateRestController.java index 7d09798..a8affb0 100644 --- a/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/OperateRestController.java +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/web/OperateRestController.java @@ -97,7 +97,7 @@ public String operateDeviceReset(@PathVariable int groupId, @RequestMapping(value = "/freecard/{groupId}/{deviceId}", method = RequestMethod.POST, consumes = "application/json") public String saveFreeCard(@PathVariable int groupId, @PathVariable int deviceId, - @RequestBody long[] freeCards, + @RequestBody String[] freeCards, @RequestParam(defaultValue = "0") int maxgroupId) { if (serverWebMessageHandler.saveCardNumber(freeCards, CardType.FREE) && serverWebMessageHandler.deployFreeCard(groupId, deviceId, maxgroupId))