common-dependencies、biz-customer | 修改 | 返回参数调整
mt 2024年11月11日15:52:42
Showing
7 changed files
with
156 additions
and
72 deletions
| ... | @@ -9,6 +9,7 @@ import com.fedex.connect.customer.service.biz.IConsignmentService; | ... | @@ -9,6 +9,7 @@ import com.fedex.connect.customer.service.biz.IConsignmentService; |
| 9 | import com.fedex.connect.customer.util.service.biz.ConsignmentUtil; | 9 | import com.fedex.connect.customer.util.service.biz.ConsignmentUtil; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 12 | +import org.springframework.web.multipart.MultipartFile; | ||
| 12 | 13 | ||
| 13 | /** | 14 | /** |
| 14 | * @Author Szl | 15 | * @Author Szl |
| ... | @@ -47,4 +48,17 @@ public class ConsignmentServiceImpl extends BaseService implements IConsignmentS | ... | @@ -47,4 +48,17 @@ public class ConsignmentServiceImpl extends BaseService implements IConsignmentS |
| 47 | //如果不存在直接返回 | 48 | //如果不存在直接返回 |
| 48 | return ResponseVo.succ(null); | 49 | return ResponseVo.succ(null); |
| 49 | } | 50 | } |
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * @Author mt | ||
| 54 | + * @Description 运单提交 | ||
| 55 | + * @Date 2024/11/11 | ||
| 56 | + * @param files | ||
| 57 | + * @param consignmentBo | ||
| 58 | + * @param user | ||
| 59 | + * @return com.fedex.connect.common.dependencies.date.vo.ResponseVo | ||
| 60 | + */ | ||
| 61 | + public ResponseVo submitConsignment(MultipartFile[] files,ConsignmentBo consignmentBo,User user){ | ||
| 62 | + return null; | ||
| 63 | + } | ||
| 50 | } | 64 | } | ... | ... |
| ... | @@ -8,6 +8,7 @@ import com.fedex.connect.common.model.biz.Consignment; | ... | @@ -8,6 +8,7 @@ import com.fedex.connect.common.model.biz.Consignment; |
| 8 | import com.fedex.connect.common.model.sys.User; | 8 | import com.fedex.connect.common.model.sys.User; |
| 9 | import com.fedex.connect.customer.data.bo.ConsignmentBo; | 9 | import com.fedex.connect.customer.data.bo.ConsignmentBo; |
| 10 | import com.fedex.connect.customer.data.dto.ConsignmentAddDto; | 10 | import com.fedex.connect.customer.data.dto.ConsignmentAddDto; |
| 11 | +import com.fedex.connect.customer.enums.ResponseCode; | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 13 | 14 | ... | ... |
| 1 | package com.fedex.connect.common.dependencies.common; | 1 | package com.fedex.connect.common.dependencies.common; |
| 2 | 2 | ||
| 3 | -import com.fedex.connect.common.dependencies.date.vo.ResponseVo; | ||
| 4 | import com.fedex.connect.common.dependencies.enums.BaseResponseCode; | 3 | import com.fedex.connect.common.dependencies.enums.BaseResponseCode; |
| 5 | import com.fedex.connect.common.dependencies.exception.OpErrorException; | 4 | import com.fedex.connect.common.dependencies.exception.OpErrorException; |
| 6 | import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; | 5 | import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; |
| ... | @@ -18,12 +17,10 @@ public class BasicController { | ... | @@ -18,12 +17,10 @@ public class BasicController { |
| 18 | try { | 17 | try { |
| 19 | user = CurrentUserInfo.getUser(); | 18 | user = CurrentUserInfo.getUser(); |
| 20 | } catch (Exception e) { | 19 | } catch (Exception e) { |
| 21 | - ResponseVo rsVo = ResponseVo.fail(BaseResponseCode.TOKEN_FORMAT_ERROR.getCode(),localeMessageUtil.getMessage(BaseResponseCode.TOKEN_FORMAT_ERROR.getMsg()),null); | 20 | + throw new OpErrorException(BaseResponseCode.TOKEN_FORMAT_ERROR.getCode(),localeMessageUtil.getMessage(BaseResponseCode.TOKEN_FORMAT_ERROR.getMsg()),e); |
| 22 | - throw new OpErrorException(rsVo.getCode(),rsVo.getMsg(),e); | ||
| 23 | } | 21 | } |
| 24 | if (user == null) { | 22 | if (user == null) { |
| 25 | - ResponseVo rsVo = ResponseVo.fail(BaseResponseCode.TOKEN_FORMAT_ERROR.getCode(),localeMessageUtil.getMessage(BaseResponseCode.OVERDUE_TOKEN_CODE.getMsg()),null); | 23 | + throw new OpErrorException(BaseResponseCode.OVERDUE_TOKEN_CODE.getCode(),localeMessageUtil.getMessage(BaseResponseCode.OVERDUE_TOKEN_CODE.getMsg())); |
| 26 | - throw new OpErrorException(rsVo.getCode(),rsVo.getMsg()); | ||
| 27 | } | 24 | } |
| 28 | return user; | 25 | return user; |
| 29 | } | 26 | } | ... | ... |
| ... | @@ -42,4 +42,12 @@ public interface BaseConstants { | ... | @@ -42,4 +42,12 @@ public interface BaseConstants { |
| 42 | //用户录入原产国全称 | 42 | //用户录入原产国全称 |
| 43 | String USER_INPUT_ORIGIN_COUNTRY = "userInputOriginCountry"; | 43 | String USER_INPUT_ORIGIN_COUNTRY = "userInputOriginCountry"; |
| 44 | } | 44 | } |
| 45 | + | ||
| 46 | + //异常枚举字段 | ||
| 47 | + interface RESPONSE_CODE_KEYS{ | ||
| 48 | + //code | ||
| 49 | + String CODE = "code"; | ||
| 50 | + //描述 | ||
| 51 | + String MSG = "msg"; | ||
| 52 | + } | ||
| 45 | } | 53 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | +package com.fedex.connect.common.dependencies.data.bo; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @Author mt | ||
| 7 | + * @Description 做反射使用,因为各模块的reponseCode不一致所以建一个通用的接受数据使用 | ||
| 8 | + * @Date 2024/11/11 | ||
| 9 | + */ | ||
| 10 | +@Data | ||
| 11 | +public class ResponseCodeBo { | ||
| 12 | + /** | ||
| 13 | + * @Author mt | ||
| 14 | + * @Description 编码 | ||
| 15 | + * @Date 2024/11/11 | ||
| 16 | + */ | ||
| 17 | + Integer code; | ||
| 18 | + /** | ||
| 19 | + * @Author mt | ||
| 20 | + * @Description 编码描述 | ||
| 21 | + * @Date 2024/11/11 | ||
| 22 | + */ | ||
| 23 | + String msg; | ||
| 24 | + /** | ||
| 25 | + * @Author mt | ||
| 26 | + * @Description 国际化描述 | ||
| 27 | + * @Date 2024/11/11 | ||
| 28 | + */ | ||
| 29 | + String errMsg; | ||
| 30 | +} |
| 1 | package com.fedex.connect.common.dependencies.date.vo; | 1 | package com.fedex.connect.common.dependencies.date.vo; |
| 2 | 2 | ||
| 3 | -import com.fedex.connect.common.dependencies.enums.BaseResponseCode; | 3 | +import com.fedex.connect.common.dependencies.contants.DigitConstants; |
| 4 | - | 4 | +import io.swagger.annotations.ApiModelProperty; |
| 5 | -import javax.servlet.http.HttpServletResponse; | 5 | +import lombok.Data; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | * @Author Szl | 8 | * @Author Szl |
| 9 | * @Description 类说明 响应结果vo | 9 | * @Description 类说明 响应结果vo |
| 10 | * @Date 2024/10/30 | 10 | * @Date 2024/10/30 |
| 11 | */ | 11 | */ |
| 12 | +@Data | ||
| 12 | public class ResponseVo<T> { | 13 | public class ResponseVo<T> { |
| 13 | - | 14 | + @ApiModelProperty("成功标识(0#否,1#是)") |
| 14 | - private int code = HttpServletResponse.SC_BAD_REQUEST;; | ||
| 15 | - private String msg; | ||
| 16 | private boolean success; | 15 | private boolean success; |
| 16 | + @ApiModelProperty("状态码") | ||
| 17 | + private Integer code; | ||
| 18 | + @ApiModelProperty("状态描述") | ||
| 19 | + private String msg; | ||
| 20 | + @ApiModelProperty("返回数据结构") | ||
| 17 | private T data; | 21 | private T data; |
| 18 | 22 | ||
| 19 | - public int getCode() { | 23 | + public ResponseVo(){ |
| 20 | - return code; | 24 | + this.success = true; |
| 21 | - } | 25 | + this.code = DigitConstants.DIGIT_TWO_HUNDRED; |
| 22 | - | 26 | + this.msg = ""; |
| 23 | - public void setCode(int code) { | 27 | + this.data = null; |
| 24 | - this.code = code; | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - public String getMsg() { | ||
| 28 | - return msg; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public void setMsg(String msg) { | ||
| 32 | - this.msg = msg; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - public boolean isSuccess() { | ||
| 36 | - return success; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public void setSuccess(boolean success) { | ||
| 40 | - this.success = success; | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - public T getData() { | ||
| 44 | - return data; | ||
| 45 | } | 28 | } |
| 46 | 29 | ||
| 47 | - public void setData(T data) { | 30 | + public ResponseVo(T data){ |
| 31 | + this.success = true; | ||
| 32 | + this.code = DigitConstants.DIGIT_TWO_HUNDRED; | ||
| 33 | + this.msg = ""; | ||
| 48 | this.data = data; | 34 | this.data = data; |
| 49 | } | 35 | } |
| 50 | 36 | ||
| 51 | - public static ResponseVo succ(Object data, String message) { | 37 | + public ResponseVo(String message){ |
| 52 | - return succ(BaseResponseCode.SUCCESS_CODE.getCode(), message, data); | 38 | + this.success = true; |
| 53 | - } | 39 | + this.code = DigitConstants.DIGIT_TWO_HUNDRED; |
| 54 | - | 40 | + this.msg = message; |
| 55 | - public static ResponseVo succ(Object data) { | 41 | + this.data = null; |
| 56 | - return succ(BaseResponseCode.SUCCESS_CODE.getCode(), "SUCCESS", data); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - public static ResponseVo succ(int code, String msg, Object data) { | ||
| 60 | - ResponseVo r = new ResponseVo(); | ||
| 61 | - r.setCode(code); | ||
| 62 | - r.setMsg(msg); | ||
| 63 | - r.setSuccess(true); | ||
| 64 | - r.setData(data); | ||
| 65 | - return r; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - public static ResponseVo fail(String msg) { | ||
| 69 | - return fail(BaseResponseCode.FAIL_CODE.getCode(), msg,null); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - public static ResponseVo fail(int code, String msg, Object data) { | ||
| 73 | - ResponseVo r = new ResponseVo(); | ||
| 74 | - r.setCode(code); | ||
| 75 | - r.setMsg(msg); | ||
| 76 | - r.setSuccess(false); | ||
| 77 | - r.setData(data); | ||
| 78 | - return r; | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - public static ResponseVo fail(BaseResponseCode resultCode) { | ||
| 82 | - return fail(resultCode.getCode(), resultCode.getMsg(), null); | ||
| 83 | } | 42 | } |
| 84 | 43 | ||
| 85 | - public static ResponseVo fail(BaseResponseCode resultCode, Object data) { | 44 | + public ResponseVo(String code,String message){ |
| 86 | - return fail(resultCode.getCode(), resultCode.getMsg(), data); | 45 | + this.success = true; |
| 46 | + this.code = DigitConstants.DIGIT_TWO_HUNDRED; | ||
| 47 | + this.msg = message; | ||
| 48 | + this.data = null; | ||
| 87 | } | 49 | } |
| 88 | } | 50 | } | ... | ... |
| 1 | +package com.fedex.connect.common.dependencies.util; | ||
| 2 | + | ||
| 3 | +import com.fedex.connect.common.dependencies.contants.BaseConstants; | ||
| 4 | +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.exception.OpErrorException; | ||
| 7 | +import com.fedex.connect.common.dependencies.i18n.LocaleMessageUtil; | ||
| 8 | +import lombok.extern.slf4j.Slf4j; | ||
| 9 | +import org.apache.poi.ss.formula.functions.T; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * @Author mt | ||
| 15 | + * @Description 返回响应错误的工具类 | ||
| 16 | + * @Date 2024/11/11 | ||
| 17 | + */ | ||
| 18 | +@Slf4j | ||
| 19 | +@Component | ||
| 20 | +public class ResponseUtils { | ||
| 21 | + @Autowired | ||
| 22 | + LocaleMessageUtil localeMessageUtil; | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * @Author mt | ||
| 26 | + * @Description 传入用于ErrorCodeEnum枚举对象,返回错误响应 | ||
| 27 | + * @Date 2024/11/11 | ||
| 28 | + * @param codeEnum | ||
| 29 | + * @return void | ||
| 30 | + */ | ||
| 31 | + public void fail(T codeEnum) { | ||
| 32 | + ResponseCodeBo responseCodeBo = this.ref(codeEnum); | ||
| 33 | + log.error(responseCodeBo.getErrMsg()); | ||
| 34 | + throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void fail(T codeEnum,Throwable e) { | ||
| 38 | + ResponseCodeBo responseCodeBo = this.ref(codeEnum); | ||
| 39 | + log.error(responseCodeBo.getErrMsg()); | ||
| 40 | + throw new OpErrorException(responseCodeBo.getCode(), responseCodeBo.getErrMsg(),e); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public ResponseVo success() { | ||
| 44 | + return new ResponseVo<>(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public ResponseVo success(T data) { | ||
| 48 | + return new ResponseVo<>(data); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public String msg(String msg){ | ||
| 52 | + String message = localeMessageUtil.getMessage(msg); | ||
| 53 | + return message; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private ResponseCodeBo ref(T obj){ | ||
| 57 | + ResponseCodeBo responseCodeBo = new ResponseCodeBo(); | ||
| 58 | + try { | ||
| 59 | + Object codeObj = AssignmentFieldUtils.getFieldValue(obj, BaseConstants.RESPONSE_CODE_KEYS.CODE); | ||
| 60 | + Object msgObj = AssignmentFieldUtils.getFieldValue(obj, BaseConstants.RESPONSE_CODE_KEYS.MSG); | ||
| 61 | + Integer code = Integer.valueOf(String.valueOf(codeObj)); | ||
| 62 | + String msg = String.valueOf(msgObj); | ||
| 63 | + String errMsg = this.msg(msg); | ||
| 64 | + responseCodeBo.setCode(code); | ||
| 65 | + responseCodeBo.setMsg(msg); | ||
| 66 | + responseCodeBo.setErrMsg(errMsg); | ||
| 67 | + }catch(Exception ex){ | ||
| 68 | + log.error("AssignmentField error : ",ex); | ||
| 69 | + } | ||
| 70 | + return responseCodeBo; | ||
| 71 | + } | ||
| 72 | +} |
-
Please register or login to post a comment