ソースを参照

合并feature

xiwa 2 年 前
コミット
4866c27ed9
100 ファイル変更2019 行追加1405 行削除
  1. BIN
      .DS_Store
  2. 1 0
      .gitignore
  3. 5 3
      .workflow/BranchPipeline.yml
  4. BIN
      data/components/.DS_Store
  5. 10 10
      data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/component.js
  6. BIN
      data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/iot-http-biz-component-0.4.0-SNAPSHOT.jar
  7. BIN
      data/components/6c095554-35e7-4e9d-a8d2-bb919e9479f4/iot-emqx-component-0.4.0-SNAPSHOT.jar
  8. BIN
      data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js
  9. 0 18
      data/converters/6260396d67aced2696184053/converter.js
  10. 2 2
      data/init/home.json
  11. 6 18
      data/init/product.json
  12. 6 6
      data/init/protocolConverter.json
  13. 18 6
      iot-auth-server/readme.txt
  14. 3 3
      iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java
  15. 5 3
      iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java
  16. 6 4
      iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java
  17. 9 0
      iot-auth-server/src/main/java/cc/iotkit/oauth/service/TokenRequestHandler.java
  18. 1 1
      iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java
  19. 8 8
      iot-common/readme.txt
  20. 6 1
      iot-common/src/main/java/cc/iotkit/common/exception/BizException.java
  21. 1 1
      iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java
  22. 10 5
      iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java
  23. 3 3
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java
  24. 18 15
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java
  25. 0 10
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java
  26. 29 24
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java
  27. 4 4
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigConsumer.java
  28. 3 27
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java
  29. 19 9
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DevicePropertyConsumer.java
  30. 0 40
      iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java
  31. BIN
      iot-components/iot-ctwing-component/.DS_Store
  32. BIN
      iot-components/iot-ctwing-component/lib/ctg-ag-sdk-core-2.5.0-20220512.061430-51.jar
  33. 92 0
      iot-components/iot-ctwing-component/pom.xml
  34. 34 0
      iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingConfig.java
  35. 206 0
      iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java
  36. 129 0
      iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/ProtocolUtil.java
  37. 36 0
      iot-components/iot-ctwing-component/src/main/resources/component.js
  38. 1 0
      iot-components/iot-ctwing-component/src/main/resources/component.spi
  39. 12 10
      iot-components/iot-emqx-component/.DS_Store
  40. 185 0
      iot-components/iot-emqx-component/emqx_rule_data.json
  41. 8 6
      iot-components/iot-emqx-component/pom.xml
  42. 6 0
      iot-components/iot-emqx-component/readme.md
  43. 4 4
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/AuthVerticle.java
  44. 9 0
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/IScripter.java
  45. 9 0
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/JsScripter.java
  46. 9 0
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/LuaScripter.java
  47. 27 6
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java
  48. 9 0
      iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentMsg.java
  49. 5 5
      iot-components/iot-emqx-component/src/main/resources/component.js
  50. 3 3
      iot-components/iot-http-biz-component/pom.xml
  51. 10 8
      iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java
  52. 6 4
      iot-components/iot-mqtt-component/pom.xml
  53. 17 5
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/IScripter.java
  54. 1 1
      iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java
  55. 0 38
      iot-components/readme.txt
  56. 0 27
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/AligenieDeviceRepository.java
  57. 0 42
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/CategoryCache.java
  58. 0 61
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/CommonDao.java
  59. 0 56
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceCache.java
  60. 0 270
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceDao.java
  61. 0 31
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceInfoRepository.java
  62. 0 42
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/OauthClientCache.java
  63. 0 59
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProductCache.java
  64. 0 23
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProtocolComponentRepository.java
  65. 0 16
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProtocolConverterRepository.java
  66. 0 33
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/SpaceCache.java
  67. 0 44
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java
  68. 0 19
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java
  69. 0 9
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThirdUserSessionRepository.java
  70. 0 17
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserActionLogRepository.java
  71. 0 42
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java
  72. 0 25
      iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java
  73. 0 28
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/OauthClient.java
  74. 0 87
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/UserActionLog.java
  75. 0 72
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/aligenie/AligenieProduct.java
  76. 0 59
      iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/DeviceReport.java
  77. 0 1
      iot-data-service/readme.txt
  78. 0 0
      iot-data/.DS_Store
  79. 48 0
      iot-data/iot-data-cache/pom.xml
  80. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java
  81. 27 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java
  82. 37 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java
  83. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java
  84. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java
  85. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java
  86. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java
  87. 14 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java
  88. 57 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java
  89. 61 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java
  90. 259 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java
  91. 76 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java
  92. 84 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java
  93. 71 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java
  94. 91 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java
  95. 77 0
      iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java
  96. 9 9
      iot-data/iot-data-service/pom.xml
  97. 3 4
      iot-data/iot-data-service/src/main/java/cc/iotkit/data/ICategoryData.java
  98. 23 15
      iot-data/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java
  99. 2 3
      iot-data/iot-data-service/src/main/java/cc/iotkit/data/IDeviceConfigData.java
  100. 19 0
      iot-data/iot-data-service/src/main/java/cc/iotkit/data/IDeviceGroupData.java

BIN
.DS_Store


+ 1 - 0
.gitignore

@@ -26,3 +26,4 @@ target
 log
 data/elasticsearch
 .init
+*.db

+ 5 - 3
.workflow/BranchPipeline.yml

@@ -1,6 +1,8 @@
 FROM openjdk:11-jre-slim
 WORKDIR /app
-ADD iot-standalone/target/iot-standalone-0.3.2-SNAPSHOT.tar /app/
-ADD /data /app/data/
+ADD iot-standalone/target/iot-standalone-0.4.0-SNAPSHOT.tar /app
+ADD data/init /app/data/init
+ADD data/components /app/data/components
+ADD data/converters /app/data/converters
 EXPOSE 8086
-ENTRYPOINT ["java", "-classpath", ".:lib/*","cc.iotkit.manager.Application"]
+ENTRYPOINT ["java", "-classpath", ".:lib/*","cc.iotkit.Application"]

BIN
iot-data-service/iot-model/.DS_Store → data/components/.DS_Store


+ 10 - 10
data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/component.js

@@ -15,7 +15,7 @@ this.onReceive=function(method,path,header,params,body){
   var duPayload=body.payload;
   var token=duPayload.accessToken;
   var openUid=duPayload.openUid;
-
+  
   //设备发现
   if(namespace=="DuerOS.ConnectedHome.Discovery" && requestName=="DiscoverAppliancesRequest"){
 	var deviceIds=[];
@@ -46,13 +46,13 @@ this.onReceive=function(method,path,header,params,body){
 		var did=device.deviceId;
 		var pk=device.productKey;
 		var dn=device.deviceName;
-
+		
 		//更新设备openUid
 		rst=apiTool.setOpenUid(token,did,"dueros",openUid);
 		if(!rst || rst.status!=200){
 		  continue;
 		}
-
+		
 		//插座
 		if(pk=="cGCrkK7Ex4FESAwe"){
 		  var powerstate=device.property.powerstate;
@@ -129,11 +129,11 @@ this.onReceive=function(method,path,header,params,body){
 			  }
 			]
 		  });
-
+		  
 		}
 	  }
 	}
-
+	
 	return {
 	  url:"",//不指定直接作为响应返回
 	  header:{
@@ -147,7 +147,7 @@ this.onReceive=function(method,path,header,params,body){
 	var deviceId=appliance.applianceId;
 	var confirmName="UnsupportedOperationError";
 	var rst={status:500};
-
+	
 	//开关
 	if(requestName=="TurnOnRequest"){
 		//开
@@ -158,12 +158,12 @@ this.onReceive=function(method,path,header,params,body){
 	  	confirmName="TurnOffConfirmation";
 		rst=apiTool.setProperties(token,deviceId,{powerstate:0});
 	}
-
+	
 	if(rst.status!=200){
 	  confirmName="UnsupportedOperationError";
 	  apiTool.log("device control failed:"+JSON.stringify(rst));
 	}
-
+	
 	var content={
 	  header: {
 		namespace: "DuerOS.ConnectedHome.Control",
@@ -175,7 +175,7 @@ this.onReceive=function(method,path,header,params,body){
 		"attributes": []
 	  }
 	};
-
+	
 	return {
 	  url:"",
 	  header:{
@@ -218,7 +218,7 @@ this.onReceive=function(method,path,header,params,body){
 		  ]
 		}
 	  }:{};
-
+	  
 	  return {
 		url:"",
 		header:{

BIN
data/components/3ababc5e-15e9-45a7-8f38-2a6afd45c780/iot-http-biz-component-0.4.0-SNAPSHOT.jar


BIN
data/components/6c095554-35e7-4e9d-a8d2-bb919e9479f4/iot-emqx-component-0.4.0-SNAPSHOT.jar


BIN
data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js → data/components/eabb131d-8fd1-43a8-88d9-a198abfd3d42/component.js


+ 0 - 18
data/converters/6260396d67aced2696184053/converter.js

@@ -1293,24 +1293,6 @@
     },
     "createAt": 1650171261224
   },
-  {
-    "id": "164951142660200010000000000000034",
-    "deviceId": "164951142660200010000000000000034",
-    "productKey": "KdJYpTp5ywNhmrmC",
-    "deviceName": "001",
-    "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
-    "state": {
-      "online": false
-    },
-    "createAt": 1649511426602,
-    "tag": {
-      "aligenie": {
-        "id": "aligenie",
-        "name": "天猫精灵接入",
-        "value": "是"
-      }
-    }
-  },
   {
     "id": "164785263238900cefafcfeeab0000125",
     "deviceId": "164785263238900cefafcfeeab0000125",

+ 2 - 2
data/init/home.json

@@ -1,13 +1,13 @@
 [
   {
-    "id": "iotkit",
+    "clientId": "iotkit",
     "name": "奇特物联",
     "clientSecret": "b86cb53d-c005-48a3-bb02-3c262151b68c",
     "allowUrl": "*",
     "createAt": 1652840868485
   },
   {
-    "id": "dueros",
+    "clientId": "dueros",
     "name": "小度音箱",
     "clientSecret": "750c67c2-29cb-40c3-bf4d-c0b9bf3eed88",
     "allowUrl": "*",

+ 6 - 18
data/init/product.json

@@ -1,26 +1,14 @@
 [
-  {
-    "id": "fee0e826-963f-4e53-a2cf-11e3e5f784ea",
-    "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
-    "name": "移动Onenet Studio接入",
-    "type": "biz",
-    "protocol": "http",
-    "jarFile": "iot-http-biz-component-0.3.2-SNAPSHOT.jar",
-    "config": "{\"port\":\"8086\"}",
-    "converter": "6260396d67aced2696184053",
-    "state": "stop",
-    "createAt": 1652238780184
-  },
   {
     "id": "eabb131d-8fd1-43a8-88d9-a198abfd3d42",
     "uid": "fa1c5eaa-de6e-48b6-805e-8f091c7bb831",
     "name": "MQTT标准协议组件",
     "type": "device",
     "protocol": "mqtt",
-    "jarFile": "iot-mqtt-component-0.3.2-SNAPSHOT.jar",
+    "jarFile": "iot-mqtt-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}",
     "converter": "6260396d67aced2696184053",
-    "state": "stop",
+    "state": "running",
     "createAt": 1650473458084
   },
   {
@@ -29,10 +17,10 @@
     "name": "EMQX标准协议组件",
     "type": "device",
     "protocol": "mqtt",
-    "jarFile": "iot-emqx-component-0.3.2-SNAPSHOT.jar",
+    "jarFile": "iot-emqx-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}",
     "converter": "6260396d67aced2696184053",
-    "state": "stop",
+    "state": "stopped",
     "createAt": 1653180468724
   },
   {
@@ -41,10 +29,10 @@
     "name": "小度音箱接入组件",
     "type": "biz",
     "protocol": "http",
-    "jarFile": "iot-http-biz-component-0.3.2-SNAPSHOT.jar",
+    "jarFile": "iot-http-biz-component-0.4.0-SNAPSHOT.jar",
     "config": "{\"port\":\"8084\"}",
     "converter": "",
-    "state": "stop",
+    "state": "stopped",
     "createAt": 1650685502665
   }
 ]

+ 6 - 6
data/init/protocolConverter.json

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iotkit-parent</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -43,17 +43,17 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-dao</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
 
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-data-service</artifactId>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 18 - 6
iot-auth-server/readme.txt

@@ -1,10 +1,19 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.oauth.controller;
 
 import cc.iotkit.common.Constants;
 import cc.iotkit.common.utils.CodecUtil;
 import cc.iotkit.common.utils.ReflectUtil;
-import cc.iotkit.dao.OauthClientCache;
-import cc.iotkit.dao.UserInfoCache;
+import cc.iotkit.data.IOauthClientData;
+import cc.iotkit.data.IUserInfoData;
 import cc.iotkit.model.OauthClient;
 import cc.iotkit.model.UserInfo;
 import cc.iotkit.oauth.vo.UserInfoVo;
@@ -16,6 +25,7 @@ import com.ejlchina.okhttps.OkHttps;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cglib.beans.BeanMap;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -36,16 +46,18 @@ public class AuthClientController {
     private String serverUrl;
 
     @Autowired
-    private OauthClientCache oauthClientCache;
+    @Qualifier("oauthClientDataCache")
+    private IOauthClientData oauthClientData;
     @Autowired
-    private UserInfoCache userInfoCache;
+    @Qualifier("userInfoDataCache")
+    private IUserInfoData userInfoData;
 
     /**
      * 根据Code码进行登录,获取 Access-Token 和 用户信息
      */
     @RequestMapping("/codeLogin")
     public SaResult codeLogin(String code, String clientId) {
-        OauthClient oauthClient = oauthClientCache.getClient(clientId);
+        OauthClient oauthClient = oauthClientData.findByClientId(clientId);
         if (oauthClient == null) {
             return SaResult.error("clientId does not exist");
         }
@@ -117,7 +129,7 @@ public class AuthClientController {
     }
 
     private UserInfoVo getUserInfo(String uid) {
-        UserInfo userInfo = userInfoCache.getUserInfo(uid);
+        UserInfo userInfo = userInfoData.findById(uid);
         UserInfoVo userVo = new UserInfoVo();
         ReflectUtil.copyNoNulls(userInfo, userVo);
         return userVo;

+ 3 - 3
iot-auth-server/src/main/java/cc/iotkit/oauth/controller/AuthServerController.java

@@ -10,7 +10,7 @@
 package cc.iotkit.oauth.controller;
 
 import cc.iotkit.common.utils.JsonUtil;
-import cc.iotkit.dao.UserInfoRepository;
+import cc.iotkit.data.IUserInfoData;
 import cc.iotkit.model.UserInfo;
 import cc.iotkit.oauth.service.TokenRequestHandler;
 import cc.iotkit.utils.AuthUtil;
@@ -33,7 +33,7 @@ import java.util.Map;
 public class AuthServerController {
 
     @Autowired
-    private UserInfoRepository userInfoRepository;
+    private IUserInfoData userInfoData;
 
     /**
      * 处理所有OAuth相关请求
@@ -56,7 +56,7 @@ public class AuthServerController {
                 // 登录处理函数
                         setDoLoginHandle((name, pwd) -> {
                     try {
-                        UserInfo userInfo = userInfoRepository.findByUid(name);
+                        UserInfo userInfo = userInfoData.findByUid(name);
                         if (userInfo != null) {
                             String secret = userInfo.getSecret();
                             if (AuthUtil.checkPwd(pwd, secret)) {

+ 5 - 3
iot-auth-server/src/main/java/cc/iotkit/oauth/service/SaOAuth2TemplateImpl.java

@@ -11,25 +11,27 @@ package cc.iotkit.oauth.service;
 
 import cc.iotkit.common.Constants;
 import cc.iotkit.common.utils.CodecUtil;
-import cc.iotkit.dao.OauthClientCache;
+import cc.iotkit.data.IOauthClientData;
 import cc.iotkit.model.OauthClient;
 import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
 import cn.dev33.satoken.oauth2.model.SaClientModel;
 import cn.dev33.satoken.stp.StpUtil;
 import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 @Component
 public class SaOAuth2TemplateImpl extends SaOAuth2Template {
 
     @Autowired
-    private OauthClientCache oauthClientCache;
+    @Qualifier("oauthClientDataCache")
+    private IOauthClientData oauthClientData;
 
     // 根据 id 获取 Client 信息
     @Override
     public SaClientModel getClientModel(String clientId) {
-        OauthClient client = oauthClientCache.getClient(clientId);
+        OauthClient client = oauthClientData.findByClientId(clientId);
         if (client == null) {
             return null;
         }

+ 6 - 4
iot-auth-server/src/main/java/cc/iotkit/oauth/service/StpInterfaceImpl.java

@@ -9,10 +9,11 @@
  */
 package cc.iotkit.oauth.service;
 
-import cc.iotkit.dao.UserInfoCache;
+import cc.iotkit.data.IUserInfoData;
 import cc.iotkit.model.UserInfo;
 import cn.dev33.satoken.stp.StpInterface;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -21,14 +22,15 @@ import java.util.List;
 public class StpInterfaceImpl implements StpInterface {
 
     @Autowired
-    private UserInfoCache userInfoCache;
+    @Qualifier("userInfoDataCache")
+    private IUserInfoData userInfoData;
 
     /**
      * 返回一个账号所拥有的权限码集合
      */
     @Override
     public List<String> getPermissionList(Object loginId, String loginType) {
-        UserInfo userInfo = userInfoCache.getUserInfo(loginId.toString());
+        UserInfo userInfo = userInfoData.findById(loginId.toString());
         return userInfo.getPermissions();
     }
 
@@ -37,7 +39,7 @@ public class StpInterfaceImpl implements StpInterface {
      */
     @Override
     public List<String> getRoleList(Object loginId, String loginType) {
-        UserInfo userInfo = userInfoCache.getUserInfo(loginId.toString());
+        UserInfo userInfo = userInfoData.findById(loginId.toString());
         return userInfo.getRoles();
     }
 

+ 9 - 0
iot-auth-server/src/main/java/cc/iotkit/oauth/service/TokenRequestHandler.java

@@ -1,3 +1,12 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.oauth.service;
 
 import cn.dev33.satoken.context.SaHolder;

+ 1 - 1
iot-auth-server/src/main/java/cc/iotkit/oauth/vo/UserInfoVo.java

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

+ 8 - 8
iot-common/readme.txt

@@ -15,21 +15,21 @@ public interface Constants {
 
     String ACCOUNT_SECRET = "3n1z33kzvpgz1foijpkepyd3e8tw84us";
 
-    String PRODUCT_CACHE = "product_cache";
+    String CACHE_PRODUCT = "product_cache";
 
-    String DEVICE_CACHE = "device_cache";
+    String CACHE_DEVICE_INFO = "device_info_cache";
 
-    String DEVICE_STATS_CACHE = "device_stats_cache";
+    String CACHE_DEVICE_STATS = "device_stats_cache";
 
-    String CATEGORY_CACHE = "category_cache";
+    String CACHE_CATEGORY = "category_cache";
 
-    String SPACE_CACHE = "space_cache";
+    String CACHE_SPACE = "space_cache";
 
     String THING_MODEL_CACHE = "thing_model_cache";
 
-    String USER_CACHE = "user_info_cache";
+    String CACHE_USER_INFO = "user_info_cache";
 
-    String OAUTH_CLIENT_CACHE = "oauth_client_cache";
+    String CACHE_OAUTH_CLIENT = "oauth_client_cache";
 
     String WECHAT_APP_ID = "wx791cb7bf75950e0c";
 
@@ -37,7 +37,7 @@ public interface Constants {
 
     String APP_DESIGN_CACHE = "app_design_cache";
 
-    String PRODUCT_SCRIPT_CACHE = "product_script_cache";
+    String CACHE_PRODUCT_SCRIPT = "product_script_cache";
 
     /**
      * 管理员角色

+ 6 - 1
iot-common/src/main/java/cc/iotkit/common/exception/BizException.java

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -18,6 +18,11 @@
 
     <dependencies>
 
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

+ 1 - 1
iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java

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

+ 10 - 5
iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -79,22 +79,27 @@
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-dao</artifactId>
+            <artifactId>iot-component-base</artifactId>
         </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-component-base</artifactId>
+            <artifactId>iot-message-bus</artifactId>
         </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-message-bus</artifactId>
+            <artifactId>iot-data-service</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-temporal-service</artifactId>
         </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-device-dao</artifactId>
+            <artifactId>iot-data-cache</artifactId>
         </dependency>
 
     </dependencies>

+ 3 - 3
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java

@@ -16,7 +16,7 @@ import cc.iotkit.comp.CompConfig;
 import cc.iotkit.comp.IComponent;
 import cc.iotkit.comps.config.ComponentConfig;
 import cc.iotkit.comps.service.DeviceBehaviourService;
-import cc.iotkit.dao.ProtocolComponentRepository;
+import cc.iotkit.data.IProtocolComponentData;
 import cc.iotkit.model.protocol.ProtocolComponent;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
@@ -41,14 +41,14 @@ public class BizComponentManager {
     @Autowired
     private ComponentConfig componentConfig;
     @Autowired
-    private ProtocolComponentRepository componentRepository;
+    private IProtocolComponentData protocolComponentData;
     @Autowired
     private DeviceBehaviourService deviceBehaviourService;
 
     @PostConstruct
     public void init() {
         try {
-            List<ProtocolComponent> componentList = componentRepository
+            List<ProtocolComponent> componentList = protocolComponentData
                     .findByStateAndType(ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_BIZ);
             for (ProtocolComponent component : componentList) {
                 register(component);

+ 18 - 15
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java

@@ -23,9 +23,9 @@ import cc.iotkit.converter.Device;
 import cc.iotkit.converter.DeviceMessage;
 import cc.iotkit.converter.ScriptConverter;
 import cc.iotkit.common.thing.ThingService;
-import cc.iotkit.dao.DeviceCache;
-import cc.iotkit.dao.ProductCache;
-import cc.iotkit.dao.ProtocolComponentRepository;
+import cc.iotkit.data.IDeviceInfoData;
+import cc.iotkit.data.IProductData;
+import cc.iotkit.data.IProtocolComponentData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.Product;
@@ -34,6 +34,7 @@ import cc.iotkit.model.protocol.ProtocolConverter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Component;
 
@@ -60,25 +61,27 @@ public class DeviceComponentManager {
     @Autowired
     private ComponentConfig componentConfig;
     @Autowired
-    private ProtocolComponentRepository componentRepository;
+    private IProtocolComponentData protocolComponentData;
     @Autowired
-    private DeviceCache deviceCache;
+    @Qualifier("productDataCache")
+    IProductData productData;
     @Autowired
-    ProductCache productCache;
+    @Qualifier("deviceInfoDataCache")
+    private IDeviceInfoData deviceInfoData;
     @Autowired
     private DeviceRouter deviceRouter;
 
     @PostConstruct
     public void init() {
-        try {
-            List<ProtocolComponent> componentList = componentRepository.findByStateAndType(
-                    ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_DEVICE);
-            for (ProtocolComponent component : componentList) {
+        List<ProtocolComponent> componentList = protocolComponentData.findByStateAndType(
+                ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_DEVICE);
+        for (ProtocolComponent component : componentList) {
+            try {
                 register(component);
                 start(component.getId());
+            } catch (Throwable e) {
+                log.error("init protocol components error", e);
             }
-        } catch (Throwable e) {
-            log.error("init protocol components error", e);
         }
     }
 
@@ -170,14 +173,14 @@ public class DeviceComponentManager {
             throw new BizException("there is no components");
         }
 
-        DeviceInfo deviceInfo = deviceCache.getDeviceInfo(service.getProductKey(), service.getDeviceName());
-        Product product = productCache.findById(service.getProductKey());
+        DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(service.getProductKey(), service.getDeviceName());
+        Product product = productData.findById(service.getProductKey());
         String linkPk = service.getProductKey();
         String linkDn = service.getDeviceName();
 
         if (product.isTransparent()) {
             //如果是透传设备,取父级设备进行链路查找
-            DeviceInfo parent = deviceCache.get(deviceInfo.getParentId());
+            DeviceInfo parent = deviceInfoData.findByDeviceId(deviceInfo.getParentId());
             linkPk = parent.getProductKey();
             linkDn = parent.getDeviceName();
         }

+ 0 - 10
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java

@@ -1,6 +1,5 @@
 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;
@@ -54,13 +53,4 @@ 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);
-    }
 }

+ 29 - 24
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java

@@ -16,7 +16,9 @@ import cc.iotkit.common.utils.JsonUtil;
 import cc.iotkit.common.utils.UniqueIdUtil;
 import cc.iotkit.comp.model.DeviceState;
 import cc.iotkit.comp.model.RegisterInfo;
-import cc.iotkit.dao.*;
+import cc.iotkit.data.IDeviceInfoData;
+import cc.iotkit.data.IProductModelData;
+import cc.iotkit.data.IProductData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.Product;
@@ -25,28 +27,27 @@ import cc.iotkit.mq.MqProducer;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
 import java.util.List;
-import java.util.Optional;
+import java.util.UUID;
 
 @Slf4j
 @Service
 public class DeviceBehaviourService {
 
     @Autowired
-    private ProductRepository productRepository;
+    private IProductModelData productModelData;
     @Autowired
-    private ProductModelRepository productModelRepository;
-    @Autowired
-    private ProductCache productCache;
-    @Autowired
-    private DeviceInfoRepository deviceInfoRepository;
-    @Autowired
-    private DeviceCache deviceCache;
+    @Qualifier("deviceInfoDataCache")
+    private IDeviceInfoData deviceInfoData;
     @Autowired
     private MqProducer<ThingModelMessage> producer;
+    @Autowired
+    @Qualifier("productDataCache")
+    private IProductData productData;
 
     public void register(RegisterInfo info) {
         try {
@@ -80,7 +81,7 @@ public class DeviceBehaviourService {
         if (parentId != null) {
             //透传设备:pk为空、model不为空,使用model查询产品
             if (StringUtils.isBlank(pk) && StringUtils.isNotBlank(model)) {
-                ProductModel productModel = productModelRepository.findByModel(model);
+                ProductModel productModel = productModelData.findByModel(model);
                 if (productModel == null) {
                     throw new BizException("product model does not exist");
                 }
@@ -88,13 +89,12 @@ public class DeviceBehaviourService {
             }
         }
 
-        Optional<Product> optProduct = productRepository.findById(pk);
-        if (optProduct.isEmpty()) {
+        Product product = productData.findById(pk);
+        if (product == null) {
             throw new BizException("Product does not exist");
         }
-        Product product = optProduct.get();
         String uid = product.getUid();
-        DeviceInfo device = deviceInfoRepository.findByProductKeyAndDeviceName(pk, info.getDeviceName());
+        DeviceInfo device = deviceInfoData.findByProductKeyAndDeviceName(pk, info.getDeviceName());
         boolean reportMsg = false;
 
         if (device != null) {
@@ -130,13 +130,14 @@ public class DeviceBehaviourService {
             device.setParentId(parentId);
             reportMsg = true;
         }
-        deviceInfoRepository.save(device);
+        deviceInfoData.save(device);
 
         //新设备或更换网关需要产生注册消息
         if (reportMsg) {
             log.info("device registered:{}", JsonUtil.toJsonString(device));
             //新注册设备注册消息
             ThingModelMessage modelMessage = new ThingModelMessage(
+                    UUID.randomUUID().toString(),
                     UniqueIdUtil.newRequestId(), "",
                     pk, dn,
                     ThingModelMessage.TYPE_LIFETIME, "register",
@@ -154,7 +155,7 @@ public class DeviceBehaviourService {
                            String deviceName,
                            String productSecret,
                            String deviceSecret) {
-        DeviceInfo deviceInfo = deviceInfoRepository.findByProductKeyAndDeviceName(productKey, deviceName);
+        DeviceInfo deviceInfo = deviceInfoData.findByProductKeyAndDeviceName(productKey, deviceName);
         if (deviceInfo == null) {
             throw new BizException("device does not exist");
         }
@@ -177,20 +178,23 @@ public class DeviceBehaviourService {
     public void deviceStateChange(String productKey,
                                   String deviceName,
                                   boolean online) {
-        DeviceInfo device = deviceInfoRepository.findByProductKeyAndDeviceName(productKey, deviceName);
+        DeviceInfo device = deviceInfoData.findByProductKeyAndDeviceName(productKey, deviceName);
         if (device == null) {
             log.warn(String.format("productKey: %s,device: %s,online: %s", productKey, device, online));
             throw new BizException("device does not exist");
         }
         deviceStateChange(device, online);
 
+        //父设备ID不为空说明是子设备
         if (device.getParentId() != null) {
             return;
         }
 
-        List<DeviceInfo> subDevices = deviceInfoRepository.findByParentId(device.getDeviceId());
-        for (DeviceInfo subDevice : subDevices) {
-            Product product = productCache.findById(subDevice.getProductKey());
+        //否则为父设备,同步透传子设备状态
+        List<String> subDeviceIds = deviceInfoData.findSubDeviceIds(device.getDeviceId());
+        for (String subDeviceId : subDeviceIds) {
+            DeviceInfo subDevice=deviceInfoData.findByDeviceId(subDeviceId);
+            Product product = productData.findById(subDevice.getProductKey());
             Boolean transparent = product.getTransparent();
             //透传设备父设备上线,子设备也上线。非透传设备父设备离线,子设备才离线
             if (transparent != null && transparent || !online) {
@@ -207,10 +211,11 @@ public class DeviceBehaviourService {
             device.getState().setOnline(false);
             device.getState().setOfflineTime(System.currentTimeMillis());
         }
-        deviceInfoRepository.save(device);
+        deviceInfoData.save(device);
 
         //设备状态变更消息
         ThingModelMessage modelMessage = new ThingModelMessage(
+                UUID.randomUUID().toString(),
                 UniqueIdUtil.newRequestId(), "",
                 device.getProductKey(), device.getDeviceName(),
                 ThingModelMessage.TYPE_STATE,
@@ -225,8 +230,8 @@ public class DeviceBehaviourService {
 
     public void reportMessage(ThingModelMessage message) {
         try {
-            DeviceInfo device = deviceCache.getDeviceInfo(message.getProductKey(),
-                    message.getDeviceName());
+            DeviceInfo device = deviceInfoData.findByProductKeyAndDeviceName(
+                    message.getProductKey(), message.getDeviceName());
             if (device == null) {
                 return;
             }

+ 4 - 4
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigService.java → iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigConsumer.java

@@ -13,7 +13,7 @@ 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.data.IDeviceConfigData;
 import cc.iotkit.model.device.DeviceConfig;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.mq.ConsumerHandler;
@@ -30,7 +30,7 @@ import java.util.Map;
  */
 @Slf4j
 @Service
-public class DeviceConfigService implements ConsumerHandler<ThingModelMessage> {
+public class DeviceConfigConsumer implements ConsumerHandler<ThingModelMessage> {
 
     @Autowired
     private MqConsumer<ThingModelMessage> configMessageConsumer;
@@ -39,7 +39,7 @@ public class DeviceConfigService implements ConsumerHandler<ThingModelMessage> {
     public DeviceComponentManager deviceComponentManager;
 
     @Autowired
-    private DeviceConfigRepository deviceConfigRepository;
+    private IDeviceConfigData deviceConfigData;
 
     @PostConstruct
     public void init() {
@@ -52,7 +52,7 @@ public class DeviceConfigService implements ConsumerHandler<ThingModelMessage> {
             String identifier = msg.getIdentifier();
             if (ThingModelMessage.ID_CONFIG_GET.equals(identifier)) {
                 //收到设备获取配置消息,回复配置信息给设备
-                DeviceConfig deviceConfig = deviceConfigRepository.findByDeviceId(msg.getDeviceId());
+                DeviceConfig deviceConfig = deviceConfigData.findByDeviceId(msg.getDeviceId());
                 if (deviceConfig == null) {
                     return;
                 }

+ 3 - 27
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java

@@ -10,35 +10,28 @@
 package cc.iotkit.comps.service;
 
 import cc.iotkit.common.Constants;
-import cc.iotkit.dao.*;
-import cc.iotkit.model.device.DeviceInfo;
-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 cc.iotkit.temporal.IThingModelMessageData;
 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.UUID;
 
 @Slf4j
 @Service
 public class DeviceMessageConsumer implements ConsumerHandler<ThingModelMessage> {
     @Lazy
     @Autowired
-    private ThingModelMessageRepository messageRepository;
-    @Autowired
-    private DeviceCache deviceCache;
+    private IThingModelMessageData thingModelMessageData;
     @Autowired
     private MqConsumer<ThingModelMessage> thingModelMessageConsumer;
     @Autowired
     private MqProducer<ThingModelMessage> thingModelMessageMqProducer;
-    @Autowired
-    private MqProducer<DeviceReport> deviceReportProducer;
 
     @PostConstruct
     public void init() {
@@ -59,29 +52,12 @@ public class DeviceMessageConsumer implements ConsumerHandler<ThingModelMessage>
                 thingModelMessageMqProducer.publish(Constants.DEVICE_CONFIG_TOPIC, msg);
             }
 
-            //重新发布设备上报记录,不包含消息内容,用于数据统计
-            deviceReportProducer.publish(Constants.DEVICE_REPORT_RECORD_TOPIC, getDeviceReport(msg));
-
             //设备消息入库
-            messageRepository.save(msg);
+            thingModelMessageData.add(msg);
         } catch (Throwable e) {
             //不能重复消费
             log.error("device message consumer error", e);
         }
     }
 
-    private DeviceReport getDeviceReport(ThingModelMessage message) {
-        DeviceInfo device = deviceCache.get(message.getDeviceId());
-        return DeviceReport.builder()
-                .id(UUID.randomUUID().toString())
-                .deviceId(message.getDeviceId())
-                .productKey(message.getProductKey())
-                .deviceName(message.getDeviceName())
-                .uid(device.getUid())
-                .identifier(message.getIdentifier())
-                .type(message.getType())
-                .code(message.getCode())
-                .time(message.getTime())
-                .build();
-    }
 }

+ 19 - 9
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/PropertyPersistService.java → iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DevicePropertyConsumer.java

@@ -1,15 +1,25 @@
+/*
+ * +----------------------------------------------------------------------
+ * | 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.DeviceDao;
-import cc.iotkit.dao.DevicePropertyRepository;
+import cc.iotkit.data.IDeviceInfoData;
 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 cc.iotkit.temporal.IDevicePropertyData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
@@ -22,14 +32,15 @@ import java.util.Map;
  */
 @Slf4j
 @Service
-public class PropertyPersistService implements ConsumerHandler<ThingModelMessage> {
+public class DevicePropertyConsumer implements ConsumerHandler<ThingModelMessage> {
 
     @Autowired
     private MqConsumer<ThingModelMessage> thingModelMessageMqConsumer;
     @Autowired
-    private DeviceDao deviceDao;
+    private IDevicePropertyData devicePropertyData;
     @Autowired
-    private DevicePropertyRepository propertyRepository;
+    @Qualifier("deviceInfoDataCache")
+    private IDeviceInfoData deviceInfoData;
 
     @PostConstruct
     public void init() {
@@ -63,7 +74,7 @@ public class PropertyPersistService implements ConsumerHandler<ThingModelMessage
 
         //批量保存
         try {
-            propertyRepository.saveAll(batch);
+            devicePropertyData.addProperties(batch);
         } catch (Throwable e) {
             log.warn("save property data error", e);
         }
@@ -74,9 +85,8 @@ public class PropertyPersistService implements ConsumerHandler<ThingModelMessage
      */
     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);
+            log.info("save device property,deviceId:{},property:{}", deviceId, JsonUtil.toJsonString(properties));
+            deviceInfoData.saveProperties(deviceId, properties);
         } catch (Throwable e) {
             log.error("save device current properties error", e);
         }

+ 0 - 40
iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/ReportRecordPersistService.java

@@ -1,40 +0,0 @@
-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);
-        }
-    }
-
-}

BIN
iot-components/iot-ctwing-component/.DS_Store


BIN
iot-components/iot-ctwing-component/lib/ctg-ag-sdk-core-2.5.0-20220512.061430-51.jar


+ 92 - 0
iot-components/iot-ctwing-component/pom.xml

@@ -0,0 +1,92 @@
+<?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-components</artifactId>
+        <groupId>cc.iotkit</groupId>
+        <version>0.4.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>iot-ctwing-component</artifactId>
+
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.vertx</groupId>
+            <artifactId>vertx-web-proxy</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ctg.ag</groupId>
+            <artifactId>ctg-ag-sdk-core</artifactId>
+            <version>2.5.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.ctg.ag</groupId>
+            <artifactId>ag-sdk-biz-84356.tar.gz</artifactId>
+            <version>20220603.182201-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-component-base</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.2.4</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <artifactSet>
+                        <includes>
+                            <include>io.vertx:vertx-web-proxy</include>
+                            <include>io.vertx:vertx-web</include>
+                            <include>io.vertx:vertx-bridge-common</include>
+                            <include>io.vertx:vertx-http-proxy</include>
+                            <include>io.vertx:vertx-core</include>
+                            <include>io.netty:netty-codec-http2</include>
+                            <include>com.ctg.ag:ctg-ag-sdk-core</include>
+                            <include>com.ctg.ag:ag-sdk-biz-84356.tar.gz</include>
+                            <include>org.apache.httpcomponents:httpasyncclient</include>
+                        </includes>
+                    </artifactSet>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>11</source>
+                    <target>11</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 34 - 0
iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingConfig.java

@@ -0,0 +1,34 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.comp.http;
+
+import lombok.Data;
+
+@Data
+public class CtwingConfig {
+
+    private int port;
+
+    /**
+     * ctwing推送消息加解密token
+     */
+    private String encryptToken;
+
+    /**
+     * ctwing应用的appKey
+     */
+    private String appKey;
+
+    /**
+     * ctwing应用的appSecret
+     */
+    private String appSecret;
+
+}

+ 206 - 0
iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java

@@ -0,0 +1,206 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.comp.http;
+
+import cc.iotkit.common.exception.BizException;
+import cc.iotkit.common.utils.CodecUtil;
+import cc.iotkit.common.utils.JsonUtil;
+import cc.iotkit.comp.AbstractDeviceComponent;
+import cc.iotkit.comp.CompConfig;
+import cc.iotkit.converter.DeviceMessage;
+import com.ctg.ag.sdk.biz.AepDeviceCommandClient;
+import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandRequest;
+import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandResponse;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.HttpServer;
+import io.vertx.core.http.HttpServerRequest;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.BodyHandler;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.beanutils.BeanUtils;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 电信天翼接入组件
+ */
+@Slf4j
+public class CtwingDeviceComponent extends AbstractDeviceComponent {
+
+    private final Vertx vertx = Vertx.vertx();
+
+    private CtwingConfig ctwingConfig;
+
+    private HttpServer backendServer;
+
+    private AepDeviceCommandClient commandClient;
+
+    @Override
+    public void create(CompConfig config) {
+        super.create(config);
+        this.ctwingConfig = JsonUtil.parse(config.getOther(), CtwingConfig.class);
+        commandClient = AepDeviceCommandClient.newClient()
+                .appKey(ctwingConfig.getAppKey())
+                .appSecret(ctwingConfig.getAppSecret())
+                .build();
+    }
+
+    @Override
+    public void start() {
+        backendServer = vertx.createHttpServer();
+        Router backendRouter = Router.router(vertx);
+
+        backendRouter.route().handler(BodyHandler.create())
+                .handler(rc -> {
+                    try {
+                        Map<String, Object> httpHeader = ProtocolUtil.getData(rc.request().headers());
+                        log.info("request header:{}", JsonUtil.toJsonString(httpHeader));
+                        Map<String, List<Object>> httpParams = ProtocolUtil.getListData(rc.request().params());
+                        log.info("request params:{}", JsonUtil.toJsonString(httpParams));
+
+                        HttpServerRequest httpRequest = rc.request();
+                        String contentType = httpRequest.headers().get("Content-Type");
+                        String requestBody = "";
+                        int responseCode = 500;
+                        if ("application/json".equals(contentType)) {
+                            requestBody = rc.getBody().toString();
+                            EncodedMessage msg = JsonUtil.parse(requestBody, EncodedMessage.class);
+                            String content = CodecUtil.aesDecrypt(ctwingConfig.getEncryptToken(), msg.getEnc_msg());
+                            log.info("decrypt msg:{}", content);
+                            getHandler().onReceive(httpHeader, "", content);
+                            responseCode = 200;
+                        }
+                        log.info("request body:{}", requestBody);
+
+                        rc.response().setStatusCode(responseCode)
+                                .end();
+                    } catch (Throwable e) {
+                        log.error("handle request error", e);
+                        rc.response().setStatusCode(500).end();
+                    }
+                });
+
+        backendServer.requestHandler(backendRouter)
+                .listen(ctwingConfig.getPort(), (http) -> {
+                    if (http.succeeded()) {
+                        log.info("http server create succeed,port:{}", ctwingConfig.getPort());
+                    } else {
+                        log.error("http server create failed", http.cause());
+                    }
+                });
+    }
+
+    @Override
+    public DeviceMessage send(DeviceMessage message) {
+        Object obj = message.getContent();
+        if (!(obj instanceof Map)) {
+            throw new BizException("message content is not Map");
+        }
+        SendContent msg = new SendContent();
+        try {
+            BeanUtils.populate(msg, (Map<String, ? extends Object>) obj);
+        } catch (Throwable e) {
+            throw new BizException("message content is incorrect");
+        }
+
+        CreateCommandRequest request = new CreateCommandRequest();
+        request.setParamMasterKey(msg.getMasterKey());
+        request.setBody(("{\n" +
+                "    \"content\":{\n" +
+                "        \"dataType\":2,\n" +
+                "        \"payload\":\"" + msg.getPayload() + "\"\n" +
+                "    },\n" +
+                "    \"deviceId\":\"" + message.getDeviceName() + "\",\n" +
+                "    \"operator\":\"none\",\n" +
+                "    \"productId\":" + msg.getProductId() + ",\n" +
+                "    \"ttl\":0,\n" +
+                "    \"level\":1\n" +
+                "}").getBytes());
+        CreateCommandResponse response;
+        try {
+            response = commandClient.CreateCommand(request);
+        } catch (Exception e) {
+            throw new RuntimeException("send cmd to ctwing error", e);
+        }
+
+        String body = new String(response.getBody());
+        log.info("send ctwing cmd result:{}", body);
+        if (response.getStatusCode() != 200) {
+            throw new RuntimeException("send cmd to ctwing error:" + body);
+        }
+
+        CtwingCmdRsp cmdRsp = JsonUtil.parse(body, CtwingCmdRsp.class);
+        if (cmdRsp.code != 0) {
+            throw new RuntimeException("send cmd to ctwing failed:" + body);
+        }
+
+        return message;
+    }
+
+    @Override
+    public void stop() {
+        backendServer.close();
+    }
+
+    @Override
+    public void destroy() {
+    }
+
+    /**
+     * 将数据编码成68H16H协议数据包,给js调用
+     */
+    public String encode68H16H(String devId, String cardNo, Object[] values) {
+        return ProtocolUtil.encode68H16H(devId, cardNo, values);
+    }
+
+    /**
+     * 将68H16H协议的base64字符串消息解码为map数据,给js调用
+     */
+    public Map<String, Object> decode68H16H(String base64Str) {
+        return ProtocolUtil.decode68H16H(base64Str);
+    }
+
+    @Data
+    public static class EncodedMessage {
+        private String msg_signature;
+        private String enc_msg;
+    }
+
+    @Data
+    public static class SendContent {
+        private String masterKey;
+        private String productId;
+        private String payload;
+    }
+
+
+    @Data
+    public static class CtwingCmdRsp {
+        private int code;
+        protected String msg;
+        protected CmdResult result;
+    }
+
+    @Data
+    public static class CmdResult {
+        private String commandId;
+        private String command;
+        private String commandStatus;
+        private int productId;
+        private String deviceId;
+        private String imei;
+        private String createBy;
+        private String createTime;
+        private int ttl;
+    }
+
+}

+ 129 - 0
iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/ProtocolUtil.java

@@ -0,0 +1,129 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.comp.http;
+
+import cc.iotkit.common.utils.HexUtil;
+import io.vertx.core.MultiMap;
+
+import java.nio.ByteBuffer;
+import java.util.*;
+
+public class ProtocolUtil {
+
+    /**
+     * 将数据编码成68H16H协议数据包
+     */
+    public static String encode68H16H(String devId, String cardNo, Object[] values) {
+        //构建数据域
+        ByteBuffer bufferData = ByteBuffer.allocate(7);
+        //模拟数据..
+        bufferData.put((byte) 1);
+        bufferData.putShort((short) 4);
+        bufferData.putInt(100);
+        byte[] data = bufferData.array();
+
+        //起始符到卡号部分数据
+        ByteBuffer buffer = ByteBuffer.allocate(1 + 2 + 5 + data.length + 4 + 7 + 2);
+        int len = 1 + 2 + 5 + data.length + 4 + 7 + 2;
+        buffer.put((byte) len);
+        buffer.put((byte) 0x68);
+        buffer.putShort((short) 0);
+        buffer.put(devId.getBytes());
+        buffer.put(data);
+        buffer.putInt(0);
+        buffer.put(cardNo.getBytes());
+        byte[] data1 = buffer.array();
+
+        //校验码
+        int check = HexUtil.calcCrc16(data1, 0, data1.length);
+        //完整数据包
+        buffer = ByteBuffer.allocate(1 + data1.length + 2 + 1);
+        buffer.put((byte) (data1.length + 2));//帧长度
+        buffer.put(data1);//起始符到卡号部分数据
+        buffer.putShort((short) check);//检验码
+        buffer.put((byte) 0x16);
+        return HexUtil.toHexString(buffer.array());
+    }
+
+    /**
+     * 将68H16H协议的base64字符串消息解码为map数据
+     */
+    public static Map<String, Object> decode68H16H(String base64Str) {
+        byte[] bytes = Base64.getDecoder().decode(base64Str);
+
+        Map<String, Object> decodeData = new HashMap<>();
+        ByteBuffer buffer = ByteBuffer.wrap(bytes);
+        buffer.flip();
+        byte len = buffer.get();//帧长度
+        buffer.get();//帧起始符
+        buffer.getShort();//预留2byte
+        byte[] devId = new byte[5];//设备ID
+        buffer.get(devId, 0, 5);
+        String strDevId = new String(devId);
+        decodeData.put("devId", strDevId);
+
+        //数据域长度=帧长度-起始符-预留-设备ID-系统用-卡号-校验码
+        int dataLen = len - 1 - 2 - 5 - 4 - 7 - 2;
+        //数据域
+        byte[] data = new byte[dataLen];
+        buffer.get(data, 0, dataLen);
+        Object[] values = ProtocolUtil.getTlvValues(data);
+        //模拟取1个值
+        decodeData.put("flow", values[0]);
+
+        buffer.getInt();//系统用
+        //卡号
+        byte[] card = new byte[7];
+        buffer.get(card, 0, card.length);
+        String cardNo = new String(card);
+        decodeData.put("cardNo", cardNo);
+
+        return decodeData;
+    }
+
+    public static Object[] getTlvValues(byte[] data) {
+        List<Object> result = new ArrayList<>();
+
+        ByteBuffer dataBuff = ByteBuffer.wrap(data);
+        dataBuff.flip();
+        //对数据域解码...
+        while (dataBuff.hasRemaining()) {
+            byte t = dataBuff.get();
+            byte l = dataBuff.get();
+            byte[] bytesV = new byte[l];
+            dataBuff.get(bytesV, 0, bytesV.length);
+            if (t == 0) {
+                //int
+                result.add(HexUtil.bytesToInt(bytesV));
+            }
+            //..其它类型
+        }
+        return result.toArray();
+    }
+
+    public static Map<String, List<Object>> getListData(MultiMap multiMap) {
+        Map<String, List<Object>> listData = new HashMap<>();
+        for (Map.Entry<String, String> entry : multiMap.entries()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            listData.putIfAbsent(key, new ArrayList<>());
+            listData.get(key).add(value);
+        }
+        return listData;
+    }
+
+    public static Map<String, Object> getData(MultiMap multiMap) {
+        Map<String, Object> data = new HashMap<>();
+        for (Map.Entry<String, String> entry : multiMap.entries()) {
+            data.put(entry.getKey(), entry.getValue());
+        }
+        return data;
+    }
+}

+ 36 - 0
iot-components/iot-ctwing-component/src/main/resources/component.js

@@ -0,0 +1,36 @@
+//引用api工具类
+var apiTool = Java.type("cc.iotkit.comp.biz.ApiTool");
+//api配置
+apiTool.config("http://localhost",8086,3000);
+
+this.onReceive=function(method,path,header,params,body){
+  //method:post、get、delete...
+  //path:请求路径
+  //header:http请求头数据,结构:{xx:xx,yy:yy}
+  //params:请求参数,结构:{xx:[...],yy:[...]}
+  //body:请求体,当提交的数据为json格式时使用,结构:{xx:xx,yy:yy}
+  apiTool.log("onReceive method:"+method);
+  apiTool.log("onReceive path:"+path);
+  apiTool.log("onReceive header:"+header);
+  apiTool.log("onReceive params:"+params);
+  apiTool.log("onReceive body:"+body);
+  var duHeader=body.header;
+  var namespace=duHeader.namespace;
+  var requestName=duHeader.name;
+  var messageId=duHeader.messageId;
+  var duPayload=duHeader.payload;
+  var token=duHeader.accessToken;
+
+  //设备发现
+  if(namespace=="DuerOS.ConnectedHome.Discovery" && requestName=="DiscoverAppliancesRequest"){
+
+  }
+
+  return {
+    url:"xx",//不指定直接作为响应返回
+    header:{
+      contentType:"xx"
+    },
+    content:"xx"
+  }
+}

+ 1 - 0
iot-components/iot-ctwing-component/src/main/resources/component.spi

@@ -0,0 +1 @@
+cc.iotkit.comp.http.CtwingDeviceComponent

+ 12 - 10
iot-components/iot-emqx-component/.DS_Store

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.2-SNAPSHOT</version>
+    <version>0.4.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-emqx-component</artifactId>
@@ -48,8 +48,10 @@
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>8</source>
-          <target>8</target>
+          <source>11</source>
+          <target>11</target>
+          <forceJavacCompilerUse>true</forceJavacCompilerUse>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
         </configuration>
       </plugin>
     </plugins>
@@ -82,25 +84,25 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-model</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
-      <artifactId>iot-dao</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <artifactId>iot-common</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
-      <artifactId>iot-common</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <artifactId>iot-component-base</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
-      <artifactId>iot-component-base</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <artifactId>iot-data-service</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

+ 185 - 0
iot-components/iot-emqx-component/emqx_rule_data.json

@@ -0,0 +1,185 @@
+{
+  "data":[
+    {
+      "rawsql":"SELECT\n  reason,\n  clientid,\n  username,\n  peername,\n  socketname\nFROM\n \"$events/client_connected\"",
+      "on_action_failed":"continue",
+      "metrics":[
+        {
+          "speed_max":0,
+          "speed_last5m":0,
+          "speed":0,
+          "passed":0,
+          "node":"emqx@127.0.0.1",
+          "no_result":0,
+          "matched":0,
+          "failed":0,
+          "exception":0
+        }
+      ],
+      "id":"rule:012980",
+      "for":[
+        "$events/client_connected"
+      ],
+      "enabled":true,
+      "description":"  连接",
+      "actions":[
+        {
+          "params":{
+            "target_topic":"/sys/client/connected",
+            "target_qos":1,
+            "payload_tmpl":"{\"reason\":\"${reason}\",\"clientid\":\"${clientid}\",\"username\":\"${username}\",\"peername\":\"${peername}\",\"socketname\":\"${socketname}\"}"
+          },
+          "name":"republish",
+          "metrics":[
+            {
+              "taken":0,
+              "success":0,
+              "node":"emqx@127.0.0.1",
+              "failed":0
+            }
+          ],
+          "id":"republish_16528854106752092",
+          "fallbacks":[
+
+          ]
+        }
+      ]
+    },
+    {
+      "rawsql":"SELECT\n  reason,\n  clientid,\n  username,\n  peername,\n  socketname\nFROM\n \"$events/client_disconnected\"",
+      "on_action_failed":"continue",
+      "metrics":[
+        {
+          "speed_max":0,
+          "speed_last5m":0,
+          "speed":0,
+          "passed":0,
+          "node":"emqx@127.0.0.1",
+          "no_result":0,
+          "matched":0,
+          "failed":0,
+          "exception":0
+        }
+      ],
+      "id":"rule:377397",
+      "for":[
+        "$events/client_disconnected"
+      ],
+      "enabled":true,
+      "description":"断开连接",
+      "actions":[
+        {
+          "params":{
+            "target_topic":"/sys/client/disconnected",
+            "target_qos":0,
+            "payload_tmpl":"{\"reason\":\"${reason}\",\"clientid\":\"${clientid}\",\"username\":\"${username}\",\"peername\":\"${peername}\",\"socketname\":\"${socketname}\"}"
+          },
+          "name":"republish",
+          "metrics":[
+            {
+              "taken":0,
+              "success":0,
+              "node":"emqx@127.0.0.1",
+              "failed":0
+            }
+          ],
+          "id":"republish_16528854190433372",
+          "fallbacks":[
+
+          ]
+        }
+      ]
+    },
+    {
+      "rawsql":"SELECT\n  clientid,\n  username,\n  topic,\n  qos\nFROM\n  \"$events/session_subscribed\"",
+      "on_action_failed":"continue",
+      "metrics":[
+        {
+          "speed_max":0,
+          "speed_last5m":0,
+          "speed":0,
+          "passed":0,
+          "node":"emqx@127.0.0.1",
+          "no_result":0,
+          "matched":0,
+          "failed":0,
+          "exception":0
+        }
+      ],
+      "id":"rule:758695",
+      "for":[
+        "$events/session_subscribed"
+      ],
+      "enabled":true,
+      "description":"子设备注册成功后,订阅topic: /sys/{productKey}/{deviceName}/c/#",
+      "actions":[
+        {
+          "params":{
+            "target_topic":"/sys/session/subscribed",
+            "target_qos":1,
+            "payload_tmpl":"{\"username\":\"${username}\",\"topic\":\"${topic}\",\"qos\":\"${qos}\",\"clientid\":\"${clientid}\"}"
+          },
+          "name":"republish",
+          "metrics":[
+            {
+              "taken":0,
+              "success":0,
+              "node":"emqx@127.0.0.1",
+              "failed":0
+            }
+          ],
+          "id":"republish_16530236276902029",
+          "fallbacks":[
+
+          ]
+        }
+      ]
+    },
+    {
+      "rawsql":"SELECT\n  clientid,\n  username,\n  topic,\n  qos\nFROM\n  \"$events/session_unsubscribed\"",
+      "on_action_failed":"continue",
+      "metrics":[
+        {
+          "speed_max":0,
+          "speed_last5m":0,
+          "speed":0,
+          "passed":0,
+          "node":"emqx@127.0.0.1",
+          "no_result":0,
+          "matched":0,
+          "failed":0,
+          "exception":0
+        }
+      ],
+      "id":"rule:514503",
+      "for":[
+        "$events/session_unsubscribed"
+      ],
+      "enabled":true,
+      "description":"",
+      "actions":[
+        {
+          "params":{
+            "target_topic":"/sys/session/unsubscribed",
+            "target_qos":0,
+            "payload_tmpl":"{\"username\":\"${username}\",\"topic\":\"${topic}\",\"qos\":\"${qos}\",\"clientid\":\"${clientid}\"}"
+          },
+          "name":"republish",
+          "metrics":[
+            {
+              "taken":0,
+              "success":0,
+              "node":"emqx@127.0.0.1",
+              "failed":0
+            }
+          ],
+          "id":"republish_16530237303922829",
+          "fallbacks":[
+
+          ]
+        }
+      ]
+    }
+  ],
+  "code":0
+}

+ 8 - 6
iot-components/iot-emqx-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -40,17 +40,17 @@
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-dao</artifactId>
+            <artifactId>iot-common</artifactId>
         </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-common</artifactId>
+            <artifactId>iot-component-base</artifactId>
         </dependency>
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-component-base</artifactId>
+            <artifactId>iot-data-service</artifactId>
         </dependency>
 
     </dependencies>
@@ -105,8 +105,10 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>8</source>
-                    <target>8</target>
+                    <source>11</source>
+                    <target>11</target>
+                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
+                    <useIncrementalCompilation>false</useIncrementalCompilation>
                 </configuration>
             </plugin>
         </plugins>

+ 6 - 0
iot-components/iot-emqx-component/readme.md

@@ -0,0 +1,6 @@
+## EMQX配置
+
+接入emqx需要在EMQX的规则引擎界面新增订阅、取消订阅、连接、断开连接的消息转发。
+
+配置内容见:emqx_rule_data.json
+

+ 4 - 4
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/AuthVerticle.java

@@ -18,7 +18,7 @@ import cc.iotkit.comp.model.DeviceState;
 import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.DeviceMessage;
 import cc.iotkit.common.thing.ThingService;
-import cc.iotkit.dao.DeviceInfoRepository;
+import cc.iotkit.data.IDeviceInfoData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import io.netty.handler.codec.mqtt.MqttQoS;
@@ -173,9 +173,9 @@ public class EmqxDeviceComponent extends AbstractDeviceComponent {
         if (parent == null) {
             return;
         }
-        DeviceInfoRepository deviceInfoRepository = SpringUtils.getBean(DeviceInfoRepository.class);
+        IDeviceInfoData deviceInfoService = SpringUtils.getBean("deviceInfoDataCache");
 
-        DeviceInfo deviceInfo = deviceInfoRepository.findByProductKeyAndDeviceName(state.getProductKey(), state.getDeviceName());
+        DeviceInfo deviceInfo = deviceInfoService.findByProductKeyAndDeviceName(state.getProductKey(), state.getDeviceName());
         if (deviceInfo != null) {
             boolean isOnline = DeviceState.STATE_ONLINE.equals(state.getState());
             deviceInfo.getState().setOnline(isOnline);
@@ -185,7 +185,7 @@ public class EmqxDeviceComponent extends AbstractDeviceComponent {
             if (isOnline) {
                 deviceInfo.getState().setOnlineTime(System.currentTimeMillis());
             }
-            deviceInfoRepository.save(deviceInfo);
+            deviceInfoService.save(deviceInfo);
         }
     }
 

+ 9 - 0
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/IScripter.java

@@ -1,3 +1,12 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.comp.emqx;
 
 import cc.iotkit.common.thing.ThingService;

+ 9 - 0
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/JsScripter.java

@@ -1,3 +1,12 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.comp.emqx;
 
 import cc.iotkit.common.thing.ThingService;

+ 9 - 0
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/LuaScripter.java

@@ -1,3 +1,12 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.comp.emqx;
 
 import cc.iotkit.common.thing.ThingService;

+ 27 - 6
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java

@@ -1,11 +1,21 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.comp.emqx;
 
 
+import cc.iotkit.common.thing.ThingService;
+import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.Device;
 import cc.iotkit.converter.DeviceMessage;
-import cc.iotkit.common.thing.ThingService;
-import cc.iotkit.dao.DeviceCache;
-import cc.iotkit.dao.ProductCache;
+import cc.iotkit.data.IDeviceInfoData;
+import cc.iotkit.data.IProductModelData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.ProductModel;
@@ -20,6 +30,9 @@ public class TransparentConverter {
     private final Map<String, IScripter> scripters = new HashMap<>();
     private final Map<String, String> scripts = new HashMap<>();
 
+    private IDeviceInfoData deviceInfoData;
+    private IProductModelData productModelData;
+
     /**
      * 透传解码
      */
@@ -50,12 +63,20 @@ public class TransparentConverter {
     }
 
     private ProductModel getScript(String model) {
-        return ProductCache.getInstance().getProductScriptByModel(model);
+        if (productModelData == null) {
+            productModelData = SpringUtils.getBean("productModelDataCache");
+        }
+
+        return productModelData.findByModel(model);
     }
 
     private DeviceInfo getGatewayInfo(String subPk, String subDn) {
-        String parentId = DeviceCache.getInstance().getDeviceInfo(subPk, subDn).getParentId();
-        return DeviceCache.getInstance().get(parentId);
+        if (deviceInfoData == null) {
+            deviceInfoData = SpringUtils.getBean("deviceInfoDataCache");
+        }
+
+        String parentId = deviceInfoData.findByProductKeyAndDeviceName(subPk, subDn).getParentId();
+        return deviceInfoData.findByDeviceId(parentId);
     }
 
     /**

+ 9 - 0
iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentMsg.java

@@ -1,3 +1,12 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
 package cc.iotkit.comp.emqx;
 
 import lombok.Data;

+ 5 - 5
iot-components/iot-emqx-component/src/main/resources/component.js

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.2-SNAPSHOT</version>
+    <version>0.4.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-http-biz-component</artifactId>
@@ -36,8 +36,8 @@
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>8</source>
-          <target>8</target>
+          <source>11</source>
+          <target>11</target>
         </configuration>
       </plugin>
     </plugins>
@@ -46,7 +46,7 @@
     <dependency>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>
-      <version>1.18.22</version>
+      <version>1.18.24</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
@@ -58,7 +58,7 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-component-base</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

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

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -66,8 +66,8 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>8</source>
-                    <target>8</target>
+                    <source>11</source>
+                    <target>11</target>
                 </configuration>
             </plugin>
         </plugins>

+ 10 - 8
iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java

@@ -3,7 +3,7 @@
   <parent>
     <artifactId>iot-components</artifactId>
     <groupId>cc.iotkit</groupId>
-    <version>0.3.2-SNAPSHOT</version>
+    <version>0.4.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>iot-mqtt-component</artifactId>
@@ -34,8 +34,10 @@
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>8</source>
-          <target>8</target>
+          <source>11</source>
+          <target>11</target>
+          <forceJavacCompilerUse>true</forceJavacCompilerUse>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
         </configuration>
       </plugin>
     </plugins>
@@ -62,7 +64,7 @@
     <dependency>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>
-      <version>1.18.22</version>
+      <version>1.18.24</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
@@ -80,19 +82,19 @@
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-common</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
       <artifactId>iot-component-base</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>cc.iotkit</groupId>
-      <artifactId>iot-dao</artifactId>
-      <version>0.3.2-SNAPSHOT</version>
+      <artifactId>iot-data-service</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

+ 6 - 4
iot-components/iot-mqtt-component/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>iot-components</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -55,7 +55,7 @@
 
         <dependency>
             <groupId>cc.iotkit</groupId>
-            <artifactId>iot-dao</artifactId>
+            <artifactId>iot-data-service</artifactId>
         </dependency>
 
     </dependencies>
@@ -89,8 +89,10 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>8</source>
-                    <target>8</target>
+                    <source>11</source>
+                    <target>11</target>
+                    <forceJavacCompilerUse>true</forceJavacCompilerUse>
+                    <useIncrementalCompilation>false</useIncrementalCompilation>
                 </configuration>
             </plugin>
         </plugins>

+ 17 - 5
iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/IScripter.java

@@ -10,11 +10,12 @@
 package cc.iotkit.comp.mqtt;
 
 
+import cc.iotkit.comp.utils.SpringUtils;
 import cc.iotkit.converter.Device;
 import cc.iotkit.converter.DeviceMessage;
 import cc.iotkit.common.thing.ThingService;
-import cc.iotkit.dao.DeviceCache;
-import cc.iotkit.dao.ProductCache;
+import cc.iotkit.data.IDeviceInfoData;
+import cc.iotkit.data.IProductModelData;
 import cc.iotkit.model.device.DeviceInfo;
 import cc.iotkit.model.device.message.ThingModelMessage;
 import cc.iotkit.model.product.ProductModel;
@@ -29,6 +30,9 @@ public class TransparentConverter {
     private final Map<String, IScripter> scripters = new HashMap<>();
     private final Map<String, String> scripts = new HashMap<>();
 
+    private IDeviceInfoData deviceInfoData;
+    private IProductModelData productModelData;
+
     /**
      * 透传解码
      */
@@ -59,12 +63,20 @@ public class TransparentConverter {
     }
 
     private ProductModel getScript(String model) {
-        return ProductCache.getInstance().getProductScriptByModel(model);
+        if (productModelData == null) {
+            productModelData = SpringUtils.getBean("productModelDataCache");
+        }
+
+        return productModelData.findByModel(model);
     }
 
     private DeviceInfo getGatewayInfo(String subPk, String subDn) {
-        String parentId = DeviceCache.getInstance().getDeviceInfo(subPk, subDn).getParentId();
-        return DeviceCache.getInstance().get(parentId);
+        if (deviceInfoData == null) {
+            deviceInfoData = SpringUtils.getBean("deviceInfoDataCache");
+        }
+
+        String parentId = deviceInfoData.findByProductKeyAndDeviceName(subPk, subDn).getParentId();
+        return deviceInfoData.findByDeviceId(parentId);
     }
 
     /**

+ 1 - 1
iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java

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

+ 0 - 38
iot-components/readme.txt

@@ -1,38 +0,0 @@
-<?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-dao</artifactId>
-
-    <dependencies>
-
-        <dependency>
-            <groupId>jakarta.annotation</groupId>
-            <artifactId>jakarta.annotation-api</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>cn.hutool</groupId>
-            <artifactId>hutool-core</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>cc.iotkit</groupId>
-            <artifactId>iot-model</artifactId>
-        </dependency>
-
-    </dependencies>
-
-</project>

+ 0 - 27
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/AligenieDeviceRepository.java

@@ -1,27 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.aligenie.AligenieDevice;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-import java.util.List;
-
-public interface AligenieDeviceRepository extends ElasticsearchRepository<AligenieDevice, String> {
-
-    void deleteByUid(String uid);
-
-    List<AligenieDevice> findByUid(String uid);
-
-    AligenieDevice findByUidAndDeviceId(String uid, String deviceId);
-
-    List<AligenieDevice> findByDeviceId(String deviceId);
-
-}

+ 0 - 42
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/CategoryCache.java

@@ -1,42 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.product.Category;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-
-
-@Repository
-public class CategoryCache {
-
-    @Autowired
-    private CategoryRepository categoryRepository;
-
-    private static CategoryCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static CategoryCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.CATEGORY_CACHE, key = "#id")
-    public Category getById(String id) {
-        return categoryRepository.findById(id).orElse(null);
-    }
-}

+ 0 - 61
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/CommonDao.java

@@ -1,61 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.Paging;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
-import org.springframework.data.elasticsearch.core.SearchHit;
-import org.springframework.data.elasticsearch.core.SearchHits;
-import org.springframework.data.elasticsearch.core.query.Criteria;
-import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
-import org.springframework.data.elasticsearch.core.query.Query;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Repository
-public class CommonDao {
-
-    @Autowired
-    private ElasticsearchRestTemplate elasticsearchRestTemplate;
-
-    /**
-     * 通用按条件分页查找
-     */
-    public <T> Paging<T> pagedFind(Class<T> cls, Criteria condition, Sort.Order order, int size, int page) {
-        Query query = new CriteriaQuery(condition);
-        long total = elasticsearchRestTemplate.count(query, cls);
-        query = query.setPageable(PageRequest.of(page - 1, size, Sort.by(order)));
-        SearchHits<T> searchHits = elasticsearchRestTemplate.search(query, cls);
-        List<T> list = new ArrayList<>();
-        for (SearchHit<T> searchHit : searchHits) {
-            list.add(searchHit.getContent());
-        }
-        return new Paging<>(total, list);
-    }
-
-    /**
-     * 通用按条件查询
-     */
-    public <T> List<T> find(Class<T> cls, Criteria condition) {
-        Query query = new CriteriaQuery(condition);
-        SearchHits<T> searchHits = elasticsearchRestTemplate.search(query, cls);
-        List<T> list = new ArrayList<>();
-        for (SearchHit<T> searchHit : searchHits) {
-            list.add(searchHit.getContent());
-        }
-        return list;
-    }
-
-}

+ 0 - 56
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceCache.java

@@ -1,56 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.device.DeviceInfo;
-import cc.iotkit.model.stats.DataItem;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-import java.util.List;
-
-@Repository
-public class DeviceCache {
-
-    @Autowired
-    private DeviceInfoRepository deviceInfoRepository;
-    @Autowired
-    private DeviceDao deviceDao;
-
-    private static DeviceCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static DeviceCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.DEVICE_CACHE, key = "#pk+'_'+#dn")
-    public DeviceInfo getDeviceInfo(String pk, String dn) {
-        return deviceInfoRepository.findByProductKeyAndDeviceName(pk, dn);
-    }
-
-    @Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
-    public DeviceInfo get(String deviceId) {
-        return deviceInfoRepository.findById(deviceId).orElse(null);
-    }
-
-    @Cacheable(value = Constants.DEVICE_STATS_CACHE, key = "#uid")
-    public List<DataItem> getDeviceStatsByCategory(String uid) {
-        return deviceDao.getDeviceStatsByCategory(uid);
-    }
-
-}

+ 0 - 270
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceDao.java

@@ -1,270 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.dao.config.EmbeddedEs;
-import cc.iotkit.model.Paging;
-import cc.iotkit.model.device.DeviceInfo;
-import cc.iotkit.model.product.Category;
-import cc.iotkit.model.product.Product;
-import cc.iotkit.model.stats.DataItem;
-import cn.hutool.core.bean.BeanUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.aggregations.AggregationBuilders;
-import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
-import org.elasticsearch.search.aggregations.bucket.terms.Terms;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
-import org.springframework.data.elasticsearch.core.ScriptType;
-import org.springframework.data.elasticsearch.core.SearchHit;
-import org.springframework.data.elasticsearch.core.SearchHits;
-import org.springframework.data.elasticsearch.core.clients.elasticsearch7.ElasticsearchAggregations;
-import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
-import org.springframework.data.elasticsearch.core.query.*;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-@Repository
-public class DeviceDao {
-
-    @Autowired
-    private ElasticsearchRestTemplate elasticsearchRestTemplate;
-
-    @Autowired
-    private DeviceInfoRepository deviceInfoRepository;
-    @Autowired
-    private ProductRepository productRepository;
-    @Autowired
-    private CategoryRepository categoryRepository;
-
-    public Paging<DeviceInfo> find(Criteria condition, int size, int page) {
-        Query query = new CriteriaQuery(condition);
-        long total = elasticsearchRestTemplate.count(query, DeviceInfo.class);
-        query = query.setPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("createAt"))));
-        SearchHits<DeviceInfo> searchHits = elasticsearchRestTemplate.search(query, DeviceInfo.class);
-        List<DeviceInfo> list = new ArrayList<>();
-        for (SearchHit<DeviceInfo> searchHit : searchHits) {
-            list.add(searchHit.getContent());
-        }
-
-        return new Paging<>(total, list);
-    }
-
-    /**
-     * 更新设备属性
-     */
-    public void updateProperties(String deviceId, Map<String, Object> properties) {
-        if (properties == null) {
-            return;
-        }
-        //外置es采用脚本更新
-        if (EmbeddedEs.disabled) {
-            Map<String, Object> param = new HashMap<>();
-            param.put("property", BeanUtil.beanToMap(properties));
-            param.put("keys", properties.keySet());
-
-            UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
-                    .and("deviceId").is(deviceId)))
-                    .withParams(param)
-                    .withScript("for(key in params.keys){ctx._source.property[key]=params.property[key];}")
-                    .withScriptType(ScriptType.INLINE)
-                    .build();
-            elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
-        } else {
-            //内置es采用文档更新
-            DeviceInfo deviceInfo = deviceInfoRepository.findByDeviceId(deviceId);
-            Map<String, Object> oldProps = deviceInfo.getProperty();
-            oldProps.putAll(properties);
-            deviceInfoRepository.save(deviceInfo);
-        }
-    }
-
-    /**
-     * 更新设备标签
-     */
-    public void updateTag(String deviceId, DeviceInfo.Tag tag) {
-        Map<String, Object> param = new HashMap<>();
-        param.put("tag", BeanUtil.beanToMap(tag));
-
-        UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
-                .and("deviceId").is(deviceId)))
-                .withParams(param)
-                .withScript(String.format("ctx._source.tag.%s=params.tag", tag.getId()))
-                .withScriptType(ScriptType.INLINE)
-                .build();
-        elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
-    }
-
-    /**
-     * 设置设备标签值为空
-     */
-    public void setTagNull(String deviceId, String tagId) {
-//        Query query = Query.query(new Criteria().and("deviceId").is(deviceId));
-//        Update update = new Update();
-//        update.set("tag." + tagId, null);
-//        mongoTemplate.updateFirst(query, update, DeviceInfo.class);
-    }
-
-    /**
-     * 获取按品类统计的用户设备数
-     */
-    public List<DataItem> getDeviceStatsByCategory(String uid) {
-        BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
-        if (StringUtils.isNotBlank(uid)) {
-            queryBuilder =
-                    queryBuilder.must(QueryBuilders.termQuery("uid.keyword", uid));
-        }
-
-        //先按产品分组统计
-        NativeSearchQuery query = new NativeSearchQueryBuilder()
-                .withQuery(queryBuilder)
-                .withAggregations(
-                        AggregationBuilders.terms("countByPk").field("productKey.keyword")
-                                .size(1000)
-                                .subAggregation(AggregationBuilders.count("count").field("productKey.keyword"))
-                )
-                .build();
-
-        ElasticsearchAggregations result = (ElasticsearchAggregations) elasticsearchRestTemplate
-                .search(query, DeviceInfo.class).getAggregations();
-        ParsedStringTerms terms = result.aggregations().get("countByPk");
-        List<? extends Terms.Bucket> buckets = terms.getBuckets();
-        Map<String, Long> productCount = new HashMap<>();
-        for (Terms.Bucket bucket : buckets) {
-            productCount.put(bucket.getKeyAsString(), bucket.getDocCount());
-        }
-
-        //取用户下产品列表
-        Iterable<Product> products;
-        if (StringUtils.isNotBlank(uid)) {
-            products = productRepository.findByUid(uid);
-        } else {
-            products = productRepository.findAll();
-        }
-        Map<String, String> pkCateMap = new HashMap<>();
-        for (Product product : products) {
-            pkCateMap.put(product.getId(), product.getCategory());
-        }
-
-        //取品类列表
-        Map<String, String> cateNames = new HashMap<>();
-        for (Category category : categoryRepository.findAll()) {
-            cateNames.put(category.getId(), category.getName());
-        }
-
-        Map<String, Long> cateStats = new HashMap<>();
-        productCount.forEach((key, val) -> {
-            String cateName = cateNames.get(pkCateMap.get(key));
-            //按品类汇总
-            long total = cateStats.getOrDefault(cateName, 0L);
-            total += val;
-            cateStats.put(cateName, total);
-        });
-
-        List<DataItem> items = new ArrayList<>();
-        cateStats.forEach((key, val) -> {
-            items.add(new DataItem(key, val));
-        });
-
-        return items;
-    }
-
-    /**
-     * 获取按品类统计的设备数
-     */
-    public List<DataItem> getDeviceStatsByCategory() {
-        return getDeviceStatsByCategory(null);
-    }
-
-    /**
-     * 根据分组id查询分组下所有设备
-     */
-    public List<DeviceInfo> findByGroupId(String groupId) {
-        Query query = new CriteriaQuery(new Criteria().and("group." + groupId).exists());
-        SearchHits<DeviceInfo> searchHits = elasticsearchRestTemplate.search(query, DeviceInfo.class);
-        return searchHits.stream().map(SearchHit::getContent).collect(Collectors.toList());
-    }
-
-    /**
-     * 按分组id统计设备数量
-     */
-    public long countByGroupId(String groupId) {
-        Query query = new CriteriaQuery(new Criteria().and("group." + groupId).exists());
-        return elasticsearchRestTemplate.count(query, DeviceInfo.class);
-    }
-
-    /**
-     * 按设备id更新设备分组
-     */
-    public void updateGroupByDeviceId(String deviceId, DeviceInfo.Group group) {
-        Map<String, Object> param = new HashMap<>();
-        param.put("group", BeanUtil.beanToMap(group));
-
-        UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
-                .and("deviceId").is(deviceId)))
-                .withParams(param)
-                .withScript(String.format("ctx._source.group.%s=params.group", group.getId()))
-                .withScriptType(ScriptType.INLINE)
-                .build();
-        elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
-    }
-
-    /**
-     * 按组id更新设备分组
-     */
-    public void updateGroup(String groupId, DeviceInfo.Group group) {
-        Map<String, Object> param = new HashMap<>();
-        param.put("group", BeanUtil.beanToMap(group));
-
-        UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
-                .and("group." + groupId).exists()))
-                .withParams(param)
-                .withScript(String.format("ctx._source.group.%s=params.group", groupId))
-                .withScriptType(ScriptType.INLINE)
-                .build();
-
-        elasticsearchRestTemplate.update(updateQuery, IndexCoordinates.of("device_info"));
-    }
-
-    /**
-     * 移除指定设备信息中的分组
-     */
-    public void removeGroup(String deviceId, String groupId) {
-        UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(
-                Criteria.where("deviceId").is(deviceId)))
-                .withScript(String.format("ctx._source.group.remove('%s')", groupId))
-                .withScriptType(ScriptType.INLINE)
-                .build();
-
-        elasticsearchRestTemplate.updateByQuery(updateQuery, IndexCoordinates.of("device_info"));
-    }
-
-    /**
-     * 移除设备信息中的分组
-     */
-    public void removeGroup(String groupId) {
-        UpdateQuery updateQuery = UpdateQuery.builder(new CriteriaQuery(new Criteria()
-                .and("group." + groupId).exists()))
-                .withScript(String.format("ctx._source.group.remove('%s')", groupId))
-                .withScriptType(ScriptType.INLINE)
-                .build();
-
-        elasticsearchRestTemplate.update(updateQuery, IndexCoordinates.of("device_info"));
-    }
-}

+ 0 - 31
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceInfoRepository.java

@@ -1,31 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.device.DeviceInfo;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-import java.util.List;
-
-public interface DeviceInfoRepository extends ElasticsearchRepository<DeviceInfo, String> {
-
-    DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName);
-
-    DeviceInfo findByDeviceId(String deviceId);
-
-    List<DeviceInfo> findByParentId(String parentId);
-
-    List<DeviceInfo> findByParentIdAndUid(String parentId, String uid);
-
-    List<DeviceInfo> findByDeviceName(String deviceName);
-
-    long countByUid(String uid);
-
-}

+ 0 - 42
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/OauthClientCache.java

@@ -1,42 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.OauthClient;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-
-@Repository
-public class OauthClientCache {
-
-    @Autowired
-    private OauthClientRepository oauthClientRepository;
-
-    private static OauthClientCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static OauthClientCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.OAUTH_CLIENT_CACHE, key = "#clientId")
-    public OauthClient getClient(String clientId) {
-        return oauthClientRepository.findById(clientId).orElse(null);
-    }
-
-}

+ 0 - 59
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProductCache.java

@@ -1,59 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.product.Product;
-import cc.iotkit.model.product.ProductModel;
-import cc.iotkit.model.product.ThingModel;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-
-@Repository
-public class ProductCache {
-
-    @Autowired
-    private ProductRepository productRepository;
-    @Autowired
-    private ThingModelRepository thingModelRepository;
-    @Autowired
-    private ProductModelRepository productModelRepository;
-
-    private static ProductCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static ProductCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.PRODUCT_CACHE, key = "'product'+#pk")
-    public Product findById(String pk) {
-        return productRepository.findById(pk).orElse(new Product());
-    }
-
-    @Cacheable(value = Constants.THING_MODEL_CACHE, key = "'thing_model'+#pk")
-    public ThingModel getThingModel(String pk) {
-        return thingModelRepository.findByProductKey(pk);
-    }
-
-    @Cacheable(value = Constants.PRODUCT_SCRIPT_CACHE, key = "'product_script'+#model")
-    public ProductModel getProductScriptByModel(String model) {
-        return productModelRepository.findByModel(model);
-    }
-
-
-}

+ 0 - 23
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProtocolComponentRepository.java

@@ -1,23 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.protocol.ProtocolComponent;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-import java.util.List;
-
-public interface ProtocolComponentRepository extends ElasticsearchRepository<ProtocolComponent, String> {
-
-    List<ProtocolComponent> findByState(String state);
-
-    List<ProtocolComponent> findByStateAndType(String state, String type);
-
-}

+ 0 - 16
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ProtocolConverterRepository.java

@@ -1,16 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.protocol.ProtocolConverter;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-public interface ProtocolConverterRepository extends ElasticsearchRepository<ProtocolConverter, String> {
-}

+ 0 - 33
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/SpaceCache.java

@@ -1,33 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.space.Space;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-
-@Repository
-public class SpaceCache {
-
-    @Autowired
-    private SpaceRepository spaceRepository;
-
-    private static SpaceCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static SpaceCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.SPACE_CACHE, key = "#spaceId")
-    public Space getSpace(String spaceId) {
-        return spaceRepository.findById(spaceId).orElse(null);
-    }
-
-}

+ 0 - 44
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThingModelMessageDao.java

@@ -1,44 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.model.Paging;
-import cc.iotkit.model.device.message.ThingModelMessage;
-import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
-import org.springframework.data.elasticsearch.core.SearchHit;
-import org.springframework.data.elasticsearch.core.SearchHits;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.stereotype.Repository;
-
-import java.util.stream.Collectors;
-
-@Repository
-public class ThingModelMessageDao {
-
-    @Autowired
-    private ElasticsearchRestTemplate template;
-
-    public Paging<ThingModelMessage> findByTypeAndIdentifier(String deviceId, String type,
-                                                             String identifier,
-                                                             int page, int size) {
-        BoolQueryBuilder builder = QueryBuilders.boolQuery();
-        builder.must(QueryBuilders.termQuery("deviceId", deviceId));
-        if (StringUtils.isNotBlank(type)) {
-            builder.must(QueryBuilders.termQuery("type", type));
-        }
-        if (StringUtils.isNotBlank(identifier)) {
-            builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier));
-        }
-        NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder)
-                .withPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("time"))))
-                .build();
-        SearchHits<ThingModelMessage> result = template.search(query, ThingModelMessage.class);
-        return new Paging<>(result.getTotalHits(), result.getSearchHits().stream()
-                .map(SearchHit::getContent).collect(Collectors.toList()));
-    }
-}

