Browse Source

Merge remote-tracking branch 'origin/master'

syh 5 năm trước cách đây
mục cha
commit
1411f93906

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

@@ -0,0 +1,76 @@
+package cn.com.ctop.bytedance.controller;
+
+import cn.com.ctop.bytedance.service.IAccountReportService;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@Slf4j
+@Api(tags = "广告主日报表")
+@RestController
+@RequestMapping("/ctop/accountReport")
+public class AccountReportController {
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private IAccountReportService accountReportService;
+
+
+    @PostMapping(value = "/getAdvertiserList")
+    public Result<List<UserAllocation>> queryPageList() {
+        Result<List<UserAllocation>> result = new Result();
+
+        try {
+            QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+            userAllocationQueryWrapper.eq("media_id", 2);
+            userAllocationQueryWrapper.isNotNull("account_id");
+            userAllocationQueryWrapper.groupBy("account_id");
+            userAllocationQueryWrapper.orderByAsc("advertiser_name");
+            List<UserAllocation> userAllocations = userAllocationMapper.selectList(userAllocationQueryWrapper);
+
+            result.setSuccess(true);
+            result.setMessage("查询成功");
+            result.setResult(userAllocations);
+        } catch (Exception e) {
+            result.setSuccess(true);
+            result.setMessage("查询失败");
+            e.printStackTrace();
+
+        }
+
+        return result;
+    }
+
+    @PostMapping("/getReportList")
+    public JSONObject getReportList(@RequestBody JSONObject json) {
+        System.err.println(json);
+
+        JSONObject summaryJson = accountReportService.getSummaryReport(json);
+        System.err.println(summaryJson);
+        return summaryJson;
+
+    }
+
+
+    @PostMapping("/getStatistics")
+    public JSONObject getStatistics(@RequestBody JSONObject json) {
+
+        JSONObject statisticsJson = accountReportService.getStatistics(json);
+        return statisticsJson;
+
+    }
+
+
+
+}

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

