1. 修复bug

topo_dev
xueqingkun 9 months ago
parent bc761c2b52
commit 7ea1d52b4e

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

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

@ -1,9 +1,11 @@
package com.supervision.police.dto; package com.supervision.police.dto;
import cn.hutool.core.collection.CollUtil;
import com.supervision.police.domain.SystemMenu; import com.supervision.police.domain.SystemMenu;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -31,6 +33,10 @@ public class MenuDTO {
public MenuDTO() { public MenuDTO() {
} }
public MenuDTO(String id) {
this.id = id;
}
public MenuDTO(SystemMenu systemMenu) { public MenuDTO(SystemMenu systemMenu) {
if (Objects.isNull(systemMenu)){ if (Objects.isNull(systemMenu)){
return; return;
@ -41,4 +47,36 @@ public class MenuDTO {
this.labelType = systemMenu.getLabelType(); this.labelType = systemMenu.getLabelType();
this.parentId = systemMenu.getParentId(); 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> { public interface SystemMenuService extends IService<SystemMenu> {
List<MenuDTO> treeMenuList();
List<MenuDTO> treeMenuList(List<MenuDTO> menuDTOList);
List<MenuDTO> listMenu(); 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 com.supervision.police.mapper.SystemMenuMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.*;
import java.util.List;
/** /**
* @author Administrator * @author Administrator
@ -22,21 +21,53 @@ public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemM
implements SystemMenuService{ implements SystemMenuService{
@Override @Override
public List<MenuDTO> listMenu() { public List<MenuDTO> treeMenuList() {
List<MenuDTO> menuDTOS = listMenu();
return treeMenuList(menuDTOS);
}
List<SystemMenu> systemMenuList = super.list(); @Override
if (CollUtil.isEmpty(systemMenuList)){ public List<MenuDTO> treeMenuList(List<MenuDTO> menuDTOList) {
if (CollUtil.isEmpty(menuDTOList)){
return new ArrayList<>(); return new ArrayList<>();
} }
List<MenuDTO> menuDTOList = systemMenuList.stream().map(MenuDTO::new).toList();
for (MenuDTO menuDTO : menuDTOList) { for (MenuDTO menuDTO : menuDTOList) {
List<MenuDTO> children = menuDTOList.stream() List<MenuDTO> children = menuDTOList.stream()
.filter(item -> menuDTO.getId().equals(item.getParentId())).toList(); .filter(item -> menuDTO.getId().equals(item.getParentId())).toList();
menuDTO.setChildren(children); menuDTO.setChildren(children);
} }
return menuDTOList.stream().filter(item -> StrUtil.isEmpty(item.getParentId())).toList(); 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.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.police.domain.SystemUser; 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.dto.user.*;
import com.supervision.police.service.SystemMenuService;
import com.supervision.police.service.SystemUserRoleRelationService; import com.supervision.police.service.SystemUserRoleRelationService;
import com.supervision.police.service.SystemUserService; import com.supervision.police.service.SystemUserService;
import com.supervision.police.mapper.SystemUserMapper; import com.supervision.police.mapper.SystemUserMapper;
@ -39,6 +39,8 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
private final SystemUserRoleRelationService userRoleRelationManageService; private final SystemUserRoleRelationService userRoleRelationManageService;
private final SystemMenuService menuService;
@Override @Override
public LoginResVO login(LoginReqVO reqVO) { 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.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信息 // 设置用户token信息
loginResVO.setToken(new UserInfoDTO(systemUser)); loginResVO.setToken(new UserInfoDTO(systemUser));

Loading…
Cancel
Save