From 1332cc511936d7dbe804921bc733c83d5e4d1400 Mon Sep 17 00:00:00 2001
From: zzw <228544128@qq.com>
Date: 星期二, 06 十月 2026 17:17:49 +0800
Subject: [PATCH] feat: add completion query and configurable system identity

---
 emergency-repair-server/src/main/java/com/emergencyrepair/system/service/SystemService.java |  134 ++++++++++++++++++++++++++++----------------
 1 files changed, 86 insertions(+), 48 deletions(-)

diff --git a/emergency-repair-server/src/main/java/com/emergencyrepair/system/service/SystemService.java b/emergency-repair-server/src/main/java/com/emergencyrepair/system/service/SystemService.java
index 5c5b3e7..e06db50 100644
--- a/emergency-repair-server/src/main/java/com/emergencyrepair/system/service/SystemService.java
+++ b/emergency-repair-server/src/main/java/com/emergencyrepair/system/service/SystemService.java
@@ -14,6 +14,7 @@
 import com.emergencyrepair.business.mapper.TeamMajorMapper;
 import com.emergencyrepair.common.BusinessException;
 import com.emergencyrepair.system.entity.SysMenu;
+import com.emergencyrepair.system.entity.SysErrorLog;
 import com.emergencyrepair.system.entity.SysLoginLog;
 import com.emergencyrepair.system.entity.SysOperationLog;
 import com.emergencyrepair.system.entity.SysRole;
@@ -21,6 +22,7 @@
 import com.emergencyrepair.system.entity.SysRoleUser;
 import com.emergencyrepair.system.entity.SysTenantMenu;
 import com.emergencyrepair.system.mapper.SysMenuMapper;
+import com.emergencyrepair.system.mapper.SysErrorLogMapper;
 import com.emergencyrepair.system.mapper.SysLoginLogMapper;
 import com.emergencyrepair.system.mapper.SysOperationLogMapper;
 import com.emergencyrepair.system.mapper.SysRoleMapper;
@@ -59,6 +61,7 @@
     private final SysRoleUserMapper roleUserMapper;
     private final SysLoginLogMapper loginLogMapper;
     private final SysOperationLogMapper operationLogMapper;
+    private final SysErrorLogMapper errorLogMapper;
     private final ButtonPermissionCatalog buttonPermissionCatalog;
     private final JdbcTemplate jdbcTemplate;
     private final EngineeringMajorMapper engineeringMajorMapper;
@@ -105,11 +108,20 @@
             menu.setMenuType(menu.getId() == null ? 1 : menu.getMenuType());
         }
         boolean isRoot = menu.getPid() == null || menu.getPid() == 0L;
-        if (menu.getMenuType() == 2) {
-            if (isRoot) {
-                throw new BusinessException("鎸夐挳绫诲瀷鍙兘寤哄湪鑿滃崟绫诲瀷涓嬬骇");
+        if (menu.getId() != null && !isRoot && menu.getId().equals(menu.getPid())) {
+            throw new BusinessException("涓婄骇鑿滃崟涓嶈兘閫夋嫨褰撳墠鑿滃崟");
+        }
+        SysMenu parent = null;
+        if (!isRoot) {
+            parent = menuMapper.selectById(menu.getPid());
+            if (parent == null) {
+                throw new BusinessException("涓婄骇鑿滃崟涓嶅瓨鍦�");
             }
-            SysMenu parent = menuMapper.selectById(menu.getPid());
+            if (menu.getId() != null && isMenuDescendant(menu.getPid(), menu.getId())) {
+                throw new BusinessException("涓婄骇鑿滃崟涓嶈兘閫夋嫨褰撳墠鑿滃崟鐨勪笅绾�");
+            }
+        }
+        if (menu.getMenuType() == 2) {
             if (parent == null || parent.getMenuType() == null || parent.getMenuType() != 1) {
                 throw new BusinessException("鎸夐挳绫诲瀷鍙兘寤哄湪鑿滃崟绫诲瀷涓嬬骇");
             }
@@ -118,11 +130,8 @@
             }
             menu.setUrl(null);
             menu.setIcon(null);
-        } else if (!isRoot) {
-            SysMenu parent = menuMapper.selectById(menu.getPid());
-            if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) {
-                throw new BusinessException("鎸夐挳绫诲瀷涓嬬骇涓嶈兘鍐嶅缓鑿滃崟");
-            }
+        } else if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) {
+            throw new BusinessException("鎸夐挳绫诲瀷涓嬬骇涓嶈兘鍐嶅缓鑿滃崟");
         }
         LocalDateTime now = LocalDateTime.now();
         menu.setUpdateTime(now);
@@ -139,6 +148,19 @@
             menuMapper.updateById(menu);
         }
         return menuMapper.selectById(menu.getId());
+    }
+
+    private boolean isMenuDescendant(Long candidateId, Long ancestorId) {
+        Long cursor = candidateId;
+        int guard = 0;
+        while (cursor != null && cursor != 0L && guard++ < 64) {
+            if (cursor.equals(ancestorId)) {
+                return true;
+            }
+            SysMenu current = menuMapper.selectById(cursor);
+            cursor = current == null ? null : current.getPid();
+        }
+        return false;
     }
 
     @Transactional
@@ -566,47 +588,32 @@
         baseEquipmentMapper.deleteById(id);
     }
 
-    public List<Map<String, Object>> tenants() {
-        return Collections.singletonList(row("id", 1L, "name", "涓存姠淇鎴�"));
-    }
-
-    public Map<String, Object> menuPermissions(Long roleId, Long tenantId) {
-        List<Long> roleMenuIds = roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery()
-                        .eq(roleId != null, SysRoleMenu::getRoleId, roleId))
-                .stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
-        List<Long> tenantMenuIds = tenantMenuMapper.selectList(Wrappers.<SysTenantMenu>lambdaQuery()
-                        .eq(tenantId != null, SysTenantMenu::getTenantId, tenantId))
-                .stream().map(SysTenantMenu::getMenuId).collect(Collectors.toList());
-        List<Long> effective = roleMenuIds.stream().filter(tenantMenuIds::contains).collect(Collectors.toList());
+    public Map<String, Object> menuPermissions(Long roleId) {
+        if (roleId == null) {
+            throw new BusinessException("璇烽�夋嫨瑙掕壊");
+        }
+        List<String> roleMenuIds = roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery()
+                        .eq(SysRoleMenu::getRoleId, roleId))
+                .stream().map(SysRoleMenu::getMenuId).map(String::valueOf).collect(Collectors.toList());
         Map<String, Object> result = new LinkedHashMap<>();
         result.put("roleMenuIds", roleMenuIds);
-        result.put("tenantMenuIds", tenantMenuIds);
-        result.put("effectiveMenuIds", effective);
+        result.put("effectiveMenuIds", roleMenuIds);
         return result;
     }
 
     @Transactional
-    public void saveMenuPermissions(Long roleId, Long tenantId, List<Long> roleMenuIds, List<Long> tenantMenuIds) {
-        if (roleId == null || tenantId == null) {
-            throw new BusinessException("璇烽�夋嫨瑙掕壊鍜岀鎴�");
+    public void saveMenuPermissions(Long roleId, List<Long> roleMenuIds) {
+        if (roleId == null) {
+            throw new BusinessException("璇烽�夋嫨瑙掕壊");
         }
         roleMenuMapper.delete(Wrappers.<SysRoleMenu>lambdaQuery().eq(SysRoleMenu::getRoleId, roleId));
-        tenantMenuMapper.delete(Wrappers.<SysTenantMenu>lambdaQuery().eq(SysTenantMenu::getTenantId, tenantId));
         List<Long> effectiveRoleMenuIds = expandWithAncestors(roleMenuIds);
-        List<Long> effectiveTenantMenuIds = expandWithAncestors(tenantMenuIds);
         for (Long menuId : effectiveRoleMenuIds) {
             SysRoleMenu relation = new SysRoleMenu();
             relation.setRoleId(roleId);
             relation.setMenuId(menuId);
             relation.setCreateTime(LocalDateTime.now());
             roleMenuMapper.insert(relation);
-        }
-        for (Long menuId : effectiveTenantMenuIds) {
-            SysTenantMenu relation = new SysTenantMenu();
-            relation.setTenantId(tenantId);
-            relation.setMenuId(menuId);
-            relation.setCreateTime(LocalDateTime.now());
-            tenantMenuMapper.insert(relation);
         }
     }
 
@@ -888,18 +895,7 @@
         Set<Long> roleMenuIds = new LinkedHashSet<>(roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery()
                         .in(SysRoleMenu::getRoleId, roleIds))
                 .stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList()));
-        Set<Long> tenantMenuIds = new LinkedHashSet<>(tenantMenuMapper.selectList(Wrappers.<SysTenantMenu>lambdaQuery()
-                        .eq(SysTenantMenu::getTenantId, 1L))
-                .stream().map(SysTenantMenu::getMenuId).collect(Collectors.toList()));
-        if (tenantMenuIds.isEmpty()) {
-            result.addAll(roleMenuIds);
-        } else {
-            for (Long menuId : roleMenuIds) {
-                if (tenantMenuIds.contains(menuId)) {
-                    result.add(menuId);
-                }
-            }
-        }
+        result.addAll(roleMenuIds);
         return result;
     }
 
@@ -913,9 +909,10 @@
             }
         }
         final Set<Long> allowedIds = allowed;
+        Set<Long> visibleIds = new LinkedHashSet<>(expandWithAncestors(new ArrayList<>(allowed)));
         List<SysMenu> navigable = listMenus().stream()
                 .filter(menu -> menu.getMenuType() == null || menu.getMenuType() != 2)
-                .filter(menu -> allowedIds.contains(menu.getId()))
+                .filter(menu -> visibleIds.contains(menu.getId()))
                 .collect(Collectors.toList());
         return buildTree(navigable);
     }
@@ -1064,6 +1061,47 @@
         return operationLogMapper.selectPage(page, wrapper);
     }
 
+    public Page<SysErrorLog> errorLogPage(int current, int size, String keyword, String module, String exceptionType, String startDate, String endDate) {
+        Page<SysErrorLog> page = new Page<>(current <= 0 ? 1 : current, size <= 0 ? 20 : size);
+        LambdaQueryWrapper<SysErrorLog> wrapper = Wrappers.lambdaQuery();
+        wrapper.select(SysErrorLog::getId, SysErrorLog::getUserId, SysErrorLog::getUserName,
+                SysErrorLog::getNickName, SysErrorLog::getModule, SysErrorLog::getRequestMethod,
+                SysErrorLog::getRequestUri, SysErrorLog::getExceptionType, SysErrorLog::getMessage,
+                SysErrorLog::getErrorTime);
+        if (StringUtils.hasText(keyword)) {
+            String value = keyword.trim();
+            wrapper.and(item -> item.like(SysErrorLog::getUserName, value)
+                    .or().like(SysErrorLog::getNickName, value)
+                    .or().like(SysErrorLog::getRequestUri, value)
+                    .or().like(SysErrorLog::getExceptionType, value)
+                    .or().like(SysErrorLog::getMessage, value));
+        }
+        if (StringUtils.hasText(module)) {
+            wrapper.eq(SysErrorLog::getModule, module.trim());
+        }
+        if (StringUtils.hasText(exceptionType)) {
+            wrapper.like(SysErrorLog::getExceptionType, exceptionType.trim());
+        }
+        LocalDateTime start = parseStart(startDate);
+        LocalDateTime end = parseEnd(endDate);
+        if (start != null) {
+            wrapper.ge(SysErrorLog::getErrorTime, start);
+        }
+        if (end != null) {
+            wrapper.le(SysErrorLog::getErrorTime, end);
+        }
+        wrapper.orderByDesc(SysErrorLog::getErrorTime);
+        return errorLogMapper.selectPage(page, wrapper);
+    }
+
+    public SysErrorLog errorLog(Long id) {
+        SysErrorLog log = errorLogMapper.selectById(id);
+        if (log == null) {
+            throw new BusinessException("閿欒鏃ュ織涓嶅瓨鍦�");
+        }
+        return log;
+    }
+
     public Long resolveUserId(String username) {
         if (!StringUtils.hasText(username)) {
             return null;

--
Gitblit v1.9.1