Commit 9b2389356f05c26dc6d60011c7a48bbdbf40ad05

Authored by 安浩浩
1 parent e26903b0

【功能新增】IoT: 增加产品脚本语言、状态和类型枚举,更新相关请求和响应对象以支持新的枚举类型

yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductScriptLanguageEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.ArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * IoT 产品脚本语言枚举
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum IotProductScriptLanguageEnum implements ArrayValuable<String> {
  17 +
  18 + JAVASCRIPT("javascript", "JavaScript"),
  19 + JAVA("java", "Java"),
  20 + PYTHON("python", "Python"),
  21 + ;
  22 +
  23 + public static final String[] ARRAYS = Arrays.stream(values()).map(IotProductScriptLanguageEnum::getCode)
  24 + .toArray(String[]::new);
  25 +
  26 + /**
  27 + * 编码
  28 + */
  29 + private final String code;
  30 + /**
  31 + * 名称
  32 + */
  33 + private final String name;
  34 +
  35 + @Override
  36 + public String[] array() {
  37 + return ARRAYS;
  38 + }
  39 +
  40 + public static IotProductScriptLanguageEnum getByCode(String code) {
  41 + return Arrays.stream(values())
  42 + .filter(type -> type.getCode().equals(code))
  43 + .findFirst()
  44 + .orElse(null);
  45 + }
  46 +}
0 47 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductScriptStatusEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.ArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * IoT 产品脚本状态枚举
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum IotProductScriptStatusEnum implements ArrayValuable<Integer> {
  17 +
  18 + ENABLE(0, "启用"),
  19 + DISABLE(1, "禁用"),
  20 + ;
  21 +
  22 + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotProductScriptStatusEnum::getStatus)
  23 + .toArray(Integer[]::new);
  24 +
  25 + /**
  26 + * 状态值
  27 + */
  28 + private final Integer status;
  29 + /**
  30 + * 状态名
  31 + */
  32 + private final String name;
  33 +
  34 + @Override
  35 + public Integer[] array() {
  36 + return ARRAYS;
  37 + }
  38 +
  39 + public static IotProductScriptStatusEnum getByStatus(Integer status) {
  40 + return Arrays.stream(values())
  41 + .filter(type -> type.getStatus().equals(status))
  42 + .findFirst()
  43 + .orElse(null);
  44 + }
  45 +
  46 + public static boolean isEnable(Integer status) {
  47 + return ENABLE.getStatus().equals(status);
  48 + }
  49 +
  50 + public static boolean isDisable(Integer status) {
  51 + return DISABLE.getStatus().equals(status);
  52 + }
  53 +}
0 54 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductScriptTypeEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.enums.product;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.ArrayValuable;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Getter;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * IoT 产品脚本类型枚举
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +@Getter
  15 +@AllArgsConstructor
  16 +public enum IotProductScriptTypeEnum implements ArrayValuable<Integer> {
  17 +
  18 + PROPERTY_PARSER(1, "property_parser", "属性解析"),
  19 + EVENT_PARSER(2, "event_parser", "事件解析"),
  20 + COMMAND_ENCODER(3, "command_encoder", "命令编码"),
  21 + ;
  22 +
  23 + public static final Integer[] ARRAYS = Arrays.stream(values()).map(IotProductScriptTypeEnum::getCode)
  24 + .toArray(Integer[]::new);
  25 +
  26 + /**
  27 + * 编码
  28 + */
  29 + private final Integer code;
  30 + /**
  31 + * 类型
  32 + */
  33 + private final String type;
  34 + /**
  35 + * 名称
  36 + */
  37 + private final String name;
  38 +
  39 + @Override
  40 + public Integer[] array() {
  41 + return ARRAYS;
  42 + }
  43 +
  44 + public static IotProductScriptTypeEnum getByCode(Integer code) {
  45 + return Arrays.stream(values())
  46 + .filter(type -> type.getCode().equals(code))
  47 + .findFirst()
  48 + .orElse(null);
  49 + }
  50 +}
0 51 \ 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/script/IotProductScriptPageReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo.script;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptLanguageEnum;
  6 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptStatusEnum;
  7 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptTypeEnum;
