Merge branch 'feature/iot' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into origin/feature/iot
# Conflicts: # yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/ExampleService.java
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package cn.iocoder.yudao.module.iot.api.device;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceEventReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStatusUpdateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 设备数据 API 实现类
|
||||
*/
|
||||
@Service
|
||||
@RestController
|
||||
@Validated
|
||||
public class DeviceDataApiImpl implements DeviceDataApi {
|
||||
|
||||
@@ -18,8 +23,19 @@ public class DeviceDataApiImpl implements DeviceDataApi {
|
||||
private IotDevicePropertyDataService deviceDataService;
|
||||
|
||||
@Override
|
||||
public void saveDeviceData(DeviceDataCreateReqDTO createDTO) {
|
||||
deviceDataService.saveDeviceData(createDTO);
|
||||
public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) {
|
||||
deviceDataService.saveDeviceData(reportReqDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.iot.emq.service;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,10 +34,10 @@ public class EmqxServiceImpl implements EmqxService {
|
||||
String productKey = topic.split("/")[2];
|
||||
String deviceName = topic.split("/")[3];
|
||||
String message = new String(mqttMessage.getPayload());
|
||||
DeviceDataCreateReqDTO createDTO = DeviceDataCreateReqDTO.builder()
|
||||
IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder()
|
||||
.productKey(productKey)
|
||||
.deviceName(deviceName)
|
||||
.message(message)
|
||||
// .properties(message) // TODO 芋艿:临时去掉,看看
|
||||
.build();
|
||||
iotDeviceDataService.saveDeviceData(createDTO);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.plugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.spring.SpringPluginManager;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
// TODO @芋艿:需要 review 下
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PluginStart implements ApplicationRunner {
|
||||
|
||||
@@ -1,42 +1,33 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.plugin;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.ServiceRegistry;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.spring.SpringPluginManager;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
// TODO @芋艿:需要 review 下
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class UnifiedConfiguration {
|
||||
|
||||
private static final String SERVICE_REGISTRY_INITIALIZED_MARKER = "serviceRegistryInitializedMarker";
|
||||
|
||||
@Resource
|
||||
private DeviceDataApi deviceDataApi;
|
||||
|
||||
@Bean(SERVICE_REGISTRY_INITIALIZED_MARKER)
|
||||
public Object serviceRegistryInitializedMarker() {
|
||||
ServiceRegistry.registerService(DeviceDataApi.class, deviceDataApi);
|
||||
log.info("[init][将 DeviceDataApi 实例注册到 ServiceRegistry 中]");
|
||||
return new Object();
|
||||
}
|
||||
@Value("${pf4j.pluginsDir:pluginsDir}")
|
||||
private String pluginsDir;
|
||||
|
||||
@Bean
|
||||
@DependsOn(SERVICE_REGISTRY_INITIALIZED_MARKER)
|
||||
// @DependsOn("deviceDataApiImpl")
|
||||
public SpringPluginManager pluginManager() {
|
||||
log.info("[init][实例化 SpringPluginManager]");
|
||||
// SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) {
|
||||
SpringPluginManager springPluginManager = new SpringPluginManager() {
|
||||
|
||||
@Override
|
||||
public void startPlugins() {
|
||||
// 禁用插件启动,避免插件启动时,启动所有插件
|
||||
log.info("[init][禁用默认启动所有插件]");
|
||||
}
|
||||
|
||||
};
|
||||
springPluginManager.addPluginStateListener(new CustomPluginStateListener());
|
||||
return springPluginManager;
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.pf4j.PluginStateEvent;
|
||||
import org.pf4j.PluginStateListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
// TODO @芋艿:需要 review 下
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CustomPluginStateListener implements PluginStateListener {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.service.device;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -28,7 +28,7 @@ public interface IotDevicePropertyDataService {
|
||||
*
|
||||
* @param createDTO 设备数据
|
||||
*/
|
||||
void saveDeviceData(DeviceDataCreateReqDTO createDTO);
|
||||
void saveDeviceData(IotDevicePropertyReportReqDTO createDTO);
|
||||
|
||||
/**
|
||||
* 获得设备属性最新数据
|
||||
|
||||
@@ -6,7 +6,7 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
||||
@@ -130,11 +130,12 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDeviceData(DeviceDataCreateReqDTO createDTO) {
|
||||
public void saveDeviceData(IotDevicePropertyReportReqDTO createDTO) {
|
||||
// TODO 芋艿:这块需要实现
|
||||
// 1. 根据产品 key 和设备名称,获得设备信息
|
||||
IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceName(createDTO.getProductKey(), createDTO.getDeviceName());
|
||||
// 2. 解析消息,保存数据
|
||||
JSONObject jsonObject = new JSONObject(createDTO.getMessage());
|
||||
JSONObject jsonObject = new JSONObject(createDTO.getParams());
|
||||
log.info("[saveDeviceData][productKey({}) deviceName({}) data({})]", createDTO.getProductKey(), createDTO.getDeviceName(), jsonObject);
|
||||
ThingModelMessage thingModelMessage = ThingModelMessage.builder()
|
||||
.id(jsonObject.getStr("id"))
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
//package cn.iocoder.yudao.module.iot.service.plugin;
|
||||
//
|
||||
//import cn.iocoder.yudao.module.iot.mqttrpc.server.RpcServer;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//
|
||||
//@Service
|
||||
//@RequiredArgsConstructor
|
||||
//public class ExampleService {
|
||||
//
|
||||
// private final RpcServer rpcServer;
|
||||
//
|
||||
// @PostConstruct
|
||||
// public void registerMethods() {
|
||||
// rpcServer.registerMethod("add", params -> {
|
||||
// if (params.length != 2) {
|
||||
// throw new IllegalArgumentException("add方法需要两个参数");
|
||||
// }
|
||||
// int a = ((Number) params[0]).intValue();
|
||||
// int b = ((Number) params[1]).intValue();
|
||||
// return add(a, b);
|
||||
// });
|
||||
//
|
||||
// rpcServer.registerMethod("concat", params -> {
|
||||
// if (params.length != 2) {
|
||||
// throw new IllegalArgumentException("concat方法需要两个参数");
|
||||
// }
|
||||
// String str1 = params[0].toString();
|
||||
// String str2 = params[1].toString();
|
||||
// return concat(str1, str2);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private int add(int a, int b) {
|
||||
// return a + b;
|
||||
// }
|
||||
//
|
||||
// private String concat(String a, String b) {
|
||||
// return a + b;
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user