+ 0 - 19
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java

@@ -1,19 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.product.ThingModel;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-public interface ThingModelRepository extends ElasticsearchRepository<ThingModel, String> {
-
-    ThingModel findByProductKey(String productKey);
-
-}

+ 0 - 9
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/ThirdUserSessionRepository.java

@@ -1,9 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.model.ThirdUserSession;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-public interface ThirdUserSessionRepository extends ElasticsearchRepository<ThirdUserSession, String> {
-
-
-}

+ 0 - 17
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserActionLogRepository.java

@@ -1,17 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.model.UserActionLog;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-
-public interface UserActionLogRepository extends ElasticsearchRepository<UserActionLog, String> {
-
-}

+ 0 - 42
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/UserInfoCache.java

@@ -1,42 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.UserInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Repository;
-
-import javax.annotation.PostConstruct;
-
-@Repository
-public class UserInfoCache {
-
-    @Autowired
-    private UserInfoRepository userInfoRepository;
-
-    private static UserInfoCache INSTANCE;
-
-    @PostConstruct
-    public void init() {
-        INSTANCE = this;
-    }
-
-    public static UserInfoCache getInstance() {
-        return INSTANCE;
-    }
-
-    @Cacheable(value = Constants.USER_CACHE, key = "#uid")
-    public UserInfo getUserInfo(String uid) {
-        return userInfoRepository.findById(uid).orElse(null);
-    }
-
-}

