Incremental 列表查询优化

master
dalong306 3 years ago
parent cf402d4e9b
commit a2d9cdb739

@ -32,6 +32,8 @@ public interface OrderMapper {
PageList<JSONObject> listIncrementalOrders(JSONObject params, PageBounds pagination);
PageList<JSONObject> listIncrementalOrdersNew(JSONObject params, PageBounds pagination);
List<JSONObject> listOrdersNoPage(JSONObject params);
PageList<JSONObject> listOrdersByClients(JSONObject params, PageBounds pagination);

@ -33,6 +33,7 @@ import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
@ -211,6 +212,12 @@ public class TradeLogServiceImpl implements TradeLogService {
add(query.getGatewayChild());
}});
}
JSONArray clientIds = clientManager.getAllClientIds(client.getIntValue("client_id"));
logger.info("====>clientIds:{}",clientIds.size());
if (clientIds.size() > 1) {
String[] arr = new String[clientIds.size()];
params.put("client_ids", clientIds.toArray(arr));
}
PageList<JSONObject> logs = orderMapper.listIncrementalOrdersByClients(params,
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
if (timezone != null) {

@ -38,6 +38,41 @@
t.tax_amount,
t.surcharge_rate
</sql>
<sql id="tradelog_list_keys_2">
SELECT
o.order_id,
o.client_id,
o.total_amount,
o.display_amount,
o.customer_payment_amount,
o.coupon_payment_amount,
o.currency,
o.create_time,
o.confirm_time,
o.status,
o.order_description,
o.order_detail,
o.client_order_id,
o.gateway,
o.channel,
o.pay_type,
o.pre_authorization,
o.refund_amount refund_fee,
o.customer_id,
o.source,
sum(t.clearing_amount) clearing_amount,
t.refund_id,
t.transaction_time,
t.transaction_type,
t.transaction_id,
t.exchange_rate,
t.clearing_status,
t.settle_amount,
t.incremental_surcharge,
t.total_surcharge,
t.tax_amount,
t.surcharge_rate
</sql>
<sql id="gateway_keys">
SELECT
o.order_id order_id,
@ -107,6 +142,73 @@
t.settle_amount,
t.transaction_time
</sql>
<sql id="gateway_keys_2">
SELECT
o.order_id order_id,
format(o.total_amount * 100, 0) total_fee,
format(o.customer_payment_amount * 100, 0) real_fee,
o.currency,
o.channel,
o.create_time,
o.confirm_time pay_time,
o.pre_authorization,
o.source,
o.pay_type,
CASE o.status
WHEN 0
THEN 'SUBMITTING'
WHEN 1
THEN 'SUBMIT_FAIL'
WHEN 2
THEN 'WAITING_PAYMENT'
WHEN 3
THEN 'CLOSED'
WHEN 4
THEN 'PAYMENT_FAIL'
WHEN 5
THEN 'SUCCESS'
WHEN 6
THEN 'PARTIAL_REFUND'
WHEN 7
THEN 'FULL_REFUND'
END AS `status`,
o.order_description order_body,
o.client_order_id partner_order_id,
CASE o.gateway
WHEN 0
THEN 'Retail In-Store'
WHEN 1
THEN 'Retail In-Store'
WHEN 2
THEN 'QR Code'
WHEN 3
THEN 'Online API'
WHEN 4
THEN 'In-APP H5'
WHEN 5
THEN 'Retail API'
WHEN 6
THEN 'Retail API'
WHEN 7
THEN 'QR Code'
WHEN 8
THEN 'Mobile H5'
WHEN 9
THEN 'Third Party Gateway'
WHEN 10
THEN 'APP'
WHEN 12
THEN 'MICROAPP'
WHEN 13
THEN 'Native QR Code'
WHEN 14
THEN 'Share Link'
END AS gateway,
format(o.refund_amount * 100, 0) refund_fee,
t.clearing_status,
t.settle_amount,
t.transaction_time
</sql>
<update id="updateRefundAmount">
<![CDATA[
@ -439,6 +541,96 @@
</select>
<select id="listIncrementalOrdersNew" resultType="com.alibaba.fastjson.JSONObject">
<if test="gateway">
<include refid="gateway_keys_2"/>
</if>
<if test="!gateway">
<include refid="tradelog_list_keys_2"/>
</if>
,ifnull(sci.incremental_rate_value,0) as rate_value
FROM (
select oo.order_id,oo.client_id,oo.total_amount,oo.display_amount,
oo.customer_payment_amount,oo.coupon_payment_amount,oo.currency,
oo.create_time,oo.confirm_time,oo.status,oo.order_description,oo.order_detail,
oo.client_order_id,oo.gateway,oo.channel,oo.pre_authorization,oo.refund_amount,oo.customer_id,oo.source,oo.pay_type
from pmt_orders oo
<where>
<if test="search_text != null">
<bind name="name_pattern" value="'%' + search_text + '%'"/>
<if test="text_type == 'remark'">
AND oo.order_detail LIKE #{name_pattern}
</if>
<if test="text_type == 'channel'">
AND oo.channel = #{search_text}
</if>
<if test="text_type == 'order_id'">
AND oo.order_id = #{search_text}
</if>
</if>
<if test="order_id != null">
AND oo.order_id = #{order_id}
</if>
<if test="trade_type != null">
AND oo.gateway IN
<foreach collection="trade_type" item="gateway" open="(" close=")" separator=",">
#{gateway}
</foreach>
</if>
<if test="from != null">
AND oo.create_time &gt;= #{from}
</if>
<if test="to != null">
AND oo.create_time &lt; #{to}
</if>
<if test="date != null">
AND oo.transaction_date = DATE(#{date})
</if>
<if test="dev_id != null">
AND oo.dev_id = #{dev_id}
</if>
<if test="status != null">
AND
<foreach collection="status" item="std" open="(" close=")" separator=" or ">
oo.status = #{std}
</foreach>
</if>
<if test="channel != null">
AND
<foreach collection="channel" item="chan" open="(" close=")" separator=" or ">
oo.channel = #{chan}
</foreach>
</if>
<if test="source != 'ALL'">
AND
oo.source = #{source}
</if>
</where>
) o
INNER JOIN pmt_transactions t
ON t.order_id = o.order_id
AND t.refund_id IS NULL
AND t.transaction_type = 'Credit'
LEFT JOIN sys_client_incremental sci on sci.client_id = o.client_id
<if test="client_ids != null">
AND o.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids == null and client_id != null">
AND o.client_id = #{client_id}
</if>
<where>
<if test="onlyIncrementAmount != null">
t.incremental_surcharge >0
</if>
</where>
GROUP BY o.order_id
</select>
<select id="listOrdersNoPage" resultType="com.alibaba.fastjson.JSONObject">
<if test="gateway">
<include refid="gateway_keys"/>
@ -551,21 +743,14 @@
<select id="listIncrementalOrdersByClients" resultType="com.alibaba.fastjson.JSONObject">
<include refid="tradelog_list_keys"/>
<include refid="tradelog_list_keys_2"/>
,ifnull(i.incremental_rate,0.00) as rate_value
FROM pmt_orders o
INNER JOIN sys_clients p ON p.client_id=o.client_id and p.is_valid=1
<if test="client_ids!=null">
AND p.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id !=null">
and (p.client_id=#{client_id} or p.parent_client_id=#{client_id})
</if>
LEFT JOIN pmt_transactions t on t.order_id=o.order_id and t.refund_id is null and t.transaction_type='Credit'
LEFT JOIN pmt_incremental_detail i on i.transaction_id = t.transaction_id
<where>
<if test="from!=null">and o.create_time &gt;= #{from}</if>
<if test="to!=null">and o.create_time &lt; #{to}</if>
@ -583,6 +768,15 @@
AND
o.source = #{source}
</if>
<if test="client_ids!=null">
AND o.client_id IN
<foreach collection="client_ids" open="(" close=")" separator="," item="client_id">
#{client_id}
</foreach>
</if>
<if test="client_ids==null and client_id !=null">
and o.client_id=#{client_id}
</if>
</where>
GROUP BY o.order_id
</select>

Loading…
Cancel
Save