Commit e7999749fb72e1bd8c8568ab2d4265a2531efe36
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
Showing
45 changed files
with
344 additions
and
587 deletions
plugins/yudao-module-iot-http-plugin-2.2.0-snapshot.jar
No preview for this file type
plugins/yudao-module-iot-plugin-http-1.0.0.jar
0 → 100644
No preview for this file type
yudao-dependencies/pom.xml
| @@ -67,7 +67,7 @@ | @@ -67,7 +67,7 @@ | ||
| 67 | <bizlog-sdk.version>3.0.6</bizlog-sdk.version> | 67 | <bizlog-sdk.version>3.0.6</bizlog-sdk.version> |
| 68 | <mqtt.version>1.2.5</mqtt.version> | 68 | <mqtt.version>1.2.5</mqtt.version> |
| 69 | <pf4j-spring.version>0.9.0</pf4j-spring.version> | 69 | <pf4j-spring.version>0.9.0</pf4j-spring.version> |
| 70 | - <vertx.version>4.4.0</vertx.version> | 70 | + <vertx.version>4.5.11</vertx.version> |
| 71 | <!-- 三方云服务相关 --> | 71 | <!-- 三方云服务相关 --> |
| 72 | <okio.version>3.5.0</okio.version> | 72 | <okio.version>3.5.0</okio.version> |
| 73 | <okhttp3.version>4.11.0</okhttp3.version> | 73 | <okhttp3.version>4.11.0</okhttp3.version> |
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/RpcConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.common.enums; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * RPC 相关的枚举 | ||
| 5 | + * | ||
| 6 | + * 虽然放在 yudao-spring-boot-starter-rpc 会相对合适,但是每个 API 模块需要使用到,所以暂时只好放在此处 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public class RpcConstants { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * RPC API 的前缀 | ||
| 14 | + */ | ||
| 15 | + public static final String RPC_API_PREFIX = "/rpc-api"; | ||
| 16 | + | ||
| 17 | +} |
yudao-module-iot/yudao-module-iot-api/pom.xml
| @@ -21,6 +21,14 @@ | @@ -21,6 +21,14 @@ | ||
| 21 | <groupId>cn.iocoder.boot</groupId> | 21 | <groupId>cn.iocoder.boot</groupId> |
| 22 | <artifactId>yudao-common</artifactId> | 22 | <artifactId>yudao-common</artifactId> |
| 23 | </dependency> | 23 | </dependency> |
| 24 | + | ||
| 25 | + <!-- Web 相关 --> | ||
| 26 | + <dependency> | ||
| 27 | + <groupId>org.springframework</groupId> | ||
| 28 | + <artifactId>spring-web</artifactId> | ||
| 29 | + <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> | ||
| 30 | + </dependency> | ||
| 31 | + | ||
| 24 | <!-- PF4J --> | 32 | <!-- PF4J --> |
| 25 | <!-- TODO 芋艿:这个依赖,要不要放在 api 包 --> | 33 | <!-- TODO 芋艿:这个依赖,要不要放在 api 包 --> |
| 26 | <dependency> | 34 | <dependency> |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/ServiceRegistry.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.api; | ||
| 2 | - | ||
| 3 | -import java.util.HashMap; | ||
| 4 | -import java.util.Map; | ||
| 5 | - | ||
| 6 | -// TODO 芋艿:纠结下 | ||
| 7 | -/** | ||
| 8 | - * 服务注册表 - 插架模块使用,无法使用 Spring 注入 | ||
| 9 | - */ | ||
| 10 | -public class ServiceRegistry { | ||
| 11 | - | ||
| 12 | - private static final Map<Class<?>, Object> services = new HashMap<>(); | ||
| 13 | - | ||
| 14 | - /** | ||
| 15 | - * 注册服务 | ||
| 16 | - * | ||
| 17 | - * @param serviceClass 服务类 | ||
| 18 | - * @param serviceImpl 服务实现 | ||
| 19 | - * @param <T> 服务类 | ||
| 20 | - */ | ||
| 21 | - public static <T> void registerService(Class<T> serviceClass, T serviceImpl) { | ||
| 22 | - services.put(serviceClass, serviceImpl); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * 获得服务 | ||
| 27 | - * | ||
| 28 | - * @param serviceClass 服务类 | ||
| 29 | - * @param <T> 服务类 | ||
| 30 | - * @return 服务实现 | ||
| 31 | - */ | ||
| 32 | - @SuppressWarnings("unchecked") | ||
| 33 | - public static <T> T getService(Class<T> serviceClass) { | ||
| 34 | - return (T) services.get(serviceClass); | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | -} | ||
| 38 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/DeviceDataApi.java
| 1 | package cn.iocoder.yudao.module.iot.api.device; | 1 | package cn.iocoder.yudao.module.iot.api.device; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceEventReportReqDTO; | ||
| 5 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStatusUpdateReqDTO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.enums.ApiConstants; | ||
| 8 | +import jakarta.annotation.security.PermitAll; | ||
| 4 | import jakarta.validation.Valid; | 9 | import jakarta.validation.Valid; |
| 10 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 11 | +import org.springframework.web.bind.annotation.PutMapping; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 5 | 13 | ||
| 14 | +// TODO 芋艿:名字可能看情况改下 | ||
| 6 | /** | 15 | /** |
| 7 | * 设备数据 API | 16 | * 设备数据 API |
| 8 | * | 17 | * |
| @@ -10,11 +19,35 @@ import jakarta.validation.Valid; | @@ -10,11 +19,35 @@ import jakarta.validation.Valid; | ||
| 10 | */ | 19 | */ |
| 11 | public interface DeviceDataApi { | 20 | public interface DeviceDataApi { |
| 12 | 21 | ||
| 22 | + // TODO @芋艿:可能会调整 | ||
| 23 | + String PREFIX = ApiConstants.PREFIX + "/device-data"; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 更新设备状态 | ||
| 27 | + * | ||
| 28 | + * @param updateReqDTO 更新请求 | ||
| 29 | + */ | ||
| 30 | + @PutMapping(PREFIX + "/update-status") | ||
| 31 | + @PermitAll // TODO 芋艿:后续看看怎么优化下 | ||
| 32 | + CommonResult<Boolean> updateDeviceStatus(@Valid @RequestBody IotDeviceStatusUpdateReqDTO updateReqDTO); | ||
| 33 | + | ||
| 13 | /** | 34 | /** |
| 14 | - * 保存设备数据 | 35 | + * 上报设备事件数据 |
| 15 | * | 36 | * |
| 16 | - * @param createDTO 设备数据 | 37 | + * @param reportReqDTO 设备事件 |
| 17 | */ | 38 | */ |
| 18 | - void saveDeviceData(@Valid DeviceDataCreateReqDTO createDTO); | 39 | + @PostMapping(PREFIX + "/report-event") |
| 40 | + @PermitAll // TODO 芋艿:后续看看怎么优化下 | ||
| 41 | + CommonResult<Boolean> reportDeviceEventData(@Valid @RequestBody IotDeviceEventReportReqDTO reportReqDTO); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 上报设备属性数据 | ||
| 45 | + * | ||
| 46 | + * @param reportReqDTO 设备数据 | ||
| 47 | + */ | ||
| 48 | + @PostMapping(PREFIX + "/report-property") | ||
| 49 | + @PermitAll // TODO 芋艿:后续看看怎么优化下 | ||
| 50 | + CommonResult<Boolean> reportDevicePropertyData(@Valid @RequestBody IotDevicePropertyReportReqDTO reportReqDTO); | ||
| 51 | + | ||
| 19 | 52 | ||
| 20 | } | 53 | } |
| 21 | \ No newline at end of file | 54 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/mqttrpc/common/RpcRequest.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/IotDeviceEventReportReqDTO.java
| 1 | -package cn.iocoder.yudao.module.iot.mqttrpc.common; | 1 | +package cn.iocoder.yudao.module.iot.api.device.dto; |
| 2 | 2 | ||
| 3 | +import jakarta.validation.constraints.NotEmpty; | ||
| 3 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Builder; | 5 | import lombok.Builder; |
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import lombok.NoArgsConstructor; | 7 | import lombok.NoArgsConstructor; |
| 7 | 8 | ||
| 8 | -// TODO @芋艿:要不要加个 mqtt 值了的前缀 | 9 | +import java.util.Map; |
| 10 | + | ||
| 9 | /** | 11 | /** |
| 10 | - * MQTT RPC 请求 | 12 | + * IoT 设备【事件】数据上报 Request DTO |
| 11 | */ | 13 | */ |
| 12 | @Data | 14 | @Data |
| 13 | -@Builder | ||
| 14 | @NoArgsConstructor | 15 | @NoArgsConstructor |
| 15 | @AllArgsConstructor | 16 | @AllArgsConstructor |
| 16 | -public class RpcRequest { | 17 | +@Builder |
| 18 | +public class IotDeviceEventReportReqDTO { | ||
| 19 | + | ||
| 20 | + // TODO 芋艿:要不要 id | ||
| 21 | + // TODO 芋艿:要不要 time | ||
| 17 | 22 | ||
| 18 | /** | 23 | /** |
| 19 | - * 方法名 | 24 | + * 产品标识 |
| 20 | */ | 25 | */ |
| 21 | - private String method; | ||
| 22 | - | 26 | + @NotEmpty(message = "产品标识不能为空") |
| 27 | + private String productKey; | ||
| 23 | /** | 28 | /** |
| 24 | - * 参数 | 29 | + * 设备名称 |
| 25 | */ | 30 | */ |
| 26 | - // TODO @haohao:object 对象会不会不好序列化? | ||
| 27 | - private Object[] params; | 31 | + @NotEmpty(message = "设备名称不能为空") |
| 32 | + private String deviceName; | ||
| 28 | 33 | ||
| 29 | /** | 34 | /** |
| 30 | - * 关联 ID | 35 | + * 事件标识 |
| 31 | */ | 36 | */ |
| 32 | - private String correlationId; | ||
| 33 | - | 37 | + @NotEmpty(message = "事件标识不能为空") |
| 38 | + private String identifier; | ||
| 34 | /** | 39 | /** |
| 35 | - * 回复地址 | 40 | + * 事件参数 |
| 36 | */ | 41 | */ |
| 37 | - private String replyTo; | 42 | + @NotEmpty(message = "事件参数不能为空") |
| 43 | + private Map<String, Object> params; | ||
| 38 | 44 | ||
| 39 | } | 45 | } |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/DeviceDataCreateReqDTO.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/IotDevicePropertyReportReqDTO.java
| 1 | package cn.iocoder.yudao.module.iot.api.device.dto; | 1 | package cn.iocoder.yudao.module.iot.api.device.dto; |
| 2 | 2 | ||
| 3 | +import jakarta.validation.constraints.NotEmpty; | ||
| 3 | import lombok.AllArgsConstructor; | 4 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Builder; | 5 | import lombok.Builder; |
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | import lombok.NoArgsConstructor; | 7 | import lombok.NoArgsConstructor; |
| 7 | -import jakarta.validation.constraints.NotNull; | ||
| 8 | 8 | ||
| 9 | +import java.util.Map; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * IoT 设备【属性】数据上报 Request DTO | ||
| 13 | + */ | ||
| 9 | @Data | 14 | @Data |
| 10 | @NoArgsConstructor | 15 | @NoArgsConstructor |
| 11 | @AllArgsConstructor | 16 | @AllArgsConstructor |
| 12 | @Builder | 17 | @Builder |
| 13 | -public class DeviceDataCreateReqDTO { | 18 | +public class IotDevicePropertyReportReqDTO { |
| 19 | + | ||
| 20 | + // TODO 芋艿:要不要 id | ||
| 21 | + // TODO 芋艿:要不要 time | ||
| 14 | 22 | ||
| 15 | /** | 23 | /** |
| 16 | * 产品标识 | 24 | * 产品标识 |
| 17 | */ | 25 | */ |
| 18 | - @NotNull(message = "产品标识不能为空") | 26 | + @NotEmpty(message = "产品标识不能为空") |
| 19 | private String productKey; | 27 | private String productKey; |
| 20 | /** | 28 | /** |
| 21 | * 设备名称 | 29 | * 设备名称 |
| 22 | */ | 30 | */ |
| 23 | - @NotNull(message = "设备名称不能为空") | 31 | + @NotEmpty(message = "设备名称不能为空") |
| 24 | private String deviceName; | 32 | private String deviceName; |
| 25 | /** | 33 | /** |
| 26 | - * 消息 | 34 | + * 属性参数 |
| 27 | */ | 35 | */ |
| 28 | - @NotNull(message = "消息不能为空") | ||
| 29 | - private String message; | 36 | + @NotEmpty(message = "属性参数不能为空") |
| 37 | + private Map<String, Object> params; | ||
| 30 | 38 | ||
| 31 | } | 39 | } |
| 32 | \ No newline at end of file | 40 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/mqttrpc/common/RpcResponse.java renamed to yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/device/dto/IotDeviceStatusUpdateReqDTO.java
| 1 | -package cn.iocoder.yudao.module.iot.mqttrpc.common; | 1 | +package cn.iocoder.yudao.module.iot.api.device.dto; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | +import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum; | ||
| 5 | +import jakarta.validation.constraints.NotEmpty; | ||
| 3 | import lombok.AllArgsConstructor; | 6 | import lombok.AllArgsConstructor; |
| 4 | import lombok.Builder; | 7 | import lombok.Builder; |
| 5 | import lombok.Data; | 8 | import lombok.Data; |
| 6 | import lombok.NoArgsConstructor; | 9 | import lombok.NoArgsConstructor; |
| 7 | 10 | ||
| 8 | /** | 11 | /** |
| 9 | - * MQTT RPC 响应 | 12 | + * IoT 设备状态更新 Request DTO |
| 10 | */ | 13 | */ |
| 11 | @Data | 14 | @Data |
| 12 | -@Builder | ||
| 13 | @NoArgsConstructor | 15 | @NoArgsConstructor |
| 14 | @AllArgsConstructor | 16 | @AllArgsConstructor |
| 15 | -public class RpcResponse { | 17 | +@Builder |
| 18 | +public class IotDeviceStatusUpdateReqDTO { | ||
| 19 | + | ||
| 20 | + // TODO 芋艿:要不要 id | ||
| 21 | + // TODO 芋艿:要不要 time | ||
| 16 | 22 | ||
| 17 | /** | 23 | /** |
| 18 | - * 关联 ID | 24 | + * 产品标识 |
| 19 | */ | 25 | */ |
| 20 | - private String correlationId; | ||
| 21 | - | 26 | + @NotEmpty(message = "产品标识不能为空") |
| 27 | + private String productKey; | ||
| 22 | /** | 28 | /** |
| 23 | - * 结果 | 29 | + * 设备名称 |
| 24 | */ | 30 | */ |
| 25 | - // TODO @haohao:object 对象会不会不好反序列化? | ||
| 26 | - private Object result; | ||
| 27 | - | 31 | + @NotEmpty(message = "设备名称不能为空") |
| 32 | + private String deviceName; | ||
| 28 | /** | 33 | /** |
| 29 | - * 错误 | 34 | + * 设备状态 |
| 30 | */ | 35 | */ |
| 31 | - private String error; | 36 | + @NotEmpty(message = "设备状态不能为空") |
| 37 | + @InEnum(IotDeviceStatusEnum.class) // 只使用:在线、离线 | ||
| 38 | + private Integer status; | ||
| 32 | 39 | ||
| 33 | } | 40 | } |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ApiConstants.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.enums; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.RpcConstants; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * API 相关的枚举 | ||
| 7 | + * | ||
| 8 | + * @author 芋道源码 | ||
| 9 | + */ | ||
| 10 | +public class ApiConstants { | ||
| 11 | + | ||
| 12 | + public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/iot"; | ||
| 13 | + | ||
| 14 | + public static final String VERSION = "1.0.0"; | ||
| 15 | + | ||
| 16 | +} |
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/mqttrpc/common/SerializationUtils.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.mqttrpc.common; | ||
| 2 | - | ||
| 3 | -import cn.hutool.json.JSONUtil; | ||
| 4 | - | ||
| 5 | -/** | ||
| 6 | - * 序列化工具类 | ||
| 7 | - * | ||
| 8 | - */ | ||
| 9 | -public class SerializationUtils { | ||
| 10 | - | ||
| 11 | - public static String serialize(Object obj) { | ||
| 12 | - return JSONUtil.toJsonStr(obj); | ||
| 13 | - } | ||
| 14 | - | ||
| 15 | - public static <T> T deserialize(String json, Class<T> clazz) { | ||
| 16 | - return JSONUtil.toBean(json, clazz); | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | -} | ||
| 20 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/api/device/DeviceDataApiImpl.java
| 1 | package cn.iocoder.yudao.module.iot.api.device; | 1 | package cn.iocoder.yudao.module.iot.api.device; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceEventReportReqDTO; | ||
| 5 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStatusUpdateReqDTO; | ||
| 4 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; | 7 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; |
| 5 | -import org.springframework.stereotype.Service; | ||
| 6 | import org.springframework.validation.annotation.Validated; | 8 | import org.springframework.validation.annotation.Validated; |
| 9 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | 10 | ||
| 8 | import javax.annotation.Resource; | 11 | import javax.annotation.Resource; |
| 9 | 12 | ||
| 13 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 14 | + | ||
| 10 | /** | 15 | /** |
| 11 | * 设备数据 API 实现类 | 16 | * 设备数据 API 实现类 |
| 12 | */ | 17 | */ |
| 13 | -@Service | 18 | +@RestController |
| 14 | @Validated | 19 | @Validated |
| 15 | public class DeviceDataApiImpl implements DeviceDataApi { | 20 | public class DeviceDataApiImpl implements DeviceDataApi { |
| 16 | 21 | ||
| @@ -18,8 +23,19 @@ public class DeviceDataApiImpl implements DeviceDataApi { | @@ -18,8 +23,19 @@ public class DeviceDataApiImpl implements DeviceDataApi { | ||
| 18 | private IotDevicePropertyDataService deviceDataService; | 23 | private IotDevicePropertyDataService deviceDataService; |
| 19 | 24 | ||
| 20 | @Override | 25 | @Override |
| 21 | - public void saveDeviceData(DeviceDataCreateReqDTO createDTO) { | ||
| 22 | - deviceDataService.saveDeviceData(createDTO); | 26 | + public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) { |
| 27 | + return success(true); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) { | ||
| 32 | + return success(true); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) { | ||
| 37 | + deviceDataService.saveDeviceData(reportReqDTO); | ||
| 38 | + return success(true); | ||
| 23 | } | 39 | } |
| 24 | 40 | ||
| 25 | } | 41 | } |
| 26 | \ No newline at end of file | 42 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/service/EmqxServiceImpl.java
| 1 | package cn.iocoder.yudao.module.iot.emq.service; | 1 | package cn.iocoder.yudao.module.iot.emq.service; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 3 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 4 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; | 4 | import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; |
| 5 | import jakarta.annotation.Resource; | 5 | import jakarta.annotation.Resource; |
| 6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| @@ -34,10 +34,10 @@ public class EmqxServiceImpl implements EmqxService { | @@ -34,10 +34,10 @@ public class EmqxServiceImpl implements EmqxService { | ||
| 34 | String productKey = topic.split("/")[2]; | 34 | String productKey = topic.split("/")[2]; |
| 35 | String deviceName = topic.split("/")[3]; | 35 | String deviceName = topic.split("/")[3]; |
| 36 | String message = new String(mqttMessage.getPayload()); | 36 | String message = new String(mqttMessage.getPayload()); |
| 37 | - DeviceDataCreateReqDTO createDTO = DeviceDataCreateReqDTO.builder() | 37 | + IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder() |
| 38 | .productKey(productKey) | 38 | .productKey(productKey) |
| 39 | .deviceName(deviceName) | 39 | .deviceName(deviceName) |
| 40 | - .message(message) | 40 | +// .properties(message) // TODO 芋艿:临时去掉,看看 |
| 41 | .build(); | 41 | .build(); |
| 42 | iotDeviceDataService.saveDeviceData(createDTO); | 42 | iotDeviceDataService.saveDeviceData(createDTO); |
| 43 | } | 43 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/PluginStart.java
| 1 | package cn.iocoder.yudao.module.iot.framework.plugin; | 1 | package cn.iocoder.yudao.module.iot.framework.plugin; |
| 2 | 2 | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | -import javax.annotation.Resource; | ||
| 6 | - | 3 | +import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | ||
| 5 | +import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; | ||
| 7 | +import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 7 | import org.pf4j.spring.SpringPluginManager; | 9 | import org.pf4j.spring.SpringPluginManager; |
| 8 | import org.springframework.boot.ApplicationArguments; | 10 | import org.springframework.boot.ApplicationArguments; |
| 9 | import org.springframework.boot.ApplicationRunner; | 11 | import org.springframework.boot.ApplicationRunner; |
| 10 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
| 11 | 13 | ||
| 12 | -import lombok.extern.slf4j.Slf4j; | ||
| 13 | - | ||
| 14 | -import cn.iocoder.yudao.module.iot.service.plugin.PluginInfoService; | ||
| 15 | -import cn.hutool.core.collection.CollUtil; | ||
| 16 | -import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | ||
| 17 | -import cn.iocoder.yudao.module.iot.dal.dataobject.plugininfo.PluginInfoDO; | ||
| 18 | -import cn.iocoder.yudao.module.iot.enums.plugin.IotPluginStatusEnum; | 14 | +import javax.annotation.Resource; |
| 15 | +import java.util.List; | ||
| 19 | 16 | ||
| 17 | +// TODO @芋艿:需要 review 下 | ||
| 20 | @Component | 18 | @Component |
| 21 | @Slf4j | 19 | @Slf4j |
| 22 | public class PluginStart implements ApplicationRunner { | 20 | public class PluginStart implements ApplicationRunner { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/UnifiedConfiguration.java
| 1 | package cn.iocoder.yudao.module.iot.framework.plugin; | 1 | package cn.iocoder.yudao.module.iot.framework.plugin; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.ServiceRegistry; | ||
| 4 | -import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; | ||
| 5 | import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener; | 3 | import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener; |
| 6 | import lombok.extern.slf4j.Slf4j; | 4 | import lombok.extern.slf4j.Slf4j; |
| 7 | import org.pf4j.spring.SpringPluginManager; | 5 | import org.pf4j.spring.SpringPluginManager; |
| 6 | +import org.springframework.beans.factory.annotation.Value; | ||
| 8 | import org.springframework.context.annotation.Bean; | 7 | import org.springframework.context.annotation.Bean; |
| 9 | import org.springframework.context.annotation.Configuration; | 8 | import org.springframework.context.annotation.Configuration; |
| 10 | -import org.springframework.context.annotation.DependsOn; | ||
| 11 | - | ||
| 12 | -import javax.annotation.Resource; | ||
| 13 | 9 | ||
| 10 | +// TODO @芋艿:需要 review 下 | ||
| 14 | @Slf4j | 11 | @Slf4j |
| 15 | @Configuration | 12 | @Configuration |
| 16 | public class UnifiedConfiguration { | 13 | public class UnifiedConfiguration { |
| 17 | 14 | ||
| 18 | - private static final String SERVICE_REGISTRY_INITIALIZED_MARKER = "serviceRegistryInitializedMarker"; | ||
| 19 | - | ||
| 20 | - @Resource | ||
| 21 | - private DeviceDataApi deviceDataApi; | ||
| 22 | - | ||
| 23 | - @Bean(SERVICE_REGISTRY_INITIALIZED_MARKER) | ||
| 24 | - public Object serviceRegistryInitializedMarker() { | ||
| 25 | - ServiceRegistry.registerService(DeviceDataApi.class, deviceDataApi); | ||
| 26 | - log.info("[init][将 DeviceDataApi 实例注册到 ServiceRegistry 中]"); | ||
| 27 | - return new Object(); | ||
| 28 | - } | 15 | + @Value("${pf4j.pluginsDir:pluginsDir}") |
| 16 | + private String pluginsDir; | ||
| 29 | 17 | ||
| 30 | @Bean | 18 | @Bean |
| 31 | - @DependsOn(SERVICE_REGISTRY_INITIALIZED_MARKER) | 19 | +// @DependsOn("deviceDataApiImpl") |
| 32 | public SpringPluginManager pluginManager() { | 20 | public SpringPluginManager pluginManager() { |
| 33 | log.info("[init][实例化 SpringPluginManager]"); | 21 | log.info("[init][实例化 SpringPluginManager]"); |
| 22 | +// SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) { | ||
| 34 | SpringPluginManager springPluginManager = new SpringPluginManager() { | 23 | SpringPluginManager springPluginManager = new SpringPluginManager() { |
| 24 | + | ||
| 35 | @Override | 25 | @Override |
| 36 | public void startPlugins() { | 26 | public void startPlugins() { |
| 37 | // 禁用插件启动,避免插件启动时,启动所有插件 | 27 | // 禁用插件启动,避免插件启动时,启动所有插件 |
| 38 | log.info("[init][禁用默认启动所有插件]"); | 28 | log.info("[init][禁用默认启动所有插件]"); |
| 39 | } | 29 | } |
| 30 | + | ||
| 40 | }; | 31 | }; |
| 41 | springPluginManager.addPluginStateListener(new CustomPluginStateListener()); | 32 | springPluginManager.addPluginStateListener(new CustomPluginStateListener()); |
| 42 | return springPluginManager; | 33 | return springPluginManager; |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/listener/CustomPluginStateListener.java
| @@ -5,6 +5,7 @@ import org.pf4j.PluginStateEvent; | @@ -5,6 +5,7 @@ import org.pf4j.PluginStateEvent; | ||
| 5 | import org.pf4j.PluginStateListener; | 5 | import org.pf4j.PluginStateListener; |
| 6 | import org.springframework.stereotype.Component; | 6 | import org.springframework.stereotype.Component; |
| 7 | 7 | ||
| 8 | +// TODO @芋艿:需要 review 下 | ||
| 8 | @Component | 9 | @Component |
| 9 | @Slf4j | 10 | @Slf4j |
| 10 | public class CustomPluginStateListener implements PluginStateListener { | 11 | public class CustomPluginStateListener implements PluginStateListener { |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataService.java
| 1 | package cn.iocoder.yudao.module.iot.service.device; | 1 | package cn.iocoder.yudao.module.iot.service.device; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 4 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; |
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; |
| 7 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| @@ -28,7 +28,7 @@ public interface IotDevicePropertyDataService { | @@ -28,7 +28,7 @@ public interface IotDevicePropertyDataService { | ||
| 28 | * | 28 | * |
| 29 | * @param createDTO 设备数据 | 29 | * @param createDTO 设备数据 |
| 30 | */ | 30 | */ |
| 31 | - void saveDeviceData(DeviceDataCreateReqDTO createDTO); | 31 | + void saveDeviceData(IotDevicePropertyReportReqDTO createDTO); |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | * 获得设备属性最新数据 | 34 | * 获得设备属性最新数据 |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataServiceImpl.java
| @@ -6,7 +6,7 @@ import cn.hutool.core.map.MapUtil; | @@ -6,7 +6,7 @@ import cn.hutool.core.map.MapUtil; | ||
| 6 | import cn.hutool.core.util.StrUtil; | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | import cn.hutool.json.JSONObject; | 7 | import cn.hutool.json.JSONObject; |
| 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 9 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; | 10 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; |
| 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; | 11 | import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDateOrTextDataSpecs; |
| 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; | 12 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; |
| @@ -130,11 +130,12 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | @@ -130,11 +130,12 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | ||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | @Override | 132 | @Override |
| 133 | - public void saveDeviceData(DeviceDataCreateReqDTO createDTO) { | 133 | + public void saveDeviceData(IotDevicePropertyReportReqDTO createDTO) { |
| 134 | + // TODO 芋艿:这块需要实现 | ||
| 134 | // 1. 根据产品 key 和设备名称,获得设备信息 | 135 | // 1. 根据产品 key 和设备名称,获得设备信息 |
| 135 | IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceName(createDTO.getProductKey(), createDTO.getDeviceName()); | 136 | IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceName(createDTO.getProductKey(), createDTO.getDeviceName()); |
| 136 | // 2. 解析消息,保存数据 | 137 | // 2. 解析消息,保存数据 |
| 137 | - JSONObject jsonObject = new JSONObject(createDTO.getMessage()); | 138 | + JSONObject jsonObject = new JSONObject(createDTO.getParams()); |
| 138 | log.info("[saveDeviceData][productKey({}) deviceName({}) data({})]", createDTO.getProductKey(), createDTO.getDeviceName(), jsonObject); | 139 | log.info("[saveDeviceData][productKey({}) deviceName({}) data({})]", createDTO.getProductKey(), createDTO.getDeviceName(), jsonObject); |
| 139 | ThingModelMessage thingModelMessage = ThingModelMessage.builder() | 140 | ThingModelMessage thingModelMessage = ThingModelMessage.builder() |
| 140 | .id(jsonObject.getStr("id")) | 141 | .id(jsonObject.getStr("id")) |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/ExampleService.java deleted
| 1 | -//package cn.iocoder.yudao.module.iot.service.plugin; | ||
| 2 | -// | ||
| 3 | -//import cn.iocoder.yudao.module.iot.mqttrpc.server.RpcServer; | ||
| 4 | -//import lombok.RequiredArgsConstructor; | ||
| 5 | -//import org.springframework.stereotype.Service; | ||
| 6 | -// | ||
| 7 | -//import javax.annotation.PostConstruct; | ||
| 8 | -// | ||
| 9 | -//@Service | ||
| 10 | -//@RequiredArgsConstructor | ||
| 11 | -//public class ExampleService { | ||
| 12 | -// | ||
| 13 | -// private final RpcServer rpcServer; | ||
| 14 | -// | ||
| 15 | -// @PostConstruct | ||
| 16 | -// public void registerMethods() { | ||
| 17 | -// rpcServer.registerMethod("add", params -> { | ||
| 18 | -// if (params.length != 2) { | ||
| 19 | -// throw new IllegalArgumentException("add方法需要两个参数"); | ||
| 20 | -// } | ||
| 21 | -// int a = ((Number) params[0]).intValue(); | ||
| 22 | -// int b = ((Number) params[1]).intValue(); | ||
| 23 | -// return add(a, b); | ||
| 24 | -// }); | ||
| 25 | -// | ||
| 26 | -// rpcServer.registerMethod("concat", params -> { | ||
| 27 | -// if (params.length != 2) { | ||
| 28 | -// throw new IllegalArgumentException("concat方法需要两个参数"); | ||
| 29 | -// } | ||
| 30 | -// String str1 = params[0].toString(); | ||
| 31 | -// String str2 = params[1].toString(); | ||
| 32 | -// return concat(str1, str2); | ||
| 33 | -// }); | ||
| 34 | -// } | ||
| 35 | -// | ||
| 36 | -// private int add(int a, int b) { | ||
| 37 | -// return a + b; | ||
| 38 | -// } | ||
| 39 | -// | ||
| 40 | -// private String concat(String a, String b) { | ||
| 41 | -// return a + b; | ||
| 42 | -// } | ||
| 43 | -//} | ||
| 44 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugin/pom.xml
| @@ -8,9 +8,9 @@ | @@ -8,9 +8,9 @@ | ||
| 8 | <version>${revision}</version> | 8 | <version>${revision}</version> |
| 9 | </parent> | 9 | </parent> |
| 10 | <modules> | 10 | <modules> |
| 11 | - <module>yudao-module-iot-demo-plugin</module> | ||
| 12 | - <module>yudao-module-iot-http-plugin</module> | ||
| 13 | - <module>yudao-module-iot-mqtt-plugin</module> | 11 | + <module>yudao-module-iot-plugin-http</module> |
| 12 | + <module>yudao-module-iot-plugin-mqtt</module> | ||
| 13 | + <module>yudao-module-iot-plugin-emqx</module> | ||
| 14 | </modules> | 14 | </modules> |
| 15 | 15 | ||
| 16 | <modelVersion>4.0.0</modelVersion> | 16 | <modelVersion>4.0.0</modelVersion> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-demo-plugin/plugin.properties deleted
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-demo-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/DemoPlugin.java deleted
| 1 | -package cn.iocoder.yudao.module.iot.plugin; | ||
| 2 | - | ||
| 3 | -import com.sun.net.httpserver.HttpServer; | ||
| 4 | -import lombok.extern.slf4j.Slf4j; | ||
| 5 | -import org.pf4j.Plugin; | ||
| 6 | -import org.pf4j.PluginWrapper; | ||
| 7 | -import org.pf4j.RuntimeMode; | ||
| 8 | - | ||
| 9 | -import java.io.IOException; | ||
| 10 | -import java.io.OutputStream; | ||
| 11 | -import java.net.InetSocketAddress; | ||
| 12 | - | ||
| 13 | -/** | ||
| 14 | - * 一个启动 HTTP 服务器的简单插件。 | ||
| 15 | - */ | ||
| 16 | -@Slf4j | ||
| 17 | -public class DemoPlugin extends Plugin { | ||
| 18 | - | ||
| 19 | - private HttpServer server; | ||
| 20 | - | ||
| 21 | - public DemoPlugin(PluginWrapper wrapper) { | ||
| 22 | - super(wrapper); | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - @Override | ||
| 26 | - public void start() { | ||
| 27 | - log.info("Demo 插件启动"); | ||
| 28 | - // for testing the development mode | ||
| 29 | - if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) { | ||
| 30 | - log.info("DemoPlugin in DEVELOPMENT mode"); | ||
| 31 | - } | ||
| 32 | - startDemoServer(); | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - @Override | ||
| 36 | - public void stop() { | ||
| 37 | - log.info("Demo 插件停止"); | ||
| 38 | - stopDemoServer(); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - private void startDemoServer() { | ||
| 42 | - try { | ||
| 43 | - server = HttpServer.create(new InetSocketAddress(9081), 0); | ||
| 44 | - server.createContext("/", exchange -> { | ||
| 45 | - String response = "Hello from DemoPlugin"; | ||
| 46 | - exchange.sendResponseHeaders(200, response.getBytes().length); | ||
| 47 | - OutputStream os = exchange.getResponseBody(); | ||
| 48 | - os.write(response.getBytes()); | ||
| 49 | - os.close(); | ||
| 50 | - }); | ||
| 51 | - server.setExecutor(null); | ||
| 52 | - server.start(); | ||
| 53 | - log.info("HTTP 服务器启动成功,端口为 9081"); | ||
| 54 | - log.info("访问地址为 http://127.0.0.1:9081/"); | ||
| 55 | - } catch (IOException e) { | ||
| 56 | - log.error("HTTP 服务器启动失败", e); | ||
| 57 | - } | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - private void stopDemoServer() { | ||
| 61 | - if (server != null) { | ||
| 62 | - server.stop(0); | ||
| 63 | - log.info("HTTP 服务器停止成功"); | ||
| 64 | - } | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | -// @Extension | ||
| 68 | -// public static class WelcomeGreeting implements Greeting { | ||
| 69 | -// | ||
| 70 | -// @Override | ||
| 71 | -// public String getGreeting() { | ||
| 72 | -// return "Welcome to DemoPlugin"; | ||
| 73 | -// } | ||
| 74 | -// | ||
| 75 | -// } | ||
| 76 | - | ||
| 77 | -} | ||
| 78 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/plugin.properties deleted
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/pom.xml deleted
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 3 | - xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation=" | ||
| 4 | - http://maven.apache.org/POM/4.0.0 | ||
| 5 | - http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 6 | - <parent> | ||
| 7 | - <artifactId>yudao-module-iot-plugin</artifactId> | ||
| 8 | - <groupId>cn.iocoder.boot</groupId> | ||
| 9 | - <version>${revision}</version> | ||
| 10 | - </parent> | ||
| 11 | - <modelVersion>4.0.0</modelVersion> | ||
| 12 | - <packaging>jar</packaging> | ||
| 13 | - | ||
| 14 | - <artifactId>yudao-module-iot-http-plugin</artifactId> | ||
| 15 | - | ||
| 16 | - <name>${project.artifactId}</name> | ||
| 17 | - <description> | ||
| 18 | - 物联网 插件模块 - http 插件 | ||
| 19 | - </description> | ||
| 20 | - | ||
| 21 | - <properties> | ||
| 22 | - <!-- 插件相关 --> | ||
| 23 | - <plugin.id>http-plugin</plugin.id> | ||
| 24 | - <plugin.class>cn.iocoder.yudao.module.iot.plugin.HttpVertxPlugin</plugin.class> | ||
| 25 | - <plugin.version>0.0.1</plugin.version> | ||
| 26 | - <plugin.provider>ahh</plugin.provider> | ||
| 27 | - <plugin.description>http-plugin-0.0.1</plugin.description> | ||
| 28 | - <plugin.dependencies/> | ||
| 29 | - </properties> | ||
| 30 | - | ||
| 31 | - <build> | ||
| 32 | - <plugins> | ||
| 33 | - <plugin> | ||
| 34 | - <groupId>org.apache.maven.plugins</groupId> | ||
| 35 | - <artifactId>maven-antrun-plugin</artifactId> | ||
| 36 | - <version>1.6</version> | ||
| 37 | - <executions> | ||
| 38 | - <execution> | ||
| 39 | - <id>unzip jar file</id> | ||
| 40 | - <phase>package</phase> | ||
| 41 | - <configuration> | ||
| 42 | - <target> | ||
| 43 | - <unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" | ||
| 44 | - dest="target/plugin-classes"/> | ||
| 45 | - </target> | ||
| 46 | - </configuration> | ||
| 47 | - <goals> | ||
| 48 | - <goal>run</goal> | ||
| 49 | - </goals> | ||
| 50 | - </execution> | ||
| 51 | - </executions> | ||
| 52 | - </plugin> | ||
| 53 | - | ||
| 54 | - <plugin> | ||
| 55 | - <artifactId>maven-assembly-plugin</artifactId> | ||
| 56 | - <version>2.3</version> | ||
| 57 | - <configuration> | ||
| 58 | - <descriptors> | ||
| 59 | - <descriptor> | ||
| 60 | - src/main/assembly/assembly.xml | ||
| 61 | - </descriptor> | ||
| 62 | - </descriptors> | ||
| 63 | - <appendAssemblyId>false</appendAssemblyId> | ||
| 64 | - </configuration> | ||
| 65 | - <executions> | ||
| 66 | - <execution> | ||
| 67 | - <id>make-assembly</id> | ||
| 68 | - <phase>package</phase> | ||
| 69 | - <goals> | ||
| 70 | - <goal>attached</goal> | ||
| 71 | - </goals> | ||
| 72 | - </execution> | ||
| 73 | - </executions> | ||
| 74 | - </plugin> | ||
| 75 | - | ||
| 76 | - <plugin> | ||
| 77 | - <groupId>org.apache.maven.plugins</groupId> | ||
| 78 | - <artifactId>maven-jar-plugin</artifactId> | ||
| 79 | - <version>2.4</version> | ||
| 80 | - <configuration> | ||
| 81 | - <archive> | ||
| 82 | - <manifestEntries> | ||
| 83 | - <Plugin-Id>${plugin.id}</Plugin-Id> | ||
| 84 | - <Plugin-Class>${plugin.class}</Plugin-Class> | ||
| 85 | - <Plugin-Version>${plugin.version}</Plugin-Version> | ||
| 86 | - <Plugin-Provider>${plugin.provider}</Plugin-Provider> | ||
| 87 | - <Plugin-Description>${plugin.description}</Plugin-Description> | ||
| 88 | - <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> | ||
| 89 | - </manifestEntries> | ||
| 90 | - </archive> | ||
| 91 | - </configuration> | ||
| 92 | - </plugin> | ||
| 93 | - | ||
| 94 | - <plugin> | ||
| 95 | - <artifactId>maven-deploy-plugin</artifactId> | ||
| 96 | - <configuration> | ||
| 97 | - <skip>true</skip> | ||
| 98 | - </configuration> | ||
| 99 | - </plugin> | ||
| 100 | - | ||
| 101 | - <!-- <plugin>--> | ||
| 102 | - <!-- <groupId>org.apache.maven.plugins</groupId>--> | ||
| 103 | - <!-- <artifactId>maven-shade-plugin</artifactId>--> | ||
| 104 | - <!-- <version>3.4.1</version>--> | ||
| 105 | - <!-- <executions>--> | ||
| 106 | - <!-- <execution>--> | ||
| 107 | - <!-- <phase>package</phase>--> | ||
| 108 | - <!-- <goals>--> | ||
| 109 | - <!-- <goal>shade</goal>--> | ||
| 110 | - <!-- </goals>--> | ||
| 111 | - <!-- <configuration>--> | ||
| 112 | - <!-- <shadedArtifactAttached>true</shadedArtifactAttached>--> | ||
| 113 | - <!-- <shadedClassifierName>shaded</shadedClassifierName>--> | ||
| 114 | - <!-- <transformers>--> | ||
| 115 | - <!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">--> | ||
| 116 | - <!-- <mainClass>cn.iocoder.yudao.module.iot.HttpPluginSpringbootApplication</mainClass>--> | ||
| 117 | - <!-- </transformer>--> | ||
| 118 | - <!-- </transformers>--> | ||
| 119 | - <!-- </configuration>--> | ||
| 120 | - <!-- </execution>--> | ||
| 121 | - <!-- </executions>--> | ||
| 122 | - <!-- </plugin>--> | ||
| 123 | - </plugins> | ||
| 124 | - </build> | ||
| 125 | - | ||
| 126 | - <dependencies> | ||
| 127 | - <!-- 其他依赖项 --> | ||
| 128 | - <dependency> | ||
| 129 | - <groupId>org.springframework.boot</groupId> | ||
| 130 | - <artifactId>spring-boot-starter-web</artifactId> | ||
| 131 | - </dependency> | ||
| 132 | - <!-- PF4J Spring 集成 --> | ||
| 133 | - <dependency> | ||
| 134 | - <groupId>org.pf4j</groupId> | ||
| 135 | - <artifactId>pf4j-spring</artifactId> | ||
| 136 | - <scope>provided</scope> | ||
| 137 | - </dependency> | ||
| 138 | - <!-- 项目依赖 --> | ||
| 139 | - <dependency> | ||
| 140 | - <groupId>cn.iocoder.boot</groupId> | ||
| 141 | - <artifactId>yudao-module-iot-api</artifactId> | ||
| 142 | - <version>${revision}</version> | ||
| 143 | - </dependency> | ||
| 144 | - <dependency> | ||
| 145 | - <groupId>org.projectlombok</groupId> | ||
| 146 | - <artifactId>lombok</artifactId> | ||
| 147 | - <version>${lombok.version}</version> | ||
| 148 | - <scope>provided</scope> | ||
| 149 | - </dependency> | ||
| 150 | - <!-- Vert.x Web --> | ||
| 151 | - <dependency> | ||
| 152 | - <groupId>io.vertx</groupId> | ||
| 153 | - <artifactId>vertx-web</artifactId> | ||
| 154 | - <version>4.5.11</version> | ||
| 155 | - </dependency> | ||
| 156 | - </dependencies> | ||
| 157 | -</project> | ||
| 158 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/resources/application.yml deleted
| 1 | -server: | ||
| 2 | - port: 8092 | ||
| 3 | - | ||
| 4 | -spring: | ||
| 5 | - application: | ||
| 6 | - name: yudao-module-iot-http-plugin | ||
| 7 | - | ||
| 8 | -# MQTT-RPC 配置 | ||
| 9 | -mqtt: | ||
| 10 | - broker: tcp://chaojiniu.top:1883 | ||
| 11 | - username: haohao | ||
| 12 | - password: ahh@123456 | ||
| 13 | - clientId: mqtt-rpc-client-${random.int} | ||
| 14 | - requestTopic: rpc/request | ||
| 15 | - responseTopicPrefix: rpc/response/ |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-mqtt-plugin/src/main/assembly/assembly.xml deleted
| 1 | -<assembly> | ||
| 2 | - <id>plugin</id> | ||
| 3 | - <formats> | ||
| 4 | - <format>zip</format> | ||
| 5 | - </formats> | ||
| 6 | - <includeBaseDirectory>false</includeBaseDirectory> | ||
| 7 | - <dependencySets> | ||
| 8 | - <dependencySet> | ||
| 9 | - <useProjectArtifact>false</useProjectArtifact> | ||
| 10 | - <scope>runtime</scope> | ||
| 11 | - <outputDirectory>lib</outputDirectory> | ||
| 12 | - <includes> | ||
| 13 | - <include>*:jar:*</include> | ||
| 14 | - </includes> | ||
| 15 | - </dependencySet> | ||
| 16 | - </dependencySets> | ||
| 17 | - <!-- | ||
| 18 | - <fileSets> | ||
| 19 | - <fileSet> | ||
| 20 | - <directory>target/classes</directory> | ||
| 21 | - <outputDirectory>classes</outputDirectory> | ||
| 22 | - </fileSet> | ||
| 23 | - </fileSets> | ||
| 24 | - --> | ||
| 25 | - <fileSets> | ||
| 26 | - <fileSet> | ||
| 27 | - <directory>target/plugin-classes</directory> | ||
| 28 | - <outputDirectory>classes</outputDirectory> | ||
| 29 | - </fileSet> | ||
| 30 | - </fileSets> | ||
| 31 | -</assembly> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-emqx-plugin/plugin.properties renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-emqx/plugin.properties
| 1 | -plugin.id=emqx-plugin | 1 | +plugin.id=plugin-emqx |
| 2 | plugin.class=cn.iocoder.yudao.module.iot.plugin.EmqxPlugin | 2 | plugin.class=cn.iocoder.yudao.module.iot.plugin.EmqxPlugin |
| 3 | -plugin.version=0.0.1 | 3 | +plugin.version=1.0.0 |
| 4 | plugin.provider=ahh | 4 | plugin.provider=ahh |
| 5 | plugin.dependencies= | 5 | plugin.dependencies= |
| 6 | -plugin.description=emqx-plugin-0.0.1 | 6 | +plugin.description=plugin-emqx-1.0.0 |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-emqx-plugin/pom.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-emqx/pom.xml
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | <modelVersion>4.0.0</modelVersion> | 11 | <modelVersion>4.0.0</modelVersion> |
| 12 | <packaging>jar</packaging> | 12 | <packaging>jar</packaging> |
| 13 | 13 | ||
| 14 | - <artifactId>yudao-module-iot-emqx-plugin</artifactId> | 14 | + <artifactId>yudao-module-iot-plugin-emqx</artifactId> |
| 15 | 15 | ||
| 16 | <name>${project.artifactId}</name> | 16 | <name>${project.artifactId}</name> |
| 17 | <description> | 17 | <description> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-demo-plugin/src/main/assembly/assembly.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-emqx/src/main/assembly/assembly.xml
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-emqx-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/EmqxPlugin.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/EmqxPlugin.java
| 1 | package cn.iocoder.yudao.module.iot.plugin; | 1 | package cn.iocoder.yudao.module.iot.plugin; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.ServiceRegistry; | 3 | +import cn.hutool.extra.spring.SpringUtil; |
| 4 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; | 4 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; |
| 5 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 6 | import org.pf4j.Plugin; | 6 | import org.pf4j.Plugin; |
| 7 | import org.pf4j.PluginWrapper; | 7 | import org.pf4j.PluginWrapper; |
| 8 | 8 | ||
| 9 | -import javax.annotation.Resource; | ||
| 10 | import java.util.concurrent.ExecutorService; | 9 | import java.util.concurrent.ExecutorService; |
| 11 | import java.util.concurrent.Executors; | 10 | import java.util.concurrent.Executors; |
| 12 | 11 | ||
| @@ -14,8 +13,6 @@ import java.util.concurrent.Executors; | @@ -14,8 +13,6 @@ import java.util.concurrent.Executors; | ||
| 14 | public class EmqxPlugin extends Plugin { | 13 | public class EmqxPlugin extends Plugin { |
| 15 | 14 | ||
| 16 | private ExecutorService executorService; | 15 | private ExecutorService executorService; |
| 17 | - @Resource | ||
| 18 | - private DeviceDataApi deviceDataApi; | ||
| 19 | 16 | ||
| 20 | public EmqxPlugin(PluginWrapper wrapper) { | 17 | public EmqxPlugin(PluginWrapper wrapper) { |
| 21 | super(wrapper); | 18 | super(wrapper); |
| @@ -30,7 +27,7 @@ public class EmqxPlugin extends Plugin { | @@ -30,7 +27,7 @@ public class EmqxPlugin extends Plugin { | ||
| 30 | executorService = Executors.newSingleThreadExecutor(); | 27 | executorService = Executors.newSingleThreadExecutor(); |
| 31 | } | 28 | } |
| 32 | 29 | ||
| 33 | - deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class); | 30 | + DeviceDataApi deviceDataApi = SpringUtil.getBean(DeviceDataApi.class); |
| 34 | if (deviceDataApi == null) { | 31 | if (deviceDataApi == null) { |
| 35 | log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!"); | 32 | log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!"); |
| 36 | return; | 33 | return; |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/dependency-reduced-pom.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/dependency-reduced-pom.xml
| @@ -6,37 +6,15 @@ | @@ -6,37 +6,15 @@ | ||
| 6 | <version>2.2.0-snapshot</version> | 6 | <version>2.2.0-snapshot</version> |
| 7 | </parent> | 7 | </parent> |
| 8 | <modelVersion>4.0.0</modelVersion> | 8 | <modelVersion>4.0.0</modelVersion> |
| 9 | - <artifactId>yudao-module-iot-http-plugin</artifactId> | 9 | + <artifactId>yudao-module-iot-plugin-http</artifactId> |
| 10 | <name>${project.artifactId}</name> | 10 | <name>${project.artifactId}</name> |
| 11 | - <version>2.2.0-snapshot</version> | 11 | + <version>1.0.0</version> |
| 12 | <description>物联网 插件模块 - http 插件</description> | 12 | <description>物联网 插件模块 - http 插件</description> |
| 13 | <build> | 13 | <build> |
| 14 | <plugins> | 14 | <plugins> |
| 15 | <plugin> | 15 | <plugin> |
| 16 | - <artifactId>maven-jar-plugin</artifactId> | ||
| 17 | - <version>2.4</version> | ||
| 18 | - <configuration> | ||
| 19 | - <archive> | ||
| 20 | - <manifestEntries> | ||
| 21 | - <Plugin-Id>${plugin.id}</Plugin-Id> | ||
| 22 | - <Plugin-Class>${plugin.class}</Plugin-Class> | ||
| 23 | - <Plugin-Version>${plugin.version}</Plugin-Version> | ||
| 24 | - <Plugin-Provider>${plugin.provider}</Plugin-Provider> | ||
| 25 | - <Plugin-Description>${plugin.description}</Plugin-Description> | ||
| 26 | - <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> | ||
| 27 | - </manifestEntries> | ||
| 28 | - </archive> | ||
| 29 | - </configuration> | ||
| 30 | - </plugin> | ||
| 31 | - <plugin> | ||
| 32 | - <artifactId>maven-deploy-plugin</artifactId> | ||
| 33 | - <configuration> | ||
| 34 | - <skip>true</skip> | ||
| 35 | - </configuration> | ||
| 36 | - </plugin> | ||
| 37 | - <plugin> | ||
| 38 | <artifactId>maven-shade-plugin</artifactId> | 16 | <artifactId>maven-shade-plugin</artifactId> |
| 39 | - <version>3.4.1</version> | 17 | + <version>3.2.4</version> |
| 40 | <executions> | 18 | <executions> |
| 41 | <execution> | 19 | <execution> |
| 42 | <phase>package</phase> | 20 | <phase>package</phase> |
| @@ -44,11 +22,9 @@ | @@ -44,11 +22,9 @@ | ||
| 44 | <goal>shade</goal> | 22 | <goal>shade</goal> |
| 45 | </goals> | 23 | </goals> |
| 46 | <configuration> | 24 | <configuration> |
| 47 | - <shadedArtifactAttached>true</shadedArtifactAttached> | ||
| 48 | - <shadedClassifierName>shaded</shadedClassifierName> | ||
| 49 | <transformers> | 25 | <transformers> |
| 50 | <transformer> | 26 | <transformer> |
| 51 | - <mainClass>cn.iocoder.yudao.module.iot.HttpPluginSpringbootApplication</mainClass> | 27 | + <mainClass>com.example.HttpPluginSpringbootApplication</mainClass> |
| 52 | </transformer> | 28 | </transformer> |
| 53 | </transformers> | 29 | </transformers> |
| 54 | </configuration> | 30 | </configuration> |
| @@ -57,25 +33,11 @@ | @@ -57,25 +33,11 @@ | ||
| 57 | </plugin> | 33 | </plugin> |
| 58 | </plugins> | 34 | </plugins> |
| 59 | </build> | 35 | </build> |
| 60 | - <dependencies> | ||
| 61 | - <dependency> | ||
| 62 | - <groupId>org.pf4j</groupId> | ||
| 63 | - <artifactId>pf4j-spring</artifactId> | ||
| 64 | - <version>0.9.0</version> | ||
| 65 | - <scope>provided</scope> | ||
| 66 | - </dependency> | ||
| 67 | - <dependency> | ||
| 68 | - <groupId>org.projectlombok</groupId> | ||
| 69 | - <artifactId>lombok</artifactId> | ||
| 70 | - <version>1.18.34</version> | ||
| 71 | - <scope>provided</scope> | ||
| 72 | - </dependency> | ||
| 73 | - </dependencies> | ||
| 74 | <properties> | 36 | <properties> |
| 75 | - <plugin.class>cn.iocoder.yudao.module.iot.plugin.HttpVertxPlugin</plugin.class> | ||
| 76 | - <plugin.version>0.0.1</plugin.version> | ||
| 77 | - <plugin.id>http-plugin</plugin.id> | ||
| 78 | - <plugin.description>http-plugin-0.0.1</plugin.description> | ||
| 79 | - <plugin.provider>ahh</plugin.provider> | 37 | + <plugin.id>${project.artifactId}</plugin.id> |
| 38 | + <plugin.description>${project.artifactId}-${project.version}</plugin.description> | ||
| 39 | + <plugin.class>cn.iocoder.yudao.module.iot.config.HttpVertxPlugin</plugin.class> | ||
| 40 | + <plugin.version>${project.version}</plugin.version> | ||
| 41 | + <plugin.provider>yudao</plugin.provider> | ||
| 80 | </properties> | 42 | </properties> |
| 81 | </project> | 43 | </project> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/plugin.properties
0 → 100644
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-demo-plugin/pom.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/pom.xml
| @@ -11,45 +11,27 @@ | @@ -11,45 +11,27 @@ | ||
| 11 | <modelVersion>4.0.0</modelVersion> | 11 | <modelVersion>4.0.0</modelVersion> |
| 12 | <packaging>jar</packaging> | 12 | <packaging>jar</packaging> |
| 13 | 13 | ||
| 14 | - <artifactId>yudao-module-iot-demo-plugin</artifactId> | 14 | + <artifactId>yudao-module-iot-plugin-http</artifactId> |
| 15 | + <version>1.0.0</version> | ||
| 15 | 16 | ||
| 16 | <name>${project.artifactId}</name> | 17 | <name>${project.artifactId}</name> |
| 17 | <description> | 18 | <description> |
| 18 | - 物联网 插件模块 - demo 插件 | 19 | + 物联网 插件模块 - http 插件 |
| 19 | </description> | 20 | </description> |
| 20 | 21 | ||
| 21 | <properties> | 22 | <properties> |
| 22 | <!-- 插件相关 --> | 23 | <!-- 插件相关 --> |
| 23 | - <plugin.id>demo-plugin</plugin.id> | ||
| 24 | - <plugin.class>cn.iocoder.yudao.module.iot.plugin.DemoPlugin</plugin.class> | ||
| 25 | - <plugin.version>0.0.1</plugin.version> | ||
| 26 | - <plugin.provider>ahh</plugin.provider> | 24 | + <plugin.id>${project.artifactId}</plugin.id> |
| 25 | + <plugin.class>cn.iocoder.yudao.module.iot.config.HttpVertxPlugin</plugin.class> | ||
| 26 | + <plugin.version>${project.version}</plugin.version> | ||
| 27 | + <plugin.provider>yudao</plugin.provider> | ||
| 28 | + <plugin.description>${project.artifactId}-${project.version}</plugin.description> | ||
| 27 | <plugin.dependencies/> | 29 | <plugin.dependencies/> |
| 28 | </properties> | 30 | </properties> |
| 29 | 31 | ||
| 30 | <build> | 32 | <build> |
| 31 | <plugins> | 33 | <plugins> |
| 32 | - <!-- DOESN'T WORK WITH MAVEN 3 (I defined the plugin metadata in properties section) | ||
| 33 | - <plugin> | ||
| 34 | - <groupId>org.codehaus.mojo</groupId> | ||
| 35 | - <artifactId>properties-maven-plugin</artifactId> | ||
| 36 | - <version>1.0-alpha-2</version> | ||
| 37 | - <executions> | ||
| 38 | - <execution> | ||
| 39 | - <phase>initialize</phase> | ||
| 40 | - <goals> | ||
| 41 | - <goal>read-project-properties</goal> | ||
| 42 | - </goals> | ||
| 43 | - <configuration> | ||
| 44 | - <files> | ||
| 45 | - <file>plugin.properties</file> | ||
| 46 | - </files> | ||
| 47 | - </configuration> | ||
| 48 | - </execution> | ||
| 49 | - </executions> | ||
| 50 | - </plugin> | ||
| 51 | - --> | ||
| 52 | - | 34 | + <!-- 插件模式 zip --> |
| 53 | <plugin> | 35 | <plugin> |
| 54 | <groupId>org.apache.maven.plugins</groupId> | 36 | <groupId>org.apache.maven.plugins</groupId> |
| 55 | <artifactId>maven-antrun-plugin</artifactId> | 37 | <artifactId>maven-antrun-plugin</artifactId> |
| @@ -60,7 +42,8 @@ | @@ -60,7 +42,8 @@ | ||
| 60 | <phase>package</phase> | 42 | <phase>package</phase> |
| 61 | <configuration> | 43 | <configuration> |
| 62 | <target> | 44 | <target> |
| 63 | - <unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" dest="target/plugin-classes" /> | 45 | + <unzip src="target/${project.artifactId}-${project.version}.${project.packaging}" |
| 46 | + dest="target/plugin-classes"/> | ||
| 64 | </target> | 47 | </target> |
| 65 | </configuration> | 48 | </configuration> |
| 66 | <goals> | 49 | <goals> |
| @@ -92,6 +75,7 @@ | @@ -92,6 +75,7 @@ | ||
| 92 | </executions> | 75 | </executions> |
| 93 | </plugin> | 76 | </plugin> |
| 94 | 77 | ||
| 78 | + <!-- 插件模式 jar --> | ||
| 95 | <plugin> | 79 | <plugin> |
| 96 | <groupId>org.apache.maven.plugins</groupId> | 80 | <groupId>org.apache.maven.plugins</groupId> |
| 97 | <artifactId>maven-jar-plugin</artifactId> | 81 | <artifactId>maven-jar-plugin</artifactId> |
| @@ -103,12 +87,30 @@ | @@ -103,12 +87,30 @@ | ||
| 103 | <Plugin-Class>${plugin.class}</Plugin-Class> | 87 | <Plugin-Class>${plugin.class}</Plugin-Class> |
| 104 | <Plugin-Version>${plugin.version}</Plugin-Version> | 88 | <Plugin-Version>${plugin.version}</Plugin-Version> |
| 105 | <Plugin-Provider>${plugin.provider}</Plugin-Provider> | 89 | <Plugin-Provider>${plugin.provider}</Plugin-Provider> |
| 90 | + <Plugin-Description>${plugin.description}</Plugin-Description> | ||
| 106 | <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> | 91 | <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> |
| 107 | </manifestEntries> | 92 | </manifestEntries> |
| 108 | </archive> | 93 | </archive> |
| 109 | </configuration> | 94 | </configuration> |
| 110 | </plugin> | 95 | </plugin> |
| 111 | 96 | ||
| 97 | + <!-- 独立模式 --> | ||
| 98 | + <plugin> | ||
| 99 | + <groupId>org.springframework.boot</groupId> | ||
| 100 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
| 101 | + <version>${spring.boot.version}</version> | ||
| 102 | + <executions> | ||
| 103 | + <execution> | ||
| 104 | + <goals> | ||
| 105 | + <goal>repackage</goal> | ||
| 106 | + </goals> | ||
| 107 | + <configuration> | ||
| 108 | + <classifier>-standalone</classifier> | ||
| 109 | + </configuration> | ||
| 110 | + </execution> | ||
| 111 | + </executions> | ||
| 112 | + </plugin> | ||
| 113 | + | ||
| 112 | <plugin> | 114 | <plugin> |
| 113 | <artifactId>maven-deploy-plugin</artifactId> | 115 | <artifactId>maven-deploy-plugin</artifactId> |
| 114 | <configuration> | 116 | <configuration> |
| @@ -123,14 +125,11 @@ | @@ -123,14 +125,11 @@ | ||
| 123 | <dependency> | 125 | <dependency> |
| 124 | <groupId>org.springframework.boot</groupId> | 126 | <groupId>org.springframework.boot</groupId> |
| 125 | <artifactId>spring-boot-starter-web</artifactId> | 127 | <artifactId>spring-boot-starter-web</artifactId> |
| 126 | - <version>${spring.boot.version}</version> | ||
| 127 | - <scope>provided</scope> | ||
| 128 | </dependency> | 128 | </dependency> |
| 129 | <!-- PF4J Spring 集成 --> | 129 | <!-- PF4J Spring 集成 --> |
| 130 | <dependency> | 130 | <dependency> |
| 131 | <groupId>org.pf4j</groupId> | 131 | <groupId>org.pf4j</groupId> |
| 132 | <artifactId>pf4j-spring</artifactId> | 132 | <artifactId>pf4j-spring</artifactId> |
| 133 | - <scope>provided</scope> | ||
| 134 | </dependency> | 133 | </dependency> |
| 135 | <!-- 项目依赖 --> | 134 | <!-- 项目依赖 --> |
| 136 | <dependency> | 135 | <dependency> |
| @@ -141,8 +140,11 @@ | @@ -141,8 +140,11 @@ | ||
| 141 | <dependency> | 140 | <dependency> |
| 142 | <groupId>org.projectlombok</groupId> | 141 | <groupId>org.projectlombok</groupId> |
| 143 | <artifactId>lombok</artifactId> | 142 | <artifactId>lombok</artifactId> |
| 144 | - <version>${lombok.version}</version> | ||
| 145 | - <scope>provided</scope> | 143 | + </dependency> |
| 144 | + <!-- Vert.x Web --> | ||
| 145 | + <dependency> | ||
| 146 | + <groupId>io.vertx</groupId> | ||
| 147 | + <artifactId>vertx-web</artifactId> | ||
| 146 | </dependency> | 148 | </dependency> |
| 147 | </dependencies> | 149 | </dependencies> |
| 148 | </project> | 150 | </project> |
| 149 | \ No newline at end of file | 151 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/assembly/assembly.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/assembly/assembly.xml
| @@ -14,14 +14,7 @@ | @@ -14,14 +14,7 @@ | ||
| 14 | </includes> | 14 | </includes> |
| 15 | </dependencySet> | 15 | </dependencySet> |
| 16 | </dependencySets> | 16 | </dependencySets> |
| 17 | - <!-- | ||
| 18 | - <fileSets> | ||
| 19 | - <fileSet> | ||
| 20 | - <directory>target/classes</directory> | ||
| 21 | - <outputDirectory>classes</outputDirectory> | ||
| 22 | - </fileSet> | ||
| 23 | - </fileSets> | ||
| 24 | - --> | 17 | + |
| 25 | <fileSets> | 18 | <fileSets> |
| 26 | <fileSet> | 19 | <fileSet> |
| 27 | <directory>target/plugin-classes</directory> | 20 | <directory>target/plugin-classes</directory> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/HttpPluginSpringbootApplication.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/HttpPluginSpringbootApplication.java
| 1 | package cn.iocoder.yudao.module.iot; | 1 | package cn.iocoder.yudao.module.iot; |
| 2 | 2 | ||
| 3 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
| 4 | +import org.springframework.boot.WebApplicationType; | ||
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | 6 | ||
| 7 | +// TODO @haohao:建议包名:cn.iocoder.yudao.module.iot.plugin.${pluginName},例如说 http。然后子包如下: | ||
| 8 | +// config:方配置类,以及 HttpVertxPlugin 初始化 | ||
| 9 | +// service:放 HttpVertxHandler 逻辑; | ||
| 6 | @SpringBootApplication | 10 | @SpringBootApplication |
| 7 | public class HttpPluginSpringbootApplication { | 11 | public class HttpPluginSpringbootApplication { |
| 12 | + | ||
| 8 | public static void main(String[] args) { | 13 | public static void main(String[] args) { |
| 9 | - SpringApplication.run(HttpPluginSpringbootApplication.class, args); | 14 | +// SpringApplication.run(HttpPluginSpringbootApplication.class, args); |
| 15 | + SpringApplication application = new SpringApplication(HttpPluginSpringbootApplication.class); | ||
| 16 | + application.setWebApplicationType(WebApplicationType.NONE); | ||
| 17 | + application.run(args); | ||
| 10 | } | 18 | } |
| 11 | -} | ||
| 12 | \ No newline at end of file | 19 | \ No newline at end of file |
| 20 | + | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +// TODO @haohao:如下是 sdk 的包:cn.iocoder.yudao.module.iot.plugin.sdk | ||
| 24 | +// 1. api 包:实现 DeviceDataApi 接口,通过 resttemplate 调用 | ||
| 25 | +// 2. config 包:初始化 DeviceDataApi 等等 | ||
| 26 | + | ||
| 27 | +// 3. 其中 resttemplate 调用的后端地址,通过每个服务的 application.yaml 进行注入。 | ||
| 13 | \ No newline at end of file | 28 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpVertxPlugin.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/config/HttpVertxPlugin.java
| 1 | -package cn.iocoder.yudao.module.iot.plugin; | 1 | +package cn.iocoder.yudao.module.iot.config; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.iot.api.ServiceRegistry; | 3 | +import cn.hutool.extra.spring.SpringUtil; |
| 4 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; | 4 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; |
| 5 | +import cn.iocoder.yudao.module.iot.service.HttpVertxHandler; | ||
| 5 | import io.vertx.core.Vertx; | 6 | import io.vertx.core.Vertx; |
| 6 | import io.vertx.ext.web.Router; | 7 | import io.vertx.ext.web.Router; |
| 7 | import io.vertx.ext.web.handler.BodyHandler; | 8 | import io.vertx.ext.web.handler.BodyHandler; |
| 9 | +import lombok.extern.slf4j.Slf4j; | ||
| 8 | import org.pf4j.PluginWrapper; | 10 | import org.pf4j.PluginWrapper; |
| 9 | import org.pf4j.spring.SpringPlugin; | 11 | import org.pf4j.spring.SpringPlugin; |
| 10 | import org.springframework.context.ApplicationContext; | 12 | import org.springframework.context.ApplicationContext; |
| 11 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; | 13 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 12 | 14 | ||
| 13 | -import lombok.extern.slf4j.Slf4j; | ||
| 14 | - | ||
| 15 | @Slf4j | 15 | @Slf4j |
| 16 | public class HttpVertxPlugin extends SpringPlugin { | 16 | public class HttpVertxPlugin extends SpringPlugin { |
| 17 | 17 | ||
| 18 | private static final int PORT = 8092; | 18 | private static final int PORT = 8092; |
| 19 | private Vertx vertx; | 19 | private Vertx vertx; |
| 20 | - private DeviceDataApi deviceDataApi; | ||
| 21 | 20 | ||
| 22 | public HttpVertxPlugin(PluginWrapper wrapper) { | 21 | public HttpVertxPlugin(PluginWrapper wrapper) { |
| 23 | super(wrapper); | 22 | super(wrapper); |
| @@ -28,7 +27,7 @@ public class HttpVertxPlugin extends SpringPlugin { | @@ -28,7 +27,7 @@ public class HttpVertxPlugin extends SpringPlugin { | ||
| 28 | log.info("HttpVertxPlugin.start()"); | 27 | log.info("HttpVertxPlugin.start()"); |
| 29 | 28 | ||
| 30 | // 获取 DeviceDataApi 实例 | 29 | // 获取 DeviceDataApi 实例 |
| 31 | - deviceDataApi = ServiceRegistry.getService(DeviceDataApi.class); | 30 | + DeviceDataApi deviceDataApi = SpringUtil.getBean(DeviceDataApi.class); |
| 32 | if (deviceDataApi == null) { | 31 | if (deviceDataApi == null) { |
| 33 | log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!"); | 32 | log.error("未能从 ServiceRegistry 获取 DeviceDataApi 实例,请确保主程序已正确注册!"); |
| 34 | return; | 33 | return; |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/config/TestConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.config; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | +import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; | ||
| 5 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceEventReportReqDTO; | ||
| 6 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; | ||
| 7 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStatusUpdateReqDTO; | ||
| 8 | +import org.pf4j.DefaultPluginManager; | ||
| 9 | +import org.pf4j.PluginWrapper; | ||
| 10 | +import org.springframework.boot.web.client.RestTemplateBuilder; | ||
| 11 | +import org.springframework.context.annotation.Bean; | ||
| 12 | +import org.springframework.context.annotation.Configuration; | ||
| 13 | +import org.springframework.web.client.RestTemplate; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 16 | + | ||
| 17 | +// TODO 芋艿:临时实现; | ||
| 18 | +@Configuration | ||
| 19 | +public class TestConfiguration { | ||
| 20 | + | ||
| 21 | +// @Resource | ||
| 22 | +// private RestTemplate restTemplate; | ||
| 23 | + | ||
| 24 | + // TODO 芋艿:这里,后续看看怎么创建好点 | ||
| 25 | + @Bean | ||
| 26 | + public RestTemplate restTemplate() { | ||
| 27 | + return new RestTemplateBuilder().build(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Bean | ||
| 31 | + public DeviceDataApi deviceDataApi(RestTemplate restTemplate) { | ||
| 32 | + return new DeviceDataApi() { | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) { | ||
| 36 | + // TODO haohao:待实现 | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) { | ||
| 42 | + // TODO haohao:待实现 | ||
| 43 | + return null; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) { | ||
| 48 | + // TODO haohao:待完整实现 | ||
| 49 | + String url = "http://127.0.0.1:48080/rpc-api/iot/device-data/report-property"; | ||
| 50 | + try { | ||
| 51 | + restTemplate.postForObject(url, reportReqDTO, CommonResult.class); | ||
| 52 | + return success(true); | ||
| 53 | + } catch (Exception e) { | ||
| 54 | + e.printStackTrace(); | ||
| 55 | + return CommonResult.error(400, "error"); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + }; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + // TODO @haohao:可能要看下,有没更好的方式 | ||
| 63 | + @Bean(initMethod = "start") | ||
| 64 | + public HttpVertxPlugin HttpVertxPlugin() { | ||
| 65 | + PluginWrapper pluginWrapper = new PluginWrapper(new DefaultPluginManager(), null, null, null); | ||
| 66 | + return new HttpVertxPlugin(pluginWrapper); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | +} |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-http-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/HttpVertxHandler.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/service/HttpVertxHandler.java
| 1 | -package cn.iocoder.yudao.module.iot.plugin; | 1 | +package cn.iocoder.yudao.module.iot.service; |
| 2 | 2 | ||
| 3 | import cn.hutool.json.JSONObject; | 3 | import cn.hutool.json.JSONObject; |
| 4 | import cn.hutool.json.JSONUtil; | 4 | import cn.hutool.json.JSONUtil; |
| 5 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; | 5 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; |
| 6 | -import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO; | 6 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 7 | import io.vertx.core.Handler; | 7 | import io.vertx.core.Handler; |
| 8 | import io.vertx.ext.web.RequestBody; | 8 | import io.vertx.ext.web.RequestBody; |
| 9 | import io.vertx.ext.web.RoutingContext; | 9 | import io.vertx.ext.web.RoutingContext; |
| @@ -46,12 +46,12 @@ public class HttpVertxHandler implements Handler<RoutingContext> { | @@ -46,12 +46,12 @@ public class HttpVertxHandler implements Handler<RoutingContext> { | ||
| 46 | 46 | ||
| 47 | try { | 47 | try { |
| 48 | // 调用主程序的接口保存数据 | 48 | // 调用主程序的接口保存数据 |
| 49 | - DeviceDataCreateReqDTO createDTO = DeviceDataCreateReqDTO.builder() | 49 | + IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder() |
| 50 | .productKey(productKey) | 50 | .productKey(productKey) |
| 51 | .deviceName(deviceName) | 51 | .deviceName(deviceName) |
| 52 | - .message(jsonData.toString()) | 52 | + .params(jsonData) // TODO 芋艿:这块要优化 |
| 53 | .build(); | 53 | .build(); |
| 54 | - deviceDataApi.saveDeviceData(createDTO); | 54 | + deviceDataApi.reportDevicePropertyData(createDTO); |
| 55 | 55 | ||
| 56 | // 构造成功响应内容 | 56 | // 构造成功响应内容 |
| 57 | JSONObject successRes = createResponseJson( | 57 | JSONObject successRes = createResponseJson( |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-http/src/main/resources/application.yml
0 → 100644
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-mqtt-plugin/plugin.properties renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-mqtt/plugin.properties
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-mqtt-plugin/pom.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-mqtt/pom.xml
| @@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
| 11 | <modelVersion>4.0.0</modelVersion> | 11 | <modelVersion>4.0.0</modelVersion> |
| 12 | <packaging>jar</packaging> | 12 | <packaging>jar</packaging> |
| 13 | 13 | ||
| 14 | - <artifactId>yudao-module-iot-mqtt-plugin</artifactId> | 14 | + <artifactId>yudao-module-iot-plugin-mqtt</artifactId> |
| 15 | 15 | ||
| 16 | <name>${project.artifactId}</name> | 16 | <name>${project.artifactId}</name> |
| 17 | <description> | 17 | <description> |
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-emqx-plugin/src/main/assembly/assembly.xml renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-mqtt/src/main/assembly/assembly.xml
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-mqtt-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttPlugin.java
yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-mqtt-plugin/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java renamed to yudao-module-iot/yudao-module-iot-plugin/yudao-module-iot-plugin-mqtt/src/main/java/cn/iocoder/yudao/module/iot/plugin/MqttServerExtension.java