| | |
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.Map;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import jakarta.servlet.http.HttpServletRequest;
|
| | | import jakarta.servlet.http.HttpServletResponse;
|
| | | import org.apache.commons.lang3.ArrayUtils;
|
| | | import org.aspectj.lang.JoinPoint;
|
| | | import org.aspectj.lang.annotation.AfterReturning;
|
| | |
| | | import org.springframework.validation.BindingResult;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.ruoyi.common.core.text.Convert;
|
| | | import com.ruoyi.common.core.utils.ExceptionUtil;
|
| | | import com.ruoyi.common.core.utils.ServletUtils;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.common.core.utils.ip.IpUtils;
|
| | |
| | | /** 计算操作消耗时间 */
|
| | | private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
| | |
|
| | | /** 参数最大长度限制 */
|
| | | private static final int PARAM_MAX_LENGTH = 2000;
|
| | |
|
| | | @Autowired
|
| | | private AsyncLogService asyncLogService;
|
| | |
|
| | |
| | | * 处理请求前执行
|
| | | */
|
| | | @Before(value = "@annotation(controllerLog)")
|
| | | public void boBefore(JoinPoint joinPoint, Log controllerLog)
|
| | | public void doBefore(JoinPoint joinPoint, Log controllerLog)
|
| | | {
|
| | | TIME_THREADLOCAL.set(System.currentTimeMillis());
|
| | | }
|
| | |
| | | if (e != null)
|
| | | {
|
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
| | | operLog.setErrorMsg(StringUtils.substring(Convert.toStr(e.getMessage(), ExceptionUtil.getExceptionMessage(e)), 0, 2000));
|
| | | }
|
| | | // 设置方法名称
|
| | | String className = joinPoint.getTarget().getClass().getName();
|
| | |
| | | {
|
| | | String requestMethod = operLog.getRequestMethod();
|
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
| | | if (StringUtils.isEmpty(paramsMap)
|
| | | && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)))
|
| | | if (StringUtils.isEmpty(paramsMap) && StringUtils.equalsAny(requestMethod, HttpMethod.PUT.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name()))
|
| | | {
|
| | | String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
| | | operLog.setOperParam(params);
|
| | | }
|
| | | else
|
| | | {
|
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
|
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, PARAM_MAX_LENGTH));
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | */
|
| | | private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames)
|
| | | {
|
| | | String params = "";
|
| | | StringBuilder params = new StringBuilder();
|
| | | if (paramsArray != null && paramsArray.length > 0)
|
| | | {
|
| | | for (Object o : paramsArray)
|
| | |
| | | try
|
| | | {
|
| | | String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter(excludeParamNames));
|
| | | params += jsonObj.toString() + " ";
|
| | | params.append(jsonObj).append(" ");
|
| | | if (params.length() >= PARAM_MAX_LENGTH)
|
| | | {
|
| | | return StringUtils.substring(params.toString(), 0, PARAM_MAX_LENGTH);
|
| | | }
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("请求参数拼装异常 msg:{}, 参数:{}", e.getMessage(), paramsArray, e);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return params.trim();
|
| | | return params.toString();
|
| | | }
|
| | |
|
| | | /**
|