Commit 222c9b86 by 春觉晓

修改门店存量分析接口,优化流失门店sql

1 parent 5fa6033d
...@@ -642,50 +642,44 @@ ...@@ -642,50 +642,44 @@
</select> </select>
<select id="countLostMerchantByBizType" resultType="java.lang.Integer"> <select id="countLostMerchantByBizType" resultType="java.lang.Integer">
SELECT SELECT COUNT(1) AS lost_merchant_count
count(distinct merchant_id) AS lost_merchant_count FROM
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t1 (SELECT merchant_id
WHERE FROM dj_smartcarlife.dj_car_life_service_merchant_bi
t1.deleted_flag = 'N' WHERE deleted_flag = 'N'
<choose>
<when test="bizType == 2">
and has_ext_warranty = 1
</when>
<when test="bizType == 3">
and has_benefits = 1
</when>
<when test="bizType == 4">
and has_light_mod = 1
</when>
</choose>
<![CDATA[
AND stat_date >= #{statDate} - INTERVAL 59 DAY
AND stat_date <= #{statDate}
]]>
<if test="merchantIds != null and merchantIds.size > 0"> <if test="merchantIds != null and merchantIds.size > 0">
and t1.merchant_id in AND merchant_id IN
<foreach item="item" index="index" collection="merchantIds" separator="," open="(" close=")"> <foreach item="item" index="index" collection="merchantIds" separator="," open="(" close=")">
#{item} #{item}
</foreach> </foreach>
</if> </if>
<if test="excludeIds != null and excludeIds.size > 0"> <if test="excludeIds != null and excludeIds.size > 0">
and t1.merchant_id not in and merchant_id not in
<foreach item="item" index="index" collection="excludeIds" separator="," open="(" close=")"> <foreach item="item" index="index" collection="excludeIds" separator="," open="(" close=")">
#{item} #{item}
</foreach> </foreach>
</if> </if>
AND EXISTS ( GROUP BY merchant_id) a
SELECT 1 WHERE NOT EXISTS (
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t2
WHERE
t2.merchant_id = t1.merchant_id
<![CDATA[
AND t2.stat_date >= #{statDate} - INTERVAL 59 DAY -- 传入的统计日期
AND t2.stat_date <= #{statDate}
]]>
<choose>
<when test="bizType == 2">
and t2.has_ext_warranty = 1
</when>
<when test="bizType == 3">
and t2.has_benefits = 1
</when>
<when test="bizType == 4">
and t2.has_light_mod = 1
</when>
</choose>
AND t2.deleted_flag = 'N'
)
AND NOT EXISTS (
SELECT 1 SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t3 FROM dj_smartcarlife.dj_car_life_service_merchant_bi t3
WHERE WHERE t3.merchant_id = a.merchant_id
t3.merchant_id = t1.merchant_id AND t3.deleted_flag = 'N'
<![CDATA[ <![CDATA[
AND t3.stat_date >= #{statDate} - INTERVAL 29 DAY AND t3.stat_date >= #{statDate} - INTERVAL 29 DAY
AND t3.stat_date <= #{statDate} AND t3.stat_date <= #{statDate}
...@@ -701,8 +695,7 @@ ...@@ -701,8 +695,7 @@
and t3.has_light_mod = 1 and t3.has_light_mod = 1
</when> </when>
</choose> </choose>
AND t3.deleted_flag = 'N' )
);
</select> </select>
<select id="countHistoryMerchant" resultType="java.lang.Integer"> <select id="countHistoryMerchant" resultType="java.lang.Integer">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!