Просмотр исходного кода

更新物料信息校验方法

hejq 7 лет назад
Родитель
Сommit
ad5e9bb090

+ 3 - 9
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -2463,18 +2463,12 @@ public class ProductServiceImpl implements ProductService {
     private ResultMap checkProductInfo(Product product) {
         StringBuffer errMsg = new StringBuffer();
         String GBK_CHARSET_NAME = "GBK";
-        String UTF_8_CHARSET_NAME = "UTF-8";
-        int maxBrandEnLength = 50;
-        int maxBrandCnLength = 25;
-        int maxKindLength = 20;
-        int maxCmpCodeLength = 100;
         // 验证品牌
         if (StringUtils.isEmpty(product.getBrand())) {
             jointErrMsg(errMsg, ErrorInfoConstant.BRAND_EMPTY_INFO.getInfo());
         } else {
             try {
-                if (product.getBrand().getBytes(GBK_CHARSET_NAME).length > maxBrandCnLength
-                        || product.getBrand().getBytes(UTF_8_CHARSET_NAME).length > maxBrandEnLength) {
+                if (product.getBrand().getBytes(GBK_CHARSET_NAME).length > ProductConstant.MAX_BRAND_EN_LENGTH) {
                     jointErrMsg(errMsg, ErrorInfoConstant.BRAND_LENGTH_INFO.getInfo());
                 }
             } catch (UnsupportedEncodingException e) {
@@ -2486,7 +2480,7 @@ public class ProductServiceImpl implements ProductService {
             jointErrMsg(errMsg, ErrorInfoConstant.KIND_EMPTY_INFO.getInfo());
         } else {
             try {
-                if (product.getProdName().getBytes(GBK_CHARSET_NAME).length > maxKindLength) {
+                if (product.getProdName().getBytes(GBK_CHARSET_NAME).length > ProductConstant.MAX_KIND_LENGTH) {
                     jointErrMsg(errMsg, ErrorInfoConstant.KIND_LENGTH_INFO.getInfo());
                 }
             } catch (UnsupportedEncodingException e) {
@@ -2501,7 +2495,7 @@ public class ProductServiceImpl implements ProductService {
                 jointErrMsg(errMsg, ErrorInfoConstant.CODE_PATTERN_INFO.getInfo());
             }
             try {
-                if (code.getBytes(GBK_CHARSET_NAME).length > maxCmpCodeLength) {
+                if (code.getBytes(GBK_CHARSET_NAME).length > ProductConstant.MAX_CMPCODE_LENGTH) {
                     jointErrMsg(errMsg, ErrorInfoConstant.CODE_LENGTH_INFO.getInfo());
                 }
             } catch (UnsupportedEncodingException e) {

+ 20 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/type/ProductConstant.java

@@ -21,4 +21,24 @@ public class ProductConstant {
      * 全部
      */
     public final static String ALL = "all";
+
+    /**
+     * 英文品牌最长长度
+     */
+    public final static int MAX_BRAND_EN_LENGTH = 50;
+
+    /**
+     * 中文品牌最长长度
+     */
+    public final static int MAX_BRAND_CN_LENGTH = 25;
+
+    /**
+     * 类目最长长度
+     */
+    public final static int MAX_KIND_LENGTH = 20;
+
+    /**
+     * 型号最长长度
+     */
+    public final static int MAX_CMPCODE_LENGTH = 100;
 }