Преглед на файлове

增加设备配置功能

xiwa преди 2 години
родител
ревизия
413818248a
променени са 99 файла, в които са добавени 1212 реда и са изтрити 165 реда
  1. 0 1
      .gitignore
  2. 29 0
      data/converters/6260396d67aced2696184053/converter.js
  3. 1 1
      iot-auth-server/pom.xml
  4. 9 0
      iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java
  5. 9 0
      iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java
  6. 9 0
      iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java
  7. 9 0
      iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java
  8. 9 0
      iot-auth-server/src/main/java/cc/iotkit/utils/SoMap.java
  9. 1 1
      iot-common/pom.xml
  10. 17 2
      iot-common/src/main/java/cc/iotkit/common/Constants.java
  11. 1 1
      iot-components/iot-component-base/pom.xml
  12. 9 0
      iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java
  13. 9 0
      iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java
  14. 9 0
      iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java
  15. 1 1
      iot-components/iot-component-converter/pom.xml
  16. 9 0
      iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java
  17. 9 0
      iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java
  18. 9 0
      iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConverter.java
  19. 6 1
      iot-components/iot-component-server/pom.xml
  20. 9 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java
  21. 9 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java
  22. 9 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java
  23. 9 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java
  24. 9 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java
  25. 10 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java
  26. 9 2
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java
  27. 75 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java
  28. 27 50
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java
  29. 84 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java
  30. 40 0
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java
  31. 1 1
      iot-components/iot-ctwing-component/pom.xml
  32. 5 5
      iot-components/iot-emqx-component/dependency-reduced-pom.xml
  33. 1 1
      iot-components/iot-emqx-component/pom.xml
  34. 2 2
      iot-components/iot-http-biz-component/dependency-reduced-pom.xml
  35. 1 1
      iot-components/iot-http-biz-component/pom.xml
  36. 9 0
      iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java
  37. 9 0
      iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java
  38. 4 4
      iot-components/iot-mqtt-component/dependency-reduced-pom.xml
  39. 1 1
      iot-components/iot-mqtt-component/pom.xml
  40. 9 0
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java
  41. 9 0
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java
  42. 14 0
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java
  43. 9 0
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java
  44. 9 0
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java
  45. 1 1
      iot-components/pom.xml
  46. 1 1
      iot-data-service/iot-dao/pom.xml
  47. 21 0
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java
  48. 9 0
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java
  49. 9 0
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java
  50. 23 0
      iot-data-service/iot-device-dao/pom.xml
  51. 51 0
      iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java
  52. 2 2
      iot-data-service/iot-model/pom.xml
  53. 50 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java
  54. 9 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java
  55. 9 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java
  56. 3 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java
  57. 9 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/DataItem.java
  58. 9 0
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/stats/TimeData.java
  59. 2 1
      iot-data-service/pom.xml
  60. 1 1
      iot-message-bus/pom.xml
  61. 9 0
      iot-message-bus/src/main/java/cc/iotkit/mq/ConsumerHandler.java
  62. 2 2
      iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java
  63. 9 0
      iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxManager.java
  64. 1 0
      iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqConsumer.java
  65. 1 1
      iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java
  66. 1 1
      iot-package/pom.xml
  67. 1 1
      iot-rule-engine/pom.xml
  68. 9 0
      iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/HttpAction.java
  69. 9 0
      iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java
  70. 9 0
      iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java
  71. 1 1
      iot-standalone/pom.xml
  72. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/config/EmbeddedRedisConfig.java
  73. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/config/SaTokenConfigure.java
  74. 45 0
      iot-standalone/src/main/java/cc/iotkit/manager/controller/DeviceController.java
  75. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/controller/ProtocolController.java
  76. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/controller/SpaceController.java
  77. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/controller/ThirdAuthController.java
  78. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/controller/UserInfoController.java
  79. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java
  80. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/model/stats/MainStats.java
  81. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java
  82. 72 48
      iot-standalone/src/main/java/cc/iotkit/manager/service/DeviceService.java
  83. 9 0
      iot-standalone/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java
  84. 57 0
      iot-standalone/src/main/resources/application-dev.yml
  85. 55 0
      iot-standalone/src/main/resources/application.yml
  86. 1 1
      iot-test-tool/iot-test-mqtt/pom.xml
  87. 21 12
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/Simulator.java
  88. 9 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Request.java
  89. 9 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/model/Response.java
  90. 12 12
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ConnectionTest.java
  91. 1 1
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/performance/ReportTest.java
  92. 8 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Gateway.java
  93. 9 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/MessageHandler.java
  94. 9 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/ReportTask.java
  95. 9 0
      iot-test-tool/iot-test-mqtt/src/main/java/cc/iotkit/test/mqtt/service/Vertxs.java
  96. 1 1
      iot-test-tool/pom.xml
  97. 1 1
      iot-virtual-device/pom.xml
  98. 7 1
      iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java
  99. 7 1
      pom.xml

