Commit a8c87d168accd14f5b266be9815046b1b45ff9db

Authored by YunaiV
1 parent 9b9fd30c

【功能新增】IoT:产品新增时,productKey 由前端生成;同时增加 icon、picUrl 字段

yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
... ... @@ -11,7 +11,7 @@ public interface ErrorCodeConstants {
11 11  
12 12 // ========== 产品相关 1-050-001-000 ============
13 13 ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在");
14   - ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在");
  14 + ErrorCode PRODUCT_KEY_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在");
15 15 ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除");
16 16 ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型");
17 17  
... ...
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/product/IotProductStatusEnum.java
... ... @@ -18,12 +18,12 @@ public enum IotProductStatusEnum implements IntArrayValuable {
18 18 UNPUBLISHED(0, "开发中"),
19 19 PUBLISHED(1, "已发布");
20 20  
21   - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductStatusEnum::getType).toArray();
  21 + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(IotProductStatusEnum::getStatus).toArray();
22 22  
23 23 /**
24 24 * 类型
25 25 */
26   - private final Integer type;
  26 + private final Integer status;
27 27 /**
28 28 * 描述
29 29 */
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/product/IotProductCategoryController.java
1 1 package cn.iocoder.yudao.module.iot.controller.admin.product;
2 2  
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
3 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
... ... @@ -17,7 +18,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
17 18 import org.springframework.validation.annotation.Validated;
18 19 import org.springframework.web.bind.annotation.*;
19 20  
  21 +import java.util.List;
  22 +
20 23 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  24 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
21 25  
22 26 @Tag(name = "管理后台 - IoT 产品分类")
23 27 @RestController
... ... @@ -29,14 +33,14 @@ public class IotProductCategoryController {
29 33 private IotProductCategoryService productCategoryService;
30 34  
31 35 @PostMapping("/create")
32   - @Operation(summary = "创建IoT 产品分类")
  36 + @Operation(summary = "创建产品分类")
33 37 @PreAuthorize("@ss.hasPermission('iot:product-category:create')")
34 38 public CommonResult<Long> createProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO createReqVO) {
35 39 return success(productCategoryService.createProductCategory(createReqVO));
36 40 }
37 41  
38 42 @PutMapping("/update")
39   - @Operation(summary = "更新IoT 产品分类")
  43 + @Operation(summary = "更新产品分类")
40 44 @PreAuthorize("@ss.hasPermission('iot:product-category:update')")
41 45 public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody IotProductCategorySaveReqVO updateReqVO) {
42 46 productCategoryService.updateProductCategory(updateReqVO);
... ... @@ -44,7 +48,7 @@ public class IotProductCategoryController {
44 48 }
45 49  
46 50 @DeleteMapping("/delete")
47   - @Operation(summary = "删除IoT 产品分类")
  51 + @Operation(summary = "删除产品分类")
48 52 @Parameter(name = "id", description = "编号", required = true)
49 53 @PreAuthorize("@ss.hasPermission('iot:product-category:delete')")
50 54 public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) {
... ... @@ -53,7 +57,7 @@ public class IotProductCategoryController {
53 57 }
54 58  
55 59 @GetMapping("/get")
56   - @Operation(summary = "获得IoT 产品分类")
  60 + @Operation(summary = "获得产品分类")
57 61 @Parameter(name = "id", description = "编号", required = true, example = "1024")
58 62 @PreAuthorize("@ss.hasPermission('iot:product-category:query')")
59 63 public CommonResult<IotProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) {
... ... @@ -62,11 +66,21 @@ public class IotProductCategoryController {
62 66 }
63 67  
64 68 @GetMapping("/page")
65   - @Operation(summary = "获得IoT 产品分类分页")
  69 + @Operation(summary = "获得产品分类分页")
66 70 @PreAuthorize("@ss.hasPermission('iot:product-category:query')")
67 71 public CommonResult<PageResult<IotProductCategoryRespVO>> getProductCategoryPage(@Valid IotProductCategoryPageReqVO pageReqVO) {
68 72 PageResult<IotProductCategoryDO> pageResult = productCategoryService.getProductCategoryPage(pageReqVO);
69 73 return success(BeanUtils.toBean(pageResult, IotProductCategoryRespVO.class));
70 74 }
71 75  
  76 + @GetMapping("/simple-list")
  77 + @Operation(summary = "获得所有产品分类列表")
  78 + @PreAuthorize("@ss.hasPermission('iot:product-category:query')")
  79 + public CommonResult<List<IotProductCategoryRespVO>> getSimpleProductCategoryList() {
  80 + List<IotProductCategoryDO> list = productCategoryService.getProductCategoryListByStatus(
  81 + CommonStatusEnum.ENABLE.getStatus());
  82 + return success(convertList(list, category ->
  83 + new IotProductCategoryRespVO().setId(category.getId()).setName(category.getName())));
  84 + }
  85 +
72 86 }
73 87 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/product/IotProductCategoryMapper.java
... ... @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu
7 7 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
8 8 import org.apache.ibatis.annotations.Mapper;
9 9  
  10 +import java.util.List;
  11 +