+ 0 - 25
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java

@@ -1,25 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-
-package cc.iotkit.dao.config;
-
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.FilterType;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
-import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
-
-@Lazy
-@Configuration
-@EnableElasticsearchRepositories(basePackages = "cc.iotkit.dao", includeFilters =
-@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchRepository.class))
-public class ElasticsearchConfiguration {
-}

+ 0 - 28
iot-data-service/iot-model/src/main/java/cc/iotkit/model/OauthClient.java

@@ -1,28 +0,0 @@
-package cc.iotkit.model;
-
-import lombok.Data;
-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;
-
-/**
- * oauth2的client
- */
-@Data
-@Document(indexName = "oauth_client")
-public class OauthClient {
-
-    @Id
-    private String clientId;
-
-    private String name;
-
-    private String clientSecret;
-
-    private String allowUrl;
-
-    @Field(type = FieldType.Date)
-    private Long createAt;
-
-}

+ 0 - 87
iot-data-service/iot-model/src/main/java/cc/iotkit/model/UserActionLog.java

@@ -1,87 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.model;
-
-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;
-
-/**
- * 用户操作日志
- */
-@Document(indexName = "user_action_log")
-@Data
-@Builder
-@NoArgsConstructor
-@AllArgsConstructor
-public class UserActionLog {
-
-    @Id
-    private String id;
-
-    private String uid;
-
-    /**
-     * 类型
-     * 0:设备控制
-     * 1:添加设备
-     * 2:分享设备
-     * 3:创建空间
-     * 4:分享家庭
-     */
-    private int type;
-
-    /**
-     * 操作目标
-     */
-    private String target;
-
-    /**
-     * 日志内容
-     */
-    private Object log;
-
-    /**
-     * 操作结果
-     */
-    private String result;
-
-    @Field(type = FieldType.Date)
-    private Long createAt;
-
-    public enum Type {
-        DEVICE_CONTROL("设备控制", 0),
-        DEVICE_ADD("添加设备", 1),
-        DEVICE_SHARED("分享设备", 2),
-        SPACE_ADD("创建空间", 3),
-        HOME_SHARED("分享家庭", 4);
-
-        private String name;
-        private int value;
-
-        private Type(String name, int value) {
-            this.name = name;
-            this.value = value;
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public int getValue() {
-            return value;
-        }
-    }
-}

+ 0 - 72
iot-data-service/iot-model/src/main/java/cc/iotkit/model/aligenie/AligenieProduct.java

@@ -1,72 +0,0 @@
-/*
- * +----------------------------------------------------------------------
- * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
- * +----------------------------------------------------------------------
- * | Licensed 未经许可不能去掉「奇特物联」相关版权
- * +----------------------------------------------------------------------
- * | Author: xw2sy@163.com
- * +----------------------------------------------------------------------
- */
-package cc.iotkit.model.aligenie;
-
-import cc.iotkit.model.Owned;
-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;
-
-import java.util.List;
-
-/**
- * 天猫精灵产品
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder
-@Document(indexName = "aligenie_product")
-public class AligenieProduct implements Owned {
-
-    @Id
-    private String productId;
-    private String deviceType;
-    private String brand;
-    private String model;
-    private String icon;
-    private List<Property> properties;
-    private List<String> actions;
-
-    /**
-     * 对应系统中的产品pk
-     */
-    private String productKey;
-    /**
-     * 物模型转换配置
-     */
-    private String transform;
-
-    /**
-     * 所属系统账户
-     */
-    private String uid;
-
-    @Field(type = FieldType.Date)
-    private Long createAt;
-
-    @Override
-    public String getId() {
-        return productId;
-    }
-
-    @Data
-    @NoArgsConstructor
-    @AllArgsConstructor
-    public static class Property {
-        private String name;
-        private String value;
-    }
-}

