【功能优化】 产品发布后物模型不可操作优化
This commit is contained in:
parent
7b5aa23d5c
commit
88088c7987
|
@ -13,6 +13,7 @@ public interface ErrorCodeConstants {
|
|||
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_050_001_000, "产品不存在");
|
||||
ErrorCode PRODUCT_IDENTIFICATION_EXISTS = new ErrorCode(1_050_001_001, "产品标识已经存在");
|
||||
ErrorCode PRODUCT_STATUS_NOT_DELETE = new ErrorCode(1_050_001_002, "产品状是发布状态,不允许删除");
|
||||
ErrorCode PRODUCT_STATUS_NOT_ALLOW_FUNCTION = new ErrorCode(1_050_001_003, "产品状是发布状态,不允许操作物模型");
|
||||
|
||||
// ========== IoT 产品物模型 1-050-002-000 ============
|
||||
ErrorCode THINK_MODEL_FUNCTION_NOT_EXISTS = new ErrorCode(1_050_002_000, "产品物模型不存在");
|
||||
|
|
|
@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.thinkmodelfunction.IotThinkMod
|
|||
import cn.iocoder.yudao.module.iot.dal.mysql.thinkmodelfunction.IotThinkModelFunctionMapper;
|
||||
import cn.iocoder.yudao.module.iot.enums.product.IotAccessModeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.product.IotProductFunctionTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.product.IotProductStatusEnum;
|
||||
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
|
||||
import cn.iocoder.yudao.module.iot.service.tdengine.IotDbStructureDataService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -65,17 +66,27 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
// 3. 系统保留字段,不能用于标识符定义
|
||||
validateNotDefaultEventAndService(createReqVO.getIdentifier());
|
||||
|
||||
// 3. 插入数据库
|
||||
// 4. 校验产品状态,发布状态下,不允许新增功能
|
||||
validateProductStatus(createReqVO.getProductId());
|
||||
|
||||
// 5. 插入数据库
|
||||
IotThinkModelFunctionDO function = IotThinkModelFunctionConvert.INSTANCE.convert(createReqVO);
|
||||
thinkModelFunctionMapper.insert(function);
|
||||
|
||||
// 4. 如果创建的是属性,需要更新默认的事件和服务
|
||||
// 6. 如果创建的是属性,需要更新默认的事件和服务
|
||||
if (Objects.equals(createReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
|
||||
createDefaultEventsAndServices(createReqVO.getProductId(), createReqVO.getProductKey());
|
||||
}
|
||||
return function.getId();
|
||||
}
|
||||
|
||||
private void validateProductStatus(Long createReqVO) {
|
||||
IotProductDO product = productService.getProduct(createReqVO);
|
||||
if (Objects.equals(product.getStatus(), IotProductStatusEnum.PUBLISHED.getType())) {
|
||||
throw exception(PRODUCT_STATUS_NOT_ALLOW_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateNotDefaultEventAndService(String identifier) {
|
||||
// set, get, post, property, event, time, value 是系统保留字段,不能用于标识符定义
|
||||
if (CollUtil.containsAny(Arrays.asList("set", "get", "post", "property", "event", "time", "value"), Collections.singletonList(identifier))) {
|
||||
|
@ -109,11 +120,14 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
// 2. 校验功能标识符是否唯一
|
||||
validateIdentifierUniqueForUpdate(updateReqVO.getId(), updateReqVO.getProductId(), updateReqVO.getIdentifier());
|
||||
|
||||
// 3. 更新数据库
|
||||
// 3. 校验产品状态,发布状态下,不允许操作功能
|
||||
validateProductStatus(updateReqVO.getProductId());
|
||||
|
||||
// 4. 更新数据库
|
||||
IotThinkModelFunctionDO thinkModelFunction = IotThinkModelFunctionConvert.INSTANCE.convert(updateReqVO);
|
||||
thinkModelFunctionMapper.updateById(thinkModelFunction);
|
||||
|
||||
// 4. 如果更新的是属性,需要更新默认的事件和服务
|
||||
// 5. 如果更新的是属性,需要更新默认的事件和服务
|
||||
if (Objects.equals(updateReqVO.getType(), IotProductFunctionTypeEnum.PROPERTY.getType())) {
|
||||
createDefaultEventsAndServices(updateReqVO.getProductId(), updateReqVO.getProductKey());
|
||||
}
|
||||
|
@ -135,6 +149,9 @@ public class IotThinkModelFunctionServiceImpl implements IotThinkModelFunctionSe
|
|||
throw exception(THINK_MODEL_FUNCTION_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 3. 校验产品状态,发布状态下,不允许操作功能
|
||||
validateProductStatus(functionDO.getProductId());
|
||||
|
||||
// 2. 删除功能
|
||||
thinkModelFunctionMapper.deleteById(id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue