|
|
|
@@ -293,4 +293,73 @@ |
|
|
|
{call user_credit_clear(#{cutOffDate},#{finalTableIndex})} |
|
|
|
</update> |
|
|
|
|
|
|
|
|
|
|
|
<select id="merchantCreditRanking" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo"> |
|
|
|
select wm.id merchantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit, |
|
|
|
IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser, |
|
|
|
IFNULL(d.count_c_user_id,0) countLesCreditUser |
|
|
|
from |
|
|
|
( |
|
|
|
select id,name from wx_merchant |
|
|
|
where is_del = 0 |
|
|
|
<if test=" null != tenantId and '' != tenantId"> |
|
|
|
and `tenant_id` = #{tenantId} |
|
|
|
</if> |
|
|
|
<if test=" null != parentTenantId and '' != parentTenantId"> |
|
|
|
and `parent_tenant_id` = #{parentTenantId} |
|
|
|
</if> |
|
|
|
) 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 |
|
|
|
<if test=" null != startTime "> |
|
|
|
and create_date >= #{startTime} |
|
|
|
</if> |
|
|
|
<if test=" null != endTime"> |
|
|
|
and create_date < #{endTime} |
|
|
|
</if> |
|
|
|
GROUP BY 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 |
|
|
|
<if test=" null != startTime "> |
|
|
|
and create_date >= #{startTime} |
|
|
|
</if> |
|
|
|
<if test=" null != endTime"> |
|
|
|
and create_date < #{endTime} |
|
|
|
</if> |
|
|
|
GROUP BY 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 |
|
|
|
<if test=" null != startTime "> |
|
|
|
and create_date >= #{startTime} |
|
|
|
</if> |
|
|
|
<if test=" null != endTime"> |
|
|
|
and create_date < #{endTime} |
|
|
|
</if> |
|
|
|
GROUP BY 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 |
|
|
|
<if test=" null != startTime "> |
|
|
|
and create_date >= #{startTime} |
|
|
|
</if> |
|
|
|
<if test=" null != endTime"> |
|
|
|
and create_date < #{endTime} |
|
|
|
</if> |
|
|
|
GROUP BY merchant_id |
|
|
|
) d on d.merchant_id = wm.id |
|
|
|
|
|
|
|
ORDER BY sumAddCredit desc |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
</mapper> |