Prechádzať zdrojové kódy

数据查看计划列表数据保留2位小数点

yangzian 4 rokov pred
rodič
commit
1f34b30187

+ 3 - 2
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/entity/vo/ReportCostVo.java

@@ -15,6 +15,7 @@ public class ReportCostVo implements Serializable {
     private String id;
     //花费
     private double cost;
+    private String costStr;
     //展示量
     private Integer showNum;
     //点击量
@@ -34,9 +35,9 @@ public class ReportCostVo implements Serializable {
     //计划名称
     private String adName;
     //出价 - 目标转化出价
-    private BigDecimal cpaBid;
+    private String cpaBid;
     // 出价
-    private BigDecimal Bid;
+    private String Bid;
     //平均千次展显费用 = 总花费/展示数 * 1000
     private String averageShow;
     //平均点击单价 = 花费 / 点击数

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

@@ -34,5 +34,7 @@ public interface BytedanceAdvertiserHourlyReportMapper extends BaseMapper<Byteda
     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);
+    ////查询上阶段 同时间点的 时报 数据信息
+    List<ReportCostVo> selectReportPlanCostHourLast(@Param("accountId") String accountId,@Param("planId") String planId,@Param("startTime") String startTime, @Param("endTime") String endTime,@Param("statHour") Integer statHour);
 
 }

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

@@ -108,6 +108,35 @@
         ad_id,
         ad_name,
         create_time,
+        update_time,
+        stat_hour
+        FROM
+        ctop_bytedance_report_plan_hourly
+        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="selectReportPlanCostHourLast" resultType="org.jeecg.modules.bytedance.report.entity.vo.ReportCostVo">
+        SELECT
+        stat_datetime,
+        sum(cost) AS cost,
+        ad_id,
+        ad_name,
+        create_time,
         update_time
         FROM
         ctop_bytedance_report_plan_hourly
@@ -124,6 +153,9 @@
         <if test="endTime !=null and endTime != ''">
             and DATE_FORMAT(stat_datetime,'%Y-%m-%d') &lt;= #{endTime}
         </if>
+        <if test="statHour !=null and statHour != ''">
+            and stat_hour &lt;= #{statHour}
+        </if>
          GROUP BY ad_id
         ORDER BY cost DESC
 
@@ -133,10 +165,10 @@
     <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,
+        sum(show_num) AS showNum,
+        sum(click) AS click,
+        sum(convert_num) AS convertNum,
+        sum(cost) AS cost,
         ad_id,
         ad_name,
         create_time,

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

@@ -43,6 +43,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
 
     //时段数组
     private final static List<String> TIMES = Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23");
+    public static final String PATTEN_DEFAULT_YMD = "yyyy-MM-dd";
 
 
     @Resource
@@ -108,7 +109,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
         compare = (nowCost - lastCost) / lastCost;
         //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
