[fix]optimize getBDSaleList

master
hellolujian 6 years ago
parent 2baadc3bd8
commit eed0365d5b

@ -3,39 +3,70 @@
<mapper namespace="au.com.royalpay.payment.manage.analysis.mappers.BDAnalysisMapper">
<select id="getBDSaleList" resultType="com.alibaba.fastjson.JSONObject">
SELECT
d.bd_name,d.bd_id,sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,-temp.clearing_amount*d.proportion))
total,
ifnull(sum(if(temp.refund_id is not null,if(temp.transaction_type='Debit',temp.clearing_amount,-temp.clearing_amount)*d.proportion,0)),0) refund_fee
FROM
(SELECT l.client_id,l.clearing_amount,l.refund_id,l.transaction_type,o.create_time FROM pmt_transactions l
INNER JOIN pmt_orders o
ON o.order_id = l.order_id
<if test="begin!=null">and o.create_time &gt;= #{begin}</if>
<if test="end!=null">and o.create_time &lt; #{end}</if>
<if test="begin_month">and DATE_FORMAT(o.create_time,'%Y-%m') &gt;=#{begin_month}</if>
<if test="end_month">and DATE_FORMAT(o.create_time,'%Y-%m') &lt;= #{end_month}</if>
where (l.transaction_type='Credit' or l.refund_id is not null)
d.bd_name,
d.bd_id,
SUM(if(temp.transaction_type = 'Credit', temp.clearing_amount * d.proportion, -temp.clearing_amount * d.proportion)) total,
ifnull(SUM(if(temp.refund_id IS NOT NULL, if(temp.transaction_type='Debit', temp.clearing_amount, -temp.clearing_amount) * d.proportion, 0)), 0) refund_fee
FROM(
SELECT
l.client_id,
l.clearing_amount,
l.refund_id,
l.transaction_type,
o.create_time
FROM pmt_transactions l
INNER JOIN pmt_orders o
ON o.order_id = l.order_id
<if test="begin != null">
AND o.create_time &gt;= #{begin}
</if>
<if test="end != null">
AND o.create_time &lt; #{end}
</if>
<if test="begin_month">
AND DATE_FORMAT(o.create_time, '%Y-%m') &gt;= #{begin_month}
</if>
<if test="end_month">
AND DATE_FORMAT(o.create_time, '%Y-%m') &lt;= #{end_month}
</if>
WHERE (l.transaction_type = 'Credit' OR l.refund_id IS NOT NULL)
) temp
INNER JOIN sys_client_bd d ON temp.client_id = d.client_id AND d.start_date &lt;= temp.create_time and
d.is_valid = '1'
AND (d.end_date is null or d.end_date > temp.create_time)
<if test="org_id!=null and org_ids==null">
INNER JOIN sys_managers m on m.manager_id = d.bd_id and m.org_id = #{org_id}
INNER JOIN sys_client_bd d
ON temp.client_id = d.client_id
AND d.start_date &lt;= temp.create_time
AND d.is_valid = '1'
AND (d.end_date IS NULL OR d.end_date > temp.create_time)
<if test="org_id != null and org_ids == null">
INNER JOIN sys_managers m
ON m.manager_id = d.bd_id
AND m.org_id = #{org_id}
</if>
<if test="org_ids!=null">
INNER JOIN sys_managers m on m.manager_id = d.bd_id and m.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
<if test="bd_group!=null">and temp.client_id in
(SELECT b.client_id FROM sys_client_bd b
INNER JOIN financial_bd_config c ON c.manager_id=b.bd_id
where b.is_valid=1 and b.start_date&lt;=now() and (b.end_date is null or b.end_date &gt;= now())
AND (c.bd_group=#{bd_group} or c.manager_id=#{bd_group})
<if test="bd_group_bd">and c.manager_id=#{bd_group_bd}</if>
<if test="org_ids != null">
INNER JOIN sys_managers m
ON m.manager_id = d.bd_id
AND m.org_id IN
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">
#{org_id}
</foreach></if>
<if test="bd_group != null">
AND temp.client_id IN(
SELECT b.client_id
FROM sys_client_bd b
INNER JOIN financial_bd_config c
ON c.manager_id = b.bd_id
WHERE b.is_valid = 1
AND b.start_date &lt;= now()
AND (b.end_date IS NULL OR b.end_date &gt;= now())
AND (c.bd_group = #{bd_group} OR c.manager_id = #{bd_group})
<if test="bd_group_bd">
AND c.manager_id = #{bd_group_bd}
</if>
)
</if>
GROUP BY d.bd_id
ORDER BY total DESC
</select>
<select id="getBDSalePartnerList" resultType="com.alibaba.fastjson.JSONObject">
SELECT
c.client_id,c.client_moniker,c.short_name,c.approve_time,IFNULL(sum(if(temp.transaction_type='Credit',temp.clearing_amount*d.proportion,-temp.clearing_amount*d.proportion)),0)

Loading…
Cancel
Save