+ 0 - 1
.gitignore

@@ -23,7 +23,6 @@ hs_err_pid*
 .idea
 target
 *.iml
-*.yml
 log
 data/elasticsearch
 .init

+ 29 - 0
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];
   }

+ 1 - 1
iot-auth-server/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 1 - 1
iot-common/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 17 - 2
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/#$";
     }
 }

+ 1 - 1
iot-components/iot-component-base/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 1 - 1
iot-components/iot-component-converter/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 6 - 1
iot-components/iot-component-server/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -92,6 +92,11 @@
             <artifactId>iot-message-bus</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-device-dao</artifactId>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 9 - 0
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;

+ 9 - 0
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;
 
 

+ 9 - 0
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;
 
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 10 - 0
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<DeviceReport> getDeviceReportProducer() {
+        return new VertxMqProducer<>(DeviceReport.class);
+    }
+
+    @Bean("deviceReportConsumer")
+    public MqConsumer<DeviceReport> getDeviceReportConsumer() {
+        return new VertxMqConsumer<>(DeviceReport.class);
+    }
 }

+ 9 - 2
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);
 

+ 75 - 0
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<ThingModelMessage> {
+
+    @Autowired
+    private MqConsumer<ThingModelMessage> 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<Object> 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);
+        }
+    }
+}

+ 27 - 50
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<ThingModelMessage>
     @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<ThingModelMessage> thingModelMessageConsumer;
+    @Autowired
+    private MqProducer<ThingModelMessage> thingModelMessageMqProducer;
+    @Autowired
+    private MqProducer<DeviceReport> deviceReportProducer;
 
     @PostConstruct
     public void init() {
@@ -45,48 +48,22 @@ public class DeviceMessageConsumer implements ConsumerHandler<ThingModelMessage>
     @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<String, Object>) 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);
             }
-
-            try {
-                //todo 存在性能问题,量大可再拆分处理
-                //设备消息日志入库
-                messageRepository.save(msg);
-                //设备上报日志入库
-                deviceReportRepository.save(getDeviceReport(msg));
-            } catch (Throwable e) {
-                log.warn("save device message to es error", e);
+            if (ThingModelMessage.TYPE_CONFIG.equals(type)) {
+                //重新发布设备配置消息,用于设备配置下发
+                thingModelMessageMqProducer.publish(Constants.DEVICE_CONFIG_TOPIC, msg);
             }
+
+            //重新发布设备上报记录,不包含消息内容,用于数据统计
+            deviceReportProducer.publish(Constants.DEVICE_REPORT_RECORD_TOPIC, getDeviceReport(msg));
+
+            //设备消息入库
+            messageRepository.save(msg);
         } catch (Throwable e) {
             //不能重复消费
             log.error("device message consumer error", e);

+ 84 - 0
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<ThingModelMessage> {
+
+    @Autowired
+    private MqConsumer<ThingModelMessage> 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<String, Object> properties = (Map<String, Object>) msg.getData();
+        String deviceId = msg.getDeviceId();
+
+        //更新设备当前属性
+        updateDeviceCurrentProperties(deviceId, properties);
+
+        //设备属性历史数据存储
+        List<DeviceProperty> 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<String, Object> 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);
+        }
+    }
+}

+ 40 - 0
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<DeviceReport> {
+
+    @Autowired
+    private MqConsumer<DeviceReport> 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);
+        }
+    }
+
+}

+ 1 - 1
iot-components/iot-ctwing-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 5 - 5
iot-components/iot-emqx-component/dependency-reduced-pom.xml

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.1-SNAPSHOT</version>
+    <version>0.3.2-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-emqx-component</artifactId>
@@ -82,25 +82,25 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-model</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-dao</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-common</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-component-base</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

+ 1 - 1
iot-components/iot-emqx-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 2 - 2
iot-components/iot-http-biz-component/dependency-reduced-pom.xml

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.1-SNAPSHOT</version>
+    <version>0.3.2-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-http-biz-component</artifactId>
@@ -58,7 +58,7 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-component-base</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

+ 1 - 1
iot-components/iot-http-biz-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 4 - 4
iot-components/iot-mqtt-component/dependency-reduced-pom.xml

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.1-SNAPSHOT</version>
+    <version>0.3.2-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-mqtt-component</artifactId>
@@ -80,19 +80,19 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-common</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-component-base</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-dao</artifactId>
-      <version>0.3.1-SNAPSHOT</version>
+      <version>0.3.2-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

+ 1 - 1
iot-components/iot-mqtt-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 14 - 0
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<String, Object> head = new HashMap<>();
                     head.put("topic", message.topicName());

+ 9 - 0
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;
 
 

+ 9 - 0
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;

+ 1 - 1
iot-components/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-data-service/iot-dao/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-data-service</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 21 - 0
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, String> {
+
+    DeviceConfig findByProductKeyAndDeviceName(String productKey, String deviceName);
+
+    DeviceConfig findByDeviceId(String deviceId);
+
+}

