1. 修复bug

topo_dev
xueqingkun 9 months ago
parent bc761c2b52
commit 7ea1d52b4e

@ -1,9 +1,10 @@
package com.supervision.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
*
@ -13,23 +14,23 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @since JDK1.8
*/
@Configuration
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
public class CorsConfig {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOriginPatterns("*")
// 是否允许整数 不再默认开启
.allowCredentials(true)
// 设置允许的方法
.allowedMethods("*")
// 允许跨域的请求头
.allowedHeaders("*")
// 跨域允许时间
.maxAge(3600);
@Bean
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
// 允许所有域名进行跨域调用
config.addAllowedOriginPattern("*");
// 允许跨域发送cookie
config.setAllowCredentials(true);
// 放行全部原始头信息
config.addAllowedHeader("*");
// 允许所有请求方法跨域调用
config.addAllowedMethod("*");
config.setMaxAge(3600L);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

@ -23,8 +23,8 @@ public class MenuController {
private final SystemMenuService menuService;
@Operation(summary = "查看用户信息列表")
@GetMapping("/listMenu")
public R<List<MenuDTO>> listMenu() {
List<MenuDTO> menuDTOS = menuService.listMenu();
public R<List<MenuDTO>> treeMenuList() {
List<MenuDTO> menuDTOS = menuService.treeMenuList();
return R.ok(menuDTOS);
}
}

@ -1,9 +1,11 @@
package com.supervision.police.dto;
import cn.hutool.core.collection.CollUtil;
import com.supervision.police.domain.SystemMenu;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -31,6 +33,10 @@ public class MenuDTO {
public MenuDTO() {
}
public MenuDTO(String id) {
this.id = id;
}
public MenuDTO(SystemMenu systemMenu) {
if (Objects.isNull(systemMenu)){
return;
@ -41,4 +47,36 @@ public class MenuDTO {
this.labelType = systemMenu.getLabelType();
this.parentId = systemMenu.getParentId();
}
public List<MenuDTO> floatMenu(){
List<MenuDTO> menuDTOS = new ArrayList<>();
menuDTOS.add(this);
if (CollUtil.isNotEmpty(this.children)){
for (MenuDTO child : this.children) {
menuDTOS.addAll(child.floatMenu());
}
}
return menuDTOS;
}
public List<MenuDTO> seekMenu(String menuId) {
List<MenuDTO> menuDTOS = new ArrayList<>();
if (this.getId().equals(menuId)) {
menuDTOS.add(this);
return menuDTOS;
}
if (CollUtil.isNotEmpty(this.children)) {
for (MenuDTO child : this.children) {
List<MenuDTO> seekList = child.seekMenu(menuId);
if (!seekList.isEmpty()) {
menuDTOS.add(this);
menuDTOS.addAll(seekList);
return menuDTOS;
}
}
}
return menuDTOS;
}
}

@ -13,6 +13,20 @@ import java.util.List;
*/
public interface SystemMenuService extends IService<SystemMenu> {
List<MenuDTO> treeMenuList();
List<MenuDTO> treeMenuList(List<MenuDTO> menuDTOList);
List<MenuDTO> listMenu();
/**
* id
* @param menuDTOList
* @param selectMenuIdList id
* @return
*/
List<MenuDTO> filterMenuBySelect(List<MenuDTO> menuDTOList, List<String> selectMenuIdList);
}

@ -9,8 +9,7 @@ import com.supervision.police.service.SystemMenuService;
import com.supervision.police.mapper.SystemMenuMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* @author Administrator
@ -22,21 +21,53 @@ public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemM
implements SystemMenuService{
@Override
public List<MenuDTO> listMenu() {
public List<MenuDTO> treeMenuList() {
List<MenuDTO> menuDTOS = listMenu();
return treeMenuList(menuDTOS);
}
List<SystemMenu> systemMenuList = super.list();
if (CollUtil.isEmpty(systemMenuList)){
@Override
public List<MenuDTO> treeMenuList(List<MenuDTO> menuDTOList) {
if (CollUtil.isEmpty(menuDTOList)){
return new ArrayList<>();
}
List<MenuDTO> menuDTOList = systemMenuList.stream().map(MenuDTO::new).toList();
for (MenuDTO menuDTO : menuDTOList) {
List<MenuDTO> children = menuDTOList.stream()
.filter(item -> menuDTO.getId().equals(item.getParentId())).toList();
menuDTO.setChildren(children);
}
return menuDTOList.stream().filter(item -> StrUtil.isEmpty(item.getParentId())).toList();
}
@Override
public List<MenuDTO> listMenu() {
return super.list().stream().map(MenuDTO::new).toList();
}
@Override
public List<MenuDTO> filterMenuBySelect(List<MenuDTO> menuDTOList, List<String> selectMenuIdList) {
if (CollUtil.isEmpty(menuDTOList) || CollUtil.isEmpty(selectMenuIdList)){
return new ArrayList<>(1);
}
List<MenuDTO> seekMenuDTOList = new ArrayList<>();
for (String menuId : selectMenuIdList) {
for (MenuDTO menuDTO : menuDTOList) {
List<MenuDTO> menuDTOS = menuDTO.seekMenu(menuId);
if (CollUtil.isNotEmpty(menuDTOS)){
seekMenuDTOList.addAll(menuDTOS);
}
}
}
return seekMenuDTOList;
}
}

@ -2,15 +2,15 @@ package com.supervision.police.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.police.domain.SystemUser;
import com.supervision.police.domain.SystemUserRoleRelation;
import com.supervision.police.dto.MenuDTO;
import com.supervision.police.dto.user.*;
import com.supervision.police.service.SystemMenuService;
import com.supervision.police.service.SystemUserRoleRelationService;
import com.supervision.police.service.SystemUserService;
import com.supervision.police.mapper.SystemUserMapper;
@ -39,6 +39,8 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
private final SystemUserRoleRelationService userRoleRelationManageService;
private final SystemMenuService menuService;
@Override
public LoginResVO login(LoginReqVO reqVO) {
@ -55,7 +57,12 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
loginResVO.setRoleList(userRoleRelationManageService.listUserRoleByUserIdList(CollUtil.newArrayList(systemUser.getId())));
// 设置用户权限信息
loginResVO.roleMenuDTOSetPermission(userRoleRelationManageService.listUserRoleMenu(systemUser.getId()));
List<RoleMenuDTO> roleMenuDTOS = userRoleRelationManageService.listUserRoleMenu(systemUser.getId());
if (CollUtil.isNotEmpty(roleMenuDTOS)){
List<MenuDTO> menuDTOS = menuService.treeMenuList();
List<MenuDTO> menuBySelect = menuService.filterMenuBySelect(menuDTOS,roleMenuDTOS.stream().map(RoleMenuDTO::getMenuId).toList());
loginResVO.setPermission(menuBySelect.stream().map(MenuDTO::getLabelCode).toList());
}
// 设置用户token信息
loginResVO.setToken(new UserInfoDTO(systemUser));

Loading…
Cancel
Save