xhxu 5 лет назад
Родитель
Сommit
d70b7bd2e9
1 измененных файлов: 24 добавлений и 20 удалений
  1. +24
    -20
      mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml

+ 24
- 20
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
<if test=" null != startTime ">
and create_date &gt;= #{startTime}
and credit.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and create_date &lt; #{endTime}
and credit.create_date &lt; #{endTime}
</if>
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 &lt; 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 &lt; 0
<if test=" null != startTime ">
and create_date &gt;= #{startTime}
and credit.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and create_date &lt; #{endTime}
and credit.create_date &lt; #{endTime}
</if>
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 &gt; 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 &gt; 0
<if test=" null != startTime ">
and create_date &gt;= #{startTime}
and credit.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and create_date &lt; #{endTime}
and credit.create_date &lt; #{endTime}
</if>
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 &lt; 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 &lt; 0
<if test=" null != startTime ">
and create_date &gt;= #{startTime}
and credit.create_date &gt;= #{startTime}
</if>
<if test=" null != endTime">
and create_date &lt;= #{endTime}
and credit.create_date &lt;= #{endTime}
</if>
GROUP BY merchant_id
GROUP BY credit.merchant_id
) d on d.merchant_id = wm.id
where (IFNULL(a.sum_credit_num,0) &gt; 0 or IFNULL(b.sum_credit_num,0) &lt; 0)
ORDER BY sumAddCredit desc


Загрузка…
Отмена
Сохранить