yangzian пре 4 година
родитељ
комит
3dbdedecd9

+ 7 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/mapper/BytedanceAdvertiserHourlyReportMapper.java

@@ -20,12 +20,19 @@ public interface BytedanceAdvertiserHourlyReportMapper extends BaseMapper<Byteda
 
 
     List<ReportCostVo> getReportCostInfo(@Param("accountId") String accountId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    //账户日报 数据
+    List<ReportCostVo> selectPlanCostInfoCount(@Param("accountId") String accountId, @Param("planId") String planId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    //账户 时报
     List<ReportCostVo> getReportCostInfoStage(@Param("accountId") String accountId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
     Map<String,Object> selAcountIdCostMax(@Param("userId") String userId, @Param("type") String type);
 
     Map<String,Object> selectAccountCost(@Param("accountId") String accountId);
 
+    //计划日报
+    List<ReportCostVo> selectReportPlanCostInfoDay(@Param("accountId") String accountId, @Param("planId") String planId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+    //计划 时报
     List<ReportCostVo> selectReportPlanCostInfo(@Param("accountId") String accountId, @Param("planId") String planId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
 }

+ 72 - 7
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/mapper/xml/BytedanceAdvertiserHourlyReportMapper.xml

@@ -39,9 +39,8 @@
             SUM(show_num) AS showNum,
             SUM(click) AS click,
             SUM(convert_num) AS convertNum,
-            SUM(stat_hour) AS statHour,
             stat_datetime,
-            stat_datetime AS time,
+            stat_hour AS time,
             create_time
         FROM
             ctop_bytedance_report_advertiser_hourly
@@ -50,9 +49,10 @@
             AND stat_datetime &gt;= #{startTime}
             AND stat_datetime &lt;= #{endTime}
         GROUP BY
-            stat_datetime
+            stat_hour
         ORDER BY
-            stat_datetime
+            stat_datetime,
+            stat_hour
     </select>
 
 <!-- 查询用户下 花费最高的 账户-->
@@ -119,12 +119,77 @@
             and ad_id = #{planId}
         </if>
         <if test="startTime !=null and startTime != ''">
-            and stat_datetime &gt;= #{startTime}
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime !=null and endTime != ''">
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+         GROUP BY ad_id
+        ORDER BY cost DESC
+
+    </select>
+
+<!-- 查询 计划日报 数据-->
+    <select id="selectReportPlanCostInfoDay" resultType="org.jeecg.modules.bytedance.report.entity.vo.ReportCostVo">
+        SELECT
+        stat_datetime,
+        show_num AS showNum,
+        click AS click,
+        convert_num AS convertNum,
+        cost AS cost,
+        ad_id,
+        ad_name,
+        create_time,
+        update_time
+        FROM
+        ctop_bytedance_report_plan_daily
+        where 1 =1
+        <if test="accountId !=null and accountId != ''">
+            and advertiser_id = #{accountId}
+        </if>
+        <if test="planId !=null and planId != ''">
+            and ad_id = #{planId}
+        </if>
+        <if test="startTime !=null and startTime != ''">
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &gt;= #{startTime}
+        </if>
+        <if test="endTime !=null and endTime != ''">
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &lt;= #{endTime}
+        </if>
+        group BY ad_id
+        ORDER BY cost DESC
+
+    </select>
+
+
+
+    <!-- 查询 账户日报 数据 数据-->
+    <select id="selectPlanCostInfoCount" resultType="org.jeecg.modules.bytedance.report.entity.vo.ReportCostVo">
+        SELECT
+        stat_datetime,
+        sum(show_num) AS showNum,
+        sum(click) AS click,
+        sum(convert_num) AS convertNum,
+        sum(cost) AS cost,
+        DATE_FORMAT(stat_datetime,'%Y-%m-%d') AS time,
+        create_time,
+        update_time
+        FROM
+        ctop_bytedance_report_advertiser_daily
+        where 1 =1
+        <if test="accountId !=null and accountId != ''">
+            and advertiser_id = #{accountId}
+        </if>
+        <if test="planId !=null and planId != ''">
+            and ad_id = #{planId}
+        </if>
+        <if test="startTime !=null and startTime != ''">
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &gt;= #{startTime}
         </if>
         <if test="endTime !=null and endTime != ''">
-            and stat_datetime &lt;= #{endTime}
+            and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &lt;= #{endTime}
         </if>
-        GROUP BY ad_id
+        GROUP BY stat_datetime
         ORDER BY cost DESC
 
     </select>

+ 30 - 20
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/service/impl/BytedanceAdvertiserHourlyReportServiceImpl.java

@@ -74,8 +74,24 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         List<ReportCostVo> nowCostList = new ArrayList<>();
         List<ReportCostVo> lastCostList = new ArrayList<>();
 
-        //当前时间段数据
-        nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfo(accountId,startTime,endTime);
+
+        //根据本阶段时间 获取 上阶段 开始-截至 时间
+        Map<String,String> lastTimeMap = TimeStartAndEndUtil.getStartEndTime(startTime,endTime);
+
+        /**
+         * 日期相差不为 0 则 展示 日报(每天数据总和)数据
+         * 日期相差天数为0  则 展示 24小时 数据
+         */
+        if (!lastTimeMap.get("daysBetween").equals("0")){
+            // 账户 日报 阶段 数据
+            nowCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,startTime,endTime);
+            lastCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
+        }else{
+            // 账户 当前时间段数据
+            nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,startTime,endTime);
+            //上阶段数据
+            lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
+        }
 
         //更新时间
         List<ReportCostVo> updTimeList = nowCostList.stream().sorted(Comparator.comparing(ReportCostVo::getCreateTime)).collect(Collectors.toList());
@@ -85,10 +101,6 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         double nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
         resultMap.put("nowCost", String.format("%.2f", nowCost));
 
-        //根据本阶段时间 获取 上阶段 开始-截至 时间
-        Map<String,String> lastTimeMap = TimeStartAndEndUtil.getStartEndTime(startTime,endTime);
-        //上阶段数据
-        lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfo(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
         //上阶段花费
         double lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
         resultMap.put("lastCost", String.format("%.2f", lastCost));
@@ -116,15 +128,6 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         // 上阶段数据
         Map lastMap = getCost(lastCostList);
 
-        /**
-         * 日期相差不为 0 则 展示 时间段(每天数据总和)数据
-         * 日期相差天数为0  则 展示 24小时 数据
-         */
-        if (!lastTimeMap.get("daysBetween").equals("0")){
-            //阶段 数据
-          nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,startTime,endTime);
-          lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
-        }
         //当前阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
         nowMap.put("costList", getCostList(nowCostList,startTime,endTime,lastTimeMap.get("daysBetween")));
         //上个阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
@@ -133,7 +136,6 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         resultMap.put("nowMap", nowMap);
         resultMap.put("lastMap", lastMap);
 
-
         return Result.successMsg("成功。",resultMap);
     }
 
@@ -288,11 +290,19 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
     @Override
     public Result getReportPlanCost(String accountId, String startTime, String endTime,Integer pageNum,Integer pageSize) throws Exception {
         DecimalFormat df = new DecimalFormat("0.00%");
+        List<ReportCostVo> reportCostVoList = null;
         //根据本阶段时间 获取 上阶段 开始-截至 时间
         Map<String,String> lastTimeMap = TimeStartAndEndUtil.getStartEndTime(startTime,endTime);
-        PageHelper.startPage(pageNum,pageSize);
-        //查询计划数据时报
-       List<ReportCostVo> reportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfo(accountId, null, startTime,endTime);
+        if (!lastTimeMap.get("daysBetween").equals("0")){
+            //日报
+            PageHelper.startPage(pageNum,pageSize);
+            reportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfoDay(accountId, null, startTime,endTime);
+        }else {
+            PageHelper.startPage(pageNum,pageSize);
+            //时报
+           reportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfo(accountId, null, startTime,endTime);
+        }
+
        reportCostVoList.forEach(reportCostVo -> {
            //出价
            QueryWrapper<ByteDanceAdvertisePlan> planQueryWrapper = new QueryWrapper<>();
@@ -333,7 +343,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
            reportCostVo.setConver(String.format("%.2f", conver));
 
            // 计划id 和 上阶段 时间 查询 上阶段数据
-           List<ReportCostVo> lastReportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfo(accountId, reportCostVo.getAdId(), lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
+           List<ReportCostVo> lastReportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfoDay(accountId, reportCostVo.getAdId(), lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
            double compare = 0;
            if (lastReportCostVoList.size() > 0){
                if (lastReportCostVoList.get(0).getCost() !=0){