From d70b7bd2e96309092badd06ec173f7fad9c6e4f2 Mon Sep 17 00:00:00 2001 From: xhxu Date: Tue, 19 Jan 2021 10:34:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/WxCreditHistoryMapper.xml | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml b/mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml index 4e6e3deb8..c43c83900 100644 --- a/mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml @@ -311,51 +311,55 @@ ) wm left join ( - select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} - where merchant_id is not null and merchant_id != -1 and credit_num > 0 + select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit + INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id + where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num > 0 - and create_date >= #{startTime} + and credit.create_date >= #{startTime} - and create_date < #{endTime} + and credit.create_date < #{endTime} - GROUP BY merchant_id + GROUP BY credit.merchant_id ) a on a.merchant_id = wm.id left join ( - select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} - where merchant_id is not null and merchant_id != -1 and credit_num < 0 + select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit + INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id + where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num < 0 - and create_date >= #{startTime} + and credit.create_date >= #{startTime} - and create_date < #{endTime} + and credit.create_date < #{endTime} - GROUP BY merchant_id + GROUP BY credit.merchant_id ) b on b.merchant_id = wm.id left join ( - select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} - where merchant_id is not null and merchant_id != -1 and credit_num > 0 + select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit + INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id + where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num > 0 - and create_date >= #{startTime} + and credit.create_date >= #{startTime} - and create_date < #{endTime} + and credit.create_date < #{endTime} - GROUP BY merchant_id + GROUP BY credit.merchant_id ) c on c.merchant_id = wm.id left join ( - select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} - where merchant_id is not null and merchant_id != -1 and credit_num < 0 + select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit + INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id + where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num < 0 - and create_date >= #{startTime} + and credit.create_date >= #{startTime} - and create_date <= #{endTime} + and credit.create_date <= #{endTime} - GROUP BY merchant_id + GROUP BY credit.merchant_id ) d on d.merchant_id = wm.id where (IFNULL(a.sum_credit_num,0) > 0 or IFNULL(b.sum_credit_num,0) < 0) ORDER BY sumAddCredit desc