Browse Source

供应商导入修改,增加验证和必填筛选

v_KaixiangGuo 3 years ago
parent
commit
f54a7b927c

+ 52 - 23
abi-cloud-qr-platform-server/src/main/java/com/abi/qms/platform/service/impl/FactoryServiceImpl.java

@@ -357,33 +357,62 @@ public class FactoryServiceImpl implements FactoryService {
         if (StringUtils.isBlank(factoryProperty.getFactoryName())) {
             errorMessage.append("供应商名称").append("为空,");
         }
-        if (StringUtils.isBlank(factoryProperty.getFactoryType())) {
+        if (StringUtils.isNotBlank(factoryProperty.getFactoryType())) {
+            if(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()) == null){
+                errorMessage.append("供应商类型").append("枚举值不正确,");
+            }else {
+                if (!FactoryTypeEnum.BEER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))) {
+                    if (StringUtils.isBlank(factoryProperty.getEmail())) {
+                        errorMessage.append("邮箱").append("为空,");
+                    }
+                    if (StringUtils.isBlank(factoryProperty.getProvince())) {
+                        errorMessage.append("省").append("为空,");
+                    }
+                    if (StringUtils.isBlank(factoryProperty.getCity())) {
+                        errorMessage.append("市").append("为空,");
+                    }
+                    if (StringUtils.isBlank(factoryProperty.getDistrict())) {
+                        errorMessage.append("区").append("为空,");
+                    }
+                    if (StringUtils.isBlank(factoryProperty.getAddress())) {
+                        errorMessage.append("详细地址").append("为空,");
+                    }
+                }
+                if (FactoryTypeEnum.TWO_COVER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))) {
+                    if (StringUtils.isBlank(factoryProperty.getKeymanName())) {
+                        errorMessage.append("联系人姓名").append("为空,");
+                    }
+                    if (StringUtils.isBlank(factoryProperty.getKeymanMobile())) {
+                        errorMessage.append("联系人手机号").append("为空,");
+                    }
+                }
+            }
+        }else {
             errorMessage.append("供应商类型").append("为空,");
         }
-        if (StringUtils.isNotBlank(factoryProperty.getFactoryType())
-                && FactoryTypeEnum.getCode(factoryProperty.getFactoryType()) == null) {
-            errorMessage.append("供应商类型").append("枚举值不正确,");
-        }
-        if (StringUtils.isNotBlank(factoryProperty.getIsFirstFactory())
-                && FirstFactoryEnum.getCode(factoryProperty.getIsFirstFactory()) == null) {
-            errorMessage.append("是否一级供应商").append("枚举值不正确,");
-        }
-        if (StringUtils.isBlank(factoryProperty.getKeymanName())) {
-            errorMessage.append("联系人姓名").append("为空,");
-        }
-        if (StringUtils.isBlank(factoryProperty.getKeymanMobile())) {
-            errorMessage.append("联系人手机号").append("为空,");
-        }
-        Pattern patternPhone = Pattern.compile("^[1]\\d{10}$");
-        if (!patternPhone.matcher(factoryProperty.getKeymanMobile()).matches()) {
-            errorMessage.append("联系人手机号").append("格式不正确,");
+        if (StringUtils.isNotBlank(factoryProperty.getIsFirstFactory())) {
+            if(FirstFactoryEnum.getCode(factoryProperty.getIsFirstFactory()) == null){
+                errorMessage.append("是否一级供应商").append("枚举值不正确,");
+            }
+        }else {
+            if (StringUtils.isNotBlank(factoryProperty.getFactoryType())
+                    && FactoryTypeEnum.COVER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))){
+                errorMessage.append("是否一级供应商").append("为空,");
+            }
         }
-        if (StringUtils.isBlank(factoryProperty.getEmail())) {
-            errorMessage.append("邮箱").append("为空,");
+        //验证手机号
+        if (StringUtils.isNotBlank(factoryProperty.getKeymanMobile())){
+            Pattern keymanMobileFormat = Pattern.compile("^1[0-9]{10}$");
+            if (!keymanMobileFormat.matcher(factoryProperty.getKeymanMobile()).matches()){
+                errorMessage.append("联系人手机号").append("格式不正确,");
+            }
         }
-        Pattern patternEmail = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
-        if (!patternEmail.matcher(factoryProperty.getEmail()).matches()) {
-            errorMessage.append("邮箱").append("格式不正确,");
+        //验证邮箱
+        if (StringUtils.isNotBlank(factoryProperty.getEmail())) {
+            Pattern emailFormat = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
+            if (!emailFormat.matcher(factoryProperty.getEmail()).matches()) {
+                errorMessage.append("邮箱").append("格式不正确,");
+            }
         }
 
         return errorMessage.toString();