| | |
| | | package com.ruoyi.common.log.aspect; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.utils.ServletUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.ip.IpUtils; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| | | // 设置消耗时间 |
| | | operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get()); |
| | | log.info("日志打印"+operLog.toString()); |
| | | // 保存数据库 |
| | | asyncLogService.saveSysLog(operLog); |
| | | } |
| | | catch (Exception exp) |
| | | { |
| | | // 记录本地异常日志 |
| | | log.error("异常信息:{}", exp.getMessage()); |
| | | log.error("日志异常信息:{}", exp.getMessage()); |
| | | exp.printStackTrace(); |
| | | } |
| | | finally |
| | |
| | | // 是否需要保存response,参数和值 |
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) |
| | | { |
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); |
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 5000)); |
| | | } |
| | | } |
| | | |
| | |
| | | && (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))) |
| | | { |
| | | String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames); |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000)); |
| | | if(operLog.getOperContent().equals("编辑商户")){ |
| | | // 将JSON字符串转换为Map |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, String> jsonMap = new HashMap<>(); |
| | | try { |
| | | jsonMap = objectMapper.readValue(params, HashMap.class); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 从Map中删除指定的元素 |
| | | jsonMap.remove("shopDetail"); |
| | | // 将Map转换回JSON字符串 |
| | | try { |
| | | params = objectMapper.writeValueAsString(jsonMap); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if(operLog.getOperContent().equals("编辑商品")){ |
| | | // 将JSON字符串转换为Map |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, String> jsonMap = new HashMap<>(); |
| | | try { |
| | | jsonMap = objectMapper.readValue(params, HashMap.class); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // 从Map中删除指定的元素 |
| | | jsonMap.remove("goodsDetail"); |
| | | // 将Map转换回JSON字符串 |
| | | try { |
| | | params = objectMapper.writeValueAsString(jsonMap); |
| | | } catch (JsonProcessingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 5000)); |
| | | } |
| | | else |
| | | { |