Bläddra i källkod

fix:增加物模型属性标识符校验

xiwa 1 år sedan
förälder
incheckning
0ae3275c1b

+ 0 - 2
iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java

@@ -58,9 +58,7 @@ public class ProductController {
     @PostMapping(value = "/add")
     @Log(title = "产品", businessType = BusinessType.INSERT)
     public ProductVo create(@Validated(AddGroup.class) @RequestBody Request<ProductBo> request) {
-
         return productService.addEntity(request.getData());
-
     }
 
     @ApiOperation(value = "编辑产品")

+ 13 - 0
iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ProductServiceImpl.java

@@ -135,6 +135,19 @@ public class ProductServiceImpl implements IProductService {
         ThingModel oldData = thingModelData.findByProductKey(productKey);
         ThingModel thingModel = new ThingModel(YitIdHelper.nextId(), productKey, JsonUtils.parseObject(model, ThingModel.Model.class));
 
+        //验证物模型合法性
+        List<ThingModel.Property> properties = thingModel.getModel().getProperties();
+        for (ThingModel.Property property : properties) {
+            //属性标识符合法性校验
+            String identifier = property.getIdentifier();
+            if (StringUtils.isBlank(identifier)) {
+                throw new BizException("属性标识符不能为空");
+            }
+            if (!identifier.matches("^[a-zA-Z].*")) {
+                throw new BizException("属性标识符【" + identifier + "】不合法");
+            }
+        }
+
         if (oldData == null) {
             //定义时序数据库物模型数据结构
             dbStructureData.defineThingModel(thingModel);

+ 0 - 3
待优化项.md

@@ -72,7 +72,4 @@ sql 日志打印的话加个拦截器,简化sql
 ## **代码生成器**
 目前代码生成器改成了jpa,但是还存在大量错误
 
-## **物模型**
-物模型标识符命名增加合法性验证
-