Переглянути джерело

fix:增加并修改新增数据的校验规则

qingwudarao 6 місяців тому
батько
коміт
827f915373

+ 6 - 1
ruoyi-modules/ruoyi-commodityManagement/src/main/java/org/dromara/commodityManagement/service/impl/BrandServiceImpl.java

@@ -39,6 +39,9 @@ public class BrandServiceImpl implements BrandService {
     @Override
     public int insertBrand(BrandBo brandBo) {
         Brand brand = MapstructUtils.convert(brandBo, Brand.class);
+        if (null != brandMapper.selectVoById(brand.getId())){
+            throw new ServiceException("品牌已存在!");
+        }
         validEntityBeforeSave(brand);
         return brandMapper.insert(brand);
     }
@@ -59,13 +62,15 @@ public class BrandServiceImpl implements BrandService {
 
     /**
      * 保存前校验
-     * @param entity 实体对象
+     * @param entity Brand实体对象
      */
     private void validEntityBeforeSave(Brand entity) {
         if (!StringUtils.isNotEmpty(entity.getName())) {
             throw new ServiceException("名称不能为空!");
         } else if (!StringUtils.isNoneBlank(entity.getType())) {
             throw new ServiceException("类型不能为空!");
+        } else if (!(entity.getType().equals("1") || entity.getType().equals("2"))) {
+            throw new ServiceException("类型错误!");
         }
     }