+ 0 - 59
iot-data-service/iot-model/src/main/java/cc/iotkit/model/device/message/DeviceReport.java

@@ -1,59 +0,0 @@
-package cc.iotkit.model.device.message;
-
-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
-@NoArgsConstructor
-@AllArgsConstructor
-@Builder
-@Document(indexName = "device_report")
-public class DeviceReport {
-
-    @Id
-    private String id;
-
-    private String deviceId;
-
-    private String productKey;
-
-    private String deviceName;
-
-    /**
-     * 设备所属用户
-     */
-    private String uid;
-
-    /**
-     * 消息类型
-     * lifetime:生命周期
-     * state:状态
-     * property:属性
-     * event:事件
-     * service:服务
-     */
-    private String type;
-
-    private String identifier;
-
-    /**
-     * 消息状态码
-     */
-    private int code;
-
-    /**
-     * 消息上报时间
-     */
-    @Field(type = FieldType.Date)
-    private Long time;
-
-}

+ 0 - 1
iot-data-service/readme.txt

@@ -1 +0,0 @@
-与数据存取相关内容的模块

+ 0 - 0
iot-data-service/.DS_Store → iot-data/.DS_Store


+ 48 - 0
iot-data/iot-data-cache/pom.xml

@@ -0,0 +1,48 @@
+<?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</artifactId>
+        <groupId>cc.iotkit</groupId>
+        <version>0.4.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>iot-data-cache</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-common</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-model</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-data-service</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CategoryCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_CATEGORY, key = "#root.method.name+#s")
+    public void findById(String s) {
+    }
+
+}

