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