Commit 10334f3fb69271ebacfeed4e1297aa6c0dcc30d9

Authored by YunaiV
1 parent c7b1cc9a

【代码评审】IOT:产品的管理

Showing 28 changed files with 135 additions and 281 deletions
yudao-dependencies/pom.xml
... ... @@ -622,7 +622,7 @@
622 622 <version>${xercesImpl.version}</version>
623 623 </dependency>
624 624  
625   - <!-- mqtt -->
  625 + <!-- MQTT -->
626 626 <dependency>
627 627 <groupId>org.eclipse.paho</groupId>
628 628 <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
... ...
yudao-module-iot/pom.xml
... ... @@ -19,6 +19,7 @@
19 19 <name>${project.artifactId}</name>
20 20 <description>
21 21 物联网模块
  22 + <!-- TODO 芋艿:需要补充下说明! -->
22 23 </description>
23 24  
24 25 </project>
25 26 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/api/package-info.java
1 1 /**
2   - * iot API 包,定义暴露给其它模块的 API
  2 + * 占位
  3 + *
  4 + * TODO 芋艿:后续删除
3 5 */
4 6 package cn.iocoder.yudao.module.iot.api;
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotDataFormatEnum.java
... ... @@ -8,7 +8,9 @@ import java.util.Arrays;
8 8  
9 9 /**
10 10 * 产品数据格式枚举类
11   - * 数据格式, 0: 标准数据格式(JSON), 1: 透传/自定义
  11 + *
  12 + * @author ahh
  13 + * @see <a href="https://help.aliyun.com/zh/iot/user-guide/message-parsing">阿里云 - 什么是消息解析</a>
12 14 */
13 15 @AllArgsConstructor
14 16 @Getter
... ... @@ -17,18 +19,17 @@ public enum IotDataFormatEnum implements IntArrayValuable {
17 19 JSON(0, "标准数据格式(JSON)"),
18 20 CUSTOMIZE(1, "透传/自定义");
19 21  
  22 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotDataFormatEnum::getType).toArray();
  23 +
20 24 /**
21 25 * 类型
22 26 */
23 27 private final Integer type;
24   -
25 28 /**
26 29 * 描述
27 30 */
28 31 private final String description;
29 32  
30   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotDataFormatEnum::getType).toArray();
31   -
32 33 @Override
33 34 public int[] array() {
34 35 return ARRAYS;
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotNetTypeEnum.java
... ... @@ -8,7 +8,8 @@ import java.util.Arrays;
8 8  
9 9 /**
10 10 * IOT 联网方式枚举类
11   - * 联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他
  11 + *
  12 + * @author ahh
12 13 */
13 14 @AllArgsConstructor
14 15 @Getter
... ... @@ -19,19 +20,17 @@ public enum IotNetTypeEnum implements IntArrayValuable {
19 20 ETHERNET(2, "Ethernet"),
20 21 OTHER(3, "其他");
21 22  
  23 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotNetTypeEnum::getType).toArray();
22 24  
23 25 /**
24 26 * 类型
25 27 */
26 28 private final Integer type;
27   -
28 29 /**
29 30 * 描述
30 31 */
31 32 private final String description;
32 33  
33   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotNetTypeEnum::getType).toArray();
34   -
35 34 @Override
36 35 public int[] array() {
37 36 return ARRAYS;
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductDeviceTypeEnum.java
... ... @@ -7,8 +7,9 @@ import lombok.Getter;
7 7 import java.util.Arrays;
8 8  
9 9 /**
10   - * IOT 产品设备类型
11   - * 设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备
  10 + * IOT 产品的设备类型
  11 + *
  12 + * @author ahh
12 13 */
13 14 @AllArgsConstructor
14 15 @Getter
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java
... ... @@ -4,9 +4,12 @@ import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
4 4 import lombok.AllArgsConstructor;
5 5 import lombok.Getter;
6 6  
  7 +import java.util.Arrays;
  8 +
7 9 /**
8   - * IOT 产品状态枚举类
9   - * 产品状态, 0: 开发中, 1: 已发布
  10 + * IOT 产品的状态枚举类
  11 + *
  12 + * @author ahh
10 13 */
11 14 @AllArgsConstructor
12 15 @Getter
... ... @@ -15,20 +18,20 @@ public enum IotProductStatusEnum implements IntArrayValuable {
15 18 UNPUBLISHED(0, "开发中"),
16 19 PUBLISHED(1, "已发布");
17 20  
  21 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductStatusEnum::getType).toArray();
  22 +
18 23 /**
19 24 * 类型
20 25 */
21 26 private final Integer type;
22   -
23 27 /**
24 28 * 描述
25 29 */
26 30 private final String description;
27 31  
28   - public static final int[] ARRAYS = {1, 2};
29   -
30 32 @Override
31 33 public int[] array() {
32 34 return ARRAYS;
33 35 }
  36 +
34 37 }
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProtocolTypeEnum.java
... ... @@ -8,7 +8,8 @@ import java.util.Arrays;
8 8  
9 9 /**
10 10 * IOT 接入网关协议枚举类
11   - * 接入网关协议, 0: 自定义, 1: Modbus, 2: OPC UA, 3: ZigBee, 4: BLE
  11 + *
  12 + * @author ahh
12 13 */
13 14 @AllArgsConstructor
14 15 @Getter
... ... @@ -20,19 +21,17 @@ public enum IotProtocolTypeEnum implements IntArrayValuable {
20 21 ZIGBEE(3, "ZigBee"),
21 22 BLE(4, "BLE");
22 23  
  24 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProtocolTypeEnum::getType).toArray();
