tao.mo

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

mt
2024年11月12日14:27:38
package com.fedex.connect.customer.constants;
/**
* @Author mt
* @Description 客户端常量
* @Date 2024/11/12
*/
public interface CustomerConstant {
/**
* @Author mt
* @Description 校验相关
* @Date 2024/11/12
*/
interface VALIDATE_KEYS{
//最大上传文件个数50哥
Integer UPLOAD_FILE_MAX_TOTAL = 50;
//最大上传总文件大小50M
Integer UPLOAD_FILE_MAX_SIZE = 50 * 1024 * 1024;
}
}
......@@ -46,9 +46,13 @@ public class ConsignmentController extends BaseController implements IConsignmen
*/
ConsignmentBo consignmentBo = JSONObject.parseObject(consignmentJson,ConsignmentBo.class);
/**
* 运单id非空校验
* 运单字段非空校验
*/
consignmentValidate.validateConsignmentSubmit(files,consignmentBo);
consignmentValidate.validateConsignmentSubmit(consignmentBo);
/**
* 附件校验
*/
attachmentValidate.validateFile(files,consignmentBo);
/**
* 获取当前用户信息
*/
......
......@@ -3,6 +3,8 @@ package com.fedex.connect.customer.data.bo;
import com.fedex.connect.common.dependencies.annotation.BaseNotBlank;
import lombok.Data;
import java.util.List;
@Data
public class ConsignmentBo {
//运单id
......@@ -27,5 +29,5 @@ public class ConsignmentBo {
private String destinationCountry;
//文件业务类型AWB,INV,PKL,OTH(分运单,发票,箱单和其它这四种类型)
@BaseNotBlank
private String[] fileBizType;
private List<String> fileBizType;
}
......
package com.fedex.connect.customer.enums;
/**
* @Author mt
* @Description 文件类型
* @Date 2024/11/12
*/
public enum FileBizTypeEnum {
AWB("AWB","运单"),
INV("INV","发票"),
PKL("PKL","箱单"),
OTH("OTH","其他"),
;
private String code;
private String name;
FileBizTypeEnum(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
......@@ -13,6 +13,12 @@ public enum ResponseCode {
MESSAGE_CODE_30004(30004,"business_exception_30004"),
MESSAGE_CODE_30005(30005,"business_exception_30005"),
MESSAGE_CODE_30006(30006,"business_exception_30006"),
MESSAGE_CODE_30007(30007,"business_exception_30007"),
MESSAGE_CODE_30008(30008,"business_exception_30008"),
MESSAGE_CODE_30009(30009,"business_exception_30009"),
MESSAGE_CODE_30010(30010,"business_exception_30010"),
MESSAGE_CODE_30011(30011,"business_exception_30011"),
/******打个样,编写样例*****/
// MESSAGE_CODE_30001(30001,"business_exception_30001"),
// MESSAGE_CODE_30002(30002,"business_success_30002"),
......
package com.fedex.connect.customer.util.service.biz;
import com.fedex.connect.common.model.sys.User;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
/**
* @Author mt
* @Description 附件相关util
* @Date 2024/11/12
*/
@Component
public class AttachmentUtil {
/**
* @Author mt
* @Description 文件上传
* @Date 2024/11/12
* @param files
* @param user
* @return void
*/
public void uploadFile(MultipartFile[] files, User user){
}
}
......@@ -44,11 +44,8 @@ public class ConsignmentUtil {
checkFieldMismatch(bo.getShipperAccount(), consignment.getShipperAccount(), ResponseCode.MESSAGE_CODE_30006.getMsg(), errList);
//checkFieldMismatch(bo.getRecipientCountry(), consignment.getRecipientCountry(), "con_recipientCountry", errList);
//checkFieldMismatch(bo.getShipperCountry(), consignment.getShipperCountry(), "con_shipperCountry", errList);
if (!errList.isEmpty()) {
String enumResCode = localeMessageUtil.getMessage(ResponseCode.MESSAGE_CODE_30003.getMsg());
String errResult = String.join(",", errList) + enumResCode;
responseUtils.fail(ResponseCode.MESSAGE_CODE_30003,errResult);
responseUtils.fail(ResponseCode.MESSAGE_CODE_30003,errList);
}
}
......
package com.fedex.connect.customer.validate.controller.biz;
import com.fedex.connect.common.dependencies.contants.DigitConstants;
import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil;
import com.fedex.connect.common.dependencies.util.ResponseUtils;
import com.fedex.connect.common.dependencies.util.Utils;
import com.fedex.connect.customer.constants.CustomerConstant;
import com.fedex.connect.customer.data.bo.ConsignmentBo;
import com.fedex.connect.customer.enums.FileBizTypeEnum;
import com.fedex.connect.customer.enums.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* @Author Szl
......@@ -12,6 +25,50 @@ import org.springframework.stereotype.Component;
@Component
public class AttachmentValidate {
@Autowired
protected LocaleMessageUtil localeMessageUtil;
protected ResponseUtils responseUtils;
/**
* @Author mt
* @Description 文件校验
* @Date 2024/11/12
* @param files
* @return void
*/
public void validateFile(MultipartFile[] files, ConsignmentBo consignmentBo){
//文件为空
if(Objects.isNull(files)
|| files.length == DigitConstants.DIGIT_MINUS_ONE
|| Objects.isNull(consignmentBo)
|| Objects.isNull(consignmentBo.getFileBizType())){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30007);
}
//上传最大文件个数限制
if(files.length > CustomerConstant.VALIDATE_KEYS.UPLOAD_FILE_MAX_TOTAL){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30008);
}
//上传总文件大小限制
List<Long> fileSizeList = new ArrayList<>();
for(MultipartFile file : files){
fileSizeList.add(file.getSize());
}
//总文件大小
Long totalSize = Utils.listOf(fileSizeList).stream().filter(Objects::nonNull)
.mapToLong(f -> Optional.ofNullable(f).orElse(0L)).sum();
//最大上传总文件大小超过50M
if(totalSize > CustomerConstant.VALIDATE_KEYS.UPLOAD_FILE_MAX_SIZE){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30009);
}
List<String> fileBizTypeList = consignmentBo.getFileBizType();
//运单或发票未上传
if(!fileBizTypeList.contains(FileBizTypeEnum.AWB.getName()) ||
!fileBizTypeList.contains(FileBizTypeEnum.INV.getName())){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30010);
}
//文件类型不在范围内
fileBizTypeList.stream().forEach(p -> {
if(Objects.isNull(FileBizTypeEnum.valueOf(p))){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30011);
};
});
}
}
......
......@@ -17,8 +17,6 @@ import java.util.Objects;
public class ConsignmentInfoValidate {
@Autowired
protected ResponseUtils responseUtils;
@Autowired
protected LocaleMessageUtil localeMessageUtil;
/**
* @Author mt
......
package com.fedex.connect.customer.validate.controller.biz;
import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil;
import com.fedex.connect.common.dependencies.util.BaseValidateUtils;
import com.fedex.connect.common.dependencies.util.ResponseUtils;
import com.fedex.connect.customer.data.bo.ConsignmentBo;
......@@ -8,7 +7,6 @@ import com.fedex.connect.customer.enums.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.util.Objects;
......@@ -22,8 +20,6 @@ public class ConsignmentValidate {
@Autowired
protected ResponseUtils responseUtils;
@Autowired
protected LocaleMessageUtil localeMessageUtil;
@Autowired
protected BaseValidateUtils baseValidateUtils;
/**
......@@ -45,14 +41,13 @@ public class ConsignmentValidate {
* @Author mt
* @Description 运单提交校验
* @Date 2024/11/11
* @param files
* @param consignmentBo
* @return void
*/
public void validateConsignmentSubmit(MultipartFile[] files,ConsignmentBo consignmentBo){
public void validateConsignmentSubmit(ConsignmentBo consignmentBo){
Integer code = ResponseCode.MESSAGE_CODE_30001.getCode();
String msg = ResponseCode.MESSAGE_CODE_30001.getMsg();
if(Objects.isNull(files)){
if(Objects.isNull(consignmentBo)){
responseUtils.fail(ResponseCode.MESSAGE_CODE_30001);
}
/**
......
......@@ -17,9 +17,14 @@ system_exception_10005=登录已过期
system_exception_10006=登录已过期,请重新登录
#******************业务相关、需要做国际化******************
business_exception_30001=必填字段未填写
business_exception_30001=${0}必填字段未填写
business_exception_30002=单次最多可查询1000个运单号码
business_exception_30003=不正确,请重新输入
business_exception_30003=${0}不正确,请重新输入
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.
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.
business_exception_30006=发货人计费账号
business_exception_30007=附件未上传
business_exception_30008=所有上传文件数量不超过50个文件
business_exception_30009=所有上传文件总大小不超过50M
business_exception_30010=运单或发票未上传
business_exception_30011=文件类型不在:运单、发票、箱单、其他
\ No newline at end of file
......
......@@ -23,3 +23,7 @@ business_exception_30003=不正确,请重新输入
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.
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.
business_exception_30006=发货人计费账号
business_exception_30007=附件未上传
business_exception_30008=所有上传文件数量不超过50个文件
business_exception_30009=所有上传文件总大小不超过50M
business_exception_30011=文件类型不在:运单、发票、箱单、其他
\ No newline at end of file
......
package com.fedex.connect.common.dependencies.contants;
/**
* @Description 用于分隔符的常量管理
* @Author mt
* @Date 2024-11-09
*/
public interface BaseSeparatorConstants {
/**
* @Description 逗号分隔符
* @Author mt
* @Date 2024-11-09
*/
String SEPARATOR_COMMA = ",";
String SEPARATOR_SPACE = " ";
/**
* @Description 英文句号分隔符
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_POINT = ".";
/**
* @Description 英文单引号
* @Author mt
* @Date 2024-11-11
*/
String SINGLE_QUOTES = "'";
/**
* @Description REGEX英文句号分隔符
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_REGEX_POINT = "\\.";
/**
* @Description 下划线
* @Author mt
* @Date 2024-11-31
*/
String SEPARATOR_UNDERLINE = "_";
/**
* @Description 英文横杠
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_WHIPPTREE = "-";
/**
* @Description 空字符串
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_NULL_CHARACTER_STRING = "";
/**
* @Description 英文冒号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_COLON = ":";
/**
* @Description 星号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_ASTERISK = "*";
/**
* @Description 星号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_SLASH = "/";
/**
* @Description 分号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_SEMICOLON = ";";
/**
* @Description 百分号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_PER_CENT = "%";
/**
* @Description 左中括号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_LEFT_MIDDLE_BRACKET = "[";
/**
* @Description 右中括号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_RIGHT_MIDDLE_BRACKET = "]";
/**
* @Description 右中括号加百分号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_RIGHT_MIDDLE_BRACKET_PER_CENT = "]%";
/**
* @Description 单引号加空格
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_SPACE_SINGLE_QUOTES = "' '";
/**
* @Description 单引号加逗号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_COMMA_SINGLE_QUOTES = "','";
/**
* @Description 左中括号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_LEFT_MIDDLE_BRACKET_SINGLE_QUOTES = "'['";
/**
* @Description 右中括号
* @Author mt
* @Date 2024-11-11
*/
String SEPARATOR_RIGHT_MIDDLE_BRACKET_SINGLE_QUOTES = "']'";
/**
* @Description 单引号百分号
* @Author mt
* @Date 2024-6-26
*/
String SEPARATOR_PER_CENT_SQL = "'%'";
/**
* @Description 错误码拼接赋号
* @Author mt
* @Date 2024-6-26
*/
String SEPARATOR_BR_ERROR = "<br/>";
/**
* @Description 错误码拼接赋号
* @Author mt
* @Date 2024-6-26
*/
String SEPARATOR_BR_OLD = "</br>";
/**
* @Author mt
* @Description 属性说明 br
* @Date 2024/1/17
*/
String SEPARATOR_BR_TWO = "<br>";
/**
* @Author mt
* @Description 属性说明 括号
* @Date 2024-3-12
*/
String SEPARATOR_BRACKET = "(";
/**
* @Author mt
* @Description 属性说明 括回
* @Date 2024-3-12
*/
String SEPARATOR_BRACKET_BACK = ")";
/**
* @Author mt
* @Description 属性说明 邮件的@符号
* @Date 2024-5-24
*/
String SEPARATOR_EMAIL = "@";
/**
* "&"符号
*/
String SEPARATOR_AMPERSAND = "&";
/**
* "<"符号
*/
String SEPARATOR_LT = "<";
/**
* ">"符号
*/
String SEPARATOR_GT = ">";
/**
* "\""符号
*/
String SEPARATOR_QUOT = "\"";
/**
* 换行
*/
String RN = "\r\n";
/**
* 回车
*/
String CR = "\n";
}
package com.fedex.connect.common.dependencies.util;
import com.fedex.connect.common.dependencies.contants.BaseConstants;
import com.fedex.connect.common.dependencies.contants.BaseSeparatorConstants;
import com.fedex.connect.common.dependencies.data.bo.ResponseCodeBo;
import com.fedex.connect.common.dependencies.date.vo.ResponseVo;
import com.fedex.connect.common.dependencies.exception.OpErrorException;
......@@ -9,6 +10,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
/**
* @Author mt
* @Description 返回响应错误的工具类
......@@ -33,10 +38,19 @@ public class ResponseUtils {
throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg());
}
public void fail(Object codeEnum,String errMsg) {
ResponseCodeBo responseCodeBo = this.ref(codeEnum);
log.error(errMsg);
throw new OpErrorException(responseCodeBo.getCode(), errMsg);
/**
* @Author mt
* @Description
* 第一个参数值为:#{0}必填字段未填写,#{1}。
* 第二个参数为:List<String>或字符串等
* @Date 2024/11/12
* @param codeEnum
* @param objects
* @return void
*/
public void fail(Object codeEnum,Object...objects) {
ResponseCodeBo responseCodeBo = this.ref(codeEnum,objects);
throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg());
}
public void fail(Object codeEnum,Throwable e) {
......@@ -63,7 +77,7 @@ public class ResponseUtils {
return message;
}
private ResponseCodeBo ref(Object obj){
private ResponseCodeBo ref(Object obj,Object...objects){
ResponseCodeBo responseCodeBo = new ResponseCodeBo();
try {
Object codeObj = AssignmentFieldUtils.getFieldValue(obj, BaseConstants.RESPONSE_CODE_KEYS.CODE);
......@@ -71,6 +85,17 @@ public class ResponseUtils {
Integer code = Integer.valueOf(String.valueOf(codeObj));
String msg = String.valueOf(msgObj);
String errMsg = this.msg(msg);
if(Objects.nonNull(objects) && objects.length > 0) {
for (int i = 0; i < objects.length; i++) {
Object object = objects[i];
if (object instanceof List) {
List<String> list = (List<String>) object;
String replaceVal = String.join(BaseSeparatorConstants.SEPARATOR_COMMA, list);
objects[i] = replaceVal;
}
}
errMsg = MessageFormat.format(errMsg,objects);
}
responseCodeBo.setCode(code);
responseCodeBo.setMsg(msg);
responseCodeBo.setErrMsg(errMsg);
......