1.短信功能调整

2.接口返回信息调整
This commit is contained in:
2023-08-28 10:50:28 +08:00
parent ff178a3ee5
commit e84b6d6698
7 changed files with 244 additions and 126 deletions

View File

@@ -0,0 +1,21 @@
package com.njcn.web.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 自定义注解,用来判断返回信息是否需要做处理
* @author xy
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface ReturnMsg {
/**
* 是否需要被处理
*/
boolean isChannel() default false;
}

View File

@@ -3,12 +3,14 @@ package com.njcn.web.exception;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil;
//import com.alibaba.excel.exception.ExcelAnalysisException;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.common.utils.ReflectCommonUtil;
import com.njcn.web.annotation.ReturnMsg;
import com.njcn.web.service.ILogService;
import com.njcn.web.utils.ControllerUtil;
import lombok.AllArgsConstructor;
@@ -24,8 +26,10 @@ import org.springframework.web.util.NestedServletException;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -52,6 +56,12 @@ public class GlobalBusinessExceptionHandler {
public HttpResult<String> handleBusinessException(HttpServletRequest httpServletRequest, BusinessException businessException) {
String operate = ReflectCommonUtil.getMethodDescribeByException(businessException);
logService.recodeBusinessExceptionLog(businessException, httpServletRequest, businessException.getMessage());
//判断方法上是否有自定义注解,做特殊处理
Method method = ReflectCommonUtil.getMethod(businessException);
if(method.isAnnotationPresent(ReturnMsg.class)){
log.info("存在自定义注解");
return HttpResultUtil.assembleResult(businessException.getCode(), null, StrFormatter.format("{}",businessException.getMessage()));
}
return HttpResultUtil.assembleBusinessExceptionResult(businessException, null, operate);
}
@@ -219,6 +229,12 @@ public class GlobalBusinessExceptionHandler {
}
LogUtil.logExceptionStackInfo(exceptionCause, tempException);
logService.recodeBusinessExceptionLog(tempException, httpServletRequest, exceptionCause);
//判断方法上是否有自定义注解,做特殊处理
Method method = ReflectCommonUtil.getMethod(exception);
if(method.isAnnotationPresent(ReturnMsg.class)){
log.info("存在自定义注解");
return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}",exceptionCause));
}
return HttpResultUtil.assembleResult(code, null, StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByException(tempException), StrUtil.C_COMMA, exceptionCause));
}