|
@@ -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);
|
|
|
}
|