log日志记录
This commit is contained in:
parent
bce338ee19
commit
110e73b993
|
@ -4,11 +4,11 @@ import java.lang.annotation.*;
|
|||
/**
|
||||
* 自定义注解记录系统操作日志
|
||||
*/
|
||||
//Target注解决定 MyLog 注解可以加在哪些成分上,如加在类身上,或者属性身上,或者方法身上等成分
|
||||
//Target注解决定 SysLog 注解可以加在哪些成分上,如加在类身上,或者属性身上,或者方法身上等成分
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
//Retention注解括号中的"RetentionPolicy.RUNTIME"意思是让 MyLog 这个注解的生命周期一直程序运行时都存在
|
||||
//Retention注解括号中的"RetentionPolicy.RUNTIME"意思是让 SysLog 这个注解的生命周期一直程序运行时都存在
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MyLog {
|
||||
public @interface SysLog {
|
||||
/**
|
||||
* 模块标题
|
||||
*/
|
|
@ -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]);
|
|
@ -8,7 +8,6 @@ import com.greenorange.promotion.common.BaseResponse;
|
|||
import com.greenorange.promotion.common.ErrorCode;
|
||||
import com.greenorange.promotion.common.ResultUtils;
|
||||
import com.greenorange.promotion.constant.UserConstant;
|
||||
import com.greenorange.promotion.exception.BusinessException;
|
||||
import com.greenorange.promotion.exception.ThrowUtils;
|
||||
import com.greenorange.promotion.model.dto.CommonBatchRequest;
|
||||
import com.greenorange.promotion.model.dto.CommonRequest;
|
||||
|
@ -26,7 +25,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
Loading…
Reference in New Issue
Block a user