解决租户管理查询慢的问题

This commit is contained in:
jishenghua 2024-12-31 23:58:57 +08:00
parent a0ea3a8b7e
commit 1d0cb1d904

View File

@ -9,18 +9,23 @@
</resultMap>
<select id="selectByConditionTenant" parameterType="com.jsh.erp.datasource.entities.TenantExample" resultMap="ResultMapEx">
select t.*, r.id roleId, r.name roleName,
select t.*,
(select r.id from jsh_user_business ub
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole' and ub.key_id=t.tenant_id limit 0,1) roleId,
(select r.name from jsh_user_business ub
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole' and ub.key_id=t.tenant_id limit 0,1) roleName,
(select count(jsh_user.id) from jsh_user where jsh_user.status='0' and jsh_user.delete_flag=0 and jsh_user.tenant_id=t.tenant_id) userCount
from jsh_tenant t
left join jsh_user_business ub on ub.key_id = t.tenant_id and ifnull(ub.delete_flag,'0') !='1'
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole'
<if test="loginName != null">
<bind name="bindLoginName" value="'%'+loginName+'%'"/>
and t.login_name like #{bindLoginName}
</if>
<if test="roleId != null and roleId != ''">
and r.id = #{roleId}
and ub.value = concat("[",#{roleId},"]")
</if>
<if test="type != null and type != ''">
and t.type = #{type}
@ -44,14 +49,13 @@
count(t.id)
from jsh_tenant t
left join jsh_user_business ub on ub.key_id = t.tenant_id and ifnull(ub.delete_flag,'0') !='1'
left join jsh_role r on ub.value=concat("[",r.id,"]") and ifnull(r.delete_flag,'0') !='1'
where ub.type='UserRole'
<if test="loginName != null">
<bind name="bindLoginName" value="'%'+loginName+'%'"/>
and t.login_name like #{bindLoginName}
</if>
<if test="roleId != null and roleId != ''">
and r.id = #{roleId}
and ub.value = concat("[",#{roleId},"]")
</if>
<if test="type != null and type != ''">
and t.type = #{type}