当前位置:网站首页>Use facet to record operation log
Use facet to record operation log
2022-07-07 04:03:00 【Friendship years】
@Aspect @Component public class SysLogAspect { @Autowired private SysLogService sysLogService; /** * Tangent point */ @Pointcut("@annotation(com.platform.annotation.SysLog)") public void logPointCut() { } /** * Pre notice * * @param joinPoint Connection point */ @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) { // The description on the note sysLog.setOperation(syslog.value()); } // Requested method name String className = joinPoint.getTarget().getClass().getName(); String methodName = signature.getName(); sysLog.setMethod(className + "." + methodName + "()"); // Requested parameters Object[] args = joinPoint.getArgs(); String params = JSON.toJSONString(args[0]); sysLog.setParams(params); // obtain request HttpServletRequest request = HttpContextUtils.getHttpServletRequest(); // Set up IP Address sysLog.setIp(IPUtils.getIpAddr(request)); // user name 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()); // Save system logs sysLogService.save(sysLog); } }
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SysLog { String value() default " The operation log "; }
@SysLog(" Delete menu ") @RequestMapping("/delete") @RequiresPermissions("sys:menu:delete") public R delete(@RequestBody Long[] menuIds) { for (Long menuId : menuIds) { if (menuId.longValue() <= 30) { return R.error(" system menu , Can't delete "); } } sysMenuService.deleteBatch(menuIds); return R.ok(); }
边栏推荐
猜你喜欢
Codeworks 5 questions per day (1700 average) - day 7
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
Operational amplifier application summary 1
map和set的实现
Top 50 hit industry in the first half of 2022
Antd comment recursive loop comment
Arduino droplet detection
链表面试常见题
How to detect whether the MySQL code runs deadlock +binlog view
2022中青杯C题城市交通思路分析
随机推荐
SSL certificate deployment
idea gradle lombok 报错集锦
Gpt-3 is a peer review online when it has been submitted for its own research
预处理——插值
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
红米k40s root玩机笔记
10 ways of interface data security assurance
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
浅谈网络安全之文件上传
Probability formula
Summer 2022 daily question 1 (1)
Introduction to opensea platform developed by NFT trading platform (I)
Ggplot facet detail adjustment summary
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
HW notes (II)
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
[leetcode] 700 and 701 (search and insert of binary search tree)
NoSQL之Redis配置与优化
Top 50 hit industry in the first half of 2022