feat(sponsor/people): 主账号同步建 biz_person (admin/总负责人), 列表可见 + 操作列对本人隐藏 + 新建下拉不包含 admin
后端:
- BizAuthController.registerSponsor step 6: 为主账号同步建 biz_person
(走 BizPersonMapper 直插, 绕过 BizPersonServiceImpl 创 SUB 子账号的逻辑;
SnowflakeId 注入 personId; department=管理部, position=总负责人, role=admin,
unit_type=sponsor, user_id=主账号自己)
- BizPersonMapper.java + xml 新增 countAdminByOrgId: 校验某 org 下是否已有 admin
(注册场景下天然返回 0, 是给未来 bug 兜底, registerSponsor 暂不调用)
- BizPersonMapper.xml selectSponsorList: WHERE 加 OR u.user_id=#{sponsorOwnerUid},
让主账号自己的 biz_person (parent_user_id=NULL) 也能被自身 list 看到
前端:
- utils/roleMap.js: PERSON_ROLE_LABEL 加 admin:'管理员'
- sponsor/SponsorPeople.vue: 角色列改用 translatePersonRole, tag type 按 role 动态
(admin=warning, supervisor=primary); 操作列本人隐藏 禁用/恢复 + 删除
(v-if=row.userId !== store.user?.userId, 防主账号把自己禁用/误删)
- sponsor/NewPerson.vue: 编辑模式 role=admin 显示静态 el-tag, 新建下拉仍只含 supervisor
- sponsor/PersonDetail.vue: 角色展示同步用 translatePersonRole
- auth/Login.vue + portal/Home.vue: 文案 监察员 → 管理员 (注册即管理员, 可建监察员子账号)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+26
-1
@@ -11,9 +11,12 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.business.domain.BizOrg;
|
||||
import com.ruoyi.business.domain.BizPerson;
|
||||
import com.ruoyi.business.dto.SmsValidForm;
|
||||
import com.ruoyi.business.mapper.BizPersonMapper;
|
||||
import com.ruoyi.business.service.IBizOrgService;
|
||||
import com.ruoyi.business.service.SysSmsService;
|
||||
import com.ruoyi.common.utils.id.SnowflakeId;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
@@ -37,7 +40,8 @@ import com.ruoyi.system.service.ISysUserService;
|
||||
* 3. 加密密码
|
||||
* 4. 插入 sys_user (用户名=前端传入, sys_user.role_type 写入 executor/sponsor, 主账号)
|
||||
* 5. 插入 biz_org (对应类型, business_nature/contact_phone 从表单)
|
||||
* 注: 主账号不建 biz_person
|
||||
* 6. 插入 biz_person (主账号同步建自己=管理员, 让自己在"人员管理"可见)
|
||||
* 注: 主账号同步建 biz_person (自己=管理员)
|
||||
*
|
||||
* 2026-08-16 重构: 删 biz_user_role_bind, 统一用 sys_user.role_type (见迁移脚本)
|
||||
*
|
||||
@@ -58,6 +62,9 @@ public class BizAuthController extends BaseController {
|
||||
@Autowired
|
||||
private IBizOrgService bizOrgService;
|
||||
|
||||
@Autowired
|
||||
private BizPersonMapper bizPersonMapper;
|
||||
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder passwordEncoder;
|
||||
|
||||
@@ -294,6 +301,24 @@ public class BizAuthController extends BaseController {
|
||||
bizOrgService.insert(org);
|
||||
Long orgId = org.getOrgId();
|
||||
|
||||
// 6. 同步建 biz_person (主账号自己 = 管理员, 让"人员管理"能看到自己)
|
||||
// 注意: 不能走 IBizPersonService.insert(BizPerson, Long), 那个方法是创建 SUB 子账号的
|
||||
// (强制 accountType='SUB' + 需 loginUsername, 主账号自己不需要).
|
||||
// sys_user 已在 step 4 建好, 这里只需把 biz_person 关联到主账号自己.
|
||||
BizPerson self = new BizPerson();
|
||||
SnowflakeId.injectIfEmpty(self, "personId");
|
||||
self.setName(unitName);
|
||||
self.setPhone(phone);
|
||||
self.setOrgId(orgId);
|
||||
self.setDepartment("管理部");
|
||||
self.setPosition("总负责人");
|
||||
self.setRole("admin"); // 主账号 = 管理员 (与子账号的监察员区分)
|
||||
self.setUnitType("sponsor");
|
||||
self.setUserId(userId);
|
||||
self.setCreateBy(username);
|
||||
self.setUpdateBy(username);
|
||||
bizPersonMapper.insert(self);
|
||||
|
||||
return success("注册成功, 请等待审核").put("userId", userId).put("orgId", orgId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.business.mapper;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.ruoyi.business.domain.BizPerson;
|
||||
|
||||
/**
|
||||
@@ -19,4 +20,6 @@ public interface BizPersonMapper
|
||||
int deleteByPrimaryKeys(String[] personIds);
|
||||
/** 联动: person 逻辑删除后, 把对应 sys_user 子账号也逻辑删除 */
|
||||
int softDeleteSysUserByPersonIds(String[] personIds);
|
||||
/** 校验某 org 下是否已有 admin 角色 (注册时兜底, 保证一公司一管理员) */
|
||||
int countAdminByOrgId(@Param("orgId") Long orgId);
|
||||
}
|
||||
@@ -47,9 +47,10 @@
|
||||
<where>
|
||||
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="name != null and name != ''"> and p.name like concat('%', #{name}, '%')</if>
|
||||
<if test="phone != null and phone != ''"> and p.phone = #{phone}</if>
|
||||
<if test="orgId != null"> and p.org_id = #{orgId}</if>
|
||||
<if test="orgName != null and orgName != ''"> and o.org_name like concat('%', #{orgName}, '%')</if>
|
||||
<if test="orgType != null and orgType != ''"> and o.org_type = #{orgType}</if>
|
||||
<if test="department != null and department != ''"> and p.department = #{department}</if>
|
||||
<if test="position != null and position != ''"> and p.position = #{position}</if>
|
||||
@@ -144,16 +145,18 @@
|
||||
</update>
|
||||
|
||||
<!-- sponsor 专属: 通过 biz_person.user_id 关联 sys_user, 利用 sys_user.parent_user_id 过滤主账号归属 -->
|
||||
<!-- INNER JOIN 自然过滤掉 user_id=NULL 的游离 person (不算员工) -->
|
||||
<!-- 主账号自己 (parent_user_id=NULL) 也通过 OR u.user_id=#{sponsorOwnerUid} 一并带上 (否则主账号看不到自己) -->
|
||||
<select id="selectSponsorList" resultMap="BizPersonResult" parameterType="BizPerson">
|
||||
<include refid="selectFieldsWithAccount"/>
|
||||
<where>
|
||||
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>
|
||||
and (u.parent_user_id = #{params.sponsorOwnerUid}
|
||||
or u.user_id = #{params.sponsorOwnerUid})
|
||||
<if test="name != null and name != ''"> and p.name like concat('%', #{name}, '%')</if>
|
||||
<if test="phone != null and phone != ''"> and p.phone = #{phone}</if>
|
||||
<if test="orgId != null"> and p.org_id = #{orgId}</if>
|
||||
<if test="orgName != null and orgName != ''"> and o.org_name like concat('%', #{orgName}, '%')</if>
|
||||
<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>
|
||||
@@ -169,9 +172,10 @@
|
||||
u.del_flag = '0'
|
||||
and p.unit_type = 'executor'
|
||||
and u.parent_user_id = #{params.executorOwnerUid}
|
||||
<if test="name != null and name != ''"> and p.name = #{name}</if>
|
||||
<if test="name != null and name != ''"> and p.name like concat('%', #{name}, '%')</if>
|
||||
<if test="phone != null and phone != ''"> and p.phone = #{phone}</if>
|
||||
<if test="orgId != null"> and p.org_id = #{orgId}</if>
|
||||
<if test="orgName != null and orgName != ''"> and o.org_name like concat('%', #{orgName}, '%')</if>
|
||||
<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>
|
||||
@@ -179,4 +183,11 @@
|
||||
</where>
|
||||
order by p.person_id desc
|
||||
</select>
|
||||
|
||||
<!-- 校验某 org 下是否已有 admin 角色 (主账号自带 biz_person.role='admin', 每公司唯一) -->
|
||||
<select id="countAdminByOrgId" resultType="int">
|
||||
select count(*) from biz_person p
|
||||
left join sys_user u on p.user_id = u.user_id
|
||||
where p.org_id = #{orgId} and p.role = 'admin' and u.del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user