|
@@ -73,6 +73,8 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
DecimalFormat df = new DecimalFormat("0.00%");
|
|
|
Map<String,Object> resultMap = new HashMap<>();
|
|
|
double compare = 0;
|
|
|
+ double lastCost = 0;
|
|
|
+ double nowCost = 0;
|
|
|
List<ReportCostVo> nowCostList = new ArrayList<>();
|
|
|
List<ReportCostVo> lastCostList = new ArrayList<>();
|
|
|
|
|
@@ -88,34 +90,46 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
// 账户 日报 阶段 数据
|
|
|
nowCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,startTime,endTime);
|
|
|
lastCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
|
|
|
+ //当前阶段 总花费
|
|
|
+ nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ resultMap.put("nowCost", String.format("%.2f", nowCost));
|
|
|
+ //上阶段花费
|
|
|
+ lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ resultMap.put("lastCost", String.format("%.2f", lastCost));
|
|
|
+ //环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
|
|
|
+ compare = (nowCost - lastCost) / lastCost;
|
|
|
+ //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
|
|
|
+ resultMap.put("compare", new Double(lastCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
|
|
|
+
|
|
|
}else{
|
|
|
// 账户 当前时间段数据
|
|
|
nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,startTime,endTime);
|
|
|
+ //上阶段数据
|
|
|
+ lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),null);
|
|
|
+ //计算环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
|
|
|
+ //获取 同时段 的花费
|
|
|
ReportCostVo statHourVo = new ReportCostVo();
|
|
|
if (nowCostList.size() > 0){
|
|
|
statHourVo = nowCostList.get(nowCostList.size()-1);
|
|
|
}
|
|
|
- //上阶段数据
|
|
|
- lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),statHourVo.getTime());
|
|
|
+ List<ReportCostVo> compareCost = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),statHourVo.getTime());
|
|
|
+ double lastCompareCost = compareCost.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ //当前阶段 总花费
|
|
|
+ nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ resultMap.put("nowCost", String.format("%.2f", nowCost));
|
|
|
+ //上阶段花费
|
|
|
+ lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ resultMap.put("lastCost", String.format("%.2f", lastCost));
|
|
|
+ //环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
|
|
|
+ compare = (nowCost - lastCompareCost) / lastCompareCost;
|
|
|
+ //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
|
|
|
+ resultMap.put("compare", new Double(lastCompareCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
|
|
|
}
|
|
|
|
|
|
//更新时间
|
|
|
List<ReportCostVo> updTimeList = nowCostList.stream().sorted(Comparator.comparing(ReportCostVo::getCreateTime)).collect(Collectors.toList());
|
|
|
resultMap.put("updTime",Check.isNull(updTimeList) ? new Date() : updTimeList.get(0).getCreateTime());
|
|
|
|
|
|
- //当前阶段 总花费
|
|
|
- double nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
- resultMap.put("nowCost", String.format("%.2f", nowCost));
|
|
|
-
|
|
|
- //上阶段花费
|
|
|
- double lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
- resultMap.put("lastCost", String.format("%.2f", lastCost));
|
|
|
-
|
|
|
- //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
|
|
|
- compare = (nowCost - lastCost) / lastCost;
|
|
|
- //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
|
|
|
- resultMap.put("compare", new Double(lastCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
|
|
|
-
|
|
|
//花费占比 = 花费 / 账户预算
|
|
|
//获取账户预算
|
|
|
QueryWrapper<AiBytedanceAdvertiserStrategy> strategyQueryWrapper = new QueryWrapper<>();
|
|
@@ -148,10 +162,8 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
lastMap.put("costList",Arrays.asList());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
resultMap.put("nowMap", nowMap);
|
|
|
resultMap.put("lastMap", lastMap);
|
|
|
-
|
|
|
return Result.successMsg("成功。",resultMap);
|
|
|
}
|
|
|
|
|
@@ -225,6 +237,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
if (!Check.isNull(reduceList)){
|
|
|
reduceList.forEach(reduce ->{
|
|
|
ReportCostVo vo = new ReportCostVo();
|
|
|
+ vo.setStatDatetime(startTime);
|
|
|
vo.setTime(reduce);
|
|
|
vo.setConver("0");//转化成本
|
|
|
vo.setConvertNum(0);//转化数
|