+ 27 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java

@@ -0,0 +1,27 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DeviceInfoCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId")
+    public void findByDeviceId(String deviceId) {
+    }
+
+    @CacheEvict(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#productKey+#deviceName")
+    public void findByProductKeyAndDeviceName(String productKey, String deviceName) {
+    }
+
+}

+ 37 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java

@@ -0,0 +1,37 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.model.device.DeviceInfo;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class DeviceInfoCachePut {
+
+    @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId")
+    public DeviceInfo findByDeviceId(String deviceId, DeviceInfo deviceInfo) {
+        return deviceInfo;
+    }
+
+    @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#productKey+#deviceName")
+    public DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName, DeviceInfo deviceInfo) {
+        return deviceInfo;
+    }
+
+    @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#parentId")
+    public List<String> findSubDeviceIds(String parentId, List<String> subDeviceIds) {
+        return subDeviceIds;
+    }
+
+}

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OauthClientCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_OAUTH_CLIENT, key = "#root.method.name+#clientId")
+    public void findByClientId(String clientId) {
+    }
+
+}

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ProductCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#pk")
+    public void findById(String pk) {
+    }
+
+}

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ProductModelCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_PRODUCT_SCRIPT, key = "#root.method.name+#model")
+    public void findByModel(String model) {
+    }
+
+}

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SpaceCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_SPACE, key = "#root.method.name+#s")
+    public void findById(String s) {
+    }
+
+}