4 8 import io.swagger.v3.oas.annotations.media.Schema;
5 9 import lombok.Data;
6 10 import lombok.EqualsAndHashCode;
... ... @@ -23,13 +27,16 @@ public class IotProductScriptPageReqVO extends PageParam {
23 27 @Schema(description = "产品唯一标识符")
24 28 private String productKey;
25 29  
26   - @Schema(description = "脚本类型(property_parser=属性解析,event_parser=事件解析,command_encoder=命令编码)", example = "2")
27   - private String scriptType;
  30 + @Schema(description = "脚本类型", example = "1")
  31 + @InEnum(IotProductScriptTypeEnum.class)
  32 + private Integer scriptType;
28 33  
29 34 @Schema(description = "脚本语言")
  35 + @InEnum(IotProductScriptLanguageEnum.class)
30 36 private String scriptLanguage;
31 37  
32   - @Schema(description = "状态(0=禁用 1=启用)", example = "2")
  38 + @Schema(description = "状态", example = "0")
  39 + @InEnum(IotProductScriptStatusEnum.class)
33 40 private Integer status;
34 41  
35 42 @Schema(description = "备注说明", example = "你说的对")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/script/IotProductScriptRespVO.java
... ... @@ -24,9 +24,9 @@ public class IotProductScriptRespVO {
24 24 @ExcelProperty("产品唯一标识符")
25 25 private String productKey;
26 26  
27   - @Schema(description = "脚本类型(property_parser=属性解析,event_parser=事件解析,command_encoder=命令编码)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
28   - @ExcelProperty("脚本类型(property_parser=属性解析,event_parser=事件解析,command_encoder=命令编码)")
29   - private String scriptType;
  27 + @Schema(description = "脚本类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  28 + @ExcelProperty("脚本类型")
  29 + private Integer scriptType;
30 30  
31 31 @Schema(description = "脚本内容", requiredMode = Schema.RequiredMode.REQUIRED)
32 32 @ExcelProperty("脚本内容")
... ... @@ -36,8 +36,8 @@ public class IotProductScriptRespVO {
36 36 @ExcelProperty("脚本语言")
37 37 private String scriptLanguage;
38 38  
39   - @Schema(description = "状态(0=禁用 1=启用)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
40   - @ExcelProperty("状态(0=禁用 1=启用)")
  39 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  40 + @ExcelProperty("状态")
41 41 private Integer status;
42 42  
43 43 @Schema(description = "备注说明", example = "你说的对")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/script/IotProductScriptSaveReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo.script;
2 2  
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptLanguageEnum;
  5 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptStatusEnum;
  6 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptTypeEnum;
3 7 import io.swagger.v3.oas.annotations.media.Schema;
4 8 import jakarta.validation.constraints.NotEmpty;
5 9 import jakarta.validation.constraints.NotNull;
... ... @@ -20,9 +24,10 @@ public class IotProductScriptSaveReqVO {
20 24 @NotEmpty(message = "产品唯一标识符不能为空")
21 25 private String productKey;
22 26  
23   - @Schema(description = "脚本类型(property_parser=属性解析,event_parser=事件解析,command_encoder=命令编码)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
24   - @NotEmpty(message = "脚本类型(property_parser=属性解析,event_parser=事件解析,command_encoder=命令编码)不能为空")
25   - private String scriptType;
  27 + @Schema(description = "脚本类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  28 + @NotNull(message = "脚本类型不能为空")
  29 + @InEnum(IotProductScriptTypeEnum.class)
  30 + private Integer scriptType;
26 31  
27 32 @Schema(description = "脚本内容", requiredMode = Schema.RequiredMode.REQUIRED)
28 33 @NotEmpty(message = "脚本内容不能为空")
... ... @@ -30,10 +35,12 @@ public class IotProductScriptSaveReqVO {
30 35  
31 36 @Schema(description = "脚本语言", requiredMode = Schema.RequiredMode.REQUIRED)
32 37 @NotEmpty(message = "脚本语言不能为空")
  38 + @InEnum(IotProductScriptLanguageEnum.class)
33 39 private String scriptLanguage;
34 40  
35   - @Schema(description = "状态(0=禁用 1=启用)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
36   - @NotNull(message = "状态(0=禁用 1=启用)不能为空")
  41 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  42 + @NotNull(message = "状态不能为空")
  43 + @InEnum(IotProductScriptStatusEnum.class)
37 44 private Integer status;
38 45  
39 46 @Schema(description = "备注说明", example = "你说的对")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/script/IotProductScriptTestReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo.script;
2 2  
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptTypeEnum;
3 5 import io.swagger.v3.oas.annotations.media.Schema;
4 6 import jakarta.validation.constraints.NotEmpty;
5 7 import jakarta.validation.constraints.NotNull;
... ... @@ -16,9 +18,10 @@ public class IotProductScriptTestReqVO {
16 18 @NotNull(message = "产品ID不能为空")
17 19 private Long productId;
18 20  
19   - @Schema(description = "脚本类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "property_parser")
20   - @NotEmpty(message = "脚本类型不能为空")
21   - private String scriptType;
  21 + @Schema(description = "脚本类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  22 + @NotNull(message = "脚本类型不能为空")
  23 + @InEnum(value = IotProductScriptTypeEnum.class)
  24 + private Integer scriptType;
22 25  
23 26 @Schema(description = "脚本内容", requiredMode = Schema.RequiredMode.REQUIRED)
24 27 @NotEmpty(message = "脚本内容不能为空")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/script/IotProductScriptUpdateStatusReqVO.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product.vo.script;
2 2  
  3 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  4 +import cn.iocoder.yudao.module.iot.enums.product.IotProductScriptStatusEnum;
3 5 import io.swagger.v3.oas.annotations.media.Schema;
4 6 import jakarta.validation.constraints.NotNull;
5 7 import lombok.Data;
... ... @@ -12,8 +14,9 @@ public class IotProductScriptUpdateStatusReqVO {
12 14 @NotNull(message = "脚本ID不能为空")
13 15 private Long id;
14 16  
15   - @Schema(description = "状态(0=禁用 1=启用)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  17 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
16 18 @NotNull(message = "状态不能为空")
  19 + @InEnum(IotProductScriptStatusEnum.class)
17 20 private Integer status;
18 21  
19 22 }
20 23 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductScriptServiceImpl.java
... ... @@ -147,14 +147,14 @@ public class IotProductScriptServiceImpl implements IotProductScriptService {
147 147  
148 148 // 根据脚本类型设置特定参数
149 149 switch (testReqVO.getScriptType()) {
150   - case "property_parser":
  150 + case 1: // PROPERTY_PARSER
151 151 params.put("method", "property");
152 152 break;
153   - case "event_parser":
  153 + case 2: // EVENT_PARSER
154 154 params.put("method", "event");
155 155 params.put("identifier", "default");
156 156 break;
157   - case "command_encoder":
  157 + case 3: // COMMAND_ENCODER
158 158 params.put("method", "command");
159 159 break;
160 160 default:
... ...