- 项目/项目评价/报名专家 3 类导出, 勾选透传 projectIds - 项目列表 总场次/已执行/未执行 三列点击跳对应会议列表 (executor 复用后端 role 隔离) - 机构软删除 + 级联软删机构下账号 - 供应商开放接口账号同步 Co-Authored-By: Claude <noreply@anthropic.com>
252 lines
13 KiB
XML
252 lines
13 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.BizOrgMapper">
|
|
<resultMap type="BizOrg" id="BizOrgResult">
|
|
<id property="orgId" column="org_id" />
|
|
<result property="userId" column="user_id" />
|
|
<result property="orgName" column="org_name" />
|
|
<result property="orgType" column="org_type" />
|
|
<result property="businessNature" column="business_nature" />
|
|
<result property="address" column="address" />
|
|
<result property="taxNo" column="tax_no" />
|
|
<result property="status" column="status" />
|
|
<result property="createTime" column="create_time" />
|
|
<result property="contactName" column="contact_name" />
|
|
<result property="contactPhone" column="contact_phone" />
|
|
<result property="intentCount" column="intent_count" />
|
|
<result property="createBy" column="create_by" />
|
|
<result property="updateBy" column="update_by" />
|
|
<result property="updateTime" column="update_time" />
|
|
<result property="delFlag" column="del_flag" />
|
|
<result property="isSynced" column="is_synced" />
|
|
</resultMap>
|
|
|
|
<sql id="selectFields">
|
|
select org_id, user_id, org_name, org_type, business_nature, address, tax_no, status, create_time,
|
|
contact_name, contact_phone, intent_count,
|
|
create_by, update_by, update_time, del_flag, is_synced
|
|
from biz_org
|
|
</sql>
|
|
|
|
<select id="selectByPrimaryKey" resultMap="BizOrgResult" parameterType="Long">
|
|
<include refid="selectFields"/>
|
|
where org_id = #{orgId}
|
|
and del_flag = '0'
|
|
</select>
|
|
|
|
<select id="selectList" resultMap="BizOrgResult" parameterType="BizOrg">
|
|
<include refid="selectFields"/>
|
|
<where>
|
|
del_flag = '0'
|
|
<if test="userId != null"> and user_id = #{userId}</if>
|
|
<if test="orgType != null and orgType != ''"> and org_type = #{orgType}</if>
|
|
<if test="orgName != null and orgName != ''"> and org_name like concat('%', #{orgName}, '%')</if>
|
|
<if test="taxNo != null and taxNo != ''"> and tax_no = #{taxNo}</if>
|
|
<if test="status != null and status != ''"> and status = #{status}</if>
|
|
</where>
|
|
order by org_id desc
|
|
</select>
|
|
|
|
<insert id="insert" parameterType="BizOrg" useGeneratedKeys="true" keyProperty="orgId">
|
|
insert into biz_org
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
|
<if test="userId != null">user_id,</if>
|
|
<if test="orgName != null and orgName != ''">org_name,</if>
|
|
<if test="orgType != null and orgType != ''">org_type,</if>
|
|
<if test="businessNature != null and businessNature != ''">business_nature,</if>
|
|
<if test="address != null and address != ''">address,</if>
|
|
<if test="taxNo != null and taxNo != ''">tax_no,</if>
|
|
<if test="contactName != null and contactName != ''">contact_name,</if>
|
|
<if test="contactPhone != null and contactPhone != ''">contact_phone,</if>
|
|
<if test="intentCount != null">intent_count,</if>
|
|
<if test="status != null and status != ''">status,</if>
|
|
<if test="isSynced != null">is_synced,</if>
|
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
|
create_time,
|
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
<if test="userId != null">#{userId},</if>
|
|
<if test="orgName != null and orgName != ''">#{orgName},</if>
|
|
<if test="orgType != null and orgType != ''">#{orgType},</if>
|
|
<if test="businessNature != null and businessNature != ''">#{businessNature},</if>
|
|
<if test="address != null and address != ''">#{address},</if>
|
|
<if test="taxNo != null and taxNo != ''">#{taxNo},</if>
|
|
<if test="contactName != null and contactName != ''">#{contactName},</if>
|
|
<if test="contactPhone != null and contactPhone != ''">#{contactPhone},</if>
|
|
<if test="intentCount != null">#{intentCount},</if>
|
|
<if test="status != null and status != ''">#{status},</if>
|
|
<if test="isSynced != null">#{isSynced},</if>
|
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
|
sysdate(),
|
|
</trim>
|
|
</insert>
|
|
|
|
<update id="updateByPrimaryKey" parameterType="BizOrg">
|
|
update biz_org
|
|
<trim prefix="SET" suffixOverrides=",">
|
|
<if test="userId != null">user_id = #{userId},</if>
|
|
<if test="orgName != null and orgName != ''">org_name = #{orgName},</if>
|
|
<if test="orgType != null and orgType != ''">org_type = #{orgType},</if>
|
|
<if test="businessNature != null and businessNature != ''">business_nature = #{businessNature},</if>
|
|
<if test="address != null">address = #{address},</if>
|
|
<if test="taxNo != null">tax_no = #{taxNo},</if>
|
|
<if test="contactName != null">contact_name = #{contactName},</if>
|
|
<if test="contactPhone != null">contact_phone = #{contactPhone},</if>
|
|
<if test="intentCount != null">intent_count = #{intentCount},</if>
|
|
<if test="status != null and status != ''">status = #{status},</if>
|
|
<if test="isSynced != null">is_synced = #{isSynced},</if>
|
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
|
update_time = sysdate(),
|
|
</trim>
|
|
where org_id = #{orgId}
|
|
</update>
|
|
|
|
<update id="deleteByPrimaryKeys" parameterType="Long">
|
|
update biz_org set del_flag = '1' where org_id in
|
|
<foreach collection="array" item="orgId" open="(" separator="," close=")">
|
|
#{orgId}
|
|
</foreach>
|
|
and del_flag = '0'
|
|
</update>
|
|
|
|
<!-- 级联软删机构下所有账号 (主账号 biz_org.user_id + 子账号 biz_person.user_id), 删除机构时调用 -->
|
|
<update id="softDeleteUsersByOrgId" parameterType="Long">
|
|
update sys_user set del_flag = '1'
|
|
where del_flag = '0' and (
|
|
user_id in (select user_id from biz_person where org_id = #{orgId})
|
|
or user_id = (select user_id from biz_org where org_id = #{orgId})
|
|
)
|
|
</update>
|
|
|
|
<!--
|
|
支持方下拉选项: JOIN sys_user 取主账号 user_name (供分配弹窗缓存 biz_project.sponsor_admin_user_name 用)
|
|
返回 Map: orgId / orgName / userName
|
|
EXPLAIN 实际命中: idx_org_type_status (org_type,status) (优化器在数据量小时倾向小索引),
|
|
org_name LIKE 走 Using where 二次过滤, ORDER BY org_id DESC 走 filesort
|
|
过滤条件: orgName 模糊匹配 (主用) / orgId 精确匹配 (拉回已选项)
|
|
-->
|
|
<select id="selectSponsorOrgOptions" parameterType="BizOrg" resultType="java.util.LinkedHashMap">
|
|
select o.org_id as orgId,
|
|
o.org_name as orgName,
|
|
o.status as status,
|
|
u.user_name as userName
|
|
from biz_org o
|
|
join sys_user u on u.user_id = o.user_id
|
|
where o.org_type = 'sponsor'
|
|
and o.del_flag = '0'
|
|
and u.del_flag = '0'
|
|
<if test="orgId != null">and o.org_id = #{orgId}</if>
|
|
<if test="orgName != null and orgName != ''">and o.org_name like concat('%', #{orgName}, '%')</if>
|
|
order by o.org_id desc
|
|
LIMIT 10
|
|
</select>
|
|
|
|
<!--
|
|
执行方下拉选项: JOIN sys_user 取 MAIN 账号 user_name (parent_user_id IS NULL 限定主账号)
|
|
返回 Map: orgId / orgName / userName
|
|
EXPLAIN 实际命中: idx_org_type_status (org_type,status) (优化器在数据量小时倾向小索引),
|
|
sys_user 走 PRIMARY eq_ref, parent_user_id IS NULL 走 Using where
|
|
关键: 只查 MAIN 账号 (parent_user_id IS NULL), 过滤掉同一公司下的普通员工子账号
|
|
value=orgId (biz_org.org_id, 直接写 biz_project_assign.execution_unit_id)
|
|
label=orgName (执行单位名称, 不带 user_name 避免人名/昵称混淆)
|
|
过滤条件: orgName 模糊匹配 (主用) / orgId 精确匹配 (拉回已选项)
|
|
-->
|
|
<select id="selectExecutorOrgOptions" parameterType="BizOrg" resultType="java.util.LinkedHashMap">
|
|
select o.org_id as orgId,
|
|
o.org_name as orgName,
|
|
o.status as status,
|
|
u.user_name as userName
|
|
from biz_org o
|
|
join sys_user u on u.user_id = o.user_id
|
|
where o.org_type = 'executor'
|
|
and o.del_flag = '0'
|
|
and u.del_flag = '0'
|
|
and u.parent_user_id is null
|
|
<if test="orgId != null">and o.org_id = #{orgId}</if>
|
|
<if test="orgName != null and orgName != ''">and o.org_name like concat('%', #{orgName}, '%')</if>
|
|
order by o.org_id desc
|
|
LIMIT 10
|
|
</select>
|
|
|
|
<!--
|
|
支持方注册下拉选项 (匿名公开, register-sponsor 选企业注册 SUB 子账号)
|
|
与 selectSponsorOrgOptions 的区别: 不 JOIN sys_user → 无主账号 (user_id IS NULL) 的 org 也能被选到
|
|
返回 Map: orgId / orgName / mainUserId (= biz_org.user_id, 可为 null)
|
|
mainUserId 用于 registerSponsor 判断: 有主账号 → SUB 绑 parent_user_id; 无主账号 → parent_user_id 留空待 admin/manager 分配
|
|
-->
|
|
<select id="selectSponsorRegisterOptions" parameterType="BizOrg" resultType="java.util.LinkedHashMap">
|
|
select o.org_id as orgId,
|
|
o.org_name as orgName,
|
|
o.user_id as mainUserId
|
|
from biz_org o
|
|
where o.org_type = 'sponsor'
|
|
and o.status = '0'
|
|
and o.del_flag = '0'
|
|
<if test="orgName != null and orgName != ''">and o.org_name like concat('%', #{orgName}, '%')</if>
|
|
order by o.org_id desc
|
|
limit 20
|
|
</select>
|
|
|
|
<!--
|
|
当前登录 sponsor 的所属公司 (供 /sponsor/account 页面回显 + 主账号改名)
|
|
主账号 (sys_user.parent_user_id IS NULL): 用 own (biz_org.user_id = #{userId})
|
|
子账号 (有 biz_person.user_id = #{userId}): 用 biz_person.org_id → biz_org
|
|
COALESCE(own.org_id, p.org_id) 二选一, isOwner 标识主账号
|
|
返回 Map: orgId / orgName / isOwner (1=主账号, 0=子账号)
|
|
-->
|
|
<select id="selectMySponsorCompany" parameterType="Long" resultType="java.util.LinkedHashMap">
|
|
select o.org_id as orgId,
|
|
o.org_name as orgName,
|
|
case when p.user_id is null then 1 else 0 end as isOwner
|
|
from sys_user u
|
|
left join biz_person p on p.user_id = u.user_id and p.unit_type = 'sponsor'
|
|
left join biz_org own on own.user_id = u.user_id and own.org_type = 'sponsor' and own.del_flag = '0'
|
|
left join biz_org o on o.org_id = COALESCE(own.org_id, p.org_id)
|
|
where u.user_id = #{userId}
|
|
and o.del_flag = '0'
|
|
limit 1
|
|
</select>
|
|
|
|
<!--
|
|
user_id → org_id 单一可信源反查:
|
|
MAIN 主账号: biz_org.user_id = #{userId} (企业表直接关联主账号)
|
|
SUB 子账号: biz_person.org_id (person 表 user_id = #{userId} 反查企业)
|
|
COALESCE 二选一, 都没有返回 NULL
|
|
-->
|
|
<select id="selectOrgIdByUserId" parameterType="Long" resultType="Long">
|
|
select coalesce(
|
|
(select org_id from biz_org where user_id = #{userId} and del_flag = '0' limit 1),
|
|
(select org_id from biz_person where user_id = #{userId} limit 1)
|
|
)
|
|
</select>
|
|
|
|
<!-- 单位名称查重 (新增/改名前): 同 orgType 下 org_name 精确匹配 (trim 后) 的条数; orgId 传非空则排除自身 (改名用) -->
|
|
<select id="countByOrgName" parameterType="BizOrg" resultType="int">
|
|
select count(*) from biz_org
|
|
where org_type = #{orgType}
|
|
and del_flag = '0'
|
|
and trim(org_name) = #{orgName}
|
|
<if test="orgId != null"> and org_id != #{orgId}</if>
|
|
</select>
|
|
|
|
<!-- 供应商同步 org 去重: 按税号精确定位 (org_type='executor' 且税号非空), 取 org_id 最小的一条 -->
|
|
<select id="selectByTaxNo" parameterType="BizOrg" resultMap="BizOrgResult">
|
|
<include refid="selectFields"/>
|
|
where org_type = 'executor'
|
|
and del_flag = '0'
|
|
and tax_no = #{taxNo}
|
|
order by org_id asc
|
|
limit 1
|
|
</select>
|
|
|
|
<!-- 供应商同步 org 去重兜底: 税号缺失时按企业名精确定位 (org_type='executor'), 取 org_id 最小的一条 -->
|
|
<select id="selectByNameAndType" parameterType="BizOrg" resultMap="BizOrgResult">
|
|
<include refid="selectFields"/>
|
|
where org_type = 'executor'
|
|
and del_flag = '0'
|
|
and trim(org_name) = #{orgName}
|
|
order by org_id asc
|
|
limit 1
|
|
</select>
|
|
</mapper>
|