!1223 【代码优化】IoT: 物模型

Merge pull request !1223 from puhui999/iot
This commit is contained in:
芋道源码 2025-02-08 23:23:34 +00:00 committed by Gitee
commit 88ec5269d9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 148 additions and 56 deletions

View File

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.iot.enums.thingmodel; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
// TODO @puhui999加个 ArrayValuable import java.util.Arrays;
/** /**
* IoT 数据定义的数据类型枚举类 * IoT 数据定义的数据类型枚举类
* *
@ -11,7 +13,7 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotDataSpecsDataTypeEnum { public enum IotDataSpecsDataTypeEnum implements ArrayValuable<String> {
INT("int"), INT("int"),
FLOAT("float"), FLOAT("float"),
@ -23,6 +25,13 @@ public enum IotDataSpecsDataTypeEnum {
STRUCT("struct"), STRUCT("struct"),
ARRAY("array"); ARRAY("array");
public static final String[] ARRAYS = Arrays.stream(values()).map(IotDataSpecsDataTypeEnum::getDataType).toArray(String[]::new);
private final String dataType; private final String dataType;
@Override
public String[] array() {
return ARRAYS;
}
} }

View File

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.iot.enums.thingmodel; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
// TODO @puhui999加个 ArrayValuable import java.util.Arrays;
/** /**
* IOT 产品物模型属性读取类型枚举 * IOT 产品物模型属性读取类型枚举
* *
@ -11,11 +13,18 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotThingModelAccessModeEnum { public enum IotThingModelAccessModeEnum implements ArrayValuable<String> {
READ_ONLY("r"), READ_ONLY("r"),
READ_WRITE("rw"); READ_WRITE("rw");
public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelAccessModeEnum::getMode).toArray(String[]::new);
private final String mode; private final String mode;
@Override
public String[] array() {
return ARRAYS;
}
} }

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.iot.enums.thingmodel; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
// TODO @puhui999加个 ArrayValuable import java.util.Arrays;
/** /**
* IOT 产品物模型参数是输入参数还是输出参数枚举 * IOT 产品物模型参数是输入参数还是输出参数枚举
* *
@ -11,11 +14,18 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotThingModelParamDirectionEnum { public enum IotThingModelParamDirectionEnum implements ArrayValuable<String> {
INPUT("input"), // 输入参数 INPUT("input"), // 输入参数
OUTPUT("output"); // 输出参数 OUTPUT("output"); // 输出参数
public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelParamDirectionEnum::getDirection).toArray(String[]::new);
private final String direction; private final String direction;
@Override
public String[] array() {
return ARRAYS;
}
} }

View File

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.iot.enums.thingmodel; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
// TODO @puhui999加个 ArrayValuable import java.util.Arrays;
/** /**
* IOT 产品物模型服务调用方式枚举 * IOT 产品物模型服务调用方式枚举
* *
@ -11,11 +13,18 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotThingModelServiceCallTypeEnum { public enum IotThingModelServiceCallTypeEnum implements ArrayValuable<String> {
ASYNC("async"), // 异步调用 ASYNC("async"), // 异步调用
SYNC("sync"); // 同步调用 SYNC("sync"); // 同步调用
public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelServiceCallTypeEnum::getType).toArray(String[]::new);
private final String type; private final String type;
@Override
public String[] array() {
return ARRAYS;
}
} }

View File

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.iot.enums.thingmodel; package cn.iocoder.yudao.module.iot.enums.thingmodel;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
// TODO @puhui999加个 ArrayValuable import java.util.Arrays;
/** /**
* IOT 产品物模型事件类型枚举 * IOT 产品物模型事件类型枚举
* *
@ -11,12 +13,19 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum IotThingModelServiceEventTypeEnum { public enum IotThingModelServiceEventTypeEnum implements ArrayValuable<String> {
INFO("info"), // 信息 INFO("info"), // 信息
ALERT("alert"), // 告警 ALERT("alert"), // 告警
ERROR("error"); // 故障 ERROR("error"); // 故障
public static final String[] ARRAYS = Arrays.stream(values()).map(IotThingModelServiceEventTypeEnum::getType).toArray(String[]::new);
private final String type; private final String type;
@Override
public String[] array() {
return ARRAYS;
}
} }

View File

@ -1,11 +1,14 @@
package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceEventTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceEventTypeEnum;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
// TODO @puhui999必要的参数校验
/** /**
* 物模型中的事件 * 物模型中的事件
* *
@ -17,10 +20,13 @@ public class ThingModelEvent {
/** /**
* 事件标识符 * 事件标识符
*/ */
@NotEmpty(message = "事件标识符不能为空")
@Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "事件标识符只能由字母、数字和下划线组成必须以字母开头长度不超过32个字符")
private String identifier; private String identifier;
/** /**
* 事件名称 * 事件名称
*/ */
@NotEmpty(message = "事件名称不能为空")
private String name; private String name;
/** /**
* 是否是标准品类的必选事件 * 是否是标准品类的必选事件
@ -31,12 +37,15 @@ public class ThingModelEvent {
* *
* 枚举 {@link IotThingModelServiceEventTypeEnum} * 枚举 {@link IotThingModelServiceEventTypeEnum}
*/ */
@NotEmpty(message = "事件类型不能为空")
@InEnum(IotThingModelServiceEventTypeEnum.class)
private String type; private String type;
/** /**
* 事件的输出参数 * 事件的输出参数
* *
* 输出参数定义事件调用后返回的结果或反馈信息用于确认操作结果或提供额外的信息 * 输出参数定义事件调用后返回的结果或反馈信息用于确认操作结果或提供额外的信息
*/ */
@Valid
private List<ThingModelParam> outputParams; private List<ThingModelParam> outputParams;
/** /**
* 标识设备需要执行的具体操作 * 标识设备需要执行的具体操作

View File

@ -1,12 +1,15 @@
package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs; import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelParamDirectionEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelParamDirectionEnum;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
// TODO @puhui999必要的参数校验
/** /**
* IOT 产品物模型中的参数 * IOT 产品物模型中的参数
* *
@ -18,16 +21,21 @@ public class ThingModelParam {
/** /**
* 参数标识符 * 参数标识符
*/ */
@NotEmpty(message = "参数标识符不能为空")
@Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "参数标识符只能由字母、数字和下划线组成必须以字母开头长度不超过32个字符")
private String identifier; private String identifier;
/** /**
* 参数名称 * 参数名称
*/ */
@NotEmpty(message = "参数名称不能为空")
private String name; private String name;
/** /**
* 用于区分输入或输出参数 * 用于区分输入或输出参数
* *
* 枚举 {@link IotThingModelParamDirectionEnum} * 枚举 {@link IotThingModelParamDirectionEnum}
*/ */
@NotEmpty(message = "参数方向不能为空")
@InEnum(IotThingModelParamDirectionEnum.class)
private String direction; private String direction;
/** /**
* 参数的序号 0 开始排序且不能重复 * 参数的序号 0 开始排序且不能重复
@ -37,7 +45,11 @@ public class ThingModelParam {
private Integer paraOrder; private Integer paraOrder;
/** /**
* 参数值的数据类型 dataSpecs dataType 保持一致 * 参数值的数据类型 dataSpecs dataType 保持一致
*
* 枚举 {@link IotDataSpecsDataTypeEnum}
*/ */
@NotEmpty(message = "数据类型不能为空")
@InEnum(IotDataSpecsDataTypeEnum.class)
private String dataType; private String dataType;
/** /**
* 参数值的数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs * 参数值的数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs

View File

@ -1,12 +1,15 @@
package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs; import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.dataType.ThingModelDataSpecs;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelAccessModeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelAccessModeEnum;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
// TODO @puhui999必要的参数校验
/** /**
* 物模型中的属性 * 物模型中的属性
* *
@ -20,26 +23,33 @@ public class ThingModelProperty {
/** /**
* 属性标识符 * 属性标识符
*/ */
@NotEmpty(message = "属性标识符不能为空")
@Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "属性标识符只能由字母、数字和下划线组成必须以字母开头长度不超过32个字符")
private String identifier; private String identifier;
/** /**
* 属性名称 * 属性名称
*/ */
@NotEmpty(message = "属性名称不能为空")
private String name; private String name;
/** /**
* 云端可以对该属性进行的操作类型 * 云端可以对该属性进行的操作类型
* *
* 枚举 {@link IotThingModelAccessModeEnum} * 枚举 {@link IotThingModelAccessModeEnum}
*/ */
@NotEmpty(message = "操作类型不能为空")
@InEnum(IotThingModelAccessModeEnum.class)
private String accessMode; private String accessMode;
/** /**
* 是否是标准品类的必选服务 * 是否是标准品类的必选服务
*/ */
private Boolean required; private Boolean required;
/** /**
* 数据类型 dataSpecs dataType 保持一致 * 参数值的数据类型 dataSpecs dataType 保持一致
* *
* 枚举 {@link cn.iocoder.yudao.module.iot.enums.thingmodel.IotDataSpecsDataTypeEnum} * 枚举 {@link IotDataSpecsDataTypeEnum}
*/ */
@NotEmpty(message = "数据类型不能为空")
@InEnum(IotDataSpecsDataTypeEnum.class)
private String dataType; private String dataType;
/** /**
* 数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs * 数据类型dataType为非列表型intfloatdoubletextdatearray的数据规范存储在 dataSpecs

View File

@ -1,11 +1,14 @@
package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model; package cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceCallTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelServiceCallTypeEnum;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
// TODO @puhui999必要的参数校验
/** /**
* 物模型中的服务 * 物模型中的服务
* *
@ -17,10 +20,13 @@ public class ThingModelService {
/** /**
* 服务标识符 * 服务标识符
*/ */
@NotEmpty(message = "服务标识符不能为空")
@Pattern(regexp = "^[a-zA-Z][a-zA-Z0-9_]{0,31}$", message = "服务标识符只能由字母、数字和下划线组成必须以字母开头长度不超过32个字符")
private String identifier; private String identifier;
/** /**
* 服务名称 * 服务名称
*/ */
@NotEmpty(message = "服务名称不能为空")
private String name; private String name;
/** /**
* 是否是标准品类的必选服务 * 是否是标准品类的必选服务
@ -31,18 +37,22 @@ public class ThingModelService {
* *
* 枚举 {@link IotThingModelServiceCallTypeEnum} * 枚举 {@link IotThingModelServiceCallTypeEnum}
*/ */
@NotEmpty(message = "调用类型不能为空")
@InEnum(IotThingModelServiceCallTypeEnum.class)
private String callType; private String callType;
/** /**
* 服务的输入参数 * 服务的输入参数
* *
* 输入参数定义服务调用时所需提供的信息用于控制设备行为或执行特定任务 * 输入参数定义服务调用时所需提供的信息用于控制设备行为或执行特定任务
*/ */
@Valid
private List<ThingModelParam> inputParams; private List<ThingModelParam> inputParams;
/** /**
* 服务的输出参数 * 服务的输出参数
* *
* 输出参数定义服务调用后返回的结果或反馈信息用于确认操作结果或提供额外的信息 * 输出参数定义服务调用后返回的结果或反馈信息用于确认操作结果或提供额外的信息
*/ */
@Valid
private List<ThingModelParam> outputParams; private List<ThingModelParam> outputParams;
/** /**
* 标识设备需要执行的具体操作 * 标识设备需要执行的具体操作

View File

@ -6,19 +6,18 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
// TODO @puhui999部分字段可以用 cursor 加上 example
@Schema(description = "管理后台 - IoT 产品物模型 List Request VO") @Schema(description = "管理后台 - IoT 产品物模型 List Request VO")
@Data @Data
public class IotThingModelListReqVO { public class IotThingModelListReqVO {
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "产品编号不能为空") @NotNull(message = "产品编号不能为空")
private Long productId; private Long productId;
@Schema(description = "功能标识") @Schema(description = "功能标识", example = "temperature")
private String identifier; private String identifier;
@Schema(description = "功能名称", example = "张三") @Schema(description = "功能名称", example = "温度")
private String name; private String name;
@Schema(description = "功能类型", example = "1") @Schema(description = "功能类型", example = "1")

View File

@ -9,21 +9,20 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
// TODO @puhui999部分字段可以用 cursor 加上 example
@Schema(description = "管理后台 - IoT 产品物模型分页 Request VO") @Schema(description = "管理后台 - IoT 产品物模型分页 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class IotThingModelPageReqVO extends PageParam { public class IotThingModelPageReqVO extends PageParam {
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "产品编号不能为空") @NotNull(message = "产品编号不能为空")
private Long productId; private Long productId;
@Schema(description = "功能标识") @Schema(description = "功能标识", example = "temperature")
private String identifier; private String identifier;
@Schema(description = "功能名称", example = "张三") @Schema(description = "功能名称", example = "温度")
private String name; private String name;
@Schema(description = "功能类型", example = "1") @Schema(description = "功能类型", example = "1")

View File

@ -10,7 +10,6 @@ import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO @puhui999部分字段可以用 cursor 加上 example
@Schema(description = "管理后台 - IoT 产品物模型 Response VO") @Schema(description = "管理后台 - IoT 产品物模型 Response VO")
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@ -20,23 +19,23 @@ public class IotThingModelRespVO {
@ExcelProperty("产品ID") @ExcelProperty("产品ID")
private Long id; private Long id;
@Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long productId; private Long productId;
@Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_sensor")
@ExcelProperty("产品标识") @ExcelProperty("产品标识")
private String productKey; private String productKey;
@Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature")
private String identifier; private String identifier;
@Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温度")
private String name; private String name;
@Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "测量当前环境温度")
private String description; private String description;
@Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer type; private Integer type;
@Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -6,11 +6,11 @@ import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelP
import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService; import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelService;
import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum; import cn.iocoder.yudao.module.iot.enums.thingmodel.IotThingModelTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
// TODO @puhui999部分字段可以用 cursor 加上 example
@Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO") @Schema(description = "管理后台 - IoT 产品物模型新增/修改 Request VO")
@Data @Data
public class IotThingModelSaveReqVO { public class IotThingModelSaveReqVO {
@ -22,33 +22,36 @@ public class IotThingModelSaveReqVO {
@NotNull(message = "产品ID不能为空") @NotNull(message = "产品ID不能为空")
private Long productId; private Long productId;
@Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temperature_001")
@NotEmpty(message = "产品标识不能为空") @NotEmpty(message = "产品标识不能为空")
private String productKey; private String productKey;
@Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "temp_monitor")
@NotEmpty(message = "功能标识不能为空") @NotEmpty(message = "功能标识不能为空")
private String identifier; private String identifier;
@Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温度监测器")
@NotEmpty(message = "功能名称不能为空") @NotEmpty(message = "功能名称不能为空")
private String name; private String name;
@Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "用于监测环境温度的传感器")
private String description; private String description;
@Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "功能类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "功能类型不能为空") @NotNull(message = "功能类型不能为空")
@InEnum(IotThingModelTypeEnum.class) @InEnum(IotThingModelTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "属性", requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private ThingModelProperty property; private ThingModelProperty property;
@Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "服务", requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private ThingModelService service; private ThingModelService service;
@Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "事件", requiredMode = Schema.RequiredMode.REQUIRED)
@Valid
private ThingModelEvent event; private ThingModelEvent event;
} }

View File

@ -55,7 +55,7 @@ public class IotThingModelServiceImpl implements IotThingModelService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long createThingModel(IotThingModelSaveReqVO createReqVO) { public Long createThingModel(IotThingModelSaveReqVO createReqVO) {
// 1.1 校验功能标识符在同一产品下是否唯一 // 1.1 校验功能标识符在同一产品下是否唯一
validateIdentifierUnique(createReqVO.getProductId(), createReqVO.getIdentifier()); validateIdentifierUnique(null, createReqVO.getProductId(), createReqVO.getIdentifier());
// 1.2 功能名称在同一产品下是否唯一 // 1.2 功能名称在同一产品下是否唯一
validateNameUnique(createReqVO.getProductId(), createReqVO.getName()); validateNameUnique(createReqVO.getProductId(), createReqVO.getName());
// 1.3 校验产品状态发布状态下不允许新增功能 // 1.3 校验产品状态发布状态下不允许新增功能
@ -81,7 +81,7 @@ public class IotThingModelServiceImpl implements IotThingModelService {
// 1.1 校验功能是否存在 // 1.1 校验功能是否存在
validateProductThingModelMapperExists(updateReqVO.getId()); validateProductThingModelMapperExists(updateReqVO.getId());
// 1.2 校验功能标识符是否唯一 // 1.2 校验功能标识符是否唯一
validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier()); validateIdentifierUnique(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier());
// 1.3 校验产品状态发布状态下不允许操作功能 // 1.3 校验产品状态发布状态下不允许操作功能
validateProductStatus(updateReqVO.getProductId()); validateProductStatus(updateReqVO.getProductId());
@ -159,8 +159,23 @@ public class IotThingModelServiceImpl implements IotThingModelService {
} }
} }
// TODO @puhui999这个方法 validateIdentifierUnique 可以融合下 private void validateIdentifierUnique(Long id, Long productId, String identifier) {
private void validateIdentifierUniqueForUpdate(Long id, Long productId, String identifier) { // 1.0 情况一创建时校验
if (id == null) {
// 1.1 系统保留字段不能用于标识符定义
if (StrUtil.equalsAny(identifier, "set", "get", "post", "property", "event", "time", "value")) {
throw exception(THING_MODEL_IDENTIFIER_INVALID);
}
// 1.2 校验唯一
IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
if (thingModel != null) {
throw exception(THING_MODEL_IDENTIFIER_EXISTS);
}
return;
}
// 2.0 情况二更新时校验
IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier); IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
if (thingModel != null && ObjectUtil.notEqual(thingModel.getId(), id)) { if (thingModel != null && ObjectUtil.notEqual(thingModel.getId(), id)) {
throw exception(THING_MODEL_IDENTIFIER_EXISTS); throw exception(THING_MODEL_IDENTIFIER_EXISTS);
@ -181,23 +196,10 @@ public class IotThingModelServiceImpl implements IotThingModelService {
} }
} }
private void validateIdentifierUnique(Long productId, String identifier) {
// 系统保留字段不能用于标识符定义
if (StrUtil.equalsAny(identifier, "set", "get", "post", "property", "event", "time", "value")) {
throw exception(THING_MODEL_IDENTIFIER_INVALID);
}
// 校验唯一
IotThingModelDO thingModel = thingModelMapper.selectByProductIdAndIdentifier(productId, identifier);
if (thingModel != null) {
throw exception(THING_MODEL_IDENTIFIER_EXISTS);
}
}
/** /**
* 创建默认的事件和服务 * 创建默认的事件和服务
* *
* @param productId 产品编号 * @param productId 产品编号
* @param productKey 产品标识 * @param productKey 产品标识
*/ */
public void createDefaultEventsAndServices(Long productId, String productKey) { public void createDefaultEventsAndServices(Long productId, String productKey) {
@ -282,6 +284,7 @@ public class IotThingModelServiceImpl implements IotThingModelService {
} }
// TODO @haohao是不是不用生成这个目前属性上报是个批量接口 // TODO @haohao是不是不用生成这个目前属性上报是个批量接口
/** /**
* 生成属性上报事件 * 生成属性上报事件
*/ */
@ -298,6 +301,7 @@ public class IotThingModelServiceImpl implements IotThingModelService {
} }
// TODO @haohao是不是不用生成这个目前属性上报是个批量接口 // TODO @haohao是不是不用生成这个目前属性上报是个批量接口
/** /**
* 生成属性设置服务 * 生成属性设置服务
*/ */
@ -352,7 +356,8 @@ public class IotThingModelServiceImpl implements IotThingModelService {
} }
@CacheEvict(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey") @CacheEvict(value = RedisKeyConstants.THING_MODEL_LIST, key = "#productKey")
public void deleteThingModelListCache0(String productKey) {} public void deleteThingModelListCache0(String productKey) {
}
private IotThingModelServiceImpl getSelf() { private IotThingModelServiceImpl getSelf() {
return SpringUtil.getBean(getClass()); return SpringUtil.getBean(getClass());