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:
commit
e7999749fb
Binary file not shown.
Binary file not shown.
|
@ -67,7 +67,7 @@
|
|||
<bizlog-sdk.version>3.0.6</bizlog-sdk.version>
|
||||
<mqtt.version>1.2.5</mqtt.version>
|
||||
<pf4j-spring.version>0.9.0</pf4j-spring.version>
|
||||
<vertx.version>4.4.0</vertx.version>
|
||||
<vertx.version>4.5.11</vertx.version>
|
||||
<!-- 三方云服务相关 -->
|
||||
<okio.version>3.5.0</okio.version>
|
||||
<okhttp3.version>4.11.0</okhttp3.version>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package cn.iocoder.yudao.framework.common.enums;
|
||||
|
||||
/**
|
||||
* RPC 相关的枚举
|
||||
*
|
||||
* 虽然放在 yudao-spring-boot-starter-rpc 会相对合适,但是每个 API 模块需要使用到,所以暂时只好放在此处
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class RpcConstants {
|
||||
|
||||
/**
|
||||
* RPC API 的前缀
|
||||
*/
|
||||
public static final String RPC_API_PREFIX = "/rpc-api";
|
||||
|
||||
}
|
|
@ -21,6 +21,14 @@
|
|||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 -->
|
||||
</dependency>
|
||||
|
||||
<!-- PF4J -->
|
||||
<!-- TODO 芋艿:这个依赖,要不要放在 api 包 -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// TODO 芋艿:纠结下
|
||||
/**
|
||||
* 服务注册表 - 插架模块使用,无法使用 Spring 注入
|
||||
*/
|
||||
public class ServiceRegistry {
|
||||
|
||||
private static final Map<Class<?>, Object> services = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 注册服务
|
||||
*
|
||||
* @param serviceClass 服务类
|
||||
* @param serviceImpl 服务实现
|
||||
* @param <T> 服务类
|
||||
*/
|
||||
public static <T> void registerService(Class<T> serviceClass, T serviceImpl) {
|
||||
services.put(serviceClass, serviceImpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得服务
|
||||
*
|
||||
* @param serviceClass 服务类
|
||||
* @param <T> 服务类
|
||||
* @return 服务实现
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getService(Class<T> serviceClass) {
|
||||
return (T) services.get(serviceClass);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,17 @@
|
|||
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.enums.ApiConstants;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
// TODO 芋艿:名字可能看情况改下
|
||||
/**
|
||||
* 设备数据 API
|
||||
*
|
||||
|
@ -10,11 +19,35 @@ import jakarta.validation.Valid;
|
|||
*/
|
||||
public interface DeviceDataApi {
|
||||
|
||||
// TODO @芋艿:可能会调整
|
||||
String PREFIX = ApiConstants.PREFIX + "/device-data";
|
||||
|
||||
/**
|
||||
* 保存设备数据
|
||||
* 更新设备状态
|
||||
*
|
||||
* @param createDTO 设备数据
|
||||
* @param updateReqDTO 更新请求
|
||||
*/
|
||||
void saveDeviceData(@Valid DeviceDataCreateReqDTO createDTO);
|
||||
@PutMapping(PREFIX + "/update-status")
|
||||
@PermitAll // TODO 芋艿:后续看看怎么优化下
|
||||
CommonResult<Boolean> updateDeviceStatus(@Valid @RequestBody IotDeviceStatusUpdateReqDTO updateReqDTO);
|
||||
|
||||
/**
|
||||
* 上报设备事件数据
|
||||
*
|
||||
* @param reportReqDTO 设备事件
|
||||
*/
|
||||
@PostMapping(PREFIX + "/report-event")
|
||||
@PermitAll // TODO 芋艿:后续看看怎么优化下
|
||||
CommonResult<Boolean> reportDeviceEventData(@Valid @RequestBody IotDeviceEventReportReqDTO reportReqDTO);
|
||||
|
||||
/**
|
||||
* 上报设备属性数据
|
||||
*
|
||||
* @param reportReqDTO 设备数据
|
||||
*/
|
||||
@PostMapping(PREFIX + "/report-property")
|
||||
@PermitAll // TODO 芋艿:后续看看怎么优化下
|
||||
CommonResult<Boolean> reportDevicePropertyData(@Valid @RequestBody IotDevicePropertyReportReqDTO reportReqDTO);
|
||||
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.api.device.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeviceDataCreateReqDTO {
|
||||
|
||||
/**
|
||||
* 产品标识
|
||||
*/
|
||||
@NotNull(message = "产品标识不能为空")
|
||||
private String productKey;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotNull(message = "设备名称不能为空")
|
||||
private String deviceName;
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
@NotNull(message = "消息不能为空")
|
||||
private String message;
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package cn.iocoder.yudao.module.iot.api.device.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* IoT 设备【事件】数据上报 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class IotDeviceEventReportReqDTO {
|
||||
|
||||
// TODO 芋艿:要不要 id
|
||||
// TODO 芋艿:要不要 time
|
||||
|
||||
/**
|
||||
* 产品标识
|
||||
*/
|
||||
@NotEmpty(message = "产品标识不能为空")
|
||||
private String productKey;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotEmpty(message = "设备名称不能为空")
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 事件标识
|
||||
*/
|
||||
@NotEmpty(message = "事件标识不能为空")
|
||||
private String identifier;
|
||||
/**
|
||||
* 事件参数
|
||||
*/
|
||||
@NotEmpty(message = "事件参数不能为空")
|
||||
private Map<String, Object> params;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package cn.iocoder.yudao.module.iot.api.device.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* IoT 设备【属性】数据上报 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class IotDevicePropertyReportReqDTO {
|
||||
|
||||
// TODO 芋艿:要不要 id
|
||||
// TODO 芋艿:要不要 time
|
||||
|
||||
/**
|
||||
* 产品标识
|
||||
*/
|
||||
@NotEmpty(message = "产品标识不能为空")
|
||||
private String productKey;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotEmpty(message = "设备名称不能为空")
|
||||
private String deviceName;
|
||||
/**
|
||||
* 属性参数
|
||||
*/
|
||||
@NotEmpty(message = "属性参数不能为空")
|
||||
private Map<String, Object> params;
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package cn.iocoder.yudao.module.iot.api.device.dto;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* IoT 设备状态更新 Request DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class IotDeviceStatusUpdateReqDTO {
|
||||
|
||||
// TODO 芋艿:要不要 id
|
||||
// TODO 芋艿:要不要 time
|
||||
|
||||
/**
|
||||
* 产品标识
|
||||
*/
|
||||
@NotEmpty(message = "产品标识不能为空")
|
||||
private String productKey;
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
@NotEmpty(message = "设备名称不能为空")
|
||||
private String deviceName;
|
||||
/**
|
||||
* 设备状态
|
||||
*/
|
||||
@NotEmpty(message = "设备状态不能为空")
|
||||
@InEnum(IotDeviceStatusEnum.class) // 只使用:在线、离线
|
||||
private Integer status;
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.iocoder.yudao.module.iot.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.RpcConstants;
|
||||
|
||||
/**
|
||||
* API 相关的枚举
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public class ApiConstants {
|
||||
|
||||
public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/iot";
|
||||
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
// TODO @芋艿:要不要加个 mqtt 值了的前缀
|
||||
/**
|
||||
* MQTT RPC 请求
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RpcRequest {
|
||||
|
||||
/**
|
||||
* 方法名
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
// TODO @haohao:object 对象会不会不好序列化?
|
||||
private Object[] params;
|
||||
|
||||
/**
|
||||
* 关联 ID
|
||||
*/
|
||||
private String correlationId;
|
||||
|
||||
/**
|
||||
* 回复地址
|
||||
*/
|
||||
private String replyTo;
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* MQTT RPC 响应
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RpcResponse {
|
||||
|
||||
/**
|
||||
* 关联 ID
|
||||
*/
|
||||
private String correlationId;
|
||||
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
// TODO @haohao:object 对象会不会不好反序列化?
|
||||
private Object result;
|
||||
|
||||
/**
|
||||
* 错误
|
||||
*/
|
||||
private String error;
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.mqttrpc.common;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
/**
|
||||
* 序列化工具类
|
||||
*
|
||||
*/
|
||||
public class SerializationUtils {
|
||||
|
||||
public static String serialize(Object obj) {
|
||||
return JSONUtil.toJsonStr(obj);
|
||||
}
|
||||
|
||||
public static <T> T deserialize(String json, Class<T> clazz) {
|
||||
return JSONUtil.toBean(json, clazz);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
// }
|
||||
//}
|
|
@ -8,9 +8,9 @@
|
|||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>yudao-module-iot-demo-plugin</module>
|
||||
<module>yudao-module-iot-http-plugin</module>
|
||||
<module>yudao-module-iot-mqtt-plugin</module>
|
||||
<module>yudao-module-iot-plugin-http</module>
|
||||
<module>yudao-module-iot-plugin-mqtt</module>
|
||||
<module>yudao-module-iot-plugin-emqx</module>
|
||||
</modules>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
plugin.id=demo-plugin
|
||||
plugin.class=cn.iocoder.yudao.module.iot.plugin.DemoPlugin
|
||||
plugin.version=0.0.1
|
||||
plugin.provider=ahh
|
||||
plugin.dependencies=
|
||||
plugin.description=demo-plugin
|
|
@ -1,77 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.plugin;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.Plugin;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.pf4j.RuntimeMode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* 一个启动 HTTP 服务器的简单插件。
|
||||
*/
|
||||
@Slf4j
|
||||
public class DemoPlugin extends Plugin {
|
||||
|
||||
private HttpServer server;
|
||||
|
||||
public DemoPlugin(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
log.info("Demo 插件启动");
|
||||
// for testing the development mode
|
||||
if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) {
|
||||
log.info("DemoPlugin in DEVELOPMENT mode");
|
||||
}
|
||||
startDemoServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
log.info("Demo 插件停止");
|
||||
stopDemoServer();
|
||||
}
|
||||
|
||||
private void startDemoServer() {
|
||||
try {
|
||||
server = HttpServer.create(new InetSocketAddress(9081), 0);
|
||||
server.createContext("/", exchange -> {
|
||||
String response = "Hello from DemoPlugin";
|
||||
exchange.sendResponseHeaders(200, response.getBytes().length);
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
});
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
log.info("HTTP 服务器启动成功,端口为 9081");
|
||||
log.info("访问地址为 http://127.0.0.1:9081/");
|
||||
} catch (IOException e) {
|
||||
log.error("HTTP 服务器启动失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopDemoServer() {
|
||||
if (server != null) {
|
||||
server.stop(0);
|
||||
log.info("HTTP 服务器停止成功");
|
||||
}
|
||||
}
|
||||
|
||||
// @Extension
|
||||
// public static class WelcomeGreeting implements Greeting {
|
||||
//
|
||||
// @Override
|
||||
// public String getGreeting() {
|
||||
// return "Welcome to DemoPlugin";
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>yudao-module-iot-plugin</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<version>2.2.0-snapshot</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yudao-module-iot-http-plugin</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>2.2.0-snapshot</version>
|
||||
<description>物联网 插件模块 - http 插件</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Plugin-Id>${plugin.id}</Plugin-Id>
|
||||
<Plugin-Class>${plugin.class}</Plugin-Class>
|
||||
<Plugin-Version>${plugin.version}</Plugin-Version>
|
||||
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
|
||||
<Plugin-Description>${plugin.description}</Plugin-Description>
|
||||
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<shadedClassifierName>shaded</shadedClassifierName>
|
||||
<transformers>
|
||||
<transformer>
|
||||
<mainClass>cn.iocoder.yudao.module.iot.HttpPluginSpringbootApplication</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.pf4j</groupId>
|
||||
<artifactId>pf4j-spring</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.plugin.HttpVertxPlugin</plugin.class>
|
||||
<plugin.version>0.0.1</plugin.version>
|
||||
<plugin.id>http-plugin</plugin.id>
|
||||
<plugin.description>http-plugin-0.0.1</plugin.description>
|
||||
<plugin.provider>ahh</plugin.provider>
|
||||
</properties>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
plugin.id=http-plugin
|
||||
plugin.class=cn.iocoder.yudao.module.iot.plugin.HttpVertxPlugin
|
||||
plugin.version=0.0.1
|
||||
plugin.provider=ahh
|
||||
plugin.dependencies=
|
||||
plugin.description=http-plugin-0.0.1
|
|
@ -1,157 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="
|
||||
http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yudao-module-iot-plugin</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>yudao-module-iot-http-plugin</artifactId>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
物联网 插件模块 - http 插件
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<!-- 插件相关 -->
|
||||
<plugin.id>http-plugin</plugin.id>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.plugin.HttpVertxPlugin</plugin.class>
|
||||
<plugin.version>0.0.1</plugin.version>
|
||||
<plugin.provider>ahh</plugin.provider>
|
||||
<plugin.description>http-plugin-0.0.1</plugin.description>
|
||||
<plugin.dependencies/>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unzip jar file</id>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<unzip src="target/${project.artifactId}-${project.version}.${project.packaging}"
|
||||
dest="target/plugin-classes"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>
|
||||
src/main/assembly/assembly.xml
|
||||
</descriptor>
|
||||
</descriptors>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>attached</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Plugin-Id>${plugin.id}</Plugin-Id>
|
||||
<Plugin-Class>${plugin.class}</Plugin-Class>
|
||||
<Plugin-Version>${plugin.version}</Plugin-Version>
|
||||
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
|
||||
<Plugin-Description>${plugin.description}</Plugin-Description>
|
||||
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-shade-plugin</artifactId>-->
|
||||
<!-- <version>3.4.1</version>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <phase>package</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>shade</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <shadedArtifactAttached>true</shadedArtifactAttached>-->
|
||||
<!-- <shadedClassifierName>shaded</shadedClassifierName>-->
|
||||
<!-- <transformers>-->
|
||||
<!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
|
||||
<!-- <mainClass>cn.iocoder.yudao.module.iot.HttpPluginSpringbootApplication</mainClass>-->
|
||||
<!-- </transformer>-->
|
||||
<!-- </transformers>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- </plugin>-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- 其他依赖项 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- PF4J Spring 集成 -->
|
||||
<dependency>
|
||||
<groupId>org.pf4j</groupId>
|
||||
<artifactId>pf4j-spring</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 项目依赖 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<artifactId>yudao-module-iot-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Vert.x Web -->
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web</artifactId>
|
||||
<version>4.5.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,31 +0,0 @@
|
|||
<assembly>
|
||||
<id>plugin</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<scope>runtime</scope>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<includes>
|
||||
<include>*:jar:*</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<!--
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
-->
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/plugin-classes</directory>
|
||||
<outputDirectory>classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
|
@ -1,11 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class HttpPluginSpringbootApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HttpPluginSpringbootApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
server:
|
||||
port: 8092
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: yudao-module-iot-http-plugin
|
||||
|
||||
# MQTT-RPC 配置
|
||||
mqtt:
|
||||
broker: tcp://chaojiniu.top:1883
|
||||
username: haohao
|
||||
password: ahh@123456
|
||||
clientId: mqtt-rpc-client-${random.int}
|
||||
requestTopic: rpc/request
|
||||
responseTopicPrefix: rpc/response/
|
|
@ -1,6 +1,6 @@
|
|||
plugin.id=emqx-plugin
|
||||
plugin.id=plugin-emqx
|
||||
plugin.class=cn.iocoder.yudao.module.iot.plugin.EmqxPlugin
|
||||
plugin.version=0.0.1
|
||||
plugin.version=1.0.0
|
||||
plugin.provider=ahh
|
||||
plugin.dependencies=
|
||||
plugin.description=emqx-plugin-0.0.1
|
||||
plugin.description=plugin-emqx-1.0.0
|
|
@ -11,7 +11,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>yudao-module-iot-emqx-plugin</artifactId>
|
||||
<artifactId>yudao-module-iot-plugin-emqx</artifactId>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
|
@ -1,12 +1,11 @@
|
|||
package cn.iocoder.yudao.module.iot.plugin;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.ServiceRegistry;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.Plugin;
|
||||
import org.pf4j.PluginWrapper;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -14,8 +13,6 @@ import java.util.concurrent.Executors;
|
|||
public class EmqxPlugin extends Plugin {
|
||||
|
||||
private ExecutorService executorService;
|
||||
@Resource
|
||||
private DeviceDataApi deviceDataApi;
|
||||
|
||||
public EmqxPlugin(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
|
@ -30,7 +27,7 @@ public class EmqxPlugin extends Plugin {
|
|||
executorService = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class);
|
||||
DeviceDataApi deviceDataApi = SpringUtil.getBean(DeviceDataApi.class);
|
||||
if (deviceDataApi == null) {
|
||||
log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!");
|
||||
return;
|
|
@ -0,0 +1,43 @@
|
|||
<?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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>yudao-module-iot-plugin</artifactId>
|
||||
<groupId>cn.iocoder.boot</groupId>
|
||||
<version>2.2.0-snapshot</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yudao-module-iot-plugin-http</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>1.0.0</version>
|
||||
<description>物联网 插件模块 - http 插件</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer>
|
||||
<mainClass>com.example.HttpPluginSpringbootApplication</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<properties>
|
||||
<plugin.id>${project.artifactId}</plugin.id>
|
||||
<plugin.description>${project.artifactId}-${project.version}</plugin.description>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.config.HttpVertxPlugin</plugin.class>
|
||||
<plugin.version>${project.version}</plugin.version>
|
||||
<plugin.provider>yudao</plugin.provider>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
plugin.id=yudao-module-iot-plugin-http
|
||||
plugin.class=cn.iocoder.yudao.module.iot.config.HttpVertxPlugin
|
||||
plugin.version=1.0.0
|
||||
plugin.provider=yudao
|
||||
plugin.dependencies=
|
||||
plugin.description=yudao-module-iot-plugin-http-1.0.0
|
|
@ -11,45 +11,27 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>yudao-module-iot-demo-plugin</artifactId>
|
||||
<artifactId>yudao-module-iot-plugin-http</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
物联网 插件模块 - demo 插件
|
||||
物联网 插件模块 - http 插件
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<!-- 插件相关 -->
|
||||
<plugin.id>demo-plugin</plugin.id>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.plugin.DemoPlugin</plugin.class>
|
||||
<plugin.version>0.0.1</plugin.version>
|
||||
<plugin.provider>ahh</plugin.provider>
|
||||
<plugin.id>${project.artifactId}</plugin.id>
|
||||
<plugin.class>cn.iocoder.yudao.module.iot.config.HttpVertxPlugin</plugin.class>
|
||||
<plugin.version>${project.version}</plugin.version>
|
||||
<plugin.provider>yudao</plugin.provider>
|
||||
<plugin.description>${project.artifactId}-${project.version}</plugin.description>
|
||||
<plugin.dependencies/>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- DOESN'T WORK WITH MAVEN 3 (I defined the plugin metadata in properties section)
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0-alpha-2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>read-project-properties</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<files>
|
||||
<file>plugin.properties</file>
|
||||
</files>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
|
||||
<!-- 插件模式 zip -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
|
@ -60,7 +42,8 @@
|
|||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" dest="target/plugin-classes" />
|
||||
<unzip src="target/${project.artifactId}-${project.version}.${project.packaging}"
|
||||
dest="target/plugin-classes"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
|
@ -92,6 +75,7 @@
|
|||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- 插件模式 jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
|
@ -103,12 +87,30 @@
|
|||
<Plugin-Class>${plugin.class}</Plugin-Class>
|
||||
<Plugin-Version>${plugin.version}</Plugin-Version>
|
||||
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
|
||||
<Plugin-Description>${plugin.description}</Plugin-Description>
|
||||
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- 独立模式 -->
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>-standalone</classifier>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
|
@ -123,14 +125,11 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- PF4J Spring 集成 -->
|
||||
<dependency>
|
||||
<groupId>org.pf4j</groupId>
|
||||
<artifactId>pf4j-spring</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 项目依赖 -->
|
||||
<dependency>
|
||||
|
@ -141,8 +140,11 @@
|
|||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Vert.x Web -->
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -14,14 +14,7 @@
|
|||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<!--
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/classes</directory>
|
||||
<outputDirectory>classes</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
-->
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target/plugin-classes</directory>
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.yudao.module.iot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// TODO @haohao:建议包名:cn.iocoder.yudao.module.iot.plugin.${pluginName},例如说 http。然后子包如下:
|
||||
// config:方配置类,以及 HttpVertxPlugin 初始化
|
||||
// service:放 HttpVertxHandler 逻辑;
|
||||
@SpringBootApplication
|
||||
public class HttpPluginSpringbootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// SpringApplication.run(HttpPluginSpringbootApplication.class, args);
|
||||
SpringApplication application = new SpringApplication(HttpPluginSpringbootApplication.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO @haohao:如下是 sdk 的包:cn.iocoder.yudao.module.iot.plugin.sdk
|
||||
// 1. api 包:实现 DeviceDataApi 接口,通过 resttemplate 调用
|
||||
// 2. config 包:初始化 DeviceDataApi 等等
|
||||
|
||||
// 3. 其中 resttemplate 调用的后端地址,通过每个服务的 application.yaml 进行注入。
|
|
@ -1,23 +1,22 @@
|
|||
package cn.iocoder.yudao.module.iot.plugin;
|
||||
package cn.iocoder.yudao.module.iot.config;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.api.ServiceRegistry;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.service.HttpVertxHandler;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.handler.BodyHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.pf4j.spring.SpringPlugin;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class HttpVertxPlugin extends SpringPlugin {
|
||||
|
||||
private static final int PORT = 8092;
|
||||
private Vertx vertx;
|
||||
private DeviceDataApi deviceDataApi;
|
||||
|
||||
public HttpVertxPlugin(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
|
@ -28,7 +27,7 @@ public class HttpVertxPlugin extends SpringPlugin {
|
|||
log.info("HttpVertxPlugin.start()");
|
||||
|
||||
// 获取 DeviceDataApi 实例
|
||||
deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class);
|
||||
DeviceDataApi deviceDataApi = SpringUtil.getBean(DeviceDataApi.class);
|
||||
if (deviceDataApi == null) {
|
||||
log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!");
|
||||
return;
|
|
@ -0,0 +1,69 @@
|
|||
package cn.iocoder.yudao.module.iot.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
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 org.pf4j.DefaultPluginManager;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
// TODO 芋艿:临时实现;
|
||||
@Configuration
|
||||
public class TestConfiguration {
|
||||
|
||||
// @Resource
|
||||
// private RestTemplate restTemplate;
|
||||
|
||||
// TODO 芋艿:这里,后续看看怎么创建好点
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplateBuilder().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeviceDataApi deviceDataApi(RestTemplate restTemplate) {
|
||||
return new DeviceDataApi() {
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) {
|
||||
// TODO haohao:待实现
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) {
|
||||
// TODO haohao:待实现
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) {
|
||||
// TODO haohao:待完整实现
|
||||
String url = "http://127.0.0.1:48080/rpc-api/iot/device-data/report-property";
|
||||
try {
|
||||
restTemplate.postForObject(url, reportReqDTO, CommonResult.class);
|
||||
return success(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return CommonResult.error(400, "error");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// TODO @haohao:可能要看下,有没更好的方式
|
||||
@Bean(initMethod = "start")
|
||||
public HttpVertxPlugin HttpVertxPlugin() {
|
||||
PluginWrapper pluginWrapper = new PluginWrapper(new DefaultPluginManager(), null, null, null);
|
||||
return new HttpVertxPlugin(pluginWrapper);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.iot.plugin;
|
||||
package cn.iocoder.yudao.module.iot.service;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RequestBody;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
@ -46,12 +46,12 @@ public class HttpVertxHandler implements Handler<RoutingContext> {
|
|||
|
||||
try {
|
||||
// 调用主程序的接口保存数据
|
||||
DeviceDataCreateReqDTO createDTO = DeviceDataCreateReqDTO.builder()
|
||||
IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder()
|
||||
.productKey(productKey)
|
||||
.deviceName(deviceName)
|
||||
.message(jsonData.toString())
|
||||
.params(jsonData) // TODO 芋艿:这块要优化
|
||||
.build();
|
||||
deviceDataApi.saveDeviceData(createDTO);
|
||||
deviceDataApi.reportDevicePropertyData(createDTO);
|
||||
|
||||
// 构造成功响应内容
|
||||
JSONObject successRes = createResponseJson(
|
|
@ -0,0 +1,3 @@
|
|||
spring:
|
||||
application:
|
||||
name: yudao-module-iot-plugin-http
|
|
@ -11,7 +11,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<artifactId>yudao-module-iot-mqtt-plugin</artifactId>
|
||||
<artifactId>yudao-module-iot-plugin-mqtt</artifactId>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
Loading…
Reference in New Issue