23 25  
24 26 /**
25 27 * 类型
26 28 */
27 29 private final Integer type;
28   -
29 30 /**
30 31 * 描述
31 32 */
32 33 private final String description;
33 34  
34   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProtocolTypeEnum::getType).toArray();
35   -
36 35 @Override
37 36 public int[] array() {
38 37 return ARRAYS;
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotValidateTypeEnum.java
... ... @@ -8,7 +8,8 @@ import java.util.Arrays;
8 8  
9 9 /**
10 10 * IOT 数据校验级别枚举类
11   - * 数据校验级别, 0: 弱校验, 1: 免校验
  11 + *
  12 + * @author ahh
12 13 */
13 14 @AllArgsConstructor
14 15 @Getter
... ... @@ -17,19 +18,17 @@ public enum IotValidateTypeEnum implements IntArrayValuable {
17 18 WEAK(0, "弱校验"),
18 19 NONE(1, "免校验");
19 20  
  21 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotValidateTypeEnum::getType).toArray();
20 22  
21 23 /**
22 24 * 类型
23 25 */
24 26 private final Integer type;
25   -
26 27 /**
27 28 * 描述
28 29 */
29 30 private final String description;
30 31  
31   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotValidateTypeEnum::getType).toArray();
32   -
33 32 @Override
34 33 public int[] array() {
35 34 return ARRAYS;
... ...
yudao-module-iot/yudao-module-iot-biz/pom.xml
... ... @@ -15,9 +15,10 @@
15 15 <name>${project.artifactId}</name>
16 16 <description>
17 17 物联网 模块,主要实现 产品管理、设备管理、协议管理等功能。
  18 + <!-- TODO 芋艿:后续补充下 -->
18 19 </description>
19 20  
20   - <dependencies> <!-- 5. 新增依赖,这里引入的都是比较常用的业务组件、技术组件 -->
  21 + <dependencies>
21 22 <dependency>
22 23 <groupId>cn.iocoder.boot</groupId>
23 24 <artifactId>yudao-module-iot-api</artifactId>
... ... @@ -53,7 +54,7 @@
53 54 <artifactId>yudao-spring-boot-starter-excel</artifactId>
54 55 </dependency>
55 56  
56   - <!-- mqtt -->
  57 + <!-- MQTT -->
57 58 <dependency>
58 59 <groupId>org.eclipse.paho</groupId>
59 60 <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/ProductController.java
... ... @@ -27,6 +27,7 @@ import java.util.List;
27 27 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
28 28 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
29 29  
  30 +// TODO @haohao:Iot 前缀要加,不然很容易重复哈
30 31 @Tag(name = "管理后台 - IOT 产品")
31 32 @RestController
32 33 @RequestMapping("/iot/product")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductPageReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo;
2 2  
3   -import lombok.*;
4   -import java.util.*;
5   -import io.swagger.v3.oas.annotations.media.Schema;
6 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
7 8 import org.springframework.format.annotation.DateTimeFormat;
  9 +
8 10 import java.time.LocalDateTime;
9 11  
10 12 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
11 13  
  14 +// TODO @haohao:涉及到 iot 的拼写,要不都用 IoT,貌似更规范
  15 +// TODO 芋艿:需要清理掉一些无用字段
12 16 @Schema(description = "管理后台 - iot 产品分页 Request VO")
13 17 @Data
14 18 @EqualsAndHashCode(callSuper = true)
... ... @@ -25,6 +29,9 @@ public class ProductPageReqVO extends PageParam {
25 29 @Schema(description = "产品标识")
26 30 private String productKey;
27 31  
  32 + @Schema(description = "接入网关协议", example = "2")
  33 + private Integer protocolType;
  34 +
28 35 @Schema(description = "协议编号(脚本解析 id)", example = "13177")
29 36 private Long protocolId;
30 37  
... ... @@ -34,22 +41,19 @@ public class ProductPageReqVO extends PageParam {
34 41 @Schema(description = "产品描述", example = "你猜")
35 42 private String description;
36 43  
37   - @Schema(description = "数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验", example = "1")
  44 + @Schema(description = "数据校验级别", example = "1")
38 45 private Integer validateType;
39 46  
40   - @Schema(description = "产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS", example = "1")
  47 + @Schema(description = "产品状态", example = "1")
41 48 private Integer status;
42 49  
43   - @Schema(description = "设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备", example = "2")
  50 + @Schema(description = "设备类型", example = "2")
44 51 private Integer deviceType;
45 52  
46   - @Schema(description = "联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他", example = "2")
  53 + @Schema(description = "联网方式", example = "2")
47 54 private Integer netType;
48 55  
49   - @Schema(description = "接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee", example = "2")
50   - private Integer protocolType;
51   -
52   - @Schema(description = "数据格式, 0: 透传模式, 1: Alink JSON")
  56 + @Schema(description = "数据格式", example = "0")
53 57 private Integer dataFormat;
54 58  
55 59 }
56 60 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductRespVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo;
2 2  
  3 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  4 +import com.alibaba.excel.annotation.ExcelProperty;
3 5 import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.*;
5   -import java.util.*;
6   -import org.springframework.format.annotation.DateTimeFormat;
  6 +import lombok.Data;
  7 +
7 8 import java.time.LocalDateTime;
8   -import com.alibaba.excel.annotation.*;
9 9  
10 10 @Schema(description = "管理后台 - iot 产品 Response VO")
11 11 @Data
12 12 @ExcelIgnoreUnannotated
13 13 public class ProductRespVO {
14 14  
  15 + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26087")
  16 + @ExcelProperty("产品ID")
  17 + private Long id;
  18 +
15 19 @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
16 20 @ExcelProperty("产品名称")
17 21 private String name;
... ... @@ -20,14 +24,14 @@ public class ProductRespVO {
20 24 @ExcelProperty("创建时间")
21 25 private LocalDateTime createTime;
22 26  
23   - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26087")
24   - @ExcelProperty("产品ID")
25   - private Long id;
26   -
27 27 @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED)
28 28 @ExcelProperty("产品标识")
29 29 private String productKey;
30 30  
  31 + @Schema(description = "接入网关协议", example = "2")
  32 + @ExcelProperty("接入网关协议")
  33 + private Integer protocolType;
  34 +
31 35 @Schema(description = "协议编号(脚本解析 id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "13177")
32 36 @ExcelProperty("协议编号(脚本解析 id)")
33 37 private Long protocolId;
... ... @@ -40,28 +44,24 @@ public class ProductRespVO {
40 44 @ExcelProperty("产品描述")
41 45 private String description;
42 46  
43   - @Schema(description = "数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
44   - @ExcelProperty("数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验")
  47 + @Schema(description = "数据校验级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  48 + @ExcelProperty("数据校验级别")
45 49 private Integer validateType;
46 50  
47   - @Schema(description = "产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
48   - @ExcelProperty("产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS")
  51 + @Schema(description = "产品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  52 + @ExcelProperty("产品状态")
49 53 private Integer status;
50 54  
51   - @Schema(description = "设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
52   - @ExcelProperty("设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备")
  55 + @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  56 + @ExcelProperty("设备类型")
53 57 private Integer deviceType;
54 58  
55   - @Schema(description = "联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他", example = "2")
56   - @ExcelProperty("联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他")
  59 + @Schema(description = "联网方式", example = "2")
  60 + @ExcelProperty("联网方式")
57 61 private Integer netType;
58 62  
59   - @Schema(description = "接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee", example = "2")
60   - @ExcelProperty("接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee")
61   - private Integer protocolType;
62   -
63   - @Schema(description = "数据格式, 0: 透传模式, 1: Alink JSON")
64   - @ExcelProperty("数据格式, 0: 透传模式, 1: Alink JSON")
  63 + @Schema(description = "数据格式")
  64 + @ExcelProperty("数据格式")
65 65 private Integer dataFormat;
66 66  
67 67 }
68 68 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/product/ProductDO.java
1 1 package cn.iocoder.yudao.module.iot.dal.dataobject.product;
2 2  
3   -import lombok.*;
4   -import java.util.*;
5   -import java.time.LocalDateTime;
6   -import java.time.LocalDateTime;
7   -import com.baomidou.mybatisplus.annotation.*;
8 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
9 8  
10 9 /**
11 10 * iot 产品 DO
12 11 *
13   - * @author 芋道源码
  12 + * @author ahh
14 13 */
15 14 @TableName("iot_product")
16 15 @KeySequence("iot_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
... ... @@ -23,53 +22,72 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
23 22 public class ProductDO extends BaseDO {
24 23  
25 24 /**
26   - * 产品名称
27   - */
28   - private String name;
29   - /**
30 25 * 产品ID
31 26 */
32 27 @TableId
33 28 private Long id;
34 29 /**
35   - * 产品标识
  30 + * 产品名称
36 31 */
37   - private String productKey;
  32 + private String name;
  33 + // TODO @haohao:这个字段,要不改成 identifier,和阿里云更统一些
38 34 /**
39   - * 协议编号(脚本解析 id)
  35 + * 产品标识
40 36 */
41   - private Long protocolId;
  37 + private String productKey;
42 38 /**
43   - * 产品所属品类标识符
  39 + * 产品所属品类编号
  40 + *
  41 + * TODO 外键:后续加
44 42 */
45 43 private Long categoryId;
46 44 /**
47 45 * 产品描述
48 46 */
49 47 private String description;
  48 +
50 49 /**
51   - * 数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验
52   - */
53   - private Integer validateType;
54   - /**
55   - * 产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS
  50 + * 产品状态
  51 + *
  52 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum}
56 53 */
57 54 private Integer status;
58 55 /**
59   - * 设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备
  56 + * 设备类型
  57 + *
  58 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProductDeviceTypeEnum}
60 59 */
61 60 private Integer deviceType;
62 61 /**
63   - * 联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他
  62 + * 联网方式
  63 + *
  64 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotNetTypeEnum}
64 65 */
65 66 private Integer netType;
  67 +
66 68 /**
67   - * 接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee
  69 + * 接入网关协议
  70 + *
  71 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotProtocolTypeEnum}
68 72 */
69 73 private Integer protocolType;
70 74 /**
71   - * 数据格式, 0: 透传模式, 1: Alink JSON
  75 + * 协议编号
  76 + *
  77 + * TODO 外键:后续加
  78 + */
  79 + private Long protocolId;
  80 + /**
  81 + * 数据格式
  82 + *
  83 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotDataFormatEnum}
72 84 */
73 85 private Integer dataFormat;
  86 + /**
  87 + * 数据校验级别
  88 + *
  89 + * 枚举 {@link cn.iocoder.yudao.module.iot.enums.product.IotValidateTypeEnum}
  90 + */
  91 + private Integer validateType;
74 92  
75 93 }
76 94 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/ProductMapper.java
... ... @@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
10 10 /**
11 11 * iot 产品 Mapper
12 12 *
13   - * @author 芋道源码
  13 + * @author ahh
14 14 */
15 15 @Mapper
16 16 public interface ProductMapper extends BaseMapperX<ProductDO> {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/callback/EmqxCallback.java
... ... @@ -10,6 +10,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
10 10 import org.springframework.context.annotation.Lazy;
11 11 import org.springframework.stereotype.Component;
12 12  
  13 +// TODO @芋艿:详细再瞅瞅
13 14 /**
14 15 * 用于处理MQTT连接的回调,如连接断开、消息到达、消息发布完成、连接完成等事件。
15 16 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/config/MqttConfig.java
... ... @@ -4,6 +4,8 @@ import lombok.Data;
4 4 import org.springframework.boot.context.properties.ConfigurationProperties;
5 5 import org.springframework.stereotype.Component;
6 6  
  7 +// TODO @芋艿:详细再瞅瞅
  8 +
7 9 /**
8 10 * 配置类,用于读取MQTT连接的配置信息,如用户名、密码、连接地址等
9 11 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/service/EmqxService.java
... ... @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.iot.emq.service;
3 3 import org.eclipse.paho.client.mqttv3.MqttClient;
4 4 import org.eclipse.paho.client.mqttv3.MqttMessage;
5 5  
  6 +// TODO @芋艿:在瞅瞅
6 7 /**
7 8 * 用于处理MQTT消息的具体业务逻辑,如订阅回调
8 9 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/service/EmqxServiceImpl.java
... ... @@ -5,6 +5,8 @@ import org.eclipse.paho.client.mqttv3.MqttClient;
5 5 import org.eclipse.paho.client.mqttv3.MqttMessage;
6 6 import org.springframework.stereotype.Service;
7 7  
  8 +// TODO @芋艿:在瞅瞅
  9 +
8 10 /**
9 11 * 用于处理MQTT消息的具体业务逻辑,如订阅回调
10 12 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/emq/start/EmqxStart.java
... ... @@ -6,6 +6,8 @@ import org.springframework.boot.ApplicationArguments;
6 6 import org.springframework.boot.ApplicationRunner;
7 7 import org.springframework.stereotype.Component;
8 8  
  9 +// TODO @芋艿:在瞅瞅
  10 +
9 11 /**
10 12 * 用于在应用启动时自动连接MQTT服务器
11 13 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/package-info.java
1 1 /**
2 2 * 属于 iot 模块的 framework 封装
3 3 *
4   - * @author 芋道源码
  4 + * @author ahh
5 5 */
6 6 package cn.iocoder.yudao.module.iot.framework;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/web/config/IotWebConfiguration.java
... ... @@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
8 8 /**
9 9 * iot 模块的 web 组件的 Configuration
10 10 *
11   - * @author 芋道源码
  11 + * @author ahh
12 12 */
13 13 @Configuration(proxyBeanMethods = false)
14 14 public class IotWebConfiguration {
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductService.java
... ... @@ -9,7 +9,7 @@ import jakarta.validation.Valid;
9 9 /**
10 10 * IOT 产品 Service 接口
11 11 *
12   - * @author 芋道源码
  12 + * @author ahh
13 13 */
14 14 public interface ProductService {
15 15  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java
... ... @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_STATU
21 21 /**
22 22 * IOT 产品 Service 实现类
23 23 *
24   - * @author 芋道源码
  24 + * @author ahh
25 25 */
26 26 @Service
27 27 @Validated
... ... @@ -37,7 +37,6 @@ public class ProductServiceImpl implements ProductService {
37 37 // 插入
38 38 ProductDO product = BeanUtils.toBean(createReqVO, ProductDO.class);
39 39 productMapper.insert(product);
40   - // 返回
41 40 return product.getId();
42 41 }
43 42  
... ... @@ -47,6 +46,7 @@ public class ProductServiceImpl implements ProductService {
47 46 * @param createReqVO 创建信息
48 47 */
49 48 private void createProductKey(ProductSaveReqVO createReqVO) {
  49 + // TODO @haohao:应该前端没传递的时候,才生成哇?ps:需要校验下唯一性,万一有重复;
50 50 // 生成随机的 11 位字符串
51 51 String productKey = UUID.randomUUID().toString().replace("-", "").substring(0, 11);
52 52 createReqVO.setProductKey(productKey);
... ... @@ -54,8 +54,10 @@ public class ProductServiceImpl implements ProductService {
54 54  
55 55 @Override
56 56 public void updateProduct(ProductSaveReqVO updateReqVO) {
  57 + updateReqVO.setProductKey(null); // 不更新产品标识
57 58 // 校验存在
58 59 validateProductExists(updateReqVO.getId());
  60 + // TODO @haohao:如果已经发布,允许编辑么?
59 61 // 更新
60 62 ProductDO updateObj = BeanUtils.toBean(updateReqVO, ProductDO.class);
61 63 productMapper.updateById(updateObj);
... ... @@ -63,11 +65,12 @@ public class ProductServiceImpl implements ProductService {
63 65  
64 66 @Override
65 67 public void deleteProduct(Long id) {
66   - // 校验存在
  68 + // TODO @haohao:这里最好只查询一次哈
  69 + // 1.1 校验存在
67 70 validateProductExists(id);
68   - // 发布状态不可删除
  71 + // 1.2 发布状态不可删除
69 72 validateProductStatus(id);
70   - // 删除
  73 + // 2. 删除
71 74 productMapper.deleteById(id);
72 75 }
73 76  
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/product/ProductMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper">
4   -
5   - <!--
6   - 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
7   - 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
8   - 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
9   - 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
10   - -->
11   -
12   -</mapper>
13 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/test/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImplTest.java deleted
1   -package cn.iocoder.yudao.module.iot.service.product;
2   -
3   -import org.junit.jupiter.api.Disabled;
4   -import org.junit.jupiter.api.Test;
5   -import org.springframework.boot.test.mock.mockito.MockBean;
6   -
7   -import jakarta.annotation.Resource;
8   -
9   -import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
10   -
11   -import cn.iocoder.yudao.module.iot.controller.admin.product.vo.*;
12   -import cn.iocoder.yudao.module.iot.dal.dataobject.product.ProductDO;
13   -import cn.iocoder.yudao.module.iot.dal.mysql.product.ProductMapper;
14   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
15   -
16   -import jakarta.annotation.Resource;
17   -import org.springframework.context.annotation.Import;
18   -import java.util.*;
19   -import java.time.LocalDateTime;
20   -
21   -import static cn.hutool.core.util.RandomUtil.*;
22   -import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
23   -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
24   -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
25   -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
26   -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
27   -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
28   -import static org.junit.jupiter.api.Assertions.*;
29   -import static org.mockito.Mockito.*;
30   -
31   -/**
32   - * {@link ProductServiceImpl} 的单元测试类
33   - *
34   - * @author 芋道源码
35   - */
36   -@Import(ProductServiceImpl.class)
37   -public class ProductServiceImplTest extends BaseDbUnitTest {
38   -
39   - @Resource
40   - private ProductServiceImpl productService;
41   -
42   - @Resource
43   - private ProductMapper productMapper;
44   -
45   - @Test
46   - public void testCreateProduct_success() {
47   - // 准备参数
48   - ProductSaveReqVO createReqVO = randomPojo(ProductSaveReqVO.class).setId(null);
49   -
50   - // 调用
51   - Long productId = productService.createProduct(createReqVO);
52   - // 断言
53   - assertNotNull(productId);
54   - // 校验记录的属性是否正确
55   - ProductDO product = productMapper.selectById(productId);
56   - assertPojoEquals(createReqVO, product, "id");
57   - }
58   -
59   - @Test
60   - public void testUpdateProduct_success() {
61   - // mock 数据
62   - ProductDO dbProduct = randomPojo(ProductDO.class);
63   - productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
64   - // 准备参数
65   - ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class, o -> {
66   - o.setId(dbProduct.getId()); // 设置更新的 ID
67   - });
68   -
69   - // 调用
70   - productService.updateProduct(updateReqVO);
71   - // 校验是否更新正确
72   - ProductDO product = productMapper.selectById(updateReqVO.getId()); // 获取最新的
73   - assertPojoEquals(updateReqVO, product);
74   - }
75   -
76   - @Test
77   - public void testUpdateProduct_notExists() {
78   - // 准备参数
79   - ProductSaveReqVO updateReqVO = randomPojo(ProductSaveReqVO.class);
80   -
81   - // 调用, 并断言异常
82   - assertServiceException(() -> productService.updateProduct(updateReqVO), PRODUCT_NOT_EXISTS);
83   - }
84   -
85   - @Test
86   - public void testDeleteProduct_success() {
87   - // mock 数据
88   - ProductDO dbProduct = randomPojo(ProductDO.class);
89   - productMapper.insert(dbProduct);// @Sql: 先插入出一条存在的数据
90   - // 准备参数
91   - Long id = dbProduct.getId();
92   -
93   - // 调用
94   - productService.deleteProduct(id);
95   - // 校验数据不存在了
96   - assertNull(productMapper.selectById(id));
97   - }
98   -
99   - @Test
100   - public void testDeleteProduct_notExists() {
101   - // 准备参数
102   - Long id = randomLongId();
103   -
104   - // 调用, 并断言异常
105   - assertServiceException(() -> productService.deleteProduct(id), PRODUCT_NOT_EXISTS);
106   - }
107   -
108   - @Test
109   - @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
110   - public void testGetProductPage() {
111   - // mock 数据
112   - ProductDO dbProduct = randomPojo(ProductDO.class, o -> { // 等会查询到
113   - o.setName(null);
114   - o.setCreateTime(null);
115   - o.setProductKey(null);
116   - o.setProtocolId(null);
117   - o.setCategoryId(null);
118   - o.setDescription(null);
119   - o.setValidateType(null);
120   - o.setStatus(null);
121   - o.setDeviceType(null);
122   - o.setNetType(null);
123   - o.setProtocolType(null);
124   - o.setDataFormat(null);
125   - });
126   - productMapper.insert(dbProduct);
127   - // 测试 name 不匹配
128   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setName(null)));
129   - // 测试 createTime 不匹配
130   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCreateTime(null)));
131   - // 测试 productKey 不匹配
132   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setProductKey(null)));
133   - // 测试 protocolId 不匹配
134   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setProtocolId(null)));
135   - // 测试 categoryId 不匹配
136   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCategoryId(null)));
137   - // 测试 description 不匹配
138   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDescription(null)));
139   - // 测试 validateType 不匹配
140   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setValidateType(null)));
141   - // 测试 status 不匹配
142   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setStatus(null)));
143   - // 测试 deviceType 不匹配
144   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDeviceType(null)));
145   - // 测试 netType 不匹配
146   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setNetType(null)));
147   - // 测试 protocolType 不匹配
148   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setProtocolType(null)));
149   - // 测试 dataFormat 不匹配
150   - productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setDataFormat(null)));
151   - // 准备参数
152   - ProductPageReqVO reqVO = new ProductPageReqVO();
153   - reqVO.setName(null);
154   - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
155   - reqVO.setProductKey(null);
156   - reqVO.setProtocolId(null);
157   - reqVO.setCategoryId(null);
158   - reqVO.setDescription(null);
159   - reqVO.setValidateType(null);
160   - reqVO.setStatus(null);
161   - reqVO.setDeviceType(null);
162   - reqVO.setNetType(null);
163   - reqVO.setProtocolType(null);
164   - reqVO.setDataFormat(null);
165   -
166   - // 调用
167   - PageResult<ProductDO> pageResult = productService.getProductPage(reqVO);
168   - // 断言
169   - assertEquals(1, pageResult.getTotal());
170   - assertEquals(1, pageResult.getList().size());
171   - assertPojoEquals(dbProduct, pageResult.getList().get(0));
172   - }
173   -
174   -}
175 0 \ No newline at end of file
yudao-server/src/main/resources/application-dev.yaml
... ... @@ -196,7 +196,7 @@ justauth:
196 196 timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟
197 197  
198 198  
199   ---- #################### iot相关配置 ####################
  199 +--- #################### iot相关配置 TODO 芋艿:再瞅瞅 ####################
200 200 iot:
201 201 emq:
202 202 # 账号
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -250,7 +250,7 @@ justauth:
250 250 prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE::
251 251 timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟
252 252  
253   ---- #################### iot相关配置 ####################
  253 +--- #################### iot相关配置 TODO 芋艿:再瞅瞅 ####################
254 254 iot:
255 255 emq:
256 256 # 账号
... ...