10 12 /**
11 13 * IoT 产品分类 Mapper
12 14 *
... ... @@ -22,4 +24,8 @@ public interface IotProductCategoryMapper extends BaseMapperX&lt;IotProductCategory
22 24 .orderByDesc(IotProductCategoryDO::getId));
23 25 }
24 26  
  27 + default List<IotProductCategoryDO> selectListByStatus(Integer status) {
  28 + return selectList(IotProductCategoryDO::getStatus, status);
  29 + }
  30 +
25 31 }
26 32 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryService.java
... ... @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.iot.controller.admin.product.vo.category.IotProdu
6 6 import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductCategoryDO;
7 7 import jakarta.validation.Valid;
8 8  
  9 +import java.util.List;
  10 +
9 11 /**
10 12 * IoT 产品分类 Service 接口
11 13 *
... ... @@ -14,7 +16,7 @@ import jakarta.validation.Valid;
14 16 public interface IotProductCategoryService {
15 17  
16 18 /**
17   - * 创建IoT 产品分类
  19 + * 创建产品分类
18 20 *
19 21 * @param createReqVO 创建信息
20 22 * @return 编号
... ... @@ -22,33 +24,41 @@ public interface IotProductCategoryService {
22 24 Long createProductCategory(@Valid IotProductCategorySaveReqVO createReqVO);
23 25  
24 26 /**
25   - * 更新IoT 产品分类
  27 + * 更新产品分类
26 28 *
27 29 * @param updateReqVO 更新信息
28 30 */
29 31 void updateProductCategory(@Valid IotProductCategorySaveReqVO updateReqVO);
30 32  
31 33 /**
32   - * 删除IoT 产品分类
  34 + * 删除产品分类
33 35 *
34 36 * @param id 编号
35 37 */
36 38 void deleteProductCategory(Long id);
37 39  
38 40 /**
39   - * 获得IoT 产品分类
  41 + * 获得产品分类
40 42 *
41 43 * @param id 编号
42   - * @return IoT 产品分类
  44 + * @return 产品分类
43 45 */
44 46 IotProductCategoryDO getProductCategory(Long id);
45 47  
46 48 /**
47   - * 获得IoT 产品分类分页
  49 + * 获得产品分类分页
48 50 *
49 51 * @param pageReqVO 分页查询
50   - * @return IoT 产品分类分页
  52 + * @return 产品分类分页
51 53 */
52 54 PageResult<IotProductCategoryDO> getProductCategoryPage(IotProductCategoryPageReqVO pageReqVO);
53 55  
  56 + /**
  57 + * 获得产品分类列表,根据状态
  58 + *
  59 + * @param status 状态
  60 + * @return 产品分类列表
  61 + */
  62 + List<IotProductCategoryDO> getProductCategoryListByStatus(Integer status);
  63 +
54 64 }
55 65 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductCategoryServiceImpl.java
... ... @@ -10,6 +10,8 @@ import jakarta.annotation.Resource;
10 10 import org.springframework.stereotype.Service;
11 11 import org.springframework.validation.annotation.Validated;
12 12  
  13 +import java.util.List;
  14 +
13 15 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
14 16 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.PRODUCT_CATEGORY_NOT_EXISTS;
15 17  
... ... @@ -67,4 +69,9 @@ public class IotProductCategoryServiceImpl implements IotProductCategoryService
67 69 return productCategoryMapper.selectPage(pageReqVO);
68 70 }
69 71  
  72 + @Override
  73 + public List<IotProductCategoryDO> getProductCategoryListByStatus(Integer status) {
  74 + return productCategoryMapper.selectListByStatus(status);
  75 + }
  76 +
