Browse Source

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

v_KaixiangGuo 3 years ago
parent
commit
668e2a52a6

+ 3 - 3
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/excel/preperties/FactoryProperty.java

@@ -15,7 +15,7 @@ public class FactoryProperty implements AbstractExcelProperty {
     @ExcelHeadAlias(value = "供应商ID(必填)")
     private String factoryCode;
 
-    @ExcelHeadAlias(value = "供应商名称(必填)")
+    @ExcelHeadAlias(value = "供应商名称(必填)")
     private String factoryName;
 
     @ExcelHeadAlias(value = "供应商类型(必填,单选)(枚举值:包材厂,二级包材厂,啤酒厂)")
@@ -36,10 +36,10 @@ public class FactoryProperty implements AbstractExcelProperty {
     @ExcelHeadAlias(value = "详细地址(包材厂、二级包材厂必填)")
     private String address;
 
-    @ExcelHeadAlias(value = "联系人姓名(二级包材厂必填)")
+    @ExcelHeadAlias(value = "联系人姓名(包材厂、二级包材厂必填)")
     private String keymanName;
 
-    @ExcelHeadAlias(value = "联系人手机号(二级包材厂必填)")
+    @ExcelHeadAlias(value = "联系人手机号(包材厂、二级包材厂必填)")
     private String keymanMobile;
 
     @ExcelHeadAlias(value = "邮箱(包材厂、二级包材厂必填)")

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

@@ -283,8 +283,12 @@ public class FactoryServiceImpl implements FactoryService {
                     req.setKeymanName(factoryProperty.getKeymanName());
                     req.setKeymanMobile(factoryProperty.getKeymanMobile());
                     req.setEmail(factoryProperty.getEmail());
+                    req.setProvince(factoryProperty.getProvince());
+                    req.setCity(factoryProperty.getCity());
+                    req.setDistrict(factoryProperty.getDistrict());
+                    req.setMaxFileCount(IMathUtils.toLong(factoryProperty.getMaxFileCount()));
+                    req.setAddress(factoryProperty.getAddress());
                 }
-                req.setMaxFileCount(IMathUtils.toLong(factoryProperty.getMaxFileCount()));
                 req.setDescription(factoryProperty.getDescription());
 
                 saveFactory(req);
@@ -361,9 +365,41 @@ public class FactoryServiceImpl implements FactoryService {
             if(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()) == null){
                 errorMessage.append("供应商类型").append("枚举值不正确,");
             }else {
+                if (FactoryTypeEnum.COVER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))){
+                    if (StringUtils.isNotBlank(factoryProperty.getIsFirstFactory())) {
+                        if(FirstFactoryEnum.getCode(factoryProperty.getIsFirstFactory()) == null){
+                            errorMessage.append("是否一级供应商").append("枚举值不正确,");
+                        }
+                    }else {
+                        errorMessage.append("是否一级供应商").append("为空,");
+                    }
+                }
                 if (!FactoryTypeEnum.BEER.is(FactoryTypeEnum.getCode(factoryProperty.getFactoryType()))) {
+                    //邮箱判空或格式校验
                     if (StringUtils.isBlank(factoryProperty.getEmail())) {
                         errorMessage.append("邮箱").append("为空,");
+                    }else {
+                        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("格式不正确,");
+                        }
+                    }
+                    //详细地址判空或格式校验
+                    if (StringUtils.isBlank(factoryProperty.getAddress())) {
+                        errorMessage.append("详细地址").append("为空,");
+                    }else {
+                        if (factoryProperty.getAddress().length() > 50){
+                            errorMessage.append("详细地址").append("超出5o限制,");
+                        }
+                    }
+                    //手机号判空或格式校验
+                    if (StringUtils.isBlank(factoryProperty.getKeymanMobile())) {
+                        errorMessage.append("联系人手机号").append("为空,");
+                    }else {
+                        Pattern keymanMobileFormat = Pattern.compile("^1[0-9]{10}$");
+                        if (!keymanMobileFormat.matcher(factoryProperty.getKeymanMobile()).matches()){
+                            errorMessage.append("联系人手机号").append("格式不正确,");
+                        }
                     }
                     if (StringUtils.isBlank(factoryProperty.getProvince())) {
                         errorMessage.append("省").append("为空,");
@@ -374,45 +410,18 @@ public class FactoryServiceImpl implements FactoryService {
                     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.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.isNotBlank(factoryProperty.getKeymanMobile())){
-            Pattern keymanMobileFormat = Pattern.compile("^1[0-9]{10}$");
-            if (!keymanMobileFormat.matcher(factoryProperty.getKeymanMobile()).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("格式不正确,");
-            }
+
+        //描述
+        if (StringUtils.isBlank(factoryProperty.getDescription()) && factoryProperty.getDescription().length() > 50) {
+            errorMessage.append("描述").append("超出5o限制,");
         }
 
         return errorMessage.toString();