fix: 优化登录门户逻辑
This commit is contained in:
parent
ae57efdae2
commit
57cc61f1c0
@ -22,29 +22,29 @@ public class ResponseResult extends HashMap<String, Object> {
|
||||
|
||||
public static ResponseResult error(String msg) {
|
||||
ResponseResult json = new ResponseResult();
|
||||
json.put((String)"code", "1");//错误
|
||||
json.put((String)"msg", msg);
|
||||
json.put("code", "1");//错误
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static ResponseResult message(String code, String msg) {
|
||||
ResponseResult json = new ResponseResult();
|
||||
json.put((String)"code", code);
|
||||
json.put((String)"msg", msg);
|
||||
json.put("code", code);
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static ResponseResult success(String msg) {
|
||||
ResponseResult json = new ResponseResult();
|
||||
json.put((String)"code", "0");//正常
|
||||
json.put((String)"msg", msg);
|
||||
json.put("code", "0");//正常
|
||||
json.put("msg", msg);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static ResponseResult successData(Object obj) {
|
||||
ResponseResult json = new ResponseResult();
|
||||
json.put((String)"code", "0");//正常
|
||||
json.put((String)"msg", "操作成功");
|
||||
json.put("code", "0");//正常
|
||||
json.put("msg", "操作成功");
|
||||
json.put("data", obj);
|
||||
return json;
|
||||
}
|
||||
|
||||
@ -67,6 +67,7 @@ public class SecurityConfig {
|
||||
.requestMatchers("/dict/cache/**").permitAll()
|
||||
.requestMatchers("/sys/psbmodulelbb/**").permitAll()
|
||||
.requestMatchers("/base/operationLog/**").permitAll()
|
||||
.requestMatchers("/system/**").permitAll()
|
||||
// .requestMatchers("/eng/**").permitAll()
|
||||
// .requestMatchers("/eq/**").permitAll()
|
||||
// .requestMatchers("/env/**").permitAll()
|
||||
|
||||
@ -12,6 +12,7 @@ import com.yfd.platform.qgc_base.domain.SdEngInfoBHOperateRequest;
|
||||
import com.yfd.platform.qgc_base.domain.SdFishDictoryB;
|
||||
import com.yfd.platform.qgc_base.service.ISdFishDictoryBService;
|
||||
import com.yfd.platform.qgc_data.service.AttachmentUploadService;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -55,7 +56,7 @@ public class SdFishDictoryBController {
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "查询鱼类字典列表(支持动态过滤和排序,不分页)")
|
||||
public ResponseResult list(@RequestBody DataSourceRequest request) {
|
||||
List<SdFishDictoryB> list = sdFishDictoryBService.list();
|
||||
List<SdFishDictoryB> list = DataSourceRequestUtil.executeList(request, SdFishDictoryB.class, sdFishDictoryBService);
|
||||
return ResponseResult.successData(list);
|
||||
}
|
||||
|
||||
|
||||
@ -241,7 +241,7 @@ public class LoginController {
|
||||
@Operation(summary = "查询当前用户信息")
|
||||
@ResponseBody
|
||||
public ResponseResult getUserInfo() {
|
||||
ResponseResult responseResult = userService.getLoginUserInfo();
|
||||
Map<String, Object> responseResult = userService.getLoginUserInfo();
|
||||
return ResponseResult.successData(responseResult);
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +101,21 @@ public class SysMenuController {
|
||||
return sysMenuService.permissionAssignment(code, roleId, StrUtil.trimToNull(tenantId));
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:权限分配(按系统分组,附带系统标识和名称)
|
||||
* 参数说明
|
||||
* roleId 角色ID
|
||||
* 返回值说明: [{"systemCode":"1","systemName":"Web端","menus":[...]}, ...]
|
||||
* 系统名称通过字典 PLATFORM_TENANT 获取
|
||||
***********************************/
|
||||
@PostMapping("/permissionAssignmentGrouped")
|
||||
@Operation(summary = "获取分配权限-按系统分组(含系统标识和名称)")
|
||||
@ResponseBody
|
||||
public List<Map<String, Object>> permissionAssignmentGrouped(String roleId,
|
||||
String tenantId) {
|
||||
return sysMenuService.permissionAssignmentGrouped(roleId, StrUtil.trimToNull(tenantId));
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 获取当前用户菜单结构树
|
||||
* 参数说明
|
||||
|
||||
@ -54,8 +54,8 @@ public class SysRoleController {
|
||||
@Operation(summary = "查询所有角色")
|
||||
@ResponseBody
|
||||
public List<SysRole> list(@RequestParam(required = false) String rolename,
|
||||
@RequestHeader(value = "Tenant_id", required = false) String tenantId) {
|
||||
return roleService.selectRoleList(rolename, null);
|
||||
@RequestParam(required = false) String tenantId) {
|
||||
return roleService.selectRoleList(rolename, tenantId);
|
||||
}
|
||||
|
||||
/***********************************
|
||||
@ -71,7 +71,7 @@ public class SysRoleController {
|
||||
@RequestHeader(value = "Tenant_id", required = false) String tenantId) {
|
||||
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysRole::getId, id);
|
||||
queryWrapper.eq(StrUtil.isNotBlank(tenantId), SysRole::getTenantId, StrUtil.trim(tenantId));
|
||||
// queryWrapper.eq(StrUtil.isNotBlank(tenantId), SysRole::getTenantId, StrUtil.trim(tenantId));
|
||||
SysRole sysRole = roleService.getOne(queryWrapper);
|
||||
return ResponseResult.successData(sysRole);
|
||||
}
|
||||
|
||||
@ -97,5 +97,14 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
***********************************/
|
||||
List<Map<String, Object>> permissionAssignment(String code, String roleId, String tenantId);
|
||||
|
||||
/***********************************
|
||||
* 用途说明:权限分配(按系统分组,附带系统标识和名称)
|
||||
* 参数说明
|
||||
* roleId 角色ID
|
||||
* tenantId 门户ID
|
||||
* 返回值说明: [{"systemCode":"1","systemName":"Web端","menus":[...]}, ...]
|
||||
***********************************/
|
||||
List<Map<String, Object>> permissionAssignmentGrouped(String roleId, String tenantId);
|
||||
|
||||
String uploadIcon(MultipartFile icon) throws FileNotFoundException;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public interface IUserService extends IService<SysUser> {
|
||||
************************************/
|
||||
Map<String, String> getNameInfo();
|
||||
//获取当前用户信息带权限
|
||||
ResponseResult getLoginUserInfo();
|
||||
Map<String, Object> getLoginUserInfo();
|
||||
|
||||
/***********************************
|
||||
* 用途说明:新增用户
|
||||
|
||||
@ -7,10 +7,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.system.domain.SysDictionary;
|
||||
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||
import com.yfd.platform.system.domain.SysMenu;
|
||||
import com.yfd.platform.system.domain.SysRole;
|
||||
import com.yfd.platform.system.mapper.SysMenuMapper;
|
||||
import com.yfd.platform.system.mapper.SysRoleMapper;
|
||||
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||
import com.yfd.platform.system.service.ISysDictionaryService;
|
||||
import com.yfd.platform.system.service.ISysMenuService;
|
||||
import com.yfd.platform.utils.FileUtil;
|
||||
import com.yfd.platform.config.FileSpaceProperties;
|
||||
@ -47,6 +51,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
@Resource
|
||||
private UserServiceImpl currentUser;
|
||||
|
||||
@Resource
|
||||
private ISysDictionaryService sysDictionaryService;
|
||||
|
||||
@Resource
|
||||
private ISysDictionaryItemsService sysDictionaryItemsService;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@ -502,6 +512,77 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
return listTree;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:权限分配(按系统分组,附带系统标识和名称)
|
||||
* 参数说明
|
||||
* roleId 角色ID
|
||||
* tenantId 门户ID
|
||||
* 返回值说明: [{"systemCode":"1","systemName":"Web端","menus":[...]}, ...]
|
||||
***********************************/
|
||||
@Override
|
||||
public List<Map<String, Object>> permissionAssignmentGrouped(String roleId, String tenantId) {
|
||||
// 1. 查询 PLATFORM_TENANT 字典项,构建 systemCode → systemName 映射
|
||||
Map<String, String> systemNameMap = new HashMap<>();
|
||||
SysDictionary tenantDict = sysDictionaryService.getByDictCode("PLATFORM_TENANT");
|
||||
if (tenantDict != null) {
|
||||
List<SysDictionaryItems> items = sysDictionaryItemsService.listByDictId(tenantDict.getId());
|
||||
if (items != null) {
|
||||
for (SysDictionaryItems item : items) {
|
||||
if (StrUtil.isNotBlank(item.getItemCode())) {
|
||||
systemNameMap.put(item.getItemCode(), item.getDictName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 查询所有菜单(不按 systemcode 过滤,按租户过滤)
|
||||
LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(SysMenu::getId, SysMenu::getParentid, SysMenu::getName,
|
||||
SysMenu::getSystemcode, SysMenu::getOrderno)
|
||||
.eq(StrUtil.isNotBlank(tenantId), SysMenu::getTenantId, tenantId)
|
||||
.orderByAsc(SysMenu::getSystemcode, SysMenu::getOrderno);
|
||||
List<Map<String, Object>> mapList = sysMenuMapper.selectMaps(queryWrapper);
|
||||
List<Map<String, Object>> listAll = ObjectConverterUtil.convertMapFieldsToEntityFormat(SysMenu.class, mapList);
|
||||
|
||||
// 3. 获取角色已有的菜单ID列表
|
||||
List<String> listRole = sysMenuMapper.selectMenuByRoleId(roleId, tenantId);
|
||||
|
||||
// 4. 标记 checkinfo
|
||||
for (Map<String, Object> map : listAll) {
|
||||
String id = (String) map.get("id");
|
||||
map.put("checkinfo", listRole != null && listRole.contains(id));
|
||||
}
|
||||
|
||||
// 5. 按 systemcode 分组
|
||||
Map<String, List<Map<String, Object>>> groupedBySystem = new LinkedHashMap<>();
|
||||
for (Map<String, Object> menu : listAll) {
|
||||
String sysCode = (String) menu.get("systemcode");
|
||||
if (StrUtil.isBlank(sysCode)) {
|
||||
sysCode = "1"; // 默认归属到 web 系统
|
||||
}
|
||||
groupedBySystem.computeIfAbsent(sysCode, k -> new ArrayList<>()).add(menu);
|
||||
}
|
||||
|
||||
// 6. 按系统分组构建树,并附加 systemCode 和 systemName
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : groupedBySystem.entrySet()) {
|
||||
String sysCode = entry.getKey();
|
||||
List<Map<String, Object>> sysMenuList = entry.getValue();
|
||||
|
||||
// 构建菜单树
|
||||
List<Map<String, Object>> menuTree = buildTrees(sysMenuList);
|
||||
|
||||
// 组装结果
|
||||
Map<String, Object> systemGroup = new HashMap<>();
|
||||
systemGroup.put("systemCode", sysCode);
|
||||
systemGroup.put("systemName", systemNameMap.getOrDefault(sysCode, sysCode));
|
||||
systemGroup.put("menus", menuTree);
|
||||
result.add(systemGroup);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 另一种方法
|
||||
/*public List<Map<String, Object>> permissionAssignment(String roleId) {
|
||||
|
||||
|
||||
@ -126,7 +126,7 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult getLoginUserInfo() {
|
||||
public Map<String, Object> getLoginUserInfo() {
|
||||
UsernamePasswordAuthenticationToken authentication =
|
||||
(UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||
LoginUser loginuser = (LoginUser) authentication.getPrincipal();
|
||||
@ -142,7 +142,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
||||
if(user.getUsertype()==0){
|
||||
collect.add("超级管理员");
|
||||
}
|
||||
ResponseResult responseResult = new ResponseResult();
|
||||
// 新写法(推荐)
|
||||
Map<String, Object> responseResult = new HashMap<>();
|
||||
responseResult.put("userInfo", userInfo);
|
||||
responseResult.put("roles", collect);
|
||||
responseResult.put("permissions", loginuser.getPermissions());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user