Explorar o código

盯盘2.0功能 查询运营数据详情添加时间条件

zhaoxian %!s(int64=4) %!d(string=hai) anos
pai
achega
5b397d9166

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountDailyMapper.java

@@ -47,4 +47,8 @@ public interface EtlKuaishouReportAccountDailyMapper extends BaseMapper<EtlKuais
     int leaderAccountPageListTotal(JSONObject request);
 
     List<EtlKuaishouReportAccountHourly> selectList(@Param("startDate") String startDate,@Param("endDate") String endDate);
+
+    int operatingStaffDataListTotal(JSONObject request);
+
+    List<JSONObject> operatingStaffDataList(JSONObject request);
 }

+ 161 - 27
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountDailyMapper.xml

@@ -471,7 +471,6 @@
         ORDER BY stat_date
     </select>
 
-
     <select id="projectPageList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
         ${filed},
@@ -499,11 +498,6 @@
         LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
         where i1.stat_date &gt;= DATE_SUB(#{startTime},INTERVAL 7 DAY)
         AND i1.stat_date &lt;= DATE_SUB(#{endTime},INTERVAL 7 DAY)
-        AND i2.user_id IN
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY i1.account_id
         ) t6 ON t2.account_id = t6.account_id
         LEFT JOIN (
@@ -516,44 +510,184 @@
         ) t7 on t2.project_id = t7.project_id
         where t1.stat_date &gt;= #{startTime}
         AND t1.stat_date &lt;= #{endTime}
-        AND t2.user_id in
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY t3.id
+        HAVING SUM(charge)>0
         <if test="sortCode != '' and sortCode != null ">
             ORDER BY ${sortCode}
+            ${sortType}
         </if>
-        ${sortType}
-    </select>
 
+    </select>
 
     <select id="projectPageListTotal" resultType="java.lang.Integer">
         SELECT IFNULL(SUM(1),0) from
-        (
-        SELECT
-        t3.id
+            (
+                SELECT
+                    t3.id
+                FROM ctop_etl_kuaishou_report_account_daily t1
+                         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+                         LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
+                where t1.stat_date &gt;= #{startTime}
+                  AND t1.stat_date &lt;= #{endTime}
+                GROUP BY t3.id
+                HAVING SUM(charge)>0
+            ) t
+    </select>
+
+    <select id="selectList" resultType="cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly">
+        SELECT * from ctop_etl_kuaishou_report_account_daily
+        WHERE stat_date &gt;= #{startDate}
+          and stat_date &lt;= #{endDate}
+    </select>
+
+    <select id="operatingStaffDataListTotal" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1),0)
+        FROM (
+        SELECT 1
         FROM ctop_etl_kuaishou_report_account_daily t1
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
-        LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
-        where t1.stat_date &gt;= #{startTime}
-        AND t1.stat_date &lt;= #{endTime}
-        AND t2.user_id in
+        WHERE stat_date &gt;= #{startTime}
+        and stat_date &lt;= #{endTime}
+        AND t2.user_id IN
         <foreach item="id" index="index" collection="userIds"
                  open="(" separator="," close=")">
             #{id}
         </foreach>
-        GROUP BY t3.id
+        GROUP BY t2.user_id
         ) t
     </select>
 
-
-    <select id="selectList" resultType="cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly">
-        SELECT * from ctop_etl_kuaishou_report_account_daily
-        WHERE stat_date &gt;= #{startDate}
-        and stat_date &lt;= #{endDate}
+    <select id="operatingStaffDataList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL(t2.user_id,'') 'userId',
+        IFNULL(t9.realname,'') 'realName',
+        IFNULL(t3.accountCount,0) 'accountCount',
+        IFNULL(SUM(t1.charge),0) 'charge',
+        IFNULL(t4.weekCharge,0) 'weekCharge',
+        concat(CAST(IFNULL(ROUND((t4.weekCharge-t5.lweekCharge)/t5.lweekCharge*100,2), 0)as char),'%')as 'grew',
+        IFNULL(t6.effectiveCount,0) 'effectiveCount',
+        IFNULL(t7.campaignCount,0) 'campaignCount',
+        IFNULL(t8.unitCount,0) 'unitCount'
+        FROM
+        ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT user_id,COUNT(1) 'accountCount' FROM ctop_user_allocation i1
+        INNER JOIN ctop_etl_kuaishou_report_account_daily  i2 ON i1.account_id = i2.account_id
+        AND i2.stat_date &gt;= #{startTime}
+        and i2.stat_date &lt;= #{endTime}
+        WHERE user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY user_id
+        ) t3 ON t2.user_id = t3.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(charge) 'weekCharge',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_report_account_daily tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &lt;=#{today}
+        and tt1.stat_date &gt;=#{weekStartTime}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t4 ON t2.user_id = t4.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(charge) 'lweekCharge',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_report_account_daily tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &lt;=#{lweekEndTime}
+        and tt1.stat_date &gt;=#{lweekStartTime}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t5 ON t2.user_id = t5.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(effective_count) 'effectiveCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_account_material_overview tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.state_date &gt;= #{startTime}
+        and tt1.state_date &lt;= #{endTime}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t6 ON t2.user_id = t6.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(new_count) 'campaignCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_newly tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &gt;= #{startTime}
+        and tt1.stat_date &lt;= #{endTime}
+        AND tt1.new_type = 'campaign'
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t7 ON t2.user_id = t7.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(new_count) 'unitCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_newly tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &gt;= #{startTime}
+        and tt1.stat_date &lt;= #{endTime}
+        AND tt1.new_type = 'unit'
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t8 ON t2.user_id = t8.user_id
+        LEFT JOIN (
+        SELECT
+        id,realname
+        FROM
+        sys_user
+        WHERE id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        ) t9 ON t2.user_id = t9.id
+        WHERE t1.stat_date &gt;= #{startTime}
+        and t1.stat_date &lt;= #{endTime}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t2.user_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
     </select>
 
