diff --git a/iot-energy/.idea/.gitignore b/iot-energy/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/iot-energy/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/iot-energy/.idea/compiler.xml b/iot-energy/.idea/compiler.xml
new file mode 100644
index 0000000..ed15471
--- /dev/null
+++ b/iot-energy/.idea/compiler.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/.idea/encodings.xml b/iot-energy/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/iot-energy/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/.idea/jarRepositories.xml b/iot-energy/.idea/jarRepositories.xml
new file mode 100644
index 0000000..2e1bf07
--- /dev/null
+++ b/iot-energy/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/.idea/misc.xml b/iot-energy/.idea/misc.xml
new file mode 100644
index 0000000..d24ea8e
--- /dev/null
+++ b/iot-energy/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/.idea/uiDesigner.xml b/iot-energy/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/iot-energy/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/.idea/vcs.xml b/iot-energy/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/iot-energy/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-energy/target/classes/application.properties b/iot-energy/target/classes/application.properties
new file mode 100644
index 0000000..61be5d9
--- /dev/null
+++ b/iot-energy/target/classes/application.properties
@@ -0,0 +1,32 @@
+spring.application.name=netty
+server.servlet.encoding.force=true
+server.port=7781
+lombok.var.flagUsage = ALLOW
+# Single file max size
+multipart.maxFileSize=50Mb
+# All files max size
+multipart.maxRequestSize=50Mb
+
+spring.datasource.dynamic.datasource.primary=primary
+spring.datasource.dynamic.datasource.primary.url=jdbc:mysql://10.16.56.3:3308/jcxt?useUnicode=true&characterEncoding=utf-8&useSSL=false
+spring.datasource.dynamic.datasource.primary.username=root
+spring.datasource.dynamic.datasource.primary.password=Unity3du#d112233
+spring.datasource.dynamic.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
+spring.datasource.dynamic.druid.initial-size=10
+spring.datasource.dynamic.druid.max-idle=20
+spring.datasource.dynamic.druid.min-idle=5
+spring.datasource.dynamic.druid.max-active=50
+spring.datasource.dynamic.druid.log-abandoned=true
+spring.datasource.dynamic.druid.remove-abandoned=true
+spring.datasource.dynamic.druid.remove-abandoned-timeout-millis=120
+spring.datasource.dynamic.druid.max-wait=1000
+spring.datasource.dynamic.druid.test-while-idle=true
+spring.datasource.dynamic.druid.validation-query=select 1 from dual
+spring.datasource.dynamic.druid.test-on-borrow=true
+spring.datasource.dynamic.druid.min-evictable-idle-time-millis=100000
+spring.datasource.dynamic.druid.max-evictable-idle-time-millis=100000
+spring.datasource.dynamic.druid.time-between-eviction-runs-millis=100000
+spring.datasource.dynamic.druid.break-after-acquire-failure=true
+spring.datasource.dynamic.druid.connection-error-retry-attempts=5
+spring.datasource.dynamic.druid.fail-fast=true
+spring.datasource.dynamic.druid.time-between-connect-error-millis=10000
\ No newline at end of file
diff --git a/iot-energy/target/classes/org/example/IotApplication.class b/iot-energy/target/classes/org/example/IotApplication.class
new file mode 100644
index 0000000..42fbc3c
Binary files /dev/null and b/iot-energy/target/classes/org/example/IotApplication.class differ
diff --git a/iot-energy/target/classes/org/example/background/condition/EnergyDataCondition.class b/iot-energy/target/classes/org/example/background/condition/EnergyDataCondition.class
new file mode 100644
index 0000000..9108bdc
Binary files /dev/null and b/iot-energy/target/classes/org/example/background/condition/EnergyDataCondition.class differ
diff --git a/iot-energy/target/classes/org/example/background/dao/EnergyDataDao.class b/iot-energy/target/classes/org/example/background/dao/EnergyDataDao.class
new file mode 100644
index 0000000..71a7119
Binary files /dev/null and b/iot-energy/target/classes/org/example/background/dao/EnergyDataDao.class differ
diff --git a/iot-energy/target/classes/org/example/background/entity/EnergyDataEntity.class b/iot-energy/target/classes/org/example/background/entity/EnergyDataEntity.class
new file mode 100644
index 0000000..777e3cc
Binary files /dev/null and b/iot-energy/target/classes/org/example/background/entity/EnergyDataEntity.class differ
diff --git a/iot-energy/target/classes/org/example/background/service/MakeInfoService.class b/iot-energy/target/classes/org/example/background/service/MakeInfoService.class
new file mode 100644
index 0000000..6852e53
Binary files /dev/null and b/iot-energy/target/classes/org/example/background/service/MakeInfoService.class differ
diff --git a/iot-energy/target/classes/org/example/background/utils/FieldUtils.class b/iot-energy/target/classes/org/example/background/utils/FieldUtils.class
new file mode 100644
index 0000000..b7fd7e1
Binary files /dev/null and b/iot-energy/target/classes/org/example/background/utils/FieldUtils.class differ
diff --git a/iot-energy/target/classes/org/example/druid/DBTypeEnum.class b/iot-energy/target/classes/org/example/druid/DBTypeEnum.class
new file mode 100644
index 0000000..bca6c8e
Binary files /dev/null and b/iot-energy/target/classes/org/example/druid/DBTypeEnum.class differ
diff --git a/iot-energy/target/classes/org/example/druid/DbContextHolder.class b/iot-energy/target/classes/org/example/druid/DbContextHolder.class
new file mode 100644
index 0000000..35a22fc
Binary files /dev/null and b/iot-energy/target/classes/org/example/druid/DbContextHolder.class differ
diff --git a/iot-energy/target/classes/org/example/druid/DruidProperties.class b/iot-energy/target/classes/org/example/druid/DruidProperties.class
new file mode 100644
index 0000000..9b84267
Binary files /dev/null and b/iot-energy/target/classes/org/example/druid/DruidProperties.class differ
diff --git a/iot-energy/target/classes/org/example/druid/DynamicDataSource.class b/iot-energy/target/classes/org/example/druid/DynamicDataSource.class
new file mode 100644
index 0000000..695d344
Binary files /dev/null and b/iot-energy/target/classes/org/example/druid/DynamicDataSource.class differ
diff --git a/iot-energy/target/classes/org/example/socket/BootNettySocketChannelInboundHandler.class b/iot-energy/target/classes/org/example/socket/BootNettySocketChannelInboundHandler.class
new file mode 100644
index 0000000..80c2f44
Binary files /dev/null and b/iot-energy/target/classes/org/example/socket/BootNettySocketChannelInboundHandler.class differ
diff --git a/iot-energy/target/classes/org/example/socket/BootNettySocketServer$1.class b/iot-energy/target/classes/org/example/socket/BootNettySocketServer$1.class
new file mode 100644
index 0000000..e63e80f
Binary files /dev/null and b/iot-energy/target/classes/org/example/socket/BootNettySocketServer$1.class differ
diff --git a/iot-energy/target/classes/org/example/socket/BootNettySocketServer.class b/iot-energy/target/classes/org/example/socket/BootNettySocketServer.class
new file mode 100644
index 0000000..d244fb4
Binary files /dev/null and b/iot-energy/target/classes/org/example/socket/BootNettySocketServer.class differ
diff --git a/iot-energy/target/classes/org/example/socket/BootNettySocketServerThread.class b/iot-energy/target/classes/org/example/socket/BootNettySocketServerThread.class
new file mode 100644
index 0000000..8518094
Binary files /dev/null and b/iot-energy/target/classes/org/example/socket/BootNettySocketServerThread.class differ
diff --git a/iot-energy/target/classes/org/example/utils/CommonConfig.class b/iot-energy/target/classes/org/example/utils/CommonConfig.class
new file mode 100644
index 0000000..afb81d8
Binary files /dev/null and b/iot-energy/target/classes/org/example/utils/CommonConfig.class differ
diff --git a/iot-energy/target/classes/org/example/utils/IdService.class b/iot-energy/target/classes/org/example/utils/IdService.class
new file mode 100644
index 0000000..e0470b6
Binary files /dev/null and b/iot-energy/target/classes/org/example/utils/IdService.class differ
diff --git a/iot-energy/target/classes/org/example/utils/MyDecoder.class b/iot-energy/target/classes/org/example/utils/MyDecoder.class
new file mode 100644
index 0000000..a1e9b20
Binary files /dev/null and b/iot-energy/target/classes/org/example/utils/MyDecoder.class differ
diff --git a/iot-energy/target/classes/org/example/utils/MyEncoder.class b/iot-energy/target/classes/org/example/utils/MyEncoder.class
new file mode 100644
index 0000000..ae5bd67
Binary files /dev/null and b/iot-energy/target/classes/org/example/utils/MyEncoder.class differ
diff --git a/iot-energy/target/classes/org/example/utils/SnowflakeIdGenerator.class b/iot-energy/target/classes/org/example/utils/SnowflakeIdGenerator.class
new file mode 100644
index 0000000..011e839
Binary files /dev/null and b/iot-energy/target/classes/org/example/utils/SnowflakeIdGenerator.class differ
diff --git a/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar b/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar
new file mode 100644
index 0000000..474e7af
Binary files /dev/null and b/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar differ
diff --git a/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar.original b/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar.original
new file mode 100644
index 0000000..24e81f1
Binary files /dev/null and b/iot-energy/target/iot-energy-1.0-SNAPSHOT.jar.original differ
diff --git a/iot-energy/target/maven-archiver/pom.properties b/iot-energy/target/maven-archiver/pom.properties
new file mode 100644
index 0000000..707f031
--- /dev/null
+++ b/iot-energy/target/maven-archiver/pom.properties
@@ -0,0 +1,4 @@
+#Created by Apache Maven 3.9.5
+groupId=org.example
+artifactId=iot-energy
+version=1.0-SNAPSHOT
diff --git a/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..1866223
--- /dev/null
+++ b/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -0,0 +1,19 @@
+org\example\background\condition\EnergyDataCondition.class
+org\example\background\utils\FieldUtils.class
+org\example\utils\MyDecoder.class
+org\example\utils\MyEncoder.class
+org\example\utils\CommonConfig.class
+org\example\utils\IdService.class
+org\example\druid\DynamicDataSource.class
+org\example\socket\BootNettySocketChannelInboundHandler.class
+org\example\socket\BootNettySocketServerThread.class
+org\example\druid\DbContextHolder.class
+org\example\socket\BootNettySocketServer$1.class
+org\example\druid\DBTypeEnum.class
+org\example\utils\SnowflakeIdGenerator.class
+org\example\IotApplication.class
+org\example\background\service\MakeInfoService.class
+org\example\socket\BootNettySocketServer.class
+org\example\druid\DruidProperties.class
+org\example\background\entity\EnergyDataEntity.class
+org\example\background\dao\EnergyDataDao.class
diff --git a/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..dfa1cd5
--- /dev/null
+++ b/iot-energy/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1,18 @@
+D:\LGZN-p\iot-energy\src\main\java\org\example\utils\IdService.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\background\service\MakeInfoService.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\IotApplication.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\utils\CommonConfig.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\socket\BootNettySocketChannelInboundHandler.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\utils\SnowflakeIdGenerator.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\utils\MyEncoder.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\background\condition\EnergyDataCondition.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\druid\DbContextHolder.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\druid\DruidProperties.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\socket\BootNettySocketServer.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\utils\MyDecoder.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\socket\BootNettySocketServerThread.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\background\entity\EnergyDataEntity.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\druid\DBTypeEnum.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\druid\DynamicDataSource.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\background\dao\EnergyDataDao.java
+D:\LGZN-p\iot-energy\src\main\java\org\example\background\utils\FieldUtils.java
diff --git a/iot-energy/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/iot-energy/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
new file mode 100644
index 0000000..e69de29
diff --git a/iot-zhengtai/.idea/.gitignore b/iot-zhengtai/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/iot-zhengtai/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/iot-zhengtai/.idea/compiler.xml b/iot-zhengtai/.idea/compiler.xml
new file mode 100644
index 0000000..9906a21
--- /dev/null
+++ b/iot-zhengtai/.idea/compiler.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/.idea/encodings.xml b/iot-zhengtai/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/iot-zhengtai/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/.idea/jarRepositories.xml b/iot-zhengtai/.idea/jarRepositories.xml
new file mode 100644
index 0000000..2e1bf07
--- /dev/null
+++ b/iot-zhengtai/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/.idea/misc.xml b/iot-zhengtai/.idea/misc.xml
new file mode 100644
index 0000000..accd629
--- /dev/null
+++ b/iot-zhengtai/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/.idea/uiDesigner.xml b/iot-zhengtai/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/iot-zhengtai/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/.idea/vcs.xml b/iot-zhengtai/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/iot-zhengtai/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/pom.xml b/iot-zhengtai/pom.xml
new file mode 100644
index 0000000..09ab7bf
--- /dev/null
+++ b/iot-zhengtai/pom.xml
@@ -0,0 +1,113 @@
+
+
+ 4.0.0
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.1.RELEASE
+
+
+
+ org.example
+ iot-zhengtai
+ 1.0-SNAPSHOT
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+ io.netty
+ netty-all
+ 4.1.6.Final
+
+
+ net.sf.json-lib
+ json-lib
+ 2.4
+ jdk15
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.70
+
+
+
+ mysql
+ mysql-connector-java
+ 5.1.49
+
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.4.1
+
+
+ com.baomidou
+ dynamic-datasource-spring-boot-starter
+ 3.4.1
+
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ 1.1.10
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.0
+ provided
+
+
+
+ commons-codec
+ commons-codec
+ 1.4
+
+
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+ 2.16.0
+
+
+
+ com.ghgande
+ j2mod
+ 2.5.3
+
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ 2.1.1.RELEASE
+
+
+
+ repackage
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/iot-zhengtai/src/main/java/org/example/IotApplication.java b/iot-zhengtai/src/main/java/org/example/IotApplication.java
new file mode 100644
index 0000000..13173a9
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/IotApplication.java
@@ -0,0 +1,30 @@
+package org.example;
+
+import org.example.socket.BootNettySocketServerThread;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
+@MapperScan({"org.example.background.dao"})
+@EnableScheduling //允许自动调用
+public class IotApplication implements CommandLineRunner {
+
+ @Autowired
+ private BootNettySocketServerThread socketServerThread;
+
+ public static void main(String[] args) {
+ SpringApplication app = new SpringApplication(IotApplication.class);
+ app.run(args);
+ }
+
+ @Override
+ public void run(String... args) throws Exception {
+ socketServerThread.start();
+ }
+
+}
\ No newline at end of file
diff --git a/iot-zhengtai/src/main/java/org/example/background/condition/ElectricityDataCondition.java b/iot-zhengtai/src/main/java/org/example/background/condition/ElectricityDataCondition.java
new file mode 100644
index 0000000..f498811
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/condition/ElectricityDataCondition.java
@@ -0,0 +1,36 @@
+package org.example.background.condition;
+
+import org.apache.ibatis.jdbc.SQL;
+import org.example.background.entity.ElectricityData;
+import org.example.socket.utils.FieldUtils;
+import org.springframework.cglib.beans.BeanMap;
+
+public class ElectricityDataCondition {
+
+ public String insert(ElectricityData data){
+ SQL sql = new SQL();
+ sql.INSERT_INTO("electricity_data");
+ BeanMap beanMap = BeanMap.create(data);
+ for (Object key : beanMap.keySet()) {
+ Object val = beanMap.get(key);
+ if (val != null) {
+ sql.VALUES(FieldUtils.camelToLines(key + ""), "#{" + key + "}");
+ }
+ }
+ return sql.toString();
+ }
+
+ public String updateByPrimaryKey(ElectricityData data) {
+ SQL sql = new SQL();
+ sql.UPDATE("electricity_data");
+ BeanMap beanMap = BeanMap.create(data);
+ for (Object key : beanMap.keySet()) {
+ Object val = beanMap.get(key);
+ if (val != null) {
+ sql.SET(FieldUtils.camelToLines(key + "") + "=#{" + key + "}");
+ }
+ }
+ sql.WHERE("electricity_id= #{electricityId}");
+ return sql.toString();
+ }
+}
diff --git a/iot-zhengtai/src/main/java/org/example/background/dao/ElectricityDataDao.java b/iot-zhengtai/src/main/java/org/example/background/dao/ElectricityDataDao.java
new file mode 100644
index 0000000..652d0b9
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/dao/ElectricityDataDao.java
@@ -0,0 +1,19 @@
+package org.example.background.dao;
+
+import org.apache.ibatis.annotations.InsertProvider;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.UpdateProvider;
+import org.example.background.condition.ElectricityDataCondition;
+import org.example.background.entity.ElectricityData;
+
+public interface ElectricityDataDao {
+
+ @InsertProvider(type = ElectricityDataCondition.class, method = "insert")
+ Integer insert(ElectricityData data);
+
+ @Select("SELECT * FROM electricity_data WHERE zd_id = #{zdId} AND acquisition_time = #{acquisitionTime} ORDER BY create_time LIMIT 1")
+ ElectricityData select(ElectricityData data);
+
+ @UpdateProvider(type = ElectricityDataCondition.class, method = "updateByPrimaryKey")
+ Integer updateByPrimaryKey(ElectricityData data);
+}
diff --git a/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityData.java b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityData.java
new file mode 100644
index 0000000..4023bfe
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityData.java
@@ -0,0 +1,109 @@
+package org.example.background.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class ElectricityData implements Serializable {
+
+ //id
+ @TableId
+ private String electricityId;
+
+ //终端地址 (设备编号)
+ private String zdId;
+
+ //互感电流倍率
+ private Float taMultiplier;
+
+ //互感电压倍率
+ private Float tvMultiplier;
+
+ //A相电流
+ private Float aPhaseCurrent;
+
+ //B相电流
+ private Float bPhaseCurrent;
+
+ //c相电流
+ private Float cPhaseCurrent;
+
+ //A相电压
+ private Float aPhaseVoltage;
+
+ //B相电压
+ private Float bPhaseVoltage;
+
+ //c相电压
+ private Float cPhaseVoltage;
+
+ //AB相电压
+ private Float abPhaseVoltage;
+
+ //BC相电压
+ private Float bcPhaseVoltage;
+
+ //AC相电压
+ private Float acPhaseVoltage;
+
+ //功率因数
+ private Float powerFactor;
+
+ //总有功功率
+ private Float totalActivePower;
+
+ //总无功功率
+ private Float totalReactivePower;
+
+ //视在功率
+ private Float apparentPower;
+
+ //频率
+ private Float frequency;
+
+ //正向有功电量
+ private Float positiveActiveCharge;
+
+ //反向有功电量
+ private Float reverseActiveCharge;
+
+ //正向有功尖电量
+ private Float positiveActiveTipCharge;
+
+ //正向有功峰电量
+ private Float forwardActivePeakCharge;
+
+ //正向有功平电量
+ private Float positiveActivePowerLevel;
+
+ //正向有功谷电量
+ private Float positiveActiveValleyCharge;
+
+ //反向有功尖电量
+ private Float reverseActiveTipCharge;
+
+ //反向有功峰电量
+ private Float reverseActivePeakCharge;
+
+ //反向有功平电量
+ private Float reverseActivePowerLevel;
+
+ //反向有功谷电量
+ private Float reverseActiveValleyCharge;
+
+ //@ApiModelProperty(value = "入库时间")
+ @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date createTime;
+
+ //@ApiModelProperty(value = "整点采集时间")
+ @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date acquisitionTime;
+
+ //@ApiModelProperty(value = "终端抄表时间")
+ @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date readTime;
+}
diff --git a/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityDayData.java b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityDayData.java
new file mode 100644
index 0000000..2f45bb6
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityDayData.java
@@ -0,0 +1,7 @@
+package org.example.background.entity;
+
+import lombok.Data;
+
+@Data
+public class ElectricityDayData {
+}
diff --git a/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityMonthData.java b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityMonthData.java
new file mode 100644
index 0000000..5f3ecac
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/entity/ElectricityMonthData.java
@@ -0,0 +1,7 @@
+package org.example.background.entity;
+
+import lombok.Data;
+
+@Data
+public class ElectricityMonthData {
+}
diff --git a/iot-zhengtai/src/main/java/org/example/background/service/MakeInfoService.java b/iot-zhengtai/src/main/java/org/example/background/service/MakeInfoService.java
new file mode 100644
index 0000000..43ac85e
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/background/service/MakeInfoService.java
@@ -0,0 +1,217 @@
+package org.example.background.service;
+
+import com.ghgande.j2mod.modbus.util.ModbusUtil;
+import org.example.background.dao.ElectricityDataDao;
+import org.example.background.entity.ElectricityData;
+import org.example.socket.utils.CommonConfig;
+import org.example.socket.utils.IdService;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+@Component
+public class MakeInfoService {
+
+ @Resource
+ private IdService idService;
+
+ @Resource
+ private ElectricityDataDao electricityDataDao;
+
+ @Resource
+ private CommonConfig config;
+
+
+ //F25信息类 电能表
+ public int[] sendElectricMessage(String ip, int fn) {
+ return config.sendElectricInstruct(ip, fn);
+ }
+
+ public String convertPlaintext(byte[] data) {
+ return ModbusUtil.toHex(data);
+ }
+
+ public Integer convertTextToData(String param, String clientIP) {
+ String[] data = param.split(" ");
+ return electric0(data, clientIP);
+ }
+
+ public Integer electric0(String[] data, String clientIp) {
+ Integer typeF = 0;
+ if(data.length > 12) {
+ switch (data[12]) {
+ case "0C":
+ switch (data[16] + data[17]) {
+ case "0103": //f25
+ electric0InStorage0C_25(data, clientIp);
+ typeF = 25;
+ break;
+ case "0110": //f129
+ electric0InStorage0C_129(data, clientIp);
+ typeF = 129;
+ break;
+ case "0410": //f131:
+ electric0InStorage0C_131(data, clientIp);
+ typeF = 131;
+ break;
+ }
+ break;
+ case "09":
+ switch (data[16] + data[17]) {
+ case "0100": //f1 查询终端配置信息
+ electric0InStorage09_01(data, clientIp);
+ typeF = 1;
+ break;
+ }
+ break;
+ }
+ }
+ return typeF;
+ }
+
+ public Integer electric0InStorage09_01(String[] data, String clientIp) {
+ ElectricityData entity = new ElectricityData();
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ String s = hexToAscii(data[18] + data[19] + data[20] + data[21]);
+ String s1 = hexToAscii(data[22] + data[23] + data[24] + data[25] + data[26] + data[27] + data[28] + data[29]);
+ entity.setElectricityId(idService.gen());
+ try {
+ entity.setAcquisitionTime(formatter.parse(formatter.format(new Date())));
+ }catch (ParseException e) {
+ e.printStackTrace();
+ }
+ entity.setCreateTime(new Date());
+ return 1;
+ }
+
+ public Integer electric0InStorage0C_25(String[] data, String clientIp) {
+ ElectricityData entity = new ElectricityData();
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ entity.setElectricityId(idService.gen());
+ entity.setZdId(String.valueOf(Integer.parseInt(data[9]+data[10],16)));
+
+ try {
+ entity.setAcquisitionTime(formatter.parse(formatter.format(new Date())));
+ }catch (ParseException e) {
+ e.printStackTrace();
+ }
+ entity.setCreateTime(new Date());
+ entity.setTotalActivePower(Float.parseFloat(data[25]+data[24] + data[23]) / 10000); //总有功功率
+ entity.setTotalReactivePower(Float.parseFloat(data[37] + data[36] + fixZhi(data[35])) / 10000); //总无功功率
+ entity.setPowerFactor(Float.parseFloat(data[48] + data[47]) / 10); //功率因数
+ entity.setAPhaseVoltage(Float.parseFloat(data[56] + data[55]) / 10); //A相电压
+ entity.setBPhaseVoltage(Float.parseFloat(data[58] + data[57]) / 10); //b相电压
+ entity.setCPhaseVoltage(Float.parseFloat(data[60] + data[59]) / 10); //c相电压
+ entity.setAPhaseCurrent(Float.parseFloat(data[63] + data[62] + data[61]) / 1000); //A相电流
+ entity.setBPhaseCurrent(Float.parseFloat(data[66] + data[65] + data[64]) / 1000); //B相电流
+ entity.setCPhaseCurrent(Float.parseFloat(data[69] + data[68] + data[67]) / 1000); //C相电流
+ entity.setAbPhaseVoltage((float)(entity.getAPhaseVoltage() * Math.sqrt(3))); //AB相电压
+ entity.setBcPhaseVoltage((float)(entity.getBPhaseVoltage() * Math.sqrt(3))); //BC相电压
+ entity.setAcPhaseVoltage((float)(entity.getCPhaseVoltage() * Math.sqrt(3))); //AC相电压
+ entity.setApparentPower(Float.parseFloat(data[75] + data[74] + data[73]) / 10000); //视在功率
+ entity.setFrequency(50f); //频率
+ entity.setTaMultiplier(20.0f);
+ entity.setTvMultiplier(1.0f);
+ Integer insert = electricityDataDao.insert(entity);
+ System.out.println("已入库");
+ return insert;
+ }
+
+ public Integer electric0InStorage0C_129(String [] data, String clientIp) {
+ ElectricityData entity = new ElectricityData();
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ entity.setZdId(String.valueOf(Integer.parseInt(data[9]+data[10],16)));
+ try {
+ entity.setAcquisitionTime(formatter.parse(formatter.format(new Date())));
+ }catch (ParseException e) {
+ e.printStackTrace();
+ }
+ ElectricityData electricityData = electricityDataDao.select(entity);
+ Integer integer = 0;
+ if(StringUtils.isEmpty(electricityData)){
+ System.out.println("上一步数据没有载入,无法执行当前入库操作");
+ }else {
+ DateFormat sdf1 = new SimpleDateFormat("yyMMddHHmm");
+ try {
+ electricityData.setReadTime(sdf1.parse(data[22] + data[21] + data[20] + data[19] + data[18]));
+ }catch (ParseException e){
+ e.printStackTrace();
+ }
+ electricityData.setPositiveActiveCharge(Float.parseFloat(data[28] + data[27] + data[26] + data[25] + data[24]) / 10000); //正向有功总电能示值
+ electricityData.setPositiveActiveTipCharge(Float.parseFloat(data[33] + data[32] + data[31] + data[30] + data[29]) / 10000);//尖
+ electricityData.setForwardActivePeakCharge(Float.parseFloat(data[38] + data[37] + data[36] + data[35] + data[34]) / 10000);//峰
+ electricityData.setPositiveActivePowerLevel(Float.parseFloat(data[43] + data[42] + data[41] + data[40] + data[39]) / 10000); //平
+ electricityData.setPositiveActiveValleyCharge(Float.parseFloat(data[48] + data[47] + data[46] + data[45] + data[44]) / 10000);//谷
+ integer = electricityDataDao.updateByPrimaryKey(electricityData);
+ System.out.println("已经填补剩余数据");
+ }
+ return integer;
+ }
+
+ public Integer electric0InStorage0C_131(String [] data, String clientIp) {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ ElectricityData entity = new ElectricityData();
+ entity.setZdId(String.valueOf(Integer.parseInt(data[9]+data[10],16)));
+ try {
+ entity.setAcquisitionTime(formatter.parse(formatter.format(new Date())));
+ }catch (ParseException e) {
+ e.printStackTrace();
+ }
+ ElectricityData electricityData = electricityDataDao.select(entity);
+ Integer integer = 0;
+ if(StringUtils.isEmpty(electricityData)){
+ System.out.println("上一步数据没有载入,无法执行当前入库操作");
+ }else {
+ electricityData.setReverseActiveCharge(Float.parseFloat(data[28] + data[27] + data[26] + data[25] + data[24]) / 10000);//反向有功总电能示值
+ electricityData.setReverseActiveTipCharge(Float.parseFloat(data[33] + data[32] + data[31] + data[30] + data[29]) / 10000); //尖
+ electricityData.setReverseActivePeakCharge(Float.parseFloat(data[38] + data[37] + data[36] + data[35] + data[34]) / 10000);//峰
+ electricityData.setReverseActivePowerLevel(Float.parseFloat(data[43] + data[42] + data[41] + data[40] + data[39]) / 10000); //平
+ electricityData.setReverseActiveValleyCharge(Float.parseFloat(data[48] + data[47] + data[46] + data[45] + data[44]) / 10000);//谷
+ integer = electricityDataDao.updateByPrimaryKey(electricityData);
+ System.out.println("已经填补剩余数据");
+ }
+ return integer;
+ }
+
+ public int[] detectingHeartbeat(String param, String clientIp) {
+ String[] data = param.split(" ");
+ int[] ints = new int[0];
+ if(data.length > 12) {
+ switch (data[12]) {
+ case "02":
+ switch (data[16] + data[17]) {
+ case "0100":
+ ints = config.sendElectricInstruct2(clientIp, 1);
+ break;
+ }
+ break;
+ }
+ }
+ return ints;
+ }
+
+ //16进制转ASCII编码
+ public static String hexToAscii(String hexString) {
+ StringBuilder asciiString = new StringBuilder();
+ for (int i = 0; i < hexString.length(); i += 2) {
+ String hexPair = hexString.substring(i, i + 2);
+ int charCode = Integer.parseInt(hexPair, 16);
+ asciiString.append((char) charCode);
+ }
+ return asciiString.toString();
+ }
+
+ public static String fixZhi(String data) {
+ int i = Integer.parseInt(data);
+ if(i%80 == 0){
+ return "00";
+ }else {
+ return data;
+ }
+ }
+}
\ No newline at end of file
diff --git a/iot-zhengtai/src/main/java/org/example/druid/DBTypeEnum.java b/iot-zhengtai/src/main/java/org/example/druid/DBTypeEnum.java
new file mode 100644
index 0000000..40cfd4c
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/druid/DBTypeEnum.java
@@ -0,0 +1,25 @@
+package org.example.druid;
+
+public enum DBTypeEnum {
+ /**
+ * 主库
+ */
+ MASTER("master"),
+
+ /**
+ * 从库
+ */
+ SLAVE("slave");
+
+ private final String value;
+
+ DBTypeEnum(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+}
+
diff --git a/iot-zhengtai/src/main/java/org/example/druid/DbContextHolder.java b/iot-zhengtai/src/main/java/org/example/druid/DbContextHolder.java
new file mode 100644
index 0000000..289654b
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/druid/DbContextHolder.java
@@ -0,0 +1,33 @@
+package org.example.druid;
+
+public class DbContextHolder {
+ //使用ThreadLocal,防止线程安全问题
+ private static final ThreadLocal CONTEXT_HOLDER = new ThreadLocal();
+
+ /**
+ * 设置数据源
+ *
+ * @param dbTypeEnum 数据库类型
+ */
+ public static void setDbType(DBTypeEnum dbTypeEnum) {
+ CONTEXT_HOLDER.set(dbTypeEnum.getValue());
+ }
+
+ /**
+ * 取得当前数据源
+ *
+ * @return dbType
+ */
+ public static String getDbType() {
+ return (String) CONTEXT_HOLDER.get();
+ }
+
+ /**
+ * 清除上下文数据
+ */
+ public static void clearDbType() {
+ CONTEXT_HOLDER.remove();
+ }
+
+}
+
diff --git a/iot-zhengtai/src/main/java/org/example/druid/DruidProperties.java b/iot-zhengtai/src/main/java/org/example/druid/DruidProperties.java
new file mode 100644
index 0000000..b73b6b5
--- /dev/null
+++ b/iot-zhengtai/src/main/java/org/example/druid/DruidProperties.java
@@ -0,0 +1,49 @@
+package org.example.druid;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.druid.DruidConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * druid 配置属性
+ */
+@Configuration
+public class DruidProperties
+{
+
+
+ @Bean
+ @ConfigurationProperties("spring.datasource.dynamic.datasource.primary")
+ public DataSource primaryDataSource()
+ {
+ return DruidDataSourceBuilder.create().build();
+ }
+
+// @Bean
+// @ConfigurationProperties(prefix = "spring.datasource.slave")
+// public DataSource slaveDataSource(){
+// return new DruidDataSourceBuilder().build();
+// }
+
+ @Bean
+ @Primary
+ public DataSource multipleDataSource(DataSource masterDataSource){
+ DynamicDataSource multipleDataSource = new DynamicDataSource();
+ Map