Showing
9 changed files
with
57 additions
and
22 deletions
| ... | @@ -10,24 +10,24 @@ public class ConsignmentBo { | ... | @@ -10,24 +10,24 @@ public class ConsignmentBo { |
| 10 | //运单id | 10 | //运单id |
| 11 | private Integer id; | 11 | private Integer id; |
| 12 | //运单号 | 12 | //运单号 |
| 13 | - @BaseNotBlank | 13 | + @BaseNotBlank(describe = "business_field_31003") |
| 14 | private String consignmentCode; | 14 | private String consignmentCode; |
| 15 | - //用户录入shipperAccount | 15 | + //发货人计费账号 |
| 16 | - @BaseNotBlank | 16 | + @BaseNotBlank(describe = "business_field_31001") |
| 17 | private String shipperAccount; | 17 | private String shipperAccount; |
| 18 | //原产国code | 18 | //原产国code |
| 19 | - @BaseNotBlank | 19 | + @BaseNotBlank(describe = "business_field_31004") |
| 20 | private String originCountryCode; | 20 | private String originCountryCode; |
| 21 | - //原产国全程 | 21 | + //原产国全称 |
| 22 | - @BaseNotBlank | 22 | + @BaseNotBlank(describe = "business_field_31005") |
| 23 | private String originCountry; | 23 | private String originCountry; |
| 24 | //目的国code | 24 | //目的国code |
| 25 | - @BaseNotBlank | 25 | + @BaseNotBlank(describe = "business_field_31006") |
| 26 | private String destinationCountryCode; | 26 | private String destinationCountryCode; |
| 27 | //目的国全称 | 27 | //目的国全称 |
| 28 | - @BaseNotBlank | 28 | + @BaseNotBlank(describe = "business_field_31007") |
| 29 | private String destinationCountry; | 29 | private String destinationCountry; |
| 30 | //文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型) | 30 | //文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型) |
| 31 | - @BaseNotBlank | 31 | + @BaseNotBlank(describe = "business_field_31008") |
| 32 | private List<String> fileBizType; | 32 | private List<String> fileBizType; |
| 33 | } | 33 | } | ... | ... |
| ... | @@ -9,6 +9,13 @@ public enum ResponseCode { | ... | @@ -9,6 +9,13 @@ public enum ResponseCode { |
| 9 | //********************biz_customer模块 | 9 | //********************biz_customer模块 |
| 10 | //#*********用于字段描述使用,不单独使用********** | 10 | //#*********用于字段描述使用,不单独使用********** |
| 11 | MESSAGE_CODE_31001(31001,"business_field_31001"), | 11 | MESSAGE_CODE_31001(31001,"business_field_31001"), |
| 12 | + MESSAGE_CODE_31002(31002,"business_field_31002"), | ||
| 13 | + MESSAGE_CODE_31003(31003,"business_field_31003"), | ||
| 14 | + MESSAGE_CODE_31004(31004,"business_field_31004"), | ||
| 15 | + MESSAGE_CODE_31005(31005,"business_field_31005"), | ||
| 16 | + MESSAGE_CODE_31006(31006,"business_field_31006"), | ||
| 17 | + MESSAGE_CODE_31007(31007,"business_field_31007"), | ||
| 18 | + MESSAGE_CODE_31008(31008,"business_field_31008"), | ||
| 12 | 19 | ||
| 13 | //#*********具体响应到前端********** | 20 | //#*********具体响应到前端********** |
| 14 | MESSAGE_CODE_30001(30001,"business_exception_30001"), | 21 | MESSAGE_CODE_30001(30001,"business_exception_30001"), | ... | ... |
| ... | @@ -27,7 +27,7 @@ public class ConsignmentInfoValidate { | ... | @@ -27,7 +27,7 @@ public class ConsignmentInfoValidate { |
| 27 | */ | 27 | */ |
| 28 | public void validateConsignmentId(Long consignmentId){ | 28 | public void validateConsignmentId(Long consignmentId){ |
| 29 | if (Objects.isNull(consignmentId)){ | 29 | if (Objects.isNull(consignmentId)){ |
| 30 | - responseUtils.fail(ResponseCode.MESSAGE_CODE_30001); | 30 | + responseUtils.fail(ResponseCode.MESSAGE_CODE_30001,ResponseCode.MESSAGE_CODE_31002.getMsg()); |
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | } | 33 | } | ... | ... |
| ... | @@ -45,14 +45,9 @@ public class ConsignmentValidate { | ... | @@ -45,14 +45,9 @@ public class ConsignmentValidate { |
| 45 | * @return void | 45 | * @return void |
| 46 | */ | 46 | */ |
| 47 | public void validateConsignmentSubmit(ConsignmentBo consignmentBo){ | 47 | public void validateConsignmentSubmit(ConsignmentBo consignmentBo){ |
| 48 | - Integer code = ResponseCode.MESSAGE_CODE_30001.getCode(); | ||
| 49 | - String msg = ResponseCode.MESSAGE_CODE_30001.getMsg(); | ||
| 50 | - if(Objects.isNull(consignmentBo)){ | ||
| 51 | - responseUtils.fail(ResponseCode.MESSAGE_CODE_30001); | ||
| 52 | - } | ||
| 53 | /** | 48 | /** |
| 54 | * 非空字段校验 | 49 | * 非空字段校验 |
| 55 | */ | 50 | */ |
| 56 | - baseValidateUtils.notBlankValidate(consignmentBo,code,msg); | 51 | + baseValidateUtils.notBlankValidate(consignmentBo,ResponseCode.MESSAGE_CODE_30001); |
| 57 | } | 52 | } |
| 58 | } | 53 | } | ... | ... |
| ... | @@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录 | ... | @@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录 |
| 21 | business_field_31001=发货人计费账号 | 21 | business_field_31001=发货人计费账号 |
| 22 | business_field_31002=运单ID | 22 | business_field_31002=运单ID |
| 23 | business_field_31003=运单号 | 23 | business_field_31003=运单号 |
| 24 | +business_field_31004=原产国编码 | ||
| 25 | +business_field_31005=原产国名称 | ||
| 26 | +business_field_31006=目的国编码 | ||
| 27 | +business_field_31007=目的国全称 | ||
| 28 | +business_field_31008=文件业务类型 | ||
| 29 | + | ||
| 24 | #*********具体响应到前端********** | 30 | #*********具体响应到前端********** |
| 25 | business_exception_30001=${0}必填字段未填写 | 31 | business_exception_30001=${0}必填字段未填写 |
| 26 | business_exception_30002=单次最多可查询1000个运单号码 | 32 | business_exception_30002=单次最多可查询1000个运单号码 | ... | ... |
| ... | @@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录 | ... | @@ -21,6 +21,12 @@ system_exception_10006=登录已过期,请重新登录 |
| 21 | business_field_31001=发货人计费账号 | 21 | business_field_31001=发货人计费账号 |
| 22 | business_field_31002=运单ID | 22 | business_field_31002=运单ID |
| 23 | business_field_31003=运单号 | 23 | business_field_31003=运单号 |
| 24 | +business_field_31004=原产国编码 | ||
| 25 | +business_field_31005=原产国名称 | ||
| 26 | +business_field_31006=目的国编码 | ||
| 27 | +business_field_31007=目的国全称 | ||
| 28 | +business_field_31008=文件业务类型 | ||
| 29 | + | ||
| 24 | #*********具体响应到前端********** | 30 | #*********具体响应到前端********** |
| 25 | business_exception_30001=${0}必填字段未填写 | 31 | business_exception_30001=${0}必填字段未填写 |
| 26 | business_exception_30002=单次最多可查询1000个运单号码 | 32 | business_exception_30002=单次最多可查询1000个运单号码 | ... | ... |
| 1 | package com.fedex.connect.common.dependencies.annotation; | 1 | package com.fedex.connect.common.dependencies.annotation; |
| 2 | 2 | ||
| 3 | +import java.lang.annotation.ElementType; | ||
| 3 | import java.lang.annotation.Retention; | 4 | import java.lang.annotation.Retention; |
| 4 | import java.lang.annotation.RetentionPolicy; | 5 | import java.lang.annotation.RetentionPolicy; |
| 6 | +import java.lang.annotation.Target; | ||
| 5 | 7 | ||
| 6 | /** | 8 | /** |
| 7 | * 字段非空注解 | 9 | * 字段非空注解 |
| 8 | */ | 10 | */ |
| 11 | +@Target(ElementType.FIELD) | ||
| 9 | @Retention(RetentionPolicy.RUNTIME) | 12 | @Retention(RetentionPolicy.RUNTIME) |
| 10 | public @interface BaseNotBlank { | 13 | public @interface BaseNotBlank { |
| 14 | + //操作描述,使用国际化文件中编码 | ||
| 15 | + String describe(); | ||
| 11 | } | 16 | } | ... | ... |
| ... | @@ -2,10 +2,13 @@ package com.fedex.connect.common.dependencies.util; | ... | @@ -2,10 +2,13 @@ package com.fedex.connect.common.dependencies.util; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.dependencies.annotation.BaseNotBlank; | 3 | import com.fedex.connect.common.dependencies.annotation.BaseNotBlank; |
| 4 | import com.fedex.connect.common.dependencies.exception.OpErrorException; | 4 | import com.fedex.connect.common.dependencies.exception.OpErrorException; |
| 5 | +import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
| 6 | import org.springframework.util.StringUtils; | 8 | import org.springframework.util.StringUtils; |
| 7 | -import java.lang.annotation.Annotation; | ||
| 8 | import java.lang.reflect.Field; | 9 | import java.lang.reflect.Field; |
| 10 | +import java.util.ArrayList; | ||
| 11 | +import java.util.List; | ||
| 9 | import java.util.Objects; | 12 | import java.util.Objects; |
| 10 | 13 | ||
| 11 | /** | 14 | /** |
| ... | @@ -15,32 +18,44 @@ import java.util.Objects; | ... | @@ -15,32 +18,44 @@ import java.util.Objects; |
| 15 | */ | 18 | */ |
| 16 | @Component | 19 | @Component |
| 17 | public class BaseValidateUtils { | 20 | public class BaseValidateUtils { |
| 21 | + @Autowired | ||
| 22 | + ResponseUtils responseUtils; | ||
| 23 | + @Autowired | ||
| 24 | + LocaleMessageUtil localeMessageUtil; | ||
| 25 | + | ||
| 18 | /** | 26 | /** |
| 19 | * 字段非空校验,仅对有BaseNotBlank注解字段进行非空校验,字段类型如果为字符串,空字符串也算空 | 27 | * 字段非空校验,仅对有BaseNotBlank注解字段进行非空校验,字段类型如果为字符串,空字符串也算空 |
| 20 | * @param obj | 28 | * @param obj |
| 21 | */ | 29 | */ |
| 22 | - public void notBlankValidate(Object obj,Integer code,String msg){ | 30 | + public void notBlankValidate(Object obj,Object codeEnum){ |
| 23 | Class cls = obj.getClass(); | 31 | Class cls = obj.getClass(); |
| 24 | Field[] fields = cls.getDeclaredFields(); | 32 | Field[] fields = cls.getDeclaredFields(); |
| 25 | try { | 33 | try { |
| 34 | + List<String> errorList = new ArrayList<>(); | ||
| 26 | for (Field field : fields) { | 35 | for (Field field : fields) { |
| 27 | - Annotation annotation = field.getAnnotation(BaseNotBlank.class); | 36 | + BaseNotBlank annotation = field.getAnnotation(BaseNotBlank.class); |
| 28 | if (Objects.nonNull(annotation)) { | 37 | if (Objects.nonNull(annotation)) { |
| 29 | Object value = AssignmentFieldUtils.getFieldValue(obj, field.getName()); | 38 | Object value = AssignmentFieldUtils.getFieldValue(obj, field.getName()); |
| 30 | if(value instanceof String){ | 39 | if(value instanceof String){ |
| 31 | String str = String.valueOf(value); | 40 | String str = String.valueOf(value); |
| 32 | if(!StringUtils.hasText(str)){ | 41 | if(!StringUtils.hasText(str)){ |
| 33 | - throw new OpErrorException(code,msg); | 42 | + String fieldName = localeMessageUtil.getMessage(annotation.describe()); |
| 43 | + errorList.add(fieldName); | ||
| 34 | } | 44 | } |
| 35 | }else{ | 45 | }else{ |
| 36 | if(Objects.isNull(value)){ | 46 | if(Objects.isNull(value)){ |
| 37 | - throw new OpErrorException(code,msg); | 47 | + String fieldName = localeMessageUtil.getMessage(annotation.describe()); |
| 48 | + errorList.add(fieldName); | ||
| 38 | } | 49 | } |
| 39 | } | 50 | } |
| 40 | } | 51 | } |
| 41 | } | 52 | } |
| 53 | + //存在非空字段为空的情况 | ||
| 54 | + if(errorList.size() > 0){ | ||
| 55 | + responseUtils.fail(codeEnum,errorList); | ||
| 56 | + } | ||
| 42 | }catch(Exception ex){ | 57 | }catch(Exception ex){ |
| 43 | - throw new OpErrorException(code,msg); | 58 | + responseUtils.fail(codeEnum); |
| 44 | } | 59 | } |
| 45 | } | 60 | } |
| 46 | } | 61 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -50,6 +50,7 @@ public class ResponseUtils { | ... | @@ -50,6 +50,7 @@ public class ResponseUtils { |
| 50 | */ | 50 | */ |
| 51 | public void fail(Object codeEnum,Object...objects) { | 51 | public void fail(Object codeEnum,Object...objects) { |
| 52 | ResponseCodeBo responseCodeBo = this.ref(codeEnum,objects); | 52 | ResponseCodeBo responseCodeBo = this.ref(codeEnum,objects); |
| 53 | + log.error(responseCodeBo.getErrMsg()); | ||
| 53 | throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg()); | 54 | throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg()); |
| 54 | } | 55 | } |
| 55 | 56 | ... | ... |
-
Please register or login to post a comment