diff --git a/common/src/main/java/cc/iotkit/common/Constants.java b/common/src/main/java/cc/iotkit/common/Constants.java
index f4a1987d..860ab832 100755
--- a/common/src/main/java/cc/iotkit/common/Constants.java
+++ b/common/src/main/java/cc/iotkit/common/Constants.java
@@ -58,4 +58,14 @@ public interface Constants {
*/
String PWD_SYSTEM_USER="s123456";
+ /**
+ * 设备原始上报消息的topic
+ */
+ String DEVICE_RAW_MESSAGE_TOPIC="device_raw";
+
+ /**
+ * 设备物模型消息的topic
+ */
+ String THING_MODEL_MESSAGE_TOPIC="device_thing";
+
}
diff --git a/communication/component/pom.xml b/communication/component/pom.xml
new file mode 100644
index 00000000..02396859
--- /dev/null
+++ b/communication/component/pom.xml
@@ -0,0 +1,16 @@
+
+
+
+ iotkit-parent
+ cc.iotkit
+ 0.0.1-SNAPSHOT
+ ../../pom.xml
+
+ 4.0.0
+
+ component
+
+
+
\ No newline at end of file
diff --git a/communication/mqtt-component/pom.xml b/communication/mqtt-component/pom.xml
new file mode 100644
index 00000000..565bb85a
--- /dev/null
+++ b/communication/mqtt-component/pom.xml
@@ -0,0 +1,21 @@
+
+
+
+ iotkit-parent
+ cc.iotkit
+ 0.0.1-SNAPSHOT
+ ../../pom.xml
+
+ 4.0.0
+
+ mqtt-component
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/communication/pom.xml b/communication/pom.xml
new file mode 100644
index 00000000..a25ff27e
--- /dev/null
+++ b/communication/pom.xml
@@ -0,0 +1,15 @@
+
+
+
+ iotkit-parent
+ cc.iotkit
+ 0.0.1-SNAPSHOT
+
+ 4.0.0
+
+ communication
+
+
+
\ No newline at end of file
diff --git a/dao/src/main/java/cc/iotkit/dao/DeviceCache.java b/dao/src/main/java/cc/iotkit/dao/DeviceCache.java
new file mode 100755
index 00000000..524487e4
--- /dev/null
+++ b/dao/src/main/java/cc/iotkit/dao/DeviceCache.java
@@ -0,0 +1,39 @@
+package cc.iotkit.dao;
+
+import cc.iotkit.common.Constants;
+import cc.iotkit.model.device.DeviceInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Repository;
+
+import static org.springframework.data.mongodb.core.query.Criteria.where;
+import static org.springframework.data.mongodb.core.query.Query.query;
+
+@Repository
+public class DeviceCache extends BaseDao {
+
+ @Autowired
+ private DeviceRepository deviceRepository;
+
+ @Autowired
+ public DeviceCache(MongoTemplate mongoTemplate) {
+ super(mongoTemplate, DeviceInfo.class);
+ }
+
+ @Cacheable(value = Constants.DEVICE_CACHE, key = "#pk+'_'+#dn")
+ public DeviceInfo findByProductKeyAndDeviceName(String pk, String dn) {
+ return deviceRepository.findByProductKeyAndDeviceName(pk, dn);
+ }
+
+ @Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
+ public DeviceInfo findByDeviceId(String deviceId) {
+ return deviceRepository.findByDeviceId(deviceId);
+ }
+
+ @Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
+ public DeviceInfo get(String deviceId) {
+ return deviceRepository.findById(deviceId).orElse(new DeviceInfo());
+ }
+}
diff --git a/dao/src/main/java/cc/iotkit/dao/DeviceDao.java b/dao/src/main/java/cc/iotkit/dao/DeviceDao.java
deleted file mode 100755
index 1d34e2b9..00000000
--- a/dao/src/main/java/cc/iotkit/dao/DeviceDao.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.common.Constants;
-import cc.iotkit.model.device.DeviceInfo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.stereotype.Repository;
-
-import static org.springframework.data.mongodb.core.query.Criteria.where;
-import static org.springframework.data.mongodb.core.query.Query.query;
-
-@Repository
-public class DeviceDao extends BaseDao {
-
- @Autowired
- private DeviceRepository deviceRepository;
-
- @Autowired
- public DeviceDao(MongoTemplate mongoTemplate) {
- super(mongoTemplate, DeviceInfo.class);
- }
-
- public void addDevice(DeviceInfo device) {
- device.setCreateAt(System.currentTimeMillis());
- mongoTemplate.insert(device);
- }
-
- public void updateDevice(DeviceInfo device) {
- if (device.getDeviceId() == null) {
- return;
- }
- mongoTemplate.updateFirst(query(where("deviceId").is(device.getDeviceId())),
- DaoTool.update(device), DeviceInfo.class);
- }
-
- public void updateDeviceByPkAndDn(DeviceInfo device) {
- if (device.getProductKey() == null || device.getDeviceName() == null) {
- return;
- }
- mongoTemplate.updateFirst(query(where("productKey").is(device.getProductKey()).
- and("deviceName").is(device.getDeviceName())),
- DaoTool.update(device), DeviceInfo.class);
- }
-
- @Cacheable(value = "deviceInfoCache", key = "#pk+'_'+#dn")
- public DeviceInfo getByPkAndDn(String pk, String dn) {
- Query query = query(where("productKey").is(pk).and("deviceName").is(dn));
- return mongoTemplate.findOne(query, DeviceInfo.class);
- }
-
- public DeviceInfo getByDeviceId(String deviceId) {
- Query query = query(where("deviceId").is(deviceId));
- return mongoTemplate.findOne(query, DeviceInfo.class);
- }
-
- @Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
- public DeviceInfo get(String deviceId) {
- return deviceRepository.findById(deviceId).orElse(new DeviceInfo());
- }
-}
diff --git a/dao/src/main/java/cc/iotkit/dao/DeviceRepository.java b/dao/src/main/java/cc/iotkit/dao/DeviceRepository.java
index d19b3170..334e0f3d 100755
--- a/dao/src/main/java/cc/iotkit/dao/DeviceRepository.java
+++ b/dao/src/main/java/cc/iotkit/dao/DeviceRepository.java
@@ -6,4 +6,9 @@ import org.springframework.stereotype.Repository;
@Repository
public interface DeviceRepository extends MongoRepository {
+
+ DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName);
+
+ DeviceInfo findByDeviceId(String deviceId);
+
}
diff --git a/dao/src/main/java/cc/iotkit/dao/ProductDao.java b/dao/src/main/java/cc/iotkit/dao/ProductCache.java
similarity index 55%
rename from dao/src/main/java/cc/iotkit/dao/ProductDao.java
rename to dao/src/main/java/cc/iotkit/dao/ProductCache.java
index 18bd810f..db78ee01 100755
--- a/dao/src/main/java/cc/iotkit/dao/ProductDao.java
+++ b/dao/src/main/java/cc/iotkit/dao/ProductCache.java
@@ -5,25 +5,23 @@ import cc.iotkit.model.product.Product;
import cc.iotkit.model.product.ThingModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
-import org.springframework.data.domain.Example;
import org.springframework.stereotype.Repository;
@Repository
-public class ProductDao {
+public class ProductCache {
@Autowired
private ProductRepository productRepository;
@Autowired
private ThingModelRepository thingModelRepository;
- @Cacheable(value = Constants.PRODUCT_CACHE, key = "'getProductById'+#pk", unless = "#result == null")
- public Product get(String pk) {
+ @Cacheable(value = Constants.PRODUCT_CACHE, key = "'pk'+#pk", unless = "#result == null")
+ public Product findById(String pk) {
return productRepository.findById(pk).orElse(new Product());
}
- @Cacheable(value = Constants.THING_MODEL_CACHE, key = "'getThingModel'+#pk", unless = "#result == null")
+ @Cacheable(value = Constants.THING_MODEL_CACHE, key = "'pk'+#pk", unless = "#result == null")
public ThingModel getThingModel(String pk) {
- return thingModelRepository.findOne(Example.of(ThingModel.builder()
- .productKey(pk).build())).orElse(new ThingModel());
+ return thingModelRepository.findByProductKey(pk);
}
}
diff --git a/dao/src/main/java/cc/iotkit/dao/ProtocolGatewayRepository.java b/dao/src/main/java/cc/iotkit/dao/ProtocolGatewayRepository.java
new file mode 100755
index 00000000..d304423c
--- /dev/null
+++ b/dao/src/main/java/cc/iotkit/dao/ProtocolGatewayRepository.java
@@ -0,0 +1,11 @@
+package cc.iotkit.dao;
+
+import cc.iotkit.model.protocol.ProtocolGateway;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ProtocolGatewayRepository extends MongoRepository {
+
+
+}
diff --git a/dao/src/main/java/cc/iotkit/dao/SceneLogDao.java b/dao/src/main/java/cc/iotkit/dao/SceneLogDao.java
deleted file mode 100755
index c53d722b..00000000
--- a/dao/src/main/java/cc/iotkit/dao/SceneLogDao.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.model.rule.SceneLog;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.stereotype.Repository;
-
-import static org.springframework.data.mongodb.core.query.Criteria.where;
-
-@Repository
-public class SceneLogDao extends BaseDao {
-
- @Autowired
- public SceneLogDao(MongoTemplate mongoTemplate) {
- super(mongoTemplate, SceneLog.class);
- }
-
- public void deleteLogs(String sceneId) {
- this.mongoTemplate.remove(Query.query(where("sceneId").is(sceneId)), SceneLog.class);
- }
-}
diff --git a/dao/src/main/java/cc/iotkit/dao/SceneLogRepository.java b/dao/src/main/java/cc/iotkit/dao/SceneLogRepository.java
index eee529e8..30216d15 100755
--- a/dao/src/main/java/cc/iotkit/dao/SceneLogRepository.java
+++ b/dao/src/main/java/cc/iotkit/dao/SceneLogRepository.java
@@ -6,4 +6,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface SceneLogRepository extends MongoRepository {
+
+ void deleteBySceneId(String sceneId);
+
}
diff --git a/dao/src/main/java/cc/iotkit/dao/TaskLogDao.java b/dao/src/main/java/cc/iotkit/dao/TaskLogDao.java
deleted file mode 100755
index ee780dbc..00000000
--- a/dao/src/main/java/cc/iotkit/dao/TaskLogDao.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package cc.iotkit.dao;
-
-import cc.iotkit.model.rule.TaskLog;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.stereotype.Repository;
-
-import static org.springframework.data.mongodb.core.query.Criteria.where;
-
-@Repository
-public class TaskLogDao extends BaseDao {
-
- @Autowired
- public TaskLogDao(MongoTemplate mongoTemplate) {
- super(mongoTemplate, TaskLog.class);
- }
-
- public void deleteLogs(String taskId) {
- this.mongoTemplate.remove(Query.query(where("taskId").is(taskId)), TaskLog.class);
- }
-}
diff --git a/dao/src/main/java/cc/iotkit/dao/TaskLogRepository.java b/dao/src/main/java/cc/iotkit/dao/TaskLogRepository.java
index c197c13f..ddbbdc71 100755
--- a/dao/src/main/java/cc/iotkit/dao/TaskLogRepository.java
+++ b/dao/src/main/java/cc/iotkit/dao/TaskLogRepository.java
@@ -6,4 +6,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface TaskLogRepository extends MongoRepository {
+
+ void deleteByTaskId(String taskId);
+
}
diff --git a/dao/src/main/java/cc/iotkit/dao/ThingModelMessageRepository.java b/dao/src/main/java/cc/iotkit/dao/ThingModelMessageRepository.java
new file mode 100644
index 00000000..c865fbdd
--- /dev/null
+++ b/dao/src/main/java/cc/iotkit/dao/ThingModelMessageRepository.java
@@ -0,0 +1,9 @@
+package cc.iotkit.dao;
+
+import cc.iotkit.model.device.message.ThingModelMessage;
+import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ThingModelMessageRepository extends ElasticsearchRepository {
+}
diff --git a/dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java b/dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java
index 16612cb5..880adb47 100755
--- a/dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java
+++ b/dao/src/main/java/cc/iotkit/dao/ThingModelRepository.java
@@ -6,4 +6,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface ThingModelRepository extends MongoRepository {
+
+ ThingModel findByProductKey(String productKey);
+
}
diff --git a/dao/src/main/java/cc/iotkit/dao/UserInfoRepository.java b/dao/src/main/java/cc/iotkit/dao/UserInfoRepository.java
index e58f2c5c..afeece71 100755
--- a/dao/src/main/java/cc/iotkit/dao/UserInfoRepository.java
+++ b/dao/src/main/java/cc/iotkit/dao/UserInfoRepository.java
@@ -4,6 +4,13 @@ import cc.iotkit.model.UserInfo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
+import java.util.List;
+
@Repository
public interface UserInfoRepository extends MongoRepository {
+
+ List findByType(int type);
+
+ List findByTypeAndOwnerId(int type, String ownerId);
+
}
diff --git a/dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java b/dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java
new file mode 100644
index 00000000..0e5850e4
--- /dev/null
+++ b/dao/src/main/java/cc/iotkit/dao/config/ElasticsearchConfiguration.java
@@ -0,0 +1,13 @@
+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.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+
+@Configuration
+@EnableElasticsearchRepositories(basePackages = "cc.iotkit.dao", includeFilters =
+@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchRepository.class))
+public class ElasticsearchConfiguration {
+}
diff --git a/dao/src/main/java/cc/iotkit/dao/config/RepositoryConfig.java b/dao/src/main/java/cc/iotkit/dao/config/RepositoryConfig.java
index 9d5dc24e..c7a636be 100755
--- a/dao/src/main/java/cc/iotkit/dao/config/RepositoryConfig.java
+++ b/dao/src/main/java/cc/iotkit/dao/config/RepositoryConfig.java
@@ -1,19 +1,24 @@
package cc.iotkit.dao.config;
import org.springframework.beans.factory.BeanFactory;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
+import org.springframework.context.annotation.*;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mongodb.MongoDatabaseFactory;
-import org.springframework.data.mongodb.core.convert.DbRefResolver;
-import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
-import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
-import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
+import org.springframework.data.mongodb.core.MongoOperations;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.convert.*;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
+import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
+import java.util.Collections;
+
@Configuration
-@EnableMongoRepositories(basePackages = "cc.iotkit.dao")
+@Import(value = MongoAutoConfiguration.class)
+@EnableMongoRepositories(basePackages = "cc.iotkit.dao", includeFilters = @ComponentScan.Filter(
+ type = FilterType.ASSIGNABLE_TYPE, value = MongoRepository.class))
public class RepositoryConfig {
@Bean
@@ -28,4 +33,16 @@ public class RepositoryConfig {
return mappingMongoConverter;
}
+ @Bean
+ @ConditionalOnMissingBean({MongoOperations.class})
+ MongoTemplate mongoTemplate(MongoDatabaseFactory factory, MongoConverter converter) {
+ return new MongoTemplate(factory, converter);
+ }
+
+ @Bean
+ @Primary
+ MongoCustomConversions mongoCustomConversions() {
+ return new MongoCustomConversions(Collections.emptyList());
+ }
+
}
diff --git a/device-server/mqtt-auth/pom.xml b/device-server/mqtt-auth/pom.xml
deleted file mode 100755
index 4b942648..00000000
--- a/device-server/mqtt-auth/pom.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
- device-server
- cc.iotkit
- 0.0.1-SNAPSHOT
-
- 4.0.0
-
- mqtt-auth
-
-
-
- org.springframework.boot
- spring-boot-starter-data-mongodb
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- com.github.ben-manes.caffeine
- caffeine
-
-
-
- org.projectlombok
- lombok
- true
-
-
-
- org.apache.commons
- commons-lang3
-
-
-
- commons-codec
- commons-codec
-
-
-
- commons-beanutils
- commons-beanutils
-
-
-
- org.bouncycastle
- bcprov-jdk15on
-
-
-
- joda-time
- joda-time
-
-
-
- cc.iotkit
- common
-
-
-
- cc.iotkit
- model
-
-
- junit
- junit
- test
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- org.projectlombok
- lombok
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/device-server/mqtt-auth/src/main/java/cc/iotkit/mqttauth/dao/DaoTool.java b/device-server/mqtt-auth/src/main/java/cc/iotkit/mqttauth/dao/DaoTool.java
deleted file mode 100755
index 74f8b660..00000000
--- a/device-server/mqtt-auth/src/main/java/cc/iotkit/mqttauth/dao/DaoTool.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package cc.iotkit.mqttauth.dao;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.commons.beanutils.BeanMap;
-import org.springframework.data.mongodb.core.query.Update;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class DaoTool {
-
- public static void update(Update update, List props) {
- for (Prop pro : props) {
- update.set(pro.getName(), pro.getValue());
- }
- }
-
- public static List getProp(String key, Object value) {
- List props = new ArrayList<>();
- if (value instanceof Map) {
- Set> entrySet = ((Map) value).entrySet();
- for (Map.Entry entry : entrySet) {
- props.addAll(getProp(key + "." + entry.getKey(), entry.getValue()));
- }
- } else if (value != null && !(value instanceof Class)) {
- props.add(new Prop(key, value));
- }
- return props;
- }
-
- @SneakyThrows
- public static Update update(T obj) {
- Map