optimise settle log sql

master
Yixian 3 years ago
parent 9497cf2559
commit 22c0f5c2d4

@ -713,17 +713,14 @@
<select id="listSettlementLogInClients" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT c.short_name,SUM(t.clearing_amount) total,
sum(if(LOCATE('MERCHANT',t.system_transaction_id),t.clearing_amount,0)) income,
sum(if(LOCATE('SURCHARGE',t.system_transaction_id),t.clearing_amount,0)) fee
SELECT c.short_name,SUM(cd.gross_amount) total,
sum(cd.clearing_amount) income,
sum(cd.total_charge+cd.tax_amount) fee
FROM sys_clients c
]]>
INNER JOIN (select system_transaction_id,clearing_amount,client_id
from pmt_transactions
where channel='Settlement'
<if test="from!=null">and transaction_time &gt;= #{from}</if>
<if test="to!=null">and transaction_time &lt; #{to}</if>
) t ON t.client_id = c.client_id
INNER JOIN log_clearing_detail cd on c.client_id=cd.client_id
<if test="from!=null">and cd.report_date &gt;= #{from}</if>
<if test="to!=null">and cd.report_date &lt; #{to}</if>
<where>
<if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if>
<if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if>
@ -735,8 +732,9 @@
</select>
<select id="countSettlementLogInClients" resultType="int">
<![CDATA[
SELECT count(1)
FROM sys_clients c
SELECT count(cd.clear_detail_id)
from log_clearing_detail
inner join sys_clients c on c.client_id=cd.client_id
]]>
<where>
<if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if>
@ -744,13 +742,9 @@
<if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
and exists (select client_id from pmt_transactions t where channel='Settlement'
<if test="from!=null">and transaction_time &gt;= #{from}</if>
<if test="to!=null">and transaction_time &lt; #{to}</if>
and client_id=c.client_id
)
<if test="from!=null">and cd.report_date &gt;= #{from}</if>
<if test="to!=null">and cd.report_date &lt; #{to}</if>
</where>
exists
</select>
<select id="analysisSettlementLog" resultType="com.alibaba.fastjson.JSONObject">

Loading…
Cancel
Save