-
 </mapper>

+ 7 - 24
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountHourlyMapper.xml

@@ -409,7 +409,7 @@
         SELECT 1
         FROM ctop_etl_kuaishou_report_account_hourly t1
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
-        WHERE stat_date = #{today}
+        WHERE stat_date = #{startTime}
         AND t2.user_id IN
         <foreach item="id" index="index" collection="userIds"
                  open="(" separator="," close=")">
@@ -436,7 +436,7 @@
         LEFT JOIN(
         SELECT user_id,COUNT(1) 'accountCount' FROM ctop_user_allocation i1
         INNER JOIN ctop_etl_kuaishou_report_account_hourly  i2 ON i1.account_id = i2.account_id
-        AND i2.stat_date = #{today}
+        AND i2.stat_date = #{startTime}
         WHERE user_id IN
         <foreach item="id" index="index" collection="userIds"
                  open="(" separator="," close=")">
@@ -534,7 +534,7 @@
             #{id}
         </foreach>
         ) t9 ON t2.user_id = t9.id
-        WHERE t1.stat_date = #{today}
+        WHERE t1.stat_date = #{startTime}
         AND t2.user_id IN
         <foreach item="id" index="index" collection="userIds"
                  open="(" separator="," close=")">
@@ -578,11 +578,6 @@
         LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
         where stat_date = DATE_SUB(#{startTime},INTERVAL 1 DAY)
         AND stat_hour &lt;= #{hours}
-        AND i2.user_id IN
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY i1.account_id
         ) t5 ON t2.account_id = t5.account_id
         LEFT JOIN(
@@ -590,24 +585,16 @@
         LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
         where stat_date = DATE_SUB(#{startTime},INTERVAL 7 DAY)
         AND stat_hour &lt;= #{hours}
-        AND i2.user_id IN
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY i1.account_id
         ) t6 ON t2.account_id = t6.account_id
         where stat_date = #{startTime}
-        AND t2.user_id IN
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY t3.id
+        HAVING SUM(charge)>0
         <if test="sortCode != '' and sortCode != null ">
             ORDER BY ${sortCode}
+            ${sortType}
         </if>
-        ${sortType}
+
     </select>
 
     <select id="projectPageListTotal" resultType="java.lang.Integer">
@@ -619,12 +606,8 @@
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
         where stat_date = #{startTime}
-        AND t2.user_id in
-        <foreach item="id" index="index" collection="userIds"
-                 open="(" separator="," close=")">
-            #{id}
-        </foreach>
         GROUP BY t3.id
+        HAVING SUM(charge)>0
         )t
     </select>
 

+ 20 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouReportAccountHourlyServiceImpl.java

@@ -503,7 +503,9 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
     @Override
     public Result<Object> operatingStaffDataList(JSONObject request) {
         String userId = request.getString("userId");
-        if (Check.isNull(userId)) {
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        if (Check.isNull(userId)||Check.isNull(startTime)||Check.isNull(endTime)) {
             return Result.error("缺少账户入参");
         }
         String sortCode = request.getString("sortCode");
@@ -542,11 +544,24 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
         request.put("yesterday", yesterday);
         //获取人群集
         request.put("userIds", getUserIdList(userId));
-        int totle = etlHourlyAccountMapper.operatingStaffDataListTotal(request);
-        PageHelper.startPage(pageNo, pageSize, false);
-        PageInfo pageInfo = new PageInfo(etlHourlyAccountMapper.operatingStaffDataList(request));
+        List<JSONObject> list = null;
+        int total = 0;
+        //单日数据
+        if (endTime.equals(startTime)) {
+            if(!today.equals(startTime)){
+                request.put("yesterday", startTime);
+            }
+            total = etlHourlyAccountMapper.operatingStaffDataListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlHourlyAccountMapper.operatingStaffDataList(request);
+        }else {
+            total = etlDailyAccountMapper.operatingStaffDataListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlDailyAccountMapper.operatingStaffDataList(request);
+        }
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
         if (!Check.isNull(pageInfo)) {
-            pageInfo.setTotal(totle);
+            pageInfo.setTotal(total);
         }
         return Result.ok(pageInfo);
     }