Переглянути джерело

fix:变更日志记录
当接口没有提供日志内容是,由url逐级向上找权限名称作为日志内容更改为 菜单->url名称

caozixuan 2 роки тому
батько
коміт
4b7f630334

+ 26 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/aspect/LogAspect.java

@@ -141,7 +141,7 @@ public class LogAspect {
             if (SystemConstant.strNotNull(detail)) {
                 operationLog.setDetail(getDetail(((MethodSignature) joinPoint.getSignature()).getParameterNames(), joinPoint.getArgs(), annotation));
             } else {
-                operationLog.setDetail(autoCreateOperationLogDetailByUrl(request.getServletPath()));
+                operationLog.setDetail(autoCreateOperationLogDetailByUrlAndPrivilegeId(request.getServletPath(),privilegeId));
             }
             operationLog.setLevel(annotation.level());
             CustomizedOperationTypeEnum customizedOperationType = annotation.customizedOperationType();
@@ -280,6 +280,31 @@ public class LogAspect {
         return detail;
     }
 
+    /**
+     * 根据权限url和所在菜单的权限id自动创建操作日志详情
+     *
+     * @param url         url
+     * @param privilegeId 所属菜单的权限id
+     * @return 操作日志详情
+     */
+    private String autoCreateOperationLogDetailByUrlAndPrivilegeId(String url, Long privilegeId) {
+        String result = "";
+        SysPrivilege menu = sysPrivilegeService.getById(privilegeId);
+        SysPrivilege urlP = sysPrivilegeService.getOne(new QueryWrapper<SysPrivilege>()
+                .lambda()
+                .select(SysPrivilege::getName)
+                .eq(SysPrivilege::getUrl, url)
+                .eq(SysPrivilege::getType, PrivilegeEnum.URL));
+        if (Objects.nonNull(menu) && Objects.nonNull(urlP)) {
+            result = result + menu.getName() + SystemConstant.CATALOG_LINK + urlP.getName();
+        } else if (Objects.nonNull(menu)) {
+            result = result + menu.getName();
+        } else if (Objects.nonNull(urlP)) {
+            result = result + urlP.getName();
+        }
+        return result;
+    }
+
     @Before(value = "operationLog()")
     public void doBeforeAdvice(JoinPoint joinPoint) {
         log.info("进入方法前执行.....");