Bladeren bron

修改日志输出

zc 2 maanden geleden
bovenliggende
commit
6571b91711

+ 53 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/aspect/PlatformOperationLogAspect.java

@@ -22,8 +22,10 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.StorePlatformMenu;
 import shop.alien.entity.store.StorePlatformRole;
+import shop.alien.entity.store.StoreUser;
 import shop.alien.entity.storePlatform.StorePlatformOperationLog;
 import shop.alien.mapper.StorePlatformMenuMapper;
+import shop.alien.mapper.StoreUserMapper;
 import shop.alien.storeplatform.annotation.PlatformOperationLog;
 import shop.alien.storeplatform.dto.CreateRoleDto;
 import shop.alien.storeplatform.dto.UpdateRoleDto;
@@ -57,6 +59,7 @@ public class PlatformOperationLogAspect {
     private final StorePlatformRoleService storePlatformRoleService;
     private final StorePlatformRoleMenuService storePlatformRoleMenuService;
     private final StorePlatformMenuMapper storePlatformMenuMapper;
+    private final StoreUserMapper storeUserMapper;
     private final SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
     private final DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
     private final TemplateParserContext templateParserContext = new TemplateParserContext("#{", "}");
@@ -188,6 +191,12 @@ public class PlatformOperationLogAspect {
     }
 
     private String resolveContent(PlatformOperationLog annotation, EvaluationContext context, Object[] args) {
+        if ("账号操作记录".equals(annotation.module()) && annotation.type().contains("移除角色")) {
+            String content = buildAccountRoleRemoveContent(args);
+            if (StringUtils.hasText(content)) {
+                return content;
+            }
+        }
         if ("角色操作记录".equals(annotation.module())) {
             return buildRoleOperationContent(annotation.type(), args);
         }
@@ -200,6 +209,50 @@ public class PlatformOperationLogAspect {
         return annotation.type();
     }
 
+    private String buildAccountRoleRemoveContent(Object[] args) {
+        if (args == null || args.length < 2) {
+            return null;
+        }
+        Integer userId = null;
+        Long roleId = null;
+        if (args[0] instanceof Integer) {
+            userId = (Integer) args[0];
+        }
+        if (args[1] instanceof Long) {
+            roleId = (Long) args[1];
+        }
+        if (userId == null || roleId == null) {
+            return null;
+        }
+
+        String accountName = resolveAccountName(userId);
+        String roleName = resolveRoleName(roleId);
+        return String.format("移除用户%s的角色%s", accountName, roleName);
+    }
+
+    private String resolveAccountName(Integer userId) {
+        StoreUser storeUser = storeUserMapper.selectById(userId);
+        if (storeUser == null) {
+            return "未知";
+        }
+        String name = storeUser.getName();
+        if (!StringUtils.hasText(name)) {
+            name = storeUser.getNickName();
+        }
+        if (!StringUtils.hasText(name)) {
+            name = storeUser.getPhone();
+        }
+        return StringUtils.hasText(name) ? name : "未知";
+    }
+
+    private String resolveRoleName(Long roleId) {
+        StorePlatformRole role = storePlatformRoleService.getRoleById(roleId);
+        if (role == null || !StringUtils.hasText(role.getRoleName())) {
+            return "未知";
+        }
+        return role.getRoleName();
+    }
+
     private String buildParamsJson(String[] parameterNames, Object[] args) {
         try {
             if (args == null || args.length == 0) {