From 8ffe22beae76001d360585fbe8b2bf515a534a34 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 23 二月 2024 18:37:31 +0800
Subject: [PATCH] 优化报表查询慢问题
---
java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml | 508 ++++++++++++++++++-------------------------------------
1 files changed, 168 insertions(+), 340 deletions(-)
diff --git a/java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml b/java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml
index 0f0ed16..cbbc791 100644
--- a/java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml
+++ b/java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml
@@ -318,43 +318,43 @@
<select id="getFeeRoomCount" parameterType="Map" resultType="Map">
select count(1) feeRoomCount
from (
- select t.payer_obj_id
- from report_owe_fee t
- inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- <if test="feeTypeCd != null and feeTypeCd != ''">
- left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
- </if>
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and t.end_time < #{endDate}
- <if test="floorId != null and floorId != ''">
- and bu.floor_id = #{floorId}
- </if>
- <if test="configId != null and configId != ''">
- and t.config_id = #{configId}
- </if>
- <if test="objName != null and objName != ''">
- and t.payer_obj_name like concat('%',#{objName},'%')
- </if>
- <if test="ownerName != null and ownerName != ''">
- and t.owner_name like concat('%',#{ownerName},'%')
- </if>
- <if test="link != null and link != ''">
- and t.owner_tel = #{link}
- </if>
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and pfc.fee_type_cd = #{feeTypeCd}
- </if>
- group by t.payer_obj_id
+ select t.payer_obj_id
+ from report_owe_fee t
+ inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ <if test="feeTypeCd != null and feeTypeCd != ''">
+ left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
+ </if>
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and t.end_time < #{endDate}
+ <if test="floorId != null and floorId != ''">
+ and bu.floor_id = #{floorId}
+ </if>
+ <if test="configId != null and configId != ''">
+ and t.config_id = #{configId}
+ </if>
+ <if test="objName != null and objName != ''">
+ and t.payer_obj_name like concat('%',#{objName},'%')
+ </if>
+ <if test="ownerName != null and ownerName != ''">
+ and t.owner_name like concat('%',#{ownerName},'%')
+ </if>
+ <if test="link != null and link != ''">
+ and t.owner_tel = #{link}
+ </if>
+ <if test="configIds !=null ">
+ and t.config_id in
+ <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+ #{item}
+ </foreach>
+ </if>
+ <if test="feeTypeCd != null and feeTypeCd != ''">
+ and pfc.fee_type_cd = #{feeTypeCd}
+ </if>
+ group by t.payer_obj_id
) a
</select>
@@ -363,73 +363,47 @@
select a.floor_id floorId,a.floor_num floorNum,a.name floorName,
(
select count(1) from (
- select bu.floor_id,t.payer_obj_id
- from report_owe_fee t
- inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- <if test="feeTypeCd != null and feeTypeCd != ''">
- left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
- </if>
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and t.end_time <= #{endDate}
- and t.amount_owed != 0
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and pfc.fee_type_cd = #{feeTypeCd}
- </if>
- group by bu.floor_id,t.payer_obj_id
+ select bu.floor_id,t.payer_obj_id
+ from report_owe_fee t
+ inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ <if test="feeTypeCd != null and feeTypeCd != ''">
+ left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
+ </if>
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and t.end_time <= #{endDate}
+ and t.amount_owed != 0
+ <if test="configIds !=null ">
+ and t.config_id in
+ <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+ #{item}
+ </foreach>
+ </if>
+ <if test="feeTypeCd != null and feeTypeCd != ''">
+ and pfc.fee_type_cd = #{feeTypeCd}
+ </if>
+ group by bu.floor_id,t.payer_obj_id
) b
where b.floor_id = a.floor_id
) oweRoomCount,
(
select count(1) from (
- select bu.floor_id,t.payer_obj_id
- from report_owe_fee t
- inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
+ select bu.floor_id,t.payer_obj_id
+ from report_owe_fee t
+ inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and pf.community_id= #{communityId}
- and t.end_time <= #{endDate}
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and pf.fee_type_cd = #{feeTypeCd}
- </if>
- group by bu.floor_id,t.payer_obj_id
- ) b
- where b.floor_id = a.floor_id
- ) feeRoomCount,
- (
- select ifnull(sum(t.received_amount),0.0) receivedFee
- from pay_fee_detail t
- INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
- LEFT JOIN building_room br on pf.payer_obj_id = br.room_id and br.status_cd = '0'
left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
where
1=1
- and bu.floor_id = a.floor_id
- and t.status_cd = '0'
- and t.community_id= a.community_id
- and t.create_time > #{startDate}
- and t.create_time < #{endDate}
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and pf.community_id= #{communityId}
+ and t.end_time <= #{endDate}
<if test="configIds !=null ">
- and pf.config_id in
+ and t.config_id in
<foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
@@ -437,48 +411,10 @@
<if test="feeTypeCd != null and feeTypeCd != ''">
and pf.fee_type_cd = #{feeTypeCd}
</if>
- ) receivedFee,
- (
- select ifnull(sum(t.received_amount),0.0) preReceivedFee
- from pay_fee_detail_month t
- where
- 1=1
- and t.obj_fpc_id = a.floor_id
- and t.status_cd = '0'
- and t.community_id= a.community_id
- and t.pay_fee_time > #{startDate}
- and t.pay_fee_time < #{endDate}
- and t.cur_month_time >= #{endDate}
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and t.fee_type_cd = #{feeTypeCd}
- </if>
- ) preReceivedFee,
- (
- select ifnull(sum(t.receivable_amount),0.0) hisOweFee
- from pay_fee_detail_month t
- where
- 1=1
- and t.obj_fpc_id = a.floor_id
- and t.status_cd = '0'
- and t.community_id= a.community_id
- and t.detail_id = '-1'
- and t.cur_month_time < #{startDate}
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and t.fee_type_cd = #{feeTypeCd}
- </if>
- ) hisOweFee,
+ group by bu.floor_id,t.payer_obj_id
+ ) b
+ where b.floor_id = a.floor_id
+ ) feeRoomCount,
(
select ifnull(sum(t.receivable_amount),0.0) curReceivableFee
from pay_fee_detail_month t
@@ -519,18 +455,51 @@
<if test="feeTypeCd != null and feeTypeCd != ''">
and t.fee_type_cd = #{feeTypeCd}
</if>
- ) curReceivedFee,
+ ) curReceivedFee
+ from f_floor a
+ where 1=1
+ and a.status_cd = '0'
+ and a.community_id = #{communityId}
+ <if test="floorId != null and floorId != ''">
+ and a.floor_id = #{floorId}
+ </if>
+ order by a.seq
+ </select>
+
+ <select id="getConfigFeeSummary" parameterType="Map" resultType="Map">
+ select a.name,
(
- select ifnull(sum(t.received_amount),0.0) hisReceivedFee
- from pay_fee_detail_month t
+ select ifnull(sum(t.receivable_amount),0.0) curReceivableFee
+ from pay_fee_detail_month t force index(i_fc)
where
1=1
- and t.obj_fpc_id = a.floor_id
+ <if test="floorId != null and floorId != ''">
+ and t.obj_fpc_id = #{floorId}
+ </if>
and t.status_cd = '0'
- and t.community_id= a.community_id
- and t.pay_fee_time > #{startDate}
- and t.pay_fee_time < #{endDate}
- and t.cur_month_time < #{startDate}
+ and t.community_id= #{communityId}
+ and t.cur_month_time >= #{startDate}
+ and t.cur_month_time < #{endDate}
+ <if test="configIds !=null ">
+ and t.config_id in
+ <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+ #{item}
+ </foreach>
+ </if>
+ and t.fee_type_cd = a.status_cd
+ ) curReceivableFee,
+ (
+ select ifnull(sum(t.receivable_amount),0.0) curReceivedFee
+ from pay_fee_detail_month t force index(i_fc)
+ where
+ 1=1
+ <if test="floorId != null and floorId != ''">
+ and t.obj_fpc_id = #{floorId}
+ </if>
+ and t.status_cd = '0'
+ and t.community_id= #{communityId}
+ and t.cur_month_time >= #{startDate}
+ and t.cur_month_time < #{endDate}
and t.detail_id != '-1'
<if test="configIds !=null ">
and t.config_id in
@@ -538,42 +507,31 @@
#{item}
</foreach>
</if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and t.fee_type_cd = #{feeTypeCd}
- </if>
- ) hisReceivedFee
- from f_floor a
- where 1=1
- and a.status_cd = '0'
- and a.community_id = #{communityId}
- order by a.seq
- </select>
-
- <select id="getConfigFeeSummary" parameterType="Map" resultType="Map">
- select a.name,
+ and t.fee_type_cd = a.status_cd
+ ) curReceivedFee,
(
select count(1) from (
- select pfc.fee_type_cd,t.payer_obj_id
- from report_owe_fee t
+ select pfc.fee_type_cd,t.payer_obj_id
+ from report_owe_fee t
inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and t.end_time <= #{endDate}
- and t.amount_owed != 0
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="feeTypeCd != null and feeTypeCd != ''">
- and pfc.fee_type_cd = #{feeTypeCd}
- </if>
- group by pfc.fee_type_cd,t.payer_obj_id
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and t.end_time <= #{endDate}
+ and t.amount_owed != 0
+ <if test="configIds !=null ">
+ and t.config_id in
+ <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+ #{item}
+ </foreach>
+ </if>
+ <if test="feeTypeCd != null and feeTypeCd != ''">
+ and pfc.fee_type_cd = #{feeTypeCd}
+ </if>
+ group by pfc.fee_type_cd,t.payer_obj_id
) b
where b.fee_type_cd = a.status_cd
) oweRoomCount,
@@ -602,137 +560,7 @@
group by pf.fee_type_cd,t.payer_obj_id
) b
where b.fee_type_cd = a.status_cd
- ) feeRoomCount,
- (
- select ifnull(sum(t.received_amount),0.0) receivedFee
- from pay_fee_detail t
- INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
- <if test="floorId != null and floorId != ''">
- LEFT JOIN building_room br on pf.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- </if>
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and bu.floor_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.create_time > #{startDate}
- and t.create_time < #{endDate}
- <if test="configIds !=null ">
- and pf.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and pf.fee_type_cd = a.status_cd
- ) receivedFee,
- (
- select ifnull(sum(t.received_amount),0.0) preReceivedFee
- from pay_fee_detail_month t
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and t.obj_fpc_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.pay_fee_time > #{startDate}
- and t.pay_fee_time < #{endDate}
- and t.cur_month_time >= #{endDate}
- and t.detail_id != '-1'
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and t.fee_type_cd = a.status_cd
- ) preReceivedFee,
- (
- select ifnull(sum(t.receivable_amount),0.0) hisOweFee
- from pay_fee_detail_month t
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and t.obj_fpc_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.detail_id = '-1'
- and t.cur_month_time < #{startDate}
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and t.fee_type_cd = a.status_cd
- ) hisOweFee,
- (
- select ifnull(sum(t.receivable_amount),0.0) curReceivableFee
- from pay_fee_detail_month t
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and t.obj_fpc_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.cur_month_time >= #{startDate}
- and t.cur_month_time < #{endDate}
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and t.fee_type_cd = a.status_cd
- ) curReceivableFee,
- (
- select ifnull(sum(t.receivable_amount),0.0) curReceivedFee
- from pay_fee_detail_month t
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and t.obj_fpc_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.cur_month_time >= #{startDate}
- and t.cur_month_time < #{endDate}
- and t.detail_id != '-1'
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and t.fee_type_cd = a.status_cd
- ) curReceivedFee,
- (
- select ifnull(sum(t.received_amount),0.0) hisReceivedFee
- from pay_fee_detail_month t
- where
- 1=1
- <if test="floorId != null and floorId != ''">
- and t.obj_fpc_id = #{floorId}
- </if>
- and t.status_cd = '0'
- and t.community_id= #{communityId}
- and t.pay_fee_time > #{startDate}
- and t.pay_fee_time < #{endDate}
- and t.cur_month_time < #{startDate}
- and t.detail_id != '-1'
- <if test="configIds !=null ">
- and t.config_id in
- <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and t.fee_type_cd = a.status_cd
- ) hisReceivedFee
+ ) feeRoomCount
from t_dict a
where 1=1
and a.table_name = 'pay_fee_config'
@@ -743,17 +571,17 @@
select count(1) feeRoomCount
from
(
- select t.payer_ob_id
- from report_owe_fee t
- inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
+ select t.payer_ob_id
+ from report_owe_fee t
+ inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and pf.community_id= #{communityId}
- group by a.payer_ob_id
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and pf.community_id= #{communityId}
+ group by a.payer_ob_id
) b
</select>
<!-- 鏌ヨ鎴垮眿璐圭敤鏄庣粏琛�-->
@@ -1013,35 +841,35 @@
) roomCount,
(
select count(1) from (
- select bu.floor_id,br.room_id
- from report_owe_fee t
- inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
+ select bu.floor_id,br.room_id
+ from report_owe_fee t
+ inner join pay_fee pf on pf.fee_id = t.fee_id and pf.status_cd = '0' and pf.state = '2008001'
inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
and pf.community_id= #{communityId}
- and t.end_time < #{endDate}
- group by bu.floor_id,br.room_id
+ and t.end_time < #{endDate}
+ group by bu.floor_id,br.room_id
) b
where b.floor_id = a.floor_id
) feeRoomCount,
(
select count(1) from (
- select bu.floor_id,br.room_id
- from report_owe_fee t
+ select bu.floor_id,br.room_id
+ from report_owe_fee t
inner join building_room br on t.payer_obj_id = br.room_id and br.status_cd = '0'
- left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
- left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
- where
- 1=1
- and t.payer_obj_type = '3333'
- and t.community_id= #{communityId}
- and t.end_time < #{endDate}
- and t.amount_owed != 0
- group by bu.floor_id,br.room_id
+ left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+ left join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
+ where
+ 1=1
+ and t.payer_obj_type = '3333'
+ and t.community_id= #{communityId}
+ and t.end_time < #{endDate}
+ and t.amount_owed != 0
+ group by bu.floor_id,br.room_id
) b
where b.floor_id = a.floor_id
) oweRoomCount,
@@ -1159,7 +987,7 @@
LEFT JOIN building_room br on pf.payer_obj_id = br.room_id and br.status_cd = '0'
left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
where 1=1
- and bu.floor_id = #{floorId}
+ and bu.floor_id = #{floorId}
and t.community_id = #{communityId}
and pf.community_id= #{communityId}
and t.pay_fee_time > #{startDate}
--
Gitblit v1.8.0