he2802 %!s(int64=4) %!d(string=hai) anos
pai
achega
14e883f332

+ 16 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/base/service/impl/CertificateServiceImpl.java

@@ -1,12 +1,15 @@
 package com.zhongzheng.modules.base.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.modules.base.bo.CertificateAddBo;
 import com.zhongzheng.modules.base.bo.CertificateEditBo;
 import com.zhongzheng.modules.base.bo.CertificateQueryBo;
+import com.zhongzheng.modules.base.domain.ApplyAreas;
 import com.zhongzheng.modules.base.domain.Certificate;
 import com.zhongzheng.modules.base.mapper.CertificateMapper;
 import com.zhongzheng.modules.base.service.ICertificateService;
@@ -91,6 +94,9 @@ public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certi
      */
     private void validEntityBeforeSave(Certificate entity){
         //TODO 做一些数据校验,如唯一约束
+        if(checkNameUnique(entity)&&Validator.isEmpty(entity.getId())){
+            throw new CustomException("名称重复");
+        }
     }
 
     @Override
@@ -100,4 +106,14 @@ public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certi
         }
         return this.removeByIds(ids);
     }
+
+    private boolean checkNameUnique(Certificate entity) {
+        Certificate info = getOne(new LambdaQueryWrapper<Certificate>()
+                .eq(Certificate::getCertificateName,entity.getCertificateName())
+                .last("limit 1"));
+        if (Validator.isNotNull(info)) {
+            return true;
+        }
+        return false;
+    }
 }