From 3b7aa2a1b3efe48aaa050bedeec3e28e45267fc2 Mon Sep 17 00:00:00 2001 From: C5315333 Date: Fri, 24 Jan 2025 12:13:21 +0800 Subject: [PATCH 1/9] bug fix --- .../AccessControlApplicationStart.java | 4 ++++ .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- .../src/main/resources/dataSource.yml | 6 +++--- .../java110/acct/AcctApplicationStart.java | 6 ++++++ .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-acct/src/main/resources/dataSource.yml | 6 +++--- .../barrier/BarrierApplicationStart.java | 10 ++++++++- .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-barrier/src/main/resources/dataSource.yml | 6 +++--- .../src/test/java/com/java110/AppTest.java | 2 -- .../com/java110/car/CarApplicationStart.java | 8 ++++++- .../src/main/resources/application-dev.yml | 21 ++++++++++++++----- .../src/main/resources/application-zihao.yml | 5 +++-- iot-car/src/main/resources/dataSource.yml | 6 +++--- .../charge/ChargeApplicationStart.java | 4 ++++ .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-charge/src/main/resources/dataSource.yml | 6 +++--- .../community/CommunityApplicationStart.java | 2 ++ .../src/main/resources/application-dev.yml | 18 +++++++++++++--- .../src/main/resources/application-zihao.yml | 5 +++-- .../src/main/resources/dataSource.yml | 6 +++--- .../com/java110/dev/DevApplicationStart.java | 7 +++++-- .../src/main/resources/application-dev.yml | 18 +++++++++++++--- .../src/main/resources/application-zihao.yml | 5 +++-- iot-dev/src/main/resources/dataSource.yml | 6 +++--- .../gateway/GatewayApplicationStart.java | 5 +++++ .../src/main/resources/application-dev.yml | 18 +++++++++++++--- .../src/main/resources/application-zihao.yml | 5 +++-- iot-gateway/src/main/resources/dataSource.yml | 6 +++--- .../com/java110/hal/HalApplicationStart.java | 7 +++++++ .../src/main/resources/application-dev.yml | 21 ++++++++++++++----- .../src/main/resources/application-zihao.yml | 5 +++-- iot-hal/src/main/resources/dataSource.yml | 6 +++--- .../src/main/resources/application-dev.yml | 9 ++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-job/src/main/resources/dataSource.yml | 6 +++--- .../java110/lamp/LampApplicationStart.java | 3 ++- .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-lamp/src/main/resources/dataSource.yml | 6 +++--- .../java110/lift/LiftApplicationStart.java | 4 +++- .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-lift/src/main/resources/dataSource.yml | 6 +++--- .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-lock/src/main/resources/dataSource.yml | 6 +++--- .../java110/meter/MeterApplicationStart.java | 2 ++ .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-meter/src/main/resources/dataSource.yml | 6 +++--- .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-monitor/src/main/resources/dataSource.yml | 6 +++--- .../openapi/OpenApiApplicationStart.java | 9 ++++++++ .../src/main/resources/application-dev.yml | 20 ++++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-openapi/src/main/resources/dataSource.yml | 6 +++--- .../src/main/resources/java110.properties | 2 +- .../system/SystemApplicationStart.java | 11 ++++++++++ .../src/main/resources/application-dev.yml | 18 +++++++++++++--- .../src/main/resources/application-zihao.yml | 5 +++-- iot-system/src/main/resources/dataSource.yml | 6 +++--- .../java110/user/UserApplicationStart.java | 7 +++++++ .../src/main/resources/application-dev.yml | 19 +++++++++++++---- .../src/main/resources/application-zihao.yml | 5 +++-- iot-user/src/main/resources/dataSource.yml | 6 +++--- .../com/java110/core/utils/Base64Convert.java | 15 +++++-------- .../INotifyChargeV1InnerServiceSMO.java | 1 + .../intf/gateway/IWebsocketV1InnerSMO.java | 2 ++ .../INotifySmartMeterV1InnerServiceSMO.java | 5 +++-- .../intf/user/IUserV1InnerServiceSMO.java | 6 +++++- .../src/main/resources/application-dev.yml | 6 +++--- 77 files changed, 483 insertions(+), 185 deletions(-) diff --git a/iot-accessControl/src/main/java/com/java110/accessControl/AccessControlApplicationStart.java b/iot-accessControl/src/main/java/com/java110/accessControl/AccessControlApplicationStart.java index 333eb0db..55930d44 100644 --- a/iot-accessControl/src/main/java/com/java110/accessControl/AccessControlApplicationStart.java +++ b/iot-accessControl/src/main/java/com/java110/accessControl/AccessControlApplicationStart.java @@ -45,6 +45,10 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.community", + "com.java110.intf.barrier", + "com.java110.intf.user", + "com.java110.intf.system", + "com.java110.intf.monitor", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.user.cmd"}) diff --git a/iot-accessControl/src/main/resources/application-dev.yml b/iot-accessControl/src/main/resources/application-dev.yml index 062035d5..4ab63fda 100644 --- a/iot-accessControl/src/main/resources/application-dev.yml +++ b/iot-accessControl/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9998 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-accessControl redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-accessControl/src/main/resources/application-zihao.yml b/iot-accessControl/src/main/resources/application-zihao.yml index 5961625c..8e0e8ba1 100644 --- a/iot-accessControl/src/main/resources/application-zihao.yml +++ b/iot-accessControl/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9998 tomcat: diff --git a/iot-accessControl/src/main/resources/dataSource.yml b/iot-accessControl/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-accessControl/src/main/resources/dataSource.yml +++ b/iot-accessControl/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-acct/src/main/java/com/java110/acct/AcctApplicationStart.java b/iot-acct/src/main/java/com/java110/acct/AcctApplicationStart.java index 92878ffc..06914aab 100644 --- a/iot-acct/src/main/java/com/java110/acct/AcctApplicationStart.java +++ b/iot-acct/src/main/java/com/java110/acct/AcctApplicationStart.java @@ -43,6 +43,12 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.user", + "com.java110.intf.car", + "com.java110.intf.community", + "com.java110.intf.charge", + "com.java110.intf.system", + "com.java110.intf.meter", + "com.java110.intf.barrier", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.acct.cmd"}) diff --git a/iot-acct/src/main/resources/application-dev.yml b/iot-acct/src/main/resources/application-dev.yml index c47ebd3a..0fafce2c 100644 --- a/iot-acct/src/main/resources/application-dev.yml +++ b/iot-acct/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9988 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-charge redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-acct/src/main/resources/application-zihao.yml b/iot-acct/src/main/resources/application-zihao.yml index fc4f79a6..d2a58cb0 100644 --- a/iot-acct/src/main/resources/application-zihao.yml +++ b/iot-acct/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9988 tomcat: diff --git a/iot-acct/src/main/resources/dataSource.yml b/iot-acct/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-acct/src/main/resources/dataSource.yml +++ b/iot-acct/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java b/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java index 840a3e70..c49f063d 100644 --- a/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java +++ b/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java @@ -44,9 +44,17 @@ import java.util.concurrent.TimeUnit; @EnableFeignClients(basePackages = { "com.java110.intf.community", "com.java110.intf.gatway", + "com.java110.intf.job", + "com.java110.intf.car", + "com.java110.intf.gateway", + "com.java110.intf.accessControl", + "com.java110.intf.user", + "com.java110.intf.charge", + "com.java110.intf.system", + "com.java110.intf.monitor", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, - basePackages = {"com.java110.user.cmd"}) + basePackages = {"com.java110.barrier.cmd"}) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @EnableDiscoveryClient public class BarrierApplicationStart { diff --git a/iot-barrier/src/main/resources/application-dev.yml b/iot-barrier/src/main/resources/application-dev.yml index df2a3d87..93fe0d22 100644 --- a/iot-barrier/src/main/resources/application-dev.yml +++ b/iot-barrier/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9996 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-barrier redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-barrier/src/main/resources/application-zihao.yml b/iot-barrier/src/main/resources/application-zihao.yml index 575eb8fe..34bd9b5f 100644 --- a/iot-barrier/src/main/resources/application-zihao.yml +++ b/iot-barrier/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9996 tomcat: diff --git a/iot-barrier/src/main/resources/dataSource.yml b/iot-barrier/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-barrier/src/main/resources/dataSource.yml +++ b/iot-barrier/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-barrier/src/test/java/com/java110/AppTest.java b/iot-barrier/src/test/java/com/java110/AppTest.java index 38804846..a1f14eb0 100644 --- a/iot-barrier/src/test/java/com/java110/AppTest.java +++ b/iot-barrier/src/test/java/com/java110/AppTest.java @@ -5,8 +5,6 @@ import com.java110.core.utils.Base64Convert; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import sun.misc.BASE64Decoder; - import java.io.IOException; import org.apache.commons.codec.binary.Base64; diff --git a/iot-car/src/main/java/com/java110/car/CarApplicationStart.java b/iot-car/src/main/java/com/java110/car/CarApplicationStart.java index f7226c62..65fd75ac 100644 --- a/iot-car/src/main/java/com/java110/car/CarApplicationStart.java +++ b/iot-car/src/main/java/com/java110/car/CarApplicationStart.java @@ -43,9 +43,15 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.community", + "com.java110.intf.user", + "com.java110.intf.barrier", + "com.java110.intf.charge", + "com.java110.intf.job", + "com.java110.intf.monitor", + "com.java110.intf.system", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, - basePackages = {"com.java110.user.cmd"}) + basePackages = {"com.java110.car.cmd"}) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @EnableDiscoveryClient public class CarApplicationStart { diff --git a/iot-car/src/main/resources/application-dev.yml b/iot-car/src/main/resources/application-dev.yml index 1f6a0ea1..b70296ef 100644 --- a/iot-car/src/main/resources/application-dev.yml +++ b/iot-car/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9995 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-car redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,7 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 - + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: config: diff --git a/iot-car/src/main/resources/application-zihao.yml b/iot-car/src/main/resources/application-zihao.yml index ebb91702..3c464e95 100644 --- a/iot-car/src/main/resources/application-zihao.yml +++ b/iot-car/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9995 tomcat: diff --git a/iot-car/src/main/resources/dataSource.yml b/iot-car/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-car/src/main/resources/dataSource.yml +++ b/iot-car/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-charge/src/main/java/com/java110/charge/ChargeApplicationStart.java b/iot-charge/src/main/java/com/java110/charge/ChargeApplicationStart.java index c5b49fba..904e206a 100644 --- a/iot-charge/src/main/java/com/java110/charge/ChargeApplicationStart.java +++ b/iot-charge/src/main/java/com/java110/charge/ChargeApplicationStart.java @@ -43,6 +43,10 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.user", + "com.java110.intf.acct", + "com.java110.intf.car", + "com.java110.intf.monitor", + "com.java110.intf.hal", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.charge.cmd"}) diff --git a/iot-charge/src/main/resources/application-dev.yml b/iot-charge/src/main/resources/application-dev.yml index c47ebd3a..0fafce2c 100644 --- a/iot-charge/src/main/resources/application-dev.yml +++ b/iot-charge/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9988 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-charge redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-charge/src/main/resources/application-zihao.yml b/iot-charge/src/main/resources/application-zihao.yml index fc4f79a6..d2a58cb0 100644 --- a/iot-charge/src/main/resources/application-zihao.yml +++ b/iot-charge/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9988 tomcat: diff --git a/iot-charge/src/main/resources/dataSource.yml b/iot-charge/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-charge/src/main/resources/dataSource.yml +++ b/iot-charge/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-community/src/main/java/com/java110/community/CommunityApplicationStart.java b/iot-community/src/main/java/com/java110/community/CommunityApplicationStart.java index 5c69033c..a7a06e5a 100644 --- a/iot-community/src/main/java/com/java110/community/CommunityApplicationStart.java +++ b/iot-community/src/main/java/com/java110/community/CommunityApplicationStart.java @@ -43,6 +43,8 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.user", + "com.java110.intf.accessControl", + "com.java110.intf.system", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.community.cmd"}) diff --git a/iot-community/src/main/resources/application-dev.yml b/iot-community/src/main/resources/application-dev.yml index ef8f56c1..884efb61 100644 --- a/iot-community/src/main/resources/application-dev.yml +++ b/iot-community/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://localhost:8761/eureka/ server: port: 9994 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-community redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-community/src/main/resources/application-zihao.yml b/iot-community/src/main/resources/application-zihao.yml index 0fb1a769..a1bcc59f 100644 --- a/iot-community/src/main/resources/application-zihao.yml +++ b/iot-community/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9994 tomcat: diff --git a/iot-community/src/main/resources/dataSource.yml b/iot-community/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-community/src/main/resources/dataSource.yml +++ b/iot-community/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-dev/src/main/java/com/java110/dev/DevApplicationStart.java b/iot-dev/src/main/java/com/java110/dev/DevApplicationStart.java index 4daa5e77..d7a72097 100644 --- a/iot-dev/src/main/java/com/java110/dev/DevApplicationStart.java +++ b/iot-dev/src/main/java/com/java110/dev/DevApplicationStart.java @@ -41,8 +41,11 @@ import java.nio.charset.Charset; @EnableDiscoveryClient @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.dev.cmd"}) -@EnableFeignClients(basePackages = {"com.java110.intf.user", - "com.java110.intf.community","com.java110.intf.job"}) +@EnableFeignClients(basePackages = { + "com.java110.intf.user", + "com.java110.intf.community", + "com.java110.intf.job" +}) public class DevApplicationStart { private static Logger logger = LoggerFactory.getLogger(DevApplicationStart.class); diff --git a/iot-dev/src/main/resources/application-dev.yml b/iot-dev/src/main/resources/application-dev.yml index 50b5ed9a..1955ebce 100644 --- a/iot-dev/src/main/resources/application-dev.yml +++ b/iot-dev/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://localhost:8761/eureka/ server: port: 9993 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-dev redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-dev/src/main/resources/application-zihao.yml b/iot-dev/src/main/resources/application-zihao.yml index bf384573..ef9c339f 100644 --- a/iot-dev/src/main/resources/application-zihao.yml +++ b/iot-dev/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9993 tomcat: diff --git a/iot-dev/src/main/resources/dataSource.yml b/iot-dev/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-dev/src/main/resources/dataSource.yml +++ b/iot-dev/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-gateway/src/main/java/com/java110/gateway/GatewayApplicationStart.java b/iot-gateway/src/main/java/com/java110/gateway/GatewayApplicationStart.java index fd7c82d3..0ea89d6b 100644 --- a/iot-gateway/src/main/java/com/java110/gateway/GatewayApplicationStart.java +++ b/iot-gateway/src/main/java/com/java110/gateway/GatewayApplicationStart.java @@ -43,6 +43,11 @@ import java.util.concurrent.TimeUnit; "com.java110.intf.user", "com.java110.intf.community", "com.java110.intf.job", + "com.java110.intf.system", + "com.java110.intf.charge", + "com.java110.intf.acct", + "com.java110.intf.meter", + "com.java110.intf.barrier", }) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @EnableDiscoveryClient diff --git a/iot-gateway/src/main/resources/application-dev.yml b/iot-gateway/src/main/resources/application-dev.yml index 64623e84..2d92b903 100644 --- a/iot-gateway/src/main/resources/application-dev.yml +++ b/iot-gateway/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://localhost:8761/eureka/ server: port: 9999 tomcat: @@ -29,9 +30,9 @@ spring: name: iot-gateway redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -39,6 +40,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-gateway/src/main/resources/application-zihao.yml b/iot-gateway/src/main/resources/application-zihao.yml index 30f8847a..5216cca1 100644 --- a/iot-gateway/src/main/resources/application-zihao.yml +++ b/iot-gateway/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9999 tomcat: diff --git a/iot-gateway/src/main/resources/dataSource.yml b/iot-gateway/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-gateway/src/main/resources/dataSource.yml +++ b/iot-gateway/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java b/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java index e6b3d710..7dac47d8 100644 --- a/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java +++ b/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java @@ -44,6 +44,13 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.community", + "com.java110.intf.intf", + "com.java110.intf.accessControl", + "com.java110.intf.lift", + "com.java110.intf.car", + "com.java110.intf.user", + "com.java110.intf.system", + "com.java110.intf.monitor", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.job.cmd"}) diff --git a/iot-hal/src/main/resources/application-dev.yml b/iot-hal/src/main/resources/application-dev.yml index 1cdb5d00..e98c3da3 100644 --- a/iot-hal/src/main/resources/application-dev.yml +++ b/iot-hal/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9987 tomcat: @@ -29,9 +30,9 @@ spring: name: iot-hal redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -50,7 +51,17 @@ spring: username: wuxw keepalive: 20 poolSize: 20 - + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: diff --git a/iot-hal/src/main/resources/application-zihao.yml b/iot-hal/src/main/resources/application-zihao.yml index 30139cfc..dbda350d 100644 --- a/iot-hal/src/main/resources/application-zihao.yml +++ b/iot-hal/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9987 tomcat: diff --git a/iot-hal/src/main/resources/dataSource.yml b/iot-hal/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-hal/src/main/resources/dataSource.yml +++ b/iot-hal/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-job/src/main/resources/application-dev.yml b/iot-job/src/main/resources/application-dev.yml index 5a8cb5c6..3cc0e93d 100644 --- a/iot-job/src/main/resources/application-dev.yml +++ b/iot-job/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9992 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-job redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 diff --git a/iot-job/src/main/resources/application-zihao.yml b/iot-job/src/main/resources/application-zihao.yml index 6a245565..bc8fa631 100644 --- a/iot-job/src/main/resources/application-zihao.yml +++ b/iot-job/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9992 tomcat: diff --git a/iot-job/src/main/resources/dataSource.yml b/iot-job/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-job/src/main/resources/dataSource.yml +++ b/iot-job/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-lamp/src/main/java/com/java110/lamp/LampApplicationStart.java b/iot-lamp/src/main/java/com/java110/lamp/LampApplicationStart.java index 5ed6b809..6240c6c7 100644 --- a/iot-lamp/src/main/java/com/java110/lamp/LampApplicationStart.java +++ b/iot-lamp/src/main/java/com/java110/lamp/LampApplicationStart.java @@ -34,7 +34,8 @@ import java.util.concurrent.TimeUnit; "com.java110.doc", }) @EnableFeignClients(basePackages = { - "com.java110.intf.lamp", +// "com.java110.intf.lamp", + "com.java110.intf.user", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.lamp.cmd"}) diff --git a/iot-lamp/src/main/resources/application-dev.yml b/iot-lamp/src/main/resources/application-dev.yml index 81dc1ea0..818062e4 100644 --- a/iot-lamp/src/main/resources/application-dev.yml +++ b/iot-lamp/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9985 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-lamp redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-lamp/src/main/resources/application-zihao.yml b/iot-lamp/src/main/resources/application-zihao.yml index 3d0cfc31..bd659c74 100644 --- a/iot-lamp/src/main/resources/application-zihao.yml +++ b/iot-lamp/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9985 tomcat: diff --git a/iot-lamp/src/main/resources/dataSource.yml b/iot-lamp/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-lamp/src/main/resources/dataSource.yml +++ b/iot-lamp/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-lift/src/main/java/com/java110/lift/LiftApplicationStart.java b/iot-lift/src/main/java/com/java110/lift/LiftApplicationStart.java index 76e0d843..01f0ce50 100644 --- a/iot-lift/src/main/java/com/java110/lift/LiftApplicationStart.java +++ b/iot-lift/src/main/java/com/java110/lift/LiftApplicationStart.java @@ -42,7 +42,9 @@ import java.util.concurrent.TimeUnit; "com.java110.doc", }) @EnableFeignClients(basePackages = { - "com.java110.intf.lift", + "com.java110.intf.monitor", + "com.java110.intf.accessControl", + "com.java110.intf.system", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.lift.cmd"}) diff --git a/iot-lift/src/main/resources/application-dev.yml b/iot-lift/src/main/resources/application-dev.yml index 4f4b5c61..05e17d8f 100644 --- a/iot-lift/src/main/resources/application-dev.yml +++ b/iot-lift/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9986 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-lift redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-lift/src/main/resources/application-zihao.yml b/iot-lift/src/main/resources/application-zihao.yml index 249d6083..fec66487 100644 --- a/iot-lift/src/main/resources/application-zihao.yml +++ b/iot-lift/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9986 tomcat: diff --git a/iot-lift/src/main/resources/dataSource.yml b/iot-lift/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-lift/src/main/resources/dataSource.yml +++ b/iot-lift/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-lock/src/main/resources/application-dev.yml b/iot-lock/src/main/resources/application-dev.yml index 335bd0c0..fbcf6850 100644 --- a/iot-lock/src/main/resources/application-dev.yml +++ b/iot-lock/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9984 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-lock redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-lock/src/main/resources/application-zihao.yml b/iot-lock/src/main/resources/application-zihao.yml index b8185ddf..f032f162 100644 --- a/iot-lock/src/main/resources/application-zihao.yml +++ b/iot-lock/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9984 tomcat: diff --git a/iot-lock/src/main/resources/dataSource.yml b/iot-lock/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-lock/src/main/resources/dataSource.yml +++ b/iot-lock/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-meter/src/main/java/com/java110/meter/MeterApplicationStart.java b/iot-meter/src/main/java/com/java110/meter/MeterApplicationStart.java index 8163159b..a028f687 100644 --- a/iot-meter/src/main/java/com/java110/meter/MeterApplicationStart.java +++ b/iot-meter/src/main/java/com/java110/meter/MeterApplicationStart.java @@ -43,6 +43,8 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.user", + "com.java110.intf.system", + "com.java110.intf.community", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.meter.cmd"}) diff --git a/iot-meter/src/main/resources/application-dev.yml b/iot-meter/src/main/resources/application-dev.yml index a49c8915..14c8c1c1 100644 --- a/iot-meter/src/main/resources/application-dev.yml +++ b/iot-meter/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9987 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-meter redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-meter/src/main/resources/application-zihao.yml b/iot-meter/src/main/resources/application-zihao.yml index 9bc1424c..04880f59 100644 --- a/iot-meter/src/main/resources/application-zihao.yml +++ b/iot-meter/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9987 tomcat: diff --git a/iot-meter/src/main/resources/dataSource.yml b/iot-meter/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-meter/src/main/resources/dataSource.yml +++ b/iot-meter/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-monitor/src/main/resources/application-dev.yml b/iot-monitor/src/main/resources/application-dev.yml index 036c5451..3c821323 100644 --- a/iot-monitor/src/main/resources/application-dev.yml +++ b/iot-monitor/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9991 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-monitor redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-monitor/src/main/resources/application-zihao.yml b/iot-monitor/src/main/resources/application-zihao.yml index a3987a3b..756d3a95 100644 --- a/iot-monitor/src/main/resources/application-zihao.yml +++ b/iot-monitor/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9991 tomcat: diff --git a/iot-monitor/src/main/resources/dataSource.yml b/iot-monitor/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-monitor/src/main/resources/dataSource.yml +++ b/iot-monitor/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-openapi/src/main/java/com/java110/openapi/OpenApiApplicationStart.java b/iot-openapi/src/main/java/com/java110/openapi/OpenApiApplicationStart.java index cf73eab5..01fa10fd 100644 --- a/iot-openapi/src/main/java/com/java110/openapi/OpenApiApplicationStart.java +++ b/iot-openapi/src/main/java/com/java110/openapi/OpenApiApplicationStart.java @@ -44,6 +44,15 @@ import java.util.concurrent.TimeUnit; @EnableFeignClients(basePackages = { "com.java110.intf.community", "com.java110.intf.user", + "com.java110.intf.car", + "com.java110.intf.barrier", + "com.java110.intf.accessControl", + "com.java110.intf.monitor", + "com.java110.intf.charge", + "com.java110.intf.meter", + "com.java110.intf.system", + "com.java110.intf.lamp", + "com.java110.intf.acct", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.openapi.cmd"}) diff --git a/iot-openapi/src/main/resources/application-dev.yml b/iot-openapi/src/main/resources/application-dev.yml index 22cb704a..c69e76e3 100644 --- a/iot-openapi/src/main/resources/application-dev.yml +++ b/iot-openapi/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9997 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-openapi redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-openapi/src/main/resources/application-zihao.yml b/iot-openapi/src/main/resources/application-zihao.yml index 26018d84..3e670fe8 100644 --- a/iot-openapi/src/main/resources/application-zihao.yml +++ b/iot-openapi/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9997 tomcat: diff --git a/iot-openapi/src/main/resources/dataSource.yml b/iot-openapi/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-openapi/src/main/resources/dataSource.yml +++ b/iot-openapi/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-openapi/src/main/resources/java110.properties b/iot-openapi/src/main/resources/java110.properties index b190fe45..013cafc9 100644 --- a/iot-openapi/src/main/resources/java110.properties +++ b/iot-openapi/src/main/resources/java110.properties @@ -1,4 +1,4 @@ -java110.mappingPath=classpath:mapper/openapi/*.xml,classpath:mapper/service/*.xml +#java110.mappingPath=classpath:mapper/openapi/*.xml,classpath:mapper/service/*.xml java110.testSwitch=ON diff --git a/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java b/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java index 6765c227..f17c8982 100644 --- a/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java +++ b/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java @@ -43,6 +43,17 @@ import java.util.concurrent.TimeUnit; }) @EnableFeignClients(basePackages = { "com.java110.intf.community", + "com.java110.intf.user", + "com.java110.intf.car", + "com.java110.intf.accessControl", + "com.java110.intf.barrier", + "com.java110.intf.charge", + "com.java110.intf.meter", + "com.java110.intf.lift", + "com.java110.intf.monitor", + "com.java110.intf.lock", + "com.java110.intf.dev", + "com.java110.intf.lamp", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.user.cmd"}) diff --git a/iot-system/src/main/resources/application-dev.yml b/iot-system/src/main/resources/application-dev.yml index 1193aaae..b6b75382 100644 --- a/iot-system/src/main/resources/application-dev.yml +++ b/iot-system/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://localhost:8761/eureka/ server: port: 9990 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-system redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: diff --git a/iot-system/src/main/resources/application-zihao.yml b/iot-system/src/main/resources/application-zihao.yml index 0b8963fb..f3ccab1e 100644 --- a/iot-system/src/main/resources/application-zihao.yml +++ b/iot-system/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9990 tomcat: diff --git a/iot-system/src/main/resources/dataSource.yml b/iot-system/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-system/src/main/resources/dataSource.yml +++ b/iot-system/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/iot-user/src/main/java/com/java110/user/UserApplicationStart.java b/iot-user/src/main/java/com/java110/user/UserApplicationStart.java index dc3bef2c..9ca719f5 100644 --- a/iot-user/src/main/java/com/java110/user/UserApplicationStart.java +++ b/iot-user/src/main/java/com/java110/user/UserApplicationStart.java @@ -40,9 +40,16 @@ import java.util.concurrent.TimeUnit; "com.java110.user", "com.java110.core", "com.java110.doc", + "com.java110.intf.accessControl", + "com.java110.accessControl.smo.impl", }) @EnableFeignClients(basePackages = { "com.java110.intf.community", + "com.java110.intf.accessControl", + "com.java110.intf.system", + "com.java110.intf.car", + "com.java110.intf.acct", + "com.java110.intf.charge", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.user.cmd"}) diff --git a/iot-user/src/main/resources/application-dev.yml b/iot-user/src/main/resources/application-dev.yml index a20dafb6..106e1340 100644 --- a/iot-user/src/main/resources/application-dev.yml +++ b/iot-user/src/main/resources/application-dev.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://localhost:8761/eureka/ server: port: 9989 tomcat: @@ -25,9 +26,9 @@ spring: name: iot-user redis: database: 4 - host: 192.168.1.109 + host: 49.232.85.130 port: 6379 - password: hc12345678 + password: aa1T3ETx5rX8# pool: max-active: 300 max-wait: 10000 @@ -35,7 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 - + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 feign: client: config: diff --git a/iot-user/src/main/resources/application-zihao.yml b/iot-user/src/main/resources/application-zihao.yml index ef6231ae..d7e15cea 100644 --- a/iot-user/src/main/resources/application-zihao.yml +++ b/iot-user/src/main/resources/application-zihao.yml @@ -3,11 +3,12 @@ eureka: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30 preferIpAddress: true + ip-address: 127.0.0.1 instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ - #defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9989 tomcat: diff --git a/iot-user/src/main/resources/dataSource.yml b/iot-user/src/main/resources/dataSource.yml index 8226eb28..2e0dcce8 100644 --- a/iot-user/src/main/resources/dataSource.yml +++ b/iot-user/src/main/resources/dataSource.yml @@ -1,9 +1,9 @@ dataSources: ds0: !!com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 diff --git a/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java b/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java index 57ea71b9..e8fc9d4b 100644 --- a/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java +++ b/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java @@ -1,11 +1,8 @@ package com.java110.core.utils; -import org.apache.commons.codec.binary.Base64; -import sun.misc.BASE64Decoder; -import sun.misc.BASE64Encoder; - import java.io.IOException; import java.io.InputStream; +import java.util.Base64; public class Base64Convert { @@ -14,8 +11,7 @@ public class Base64Convert { } public static String decoder(String data){ - Base64 decoder = new Base64(); - return new String(decoder.decode(data)); + return new String(Base64.getDecoder().decode(data)); } /** @@ -32,7 +28,7 @@ public class Base64Convert { byte[] bytes = new byte[in.available()]; // 将文件中的内容读入到数组中 in.read(bytes); - strBase64 = new BASE64Encoder().encode(bytes); //将字节流数组转换为字符串 + strBase64 = Base64.getEncoder().encodeToString(bytes); //将字节流数组转换为字符串 } finally { if (in != null) { in.close(); @@ -55,7 +51,7 @@ public class Base64Convert { public static byte[] base64ToByte(String strBase64) throws IOException { // 解码,然后将字节转换为文件 strBase64 = strBase64.replaceAll("\r|\n", ""); - byte[] bytes = new BASE64Decoder().decodeBuffer(strBase64); //将字符串转换为byte数组 + byte[] bytes = Base64.getDecoder().decode(strBase64.getBytes()); //将字符串转换为byte数组 return bytes; } @@ -68,8 +64,7 @@ public class Base64Convert { */ public static String byteTobase64(byte[] strBase64) { // 解码,然后将字节转换为文件 - - String bytes = new BASE64Encoder().encode(strBase64); //将字符串转换为byte数组 + String bytes = new String(Base64.getDecoder().decode(strBase64)); //将字符串转换为byte数组 return bytes; } diff --git a/java110-interface/src/main/java/com/java110/intf/charge/INotifyChargeV1InnerServiceSMO.java b/java110-interface/src/main/java/com/java110/intf/charge/INotifyChargeV1InnerServiceSMO.java index 5e98e779..e52fc24b 100644 --- a/java110-interface/src/main/java/com/java110/intf/charge/INotifyChargeV1InnerServiceSMO.java +++ b/java110-interface/src/main/java/com/java110/intf/charge/INotifyChargeV1InnerServiceSMO.java @@ -75,5 +75,6 @@ public interface INotifyChargeV1InnerServiceSMO { * 开启充电成功 * @param notifyChargeOrderDto */ + @RequestMapping(value = "/startChargeSuccess", method = RequestMethod.POST) ResultVo startChargeSuccess(@RequestBody NotifyChargeOrderDto notifyChargeOrderDto); } diff --git a/java110-interface/src/main/java/com/java110/intf/gateway/IWebsocketV1InnerSMO.java b/java110-interface/src/main/java/com/java110/intf/gateway/IWebsocketV1InnerSMO.java index 200cadb0..ba01264a 100644 --- a/java110-interface/src/main/java/com/java110/intf/gateway/IWebsocketV1InnerSMO.java +++ b/java110-interface/src/main/java/com/java110/intf/gateway/IWebsocketV1InnerSMO.java @@ -5,10 +5,12 @@ import com.java110.intf.FeignConfiguration; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; @FeignClient(name = "iot-gateway", configuration = {FeignConfiguration.class}) @RequestMapping("/websocketV1") public interface IWebsocketV1InnerSMO { + @RequestMapping(value = "/webSentParkingArea", method = RequestMethod.POST) int webSentParkingArea(@RequestBody JSONObject reqJson); } diff --git a/java110-interface/src/main/java/com/java110/intf/meter/INotifySmartMeterV1InnerServiceSMO.java b/java110-interface/src/main/java/com/java110/intf/meter/INotifySmartMeterV1InnerServiceSMO.java index f964d61e..8a4e1f73 100644 --- a/java110-interface/src/main/java/com/java110/intf/meter/INotifySmartMeterV1InnerServiceSMO.java +++ b/java110-interface/src/main/java/com/java110/intf/meter/INotifySmartMeterV1InnerServiceSMO.java @@ -22,6 +22,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; /** @@ -46,9 +47,9 @@ public interface INotifySmartMeterV1InnerServiceSMO { public ResponseEntity notifySmartMater(@RequestBody NotifyMeterWaterOrderDto notifyMeterWaterOrderDto); @RequestMapping(value = "/switchControlNotify", method = RequestMethod.POST) - ResponseEntity switchControlNotify(@RequestBody String implBean, @RequestBody String postInfo); + ResponseEntity switchControlNotify(@RequestParam String implBean, @RequestParam String postInfo); @RequestMapping(value = "/cleanControlNotify", method = RequestMethod.POST) - ResponseEntity cleanControlNotify(@RequestBody String implBean, @RequestBody String postInfo); + ResponseEntity cleanControlNotify(@RequestParam String implBean, @RequestParam String postInfo); } diff --git a/java110-interface/src/main/java/com/java110/intf/user/IUserV1InnerServiceSMO.java b/java110-interface/src/main/java/com/java110/intf/user/IUserV1InnerServiceSMO.java index 05fbba68..5028ab13 100644 --- a/java110-interface/src/main/java/com/java110/intf/user/IUserV1InnerServiceSMO.java +++ b/java110-interface/src/main/java/com/java110/intf/user/IUserV1InnerServiceSMO.java @@ -111,5 +111,9 @@ public interface IUserV1InnerServiceSMO { @RequestMapping(value = "/queryStaffsNoInOrg", method = RequestMethod.POST) List queryStaffsNoInOrg(@RequestBody UserDto userDto); - List queryCommunityStaffsByCommunityId(Map map); + //add by The @RequestMapping + @RequestMapping(value = "/queryCommunityStaffsByCommunityId", method = RequestMethod.GET) + default List queryCommunityStaffsByCommunityId(Map map) { + return null; + } } diff --git a/springboot/src/main/resources/application-dev.yml b/springboot/src/main/resources/application-dev.yml index a951df2c..5f0705b9 100644 --- a/springboot/src/main/resources/application-dev.yml +++ b/springboot/src/main/resources/application-dev.yml @@ -49,9 +49,9 @@ spring: keepalive: 20 poolSize: 20 datasource: - url: jdbc:mysql://192.168.100.108:3306/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 - username: hc_iot - password: hc_iot12345678 + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver druid: -- Gitee From e553cabc9852a99f43e79c666048f5a9b6e69a39 Mon Sep 17 00:00:00 2001 From: C5315333 Date: Fri, 24 Jan 2025 14:50:37 +0800 Subject: [PATCH 2/9] bug fix --- iot-system/src/main/resources/application-dev.yml | 4 ++-- iot-user/src/main/resources/application-dev.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iot-system/src/main/resources/application-dev.yml b/iot-system/src/main/resources/application-dev.yml index b6b75382..7c2f4f54 100644 --- a/iot-system/src/main/resources/application-dev.yml +++ b/iot-system/src/main/resources/application-dev.yml @@ -7,8 +7,8 @@ eureka: instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ -# defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9990 tomcat: diff --git a/iot-user/src/main/resources/application-dev.yml b/iot-user/src/main/resources/application-dev.yml index 106e1340..bc852a6a 100644 --- a/iot-user/src/main/resources/application-dev.yml +++ b/iot-user/src/main/resources/application-dev.yml @@ -7,8 +7,8 @@ eureka: instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ -# defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9989 tomcat: -- Gitee From a6b422fb084e0c6eb72438af6bd0f906f7b8e90b Mon Sep 17 00:00:00 2001 From: C5315333 Date: Fri, 24 Jan 2025 14:53:21 +0800 Subject: [PATCH 3/9] bug fix --- iot-gateway/src/main/resources/application-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iot-gateway/src/main/resources/application-dev.yml b/iot-gateway/src/main/resources/application-dev.yml index 2d92b903..c1023f1b 100644 --- a/iot-gateway/src/main/resources/application-dev.yml +++ b/iot-gateway/src/main/resources/application-dev.yml @@ -7,8 +7,8 @@ eureka: instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ -# defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9999 tomcat: -- Gitee From 3cd0c5708c2101f93a8fa75a6f1862083dd0806e Mon Sep 17 00:00:00 2001 From: C5315333 Date: Fri, 24 Jan 2025 15:31:16 +0800 Subject: [PATCH 4/9] bug fix --- iot-community/src/main/resources/application-dev.yml | 4 ++-- iot-dev/src/main/resources/application-dev.yml | 4 ++-- .../main/java/com/java110/system/SystemApplicationStart.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iot-community/src/main/resources/application-dev.yml b/iot-community/src/main/resources/application-dev.yml index 884efb61..c263f423 100644 --- a/iot-community/src/main/resources/application-dev.yml +++ b/iot-community/src/main/resources/application-dev.yml @@ -7,8 +7,8 @@ eureka: instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ -# defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9994 tomcat: diff --git a/iot-dev/src/main/resources/application-dev.yml b/iot-dev/src/main/resources/application-dev.yml index 1955ebce..6c45d062 100644 --- a/iot-dev/src/main/resources/application-dev.yml +++ b/iot-dev/src/main/resources/application-dev.yml @@ -7,8 +7,8 @@ eureka: instanceId: ${spring.cloud.client.ip-address}:${server.port} client: serviceUrl: - defaultZone: http://dev.java110.com:8761/eureka/ -# defaultZone: http://localhost:8761/eureka/ +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ server: port: 9993 tomcat: diff --git a/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java b/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java index f17c8982..113105fc 100644 --- a/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java +++ b/iot-system/src/main/java/com/java110/system/SystemApplicationStart.java @@ -56,7 +56,7 @@ import java.util.concurrent.TimeUnit; "com.java110.intf.lamp", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, - basePackages = {"com.java110.user.cmd"}) + basePackages = {"com.java110.system.cmd"}) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @EnableDiscoveryClient public class SystemApplicationStart { -- Gitee From 849f7c7665fb90eca728595a4a12aa9ec0cce4b1 Mon Sep 17 00:00:00 2001 From: C5315333 Date: Wed, 5 Feb 2025 15:03:22 +0800 Subject: [PATCH 5/9] code submit --- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- .../src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-acct/src/main/resources/dataSource.yml | 2 +- iot-barrier/pom.xml | 15 + .../barrier/BarrierApplicationStart.java | 4 +- .../factory/CarMachineProcessFactory.java | 8 +- .../src/main/resources/application-dev.yml | 15 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-barrier/src/main/resources/dataSource.yml | 2 +- iot-broker/pom.xml | 84 +++ .../java/com/java110/MqttBrokerServerApp.java | 34 ++ .../broker/connect/HKLongConnection.java | 104 ++++ .../broker/connect/MultipartReader.java | 116 ++++ .../java110/broker/connect/OkHttpConfig.java | 20 + .../broker/connect/WebSocketService.java | 71 +++ .../broker/controller/HkISApiController.java | 20 + .../com/java110/broker/mqtt/JsonUtil.java | 20 + .../java110/broker/mqtt/MonitorMsgTime.java | 60 ++ .../java110/broker/mqtt/MqttCodecUtil.java | 96 ++++ .../broker/mqtt/MqttMessageIdGenerator.java | 19 + .../com/java110/broker/mqtt/MqttMsgBack.java | 528 ++++++++++++++++++ .../com/java110/broker/mqtt/MqttServer.java | 86 +++ .../mqtt/MqttServerChannelInitializer.java | 29 + .../broker/mqtt/ServerMqttHandler.java | 192 +++++++ .../com/java110/broker/mqtt/TimerData.java | 18 + .../com/java110/broker/utils/XMLUtils.java | 339 +++++++++++ iot-broker/src/main/resources/application.yml | 12 + .../src/test/java/com/java110/AppTest.java | 38 ++ .../car/cmd/ownerCar/SaveOwnerCarCmd.java | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-car/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-charge/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- .../src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-dev/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-gateway/src/main/resources/dataSource.yml | 2 +- iot-h5/iot-user/manifest.json | 4 +- .../com/java110/hal/HalApplicationStart.java | 2 + .../mqtt/heartbeat/CustomMqttMsgThread.java | 38 +- .../subscribe/MqttClientSubscribeFactory.java | 40 +- .../src/main/resources/application-dev.yml | 10 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-hal/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-job/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-lamp/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-lift/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-lock/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 6 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-meter/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-monitor/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-openapi/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-system/src/main/resources/dataSource.yml | 2 +- .../src/main/resources/application-dev.yml | 4 +- .../src/main/resources/dataSource-zihao.yml | 2 +- iot-user/src/main/resources/dataSource.yml | 2 +- .../com/java110/core/utils/Base64Convert.java | 15 +- 82 files changed, 2049 insertions(+), 128 deletions(-) create mode 100644 iot-broker/pom.xml create mode 100644 iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java create mode 100644 iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java create mode 100644 iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java create mode 100644 iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java create mode 100644 iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java create mode 100644 iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/JsonUtil.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttCodecUtil.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttMessageIdGenerator.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttServerChannelInitializer.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/TimerData.java create mode 100644 iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java create mode 100644 iot-broker/src/main/resources/application.yml create mode 100644 iot-broker/src/test/java/com/java110/AppTest.java diff --git a/iot-accessControl/src/main/resources/application-dev.yml b/iot-accessControl/src/main/resources/application-dev.yml index 4ab63fda..0279f0e9 100644 --- a/iot-accessControl/src/main/resources/application-dev.yml +++ b/iot-accessControl/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-accessControl redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-accessControl/src/main/resources/dataSource-zihao.yml b/iot-accessControl/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-accessControl/src/main/resources/dataSource-zihao.yml +++ b/iot-accessControl/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-accessControl/src/main/resources/dataSource.yml b/iot-accessControl/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-accessControl/src/main/resources/dataSource.yml +++ b/iot-accessControl/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-acct/src/main/resources/application-dev.yml b/iot-acct/src/main/resources/application-dev.yml index 0fafce2c..78d32b29 100644 --- a/iot-acct/src/main/resources/application-dev.yml +++ b/iot-acct/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-charge redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-acct/src/main/resources/dataSource-zihao.yml b/iot-acct/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-acct/src/main/resources/dataSource-zihao.yml +++ b/iot-acct/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-acct/src/main/resources/dataSource.yml b/iot-acct/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-acct/src/main/resources/dataSource.yml +++ b/iot-acct/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-barrier/pom.xml b/iot-barrier/pom.xml index 0f7f3922..c26639f1 100644 --- a/iot-barrier/pom.xml +++ b/iot-barrier/pom.xml @@ -24,6 +24,21 @@ 3.8.1 test + + com.java110 + iot-hal + 1.0-SNAPSHOT + + + + + + + + + + + com.java110 java110-core diff --git a/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java b/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java index c49f063d..d6ef7298 100644 --- a/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java +++ b/iot-barrier/src/main/java/com/java110/barrier/BarrierApplicationStart.java @@ -7,6 +7,7 @@ import com.java110.core.cmd.ServiceCmdEventPublishing; import com.java110.core.init.ServiceStartInit; import com.java110.core.trace.Java110FeignClientInterceptor; import com.java110.core.trace.Java110RestTemplateInterceptor; +import com.java110.hal.mqtt.init.MqttConfig; import okhttp3.ConnectionPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,6 +23,7 @@ import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; import org.springframework.http.converter.StringHttpMessageConverter; import javax.annotation.Resource; @@ -40,7 +42,7 @@ import java.util.concurrent.TimeUnit; "com.java110.barrier", "com.java110.core", "com.java110.doc", -}) +},scanBasePackageClasses = {MqttConfig.class}) @EnableFeignClients(basePackages = { "com.java110.intf.community", "com.java110.intf.gatway", diff --git a/iot-barrier/src/main/java/com/java110/barrier/factory/CarMachineProcessFactory.java b/iot-barrier/src/main/java/com/java110/barrier/factory/CarMachineProcessFactory.java index fa2fcf73..fddecf38 100644 --- a/iot-barrier/src/main/java/com/java110/barrier/factory/CarMachineProcessFactory.java +++ b/iot-barrier/src/main/java/com/java110/barrier/factory/CarMachineProcessFactory.java @@ -30,11 +30,11 @@ public class CarMachineProcessFactory { */ ICarMachineProcess carMachineProcessImpl = null; - IHardwareManufacturerV1InnerServiceSMO manufacturerServiceImpl = ApplicationContextFactory.getBean("hardwareManufacturerV1InnerServiceSMOImpl", IHardwareManufacturerV1InnerServiceSMO.class); + IHardwareManufacturerV1InnerServiceSMO manufacturerServiceImpl = ApplicationContextFactory.getBean(IHardwareManufacturerV1InnerServiceSMO.class.getName(), IHardwareManufacturerV1InnerServiceSMO.class); - if (manufacturerServiceImpl == null) { - manufacturerServiceImpl = ApplicationContextFactory.getBean(IHardwareManufacturerV1InnerServiceSMO.class.getName(), IHardwareManufacturerV1InnerServiceSMO.class); - } +// if (manufacturerServiceImpl == null) { +// manufacturerServiceImpl = ApplicationContextFactory.getBean(IHardwareManufacturerV1InnerServiceSMO.class.getName(), IHardwareManufacturerV1InnerServiceSMO.class); +// } HardwareManufacturerDto tmpManufacturerDto = new HardwareManufacturerDto(); tmpManufacturerDto.setHmType(HardwareManufacturerDto.HM_TYPE_BARRIER); diff --git a/iot-barrier/src/main/resources/application-dev.yml b/iot-barrier/src/main/resources/application-dev.yml index 93fe0d22..445a3d84 100644 --- a/iot-barrier/src/main/resources/application-dev.yml +++ b/iot-barrier/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-barrier redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 @@ -36,6 +36,17 @@ spring: min-idle: 0 timeout: 0 maxWaitMillis: 20000 + mqtt: + client: + id: java110-client-id8 + completionTimeout: 10 + default: + topic: topic + url: tcp://127.0.0.1:12001 + username: admin + password: public + keepalive: 20 + poolSize: 20 datasource: url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: mysql.park diff --git a/iot-barrier/src/main/resources/dataSource-zihao.yml b/iot-barrier/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-barrier/src/main/resources/dataSource-zihao.yml +++ b/iot-barrier/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-barrier/src/main/resources/dataSource.yml b/iot-barrier/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-barrier/src/main/resources/dataSource.yml +++ b/iot-barrier/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-broker/pom.xml b/iot-broker/pom.xml new file mode 100644 index 00000000..83bf9c3c --- /dev/null +++ b/iot-broker/pom.xml @@ -0,0 +1,84 @@ + + + MicroCommunityIot + com.java110 + 1.0-SNAPSHOT + + 4.0.0 + + iot-broker + jar + + iot-broker + http://maven.apache.org + + + UTF-8 + + + + + + com.squareup.okhttp3 + okhttp + 4.10.0 + + + + org.springframework.boot + spring-boot-starter + + + cn.hutool + hutool-all + 5.8.11 + + + + com.alibaba + fastjson + 1.2.83 + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + org.springframework.boot + spring-boot-starter-web + + + io.netty + netty-all + 4.1.72.Final + + + org.projectlombok + lombok + + + + + + + + + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java b/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java new file mode 100644 index 00000000..370da3cd --- /dev/null +++ b/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java @@ -0,0 +1,34 @@ +package com.java110; + +import com.java110.broker.mqtt.MqttServer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableAutoConfiguration +@SpringBootApplication +public class MqttBrokerServerApp implements CommandLineRunner +{ + @Autowired + private MqttServer mqttService; + public static void main( String[] args ) + { + SpringApplication.run(MqttBrokerServerApp.class, args); + } + + @Override + public void run(String... args) throws Exception { + Thread t1 = new Thread(new Runnable() { + public void run() { + try { + MqttBrokerServerApp.this.mqttService.start(); + } catch (Throwable $ex) { + throw $ex; + } + } + }); + t1.run(); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java b/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java new file mode 100644 index 00000000..f9849e8c --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java @@ -0,0 +1,104 @@ +package com.java110.broker.connect; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class HKLongConnection { + + private static final String USERNAME = "admin"; + private static final String PASSWORD = "your_password"; // 替换为你的密码 + private static final String REALM = "IP Camera(C2183)"; + private static final String NONCE = "4e5468694e7a42694e7a4d364f4449354d7a6b354d54513d"; + private static final String URI = "/ISAPI/Event/notification/alertStream"; + private static final String CNONCE = "3d183a245b8729121ae4ca3d41b90f18"; + private static final String NC = "00000001"; + private static final String QOP = "auth"; + + public static void main(String[] args) { + OkHttpClient client = new OkHttpClient.Builder() + .build(); + + Request request = new Request.Builder() + .url("http://10.6.165.192" + URI) + .header("Connection", "Keep-Alive") + .header("Authorization", createDigestAuthHeader(USERNAME, PASSWORD, "GET", URI, NONCE, NC, CNONCE, QOP)) + .build(); + + client.newCall(request).enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + e.printStackTrace(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + if (!response.isSuccessful()) { + throw new IOException("Unexpected code " + response); + } + // 获取响应体 + ResponseBody responseBody = response.body(); + if (responseBody != null) { + MediaType contentType = responseBody.contentType(); + if (contentType != null && contentType.type().equals("multipart")) { + MultipartReader multipartReader = new MultipartReader(responseBody.source(), contentType); + multipartReader.readParts(new MultipartReader.PartCallback() { + @Override + public void onPart(MultipartReader.Part part) throws IOException { + Headers headers = part.headers(); + String contentType = headers.get("Content-Type"); + String contentDisposition = headers.get("Content-Disposition"); + System.out.println("Part headers: " + headers); + System.out.println("Content-Type: " + contentType); + System.out.println("contentDisposition: " + contentDisposition); + System.out.println("Part body: " + part.body().readUtf8()); + + if (contentType != null && contentType.startsWith("application/xml")) { + System.out.println("XML Content: " + part.body().readUtf8()); + } else if (contentType != null && contentType.startsWith("image/jpeg")) { + // 处理图片数据 + byte[] imageBytes = part.body().readByteArray(); + System.out.println("Image Length: " + imageBytes.length); + // 你可以在这里保存图片或进一步处理 + } + + } + }); + } else { + System.out.println("Response is not multipart: " + contentType); + } + } + } + }); + } + + private static String createDigestAuthHeader(String username, String password, String method, String uri, String nonce, String nc, String cnonce, String qop) { + String ha1 = md5(username + ":" + REALM + ":" + password); + String ha2 = md5(method + ":" + uri); + String response = md5(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2); + return "Digest username=\"" + username + "\", realm=\"" + REALM + "\", nonce=\"" + nonce + "\", uri=\"" + uri + "\", cnonce=\"" + cnonce + "\", nc=" + nc + ", qop=" + qop + ", response=\"" + response + "\""; + } + + private static String md5(String input) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] messageDigest = md.digest(input.getBytes()); + StringBuilder sb = new StringBuilder(); + for (byte b : messageDigest) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java b/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java new file mode 100644 index 00000000..236a4599 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java @@ -0,0 +1,116 @@ +package com.java110.broker.connect; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.RequestBody; +import okhttp3.internal.Util; +import okio.Buffer; +import okio.BufferedSink; +import okio.BufferedSource; +import okio.Okio; + +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class MultipartReader { + + private static final String BOUNDARY_PATTERN = "boundary=([^\\s;]+)"; + private static final Pattern BOUNDARY_REGEX = Pattern.compile(BOUNDARY_PATTERN); + + private final BufferedSource source; + private final String boundary; + + public MultipartReader(BufferedSource source, MediaType contentType) { + this.source = source; + Matcher matcher = BOUNDARY_REGEX.matcher(contentType.toString()); + if (!matcher.find()) { + throw new IllegalArgumentException("Content-Type does not contain boundary"); + } + this.boundary = matcher.group(1); + } + + public void readParts(PartCallback callback) throws IOException { + Buffer prefix = new Buffer(); + prefix.writeUtf8("--").writeUtf8(boundary).writeUtf8("\r\n"); + + Buffer suffix = new Buffer(); + suffix.writeUtf8("\r\n--").writeUtf8(boundary).writeUtf8("--\r\n"); + + while (true) { + if (!source.request(prefix.size())) { + throw new IOException("Unexpected end of stream"); + } + + if (source.buffer().rangeEquals(0, prefix.readByteString())) { + source.skip(prefix.size()); + if (!source.request(suffix.size())) { + throw new IOException("Unexpected end of stream"); + } + + if (source.buffer().rangeEquals(0, suffix.readByteString())) { + source.skip(suffix.size()); + break; + } + + Part part = readPart(); + callback.onPart(part); + } else { + throw new IOException("Unexpected prefix"); + } + } + } + + private Part readPart() throws IOException { + Headers.Builder headers = new Headers.Builder(); + while (true) { + String line = source.readUtf8LineStrict(); + if (line.length() == 0) { + break; + } + int index = line.indexOf(':'); + if (index == -1) { + throw new IOException("Unexpected header line: " + line); + } + String name = line.substring(0, index).trim(); + String value = line.substring(index + 1).trim(); + headers.add(name, value); + } + + Buffer body = new Buffer(); + while (true) { + String line = source.readUtf8LineStrict(); + if (line.equals("--" + boundary)) { + break; + } else if (line.equals("--" + boundary + "--")) { + break; + } else { + body.writeUtf8(line).writeUtf8("\r\n"); + } + } + + return new Part(headers.build(), body); + } + + public interface PartCallback { + void onPart(Part part) throws IOException; + } + + public static final class Part { + private final Headers headers; + private final Buffer body; + + public Part(Headers headers, Buffer body) { + this.headers = headers; + this.body = body; + } + + public Headers headers() { + return headers; + } + + public BufferedSource body() { + return body; + } + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java b/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java new file mode 100644 index 00000000..29242a7f --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java @@ -0,0 +1,20 @@ +package com.java110.broker.connect; + +import okhttp3.OkHttpClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.TimeUnit; + +//@Configuration +public class OkHttpConfig { + + @Bean + public OkHttpClient okHttpClient() { + return new OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(0, TimeUnit.SECONDS) // 设置为0表示无限超时,适用于长连接 + .writeTimeout(30, TimeUnit.SECONDS) + .build(); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java b/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java new file mode 100644 index 00000000..fad98e8f --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java @@ -0,0 +1,71 @@ +package com.java110.broker.connect; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.WebSocket; +import okhttp3.WebSocketListener; +import okio.ByteString; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +//@Service +public class WebSocketService { + + private final OkHttpClient client; + private WebSocket webSocket; + + @Autowired + public WebSocketService(OkHttpClient client) { + this.client = client; + } + + public void connect(String url) { + Request request = new Request.Builder().url(url).build(); + client.newWebSocket(request, new WebSocketListener() { + @Override + public void onOpen(WebSocket webSocket, Response response) { + System.out.println("WebSocket opened: " + response); + WebSocketService.this.webSocket = webSocket; + // 发送初始消息 + webSocket.send("Hello Server!"); + } + + @Override + public void onMessage(WebSocket webSocket, String text) { + System.out.println("Received TEXT message: " + text); + // 处理接收到的消息 + } + + @Override + public void onMessage(WebSocket webSocket, ByteString bytes) { + System.out.println("Received BINARY message: " + bytes.hex()); + // 处理接收到的二进制消息 + } + + @Override + public void onClosing(WebSocket webSocket, int code, String reason) { + System.out.println("WebSocket closing: " + code + " " + reason); + webSocket.close(1000, null); + WebSocketService.this.webSocket = null; + } + + @Override + public void onFailure(WebSocket webSocket, Throwable t, Response response) { + System.out.println("WebSocket failed: " + t.getMessage()); + t.printStackTrace(); + WebSocketService.this.webSocket = null; + } + }); + } + + public void sendMessage(String message) { + if (webSocket != null && webSocket.queueSize() == 0) { + webSocket.send(message); + } + } + + public WebSocket getWebSocket() { + return webSocket; + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java new file mode 100644 index 00000000..dd455ae0 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java @@ -0,0 +1,20 @@ +package com.java110.broker.controller; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HkISApiController { + + //从程序->设备 + @PostMapping("/hc/barrier/request/{machineId}") + public void test() { + + } + + //从设备->程序 + @PostMapping("/hc/barrier/response") + public void test2() { + + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/JsonUtil.java b/iot-broker/src/main/java/com/java110/broker/mqtt/JsonUtil.java new file mode 100644 index 00000000..9cc700cd --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/JsonUtil.java @@ -0,0 +1,20 @@ +package com.java110.broker.mqtt; + +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; + +public class JsonUtil { + + public static boolean isJsonObject(String content) { + if (StringUtils.isBlank(content)) { + return false; + } else { + try { + JSONObject jsonStr = JSONObject.parseObject(content); + return true; + } catch (Exception var2) { + return false; + } + } + } +} \ No newline at end of file diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java new file mode 100644 index 00000000..755ea0ab --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java @@ -0,0 +1,60 @@ +package com.java110.broker.mqtt; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.codec.mqtt.MqttPublishMessage; +import lombok.extern.slf4j.Slf4j; + +import java.net.InetSocketAddress; +import java.util.concurrent.ScheduledFuture; + +/** + * @author: zhouwenjie + * @description: 判断策略相关消息是否在规定时间段内发送,获取结束状态 + * @create: 2021-01-07 16:09 + **/ +@Slf4j +public class MonitorMsgTime implements Runnable { + + private Integer packetId; + private MqttMessage mqttMessage; + private ChannelHandlerContext ctx; + + public MonitorMsgTime(Integer packetId, MqttMessage mqttMessage, ChannelHandlerContext ctx) { + this.packetId = packetId; + this.mqttMessage = mqttMessage; + this.ctx = ctx; + } + + @Override + public void run() { + //注意,整个执行过程中,代码报错,线程就会终止 + InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); + if (ctx != null && ctx.channel().isActive()) { + log.info("重复发送消息给客户端:" + address.getHostString()); + if (mqttMessage instanceof MqttPublishMessage) { + //推送的原始消息,每次推送,都需要重新拷贝一份 + try { + MqttPublishMessage mqttPublishMessage = (MqttPublishMessage) mqttMessage; + ByteBuf byteBuf = mqttPublishMessage.payload(); + byteBuf.retainedDuplicate(); + ctx.writeAndFlush(mqttPublishMessage); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } else { + //回复的ack类型消息 + ctx.writeAndFlush(mqttMessage); + } + } else { + log.error(address.getHostString() + " 客户端断开,结束重复发送"); + //如果离线了,就不发了 + ScheduledFuture scheduledFuture = TimerData.scheduledFutureMap.remove(packetId); + if (scheduledFuture != null) { + scheduledFuture.cancel(true); + } + } + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttCodecUtil.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttCodecUtil.java new file mode 100644 index 00000000..24767b8d --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttCodecUtil.java @@ -0,0 +1,96 @@ +package com.java110.broker.mqtt; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.DecoderException; +import io.netty.handler.codec.mqtt.MqttFixedHeader; +import io.netty.handler.codec.mqtt.MqttQoS; +import io.netty.handler.codec.mqtt.MqttVersion; +import io.netty.util.Attribute; +import io.netty.util.AttributeKey; + +public class MqttCodecUtil { + + private static final char[] TOPIC_WILDCARDS = new char[]{'#', '+'}; + static final AttributeKey MQTT_VERSION_KEY = AttributeKey.valueOf("NETTY_CODEC_MQTT_VERSION"); + + static MqttVersion getMqttVersion(ChannelHandlerContext ctx) { + Attribute attr = ctx.channel().attr(MQTT_VERSION_KEY); + MqttVersion version = (MqttVersion)attr.get(); + return version == null ? MqttVersion.MQTT_3_1_1 : version; + } + + static void setMqttVersion(ChannelHandlerContext ctx, MqttVersion version) { + Attribute attr = ctx.channel().attr(MQTT_VERSION_KEY); + attr.set(version); + } + + static boolean isValidPublishTopicName(String topicName) { + for(char c : TOPIC_WILDCARDS) { + if (topicName.indexOf(c) >= 0) { + return false; + } + } + + return true; + } + + static boolean isValidMessageId(int messageId) { + return messageId != 0; + } + + static boolean isValidClientId(MqttVersion mqttVersion, int maxClientIdLength, String clientId) { + if (mqttVersion != MqttVersion.MQTT_3_1) { + if (mqttVersion != MqttVersion.MQTT_3_1_1) { + throw new IllegalArgumentException(mqttVersion + " is unknown mqtt version"); + } else { + return clientId != null; + } + } else { + return clientId != null && clientId.length() >= 1 && clientId.length() <= maxClientIdLength; + } + } + + static MqttFixedHeader validateFixedHeader(ChannelHandlerContext ctx, MqttFixedHeader mqttFixedHeader) { + switch (mqttFixedHeader.messageType()) { + case PUBREL: + case SUBSCRIBE: + case UNSUBSCRIBE: + if (mqttFixedHeader.qosLevel() != MqttQoS.AT_LEAST_ONCE) { + throw new DecoderException(mqttFixedHeader.messageType().name() + " message must have QoS 1"); + } + + return mqttFixedHeader; + default: + return mqttFixedHeader; + } + } + + static MqttFixedHeader resetUnusedFields(MqttFixedHeader mqttFixedHeader) { + switch (mqttFixedHeader.messageType()) { + case PUBREL: + case SUBSCRIBE: + case UNSUBSCRIBE: + if (mqttFixedHeader.isRetain()) { + return new MqttFixedHeader(mqttFixedHeader.messageType(), mqttFixedHeader.isDup(), mqttFixedHeader.qosLevel(), false, mqttFixedHeader.remainingLength()); + } + + return mqttFixedHeader; + default: + return mqttFixedHeader; + case CONNECT: + case CONNACK: + case PUBACK: + case PUBREC: + case PUBCOMP: + case SUBACK: + case UNSUBACK: + case PINGREQ: + case PINGRESP: + case DISCONNECT: + return !mqttFixedHeader.isDup() && mqttFixedHeader.qosLevel() == MqttQoS.AT_MOST_ONCE && !mqttFixedHeader.isRetain() ? mqttFixedHeader : new MqttFixedHeader(mqttFixedHeader.messageType(), false, MqttQoS.AT_MOST_ONCE, false, mqttFixedHeader.remainingLength()); + } + } + + private MqttCodecUtil() { + } +} \ No newline at end of file diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMessageIdGenerator.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMessageIdGenerator.java new file mode 100644 index 00000000..d94ad34e --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMessageIdGenerator.java @@ -0,0 +1,19 @@ +package com.java110.broker.mqtt; + +import org.springframework.stereotype.Component; + +import java.util.concurrent.atomic.AtomicInteger; +@Component +public class MqttMessageIdGenerator { + private static final int MAX_MESSAGE_ID = 65535; + private AtomicInteger messageIdCounter = new AtomicInteger(1); + + public synchronized int nextMessageId() { + int messageId = messageIdCounter.getAndIncrement(); + if (messageId > MAX_MESSAGE_ID) { + messageIdCounter.set(1); + messageId = messageIdCounter.getAndIncrement(); + } + return messageId; + } +} \ No newline at end of file diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java new file mode 100644 index 00000000..2dc6bc42 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java @@ -0,0 +1,528 @@ +package com.java110.broker.mqtt; + +import cn.hutool.core.collection.CollUtil; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.mqtt.MqttConnAckMessage; +import io.netty.handler.codec.mqtt.MqttConnAckVariableHeader; +import io.netty.handler.codec.mqtt.MqttConnectMessage; +import io.netty.handler.codec.mqtt.MqttConnectReturnCode; +import io.netty.handler.codec.mqtt.MqttConnectVariableHeader; +import io.netty.handler.codec.mqtt.MqttFixedHeader; +import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; +import io.netty.handler.codec.mqtt.MqttMessageType; +import io.netty.handler.codec.mqtt.MqttPubAckMessage; +import io.netty.handler.codec.mqtt.MqttPublishMessage; +import io.netty.handler.codec.mqtt.MqttPublishVariableHeader; +import io.netty.handler.codec.mqtt.MqttQoS; +import io.netty.handler.codec.mqtt.MqttSubAckMessage; +import io.netty.handler.codec.mqtt.MqttSubAckPayload; +import io.netty.handler.codec.mqtt.MqttSubscribeMessage; +import io.netty.handler.codec.mqtt.MqttSubscribePayload; +import io.netty.handler.codec.mqtt.MqttTopicSubscription; +import io.netty.handler.codec.mqtt.MqttUnsubAckMessage; +import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; +import io.netty.util.ReferenceCountUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import static io.netty.handler.codec.mqtt.MqttMessageType.PUBACK; +import static io.netty.handler.codec.mqtt.MqttMessageType.PUBREC; +import static io.netty.handler.codec.mqtt.MqttQoS.AT_LEAST_ONCE; +import static io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE; +import static io.netty.handler.codec.mqtt.MqttQoS.EXACTLY_ONCE; + +/** + * @author: zhouwenjie + * @description: 对接收到的消息进行业务处理 + * @create: 2023-04-07 16:29 + * CONNECT 1 C->S 客户端请求与服务端建立连接 (服务端接收) + * CONNACK 2 S->C 服务端确认连接建立(客户端接收) + * PUBLISH 3 CóS 发布消息 (服务端接收【QoS(服务质量等级) 0级别,最多分发一次】)-->生产者只会发送一次消息,不关心消息是否被代理服务端或消费者收到 + * PUBACK 4 CóS 收到发布消息确认(客户端接收【QoS 1级别,至少分发一次】) -->保证消息发送到服务端(也就是代理服务器broker),如果没收到或一定时间没收到服务端的ack,就会重发消息 + * PUBREC 5 CóS 收到发布消息(客户端接收【QoS 2级别】)| + * PUBREL 6 CóS 释放发布消息(服务端接收【QoS 2级别】)|只分发一次消息,且保证到达 -->这三步保证消息有且仅有一次传递给消费者 + * PUBCOMP 7 CóS 完成发布消息(客户端接收【QoS 2级别】)| + * SUBSCRIBE 8 C->S 订阅请求(服务端接收) + * SUBACK 9 S->C 订阅确认(客户端接收) + * UNSUBSCRIBE 10 C->S 取消订阅(服务端接收) + * UNSUBACK 11 S->C 取消订阅确认(客户端接收) + * PINGREQ 12 C->S 客户端发送PING(连接保活)命令(服务端接收) + * PINGRESP 13 S->C PING命令回复(客户端接收) + * DISCONNECT 14 C->S 断开连接 (服务端接收) + *

+ * 注意:在我们发送消息的时候,一定要确认好等级,回复确认的消息统一设置为qos=0; + * 比如,我们需要发送最高等级的消息就将qos设置为2,当我们接收方收到这个等级的消息的时候判断一下等级,设置好消息类型,然后qos因为是回复消息, + * 所以全部设置成0,而当发送端收到消息之后,比如PUBREC,那么我们还将发送(注意不是回复)PUBREL给接收端,希望对方回复确认一下,所以qos设置为1。 + * 综上可知:发送端没有回复确认消息之说,只有发送消息,接收端没有发送消息之说,只有回复确认消息,搞清楚这个概念,在设置参数的时候就明了。 + **/ + +@Slf4j +@Component +public class MqttMsgBack { + + @Value("${driver.mqtt.user_name}") + private String userName; + + @Value("${driver.mqtt.password}") + private String password; + + @Value("${driver.mqtt.wait_time}") + private long waitTime; + + /** + * 功能描述:连接请求处理 + */ + public static final ConcurrentHashMap connectMap = new ConcurrentHashMap<>(); + + /** + * 功能描述:存放主题和其订阅的客户端集合 + */ + public static final ConcurrentHashMap> subMap = new ConcurrentHashMap>(); + + /** + * 功能描述:存放订阅是的服务质量等级,只有发送小于或等于这个服务质量的消息给订阅者 + */ + public static final ConcurrentHashMap qoSMap = new ConcurrentHashMap(); + + /** + * 功能描述:存放客户端和其所订阅的主题集合,用来在客户端断开的时候删除订阅中的客户端 + */ + public static final ConcurrentHashMap> ctMap = new ConcurrentHashMap>(); + + /** + * 功能描述:存放需要缓存的消息,一边发送给新订阅的客户端 + */ + public static final ConcurrentHashMap cacheRetainedMessages = new ConcurrentHashMap(); + + /** + * 功能描述:缓存需要重复发送的消息,以便在收到ack的时候将消息内存释放掉 + */ + public static final ConcurrentHashMap cacheRepeatMessages = new ConcurrentHashMap(); + + /** + * 确认连接请求 + * + * @param ctx + * @param mqttMessage + */ + public void connectionAck(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttConnectMessage mqttConnectMessage; + try { + mqttConnectMessage = (MqttConnectMessage) mqttMessage; + //获取连接者的ClientId + String clientIdentifier = mqttConnectMessage.payload().clientIdentifier(); + //查询用户名密码是否正确 + String userNameNow = mqttConnectMessage.payload().userName(); + String passwordNow = mqttConnectMessage.payload().password(); + if (userName.equals(userNameNow) && password.equals(passwordNow)) { + MqttFixedHeader mqttFixedHeaderInfo = mqttConnectMessage.fixedHeader(); + MqttConnectVariableHeader mqttConnectVariableHeaderInfo = mqttConnectMessage.variableHeader(); + //构建返回报文, 可变报头 + MqttConnAckVariableHeader mqttConnAckVariableHeaderBack = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_ACCEPTED, mqttConnectVariableHeaderInfo.isCleanSession()); + //构建返回报文, 固定报头 至多一次(至少—次,只有一次) + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.CONNACK, mqttFixedHeaderInfo.isDup(), AT_MOST_ONCE, mqttFixedHeaderInfo.isRetain(), 0x02); + //构建连接回复消息体 + MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeaderBack, mqttConnAckVariableHeaderBack); + ctx.writeAndFlush(connAck); + //设置节点名 + InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); + + if (connectMap.contains(ctx.channel().id().asLongText())) { + ChannelHandlerContext channelHandlerContext = connectMap.get(ctx.channel().id().asLongText()); + channelHandlerContext.close(); + connectMap.remove(ctx.channel().id().asLongText()); + } + connectMap.put(ctx.channel().id().asLongText(), ctx); + + log.info("终端登录成功,ID号:{},IP信息:{},终端号:{}", clientIdentifier, address.getHostString(), address.getPort()); + } else { + //如果用户名密码错误则提示对方 + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, AT_MOST_ONCE, false, 0x02); + MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD, false); + MqttConnAckMessage mqttConnAckMessage = new MqttConnAckMessage(fixedHeader, variableHeader); + ctx.writeAndFlush(mqttConnAckMessage); + ctx.close(); + log.error("连接失败:" + MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD.name()); + } + } catch (ClassCastException e) { + //转换失败,对方发送的协议版本不兼容 + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, AT_MOST_ONCE, false, 0x02); + MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION, false); + MqttConnAckMessage mqttConnAckMessage = new MqttConnAckMessage(fixedHeader, variableHeader); + ctx.writeAndFlush(mqttConnAckMessage); + ctx.close(); + e.printStackTrace(); + log.error("连接失败:" + MqttConnectReturnCode.CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION.name()); + } + } + + /** + * 根据qos发布确认 + * 1:表示发送的消息需要一直持久保存(不受服务器重启影响),不但要发送给当前的订阅者,并且以后新来的订阅了此Topic name的订阅者会马上得到推送。 + * 0:仅仅为当前订阅者推送此消息。 + * 假如服务器收到一个空消息体(zero-length payload)、RETAIN = 1、那么就代表需要将这个缓存消息删除掉,不再继续推送给新订阅者,前提是一定保证空消息体。 + * 两个条件需要对应上才能删除,消息体为空、主题名称对应. + * 注意:对于每个主题,只能保留一条消息。当发布一个带有RETAIN标志的新消息时,它将替换上一条保留的消息,因此在同一主题下只会存在一条保留消息。 + * + * @param ctx + * @param mqttMessage 拷贝的数据需要释放,其他的消息,比如连接消息,不用转发,会在handler中自动释放 + */ + public void publishAck(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttPublishMessage mqttPublishMessage = (MqttPublishMessage) mqttMessage; + MqttFixedHeader mqttFixedHeaderInfo = mqttPublishMessage.fixedHeader(); + MqttQoS qos = mqttFixedHeaderInfo.qosLevel(); + //得到主题 + MqttPublishVariableHeader variableHeader = mqttPublishMessage.variableHeader(); + String topicName = variableHeader.topicName(); + //将消息发送给订阅的客户端 + ByteBuf byteBuf = mqttPublishMessage.payload(); + HashSet set = subMap.get(topicName); + if (set != null) { + for (String channelId : set) { + ChannelHandlerContext context = ServerMqttHandler.clientMap.get(channelId); + if (context != null && context.channel().isActive()) { + MqttQoS cacheQos = qoSMap.get(topicName + "-" + channelId); + if (cacheQos != null && qos.value() <= cacheQos.value()) { + // retainedDuplicate()增加引用计数器,不至于后续操作byteBuf出现错误,引用计数器为0的情况,这里会清除retainedDuplicate的操作有: + // SimpleChannelInboundHandler处理器、编码器 MqttEncoder、和最后确认的时候释放,所以每次操作消息之前,先进行一次retainedDuplicate + byteBuf.retainedDuplicate(); + context.writeAndFlush(mqttPublishMessage); + if (qos == AT_LEAST_ONCE || qos == EXACTLY_ONCE) { + + //只发送服务质量等级小于等于订阅时客户端指定的服务质量等级 + // 创建一个新的缓冲区 + byteBuf.retainedDuplicate(); + //防止内存溢出,最后在消息被ack或者客户端断开掉线的时候,拿到并进行释放 + cacheRepeatMessages.put(channelId, byteBuf); + cachePublishMsg(qos, byteBuf, variableHeader, mqttFixedHeaderInfo, context); + } + } + } else { + if (context != null) { + InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); + log.error(address.getHostString() + "转发订阅消息提醒:客户端连接异常~"); + } + //防止客户端频繁上下线导致id变化,带来不必要的空指针 + ServerMqttHandler.clientMap.remove(channelId); + //删除订阅主题 + Set topicSet = ctMap.get(channelId); + if (CollUtil.isNotEmpty(topicSet)) { + for (String topic : topicSet) { + if (subMap != null) { + HashSet ids = subMap.get(topic); + if (CollUtil.isNotEmpty(ids)) { + ids.remove(channelId); + if (CollUtil.isEmpty(ids)) { + subMap.remove(topic); + } + } + } + if (qoSMap != null) { + qoSMap.remove(topic + "-" + channelId); + } + } + } + ctMap.remove(channelId); + } + } + } + // 缓存消息给后订阅的客户端 + boolean retain = mqttFixedHeaderInfo.isRetain(); + if (retain) { + if (byteBuf.readableBytes() > 0) { + byteBuf.retainedDuplicate(); + cacheRetainedMessages.put(topicName, mqttPublishMessage); + } else { + MqttPublishMessage message = cacheRetainedMessages.get(topicName); + if (message != null) { + cacheRetainedMessages.remove(topicName); + // 这里需要手动删除ByteBuf缓存,因为一直会有一份缓存在内存中备用 + boolean release = ReferenceCountUtil.release(message); + log.info("缓存消息给后订阅的客户端释放成功失败:{}", release); + } + } + } + //返回消息给发送端 + switch (qos) { + //至多一次 + case AT_MOST_ONCE: + break; + //至少一次 + case AT_LEAST_ONCE: + //构建返回报文, 可变报头 + MqttMessageIdVariableHeader mqttMessageIdVariableHeaderBack = MqttMessageIdVariableHeader.from(mqttPublishMessage.variableHeader().packetId()); + //构建返回报文, 固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(PUBACK, mqttFixedHeaderInfo.isDup(), AT_MOST_ONCE, mqttFixedHeaderInfo.isRetain(), 0x02); + //构建PUBACK消息体 + MqttPubAckMessage pubAck = new MqttPubAckMessage(mqttFixedHeaderBack, mqttMessageIdVariableHeaderBack); + ctx.writeAndFlush(pubAck); + break; + //刚好一次 + case EXACTLY_ONCE: + //构建返回报文,固定报头 + MqttFixedHeader mqttFixedHeaderBack2 = new MqttFixedHeader(PUBREC, false, AT_MOST_ONCE, false, 0x02); + //构建返回报文,可变报头 + MqttMessageIdVariableHeader mqttPubReplyMessageVariableHeader = MqttMessageIdVariableHeader.from(mqttPublishMessage.variableHeader().packetId()); + + MqttMessage mqttMessageBack = new MqttMessage(mqttFixedHeaderBack2, mqttPubReplyMessageVariableHeader); + ctx.writeAndFlush(mqttMessageBack); + break; + default: + break; + } + } + + private void cachePublishMsg(MqttQoS qos, ByteBuf byteBuf, MqttPublishVariableHeader variableHeader, MqttFixedHeader mqttFixedHeaderInfo, ChannelHandlerContext context) { + //缓存一份消息,规定时间内没有收到ack,用作重发,重发时将isDup设置为true,代表重复消息 + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, mqttFixedHeaderInfo.remainingLength()); + MqttPublishMessage cachePubMessage = new MqttPublishMessage(fixedHeader, variableHeader, byteBuf); + ScheduledFuture scheduledFuture = TimerData.scheduledThreadPoolExecutor.scheduleAtFixedRate(new MonitorMsgTime(variableHeader.packetId(), cachePubMessage, context), waitTime, waitTime, TimeUnit.MILLISECONDS); + TimerData.scheduledFutureMap.put(variableHeader.packetId(), scheduledFuture); + } + + /** + * 发布完成 qos2 + * + * @param ctx + * @param mqttMessage + */ + public void publishComp(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + //构建返回报文, 固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.PUBCOMP, false, AT_MOST_ONCE, false, 0x02); + //构建返回报文, 可变报头 + MqttMessageIdVariableHeader mqttPubReplyMessageVariableHeader = MqttMessageIdVariableHeader.from(messageIdVariableHeader.messageId()); + MqttMessage mqttMessageBack = new MqttMessage(mqttFixedHeaderBack, mqttPubReplyMessageVariableHeader); + ctx.writeAndFlush(mqttMessageBack); + } + + /** + * 订阅确认 + * 订阅和取消订阅没有qos2级别,默认就是1级别 + * 需要存储订阅主题和客户端、客户端和订阅主题、验证防止重复订阅、发送缓存消息 + * + * @param ctx + * @param mqttMessage + */ + public void subscribeAck(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttSubscribeMessage mqttSubscribeMessage = (MqttSubscribeMessage) mqttMessage; + MqttMessageIdVariableHeader messageIdVariableHeader = mqttSubscribeMessage.variableHeader(); + //构建返回报文, 可变报头 + MqttMessageIdVariableHeader variableHeaderBack = MqttMessageIdVariableHeader.from(messageIdVariableHeader.messageId()); + MqttSubscribePayload subscribePayload = mqttSubscribeMessage.payload(); + List mqttTopicSubscriptions = subscribePayload.topicSubscriptions(); + List grantedQoSLevels = new ArrayList(); + String id = ctx.channel().id().toString(); + //存储客户端订阅的主题集合,断开或者异常连接时,删除订阅ctMap和subMap里的值 + Set topicSet = ctMap.get(id); + if (topicSet == null) { + topicSet = new HashSet(); + } + for (MqttTopicSubscription subscription : mqttTopicSubscriptions) { + String topicName = subscription.topicName(); + + HashSet contexts = subMap.get(topicName); + if (contexts == null) { + contexts = new HashSet(); + } + //先判断主题是否已经订阅过了,防止重复订阅 + boolean isSub = contexts.contains(topicName); + if (!isSub) { + MqttQoS qos = subscription.qualityOfService(); + //存储主题被订阅的客户端集合 + contexts.add(id); + qoSMap.put(topicName + "-" + id, qos); + subMap.put(topicName, contexts); + //存储客户端订阅的主题集合 + topicSet.add(topicName); + } + //存储客户端订阅的主题集合 + int value = subscription.qualityOfService().value(); + grantedQoSLevels.add(value); + } + // 构建返回报文 有效负载 + MqttSubAckPayload payloadBack = new MqttSubAckPayload(grantedQoSLevels); + // 构建返回报文 固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.SUBACK, false, AT_MOST_ONCE, false, 0); + // 构建返回报文 订阅确认 + MqttSubAckMessage subAck = new MqttSubAckMessage(mqttFixedHeaderBack, variableHeaderBack, payloadBack); + ctx.writeAndFlush(subAck); + for (String topic : topicSet) { + MqttQoS cacheQos = qoSMap.get(topic + "-" + id); + //查看订阅的主题是否需要需要发送消息 + MqttPublishMessage mqttMsg = cacheRetainedMessages.get(topic); + if (mqttMsg != null) { + MqttFixedHeader mqttFixedHeaderInfo = mqttMsg.fixedHeader(); + MqttQoS qos = mqttFixedHeaderInfo.qosLevel(); + if (cacheQos != null && qos.value() <= cacheQos.value()) { + if (mqttMsg != null) { + MqttPublishVariableHeader variableHeader = mqttMsg.variableHeader(); + ByteBuf payload = mqttMsg.payload(); + //引用计数器增加 + payload.retainedDuplicate(); + ctx.writeAndFlush(mqttMsg); + // 开启消息重发机制 + if (qos == AT_LEAST_ONCE || qos == EXACTLY_ONCE) { + //引用计数器增加 + payload.retainedDuplicate(); + cacheRepeatMessages.put(id, payload); + cachePublishMsg(qos, payload, variableHeader, mqttFixedHeaderInfo, ctx); + } + } + } + } + } + } + + /** + * 取消订阅确认 + * + * @param ctx + * @param mqttMessage + */ + public void unsubscribeAck(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttUnsubscribeMessage mqttUnsubscribeMessage = (MqttUnsubscribeMessage) mqttMessage; + MqttMessageIdVariableHeader messageIdVariableHeader = mqttUnsubscribeMessage.variableHeader(); + // 构建返回报文 可变报头 + MqttMessageIdVariableHeader variableHeaderBack = MqttMessageIdVariableHeader.from(messageIdVariableHeader.messageId()); + // 构建返回报文 固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, AT_MOST_ONCE, false, 0x02); + // 构建返回报文 取消订阅确认 + MqttUnsubAckMessage unSubAck = new MqttUnsubAckMessage(mqttFixedHeaderBack, variableHeaderBack); + log.info("取消订阅回复:{}", unSubAck); + //删除本地订阅客户端 + String id = ctx.channel().id().toString(); + List topics = mqttUnsubscribeMessage.payload().topics(); + Set topicSet = ctMap.get(id); + for (String topic : topics) { + if (subMap != null) { + HashSet ids = subMap.get(topic); + if (CollUtil.isNotEmpty(ids)) { + ids.remove(id); + if (CollUtil.isEmpty(ids)) { + subMap.remove(topic); + } + } + } + if (qoSMap != null) { + qoSMap.remove(topic + "-" + id); + } + + if (CollUtil.isNotEmpty(topicSet)) { + topicSet.remove(topic); + } + } + ctx.writeAndFlush(unSubAck); + } + + /** + * 心跳响应 + * + * @param ctx + * @param mqttMessage + */ + public void pingResp(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, AT_MOST_ONCE, false, 0); + MqttMessage mqttMessageBack = new MqttMessage(fixedHeader); + log.info("心跳回复:{}", mqttMessageBack.toString()); + ctx.writeAndFlush(mqttMessageBack); + } + + + /** + * ------------------------------------------------------服务端作为发送消息端可能会接收的事件---------------------------------------------------------------- + *

+ * 收到接收方消息确认,qos>1的情况,应该删除消息缓存(缓存消息保存到线程定时中了,循环发送取消,消息缓存也没有了),取消消息重发机制 + * + * @param ctx + * @param mqttMessage + */ + public void receivePubAck(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttFixedHeader fixedHeader = mqttMessage.fixedHeader(); + MqttMessageType messageType = fixedHeader.messageType(); + if (messageType == PUBACK) { + MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = variableHeader.messageId(); + //等级为1的情况,直接删除原始消息,取消消息重发机制 + ScheduledFuture scheduledFuture = TimerData.scheduledFutureMap.remove(messageId); + if (scheduledFuture != null) { + scheduledFuture.cancel(true); + } + //移除消息记录 + ByteBuf byteBuf = cacheRepeatMessages.remove(ctx.channel().id().toString()); + if (byteBuf != null) { + // 释放内存 + byteBuf.release(); + } + } + if (messageType == PUBREC) { + //等级为2的情况,收到PUBREC报文消息,先停止消息重发机制,再响应一个PUBREL报文并且构建消息重发机制 + MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = variableHeader.messageId(); + //构建返回报文,固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.PUBREL, false, AT_LEAST_ONCE, false, 0); + //构建返回报文,可变报头 + MqttMessageIdVariableHeader mqttPubReplyMessageVariableHeader = MqttMessageIdVariableHeader.from(messageId); + MqttMessage mqttMessageBack = new MqttMessage(mqttFixedHeaderBack, mqttPubReplyMessageVariableHeader); + //删除初始消息重发机制 + ScheduledFuture scheduledFuture = TimerData.scheduledFutureMap.remove(messageId); + if (scheduledFuture != null) { + scheduledFuture.cancel(true); + } + //释放消息缓存 + ByteBuf byteBuf = cacheRepeatMessages.remove(ctx.channel().id().toString()); + if (byteBuf != null) { + byteBuf.release(); + } + ctx.writeAndFlush(mqttMessageBack); + //重发机制要放在最下方,否则,一旦出错,会多次出发此机制 + cachePubrelMsg(messageId, ctx); + } + } + + private void cachePubrelMsg(int messageId, ChannelHandlerContext context) { + //缓存一份消息,规定时间内没有收到ack,用作重发,重发时将isDup设置为true,代表重复消息 + //构建返回报文,固定报头 + MqttFixedHeader mqttFixedHeaderBack = new MqttFixedHeader(MqttMessageType.PUBREL, true, AT_LEAST_ONCE, false, 0); + //构建返回报文,可变报头 + MqttMessageIdVariableHeader mqttMessageIdVariableHeaderBack = MqttMessageIdVariableHeader.from(messageId); + MqttMessage mqttMessageBack = new MqttMessage(mqttFixedHeaderBack, mqttMessageIdVariableHeaderBack); + ScheduledFuture scheduledFuture = TimerData.scheduledThreadPoolExecutor.scheduleAtFixedRate(new MonitorMsgTime(messageId, mqttMessageBack, context), waitTime, waitTime, TimeUnit.MILLISECONDS); + TimerData.scheduledFutureMap.put(messageId, scheduledFuture); + } + + /** + * 功能描述: 接收到最后一次确认,取消上次PUBREL的消息重发机制 + * + * @param ctx + * @param mqttMessage + * @return void + * @author zhouwenjie + * @date 2023/6/9 16:00 + */ + public void receivePubcomp(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = variableHeader.messageId(); + ScheduledFuture scheduledFuture = TimerData.scheduledFutureMap.remove(messageId); + if (scheduledFuture != null) { + scheduledFuture.cancel(true); + } + ByteBuf byteBuf = cacheRepeatMessages.remove(ctx.channel().id().toString()); + if (byteBuf != null) { + byteBuf.release(); + } + } +} + diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java new file mode 100644 index 00000000..09e8d63f --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java @@ -0,0 +1,86 @@ +package com.java110.broker.mqtt; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PreDestroy; + +/** + * @author: zhouwenjie + * @description: netty启动配置类 + * @create: 2020-04-03 11:43 + **/ +@Slf4j +@Component +public class MqttServer { + + @Autowired + private MqttServerChannelInitializer mqttServerChannelInitializer; + + private NioEventLoopGroup bossGroup; + + private NioEventLoopGroup workerGroup; + + private ChannelFuture future; + + @Value("${driver.mqtt.socket_port}") + private int socketPort; + + public void start() { + //创建接收请求和处理请求的实例(默认线程数为 CPU 核心数乘以2也可自定义) + bossGroup = new NioEventLoopGroup(3); + workerGroup = new NioEventLoopGroup(6); + try { + //创建服务端启动辅助类(boostrap 用来为 Netty 程序的启动组装配置一些必须要组件,例如上面的创建的两个线程组) + ServerBootstrap socketBs = new ServerBootstrap(); + //channel 方法用于指定服务器端监听套接字通道 + //socket配置 + socketBs.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + //ChannelOption.SO_BACKLOG对应的是tcp/ip协议listen函数中的backlog参数, + // 函数listen(int socketfd,int backlog)用来初始化服务端可连接队列, + // 服务端处理客户端连接请求是顺序处理的,所以同一时间只能处理一个客户端连接, + // 多个客户端来的时候,服务端将不能处理的客户端连接请求放在队列中等待处理,backlog参数指定了队列的大小 + .option(ChannelOption.SO_BACKLOG, 1024) + //快速复用,防止服务端重启端口被占用的情况发生 + .option(ChannelOption.SO_REUSEADDR, true) + .childHandler(mqttServerChannelInitializer) + //如果TCP_NODELAY没有设置为true,那么底层的TCP为了能减少交互次数,会将网络数据积累到一定的数量后, + // 服务器端才发送出去,会造成一定的延迟。在互联网应用中,通常希望服务是低延迟的,建议将TCP_NODELAY设置为true + .childOption(ChannelOption.TCP_NODELAY, true) + //默认的心跳间隔是7200s即2小时。Netty默认关闭该功能。 + .childOption(ChannelOption.SO_KEEPALIVE, true); + future = socketBs.bind(socketPort).sync(); + if (future.isSuccess()) { + log.info("[*MQTT驱动服务端启动成功]"); + future.channel().closeFuture().sync(); + } else { + log.info("[~~~MQTT驱动服务端启动失败~~~]"); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + } + + /** + * 这里可以手动关闭,同时在整个springboot应用停止的时候,这里也得以调用【@PreDestroy】 + * 参考 https://www.cnblogs.com/CreatorKou/p/11606870.html + */ + @PreDestroy + public void shutdown() { + // 优雅关闭两个 EventLoopGroup 对象 + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + log.info("[*MQTT服务端关闭成功]"); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServerChannelInitializer.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServerChannelInitializer.java new file mode 100644 index 00000000..4a41de95 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServerChannelInitializer.java @@ -0,0 +1,29 @@ +package com.java110.broker.mqtt; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.mqtt.MqttDecoder; +import io.netty.handler.codec.mqtt.MqttEncoder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author: zhouwenjie + * @description: 配置管道 服务端初始化,客户端与服务器端连接一旦创建,这个类中方法就会被回调,设置出站编码器和入站解码器 + * @create: 2020-04-03 14:14 + **/ +@Component +public class MqttServerChannelInitializer extends ChannelInitializer { + + @Autowired + private ServerMqttHandler serverMqttHandler; + + @Override + protected void initChannel(SocketChannel ch) { + ChannelPipeline pipeline = ch.pipeline(); + pipeline.addLast("decoder", new MqttDecoder(1024 * 8)); + pipeline.addLast("encoder", MqttEncoder.INSTANCE); + pipeline.addLast(serverMqttHandler); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java b/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java new file mode 100644 index 00000000..037c6cf5 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java @@ -0,0 +1,192 @@ +package com.java110.broker.mqtt; + +import cn.hutool.core.collection.CollUtil; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.mqtt.MqttFixedHeader; +import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.codec.mqtt.MqttQoS; +import io.netty.handler.timeout.IdleState; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.net.InetSocketAddress; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +@Slf4j +@Component +@ChannelHandler.Sharable +public class ServerMqttHandler extends SimpleChannelInboundHandler { + + public static final ConcurrentHashMap clientMap = new ConcurrentHashMap(); + + @Value("${driver.mqtt.address_list}") + private List addressList; + + @Autowired + private MqttMsgBack mqttMsgBack; + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); + //判断连接是否合法 + if (addressList.contains(address.getHostString())) { + clientMap.put(ctx.channel().id().toString(), ctx); + super.handlerAdded(ctx); + } else { + ctx.close(); + } + } + + /** + * 功能描述: 客户端终止连接服务器会触发此函数 + * + * @param ctx + * @return void + * @author zhouwenjie + * @date 2020/4/3 16:47 + */ + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + delSubCache(ctx); + super.channelInactive(ctx); + } + + + /** + * 功能描述: 有客户端发消息会触发此函数 + * + * @param ctx + * @param mqttMessage + * @return void + * @author zhouwenjie + * @date 2020/4/3 16:48 + */ + @Override + public void channelRead0(ChannelHandlerContext ctx, MqttMessage mqttMessage) { + if (null != mqttMessage) { + log.info("接收mqtt消息:" + mqttMessage); + MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); + + switch (mqttFixedHeader.messageType()) { + // ----------------------接收消息端(服务端)可能会触发的事件---------------------------------------------------------------- + case CONNECT: + // 在一个网络连接上,客户端只能发送一次CONNECT报文。服务端必须将客户端发送的第二个CONNECT报文当作协议违规处理并断开客户端的连接 + // 建议connect消息单独处理,用来对客户端进行认证管理等 这里直接返回一个CONNACK消息 + mqttMsgBack.connectionAck(ctx, mqttMessage); + break; + case PUBLISH: + // 收到消息,返回确认,PUBACK报文是对QoS 1等级的PUBLISH报文的响应,PUBREC报文是对PUBLISH报文的响应 + mqttMsgBack.publishAck(ctx, mqttMessage); + break; + case PUBREL: + // 释放消息,PUBREL报文是对QoS 2等级的PUBREC报文的响应,此时我们应该回应一个PUBCOMP报文 + mqttMsgBack.publishComp(ctx, mqttMessage); + break; + case SUBSCRIBE: + // 客户端订阅主题 + // 客户端向服务端发送SUBSCRIBE报文用于创建一个或多个订阅,每个订阅注册客户端关心的一个或多个主题。 + // 为了将应用消息转发给与那些订阅匹配的主题,服务端发送PUBLISH报文给客户端。 + // SUBSCRIBE报文也(为每个订阅)指定了最大的QoS等级,服务端根据这个发送应用消息给客户端 + mqttMsgBack.subscribeAck(ctx, mqttMessage); + break; + case UNSUBSCRIBE: + // 客户端取消订阅 + // 客户端发送UNSUBSCRIBE报文给服务端,用于取消订阅主题 + mqttMsgBack.unsubscribeAck(ctx, mqttMessage); + break; + case PINGREQ: + // 客户端发起心跳 + mqttMsgBack.pingResp(ctx, mqttMessage); + break; + case DISCONNECT: + // 客户端主动断开连接 + // DISCONNECT报文是客户端发给服务端的最后一个控制报文, 服务端必须验证所有的保留位都被设置为0 + break; + // ----------------------服务端作为发送消息端可能会接收的事件---------------------------------------------------------------- + case PUBACK: + case PUBREC: + //QoS 2级别,响应一个PUBREL报文消息,PUBACK、PUBREC这俩都是ack消息 + //PUBACK报文是对QoS 1等级的PUBLISH报文的响应,如果一段时间没有收到客户端ack,服务端会重新发送消息 + mqttMsgBack.receivePubAck(ctx, mqttMessage); + break; + case PUBCOMP: + //收到qos2级别接收端最后一次发送过来的确认消息 + mqttMsgBack.receivePubcomp(ctx, mqttMessage); + break; + default: + break; + } + } + } + + /** + * 功能描述: 心跳检测 + * + * @param ctx 这里的作用主要是解决断网,弱网的情况发生 + * @param evt + * @return void + * @author zhouwenjie + * @date 2020/4/3 17:02 + */ + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { + String socketString = ctx.channel().remoteAddress().toString(); + if (evt instanceof IdleStateEvent) { + IdleStateEvent event = (IdleStateEvent) evt; + if (event.state() == IdleState.READER_IDLE) { + log.info("Client: " + socketString + " READER_IDLE 读超时"); + delSubCache(ctx); + ctx.disconnect(); + } + } + } + + + /** + * 功能描述: + * + * @param ctx + * @param cause + * @return void + * @author 发生异常会触发此函数 + * @date 2020/4/3 16:49 + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + cause.printStackTrace(); + } + + private void delSubCache(ChannelHandlerContext ctx){ + String id = ctx.channel().id().toString(); + clientMap.remove(id); + //删除订阅主题 + Set topicSet = MqttMsgBack.ctMap.get(id); + if (CollUtil.isNotEmpty(topicSet)) { + ConcurrentHashMap> subMap = MqttMsgBack.subMap; + ConcurrentHashMap qoSMap = MqttMsgBack.qoSMap; + for (String topic : topicSet) { + if (subMap != null) { + HashSet ids = subMap.get(topic); + if (CollUtil.isNotEmpty(ids)) { + ids.remove(id); + if (CollUtil.isEmpty(ids)) { + subMap.remove(topic); + } + } + } + if (qoSMap != null) { + qoSMap.remove(topic + "-" + id); + } + } + } + MqttMsgBack.ctMap.remove(id); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/TimerData.java b/iot-broker/src/main/java/com/java110/broker/mqtt/TimerData.java new file mode 100644 index 00000000..b4711e2e --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/TimerData.java @@ -0,0 +1,18 @@ +package com.java110.broker.mqtt; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; + +/** + * @author: zhouwenjie + * @description: 轮询线程信息存储 + * @create: 2021-04-29 08:06 + **/ +public class TimerData { + + + public static ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(10); + + public static ConcurrentHashMap> scheduledFutureMap = new ConcurrentHashMap<>(); +} diff --git a/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java b/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java new file mode 100644 index 00000000..d03b8584 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java @@ -0,0 +1,339 @@ +package com.java110.broker.utils; + +import org.w3c.dom.*; +import org.xml.sax.InputSource; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class XMLUtils { + private static final DocumentBuilderFactory documentBuilderFactory; + private static final TransformerFactory transformerFactory; + private static final DocumentBuilder documentBuilder; + + static { + documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setNamespaceAware(false); + documentBuilderFactory.setValidating(false); + transformerFactory = TransformerFactory.newInstance(); + try { + documentBuilder = documentBuilderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new RuntimeException("无法创建 DOM 解析器", e); + } + } + + /** + * 自定义的 NodeList 实现类 + */ + private static class NodeListImpl implements NodeList { + private final List nodes = new ArrayList<>(); + + /** + * 添加节点到 NodeList 中 + * @param node 要添加的节点 + */ + private void addItem(Node node) { + nodes.add(node); + } + @Override + public Node item(int index) { + return nodes.get(index); + } + @Override + public int getLength() { + return nodes.size(); + } + } + + /** + * 将 NodeList 转换为 List + * @param nodeList 要转换的 NodeList 对象 + * @return 转换后的 List + */ + public static List nodeListToList(NodeList nodeList) { + List list = new ArrayList<>(); + for (int i = 0; i < nodeList.getLength(); i++) { + list.add(nodeList.item(i)); + } + return list; + } + + /** + * 将 List 转换为 NodeList + * @param list 要转换的 List 对象 + * @return 转换后的 NodeList + */ + public static NodeList listToNodeList(List list) { + NodeListImpl nodeList = new NodeListImpl(); + for (Node node : list) { + nodeList.addItem(node); + } + return nodeList; + } + + /** + * 将 Node 转换为 Element + * @param node 要转换的节点 + * @return 转换后的元素节点 + */ + public static Element nodeToElement(Node node) { + try { + if (node.getNodeType() != Node.ELEMENT_NODE) { + throw new IllegalArgumentException("该节点不是元素节点"); + } + return (Element) node; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将 Node 转换为 Attr + * @param node 要转换的节点 + * @return 转换后的属性节点 + */ + public static Attr nodeToAttr(Node node) { + try { + if (node.getNodeType() != Node.ATTRIBUTE_NODE) { + throw new IllegalArgumentException("该节点不是属性节点"); + } + return (Attr) node; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将 Node 转换为 Text + * @param node 要转换的节点 + * @return 转换后的文本节点 + */ + public static Text nodeToText(Node node) { + try { + if (node.getNodeType() != Node.TEXT_NODE) { + throw new IllegalArgumentException("该节点不是文本节点"); + } + return (Text) node; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将 Element 转换为 Node + * @param element 要转换的元素节点 + * @return 转换后的节点 + */ + public static Node elementToNode(Element element) { + return element; + } + + /** + * 将 Attr 转换为 Node + * @param attr 要转换的属性节点 + * @return 转换后的节点 + */ + public static Node attrToNode(Attr attr) { + return attr; + } + + /** + * 将 Text 转换为 Node + * @param text 要转换的文本节点 + * @return 转换后的节点 + */ + public static Node textToNode(Text text) { + return text; + } + + /** + * 将 XML 字符串转换为 Document 对象 + * @param xmlStr XML 字符串 + * @return Document 对象 + */ + public static Document strToDoc(String xmlStr) { + try { + // 创建一个 InputSource 对象来包装 XML 字符串 + InputSource inputSource = new InputSource(new StringReader(xmlStr)); + // 解析 XML 字符串并返回 Document 对象 + Document document = documentBuilder.parse(inputSource); + // 将文档标准化 + document.normalize(); + return document; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将 Document 对象转换为 XML 字符串 + * @param document 要转换的 Document 对象 + * @return 转换后的 XML 字符串 + */ + public static String docToStr(Document document) { + String xmlStr = ""; + try { + // 创建一个新的转换器对象 + Transformer transformer = transformerFactory.newTransformer(); + // 设置转换器属性 + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + // 创建一个字符输出流 + StringWriter writer = new StringWriter(); + // 将 Document 对象转换为 XML 字符串,并写入字符输出流 + transformer.transform(new DOMSource(document), new StreamResult(writer)); + // 将字符输出流转换为字符串并赋值给 xmlStr + xmlStr = writer.toString(); + } catch (Exception e) { + e.printStackTrace(); + } + return xmlStr; + } + + /** + * 获取指定节点的所有子节点 + * @param node 父节点 + * @return 所有子节点列表 + */ + public static List getChildNodes(Node node) { + List childNodes = new ArrayList<>(); + // 获取所有子节点 + NodeList nodeList = node.getChildNodes(); + // 遍历所有子节点 + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + childNodes.add(childNode); + } + return childNodes; + } + + /** + * 获取指定元素的所有子元素 + * @param element 父元素 + * @return 所有子元素列表 + */ + public static List getChildElements(Element element) { + List childElements = new ArrayList<>(); + // 获取所有子节点 + NodeList nodeList = element.getChildNodes(); + // 遍历所有子节点 + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + // 判断节点类型是否为元素节点 + if (childNode.getNodeType() == Node.ELEMENT_NODE) { + // 将元素节点添加到列表中 + childElements.add((Element) childNode); + } + } + return childElements; + } + + /** + * 获取元素所有属性 + * @param element 元素节点 + * @return 属性列表 + */ + public static List getElementAttrs(Element element) { + List attributes = new ArrayList<>(); + // 获取元素的属性集合 + NamedNodeMap attributeMap = element.getAttributes(); + // 遍历属性集合 + for (int i = 0; i < attributeMap.getLength(); i++) { + Node attributeNode = attributeMap.item(i); + // 判断节点类型是否为属性节点 + if (attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) { + // 将属性节点添加到列表中 + attributes.add((Attr) attributeNode); + } + } + return attributes; + } + + /** + * 从指定文件名读取 XML 文件并返回 Document 对象 + * @param filename XML 文件名 + * @return Document 对象 + */ + public static Document readXMLFile(String filename) { + // 创建一个文件对象 + File xmlFile = new File(filename); + try { + // 创建一个FileInputStream对象 + FileInputStream fis = new FileInputStream(xmlFile); + // 解析XML文件并返回Document对象 + Document doc = documentBuilder.parse(fis); + return doc; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 打印 XML 文档 + * @param doc XML文档对象 + */ + public static void printXML(Document doc) { + Element root = doc.getDocumentElement(); + printXML(System.out, root, 0); + } + + /** + * 打印 XML 元素及其属性、子元素 + * @param element XML元素 + */ + public static void printXML(Element element) { + printXML(System.out, element, 0); + } + + private static void printXML(PrintStream ps, Element element, int indent) { + printTrunk(ps, indent); + ps.printf("├─ 元素: %s\n", element.getNodeName()); + + NamedNodeMap attributes = element.getAttributes(); + for (int i = 0; i < attributes.getLength(); i++) { + Attr attribute = (Attr) attributes.item(i); + printTrunk(ps, indent + 1); + ps.printf("├─ 属性: %s = %s\n", attribute.getName(), attribute.getValue()); + } + + NodeList children = element.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + printXML(ps, (Element) child, indent + 1); + } else if (child.getNodeType() == Node.TEXT_NODE) { + String text = child.getNodeValue().trim(); + if (!text.isEmpty()) { + printTrunk(ps, indent + 1); + ps.printf("└─ 文本: %s\n", text); + } + } + } + } + + /** + * 根据缩进层数打印树干,也就是前置"| " + * @param ps 打印流 + * @param indent 缩进层数 + */ + private static void printTrunk(PrintStream ps, int indent) { + for (int i = 0; i < indent; i++) { + ps.print("| "); + } + } +} + diff --git a/iot-broker/src/main/resources/application.yml b/iot-broker/src/main/resources/application.yml new file mode 100644 index 00000000..729fb0ba --- /dev/null +++ b/iot-broker/src/main/resources/application.yml @@ -0,0 +1,12 @@ +spring: + profiles: + active: dev +server: + port: 12000 +driver: + mqtt: + socket_port: 12001 + wait_time: 3000 + address_list: 127.0.0.1 + user_name: admin + password: public \ No newline at end of file diff --git a/iot-broker/src/test/java/com/java110/AppTest.java b/iot-broker/src/test/java/com/java110/AppTest.java new file mode 100644 index 00000000..f007402b --- /dev/null +++ b/iot-broker/src/test/java/com/java110/AppTest.java @@ -0,0 +1,38 @@ +package com.java110; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/iot-car/src/main/java/com/java110/car/cmd/ownerCar/SaveOwnerCarCmd.java b/iot-car/src/main/java/com/java110/car/cmd/ownerCar/SaveOwnerCarCmd.java index 20e4dd89..02ff08e0 100644 --- a/iot-car/src/main/java/com/java110/car/cmd/ownerCar/SaveOwnerCarCmd.java +++ b/iot-car/src/main/java/com/java110/car/cmd/ownerCar/SaveOwnerCarCmd.java @@ -72,7 +72,7 @@ public class SaveOwnerCarCmd extends Cmd { @Override public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException { Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区ID"); - Assert.hasKeyAndValue(reqJson, "ownerId", "请求报文中未包含ownerId"); +// Assert.hasKeyAndValue(reqJson, "ownerId", "请求报文中未包含ownerId"); Assert.hasKeyAndValue(reqJson, "carNum", "请求报文中未包含carNum"); Assert.hasKeyAndValue(reqJson, "carType", "请求报文中未包含carType"); Assert.hasKeyAndValue(reqJson, "psId", "未包含psId"); diff --git a/iot-car/src/main/resources/application-dev.yml b/iot-car/src/main/resources/application-dev.yml index b70296ef..5658fa3a 100644 --- a/iot-car/src/main/resources/application-dev.yml +++ b/iot-car/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-car redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-car/src/main/resources/dataSource-zihao.yml b/iot-car/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-car/src/main/resources/dataSource-zihao.yml +++ b/iot-car/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-car/src/main/resources/dataSource.yml b/iot-car/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-car/src/main/resources/dataSource.yml +++ b/iot-car/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-charge/src/main/resources/application-dev.yml b/iot-charge/src/main/resources/application-dev.yml index 0fafce2c..78d32b29 100644 --- a/iot-charge/src/main/resources/application-dev.yml +++ b/iot-charge/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-charge redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-charge/src/main/resources/dataSource-zihao.yml b/iot-charge/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-charge/src/main/resources/dataSource-zihao.yml +++ b/iot-charge/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-charge/src/main/resources/dataSource.yml b/iot-charge/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-charge/src/main/resources/dataSource.yml +++ b/iot-charge/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-community/src/main/resources/application-dev.yml b/iot-community/src/main/resources/application-dev.yml index c263f423..877e10b8 100644 --- a/iot-community/src/main/resources/application-dev.yml +++ b/iot-community/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-community redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-community/src/main/resources/dataSource-zihao.yml b/iot-community/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-community/src/main/resources/dataSource-zihao.yml +++ b/iot-community/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-community/src/main/resources/dataSource.yml b/iot-community/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-community/src/main/resources/dataSource.yml +++ b/iot-community/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-dev/src/main/resources/application-dev.yml b/iot-dev/src/main/resources/application-dev.yml index 6c45d062..c1f9ebe3 100644 --- a/iot-dev/src/main/resources/application-dev.yml +++ b/iot-dev/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-dev redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-dev/src/main/resources/dataSource-zihao.yml b/iot-dev/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-dev/src/main/resources/dataSource-zihao.yml +++ b/iot-dev/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-dev/src/main/resources/dataSource.yml b/iot-dev/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-dev/src/main/resources/dataSource.yml +++ b/iot-dev/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-gateway/src/main/resources/application-dev.yml b/iot-gateway/src/main/resources/application-dev.yml index c1023f1b..065908d0 100644 --- a/iot-gateway/src/main/resources/application-dev.yml +++ b/iot-gateway/src/main/resources/application-dev.yml @@ -30,9 +30,9 @@ spring: name: iot-gateway redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-gateway/src/main/resources/dataSource-zihao.yml b/iot-gateway/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-gateway/src/main/resources/dataSource-zihao.yml +++ b/iot-gateway/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-gateway/src/main/resources/dataSource.yml b/iot-gateway/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-gateway/src/main/resources/dataSource.yml +++ b/iot-gateway/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-h5/iot-user/manifest.json b/iot-h5/iot-user/manifest.json index 18e74d03..5a2d4870 100644 --- a/iot-h5/iot-user/manifest.json +++ b/iot-h5/iot-user/manifest.json @@ -1,6 +1,6 @@ { "name" : "HC小区物联网用户端", - "appid" : "__UNI__A1B0B07", + "appid" : "__UNI__7B52CBC", "description" : "用户业主设备控制", "versionName" : "1.0.0", "versionCode" : "100", @@ -59,7 +59,7 @@ "quickapp" : {}, "mp-weixin" : { "usingComponents" : true, - "appid" : "wxf83d66b0e9f5964d", + "appid" : "wx6a6c884d5202c330", "setting" : { "urlCheck" : false, "es6" : false diff --git a/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java b/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java index 7dac47d8..1adf9609 100644 --- a/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java +++ b/iot-hal/src/main/java/com/java110/hal/HalApplicationStart.java @@ -51,6 +51,8 @@ import java.util.concurrent.TimeUnit; "com.java110.intf.user", "com.java110.intf.system", "com.java110.intf.monitor", + "com.java110.intf.meter", + "com.java110.intf.barrier", }) @Java110CmdDiscovery(cmdPublishClass = ServiceCmdEventPublishing.class, basePackages = {"com.java110.job.cmd"}) diff --git a/iot-hal/src/main/java/com/java110/hal/mqtt/heartbeat/CustomMqttMsgThread.java b/iot-hal/src/main/java/com/java110/hal/mqtt/heartbeat/CustomMqttMsgThread.java index 897094e7..7542a519 100644 --- a/iot-hal/src/main/java/com/java110/hal/mqtt/heartbeat/CustomMqttMsgThread.java +++ b/iot-hal/src/main/java/com/java110/hal/mqtt/heartbeat/CustomMqttMsgThread.java @@ -50,12 +50,12 @@ public class CustomMqttMsgThread implements Runnable { IHardwareManufacturerAttrV1InnerServiceSMO hardwareManufacturerAttrV1InnerServiceSMOImpl - = ApplicationContextFactory.getBean("hardwareManufacturerAttrV1InnerServiceSMOImpl", + = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), IHardwareManufacturerAttrV1InnerServiceSMO.class); - if (hardwareManufacturerAttrV1InnerServiceSMOImpl == null) { - hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), - IHardwareManufacturerAttrV1InnerServiceSMO.class); - } +// if (hardwareManufacturerAttrV1InnerServiceSMOImpl == null) { +// hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), +// IHardwareManufacturerAttrV1InnerServiceSMO.class); +// } // todo 根据topic 查询 HardwareManufacturerAttrDto tmpManufacturerDto = new HardwareManufacturerAttrDto(); tmpManufacturerDto.setSpecCd(HardwareManufacturerAttrDto.SPEC_TOPIC); @@ -97,10 +97,10 @@ public class CustomMqttMsgThread implements Runnable { return; } - IAttendanceCheckinV1InnerServiceSMO attendanceCheckinV1InnerServiceSMO = ApplicationContextFactory.getBean("attendanceCheckinV1InnerServiceSMOImpl", IAttendanceCheckinV1InnerServiceSMO.class); - if (attendanceCheckinV1InnerServiceSMO == null) { - attendanceCheckinV1InnerServiceSMO = ApplicationContextFactory.getBean(IAttendanceCheckinV1InnerServiceSMO.class.getName(), IAttendanceCheckinV1InnerServiceSMO.class); - } + IAttendanceCheckinV1InnerServiceSMO attendanceCheckinV1InnerServiceSMO = ApplicationContextFactory.getBean(IAttendanceCheckinV1InnerServiceSMO.class.getName(), IAttendanceCheckinV1InnerServiceSMO.class); +// if (attendanceCheckinV1InnerServiceSMO == null) { +// attendanceCheckinV1InnerServiceSMO = ApplicationContextFactory.getBean(IAttendanceCheckinV1InnerServiceSMO.class.getName(), IAttendanceCheckinV1InnerServiceSMO.class); +// } if (!manufacturerAttrDto.getValue().contains("SN") && manufacturerAttrDto.getValue().equals(mqttMsgDto.getTopic())) { attendanceCheckinV1InnerServiceSMO.attendanceResult(new MqttResultDto(manufacturerAttrDto.getHmId(), mqttMsgDto.getTopic(), mqttMsgDto.getMsg())); @@ -121,10 +121,10 @@ public class CustomMqttMsgThread implements Runnable { return; } - IInstrumentV1InnerServiceSMO instrumentV1InnerServiceSMO = ApplicationContextFactory.getBean("instrumentV1InnerServiceSMOImpl", IInstrumentV1InnerServiceSMO.class); - if (instrumentV1InnerServiceSMO == null) { - instrumentV1InnerServiceSMO = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); - } + IInstrumentV1InnerServiceSMO instrumentV1InnerServiceSMO = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); +// if (instrumentV1InnerServiceSMO == null) { +// instrumentV1InnerServiceSMO = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); +// } if (!manufacturerAttrDto.getValue().contains("SN") && manufacturerAttrDto.getValue().equals(mqttMsgDto.getTopic())) { instrumentV1InnerServiceSMO.instrumentResult(new MqttResultDto(manufacturerAttrDto.getHmId(), mqttMsgDto.getTopic(), mqttMsgDto.getMsg())); @@ -153,12 +153,12 @@ public class CustomMqttMsgThread implements Runnable { } IAccessControlResultV1InnerServiceSMO accessControlResultV1InnerServiceSMO = - ApplicationContextFactory.getBean("accessControlResultV1InnerServiceSMOImpl", + ApplicationContextFactory.getBean(IAccessControlResultV1InnerServiceSMO.class.getName(), IAccessControlResultV1InnerServiceSMO.class); - if (accessControlResultV1InnerServiceSMO == null) { - accessControlResultV1InnerServiceSMO = ApplicationContextFactory.getBean(IAccessControlResultV1InnerServiceSMO.class.getName(), - IAccessControlResultV1InnerServiceSMO.class); - } +// if (accessControlResultV1InnerServiceSMO == null) { +// accessControlResultV1InnerServiceSMO = ApplicationContextFactory.getBean(IAccessControlResultV1InnerServiceSMO.class.getName(), +// IAccessControlResultV1InnerServiceSMO.class); +// } //todo 检查 配置的topic 中是否存在sn if (!manufacturerAttrDto.getValue().contains("SN") && manufacturerAttrDto.getValue().equals(mqttMsgDto.getTopic())) { accessControlResultV1InnerServiceSMO.accessControlResult(new AccessControlResultDto(manufacturerAttrDto.getHmId(), mqttMsgDto.getTopic(), mqttMsgDto.getMsg())); @@ -195,7 +195,7 @@ public class CustomMqttMsgThread implements Runnable { return; } IMqttNotifyBarrierV1InnerServiceSMO mqttNotifyBarrierV1InnerServiceSMOImpl = - ApplicationContextFactory.getBean("mqttNotifyBarrierV1InnerServiceSMOImpl", + ApplicationContextFactory.getBean(IMqttNotifyBarrierV1InnerServiceSMO.class.getName(), IMqttNotifyBarrierV1InnerServiceSMO.class); if (mqttNotifyBarrierV1InnerServiceSMOImpl == null) { mqttNotifyBarrierV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IMqttNotifyBarrierV1InnerServiceSMO.class.getName(), diff --git a/iot-hal/src/main/java/com/java110/hal/mqtt/subscribe/MqttClientSubscribeFactory.java b/iot-hal/src/main/java/com/java110/hal/mqtt/subscribe/MqttClientSubscribeFactory.java index aa664ee3..071fee9d 100644 --- a/iot-hal/src/main/java/com/java110/hal/mqtt/subscribe/MqttClientSubscribeFactory.java +++ b/iot-hal/src/main/java/com/java110/hal/mqtt/subscribe/MqttClientSubscribeFactory.java @@ -24,11 +24,11 @@ public class MqttClientSubscribeFactory { public static void subscribe() { - IHardwareManufacturerAttrV1InnerServiceSMO hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("hardwareManufacturerAttrV1InnerServiceSMOImpl", IHardwareManufacturerAttrV1InnerServiceSMO.class); + IHardwareManufacturerAttrV1InnerServiceSMO hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), IHardwareManufacturerAttrV1InnerServiceSMO.class); - if (hardwareManufacturerAttrV1InnerServiceSMOImpl == null) { - hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), IHardwareManufacturerAttrV1InnerServiceSMO.class); - } +// if (hardwareManufacturerAttrV1InnerServiceSMOImpl == null) { +// hardwareManufacturerAttrV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IHardwareManufacturerAttrV1InnerServiceSMO.class.getName(), IHardwareManufacturerAttrV1InnerServiceSMO.class); +// } HardwareManufacturerAttrDto hardwareManufacturerAttrDto = new HardwareManufacturerAttrDto(); hardwareManufacturerAttrDto.setSpecCd(HardwareManufacturerAttrDto.SPEC_TOPIC); @@ -70,10 +70,10 @@ public class MqttClientSubscribeFactory { return; } - IAttendanceMachineV1InnerServiceSMO attendanceMachineV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("attendanceMachineV1InnerServiceSMOImpl", IAttendanceMachineV1InnerServiceSMO.class); - if (attendanceMachineV1InnerServiceSMOImpl == null) { - attendanceMachineV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAttendanceMachineV1InnerServiceSMO.class.getName(), IAttendanceMachineV1InnerServiceSMO.class); - } + IAttendanceMachineV1InnerServiceSMO attendanceMachineV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAttendanceMachineV1InnerServiceSMO.class.getName(), IAttendanceMachineV1InnerServiceSMO.class); +// if (attendanceMachineV1InnerServiceSMOImpl == null) { +// attendanceMachineV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAttendanceMachineV1InnerServiceSMO.class.getName(), IAttendanceMachineV1InnerServiceSMO.class); +// } AttendanceMachineDto attendanceMachineDto = new AttendanceMachineDto(); attendanceMachineDto.setImplBean(manufacturerAttrDto.getHmId()); @@ -100,10 +100,10 @@ public class MqttClientSubscribeFactory { return; } - IInstrumentV1InnerServiceSMO instrumentV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("instrumentV1InnerServiceSMOImpl", IInstrumentV1InnerServiceSMO.class); - if (instrumentV1InnerServiceSMOImpl == null) { - instrumentV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); - } + IInstrumentV1InnerServiceSMO instrumentV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); +// if (instrumentV1InnerServiceSMOImpl == null) { +// instrumentV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IInstrumentV1InnerServiceSMO.class.getName(), IInstrumentV1InnerServiceSMO.class); +// } InstrumentDto instrumentDto = new InstrumentDto(); instrumentDto.setImplBean(manufacturerAttrDto.getHmId()); @@ -137,11 +137,11 @@ public class MqttClientSubscribeFactory { return; } - IBarrierV1InnerServiceSMO barrierV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("barrierV1InnerServiceSMOImpl", IBarrierV1InnerServiceSMO.class); + IBarrierV1InnerServiceSMO barrierV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IBarrierV1InnerServiceSMO.class.getName(), IBarrierV1InnerServiceSMO.class); - if (barrierV1InnerServiceSMOImpl == null) { - barrierV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IBarrierV1InnerServiceSMO.class.getName(), IBarrierV1InnerServiceSMO.class); - } +// if (barrierV1InnerServiceSMOImpl == null) { +// barrierV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IBarrierV1InnerServiceSMO.class.getName(), IBarrierV1InnerServiceSMO.class); +// } BarrierDto barrierDto = new BarrierDto(); barrierDto.setImplBean(manufacturerAttrDto.getHmId()); @@ -178,11 +178,11 @@ public class MqttClientSubscribeFactory { return; } - IAccessControlV1InnerServiceSMO accessControlV1InnerServiceSMOImpl = ApplicationContextFactory.getBean("accessControlV1InnerServiceSMOImpl", IAccessControlV1InnerServiceSMO.class); + IAccessControlV1InnerServiceSMO accessControlV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAccessControlV1InnerServiceSMO.class.getName(), IAccessControlV1InnerServiceSMO.class); - if (accessControlV1InnerServiceSMOImpl == null) { - accessControlV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAccessControlV1InnerServiceSMO.class.getName(), IAccessControlV1InnerServiceSMO.class); - } +// if (accessControlV1InnerServiceSMOImpl == null) { +// accessControlV1InnerServiceSMOImpl = ApplicationContextFactory.getBean(IAccessControlV1InnerServiceSMO.class.getName(), IAccessControlV1InnerServiceSMO.class); +// } AccessControlDto accessControlDto = new AccessControlDto(); accessControlDto.setImplBean(manufacturerAttrDto.getHmId()); diff --git a/iot-hal/src/main/resources/application-dev.yml b/iot-hal/src/main/resources/application-dev.yml index e98c3da3..335ef2b7 100644 --- a/iot-hal/src/main/resources/application-dev.yml +++ b/iot-hal/src/main/resources/application-dev.yml @@ -30,9 +30,9 @@ spring: name: iot-hal redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 @@ -46,9 +46,9 @@ spring: completionTimeout: 10 default: topic: topic - password: wuxw2015 - url: tcp://mqtt.homecommunity.cn:1883 - username: wuxw + url: tcp://127.0.0.1:12001 + username: admin + password: public keepalive: 20 poolSize: 20 datasource: diff --git a/iot-hal/src/main/resources/dataSource-zihao.yml b/iot-hal/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-hal/src/main/resources/dataSource-zihao.yml +++ b/iot-hal/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-hal/src/main/resources/dataSource.yml b/iot-hal/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-hal/src/main/resources/dataSource.yml +++ b/iot-hal/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-job/src/main/resources/application-dev.yml b/iot-job/src/main/resources/application-dev.yml index 3cc0e93d..d3b5ecb2 100644 --- a/iot-job/src/main/resources/application-dev.yml +++ b/iot-job/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-job redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-job/src/main/resources/dataSource-zihao.yml b/iot-job/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-job/src/main/resources/dataSource-zihao.yml +++ b/iot-job/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-job/src/main/resources/dataSource.yml b/iot-job/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-job/src/main/resources/dataSource.yml +++ b/iot-job/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lamp/src/main/resources/application-dev.yml b/iot-lamp/src/main/resources/application-dev.yml index 818062e4..79db7e29 100644 --- a/iot-lamp/src/main/resources/application-dev.yml +++ b/iot-lamp/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-lamp redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-lamp/src/main/resources/dataSource-zihao.yml b/iot-lamp/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-lamp/src/main/resources/dataSource-zihao.yml +++ b/iot-lamp/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lamp/src/main/resources/dataSource.yml b/iot-lamp/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-lamp/src/main/resources/dataSource.yml +++ b/iot-lamp/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lift/src/main/resources/application-dev.yml b/iot-lift/src/main/resources/application-dev.yml index 05e17d8f..4a0209d0 100644 --- a/iot-lift/src/main/resources/application-dev.yml +++ b/iot-lift/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-lift redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-lift/src/main/resources/dataSource-zihao.yml b/iot-lift/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-lift/src/main/resources/dataSource-zihao.yml +++ b/iot-lift/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lift/src/main/resources/dataSource.yml b/iot-lift/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-lift/src/main/resources/dataSource.yml +++ b/iot-lift/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lock/src/main/resources/application-dev.yml b/iot-lock/src/main/resources/application-dev.yml index fbcf6850..4e393e51 100644 --- a/iot-lock/src/main/resources/application-dev.yml +++ b/iot-lock/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-lock redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-lock/src/main/resources/dataSource-zihao.yml b/iot-lock/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-lock/src/main/resources/dataSource-zihao.yml +++ b/iot-lock/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-lock/src/main/resources/dataSource.yml b/iot-lock/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-lock/src/main/resources/dataSource.yml +++ b/iot-lock/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-meter/src/main/resources/application-dev.yml b/iot-meter/src/main/resources/application-dev.yml index 14c8c1c1..83b6d527 100644 --- a/iot-meter/src/main/resources/application-dev.yml +++ b/iot-meter/src/main/resources/application-dev.yml @@ -10,7 +10,7 @@ eureka: # defaultZone: http://dev.java110.com:8761/eureka/ defaultZone: http://localhost:8761/eureka/ server: - port: 9987 + port: 9983 tomcat: uri-encoding: UTF-8 @@ -26,9 +26,9 @@ spring: name: iot-meter redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-meter/src/main/resources/dataSource-zihao.yml b/iot-meter/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-meter/src/main/resources/dataSource-zihao.yml +++ b/iot-meter/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-meter/src/main/resources/dataSource.yml b/iot-meter/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-meter/src/main/resources/dataSource.yml +++ b/iot-meter/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-monitor/src/main/resources/application-dev.yml b/iot-monitor/src/main/resources/application-dev.yml index 3c821323..630b84d9 100644 --- a/iot-monitor/src/main/resources/application-dev.yml +++ b/iot-monitor/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-monitor redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-monitor/src/main/resources/dataSource-zihao.yml b/iot-monitor/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-monitor/src/main/resources/dataSource-zihao.yml +++ b/iot-monitor/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-monitor/src/main/resources/dataSource.yml b/iot-monitor/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-monitor/src/main/resources/dataSource.yml +++ b/iot-monitor/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-openapi/src/main/resources/application-dev.yml b/iot-openapi/src/main/resources/application-dev.yml index c69e76e3..10912fe3 100644 --- a/iot-openapi/src/main/resources/application-dev.yml +++ b/iot-openapi/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-openapi redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-openapi/src/main/resources/dataSource-zihao.yml b/iot-openapi/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-openapi/src/main/resources/dataSource-zihao.yml +++ b/iot-openapi/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-openapi/src/main/resources/dataSource.yml b/iot-openapi/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-openapi/src/main/resources/dataSource.yml +++ b/iot-openapi/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-system/src/main/resources/application-dev.yml b/iot-system/src/main/resources/application-dev.yml index 7c2f4f54..8936bcff 100644 --- a/iot-system/src/main/resources/application-dev.yml +++ b/iot-system/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-system redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-system/src/main/resources/dataSource-zihao.yml b/iot-system/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-system/src/main/resources/dataSource-zihao.yml +++ b/iot-system/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-system/src/main/resources/dataSource.yml b/iot-system/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-system/src/main/resources/dataSource.yml +++ b/iot-system/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-user/src/main/resources/application-dev.yml b/iot-user/src/main/resources/application-dev.yml index bc852a6a..257a33dc 100644 --- a/iot-user/src/main/resources/application-dev.yml +++ b/iot-user/src/main/resources/application-dev.yml @@ -26,9 +26,9 @@ spring: name: iot-user redis: database: 4 - host: 49.232.85.130 + host: 127.0.0.1 port: 6379 - password: aa1T3ETx5rX8# + password: park pool: max-active: 300 max-wait: 10000 diff --git a/iot-user/src/main/resources/dataSource-zihao.yml b/iot-user/src/main/resources/dataSource-zihao.yml index 6736e1cc..c4fc75af 100644 --- a/iot-user/src/main/resources/dataSource-zihao.yml +++ b/iot-user/src/main/resources/dataSource-zihao.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/iot-user/src/main/resources/dataSource.yml b/iot-user/src/main/resources/dataSource.yml index 2e0dcce8..f05af6be 100644 --- a/iot-user/src/main/resources/dataSource.yml +++ b/iot-user/src/main/resources/dataSource.yml @@ -20,4 +20,4 @@ shardingRule: props: - sql.show: true \ No newline at end of file + sql.show: false \ No newline at end of file diff --git a/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java b/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java index e8fc9d4b..57ea71b9 100644 --- a/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java +++ b/java110-core/src/main/java/com/java110/core/utils/Base64Convert.java @@ -1,8 +1,11 @@ package com.java110.core.utils; +import org.apache.commons.codec.binary.Base64; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + import java.io.IOException; import java.io.InputStream; -import java.util.Base64; public class Base64Convert { @@ -11,7 +14,8 @@ public class Base64Convert { } public static String decoder(String data){ - return new String(Base64.getDecoder().decode(data)); + Base64 decoder = new Base64(); + return new String(decoder.decode(data)); } /** @@ -28,7 +32,7 @@ public class Base64Convert { byte[] bytes = new byte[in.available()]; // 将文件中的内容读入到数组中 in.read(bytes); - strBase64 = Base64.getEncoder().encodeToString(bytes); //将字节流数组转换为字符串 + strBase64 = new BASE64Encoder().encode(bytes); //将字节流数组转换为字符串 } finally { if (in != null) { in.close(); @@ -51,7 +55,7 @@ public class Base64Convert { public static byte[] base64ToByte(String strBase64) throws IOException { // 解码,然后将字节转换为文件 strBase64 = strBase64.replaceAll("\r|\n", ""); - byte[] bytes = Base64.getDecoder().decode(strBase64.getBytes()); //将字符串转换为byte数组 + byte[] bytes = new BASE64Decoder().decodeBuffer(strBase64); //将字符串转换为byte数组 return bytes; } @@ -64,7 +68,8 @@ public class Base64Convert { */ public static String byteTobase64(byte[] strBase64) { // 解码,然后将字节转换为文件 - String bytes = new String(Base64.getDecoder().decode(strBase64)); //将字符串转换为byte数组 + + String bytes = new BASE64Encoder().encode(strBase64); //将字符串转换为byte数组 return bytes; } -- Gitee From ba051707f0d1657c315657246db56838be7d81ad Mon Sep 17 00:00:00 2001 From: haoxiong <1670082569@qq.com> Date: Sat, 8 Feb 2025 17:23:43 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 2 +- .../wechat/WechatPaymentFactoryAdapt.java | 8 +- .../src/main/resources/application-dev.yml | 6 +- .../src/main/resources/application-zihao.yml | 2 +- .../src/main/resources/java110.properties | 2 +- .../src/main/resources/application-dev.yml | 2 +- iot-broker/pom.xml | 45 +++ .../broker/connect/HKLongConnection.java | 104 ------ .../broker/connect/MultipartReader.java | 116 ------ .../java110/broker/connect/OkHttpConfig.java | 20 -- .../broker/connect/WebSocketService.java | 71 ---- .../broker/controller/HkISApiController.java | 72 +++- .../com/java110/broker/mqtt/MqttServer.java | 1 + .../com/java110/broker/utils/XMLUtils.java | 339 ------------------ .../com/java110/broker/utils/XmlUtils.java | 80 +++++ .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../configuration/ServiceConfiguration.java | 2 + .../service/impl/AppServiceCheckImpl.java | 1 + .../src/main/resources/application-dev.yml | 2 +- iot-h5/iot-user/api/user/sessionApi.js | 1 + iot-h5/iot-user/api/user/userApi.js | 2 + iot-h5/iot-user/conf/config.js | 2 +- iot-h5/iot-user/lib/java110/utils/EnvUtil.js | 19 +- iot-h5/iot-user/manifest.json | 9 +- iot-h5/iot-user/pages.json | 4 +- iot-h5/iot-user/pages/fee/tempCarFee.vue | 30 ++ iot-h5/iot-user/pages/fee/tempParkingFee.vue | 64 +++- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../java/com/java110/core/utils/PayUtil.java | 2 +- .../src/main/resources/application-dev.yml | 2 +- 42 files changed, 334 insertions(+), 704 deletions(-) delete mode 100644 iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java delete mode 100644 iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java delete mode 100644 iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java delete mode 100644 iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java delete mode 100644 iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java create mode 100644 iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java diff --git a/iot-accessControl/src/main/resources/application-dev.yml b/iot-accessControl/src/main/resources/application-dev.yml index 0279f0e9..59ffd369 100644 --- a/iot-accessControl/src/main/resources/application-dev.yml +++ b/iot-accessControl/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-accessControl redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java b/iot-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java index a749889d..b59a8929 100644 --- a/iot-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java +++ b/iot-acct/src/main/java/com/java110/acct/payment/adapt/wechat/WechatPaymentFactoryAdapt.java @@ -169,15 +169,15 @@ public class WechatPaymentFactoryAdapt implements IPaymentFactoryAdapt { SortedMap paramMap = new TreeMap(); paramMap.put("appid", smallWeChatDto.getAppId()); + paramMap.put("body", feeName); paramMap.put("mch_id", mchId); paramMap.put("nonce_str", PayUtil.makeUUID(32)); - paramMap.put("body", feeName); + paramMap.put("notify_url", notifyUrl); + paramMap.put("openid", openid); paramMap.put("out_trade_no", orderNum); - paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount)); paramMap.put("spbill_create_ip", PayUtil.getLocalIp()); - paramMap.put("notify_url", notifyUrl); + paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount)); paramMap.put("trade_type", tradeType); - paramMap.put("openid", openid); String paySwitch = MappingCache.getValue(DOMAIN_WECHAT_PAY, WECHAT_SERVICE_PAY_SWITCH); if (WECHAT_SERVICE_PAY_SWITCH_ON.equals(paySwitch)) { diff --git a/iot-acct/src/main/resources/application-dev.yml b/iot-acct/src/main/resources/application-dev.yml index 78d32b29..589d339b 100644 --- a/iot-acct/src/main/resources/application-dev.yml +++ b/iot-acct/src/main/resources/application-dev.yml @@ -10,7 +10,7 @@ eureka: # defaultZone: http://dev.java110.com:8761/eureka/ defaultZone: http://localhost:8761/eureka/ server: - port: 9988 + port: 9982 tomcat: uri-encoding: UTF-8 @@ -23,10 +23,10 @@ spring: enabled: true force: true application: - name: iot-charge + name: iot-acct redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-acct/src/main/resources/application-zihao.yml b/iot-acct/src/main/resources/application-zihao.yml index d2a58cb0..34447340 100644 --- a/iot-acct/src/main/resources/application-zihao.yml +++ b/iot-acct/src/main/resources/application-zihao.yml @@ -24,7 +24,7 @@ spring: enabled: true force: true application: - name: iot-charge + name: iot-acct redis: database: 0 host: dev.redis.java110.com diff --git a/iot-acct/src/main/resources/java110.properties b/iot-acct/src/main/resources/java110.properties index 4dd80f3a..ea1b49f5 100644 --- a/iot-acct/src/main/resources/java110.properties +++ b/iot-acct/src/main/resources/java110.properties @@ -1,4 +1,4 @@ -java110.mappingPath=classpath:mapper/charge/*.xml,classpath:mapper/service/*.xml +java110.mappingPath=classpath:mapper/acct/*.xml,classpath:mapper/acct/*.xml java110.testSwitch=ON diff --git a/iot-barrier/src/main/resources/application-dev.yml b/iot-barrier/src/main/resources/application-dev.yml index 445a3d84..7cb04e61 100644 --- a/iot-barrier/src/main/resources/application-dev.yml +++ b/iot-barrier/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-barrier redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-broker/pom.xml b/iot-broker/pom.xml index 83bf9c3c..58289b78 100644 --- a/iot-broker/pom.xml +++ b/iot-broker/pom.xml @@ -18,7 +18,52 @@ + + commons-httpclient + commons-httpclient + 3.1 + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.apache.httpcomponents + httpasyncclient + 4.1.4 + + + org.apache.httpcomponents + httpcore-nio + 4.4.13 + + + dom4j + dom4j + 1.6.1 + + + org.json + json + 20210307 + + + commons-io + commons-io + 2.11.0 + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + org.json + json + 20210307 + com.squareup.okhttp3 okhttp diff --git a/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java b/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java deleted file mode 100644 index f9849e8c..00000000 --- a/iot-broker/src/main/java/com/java110/broker/connect/HKLongConnection.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.java110.broker.connect; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Headers; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class HKLongConnection { - - private static final String USERNAME = "admin"; - private static final String PASSWORD = "your_password"; // 替换为你的密码 - private static final String REALM = "IP Camera(C2183)"; - private static final String NONCE = "4e5468694e7a42694e7a4d364f4449354d7a6b354d54513d"; - private static final String URI = "/ISAPI/Event/notification/alertStream"; - private static final String CNONCE = "3d183a245b8729121ae4ca3d41b90f18"; - private static final String NC = "00000001"; - private static final String QOP = "auth"; - - public static void main(String[] args) { - OkHttpClient client = new OkHttpClient.Builder() - .build(); - - Request request = new Request.Builder() - .url("http://10.6.165.192" + URI) - .header("Connection", "Keep-Alive") - .header("Authorization", createDigestAuthHeader(USERNAME, PASSWORD, "GET", URI, NONCE, NC, CNONCE, QOP)) - .build(); - - client.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - e.printStackTrace(); - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } - // 获取响应体 - ResponseBody responseBody = response.body(); - if (responseBody != null) { - MediaType contentType = responseBody.contentType(); - if (contentType != null && contentType.type().equals("multipart")) { - MultipartReader multipartReader = new MultipartReader(responseBody.source(), contentType); - multipartReader.readParts(new MultipartReader.PartCallback() { - @Override - public void onPart(MultipartReader.Part part) throws IOException { - Headers headers = part.headers(); - String contentType = headers.get("Content-Type"); - String contentDisposition = headers.get("Content-Disposition"); - System.out.println("Part headers: " + headers); - System.out.println("Content-Type: " + contentType); - System.out.println("contentDisposition: " + contentDisposition); - System.out.println("Part body: " + part.body().readUtf8()); - - if (contentType != null && contentType.startsWith("application/xml")) { - System.out.println("XML Content: " + part.body().readUtf8()); - } else if (contentType != null && contentType.startsWith("image/jpeg")) { - // 处理图片数据 - byte[] imageBytes = part.body().readByteArray(); - System.out.println("Image Length: " + imageBytes.length); - // 你可以在这里保存图片或进一步处理 - } - - } - }); - } else { - System.out.println("Response is not multipart: " + contentType); - } - } - } - }); - } - - private static String createDigestAuthHeader(String username, String password, String method, String uri, String nonce, String nc, String cnonce, String qop) { - String ha1 = md5(username + ":" + REALM + ":" + password); - String ha2 = md5(method + ":" + uri); - String response = md5(ha1 + ":" + nonce + ":" + nc + ":" + cnonce + ":" + qop + ":" + ha2); - return "Digest username=\"" + username + "\", realm=\"" + REALM + "\", nonce=\"" + nonce + "\", uri=\"" + uri + "\", cnonce=\"" + cnonce + "\", nc=" + nc + ", qop=" + qop + ", response=\"" + response + "\""; - } - - private static String md5(String input) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] messageDigest = md.digest(input.getBytes()); - StringBuilder sb = new StringBuilder(); - for (byte b : messageDigest) { - sb.append(String.format("%02x", b)); - } - return sb.toString(); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java b/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java deleted file mode 100644 index 236a4599..00000000 --- a/iot-broker/src/main/java/com/java110/broker/connect/MultipartReader.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.java110.broker.connect; -import okhttp3.Headers; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.RequestBody; -import okhttp3.internal.Util; -import okio.Buffer; -import okio.BufferedSink; -import okio.BufferedSource; -import okio.Okio; - -import java.io.IOException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public final class MultipartReader { - - private static final String BOUNDARY_PATTERN = "boundary=([^\\s;]+)"; - private static final Pattern BOUNDARY_REGEX = Pattern.compile(BOUNDARY_PATTERN); - - private final BufferedSource source; - private final String boundary; - - public MultipartReader(BufferedSource source, MediaType contentType) { - this.source = source; - Matcher matcher = BOUNDARY_REGEX.matcher(contentType.toString()); - if (!matcher.find()) { - throw new IllegalArgumentException("Content-Type does not contain boundary"); - } - this.boundary = matcher.group(1); - } - - public void readParts(PartCallback callback) throws IOException { - Buffer prefix = new Buffer(); - prefix.writeUtf8("--").writeUtf8(boundary).writeUtf8("\r\n"); - - Buffer suffix = new Buffer(); - suffix.writeUtf8("\r\n--").writeUtf8(boundary).writeUtf8("--\r\n"); - - while (true) { - if (!source.request(prefix.size())) { - throw new IOException("Unexpected end of stream"); - } - - if (source.buffer().rangeEquals(0, prefix.readByteString())) { - source.skip(prefix.size()); - if (!source.request(suffix.size())) { - throw new IOException("Unexpected end of stream"); - } - - if (source.buffer().rangeEquals(0, suffix.readByteString())) { - source.skip(suffix.size()); - break; - } - - Part part = readPart(); - callback.onPart(part); - } else { - throw new IOException("Unexpected prefix"); - } - } - } - - private Part readPart() throws IOException { - Headers.Builder headers = new Headers.Builder(); - while (true) { - String line = source.readUtf8LineStrict(); - if (line.length() == 0) { - break; - } - int index = line.indexOf(':'); - if (index == -1) { - throw new IOException("Unexpected header line: " + line); - } - String name = line.substring(0, index).trim(); - String value = line.substring(index + 1).trim(); - headers.add(name, value); - } - - Buffer body = new Buffer(); - while (true) { - String line = source.readUtf8LineStrict(); - if (line.equals("--" + boundary)) { - break; - } else if (line.equals("--" + boundary + "--")) { - break; - } else { - body.writeUtf8(line).writeUtf8("\r\n"); - } - } - - return new Part(headers.build(), body); - } - - public interface PartCallback { - void onPart(Part part) throws IOException; - } - - public static final class Part { - private final Headers headers; - private final Buffer body; - - public Part(Headers headers, Buffer body) { - this.headers = headers; - this.body = body; - } - - public Headers headers() { - return headers; - } - - public BufferedSource body() { - return body; - } - } -} diff --git a/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java b/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java deleted file mode 100644 index 29242a7f..00000000 --- a/iot-broker/src/main/java/com/java110/broker/connect/OkHttpConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.java110.broker.connect; - -import okhttp3.OkHttpClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.concurrent.TimeUnit; - -//@Configuration -public class OkHttpConfig { - - @Bean - public OkHttpClient okHttpClient() { - return new OkHttpClient.Builder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(0, TimeUnit.SECONDS) // 设置为0表示无限超时,适用于长连接 - .writeTimeout(30, TimeUnit.SECONDS) - .build(); - } -} diff --git a/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java b/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java deleted file mode 100644 index fad98e8f..00000000 --- a/iot-broker/src/main/java/com/java110/broker/connect/WebSocketService.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.java110.broker.connect; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; -import okio.ByteString; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -//@Service -public class WebSocketService { - - private final OkHttpClient client; - private WebSocket webSocket; - - @Autowired - public WebSocketService(OkHttpClient client) { - this.client = client; - } - - public void connect(String url) { - Request request = new Request.Builder().url(url).build(); - client.newWebSocket(request, new WebSocketListener() { - @Override - public void onOpen(WebSocket webSocket, Response response) { - System.out.println("WebSocket opened: " + response); - WebSocketService.this.webSocket = webSocket; - // 发送初始消息 - webSocket.send("Hello Server!"); - } - - @Override - public void onMessage(WebSocket webSocket, String text) { - System.out.println("Received TEXT message: " + text); - // 处理接收到的消息 - } - - @Override - public void onMessage(WebSocket webSocket, ByteString bytes) { - System.out.println("Received BINARY message: " + bytes.hex()); - // 处理接收到的二进制消息 - } - - @Override - public void onClosing(WebSocket webSocket, int code, String reason) { - System.out.println("WebSocket closing: " + code + " " + reason); - webSocket.close(1000, null); - WebSocketService.this.webSocket = null; - } - - @Override - public void onFailure(WebSocket webSocket, Throwable t, Response response) { - System.out.println("WebSocket failed: " + t.getMessage()); - t.printStackTrace(); - WebSocketService.this.webSocket = null; - } - }); - } - - public void sendMessage(String message) { - if (webSocket != null && webSocket.queueSize() == 0) { - webSocket.send(message); - } - } - - public WebSocket getWebSocket() { - return webSocket; - } -} diff --git a/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java index dd455ae0..f57b7bb6 100644 --- a/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java +++ b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java @@ -1,20 +1,74 @@ package com.java110.broker.controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; +import cn.hutool.json.JSONObject; +import cn.hutool.json.XML; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; @RestController public class HkISApiController { + private static final String UPLOAD_DIR = "/Users/admin/workspace/MicroCommunityIot/iot-broker/src/main/resources/images/"; - //从程序->设备 - @PostMapping("/hc/barrier/request/{machineId}") - public void test() { + public String printParameters(HttpServletRequest request) { + if (request instanceof MultipartHttpServletRequest) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + // 获取所有上传的文件 + Map> fileMap = multipartRequest.getMultiFileMap(); + // 循环打印所有上传的文件 + for (Map.Entry> entry : fileMap.entrySet()) { + String paramName = entry.getKey(); + List files = entry.getValue(); - } + for (MultipartFile file : files) { + System.out.println("File Parameter Name: " + paramName); + System.out.println("File Name: " + file.getOriginalFilename()); + System.out.println("File Size: " + file.getSize() + " bytes"); + System.out.println("File Content Type: " + file.getContentType()); - //从设备->程序 - @PostMapping("/hc/barrier/response") - public void test2() { + if (file.getContentType() != null) { + if (file.getContentType().startsWith("application/xml") || file.getContentType().startsWith("text/xml")) { + // 处理XML文件 + try { + String xmlContent = new String(file.getBytes()); + JSONObject jsonObject = XML.toJSONObject(xmlContent); + System.out.println("JSON Content: " + jsonObject.toString()); + } catch (IOException e) { + e.printStackTrace(); + return "Failed to read XML file: " + file.getOriginalFilename(); + } + } else if (file.getContentType().startsWith("image")) { + // 处理图片文件 + try { + File dest = new File(UPLOAD_DIR + file.getOriginalFilename()); + file.transferTo(dest); + System.out.println("File saved to: " + dest.getAbsolutePath()); + } catch (IOException e) { + e.printStackTrace(); + return "Failed to save image file: " + file.getOriginalFilename(); + } + } else { + System.out.println("Unsupported file type: " + file.getContentType()); + } + } else { + System.out.println("File content type is null."); + } + } + } + } else { + return "Request is not a multipart request."; + } + return "Parameters received and printed."; } } diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java index 09e8d63f..3eb3b0b9 100644 --- a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java @@ -41,6 +41,7 @@ public class MqttServer { //创建服务端启动辅助类(boostrap 用来为 Netty 程序的启动组装配置一些必须要组件,例如上面的创建的两个线程组) ServerBootstrap socketBs = new ServerBootstrap(); //channel 方法用于指定服务器端监听套接字通道 + //socket配置 socketBs.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) diff --git a/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java b/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java deleted file mode 100644 index d03b8584..00000000 --- a/iot-broker/src/main/java/com/java110/broker/utils/XMLUtils.java +++ /dev/null @@ -1,339 +0,0 @@ -package com.java110.broker.utils; - -import org.w3c.dom.*; -import org.xml.sax.InputSource; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -public class XMLUtils { - private static final DocumentBuilderFactory documentBuilderFactory; - private static final TransformerFactory transformerFactory; - private static final DocumentBuilder documentBuilder; - - static { - documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(false); - documentBuilderFactory.setValidating(false); - transformerFactory = TransformerFactory.newInstance(); - try { - documentBuilder = documentBuilderFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new RuntimeException("无法创建 DOM 解析器", e); - } - } - - /** - * 自定义的 NodeList 实现类 - */ - private static class NodeListImpl implements NodeList { - private final List nodes = new ArrayList<>(); - - /** - * 添加节点到 NodeList 中 - * @param node 要添加的节点 - */ - private void addItem(Node node) { - nodes.add(node); - } - @Override - public Node item(int index) { - return nodes.get(index); - } - @Override - public int getLength() { - return nodes.size(); - } - } - - /** - * 将 NodeList 转换为 List - * @param nodeList 要转换的 NodeList 对象 - * @return 转换后的 List - */ - public static List nodeListToList(NodeList nodeList) { - List list = new ArrayList<>(); - for (int i = 0; i < nodeList.getLength(); i++) { - list.add(nodeList.item(i)); - } - return list; - } - - /** - * 将 List 转换为 NodeList - * @param list 要转换的 List 对象 - * @return 转换后的 NodeList - */ - public static NodeList listToNodeList(List list) { - NodeListImpl nodeList = new NodeListImpl(); - for (Node node : list) { - nodeList.addItem(node); - } - return nodeList; - } - - /** - * 将 Node 转换为 Element - * @param node 要转换的节点 - * @return 转换后的元素节点 - */ - public static Element nodeToElement(Node node) { - try { - if (node.getNodeType() != Node.ELEMENT_NODE) { - throw new IllegalArgumentException("该节点不是元素节点"); - } - return (Element) node; - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return null; - } - } - - /** - * 将 Node 转换为 Attr - * @param node 要转换的节点 - * @return 转换后的属性节点 - */ - public static Attr nodeToAttr(Node node) { - try { - if (node.getNodeType() != Node.ATTRIBUTE_NODE) { - throw new IllegalArgumentException("该节点不是属性节点"); - } - return (Attr) node; - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return null; - } - } - - /** - * 将 Node 转换为 Text - * @param node 要转换的节点 - * @return 转换后的文本节点 - */ - public static Text nodeToText(Node node) { - try { - if (node.getNodeType() != Node.TEXT_NODE) { - throw new IllegalArgumentException("该节点不是文本节点"); - } - return (Text) node; - } catch (IllegalArgumentException e) { - e.printStackTrace(); - return null; - } - } - - /** - * 将 Element 转换为 Node - * @param element 要转换的元素节点 - * @return 转换后的节点 - */ - public static Node elementToNode(Element element) { - return element; - } - - /** - * 将 Attr 转换为 Node - * @param attr 要转换的属性节点 - * @return 转换后的节点 - */ - public static Node attrToNode(Attr attr) { - return attr; - } - - /** - * 将 Text 转换为 Node - * @param text 要转换的文本节点 - * @return 转换后的节点 - */ - public static Node textToNode(Text text) { - return text; - } - - /** - * 将 XML 字符串转换为 Document 对象 - * @param xmlStr XML 字符串 - * @return Document 对象 - */ - public static Document strToDoc(String xmlStr) { - try { - // 创建一个 InputSource 对象来包装 XML 字符串 - InputSource inputSource = new InputSource(new StringReader(xmlStr)); - // 解析 XML 字符串并返回 Document 对象 - Document document = documentBuilder.parse(inputSource); - // 将文档标准化 - document.normalize(); - return document; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - /** - * 将 Document 对象转换为 XML 字符串 - * @param document 要转换的 Document 对象 - * @return 转换后的 XML 字符串 - */ - public static String docToStr(Document document) { - String xmlStr = ""; - try { - // 创建一个新的转换器对象 - Transformer transformer = transformerFactory.newTransformer(); - // 设置转换器属性 - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - // 创建一个字符输出流 - StringWriter writer = new StringWriter(); - // 将 Document 对象转换为 XML 字符串,并写入字符输出流 - transformer.transform(new DOMSource(document), new StreamResult(writer)); - // 将字符输出流转换为字符串并赋值给 xmlStr - xmlStr = writer.toString(); - } catch (Exception e) { - e.printStackTrace(); - } - return xmlStr; - } - - /** - * 获取指定节点的所有子节点 - * @param node 父节点 - * @return 所有子节点列表 - */ - public static List getChildNodes(Node node) { - List childNodes = new ArrayList<>(); - // 获取所有子节点 - NodeList nodeList = node.getChildNodes(); - // 遍历所有子节点 - for (int i = 0; i < nodeList.getLength(); i++) { - Node childNode = nodeList.item(i); - childNodes.add(childNode); - } - return childNodes; - } - - /** - * 获取指定元素的所有子元素 - * @param element 父元素 - * @return 所有子元素列表 - */ - public static List getChildElements(Element element) { - List childElements = new ArrayList<>(); - // 获取所有子节点 - NodeList nodeList = element.getChildNodes(); - // 遍历所有子节点 - for (int i = 0; i < nodeList.getLength(); i++) { - Node childNode = nodeList.item(i); - // 判断节点类型是否为元素节点 - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - // 将元素节点添加到列表中 - childElements.add((Element) childNode); - } - } - return childElements; - } - - /** - * 获取元素所有属性 - * @param element 元素节点 - * @return 属性列表 - */ - public static List getElementAttrs(Element element) { - List attributes = new ArrayList<>(); - // 获取元素的属性集合 - NamedNodeMap attributeMap = element.getAttributes(); - // 遍历属性集合 - for (int i = 0; i < attributeMap.getLength(); i++) { - Node attributeNode = attributeMap.item(i); - // 判断节点类型是否为属性节点 - if (attributeNode.getNodeType() == Node.ATTRIBUTE_NODE) { - // 将属性节点添加到列表中 - attributes.add((Attr) attributeNode); - } - } - return attributes; - } - - /** - * 从指定文件名读取 XML 文件并返回 Document 对象 - * @param filename XML 文件名 - * @return Document 对象 - */ - public static Document readXMLFile(String filename) { - // 创建一个文件对象 - File xmlFile = new File(filename); - try { - // 创建一个FileInputStream对象 - FileInputStream fis = new FileInputStream(xmlFile); - // 解析XML文件并返回Document对象 - Document doc = documentBuilder.parse(fis); - return doc; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - /** - * 打印 XML 文档 - * @param doc XML文档对象 - */ - public static void printXML(Document doc) { - Element root = doc.getDocumentElement(); - printXML(System.out, root, 0); - } - - /** - * 打印 XML 元素及其属性、子元素 - * @param element XML元素 - */ - public static void printXML(Element element) { - printXML(System.out, element, 0); - } - - private static void printXML(PrintStream ps, Element element, int indent) { - printTrunk(ps, indent); - ps.printf("├─ 元素: %s\n", element.getNodeName()); - - NamedNodeMap attributes = element.getAttributes(); - for (int i = 0; i < attributes.getLength(); i++) { - Attr attribute = (Attr) attributes.item(i); - printTrunk(ps, indent + 1); - ps.printf("├─ 属性: %s = %s\n", attribute.getName(), attribute.getValue()); - } - - NodeList children = element.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) { - printXML(ps, (Element) child, indent + 1); - } else if (child.getNodeType() == Node.TEXT_NODE) { - String text = child.getNodeValue().trim(); - if (!text.isEmpty()) { - printTrunk(ps, indent + 1); - ps.printf("└─ 文本: %s\n", text); - } - } - } - } - - /** - * 根据缩进层数打印树干,也就是前置"| " - * @param ps 打印流 - * @param indent 缩进层数 - */ - private static void printTrunk(PrintStream ps, int indent) { - for (int i = 0; i < indent; i++) { - ps.print("| "); - } - } -} - diff --git a/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java b/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java new file mode 100644 index 00000000..77b70d45 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java @@ -0,0 +1,80 @@ +package com.java110.broker.utils; + +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; +import org.springframework.core.io.ClassPathResource; + +import java.io.*; + +public class XmlUtils { + + public static String createXmlString() { + // 创建一个新的XML文档 + Document document = DocumentHelper.createDocument(); + + // 创建根元素 + Element root = document.addElement("root"); + + // 添加子元素 + Element element1 = root.addElement("element"); + element1.addText("Value1"); + + Element element2 = root.addElement("element"); + element2.addText("Value2"); + + // 将XML文档转换为字符串 + return document.asXML(); + } + + public static String createPrettyXmlString() { + // 创建一个新的XML文档 + Document document = DocumentHelper.createDocument(); + + // 创建根元素 + Element root = document.addElement("root"); + + // 添加子元素 + Element element1 = root.addElement("element"); + element1.addText("Value1"); + + Element element2 = root.addElement("element"); + element2.addText("Value2"); + + // 使用OutputFormat来格式化XML + OutputFormat format = OutputFormat.createPrettyPrint(); + format.setEncoding("UTF-8"); + + StringWriter stringWriter = new StringWriter(); + XMLWriter xmlWriter = new XMLWriter(stringWriter, format); + + try { + xmlWriter.write(document); + xmlWriter.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + return stringWriter.toString(); + } + + public static String readBarrierXml(String fileName) throws IOException { + // 获取资源文件 + ClassPathResource resource = new ClassPathResource(fileName); + InputStream inputStream = resource.getInputStream(); + + // 读取文件内容 + StringBuilder contentBuilder = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + contentBuilder.append(line).append("\n"); + } + } + + return contentBuilder.toString(); + } +} + diff --git a/iot-car/src/main/resources/application-dev.yml b/iot-car/src/main/resources/application-dev.yml index 5658fa3a..586d8a54 100644 --- a/iot-car/src/main/resources/application-dev.yml +++ b/iot-car/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-car redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-charge/src/main/resources/application-dev.yml b/iot-charge/src/main/resources/application-dev.yml index 78d32b29..2e74603a 100644 --- a/iot-charge/src/main/resources/application-dev.yml +++ b/iot-charge/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-charge redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-community/src/main/resources/application-dev.yml b/iot-community/src/main/resources/application-dev.yml index 877e10b8..bdd4b617 100644 --- a/iot-community/src/main/resources/application-dev.yml +++ b/iot-community/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-community redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-dev/src/main/resources/application-dev.yml b/iot-dev/src/main/resources/application-dev.yml index c1f9ebe3..7dc93537 100644 --- a/iot-dev/src/main/resources/application-dev.yml +++ b/iot-dev/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-dev redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-gateway/src/main/java/com/java110/gateway/configuration/ServiceConfiguration.java b/iot-gateway/src/main/java/com/java110/gateway/configuration/ServiceConfiguration.java index 227b5a05..67d7d89f 100644 --- a/iot-gateway/src/main/java/com/java110/gateway/configuration/ServiceConfiguration.java +++ b/iot-gateway/src/main/java/com/java110/gateway/configuration/ServiceConfiguration.java @@ -79,6 +79,8 @@ public class ServiceConfiguration { //exclusions.append("/iot/api/appUser.saveAppUser,");// 房屋认证 + exclusions.append("/iot/api/wechat.getWechatMiniOpenId,");// 获取openId + } diff --git a/iot-gateway/src/main/java/com/java110/gateway/service/impl/AppServiceCheckImpl.java b/iot-gateway/src/main/java/com/java110/gateway/service/impl/AppServiceCheckImpl.java index 96a3056b..e238055d 100644 --- a/iot-gateway/src/main/java/com/java110/gateway/service/impl/AppServiceCheckImpl.java +++ b/iot-gateway/src/main/java/com/java110/gateway/service/impl/AppServiceCheckImpl.java @@ -74,6 +74,7 @@ public class AppServiceCheckImpl implements IAppServiceCheck { throw new IllegalArgumentException("USER-ID 不能为空"); } for (AppRoute appRoute : appRoutes) { + System.out.println("========"+appRoute.getAppService().getServiceCode()); if (StatusConstant.STATUS_CD_VALID.equals(appRoute.getStatusCd()) && appRoute.getAppService().getServiceCode().equals(serviceCode)) { appService = appRoute.getAppService(); diff --git a/iot-gateway/src/main/resources/application-dev.yml b/iot-gateway/src/main/resources/application-dev.yml index 065908d0..58c8000b 100644 --- a/iot-gateway/src/main/resources/application-dev.yml +++ b/iot-gateway/src/main/resources/application-dev.yml @@ -30,7 +30,7 @@ spring: name: iot-gateway redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-h5/iot-user/api/user/sessionApi.js b/iot-h5/iot-user/api/user/sessionApi.js index e23746a3..09a5b871 100644 --- a/iot-h5/iot-user/api/user/sessionApi.js +++ b/iot-h5/iot-user/api/user/sessionApi.js @@ -147,6 +147,7 @@ export function _refreshWechatMiniOpenId() { return; } let openId = _data.data; + console.log("======", openId) loginByOpenId(openId); }) }, diff --git a/iot-h5/iot-user/api/user/userApi.js b/iot-h5/iot-user/api/user/userApi.js index 2b9e8619..89e3f422 100644 --- a/iot-h5/iot-user/api/user/userApi.js +++ b/iot-h5/iot-user/api/user/userApi.js @@ -250,6 +250,7 @@ export function getWechatMiniOpenId(_objData){ method: "GET", data: _objData, //动态数据 success: function(res) { + console.log("-----------",_objData) if (res.statusCode == 200) { resolve(res.data); return; @@ -257,6 +258,7 @@ export function getWechatMiniOpenId(_objData){ reject(); }, fail: function(e) { + console.log("-----e------",e) reject(); } }); diff --git a/iot-h5/iot-user/conf/config.js b/iot-h5/iot-user/conf/config.js index 014d02be..4e8a7355 100644 --- a/iot-h5/iot-user/conf/config.js +++ b/iot-h5/iot-user/conf/config.js @@ -15,7 +15,7 @@ const baseUrl = '/'; // #ifndef H5 //服务器域名 小程序 或者 app 时 后端地址 -const baseUrl = 'http://192.168.100.108:9999/'; +const baseUrl = 'http://127.0.0.1:9999/'; // #endif let commonBaseUrl = 'http://iot.newwish.cc/'; diff --git a/iot-h5/iot-user/lib/java110/utils/EnvUtil.js b/iot-h5/iot-user/lib/java110/utils/EnvUtil.js index 5fef0ff8..0443c400 100644 --- a/iot-h5/iot-user/lib/java110/utils/EnvUtil.js +++ b/iot-h5/iot-user/lib/java110/utils/EnvUtil.js @@ -1,11 +1,12 @@ export function isWxOrAli() { - let _env = "WECHAT" - if (/MicroMessenger/.test(window.navigator.userAgent)) { - _env = "WECHAT" - } else if (/AlipayClient/.test(window.navigator.userAgent)) { - _env = "ALIPAY" - } else { - _env = "OTHER" - } - return _env; + return "WECHAT" + // let _env = "WECHAT" + // if (/MicroMessenger/.test(window.navigator.userAgent)) { + // _env = "WECHAT" + // } else if (/AlipayClient/.test(window.navigator.userAgent)) { + // _env = "ALIPAY" + // } else { + // _env = "OTHER" + // } + // return _env; } diff --git a/iot-h5/iot-user/manifest.json b/iot-h5/iot-user/manifest.json index 5a2d4870..3bfbac00 100644 --- a/iot-h5/iot-user/manifest.json +++ b/iot-h5/iot-user/manifest.json @@ -59,10 +59,12 @@ "quickapp" : {}, "mp-weixin" : { "usingComponents" : true, - "appid" : "wx6a6c884d5202c330", + "appid" : "wxc00307c8836a6c45", "setting" : { "urlCheck" : false, - "es6" : false + "es6" : true, + "postcss" : true, + "minified" : true }, "navigateToMiniProgramAppIDList" : [ "xxxx" ], //商城小程序AppId "permission" : { @@ -89,5 +91,8 @@ "domain" : "owner.demo.winqi.cn", "publicPath" : "./", "title" : "业主版" + }, + "uniStatistics" : { + "version" : "2" } } diff --git a/iot-h5/iot-user/pages.json b/iot-h5/iot-user/pages.json index 2f6fdfbd..07d31a53 100644 --- a/iot-h5/iot-user/pages.json +++ b/iot-h5/iot-user/pages.json @@ -445,8 +445,8 @@ "condition": { //模式配置,仅开发期间生效 "current": 0, //当前激活的模式(list 的索引项) "list": [{ - "name": "", //模式名称 - "path": "", //启动页面,必选 + "name": "首页", //模式名称 + "path": "pages/index/index", //启动页面,必选 "query": "" //启动参数,在页面的onLoad函数里面得到 }] }, diff --git a/iot-h5/iot-user/pages/fee/tempCarFee.vue b/iot-h5/iot-user/pages/fee/tempCarFee.vue index 866f4270..c1c4998a 100644 --- a/iot-h5/iot-user/pages/fee/tempCarFee.vue +++ b/iot-h5/iot-user/pages/fee/tempCarFee.vue @@ -216,6 +216,36 @@ }); }); // #endif + + // #ifdef MP-WEIXIN + uni.requestPayment({ + provider: 'wxpay', + timeStamp: _data.timeStamp, + nonceStr: _data.nonceStr, + package: _data.package, + signType: _data.signType, + paySign: _data.sign, + success: function(res) { + if (res.errMsg == 'requestPayment:ok') { + + uni.showToast({ + title: "支付成功", + duration: 2000 + }); + uni.navigateBack({ + delta:1 + }); + } + }, + fail: function(err) { + uni.showToast({ + title: err, + icon: 'none' + }) + console.log(err); + } + }); + // #endif return; } if(_data.code == '100'){ diff --git a/iot-h5/iot-user/pages/fee/tempParkingFee.vue b/iot-h5/iot-user/pages/fee/tempParkingFee.vue index 87d0ae28..aa9c825e 100644 --- a/iot-h5/iot-user/pages/fee/tempParkingFee.vue +++ b/iot-h5/iot-user/pages/fee/tempParkingFee.vue @@ -111,6 +111,7 @@ } from '../../lib/java110/utils/StringUtil.js' import { refreshUserOpenId, + getWechatMiniOpenId, getOpenIdFromAliPay } from '../../api/user/userApi.js' import { @@ -120,6 +121,10 @@ import { queryWaitPayFeeTempCar } from '@/api/car/carApi.js'; + + import { + _refreshWechatMiniOpenId + } from '@/api/user/sessionApi.js'; export default { data() { return { @@ -168,14 +173,31 @@ this.machineId = options.machineId; this.communityId = options.communityId; uni.setStorageSync("wAppId", this.appId) + let _that =this; if (!isNotNull(this.openId)) { + //刷新 openId + // #ifdef H5 if (isWxOrAli() == 'ALIPAY') { - this._refreshAliPayOpenId(); - } else { - this._refreshWechatOpenId(); + //_that._refreshAliPayOpenId(); + return; } + //todo h5 情况 + _that._refreshWechatOpenId(); return; + // #endif + + // #ifdef MP-WEIXIN + _that._refreshWechatMiniOpenId(); + // #endif + + // //刷新 openId + // if (isWxOrAli() == 'ALIPAY') { + // this._refreshAliPayOpenId(); + // } else { + // this._refreshWechatOpenId(); + // } + // return; } this._loadExistsCarNum(); }, @@ -292,6 +314,42 @@ } }); }, + _refreshWechatMiniOpenId:function(){ + console.log("===================") + let _that =this; + wx.login({ + success: function(loginRes) { + + if (!loginRes.code) { + return; + } + let accountInfo = wx.getAccountInfoSync(); + let appId = accountInfo.miniProgram.appId; + console.log("===================", appId, accountInfo) + getWechatMiniOpenId({ + code:loginRes.code, + appId:appId, + }).then(_data =>{ + console.log("===================", _data) + if(_data.code != 0){ + uni.showToast({ + icon:'none', + title:_data.msg + }) + return; + } + _that.openId = _data.data; + + }) + + }, + fail: function(error) { + // 调用 wx.login 接口失败 + console.log('调用wx.login获取code失败'); + console.log(error); + } + }); + }, _loadExistsCarNum: function() { let _that = this; let _openType = "WECHAT"; diff --git a/iot-hal/src/main/resources/application-dev.yml b/iot-hal/src/main/resources/application-dev.yml index 335ef2b7..72159456 100644 --- a/iot-hal/src/main/resources/application-dev.yml +++ b/iot-hal/src/main/resources/application-dev.yml @@ -30,7 +30,7 @@ spring: name: iot-hal redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-job/src/main/resources/application-dev.yml b/iot-job/src/main/resources/application-dev.yml index d3b5ecb2..381f0e0d 100644 --- a/iot-job/src/main/resources/application-dev.yml +++ b/iot-job/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-job redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-lamp/src/main/resources/application-dev.yml b/iot-lamp/src/main/resources/application-dev.yml index 79db7e29..eddc8ab3 100644 --- a/iot-lamp/src/main/resources/application-dev.yml +++ b/iot-lamp/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-lamp redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-lift/src/main/resources/application-dev.yml b/iot-lift/src/main/resources/application-dev.yml index 4a0209d0..19d4707a 100644 --- a/iot-lift/src/main/resources/application-dev.yml +++ b/iot-lift/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-lift redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-lock/src/main/resources/application-dev.yml b/iot-lock/src/main/resources/application-dev.yml index 4e393e51..03bb6654 100644 --- a/iot-lock/src/main/resources/application-dev.yml +++ b/iot-lock/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-lock redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-meter/src/main/resources/application-dev.yml b/iot-meter/src/main/resources/application-dev.yml index 83b6d527..c1c3355a 100644 --- a/iot-meter/src/main/resources/application-dev.yml +++ b/iot-meter/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-meter redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-monitor/src/main/resources/application-dev.yml b/iot-monitor/src/main/resources/application-dev.yml index 630b84d9..988da68a 100644 --- a/iot-monitor/src/main/resources/application-dev.yml +++ b/iot-monitor/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-monitor redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-openapi/src/main/resources/application-dev.yml b/iot-openapi/src/main/resources/application-dev.yml index 10912fe3..77d329dd 100644 --- a/iot-openapi/src/main/resources/application-dev.yml +++ b/iot-openapi/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-openapi redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-system/src/main/resources/application-dev.yml b/iot-system/src/main/resources/application-dev.yml index 8936bcff..19dfa76f 100644 --- a/iot-system/src/main/resources/application-dev.yml +++ b/iot-system/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-system redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/iot-user/src/main/resources/application-dev.yml b/iot-user/src/main/resources/application-dev.yml index 257a33dc..a06898fa 100644 --- a/iot-user/src/main/resources/application-dev.yml +++ b/iot-user/src/main/resources/application-dev.yml @@ -26,7 +26,7 @@ spring: name: iot-user redis: database: 4 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: park pool: diff --git a/java110-core/src/main/java/com/java110/core/utils/PayUtil.java b/java110-core/src/main/java/com/java110/core/utils/PayUtil.java index 5a46f095..353ad6fe 100644 --- a/java110-core/src/main/java/com/java110/core/utils/PayUtil.java +++ b/java110-core/src/main/java/com/java110/core/utils/PayUtil.java @@ -132,7 +132,7 @@ public class PayUtil { } } sb.append("key=" + key); - logger.debug("加密前串:" + sb.toString()); + logger.info("加密前串:" + sb.toString()); String sign = md5(sb.toString()).toUpperCase(); return sign; } diff --git a/springboot/src/main/resources/application-dev.yml b/springboot/src/main/resources/application-dev.yml index 5f0705b9..f1135132 100644 --- a/springboot/src/main/resources/application-dev.yml +++ b/springboot/src/main/resources/application-dev.yml @@ -24,7 +24,7 @@ spring: name: iot-boot redis: database: 6 - host: 127.0.0.1 + host: 192.168.56.21 port: 6379 password: hc # host: localhost -- Gitee From 5779b47460dff576a2986951517f963adb255009 Mon Sep 17 00:00:00 2001 From: haoxiong <1670082569@qq.com> Date: Sat, 8 Feb 2025 18:43:29 +0800 Subject: [PATCH 7/9] mqtt broker bug fix --- .../broker/utils/ApacheHttpClientService.java | 84 ++++++++++++++++++ .../src/main/resources/template/barrier.xml | 3 + .../src/main/resources/template/lcd-all.json | 85 +++++++++++++++++++ .../src/main/resources/template/lcd.json | 27 ++++++ .../src/main/resources/template/voice.json | 9 ++ .../src/test/java/com/java110/AppTest.java | 38 --------- 6 files changed, 208 insertions(+), 38 deletions(-) create mode 100644 iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java create mode 100644 iot-broker/src/main/resources/template/barrier.xml create mode 100644 iot-broker/src/main/resources/template/lcd-all.json create mode 100644 iot-broker/src/main/resources/template/lcd.json create mode 100644 iot-broker/src/main/resources/template/voice.json delete mode 100644 iot-broker/src/test/java/com/java110/AppTest.java diff --git a/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java b/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java new file mode 100644 index 00000000..af3d749e --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java @@ -0,0 +1,84 @@ +package com.java110.broker.utils; + +import org.apache.http.HttpEntity; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; + +public class ApacheHttpClientService { + + public String sendRequestWithAuth(String url, String username, String password) throws IOException { + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials( + AuthScope.ANY, + new UsernamePasswordCredentials(username, password) + ); + + try (CloseableHttpClient httpClient = HttpClients.custom() + .setDefaultCredentialsProvider(credsProvider) + .build()) { + + HttpGet request = new HttpGet(url); + try (CloseableHttpResponse response = httpClient.execute(request)) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + return EntityUtils.toString(entity); + } + } + } + return null; + } + + public String sendPostRequestWithAuth(String url, String username, String password, String requestBody) throws IOException { + + CredentialsProvider credsProvider = new BasicCredentialsProvider(); + credsProvider.setCredentials( + AuthScope.ANY, + new UsernamePasswordCredentials(username, password) + ); + try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()) { + HttpPut request = new HttpPut(url); + request.setEntity(new StringEntity(requestBody, "UTF-8")); + request.setHeader("Content-Type", "application/json"); + try (CloseableHttpResponse response = httpClient.execute(request)) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + return EntityUtils.toString(entity); + } + } catch (Exception e ) { + e.printStackTrace(); + } + } catch (Exception e ) { + e.printStackTrace(); + } + return null; + } + + + public static void main(String[] args) throws IOException { + ApacheHttpClientService ac = new ApacheHttpClientService(); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Security/userCheck", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Parking/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/barrierGate/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/barrierGate/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/voiceBroadcastInfo/capabilities", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/LCD/capabilities", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/System/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Event/notification/httpHosts/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Event/notification/httpHosts/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); +// String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/barrierGate", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/barrier.xml")); +// String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/voiceBroadcastInfo/combinateBroadcast", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/voice.json")); + String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/LCD", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/lcd-all.json")); + System.out.println(res); + } +} diff --git a/iot-broker/src/main/resources/template/barrier.xml b/iot-broker/src/main/resources/template/barrier.xml new file mode 100644 index 00000000..60282a71 --- /dev/null +++ b/iot-broker/src/main/resources/template/barrier.xml @@ -0,0 +1,3 @@ + + close + \ No newline at end of file diff --git a/iot-broker/src/main/resources/template/lcd-all.json b/iot-broker/src/main/resources/template/lcd-all.json new file mode 100644 index 00000000..4395f8fd --- /dev/null +++ b/iot-broker/src/main/resources/template/lcd-all.json @@ -0,0 +1,85 @@ +{ + "LCD": { + "displayPassingVehicleInfoEnabled": true, + "displayPlateEnable": true, + "displayTimeEnable": true, + "timeFormat": "hh-mm-ss", + "expireRemindDay": 30, + "CustomContentList": [{ + "CustomContent": { + "id": 1, + "content": "欢迎光临 陕A2M297", + "fontSizeLine": 40, + "fontColorLine": { + "R": 255, + "G": 255, + "B": 255 + }, + "fontBoldLine": false, + "passVehicleDisplayEnabled": false + } + }], + "fontSize": 50, + "fontColor": { + "R": 0, + "G": 0, + "B": 255 + }, + "MediaDataInfo": { + "cycleIntervalTime": 60, + "cyclePlayOrder": [] + }, + "ctrlMode": "camera", + "allowListDisplayEnabled": false, + "blockListDisplayEnabled": false, + "temporaryListDisplayEnabled": false, + "fanSpeedLevel": "close", + "temperatureThreshold": 0, + "screenWidth": 0, + "screenHeight": 0, + "softwareVersion": "V3.0.0_build20240902STD_|240910", + "autoSwitchFreeEnabled": true, + "BackBright": { + "enabled": false, + "ctrlMode": "manualAndTime", + "value": 0, + "timeCtrlEnabled": false, + "TimeCtrlList": [{ + "TimeCtrl": { + "startTime": "00:00", + "endTime": "00:00", + "value": 0, + "vehiclePassingValue": 0 + } + }] + }, + "displayTime": 20, + "HintContentList": [{ + "HintContent": { + "id": 1, + "content": "自动识别", + "contentType": "free", + "fontSizeLine": 50, + "fontColorLine": { + "R": 255, + "G": 255, + "B": 255 + }, + "fontBoldLine": false + } + }, { + "HintContent": { + "id": 2, + "content": "一车一杆", + "contentType": "free", + "fontSizeLine": 50, + "fontColorLine": { + "R": 255, + "G": 255, + "B": 255 + }, + "fontBoldLine": false + } + }] + } +} \ No newline at end of file diff --git a/iot-broker/src/main/resources/template/lcd.json b/iot-broker/src/main/resources/template/lcd.json new file mode 100644 index 00000000..074f7c71 --- /dev/null +++ b/iot-broker/src/main/resources/template/lcd.json @@ -0,0 +1,27 @@ +{ + "LCD": { + "CustomContentList": [{ + "CustomContent": { + "id": 1, + "content": "欢迎光临陕A2M297" + } + }], + "fontSize": 50, + "fontColor": { + "R": 0, + "G": 0, + "B": 255 + }, + "MediaDataInfo": { + "cycleIntervalTime": 60, + "cyclePlayOrder": [] + }, + "ctrlMode": "camera", + "displayTime": 20, + "HintContentList": [{ + "HintContent": { + "content": "测试自动识别车牌提示" + } + }] + } +} \ No newline at end of file diff --git a/iot-broker/src/main/resources/template/voice.json b/iot-broker/src/main/resources/template/voice.json new file mode 100644 index 00000000..323a9f91 --- /dev/null +++ b/iot-broker/src/main/resources/template/voice.json @@ -0,0 +1,9 @@ +{ + "CombinateBroadcast": { + "BroadcastInfoList": [{ + "BroadcastInfo": { + "customValue": "陕A 2M297, 应缴费金额 1200" + } + }] + } +} \ No newline at end of file diff --git a/iot-broker/src/test/java/com/java110/AppTest.java b/iot-broker/src/test/java/com/java110/AppTest.java deleted file mode 100644 index f007402b..00000000 --- a/iot-broker/src/test/java/com/java110/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.java110; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} -- Gitee From d7e3f1ca0fc0d3e56fbbe989cbc63daf3650a22e Mon Sep 17 00:00:00 2001 From: haoxiong <1670082569@qq.com> Date: Mon, 10 Feb 2025 15:50:19 +0800 Subject: [PATCH 8/9] mqtt broker completed --- iot-broker/pom.xml | 101 ++--------- .../java/com/java110/MqttBrokerServerApp.java | 107 +++++++++-- .../broker/controller/HkISApiController.java | 83 ++++++++- .../com/java110/broker/model/BarrierPo.java | 166 ++++++++++++++++++ .../java110/broker/mqtt/MonitorMsgTime.java | 6 +- .../com/java110/broker/mqtt/MqttMsgBack.java | 25 +-- .../com/java110/broker/mqtt/MqttRequest.java | 95 ++++++++++ .../com/java110/broker/mqtt/MqttServer.java | 8 +- .../broker/mqtt/ServerMqttHandler.java | 14 +- .../broker/service/HkISApiRequestService.java | 4 + .../broker/service/MqttServiceHandler.java | 5 + .../impl/HkISApiRequestServiceImpl.java | 8 + .../service/impl/MqttServiceHandlerImpl.java | 64 +++++++ .../broker/utils/ApacheHttpClientService.java | 63 ++++++- .../java110/broker/utils/MqttCommonUtils.java | 15 ++ .../com/java110/broker/utils/XmlUtils.java | 68 +++++++ .../src/main/resources/application-dev.yml | 67 +++++++ iot-broker/src/main/resources/application.yml | 11 +- .../resources/images/licensePlatePicture.jpg | Bin 0 -> 2312 bytes .../src/main/resources/java110.properties | 4 + .../src/main/resources/template/lcd-all.json | 63 +------ .../src/main/resources/template/voice.json | 2 +- .../components/car/addBarrier/addBarrier.html | 27 +++ .../components/car/addBarrier/addBarrier.js | 6 + .../car/editBarrier/editBarrier.html | 27 +++ .../components/car/editBarrier/editBarrier.js | 6 + .../com/java110/dto/barrier/BarrierDto.java | 26 +++ .../com/java110/po/barrier/BarrierPo.java | 27 +++ .../barrier/BarrierV1ServiceDaoImplMapper.xml | 15 +- pom.xml | 1 + 30 files changed, 898 insertions(+), 216 deletions(-) create mode 100644 iot-broker/src/main/java/com/java110/broker/model/BarrierPo.java create mode 100644 iot-broker/src/main/java/com/java110/broker/mqtt/MqttRequest.java create mode 100644 iot-broker/src/main/java/com/java110/broker/service/HkISApiRequestService.java create mode 100644 iot-broker/src/main/java/com/java110/broker/service/MqttServiceHandler.java create mode 100644 iot-broker/src/main/java/com/java110/broker/service/impl/HkISApiRequestServiceImpl.java create mode 100644 iot-broker/src/main/java/com/java110/broker/service/impl/MqttServiceHandlerImpl.java create mode 100644 iot-broker/src/main/java/com/java110/broker/utils/MqttCommonUtils.java create mode 100644 iot-broker/src/main/resources/application-dev.yml create mode 100644 iot-broker/src/main/resources/images/licensePlatePicture.jpg create mode 100644 iot-broker/src/main/resources/java110.properties diff --git a/iot-broker/pom.xml b/iot-broker/pom.xml index 58289b78..80756895 100644 --- a/iot-broker/pom.xml +++ b/iot-broker/pom.xml @@ -19,105 +19,24 @@ - commons-httpclient - commons-httpclient - 3.1 + junit + junit + 3.8.1 + test - org.apache.httpcomponents - httpclient - 4.5.13 + com.java110 + java110-core - org.apache.httpcomponents - httpasyncclient - 4.1.4 + com.java110 + java110-db - org.apache.httpcomponents - httpcore-nio - 4.4.13 - - - dom4j - dom4j - 1.6.1 - - - - org.json - json - 20210307 - - - commons-io - commons-io - 2.11.0 - - - org.apache.httpcomponents - httpclient - 4.5.13 - - - org.json - json - 20210307 - - - com.squareup.okhttp3 - okhttp - 4.10.0 - - - - org.springframework.boot - spring-boot-starter - - - cn.hutool - hutool-all - 5.8.11 - - - - com.alibaba - fastjson - 1.2.83 - - - - org.apache.commons - commons-lang3 - 3.12.0 - - - org.springframework.boot - spring-boot-starter-web - - - io.netty - netty-all - 4.1.72.Final - - - org.projectlombok - lombok + com.java110 + java110-doc - - - - - - - - - - - - - diff --git a/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java b/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java index 370da3cd..12a13d7f 100644 --- a/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java +++ b/iot-broker/src/main/java/com/java110/MqttBrokerServerApp.java @@ -1,34 +1,111 @@ package com.java110; import com.java110.broker.mqtt.MqttServer; +import com.java110.core.annotation.Java110CmdDiscovery; +import com.java110.core.client.OutRestTemplate; +import com.java110.core.client.RestTemplate; +import com.java110.core.cmd.ServiceCmdEventPublishing; +import com.java110.core.init.ServiceStartInit; +import com.java110.core.trace.Java110FeignClientInterceptor; +import com.java110.core.trace.Java110RestTemplateInterceptor; +import okhttp3.ConnectionPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.http.converter.StringHttpMessageConverter; -@EnableAutoConfiguration -@SpringBootApplication +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.TimeUnit; + +@SpringBootApplication(scanBasePackages = { + "com.java110.car", + "com.java110.core", + "com.java110.doc", + "com.java110.broker", +}) +@EnableFeignClients(basePackages = { + "com.java110.intf.barrier", +}) + +@EnableDiscoveryClient public class MqttBrokerServerApp implements CommandLineRunner { @Autowired private MqttServer mqttService; - public static void main( String[] args ) - { - SpringApplication.run(MqttBrokerServerApp.class, args); + private static Logger logger = LoggerFactory.getLogger(MqttBrokerServerApp.class); + + @Resource + private Java110RestTemplateInterceptor java110RestTemplateInterceptor; + + @Bean + @LoadBalanced + public RestTemplate restTemplate() { + StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8")); + RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(RestTemplate.class); + restTemplate.getInterceptors().add(java110RestTemplateInterceptor); + return restTemplate; } + /** + * 实例化RestTemplate + * + * @return restTemplate + */ + @Bean + public OutRestTemplate outRestTemplate() { + StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8")); + OutRestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(OutRestTemplate.class); + return restTemplate; + } + + @Bean + @ConditionalOnBean(Java110FeignClientInterceptor.class) + public okhttp3.OkHttpClient okHttpClient(@Autowired + Java110FeignClientInterceptor okHttpLoggingInterceptor){ + okhttp3.OkHttpClient.Builder ClientBuilder = new okhttp3.OkHttpClient.Builder() + .readTimeout(30, TimeUnit.SECONDS) //读取超时 + .connectTimeout(10, TimeUnit.SECONDS) //连接超时 + .writeTimeout(60, TimeUnit.SECONDS) //写入超时 + .connectionPool(new ConnectionPool(10 /*maxIdleConnections*/, 3, TimeUnit.MINUTES)) + .addInterceptor(okHttpLoggingInterceptor); + return ClientBuilder.build(); + } + + + public static void main(String[] args) throws Exception { + try { + ServiceStartInit.preInitSystemConfig(); + ApplicationContext context = SpringApplication.run(MqttBrokerServerApp.class, args); + new Thread(new Runnable() { + public void run() { + try { + context.getBean(MqttServer.class).start(); + } catch (Throwable $ex) { + throw $ex; + } + } + }).start(); + //服务启动加载 + ServiceStartInit.initSystemConfig(context); + } catch (Throwable e) { + logger.error("系统启动失败", e); + } + } @Override public void run(String... args) throws Exception { - Thread t1 = new Thread(new Runnable() { - public void run() { - try { - MqttBrokerServerApp.this.mqttService.start(); - } catch (Throwable $ex) { - throw $ex; - } - } - }); - t1.run(); + } } diff --git a/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java index f57b7bb6..5a2531fc 100644 --- a/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java +++ b/iot-broker/src/main/java/com/java110/broker/controller/HkISApiController.java @@ -1,30 +1,49 @@ package com.java110.broker.controller; -import cn.hutool.json.JSONObject; -import cn.hutool.json.XML; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; +import com.java110.broker.mqtt.*; +import com.java110.broker.utils.XmlUtils; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.mqtt.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Enumeration; import java.util.List; import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; @RestController public class HkISApiController { + + private static final Logger log = LoggerFactory.getLogger(HkISApiController.class); private static final String UPLOAD_DIR = "/Users/admin/workspace/MicroCommunityIot/iot-broker/src/main/resources/images/"; + @Autowired + MqttMessageIdGenerator messageIdGenerator; + @Value("${driver.mqtt.wait_time}") + private long waitTime; + @RequestMapping("/hc/barrier/request") public String printParameters(HttpServletRequest request) { + if (request instanceof MultipartHttpServletRequest) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 获取所有上传的文件 Map> fileMap = multipartRequest.getMultiFileMap(); + // 循环打印所有上传的文件 for (Map.Entry> entry : fileMap.entrySet()) { String paramName = entry.getKey(); @@ -41,7 +60,33 @@ public class HkISApiController { // 处理XML文件 try { String xmlContent = new String(file.getBytes()); - JSONObject jsonObject = XML.toJSONObject(xmlContent); + JSONObject jsonObject = XmlUtils.parseXmlToJsonObject(xmlContent); + if (!jsonObject.containsKey("EventNotificationAlert") + || !jsonObject.getJSONObject("EventNotificationAlert").containsKey("ANPR") + || !"ANPR".equals(jsonObject.getJSONObject("EventNotificationAlert").getString("eventType")) + ) { + return "Unsupported XML file"; + } + JSONObject ANPRObj = jsonObject.getJSONObject("EventNotificationAlert").getJSONObject("ANPR"); + String ipAddress = jsonObject.getJSONObject("EventNotificationAlert").getString("ipAddress"); + String licensePlate = ANPRObj.getString("licensePlate"); + String plateColor = ANPRObj.getString("plateColor"); + + JSONObject response = new JSONObject(); + response.put("carNum", licensePlate); + response.put("carType", "1003"); + response.put("machineCode", "E001"); + response.put("cmd", "barrierResult"); + response.put("taskId", UUID.randomUUID()); + if (!MqttMsgBack.connectMap.isEmpty()) { + MqttMsgBack.connectMap.forEach((key, cxt) -> { + try { + sendByChannel(cxt, "hc/barrier/response", response.toJSONString(), messageIdGenerator.nextMessageId()); + } catch (Exception e) { + e.printStackTrace(); + } + }); + }; System.out.println("JSON Content: " + jsonObject.toString()); } catch (IOException e) { e.printStackTrace(); @@ -71,4 +116,28 @@ public class HkISApiController { return "Parameters received and printed."; } + + public void sendByChannel(ChannelHandlerContext ctx, String topic, String sendMessage, Integer packetId) throws Exception { + + MqttRequest request = new MqttRequest(sendMessage.getBytes()); + ByteBuf byteBuf = Unpooled.buffer().writeBytes(request.getPayload()); + MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic, packetId); + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( + MqttMessageType.PUBLISH, + request.isDup(), + request.getQos(), + request.isRetained(), + 2); + MqttPublishMessage pubMessage = (MqttPublishMessage) MqttMessageFactory.newMessage(mqttFixedHeader, mqttPublishVariableHeader, byteBuf); + ctx.writeAndFlush(pubMessage); + cachePublishMsg(request.getQos(), byteBuf, mqttPublishVariableHeader, mqttFixedHeader, ctx); + } + + private void cachePublishMsg(MqttQoS qos, ByteBuf byteBuf, MqttPublishVariableHeader variableHeader, MqttFixedHeader mqttFixedHeaderInfo, ChannelHandlerContext context) { + //缓存一份消息,规定时间内没有收到ack,用作重发,重发时将isDup设置为true,代表重复消息 + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, mqttFixedHeaderInfo.remainingLength()); + MqttPublishMessage cachePubMessage = new MqttPublishMessage(fixedHeader, variableHeader, byteBuf); + ScheduledFuture scheduledFuture = TimerData.scheduledThreadPoolExecutor.scheduleAtFixedRate(new MonitorMsgTime(variableHeader.packetId(), cachePubMessage, context), waitTime, waitTime, TimeUnit.MILLISECONDS); + TimerData.scheduledFutureMap.put(variableHeader.packetId(), scheduledFuture); + } } diff --git a/iot-broker/src/main/java/com/java110/broker/model/BarrierPo.java b/iot-broker/src/main/java/com/java110/broker/model/BarrierPo.java new file mode 100644 index 00000000..9506cbfb --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/model/BarrierPo.java @@ -0,0 +1,166 @@ +/* + * Copyright 2017-2020 吴学文 and java110 team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.java110.broker.model; + +import java.io.Serializable; + +/** + * 类表述: Po 数据模型实体对象 基本保持与数据库模型一直 用于 增加修改删除 等时的数据载体 + * add by 吴学文 at 2023-09-21 01:05:11 mail: 928255095@qq.com + * open source address: https://gitee.com/wuxw7/MicroCommunity + * 官网:http://www.homecommunity.cn + * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下 + * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行 + */ +public class BarrierPo implements Serializable { + + private String heartbeatTime; + private String implBean; + private String machineId; + private String machineCode; + private String statusCd = "0"; + private String communityId; + private String machineName; + private String machineIp; + private Integer machinePort; + private String machineLoginName; + private String machinePassword; + private String direction; + private String boxId; + + private String monitorId; + private String monitorName; + + public Integer getMachinePort() { + return machinePort; + } + + public void setMachinePort(Integer machinePort) { + this.machinePort = machinePort; + } + + public String getMachineLoginName() { + return machineLoginName; + } + + public void setMachineLoginName(String machineLoginName) { + this.machineLoginName = machineLoginName; + } + + public String getMachinePassword() { + return machinePassword; + } + + public void setMachinePassword(String machinePassword) { + this.machinePassword = machinePassword; + } + + public String getHeartbeatTime() { + return heartbeatTime; + } + + public void setHeartbeatTime(String heartbeatTime) { + this.heartbeatTime = heartbeatTime; + } + + public String getImplBean() { + return implBean; + } + + public void setImplBean(String implBean) { + this.implBean = implBean; + } + + public String getMachineId() { + return machineId; + } + + public void setMachineId(String machineId) { + this.machineId = machineId; + } + + public String getMachineCode() { + return machineCode; + } + + public void setMachineCode(String machineCode) { + this.machineCode = machineCode; + } + + public String getStatusCd() { + return statusCd; + } + + public void setStatusCd(String statusCd) { + this.statusCd = statusCd; + } + + public String getCommunityId() { + return communityId; + } + + public void setCommunityId(String communityId) { + this.communityId = communityId; + } + + public String getMachineName() { + return machineName; + } + + public void setMachineName(String machineName) { + this.machineName = machineName; + } + + public String getMachineIp() { + return machineIp; + } + + public void setMachineIp(String machineIp) { + this.machineIp = machineIp; + } + + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + public String getBoxId() { + return boxId; + } + + public void setBoxId(String boxId) { + this.boxId = boxId; + } + + public String getMonitorId() { + return monitorId; + } + + public void setMonitorId(String monitorId) { + this.monitorId = monitorId; + } + + public String getMonitorName() { + return monitorName; + } + + public void setMonitorName(String monitorName) { + this.monitorName = monitorName; + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java index 755ea0ab..a8957287 100644 --- a/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MonitorMsgTime.java @@ -4,7 +4,8 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttPublishMessage; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.InetSocketAddress; import java.util.concurrent.ScheduledFuture; @@ -14,9 +15,8 @@ import java.util.concurrent.ScheduledFuture; * @description: 判断策略相关消息是否在规定时间段内发送,获取结束状态 * @create: 2021-01-07 16:09 **/ -@Slf4j public class MonitorMsgTime implements Runnable { - + private static final Logger log = LoggerFactory.getLogger(MonitorMsgTime.class); private Integer packetId; private MqttMessage mqttMessage; private ChannelHandlerContext ctx; diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java index 2dc6bc42..6b7dd86a 100644 --- a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttMsgBack.java @@ -1,6 +1,7 @@ package com.java110.broker.mqtt; -import cn.hutool.core.collection.CollUtil; +import com.java110.broker.service.MqttServiceHandler; +import com.java110.broker.utils.MqttCommonUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.mqtt.MqttConnAckMessage; @@ -24,7 +25,9 @@ import io.netty.handler.codec.mqtt.MqttTopicSubscription; import io.netty.handler.codec.mqtt.MqttUnsubAckMessage; import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; import io.netty.util.ReferenceCountUtil; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -68,10 +71,9 @@ import static io.netty.handler.codec.mqtt.MqttQoS.EXACTLY_ONCE; * 综上可知:发送端没有回复确认消息之说,只有发送消息,接收端没有发送消息之说,只有回复确认消息,搞清楚这个概念,在设置参数的时候就明了。 **/ -@Slf4j @Component public class MqttMsgBack { - + private static final Logger log = LoggerFactory.getLogger(MqttMsgBack.class); @Value("${driver.mqtt.user_name}") private String userName; @@ -81,6 +83,8 @@ public class MqttMsgBack { @Value("${driver.mqtt.wait_time}") private long waitTime; + @Autowired + private MqttServiceHandler mqttServiceHandler; /** * 功能描述:连接请求处理 */ @@ -218,13 +222,13 @@ public class MqttMsgBack { ServerMqttHandler.clientMap.remove(channelId); //删除订阅主题 Set topicSet = ctMap.get(channelId); - if (CollUtil.isNotEmpty(topicSet)) { + if (topicSet != null && !topicSet.isEmpty()) { for (String topic : topicSet) { if (subMap != null) { HashSet ids = subMap.get(topic); - if (CollUtil.isNotEmpty(ids)) { + if (ids != null && !ids.isEmpty()) { ids.remove(channelId); - if (CollUtil.isEmpty(ids)) { + if (ids == null || ids.isEmpty()) { subMap.remove(topic); } } @@ -268,6 +272,7 @@ public class MqttMsgBack { //构建PUBACK消息体 MqttPubAckMessage pubAck = new MqttPubAckMessage(mqttFixedHeaderBack, mqttMessageIdVariableHeaderBack); ctx.writeAndFlush(pubAck); + mqttServiceHandler.handleMessage(topicName, MqttCommonUtils.convertbyteBufToString(byteBuf)); break; //刚好一次 case EXACTLY_ONCE: @@ -409,9 +414,9 @@ public class MqttMsgBack { for (String topic : topics) { if (subMap != null) { HashSet ids = subMap.get(topic); - if (CollUtil.isNotEmpty(ids)) { + if (ids != null && !ids.isEmpty()) { ids.remove(id); - if (CollUtil.isEmpty(ids)) { + if (ids == null || ids.isEmpty()) { subMap.remove(topic); } } @@ -420,7 +425,7 @@ public class MqttMsgBack { qoSMap.remove(topic + "-" + id); } - if (CollUtil.isNotEmpty(topicSet)) { + if (topicSet != null && !topicSet.isEmpty()) { topicSet.remove(topic); } } diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttRequest.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttRequest.java new file mode 100644 index 00000000..f8e224ed --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttRequest.java @@ -0,0 +1,95 @@ +package com.java110.broker.mqtt; + +import io.netty.handler.codec.mqtt.MqttQoS; + +public class MqttRequest { + private boolean mutable = true; + private byte[] payload; + private MqttQoS qos; + private boolean retained; + private boolean dup; + private int messageId; + + public MqttRequest() { + this.qos = MqttQoS.AT_LEAST_ONCE; + this.retained = false; + this.dup = false; + this.setPayload(new byte[0]); + } + + public MqttRequest(byte[] payload) { + this.qos = MqttQoS.AT_LEAST_ONCE; + this.retained = false; + this.dup = false; + this.setPayload(payload); + } + + public byte[] getPayload() { + return this.payload; + } + + public void clearPayload() { + this.checkMutable(); + this.payload = new byte[0]; + } + + public void setPayload(byte[] payload) { + this.checkMutable(); + if (payload == null) { + throw new NullPointerException(); + } else { + this.payload = payload; + } + } + + public boolean isRetained() { + return this.retained; + } + + public void setRetained(boolean retained) { + this.checkMutable(); + this.retained = retained; + } + + public MqttQoS getQos() { + return this.qos; + } + + public void setQos(MqttQoS qos) { + this.qos = qos; + } + + public boolean isMutable() { + return this.mutable; + } + + public void setMutable(boolean mutable) { + this.mutable = mutable; + } + + protected void checkMutable() throws IllegalStateException { + if (!this.mutable) { + throw new IllegalStateException(); + } + } + + public boolean isDup() { + return this.dup; + } + + public void setDup(boolean dup) { + this.dup = dup; + } + + public int getMessageId() { + return this.messageId; + } + + public void setMessageId(int messageId) { + this.messageId = messageId; + } + + public String toString() { + return new String(this.payload); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java index 3eb3b0b9..2d7acd35 100644 --- a/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/MqttServer.java @@ -5,7 +5,8 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -17,10 +18,11 @@ import javax.annotation.PreDestroy; * @description: netty启动配置类 * @create: 2020-04-03 11:43 **/ -@Slf4j @Component public class MqttServer { + private static final Logger log = LoggerFactory.getLogger(MqttServer.class); + @Autowired private MqttServerChannelInitializer mqttServerChannelInitializer; @@ -30,7 +32,7 @@ public class MqttServer { private ChannelFuture future; - @Value("${driver.mqtt.socket_port}") + @Value("${driver.mqtt.socket_port:12001}") private int socketPort; public void start() { diff --git a/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java b/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java index 037c6cf5..6d81f0d2 100644 --- a/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java +++ b/iot-broker/src/main/java/com/java110/broker/mqtt/ServerMqttHandler.java @@ -1,6 +1,5 @@ package com.java110.broker.mqtt; -import cn.hutool.core.collection.CollUtil; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -9,7 +8,8 @@ import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -20,14 +20,14 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -@Slf4j @Component @ChannelHandler.Sharable public class ServerMqttHandler extends SimpleChannelInboundHandler { + private static final Logger log = LoggerFactory.getLogger(ServerMqttHandler.class); public static final ConcurrentHashMap clientMap = new ConcurrentHashMap(); - @Value("${driver.mqtt.address_list}") + @Value("${driver.mqtt.address_list:192.168.0.64}") private List addressList; @Autowired @@ -169,15 +169,15 @@ public class ServerMqttHandler extends SimpleChannelInboundHandler clientMap.remove(id); //删除订阅主题 Set topicSet = MqttMsgBack.ctMap.get(id); - if (CollUtil.isNotEmpty(topicSet)) { + if (topicSet != null && !topicSet.isEmpty()) { ConcurrentHashMap> subMap = MqttMsgBack.subMap; ConcurrentHashMap qoSMap = MqttMsgBack.qoSMap; for (String topic : topicSet) { if (subMap != null) { HashSet ids = subMap.get(topic); - if (CollUtil.isNotEmpty(ids)) { + if (!ids.isEmpty()) { ids.remove(id); - if (CollUtil.isEmpty(ids)) { + if (ids.isEmpty()) { subMap.remove(topic); } } diff --git a/iot-broker/src/main/java/com/java110/broker/service/HkISApiRequestService.java b/iot-broker/src/main/java/com/java110/broker/service/HkISApiRequestService.java new file mode 100644 index 00000000..8b36323e --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/service/HkISApiRequestService.java @@ -0,0 +1,4 @@ +package com.java110.broker.service; + +public interface HkISApiRequestService { +} diff --git a/iot-broker/src/main/java/com/java110/broker/service/MqttServiceHandler.java b/iot-broker/src/main/java/com/java110/broker/service/MqttServiceHandler.java new file mode 100644 index 00000000..1bd38e46 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/service/MqttServiceHandler.java @@ -0,0 +1,5 @@ +package com.java110.broker.service; + +public interface MqttServiceHandler { + void handleMessage(String topicName, String payload); +} diff --git a/iot-broker/src/main/java/com/java110/broker/service/impl/HkISApiRequestServiceImpl.java b/iot-broker/src/main/java/com/java110/broker/service/impl/HkISApiRequestServiceImpl.java new file mode 100644 index 00000000..5e91462e --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/service/impl/HkISApiRequestServiceImpl.java @@ -0,0 +1,8 @@ +package com.java110.broker.service.impl; + +import com.java110.broker.service.HkISApiRequestService; + +public class HkISApiRequestServiceImpl implements HkISApiRequestService { + + +} diff --git a/iot-broker/src/main/java/com/java110/broker/service/impl/MqttServiceHandlerImpl.java b/iot-broker/src/main/java/com/java110/broker/service/impl/MqttServiceHandlerImpl.java new file mode 100644 index 00000000..7cbb40cf --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/service/impl/MqttServiceHandlerImpl.java @@ -0,0 +1,64 @@ +package com.java110.broker.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.java110.broker.mqtt.JsonUtil; +import com.java110.broker.service.MqttServiceHandler; +import com.java110.broker.utils.ApacheHttpClientService; +import com.java110.dto.barrier.BarrierDto; +import com.java110.intf.barrier.IBarrierV1InnerServiceSMO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.List; + +@Service +public class MqttServiceHandlerImpl implements MqttServiceHandler { + @Autowired + private IBarrierV1InnerServiceSMO barrierService; + @Autowired + private ApacheHttpClientService clientService; + public static final String BARRIER_URL = "http://%s:%s"; + @Override + public void handleMessage(String topicName, String payload) { + if (!topicName.startsWith("hc/barrier/request/")) { + return; + } + System.out.println("topicName=" + topicName + ",payload=" + payload); + String machineCode = topicName.substring("hc/barrier/request/".length()); + BarrierDto barrierDto = new BarrierDto(); + barrierDto.setMachineCode(machineCode); + List barrierDtos = barrierService.queryBarriers(barrierDto); + if (barrierDtos == null || barrierDtos.size() < 1) { + return; + } + BarrierDto barrierPo = barrierDtos.get(0); + if (!JsonUtil.isJsonObject(payload)) { + System.out.println("payload not jsonobject , " + payload); + } + String baseUrl = String.format(BARRIER_URL, barrierPo.getMachineIp(), barrierPo.getMachinePort()); + JSONObject jsonStr = JSONObject.parseObject(payload); + switch (jsonStr.getString("cmd")) { + case "heartbeat": + break; + case "playTts": + try { + clientService.sendLcdRequestWithAuth(baseUrl, barrierPo.getMachineLoginName(), barrierPo.getMachinePassword(), jsonStr.getString("text")); + clientService.sendBroadcastRequestWithAuth(baseUrl, barrierPo.getMachineLoginName(), barrierPo.getMachinePassword(), jsonStr.getString("text")); + } catch (IOException e) { + e.printStackTrace(); + } + break; + case "openBarrier": + try { + clientService.sendOpenBarrierRequestWithAuth(baseUrl, barrierPo.getMachineLoginName(), barrierPo.getMachinePassword()); + } catch (IOException e) { + e.printStackTrace(); + } + break; + case "barrierResult": + break; + } + } + +} diff --git a/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java b/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java index af3d749e..4e8a20a4 100644 --- a/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java +++ b/iot-broker/src/main/java/com/java110/broker/utils/ApacheHttpClientService.java @@ -1,5 +1,7 @@ package com.java110.broker.utils; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.apache.http.HttpEntity; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -12,9 +14,10 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; +import org.springframework.stereotype.Service; import java.io.IOException; - +@Service public class ApacheHttpClientService { public String sendRequestWithAuth(String url, String username, String password) throws IOException { @@ -39,7 +42,7 @@ public class ApacheHttpClientService { return null; } - public String sendPostRequestWithAuth(String url, String username, String password, String requestBody) throws IOException { + public String sendPostRequestWithAuth(String url, String username, String password, String requestBody, String contentType) throws IOException { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( @@ -49,7 +52,7 @@ public class ApacheHttpClientService { try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()) { HttpPut request = new HttpPut(url); request.setEntity(new StringEntity(requestBody, "UTF-8")); - request.setHeader("Content-Type", "application/json"); + request.setHeader("Content-Type", contentType); try (CloseableHttpResponse response = httpClient.execute(request)) { HttpEntity entity = response.getEntity(); if (entity != null) { @@ -64,6 +67,52 @@ public class ApacheHttpClientService { return null; } + public void sendLcdRequestWithAuth(String baseUrl, String username, String password, String text) throws IOException { + String requestUrl = baseUrl + "/ISAPI/Parking/channels/1/LCD"; + JSONObject customContent = new JSONObject(); + customContent.put("id", 1); + customContent.put("content", text); + + JSONArray customContentList = new JSONArray(); + JSONObject customContentListObj = new JSONObject(); + customContentListObj.put("CustomContent", customContent); + customContentList.add(customContentListObj); + + JSONObject lcd = new JSONObject(); + lcd.put("CustomContentList", customContentList); + + JSONObject lcdObject = new JSONObject(); + lcdObject.put("LCD", lcd); + sendPostRequestWithAuth(requestUrl, username, password, lcdObject.toString(), "application/json"); + } + + public void sendBroadcastRequestWithAuth(String baseUrl, String username, String password, String text) throws IOException { + String requestUrl = baseUrl + "/ISAPI/Parking/channels/1/voiceBroadcastInfo/combinateBroadcast"; + JSONObject BroadcastInfo = new JSONObject(); + BroadcastInfo.put("id", 1); + BroadcastInfo.put("customValue", text); + + JSONArray BroadcastInfoList = new JSONArray(); + JSONObject BroadcastInfoListObj = new JSONObject(); + BroadcastInfoListObj.put("BroadcastInfo", BroadcastInfo); + BroadcastInfoList.add(BroadcastInfoListObj); + + JSONObject Broadcast = new JSONObject(); + Broadcast.put("BroadcastInfoList", BroadcastInfoList); + + JSONObject broadcastObject = new JSONObject(); + broadcastObject.put("CombinateBroadcast", Broadcast); + sendPostRequestWithAuth(requestUrl, username, password, broadcastObject.toString(), "application/json"); + } + + public void sendOpenBarrierRequestWithAuth(String baseUrl, String username, String password) throws IOException { + String requestUrl = baseUrl + "/ISAPI/Parking/channels/1/barrierGate"; + String requestXml = "\n" + + " open\n" + + ""; + sendPostRequestWithAuth(requestUrl, username, password, requestXml, "application/xml"); + } + public static void main(String[] args) throws IOException { ApacheHttpClientService ac = new ApacheHttpClientService(); @@ -77,8 +126,10 @@ public class ApacheHttpClientService { // String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Event/notification/httpHosts/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); // String res = ac.sendRequestWithAuth("http://192.168.0.64/ISAPI/Event/notification/httpHosts/capabilities?format=json", "admin", "Zaq1xsw2cde3vfr4"); // String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/barrierGate", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/barrier.xml")); -// String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/voiceBroadcastInfo/combinateBroadcast", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/voice.json")); - String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/LCD", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/lcd-all.json")); - System.out.println(res); +// String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/voiceBroadcastInfo/combinateBroadcast", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/voice.json"), "application/json"); + ac.sendBroadcastRequestWithAuth("http://192.168.0.64", "admin", "Zaq1xsw2cde3vfr4", "欢迎关联"); +// String res = ac.sendPostRequestWithAuth("http://192.168.0.64/ISAPI/Parking/channels/1/LCD", "admin", "Zaq1xsw2cde3vfr4", XmlUtils.readBarrierXml("template/lcd-all.json"), "application/json"); + +// System.out.println(res); } } diff --git a/iot-broker/src/main/java/com/java110/broker/utils/MqttCommonUtils.java b/iot-broker/src/main/java/com/java110/broker/utils/MqttCommonUtils.java new file mode 100644 index 00000000..5a59da21 --- /dev/null +++ b/iot-broker/src/main/java/com/java110/broker/utils/MqttCommonUtils.java @@ -0,0 +1,15 @@ +package com.java110.broker.utils; + +import io.netty.buffer.ByteBuf; + +public class MqttCommonUtils { + + public static String convertbyteBufToString(ByteBuf byteBuf) { + if (byteBuf == null) { + return null; + } + byte[] tmp = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(tmp); + return new String(tmp); + } +} diff --git a/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java b/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java index 77b70d45..371002c0 100644 --- a/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java +++ b/iot-broker/src/main/java/com/java110/broker/utils/XmlUtils.java @@ -1,13 +1,17 @@ package com.java110.broker.utils; +import com.alibaba.fastjson.JSONObject; import org.dom4j.Document; +import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter; import org.springframework.core.io.ClassPathResource; import java.io.*; +import java.util.Iterator; public class XmlUtils { @@ -76,5 +80,69 @@ public class XmlUtils { return contentBuilder.toString(); } + + public static JSONObject parseXmlToJsonObject(String xmlContent) { + try { + // 解析XML字符串 + Document document = DocumentHelper.parseText(xmlContent); + Element root = document.getRootElement(); + + // 将XML元素转换为JSONObject + JSONObject jsonObject = new JSONObject(); + parseElement(root, jsonObject); + + return jsonObject; + } catch (DocumentException e) { + e.printStackTrace(); + return new JSONObject(); + } + } + + private static void parseElement(Element element, JSONObject jsonObject) { + // 获取元素的名称和文本内容 + String elementName = element.getName(); + String elementText = element.getTextTrim(); + + // 如果元素有子元素,则递归处理 + if (element.elements().size() > 0) { + JSONObject childObject = new JSONObject(); + for (Iterator it = element.elementIterator(); it.hasNext(); ) { + Element childElement = it.next(); + parseElement(childElement, childObject); + } + jsonObject.put(elementName, childObject); + } else { + // 如果元素没有子元素,则直接添加文本内容 + jsonObject.put(elementName, elementText); + } + + // 处理属性 + if (element.attributes().size() > 0) { + for (Iterator it = element.attributeIterator(); it.hasNext(); ) { + org.dom4j.Attribute attribute = (org.dom4j.Attribute) it.next(); + jsonObject.put("@" + attribute.getName(), attribute.getValue()); + } + } + } + + public static JSONObject readXmlFileToJsonObject(String filePath) { + try { + // 读取XML文件 + ClassPathResource resource = new ClassPathResource(filePath); + InputStream inputStream = resource.getInputStream(); + SAXReader reader = new SAXReader(); + Document document = reader.read(inputStream); + + // 将XML文档转换为JSONObject + Element root = document.getRootElement(); + JSONObject jsonObject = new JSONObject(); + parseElement(root, jsonObject); + + return jsonObject; + } catch (DocumentException | IOException e) { + e.printStackTrace(); + return new JSONObject(); + } + } } diff --git a/iot-broker/src/main/resources/application-dev.yml b/iot-broker/src/main/resources/application-dev.yml new file mode 100644 index 00000000..bdf90f0d --- /dev/null +++ b/iot-broker/src/main/resources/application-dev.yml @@ -0,0 +1,67 @@ +eureka: + instance: + leaseRenewalIntervalInSeconds: 10 + leaseExpirationDurationInSeconds: 30 + preferIpAddress: true + ip-address: 127.0.0.1 + instanceId: ${spring.cloud.client.ip-address}:${server.port} + client: + serviceUrl: +# defaultZone: http://dev.java110.com:8761/eureka/ + defaultZone: http://localhost:8761/eureka/ +server: + port: 12000 + tomcat: + uri-encoding: UTF-8 +logging: + level: + root: debug + +spring: + profiles: + active: share + http: + encoding: + charset: UTF-8 + enabled: true + force: true + application: + name: iot-broker + redis: + database: 4 + host: 192.168.56.21 + port: 6379 + password: park + pool: + max-active: 300 + max-wait: 10000 + max-idle: 100 + min-idle: 0 + timeout: 0 + maxWaitMillis: 20000 + datasource: + url: jdbc:mysql://bj-cdb-dnfgsdho.sql.tencentcdb.com:21302/hc_iot?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 + username: mysql.park + password: aa1T3ETx5rX8#2 + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver + druid: + initial-size: 5 + max-active: 10 + min-idle: 5 + max-wait: 60000 + +driver: + mqtt: + socket_port: 12001 + wait_time: 3000 + address_list: 127.0.0.1 + user_name: admin + password: public + +feign: + client: + config: + default: + connect-timeout: 10000 + read-timeout: 20000 \ No newline at end of file diff --git a/iot-broker/src/main/resources/application.yml b/iot-broker/src/main/resources/application.yml index 729fb0ba..caf4dfcd 100644 --- a/iot-broker/src/main/resources/application.yml +++ b/iot-broker/src/main/resources/application.yml @@ -1,12 +1,3 @@ spring: profiles: - active: dev -server: - port: 12000 -driver: - mqtt: - socket_port: 12001 - wait_time: 3000 - address_list: 127.0.0.1 - user_name: admin - password: public \ No newline at end of file + active: dev \ No newline at end of file diff --git a/iot-broker/src/main/resources/images/licensePlatePicture.jpg b/iot-broker/src/main/resources/images/licensePlatePicture.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d3794778518b86fb9c0f8aa9b39da51318ccc125 GIT binary patch literal 2312 zcmbW!c{JOJ76D>7=7 z#1<5_c8nLQmd;ZeQFKvDMyg6%Yw6;dnRn*AKi_-bbMF1;-hV##?o8~w08#)AMT9B> zuA!=;s)^JK(CPCvt9vyVX;Nbu*fXBUqEWhwXBkIULB8;*g5#1 zqQ9t$#{nTVHL+-{yMci_hZaEN{Lk6p18`{|0%!n(v;he?2n+}9^n%I&03-?eBf!4{ zk^n;_rJ&L>vT_Q51PBb4fPf_>A&}k8_}v)*flDgxH?fma@;C?8jzpL;v+qiy?Hjw5 zNl!mu%+5z8$;hgxs;Pgcb3hlXr*DosWP!J|I(FQ_kwA2ECVP6FI_>S_8x$OJff7m$ zqhE@?91|PINKQ$;c0KI|Dy>Ss;+6e-`vvL*52`;=V9-ozW#y1 z$AVGe*t7A8$>%e(bE4no#cvkgeq32yTi@9Hw6zTaz<+Xf`=6ly@W6LH5)cR&0{z_s zl8D(YFdQPe-$Y8$&I5WbQc2sCDUGntzT4O>gEk|5P(B~^R8|FJKBM#TchVoC{|=P& ze~JDA{pHzt4(tJgb{__Y12({o?#a=QHLw}tTLXvwUmsB%OL>8!RX3S5tuCw4Heht4Ase{^N6BQ|gBYWGw z>Zjk#JCfmc#=r2o-C&K|x7u6ngF_^Eh&Gw}3uBBvfEUSjwtL04tDVVrxZZYbgrqh) zGFws=IZ^Bx2V6Qjrr(Z+Y%F??)Ej41zF?arf1=>RvFO7D_pl}-vF7^W#GfBfkSG1R zY<$leupDm{G?qO?5;xRJDbLC*x2`30RMNKEt*vJBlSIs)#azpfh*<5iS0ysmCeCV< zE~p(;}_~;bU&kB=1Ztp{jDA-JYYp;ft?os9vOoP?|dBg4W!C3(<#p+0G-fV)43!z{$A z4Y?dT`o!8hN?(Jxso*V=7u<&r6>8rXbL^-%N1xMM{C~DDC4Yg2F z@nP+-{;&^pvWxasg10(`?vNvf;=31JN)??xS8d4W&2c?-F+W6}(j}v%2D@wCaT3f& zCUJM=lfiLmc<}JgMYZx|b#ci6I z?wOluG-kExa`*Tx%>@fZx{HN^=&JJZl^G@QJihYPAvmj`K&C?g+}6Ia+z%gZ);x00~w97qMTA}VA-wKp-G zK7uQY7K;>!g2oYhWW^Z{#+8vI@l;Y*8B;-x&>9A&S@QSM1@+m2+VNfcH#a{1W?Gw#L;Gw?rfiH*{i9smc#M1GiNbeY>isQt zh}WH-!-g*Zln#hsT&^}8KTIF5JGw+HpvCr4pS_7G`N=sR;#0om>4LRhU8@G|^|^f* z+JY$lJe$do!s;Tv3VTdGMRT^-N@eW0RrlS8Bs2+i2VilJP?qZE(~hB_l$bE8$0uR2 zM}`mt?y=TaX`MqWM4vRTW&JK-fp-+K?;Q zhC!M}{IDI#FL_)zhPyar1}`=|n|i1(Szq56d~)+Gp1bfY+hOb{eak)u zoy0SsR2UeC5FYni*EkecYh*4E_X2pN>>2S?4d*Sfdx^{wqpM1xyZ1QD|BeEyoC!wVCphU#i>Z3u5Yw2wboRGb2w> zGEr^3_rQoF!MxW#2-;9}28Q=IZL+pVJZ(9km8uH184P?m6BYL;z=OZYCMDPXZLMO$ IduI~(7j_mY&Hw-a literal 0 HcmV?d00001 diff --git a/iot-broker/src/main/resources/java110.properties b/iot-broker/src/main/resources/java110.properties new file mode 100644 index 00000000..e76452d1 --- /dev/null +++ b/iot-broker/src/main/resources/java110.properties @@ -0,0 +1,4 @@ +java110.mappingPath=classpath:mapper/car/*.xml,classpath:mapper/service/*.xml +java110.testSwitch=ON + + diff --git a/iot-broker/src/main/resources/template/lcd-all.json b/iot-broker/src/main/resources/template/lcd-all.json index 4395f8fd..bf1b5a16 100644 --- a/iot-broker/src/main/resources/template/lcd-all.json +++ b/iot-broker/src/main/resources/template/lcd-all.json @@ -8,77 +8,20 @@ "CustomContentList": [{ "CustomContent": { "id": 1, - "content": "欢迎光临 陕A2M297", - "fontSizeLine": 40, - "fontColorLine": { - "R": 255, - "G": 255, - "B": 255 - }, - "fontBoldLine": false, - "passVehicleDisplayEnabled": false + "content": "欢迎光临 郝思博" } }], - "fontSize": 50, - "fontColor": { - "R": 0, - "G": 0, - "B": 255 - }, - "MediaDataInfo": { - "cycleIntervalTime": 60, - "cyclePlayOrder": [] - }, - "ctrlMode": "camera", - "allowListDisplayEnabled": false, - "blockListDisplayEnabled": false, - "temporaryListDisplayEnabled": false, - "fanSpeedLevel": "close", - "temperatureThreshold": 0, - "screenWidth": 0, - "screenHeight": 0, - "softwareVersion": "V3.0.0_build20240902STD_|240910", - "autoSwitchFreeEnabled": true, - "BackBright": { - "enabled": false, - "ctrlMode": "manualAndTime", - "value": 0, - "timeCtrlEnabled": false, - "TimeCtrlList": [{ - "TimeCtrl": { - "startTime": "00:00", - "endTime": "00:00", - "value": 0, - "vehiclePassingValue": 0 - } - }] - }, - "displayTime": 20, "HintContentList": [{ "HintContent": { "id": 1, "content": "自动识别", - "contentType": "free", - "fontSizeLine": 50, - "fontColorLine": { - "R": 255, - "G": 255, - "B": 255 - }, - "fontBoldLine": false + "contentType": "free" } }, { "HintContent": { "id": 2, "content": "一车一杆", - "contentType": "free", - "fontSizeLine": 50, - "fontColorLine": { - "R": 255, - "G": 255, - "B": 255 - }, - "fontBoldLine": false + "contentType": "free" } }] } diff --git a/iot-broker/src/main/resources/template/voice.json b/iot-broker/src/main/resources/template/voice.json index 323a9f91..1b8a82b9 100644 --- a/iot-broker/src/main/resources/template/voice.json +++ b/iot-broker/src/main/resources/template/voice.json @@ -2,7 +2,7 @@ "CombinateBroadcast": { "BroadcastInfoList": [{ "BroadcastInfo": { - "customValue": "陕A 2M297, 应缴费金额 1200" + "customValue": "欢 迎 光 临" } }] } diff --git a/iot-web/public/components/car/addBarrier/addBarrier.html b/iot-web/public/components/car/addBarrier/addBarrier.html index dab45e48..b9aaeb53 100644 --- a/iot-web/public/components/car/addBarrier/addBarrier.html +++ b/iot-web/public/components/car/addBarrier/addBarrier.html @@ -33,6 +33,33 @@ class="form-control"> +

+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+