From 413818248aa18471df1df69976a0fbd93f66da93 Mon Sep 17 00:00:00 2001 From: xiwa Date: Mon, 4 Jul 2022 11:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E5=A4=87=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - .../6260396d67aced2696184053/converter.js | 29 +++++ iot-auth-server/pom.xml | 2 +- .../controller/AuthServerController.java | 9 ++ .../oauth/service/SaOAuth2TemplateImpl.java | 9 ++ .../oauth/service/StpInterfaceImpl.java | 9 ++ .../java/cc/iotkit/oauth/vo/UserInfoVo.java | 9 ++ .../src/main/java/cc/iotkit/utils/SoMap.java | 9 ++ iot-common/pom.xml | 2 +- .../main/java/cc/iotkit/common/Constants.java | 19 ++- iot-components/iot-component-base/pom.xml | 2 +- .../iotkit/comp/AbstractDeviceComponent.java | 9 ++ .../java/cc/iotkit/comp/IDeviceComponent.java | 9 ++ .../cc/iotkit/comp/utils/SpringUtils.java | 9 ++ .../iot-component-converter/pom.xml | 2 +- .../main/java/cc/iotkit/converter/Device.java | 9 ++ .../cc/iotkit/converter/DeviceMessage.java | 9 ++ .../cc/iotkit/converter/ScriptConverter.java | 9 ++ iot-components/iot-component-server/pom.xml | 7 +- .../main/java/cc/iotkit/comps/ApiTool.java | 9 ++ .../cc/iotkit/comps/BizComponentManager.java | 9 ++ .../cc/iotkit/comps/ComponentManager.java | 9 ++ .../cc/iotkit/comps/DeviceMessageHandler.java | 9 ++ .../java/cc/iotkit/comps/DeviceRouter.java | 9 ++ .../iotkit/comps/config/ComponentConfig.java | 10 ++ .../comps/service/DeviceBehaviourService.java | 11 +- .../comps/service/DeviceConfigService.java | 75 +++++++++++ .../comps/service/DeviceMessageConsumer.java | 77 ++++------- .../comps/service/PropertyPersistService.java | 84 ++++++++++++ .../service/ReportRecordPersistService.java | 40 ++++++ iot-components/iot-ctwing-component/pom.xml | 2 +- .../dependency-reduced-pom.xml | 10 +- iot-components/iot-emqx-component/pom.xml | 2 +- .../dependency-reduced-pom.xml | 4 +- iot-components/iot-http-biz-component/pom.xml | 2 +- .../cc/iotkit/comp/biz/HttpBizComponent.java | 9 ++ .../java/cc/iotkit/comp/biz/HttpConfig.java | 9 ++ .../dependency-reduced-pom.xml | 8 +- iot-components/iot-mqtt-component/pom.xml | 2 +- .../java/cc/iotkit/comp/mqtt/MqttConfig.java | 9 ++ .../iotkit/comp/mqtt/MqttDeviceComponent.java | 9 ++ .../cc/iotkit/comp/mqtt/MqttVerticle.java | 14 ++ .../comp/mqtt/TransparentConverter.java | 9 ++ .../cc/iotkit/comp/mqtt/TransparentMsg.java | 9 ++ iot-components/pom.xml | 2 +- iot-data-service/iot-dao/pom.xml | 2 +- .../cc/iotkit/dao/DeviceConfigRepository.java | 21 +++ .../java/cc/iotkit/dao/UserInfoCache.java | 9 ++ .../java/cc/iotkit/dao/config/EmbeddedEs.java | 9 ++ iot-data-service/iot-device-dao/pom.xml | 23 ++++ .../main/java/cc/iotkit/data/ProductDao.java | 51 ++++++++ iot-data-service/iot-model/pom.xml | 4 +- .../cc/iotkit/model/device/DeviceConfig.java | 50 ++++++++ .../cc/iotkit/model/device/DeviceGroup.java | 9 ++ .../cc/iotkit/model/device/VirtualDevice.java | 9 ++ .../device/message/ThingModelMessage.java | 3 + .../java/cc/iotkit/model/stats/DataItem.java | 9 ++ .../java/cc/iotkit/model/stats/TimeData.java | 9 ++ iot-data-service/pom.xml | 3 +- iot-message-bus/pom.xml | 2 +- .../java/cc/iotkit/mq/ConsumerHandler.java | 9 ++ .../java/cc/iotkit/mq/vertx/BeanCodec.java | 4 +- .../java/cc/iotkit/mq/vertx/VertxManager.java | 9 ++ .../cc/iotkit/mq/vertx/VertxMqConsumer.java | 1 + .../cc/iotkit/mq/vertx/VertxMqProducer.java | 2 +- iot-package/pom.xml | 2 +- iot-rule-engine/pom.xml | 2 +- .../iotkit/ruleengine/action/HttpAction.java | 9 ++ .../handler/RuleDeviceConsumer.java | 9 ++ .../iotkit/ruleengine/task/TaskManager.java | 9 ++ iot-standalone/pom.xml | 2 +- .../manager/config/EmbeddedRedisConfig.java | 9 ++ .../manager/config/SaTokenConfigure.java | 9 ++ .../manager/controller/DeviceController.java | 45 +++++++ .../controller/ProtocolController.java | 9 ++ .../manager/controller/SpaceController.java | 9 ++ .../controller/ThirdAuthController.java | 9 ++ .../controller/UserInfoController.java | 9 ++ .../manager/model/query/DeviceQuery.java | 9 ++ .../iotkit/manager/model/stats/MainStats.java | 9 ++ .../manager/service/DeferredDataConsumer.java | 9 ++ .../iotkit/manager/service/DeviceService.java | 120 +++++++++++------- .../manager/service/ExampleDataInit.java | 9 ++ .../src/main/resources/application-dev.yml | 57 +++++++++ .../src/main/resources/application.yml | 55 ++++++++ iot-test-tool/iot-test-mqtt/pom.xml | 2 +- .../java/cc/iotkit/test/mqtt/Simulator.java | 33 +++-- .../cc/iotkit/test/mqtt/model/Request.java | 9 ++ .../cc/iotkit/test/mqtt/model/Response.java | 9 ++ .../test/mqtt/performance/ConnectionTest.java | 24 ++-- .../test/mqtt/performance/ReportTest.java | 2 +- .../cc/iotkit/test/mqtt/service/Gateway.java | 8 ++ .../test/mqtt/service/MessageHandler.java | 9 ++ .../iotkit/test/mqtt/service/ReportTask.java | 9 ++ .../cc/iotkit/test/mqtt/service/Vertxs.java | 9 ++ iot-test-tool/pom.xml | 2 +- iot-virtual-device/pom.xml | 2 +- .../iotkit/virtualdevice/VirtualManager.java | 8 +- pom.xml | 8 +- 99 files changed, 1212 insertions(+), 165 deletions(-) create mode 100644 iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java create mode 100644 iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java create mode 100644 iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java create mode 100644 iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java create mode 100644 iot-data-service/iot-device-dao/pom.xml create mode 100644 iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java create mode 100644 iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java create mode 100644 iot-standalone/src/main/resources/application-dev.yml create mode 100644 iot-standalone/src/main/resources/application.yml diff --git a/.gitignore b/.gitignore index 56586457..b1006f56 100755 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,6 @@ hs_err_pid* .idea target *.iml -*.yml log data/elasticsearch .init diff --git a/data/converters/6260396d67aced2696184053/converter.js b/data/converters/6260396d67aced2696184053/converter.js index a2353f39..1aaba5cd 100644 --- a/data/converters/6260396d67aced2696184053/converter.js +++ b/data/converters/6260396d67aced2696184053/converter.js @@ -63,6 +63,30 @@ this.decode = function (msg) { time: new Date().getTime(), code: payload.code }; + }else if(topic.endsWith("/config/set_reply")){ + //设备配置设置回复 + return { + mid: msg.mid, + productKey: msg.productKey, + deviceName: msg.deviceName, + type:"config", + identifier: "set_reply", + occur: new Date().getTime(), + time: new Date().getTime(), + code: payload.code + }; + }else if(topic.endsWith("/config/get")){ + //设备配置获取 + return { + mid: msg.mid, + productKey: msg.productKey, + deviceName: msg.deviceName, + type:"config", + identifier: "get", + occur: new Date().getTime(), + time: new Date().getTime(), + data: {}, + }; } else if (topic.endsWith("_reply")) { //服务回复 return { @@ -119,7 +143,12 @@ this.encode = function (service,device) { }else if(type=="service"){ method+=identifier; topic+=identifier; + }else if(type=="config"){ + //设备配置下发 + method+=identifier; + topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/config/"+identifier; } + for(var p in service.params){ params[p]=service.params[p]; } diff --git a/iot-auth-server/pom.xml b/iot-auth-server/pom.xml index 37c7953a..fb3111e3 100644 --- a/iot-auth-server/pom.xml +++ b/iot-auth-server/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java b/iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java index 6cd9de0c..324c2e8f 100644 --- a/iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java +++ b/iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.oauth.controller; import cc.iotkit.common.utils.JsonUtil; diff --git a/iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java b/iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java index 1a266abb..a9fc09fc 100644 --- a/iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java +++ b/iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.oauth.service; import cc.iotkit.common.Constants; diff --git a/iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java b/iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java index 2ce9bd51..8294a72f 100644 --- a/iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java +++ b/iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.oauth.service; import cc.iotkit.dao.UserInfoCache; diff --git a/iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java b/iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java index 36190895..547090e4 100644 --- a/iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java +++ b/iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.oauth.vo; import lombok.AllArgsConstructor; diff --git a/iot-auth-server/src/main/java/cc/iotkit/utils/SoMap.java b/iot-auth-server/src/main/java/cc/iotkit/utils/SoMap.java index 06ed14bd..f7fdfe73 100644 --- a/iot-auth-server/src/main/java/cc/iotkit/utils/SoMap.java +++ b/iot-auth-server/src/main/java/cc/iotkit/utils/SoMap.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.utils; import java.lang.reflect.Field; diff --git a/iot-common/pom.xml b/iot-common/pom.xml index e1889e96..0904079d 100644 --- a/iot-common/pom.xml +++ b/iot-common/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-common/src/main/java/cc/iotkit/common/Constants.java b/iot-common/src/main/java/cc/iotkit/common/Constants.java index a48292f4..b8af04ab 100644 --- a/iot-common/src/main/java/cc/iotkit/common/Constants.java +++ b/iot-common/src/main/java/cc/iotkit/common/Constants.java @@ -74,6 +74,21 @@ public interface Constants { */ String THING_MODEL_MESSAGE_TOPIC = "device_thing"; + /** + * 设备属性上报消息的topic + */ + String DEVICE_PROPERTY_REPORT_TOPIC = "device_property_report"; + + /** + * 不含消息内容的设备上报记录的topic,用于统计 + */ + String DEVICE_REPORT_RECORD_TOPIC = "device_report_record"; + + /** + * 设备配置消息topic + */ + String DEVICE_CONFIG_TOPIC = "device_config"; + /** * http消费设备信息的topic */ @@ -102,7 +117,7 @@ public interface Constants { /** * 三方平台openUid名称 */ - enum ThirdOpenUid{ + enum ThirdOpenUid { duerosOpenUid("小度OpenUid"), aligenieOpenUid("天猫精灵OpenUid"), miiotOpenUid("小爱OpenUid"); @@ -191,7 +206,7 @@ public interface Constants { String SET_OPEN_UID = "/setOpenUid"; } - interface MQTT { + interface MQTT { String DEVICE_SUBSCRIBE_TOPIC = "^/sys/.+/.+/c/#$"; } } diff --git a/iot-components/iot-component-base/pom.xml b/iot-components/iot-component-base/pom.xml index 74b0a514..a36620e9 100644 --- a/iot-components/iot-component-base/pom.xml +++ b/iot-components/iot-component-base/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java index 9a572914..07559f25 100644 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java +++ b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp; import cc.iotkit.comp.model.AuthInfo; diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java index 8cc058af..ca7c960f 100644 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java +++ b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp; import cc.iotkit.comp.model.AuthInfo; diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java index 3553337a..14d99ae4 100644 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java +++ b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.utils; import org.springframework.aop.framework.AopContext; diff --git a/iot-components/iot-component-converter/pom.xml b/iot-components/iot-component-converter/pom.xml index 9081ef3e..d6239425 100644 --- a/iot-components/iot-component-converter/pom.xml +++ b/iot-components/iot-component-converter/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java index e8e5e712..e5d30661 100644 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java +++ b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.converter; import lombok.AllArgsConstructor; diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java index a5f3ce66..4967109c 100644 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java +++ b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.converter; import lombok.Data; diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConverter.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConverter.java index 4281e3b0..361cf611 100644 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConverter.java +++ b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConverter.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.converter; import cc.iotkit.common.thing.ThingService; diff --git a/iot-components/iot-component-server/pom.xml b/iot-components/iot-component-server/pom.xml index fd6e9792..f6ed763a 100644 --- a/iot-components/iot-component-server/pom.xml +++ b/iot-components/iot-component-server/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 @@ -92,6 +92,11 @@ iot-message-bus + + cc.iotkit + iot-device-dao + + \ No newline at end of file diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java index c2300535..54f2bcc4 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps; import cc.iotkit.common.Constants; diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java index 3d3a9113..09d98e13 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps; diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java index 1827c632..653122f3 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps; diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java index dc7c02fe..f3a25f97 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps; import cc.iotkit.common.exception.BizException; diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java index 51134a0e..2050443b 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps; import cc.iotkit.comp.IComponent; diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java index b8f0ffa2..489e2003 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java @@ -1,5 +1,6 @@ package cc.iotkit.comps.config; +import cc.iotkit.model.device.message.DeviceReport; import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.mq.MqConsumer; import cc.iotkit.mq.MqProducer; @@ -53,4 +54,13 @@ public class ComponentConfig { return new VertxMqConsumer<>(ThingModelMessage.class); } + @Bean("deviceReportProducer") + public MqProducer getDeviceReportProducer() { + return new VertxMqProducer<>(DeviceReport.class); + } + + @Bean("deviceReportConsumer") + public MqConsumer getDeviceReportConsumer() { + return new VertxMqConsumer<>(DeviceReport.class); + } } diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java index 820c334b..668786e7 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps.service; import cc.iotkit.common.Constants; @@ -194,11 +203,9 @@ public class DeviceBehaviourService { if (online) { device.getState().setOnline(true); device.getState().setOnlineTime(System.currentTimeMillis()); -// deviceStateHolder.online(device.getDeviceId()); } else { device.getState().setOnline(false); device.getState().setOfflineTime(System.currentTimeMillis()); -// deviceStateHolder.offline(device.getDeviceId()); } deviceInfoRepository.save(device); diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java new file mode 100644 index 00000000..ab224b75 --- /dev/null +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java @@ -0,0 +1,75 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.comps.service; + +import cc.iotkit.common.Constants; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.JsonUtil; +import cc.iotkit.comps.DeviceComponentManager; +import cc.iotkit.dao.DeviceConfigRepository; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.message.ThingModelMessage; +import cc.iotkit.mq.ConsumerHandler; +import cc.iotkit.mq.MqConsumer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.Map; + +/** + * 设备配置服务 + */ +@Slf4j +@Service +public class DeviceConfigService implements ConsumerHandler { + + @Autowired + private MqConsumer configMessageConsumer; + + @Autowired + public DeviceComponentManager deviceComponentManager; + + @Autowired + private DeviceConfigRepository deviceConfigRepository; + + @PostConstruct + public void init() { + configMessageConsumer.consume(Constants.DEVICE_CONFIG_TOPIC, this); + } + + @Override + public void handler(ThingModelMessage msg) { + try { + String identifier = msg.getIdentifier(); + if (ThingModelMessage.ID_CONFIG_GET.equals(identifier)) { + //收到设备获取配置消息,回复配置信息给设备 + DeviceConfig deviceConfig = deviceConfigRepository.findByDeviceId(msg.getDeviceId()); + if (deviceConfig == null) { + return; + } + + Map config = JsonUtil.parse(deviceConfig.getConfig(), Map.class); + ThingService service = ThingService.builder() + .productKey(msg.getProductKey()) + .deviceName(msg.getDeviceName()) + .identifier(ThingModelMessage.ID_CONFIG_GET + "_reply") + .type(ThingModelMessage.TYPE_CONFIG) + .mid(msg.getMid()) + .params(config) + .build(); + deviceComponentManager.send(service); + } + } catch (Throwable e) { + log.error("consumer device config msg error", e); + } + } +} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java index 4b87943e..fbb4701f 100644 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java @@ -1,21 +1,28 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comps.service; import cc.iotkit.common.Constants; -import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.dao.*; import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.DeviceProperty; import cc.iotkit.model.device.message.DeviceReport; import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.mq.ConsumerHandler; import cc.iotkit.mq.MqConsumer; +import cc.iotkit.mq.MqProducer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; -import java.util.Map; import java.util.UUID; @Slf4j @@ -24,18 +31,14 @@ public class DeviceMessageConsumer implements ConsumerHandler @Lazy @Autowired private ThingModelMessageRepository messageRepository; - @Lazy - @Autowired - private DevicePropertyRepository propertyRepository; - @Lazy - @Autowired - private DeviceReportRepository deviceReportRepository; - @Autowired - private DeviceDao deviceDao; @Autowired private DeviceCache deviceCache; @Autowired private MqConsumer thingModelMessageConsumer; + @Autowired + private MqProducer thingModelMessageMqProducer; + @Autowired + private MqProducer deviceReportProducer; @PostConstruct public void init() { @@ -45,48 +48,22 @@ public class DeviceMessageConsumer implements ConsumerHandler @Override public void handler(ThingModelMessage msg) { try { - String deviceId = msg.getDeviceId(); - log.info("save message to es:{}", JsonUtil.toJsonString(msg)); - //属性入库 - if (ThingModelMessage.TYPE_PROPERTY.equals(msg.getType()) + String type = msg.getType(); + //重新发布属性入库消息 + if (ThingModelMessage.TYPE_PROPERTY.equals(type) && "report".equals(msg.getIdentifier())) { - log.info("update device property,deviceId:{},property:{}", - deviceId, JsonUtil.toJsonString(msg.getData())); - deviceDao.updateProperties(deviceId, (Map) msg.getData()); - - //设备属性历史数据存储 - if (msg.getData() instanceof Map) { - Map map = (Map) msg.getData(); - int index = 0; - for (Object key : map.keySet()) { - index++; - try { - propertyRepository.save( - new DeviceProperty( - //防止重复id被覆盖 - msg.getMid() + "_" + index, - deviceId, - key.toString(), - map.get(key), - msg.getOccurred() - ) - ); - } catch (Throwable e) { - log.warn("save property data to es error", e); - } - } - } + thingModelMessageMqProducer.publish(Constants.DEVICE_PROPERTY_REPORT_TOPIC, msg); + } + if (ThingModelMessage.TYPE_CONFIG.equals(type)) { + //重新发布设备配置消息,用于设备配置下发 + thingModelMessageMqProducer.publish(Constants.DEVICE_CONFIG_TOPIC, msg); } - try { - //todo 存在性能问题,量大可再拆分处理 - //设备消息日志入库 - messageRepository.save(msg); - //设备上报日志入库 - deviceReportRepository.save(getDeviceReport(msg)); - } catch (Throwable e) { - log.warn("save device message to es error", e); - } + //重新发布设备上报记录,不包含消息内容,用于数据统计 + deviceReportProducer.publish(Constants.DEVICE_REPORT_RECORD_TOPIC, getDeviceReport(msg)); + + //设备消息入库 + messageRepository.save(msg); } catch (Throwable e) { //不能重复消费 log.error("device message consumer error", e); diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java new file mode 100644 index 00000000..af8de02a --- /dev/null +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java @@ -0,0 +1,84 @@ +package cc.iotkit.comps.service; + +import cc.iotkit.common.Constants; +import cc.iotkit.common.utils.JsonUtil; +import cc.iotkit.dao.DeviceDao; +import cc.iotkit.dao.DevicePropertyRepository; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.device.message.ThingModelMessage; +import cc.iotkit.mq.ConsumerHandler; +import cc.iotkit.mq.MqConsumer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * 设备属性消息消费入库 + */ +@Slf4j +@Service +public class PropertyPersistService implements ConsumerHandler { + + @Autowired + private MqConsumer thingModelMessageMqConsumer; + @Autowired + private DeviceDao deviceDao; + @Autowired + private DevicePropertyRepository propertyRepository; + + @PostConstruct + public void init() { + thingModelMessageMqConsumer.consume(Constants.DEVICE_PROPERTY_REPORT_TOPIC, this); + } + + @Override + public void handler(ThingModelMessage msg) { + if (!(msg.getData() instanceof Map)) { + return; + } + + Map properties = (Map) msg.getData(); + String deviceId = msg.getDeviceId(); + + //更新设备当前属性 + updateDeviceCurrentProperties(deviceId, properties); + + //设备属性历史数据存储 + List batch = new ArrayList<>(); + for (String key : properties.keySet()) { + batch.add(new DeviceProperty( + //防止重复id被覆盖 + msg.getMid() + "_" + key, + deviceId, + key, + properties.get(key), + msg.getOccurred() + )); + } + + //批量保存 + try { + propertyRepository.saveAll(batch); + } catch (Throwable e) { + log.warn("save property data error", e); + } + } + + /** + * 更新设备当前属性 + */ + private void updateDeviceCurrentProperties(String deviceId, Map properties) { + try { + log.info("update device property,deviceId:{},property:{}", + deviceId, JsonUtil.toJsonString(properties)); + deviceDao.updateProperties(deviceId, properties); + } catch (Throwable e) { + log.error("save device current properties error", e); + } + } +} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java new file mode 100644 index 00000000..5503b623 --- /dev/null +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java @@ -0,0 +1,40 @@ +package cc.iotkit.comps.service; + +import cc.iotkit.common.Constants; +import cc.iotkit.dao.DeviceReportRepository; +import cc.iotkit.model.device.message.DeviceReport; +import cc.iotkit.mq.ConsumerHandler; +import cc.iotkit.mq.MqConsumer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; + +/** + * 设备上报记录消费入库 + */ +@Slf4j +@Service +public class ReportRecordPersistService implements ConsumerHandler { + + @Autowired + private MqConsumer deviceReportMqConsumer; + @Autowired + private DeviceReportRepository deviceReportRepository; + + @PostConstruct + public void init() { + deviceReportMqConsumer.consume(Constants.DEVICE_REPORT_RECORD_TOPIC, this); + } + + @Override + public void handler(DeviceReport msg) { + try { + deviceReportRepository.save(msg); + } catch (Throwable e) { + log.warn("save report record error", e); + } + } + +} diff --git a/iot-components/iot-ctwing-component/pom.xml b/iot-components/iot-ctwing-component/pom.xml index 98a90fe5..e0f33f12 100644 --- a/iot-components/iot-ctwing-component/pom.xml +++ b/iot-components/iot-ctwing-component/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-emqx-component/dependency-reduced-pom.xml b/iot-components/iot-emqx-component/dependency-reduced-pom.xml index d00e9956..cdfec43f 100644 --- a/iot-components/iot-emqx-component/dependency-reduced-pom.xml +++ b/iot-components/iot-emqx-component/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 iot-emqx-component @@ -82,25 +82,25 @@ cc.iotkit iot-model - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile cc.iotkit iot-dao - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile cc.iotkit iot-common - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile cc.iotkit iot-component-base - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile diff --git a/iot-components/iot-emqx-component/pom.xml b/iot-components/iot-emqx-component/pom.xml index 7f2265b4..f3d6311b 100644 --- a/iot-components/iot-emqx-component/pom.xml +++ b/iot-components/iot-emqx-component/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-http-biz-component/dependency-reduced-pom.xml b/iot-components/iot-http-biz-component/dependency-reduced-pom.xml index adc65c19..4a3d2f0a 100644 --- a/iot-components/iot-http-biz-component/dependency-reduced-pom.xml +++ b/iot-components/iot-http-biz-component/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 iot-http-biz-component @@ -58,7 +58,7 @@ cc.iotkit iot-component-base - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile diff --git a/iot-components/iot-http-biz-component/pom.xml b/iot-components/iot-http-biz-component/pom.xml index 44ffdf04..cf2b6b8a 100644 --- a/iot-components/iot-http-biz-component/pom.xml +++ b/iot-components/iot-http-biz-component/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java index 57e66e02..8648aea4 100644 --- a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java +++ b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.biz; import cc.iotkit.common.utils.JsonUtil; diff --git a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java index 97808c0d..c4b3fa23 100644 --- a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java +++ b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.biz; import lombok.Data; diff --git a/iot-components/iot-mqtt-component/dependency-reduced-pom.xml b/iot-components/iot-mqtt-component/dependency-reduced-pom.xml index 2a0b2e8f..b9652403 100644 --- a/iot-components/iot-mqtt-component/dependency-reduced-pom.xml +++ b/iot-components/iot-mqtt-component/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 iot-mqtt-component @@ -80,19 +80,19 @@ cc.iotkit iot-common - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile cc.iotkit iot-component-base - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile cc.iotkit iot-dao - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT compile diff --git a/iot-components/iot-mqtt-component/pom.xml b/iot-components/iot-mqtt-component/pom.xml index 4d2a04c9..e502eea5 100644 --- a/iot-components/iot-mqtt-component/pom.xml +++ b/iot-components/iot-mqtt-component/pom.xml @@ -5,7 +5,7 @@ iot-components cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java index 84edb733..68dea236 100644 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java +++ b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.mqtt; import lombok.Data; diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java index 33406c75..74ee899d 100644 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java +++ b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.mqtt; import cc.iotkit.common.exception.BizException; diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java index 3ef97087..21e261d0 100644 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java +++ b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.mqtt; import cc.iotkit.common.exception.BizException; @@ -13,6 +22,7 @@ import io.vertx.core.net.PemKeyCertOptions; import io.vertx.mqtt.*; import io.vertx.mqtt.messages.codes.MqttSubAckReasonCode; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import java.nio.charset.Charset; import java.util.ArrayList; @@ -122,6 +132,10 @@ public class MqttVerticle extends AbstractVerticle { String payload = message.payload().toString(Charset.defaultCharset()); log.info("Received message:{}, with QoS {}", payload, message.qosLevel()); + if (StringUtils.isBlank(payload)) { + return; + } + try { Map head = new HashMap<>(); head.put("topic", message.topicName()); diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java index f0bc05cb..6db5db69 100644 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java +++ b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.mqtt; diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java index 4169c8d5..cb0f65d3 100644 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java +++ b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.comp.mqtt; import lombok.Data; diff --git a/iot-components/pom.xml b/iot-components/pom.xml index fb430dd8..e3a3ed90 100644 --- a/iot-components/pom.xml +++ b/iot-components/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-data-service/iot-dao/pom.xml b/iot-data-service/iot-dao/pom.xml index a9979d06..cb1ed0ea 100644 --- a/iot-data-service/iot-dao/pom.xml +++ b/iot-data-service/iot-dao/pom.xml @@ -5,7 +5,7 @@ iot-data-service cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java new file mode 100644 index 00000000..7a110723 --- /dev/null +++ b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java @@ -0,0 +1,21 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.dao; + +import cc.iotkit.model.device.DeviceConfig; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface DeviceConfigRepository extends ElasticsearchRepository { + + DeviceConfig findByProductKeyAndDeviceName(String productKey, String deviceName); + + DeviceConfig findByDeviceId(String deviceId); + +} diff --git a/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java index 7a6be9f5..fb1a11af 100644 --- a/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java +++ b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.dao; import cc.iotkit.common.Constants; diff --git a/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java index 86622a31..dad0002a 100644 --- a/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java +++ b/iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.dao.config; public interface EmbeddedEs { diff --git a/iot-data-service/iot-device-dao/pom.xml b/iot-data-service/iot-device-dao/pom.xml new file mode 100644 index 00000000..0e3bca2d --- /dev/null +++ b/iot-data-service/iot-device-dao/pom.xml @@ -0,0 +1,23 @@ + + + + iot-data-service + cc.iotkit + 0.3.2-SNAPSHOT + + 4.0.0 + + iot-device-dao + + + + + cc.iotkit + iot-model + + + + + \ No newline at end of file diff --git a/iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java b/iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java new file mode 100644 index 00000000..18cd25a1 --- /dev/null +++ b/iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java @@ -0,0 +1,51 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.data; + +import cc.iotkit.model.product.Product; + +import java.util.List; + +/** + * 产品接口 + */ +public interface ProductDao { + + /** + * 通过产品id取产品信息 + */ + Product findById(String id); + + /** + * 添加产品 + */ + void add(Product product); + + /** + * 按id更新产品 + */ + void updateById(Product product); + + /** + * 按用户id统计产品数量 + */ + long countByUid(String uid); + + /** + * 按用户id取产品列表 + */ + List findByUid(String uid); + + /** + * 按品类取产品列表 + */ + List findByCategory(String category); + +} diff --git a/iot-data-service/iot-model/pom.xml b/iot-data-service/iot-model/pom.xml index 1954f319..d179b25f 100644 --- a/iot-data-service/iot-model/pom.xml +++ b/iot-data-service/iot-model/pom.xml @@ -5,9 +5,9 @@ iot-data-service cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 iot-model diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java new file mode 100644 index 00000000..20a17ba2 --- /dev/null +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java @@ -0,0 +1,50 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.model.device; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +/** + * 设备配置 + */ +@Data +@Document(indexName = "device_config") +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceConfig { + + @Id + private String id; + + private String deviceId; + + /** + * 产品key + */ + private String productKey; + + private String deviceName; + + /** + * 设备配置json内容 + */ + private String config; + + @Field(type = FieldType.Date) + private Long createAt; +} diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java index 9df0a2cc..e2c4bd5d 100644 --- a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.model.device; import cc.iotkit.model.Owned; diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java index e1b0d834..93db302d 100644 --- a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.model.device; import cc.iotkit.model.Owned; diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java index eb6e3914..55875558 100644 --- a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java @@ -36,9 +36,12 @@ public class ThingModelMessage { public static final String TYPE_PROPERTY = "property"; public static final String TYPE_EVENT = "event"; public static final String TYPE_SERVICE = "service"; + public static final String TYPE_CONFIG = "config"; public static final String ID_PROPERTY_GET = "get"; public static final String ID_PROPERTY_SET = "set"; + public static final String ID_CONFIG_GET = "get"; + public static final String ID_CONFIG_SET = "set"; @Id private String mid; diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/DataItem.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/DataItem.java index adbba6a2..aa14c0d6 100644 --- a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/DataItem.java +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/DataItem.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.model.stats; import lombok.AllArgsConstructor; diff --git a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/TimeData.java b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/TimeData.java index a1b7a48b..0ce20906 100644 --- a/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/TimeData.java +++ b/iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/TimeData.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.model.stats; import lombok.AllArgsConstructor; diff --git a/iot-data-service/pom.xml b/iot-data-service/pom.xml index 276d5d0b..84921355 100644 --- a/iot-data-service/pom.xml +++ b/iot-data-service/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 pom @@ -13,6 +13,7 @@ iot-model iot-dao + iot-device-dao iot-data-service diff --git a/iot-message-bus/pom.xml b/iot-message-bus/pom.xml index 05ac0f68..f3dec2d6 100644 --- a/iot-message-bus/pom.xml +++ b/iot-message-bus/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-message-bus/src/main/java/cc/iotkit/mq/ConsumerHandler.java b/iot-message-bus/src/main/java/cc/iotkit/mq/ConsumerHandler.java index 62d37d7b..55c329da 100644 --- a/iot-message-bus/src/main/java/cc/iotkit/mq/ConsumerHandler.java +++ b/iot-message-bus/src/main/java/cc/iotkit/mq/ConsumerHandler.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.mq; public interface ConsumerHandler { diff --git a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java index 4b0d5269..34a4088c 100644 --- a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java +++ b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java @@ -30,12 +30,12 @@ public class BeanCodec implements MessageCodec { @Override public T transform(T o) { - return Json.decodeValue(JsonUtil.toJsonString(o), beanType); + return JsonUtil.parse(JsonUtil.toJsonString(o), beanType); } @Override public String name() { - return "beanCodec"; + return beanType.getSimpleName(); } @Override diff --git a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxManager.java b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxManager.java index 6b26ae72..a50a7960 100644 --- a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxManager.java +++ b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxManager.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.mq.vertx; import io.vertx.core.Vertx; diff --git a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqConsumer.java b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqConsumer.java index f02e19eb..e5be3a36 100644 --- a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqConsumer.java +++ b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqConsumer.java @@ -9,6 +9,7 @@ */ package cc.iotkit.mq.vertx; +import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.mq.ConsumerHandler; import cc.iotkit.mq.MqConsumer; import io.vertx.core.AbstractVerticle; diff --git a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java index 5829bc1a..89e0da96 100644 --- a/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java +++ b/iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java @@ -52,7 +52,7 @@ public class VertxMqProducer implements MqProducer { } public void publish(String topic, T msg) { - eventBus.publish(topic, msg, new DeliveryOptions().setCodecName("beanCodec")); + eventBus.publish(topic, msg, new DeliveryOptions().setCodecName(cls.getSimpleName())); } } } diff --git a/iot-package/pom.xml b/iot-package/pom.xml index 66492b97..83cf6d50 100644 --- a/iot-package/pom.xml +++ b/iot-package/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-rule-engine/pom.xml b/iot-rule-engine/pom.xml index 969064e2..d835409a 100644 --- a/iot-rule-engine/pom.xml +++ b/iot-rule-engine/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpAction.java b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpAction.java index dc1870e6..e2ab1bd4 100644 --- a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpAction.java +++ b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpAction.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.ruleengine.action; import cc.iotkit.model.device.message.ThingModelMessage; diff --git a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java index 66ca2dc8..202052db 100644 --- a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java +++ b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.ruleengine.handler; import cc.iotkit.common.Constants; diff --git a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java index 3d339ffa..e7a2405a 100644 --- a/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java +++ b/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.ruleengine.task; import cc.iotkit.common.exception.BizException; diff --git a/iot-standalone/pom.xml b/iot-standalone/pom.xml index fd7534ed..ecdf563f 100644 --- a/iot-standalone/pom.xml +++ b/iot-standalone/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java b/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java index 384a9303..a7f22101 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.config; import redis.embedded.RedisServer; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/config/SaTokenConfigure.java b/iot-standalone/src/main/java/cc/iotkit/manager/config/SaTokenConfigure.java index faa86bcb..7b4e3379 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/config/SaTokenConfigure.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/config/SaTokenConfigure.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.config; import cn.dev33.satoken.interceptor.SaAnnotationInterceptor; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java b/iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java index bf2cd6c6..1e51850d 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java @@ -20,6 +20,7 @@ import cc.iotkit.manager.model.query.DeviceQuery; import cc.iotkit.manager.service.DataOwnerService; import cc.iotkit.manager.service.DeferredDataConsumer; import cc.iotkit.manager.service.DeviceService; +import cc.iotkit.model.device.DeviceConfig; import cc.iotkit.model.device.DeviceGroup; import cc.iotkit.utils.AuthUtil; import cc.iotkit.model.InvokeResult; @@ -75,6 +76,8 @@ public class DeviceController { private DeviceGroupRepository deviceGroupRepository; @Autowired private DeviceCache deviceCache; + @Autowired + private DeviceConfigRepository deviceConfigRepository; @PostMapping(Constants.API_DEVICE.INVOKE_SERVICE) public InvokeResult invokeService(@PathVariable("deviceId") String deviceId, @@ -394,4 +397,46 @@ public class DeviceController { deviceGroupRepository.save(deviceGroup); } + /** + * 保存设备配置 + */ + @PostMapping("/config/{deviceId}/save") + public void saveConfig(@PathVariable("deviceId") String deviceId, String config) { + DeviceInfo deviceInfo = deviceCache.get(deviceId); + dataOwnerService.checkOwner(deviceInfo); + + DeviceConfig deviceConfig = deviceConfigRepository.findByDeviceId(deviceId); + if (deviceConfig == null) { + deviceConfig = DeviceConfig.builder() + .deviceId(deviceId) + .deviceName(deviceInfo.getDeviceName()) + .productKey(deviceInfo.getProductKey()) + .config(config) + .createAt(System.currentTimeMillis()) + .build(); + } else { + deviceConfig.setConfig(config); + } + + deviceConfigRepository.save(deviceConfig); + } + + /** + * 获取设备配置 + */ + @GetMapping("/config/{deviceId}/get") + public DeviceConfig getConfig(@PathVariable("deviceId") String deviceId) { + DeviceInfo deviceInfo = deviceCache.get(deviceId); + dataOwnerService.checkOwner(deviceInfo); + return deviceConfigRepository.findByDeviceId(deviceId); + } + + /** + * 设备配置下发 + */ + @PostMapping("/config/{deviceId}/send") + public InvokeResult sendConfig(@PathVariable("deviceId") String deviceId) { + return new InvokeResult(deviceService.sendConfig(deviceId)); + } + } diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java b/iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java index 79a785b7..598cc455 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.controller; import cc.iotkit.common.exception.BizException; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java b/iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java index 20f7872e..6f3edf42 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.controller; import cc.iotkit.common.exception.BizException; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/controller/ThirdAuthController.java b/iot-standalone/src/main/java/cc/iotkit/manager/controller/ThirdAuthController.java index d1e8ba36..594cc51a 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/controller/ThirdAuthController.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/controller/ThirdAuthController.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.controller; import cc.iotkit.common.utils.JsonUtil; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java b/iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java index 23f8d74b..be6c04c7 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.controller; import cc.iotkit.common.Constants; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java b/iot-standalone/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java index 5e7c358d..c673d01a 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.model.query; import lombok.Data; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/model/stats/MainStats.java b/iot-standalone/src/main/java/cc/iotkit/manager/model/stats/MainStats.java index dbb3da00..2cbb725c 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/model/stats/MainStats.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/model/stats/MainStats.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.model.stats; import cc.iotkit.model.stats.DataItem; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java index 60ea0ee7..8890a12e 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.service; import cc.iotkit.common.Constants; diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java index c234edcf..030b8ac8 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java @@ -11,11 +11,14 @@ package cc.iotkit.manager.service; import cc.iotkit.common.exception.NotFoundException; import cc.iotkit.common.exception.OfflineException; +import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.UniqueIdUtil; import cc.iotkit.comps.DeviceComponentManager; import cc.iotkit.common.thing.ThingService; +import cc.iotkit.dao.DeviceConfigRepository; import cc.iotkit.dao.DeviceInfoRepository; import cc.iotkit.dao.ThingModelMessageRepository; +import cc.iotkit.model.device.DeviceConfig; import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.virtualdevice.VirtualManager; @@ -41,79 +44,100 @@ public class DeviceService { private ThingModelMessageRepository thingModelMessageRepository; @Autowired private VirtualManager virtualManager; + @Autowired + private DeviceConfigRepository deviceConfigRepository; + /** + * 设备服务调用 + */ public String invokeService(String deviceId, String service, Map args) { return invokeService(deviceId, service, args, true); } + /** + * 设备服务调用 + */ public String invokeService(String deviceId, String service, Map args, boolean checkOwner) { - DeviceInfo device = deviceInfoRepository.findById(deviceId) - .orElseThrow(() -> new NotFoundException("device not found by deviceId")); + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); - if (checkOwner) { - dataOwnerService.checkOwner(device); - } - if (!device.getState().isOnline()) { - throw new OfflineException("device is offline"); - } - - ThingService thingService = ThingService.builder() - .mid(UniqueIdUtil.newRequestId()) - .productKey(device.getProductKey()) - .deviceName(device.getDeviceName()) - .type(ThingModelMessage.TYPE_SERVICE) - .identifier(service) - .params(args) - .build(); - thingModelService.parseParams(thingService); - - deviceComponentManager.send(thingService); - String mid = thingService.getMid(); - - //保存设备日志 - ThingModelMessage thingModelMessage = ThingModelMessage.builder() - .mid(mid) - .deviceId(deviceId) - .productKey(device.getProductKey()) - .deviceName(device.getDeviceName()) - .type(ThingModelMessage.TYPE_SERVICE) - .identifier(service) - .data(args) - .occurred(System.currentTimeMillis()) - .time(System.currentTimeMillis()) - .build(); - thingModelMessageRepository.save(thingModelMessage); - - return mid; + return send(deviceId, device.getProductKey(), device.getDeviceName(), + args, ThingModelMessage.TYPE_SERVICE, service); } + /** + * 设备属性设置 + */ public String setProperty(String deviceId, Map properties) { return setProperty(deviceId, properties, true); } + /** + * 设备属性设置 + */ public String setProperty(String deviceId, Map properties, boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), properties, + ThingModelMessage.TYPE_PROPERTY, ThingModelMessage.ID_PROPERTY_SET); + } + + /** + * 设备配置下发 + */ + public String sendConfig(String deviceId, boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + DeviceConfig config = deviceConfigRepository.findByDeviceId(deviceId); + Map data = JsonUtil.parse(config.getConfig(), Map.class); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), data, + ThingModelMessage.TYPE_CONFIG, ThingModelMessage.ID_CONFIG_SET); + } + + /** + * 设备配置下发 + */ + public String sendConfig(String deviceId) { + return sendConfig(deviceId, true); + } + + /** + * 检查设备操作权限和状态 + */ + private DeviceInfo getAndCheckDevice(String deviceId, boolean checkOwner) { DeviceInfo device = deviceInfoRepository.findById(deviceId) .orElseThrow(() -> new NotFoundException("device not found by deviceId")); if (checkOwner) { dataOwnerService.checkOwner(device); } + if (!device.getState().isOnline()) { throw new OfflineException("device is offline"); } + return device; + } + /** + * 数据下发 + */ + private String send(String deviceId, String pk, String dn, + Object data, String type, String identifier) { ThingService thingService = ThingService.builder() .mid(UniqueIdUtil.newRequestId()) - .productKey(device.getProductKey()) - .deviceName(device.getDeviceName()) - .type(ThingModelMessage.TYPE_PROPERTY) - .identifier("set") - .params(properties) + .productKey(pk) + .deviceName(dn) + .type(type) + .identifier(identifier) + .params(data) .build(); - thingModelService.parseParams(thingService); + if (!type.equals(ThingModelMessage.TYPE_CONFIG)) { + //非配置下发需要做物模型转换 + thingModelService.parseParams(thingService); + } if (virtualManager.isVirtual(deviceId)) { //虚拟设备指令下发 @@ -128,11 +152,11 @@ public class DeviceService { ThingModelMessage thingModelMessage = ThingModelMessage.builder() .mid(mid) .deviceId(deviceId) - .productKey(device.getProductKey()) - .deviceName(device.getDeviceName()) - .type(ThingModelMessage.TYPE_PROPERTY) - .identifier("set") - .data(properties) + .productKey(pk) + .deviceName(dn) + .type(type) + .identifier(identifier) + .data(data) .occurred(System.currentTimeMillis()) .time(System.currentTimeMillis()) .build(); diff --git a/iot-standalone/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java b/iot-standalone/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java index 9aad76e0..b23cf8d0 100644 --- a/iot-standalone/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java +++ b/iot-standalone/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.manager.service; import cc.iotkit.common.utils.JsonUtil; diff --git a/iot-standalone/src/main/resources/application-dev.yml b/iot-standalone/src/main/resources/application-dev.yml new file mode 100644 index 00000000..df9db966 --- /dev/null +++ b/iot-standalone/src/main/resources/application-dev.yml @@ -0,0 +1,57 @@ +server: + port: 8086 + +spring: + servlet: + multipart: + enabled: true + max-file-size: 10MB + max-request-size: 12MB + + elasticsearch: + rest: + #使用内置es的配置 + uris: http://127.0.0.1:9200 + username: + password: + connection-timeout: 10s + + redis: + #使用内置redis的配置 + host: 127.0.0.1 + port: 6379 + database: 0 + password: + + mvc: + pathmatch: + matching-strategy: ant_path_matcher + +#图片存储用的是阿里云oss,如果需要上传产品图片才需要配置 +aliyun: + bucketId: iotkit-img + endpoint: oss-cn-shenzhen.aliyuncs.com + accessKeyId: 填写阿里云accessKeyId + accessKeySecret: 填写阿里云accessKeySecret + +sa-token: + # token名称 (同时也是cookie名称) + token-name: token + # token有效期,单位s 默认30天, -1代表永不过期 + timeout: 2592000 + # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 + activity-timeout: -1 + # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + is-concurrent: true + # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + is-share: false + # token风格 + token-style: uuid + # 是否输出操作日志 + is-log: false + +#认证中心地址 +oauth2: + auth-server-url: http://127.0.0.1:8086 + +a b: 123:4 5 diff --git a/iot-standalone/src/main/resources/application.yml b/iot-standalone/src/main/resources/application.yml new file mode 100644 index 00000000..baf8c348 --- /dev/null +++ b/iot-standalone/src/main/resources/application.yml @@ -0,0 +1,55 @@ +server: + port: 8086 + +spring: + servlet: + multipart: + enabled: true + max-file-size: 10MB + max-request-size: 12MB + + elasticsearch: + rest: + #使用内置es的配置 + uris: http://127.0.0.1:9200 + username: + password: + connection-timeout: 10s + + redis: + #使用内置redis的配置 + host: 127.0.0.1 + port: 6379 + database: 0 + password: + + mvc: + pathmatch: + matching-strategy: ant_path_matcher + +#图片存储用的是阿里云oss,如果需要上传产品图片才需要配置 +aliyun: + bucketId: iotkit-img + endpoint: oss-cn-shenzhen.aliyuncs.com + accessKeyId: 填写阿里云accessKeyId + accessKeySecret: 填写阿里云accessKeySecret + +sa-token: + # token名称 (同时也是cookie名称) + token-name: token + # token有效期,单位s 默认30天, -1代表永不过期 + timeout: 2592000 + # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 + activity-timeout: -1 + # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + is-concurrent: true + # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + is-share: false + # token风格 + token-style: uuid + # 是否输出操作日志 + is-log: false + +#认证中心地址 +oauth2: + auth-server-url: http://127.0.0.1:8086 diff --git a/iot-test-tool/iot-test-mqtt/pom.xml b/iot-test-tool/iot-test-mqtt/pom.xml index 53fd520d..89efd198 100644 --- a/iot-test-tool/iot-test-mqtt/pom.xml +++ b/iot-test-tool/iot-test-mqtt/pom.xml @@ -5,7 +5,7 @@ iot-test-tool cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/Simulator.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/Simulator.java index 802096d6..b77c694f 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/Simulator.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/Simulator.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt; import cc.iotkit.test.mqtt.config.Mqtt; @@ -19,19 +28,19 @@ public class Simulator { new Thread(() -> { Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB", "AA:BB:CC:DD:22"); gateway.addSubDevice("Rf4QSjbm65X45753", "ABC12300002", "S01"); - gateway.addSubDevice("Rf4QSjbm65X45753", "ABC12300003", "S01"); - gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300001", "F01"); - gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300002", "F01"); - gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300002", "F01"); +// gateway.addSubDevice("Rf4QSjbm65X45753", "ABC12300003", "S01"); +// gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300001", "F01"); +// gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300002", "F01"); +// gateway.addSubDevice("hdX3PCMcFrCYpesJ", "ABD12300002", "F01"); gateway.start(); - - Gateway gateway2 = new Gateway("N523nWsCiG3CAn6X", "AA:BB:CC:EE:01"); - //插座 - gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300001", "S1"); - gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300002", "S1"); - gateway2.addSubDevice("6kYp6jszrDns2yh4", "ABE12400001", "S1"); - gateway2.addSubDevice("", "ABE12500001", "M1"); - gateway2.start(); +// +// Gateway gateway2 = new Gateway("N523nWsCiG3CAn6X", "AA:BB:CC:EE:01"); +// //插座 +// gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300001", "S1"); +// gateway2.addSubDevice("cGCrkK7Ex4FESAwe", "ABE12300002", "S1"); +// gateway2.addSubDevice("6kYp6jszrDns2yh4", "ABE12400001", "S1"); +// gateway2.addSubDevice("", "ABE12500001", "M1"); +// gateway2.start(); }).start(); System.in.read(); diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java index a0952ef7..9a5bc20b 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt.model; import lombok.AllArgsConstructor; diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Response.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Response.java index e901abbc..f429f350 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Response.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Response.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt.model; diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java index 26bf1c1c..ac18efaa 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java @@ -33,7 +33,7 @@ public class ConnectionTest { Mqtt.brokerHost = args[0]; } - int total = 1000; + int total = 500; if (args.length > 1) { total = Integer.parseInt(args[1]); } @@ -46,17 +46,17 @@ public class ConnectionTest { Gateway gateway = new Gateway("hbtgIA0SuVw9lxjB", "TEST:GW:" + StringUtils.leftPad(finalI + "", 6, "0")); - gateway.addSubDevice("Rf4QSjbm65X45753", - "TEST_SW_" + StringUtils.leftPad(finalI + "", 6, "0"), - "S01"); - - gateway.addSubDevice("cGCrkK7Ex4FESAwe", - "TEST_SC_" + StringUtils.leftPad(finalI + "", 6, "0"), - "S01"); - - gateway.addSubDevice("xpsYHExTKPFaQMS7", - "TEST_LT_" + StringUtils.leftPad(finalI + "", 6, "0"), - "L01"); +// gateway.addSubDevice("Rf4QSjbm65X45753", +// "TEST_SW_" + StringUtils.leftPad(finalI + "", 6, "0"), +// "S01"); +// +// gateway.addSubDevice("cGCrkK7Ex4FESAwe", +// "TEST_SC_" + StringUtils.leftPad(finalI + "", 6, "0"), +// "S01"); +// +// gateway.addSubDevice("xpsYHExTKPFaQMS7", +// "TEST_LT_" + StringUtils.leftPad(finalI + "", 6, "0"), +// "L01"); gateway.start(); }); diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java index e78f1b24..58bb0ab3 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java @@ -39,7 +39,7 @@ public class ReportTest { Mqtt.brokerHost = args[0]; } - int total = 1000; + int total = 500; if (args.length > 1) { total = Integer.parseInt(args[1]); } diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java index f8892f09..44478be0 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java @@ -79,6 +79,14 @@ public class Gateway extends Device { log.info("subscribe topic:{}", topic); client.subscribe(topic, 1, r -> { + //配置获取 +// String configGetTopic = String.format("/sys/%s/%s/s/config/get", productKey, deviceName); +// Request configRequest = new Request(); +// configRequest.setId(UUID.randomUUID().toString()); +// String configPayload = JsonUtil.toJsonString(configRequest); +// client.publish(configGetTopic, Buffer.buffer(configPayload), MqttQoS.AT_LEAST_ONCE, false, false); +// log.info("publish message,topic:{},payload:{}", configGetTopic, configPayload); + //注册子设备 for (Device subDevice : subDevices) { log.info("start register sub device,pk:{},dn:{}", subDevice.getProductKey(), subDevice.getDeviceName()); diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/MessageHandler.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/MessageHandler.java index ae7f42cd..e9ea5ecf 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/MessageHandler.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/MessageHandler.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt.service; diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/ReportTask.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/ReportTask.java index c9efc256..a472dd9e 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/ReportTask.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/ReportTask.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt.service; import cc.iotkit.common.utils.JsonUtil; diff --git a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Vertxs.java b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Vertxs.java index bfeb6d16..99a1389f 100644 --- a/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Vertxs.java +++ b/iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Vertxs.java @@ -1,3 +1,12 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ package cc.iotkit.test.mqtt.service; import io.vertx.core.Vertx; diff --git a/iot-test-tool/pom.xml b/iot-test-tool/pom.xml index 9864af4c..2cc09217 100644 --- a/iot-test-tool/pom.xml +++ b/iot-test-tool/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 pom diff --git a/iot-virtual-device/pom.xml b/iot-virtual-device/pom.xml index 3eaf2c98..980fa58a 100644 --- a/iot-virtual-device/pom.xml +++ b/iot-virtual-device/pom.xml @@ -5,7 +5,7 @@ iotkit-parent cc.iotkit - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT 4.0.0 diff --git a/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java b/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java index e4701bac..85498d46 100644 --- a/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java +++ b/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java @@ -161,6 +161,7 @@ public class VirtualManager { //更新deviceId的虚拟设备Id对应关系 Set virtualIds = deviceIdToVirtualId.getOrDefault(deviceId, new HashSet<>()); virtualIds.add(id); + //一个真实设备可能会被多个虚拟设备使用 deviceIdToVirtualId.put(deviceId, virtualIds); } @@ -211,9 +212,14 @@ public class VirtualManager { virtualScripts.remove(id); //更新deviceId的虚拟设备Id对应关系 - for (String deviceId : deviceIdToVirtualId.keySet()) { + Iterator keyIterator = deviceIdToVirtualId.keySet().iterator(); + while (keyIterator.hasNext()) { + String deviceId = keyIterator.next(); Set virtualIds = deviceIdToVirtualId.get(deviceId); virtualIds.remove(id); + if (virtualIds.size() == 0) { + keyIterator.remove(); + } } //删除job diff --git a/pom.xml b/pom.xml index cbc260eb..47879fe3 100755 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ cc.iotkit iotkit-parent - 0.3.1-SNAPSHOT + 0.3.2-SNAPSHOT iotkit-parent iotkit parent @@ -292,6 +292,12 @@ ${project.version} + + cc.iotkit + iot-device-dao + ${project.version} + +