Commit 13ced8a114204a83d614a5a46fa21356f2be50ba
Merge branch 'feature/iot' of https://gitee.com/alwayssuper/ruoyi-vue-pro into feature/iot
Conflicts: yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/ExampleService.java
Showing
9 changed files
with
78 additions
and
44 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/deviceconsumer/DeviceConsumer.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.iot.mq.consumer.deviceconsumer; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; | ||
| 5 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | ||
| 6 | +import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService; | ||
| 7 | +import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.springframework.context.event.EventListener; | ||
| 10 | +import org.springframework.scheduling.annotation.Async; | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | + | ||
| 13 | +import javax.annotation.Resource; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 针对 {@link ThingModelMessage} 的消费者 | ||
| 17 | + * | ||
| 18 | + * @author alwayssuper | ||
| 19 | + */ | ||
| 20 | +@Component | ||
| 21 | +@Slf4j | ||
| 22 | +public class DeviceConsumer { | ||
| 23 | + @Resource | ||
| 24 | + private IotDeviceLogDataService iotDeviceLogDataService; | ||
| 25 | + @Resource | ||
| 26 | + private IotDevicePropertyDataService deviceDataService; | ||
| 27 | + | ||
| 28 | + // TODO @芋艿:这块先用ThingModelMessage,后续看看用啥替代 | ||
| 29 | + @EventListener | ||
| 30 | + @Async | ||
| 31 | + public void onMessage(ThingModelMessage message) { | ||
| 32 | + log.info("[onMessage][消息内容({})]", message); | ||
| 33 | + deviceDataService.saveDeviceDataTest(message); | ||
| 34 | + iotDeviceLogDataService.saveDeviceLog(message); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/simulatesend/SimulateSendConsumer.java
| @@ -4,7 +4,6 @@ package cn.iocoder.yudao.module.iot.mq.consumer.simulatesend; | @@ -4,7 +4,6 @@ package cn.iocoder.yudao.module.iot.mq.consumer.simulatesend; | ||
| 4 | * TODO @alwayssuper:记得实现,还有类注释哈 | 4 | * TODO @alwayssuper:记得实现,还有类注释哈 |
| 5 | * | 5 | * |
| 6 | * @author alwayssuper | 6 | * @author alwayssuper |
| 7 | - * @since 2024/12/20 8:04 | ||
| 8 | */ | 7 | */ |
| 9 | public class SimulateSendConsumer { | 8 | public class SimulateSendConsumer { |
| 10 | } | 9 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/message/package-info.java
0 → 100644
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java
| 1 | package cn.iocoder.yudao.module.iot.mq.producer.simulatesend; | 1 | package cn.iocoder.yudao.module.iot.mq.producer.simulatesend; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | ||
| 3 | import jakarta.annotation.Resource; | 4 | import jakarta.annotation.Resource; |
| 4 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.springframework.context.ApplicationContext; | 6 | import org.springframework.context.ApplicationContext; |
| @@ -19,4 +20,12 @@ public class SimulateSendProducer { | @@ -19,4 +20,12 @@ public class SimulateSendProducer { | ||
| 19 | @Resource | 20 | @Resource |
| 20 | private ApplicationContext applicationContext; | 21 | private ApplicationContext applicationContext; |
| 21 | 22 | ||
| 23 | + /** | ||
| 24 | + * 发送 {@link ThingModelMessage} 消息 | ||
| 25 | + * | ||
| 26 | + * @param thingModelMessage 物模型消息 | ||
| 27 | + */ | ||
| 28 | + public void sendSimulateMessage(ThingModelMessage thingModelMessage) { | ||
| 29 | + applicationContext.publishEvent(thingModelMessage); | ||
| 30 | + } | ||
| 22 | } | 31 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; | 4 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; |
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; |
| 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | ||
| 7 | 8 | ||
| 8 | /** | 9 | /** |
| 9 | * IoT 设备日志数据 Service 接口 | 10 | * IoT 设备日志数据 Service 接口 |
| @@ -36,4 +37,7 @@ public interface IotDeviceLogDataService { | @@ -36,4 +37,7 @@ public interface IotDeviceLogDataService { | ||
| 36 | */ | 37 | */ |
| 37 | PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO); | 38 | PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO); |
| 38 | 39 | ||
| 40 | + | ||
| 41 | + void saveDeviceLog(ThingModelMessage msg); | ||
| 42 | + | ||
| 39 | } | 43 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; | 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; |
| 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 8 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | ||
| 8 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper; | 9 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper; |
| 9 | import jakarta.annotation.Resource; | 10 | import jakarta.annotation.Resource; |
| 10 | import lombok.extern.slf4j.Slf4j; | 11 | import lombok.extern.slf4j.Slf4j; |
| @@ -76,4 +77,9 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | @@ -76,4 +77,9 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ | ||
| 76 | return new PageResult<>(list, total); | 77 | return new PageResult<>(list, total); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 80 | + @Override | ||
| 81 | + public void saveDeviceLog(ThingModelMessage msg) { | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 79 | } | 85 | } |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataService.java
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; | 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 cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | ||
| 7 | import jakarta.validation.Valid; | 8 | import jakarta.validation.Valid; |
| 8 | 9 | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| @@ -30,6 +31,14 @@ public interface IotDevicePropertyDataService { | @@ -30,6 +31,14 @@ public interface IotDevicePropertyDataService { | ||
| 30 | */ | 31 | */ |
| 31 | void saveDeviceData(IotDevicePropertyReportReqDTO createDTO); | 32 | void saveDeviceData(IotDevicePropertyReportReqDTO createDTO); |
| 32 | 33 | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 保存设备数据 | ||
| 37 | + * | ||
| 38 | + * @param thingModelMessage 设备数据 | ||
| 39 | + */ | ||
| 40 | + void saveDeviceDataTest(ThingModelMessage thingModelMessage); | ||
| 41 | + | ||
| 33 | /** | 42 | /** |
| 34 | * 获得设备属性最新数据 | 43 | * 获得设备属性最新数据 |
| 35 | * | 44 | * |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataServiceImpl.java
| @@ -150,6 +150,15 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | @@ -150,6 +150,15 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe | ||
| 150 | thingModelMessageService.saveThingModelMessage(device, thingModelMessage); | 150 | thingModelMessageService.saveThingModelMessage(device, thingModelMessage); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | + //TODO:后续捋一捋这块逻辑,先借鉴一下目前的代码 | ||
| 154 | + @Override | ||
| 155 | + public void saveDeviceDataTest(ThingModelMessage thingModelMessage) { | ||
| 156 | + // 1. 根据产品 key 和设备名称,获得设备信息 | ||
| 157 | + IotDeviceDO device = deviceService.getDeviceByProductKeyAndDeviceName(thingModelMessage.getProductKey(), thingModelMessage.getDeviceName()); | ||
| 158 | + // 2. 保存数据 | ||
| 159 | + thingModelMessageService.saveThingModelMessage(device, thingModelMessage); | ||
| 160 | + } | ||
| 161 | + | ||
| 153 | @Override | 162 | @Override |
| 154 | public List<IotDeviceDataDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { | 163 | public List<IotDeviceDataDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { |
| 155 | List<IotDeviceDataDO> list = new ArrayList<>(); | 164 | List<IotDeviceDataDO> list = new ArrayList<>(); |
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 |