Browse Source

Merge remote-tracking branch 'origin/test' into test

syh 5 years ago
parent
commit
c405884388

+ 0 - 10
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouReportController.java

@@ -82,11 +82,9 @@ public class KuaiShouReportController {
                             if (i == 0) {
                                 kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, nowDate, nowDate, 500, 1);
                                 hourDate = nowDate;
-                                System.err.println(nowDate);
                             } else if (i > 0) {
                                 String hourAnotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", hourDate, -1);
                                 kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, hourAnotherDay, hourAnotherDay, 500, 1);
-                                System.err.println(hourAnotherDay);
                                 hourDate = hourAnotherDay;
                             }
 
@@ -107,12 +105,4 @@ public class KuaiShouReportController {
 
     }
 
-
-    public static void main(String[] args) throws ParseException {
-        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-        String anotherDay1 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
-        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay1, -180);
-
-        System.err.println(anotherDay);
-    }
 }

+ 0 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -169,11 +169,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page", pageNum);
         KuaishouResult<KuaishouReportHourlyAccount> kuaishouResult = null;
         try {
-
             String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
-                System.err.println(resultJson);
                 if (resultJson.getInteger("code") == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
@@ -185,7 +183,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             Long like = detailJson.getLong("like");
                             detailJson.put("photo_like", like);
                             KuaishouReportHourlyAccount kuaishouReportHourlyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyAccount.class);
-//                            System.err.println(kuaishouReportHourlyAccount);
                             kuaishouReportHourlyAccount.setAccountId(advertiserId);
                             kuaishouReportHourlyAccount.setId("" + advertiserId + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
                             hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);

+ 0 - 4
module-report/src/main/java/cn/com/ctop/bytedance/controller/AccountReportController.java

@@ -53,10 +53,7 @@ public class AccountReportController {
 
     @PostMapping("/getReportList")
     public JSONObject getReportList(@RequestBody JSONObject json) {
-        System.err.println(json);
-
         JSONObject summaryJson = accountReportService.getSummaryReport(json);
-        System.err.println(summaryJson);
         return summaryJson;
 
     }
@@ -64,7 +61,6 @@ public class AccountReportController {
 
     @PostMapping("/getStatistics")
     public JSONObject getStatistics(@RequestBody JSONObject json) {
-
         JSONObject statisticsJson = accountReportService.getStatistics(json);
         return statisticsJson;
 

+ 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);
 }

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

@@ -11,10 +11,12 @@
         sum(aclick) aclick, -- 素材曝光数
         (sum(photo_click) / sum(photo_show)) photoClickRatio, -- 封面点击率
         (sum(form_count) / sum(bclick)) cvr,
-        (sum(charge) / (sum(photo_show) * 1000)) cpm,
+        ((sum(charge) / (sum(photo_show)) * 1000)) cpm,
         sum(bclick) bClick,-- 行为数
         sum(form_count) formCount, -- 表单提交数
-        (sum(charge) / sum(form_count)) formPrice -- 表单提交单价
+        (sum(charge) / sum(form_count)) formPrice, -- 表单提交单价
+        sum(activation) activationCount, -- 激活数
+        (sum(charge) / sum(activation)) activationPrice -- 激活单价
         from
         ctop_kuaishou_report_hourly_account
         where stat_date = #{date}
@@ -29,86 +31,86 @@
 
     <select id="selectAccountReport" resultType="com.alibaba.fastjson.JSONObject">
         select
-        sum(t1.charge) cost, -- 消耗
-        sum(t1.photo_show) photoShow, -- 封面展示
-        sum(t1.photo_click) photoClick, -- 封面点击
+        sum(charge) cost, -- 消耗
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
         sum(aclick) aclick, -- 素材曝光数
-        (sum(t1.photo_click) / sum(t1.photo_show)) photoClickRatio, -- 封面点击率
-        (sum(t1.form_count) / sum(t1.bclick)) cvr,
-        (sum(t1.charge) / (sum(t1.photo_show) * 1000)) cpm,
-        sum(t1.bclick) bClick,-- 行为数
-        sum(t1.form_count) formCount,
-        (sum(t1.charge) / sum(t1.form_count)) formPrice, -- 表单提交单价
-        t1.account_id accountId,
-        t2.auth_name accountName
+        (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, -- 表单提交单价
+        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
-        ctop_kuaishou_report_daily_account t1
-        LEFT JOIN ctop_user_allocation t2
-        ON t1.account_id = t2.account_id
-        where t1.account_id in
+        ctop_kuaishou_report_daily_account
+        where account_id in
         <foreach item="item" index="index" collection="accountIds"
                  open="(" separator="," close=")">
             #{item}
         </foreach>
-        group by t1.account_id;
+        group by account_id;
     </select>
 
 
     <select id="selectAccountReportByDate" resultType="com.alibaba.fastjson.JSONObject">
         select
-        sum(t1.charge) cost, -- 消耗
-        sum(t1.photo_show) photoShow, -- 封面展示
-        sum(t1.photo_click) photoClick, -- 封面点击
+        sum(charge) cost, -- 消耗
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
         sum(aclick) aclick, -- 素材曝光数
-        (sum(t1.photo_click) / sum(t1.photo_show)) photoClickRatio, -- 封面点击率
-        (sum(t1.form_count) / sum(t1.bclick)) cvr,
-        (sum(t1.charge) / (sum(t1.photo_show) * 1000)) cpm,
-        sum(t1.bclick) bClick,-- 行为数
-        sum(t1.form_count) formCount,
-        (sum(t1.charge) / sum(t1.form_count)) formPrice, -- 表单提交单价
-        t1.account_id accountId,
-        t2.auth_name accountName
+        (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, -- 表单提交单价
+        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
-        ctop_kuaishou_report_daily_account t1
-        LEFT JOIN ctop_user_allocation t2
-        ON t1.account_id = t2.account_id
-        where t1.stat_date &lt;= #{startDate}
-        and t1.stat_date &gt;= #{endDate}
-        and t1.account_id in
+        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 t1.account_id;
+        group by account_id;
     </select>
 
 
     <select id="selectReportDetailGroupAccountId" resultType="com.alibaba.fastjson.JSONObject">
         select
-        sum(t1.charge) cost, -- 消耗
-        sum(t1.photo_show) photoShow, -- 封面展示
-        sum(t1.photo_click) photoClick, -- 封面点击
+        sum(charge) cost, -- 消耗
+        sum(photo_show) photoShow, -- 封面展示
+        sum(photo_click) photoClick, -- 封面点击
         sum(aclick) aclick, -- 素材曝光数
-        (sum(t1.photo_click) / sum(t1.photo_show)) photoClickRatio, -- 封面点击率
-        (sum(t1.form_count) / sum(t1.bclick)) cvr,
-        (sum(t1.charge) / (sum(t1.photo_show) * 1000)) cpm,
-        sum(t1.bclick) bClick,-- 行为数
-        sum(t1.form_count) formCount,
-        (sum(t1.charge) / sum(t1.form_count)) formPrice, -- 表单提交单价
-        t1.account_id accountId,
-        t2.auth_name accountName
+        (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, -- 表单提交单价
+        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
-        ctop_kuaishou_report_hourly_account t1
-        LEFT JOIN ctop_user_allocation t2
-        ON t1.account_id = t2.account_id
-        where t1.stat_date = #{date}
-        and t1.account_id in
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+        and stat_hour &lt;= #{statHour}
+        and account_id in
         <foreach item="item" index="index" collection="accountIds"
                  open="(" separator="," close=")">
             #{item}
         </foreach>
-        and stat_hour &lt;= #{statHour}
-        group by t1.account_id;
+        group by account_id;
     </select>
 
 
@@ -252,30 +254,41 @@
 
     <select id="selectAllByAccounts" resultType="com.alibaba.fastjson.JSONObject">
         select
-        sum(t1.charge) cost, -- 消耗
-        sum(t1.photo_show) photoShow, -- 封面展示
-        sum(t1.photo_click) photoClick, -- 封面点击
-        sum(aclick) aclick, -- 素材曝光数
-        (sum(t1.photo_click) / sum(t1.photo_show)) photoClickRatio, -- 封面点击率
-        (sum(t1.form_count) / sum(t1.bclick)) cvr,
-        (sum(t1.charge) / (sum(t1.photo_show) * 1000)) cpm,
-        sum(t1.bclick) bClick,-- 行为数
-        sum(t1.form_count) formCount,
-        (sum(t1.charge) / sum(t1.form_count)) formPrice, -- 表单提交单价
-        t1.account_id accountId,
-        t2.auth_name 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 t1
-        LEFT JOIN ctop_user_allocation t2
-        ON t1.account_id = t2.account_id
-        where t1.account_id in
+        ctop_kuaishou_report_daily_account
+        where account_id in
         <foreach item="item" index="index" collection="accountIds"
                  open="(" separator="," close=")">
             #{item}
         </foreach>
-        group by t1.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>
 
 

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

@@ -30,9 +30,7 @@ public class AccountReportServiceImpl implements IAccountReportService {
         if (Check.isNull(json)) {
             return null;
         }
-
         JSONArray accountIds = json.getJSONArray("accountIds");
-        System.err.println(accountIds);
         if (Check.isNull(accountIds)) {
             return null;
         }
@@ -150,7 +148,6 @@ public class AccountReportServiceImpl implements IAccountReportService {
                                 nowJson.put("aClickProportion", 0); // 较昨日增加比例
                             }
 
-
                             BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
                             nowJson.put("discountCost", discountCost); // 折后消耗
                             BigDecimal yesterdayDiscountCost = yesterdayCost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
@@ -196,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);
@@ -235,6 +232,7 @@ public class AccountReportServiceImpl implements IAccountReportService {
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
             String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
             JSONArray accountIds = json.getJSONArray("accountIds");
+            BigDecimal discount = json.getBigDecimal("discount");
             if (Check.isNull(accountIds)) {
                 return null;
             }
@@ -357,19 +355,42 @@ public class AccountReportServiceImpl implements IAccountReportService {
                             }
                         }
 
+
+                        Long nowActivationCount = nowAccountSummary.getLong("activationCount"); // 激活数
+                        Long yesterdayActivationCount = yesterdayAccountSummary.getLong("activationCount");
+                        if (!Check.isNull(nowActivationCount) && !Check.isNull(yesterdayActivationCount)) {
+                            if (yesterdayAClick != 0L) {
+                                double activationCountProportion = (nowActivationCount.doubleValue() - yesterdayActivationCount.doubleValue()) / yesterdayActivationCount.doubleValue();
+                                chainRatioJson.put("activationCountProportion", activationCountProportion);
+                            } else {
+                                chainRatioJson.put("activationCountProportion", 0); //表单提交数环比
+                            }
+                        }
+
                         BigDecimal nowFormPrice = nowAccountSummary.getBigDecimal("formPrice"); // 表单提交单价
                         BigDecimal yesterdayFormPrice = yesterdayAccountSummary.getBigDecimal("formPrice");
                         if (!Check.isNull(nowFormPrice) && !Check.isNull(yesterdayFormPrice)) {
                             if (yesterdayFormPrice.compareTo(new BigDecimal(0)) != 0) {
                                 BigDecimal formPriceProportion = (nowFormPrice.subtract(yesterdayFormPrice)).divide(yesterdayFormPrice, BigDecimal.ROUND_HALF_UP, 2);
-                                chainRatioJson.put("formPriceProportion", formPriceProportion);
+                                chainRatioJson.put("formPriceProportion", formPriceProportion.divide(discount, BigDecimal.ROUND_HALF_UP, 2));
                             } else {
                                 chainRatioJson.put("formPriceProportion", 0); // 表单提交单价环比
                             }
+
+
+                            BigDecimal nowActivationPrice = nowAccountSummary.getBigDecimal("activationPrice"); // 表单提交单价
+                            BigDecimal yesterdayActivationPrice = yesterdayAccountSummary.getBigDecimal("activationPrice");
+                            if (!Check.isNull(nowActivationPrice) && !Check.isNull(yesterdayActivationPrice)) {
+                                if (yesterdayFormPrice.compareTo(new BigDecimal(0)) != 0) {
+                                    BigDecimal activationPriceProportion = (nowActivationPrice.subtract(yesterdayActivationPrice)).divide(yesterdayActivationPrice, BigDecimal.ROUND_HALF_UP, 2);
+                                    chainRatioJson.put("activationPriceProportion", activationPriceProportion.divide(discount, BigDecimal.ROUND_HALF_UP, 2));
+                                } else {
+                                    chainRatioJson.put("activationPriceProportion", 0); // 表单提交单价环比
+                                }
+                            }
                         }
                     }
                 }
-
                 returnJson.put("chainRatio", chainRatioJson);
             } else if (type == 2) {
                 if (Check.isNull(statHour)) {
@@ -414,20 +435,12 @@ public class AccountReportServiceImpl implements IAccountReportService {
             }
 
             returnJson.put("accountDetail", accountDetail);
-            System.err.println(returnJson);
-
         } catch (Exception e) {
             e.printStackTrace();
 
         }
 
-
         return returnJson;
     }
 
-
-    public static void main(String[] args) {
-
-
-    }
 }