Commit f7b62b4bcc666728c4455de3080df4a231e0c3cc
1 parent
609cc719
修改:新增产品生成 ProductKey
Showing
2 changed files
with
35 additions
and
29 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/vo/ProductSaveReqVO.java
| @@ -9,46 +9,37 @@ import jakarta.validation.constraints.*; | @@ -9,46 +9,37 @@ import jakarta.validation.constraints.*; | ||
| 9 | @Data | 9 | @Data |
| 10 | public class ProductSaveReqVO { | 10 | public class ProductSaveReqVO { |
| 11 | 11 | ||
| 12 | - @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") | ||
| 13 | - @NotEmpty(message = "产品名称不能为空") | ||
| 14 | - private String name; | ||
| 15 | - | ||
| 16 | - @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "26087") | 12 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.AUTO, example = "1") |
| 17 | private Long id; | 13 | private Long id; |
| 18 | 14 | ||
| 19 | - @Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 20 | - @NotEmpty(message = "产品标识不能为空") | 15 | + @Schema(description = "产品Key", requiredMode = Schema.RequiredMode.AUTO, example = "12345abc") |
| 21 | private String productKey; | 16 | private String productKey; |
| 22 | 17 | ||
| 23 | - @Schema(description = "协议编号(脚本解析 id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "13177") | ||
| 24 | - @NotNull(message = "协议编号(脚本解析 id)不能为空") | ||
| 25 | - private Long protocolId; | ||
| 26 | - | ||
| 27 | - @Schema(description = "产品所属品类标识符", example = "14237") | ||
| 28 | - private Long categoryId; | ||
| 29 | - | ||
| 30 | - @Schema(description = "产品描述", example = "你猜") | ||
| 31 | - private String description; | ||
| 32 | - | ||
| 33 | - @Schema(description = "数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 34 | - @NotNull(message = "数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验不能为空") | ||
| 35 | - private Integer validateType; | ||
| 36 | - | ||
| 37 | - @Schema(description = "产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 38 | - @NotNull(message = "产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS不能为空") | ||
| 39 | - private Integer status; | 18 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "温湿度") |
| 19 | + @NotEmpty(message = "产品名称不能为空") | ||
| 20 | + private String name; | ||
| 40 | 21 | ||
| 41 | - @Schema(description = "设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 42 | - @NotNull(message = "设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备不能为空") | 22 | + @Schema(description = "设备类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 23 | + @NotNull(message = "设备类型不能为空") | ||
| 43 | private Integer deviceType; | 24 | private Integer deviceType; |
| 44 | 25 | ||
| 45 | - @Schema(description = "联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他", example = "2") | 26 | + @Schema(description = "联网方式", requiredMode = Schema.RequiredMode.REQUIRED,example = "0") |
| 27 | + @NotNull(message = "联网方式不能为空") | ||
| 46 | private Integer netType; | 28 | private Integer netType; |
| 47 | 29 | ||
| 48 | - @Schema(description = "接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee", example = "2") | 30 | + @Schema(description = "接入网关协议", requiredMode = Schema.RequiredMode.REQUIRED,example = "0") |
| 31 | + @NotNull(message = "接入网关协议不能为空") | ||
| 49 | private Integer protocolType; | 32 | private Integer protocolType; |
| 50 | 33 | ||
| 51 | - @Schema(description = "数据格式, 0: 透传模式, 1: Alink JSON") | 34 | + @Schema(description = "数据格式",requiredMode = Schema.RequiredMode.REQUIRED, example = "0") |
| 35 | + @NotNull(message = "数据格式不能为空") | ||
| 52 | private Integer dataFormat; | 36 | private Integer dataFormat; |
| 53 | 37 | ||
| 38 | + @Schema(description = "数据校验级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "0") | ||
| 39 | + @NotNull(message = "数据校验级别不能为空") | ||
| 40 | + private Integer validateType; | ||
| 41 | + | ||
| 42 | + @Schema(description = "产品描述", example = "描述") | ||
| 43 | + private String description; | ||
| 44 | + | ||
| 54 | } | 45 | } |
| 55 | \ No newline at end of file | 46 | \ No newline at end of file |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/ProductServiceImpl.java
| @@ -10,6 +10,8 @@ import jakarta.annotation.Resource; | @@ -10,6 +10,8 @@ import jakarta.annotation.Resource; | ||
| 10 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.validation.annotation.Validated; | 11 | import org.springframework.validation.annotation.Validated; |
| 12 | 12 | ||
| 13 | +import java.util.UUID; | ||
| 14 | + | ||
| 13 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 15 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 14 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; | 16 | import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS; |
| 15 | 17 | ||
| @@ -27,6 +29,8 @@ public class ProductServiceImpl implements ProductService { | @@ -27,6 +29,8 @@ public class ProductServiceImpl implements ProductService { | ||
| 27 | 29 | ||
| 28 | @Override | 30 | @Override |
| 29 | public Long createProduct(ProductSaveReqVO createReqVO) { | 31 | public Long createProduct(ProductSaveReqVO createReqVO) { |
| 32 | + // 生成 ProductKey | ||
| 33 | + createProductKey(createReqVO); | ||
| 30 | // 插入 | 34 | // 插入 |
| 31 | ProductDO product = BeanUtils.toBean(createReqVO, ProductDO.class); | 35 | ProductDO product = BeanUtils.toBean(createReqVO, ProductDO.class); |
| 32 | productMapper.insert(product); | 36 | productMapper.insert(product); |
| @@ -34,6 +38,17 @@ public class ProductServiceImpl implements ProductService { | @@ -34,6 +38,17 @@ public class ProductServiceImpl implements ProductService { | ||
| 34 | return product.getId(); | 38 | return product.getId(); |
| 35 | } | 39 | } |
| 36 | 40 | ||
| 41 | + /** | ||
| 42 | + * 创建 ProductKey | ||
| 43 | + * | ||
| 44 | + * @param createReqVO 创建信息 | ||
| 45 | + */ | ||
| 46 | + private void createProductKey(ProductSaveReqVO createReqVO) { | ||
| 47 | + // 生成随机的 11 位字符串 | ||
| 48 | + String productKey = UUID.randomUUID().toString().replace("-", "").substring(0, 11); | ||
| 49 | + createReqVO.setProductKey(productKey); | ||
| 50 | + } | ||
| 51 | + | ||
| 37 | @Override | 52 | @Override |
| 38 | public void updateProduct(ProductSaveReqVO updateReqVO) { | 53 | public void updateProduct(ProductSaveReqVO updateReqVO) { |
| 39 | // 校验存在 | 54 | // 校验存在 |