Commit 269dec1b2e04552dfc5ad7820a81a174e1ccfef2

Authored by YunaiV
1 parent 03462a10

【代码评审】IoT:模拟设备数据

Showing 13 changed files with 66 additions and 142 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceDataController.java
@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.controller.admin.device; @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.controller.admin.device;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 -import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;  
7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.*; 6 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.*;
8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO; 7 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
9 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO; 8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
@@ -52,7 +51,7 @@ public class IotDeviceDataController { @@ -52,7 +51,7 @@ public class IotDeviceDataController {
52 return success(BeanUtils.toBean(list, IotTimeDataRespVO.class)); 51 return success(BeanUtils.toBean(list, IotTimeDataRespVO.class));
53 } 52 }
54 53
55 - // TODO:数据权限 54 + // TODO:功能权限
56 @PostMapping("/simulator") 55 @PostMapping("/simulator")
57 @Operation(summary = "模拟设备") 56 @Operation(summary = "模拟设备")
58 public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { 57 public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
@@ -62,7 +61,7 @@ public class IotDeviceDataController { @@ -62,7 +61,7 @@ public class IotDeviceDataController {
62 return success(true); 61 return success(true);
63 } 62 }
64 63
65 - // TODO:数据权限 64 + // TODO:功能权限
66 @GetMapping("/log/page") 65 @GetMapping("/log/page")
67 @Operation(summary = "获得设备日志分页") 66 @Operation(summary = "获得设备日志分页")
68 public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) { 67 public CommonResult<PageResult<IotDeviceLogRespVO>> getDeviceLogPage(@Valid IotDeviceLogPageReqVO pageReqVO) {
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataSimulatorSaveReqVO.java
@@ -19,7 +19,6 @@ public class IotDeviceDataSimulatorSaveReqVO { @@ -19,7 +19,6 @@ public class IotDeviceDataSimulatorSaveReqVO {
19 @NotEmpty(message = "产品标识不能为空") 19 @NotEmpty(message = "产品标识不能为空")
20 private String productKey; 20 private String productKey;
21 21
22 - // TODO @super:中文写作规范,中英文之间,要有空格。例如说,设备 ID。ps:这里应该是设备标识  
23 @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123") 22 @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123")
24 @NotEmpty(message = "设备标识不能为空") 23 @NotEmpty(message = "设备标识不能为空")
25 private String deviceKey; 24 private String deviceKey;
@@ -38,6 +37,7 @@ public class IotDeviceDataSimulatorSaveReqVO { @@ -38,6 +37,7 @@ public class IotDeviceDataSimulatorSaveReqVO {
38 @NotEmpty(message = "数据内容不能为空") 37 @NotEmpty(message = "数据内容不能为空")
39 private String content; 38 private String content;
40 39
  40 + // TODO @芋艿:需要讨论下,reportTime 到底以那个为准!
41 @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED) 41 @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED)
42 private Long reportTime; 42 private Long reportTime;
43 43
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java
@@ -25,7 +25,6 @@ public class IotDeviceLogDO { @@ -25,7 +25,6 @@ public class IotDeviceLogDO {
25 */ 25 */
26 private String id; 26 private String id;
27 27
28 - // TODO @super:关联要 @下  
29 /** 28 /**
30 * 产品标识 29 * 产品标识
31 * <p> 30 * <p>
@@ -33,7 +32,6 @@ public class IotDeviceLogDO { @@ -33,7 +32,6 @@ public class IotDeviceLogDO {
33 */ 32 */
34 private String productKey; 33 private String productKey;
35 34
36 - // TODO @super:关联要 @下  
37 /** 35 /**
38 * 设备标识 36 * 设备标识
39 * <p> 37 * <p>
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java
@@ -10,9 +10,7 @@ import org.apache.ibatis.annotations.Param; @@ -10,9 +10,7 @@ import org.apache.ibatis.annotations.Param;
10 import java.util.List; 10 import java.util.List;
11 11
12 /** 12 /**
13 - * IOT 设备日志数据 Mapper 接口  
14 - *  
15 - * 基于 TDengine 实现设备日志的存储 13 + * 设备日志 {@link IotDeviceLogDO} Mapper 接口
16 */ 14 */
17 @Mapper 15 @Mapper
18 @TDengineDS 16 @TDengineDS
@@ -21,12 +19,11 @@ public interface IotDeviceLogDataMapper { @@ -21,12 +19,11 @@ public interface IotDeviceLogDataMapper {
21 19
22 /** 20 /**
23 * 创建设备日志超级表 21 * 创建设备日志超级表
24 - * 初始化只创建一次  
25 */ 22 */
26 void createDeviceLogSTable(); 23 void createDeviceLogSTable();
27 24
28 -  
29 // TODO @super:单个参数,不用加 @Param 25 // TODO @super:单个参数,不用加 @Param
  26 + // TODO @芋艿:在瞅瞅
30 //讨论:艿菇这里有些特殊情况,我也学习了一下这块知识: 27 //讨论:艿菇这里有些特殊情况,我也学习了一下这块知识:
31 // 如果使用的是Java 8及以上版本,并且编译器保留了参数名(通过编译器选项-parameters启用),则可以去掉@Param注解。MyBatis会自动使用参数的实际名称 28 // 如果使用的是Java 8及以上版本,并且编译器保留了参数名(通过编译器选项-parameters启用),则可以去掉@Param注解。MyBatis会自动使用参数的实际名称
32 // 但在TDengine中 @Param去掉后TDengine会报错,以下是大模型的回答: 29 // 但在TDengine中 @Param去掉后TDengine会报错,以下是大模型的回答:
@@ -65,18 +62,12 @@ public interface IotDeviceLogDataMapper { @@ -65,18 +62,12 @@ public interface IotDeviceLogDataMapper {
65 */ 62 */
66 Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO); 63 Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
67 64
  65 + // TODO @芋艿:这个方法名,后续看看叫啥好
68 /** 66 /**
69 * 查询设备日志表是否存在 67 * 查询设备日志表是否存在
70 * 68 *
71 - * @return 不存在返回null 69 + * @return 不存在返回 null
72 */ 70 */
73 Object checkDeviceLogSTableExists(); 71 Object checkDeviceLogSTableExists();
74 72
75 - /**  
76 - * 检查设备日志子表是否存在  
77 - *  
78 - * @param deviceKey 设备标识  
79 - * @return 不存在返回null  
80 - */  
81 - Object checkDeviceLogTableExists(@Param("deviceKey") String deviceKey);  
82 } 73 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java
@@ -6,17 +6,15 @@ import lombok.extern.slf4j.Slf4j; @@ -6,17 +6,15 @@ import lombok.extern.slf4j.Slf4j;
6 import org.springframework.boot.ApplicationArguments; 6 import org.springframework.boot.ApplicationArguments;
7 import org.springframework.boot.ApplicationRunner; 7 import org.springframework.boot.ApplicationRunner;
8 import org.springframework.context.annotation.Configuration; 8 import org.springframework.context.annotation.Configuration;
9 -import org.springframework.core.annotation.Order;  
10 9
11 /** 10 /**
12 * TDengine 表初始化的 Configuration 11 * TDengine 表初始化的 Configuration
13 * 12 *
14 * @author alwayssuper 13 * @author alwayssuper
15 */ 14 */
  15 +@Configuration
16 @Slf4j 16 @Slf4j
17 @RequiredArgsConstructor 17 @RequiredArgsConstructor
18 -@Configuration  
19 -@Order  
20 public class TDengineTableInitConfiguration implements ApplicationRunner { 18 public class TDengineTableInitConfiguration implements ApplicationRunner {
21 19
22 private final IotDeviceLogDataService deviceLogService; 20 private final IotDeviceLogDataService deviceLogService;
@@ -26,9 +24,7 @@ public class TDengineTableInitConfiguration implements ApplicationRunner { @@ -26,9 +24,7 @@ public class TDengineTableInitConfiguration implements ApplicationRunner {
26 try { 24 try {
27 // 初始化设备日志表 25 // 初始化设备日志表
28 deviceLogService.defineDeviceLog(); 26 deviceLogService.defineDeviceLog();
29 - // TODO @super:这个日志,是不是不用打,不然重复啦!!!  
30 } catch (Exception ex) { 27 } catch (Exception ex) {
31 - // TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!!  
32 // 初始化失败时打印错误日志并退出系统 28 // 初始化失败时打印错误日志并退出系统
33 log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex); 29 log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex);
34 System.exit(1); 30 System.exit(1);
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/consumer/deviceconsumer/DeviceConsumer.java
1 package cn.iocoder.yudao.module.iot.mq.consumer.deviceconsumer; 1 package cn.iocoder.yudao.module.iot.mq.consumer.deviceconsumer;
2 2
3 3
4 -import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;  
5 import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage; 4 import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
6 import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService; 5 import cn.iocoder.yudao.module.iot.service.device.IotDeviceLogDataService;
7 import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService; 6 import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService;
@@ -20,8 +19,9 @@ import javax.annotation.Resource; @@ -20,8 +19,9 @@ import javax.annotation.Resource;
20 @Component 19 @Component
21 @Slf4j 20 @Slf4j
22 public class DeviceConsumer { 21 public class DeviceConsumer {
  22 +
23 @Resource 23 @Resource
24 - private IotDeviceLogDataService iotDeviceLogDataService; 24 + private IotDeviceLogDataService deviceLogDataService;
25 @Resource 25 @Resource
26 private IotDevicePropertyDataService deviceDataService; 26 private IotDevicePropertyDataService deviceDataService;
27 27
@@ -35,7 +35,7 @@ public class DeviceConsumer { @@ -35,7 +35,7 @@ public class DeviceConsumer {
35 // 设备数据记录 35 // 设备数据记录
36 deviceDataService.saveDeviceDataTest(message); 36 deviceDataService.saveDeviceDataTest(message);
37 // 设备日志记录 37 // 设备日志记录
38 - iotDeviceLogDataService.saveDeviceLog(message); 38 + deviceLogDataService.saveDeviceLog(message);
39 } 39 }
40 40
41 } 41 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/mq/producer/simulatesend/SimulateSendProducer.java
@@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j; @@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
6 import org.springframework.context.ApplicationContext; 6 import org.springframework.context.ApplicationContext;
7 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
8 8
9 -// TODO @alwayssuper:是不是还没用起来哈?Producer 最好属于某个模块; 9 +// TODO @芋艿:@alwayssuper:是不是还没用起来哈?Producer 最好属于某个模块;
10 /** 10 /**
11 * SimulateSend 模拟设备上报的 Producer 11 * SimulateSend 模拟设备上报的 Producer
12 * 12 *
@@ -28,4 +28,5 @@ public class SimulateSendProducer { @@ -28,4 +28,5 @@ public class SimulateSendProducer {
28 public void sendSimulateMessage(ThingModelMessage thingModelMessage) { 28 public void sendSimulateMessage(ThingModelMessage thingModelMessage) {
29 applicationContext.publishEvent(thingModelMessage); 29 applicationContext.publishEvent(thingModelMessage);
30 } 30 }
  31 +
31 } 32 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java
@@ -16,7 +16,7 @@ public interface IotDeviceLogDataService { @@ -16,7 +16,7 @@ public interface IotDeviceLogDataService {
16 /** 16 /**
17 * 初始化 TDengine 超级表 17 * 初始化 TDengine 超级表
18 * 18 *
19 - *系统启动时,会自动初始化一次 19 + * 系统启动时,会自动初始化一次
20 */ 20 */
21 void defineDeviceLog(); 21 void defineDeviceLog();
22 22
@@ -40,8 +40,8 @@ public interface IotDeviceLogDataService { @@ -40,8 +40,8 @@ public interface IotDeviceLogDataService {
40 /** 40 /**
41 * 插入设备日志 41 * 插入设备日志
42 * 42 *
43 - * @param msg 设备数据 43 + * @param message 设备数据
44 */ 44 */
45 - void saveDeviceLog(ThingModelMessage msg); 45 + void saveDeviceLog(ThingModelMessage message);
46 46
47 } 47 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java
@@ -13,7 +13,6 @@ import lombok.extern.slf4j.Slf4j; @@ -13,7 +13,6 @@ import lombok.extern.slf4j.Slf4j;
13 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
14 import org.springframework.validation.annotation.Validated; 14 import org.springframework.validation.annotation.Validated;
15 15
16 -import java.util.Date;  
17 import java.util.List; 16 import java.util.List;
18 17
19 /** 18 /**
@@ -27,28 +26,18 @@ import java.util.List; @@ -27,28 +26,18 @@ import java.util.List;
27 public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ 26 public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
28 27
29 @Resource 28 @Resource
30 - private IotDeviceLogDataMapper iotDeviceLogDataMapper; 29 + private IotDeviceLogDataMapper deviceLogDataMapper;
31 30
32 - // TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。  
33 @Override 31 @Override
34 public void defineDeviceLog() { 32 public void defineDeviceLog() {
35 - // TODO @super:改成不存在才创建。  
36 -// try {  
37 -// // 创建超级表(使用 IF NOT EXISTS 语句避免重复创建错误)  
38 -// iotDeviceLogDataMapper.createDeviceLogSTable();  
39 -// } catch (Exception e) {  
40 -// if (e.getMessage().contains("already exists")) {  
41 -// log.info("[TDengine] 设备日志超级表已存在,跳过创建");  
42 -// return;  
43 -// }  
44 -// throw e;  
45 -// }  
46 - if(iotDeviceLogDataMapper.checkDeviceLogSTableExists()==null){  
47 - log.info("[TDengine] 设备日志超级表不存在,开始创建");  
48 - iotDeviceLogDataMapper.createDeviceLogSTable();  
49 - }else{  
50 - log.info("[TDengine] 设备日志超级表已存在,跳过创建"); 33 + if (deviceLogDataMapper.checkDeviceLogSTableExists() != null) {
  34 + log.info("[defineDeviceLog][设备日志超级表已存在,跳过创建]");
  35 + return;
51 } 36 }
  37 +
  38 + log.info("[defineDeviceLog][设备日志超级表不存在,开始创建]");
  39 + deviceLogDataMapper.createDeviceLogSTable();
  40 + log.info("[defineDeviceLog][设备日志超级表不存在,创建完成]");
52 } 41 }
53 42
54 @Override 43 @Override
@@ -57,47 +46,32 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{ @@ -57,47 +46,32 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
57 IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class); 46 IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class);
58 47
59 // 2. 处理时间字段 48 // 2. 处理时间字段
60 - // TODO @super:一次性的字段,不用单独给个变量  
61 -// long currentTime = System.currentTimeMillis();  
62 - // 2.1 设置时序时间为当前时间  
63 // iotDeviceLogDO.setTs(currentTime); // TODO @super:TS在SQL中直接NOW 咱们的TS数据获取是走哪一种;走 now() 49 // iotDeviceLogDO.setTs(currentTime); // TODO @super:TS在SQL中直接NOW 咱们的TS数据获取是走哪一种;走 now()
64 50
65 // 3. 插入数据 51 // 3. 插入数据
66 - // TODO @super:不要直接调用对方的 IotDeviceLogDataMapper,通过 service 哈!  
67 - // 讨论:艿菇 这就是iotDeviceLogDataService的Impl  
68 - iotDeviceLogDataMapper.insert(iotDeviceLogDO); 52 + deviceLogDataMapper.insert(iotDeviceLogDO);
69 } 53 }
70 54
71 - // TODO @super:在 iotDeviceLogDataService 写  
72 - // 讨论:艿菇 这就是iotDeviceLogDataService的Impl  
73 @Override 55 @Override
74 public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) { 56 public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) {
75 - // 当设备日志表未创建时,查询会出现报错  
76 - if(iotDeviceLogDataMapper.checkDeviceLogTableExists(pageReqVO.getDeviceKey())==null){  
77 - return null;  
78 - }  
79 - // 查询数据  
80 - List<IotDeviceLogDO> list = iotDeviceLogDataMapper.selectPage(pageReqVO);  
81 - Long total = iotDeviceLogDataMapper.selectCount(pageReqVO);  
82 - // 构造分页结果 57 + // TODO @芋艿:增加一个表不存在的 try catch
  58 + List<IotDeviceLogDO> list = deviceLogDataMapper.selectPage(pageReqVO);
  59 + Long total = deviceLogDataMapper.selectCount(pageReqVO);
83 return new PageResult<>(list, total); 60 return new PageResult<>(list, total);
84 } 61 }
85 62
86 @Override 63 @Override
87 - public void saveDeviceLog(ThingModelMessage msg) {  
88 - // 1. 构建设备日志对象  
89 - IotDeviceLogDO iotDeviceLogDO = IotDeviceLogDO.builder()  
90 - .id(msg.getId()) // 消息ID  
91 - .deviceKey(msg.getDeviceKey()) // 设备标识  
92 - .productKey(msg.getProductKey()) // 产品标识  
93 - .type(msg.getMethod()) // 消息类型,使用method作为类型  
94 - .subType("property") // TODO:这块先写死,后续优化  
95 - .content(JSONUtil.toJsonStr(msg)) // TODO:后续优化  
96 - .reportTime(msg.getTime()) // 上报时间 64 + public void saveDeviceLog(ThingModelMessage message) {
  65 + IotDeviceLogDO log = IotDeviceLogDO.builder()
  66 + .id(message.getId())
  67 + .deviceKey(message.getDeviceKey())
  68 + .productKey(message.getProductKey())
  69 + .type(message.getMethod()) // 消息类型,使用method作为类型 TODO 芋艿:在看看
  70 + .subType("property") // TODO 芋艿:这块先写死,后续优化
  71 + .content(JSONUtil.toJsonStr(message)) // TODO 芋艿:后续优化
  72 + .reportTime(message.getTime()) // 上报时间 TODO 芋艿:在想想时间
97 .build(); 73 .build();
98 -  
99 - // 2. 插入设备日志  
100 - iotDeviceLogDataMapper.insert(iotDeviceLogDO); 74 + deviceLogDataMapper.insert(log);
101 } 75 }
102 76
103 } 77 }
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataService.java
@@ -32,7 +32,6 @@ public interface IotDevicePropertyDataService { @@ -32,7 +32,6 @@ public interface IotDevicePropertyDataService {
32 */ 32 */
33 void saveDeviceData(IotDevicePropertyReportReqDTO createDTO); 33 void saveDeviceData(IotDevicePropertyReportReqDTO createDTO);
34 34
35 -  
36 /** 35 /**
37 * 保存设备数据 36 * 保存设备数据
38 * 37 *
@@ -45,7 +44,6 @@ public interface IotDevicePropertyDataService { @@ -45,7 +44,6 @@ public interface IotDevicePropertyDataService {
45 * 44 *
46 * @param simulatorReqVO 设备数据 45 * @param simulatorReqVO 设备数据
47 */ 46 */
48 -  
49 void simulatorSend(IotDeviceDataSimulatorSaveReqVO simulatorReqVO); 47 void simulatorSend(IotDeviceDataSimulatorSaveReqVO simulatorReqVO);
50 48
51 /** 49 /**
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataServiceImpl.java
@@ -159,7 +159,7 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe @@ -159,7 +159,7 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe
159 thingModelMessageService.saveThingModelMessage(device, thingModelMessage); 159 thingModelMessageService.saveThingModelMessage(device, thingModelMessage);
160 } 160 }
161 161
162 - //TODO:后续捋一捋这块逻辑,先借鉴一下目前的代码 162 + //TODO @芋艿:后续捋一捋这块逻辑,先借鉴一下目前的代码
163 @Override 163 @Override
164 public void saveDeviceDataTest(ThingModelMessage thingModelMessage) { 164 public void saveDeviceDataTest(ThingModelMessage thingModelMessage) {
165 // 1. 根据产品 key 和设备名称,获得设备信息 165 // 1. 根据产品 key 和设备名称,获得设备信息
@@ -168,7 +168,7 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe @@ -168,7 +168,7 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe
168 thingModelMessageService.saveThingModelMessage(device, thingModelMessage); 168 thingModelMessageService.saveThingModelMessage(device, thingModelMessage);
169 } 169 }
170 170
171 - //TODO: copy 了 saveDeviceData 的逻辑,后续看看这块怎么优化 171 + //TODO @芋艿:copy 了 saveDeviceData 的逻辑,后续看看这块怎么优化
172 @Override 172 @Override
173 public void simulatorSend(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) { 173 public void simulatorSend(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
174 // 1. 根据设备 key ,获得设备信息 174 // 1. 根据设备 key ,获得设备信息
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
@@ -4,28 +4,20 @@ @@ -4,28 +4,20 @@
4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5 <mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper"> 5 <mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogDataMapper">
6 6
7 - <!-- 创建设备日志超级表 初始化只创建一次-->  
8 <update id="createDeviceLogSTable"> 7 <update id="createDeviceLogSTable">
9 CREATE STABLE IF NOT EXISTS device_log ( 8 CREATE STABLE IF NOT EXISTS device_log (
10 - ts TIMESTAMP,  
11 - id NCHAR(50),  
12 - product_key NCHAR(50),  
13 - type NCHAR(50),  
14 - <!-- TODO @super:下划线 sub_type -->  
15 - sub_type NCHAR(50),  
16 - content NCHAR(1024),  
17 - report_time TIMESTAMP 9 + ts TIMESTAMP,
  10 + id NCHAR(50),
  11 + product_key NCHAR(50),
  12 + type NCHAR(50),
  13 + sub_type NCHAR(50),
  14 + content NCHAR(1024),
  15 + report_time TIMESTAMP
18 ) TAGS ( 16 ) TAGS (
19 device_key NCHAR(50) 17 device_key NCHAR(50)
20 ) 18 )
21 </update> 19 </update>
22 20
23 - <!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建-->  
24 - <update id="createDeviceLogTable">  
25 - CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}')  
26 - </update>  
27 -  
28 - <!-- 插入设备日志数据 在子表不存在的情况下 可在数据插入时 自动建表 -->  
29 <insert id="insert"> 21 <insert id="insert">
30 INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time) 22 INSERT INTO device_log_${log.deviceKey} (ts, id, product_key, type, subType, content, report_time)
31 USING device_log 23 USING device_log
@@ -42,7 +34,7 @@ @@ -42,7 +34,7 @@
42 </insert> 34 </insert>
43 35
44 <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO"> 36 <select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
45 - SELECT ts, id, device_key, product_key, type, subType, content, report_time 37 + SELECT ts, id, device_key, product_key, type, sub_type, content, report_time
46 FROM device_log_${reqVO.deviceKey} 38 FROM device_log_${reqVO.deviceKey}
47 <where> 39 <where>
48 <if test="reqVO.type != null and reqVO.type != ''"> 40 <if test="reqVO.type != null and reqVO.type != ''">
@@ -75,15 +67,12 @@ @@ -75,15 +67,12 @@
75 </where> 67 </where>
76 </select> 68 </select>
77 69
78 - <!-- 检查设备日志超级表是否存在 -->  
79 <select id="checkDeviceLogSTableExists" resultType="Object"> 70 <select id="checkDeviceLogSTableExists" resultType="Object">
80 SHOW STABLES LIKE 'device_log' 71 SHOW STABLES LIKE 'device_log'
81 </select> 72 </select>
82 73
83 - <!-- 检查设备日志子表是否存在 -->  
84 <select id="checkDeviceLogTableExists" resultType="Object"> 74 <select id="checkDeviceLogTableExists" resultType="Object">
85 SHOW TABLES LIKE 'device_log_${deviceKey}' 75 SHOW TABLES LIKE 'device_log_${deviceKey}'
86 </select> 76 </select>
87 77
88 -  
89 </mapper> 78 </mapper>
90 \ No newline at end of file 79 \ No newline at end of file
yudao-server/src/main/resources/application-local.yaml
@@ -45,7 +45,7 @@ spring: @@ -45,7 +45,7 @@ spring:
45 primary: master 45 primary: master
46 datasource: 46 datasource:
47 master: 47 master:
48 - url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 48 + url: jdbc:mysql://127.0.0.1:3307/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
49 # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例 49 # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例
50 # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 50 # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
51 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 51 # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
@@ -53,8 +53,8 @@ spring: @@ -53,8 +53,8 @@ spring:
53 # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 53 # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
54 # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例 54 # url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
55 # url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例 55 # url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
56 - username: ruoyi-vue-pro  
57 - password: ruoyi-@h2ju02hebp 56 + username: root
  57 + password: ahh@123456
58 # username: sa # SQL Server 连接的示例 58 # username: sa # SQL Server 连接的示例
59 # password: Yudao@2024 # SQL Server 连接的示例 59 # password: Yudao@2024 # SQL Server 连接的示例
60 # username: SYSDBA # DM 连接的示例 60 # username: SYSDBA # DM 连接的示例
@@ -63,25 +63,17 @@ spring: @@ -63,25 +63,17 @@ spring:
63 # password: Yudao@2024 # OpenGauss 连接的示例 63 # password: Yudao@2024 # OpenGauss 连接的示例
64 slave: # 模拟从库,可根据自己需要修改 64 slave: # 模拟从库,可根据自己需要修改
65 lazy: true # 开启懒加载,保证启动速度 65 lazy: true # 开启懒加载,保证启动速度
66 - url: jdbc:mysql://chaojiniu.top:23306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true  
67 - username: ruoyi-vue-pro  
68 - password: ruoyi-@h2ju02hebp  
69 - tdengine: # IOT 数据库  
70 -# lazy: true # 开启懒加载,保证启动速度  
71 - url: jdbc:TAOS-RS://chaojiniu.top:6041/ruoyi_vue_pro  
72 - driver-class-name: com.taosdata.jdbc.rs.RestfulDriver 66 + url: jdbc:mysql://127.0.0.1:3307/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
73 username: root 67 username: root
74 - password: taosdata  
75 - druid:  
76 - validation-query: SELECT SERVER_STATUS() # TDengine 数据源的有效性检查 SQL 68 + password: ahh@123456
77 69
78 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 70 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
79 data: 71 data:
80 redis: 72 redis:
81 - host: chaojiniu.top # 地址 73 + host: 127.0.0.1 # 地址
82 port: 6379 # 端口 74 port: 6379 # 端口
83 - database: 15 # 数据库索引  
84 - password: fsknKD7UvQYZsyf2hXXn # 密码,建议生产环境开启 75 + database: 0 # 数据库索引
  76 +# password: dev # 密码,建议生产环境开启
85 77
86 --- #################### 定时任务相关配置 #################### 78 --- #################### 定时任务相关配置 ####################
87 79
@@ -191,12 +183,12 @@ debug: false @@ -191,12 +183,12 @@ debug: false
191 --- #################### 微信公众号、小程序相关配置 #################### 183 --- #################### 微信公众号、小程序相关配置 ####################
192 wx: 184 wx:
193 mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 185 mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档
194 -# app-id: wx041349c6f39b268b # 测试号(牛希尧提供的)  
195 -# secret: 5abee519483bc9f8cb37ce280e814bd0 186 + # app-id: wx041349c6f39b268b # 测试号(牛希尧提供的)
  187 + # secret: 5abee519483bc9f8cb37ce280e814bd0
196 app-id: wx5b23ba7a5589ecbb # 测试号(自己的) 188 app-id: wx5b23ba7a5589ecbb # 测试号(自己的)
197 secret: 2a7b3b20c537e52e74afd395eb85f61f 189 secret: 2a7b3b20c537e52e74afd395eb85f61f
198 -# app-id: wxa69ab825b163be19 # 测试号(Kongdy 提供的)  
199 -# secret: bd4f9fab889591b62aeac0d7b8d8b4a0 190 + # app-id: wxa69ab825b163be19 # 测试号(Kongdy 提供的)
  191 + # secret: bd4f9fab889591b62aeac0d7b8d8b4a0
200 # 存储配置,解决 AccessToken 的跨节点的共享 192 # 存储配置,解决 AccessToken 的跨节点的共享
201 config-storage: 193 config-storage:
202 type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 194 type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
@@ -205,10 +197,10 @@ wx: @@ -205,10 +197,10 @@ wx:
205 miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档 197 miniapp: # 小程序配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-miniapp-spring-boot-starter/README.md 文档
206 # appid: wx62056c0d5e8db250 # 测试号(牛希尧提供的) 198 # appid: wx62056c0d5e8db250 # 测试号(牛希尧提供的)
207 # secret: 333ae72f41552af1e998fe1f54e1584a 199 # secret: 333ae72f41552af1e998fe1f54e1584a
208 -# appid: wx63c280fe3248a3e7 # wenhualian的接口测试号  
209 -# secret: 6f270509224a7ae1296bbf1c8cb97aed  
210 -# appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的)  
211 -# secret: 4a1a04e07f6a4a0751b39c3064a92c8b 200 + # appid: wx63c280fe3248a3e7 # wenhualian的接口测试号
  201 + # secret: 6f270509224a7ae1296bbf1c8cb97aed
  202 + # appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的)
  203 + # secret: 4a1a04e07f6a4a0751b39c3064a92c8b
212 appid: wx66186af0759f47c9 # 测试号(puhui 提供的) 204 appid: wx66186af0759f47c9 # 测试号(puhui 提供的)
213 secret: 3218bcbd112cbc614c7264ceb20144ac 205 secret: 3218bcbd112cbc614c7264ceb20144ac
214 config-storage: 206 config-storage:
@@ -267,7 +259,7 @@ justauth: @@ -267,7 +259,7 @@ justauth:
267 iot: 259 iot:
268 emq: 260 emq:
269 # 账号 261 # 账号
270 - username: haohao 262 + username: anhaohao
271 # 密码 263 # 密码
272 password: ahh@123456 264 password: ahh@123456
273 # 主机地址 265 # 主机地址
@@ -279,18 +271,4 @@ iot: @@ -279,18 +271,4 @@ iot:
279 # 保持连接 271 # 保持连接
280 keepalive: 60 272 keepalive: 60
281 # 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息) 273 # 清除会话(设置为false,断开连接,重连后使用原来的会话 保留订阅的主题,能接收离线期间的消息)
282 - clearSession: true  
283 -  
284 -# MQTT-RPC 配置  
285 -mqtt:  
286 - broker: tcp://chaojiniu.top:1883  
287 - username: haohao  
288 - password: ahh@123456  
289 - clientId: mqtt-rpc-server-${random.int}  
290 - requestTopic: rpc/request  
291 - responseTopicPrefix: rpc/response/  
292 -  
293 -  
294 -# 插件配置  
295 -pf4j:  
296 - pluginsDir: /Users/anhaohao/code/gitee/ruoyi-vue-pro/plugins # 插件目录  
297 \ No newline at end of file 274 \ No newline at end of file
  275 + clearSession: true
298 \ No newline at end of file 276 \ No newline at end of file