+ 14 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java

@@ -0,0 +1,14 @@
+package cc.iotkit.data.cache;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+public class UserInfoCacheEvict {
+
+    @CacheEvict(value = Constants.CACHE_USER_INFO, key = "#root.method.name+#uid")
+    public void findByUid(String uid) {
+    }
+
+}

+ 57 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java

@@ -0,0 +1,57 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data.config;
+
+import cc.iotkit.common.Constants;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+import org.springframework.data.redis.serializer.RedisSerializer;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.Set;
+
+@Configuration
+@EnableCaching
+public class CacheConfig {
+
+    @Bean
+    public RedisCacheConfiguration getRedisCacheConfiguration() {
+        RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
+        cacheConfiguration = cacheConfiguration.serializeValuesWith(RedisSerializationContext
+                .SerializationPair.fromSerializer(RedisSerializer.json()));
+        return cacheConfiguration;
+    }
+
+    @Bean
+    public CacheManager cacheManager(RedisConnectionFactory factory, RedisCacheConfiguration config) {
+        Set<String> cacheNames = Set.of(Constants.CACHE_DEVICE_INFO, Constants.CACHE_DEVICE_STATS);
+        Map<String, RedisCacheConfiguration> cacheConfigs = Map.of(
+                Constants.CACHE_DEVICE_INFO, config,
+                Constants.CACHE_PRODUCT, config,
+                Constants.CACHE_OAUTH_CLIENT, config,
+                Constants.CACHE_CATEGORY, config,
+                //统计缓存5分钟
+                Constants.CACHE_DEVICE_STATS, config.entryTtl(Duration.ofMinutes(5))
+        );
+
+        return RedisCacheManager.builder(factory)
+                .initialCacheNames(cacheNames)
+                .withInitialCacheConfigurations(cacheConfigs)
+                .build();
+    }
+
+}

+ 61 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java

@@ -0,0 +1,61 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.ICategoryData;
+import cc.iotkit.data.cache.CategoryCacheEvict;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.product.Category;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("categoryDataCache")
+public class CategoryDataCache implements ICategoryData {
+
+    @Autowired
+    private ICategoryData categoryData;
+    @Autowired
+    private CategoryCacheEvict categoryCacheEvict;
+
+    @Override
+    @Cacheable(value = Constants.CACHE_CATEGORY, key = "#root.method.name+#s", unless = "#result == null")
+    public Category findById(String s) {
+        return categoryData.findById(s);
+    }
+
+    @Override
+    public Category save(Category data) {
+        data = categoryData.save(data);
+        categoryCacheEvict.findById(data.getId());
+        return data;
+    }
+
+    @Override
+    public Category add(Category data) {
+        return categoryData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        categoryData.deleteById(s);
+    }
+
+    @Override
+    public long count() {
+        return categoryData.count();
+    }
+
+    @Override
+    public List<Category> findAll() {
+        return categoryData.findAll();
+    }
+
+    @Override
+    public Paging<Category> findAll(int page, int size) {
+        return categoryData.findAll(page, size);
+    }
+}

+ 259 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java

