浏览代码

修改sql

yumeng 5 年之前
父节点
当前提交
227c1a852f

+ 9 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/AccountReportMapper.java

@@ -127,4 +127,13 @@ public interface AccountReportMapper {
      * @return
      */
     JSONObject selectSummaryByAccountId(@Param("date") String date, @Param("accountIds") JSONArray accountIds, @Param("statHour") Integer statHour);
+
+    /**
+     *
+     * @param startDate
+     * @param endDate
+     * @param accountIds
+     * @return
+     */
+    List<JSONObject> selectDayDetailByMonth(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("accountIds") JSONArray accountIds);
 }

+ 33 - 14
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/AccountReportMapper.xml

@@ -41,6 +41,8 @@
         sum(bclick) bClick,-- 行为数
         sum(form_count) formCount,
         (sum(charge) / sum(form_count)) formPrice, -- 表单提交单价
+        sum(activation) activationCount, -- 激活数
+        (sum(charge) / sum(activation)) activationPrice, -- 激活单价
         account_id accountId,
         (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName
         from
@@ -66,6 +68,8 @@
         sum(bclick) bClick,-- 行为数
         sum(form_count) formCount,
         (sum(charge) / sum(form_count)) formPrice, -- 表单提交单价
+        sum(activation) activationCount, -- 激活数
+        (sum(charge) / sum(activation)) activationPrice, -- 激活单价
         account_id accountId,
         (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName
         from
@@ -250,26 +254,41 @@
 
     <select id="selectAllByAccounts" resultType="com.alibaba.fastjson.JSONObject">
         select
-        sum(charge) cost, -- 消耗
-        sum(photo_show) photoShow, -- 封面展示
-        sum(photo_click) photoClick, -- 封面点击
-        sum(aclick) aclick, -- 素材曝光数
-        (sum(photo_click) / sum(photo_show)) photoClickRatio, -- 封面点击率
-        (sum(form_count) / sum(bclick)) cvr,
-        ((sum(charge) / (sum(photo_show)) * 1000)) cpm,
-        sum(bclick) bClick,-- 行为数
-        sum(form_count) formCount,
-        (sum(charge) / sum(form_count)) formPrice, -- 表单提交单价
-        account_id accountId,
-        (select auth_name from ctop_user_allocation where account_id = accountId limit 1) accountName
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        DATE_FORMAT(stat_date,'%Y-%m') statDate
         from
-        ctop_kuaishou_report_hourly_account
+        ctop_kuaishou_report_daily_account
         where account_id in
         <foreach item="item" index="index" collection="accountIds"
                  open="(" separator="," close=")">
             #{item}
         </foreach>
-        group by account_id
+        group by DATE_FORMAT(stat_date,'%Y-%m')
+        order by stat_date asc
+    </select>
+
+
+    <select id="selectDayDetailByMonth" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        DATE_FORMAT(stat_date,'%Y-%m') statDate
+        from
+        ctop_kuaishou_report_daily_account
+        where stat_date &lt;= #{startDate}
+        and stat_date &gt;= #{endDate}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by DATE_FORMAT(stat_date,'%Y-%m')
+        order by stat_date asc
     </select>
 
 

+ 1 - 1
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/AccountReportServiceImpl.java

@@ -193,7 +193,7 @@ public class AccountReportServiceImpl implements IAccountReportService {
             } else if (type == 7) {// 近六个月
                 String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
                 accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
-                detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
+                detail = accountReportMapper.selectDayDetailByMonth(anotherDay, endDate, accountIds);
 
             } else if (type == 8) {  // 所有
                 accountJson = accountReportMapper.selectAllAccount(accountIds);