log日志记录

This commit is contained in:
2025-05-03 15:03:36 +08:00
parent bce338ee19
commit 110e73b993
3 changed files with 17 additions and 19 deletions

View File

@ -2,7 +2,7 @@ package com.greenorange.promotion.aop;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.greenorange.promotion.annotation.MyLog;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.model.entity.SysOperLog;
import com.greenorange.promotion.service.log.SysOperLogService;
import jakarta.annotation.Resource;
@ -29,7 +29,7 @@ import java.util.Map;
*/
@Aspect
@Component
public class OperLogAspect {
public class OperateLogAspect {
@Resource
private SysOperLogService sysOperLogService;
@ -38,8 +38,8 @@ public class OperLogAspect {
ThreadLocal<Long> startTime = new ThreadLocal<>();
@Before("@annotation(myLog)")
public void beforeMethod(JoinPoint joinPoint, MyLog myLog){
@Before("@annotation(sysLog)")
public void beforeMethod(JoinPoint joinPoint, SysLog sysLog){
startTime.set(System.currentTimeMillis());
}
@ -49,8 +49,8 @@ public class OperLogAspect {
* @param joinPoint 切入点
* @param result 返回结果
*/
@AfterReturning(value = "@annotation(myLog)", returning = "result")
public void saveOperLog(JoinPoint joinPoint, MyLog myLog, Object result) {
@AfterReturning(value = "@annotation(sysLog)", returning = "result")
public void saveOperateLog(JoinPoint joinPoint, SysLog sysLog, Object result) {
// 获取RequestAttributes
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
// 从获取RequestAttributes中获取HttpServletRequest的信息
@ -62,8 +62,8 @@ public class OperLogAspect {
Method method = signature.getMethod();
// 获取操作
SysOperLog sysOperLog = new SysOperLog();
sysOperLog.setTitle(myLog.title());//设置模块名称
sysOperLog.setContent(myLog.content());//设置日志内容
sysOperLog.setTitle(sysLog.title());//设置模块名称
sysOperLog.setContent(sysLog.content());//设置日志内容
// 将入参转换成json
String params = argsArrayToString(joinPoint.getArgs());
// 获取请求的类名
@ -118,10 +118,10 @@ public class OperLogAspect {
String methodName = method.getName();
methodName = className + "." + methodName + "()";
// 获取操作
MyLog myLog = method.getAnnotation(MyLog.class);
if (myLog != null) {
sysOperLog.setTitle(myLog.title());//设置模块名称
sysOperLog.setContent(myLog.content());//设置日志内容
SysLog sysLog = method.getAnnotation(SysLog.class);
if (sysLog != null) {
sysOperLog.setTitle(sysLog.title());//设置模块名称
sysOperLog.setContent(sysLog.content());//设置日志内容
}
// 将入参转换成json
String params = argsArrayToString(joinPoint.getArgs());
@ -181,7 +181,7 @@ public class OperLogAspect {
}
//字符串截取
public static String substring(String str, int start, int end) {
public String substring(String str, int start, int end) {
if (str == null) {
return null;
} else {
@ -216,7 +216,7 @@ public class OperLogAspect {
* 转换request 请求参数
* @param paramMap request获取的参数数组
*/
public Map<String, String> converMap(Map<String, String[]> paramMap) {
public Map<String, String> convertMap(Map<String, String[]> paramMap) {
Map<String, String> returnMap = new HashMap<>();
for (String key : paramMap.keySet()) {
returnMap.put(key, paramMap.get(key)[0]);