tao.mo

biz-customer | 修改 | 校验信息调整

mt
2024年11月12日14:27:38
1 +package com.fedex.connect.customer.constants;
2 +
3 +/**
4 + * @Author mt
5 + * @Description 客户端常量
6 + * @Date 2024/11/12
7 + */
8 +public interface CustomerConstant {
9 + /**
10 + * @Author mt
11 + * @Description 校验相关
12 + * @Date 2024/11/12
13 + */
14 + interface VALIDATE_KEYS{
15 + //最大上传文件个数50哥
16 + Integer UPLOAD_FILE_MAX_TOTAL = 50;
17 + //最大上传总文件大小50M
18 + Integer UPLOAD_FILE_MAX_SIZE = 50 * 1024 * 1024;
19 + }
20 +
21 +}
...@@ -46,9 +46,13 @@ public class ConsignmentController extends BaseController implements IConsignmen ...@@ -46,9 +46,13 @@ public class ConsignmentController extends BaseController implements IConsignmen
46 */ 46 */
47 ConsignmentBo consignmentBo = JSONObject.parseObject(consignmentJson,ConsignmentBo.class); 47 ConsignmentBo consignmentBo = JSONObject.parseObject(consignmentJson,ConsignmentBo.class);
48 /** 48 /**
49 - * 运单id非空校验 49 + * 运单字段非空校验
50 */ 50 */
51 - consignmentValidate.validateConsignmentSubmit(files,consignmentBo); 51 + consignmentValidate.validateConsignmentSubmit(consignmentBo);
52 + /**
53 + * 附件校验
54 + */
55 + attachmentValidate.validateFile(files,consignmentBo);
52 /** 56 /**
53 * 获取当前用户信息 57 * 获取当前用户信息
54 */ 58 */
......
...@@ -3,6 +3,8 @@ package com.fedex.connect.customer.data.bo; ...@@ -3,6 +3,8 @@ package com.fedex.connect.customer.data.bo;
3 import com.fedex.connect.common.dependencies.annotation.BaseNotBlank; 3 import com.fedex.connect.common.dependencies.annotation.BaseNotBlank;
4 import lombok.Data; 4 import lombok.Data;
5 5
6 +import java.util.List;
7 +
6 @Data 8 @Data
7 public class ConsignmentBo { 9 public class ConsignmentBo {
8 //运单id 10 //运单id
...@@ -27,5 +29,5 @@ public class ConsignmentBo { ...@@ -27,5 +29,5 @@ public class ConsignmentBo {
27 private String destinationCountry; 29 private String destinationCountry;
28 //文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型) 30 //文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型)
29 @BaseNotBlank 31 @BaseNotBlank
30 - private String[] fileBizType; 32 + private List<String> fileBizType;
31 } 33 }
......
1 +package com.fedex.connect.customer.enums;
2 +
3 +/**
4 + * @Author mt
5 + * @Description 文件类型
6 + * @Date 2024/11/12
7 + */
8 +public enum FileBizTypeEnum {
9 + AWB("AWB","运单"),
10 + INV("INV","发票"),
11 + PKL("PKL","箱单"),
12 + OTH("OTH","其他"),
13 + ;
14 + private String code;
15 + private String name;
16 +
17 + FileBizTypeEnum(String code, String name) {
18 + this.code = code;
19 + this.name = name;
20 + }
21 +
22 + public String getCode() {
23 + return code;
24 + }
25 +
26 + public String getName() {
27 + return name;
28 + }
29 +}
...@@ -13,6 +13,12 @@ public enum ResponseCode { ...@@ -13,6 +13,12 @@ public enum ResponseCode {
13 MESSAGE_CODE_30004(30004,"business_exception_30004"), 13 MESSAGE_CODE_30004(30004,"business_exception_30004"),
14 MESSAGE_CODE_30005(30005,"business_exception_30005"), 14 MESSAGE_CODE_30005(30005,"business_exception_30005"),
15 MESSAGE_CODE_30006(30006,"business_exception_30006"), 15 MESSAGE_CODE_30006(30006,"business_exception_30006"),
16 + MESSAGE_CODE_30007(30007,"business_exception_30007"),
17 + MESSAGE_CODE_30008(30008,"business_exception_30008"),
18 + MESSAGE_CODE_30009(30009,"business_exception_30009"),
19 + MESSAGE_CODE_30010(30010,"business_exception_30010"),
20 + MESSAGE_CODE_30011(30011,"business_exception_30011"),
21 +
16 /******打个样,编写样例*****/ 22 /******打个样,编写样例*****/
17 // MESSAGE_CODE_30001(30001,"business_exception_30001"), 23 // MESSAGE_CODE_30001(30001,"business_exception_30001"),
18 // MESSAGE_CODE_30002(30002,"business_success_30002"), 24 // MESSAGE_CODE_30002(30002,"business_success_30002"),
......
1 +package com.fedex.connect.customer.util.service.biz;
2 +
3 +import com.fedex.connect.common.model.sys.User;
4 +import org.springframework.stereotype.Component;
5 +import org.springframework.web.multipart.MultipartFile;
6 +
7 +/**
8 + * @Author mt
9 + * @Description 附件相关util
10 + * @Date 2024/11/12
11 + */
12 +@Component
13 +public class AttachmentUtil {
14 + /**
15 + * @Author mt
16 + * @Description 文件上传
17 + * @Date 2024/11/12
18 + * @param files
19 + * @param user
20 + * @return void
21 + */
22 + public void uploadFile(MultipartFile[] files, User user){
23 +
24 + }
25 +}
...@@ -44,11 +44,8 @@ public class ConsignmentUtil { ...@@ -44,11 +44,8 @@ public class ConsignmentUtil {
44 checkFieldMismatch(bo.getShipperAccount(), consignment.getShipperAccount(), ResponseCode.MESSAGE_CODE_30006.getMsg(), errList); 44 checkFieldMismatch(bo.getShipperAccount(), consignment.getShipperAccount(), ResponseCode.MESSAGE_CODE_30006.getMsg(), errList);
45 //checkFieldMismatch(bo.getRecipientCountry(), consignment.getRecipientCountry(), "con_recipientCountry", errList); 45 //checkFieldMismatch(bo.getRecipientCountry(), consignment.getRecipientCountry(), "con_recipientCountry", errList);
46 //checkFieldMismatch(bo.getShipperCountry(), consignment.getShipperCountry(), "con_shipperCountry", errList); 46 //checkFieldMismatch(bo.getShipperCountry(), consignment.getShipperCountry(), "con_shipperCountry", errList);
47 -
48 if (!errList.isEmpty()) { 47 if (!errList.isEmpty()) {
49 - String enumResCode = localeMessageUtil.getMessage(ResponseCode.MESSAGE_CODE_30003.getMsg()); 48 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30003,errList);
50 - String errResult = String.join(",", errList) + enumResCode;
51 - responseUtils.fail(ResponseCode.MESSAGE_CODE_30003,errResult);
52 } 49 }
53 } 50 }
54 51
......
1 package com.fedex.connect.customer.validate.controller.biz; 1 package com.fedex.connect.customer.validate.controller.biz;
2 2
3 +import com.fedex.connect.common.dependencies.contants.DigitConstants;
3 import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; 4 import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil;
5 +import com.fedex.connect.common.dependencies.util.ResponseUtils;
6 +import com.fedex.connect.common.dependencies.util.Utils;
7 +import com.fedex.connect.customer.constants.CustomerConstant;
8 +import com.fedex.connect.customer.data.bo.ConsignmentBo;
9 +import com.fedex.connect.customer.enums.FileBizTypeEnum;
10 +import com.fedex.connect.customer.enums.ResponseCode;
4 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
13 +import org.springframework.web.multipart.MultipartFile;
14 +
15 +import java.util.ArrayList;
16 +import java.util.List;
17 +import java.util.Objects;
18 +import java.util.Optional;
6 19
7 /** 20 /**
8 * @Author Szl 21 * @Author Szl
...@@ -12,6 +25,50 @@ import org.springframework.stereotype.Component; ...@@ -12,6 +25,50 @@ import org.springframework.stereotype.Component;
12 @Component 25 @Component
13 public class AttachmentValidate { 26 public class AttachmentValidate {
14 @Autowired 27 @Autowired
15 - protected LocaleMessageUtil localeMessageUtil; 28 + protected ResponseUtils responseUtils;
16 29
30 + /**
31 + * @Author mt
32 + * @Description 文件校验
33 + * @Date 2024/11/12
34 + * @param files
35 + * @return void
36 + */
37 + public void validateFile(MultipartFile[] files, ConsignmentBo consignmentBo){
38 + //文件为空
39 + if(Objects.isNull(files)
40 + || files.length == DigitConstants.DIGIT_MINUS_ONE
41 + || Objects.isNull(consignmentBo)
42 + || Objects.isNull(consignmentBo.getFileBizType())){
43 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30007);
44 + }
45 + //上传最大文件个数限制
46 + if(files.length > CustomerConstant.VALIDATE_KEYS.UPLOAD_FILE_MAX_TOTAL){
47 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30008);
48 + }
49 + //上传总文件大小限制
50 + List<Long> fileSizeList = new ArrayList<>();
51 + for(MultipartFile file : files){
52 + fileSizeList.add(file.getSize());
53 + }
54 + //总文件大小
55 + Long totalSize = Utils.listOf(fileSizeList).stream().filter(Objects::nonNull)
56 + .mapToLong(f -> Optional.ofNullable(f).orElse(0L)).sum();
57 + //最大上传总文件大小超过50M
58 + if(totalSize > CustomerConstant.VALIDATE_KEYS.UPLOAD_FILE_MAX_SIZE){
59 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30009);
60 + }
61 + List<String> fileBizTypeList = consignmentBo.getFileBizType();
62 + //运单或发票未上传
63 + if(!fileBizTypeList.contains(FileBizTypeEnum.AWB.getName()) ||
64 + !fileBizTypeList.contains(FileBizTypeEnum.INV.getName())){
65 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30010);
66 + }
67 + //文件类型不在范围内
68 + fileBizTypeList.stream().forEach(p -> {
69 + if(Objects.isNull(FileBizTypeEnum.valueOf(p))){
70 + responseUtils.fail(ResponseCode.MESSAGE_CODE_30011);
71 + };
72 + });
73 + }
17 } 74 }
......
...@@ -17,8 +17,6 @@ import java.util.Objects; ...@@ -17,8 +17,6 @@ import java.util.Objects;
17 public class ConsignmentInfoValidate { 17 public class ConsignmentInfoValidate {
18 @Autowired 18 @Autowired
19 protected ResponseUtils responseUtils; 19 protected ResponseUtils responseUtils;
20 - @Autowired
21 - protected LocaleMessageUtil localeMessageUtil;
22 20
23 /** 21 /**
24 * @Author mt 22 * @Author mt
......
1 package com.fedex.connect.customer.validate.controller.biz; 1 package com.fedex.connect.customer.validate.controller.biz;
2 2
3 -import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil;
4 import com.fedex.connect.common.dependencies.util.BaseValidateUtils; 3 import com.fedex.connect.common.dependencies.util.BaseValidateUtils;
5 import com.fedex.connect.common.dependencies.util.ResponseUtils; 4 import com.fedex.connect.common.dependencies.util.ResponseUtils;
6 import com.fedex.connect.customer.data.bo.ConsignmentBo; 5 import com.fedex.connect.customer.data.bo.ConsignmentBo;
...@@ -8,7 +7,6 @@ import com.fedex.connect.customer.enums.ResponseCode; ...@@ -8,7 +7,6 @@ import com.fedex.connect.customer.enums.ResponseCode;
8 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
10 import org.springframework.util.StringUtils; 9 import org.springframework.util.StringUtils;
11 -import org.springframework.web.multipart.MultipartFile;
12 10
13 import java.util.Objects; 11 import java.util.Objects;
14 12
...@@ -22,8 +20,6 @@ public class ConsignmentValidate { ...@@ -22,8 +20,6 @@ public class ConsignmentValidate {
22 @Autowired 20 @Autowired
23 protected ResponseUtils responseUtils; 21 protected ResponseUtils responseUtils;
24 @Autowired 22 @Autowired
25 - protected LocaleMessageUtil localeMessageUtil;
26 - @Autowired
27 protected BaseValidateUtils baseValidateUtils; 23 protected BaseValidateUtils baseValidateUtils;
28 24
29 /** 25 /**
...@@ -45,14 +41,13 @@ public class ConsignmentValidate { ...@@ -45,14 +41,13 @@ public class ConsignmentValidate {
45 * @Author mt 41 * @Author mt
46 * @Description 运单提交校验 42 * @Description 运单提交校验
47 * @Date 2024/11/11 43 * @Date 2024/11/11
48 - * @param files
49 * @param consignmentBo 44 * @param consignmentBo
50 * @return void 45 * @return void
51 */ 46 */
52 - public void validateConsignmentSubmit(MultipartFile[] files,ConsignmentBo consignmentBo){ 47 + public void validateConsignmentSubmit(ConsignmentBo consignmentBo){
53 Integer code = ResponseCode.MESSAGE_CODE_30001.getCode(); 48 Integer code = ResponseCode.MESSAGE_CODE_30001.getCode();
54 String msg = ResponseCode.MESSAGE_CODE_30001.getMsg(); 49 String msg = ResponseCode.MESSAGE_CODE_30001.getMsg();
55 - if(Objects.isNull(files)){ 50 + if(Objects.isNull(consignmentBo)){
56 responseUtils.fail(ResponseCode.MESSAGE_CODE_30001); 51 responseUtils.fail(ResponseCode.MESSAGE_CODE_30001);
57 } 52 }
58 /** 53 /**
......
...@@ -17,9 +17,14 @@ system_exception_10005=登录已过期 ...@@ -17,9 +17,14 @@ system_exception_10005=登录已过期
17 system_exception_10006=登录已过期,请重新登录 17 system_exception_10006=登录已过期,请重新登录
18 18
19 #******************业务相关、需要做国际化****************** 19 #******************业务相关、需要做国际化******************
20 -business_exception_30001=必填字段未填写 20 +business_exception_30001=${0}必填字段未填写
21 business_exception_30002=单次最多可查询1000个运单号码 21 business_exception_30002=单次最多可查询1000个运单号码
22 -business_exception_30003=不正确,请重新输入 22 +business_exception_30003=${0}不正确,请重新输入
23 business_exception_30004=The waybill you entered is generated by another user, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation. 23 business_exception_30004=The waybill you entered is generated by another user, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation.
24 business_exception_30005=The waybill you entered is generated by another account, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation. 24 business_exception_30005=The waybill you entered is generated by another account, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation.
25 business_exception_30006=发货人计费账号 25 business_exception_30006=发货人计费账号
26 +business_exception_30007=附件未上传
27 +business_exception_30008=所有上传文件数量不超过50个文件
28 +business_exception_30009=所有上传文件总大小不超过50M
29 +business_exception_30010=运单或发票未上传
30 +business_exception_30011=文件类型不在:运单、发票、箱单、其他
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -23,3 +23,7 @@ business_exception_30003=不正确,请重新输入 ...@@ -23,3 +23,7 @@ business_exception_30003=不正确,请重新输入
23 business_exception_30004=The waybill you entered is generated by another user, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation. 23 business_exception_30004=The waybill you entered is generated by another user, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation.
24 business_exception_30005=The waybill you entered is generated by another account, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation. 24 business_exception_30005=The waybill you entered is generated by another account, whether continue uploading? Confirm, Cancel. No more prompts in the future for the same situation.
25 business_exception_30006=发货人计费账号 25 business_exception_30006=发货人计费账号
26 +business_exception_30007=附件未上传
27 +business_exception_30008=所有上传文件数量不超过50个文件
28 +business_exception_30009=所有上传文件总大小不超过50M
29 +business_exception_30011=文件类型不在:运单、发票、箱单、其他
...\ No newline at end of file ...\ No newline at end of file
......
1 +package com.fedex.connect.common.dependencies.contants;
2 +/**
3 + * @Description 用于分隔符的常量管理
4 + * @Author mt
5 + * @Date 2024-11-09
6 + */
7 +public interface BaseSeparatorConstants {
8 + /**
9 + * @Description 逗号分隔符
10 + * @Author mt
11 + * @Date 2024-11-09
12 + */
13 + String SEPARATOR_COMMA = ",";
14 + String SEPARATOR_SPACE = " ";
15 +
16 + /**
17 + * @Description 英文句号分隔符
18 + * @Author mt
19 + * @Date 2024-11-11
20 + */
21 + String SEPARATOR_POINT = ".";
22 +
23 + /**
24 + * @Description 英文单引号
25 + * @Author mt
26 + * @Date 2024-11-11
27 + */
28 + String SINGLE_QUOTES = "'";
29 +
30 + /**
31 + * @Description REGEX英文句号分隔符
32 + * @Author mt
33 + * @Date 2024-11-11
34 + */
35 + String SEPARATOR_REGEX_POINT = "\\.";
36 +
37 + /**
38 + * @Description 下划线
39 + * @Author mt
40 + * @Date 2024-11-31
41 + */
42 + String SEPARATOR_UNDERLINE = "_";
43 +
44 + /**
45 + * @Description 英文横杠
46 + * @Author mt
47 + * @Date 2024-11-11
48 + */
49 + String SEPARATOR_WHIPPTREE = "-";
50 +
51 + /**
52 + * @Description 空字符串
53 + * @Author mt
54 + * @Date 2024-11-11
55 + */
56 + String SEPARATOR_NULL_CHARACTER_STRING = "";
57 +
58 + /**
59 + * @Description 英文冒号
60 + * @Author mt
61 + * @Date 2024-11-11
62 + */
63 + String SEPARATOR_COLON = ":";
64 +
65 + /**
66 + * @Description 星号
67 + * @Author mt
68 + * @Date 2024-11-11
69 + */
70 + String SEPARATOR_ASTERISK = "*";
71 +
72 + /**
73 + * @Description 星号
74 + * @Author mt
75 + * @Date 2024-11-11
76 + */
77 + String SEPARATOR_SLASH = "/";
78 + /**
79 + * @Description 分号
80 + * @Author mt
81 + * @Date 2024-11-11
82 + */
83 + String SEPARATOR_SEMICOLON = ";";
84 + /**
85 + * @Description 百分号
86 + * @Author mt
87 + * @Date 2024-11-11
88 + */
89 + String SEPARATOR_PER_CENT = "%";
90 + /**
91 + * @Description 左中括号
92 + * @Author mt
93 + * @Date 2024-11-11
94 + */
95 + String SEPARATOR_LEFT_MIDDLE_BRACKET = "[";
96 + /**
97 + * @Description 右中括号
98 + * @Author mt
99 + * @Date 2024-11-11
100 + */
101 + String SEPARATOR_RIGHT_MIDDLE_BRACKET = "]";
102 + /**
103 + * @Description 右中括号加百分号
104 + * @Author mt
105 + * @Date 2024-11-11
106 + */
107 + String SEPARATOR_RIGHT_MIDDLE_BRACKET_PER_CENT = "]%";
108 +
109 + /**
110 + * @Description 单引号加空格
111 + * @Author mt
112 + * @Date 2024-11-11
113 + */
114 + String SEPARATOR_SPACE_SINGLE_QUOTES = "' '";
115 + /**
116 + * @Description 单引号加逗号
117 + * @Author mt
118 + * @Date 2024-11-11
119 + */
120 + String SEPARATOR_COMMA_SINGLE_QUOTES = "','";
121 +
122 + /**
123 + * @Description 左中括号
124 + * @Author mt
125 + * @Date 2024-11-11
126 + */
127 + String SEPARATOR_LEFT_MIDDLE_BRACKET_SINGLE_QUOTES = "'['";
128 + /**
129 + * @Description 右中括号
130 + * @Author mt
131 + * @Date 2024-11-11
132 + */
133 + String SEPARATOR_RIGHT_MIDDLE_BRACKET_SINGLE_QUOTES = "']'";
134 +
135 + /**
136 + * @Description 单引号百分号
137 + * @Author mt
138 + * @Date 2024-6-26
139 + */
140 + String SEPARATOR_PER_CENT_SQL = "'%'";
141 +
142 + /**
143 + * @Description 错误码拼接赋号
144 + * @Author mt
145 + * @Date 2024-6-26
146 + */
147 + String SEPARATOR_BR_ERROR = "<br/>";
148 +
149 + /**
150 + * @Description 错误码拼接赋号
151 + * @Author mt
152 + * @Date 2024-6-26
153 + */
154 + String SEPARATOR_BR_OLD = "</br>";
155 + /**
156 + * @Author mt
157 + * @Description 属性说明 br
158 + * @Date 2024/1/17
159 + */
160 + String SEPARATOR_BR_TWO = "<br>";
161 +
162 + /**
163 + * @Author mt
164 + * @Description 属性说明 括号
165 + * @Date 2024-3-12
166 + */
167 + String SEPARATOR_BRACKET = "(";
168 +
169 + /**
170 + * @Author mt
171 + * @Description 属性说明 括回
172 + * @Date 2024-3-12
173 + */
174 + String SEPARATOR_BRACKET_BACK = ")";
175 +
176 + /**
177 + * @Author mt
178 + * @Description 属性说明 邮件的@符号
179 + * @Date 2024-5-24
180 + */
181 + String SEPARATOR_EMAIL = "@";
182 +
183 + /**
184 + * "&"符号
185 + */
186 + String SEPARATOR_AMPERSAND = "&";
187 +
188 + /**
189 + * "<"符号
190 + */
191 + String SEPARATOR_LT = "<";
192 +
193 + /**
194 + * ">"符号
195 + */
196 + String SEPARATOR_GT = ">";
197 +
198 + /**
199 + * "\""符号
200 + */
201 + String SEPARATOR_QUOT = "\"";
202 +
203 + /**
204 + * 换行
205 + */
206 + String RN = "\r\n";
207 +
208 + /**
209 + * 回车
210 + */
211 + String CR = "\n";
212 +}
1 package com.fedex.connect.common.dependencies.util; 1 package com.fedex.connect.common.dependencies.util;
2 2
3 import com.fedex.connect.common.dependencies.contants.BaseConstants; 3 import com.fedex.connect.common.dependencies.contants.BaseConstants;
4 +import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants;
4 import com.fedex.connect.common.dependencies.data.bo.ResponseCodeBo; 5 import com.fedex.connect.common.dependencies.data.bo.ResponseCodeBo;
5 import com.fedex.connect.common.dependencies.date.vo.ResponseVo; 6 import com.fedex.connect.common.dependencies.date.vo.ResponseVo;
6 import com.fedex.connect.common.dependencies.exception.OpErrorException; 7 import com.fedex.connect.common.dependencies.exception.OpErrorException;
...@@ -9,6 +10,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +10,10 @@ import lombok.extern.slf4j.Slf4j;
9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
11 12
13 +import java.text.MessageFormat;
14 +import java.util.List;
15 +import java.util.Objects;
16 +
12 /** 17 /**
13 * @Author mt 18 * @Author mt
14 * @Description 返回响应错误的工具类 19 * @Description 返回响应错误的工具类
...@@ -33,10 +38,19 @@ public class ResponseUtils { ...@@ -33,10 +38,19 @@ public class ResponseUtils {
33 throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg()); 38 throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg());
34 } 39 }
35 40
36 - public void fail(Object codeEnum,String errMsg) { 41 + /**
37 - ResponseCodeBo responseCodeBo = this.ref(codeEnum); 42 + * @Author mt
38 - log.error(errMsg); 43 + * @Description
39 - throw new OpErrorException(responseCodeBo.getCode(), errMsg); 44 + * 第一个参数值为:#{0}必填字段未填写,#{1}。
45 + * 第二个参数为:List<String>或字符串等
46 + * @Date 2024/11/12
47 + * @param codeEnum
48 + * @param objects
49 + * @return void
50 + */
51 + public void fail(Object codeEnum,Object...objects) {
52 + ResponseCodeBo responseCodeBo = this.ref(codeEnum,objects);
53 + throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg());
40 } 54 }
41 55
42 public void fail(Object codeEnum,Throwable e) { 56 public void fail(Object codeEnum,Throwable e) {
...@@ -63,7 +77,7 @@ public class ResponseUtils { ...@@ -63,7 +77,7 @@ public class ResponseUtils {
63 return message; 77 return message;
64 } 78 }
65 79
66 - private ResponseCodeBo ref(Object obj){ 80 + private ResponseCodeBo ref(Object obj,Object...objects){
67 ResponseCodeBo responseCodeBo = new ResponseCodeBo(); 81 ResponseCodeBo responseCodeBo = new ResponseCodeBo();
68 try { 82 try {
69 Object codeObj = AssignmentFieldUtils.getFieldValue(obj, BaseConstants.RESPONSE_CODE_KEYS.CODE); 83 Object codeObj = AssignmentFieldUtils.getFieldValue(obj, BaseConstants.RESPONSE_CODE_KEYS.CODE);
...@@ -71,6 +85,17 @@ public class ResponseUtils { ...@@ -71,6 +85,17 @@ public class ResponseUtils {
71 Integer code = Integer.valueOf(String.valueOf(codeObj)); 85 Integer code = Integer.valueOf(String.valueOf(codeObj));
72 String msg = String.valueOf(msgObj); 86 String msg = String.valueOf(msgObj);
73 String errMsg = this.msg(msg); 87 String errMsg = this.msg(msg);
88 + if(Objects.nonNull(objects) && objects.length > 0) {
89 + for (int i = 0; i < objects.length; i++) {
90 + Object object = objects[i];
91 + if (object instanceof List) {
92 + List<String> list = (List<String>) object;
93 + String replaceVal = String.join(BaseSeparatorConstants.SEPARATOR_COMMA, list);
94 + objects[i] = replaceVal;
95 + }
96 + }
97 + errMsg = MessageFormat.format(errMsg,objects);
98 + }
74 responseCodeBo.setCode(code); 99 responseCodeBo.setCode(code);
75 responseCodeBo.setMsg(msg); 100 responseCodeBo.setMsg(msg);
76 responseCodeBo.setErrMsg(errMsg); 101 responseCodeBo.setErrMsg(errMsg);
......