@@ -0,0 +1,130 @@
+package cn.com.ctop.bytedance.mapper;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface AccountReportMapper {
+
+
+    /**
+     * 查询 当日最大小时
+     *
+     * @param nowDate
+     * @return
+     */
+    Integer selectMaxHourByDate(String nowDate);
+
+    /**
+     * 今日消耗
+     *
+     * @param date
+     * @return
+     */
+    JSONObject selectDayReport(@Param("date") String date, @Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询明细
+     *
+     * @param date
+     * @return
+     */
+    List<JSONObject> selectReportDetail(@Param("date") String date, @Param("accountIds") JSONArray accountIds);
+
+    /**
+     * 根据开始、结束日期查询消耗
+     *
+     * @param anotherDay
+     * @param endDate
+     * @return
+     */
+    JSONObject selectByDate(@Param("startDate") String anotherDay, @Param("endDate") String endDate, @Param("accountIds") JSONArray accountIds);
+
+    /**
+     * 查询全部消耗 包括今日消耗
+     *
+     * @return
+     */
+    JSONObject selectAllAccount(@Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 根据日期 小时 查询信息
+     *
+     * @param date
+     * @param statHour
+     * @return
+     */
+    JSONObject selectDayHourlyByHourAndDate(@Param("date") String date, @Param("statHour") String statHour, @Param("accountIds") JSONArray accountIds);
+
+    /**
+     * 根据日期 最大小时小时 查询信息
+     *
+     * @param date
+     * @param statHour
+     * @return
+     */
+    JSONObject selectSumDayHourlyByHourAndDate(@Param("date") String date, @Param("statHour") String statHour, @Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询 七天汇总数据
+     *
+     * @param anotherDay
+     * @param endDate
+     * @return
+     */
+    List<JSONObject> selectDayDetailByDate(@Param("startDate") String anotherDay, @Param("endDate") String endDate, @Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询所有按月统计数据
+     *
+     * @return
+     */
+    List<JSONObject> selectAllByAccounts(@Param("accountIds") JSONArray accountId);
+
+
+    /**
+     * 查询账号维度 分组数据
+     *
+     * @param date
+     * @param accountIds
+     * @return
+     */
+    List<JSONObject> selectReportDetailGroupAccountId(@Param("date") String date, @Param("accountIds") JSONArray accountIds, @Param("statHour") Integer statHour);
+
+    /**
+     * 根据开始结束时间查询明细
+     *
+     * @param startDate
+     * @param endDate
+     * @param accountIds
+     * @return
+     */
+    List<JSONObject> selectAccountReportByDate(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询所有明细
+     *
+     * @param accountIds
+     * @return
+     */
+    List<JSONObject> selectAccountReport(@Param("accountIds") JSONArray accountIds);
+
+
+    /**
+     * 查询 根据日期查询汇总数据
+     *
+     * @param date
+     * @param accountIds
+     * @param statHour
+     * @return
+     */
+    JSONObject selectSummaryByAccountId(@Param("date") String date, @Param("accountIds") JSONArray accountIds, @Param("statHour") Integer statHour);
+}

+ 11 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/BytedanceReportMapper.java

@@ -52,6 +52,16 @@ public interface BytedanceReportMapper {
     JSONObject selectDayHourlyByHourAndDate(@Param("date") String date, @Param("statHour") String statHour);
     JSONObject selectDayHourlyByHourAndDate(@Param("date") String date, @Param("statHour") String statHour);
 
 
     /**
     /**
+     * 根据日期 最大小时小时 查询信息
+     *
+     * @param date
+     * @param statHour
+     * @return
+     */
+    JSONObject selectSumDayHourlyByHourAndDate(@Param("date") String date, @Param("statHour") String statHour);
+
+
+    /**
      * 查询 七天汇总数据
      * 查询 七天汇总数据
      *
      *
      * @param anotherDay
      * @param anotherDay
@@ -113,6 +123,7 @@ public interface BytedanceReportMapper {
 
 
     /**
     /**
      * 根据日期获取 分时详情数据
      * 根据日期获取 分时详情数据
+     *
      * @param date
      * @param date
      * @return
      * @return
      */
      */

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

@@ -0,0 +1,273 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.bytedance.mapper.AccountReportMapper">
+
+
+    <select id="selectSummaryByAccountId" 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 -- 表单提交单价
+        from
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and stat_hour &lt;= #{statHour}
+    </select>
+
+
+    <select id="selectAccountReport" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        stat_hour statHour
+        from
+        ctop_kuaishou_report_daily_account
+        where account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by stat_hour;
+    </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(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
+        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
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by t1.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(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
+        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
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and stat_hour &lt;= #{statHour}
+        group by t1.account_id;
+    </select>
+
+
+    <select id="selectMaxHourByDate" resultType="java.lang.Integer">
+        select
+        max(stat_hour)
+       from
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+
+      </select>
+
+
+    <select id="selectDayReport" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        max(stat_hour) maxHour
+        from
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+
+    <select id="selectByDate" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick
+        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>
+    </select>
+
+    <select id="selectAllAccount" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick
+        from
+        ctop_kuaishou_report_daily_account
+        where account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+
+    <select id="selectReportDetail" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        stat_hour statHour,
+        stat_date statDate
+        from
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by stat_hour
+        order by stat_hour asc
+    </select>
+
+
+    <select id="selectDayHourlyByHourAndDate" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick
+        from
+        ctop_kuaishou_report_hourly_account
+        where stat_date = #{date}
+        and stat_hour = #{statHour}
+        and account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="selectSumDayHourlyByHourAndDate" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick
+        from
+        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>
+    </select>
+
+
+    <select id="selectDayDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        sum(charge) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aclick) aclick,
+        stat_date 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 stat_date
+        order by stat_date asc
+    </select>
+
+
+    <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
+        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
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by t1.account_id;
+
+
+    </select>
+
+
+</mapper>

+ 19 - 6
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/BytedanceReportMapper.xml

@@ -8,7 +8,8 @@
          sum(charge) cost,
          sum(charge) cost,
          sum(photo_show) photoShow,
          sum(photo_show) photoShow,
          sum(photo_click) photoClick,
          sum(photo_click) photoClick,
-         sum(aclick) aclick
+         sum(aclick) aclick,
+         max(stat_hour) maxHour
        from
        from
         ctop_kuaishou_report_hourly_account
         ctop_kuaishou_report_hourly_account
         where stat_date = #{date}
         where stat_date = #{date}
@@ -66,6 +67,18 @@
       and stat_hour = #{statHour}
       and stat_hour = #{statHour}
     </select>
     </select>
 
 
+    <select id="selectSumDayHourlyByHourAndDate" resultType="com.alibaba.fastjson.JSONObject">
+      select
+       sum(charge) cost,
+       sum(photo_show) photoShow,
+       sum(photo_click) photoClick,
+       sum(aclick) aclick
+     from
+      ctop_kuaishou_report_hourly_account
+      where stat_date = #{date}
+      and stat_hour &lt;= #{statHour}
+    </select>
+
 
 
     <select id="selectDayDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
     <select id="selectDayDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
       select
       select
@@ -79,7 +92,7 @@
       where stat_date &lt;= #{startDate}
       where stat_date &lt;= #{startDate}
       and  stat_date &gt;= #{endDate}
       and  stat_date &gt;= #{endDate}
       group by stat_date
       group by stat_date
-      order by stat_date desc
+      order by stat_date asc
     </select>
     </select>
 
 
 
 
@@ -95,7 +108,7 @@
       where stat_date &lt;= #{startDate}
       where stat_date &lt;= #{startDate}
       and  stat_date &gt;= #{endDate}
       and  stat_date &gt;= #{endDate}
       group by DATE_FORMAT(stat_date,'%Y-%m')
       group by DATE_FORMAT(stat_date,'%Y-%m')
-      order by stat_date desc
+      order by stat_date asc
     </select>
     </select>
 
 
     <select id="selectAllDayDetailByMonth" resultType="com.alibaba.fastjson.JSONObject">
     <select id="selectAllDayDetailByMonth" resultType="com.alibaba.fastjson.JSONObject">
@@ -108,7 +121,7 @@
      from
      from
       ctop_kuaishou_report_daily_account
       ctop_kuaishou_report_daily_account
       group by DATE_FORMAT(stat_date,'%Y-%m')
       group by DATE_FORMAT(stat_date,'%Y-%m')
-      order by stat_date desc
+      order by stat_date asc
     </select>
     </select>
 
 
 
 
@@ -136,7 +149,7 @@
       ctop_kuaishou_report_daily_account
       ctop_kuaishou_report_daily_account
       where DATE_FORMAT(stat_date,'%Y-%m') = #{date}
       where DATE_FORMAT(stat_date,'%Y-%m') = #{date}
       group by stat_date
       group by stat_date
-      order by stat_date desc
+      order by stat_date asc
     </select>
     </select>
 
 
 
 
@@ -180,7 +193,7 @@
       ctop_kuaishou_report_hourly_account
       ctop_kuaishou_report_hourly_account
       where stat_date = #{date}
       where stat_date = #{date}
       group by stat_hour
       group by stat_hour
-      order by stat_hour desc
+      order by stat_hour asc
     </select>
     </select>
 
 
 
 

+ 21 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IAccountReportService.java

@@ -0,0 +1,21 @@
+package cn.com.ctop.bytedance.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IAccountReportService {
+    /**
+     * 获取汇总报表
+     *
+     * @param json
+     * @return
+     */
+    JSONObject getSummaryReport(JSONObject json);
+
+    /**
+     * 获取 统计报表数据
+     *
+     * @param json
+     * @return
+     */
+    JSONObject getStatistics(JSONObject json);
+}

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

@@ -0,0 +1,447 @@
+package cn.com.ctop.bytedance.service.impl;
+
+import cn.com.ctop.bytedance.mapper.AccountReportMapper;
+import cn.com.ctop.bytedance.service.IAccountReportService;
+import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class AccountReportServiceImpl implements IAccountReportService {
+    @Autowired
+    private AccountReportMapper accountReportMapper;
+
+    /**
+     * 获取 汇总
+     *
+     * @param json
+     * @return
+     */
+    @Override
+    public JSONObject getSummaryReport(JSONObject json) {
+        JSONObject returnJson = new JSONObject();
+        if (Check.isNull(json)) {
+            return null;
+        }
+
+        JSONArray accountIds = json.getJSONArray("accountIds");
+        System.err.println(accountIds);
+        if (Check.isNull(accountIds)) {
+            return null;
+        }
+        try {
+            JSONObject accountJson = new JSONObject();
+            List<JSONObject> detail = new ArrayList<>();
+
+            Integer type = json.getInteger("type");
+            BigDecimal discount = json.getBigDecimal("discount");
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
+            String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
+            if (type == 1) { // 今日汇总
+                Integer maxHour = accountReportMapper.selectMaxHourByDate(nowDate);
+                if (Check.isNull(maxHour) || maxHour == 0) {
+                    return null;
+                }
+                String maxHourStr = String.valueOf(maxHour - 1);
+                accountJson = accountReportMapper.selectSumDayHourlyByHourAndDate(nowDate, maxHourStr, accountIds); // 今日 小时汇总数据
+                JSONObject yesterdayJson = accountReportMapper.selectSumDayHourlyByHourAndDate(anotherDay, maxHourStr, accountIds); // 昨日 小时汇总数据
+                accountJson.put("maxHour", maxHour);
+                if (!Check.isNull(accountJson)) {
+                    BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
+                    BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗
+                    BigDecimal compareBigDecimal = new BigDecimal(0);
+                    if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
+                        BigDecimal costProportion = (cost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
+                        accountJson.put("costProportion", costProportion); // 较昨日增加比例
+                    } else {
+                        accountJson.put("costProportion", 0); // 较昨日增加比例
+                    }
+
+                    BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
+                    accountJson.put("discountCost", discountCost); // 折后消耗
+                    BigDecimal yesterdayDiscountCost = yesterdayCost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
+                    if (yesterdayDiscountCost.compareTo(compareBigDecimal) != 0) {
+                        BigDecimal discountCostProportion = (discountCost.subtract(yesterdayDiscountCost)).divide(yesterdayDiscountCost, BigDecimal.ROUND_HALF_UP, 2);
+                        accountJson.put("discountCostProportion", discountCostProportion); // 较昨日折后上涨
+                    } else {
+                        accountJson.put("discountCostProportion", 0); // 较昨日折后上涨
+                    }
+
+                    Long photoShow = accountJson.getLong("photoShow");// 今日封面展示
+                    Long yesterdayPhotoShow = yesterdayJson.getLong("photoShow");// 昨日封面展示
+                    if (yesterdayPhotoShow != 0L) {
+                        double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
+                        accountJson.put("showProportion", showProportion); // 较昨日增加比例
+                    } else {
+                        accountJson.put("showProportion", 0); // 较昨日增加比例
+                    }
+
+                    Long photoClick = accountJson.getLong("photoClick");// 今日封面展示
+                    Long yesterdayPhotoClick = yesterdayJson.getLong("photoClick");// 昨日封面展示
+                    if (yesterdayPhotoClick != 0L) {
+                        double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
+                        accountJson.put("photoClickProportion", photoClickProportion); // 较昨日增加比例
+                    } else {
+                        accountJson.put("photoClickProportion", 0); // 较昨日增加比例
+                    }
+
+                    Long aClick = accountJson.getLong("aclick");
+                    Long yesterdayAClick = yesterdayJson.getLong("aclick");
+                    if (yesterdayAClick != 0L) {
+                        double aClickProportion = (aClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
+                        accountJson.put("aClickProportion", aClickProportion); // 较昨日增加比例
+                    } else {
+                        accountJson.put("aClickProportion", 0); // 较昨日增加比例
+                    }
+                }
+
+
+                // 折线图
+                List<JSONObject> yesterdayDetailArr = accountReportMapper.selectReportDetail(anotherDay, accountIds);
+                for (int i = 0; i < yesterdayDetailArr.size(); i++) {
+
+                    JSONObject yesterdayDetail = yesterdayDetailArr.get(i);
+                    if (!Check.isNull(yesterdayDetail)) {
+                        String yesterdayStatHour = yesterdayDetail.getString("statHour");
+                        JSONObject nowJson = accountReportMapper.selectDayHourlyByHourAndDate(nowDate, yesterdayStatHour, accountIds);
+                        if (!Check.isNull(nowJson)) {
+                            nowJson.put("statDate", nowDate);
+                            BigDecimal cost = nowJson.getBigDecimal("cost"); // 今日消耗
+                            BigDecimal yesterdayCost = yesterdayDetail.getBigDecimal("cost");// 昨日消耗
+                            BigDecimal compareBigDecimal = new BigDecimal(0);
+                            if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
+                                BigDecimal costProportion = ((cost.subtract(yesterdayCost))).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
+                                nowJson.put("costProportion", costProportion); // 较昨日增加比例
+                            } else {
+                                nowJson.put("costProportion", 0); // 较昨日增加比例
+                            }
+
+                            Long photoShow = nowJson.getLong("photoShow");// 今日封面展示
+                            Long yesterdayPhotoShow = yesterdayDetail.getLong("photoShow");// 昨日封面展示
+                            if (yesterdayPhotoShow != 0L) {
+                                double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
+                                nowJson.put("showProportion", showProportion); // 较昨日增加比例
+                            } else {
+                                nowJson.put("showProportion", 0); // 较昨日增加比例
+                            }
+
+                            Long photoClick = nowJson.getLong("photoClick");// 今日封面展示
+                            Long yesterdayPhotoClick = yesterdayDetail.getLong("photoClick");// 昨日封面展示
+                            if (yesterdayPhotoClick != 0L) {
+                                double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
+                                nowJson.put("photoClickProportion", photoClickProportion); // 较昨日增加比例
+                            } else {
+                                nowJson.put("photoClickProportion", 0); // 较昨日增加比例
+                            }
+
+                            Long aClick = nowJson.getLong("aclick");// 今日封面展示
+                            Long yesterdayAClick = yesterdayDetail.getLong("aclick");// 昨日封面展示
+                            if (yesterdayAClick != 0L) {
+                                double aClickProportion = (aClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
+                                nowJson.put("aClickProportion", aClickProportion); // 较昨日增加比例
+                            } else {
+                                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);
+                            if (yesterdayDiscountCost.compareTo(compareBigDecimal) != 0) {
+                                BigDecimal discountCostProportion = (discountCost.subtract(yesterdayDiscountCost)).divide(yesterdayDiscountCost, BigDecimal.ROUND_HALF_UP, 2);
+                                nowJson.put("discountCostProportion", discountCostProportion); // 较昨日折后上涨
+                            } else {
+                                nowJson.put("discountCostProportion", 0); // 较昨日折后上涨
+                            }
+
+
+                            yesterdayDetail.put("now", nowJson);
+                        }
+                    }
+
+                    detail.add(yesterdayDetail);
+                }
+
+            } else if (type == 2) {
+                accountJson = accountReportMapper.selectDayReport(anotherDay, accountIds);
+                detail = accountReportMapper.selectReportDetail(anotherDay, accountIds);
+            } else if (type == 3) { // 近七天
+                String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
+                accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
+
+                detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
+
+            } else if (type == 4) { // 近15天
+                String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
+                accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
+                detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
+
+            } else if (type == 5) {// 近一个月
+                String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
+                accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
+                detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
+
+            } else if (type == 6) {// 近三个月
+                String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
+                accountJson = accountReportMapper.selectByDate(anotherDay, endDate, accountIds);
+                detail = accountReportMapper.selectDayDetailByDate(anotherDay, endDate, accountIds);
+
+            } 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);
+
+            } else if (type == 8) {  // 所有
+                accountJson = accountReportMapper.selectAllAccount(accountIds);
+                detail = accountReportMapper.selectAllByAccounts(accountIds);
+
+
+            } else if (type == 9) {  // 自定义查询日期
+                String startDate = json.getString("startDate");
+                String endDate = json.getString("endDate");
+                accountJson = accountReportMapper.selectByDate(startDate, endDate, accountIds);
+                detail = accountReportMapper.selectDayDetailByDate(startDate, endDate, accountIds);
+
+            }
+
+            if (type != 1) {
+                if (!Check.isNull(accountJson)) {
+                    BigDecimal cost = accountJson.getBigDecimal("cost");
+                    BigDecimal discountCost = cost.divide(discount, BigDecimal.ROUND_HALF_UP, 2);
+                    accountJson.put("discountCost", discountCost); // 折后消耗
+                }
+            }
+            returnJson.put("summary", accountJson);
+            returnJson.put("trend", detail);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return returnJson;
+    }
+
+    @Override
+    public JSONObject getStatistics(JSONObject json) {
+        JSONObject returnJson = new JSONObject();
+        try {
+
+
+            Integer type = json.getInteger("type");
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
+            String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
+            JSONArray accountIds = json.getJSONArray("accountIds");
+            if (Check.isNull(accountIds)) {
+                return null;
+            }
+
+            List<JSONObject> accountDetail = new ArrayList<>();
+            Integer statHour = json.getInteger("statHour");
+            Integer hour;
+            if (type == 1) { // 今日汇总
+                if (Check.isNull(statHour)) {
+                    Integer maxHour = accountReportMapper.selectMaxHourByDate(nowDate);
+                    hour = maxHour - 1;
+                } else {
+                    hour = statHour;
+                }
+                JSONObject chainRatioJson = new JSONObject();
+                accountDetail = accountReportMapper.selectReportDetailGroupAccountId(nowDate, accountIds, hour);
+                JSONObject nowAccountSummary = accountReportMapper.selectSummaryByAccountId(nowDate, accountIds, hour);
+                if (!Check.isNull(nowAccountSummary)) {
+                    returnJson.put("now", nowAccountSummary);
+                    JSONObject yesterdayAccountSummary = accountReportMapper.selectSummaryByAccountId(anotherDay, accountIds, hour);
+                    if (!Check.isNull(yesterdayAccountSummary)) {
+                        returnJson.put("yesterday", yesterdayAccountSummary);
+                        BigDecimal nowCost = nowAccountSummary.getBigDecimal("cost");
+                        BigDecimal yesterdayCost = yesterdayAccountSummary.getBigDecimal("cost");
+                        if (!Check.isNull(nowCost) && !Check.isNull(yesterdayCost)) {
+                            if (yesterdayCost.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal costProportion = (nowCost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP, 2);
+                                chainRatioJson.put("costProportion", costProportion);
+                            } else {
+                                chainRatioJson.put("costProportion", 0); // 消耗环比
+                            }
+                        }
+
+
+                        Long photoShow = nowAccountSummary.getLong("photoShow");// 今日封面展示
+                        Long yesterdayPhotoShow = yesterdayAccountSummary.getLong("photoShow");// 昨日封面展示
+                        if (!Check.isNull(photoShow) && !Check.isNull(yesterdayPhotoShow)) {
+                            if (yesterdayPhotoShow != 0L) {
+                                double showProportion = (photoShow.doubleValue() - yesterdayPhotoShow.doubleValue()) / yesterdayPhotoShow.doubleValue();
+                                chainRatioJson.put("showProportion", showProportion); // 较昨日增加比例
+                            } else {
+                                chainRatioJson.put("showProportion", 0); // 展示环比
+                            }
+                        }
+
+
+                        Long photoClick = nowAccountSummary.getLong("photoClick");// 封面点击
+                        Long yesterdayPhotoClick = yesterdayAccountSummary.getLong("photoClick");
+                        if (!Check.isNull(photoClick) && !Check.isNull(yesterdayPhotoClick)) {
+                            if (yesterdayPhotoClick != 0L) {
+                                double photoClickProportion = (photoClick.doubleValue() - yesterdayPhotoClick.doubleValue()) / yesterdayPhotoClick.doubleValue();
+                                chainRatioJson.put("photoClickProportion", photoClickProportion);
+                            } else {
+                                chainRatioJson.put("photoClickProportion", 0); // 点击环比
+                            }
+                        }
+
+
+                        Long nowAClick = nowAccountSummary.getLong("aclick"); // 爆光
+                        Long yesterdayAClick = yesterdayAccountSummary.getLong("aclick");
+                        if (!Check.isNull(nowAClick) && !Check.isNull(nowAClick)) {
+                            if (yesterdayAClick != 0L) {
+                                double aClickProportion = (nowAClick.doubleValue() - yesterdayAClick.doubleValue()) / yesterdayAClick.doubleValue();
+                                chainRatioJson.put("aClickProportion", aClickProportion);
+                            } else {
+                                chainRatioJson.put("aClickProportion", 0); //爆光环比
+                            }
+                        }
+
+
+                        BigDecimal nowPhotoClickRatio = nowAccountSummary.getBigDecimal("photoClickRatio"); // 封面点击率
+                        BigDecimal yesterdayPhotoClickRatio = yesterdayAccountSummary.getBigDecimal("photoClickRatio");
+                        if (!Check.isNull(nowPhotoClickRatio) && !Check.isNull(yesterdayPhotoClickRatio)) {
+                            if (yesterdayPhotoClickRatio.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal photoClickRatioProportion = (nowPhotoClickRatio.subtract(yesterdayPhotoClickRatio)).divide(yesterdayPhotoClickRatio, BigDecimal.ROUND_HALF_UP, 2);
+                                chainRatioJson.put("photoClickRatioProportion", photoClickRatioProportion);
+                            } else {
+                                chainRatioJson.put("photoClickRatioProportion", 0); // 封面点击率环比
+                            }
+                        }
+
+
+                        BigDecimal nowCvr = nowAccountSummary.getBigDecimal("cvr"); // cvr
+                        BigDecimal yesterdayCvr = yesterdayAccountSummary.getBigDecimal("cvr");
+                        if (!Check.isNull(nowCvr) && !Check.isNull(yesterdayCvr)) {
+                            if (yesterdayCvr.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal cvrProportion = (nowCvr.subtract(yesterdayCvr)).divide(yesterdayCvr, BigDecimal.ROUND_HALF_UP, 2);
+                                chainRatioJson.put("cvrProportion", cvrProportion);
+                            } else {
+                                chainRatioJson.put("cvrProportion", 0); // cvr环比
+                            }
+                        }
+
+
+                        BigDecimal nowCpm = nowAccountSummary.getBigDecimal("cpm"); // cpm
+                        BigDecimal yesterdayCpm = yesterdayAccountSummary.getBigDecimal("cpm");
+                        if (!Check.isNull(nowCpm) && !Check.isNull(yesterdayCpm)) {
+                            if (yesterdayCpm.compareTo(new BigDecimal(0)) != 0) {
+                                BigDecimal cpmProportion = (nowCpm.subtract(yesterdayCpm)).divide(yesterdayCpm, BigDecimal.ROUND_HALF_UP, 2);
+                                chainRatioJson.put("cpmProportion", cpmProportion);
+                            } else {
+                                chainRatioJson.put("cpmProportion", 0); // cpm环比
+                            }
+                        }
+
+
+                        Long nowBClick = nowAccountSummary.getLong("bClick"); // 行为数
+                        Long yesterdayBClick = yesterdayAccountSummary.getLong("bClick");
+                        if (!Check.isNull(nowBClick) && !Check.isNull(yesterdayBClick)) {
+                            if (yesterdayAClick != 0L) {
+                                double bClickProportion = (nowBClick.doubleValue() - yesterdayBClick.doubleValue()) / yesterdayBClick.doubleValue();
+                                chainRatioJson.put("bClickProportion", bClickProportion);
+                            } else {
+                                chainRatioJson.put("bClickProportion", 0); //行为数环比
+                            }
+                        }
+
+
+                        Long nowFormCount = nowAccountSummary.getLong("formCount"); // 表单提交数
+                        Long yesterdayFormCount = yesterdayAccountSummary.getLong("formCount");
+
+                        if (!Check.isNull(nowFormCount) && !Check.isNull(yesterdayFormCount)) {
+                            if (yesterdayAClick != 0L) {
+                                double formCountProportion = (nowFormCount.doubleValue() - yesterdayFormCount.doubleValue()) / yesterdayFormCount.doubleValue();
+                                chainRatioJson.put("formCountProportion", formCountProportion);
+                            } else {
+                                chainRatioJson.put("formCountProportion", 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);
+                            } else {
+                                chainRatioJson.put("formPriceProportion", 0); // 表单提交单价环比
+                            }
+
+                        }
+                    }
+
+
+                }
+
+                returnJson.put("chainRatio", chainRatioJson);
+            } else if (type == 2) {
+                if (Check.isNull(statHour)) {
+                    accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, 23);
+                } else {
+                    accountDetail = accountReportMapper.selectReportDetailGroupAccountId(anotherDay, accountIds, statHour);
+                }
+
+            } else if (type == 3) { // 近七天
+                String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
+                accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
+
+            } else if (type == 4) { // 近15天
+                String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
+                accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
+
+
+            } else if (type == 5) {// 近一个月
+                String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
+                accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
+
+
+            } else if (type == 6) {// 近三个月
+                String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
+                accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
+
+
+            } else if (type == 7) {// 近六个月
+                String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
+                accountDetail = accountReportMapper.selectAccountReportByDate(anotherDay, endDate, accountIds);
+
+
+            } else if (type == 8) {  // 所有
+                accountDetail = accountReportMapper.selectAccountReport(accountIds);
+
+
+            } else if (type == 9) {  // 自定义查询日期
+                String startDate = json.getString("startDate");
+                String endDate = json.getString("endDate");
+                accountDetail = accountReportMapper.selectAccountReportByDate(startDate, endDate, accountIds);
+
+            }
+
+            returnJson.put("accountDetail", accountDetail);
+            System.err.println(returnJson);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+
+        }
+
+
+        return returnJson;
+    }
+
+
+    public static void main(String[] args) {
+
+
+    }
+}

+ 12 - 2
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -203,9 +203,19 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); // 当前日期
             String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
             String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 当前日期-1
             if (type == 1) { // 今日总消耗
             if (type == 1) { // 今日总消耗
-                accountJson = reportMapper.selectDayReport(nowDate);
+                JSONObject nowJson = reportMapper.selectDayReport(nowDate);
+                if (Check.isNull(nowJson)) {
+                    return accountJson;
+                }
+                int maxHour = nowJson.getInteger("maxHour");
+                if (maxHour == 0 || Check.isNull(maxHour)) {
+                    return accountJson;
+                }
+                String maxHourStr = String.valueOf(maxHour - 1);
+                accountJson = reportMapper.selectSumDayHourlyByHourAndDate(nowDate, maxHourStr);
+                accountJson.put("maxHour", maxHour);
                 if (!Check.isNull(accountJson)) {
                 if (!Check.isNull(accountJson)) {
-                    JSONObject yesterdayJson = reportMapper.selectDayReport(anotherDay);
+                    JSONObject yesterdayJson = reportMapper.selectSumDayHourlyByHourAndDate(anotherDay, maxHourStr);
                     if (!Check.isNull(yesterdayJson)) {
                     if (!Check.isNull(yesterdayJson)) {
                         BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
                         BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
                         BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗
                         BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