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
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 | 1 | package cn.iocoder.yudao.module.iot.mq.producer.simulatesend; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | |
| 3 | 4 | import jakarta.annotation.Resource; |
| 4 | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | 6 | import org.springframework.context.ApplicationContext; |
| ... | ... | @@ -19,4 +20,12 @@ public class SimulateSendProducer { |
| 19 | 20 | @Resource |
| 20 | 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 | 4 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; |
| 6 | 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 | 10 | * IoT 设备日志数据 Service 接口 |
| ... | ... | @@ -36,4 +37,7 @@ public interface IotDeviceLogDataService { |
| 36 | 37 | */ |
| 37 | 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 | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; |
| 8 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | |
| 8 | 9 | import cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper; |
| 9 | 10 | import jakarta.annotation.Resource; |
| 10 | 11 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -76,4 +77,9 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ |
| 76 | 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 | 4 | import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataPageReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; |
| 7 | +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; | |
| 7 | 8 | import jakarta.validation.Valid; |
| 8 | 9 | |
| 9 | 10 | import java.util.List; |
| ... | ... | @@ -30,6 +31,14 @@ public interface IotDevicePropertyDataService { |
| 30 | 31 | */ |
| 31 | 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 | 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 | 162 | @Override |
| 154 | 163 | public List<IotDeviceDataDO> getLatestDeviceProperties(@Valid IotDeviceDataPageReqVO deviceDataReqVO) { |
| 155 | 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 | 0 | \ No newline at end of file |