189 lines
10 KiB
XML
189 lines
10 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
<mapper namespace="com.ruoyi.business.mapper.BizPersonMapper">
|
|
<resultMap type="BizPerson" id="BizPersonResult">
|
|
<id property="personId" column="person_id" />
|
|
<result property="name" column="name" />
|
|
<result property="phone" column="phone" />
|
|
<result property="orgId" column="org_id" />
|
|
<result property="orgName" column="org_name" />
|
|
<result property="orgType" column="org_type" />
|
|
<result property="department" column="department" />
|
|
<result property="position" column="position" />
|
|
<result property="userId" column="user_id" />
|
|
<result property="unitType" column="unit_type" />
|
|
<result property="accountType" column="account_type" />
|
|
<result property="parentUserId" column="parent_user_id" />
|
|
<result property="account" column="user_name" />
|
|
<result property="email" column="email" />
|
|
<result property="createBy" column="create_by" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="updateBy" column="update_by" />
|
|
<result property="updateTime" column="update_time" />
|
|
</resultMap>
|
|
|
|
<sql id="selectFields">
|
|
select person_id, name, phone, org_id, department, position, unit_type, user_id, create_by, create_time, update_by, update_time
|
|
from biz_person
|
|
</sql>
|
|
|
|
<!-- 通用列表: 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.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.status, u.del_flag as user_del_flag,
|
|
u.user_name as user_name,
|
|
u.email as email
|
|
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
|
|
</sql>
|
|
|
|
<select id="selectByPrimaryKey" resultMap="BizPersonResult" parameterType="String">
|
|
<include refid="selectFieldsWithAccount"/>
|
|
where p.person_id = #{personId}
|
|
</select>
|
|
|
|
<select id="selectList" resultMap="BizPersonResult" parameterType="BizPerson">
|
|
<include refid="selectFieldsWithAccount"/>
|
|
<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 like concat('%', #{name}, '%')</if>
|
|
<if test="phone != null and phone != ''"> and p.phone = #{phone}</if>
|
|
<if test="email != null and email != ''"> and u.email = #{email}</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>
|
|
<if test="status != null and status != ''"> and u.status = #{status}</if>
|
|
<if test="parentUserId != null"> and u.parent_user_id = #{parentUserId}</if>
|
|
<if test="userId != null"> and p.user_id = #{userId}</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>
|
|
|
|
<insert id="insert" parameterType="BizPerson">
|
|
insert into biz_person
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="personId != null and personId != ''">person_id,</if>
|
|
<if test="name != null">name,</if>
|
|
<if test="phone != null">phone,</if>
|
|
<if test="orgId != null">org_id,</if>
|
|
<if test="department != null">department,</if>
|
|
<if test="position != null">position,</if>
|
|
<if test="unitType != null">unit_type,</if>
|
|
<if test="userId != null">user_id,</if>
|
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
|
create_time,
|
|
<if test="updateBy != null and updateBy != ''">update_by,</if>
|
|
update_time,
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="personId != null and personId != ''">#{personId},</if>
|
|
<if test="name != null">#{name},</if>
|
|
<if test="phone != null">#{phone},</if>
|
|
<if test="orgId != null">#{orgId},</if>
|
|
<if test="department != null">#{department},</if>
|
|
<if test="position != null">#{position},</if>
|
|
<if test="unitType != null">#{unitType},</if>
|
|
<if test="userId != null">#{userId},</if>
|
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
|
sysdate(),
|
|
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
|
|
sysdate(),
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateByPrimaryKey" parameterType="BizPerson">
|
|
update biz_person
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="userId != null and userId != ''">user_id = #{userId},</if>
|
|
<if test="orgId != null">org_id = #{orgId},</if>
|
|
<if test="unitType != null and unitType != ''">unit_type = #{unitType},</if>
|
|
<if test="name != null">name = #{name},</if>
|
|
<if test="phone != null">phone = #{phone},</if>
|
|
<if test="department != null">department = #{department},</if>
|
|
<if test="position != null">position = #{position},</if>
|
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
|
update_time = sysdate(),
|
|
</trim>
|
|
where person_id = #{personId}
|
|
</update>
|
|
|
|
<!-- 逻辑删除: 改 sys_user.del_flag='1' (biz_person 没这字段, 改用 sys_user 软删) -->
|
|
<update id="deleteByPrimaryKey" parameterType="String">
|
|
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 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 子账号也逻辑删除 (兼容保留, 与 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.person_id in
|
|
<foreach collection="personIds" item="personId" open="(" separator="," close=")">
|
|
#{personId}
|
|
</foreach>
|
|
</update>
|
|
|
|
<!-- sponsor 专属: 通过 biz_person.user_id 关联 sys_user, 利用 sys_user.parent_user_id 过滤主账号归属 -->
|
|
<!-- 主账号自己 (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}
|
|
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="status != null and status != ''"> and u.status = #{status}</if>
|
|
</where>
|
|
order by p.person_id desc
|
|
</select>
|
|
|
|
<!-- executor 专属: 同 sponsor, SQL 硬编码 unit_type='executor' + parent_user_id=当前主账号 (前端绕不开) -->
|
|
<!-- 主账号自己 (parent_user_id=NULL) 也通过 OR u.user_id=#{executorOwnerUid} 一并带上 (否则主账号看不到自己) -->
|
|
<select id="selectExecutorList" resultMap="BizPersonResult" parameterType="BizPerson">
|
|
<include refid="selectFieldsWithAccount"/>
|
|
<where>
|
|
u.del_flag = '0'
|
|
and p.unit_type = 'executor'
|
|
and (u.parent_user_id = #{params.executorOwnerUid}
|
|
or u.user_id = #{params.executorOwnerUid})
|
|
<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="status != null and status != ''"> and u.status = #{status}</if>
|
|
</where>
|
|
order by p.person_id desc
|
|
</select>
|
|
|
|
</mapper>
|