|
@@ -1,12 +1,28 @@
|
|
|
package org.jeecg.modules.bytedance.report.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.modules.bytedance.advertise.entity.AiBytedanceAdvertiserStrategy;
|
|
|
+import org.jeecg.modules.bytedance.advertise.entity.RuleDataAccount;
|
|
|
+import org.jeecg.modules.bytedance.advertise.mapper.AiBytedanceAdvertiserStrategyMapper;
|
|
|
+import org.jeecg.modules.bytedance.common.utils.Check;
|
|
|
import org.jeecg.modules.bytedance.report.entity.BytedanceAdvertiserHourlyReport;
|
|
|
+import org.jeecg.modules.bytedance.report.entity.vo.ReportCostVo;
|
|
|
import org.jeecg.modules.bytedance.report.mapper.BytedanceAdvertiserHourlyReportMapper;
|
|
|
import org.jeecg.modules.bytedance.report.service.IBytedanceAdvertiserHourlyReportService;
|
|
|
+import org.jeecg.modules.bytedance.report.utils.TimeStartAndEndUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 广告主小时级别报表信息
|
|
|
* @Author: jeecg-boot
|
|
@@ -18,4 +34,116 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<BytedanceAdvertiserHourlyReportMapper, BytedanceAdvertiserHourlyReport> implements IBytedanceAdvertiserHourlyReportService {
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BytedanceAdvertiserHourlyReportMapper bytedanceAdvertiserHourlyReportMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AiBytedanceAdvertiserStrategyMapper aiBytedanceAdvertiserStrategyMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description:
|
|
|
+ *
|
|
|
+ * @param accountId 账户id
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2021/5/19 16:56
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getReportYearOnYearCost(String accountId, String startTime, String endTime) throws Exception{
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00%");
|
|
|
+ Map<String,Object> resultMap = new HashMap<>();
|
|
|
+ double compare = 0;
|
|
|
+ List<ReportCostVo> nowCostList = new ArrayList<>();
|
|
|
+ List<ReportCostVo> lastCostList = new ArrayList<>();
|
|
|
+
|
|
|
+ //当前时间段数据
|
|
|
+ nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfo(accountId,startTime,endTime);
|
|
|
+ //当前阶段 总花费
|
|
|
+ double nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
|
|
|
+ resultMap.put("nowCost", 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", lastCost);
|
|
|
+
|
|
|
+ //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
|
|
|
+ compare = (nowCost - lastCost) / lastCost;
|
|
|
+ resultMap.put("compare", df.format(compare));
|
|
|
+
|
|
|
+ //花费占比 = 花费 / 账户预算
|
|
|
+ //获取账户预算
|
|
|
+ QueryWrapper<AiBytedanceAdvertiserStrategy> strategyQueryWrapper = new QueryWrapper<>();
|
|
|
+ strategyQueryWrapper.eq("account_id",accountId);
|
|
|
+ strategyQueryWrapper.eq("status",0);
|
|
|
+ strategyQueryWrapper.last("limit 1");
|
|
|
+ AiBytedanceAdvertiserStrategy strategy = aiBytedanceAdvertiserStrategyMapper.selectOne(strategyQueryWrapper);
|
|
|
+ //没有预算则使用上阶段花费
|
|
|
+ double accountBudget = Check.isNull(strategy) ? lastCost : strategy.getAccountBudget();
|
|
|
+ //花费占比
|
|
|
+ double costShare = nowCost / accountBudget;
|
|
|
+ resultMap.put("costShare", df.format(costShare));
|
|
|
+
|
|
|
+ //获取 本阶段 转化成本;转化数;转化率;平均千次展现费用。数据展示
|
|
|
+ Map nowMap = getCost(nowCostList);
|
|
|
+ // 上阶段数据
|
|
|
+ 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", nowCostList);
|
|
|
+ lastMap.put("costList", lastCostList);
|
|
|
+
|
|
|
+ resultMap.put("nowMap", nowMap);
|
|
|
+ resultMap.put("lastMap", lastMap);
|
|
|
+
|
|
|
+ return Result.successMsg("成功。",resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String,Object> getCost(List<ReportCostVo> list){
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ //花费
|
|
|
+ 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));
|
|
|
+ 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));
|
|
|
+
|
|
|
+ // 平均千次展显费用 = 总花费/展示数 * 1000
|
|
|
+ int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
|
|
|
+ double show = (cost / showNum) * 1000 ;
|
|
|
+ map.put("averageShow", String.format("%.2f", show));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|