浏览代码

产品自定义编码为空算重复问题处理

yzc 2 年之前
父节点
当前提交
a2dd2bf757
共有 1 个文件被更改,包括 12 次插入4 次删除
  1. 12 4
      hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

+ 12 - 4
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -316,8 +316,12 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         productInfoDto.setCode(CodeEnum.PRODUCT.getCode());
         // 排除名称重复
         this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), "产品名称重复");
-        // 排除自定义编码重复
-        this.nameDuplication(ProductInfo::getCustomCode, productInfoDto.getCustomCode(), "产品自定义编码重复");
+        // 排除不为空的自定义编码重复
+        long count = this.count(q -> q.eq(ProductInfo::getCustomCode, productInfoDto.getCustomCode()).ne(ProductInfo::getCustomCode,""));
+        if (count != 0) {
+            throw new ServiceException("产品自定义编码重复");
+        }
+
         this.save(productInfoDto);
         ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId());
     }
@@ -472,8 +476,12 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         productInfoDto.setCode(null);
         // 排除名称重复
         this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), productInfoDto.getId(), "产品名称重复");
-        // 排除自定义编码重复
-        this.nameDuplication(ProductInfo::getCustomCode, productInfoDto.getCustomCode(), productInfoDto.getId(), "产品自定义编码重复");
+        // 排除不为空的自定义编码重复
+        long count = this.count(q -> q.ne(ProductInfo::getId,productInfoDto.getId())
+                .eq(ProductInfo::getCustomCode, productInfoDto.getCustomCode()).ne(ProductInfo::getCustomCode,""));
+        if (count != 0) {
+            throw new ServiceException("产品自定义编码重复");
+        }
         this.updateById(productInfoDto);
         ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
     }