Commit deab8c1cc6bb7864d9c40e0c369f649f6f9bfa41

Authored by YunaiV
1 parent 16120820

【代码评审】IoT:设备日志 TDengine 表与模拟设备

Showing 18 changed files with 89 additions and 86 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 3 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6   -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceSaveReqVO;
7 6 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.*;
8 7 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
9 8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
... ... @@ -13,7 +12,6 @@ import io.swagger.v3.oas.annotations.Operation;
13 12 import io.swagger.v3.oas.annotations.tags.Tag;
14 13 import jakarta.annotation.Resource;
15 14 import jakarta.validation.Valid;
16   -import org.springframework.security.access.prepost.PreAuthorize;
17 15 import org.springframework.validation.annotation.Validated;
18 16 import org.springframework.web.bind.annotation.*;
19 17  
... ... @@ -34,7 +32,7 @@ public class IotDeviceDataController {
34 32 @Resource
35 33 private IotDeviceLogDataService iotDeviceLogDataService;
36 34  
37   - @Resource
  35 + @Resource // TODO @super:service 之间,不用空行;原因是,这样更简洁;空行,主要是为了“间隔”,提升可读性
38 36 private IotDeviceLogDataService deviceLogDataService;
39 37  
40 38 // TODO @浩浩:这里的 /latest-list,包括方法名。
... ... @@ -52,14 +50,17 @@ public class IotDeviceDataController {
52 50 PageResult<Map<String, Object>> list = deviceDataService.getHistoryDeviceProperties(deviceDataReqVO);
53 51 return success(BeanUtils.toBean(list, IotTimeDataRespVO.class));
54 52 }
  53 +
55 54 // TODO:数据权限
56 55 @PostMapping("/simulator")
57 56 @Operation(summary = "模拟设备")
58 57 public CommonResult<Boolean> simulatorDevice(@Valid @RequestBody IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
59 58 //TODO:先生成一下设备日志 后续完善模拟设备代码逻辑
  59 + // TODO @super:应该 deviceDataService 里面有个 simulatorDevice,然后里面去 insert 日志!
60 60 iotDeviceLogDataService.createDeviceLog(simulatorReqVO);
61 61 return success(true);
62 62 }
  63 +
63 64 // TODO:数据权限
64 65 @GetMapping("/log/page")
65 66 @Operation(summary = "获得设备日志分页")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java
... ... @@ -14,7 +14,7 @@ public class IotDeviceSaveReqVO {
14 14 private Long id;
15 15  
16 16 @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.AUTO, example = "177")
17   - @Size(max = 50, message = "设备编号长度不能超过50个字符")
  17 + @Size(max = 50, message = "设备编号长度不能超过 50 个字符")
18 18 private String deviceKey;
19 19  
20 20 @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceDataSimulatorSaveReqVO.java
... ... @@ -3,27 +3,27 @@ package cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData;
3 3 import io.swagger.v3.oas.annotations.media.Schema;
4 4 import jakarta.validation.constraints.NotEmpty;
5 5 import lombok.Data;
6   -import org.springframework.format.annotation.DateTimeFormat;
7   -
8   -import java.time.LocalDateTime;
9   -
10   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
11 6  
  7 +// TODO super: SaveReqVO => ReqVO
12 8 @Schema(description = "管理后台 - IoT 模拟设备数据 Request VO")
13 9 @Data
14 10 public class IotDeviceDataSimulatorSaveReqVO {
15 11  
16   - @Schema(description = "消息ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "msg123")
  12 + // TODO @super:感觉后端随机更合适?
  13 + @Schema(description = "消息 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "msg123")
17 14 private String id;
18 15  
  16 + // TODO @super:不用传递 productKey,因为 deviceKey 可以推导出来
19 17 @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123")
20 18 @NotEmpty(message = "产品ID不能为空")
21 19 private String productKey;
22 20  
  21 + // TODO @super:中文写作规范,中英文之间,要有空格。例如说,设备 ID。ps:这里应该是设备标识
23 22 @Schema(description = "设备ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123")
24 23 @NotEmpty(message = "设备ID不能为空")
25 24 private String deviceKey;
26 25  
  26 + // TODO @super:type、subType,是不是不用传递,因为模拟只有属性???
27 27 @Schema(description = "消息/日志类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property")
28 28 @NotEmpty(message = "消息类型不能为空")
29 29 private String type;
... ... @@ -36,6 +36,7 @@ public class IotDeviceDataSimulatorSaveReqVO {
36 36 @NotEmpty(message = "数据内容不能为空")
37 37 private String content;
38 38  
  39 + // TODO @芋艿:需要讨论下,reportTime 到底以那个为准!
39 40 @Schema(description = "上报时间", requiredMode = Schema.RequiredMode.REQUIRED)
40 41 private Long reportTime;
41 42  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceLogPageReqVO.java
... ... @@ -18,13 +18,16 @@ public class IotDeviceLogPageReqVO extends PageParam {
18 18 @NotEmpty(message = "设备标识不能为空")
19 19 private String deviceKey;
20 20  
  21 + // TODO @super:对应的枚举类
21 22 @Schema(description = "消息类型", example = "property")
22 23 private String type;
23 24  
24 25 @Schema(description = "标识符", example = "temperature")
  26 + // TODO @super:对应的枚举类
25 27 private String subType;
26 28  
27 29 @Schema(description = "创建时间")
28 30 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
29 31 private LocalDateTime[] createTime;
30   -}
31 32 \ No newline at end of file
  33 +
  34 +}
32 35 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/deviceData/IotDeviceLogRespVO.java
... ... @@ -11,8 +11,10 @@ public class IotDeviceLogRespVO {
11 11  
12 12 @Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
13 13 private String id;
  14 +
14 15 @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "product123")
15 16 private String productKey;
  17 +
16 18 @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "device123")
17 19 private String deviceKey;
18 20  
... ... @@ -30,4 +32,5 @@ public class IotDeviceLogRespVO {
30 32  
31 33 @Schema(description = "记录时间戳", requiredMode = Schema.RequiredMode.REQUIRED)
32 34 private LocalDateTime ts;
33   -}
34 35 \ No newline at end of file
  36 +
  37 +}
35 38 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/IotThingModelController.java
... ... @@ -74,6 +74,7 @@ public class IotThingModelController {
74 74 return success(IotThingModelConvert.INSTANCE.convertList(list));
75 75 }
76 76  
  77 + // TODO @puhui @super:getThingModelListByProductId 和 getThingModelListByProductId 可以融合么?
77 78 @GetMapping("/list")
78 79 @Operation(summary = "获得产品物模型列表")
79 80 @PreAuthorize("@ss.hasPermission('iot:thing-model:query')")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/thingmodel/vo/IotThingModelListReqVO.java
... ... @@ -6,11 +6,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
6 6 import jakarta.validation.constraints.NotNull;
7 7 import lombok.Data;
8 8  
9   -
10   -
11 9 @Schema(description = "管理后台 - IoT 产品物模型List Request VO")
12 10 @Data
13 11 public class IotThingModelListReqVO {
  12 +
14 13 @Schema(description = "功能标识")
15 14 private String identifier;
16 15  
... ... @@ -21,7 +20,8 @@ public class IotThingModelListReqVO {
21 20 @InEnum(IotThingModelTypeEnum.class)
22 21 private Integer type;
23 22  
24   - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED)
25   - @NotNull(message = "产品ID不能为空")
  23 + @Schema(description = "产品 ID", requiredMode = Schema.RequiredMode.REQUIRED)
  24 + @NotNull(message = "产品 ID 不能为空")
26 25 private Long productId;
  26 +
27 27 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceLogDO.java
1 1 package cn.iocoder.yudao.module.iot.dal.dataobject.device;
2 2  
3   -import cn.hutool.core.date.DateTime;
4 3 import lombok.AllArgsConstructor;
5 4 import lombok.Builder;
6 5 import lombok.Data;
7 6 import lombok.NoArgsConstructor;
8 7  
9   -import java.time.LocalDateTime;
10   -
11 8 /**
12 9 * IoT 设备日志数据 DO
13 10 *
  11 + * 目前使用 TDengine 存储
  12 + *
14 13 * @author alwayssuper
15 14 */
16 15 @Data
... ... @@ -18,33 +17,41 @@ import java.time.LocalDateTime;
18 17 @NoArgsConstructor
19 18 @AllArgsConstructor
20 19 public class IotDeviceLogDO {
  20 +
  21 + // TODO @芋艿:消息 ID 的生成逻辑
21 22 /**
22   - * 消息ID
  23 + * 消息 ID
23 24 */
24 25 private String id;
25 26  
  27 + // TODO @super:关联要 @下
26 28 /**
27   - * 产品ID
  29 + * 产品标识
28 30 */
29 31 private String productKey;
30 32  
  33 + // TODO @super:关联要 @下
31 34 /**
32   - * 设备ID
  35 + * 设备标识
33 36 */
34 37 private String deviceKey;
35 38  
  39 + // TODO @super:枚举类
36 40 /**
37   - * 消息/日志类型
  41 + * 日志类型
38 42 */
39 43 private String type;
40 44  
  45 + // TODO @super:枚举类
41 46 /**
42 47 * 标识符:用于标识具体的属性、事件或服务
43 48 */
44 49 private String subType;
45 50  
46 51 /**
47   - * 数据内容:存储具体的消息数据内容,通常是JSON格式
  52 + * 数据内容
  53 + *
  54 + * 存储具体的消息数据内容,通常是 JSON 格式
48 55 */
49 56 private String content;
50 57  
... ... @@ -58,5 +65,4 @@ public class IotDeviceLogDO {
58 65 */
59 66 private Long ts;
60 67  
61   -
62 68 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java
... ... @@ -6,7 +6,7 @@ import lombok.Data;
6 6 import lombok.NoArgsConstructor;
7 7  
8 8 // TODO @芋艿:纠结下字段
9   -@Deprecated
  9 +@Deprecated // TODO @super:看看啥时候删除下哈。
10 10 /**
11 11 * TD 物模型消息日志的数据库
12 12 */
... ... @@ -25,7 +25,7 @@ public class ThingModelMessageDO {
25 25  
26 26 /**
27 27 * 系统扩展参数
28   - *
  28 + *
29 29 * 例如:设备状态、系统时间、固件版本等系统级信息
30 30 */
31 31 private Object system;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDeviceLogDataMapper.java
1 1 package cn.iocoder.yudao.module.iot.dal.tdengine;
2 2  
3   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 3 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceLogPageReqVO;
5 4 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO;
6 5 import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
... ... @@ -12,7 +11,7 @@ import java.util.List;
12 11  
13 12 /**
14 13 * IOT 设备日志数据 Mapper 接口
15   - *
  14 + *
16 15 * 基于 TDengine 实现设备日志的存储
17 16 */
18 17 @Mapper
... ... @@ -22,11 +21,12 @@ public interface IotDeviceLogDataMapper {
22 21  
23 22 /**
24 23 * 创建设备日志超级表
25   - *
  24 + *
26 25 * 注意:初始化时只需创建一次
27 26 */
28 27 void createDeviceLogSTable();
29 28  
  29 + // TODO @super:是不是删除哈
30 30 /**
31 31 * 创建设备日志子表
32 32 *
... ... @@ -34,11 +34,12 @@ public interface IotDeviceLogDataMapper {
34 34 */
35 35 void createDeviceLogTable(@Param("deviceKey") String deviceKey);
36 36  
  37 + // TODO @super:单个参数,不用加 @Param
37 38 /**
38 39 * 插入设备日志数据
39   - *
  40 + *
40 41 * 如果子表不存在,会自动创建子表
41   - *
  42 + *
42 43 * @param log 设备日志数据
43 44 */
44 45 void insert(@Param("log") IotDeviceLogDO log);
... ... @@ -58,4 +59,5 @@ public interface IotDeviceLogDataMapper {
58 59 * @return 日志总数
59 60 */
60 61 Long selectCount(@Param("reqVO") IotDeviceLogPageReqVO reqVO);
  62 +
61 63 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdThingModelMessageMapper.java
1 1 package cn.iocoder.yudao.module.iot.dal.tdengine;
2 2  
3   -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
4   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
5   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessageDO;
6 3 import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
7   -import com.baomidou.dynamic.datasource.annotation.DS;
8 4 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
9 5 import org.apache.ibatis.annotations.Mapper;
10 6 import org.apache.ibatis.annotations.Param;
... ... @@ -13,7 +9,7 @@ import org.apache.ibatis.annotations.Param;
13 9 * 处理 TD 中物模型消息日志的操作
14 10 */
15 11 @Mapper
16   -@Deprecated
  12 +@Deprecated // TODO super:什么时候,删除下哈。
17 13 @TDengineDS
18 14 @InterceptorIgnore(tenantLine = "true") // 避免 SQL 解析,因为 JSqlParser 对 TDengine 的 SQL 解析会报错
19 15 public interface TdThingModelMessageMapper {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java
... ... @@ -16,7 +16,7 @@ import org.springframework.core.annotation.Order;
16 16 @Slf4j
17 17 @RequiredArgsConstructor
18 18 @Configuration
19   -@Order(Integer.MAX_VALUE) // 保证在最后执行
  19 +@Order
20 20 public class TDengineTableInitConfiguration implements ApplicationRunner {
21 21  
22 22 private final IotDeviceLogDataService deviceLogService;
... ... @@ -26,15 +26,18 @@ public class TDengineTableInitConfiguration implements ApplicationRunner {
26 26 try {
27 27 // 初始化设备日志表
28 28 deviceLogService.initTDengineSTable();
29   - log.info("初始化 设备日志表 TDengine 表结构成功");
  29 + // TODO @super:这个日志,是不是不用打,不然重复啦!!!
  30 + log.info("[run]初始化 设备日志表 TDengine 表结构成功");
30 31 } catch (Exception ex) {
  32 + // TODO @super:初始化失败,打印 error 日志,退出系统。。不然跑起来,就初始啦!!!
31 33 if (ex.getMessage().contains("Table already exists")) {
32 34 log.info("TDengine 设备日志超级表已存在,跳过创建");
33 35 return;
34   - }else{
  36 + } else{
35 37 log.error("初始化 设备日志表 TDengine 表结构失败", ex);
36 38 }
37 39 throw ex;
38 40 }
39 41 }
  42 +
40 43 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataService.java
... ... @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDevi
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 7  
8   -
9 8 /**
10 9 * IoT 设备日志数据 Service 接口
11 10 *
... ... @@ -15,7 +14,7 @@ public interface IotDeviceLogDataService {
15 14  
16 15 /**
17 16 * 初始化 TDengine 超级表
18   - *
  17 + *
19 18 *系统启动时,会自动初始化一次
20 19 */
21 20 void initTDengineSTable();
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceLogDataServiceImpl.java
1 1 package cn.iocoder.yudao.module.iot.service.device;
2 2  
3   -import cn.hutool.core.date.DateTime;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 4 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 5 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.deviceData.IotDeviceDataSimulatorSaveReqVO;
... ... @@ -12,8 +11,6 @@ import lombok.extern.slf4j.Slf4j;
12 11 import org.springframework.stereotype.Service;
13 12 import org.springframework.validation.annotation.Validated;
14 13  
15   -import java.time.LocalDateTime;
16   -import java.time.ZoneId;
17 14 import java.util.List;
18 15  
19 16 /**
... ... @@ -29,34 +26,30 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
29 26 @Resource
30 27 private IotDeviceLogDataMapper iotDeviceLogDataMapper;
31 28  
32   -
  29 + // TODO @super:方法名。defineDeviceLog。。未来,有可能别人使用别的记录日志,例如说 es 之类的。
33 30 @Override
34 31 public void initTDengineSTable() {
35   - try {
36   - // 创建设备日志超级表
37   - iotDeviceLogDataMapper.createDeviceLogSTable();
38   - log.info("创建设备日志超级表成功");
39   - } catch (Exception ex) {
40   - throw ex;
41   - }
  32 + // TODO @super:改成不存在才创建。
  33 + iotDeviceLogDataMapper.createDeviceLogSTable();
42 34 }
43 35  
44 36 @Override
45 37 public void createDeviceLog(IotDeviceDataSimulatorSaveReqVO simulatorReqVO) {
46   - //TODO:讨论一下,iotkit这块TS和上报时间都是外部传入的 但是看TDengine文档 他是建议对TS在SQL中直接NOW 咱们的TS数据获取是走哪一种
47   -
48 38 // 1. 转换请求对象为 DO
49 39 IotDeviceLogDO iotDeviceLogDO = BeanUtils.toBean(simulatorReqVO, IotDeviceLogDO.class);
50   -
  40 +
51 41 // 2. 处理时间字段
  42 + // TODO @super:一次性的字段,不用单独给个变量
52 43 long currentTime = System.currentTimeMillis();
53 44 // 2.1 设置时序时间为当前时间
54   - iotDeviceLogDO.setTs(currentTime);
  45 + iotDeviceLogDO.setTs(currentTime); // TODO @super:TS在SQL中直接NOW 咱们的TS数据获取是走哪一种;走 now()
55 46  
56 47 // 3. 插入数据
  48 + // TODO @super:不要直接调用对方的 IotDeviceLogDataMapper,通过 service 哈!
57 49 iotDeviceLogDataMapper.insert(iotDeviceLogDO);
58 50 }
59 51  
  52 + // TODO @super:在 iotDeviceLogDataService 写
60 53 @Override
61 54 public PageResult<IotDeviceLogDO> getDeviceLogPage(IotDeviceLogPageReqVO pageReqVO) {
62 55 // 查询数据
... ... @@ -65,4 +58,5 @@ public class IotDeviceLogDataServiceImpl implements IotDeviceLogDataService{
65 58 // 构造分页结果
66 59 return new PageResult<>(list, total);
67 60 }
  61 +
68 62 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDevicePropertyDataServiceImpl.java
... ... @@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
18 18 import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
19 19 import cn.iocoder.yudao.module.iot.dal.tdengine.IotDevicePropertyDataMapper;
20 20 import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
21   -import cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper;
22 21 import cn.iocoder.yudao.module.iot.enums.IotConstants;
23 22 import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum;
24 23 import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
... ... @@ -111,7 +110,6 @@ public class IotDevicePropertyDataServiceImpl implements IotDevicePropertyDataSe
111 110 return;
112 111 }
113 112 newFields.add(0, new TDengineTableField(TDengineTableField.FIELD_TS, TDengineTableField.TYPE_TIMESTAMP));
114   - // 2.1.1 创建产品超级表
115 113 devicePropertyDataMapper.createProductPropertySTable(product.getProductKey(), newFields);
116 114 return;
117 115 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
... ... @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
9 9 import cn.iocoder.yudao.module.iot.dal.mysql.product.IotProductMapper;
10 10 import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
11 11 import cn.iocoder.yudao.module.iot.service.device.IotDevicePropertyDataService;
12   -import cn.iocoder.yudao.module.iot.service.tdengine.IotThingModelMessageService;
13 12 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
14 13 import jakarta.annotation.Resource;
15 14 import org.springframework.context.annotation.Lazy;
... ... @@ -116,14 +115,15 @@ public class IotProductServiceImpl implements IotProductService {
116 115 public void updateProductStatus(Long id, Integer status) {
117 116 // 1. 校验存在
118 117 validateProductExists(id);
119   - // 2. 更新
120   - IotProductDO updateObj = IotProductDO.builder().id(id).status(status).build();
121   - // 3. 产品是发布状态
  118 +
  119 + // 2. 产品是发布状态
122 120 if (Objects.equals(status, IotProductStatusEnum.PUBLISHED.getStatus())) {
123   - // 3.1 创建产品超级表数据模型
  121 + // 创建产品超级表数据模型
124 122 devicePropertyDataService.defineDevicePropertyData(id);
125   -
126 123 }
  124 +
  125 + // 3. 更新
  126 + IotProductDO updateObj = IotProductDO.builder().id(id).status(status).build();
127 127 productMapper.updateById(updateObj);
128 128 }
129 129  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/tdengine/IotThingModelMessageServiceImpl.java
... ... @@ -7,20 +7,20 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
7 7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.IotDeviceStatusUpdateReqVO;
8 8 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
9 9 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDataDO;
10   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.*;
  10 +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.FieldParser;
  11 +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdFieldDO;
  12 +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
  13 +import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.ThingModelMessage;
11 14 import cn.iocoder.yudao.module.iot.dal.dataobject.thingmodel.IotThingModelDO;
12   -import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
13 15 import cn.iocoder.yudao.module.iot.dal.redis.deviceData.DeviceDataRedisDAO;
14 16 import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper;
15 17 import cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper;
16   -import cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper;
17 18 import cn.iocoder.yudao.module.iot.enums.IotConstants;
18 19 import cn.iocoder.yudao.module.iot.enums.device.IotDeviceStatusEnum;
19 20 import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
20 21 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
21   -import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
22 22 import cn.iocoder.yudao.module.iot.service.product.IotProductService;
23   -import cn.iocoder.yudao.module.iot.util.IotTdDatabaseUtils;
  23 +import cn.iocoder.yudao.module.iot.service.thingmodel.IotThingModelService;
24 24 import jakarta.annotation.Resource;
25 25 import lombok.extern.slf4j.Slf4j;
26 26 import org.springframework.beans.factory.annotation.Value;
... ... @@ -62,12 +62,8 @@ public class IotThingModelMessageServiceImpl implements IotThingModelMessageServ
62 62 private TdEngineDMLMapper tdEngineDMLMapper;
63 63  
64 64 @Resource
65   - private TdThingModelMessageMapper tdThingModelMessageMapper;
66   -
67   - @Resource
68 65 private DeviceDataRedisDAO deviceDataRedisDAO;
69   -
70   -
  66 +
71 67 // TODO @haohao:这个方法,可以考虑加下 1. 2. 3. 更有层次感
72 68 @Override
73 69 @TenantIgnore
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDeviceLogDataMapper.xml
... ... @@ -7,19 +7,19 @@
7 7 <!-- 创建设备日志超级表 初始化只创建一次-->
8 8 <update id="createDeviceLogSTable">
9 9 CREATE STABLE device_log (
10   - ts TIMESTAMP,
11   - id NCHAR(50),
12   - product_key NCHAR(50),
13   - type NCHAR(50),
14   - subType NCHAR(50),
15   - content NCHAR(1024),
16   - report_time TIMESTAMP
17   - )TAGS (
18   - device_key NCHAR(50)
19   - )
  10 + ts TIMESTAMP,
  11 + id NCHAR(50),
  12 + product_key NCHAR(50),
  13 + type NCHAR(50),
  14 + <!-- TODO @super:下划线 sub_type -->
  15 + subType NCHAR(50),
  16 + content NCHAR(1024),
  17 + report_time TIMESTAMP
  18 + ) TAGS (
  19 + device_key NCHAR(50)
  20 + )
20 21 </update>
21 22  
22   -
23 23 <!-- 创建设备日志子表 讨论:TDengine 在子表不存在的情况下 可在数据插入时 自动建表 要不要去掉创建子表的逻辑 由第一次插入数据时自动创建-->
24 24 <update id="createDeviceLogTable">
25 25 CREATE TABLE device_log_${deviceKey} USING device_log TAGS('${deviceKey}')
... ...