feat: 统一角色枚举 (meetingExecutor/supervisor) + 子账号数据隔离 + Login 读取后端 role_type
后端:
- SysUser 加 roleType 字段 (entity + mapper selectUserVo + service 接口/实现)
- SysUserMapper 新增 selectUserIdsByParent (按 parent_user_id 取子账号列表)
- BizPersonController.list 自动注入 MAIN 业务用户可见性: 仅查 user_id IN (子账号列表)
- BizPersonMapper 加 params.subUserIds foreach 过滤
- BizPerson/BizPersonServiceImpl 配合 getParams().put
前端:
- Login.vue 改用后端 sys_user.roleType 替代 username 前缀 autoRole, 修复 exe01 错入 leader 菜单
- utils/roleMap.js 新增: meetingExecutor->会议执行, supervisor->监察员
- executor/People.vue / sponsor/NewPerson.vue / sponsor/Projects.vue / sponsor/SponsorProjects.vue /
manager/ManagerProjectDetail.vue / manager/{Executor,Sponsor}PersonNew.vue /
admin/{Executor,Sponsor}PersonNew.vue 全部改为 enum key
SQL:
- migration_unify_role_type_2026_08_16.sql 清洗 biz_person.role 从中文到 enum key
This commit is contained in:
+58
-4
@@ -19,6 +19,7 @@ import com.ruoyi.business.mapper.BizOrgMapper;
|
||||
import com.ruoyi.business.service.IBizPersonService;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
|
||||
/**
|
||||
* 人员Controller
|
||||
@@ -32,9 +33,34 @@ public class BizPersonController extends BaseController
|
||||
|
||||
@Autowired
|
||||
private BizOrgMapper bizOrgMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
/**
|
||||
* 业务角色白名单: 这些 roleType 的 MAIN 账号调 /list 会自动按"本机构子账号"隔离
|
||||
* (sys_user.parent_user_id → sys_user.user_id → biz_person.user_id 链路过滤)
|
||||
*/
|
||||
private static final java.util.Set<String> BUSINESS_MAIN_ROLES = java.util.Set.of(
|
||||
"executor", "sponsor", "doctor", "manager", "leader"
|
||||
);
|
||||
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(BizPerson bizPerson)
|
||||
{
|
||||
// 当前登录用户是 MAIN 业务账号 → 自动注入 subUserIds, 隔离到本主账号的子账号对应人员
|
||||
Long currentUserId = getUserId();
|
||||
SysUser currentUser = currentUserId == null ? null : sysUserMapper.selectUserById(currentUserId);
|
||||
if (currentUser != null
|
||||
&& "MAIN".equals(currentUser.getAccountType())
|
||||
&& currentUser.getRoleType() != null
|
||||
&& BUSINESS_MAIN_ROLES.contains(currentUser.getRoleType())) {
|
||||
List<Long> subUserIds = sysUserMapper.selectUserIdsByParent(currentUserId);
|
||||
// 即使没子账号也强制注入, 避免漏出 sys_user.parent_user_id=NULL 的孤立 person
|
||||
bizPerson.getParams().put("subUserIds", subUserIds == null || subUserIds.isEmpty()
|
||||
? java.util.Collections.singletonList(-1L)
|
||||
: subUserIds);
|
||||
}
|
||||
startPage();
|
||||
List<BizPerson> list = bizPersonService.selectList(bizPerson);
|
||||
return getDataTable(list);
|
||||
@@ -107,6 +133,33 @@ public class BizPersonController extends BaseController
|
||||
@Log(title = "人员批量导入", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/sponsorImport")
|
||||
public AjaxResult sponsorImport(@RequestParam("file") MultipartFile file) throws Exception
|
||||
{
|
||||
return doImport(file, "sponsor");
|
||||
}
|
||||
|
||||
/**
|
||||
* executor 端批量导入人员 (上传 .xlsx) - 模板列头同 sponsor
|
||||
* orgName 按 orgType='executor' 匹配, unitType 写 executor
|
||||
*/
|
||||
@GetMapping("/executorImportTemplate")
|
||||
public void executorImportTemplate(HttpServletResponse response)
|
||||
{
|
||||
ExcelUtil<BizPersonImportVO> util = new ExcelUtil<>(BizPersonImportVO.class);
|
||||
util.importTemplateExcel(response, "人员导入");
|
||||
}
|
||||
|
||||
@Log(title = "人员批量导入", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/executorImport")
|
||||
public AjaxResult executorImport(@RequestParam("file") MultipartFile file) throws Exception
|
||||
{
|
||||
return doImport(file, "executor");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用人员导入逻辑 (sponsor / executor 共用)
|
||||
* @param unitType 'sponsor' 或 'executor' - 决定 orgName 匹配和 person.unitType 字段
|
||||
*/
|
||||
private AjaxResult doImport(MultipartFile file, String unitType) throws Exception
|
||||
{
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new ServiceException("请选择要上传的文件");
|
||||
@@ -126,17 +179,18 @@ public class BizPersonController extends BaseController
|
||||
r.put("name", row.getName());
|
||||
r.put("phone", row.getPhone());
|
||||
try {
|
||||
// 1. orgName → orgId (按 orgType='sponsor' 精确匹配, 查不到就报错)
|
||||
// 1. orgName → orgId (按 unitType 精确匹配, 查不到就报错)
|
||||
String orgName = row.getOrgName();
|
||||
if (orgName == null || orgName.trim().isEmpty()) {
|
||||
throw new ServiceException("所属公司不能为空");
|
||||
}
|
||||
BizOrg orgQuery = new BizOrg();
|
||||
orgQuery.setOrgName(orgName.trim());
|
||||
orgQuery.setOrgType("sponsor");
|
||||
orgQuery.setOrgType(unitType);
|
||||
List<BizOrg> matched = bizOrgMapper.selectList(orgQuery);
|
||||
if (matched == null || matched.isEmpty()) {
|
||||
throw new ServiceException("找不到所属公司: " + orgName + " (需先在 [公司管理] 录入 orgType=sponsor 的公司)");
|
||||
String label = "sponsor".equals(unitType) ? "支持单位管理" : "服务机构管理";
|
||||
throw new ServiceException("找不到所属公司: " + orgName + " (需先在 [" + label + "] 录入 orgType=" + unitType + " 的公司)");
|
||||
}
|
||||
Long orgId = matched.get(0).getOrgId();
|
||||
|
||||
@@ -148,7 +202,7 @@ public class BizPersonController extends BaseController
|
||||
p.setPosition(row.getPosition());
|
||||
p.setRole(row.getRole());
|
||||
p.setStatus("0"); // 默认正常
|
||||
p.setUnitType("sponsor");
|
||||
p.setUnitType(unitType);
|
||||
p.setLoginUsername(row.getPhone()); // 用户名 = 手机号 (要求唯一)
|
||||
p.setLoginPassword("123456"); // 默认密码
|
||||
p.setCreateBy(getUsername());
|
||||
|
||||
@@ -32,11 +32,9 @@ public class BizPerson extends BaseEntity {
|
||||
/** role */
|
||||
@Excel(name = "role")
|
||||
private String role;
|
||||
/** status */
|
||||
@Excel(name = "status")
|
||||
/** 状态 0正常 1禁用 - 跟 sys_user.status 同步, 前端展示请读 sys_user */
|
||||
@Deprecated
|
||||
private String status;
|
||||
/** 逻辑删除 0正常 1已删 */
|
||||
private String delFlag;
|
||||
/** create_by */
|
||||
@Excel(name = "create_by")
|
||||
private String createBy;
|
||||
@@ -60,8 +58,10 @@ public class BizPerson extends BaseEntity {
|
||||
/** 主账号ID (来自 sys_user.parent_user_id, 子账号指向其主账号) - 仅展示用 */
|
||||
private Long parentUserId;
|
||||
/** 子账号登录账号 (前端传入, 用于创建 sys_user 子账号) - 非持久化字段 */
|
||||
@com.fasterxml.jackson.annotation.JsonProperty("userName")
|
||||
private transient String loginUsername;
|
||||
/** 子账号初始密码 (前端传入, 明文, 创建后不存储明文) - 非持久化字段 */
|
||||
@com.fasterxml.jackson.annotation.JsonProperty("password")
|
||||
private transient String loginPassword;
|
||||
public String getPersonId() { return personId; }
|
||||
public void setPersonId(String personId) { this.personId = personId; }
|
||||
@@ -83,8 +83,9 @@ public class BizPerson extends BaseEntity {
|
||||
public void setRole(String role) { this.role = role; }
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public String getDelFlag() { return delFlag; }
|
||||
public void setDelFlag(String delFlag) { this.delFlag = delFlag; }
|
||||
/** 兼容前端调用, 实际读 sys_user.delFlag */
|
||||
public String getDelFlag() { return null; }
|
||||
public void setDelFlag(String delFlag) { /* noop - 跟 sys_user 同步 */ }
|
||||
public String getCreateBy() { return createBy; }
|
||||
public void setCreateBy(String createBy) { this.createBy = createBy; }
|
||||
public Date getCreateTime() { return createTime; }
|
||||
|
||||
+42
-4
@@ -3,7 +3,9 @@ package com.ruoyi.business.service.impl;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.business.domain.BizOrg;
|
||||
import com.ruoyi.business.domain.BizPerson;
|
||||
import com.ruoyi.business.mapper.BizOrgMapper;
|
||||
import com.ruoyi.business.mapper.BizPersonMapper;
|
||||
import com.ruoyi.business.service.IBizPersonService;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
@@ -18,6 +20,8 @@ public class BizPersonServiceImpl implements IBizPersonService
|
||||
private BizPersonMapper bizPersonMapper;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
@Autowired
|
||||
private BizOrgMapper bizOrgMapper;
|
||||
|
||||
@Override
|
||||
public BizPerson getById(String personId)
|
||||
@@ -42,6 +46,23 @@ public class BizPersonServiceImpl implements IBizPersonService
|
||||
if (exist != null) {
|
||||
throw new ServiceException("登录账号已存在");
|
||||
}
|
||||
|
||||
// 0.5 兜底: 如果前端没传 orgId, 按 (orgName + unitType) 查 biz_org 回填
|
||||
// (前端从 org 页面跳来时已带 orgId; 直接访问 new 页面没带 orgId 时走这条路径)
|
||||
if (entity.getOrgId() == null && entity.getOrgName() != null && !entity.getOrgName().isEmpty()
|
||||
&& entity.getUnitType() != null && !entity.getUnitType().isEmpty()) {
|
||||
BizOrg q = new BizOrg();
|
||||
q.setOrgName(entity.getOrgName().trim());
|
||||
q.setOrgType(entity.getUnitType());
|
||||
List<BizOrg> matched = bizOrgMapper.selectList(q);
|
||||
if (matched != null && !matched.isEmpty()) {
|
||||
entity.setOrgId(matched.get(0).getOrgId());
|
||||
}
|
||||
}
|
||||
if (entity.getOrgId() == null) {
|
||||
throw new ServiceException("请填写所属公司 (需先在 [支持单位管理/服务机构管理] 录入 orgType=" + entity.getUnitType() + " 的公司)");
|
||||
}
|
||||
|
||||
// 1. 创建 sys_user 子账号
|
||||
SysUser newUser = new SysUser();
|
||||
newUser.setUserName(entity.getLoginUsername());
|
||||
@@ -67,15 +88,33 @@ public class BizPersonServiceImpl implements IBizPersonService
|
||||
return newUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新人员: 同时更新 biz_person 业务字段 + 同步更新 sys_user 基础字段
|
||||
* 同步字段: nick_name (业务姓名) / phonenumber (业务手机号) / status (账号启停)
|
||||
* 不同步: password (走独立 updatePwd 接口)
|
||||
*/
|
||||
@Override
|
||||
public int updateByPrimaryKey(BizPerson entity)
|
||||
{ return bizPersonMapper.updateByPrimaryKey(entity); }
|
||||
public int updateByPrimaryKey(BizPerson entity) {
|
||||
int n = bizPersonMapper.updateByPrimaryKey(entity);
|
||||
if (n > 0 && entity.getUserId() != null) {
|
||||
SysUser u = new SysUser();
|
||||
u.setUserId(entity.getUserId());
|
||||
u.setNickName(entity.getName());
|
||||
u.setPhonenumber(entity.getPhone());
|
||||
u.setUpdateBy(SecurityUtils.getUsername());
|
||||
// status 同步 (如果前端传了 status 字段)
|
||||
if (entity.getStatus() != null) {
|
||||
u.setStatus(entity.getStatus());
|
||||
}
|
||||
sysUserMapper.updateUser(u);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(String personId)
|
||||
{
|
||||
int n = bizPersonMapper.deleteByPrimaryKey(personId);
|
||||
if (n > 0) bizPersonMapper.softDeleteSysUserByPersonIds(new String[]{ personId });
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -83,7 +122,6 @@ public class BizPersonServiceImpl implements IBizPersonService
|
||||
public int deleteByPrimaryKeys(String[] personIds)
|
||||
{
|
||||
int n = bizPersonMapper.deleteByPrimaryKeys(personIds);
|
||||
if (n > 0) bizPersonMapper.softDeleteSysUserByPersonIds(personIds);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
@@ -23,16 +23,16 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectFields">
|
||||
select person_id, name, phone, org_id, department, position, role, unit_type, status, del_flag, user_id, create_by, create_time, update_by, update_time
|
||||
select person_id, name, phone, org_id, department, position, role, unit_type, user_id, create_by, create_time, update_by, update_time
|
||||
from biz_person
|
||||
</sql>
|
||||
|
||||
<!-- 通用列表: LEFT JOIN biz_org 取公司名/类型, LEFT JOIN sys_user 取账号类型 -->
|
||||
<!-- 通用列表: LEFT JOIN biz_org 取公司名/类型, LEFT JOIN sys_user 取账号状态/类型 -->
|
||||
<sql id="selectFieldsWithAccount">
|
||||
select p.person_id, p.name, p.phone, p.org_id, o.org_name, o.org_type,
|
||||
p.department, p.position, p.role, p.unit_type, p.status, p.del_flag, p.user_id,
|
||||
p.department, p.position, p.role, p.unit_type, p.user_id,
|
||||
p.create_by, p.create_time, p.update_by, p.update_time,
|
||||
u.account_type, u.parent_user_id, u.del_flag as user_del_flag
|
||||
u.account_type, u.parent_user_id, u.status, u.del_flag as user_del_flag
|
||||
from biz_person p
|
||||
left join biz_org o on p.org_id = o.org_id
|
||||
left join sys_user u on p.user_id = u.user_id
|
||||
@@ -46,7 +46,7 @@
|
||||
<select id="selectList" resultMap="BizPersonResult" parameterType="BizPerson">
|
||||
<include refid="selectFieldsWithAccount"/>
|
||||
<where>
|
||||
p.del_flag = '0'
|
||||
u.del_flag = '0'
|
||||
<if test="unitType != null and unitType != ''"> and p.unit_type = #{unitType}</if>
|
||||
<if test="name != null and name != ''"> and p.name = #{name}</if>
|
||||
<if test="phone != null and phone != ''"> and p.phone = #{phone}</if>
|
||||
@@ -55,8 +55,15 @@
|
||||
<if test="department != null and department != ''"> and p.department = #{department}</if>
|
||||
<if test="position != null and position != ''"> and p.position = #{position}</if>
|
||||
<if test="role != null and role != ''"> and p.role = #{role}</if>
|
||||
<if test="status != null and status != ''"> and p.status = #{status}</if>
|
||||
<if test="status != null and status != ''"> and u.status = #{status}</if>
|
||||
<if test="parentUserId != null"> and u.parent_user_id = #{parentUserId}</if>
|
||||
<!-- 业务主账号隔离: biz_person.user_id IN (我的子账号 user_ids) -->
|
||||
<if test="params.subUserIds != null and params.subUserIds.size() > 0">
|
||||
and p.user_id in
|
||||
<foreach collection="params.subUserIds" item="sid" open="(" separator="," close=")">
|
||||
#{sid}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
order by p.person_id desc
|
||||
</select>
|
||||
@@ -72,7 +79,6 @@
|
||||
<if test="position != null">position,</if>
|
||||
<if test="role != null">role,</if>
|
||||
<if test="unitType != null">unit_type,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time,
|
||||
@@ -88,7 +94,6 @@
|
||||
<if test="position != null">#{position},</if>
|
||||
<if test="role != null">#{role},</if>
|
||||
<if test="unitType != null">#{unitType},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate(),
|
||||
@@ -108,31 +113,32 @@
|
||||
<if test="department != null">department = #{department},</if>
|
||||
<if test="position != null">position = #{position},</if>
|
||||
<if test="role != null">role = #{role},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
update_time = sysdate(),
|
||||
</trim>
|
||||
where person_id = #{personId}
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除: 设 del_flag='1', 同时联动把关联 sys_user 子账号也逻辑删除 -->
|
||||
<!-- 逻辑删除: 改 sys_user.del_flag='1' (biz_person 没这字段, 改用 sys_user 软删) -->
|
||||
<update id="deleteByPrimaryKey" parameterType="String">
|
||||
update biz_person set del_flag='1', update_time=sysdate()
|
||||
where person_id = #{personId} and del_flag='0'
|
||||
update sys_user u inner join biz_person p on u.user_id = p.user_id
|
||||
set u.del_flag='1'
|
||||
where p.person_id = #{personId} and u.del_flag='0'
|
||||
</update>
|
||||
<update id="deleteByPrimaryKeys" parameterType="String">
|
||||
update biz_person set del_flag='1', update_time=sysdate()
|
||||
where del_flag='0' and person_id in
|
||||
update sys_user u inner join biz_person p on u.user_id = p.user_id
|
||||
set u.del_flag='1'
|
||||
where u.del_flag='0' and p.person_id in
|
||||
<foreach collection="personIds" item="personId" open="(" separator="," close=")">
|
||||
#{personId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 联动: 把 personIds 对应的 sys_user 子账号也逻辑删除 -->
|
||||
<!-- 联动: 把 personIds 对应的 sys_user 子账号也逻辑删除 (兼容保留, 与 deleteByPrimaryKeys 行为一致) -->
|
||||
<update id="softDeleteSysUserByPersonIds" parameterType="String">
|
||||
update sys_user u inner join biz_person p on u.user_id = p.user_id
|
||||
set u.del_flag='1'
|
||||
where u.del_flag='0' and p.del_flag='1' and p.person_id in
|
||||
where u.del_flag='0' and p.person_id in
|
||||
<foreach collection="personIds" item="personId" open="(" separator="," close=")">
|
||||
#{personId}
|
||||
</foreach>
|
||||
@@ -143,8 +149,7 @@
|
||||
<select id="selectSponsorList" resultMap="BizPersonResult" parameterType="BizPerson">
|
||||
<include refid="selectFieldsWithAccount"/>
|
||||
<where>
|
||||
p.del_flag = '0'
|
||||
and u.del_flag = '0'
|
||||
u.del_flag = '0'
|
||||
and p.unit_type = 'sponsor'
|
||||
and u.parent_user_id = #{params.sponsorOwnerUid}
|
||||
<if test="name != null and name != ''"> and p.name = #{name}</if>
|
||||
@@ -153,7 +158,7 @@
|
||||
<if test="department != null and department != ''"> and p.department = #{department}</if>
|
||||
<if test="position != null and position != ''"> and p.position = #{position}</if>
|
||||
<if test="role != null and role != ''"> and p.role = #{role}</if>
|
||||
<if test="status != null and status != ''"> and p.status = #{status}</if>
|
||||
<if test="status != null and status != ''"> and u.status = #{status}</if>
|
||||
</where>
|
||||
order by p.person_id desc
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user