当前位置:网站首页>使用切面实现记录操作日志
使用切面实现记录操作日志
2022-07-06 21:08:00 【&友情岁月&】
@Aspect
@Component
public class SysLogAspect {
@Autowired
private SysLogService sysLogService;
/**
* 切点
*/
@Pointcut("@annotation(com.platform.annotation.SysLog)")
public void logPointCut() {
}
/**
* 前置通知
*
* @param joinPoint 连接点
*/
@Before("logPointCut()")
public void saveSysLog(JoinPoint joinPoint) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
SysLogEntity sysLog = new SysLogEntity();
SysLog syslog = method.getAnnotation(SysLog.class);
if (syslog != null) {
//注解上的描述
sysLog.setOperation(syslog.value());
}
//请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
sysLog.setMethod(className + "." + methodName + "()");
//请求的参数
Object[] args = joinPoint.getArgs();
String params = JSON.toJSONString(args[0]);
sysLog.setParams(params);
//获取request
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
//设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
//用户名
SysUserEntity sysUserEntity = ShiroUtils.getUserEntity();
String username = "";
if ("login".equals(methodName)) {
username = params;
}
if (null != sysUserEntity) {
username = ShiroUtils.getUserEntity().getUsername();
}
sysLog.setUsername(username);
sysLog.setCreateDate(new Date());
//保存系统日志
sysLogService.save(sysLog);
}
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SysLog {
String value() default "操作日志";
}@SysLog("删除菜单")
@RequestMapping("/delete")
@RequiresPermissions("sys:menu:delete")
public R delete(@RequestBody Long[] menuIds) {
for (Long menuId : menuIds) {
if (menuId.longValue() <= 30) {
return R.error("系统菜单,不能删除");
}
}
sysMenuService.deleteBatch(menuIds);
return R.ok();
}边栏推荐
- GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
- Adaptive non European advertising retrieval system amcad
- C# Task拓展方法
- SSL certificate deployment
- 海思3559万能平台搭建:RTSP实时播放的支持
- Function reentry, function overloading and function rewriting are understood by yourself
- Open3D 网格滤波
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- 史上最全学习率调整策略lr_scheduler
- 概率论公式
猜你喜欢

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式

什么是 BA ?BA怎么样?BA和BI是什么关系?

海思万能平台搭建:颜色空间转换YUV2RGB

Code quality management

Introduction to opensea platform developed by NFT trading platform (I)

About Tolerance Intervals

哈夫曼树基本概念

U.S. Air Force Research Laboratory, "exploring the vulnerability and robustness of deep learning systems", the latest 85 page technical report in 2022

浅谈网络安全之文件上传

海思3559万能平台搭建:RTSP实时播放的支持
随机推荐
CMB's written test - quantitative relationship
枚举通用接口&枚举使用规范
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
On file uploading of network security
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
It's too convenient. You can complete the code release and approval by nailing it!
VHDL implementation of arbitrary size matrix multiplication
PIP download only, not install
1200.Minimum Absolute Difference
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
Can the applet run in its own app and realize live broadcast and connection?
2022年上半年HIT行业TOP50
Index of MySQL
什么是 BA ?BA怎么样?BA和BI是什么关系?
VHDL implementation of single cycle CPU design
本机mysql
Huawei and Xiaomi "copy each other"
Codeworks 5 questions per day (1700 average) - day 7
Summer 2022 daily question 1 (1)
AVL树插入操作与验证操作的简单实现