+ 9 - 0
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;

+ 9 - 0
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 {

+ 23 - 0
iot-data-service/iot-device-dao/pom.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>iot-data-service</artifactId>
+        <groupId>cc.iotkit</groupId>
+        <version>0.3.2-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>iot-device-dao</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-model</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 51 - 0
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<Product> findByUid(String uid);
+
+    /**
+     * 按品类取产品列表
+     */
+    List<Product> findByCategory(String category);
+
+}

+ 2 - 2
iot-data-service/iot-model/pom.xml

@@ -5,9 +5,9 @@
     <parent>
         <artifactId>iot-data-service</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
-    <version>0.3.1-SNAPSHOT</version>
+    <version>0.3.2-SNAPSHOT</version>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>iot-model</artifactId>

+ 50 - 0
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;
+}

+ 9 - 0
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;

+ 9 - 0
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;

+ 3 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 2 - 1
iot-data-service/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>
@@ -13,6 +13,7 @@
     <modules>
         <module>iot-model</module>
         <module>iot-dao</module>
+        <module>iot-device-dao</module>
     </modules>
 
     <artifactId>iot-data-service</artifactId>

+ 1 - 1
iot-message-bus/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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<T> {

+ 2 - 2
iot-message-bus/src/main/java/cc/iotkit/mq/vertx/BeanCodec.java

@@ -30,12 +30,12 @@ public class BeanCodec<T> implements MessageCodec<T, T> {
 
     @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

+ 9 - 0
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;

+ 1 - 0
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;

+ 1 - 1
iot-message-bus/src/main/java/cc/iotkit/mq/vertx/VertxMqProducer.java

@@ -52,7 +52,7 @@ public class VertxMqProducer<T> implements MqProducer<T> {
         }
 
         public void publish(String topic, T msg) {
-            eventBus.publish(topic, msg, new DeliveryOptions().setCodecName("beanCodec"));
+            eventBus.publish(topic, msg, new DeliveryOptions().setCodecName(cls.getSimpleName()));
         }
     }
 }

+ 1 - 1
iot-package/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
iot-rule-engine/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 1 - 1
iot-standalone/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 45 - 0
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));
+    }
+
 }

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 9 - 0
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;

+ 72 - 48
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<String, Object> args) {
         return invokeService(deviceId, service, args, true);
     }
 
+    /**
+     * 设备服务调用
+     */
     public String invokeService(String deviceId, String service,
                                 Map<String, Object> args, 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");
-        }
-
-        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);
+        DeviceInfo device = getAndCheckDevice(deviceId, checkOwner);
 
-        return mid;
+        return send(deviceId, device.getProductKey(), device.getDeviceName(),
+                args, ThingModelMessage.TYPE_SERVICE, service);
     }
 
+    /**
+     * 设备属性设置
+     */
     public String setProperty(String deviceId, Map<String, Object> properties) {
         return setProperty(deviceId, properties, true);
     }
 
+    /**
+     * 设备属性设置
+     */
     public String setProperty(String deviceId, Map<String, Object> 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();

+ 9 - 0
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;

+ 57 - 0
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

+ 55 - 0
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

+ 1 - 1
iot-test-tool/iot-test-mqtt/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-test-tool</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 21 - 12
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();

+ 9 - 0
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;

+ 9 - 0
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;
 
 

+ 12 - 12
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();
             });

+ 1 - 1
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]);
         }

+ 8 - 0
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());

+ 9 - 0
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;
 
 

+ 9 - 0
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;

+ 9 - 0
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;

+ 1 - 1
iot-test-tool/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>

+ 1 - 1
iot-virtual-device/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.1-SNAPSHOT</version>
+        <version>0.3.2-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 7 - 1
iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java

@@ -161,6 +161,7 @@ public class VirtualManager {
                 //更新deviceId的虚拟设备Id对应关系
                 Set<String> 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<String> keyIterator = deviceIdToVirtualId.keySet().iterator();
+        while (keyIterator.hasNext()) {
+            String deviceId = keyIterator.next();
             Set<String> virtualIds = deviceIdToVirtualId.get(deviceId);
             virtualIds.remove(id);
+            if (virtualIds.size() == 0) {
+                keyIterator.remove();
+            }
         }
 
         //删除job

+ 7 - 1
pom.xml

@@ -24,7 +24,7 @@
 
     <groupId>cc.iotkit</groupId>
     <artifactId>iotkit-parent</artifactId>
-    <version>0.3.1-SNAPSHOT</version>
+    <version>0.3.2-SNAPSHOT</version>
     <name>iotkit-parent</name>
     <description>iotkit parent</description>
     <properties>
@@ -292,6 +292,12 @@
                 <version>${project.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>cc.iotkit</groupId>
+                <artifactId>iot-device-dao</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+
         </dependencies>
     </dependencyManagement>