Forráskód Böngészése

fix: 新增产品时productKey校验

jay 1 éve
szülő
commit
c866098564

+ 2 - 1
iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/ErrCode.java

@@ -104,7 +104,8 @@ public enum ErrCode implements IEnum {
     RECORD_NOT_FOUND(00000000, "记录不存在"),
     ADD_PLATFORM_USER_ERROR(00000000, "添加平台用户失败"),
     UPLOAD_FILE_ERROR(00000000, "上传文件失败"),
-    FILE_NAME_IS_NULL(00000000, "文件名为空,获取文件名失败");
+    FILE_NAME_IS_NULL(00000000, "文件名为空,获取文件名失败"),
+    PRODUCT_KEY_EXIST(00000000, "ProductKey已存在");
 
 
 

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

@@ -87,6 +87,11 @@ public class ProductServiceImpl implements IProductService {
 
         String secret = UUID.randomUUID().toString(true);
         product.setProductSecret(secret);
+        String productKey = data.getProductKey();
+        Product oldProduct = productData.findByProductKey(productKey);
+        if(oldProduct != null){
+            throw new BizException(ErrCode.PRODUCT_KEY_EXIST);
+        }
 
         productData.save(product);
         return MapstructUtils.convert(product, ProductVo.class);