给用户和租户的相关查询sql进行优化

This commit is contained in:
jishenghua 2024-12-09 00:37:31 +08:00
parent 411effc0a7
commit 328844c646
5 changed files with 22 additions and 14 deletions

View File

@ -59,6 +59,7 @@ public class TenantService {
public List<Tenant> getTenant()throws Exception {
TenantExample example = new TenantExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Tenant> list=null;
try{
list=tenantMapper.selectByExample(example);
@ -162,7 +163,7 @@ public class TenantService {
public int checkIsNameExist(Long id, String name)throws Exception {
TenantExample example = new TenantExample();
example.createCriteria().andIdNotEqualTo(id).andLoginNameEqualTo(name);
example.createCriteria().andIdNotEqualTo(id).andLoginNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Tenant> list=null;
try{
list= tenantMapper.selectByExample(example);
@ -175,7 +176,7 @@ public class TenantService {
public Tenant getTenantByTenantId(long tenantId) {
Tenant tenant = new Tenant();
TenantExample example = new TenantExample();
example.createCriteria().andTenantIdEqualTo(tenantId);
example.createCriteria().andTenantIdEqualTo(tenantId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Tenant> list = tenantMapper.selectByExample(example);
if(list.size()>0) {
tenant = list.get(0);

View File

@ -15,7 +15,7 @@
left join jsh_account_item ai on ah.id=ai.header_id and ifnull(ai.delete_flag,'0') !='1'
left join jsh_depot_head dh on dh.id=ai.bill_id and ifnull(dh.delete_flag,'0') !='1'
left join jsh_supplier s on ah.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
left join jsh_user u on ah.creator=u.id and ifnull(u.Status,'0') !='1'
left join jsh_user u on ah.creator=u.id and ifnull(u.delete_flag,'0') !='1'
left join jsh_person p on ah.hands_person_id=p.id and ifnull(p.delete_Flag,'0') !='1'
left join jsh_account a on ah.account_id=a.id and ifnull(a.delete_Flag,'0') !='1'
where 1=1

View File

@ -1163,7 +1163,7 @@
select distinct dh.*, s.supplier OrganName, u.username userName
from jsh_depot_head dh
left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
left join jsh_user u on dh.creator=u.id and ifnull(u.Status,'0') !='1'
left join jsh_user u on dh.creator=u.id and and ifnull(u.delete_flag,'0') !='1'
left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
where 1=1
@ -1217,7 +1217,7 @@
select distinct dh.*, s.supplier OrganName, u.username userName
from jsh_depot_head dh
left join jsh_supplier s on dh.organ_id=s.id and ifnull(s.delete_Flag,'0') !='1'
left join jsh_user u on dh.creator=u.id and ifnull(u.Status,'0') !='1'
left join jsh_user u on dh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
left join jsh_depot_item di on dh.id = di.header_id and ifnull(di.delete_flag,'0') !='1'
left join jsh_material m on di.material_id = m.id and ifnull(m.delete_flag,'0') !='1'
where 1=1
@ -1361,7 +1361,7 @@
</if>) tb
left join jsh_depot_head jdh on jdh.id=tb.id and ifnull(jdh.delete_flag,'0') !='1'
left join jsh_supplier s on jdh.organ_id=s.id and ifnull(s.delete_flag,'0') !='1'
left join jsh_user u on jdh.creator=u.id and ifnull(u.Status,'0') !='1'
left join jsh_user u on jdh.creator=u.id and ifnull(u.delete_flag,'0') !='1'
left join jsh_account a on jdh.account_id=a.id and ifnull(a.delete_flag,'0') !='1'
</select>

View File

@ -25,6 +25,7 @@
<bind name="bindRemark" value="'%'+remark+'%'"/>
and remark like #{bindRemark}
</if>
and ifnull(delete_flag,'0') !='1'
order by id desc
<if test="offset != null and rows != null">
limit #{offset},#{rows}
@ -49,5 +50,6 @@
<bind name="bindRemark" value="'%'+remark+'%'"/>
and remark like #{bindRemark}
</if>
and ifnull(delete_flag,'0') !='1'
</select>
</mapper>

View File

@ -26,7 +26,7 @@
left join jsh_orga_user_rel rel on user.id=rel.user_id and ifnull(rel.delete_flag,'0') !='1'
left join jsh_organization org on rel.orga_id=org.id and ifnull(org.delete_flag,'0') !='1'
where 1=1
and user.status !='1'
and ifnull(user.delete_flag,'0') !='1'
<if test="userName != null">
<bind name="bindUserName" value="'%'+userName+'%'"/>
and user.username like #{bindUserName}
@ -45,7 +45,7 @@
select count(user.id)
FROM jsh_user user
where 1=1
and user.status !='1'
and ifnull(user.delete_flag,'0') !='1'
<if test="userName != null">
<bind name="bindUserName" value="'%'+userName+'%'"/>
and user.username like #{bindUserName}
@ -60,7 +60,8 @@
user.description, user.remark,user.isystem
FROM jsh_user user
where 1=1
and ifnull(user.status,'0') not in('1','2')
and user.status = 0
and ifnull(user.delete_flag,'0') !='1'
<if test="userName != null and userName != ''">
and user.userName = #{userName}
</if>
@ -118,7 +119,8 @@
and user.id=rel.user_id
and rel.orga_id=#{orgId}
and ifnull(rel.delete_flag,'0') !='1'
and ifnull(user.status,'0') not in('1','2')
and user.status = 0
and ifnull(user.delete_flag,'0') !='1'
) node
order by sort asc
</select>
@ -133,14 +135,15 @@
</select>
<update id="disableUserByLimit">
update jsh_user set Status='2'
where tenant_id=#{tenantId} and id!=#{tenantId} and Status!='1'
update jsh_user set status='2'
where tenant_id=#{tenantId} and id!=#{tenantId}
</update>
<select id="getListByOrgaId" resultType="com.jsh.erp.datasource.entities.User">
select u.*,our.orga_id from jsh_user u
left join jsh_orga_user_rel our on u.id=our.user_id
where u.leader_flag='1' and orga_id= #{orgaId}
and ifnull(u.delete_flag,'0') !='1'
<if test="id != null">
and u.id != #{id}
</if>
@ -149,12 +152,14 @@
<select id="getUserByWeixinOpenId" resultType="com.jsh.erp.datasource.entities.User">
select u.* from jsh_user u
where u.weixin_open_id = #{weixinOpenId}
and ifnull(u.status,'0') not in('1','2')
and u.status=0
and ifnull(u.delete_flag,'0') !='1'
</select>
<update id="updateUserWithWeixinOpenId">
update jsh_user u set u.weixin_open_id = #{weixinOpenId}
where u.login_name = #{loginName} and u.password = #{password}
and ifnull(u.status,'0') not in('1','2')
and u.status=0
and ifnull(u.delete_flag,'0') !='1'
</update>
</mapper>