|
@@ -1,11 +1,16 @@
|
|
|
package org.jeecg.modules.bytedance.report.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.modules.bytedance.advertise.entity.AiBytedanceAdvertiserStrategy;
|
|
|
+import org.jeecg.modules.bytedance.advertise.entity.ByteDanceAdvertisePlan;
|
|
|
import org.jeecg.modules.bytedance.advertise.entity.RuleDataAccount;
|
|
|
import org.jeecg.modules.bytedance.advertise.mapper.AiBytedanceAdvertiserStrategyMapper;
|
|
|
+import org.jeecg.modules.bytedance.advertise.mapper.ByteDanceAdvertisePlanMapper;
|
|
|
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;
|
|
@@ -18,10 +23,8 @@ 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;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 广告主小时级别报表信息
|
|
@@ -41,6 +44,9 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
@Resource
|
|
|
private AiBytedanceAdvertiserStrategyMapper aiBytedanceAdvertiserStrategyMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ByteDanceAdvertisePlanMapper byteDanceAdvertisePlanMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -117,6 +123,11 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取 数据
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public Map<String,Object> getCost(List<ReportCostVo> list){
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
@@ -138,12 +149,130 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
|
|
|
int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
|
|
|
double show = (cost / showNum) * 1000 ;
|
|
|
map.put("averageShow", String.format("%.2f", show));
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
- return map;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description:
|
|
|
+ *
|
|
|
+ * @param userId 当前登录用户id
|
|
|
+ * @param type 类型 kuaishou bytedance
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result initAccountIdAndTime(String userId, String type) throws Exception {
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Map<String,Object> resultMap = new HashMap<>();
|
|
|
+ Map<String,Object> map = bytedanceAdvertiserHourlyReportMapper.selAcountIdCostMax(userId,type);
|
|
|
+ resultMap.put("startTime", formatter.format(new Date()));
|
|
|
+ resultMap.put("endTime", formatter.format(new Date()));
|
|
|
+ resultMap.put("account", map);
|
|
|
+ return Result.successMsg("成功",resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 查询账户余额;花费
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getAccountCost(String accountId) throws Exception {
|
|
|
+
|
|
|
+ Map<String,Object> resultMap = new HashMap<>();
|
|
|
+ Map<String,Object> accountMap = bytedanceAdvertiserHourlyReportMapper.selectAccountCost(accountId);
|
|
|
+ //获取账户预算
|
|
|
+ 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) ? 0 : strategy.getAccountBudget();
|
|
|
+ resultMap.put("accountMap", accountMap);
|
|
|
+ resultMap.put("accountBudget", accountBudget);
|
|
|
+
|
|
|
+ return Result.successMsg("成功。", resultMap);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description:查询计划数据
|
|
|
+ *
|
|
|
+ * @param accountId 账户id
|
|
|
+ * @param startTime 开始时间
|
|
|
+ * @param endTime 结束时间
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getReportPlanCost(String accountId, String startTime, String endTime,Integer pageNum,Integer pageSize) throws Exception {
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00%");
|
|
|
+ //根据本阶段时间 获取 上阶段 开始-截至 时间
|
|
|
+ Map<String,String> lastTimeMap = TimeStartAndEndUtil.getStartEndTime(startTime,endTime);
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ //查询计划数据时报
|
|
|
+ List<ReportCostVo> 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());
|
|
|
+
|
|
|
+ // 平均千次展显费用 = 总花费/展示数 * 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();
|
|
|
+ //点击率 = 展示 / 点击数
|
|
|
+ clickRate = reportCostVo.getShowNum() / reportCostVo.getClick();
|
|
|
+ //转化率 = 转化数 / 点击数 * 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.selectReportPlanCostInfo(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));
|
|
|
+ });
|
|
|
+ PageInfo<ReportCostVo> pageInfo = new PageInfo<ReportCostVo>(reportCostVoList);
|
|
|
+ return Result.successMsg("成功。", pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|