Commit 88088c798799bfebd00439199914f2fb08a7a8a9
1 parent
7b5aa23d
【功能优化】 产品发布后物模型不可操作优化
Showing
2 changed files
with
22 additions
and
4 deletions
yudao-module-iot/yudao-module-iot-api/src/main/java/cn/iocoder/yudao/module/iot/enums/ErrorCodeConstants.java
| ... | ... | @@ -13,6 +13,7 @@ public interface ErrorCodeConstants { |
| 13 | 13 | ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在"); |
| 14 | 14 | ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在"); |
| 15 | 15 | ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除"); |
| 16 | + ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型"); | |
| 16 | 17 | |
| 17 | 18 | // ========== IoT 产品物模型 1-050-002-000 ============ |
| 18 | 19 | ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在"); | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/thinkmodelfunction/IotThinkModelFunctionServiceImpl.java
| ... | ... | @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkMod |
| 20 | 20 | import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper; |
| 21 | 21 | import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum; |
| 22 | 22 | import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum; |
| 23 | +import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum; | |
| 23 | 24 | import cn.iocoder.yudao.module.iot.service.product.IotProductService; |
| 24 | 25 | import cn.iocoder.yudao.module.iot.service.tdengine.IotDbStructureDataService; |
| 25 | 26 | import jakarta.annotation.Resource; |
| ... | ... | @@ -65,17 +66,27 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe |
| 65 | 66 | // 3. 系统保留字段,不能用于标识符定义 |
| 66 | 67 | validateNotDefaultEventAndService(createReqVO.getIdentifier()); |
| 67 | 68 | |
| 68 | - // 3. 插入数据库 | |
| 69 | + // 4. 校验产品状态,发布状态下,不允许新增功能 | |
| 70 | + validateProductStatus(createReqVO.getProductId()); | |
| 71 | + | |
| 72 | + // 5. 插入数据库 | |
| 69 | 73 | IotThinkModelFunctionDO function = IotThinkModelFunctionConvert.INSTANCE.convert(createReqVO); |
| 70 | 74 | thinkModelFunctionMapper.insert(function); |
| 71 | 75 | |
| 72 | - // 4. 如果创建的是属性,需要更新默认的事件和服务 | |
| 76 | + // 6. 如果创建的是属性,需要更新默认的事件和服务 | |
| 73 | 77 | if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { |
| 74 | 78 | createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey()); |
| 75 | 79 | } |
| 76 | 80 | return function.getId(); |
| 77 | 81 | } |
| 78 | 82 | |
| 83 | + private void validateProductStatus(Long createReqVO) { | |
| 84 | + IotProductDO product = productService.getProduct(createReqVO); | |
| 85 | + if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) { | |
| 86 | + throw exception(PRODUCT_STATUS_NOT_ALLOW_FUNCTION); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 79 | 90 | private void validateNotDefaultEventAndService(String identifier) { |
| 80 | 91 | // set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义 |
| 81 | 92 | if (CollUtil.containsAny(Arrays.asList("set", "get", "post", "property", "event", "time", "value"), Collections.singletonList(identifier))) { |
| ... | ... | @@ -109,11 +120,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe |
| 109 | 120 | // 2. 校验功能标识符是否唯一 |
| 110 | 121 | validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier()); |
| 111 | 122 | |
| 112 | - // 3. 更新数据库 | |
| 123 | + // 3. 校验产品状态,发布状态下,不允许操作功能 | |
| 124 | + validateProductStatus(updateReqVO.getProductId()); | |
| 125 | + | |
| 126 | + // 4. 更新数据库 | |
| 113 | 127 | IotThinkModelFunctionDO thinkModelFunction = IotThinkModelFunctionConvert.INSTANCE.convert(updateReqVO); |
| 114 | 128 | thinkModelFunctionMapper.updateById(thinkModelFunction); |
| 115 | 129 | |
| 116 | - // 4. 如果更新的是属性,需要更新默认的事件和服务 | |
| 130 | + // 5. 如果更新的是属性,需要更新默认的事件和服务 | |
| 117 | 131 | if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) { |
| 118 | 132 | createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey()); |
| 119 | 133 | } |
| ... | ... | @@ -135,6 +149,9 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe |
| 135 | 149 | throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS); |
| 136 | 150 | } |
| 137 | 151 | |
| 152 | + // 3. 校验产品状态,发布状态下,不允许操作功能 | |
| 153 | + validateProductStatus(functionDO.getProductId()); | |
| 154 | + | |
| 138 | 155 | // 2. 删除功能 |
| 139 | 156 | thinkModelFunctionMapper.deleteById(id); |
| 140 | 157 | ... | ... |