| | |
| | | { |
| | | // *========数据库日志=========*// |
| | | SysOperLog operLog = new SysOperLog(); |
| | | operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | | // 请求的地址 |
| | | String ip = IpUtils.getIpAddr(); |
| | | operLog.setOperIp(ip); |
| | | operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); |
| | | String username = SecurityUtils.getUsername(); |
| | | if (StringUtils.isNotBlank(username)) |
| | | { |
| | | operLog.setOperName(username); |
| | | } |
| | | |
| | | if (e != null) |
| | | { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | } |
| | | // 设置方法名称 |
| | | String className = joinPoint.getTarget().getClass().getName(); |
| | | String methodName = joinPoint.getSignature().getName(); |
| | | operLog.setMethod(className + "." + methodName + "()"); |
| | | // 设置请求方式 |
| | | operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); |
| | | // 处理设置注解上的参数 |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| | | // 设置消耗时间 |
| | | operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get()); |
| | | // 保存数据库 |
| | | asyncLogService.saveSysLog(operLog); |
| | | } |
| | |
| | | */ |
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception |
| | | { |
| | | // 设置action动作 |
| | | operLog.setBusinessType(log.businessType().ordinal()); |
| | | // 设置标题 |
| | | operLog.setTitle(log.title()); |
| | | // 设置操作人类别 |
| | | operLog.setOperatorType(log.operatorType().ordinal()); |
| | | // 是否需要保存request,参数和值 |
| | | if (log.isSaveRequestData()) |
| | | { |
| | |
| | | // 是否需要保存response,参数和值 |
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) |
| | | { |
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog, String[] excludeParamNames) throws Exception |
| | | { |
| | | String requestMethod = operLog.getRequestMethod(); |
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); |
| | | if (StringUtils.isEmpty(paramsMap) |
| | | && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))) |
| | | { |
| | | String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames); |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000)); |
| | | } |
| | | else |
| | | { |
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000)); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |