Bläddra i källkod

销售盯盘 sql 排名 BUG修改

zhaoxian 3 år sedan
förälder
incheckning
12e2e704ae

+ 154 - 120
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/ManagerSaleValueMapper.xml

@@ -56,26 +56,32 @@
         FROM (
         SELECT sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d')
-        <if test="hour !=null">
-            AND hour &lt;= #{hour}
-        </if>
+        <where>
+            <if test="accountIds !=null and accountIds.size()>0">
+                AND account_id in
+                <foreach collection="accountIds" item="id" separator=","
+                         open="(" close=")">
+                    #{id}
+                </foreach>
+            </if>
+            and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d')
+            <if test="hour !=null">
+                AND hour &lt;= #{hour}
+            </if>
+        </where>
         ) t
         LEFT JOIN
         (
         SELECT sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        where stat_date = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -88,12 +94,15 @@
         FROM (
         SELECT sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d')
+        where stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -102,12 +111,14 @@
         (
         SELECT sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        WHERE stat_datetime = DATE_FORMAT(DATE_ADD(#{statDay},INTERVAL -1 day), '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         <if test="hour !=null">
             AND hour &lt;= #{hour}
         </if>
@@ -128,7 +139,7 @@
 
     <select id="queryTtManydaysCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT DATE_FORMAT(stat_datetime,'%Y-%m-%d') as 'statDate', IFNULL(sum(cost), 0.00) as 'charge'
-        FROM application.bytedance_advertiser_report_daily_dw
+        FROM application.bytedance_advertiser_report_hourly_dw
         WHERE account_id in
         <foreach collection="accountIds" item="id" separator=","
                  open="(" close=")">
@@ -142,14 +153,17 @@
 
     <select id="queryKsManydaysCharge" resultType="com.alibaba.fastjson.JSONObject">
         SELECT DATE_FORMAT(stat_date,'%Y-%m-%d') as 'statDate', IFNULL(sum(charge), 0.00) as 'charge'
-        FROM application.kuaishou_account_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        FROM application.kuaishou_account_report_hourly_dw
+        WHERE
+        stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
         and stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY stat_date
         order by stat_date
     </select>
@@ -157,13 +171,16 @@
     <select id="queryKsManydaysTotalCharge" resultType="String">
         SELECT IFNULL(sum(charge), 0.00)
         FROM application.kuaishou_account_report_daily_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date >= DATE_FORMAT(#{startDay}, '%Y%m%d')
+        WHERE
+        stat_date >= DATE_FORMAT(#{startDay}, '%Y%m%d')
         and stat_date &lt; DATE_FORMAT(#{endDay}, '%Y%m%d')
+        <if test="accountIds !=null and accountIds.size()>0">
+            and account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
     </select>
 
     <select id="queryKsRealCharged" resultType="com.alibaba.fastjson.JSONObject">
@@ -177,28 +194,32 @@
         IFNULL( sum( real_charged_in_yuan ), 0.00 ) AS 'realCharged'
         FROM
         application.app_kuaishou_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
+        WHERE stat_date >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT( #{statDay}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+
         ) thisMonth
         LEFT JOIN (
         SELECT
         IFNULL( sum( real_charged_in_yuan ), 0.00 ) AS 'realCharged'
         FROM
         application.app_kuaishou_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
+        WHERE stat_date >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
         AND stat_date &lt; DATE_FORMAT(#{monthFirstday}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND
+            account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) lastMonth ON 1=1
     </select>
 
@@ -213,28 +234,31 @@
         IFNULL( sum( cash_cost ), 0.00 ) AS 'realCharged'
         FROM
         application.app_bytedance_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
+        WHERE stat_datetime >= DATE_FORMAT( #{monthFirstday}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT( #{statDay}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND
+            account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) thisMonth
         LEFT JOIN (
         SELECT
         IFNULL( sum( cash_cost ), 0.00 ) AS 'realCharged'
         FROM
         application.app_bytedance_agent_report_d
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
+        WHERE stat_datetime >= DATE_FORMAT(#{lastMonthFirstday}, '%Y%m%d' )
         AND stat_datetime &lt; DATE_FORMAT(#{monthFirstday}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) lastMonth ON 1=1
     </select>
 
@@ -269,19 +293,21 @@
         FROM
         `jeecg-boot`.ctop_project_member t1
         LEFT JOIN `jeecg-boot`.ctop_project t2 ON t1.project_id = t2.id
-        WHERE t1.user_id IN
-        <foreach collection="userIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
+        WHERE t1.project_name IS NOT NULL
+        AND t1.project_name != ''
+        <if test="userIds !=null and userIds.size()>0">
+            AND t1.user_id IN
+            <foreach collection="userIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         <if test='mediaId ==2'>
             AND (t2.media_id = 2 or t2.media_id = 4)
         </if>
         <if test='mediaId ==1'>
             AND (t2.media_id = 1 or t2.media_id = 3)
         </if>
-        AND t1.project_name IS NOT NULL
-        AND t1.project_name != ''
         )
         GROUP BY
         t1.account_id
@@ -315,12 +341,14 @@
     <select id="queryKsHourList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT hour,sum(charge) as 'charge'
         FROM application.kuaishou_account_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        WHERE stat_date = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY hour
         ORDER BY hour
     </select>
@@ -328,12 +356,14 @@
     <select id="queryTtHourList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT hour,sum(cost) as 'charge'
         FROM application.bytedance_advertiser_report_hourly_dw
-        WHERE account_id in
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        and stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        WHERE stat_datetime = DATE_FORMAT(#{statDay}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id in
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         GROUP BY hour
         ORDER BY hour
     </select>
@@ -349,29 +379,31 @@
         SELECT
         IFNULL( sum(cost), 0.00 ) AS 'charge'
         FROM
-        application.bytedance_advertiser_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) this
         LEFT JOIN (
         SELECT
         IFNULL( sum(cost), 0.00 ) AS 'charge'
         FROM
-        application.bytedance_advertiser_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_datetime >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
+        application.bytedance_advertiser_report_hourly_dw
+        WHERE stat_datetime >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
         AND stat_datetime &lt;= DATE_FORMAT( #{lastTimeEnd}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) last ON 1=1
     </select>
 
@@ -386,29 +418,31 @@
         SELECT
         IFNULL( sum(charge), 0.00 ) AS 'charge'
         FROM
-        application.kuaishou_account_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
+        application.kuaishou_account_report_hourly_dw
+        WHERE stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) this
         LEFT JOIN (
         SELECT
         IFNULL( sum(charge), 0.00 ) AS 'charge'
         FROM
-        application.kuaishou_account_report_daily_dw
-        WHERE
-        account_id IN
-        <foreach collection="accountIds" item="id" separator=","
-                 open="(" close=")">
-            #{id}
-        </foreach>
-        AND stat_date >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
+        application.kuaishou_account_report_hourly_dw
+        WHERE stat_date >= DATE_FORMAT( #{lastTimeStart}, '%Y%m%d' )
         AND stat_date &lt;= DATE_FORMAT( #{lastTimeEnd}, '%Y%m%d' )
+        <if test="accountIds !=null and accountIds.size()>0">
+            AND account_id IN
+            <foreach collection="accountIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
         ) last ON 1=1
     </select>