@@ -0,0 +1,259 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.common.utils.JsonUtil;
+import cc.iotkit.data.IDeviceInfoData;
+import cc.iotkit.data.cache.DeviceInfoCacheEvict;
+import cc.iotkit.data.cache.DeviceInfoCachePut;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.device.DeviceInfo;
+import cc.iotkit.model.stats.DataItem;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.SmartInitializingSingleton;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Service
+@Qualifier("deviceInfoDataCache")
+public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSingleton {
+
+    private static final String PROPERTY_CACHE_KEY = "str:iotkit:device:property:%s";
+
+    @Autowired
+    private StringRedisTemplate redisTemplate;
+
+    @Autowired
+    private DeviceInfoCachePut deviceInfoCachePut;
+    @Autowired
+    private DeviceInfoCacheEvict deviceInfoCacheEvict;
+
+    @Autowired
+    private IDeviceInfoData deviceInfoData;
+
+
+    @Override
+    public void afterSingletonsInstantiated() {
+        if ("true".equals(System.getProperty("disabledEmbeddedRedis"))) {
+            return;
+        }
+
+        //需要等待缓存初始化
+        Timer timer = new Timer();
+        timer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                //内嵌redis每次启动需要重新装载缓存
+                int page = 1;
+                Paging<DeviceInfo> paged;
+                List<String> parentIds = new ArrayList<>();
+                while ((paged = deviceInfoData.findAll(page++, 1000)).getData().size() > 0) {
+                    List<DeviceInfo> devices = paged.getData();
+                    for (DeviceInfo device : devices) {
+                        //装载设备信息缓存
+                        deviceInfoCachePut.findByDeviceId(device.getDeviceId(), device);
+                        deviceInfoCachePut.findByProductKeyAndDeviceName(device.getProductKey(), device.getDeviceName(), device);
+                        String parentId = device.getParentId();
+                        if (StringUtils.isBlank(parentId)) {
+                            parentIds.add(parentId);
+                        }
+                    }
+                }
+                //装载子设备id列表缓存
+                for (String parentId : parentIds) {
+                    putSubDeviceIds(parentId);
+                }
+            }
+        }, 100);
+    }
+
+    private String getPropertyCacheKey(String deviceId) {
+        return String.format(PROPERTY_CACHE_KEY, deviceId);
+    }
+
+    @Override
+    public void saveProperties(String deviceId, Map<String, Object> properties) {
+        Map<String, Object> old = getProperties(deviceId);
+        old.putAll(properties);
+        redisTemplate.opsForValue().set(getPropertyCacheKey(deviceId), JsonUtil.toJsonString(old));
+    }
+
+    @Override
+    public Map<String, Object> getProperties(String deviceId) {
+        String json = redisTemplate.opsForValue().get(getPropertyCacheKey(deviceId));
+        if (StringUtils.isBlank(json)) {
+            return new HashMap<>();
+        }
+        return JsonUtil.parse(json, Map.class);
+    }
+
+    @Override
+    @Cacheable(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId", unless = "#result == null")
+    public DeviceInfo findByDeviceId(String deviceId) {
+        //不需要查数据库,在数据变更时更新到缓存
+        return null;
+    }
+
+    @Override
+    @Cacheable(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#productKey+#deviceName", unless = "#result == null")
+    public DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName) {
+        //不需要查数据库,在数据变更时更新到缓存
+        return null;
+    }
+
+    @Override
+    public List<DeviceInfo> findByParentId(String parentId) {
+        return deviceInfoData.findByParentId(parentId);
+    }
+
+    @Override
+    public List<String> findSubDeviceIds(String parentId) {
+        return deviceInfoData.findSubDeviceIds(parentId);
+    }
+
+    @Override
+    public List<DeviceInfo> findByDeviceName(String deviceName) {
+        return deviceInfoData.findByDeviceName(deviceName);
+    }
+
+    @Override
+    public Paging<DeviceInfo> findByConditions(String uid, String subUid, String productKey,
+                                               String groupId, String state, String keyword, int page, int size) {
+        return deviceInfoData.findByConditions(uid, subUid, productKey, groupId, state, keyword, page, size);
+    }
+
+    @Override
+    public void updateTag(String deviceId, DeviceInfo.Tag tag) {
+        deviceInfoData.updateTag(deviceId, tag);
+        DeviceInfo data = deviceInfoData.findByDeviceId(deviceId);
+        putDeviceInfo(data);
+    }
+
+    @Override
+    @Cacheable(value = Constants.CACHE_DEVICE_STATS, key = "#root.method.name+#uid", unless = "#result == null")
+    public List<DataItem> getDeviceStatsByCategory(String uid) {
+        return deviceInfoData.getDeviceStatsByCategory(uid);
+    }
+
+    @Override
+    public long countByGroupId(String groupId) {
+        return deviceInfoData.countByGroupId(groupId);
+    }
+
+    @Override
+    public void addToGroup(String deviceId, DeviceInfo.Group group) {
+        deviceInfoData.addToGroup(deviceId, group);
+        DeviceInfo data = deviceInfoData.findByDeviceId(deviceId);
+        putDeviceInfo(data);
+    }
+
+    @Override
+    public void updateGroup(String groupId, DeviceInfo.Group group) {
+        deviceInfoData.updateGroup(groupId, group);
+    }
+
+    @Override
+    public void removeGroup(String deviceId, String groupId) {
+        deviceInfoData.removeGroup(deviceId, groupId);
+        DeviceInfo data = deviceInfoData.findByDeviceId(deviceId);
+        putDeviceInfo(data);
+    }
+
+    @Override
+    public void removeGroup(String groupId) {
+        deviceInfoData.removeGroup(groupId);
+    }
+
+    @Override
+    public List<DeviceInfo> findByUid(String uid) {
+        return deviceInfoData.findByUid(uid);
+    }
+
+    @Override
+    public Paging<DeviceInfo> findByUid(String uid, int page, int size) {
+        return deviceInfoData.findByUid(uid, page, size);
+    }
+
+    @Override
+    public long countByUid(String uid) {
+        return deviceInfoData.countByUid(uid);
+    }
+
+    @Override
+    public DeviceInfo findById(String s) {
+        return deviceInfoData.findById(s);
+    }
+
+    @Override
+    public DeviceInfo save(DeviceInfo data) {
+        DeviceInfo r = deviceInfoData.save(data);
+        //更新设备信息缓存
+        putDeviceInfo(data);
+        //更新子设备列表缓存
+        putSubDeviceIds(data.getParentId());
+        return r;
+    }
+
+    @Override
+    public DeviceInfo add(DeviceInfo data) {
+        return save(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        DeviceInfo device = deviceInfoData.findById(s);
+        deviceInfoData.deleteById(s);
+        //清除缓存
+        deviceInfoCacheEvict.findByDeviceId(device.getDeviceId());
+        deviceInfoCacheEvict.findByProductKeyAndDeviceName(device.getProductKey(), device.getDeviceName());
+        //更新子设备列表缓存
+        putSubDeviceIds(device.getParentId());
+    }
+
+    @Override
+    public long count() {
+        return deviceInfoData.count();
+    }
+
+    @Override
+    public List<DeviceInfo> findAll() {
+        return deviceInfoData.findAll();
+    }
+
+    @Override
+    public Paging<DeviceInfo> findAll(int page, int size) {
+        return deviceInfoData.findAll(page, size);
+    }
+
+    /**
+     * 更新缓存
+     */
+    private void putDeviceInfo(DeviceInfo data) {
+        deviceInfoCachePut.findByDeviceId(data.getDeviceId(), data);
+        deviceInfoCachePut.findByProductKeyAndDeviceName(data.getProductKey(), data.getDeviceName(), data);
+    }
+
+    /**
+     * 更新子设备id列表
+     */
+    private void putSubDeviceIds(String parentId) {
+        if (StringUtils.isBlank(parentId)) {
+            return;
+        }
+        List<String> subDeviceIds = deviceInfoData.findSubDeviceIds(parentId);
+        deviceInfoCachePut.findSubDeviceIds(parentId, subDeviceIds);
+    }
+}

+ 76 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java

@@ -0,0 +1,76 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.IOauthClientData;
+import cc.iotkit.data.cache.OauthClientCacheEvict;
+import cc.iotkit.model.OauthClient;
+import cc.iotkit.model.Paging;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("oauthClientDataCache")
+public class OauthClientDataCache implements IOauthClientData {
+
+    @Autowired
+    private IOauthClientData oauthClientData;
+    @Autowired
+    private OauthClientCacheEvict oauthClientCacheEvict;
+
+    @Override
+    @Cacheable(value = Constants.CACHE_OAUTH_CLIENT, key = "#root.method.name+#clientId", unless = "#result == null")
+    public OauthClient findByClientId(String clientId) {
+        return oauthClientData.findByClientId(clientId);
+    }
+
+    @Override
+    public OauthClient findById(String s) {
+        return oauthClientData.findById(s);
+    }
+
+    @Override
+    public OauthClient save(OauthClient data) {
+        OauthClient oauthClient = oauthClientData.save(data);
+        //清除缓存
+        oauthClientCacheEvict.findByClientId(data.getClientId());
+        return oauthClient;
+    }
+
+    @Override
+    public OauthClient add(OauthClient data) {
+        return oauthClientData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        oauthClientData.deleteById(s);
+    }
+
+    @Override
+    public long count() {
+        return oauthClientData.count();
+    }
+
+    @Override
+    public List<OauthClient> findAll() {
+        return oauthClientData.findAll();
+    }
+
+    @Override
+    public Paging<OauthClient> findAll(int page, int size) {
+        return oauthClientData.findAll(page, size);
+    }
+}

+ 84 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java

@@ -0,0 +1,84 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.IProductData;
+import cc.iotkit.data.cache.ProductCacheEvict;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.product.Product;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("deviceInfoDataCache")
+public class ProductDataCache implements IProductData {
+
+    @Autowired
+    private IProductData productData;
+    @Autowired
+    private ProductCacheEvict productCacheEvict;
+
+    @Override
+    public List<Product> findByCategory(String category) {
+        return productData.findByCategory(category);
+    }
+
+    @Override
+    public List<Product> findByUid(String uid) {
+        return productData.findByUid(uid);
+    }
+
+    @Override
+    public Paging<Product> findByUid(String uid, int page, int size) {
+        return productData.findByUid(uid, page, size);
+    }
+
+    @Override
+    public long countByUid(String uid) {
+        return productData.countByUid(uid);
+    }
+
+    @Override
+    @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#s", unless = "#result == null")
+    public Product findById(String s) {
+        return productData.findById(s);
+    }
+
+    @Override
+    public Product save(Product data) {
+        Product p = productData.save(data);
+        //清除缓存
+        productCacheEvict.findById(p.getId());
+        return p;
+    }
+
+    @Override
+    public Product add(Product data) {
+        return productData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        productData.deleteById(s);
+        //清除缓存
+        productCacheEvict.findById(s);
+    }
+
+    @Override
+    public long count() {
+        return productData.count();
+    }
+
+    @Override
+    public List<Product> findAll() {
+        return productData.findAll();
+    }
+
+    @Override
+    public Paging<Product> findAll(int page, int size) {
+        return productData.findAll(page, size);
+    }
+}

+ 71 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java

@@ -0,0 +1,71 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.IProductModelData;
+import cc.iotkit.data.cache.ProductModelCacheEvict;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.product.ProductModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("productModelDataCache")
+public class ProductModelDataCache implements IProductModelData {
+
+    @Autowired
+    private IProductModelData productModelData;
+    @Autowired
+    private ProductModelCacheEvict productModelCacheEvict;
+
+    @Override
+    @Cacheable(value = Constants.CACHE_PRODUCT_SCRIPT, key = "#root.method.name+#model", unless = "#result == null")
+    public ProductModel findByModel(String model) {
+        return productModelData.findByModel(model);
+    }
+
+    @Override
+    public List<ProductModel> findByProductKey(String productKey) {
+        return productModelData.findByProductKey(productKey);
+    }
+
+    @Override
+    public ProductModel findById(String s) {
+        return productModelData.findById(s);
+    }
+
+    @Override
+    public ProductModel save(ProductModel data) {
+        ProductModel productModel = productModelData.save(data);
+        productModelCacheEvict.findByModel(data.getModel());
+        return productModel;
+    }
+
+    @Override
+    public ProductModel add(ProductModel data) {
+        return productModelData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        productModelData.deleteById(s);
+    }
+
+    @Override
+    public long count() {
+        return productModelData.count();
+    }
+
+    @Override
+    public List<ProductModel> findAll() {
+        return productModelData.findAll();
+    }
+
+    @Override
+    public Paging<ProductModel> findAll(int page, int size) {
+        return productModelData.findAll(page, size);
+    }
+}

+ 91 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java

@@ -0,0 +1,91 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.ISpaceData;
+import cc.iotkit.data.cache.SpaceCacheEvict;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.space.Space;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("spaceDataCache")
+public class SpaceDataCache implements ISpaceData {
+
+    @Autowired
+    private ISpaceData spaceData;
+    @Autowired
+    private SpaceCacheEvict spaceCacheEvict;
+
+    @Override
+    public List<Space> findByUidOrderByCreateAtDesc(String uid) {
+        return spaceData.findByUidOrderByCreateAtDesc(uid);
+    }
+
+    @Override
+    public List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId) {
+        return spaceData.findByUidAndHomeIdOrderByCreateAtDesc(uid, homeId);
+    }
+
+    @Override
+    public List<Space> findByHomeId(String homeId) {
+        return spaceData.findByHomeId(homeId);
+    }
+
+    @Override
+    public List<Space> findByUid(String uid) {
+        return spaceData.findByUid(uid);
+    }
+
+    @Override
+    public Paging<Space> findByUid(String uid, int page, int size) {
+        return spaceData.findByUid(uid, page, size);
+    }
+
+    @Override
+    public long countByUid(String uid) {
+        return spaceData.countByUid(uid);
+    }
+
+    @Override
+    @Cacheable(value = Constants.CACHE_SPACE, key = "#root.method.name+#s", unless = "#result == null")
+    public Space findById(String s) {
+        return spaceData.findById(s);
+    }
+
+    @Override
+    public Space save(Space data) {
+        data = spaceData.save(data);
+        spaceCacheEvict.findById(data.getId());
+        return data;
+    }
+
+    @Override
+    public Space add(Space data) {
+        return spaceData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        spaceData.deleteById(s);
+    }
+
+    @Override
+    public long count() {
+        return spaceData.count();
+    }
+
+    @Override
+    public List<Space> findAll() {
+        return spaceData.findAll();
+    }
+
+    @Override
+    public Paging<Space> findAll(int page, int size) {
+        return spaceData.findAll(page, size);
+    }
+}

+ 77 - 0
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java

@@ -0,0 +1,77 @@
+package cc.iotkit.data.service;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.data.IUserInfoData;
+import cc.iotkit.data.cache.UserInfoCacheEvict;
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.UserInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@Qualifier("userInfoDataCache")
+public class UserInfoDataCache implements IUserInfoData {
+
+    @Autowired
+    private IUserInfoData userInfoData;
+    @Autowired
+    private UserInfoCacheEvict userInfoCacheEvict;
+
+    @Override
+    @Cacheable(value = Constants.CACHE_USER_INFO, key = "#root.method.name+#uid", unless = "#result == null")
+    public UserInfo findByUid(String uid) {
+        return userInfoData.findByUid(uid);
+    }
+
+    @Override
+    public List<UserInfo> findByType(int type) {
+        return userInfoData.findByType(type);
+    }
+
+    @Override
+    public List<UserInfo> findByTypeAndOwnerId(int type, String ownerId) {
+        return userInfoData.findByTypeAndOwnerId(type, ownerId);
+    }
+
+    @Override
+    public UserInfo findById(String s) {
+        return userInfoData.findById(s);
+    }
+
+    @Override
+    public UserInfo save(UserInfo data) {
+        UserInfo userInfo = userInfoData.save(data);
+        //清除缓存
+        userInfoCacheEvict.findByUid(data.getUid());
+        return userInfo;
+    }
+
+    @Override
+    public UserInfo add(UserInfo data) {
+        return userInfoData.add(data);
+    }
+
+    @Override
+    public void deleteById(String s) {
+        userInfoData.deleteById(s);
+    }
+
+    @Override
+    public long count() {
+        return userInfoData.count();
+    }
+
+    @Override
+    public List<UserInfo> findAll() {
+        return userInfoData.findAll();
+    }
+
+    @Override
+    public Paging<UserInfo> findAll(int page, int size) {
+        return userInfoData.findAll(page, size);
+    }
+}

+ 9 - 9
iot-data-service/pom.xml → iot-data/iot-data-service/pom.xml

@@ -3,20 +3,20 @@
          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>iotkit-parent</artifactId>
+        <artifactId>iot-data</artifactId>
         <groupId>cc.iotkit</groupId>
-        <version>0.3.2-SNAPSHOT</version>
+        <version>0.4.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <packaging>pom</packaging>
-
-    <modules>
-        <module>iot-model</module>
-        <module>iot-dao</module>
-        <module>iot-device-dao</module>
-    </modules>
 
     <artifactId>iot-data-service</artifactId>
 
+    <dependencies>
+
+        <dependency>
+            <groupId>cc.iotkit</groupId>
+            <artifactId>iot-model</artifactId>
+        </dependency>
 
+    </dependencies>
 </project>

+ 3 - 4
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/config/EmbeddedEs.java → iot-data/iot-data-service/src/main/java/cc/iotkit/data/ICategoryData.java

@@ -7,10 +7,9 @@
  * | Author: xw2sy@163.com
  * +----------------------------------------------------------------------
  */
-package cc.iotkit.dao.config;
+package cc.iotkit.data;
 
-public interface EmbeddedEs {
-
-    boolean disabled = "true".equals(System.getProperty("disabledEmbeddedEs"));
+import cc.iotkit.model.product.Category;
 
+public interface ICategoryData extends ICommonData<Category, String> {
 }

+ 23 - 15
iot-data-service/iot-device-dao/src/main/java/cc/iotkit/data/ProductDao.java → iot-data/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java

@@ -9,43 +9,51 @@
  */
 package cc.iotkit.data;
 
-import cc.iotkit.model.product.Product;
+import cc.iotkit.model.Id;
+import cc.iotkit.model.Paging;
 
 import java.util.List;
 
 /**
- * 产品接口
+ * 数据基础服务接口
  */
-public interface ProductDao {
+public interface ICommonData<T extends Id<ID>, ID> {
 
     /**
-     * 通过产品id取产品信息
+     * 通过ID取数据
      */
-    Product findById(String id);
+    T findById(ID id);
 
     /**
-     * 添加产品
+     * 保存数据,id不为空更新,否则添加
      */
-    void add(Product product);
+    T save(T data);
 
     /**
-     * 按id更新产品
+     * 添加数据
      */
-    void updateById(Product product);
+    T add(T data);
 
     /**
-     * 按用户id统计产品数量
+     * 按id删除
      */
-    long countByUid(String uid);
+    void deleteById(ID id);
 
     /**
-     * 按用户id取产品列表
+     * 总数统计
      */
-    List<Product> findByUid(String uid);
+    long count();
 
     /**
-     * 按品类取产品列表
+     * 取所有数据
      */
-    List<Product> findByCategory(String category);
+    List<T> findAll();
 
+    /**
+     * 分页获取所有信息
+     *
+     * @param page 页码,从0开始
+     * @param size 分页大小
+     */
+    Paging<T> findAll(int page, int size);
 }

+ 2 - 3
iot-data-service/iot-dao/src/main/java/cc/iotkit/dao/DeviceConfigRepository.java → iot-data/iot-data-service/src/main/java/cc/iotkit/data/IDeviceConfigData.java

@@ -7,12 +7,11 @@
  * | Author: xw2sy@163.com
  * +----------------------------------------------------------------------
  */
-package cc.iotkit.dao;
+package cc.iotkit.data;
 
 import cc.iotkit.model.device.DeviceConfig;
-import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
 
-public interface DeviceConfigRepository extends ElasticsearchRepository<DeviceConfig, String> {
+public interface IDeviceConfigData extends ICommonData<DeviceConfig, String> {
 
     DeviceConfig findByProductKeyAndDeviceName(String productKey, String deviceName);
 

+ 19 - 0
iot-data/iot-data-service/src/main/java/cc/iotkit/data/IDeviceGroupData.java

@@ -0,0 +1,19 @@
+/*
+ * +----------------------------------------------------------------------
+ * | Copyright (c) 奇特物联 2021-2022 All rights reserved.
+ * +----------------------------------------------------------------------
+ * | Licensed 未经许可不能去掉「奇特物联」相关版权
+ * +----------------------------------------------------------------------
+ * | Author: xw2sy@163.com
+ * +----------------------------------------------------------------------
+ */
+package cc.iotkit.data;
+
+import cc.iotkit.model.Paging;
+import cc.iotkit.model.device.DeviceGroup;
+
+public interface IDeviceGroupData extends ICommonData<DeviceGroup, String> {
+
+    Paging<DeviceGroup> findByNameLike(String name, int page, int size);
+
+}

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません