| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | |
| | | 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; |