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-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..41e1217 --- /dev/null +++ b/clustermanage-client-javafx/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + + cc.bitky.clustermanage + clustermanage-client + 0.8.6-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/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 new file mode 100644 index 0000000..f07ce22 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/MainLauncher.java @@ -0,0 +1,23 @@ +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 { + startApp(primaryStage); + } + + 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(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/NettyClient.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyClient.java new file mode 100644 index 0000000..f53f8d1 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/NettyClient.java @@ -0,0 +1,70 @@ +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 NettyClient { + + private SuccessfulListener launchListener; + private SuccessfulListener finishListener; + private EventLoopGroup group; + + + public void start(String hostName, int port) { + new Thread(() -> { + group = new NioEventLoopGroup(); + Bootstrap bootstrap = new Bootstrap(); + bootstrap.group(group) + .channel(NioSocketChannel.class) + .handler(new KyChannelInitializer()); + if (hostName != null && !hostName.equals("")) + bootstrap.remoteAddress(new InetSocketAddress(hostName, port)); + else + bootstrap.remoteAddress(new InetSocketAddress(port)); + 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..eed641f --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/CanFrameChannelInboundHandler.java @@ -0,0 +1,141 @@ +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 cc.bitky.clustermanage.utils.TcpMsgBuilder; +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); + String freeCardNumber = TcpMsgBuilder.byteArrayToString(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); + String cardNumber = TcpMsgBuilder.byteArrayToString(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); + } +} 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..3f24304 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/KyChannelInitializer.java @@ -0,0 +1,34 @@ +package cc.bitky.clustermanage.netty.handler; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import cc.bitky.clustermanage.view.MainViewActionListener; +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 { + ParsedMessageInBoundHandler parsedMessageInBoundHandler = new ParsedMessageInBoundHandler(); + + @Override + protected void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline(); + pipeline.addLast(new LoggingHandler("kyOutlineLogger", LogLevel.INFO)); + pipeline.addLast(new CanFrameChannelInboundHandler()); + pipeline.addLast(parsedMessageInBoundHandler); + pipeline.addLast(new KyOutBoundHandler()); + MainView.getInstance().setListener(new MainViewActionListener() { + @Override + public void btnChargeChanged(TcpMsgResponseDeviceStatus tcpMsgResponseDeviceStatus) { + pipeline.write(tcpMsgResponseDeviceStatus); + } + + @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/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..8a0780b --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/netty/handler/ParsedMessageInBoundHandler.java @@ -0,0 +1,199 @@ +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.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()); + + + @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); + MainView.getInstance().remoteUpdateDevice(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(sum, 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(sum, 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(sum, 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(sum, 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(sum, 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(sum, 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(sum, 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(sum, 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(sum, 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(sum, device); + break; + + default: + logger.warn("无法解析正确的 Message"); + errorSum++; + break; + } + } + + /** + * 在从 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); + if (device == null) { + device = new Device(msg.getGroupId(), msg.getBoxId()); + Container.deviceHashMap.put(deviceKey, device); + } + return device; + } + + /** + * 清除接收帧的计数 + * + * @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/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..39d892c --- /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 String cardNumber; + + protected BaseMsgCardNum(int groupId, int boxId, String cardNumber, int msgType) { + super(groupId, boxId); + setMsgId(msgType); + this.cardNumber = cardNumber; + } + + public String 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..06db0bc --- /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, 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/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..923896f --- /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, 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/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..1f7466f --- /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 String cardNumber; + + /** + * 服务器部署万能卡号 + * + * @param groupId 组号 + * @param boxId 设备号 + * @param cardNumber 万能卡号集合 + */ + public WebMsgDeployFreeCardSpecial(int groupId, int boxId, String 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 String 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..8ddb9d8 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/utils/TcpMsgBuilder.java @@ -0,0 +1,107 @@ +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 = stringToByteArray(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个字节 + */ + 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]; + } + } + + 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); + } + + + +} 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/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/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/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/MainView.java b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java new file mode 100644 index 0000000..91a6c98 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/MainView.java @@ -0,0 +1,186 @@ +package cc.bitky.clustermanage.view; + +import java.io.IOException; +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.MenuItem; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.FlowPane; + +public class MainView extends BorderPane implements Initializable { + private static MainView mainView; + ObservableList deviceGroups; + 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 MenuItem menuItemConn; + @FXML + private MenuItem menuItemSend; + + private MainView() throws IOException { + FXMLLoader loader = new FXMLLoader(getClass().getResource("rootLayout.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(MainViewActionListener listener) { + this.listener = listener; + } + + @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(); + labelCurrentGroupId.setText(groupId + "组"); + 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((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++) { + deviceGroups.add(new DeviceGroup(i)); + deviceGroupList.setItems(deviceGroups); + } + } + } + + 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()); + Platform.runLater(() -> { + labelRecCount.setText(sum + ""); + Container.deviceViewHashMap.get(device.getDeviceId()).initView(device); + }); + } + } + + public void remoteUpdateDevice(int sum, Device... devices) { + for (Device device : devices) { + 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 new file mode 100644 index 0000000..4e311d9 --- /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; + String 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 String getCardNumber() { + return cardNumber; + } + + public void setCardNumber(String 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/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 new file mode 100644 index 0000000..c946211 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceGroupListCell.java @@ -0,0 +1,24 @@ +package cc.bitky.clustermanage.view.viewbean; + +import java.net.URL; +import java.util.ResourceBundle; + +import cc.bitky.clustermanage.view.bean.DeviceGroup; +import javafx.fxml.Initializable; +import javafx.scene.control.ListCell; + +public class DeviceGroupListCell extends ListCell implements Initializable { + + @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..a6d6956 --- /dev/null +++ b/clustermanage-client-javafx/src/main/java/cc/bitky/clustermanage/view/viewbean/DeviceView.java @@ -0,0 +1,199 @@ +package cc.bitky.clustermanage.view.viewbean; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +import cc.bitky.clustermanage.netty.message.tcp.TcpMsgResponseDeviceStatus; +import cc.bitky.clustermanage.view.DeviceStatusChangeListener; +import cc.bitky.clustermanage.view.bean.Device; +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(); + DeviceStatusChangeListener 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(); + initView(null); + + } + + public void setListener(DeviceStatusChangeListener listener) { + this.listener = listener; + } + + 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) { + 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(new TcpMsgResponseDeviceStatus(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(new TcpMsgResponseDeviceStatus(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..d5c6c3d --- /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/pom.xml b/clustermanage-server/pom.xml index ffc589e..e915c9b 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.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 new file mode 100644 index 0000000..5d346f9 --- /dev/null +++ b/clustermanage-server/src/main/java/cc/bitky/clustermanage/ServerSetting.java @@ -0,0 +1,40 @@ +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; + 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))