数据接口重构
parent
413818248a
commit
61fa50b612
Binary file not shown.
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iotkit-parent</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -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,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iotkit-parent</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -94,7 +94,17 @@
|
|||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-device-dao</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-data-cache</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -25,7 +25,7 @@ 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.IProtocolComponentData;
|
||||
import cc.iotkit.model.device.DeviceInfo;
|
||||
import cc.iotkit.model.device.message.ThingModelMessage;
|
||||
import cc.iotkit.model.product.Product;
|
||||
|
@ -60,7 +60,7 @@ public class DeviceComponentManager {
|
|||
@Autowired
|
||||
private ComponentConfig componentConfig;
|
||||
@Autowired
|
||||
private ProtocolComponentRepository componentRepository;
|
||||
private IProtocolComponentData protocolComponentData;
|
||||
@Autowired
|
||||
private DeviceCache deviceCache;
|
||||
@Autowired
|
||||
|
@ -71,7 +71,7 @@ public class DeviceComponentManager {
|
|||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
List<ProtocolComponent> componentList = componentRepository.findByStateAndType(
|
||||
List<ProtocolComponent> componentList = protocolComponentData.findByStateAndType(
|
||||
ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_DEVICE);
|
||||
for (ProtocolComponent component : componentList) {
|
||||
register(component);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ 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;
|
||||
|
@ -29,24 +32,24 @@ 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;
|
||||
@Autowired
|
||||
private ProductModelRepository productModelRepository;
|
||||
private IProductModelData productModelData;
|
||||
@Autowired
|
||||
private ProductCache productCache;
|
||||
@Autowired
|
||||
private DeviceInfoRepository deviceInfoRepository;
|
||||
private IDeviceInfoData deviceInfoData;
|
||||
@Autowired
|
||||
private DeviceCache deviceCache;
|
||||
@Autowired
|
||||
private MqProducer<ThingModelMessage> producer;
|
||||
@Autowired
|
||||
private IProductData productData;
|
||||
|
||||
public void register(RegisterInfo info) {
|
||||
try {
|
||||
|
@ -80,7 +83,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 +91,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 +132,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 +157,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,7 +180,7 @@ 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");
|
||||
|
@ -188,7 +191,7 @@ public class DeviceBehaviourService {
|
|||
return;
|
||||
}
|
||||
|
||||
List<DeviceInfo> subDevices = deviceInfoRepository.findByParentId(device.getDeviceId());
|
||||
List<DeviceInfo> subDevices = deviceInfoData.findByParentId(device.getDeviceId());
|
||||
for (DeviceInfo subDevice : subDevices) {
|
||||
Product product = productCache.findById(subDevice.getProductKey());
|
||||
Boolean transparent = product.getTransparent();
|
||||
|
@ -207,10 +210,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,
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ 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.data.cache.DeviceCacheService;
|
||||
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.stereotype.Service;
|
||||
|
@ -22,14 +24,18 @@ 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;
|
||||
@Autowired
|
||||
private DevicePropertyRepository propertyRepository;
|
||||
private IDevicePropertyData devicePropertyData;
|
||||
@Autowired
|
||||
private IDeviceInfoData deviceInfoData;
|
||||
@Autowired
|
||||
private DeviceCacheService deviceCacheService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
@ -63,7 +69,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 +80,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));
|
||||
deviceCacheService.saveProperties(deviceId, properties);
|
||||
} catch (Throwable e) {
|
||||
log.error("save device current properties error", e);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>iot-emqx-component</artifactId>
|
||||
|
@ -82,25 +82,25 @@
|
|||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-model</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-dao</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-common</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-component-base</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -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(IDeviceInfoData.class);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>iot-http-biz-component</artifactId>
|
||||
|
@ -58,7 +58,7 @@
|
|||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-component-base</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>iot-mqtt-component</artifactId>
|
||||
|
@ -80,19 +80,19 @@
|
|||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-common</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-component-base</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-dao</artifactId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iot-components</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<artifactId>iotkit-parent</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.aligenie.AligenieProduct;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AligenieProductRepository extends ElasticsearchRepository<AligenieProduct, String> {
|
||||
|
||||
List<AligenieProduct> findByUid(String uid);
|
||||
|
||||
AligenieProduct findByProductKey(String productKey);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.product.AppDesign;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AppDesignRepository extends ElasticsearchRepository<AppDesign, String> {
|
||||
|
||||
AppDesign findByProductKey(String productKey);
|
||||
|
||||
List<AppDesign> findByUid(String uid);
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.DeviceGroup;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface DeviceGroupRepository extends ElasticsearchRepository<DeviceGroup, String> {
|
||||
|
||||
Page<DeviceGroup> findByNameLike(String name, Pageable pageable);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.message.DeviceProperty;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface DevicePropertyRepository extends ElasticsearchRepository<DeviceProperty, String> {
|
||||
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.message.DeviceReport;
|
||||
import cc.iotkit.model.stats.TimeData;
|
||||
import lombok.SneakyThrows;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.clients.elasticsearch7.ElasticsearchAggregations;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class DeviceReportDao {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate template;
|
||||
|
||||
/**
|
||||
* 按用户统计时间段内上报次数
|
||||
*/
|
||||
public List<TimeData> getDeviceMessageStatsWithUid(String uid, long start, long end) {
|
||||
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery()
|
||||
.must(QueryBuilders.rangeQuery("time")
|
||||
.from(start, true).to(end, true));
|
||||
if (uid != null) {
|
||||
queryBuilder =
|
||||
queryBuilder.must(QueryBuilders.termQuery("uid", uid));
|
||||
}
|
||||
|
||||
NativeSearchQuery query = new NativeSearchQueryBuilder()
|
||||
.withQuery(queryBuilder)
|
||||
.withAggregations(AggregationBuilders.dateHistogram("agg")
|
||||
.field("time")
|
||||
.calendarInterval(DateHistogramInterval.HOUR)
|
||||
.calendarInterval(DateHistogramInterval.hours(1))
|
||||
)
|
||||
.build();
|
||||
|
||||
ElasticsearchAggregations result = (ElasticsearchAggregations) template
|
||||
.search(query, DeviceReport.class).getAggregations();
|
||||
ParsedDateHistogram histogram = result.aggregations().get("agg");
|
||||
|
||||
List<TimeData> data = new ArrayList<>();
|
||||
for (Histogram.Bucket bucket : histogram.getBuckets()) {
|
||||
long seconds = ((ZonedDateTime) bucket.getKey()).toInstant().getEpochSecond();
|
||||
data.add(new TimeData(seconds * 1000, bucket.getDocCount()));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计时间段内上报次数
|
||||
*/
|
||||
@SneakyThrows
|
||||
public List<TimeData> getDeviceMessageStats(long start, long end) {
|
||||
return getDeviceMessageStatsWithUid(null, start, end);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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> {
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.rule.RuleInfo;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RuleInfoRepository extends ElasticsearchRepository<RuleInfo, String> {
|
||||
|
||||
List<RuleInfo> findByUidAndType(String uid, String type);
|
||||
|
||||
Page<RuleInfo> findByUidAndType(String uid, String type, Pageable pageable);
|
||||
|
||||
Page<RuleInfo> findByType(String type, Pageable pageable);
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.rule.RuleLog;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface RuleLogRepository extends ElasticsearchRepository<RuleLog, String> {
|
||||
|
||||
void deleteByRuleId(String ruleId);
|
||||
|
||||
Page<RuleLog> findByRuleId(String ruleId, Pageable pageable);
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.space.SpaceDevice;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SpaceDeviceRepository extends ElasticsearchRepository<SpaceDevice, String> {
|
||||
|
||||
List<SpaceDevice> findByUidOrderByUseAtDesc(String uid);
|
||||
|
||||
List<SpaceDevice> findByUidOrderByAddAtDesc(String uid);
|
||||
|
||||
List<SpaceDevice> findByUid(String uid);
|
||||
|
||||
List<SpaceDevice> findBySpaceIdOrderByAddAtDesc(String spaceId);
|
||||
|
||||
List<SpaceDevice> findByUidAndSpaceIdOrderByAddAtDesc(String uid, String spaceId);
|
||||
|
||||
SpaceDevice findByDeviceId(String deviceId);
|
||||
|
||||
SpaceDevice findByDeviceIdAndUid(String deviceId, String uid);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.space.Space;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SpaceRepository extends ElasticsearchRepository<Space, String> {
|
||||
|
||||
List<Space> findByUidOrderByCreateAtDesc(String uid);
|
||||
|
||||
List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId);
|
||||
|
||||
List<Space> findByHomeId(String homeId);
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.rule.TaskInfo;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskInfoRepository extends ElasticsearchRepository<TaskInfo, String> {
|
||||
|
||||
List<TaskInfo> findByUid(String uid);
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.rule.TaskLog;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface TaskLogRepository extends ElasticsearchRepository<TaskLog, String> {
|
||||
|
||||
void deleteByTaskId(String taskId);
|
||||
|
||||
Page<TaskLog> findByTaskId(String taskId, Pageable pageable);
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.message.ThingModelMessage;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface ThingModelMessageRepository extends ElasticsearchRepository<ThingModelMessage, String> {
|
||||
|
||||
Page<ThingModelMessage> findByTypeAndIdentifier(String type, String identifier, Pageable pageable);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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> {
|
||||
|
||||
|
||||
}
|
|
@ -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> {
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.UserInfo;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserInfoRepository extends ElasticsearchRepository<UserInfo, String> {
|
||||
|
||||
UserInfo findByUid(String uid);
|
||||
|
||||
List<UserInfo> findByType(int type);
|
||||
|
||||
List<UserInfo> findByTypeAndOwnerId(int type, String ownerId);
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.VirtualDeviceLog;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
public interface VirtualDeviceLogRepository extends ElasticsearchRepository<VirtualDeviceLog, String> {
|
||||
|
||||
Page<VirtualDeviceLog> findByVirtualDeviceId(String virtualDeviceId, Pageable pageable);
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.model.device.VirtualDevice;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface VirtualDeviceRepository extends ElasticsearchRepository<VirtualDevice, String> {
|
||||
|
||||
Page<VirtualDevice> findByUid(String uid, Pageable pageable);
|
||||
|
||||
List<VirtualDevice> findByUidAndState(String uid, String state);
|
||||
|
||||
List<VirtualDevice> findByTriggerAndState(String trigger, String state);
|
||||
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 第三方接入用户会话
|
||||
*/
|
||||
@Data
|
||||
@Document(indexName = "third_user_session")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ThirdUserSession {
|
||||
|
||||
/**
|
||||
* 账号id
|
||||
*/
|
||||
@Id
|
||||
private String uid;
|
||||
|
||||
/**
|
||||
* 账号类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 登录授权后的token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 授权时间
|
||||
*/
|
||||
@Field(type = FieldType.Date)
|
||||
private Long authAt;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.model.product;
|
||||
|
||||
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;
|
||||
|
||||
@Data
|
||||
@Document(indexName = "category")
|
||||
public class Category {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Field(type = FieldType.Date)
|
||||
private Long createAt;
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
与数据存取相关内容的模块
|
|
@ -3,9 +3,9 @@
|
|||
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>
|
||||
<artifactId>iot-data</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -33,6 +33,11 @@
|
|||
<artifactId>iot-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-data-service</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -10,6 +10,7 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.ICategoryData;
|
||||
import cc.iotkit.model.product.Category;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -22,7 +23,7 @@ import javax.annotation.PostConstruct;
|
|||
public class CategoryCache {
|
||||
|
||||
@Autowired
|
||||
private CategoryRepository categoryRepository;
|
||||
private ICategoryData categoryData;
|
||||
|
||||
private static CategoryCache INSTANCE;
|
||||
|
||||
|
@ -37,6 +38,6 @@ public class CategoryCache {
|
|||
|
||||
@Cacheable(value = Constants.CATEGORY_CACHE, key = "#id")
|
||||
public Category getById(String id) {
|
||||
return categoryRepository.findById(id).orElse(null);
|
||||
return categoryData.findById(id);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.IDeviceInfoData;
|
||||
import cc.iotkit.model.device.DeviceInfo;
|
||||
import cc.iotkit.model.stats.DataItem;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -23,7 +24,7 @@ import java.util.List;
|
|||
public class DeviceCache {
|
||||
|
||||
@Autowired
|
||||
private DeviceInfoRepository deviceInfoRepository;
|
||||
private IDeviceInfoData deviceInfoData;
|
||||
@Autowired
|
||||
private DeviceDao deviceDao;
|
||||
|
||||
|
@ -40,17 +41,17 @@ public class DeviceCache {
|
|||
|
||||
@Cacheable(value = Constants.DEVICE_CACHE, key = "#pk+'_'+#dn")
|
||||
public DeviceInfo getDeviceInfo(String pk, String dn) {
|
||||
return deviceInfoRepository.findByProductKeyAndDeviceName(pk, dn);
|
||||
return deviceInfoData.findByProductKeyAndDeviceName(pk, dn);
|
||||
}
|
||||
|
||||
@Cacheable(value = Constants.DEVICE_CACHE, key = "#deviceId")
|
||||
public DeviceInfo get(String deviceId) {
|
||||
return deviceInfoRepository.findById(deviceId).orElse(null);
|
||||
return deviceInfoData.findByDeviceId(deviceId);
|
||||
}
|
||||
|
||||
@Cacheable(value = Constants.DEVICE_STATS_CACHE, key = "#uid")
|
||||
public List<DataItem> getDeviceStatsByCategory(String uid) {
|
||||
return deviceDao.getDeviceStatsByCategory(uid);
|
||||
return deviceInfoData.getDeviceStatsByCategory(uid);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.data.ICategoryData;
|
||||
import cc.iotkit.data.IDeviceInfoData;
|
||||
import cc.iotkit.data.IProductData;
|
||||
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 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.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.core.clients.elasticsearch7.ElasticsearchAggregations;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public class DeviceDao {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
|
||||
@Autowired
|
||||
private IDeviceInfoData deviceInfoData;
|
||||
@Autowired
|
||||
private IProductData productData;
|
||||
@Autowired
|
||||
private ICategoryData categoryData;
|
||||
|
||||
/**
|
||||
* 获取按品类统计的用户设备数
|
||||
*/
|
||||
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 = productData.findByUid(uid);
|
||||
} else {
|
||||
products = productData.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 : categoryData.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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.IOauthClientData;
|
||||
import cc.iotkit.model.OauthClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.PostConstruct;
|
|||
public class OauthClientCache {
|
||||
|
||||
@Autowired
|
||||
private OauthClientRepository oauthClientRepository;
|
||||
private IOauthClientData oauthClientData;
|
||||
|
||||
private static OauthClientCache INSTANCE;
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class OauthClientCache {
|
|||
|
||||
@Cacheable(value = Constants.OAUTH_CLIENT_CACHE, key = "#clientId")
|
||||
public OauthClient getClient(String clientId) {
|
||||
return oauthClientRepository.findById(clientId).orElse(null);
|
||||
return oauthClientData.findByClientId(clientId);
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,9 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.IProductModelData;
|
||||
import cc.iotkit.data.IProductData;
|
||||
import cc.iotkit.data.IThingModelData;
|
||||
import cc.iotkit.model.product.Product;
|
||||
import cc.iotkit.model.product.ProductModel;
|
||||
import cc.iotkit.model.product.ThingModel;
|
||||
|
@ -23,11 +26,11 @@ import javax.annotation.PostConstruct;
|
|||
public class ProductCache {
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
private IProductData productData;
|
||||
@Autowired
|
||||
private ThingModelRepository thingModelRepository;
|
||||
private IThingModelData thingModelData;
|
||||
@Autowired
|
||||
private ProductModelRepository productModelRepository;
|
||||
private IProductModelData productModelData;
|
||||
|
||||
private static ProductCache INSTANCE;
|
||||
|
||||
|
@ -42,17 +45,17 @@ public class ProductCache {
|
|||
|
||||
@Cacheable(value = Constants.PRODUCT_CACHE, key = "'product'+#pk")
|
||||
public Product findById(String pk) {
|
||||
return productRepository.findById(pk).orElse(new Product());
|
||||
return productData.findById(pk);
|
||||
}
|
||||
|
||||
@Cacheable(value = Constants.THING_MODEL_CACHE, key = "'thing_model'+#pk")
|
||||
public ThingModel getThingModel(String pk) {
|
||||
return thingModelRepository.findByProductKey(pk);
|
||||
return thingModelData.findByProductKey(pk);
|
||||
}
|
||||
|
||||
@Cacheable(value = Constants.PRODUCT_SCRIPT_CACHE, key = "'product_script'+#model")
|
||||
public ProductModel getProductScriptByModel(String model) {
|
||||
return productModelRepository.findByModel(model);
|
||||
return productModelData.findByModel(model);
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.ISpaceData;
|
||||
import cc.iotkit.model.space.Space;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -12,7 +13,7 @@ import javax.annotation.PostConstruct;
|
|||
public class SpaceCache {
|
||||
|
||||
@Autowired
|
||||
private SpaceRepository spaceRepository;
|
||||
private ISpaceData spaceData;
|
||||
|
||||
private static SpaceCache INSTANCE;
|
||||
|
||||
|
@ -27,7 +28,7 @@ public class SpaceCache {
|
|||
|
||||
@Cacheable(value = Constants.SPACE_CACHE, key = "#spaceId")
|
||||
public Space getSpace(String spaceId) {
|
||||
return spaceRepository.findById(spaceId).orElse(null);
|
||||
return spaceData.findById(spaceId);
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
package cc.iotkit.dao;
|
||||
|
||||
import cc.iotkit.common.Constants;
|
||||
import cc.iotkit.data.IUserInfoData;
|
||||
import cc.iotkit.model.UserInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -21,7 +22,7 @@ import javax.annotation.PostConstruct;
|
|||
public class UserInfoCache {
|
||||
|
||||
@Autowired
|
||||
private UserInfoRepository userInfoRepository;
|
||||
private IUserInfoData userInfoData;
|
||||
|
||||
private static UserInfoCache INSTANCE;
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class UserInfoCache {
|
|||
|
||||
@Cacheable(value = Constants.USER_CACHE, key = "#uid")
|
||||
public UserInfo getUserInfo(String uid) {
|
||||
return userInfoRepository.findById(uid).orElse(null);
|
||||
return userInfoData.findById(uid);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?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>iotkit-parent</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</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.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
41
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceCacheService.java
vendored
Normal file
41
iot-data/iot-data-cache/src/main/java/cc/iotkit/data/cache/DeviceCacheService.java
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
package cc.iotkit.data.cache;
|
||||
|
||||
import cc.iotkit.common.utils.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DeviceCacheService {
|
||||
|
||||
private static final String PROPERTY_CACHE_KEY = "str:device:property:%s";
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
private String getPropertyCacheKey(String deviceId) {
|
||||
return String.format(PROPERTY_CACHE_KEY, deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设备属性到redis
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param properties 设备属性map
|
||||
*/
|
||||
public void saveProperties(String deviceId, Map<String, Object> properties) {
|
||||
redisTemplate.opsForValue().set(getPropertyCacheKey(deviceId), JsonUtil.toJsonString(properties));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备属性map
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
*/
|
||||
public Map<String, Object> getProperties(String deviceId) {
|
||||
return JsonUtil.parse(redisTemplate.opsForValue().get(getPropertyCacheKey(deviceId)), Map.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -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.3.3-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>
|
|
@ -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> {
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
@ -7,12 +7,13 @@
|
|||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.OauthClient;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.device.DeviceGroup;
|
||||
|
||||
public interface OauthClientRepository extends ElasticsearchRepository<OauthClient, String> {
|
||||
public interface IDeviceGroupData extends ICommonData<DeviceGroup, String> {
|
||||
|
||||
Paging<DeviceGroup> findByNameLike(String name, int page, int size);
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | 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.DeviceInfo;
|
||||
import cc.iotkit.model.stats.DataItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IDeviceInfoData extends IOwnedData<DeviceInfo, String> {
|
||||
|
||||
/**
|
||||
* 根据设备ID取设备信息
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
*/
|
||||
DeviceInfo findByDeviceId(String deviceId);
|
||||
|
||||
/**
|
||||
* 按productKey和deviceName取设备信息
|
||||
*/
|
||||
DeviceInfo findByProductKeyAndDeviceName(String productKey, String deviceName);
|
||||
|
||||
/**
|
||||
* 根据父设备ID取子设备列表
|
||||
*
|
||||
* @param parentId 父设备ID
|
||||
*/
|
||||
List<DeviceInfo> findByParentId(String parentId);
|
||||
|
||||
/**
|
||||
* 根据deviceName查找设备
|
||||
*/
|
||||
List<DeviceInfo> findByDeviceName(String deviceName);
|
||||
|
||||
/**
|
||||
* 按条件搜索设备
|
||||
*
|
||||
* @param uid 所属账号id
|
||||
* @param subUid 子账号id
|
||||
* @param productKey 产品key
|
||||
* @param groupId 设备分组
|
||||
* @param state 是否在线:online在线,offline离线
|
||||
* @param keyword 关键字
|
||||
* @param page 页码
|
||||
* @param size 分页大小
|
||||
*/
|
||||
Paging<DeviceInfo> findByConditions(String uid, String subUid, String productKey,
|
||||
String groupId, String state, String keyword,
|
||||
int page, int size);
|
||||
|
||||
/**
|
||||
* 更新设备标签
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param tag 标签
|
||||
*/
|
||||
void updateTag(String deviceId, DeviceInfo.Tag tag);
|
||||
|
||||
/**
|
||||
* 获取按品类统计的用户设备数
|
||||
*/
|
||||
List<DataItem> getDeviceStatsByCategory(String uid);
|
||||
|
||||
/**
|
||||
* 按分组id统计设备数量
|
||||
*/
|
||||
long countByGroupId(String groupId);
|
||||
|
||||
/**
|
||||
* 将设备添加到分组
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param group 设备分组
|
||||
*/
|
||||
void addToGroup(String deviceId, DeviceInfo.Group group);
|
||||
|
||||
/**
|
||||
* 按组id更新设备分组
|
||||
*
|
||||
* @param groupId 分组ID
|
||||
* @param group 设备分组信息
|
||||
*/
|
||||
void updateGroup(String groupId, DeviceInfo.Group group);
|
||||
|
||||
/**
|
||||
* 移除指定设备信息中的分组
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param groupId 分组ID
|
||||
*/
|
||||
void removeGroup(String deviceId, String groupId);
|
||||
|
||||
/**
|
||||
* 移除设备信息中的分组
|
||||
*
|
||||
* @param groupId 分组ID
|
||||
*/
|
||||
void removeGroup(String groupId);
|
||||
}
|
|
@ -7,16 +7,12 @@
|
|||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.space.Home;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HomeRepository extends ElasticsearchRepository<Home, String> {
|
||||
|
||||
List<Home> findByUid(String uid);
|
||||
public interface IHomeData extends IOwnedData<Home, String> {
|
||||
|
||||
Home findByUidAndCurrent(String uid, boolean current);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.OauthClient;
|
||||
|
||||
public interface IOauthClientData extends ICommonData<OauthClient, String> {
|
||||
|
||||
OauthClient findByClientId(String clientId);
|
||||
|
||||
}
|
|
@ -7,13 +7,28 @@
|
|||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.device.message.DeviceReport;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import cc.iotkit.model.Owned;
|
||||
import cc.iotkit.model.Paging;
|
||||
|
||||
public interface DeviceReportRepository extends ElasticsearchRepository<DeviceReport, String> {
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据基础服务接口
|
||||
*/
|
||||
public interface IOwnedData<T extends Owned<ID>, ID> extends ICommonData<T, ID> {
|
||||
|
||||
/**
|
||||
* 按所属用户取数据
|
||||
*/
|
||||
List<T> findByUid(String uid);
|
||||
|
||||
Paging<T> findByUid(String uid, int page, int size);
|
||||
|
||||
/**
|
||||
* 按所属用户统计总数
|
||||
*/
|
||||
long countByUid(String uid);
|
||||
|
||||
}
|
|
@ -7,19 +7,20 @@
|
|||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.product.Product;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductRepository extends ElasticsearchRepository<Product, String> {
|
||||
|
||||
long countByUid(String uid);
|
||||
|
||||
List<Product> findByUid(String uid);
|
||||
/**
|
||||
* 产品接口
|
||||
*/
|
||||
public interface IProductData extends IOwnedData<Product, String> {
|
||||
|
||||
/**
|
||||
* 按品类取产品列表
|
||||
*/
|
||||
List<Product> findByCategory(String category);
|
||||
|
||||
}
|
|
@ -7,14 +7,13 @@
|
|||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.product.ProductModel;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductModelRepository extends ElasticsearchRepository<ProductModel, String> {
|
||||
public interface IProductModelData extends ICommonData<ProductModel, String> {
|
||||
|
||||
ProductModel findByModel(String model);
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.protocol.ProtocolComponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IProtocolComponentData extends IOwnedData<ProtocolComponent, String> {
|
||||
|
||||
List<ProtocolComponent> findByState(String state);
|
||||
|
||||
List<ProtocolComponent> findByStateAndType(String state, String type);
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.protocol.ProtocolConverter;
|
||||
|
||||
public interface IProtocolConverterData extends IOwnedData<ProtocolConverter, String> {
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.rule.RuleInfo;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IRuleInfoData extends IOwnedData<RuleInfo, String> {
|
||||
|
||||
List<RuleInfo> findByUidAndType(String uid, String type);
|
||||
|
||||
Paging<RuleInfo> findByUidAndType(String uid, String type, int page, int size);
|
||||
|
||||
Paging<RuleInfo> findByType(String type, int page, int size);
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.space.Space;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ISpaceData extends IOwnedData<Space,String> {
|
||||
|
||||
List<Space> findByUidOrderByCreateAtDesc(String uid);
|
||||
|
||||
List<Space> findByUidAndHomeIdOrderByCreateAtDesc(String uid, String homeId);
|
||||
|
||||
List<Space> findByHomeId(String homeId);
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.space.SpaceDevice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ISpaceDeviceData extends IOwnedData<SpaceDevice, String> {
|
||||
|
||||
List<SpaceDevice> findByUidOrderByUseAtDesc(String uid);
|
||||
|
||||
List<SpaceDevice> findByUidOrderByAddAtDesc(String uid);
|
||||
|
||||
List<SpaceDevice> findBySpaceIdOrderByAddAtDesc(String spaceId);
|
||||
|
||||
List<SpaceDevice> findByUidAndSpaceIdOrderByAddAtDesc(String uid, String spaceId);
|
||||
|
||||
SpaceDevice findByDeviceId(String deviceId);
|
||||
|
||||
SpaceDevice findByDeviceIdAndUid(String deviceId, String uid);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.rule.TaskInfo;
|
||||
|
||||
public interface ITaskInfoData extends IOwnedData<TaskInfo, String> {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.product.ThingModel;
|
||||
|
||||
public interface IThingModelData extends ICommonData<ThingModel, String> {
|
||||
|
||||
ThingModel findByProductKey(String productKey);
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.UserInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserInfoData extends ICommonData<UserInfo, String> {
|
||||
|
||||
UserInfo findByUid(String uid);
|
||||
|
||||
List<UserInfo> findByType(int type);
|
||||
|
||||
List<UserInfo> findByTypeAndOwnerId(int type, String ownerId);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cc.iotkit.data;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.device.VirtualDevice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IVirtualDeviceData extends IOwnedData<VirtualDevice, String> {
|
||||
|
||||
Paging<VirtualDevice> findByUid(String uid, int size, int page);
|
||||
|
||||
List<VirtualDevice> findByUidAndState(String uid, String state);
|
||||
|
||||
List<VirtualDevice> findByTriggerAndState(String trigger, String state);
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?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.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>iot-es-temporal-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<artifactId>iot-temporal-service</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,43 @@
|
|||
package cc.iotkit.temporal.es.document;
|
||||
|
||||
import cc.iotkit.model.device.message.DeviceProperty;
|
||||
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_property")
|
||||
public class DevicePropertyDoc {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String name;
|
||||
|
||||
private Object value;
|
||||
|
||||
@Field(type = FieldType.Date)
|
||||
private Long time;
|
||||
|
||||
public DeviceProperty de() {
|
||||
return new DeviceProperty(id, deviceId, name, value, time);
|
||||
}
|
||||
|
||||
public DevicePropertyDoc(DeviceProperty raw) {
|
||||
this.id = raw.getId();
|
||||
this.deviceId = raw.getDeviceId();
|
||||
this.name = raw.getName();
|
||||
this.value = raw.getValue();
|
||||
this.time = raw.getTime();
|
||||
}
|
||||
}
|
|
@ -1,31 +1,23 @@
|
|||
/*
|
||||
* +----------------------------------------------------------------------
|
||||
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||
* +----------------------------------------------------------------------
|
||||
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||
* +----------------------------------------------------------------------
|
||||
* | Author: xw2sy@163.com
|
||||
* +----------------------------------------------------------------------
|
||||
*/
|
||||
package cc.iotkit.dao;
|
||||
package cc.iotkit.temporal.es.service;
|
||||
|
||||
import cc.iotkit.model.device.message.DeviceProperty;
|
||||
import cc.iotkit.temporal.IDevicePropertyData;
|
||||
import cc.iotkit.temporal.es.document.DevicePropertyDoc;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Repository
|
||||
public class DevicePropertyDao {
|
||||
@Service
|
||||
public class DevicePropertyDataImpl implements IDevicePropertyData {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate template;
|
||||
|
@ -41,9 +33,17 @@ public class DevicePropertyDao {
|
|||
)
|
||||
.withSorts(new FieldSortBuilder("time").order(SortOrder.ASC))
|
||||
.build();
|
||||
SearchHits<DeviceProperty> result = template.search(query, DeviceProperty.class);
|
||||
SearchHits<DevicePropertyDoc> result = template.search(query, DevicePropertyDoc.class);
|
||||
return result.getSearchHits().stream()
|
||||
.map(SearchHit::getContent).collect(Collectors.toList());
|
||||
.map(h -> h.getContent().de())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProperties(List<DeviceProperty> properties) {
|
||||
template.save(properties.stream().map(DevicePropertyDoc::new)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.iotkit.temporal.es.service;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.rule.RuleLog;
|
||||
import cc.iotkit.temporal.IRuleLogData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RuleLogDataImpl implements IRuleLogData {
|
||||
@Override
|
||||
public void deleteByRuleId(String ruleId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paging<RuleLog> findByRuleId(String ruleId, int page, int size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(RuleLog log) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cc.iotkit.temporal.es.service;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.rule.TaskLog;
|
||||
import cc.iotkit.temporal.ITaskLogData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TaskLogDataImpl implements ITaskLogData {
|
||||
@Override
|
||||
public void deleteByTaskId(String taskId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paging<TaskLog> findByTaskId(String taskId, int page, int size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(TaskLog log) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package cc.iotkit.dao;
|
||||
package cc.iotkit.temporal.es.service;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.device.message.ThingModelMessage;
|
||||
import cc.iotkit.model.stats.TimeData;
|
||||
import cc.iotkit.temporal.IThingModelMessageData;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
|
@ -13,12 +15,13 @@ 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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Repository
|
||||
public class ThingModelMessageDao {
|
||||
@Service
|
||||
public class ThingModelMessageDataImpl implements IThingModelMessageData {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchRestTemplate template;
|
||||
|
@ -41,4 +44,19 @@ public class ThingModelMessageDao {
|
|||
return new Paging<>(result.getTotalHits(), result.getSearchHits().stream()
|
||||
.map(SearchHit::getContent).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimeData> getDeviceMessageStatsWithUid(String uid, long start, long end) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ThingModelMessage msg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.iotkit.temporal.es.service;
|
||||
|
||||
import cc.iotkit.model.Paging;
|
||||
import cc.iotkit.model.device.VirtualDeviceLog;
|
||||
import cc.iotkit.temporal.IVirtualDeviceLogData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData {
|
||||
@Override
|
||||
public Paging<VirtualDeviceLog> findByVirtualDeviceId(String virtualDeviceId, int page, int size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(VirtualDeviceLog log) {
|
||||
|
||||
}
|
||||
}
|
|
@ -3,11 +3,11 @@
|
|||
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>
|
||||
<artifactId>iot-data</artifactId>
|
||||
<groupId>cc.iotkit</groupId>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<version>0.3.2-SNAPSHOT</version>
|
||||
<version>0.3.3-SNAPSHOT</version>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>iot-model</artifactId>
|
|
@ -0,0 +1,9 @@
|
|||
package cc.iotkit.model;
|
||||
|
||||
public interface Id<T> {
|
||||
|
||||
T getId();
|
||||
|
||||
void setId(T id);
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue