|
@@ -26,6 +26,7 @@ import java.math.BigDecimal;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 广告主小时级别报表信息
|
|
@@ -39,6 +40,10 @@ import java.util.*;
|
|
|
public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<BytedanceAdvertiserHourlyReportMapper, BytedanceAdvertiserHourlyReport> implements IBytedanceAdvertiserHourlyReportService {
|
|
|
|
|
|
|
|
|
+ //时段数组
|
|
|
+ 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");
|
|
|
+
|
|
|
+
|
|
|
@Resource
|
|
|
private BytedanceAdvertiserHourlyReportMapper bytedanceAdvertiserHourlyReportMapper;
|
|
|
|
|
@@ -114,9 +119,9 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
|
|
|
}
|
|
|
//当前阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
|
|
|
- nowMap.put("costList", getCostList(nowCostList));
|
|
|
+ nowMap.put("costList", getCostList(nowCostList,startTime,endTime,lastTimeMap.get("daysBetween")));
|
|
|
//上个阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
|
|
|
- lastMap.put("costList", getCostList(lastCostList));
|
|
|
+ lastMap.put("costList", getCostList(lastCostList,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),lastTimeMap.get("daysBetween")));
|
|
|
|
|
|
resultMap.put("nowMap", nowMap);
|
|
|
resultMap.put("lastMap", lastMap);
|
|
@@ -135,41 +140,73 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
double cost = list.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
//转化成本 = 总花费 / 转化数
|
|
|
int converNum = list.stream().mapToInt(ReportCostVo::getConvertNum).sum();
|
|
|
- double conver = cost / converNum;
|
|
|
- map.put("conver", String.format("%.2f", conver));
|
|
|
+ double conver = cost / new Double(converNum);
|
|
|
+ map.put("conver",Double.isNaN(conver) ? "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", String.format("%.2f", click));
|
|
|
+ map.put("converRate", Double.isNaN(click) ? "0" : String.format("%.2f", click));
|
|
|
// 平均千次展显费用 = 总花费/展示数 * 1000
|
|
|
int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
|
|
|
double show = (cost / showNum) * 1000 ;
|
|
|
- map.put("averageShow", String.format("%.2f", show));
|
|
|
+ map.put("averageShow", Double.isNaN(show) ? "0" : String.format("%.2f", show));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
//获取 数据 (时间段)
|
|
|
- public List<ReportCostVo> getCostList(List<ReportCostVo> list){
|
|
|
+ public List<ReportCostVo> getCostList(List<ReportCostVo> list,String startTime,String endTime,String daysBetween){
|
|
|
list.forEach(reportCostVo -> {
|
|
|
//花费
|
|
|
double cost = reportCostVo.getCost();
|
|
|
//转化成本 = 总花费 / 转化数
|
|
|
int converNum = reportCostVo.getConvertNum();
|
|
|
double conver = cost / converNum;
|
|
|
- reportCostVo.setConver(String.format("%.2f", conver));
|
|
|
+ reportCostVo.setConver(converNum == 0 ? "0" : String.format("%.2f", conver));
|
|
|
reportCostVo.setConvertNum(converNum);
|
|
|
|
|
|
//转化率 = 转化数 / 点击数 * 100
|
|
|
int clickNum = reportCostVo.getClick();
|
|
|
double click = Double.valueOf(converNum) / Double.valueOf(clickNum) * 100;
|
|
|
- reportCostVo.setConverRate(String.format("%.2f", click));
|
|
|
+ reportCostVo.setConverRate(clickNum == 0 ? "0" : String.format("%.2f", click));
|
|
|
|
|
|
// 平均千次展显费用 = 总花费/展示数 * 1000
|
|
|
int showNum = reportCostVo.getShowNum();
|
|
|
double show = (cost / showNum) * 1000 ;
|
|
|
- reportCostVo.setAverageShow(String.format("%.2f", show));
|
|
|
+ reportCostVo.setAverageShow( showNum == 0 ? "0" : String.format("%.2f", show));
|
|
|
});
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间间隔为0 则表示获取当天数据 0-23时段
|
|
|
+ * 不为0 则表示 获取 开始-截至 时间 阶段数据
|
|
|
+ */
|
|
|
+ List<String> reduceList = new ArrayList<>();
|
|
|
+ if ("0".equals(daysBetween)){
|
|
|
+ //返回数据中 time 的集合
|
|
|
+ List<String> voTimes = list.stream().map(ReportCostVo::getTime).collect(Collectors.toList());
|
|
|
+ // 获取0-23时段 和 已有时段的 差集 (times - voTimes)
|
|
|
+ reduceList = TIMES.stream().filter(item -> !voTimes.contains(item)).collect(Collectors.toList());
|
|
|
+ }else {
|
|
|
+ // 获取两个日期之间 所有的 时间 年-月-日
|
|
|
+ List<String> betweenDaysList = TimeStartAndEndUtil.getAllDatesOfTwoTimes(startTime,endTime);
|
|
|
+ ////返回数据中 time 的集合
|
|
|
+ List<String> dayTimes = list.stream().map(ReportCostVo::getTime).collect(Collectors.toList());
|
|
|
+ //差集
|
|
|
+ reduceList = betweenDaysList.stream().filter(item -> !dayTimes.contains(item)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ //补充差集时段数据
|
|
|
+ if (!Check.isNull(reduceList)){
|
|
|
+ reduceList.forEach(reduce ->{
|
|
|
+ ReportCostVo vo = new ReportCostVo();
|
|
|
+ vo.setTime(reduce);
|
|
|
+ vo.setConver("0");//转化成本
|
|
|
+ vo.setConvertNum(0);//转化数
|
|
|
+ vo.setConverRate("0");//转化率
|
|
|
+ vo.setAverageShow("0");//平均前次展现费用
|
|
|
+ list.add(vo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Collections.sort(list,Comparator.comparing(ReportCostVo::getTime));
|
|
|
return list;
|
|
|
}
|
|
|
|