-        resultMap.put("compare", Double.isNaN(compare) ? "0" : String.format("%.2f", compare*100));
+        resultMap.put("compare", new Double(lastCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
 
         //花费占比 = 花费 / 账户预算
         //获取账户预算
@@ -121,7 +122,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         double accountBudget = Check.isNull(strategy) ? lastCost : strategy.getAccountBudget().doubleValue();
         //花费占比
         double costShare = nowCost / accountBudget;
-        resultMap.put("costShare", Double.isNaN(costShare) ? "0" : df.format(costShare));
+        resultMap.put("costShare",new Double(accountBudget).intValue() == 0 ? "0" : df.format(costShare));
 
         //获取 本阶段  转化成本;转化数;转化率;平均千次展现费用。数据展示
         Map nowMap = getCost(nowCostList);
@@ -152,16 +153,16 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         //转化成本 = 总花费 / 转化数
         int converNum = list.stream().mapToInt(ReportCostVo::getConvertNum).sum();
         double conver = cost / new Double(converNum);
-        map.put("conver",Double.isNaN(conver) ? "0" : String.format("%.2f", conver));
+        map.put("conver",converNum == 0 ? "0" : String.format("%.2f", conver));
         map.put("converNum", converNum);
         //转化率 = 转化数 / 点击数 * 100
         int clickNum = list.stream().mapToInt(ReportCostVo::getClick).sum();
         double click = Double.valueOf(converNum) /  Double.valueOf(clickNum) * 100;
-        map.put("converRate", Double.isNaN(click) ? "0" : String.format("%.2f", click));
+        map.put("converRate", clickNum == 0 ? "0" : String.format("%.2f", click));
         // 平均千次展显费用 = 总花费/展示数 * 1000
         int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
         double show = (cost / showNum) * 1000 ;
-        map.put("averageShow", Double.isNaN(show) ? "0" : String.format("%.2f", show));
+        map.put("averageShow", showNum == 0 ? "0" : String.format("%.2f", show));
         return map;
     }
 
@@ -289,11 +290,16 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
      */
     @Override
     public Result getReportPlanCost(String accountId, String startTime, String endTime,Integer pageNum,Integer pageSize) throws Exception {
+        SimpleDateFormat sf = new SimpleDateFormat(PATTEN_DEFAULT_YMD);
         DecimalFormat df = new DecimalFormat("0.00%");
-        List<ReportCostVo> reportCostVoList = null;
+        DecimalFormat df1 = new DecimalFormat("0.00");
+        List<ReportCostVo> reportCostVoList = new ArrayList<ReportCostVo>();
+        List<ReportCostVo> lastReportCostVoList = new ArrayList<ReportCostVo>();
         //根据本阶段时间 获取 上阶段 开始-截至 时间
         Map<String,String> lastTimeMap = TimeStartAndEndUtil.getStartEndTime(startTime,endTime);
-        if (!lastTimeMap.get("daysBetween").equals("0")){
+        String nowTime = sf.format(new Date());
+
+        if (!startTime.equals(nowTime)){
             //日报
             PageHelper.startPage(pageNum,pageSize);
             reportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfoDay(accountId, null, startTime,endTime);
@@ -301,66 +307,78 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
             PageHelper.startPage(pageNum,pageSize);
             //时报
            reportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfo(accountId, null, startTime,endTime);
+
         }
 
-       reportCostVoList.forEach(reportCostVo -> {
-           //出价
-           QueryWrapper<ByteDanceAdvertisePlan> planQueryWrapper = new QueryWrapper<>();
-           planQueryWrapper.eq("account_id",accountId);
-           planQueryWrapper.last("limit 1");
-           ByteDanceAdvertisePlan planInfo = byteDanceAdvertisePlanMapper.selectOne(planQueryWrapper);
-           reportCostVo.setCpaBid(planInfo.getCpaBid());
-           reportCostVo.setBid(planInfo.getBid());
-
-           // 平均千次展显费用 = 总花费/展示数 * 1000
-           double show = 0;
-           if (reportCostVo.getShowNum() != 0){
-               show = (reportCostVo.getCost() / reportCostVo.getShowNum()) * 1000 ;
-           }
-           reportCostVo.setAverageShow(String.format("%.2f", show));
-
-           double avgClick = 0;
-           double clickRate = 0;
-           double convetRate = 0;
-           if (reportCostVo.getClick() != 0){
-               //平均点击单价 = 花费 / 点击数
-               avgClick = reportCostVo.getCost() / reportCostVo.getClick().doubleValue();
-               //点击率 = 点击数 / 展示数
-               clickRate = reportCostVo.getClick().doubleValue() / reportCostVo.getShowNum().doubleValue();
-               //转化率 = 转化数 / 点击数 * 100
-               convetRate = Double.valueOf(reportCostVo.getConvertNum()) /  Double.valueOf(reportCostVo.getClick()) * 100;
-           }
-
-           reportCostVo.setAverageClick(String.format("%.2f", avgClick));
-           reportCostVo.setClickRate(df.format(clickRate));
-           reportCostVo.setConverRate(String.format("%.2f", convetRate));
-
-           //转化成本 = 总花费 / 转化数
-           double conver = 0;
-           if (reportCostVo.getConvertNum() != 0){
-               conver = reportCostVo.getCost() / reportCostVo.getConvertNum();
-           }
-           reportCostVo.setConver(String.format("%.2f", conver));
-
-           // 计划id 和 上阶段 时间 查询 上阶段数据
-           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){
-                   //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
-                   compare = (reportCostVo.getCost() - lastReportCostVoList.get(0).getCost()) / lastReportCostVoList.get(0).getCost();
-               }
-           }
-           reportCostVo.setCompare(df.format(compare));
-
-           //操作状态
-           QueryWrapper<ByteDanceAdvertisePlan> advertisePlanQueryWrapper = new QueryWrapper<>();
-           advertisePlanQueryWrapper.eq("account_id",accountId);
-           advertisePlanQueryWrapper.eq("id",reportCostVo.getAdId());
-           advertisePlanQueryWrapper.last("limit 1");
-           ByteDanceAdvertisePlan advertisePlan = byteDanceAdvertisePlanMapper.selectOne(advertisePlanQueryWrapper);
-           reportCostVo.setOptStatus(advertisePlan.getOptStatus());
-       });
+        for (ReportCostVo reportCostVo : reportCostVoList) {
+            reportCostVo.setCostStr(String.format("%.2f",reportCostVo.getCost()));
+            //出价  ctop_bytedance_advertise_plan 广告计划信息表
+            QueryWrapper<ByteDanceAdvertisePlan> planQueryWrapper = new QueryWrapper<>();
+            planQueryWrapper.eq("account_id",accountId);
+            planQueryWrapper.eq("id",reportCostVo.getAdId());
+            planQueryWrapper.last("limit 1");
+            ByteDanceAdvertisePlan planInfo = byteDanceAdvertisePlanMapper.selectOne(planQueryWrapper);
+            reportCostVo.setCpaBid(String.format("%.2f",planInfo.getCpaBid()));
+            reportCostVo.setBid(String.format("%.2f",planInfo.getBid()));
+
+            // 平均千次展显费用 = 总花费/展示数 * 1000
+            double show = 0;
+            if (reportCostVo.getShowNum() != 0){
+                show = (reportCostVo.getCost() / reportCostVo.getShowNum()) * 1000 ;
+            }
+            reportCostVo.setAverageShow(String.format("%.2f", show));
+
+            double avgClick = 0;
+            double clickRate = 0;
+            double convetRate = 0;
+            if (reportCostVo.getClick() != 0){
+                //平均点击单价 = 花费 / 点击数
+                avgClick = reportCostVo.getCost() / reportCostVo.getClick().doubleValue();
+                //点击率 = 点击数 / 展示数
+                clickRate = reportCostVo.getClick().doubleValue() / reportCostVo.getShowNum().doubleValue();
+                //转化率 = 转化数 / 点击数 * 100
+                convetRate = Double.valueOf(reportCostVo.getConvertNum()) /  Double.valueOf(reportCostVo.getClick()) * 100;
+            }
+
+            reportCostVo.setAverageClick(String.format("%.2f", avgClick));
+            reportCostVo.setClickRate(df.format(clickRate));
+            reportCostVo.setConverRate(String.format("%.2f", convetRate));
+
+            //转化成本 = 总花费 / 转化数
+            double conver = 0;
+            if (reportCostVo.getConvertNum() != 0){
+                conver = reportCostVo.getCost() / reportCostVo.getConvertNum();
+            }
+            reportCostVo.setConver(String.format("%.2f", conver));
+
+            //日报
+            if (!startTime.equals(nowTime)){
+                // 计划id 和 上阶段 时间 查询 上阶段数据
+                lastReportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostInfoDay(accountId, reportCostVo.getAdId(), lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
+            }else {
+                //时报
+                // 获取当前时间 数据 最后的 时间点
+                ReportCostVo statHourVo = reportCostVoList.stream().max(Comparator.comparing(ReportCostVo::getStatHour)).get();
+                //查询上阶段 同时间点 之前的 时报 数据信息
+                lastReportCostVoList = bytedanceAdvertiserHourlyReportMapper.selectReportPlanCostHourLast(accountId,reportCostVo.getAdId(),lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),statHourVo.getStatHour());
+            }
+            double compare = 0;
+            if (lastReportCostVoList.size() > 0){
+                if (lastReportCostVoList.get(0).getCost() !=0){
+                    //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
+                    compare = (reportCostVo.getCost() - lastReportCostVoList.get(0).getCost()) / lastReportCostVoList.get(0).getCost();
+                }
+            }
+            reportCostVo.setCompare(df.format(compare));
+
+            //操作状态
+            QueryWrapper<ByteDanceAdvertisePlan> advertisePlanQueryWrapper = new QueryWrapper<>();
+            advertisePlanQueryWrapper.eq("account_id",accountId);
+            advertisePlanQueryWrapper.eq("id",reportCostVo.getAdId());
+            advertisePlanQueryWrapper.last("limit 1");
+            ByteDanceAdvertisePlan advertisePlan = byteDanceAdvertisePlanMapper.selectOne(advertisePlanQueryWrapper);
+            reportCostVo.setOptStatus(advertisePlan.getOptStatus());
+        }
         PageInfo<ReportCostVo> pageInfo = new PageInfo<ReportCostVo>(reportCostVoList);
         return Result.successMsg("成功。", pageInfo);
     }