70 77 }
71 78 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/product/IotProductServiceImpl.java
1 1 package cn.iocoder.yudao.module.iot.service.product;
2 2  
3   -import cn.hutool.core.util.StrUtil;
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.product.vo.product.IotProductPageReqVO;
... ... @@ -11,14 +10,12 @@ import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
11 10 import cn.iocoder.yudao.module.iot.service.thinkmodelfunction.IotThinkModelFunctionService;
12 11 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
13 12 import jakarta.annotation.Resource;
14   -
15 13 import org.springframework.context.annotation.Lazy;
16 14 import org.springframework.stereotype.Service;
17 15 import org.springframework.validation.annotation.Validated;
18 16  
19 17 import java.util.List;
20 18 import java.util.Objects;
21   -import java.util.UUID;
22 19  
23 20 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
24 21 import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.*;
... ... @@ -42,31 +39,16 @@ public class IotProductServiceImpl implements IotProductService {
42 39 @Override
43 40 public Long createProduct(IotProductSaveReqVO createReqVO) {
44 41 // 1. 生成 ProductKey
45   - createProductKey(createReqVO);
  42 + if (productMapper.selectByProductKey(createReqVO.getProductKey()) != null) {
  43 + throw exception(PRODUCT_KEY_EXISTS);
  44 + }
46 45 // 2. 插入
47   - IotProductDO product = BeanUtils.toBean(createReqVO, IotProductDO.class);
  46 + IotProductDO product = BeanUtils.toBean(createReqVO, IotProductDO.class)
  47 + .setStatus(IotProductStatusEnum.UNPUBLISHED.getStatus());
48 48 productMapper.insert(product);
49 49 return product.getId();
50 50 }
51 51  
52   - /**
53   - * 创建 ProductKey
54   - *
55   - * @param createReqVO 创建信息
56   - */
57   - private void createProductKey(IotProductSaveReqVO createReqVO) {
58   - String productKey = createReqVO.getProductKey();
59   - // 1. productKey为空,生成随机的 11 位字符串
60   - if (StrUtil.isEmpty(productKey)) {
61   - productKey = UUID.randomUUID().toString().replace("-", "").substring(0, 11);
62   - }
63   - // 2. 校验唯一性
64   - if (productMapper.selectByProductKey(productKey) != null) {
65   - throw exception(PRODUCT_IDENTIFICATION_EXISTS);
66   - }
67   - createReqVO.setProductKey(productKey);
68   - }
69   -
70 52 @Override
71 53 public void updateProduct(IotProductSaveReqVO updateReqVO) {
72 54 updateReqVO.setProductKey(null); // 不更新产品标识
... ... @@ -98,7 +80,7 @@ public class IotProductServiceImpl implements IotProductService {
98 80 }
99 81  
100 82 private void validateProductStatus(IotProductDO iotProductDO) {
101   - if (Objects.equals(iotProductDO.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) {
  83 + if (Objects.equals(iotProductDO.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) {
102 84 throw exception(PRODUCT_STATUS_NOT_DELETE);
103 85 }
104 86 }
... ... @@ -121,7 +103,7 @@ public class IotProductServiceImpl implements IotProductService {
121 103 // 2. 更新
122 104 IotProductDO updateObj = IotProductDO.builder().id(id).status(status).build();
123 105 // 3. 产品是发布状态
124   - if (Objects.equals(status, IotProductStatusEnum.PUBLISHED.getType())) {
  106 + if (Objects.equals(status, IotProductStatusEnum.PUBLISHED.getStatus())) {
125 107 // 3.1 创建超级表数据模型
126 108 thinkModelFunctionService.createSuperTableDataModel(id);
127 109 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionServiceImpl.java
... ... @@ -82,7 +82,7 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
82 82  
83 83 private void validateProductStatus(Long createReqVO) {
84 84 IotProductDO product = productService.getProduct(createReqVO);
85   - if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) {
  85 + if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getStatus())) {
86 86 throw exception(PRODUCT_STATUS_NOT_ALLOW_FUNCTION);
87 87 }
88 88 }
... ...