fix: 优化逻辑
This commit is contained in:
parent
e29aea6b25
commit
e49bdd2992
@ -63,6 +63,7 @@ public class SecurityConfig {
|
||||
.requestMatchers("/data/fishDraft/previewFile").permitAll()
|
||||
.requestMatchers("/tempFile/**").permitAll()
|
||||
.requestMatchers("/system/user/auditUser").permitAll()
|
||||
.requestMatchers("/register/accessToken").permitAll()
|
||||
.requestMatchers("/api/oauth2/oauth/token").permitAll()
|
||||
.requestMatchers("/dict/cache/**").permitAll()
|
||||
.requestMatchers("/sys/psbmodulelbb/**").permitAll()
|
||||
|
||||
@ -2,6 +2,7 @@ package com.yfd.platform.system.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.jwt.JWTUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.config.WebConfig;
|
||||
import com.yfd.platform.qgc_data.domain.SysUserDataScope;
|
||||
@ -11,6 +12,8 @@ import com.yfd.platform.qgc_base.service.ISdEngInfoBHService;
|
||||
import com.yfd.platform.qgc_base.service.ISdHbrvDicService;
|
||||
import com.yfd.platform.system.domain.*;
|
||||
import com.yfd.platform.system.mapper.SysMenuMapper;
|
||||
import com.yfd.platform.system.mapper.SysOrganizationMapper;
|
||||
import com.yfd.platform.system.mapper.SysRoleMapper;
|
||||
import com.yfd.platform.system.mapper.SysUserTenantMapper;
|
||||
import com.yfd.platform.system.service.ISmsVerifyCodeService;
|
||||
import com.yfd.platform.system.service.ISysLogService;
|
||||
@ -61,6 +64,12 @@ public class SmsVerifyCodeController {
|
||||
@Resource
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Resource
|
||||
private SysOrganizationMapper organizationMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Resource
|
||||
private ISysUserDataScopeService sysUserDataScopeService;
|
||||
|
||||
@ -119,8 +128,7 @@ public class SmsVerifyCodeController {
|
||||
// if (existUser.getStatus() == 0) {
|
||||
// return ResponseResult.error("账号已被禁用");
|
||||
// }
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return ResponseResult.error("类型错误:1-注册 2-找回密码 3-登录");
|
||||
}
|
||||
|
||||
@ -179,7 +187,6 @@ public class SmsVerifyCodeController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
*/
|
||||
@ -218,13 +225,15 @@ public class SmsVerifyCodeController {
|
||||
} catch (Exception e) {
|
||||
return ResponseResult.error("密码解密失败");
|
||||
}
|
||||
SysOrganization aDefault = organizationMapper.selectOne(new LambdaQueryWrapper<SysOrganization>().eq(SysOrganization::getCustom1, "default"));
|
||||
String orgid = aDefault == null ? null : aDefault.getId();
|
||||
user.setRegStatus("PENDING");
|
||||
user.setPhone(smsVerifyCodeRequest.getPhone());
|
||||
user.setBelongingUnit(smsVerifyCodeRequest.getBelongingUnit());
|
||||
user.setRegTime(new Date());
|
||||
user.setNickname(smsVerifyCodeRequest.getRealName());
|
||||
user.setStatus(0);
|
||||
user.setOrgid("e90063ced25e3d469860e88d920c082f");
|
||||
user.setOrgid(orgid);
|
||||
user.setUsertype(1);
|
||||
user.setTenantId(tenantId);
|
||||
user.setUsername(smsVerifyCodeRequest.getUsername());
|
||||
@ -340,8 +349,10 @@ public class SmsVerifyCodeController {
|
||||
// sysUserDataScopeService.addDataScope(scope);
|
||||
// }
|
||||
SysUser user = new SysUser();
|
||||
SysRole aDefault = roleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getCustom1, "default"));
|
||||
String roleids = aDefault == null ? null : aDefault.getId();
|
||||
user.setId(userId);
|
||||
userService.updateUserRoles( user,"c13481a486c9ee559cf305284df4d207");
|
||||
userService.updateUserRoles(user, roleids);
|
||||
// 加上角色权限
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,6 +58,21 @@ public class SysRoleController {
|
||||
return roleService.selectRoleList(rolename, tenantId);
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:按门户分组查询角色(门户 → 角色两层结构)
|
||||
* 参数说明
|
||||
* rolename 角色名称(可选,模糊搜索)
|
||||
* 返回值说明: [{"tenantId":"...","tenantName":"水利门户","roles":[...]}, ...]
|
||||
* 门户中文名通过字典 PLATFORM_TENANT 获取
|
||||
***********************************/
|
||||
@PostMapping("/listGroupedByTenant")
|
||||
@Operation(summary = "按门户分组查询角色(含门户中文名)")
|
||||
@ResponseBody
|
||||
public List<Map<String, Object>> listGroupedByTenant(@RequestParam(required = false) String rolename,
|
||||
@RequestParam(required = false) String tenantId) {
|
||||
return roleService.selectRoleListGroupedByTenant(tenantId,rolename);
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:根据Id获取当个角色
|
||||
* 参数说明
|
||||
|
||||
@ -67,4 +67,13 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
List<SysRole> selectRoleList(String rolename, String tenantId);
|
||||
|
||||
List<SysRole> queryRolesList(String roleName, String tenantId);
|
||||
|
||||
/***********************************
|
||||
* 用途说明:按门户分组查询角色(门户 → 角色两层结构)
|
||||
* 参数说明
|
||||
* rolename 角色名称(可选,模糊搜索)
|
||||
* 返回值说明: [{"tenantId":"...","tenantName":"水利门户","roles":[...]}, ...]
|
||||
* 门户中文名通过字典 PLATFORM_TENANT 获取
|
||||
***********************************/
|
||||
List<Map<String, Object>> selectRoleListGroupedByTenant(String tenantId,String rolename);
|
||||
}
|
||||
|
||||
@ -6,8 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.system.domain.SysDictionary;
|
||||
import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||
import com.yfd.platform.system.domain.SysRole;
|
||||
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.ISysRoleService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -16,8 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import jakarta.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -37,6 +40,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
@Resource
|
||||
private UserServiceImpl currentuser;
|
||||
|
||||
@Resource
|
||||
private ISysDictionaryService sysDictionaryService;
|
||||
|
||||
@Resource
|
||||
private ISysDictionaryItemsService sysDictionaryItemsService;
|
||||
|
||||
/***********************************
|
||||
* 用途说明:新增角色
|
||||
* 参数说明
|
||||
@ -185,4 +194,57 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
return sysRoleList;
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明:按门户分组查询角色(门户 → 角色两层结构)
|
||||
* 参数说明
|
||||
* rolename 角色名称(可选,模糊搜索)
|
||||
* 返回值说明: [{"tenantId":"...","tenantName":"水利门户","roles":[...]}, ...]
|
||||
* 门户中文名通过字典 PLATFORM_TENANT 获取
|
||||
***********************************/
|
||||
@Override
|
||||
public List<Map<String, Object>> selectRoleListGroupedByTenant(String tenantId,String rolename) {
|
||||
// 1. 查询所有角色(排除超级管理员级别,支持角色名称模糊搜索)
|
||||
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(StrUtil.isNotBlank(tenantId), SysRole::getTenantId, tenantId);
|
||||
queryWrapper.like(StrUtil.isNotBlank(rolename), SysRole::getRolename, rolename);
|
||||
// queryWrapper.ne(SysRole::getLevel, "1");
|
||||
queryWrapper.orderByAsc(SysRole::getTenantId).orderByAsc(SysRole::getLevel);
|
||||
List<SysRole> roleList = this.list(queryWrapper);
|
||||
|
||||
// 2. 查询 PLATFORM_TENANT 字典项,构建 tenantId → tenantName 映射
|
||||
Map<String, String> tenantNameMap = new HashMap<>();
|
||||
SysDictionary tenantDict = sysDictionaryService.getByDictCode("PLATFORM_TENANT");
|
||||
if (tenantDict != null) {
|
||||
List<SysDictionaryItems> items = sysDictionaryItemsService.list(new LambdaQueryWrapper<SysDictionaryItems>().eq(SysDictionaryItems::getDictId, tenantDict.getId()).eq(StrUtil.isNotBlank(tenantId),SysDictionaryItems::getItemCode, tenantId).select(SysDictionaryItems::getItemCode, SysDictionaryItems::getDictName));
|
||||
if (items != null) {
|
||||
for (SysDictionaryItems item : items) {
|
||||
if (StrUtil.isNotBlank(item.getItemCode())) {
|
||||
tenantNameMap.put(item.getItemCode(), item.getDictName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 按 tenantId 分组(跳过无门户的角色)
|
||||
Map<String, List<SysRole>> grouped = new LinkedHashMap<>();
|
||||
for (SysRole role : roleList) {
|
||||
String code = role.getTenantId();
|
||||
if (StrUtil.isBlank(code)) {
|
||||
continue;
|
||||
}
|
||||
grouped.computeIfAbsent(code, k -> new ArrayList<>()).add(role);
|
||||
}
|
||||
|
||||
// 4. 组装两层结构:门户 → 角色
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<SysRole>> entry : grouped.entrySet()) {
|
||||
Map<String, Object> group = new HashMap<>();
|
||||
group.put("tenantId", entry.getKey());
|
||||
group.put("tenantName", tenantNameMap.getOrDefault(entry.getKey(), entry.getKey()));
|
||||
group.put("roles", entry.getValue());
|
||||
result.add(group);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -371,12 +371,21 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
||||
|
||||
// 解析新角色列表
|
||||
String[] newRoles = roleIds.split(",");
|
||||
|
||||
String operator;
|
||||
try {
|
||||
operator = SecurityUtils.getUserId();
|
||||
} catch (Exception e) {
|
||||
// 记录日志,方便排查
|
||||
log.error("获取当前用户ID失败", e);
|
||||
// 根据业务需求处理:可返回默认值、抛出业务异常或置空
|
||||
operator = null; // 或 "anonymous" 等默认值
|
||||
}
|
||||
// 需要新增的角色(新角色 - 当前角色)
|
||||
for (String roleId : newRoles) {
|
||||
if (!currentRoleSet.contains(roleId)) {
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
sysUserMapper.addUserRoles(SecurityUtils.getUserId(),id, roleId, userId);
|
||||
|
||||
sysUserMapper.addUserRoles(operator,id, roleId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@
|
||||
<if test="tenantId != null and tenantId != ''">
|
||||
and (ut.TENANT_ID = #{tenantId} OR u.tenant_id = #{tenantId})
|
||||
</if>
|
||||
ORDER BY u.lastmodifydate DESC
|
||||
ORDER BY u.username
|
||||
</select>
|
||||
<select id="getOrganizationByid" resultType="java.util.Map">
|
||||
SELECT DISTINCT
|
||||
|
||||
Loading…
Reference in New Issue
Block a user