| | |
| | | package com.ruoyi.common.log.aspect; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | 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 com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessStatus; |
| | | import com.ruoyi.common.log.filter.PropertyPreExcludeFilter; |
| | | import com.ruoyi.common.log.service.AsyncLogService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysOperLog; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.AfterReturning; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.common.core.utils.ServletUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.ip.IpUtils; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessStatus; |
| | | import com.ruoyi.common.log.filter.PropertyPreExcludeFilter; |
| | | import com.ruoyi.common.log.service.AsyncLogService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.domain.SysOperLog; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Collection; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 操作日志记录处理 |
| | | * |
| | | * @author ruoyi |
| | | * @author jqs |
| | | */ |
| | | @Aspect |
| | | @Component |
| | |
| | | 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 |
| | |
| | | operLog.setBusinessType(log.businessType().ordinal()); |
| | | // 设置标题 |
| | | operLog.setTitle(log.title()); |
| | | //设置操作内容 |
| | | operLog.setOperContent(log.operContent()); |
| | | // 设置操作人类别 |
| | | operLog.setOperatorType(log.operatorType().ordinal()); |
| | | // 是否需要保存request,参数和值 |
| | |
| | | // 是否需要保存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 |
| | | { |