提交 27f35f7c 作者: 张开石

1、添加操作日志注解及其切面类,实现保存操作日志的功能

父级 9bd973ed
package com.cmeeting.annotation;
import java.lang.annotation.*;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OperLog {
// 操作界面
String location();
// 操作记录
String operation();
}
package com.cmeeting.aspect;
import com.cmeeting.ad.entity.RobotSecurityUser;
import com.cmeeting.ad.util.SecurityUtil;
import com.cmeeting.annotation.OperLog;
import com.cmeeting.pojo.OperationLog;
import com.cmeeting.service.OperationLogService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Aspect
@Slf4j
@Component
public class OperLogAspect {
@Autowired
private OperationLogService operationLogService;
@Before(value = "@annotation(operLog)")
public void before(JoinPoint point, OperLog operLog) {
RobotSecurityUser user = SecurityUtil.getUser();
String location = operLog.location();
String operation = operLog.operation();
OperationLog operationLog = new OperationLog();
operationLog.setLocation(location);
operationLog.setOperation(operation);
operationLog.setUserId(user.getId());
operationLog.setUserName(user.getUsername());
operationLogService.save(operationLog);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论