|
@@ -3,10 +3,7 @@ package com.zanxiang.game.data.serve.service.impl;
|
|
|
import com.google.common.base.CaseFormat;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
-import com.zanxiang.game.data.serve.pojo.dto.AgentDayAgainDTO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.dto.GamePromoteDayDTO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.dto.GamePromoteDayTotalDTO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.dto.GamePromoteTotalDTO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.dto.*;
|
|
|
import com.zanxiang.game.data.serve.pojo.entity.AdsAccountAgentDay;
|
|
|
import com.zanxiang.game.data.serve.pojo.entity.AdsAgentDayAgain;
|
|
|
import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
@@ -72,8 +69,11 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
if (StringUtils.isNotBlank(dto.getAccountId())) {
|
|
|
cri.where().andEquals("account_id", dto.getAccountId());
|
|
|
}
|
|
|
- if (null != dto.getAgentId()) {
|
|
|
- cri.where().andEquals("agent_id", dto.getAgentId());
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountType())) {
|
|
|
+ cri.where().andEquals("account_type", dto.getAccountType());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getAgentId())) {
|
|
|
+ cri.where().andInList("agent_id", dto.getAgentId());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getCpName())) {
|
|
|
cri.where().andLike("game_cp", dto.getCpName());
|
|
@@ -216,8 +216,11 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
if (StringUtils.isNotBlank(dto.getAccountId())) {
|
|
|
cri.where().andEquals("account_id", dto.getAccountId());
|
|
|
}
|
|
|
- if (null != dto.getAgentId()) {
|
|
|
- cri.where().andEquals("agent_id", dto.getAgentId());
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountType())) {
|
|
|
+ cri.where().andEquals("account_type", dto.getAccountType());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getAgentId())) {
|
|
|
+ cri.where().andInList("agent_id", dto.getAgentId());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getCpName())) {
|
|
|
cri.where().andLike("game_cp", dto.getCpName());
|
|
@@ -276,8 +279,11 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
if (StringUtils.isNotBlank(dto.getAccountId())) {
|
|
|
cri.where().andEquals("a.account_id", dto.getAccountId());
|
|
|
}
|
|
|
- if (null != dto.getAgentId()) {
|
|
|
- cri.where().andEquals("a.agent_id", dto.getAgentId());
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountType())) {
|
|
|
+ cri.where().andEquals("account_type", dto.getAccountType());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getAgentId())) {
|
|
|
+ cri.where().andInList("agent_id", dto.getAgentId());
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(dto.getCpName())) {
|
|
|
cri.where().andLike("a.game_cp", dto.getCpName());
|
|
@@ -436,7 +442,7 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
BigDecimal.ZERO:item.getUserRechargeMoney().divide(BigDecimal.valueOf(item.getUserRechargeCount()),4, RoundingMode.DOWN));
|
|
|
|
|
|
item.setUserRechargeCost(item.getUserRechargeUser() == 0 ?
|
|
|
- BigDecimal.ZERO:item.getCost().divide(BigDecimal.valueOf(item.getUserRechargeUser()),4, RoundingMode.DOWN));
|
|
|
+ BigDecimal.ZERO:item.getCost().divide(BigDecimal.valueOf(item.getUserRechargeUser()),2, RoundingMode.DOWN));
|
|
|
|
|
|
item.setRepeatRechargeRate(item.getUserRechargeUser() == 0 ?
|
|
|
BigDecimal.ZERO:BigDecimal.valueOf(item.getRepeatRechargeUser()).divide(BigDecimal.valueOf(item.getUserRechargeUser()),4, RoundingMode.DOWN));
|
|
@@ -556,6 +562,217 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public GamePromoteTotalSumVO accountAgentTotalSum(GamePromoteTotalSumDTO dto) {
|
|
|
+ Long sysUserId = SecurityUtil.isAdmin() ? null : SecurityUtil.getUserId();
|
|
|
+ sysUserId = null == dto.getSysUserId() ? sysUserId : dto.getSysUserId();
|
|
|
+ dto.setSysUserId(sysUserId);
|
|
|
+ if (null == dto.getCostEndDay() || null == dto.getCostBeginDay()) {
|
|
|
+ dto.setCostBeginDay(LocalDate.now());
|
|
|
+ dto.setCostEndDay(LocalDate.now());
|
|
|
+ }
|
|
|
+ if (null == dto.getRechargeEndDay() || null == dto.getRechargeBeginDay()) {
|
|
|
+ dto.setRechargeEndDay(LocalDate.now());
|
|
|
+ dto.setRechargeBeginDay(LocalDate.now());
|
|
|
+ }
|
|
|
+ // 推广总计
|
|
|
+ SimpleCriteria cri = getSimpleCriteria(dto);
|
|
|
+ if (null != dto.getCostBeginDay()) {
|
|
|
+ cri.where().and("a.dt", ">=", dto.getCostBeginDay());
|
|
|
+ }
|
|
|
+ if (null != dto.getCostEndDay()) {
|
|
|
+ cri.where().and("a.dt", "<=", dto.getCostEndDay());
|
|
|
+ }
|
|
|
+ Sql sql = Sqls.queryEntity(accountAgentTotalSumSql() + "$condition");
|
|
|
+ Entity<GamePromoteTotalSumVO> entity = dao.getEntity(GamePromoteTotalSumVO.class);
|
|
|
+ sql.setEntity(entity).setCondition(cri);
|
|
|
+ dao.execute(sql);
|
|
|
+ GamePromoteTotalSumVO gamePromoteTotalSumVO = sql.getObject(GamePromoteTotalSumVO.class);
|
|
|
+
|
|
|
+ //账面总计
|
|
|
+ SimpleCriteria showCri = getSimpleCriteria(dto);
|
|
|
+ if (null != dto.getRechargeBeginDay()) {
|
|
|
+ showCri.where().and("a.dt", ">=", dto.getRechargeBeginDay());
|
|
|
+ }
|
|
|
+ if (null != dto.getRechargeEndDay()) {
|
|
|
+ showCri.where().and("a.dt", "<=", dto.getRechargeEndDay());
|
|
|
+ }
|
|
|
+ String show = """
|
|
|
+ select
|
|
|
+ ifnull(sum(a.amount_count),0) as show_recharge_count,
|
|
|
+ ifnull(sum(a.amount_num),0) as show_recharge_user,
|
|
|
+ ifnull(sum(a.amount),0) as show_recharge_money,
|
|
|
+ round(if(sum(a.amount_count) > 0, sum(a.amount) / sum(a.amount_count), 0), 4) as avg_show_user_recharge,
|
|
|
+ round(if(sum(a.amount_num) > 0, sum(a.amount) / sum(a.amount_num), 0), 4) as show_recharge_arpu
|
|
|
+ from
|
|
|
+ ads_account_agent_day a
|
|
|
+ """;
|
|
|
+ Sql showSql = Sqls.queryEntity(show + "$condition");
|
|
|
+ Entity<ShowRecharge> showEntity = dao.getEntity(ShowRecharge.class);
|
|
|
+ showSql.setEntity(showEntity).setCondition(showCri);
|
|
|
+ dao.execute(showSql);
|
|
|
+ ShowRecharge showRecharge = showSql.getObject(ShowRecharge.class);
|
|
|
+ if (null != showRecharge) {
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeArpu(showRecharge.showRechargeArpu);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeCount(showRecharge.getShowRechargeCount());
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeMoney(showRecharge.showRechargeMoney);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeUser(showRecharge.getShowRechargeUser());
|
|
|
+ gamePromoteTotalSumVO.setAvgShowUserRecharge(showRecharge.avgShowUserRecharge);
|
|
|
+ } else {
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeArpu(BigDecimal.ZERO);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeCount(0L);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeMoney(BigDecimal.ZERO);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeUser(0L);
|
|
|
+ gamePromoteTotalSumVO.setAvgShowUserRecharge(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // dayN总计
|
|
|
+ SimpleCriteria agentAccountCri = getSimpleCriteria(dto);
|
|
|
+ if (null != dto.getCostBeginDay()) {
|
|
|
+ agentAccountCri.where().and("a.dt", ">=", dto.getCostBeginDay());
|
|
|
+ }
|
|
|
+ if (null != dto.getCostEndDay()) {
|
|
|
+ agentAccountCri.where().and("a.dt", "<=", dto.getCostEndDay());
|
|
|
+ }
|
|
|
+ agentAccountCri.groupBy("a.account_id,a.agent_id,a.source_system");
|
|
|
+ Sql agentAccountSql = Sqls.queryEntity(accountAgentTotalSumDayNSql() + "$condition");
|
|
|
+ Entity<AgentAccount> agentAccountEntity = dao.getEntity(AgentAccount.class);
|
|
|
+ agentAccountSql.setEntity(agentAccountEntity).setCondition(agentAccountCri);
|
|
|
+ dao.execute(agentAccountSql);
|
|
|
+ List<AgentAccount> agentAccountList = agentAccountSql.getList(AgentAccount.class);
|
|
|
+ //渠道注册时间内的dayn充值数据,获取表ads_dayn_amount的json数据
|
|
|
+ Map<String, Object> dayNMap = new HashMap<>(4);
|
|
|
+ dayNMap.put("beginDay", dto.getCostBeginDay());
|
|
|
+ dayNMap.put("endDay", dto.getCostEndDay());
|
|
|
+ Sql sqlDayN = Sqls.queryString("""
|
|
|
+ select dayN
|
|
|
+ from ads_dayn_amount
|
|
|
+ where
|
|
|
+ dt>=@beginDay and dt<=@endDay
|
|
|
+ and account_id = @accountId
|
|
|
+ and agent_id = @agentId
|
|
|
+ and source_system = @sourceSystem
|
|
|
+ """);
|
|
|
+ DayN dayNTotal = agentAccountList.stream().map(item -> {
|
|
|
+ dayNMap.put("accountId", item.getAccountId());
|
|
|
+ dayNMap.put("agentId", item.getAgentId());
|
|
|
+ dayNMap.put("sourceSystem", item.getSourceSystem());
|
|
|
+ sqlDayN.setParams(dayNMap);
|
|
|
+ dao.execute(sqlDayN);
|
|
|
+ List<String> dayNList = sqlDayN.getList(String.class);
|
|
|
+ DayN dayN = null;
|
|
|
+ //ads_dayn_amount存在充值数据
|
|
|
+ if (!CollectionUtils.isEmpty(dayNList)) {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ List<Map<String, String>> jsonList = gson.fromJson(dayNList.toString(), ArrayList.class);
|
|
|
+
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("dayN", "0.00-0-0-0");
|
|
|
+ for (Map<String, String> jsonMap : jsonList) {
|
|
|
+ for (Map.Entry<String, String> entry : jsonMap.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ String[] parts = value.split("-");
|
|
|
+ if (DateUtil.parseLocalDate(key).compareTo(dto.getRechargeBeginDay()) >= 0
|
|
|
+ && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDay()) <= 0) {
|
|
|
+ String[] existingParts = resultMap.get("dayN").split("-");
|
|
|
+ BigDecimal money = new BigDecimal(existingParts[0]).add(new BigDecimal(parts[0]));
|
|
|
+ int count = Integer.parseInt(existingParts[1]) + Integer.parseInt(parts[1]);
|
|
|
+ int num = Integer.parseInt(existingParts[2]) + Integer.parseInt(parts[2]);
|
|
|
+ int repeatNum = Integer.parseInt(existingParts[3]) + Integer.parseInt(parts[3]);
|
|
|
+ String newValue = money + "-" + count + "-" + num + "-" + repeatNum;
|
|
|
+ resultMap.put("dayN", newValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
|
|
|
+ String[] parts = resultMap.get("dayN").split("-");
|
|
|
+ dayN = DayN.builder()
|
|
|
+ .rechargeMoney(new BigDecimal(parts[0]))
|
|
|
+ .rechargeCount(Long.valueOf(parts[1]))
|
|
|
+ .rechargeNum(Long.valueOf(parts[2]))
|
|
|
+ .repeatNum(Long.valueOf(parts[3]))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dayN;
|
|
|
+ }).filter(Objects::nonNull).reduce((accumulator, currentItem) -> {
|
|
|
+ // 如果 accumulator 为空,直接返回 currentItem
|
|
|
+ accumulator.setRechargeCount(accumulator.getRechargeCount() + currentItem.getRechargeCount());
|
|
|
+ accumulator.setRechargeMoney(accumulator.getRechargeMoney().add(currentItem.getRechargeMoney()));
|
|
|
+ accumulator.setRechargeNum(accumulator.getRechargeNum() + currentItem.getRechargeNum());
|
|
|
+ accumulator.setRepeatNum(accumulator.getRepeatNum() + currentItem.getRepeatNum());
|
|
|
+ // 其他字段相加的逻辑
|
|
|
+ return accumulator;
|
|
|
+ }).orElse(new DayN());
|
|
|
+
|
|
|
+ //充值时间范围内存在充值数据
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeMoney(dayNTotal.getRechargeMoney());
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeCount(dayNTotal.getRechargeCount());
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeUser(dayNTotal.getRechargeNum());
|
|
|
+ gamePromoteTotalSumVO.setRepeatRechargeUser(dayNTotal.getRepeatNum());
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeArpu(gamePromoteTotalSumVO.getUserRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO : gamePromoteTotalSumVO.getUserRechargeMoney().divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setOldUserRechargeMoney(gamePromoteTotalSumVO.getShowRechargeMoney().subtract(gamePromoteTotalSumVO.getUserRechargeMoney()));
|
|
|
+ gamePromoteTotalSumVO.setOldUserRechargeCount(gamePromoteTotalSumVO.getShowRechargeCount() - gamePromoteTotalSumVO.getUserRechargeCount());
|
|
|
+ gamePromoteTotalSumVO.setOldUserRechargeUser(gamePromoteTotalSumVO.getShowRechargeUser() - gamePromoteTotalSumVO.getUserRechargeUser());
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setRecoveryRate(gamePromoteTotalSumVO.getCost().compareTo(BigDecimal.ZERO) == 0 ?
|
|
|
+ BigDecimal.ZERO : gamePromoteTotalSumVO.getUserRechargeMoney().divide(gamePromoteTotalSumVO.getCost(), 4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeRate(gamePromoteTotalSumVO.getRegUserCount() == 0 ?
|
|
|
+ BigDecimal.ZERO : BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeUser()).divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getRegUserCount()), 4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setNewUserRechargeRatio(gamePromoteTotalSumVO.getShowRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO : BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeUser()).divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getShowRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setAvgUserRecharge(gamePromoteTotalSumVO.getUserRechargeCount() == 0 ?
|
|
|
+ BigDecimal.ZERO : gamePromoteTotalSumVO.getUserRechargeMoney().divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeCount()), 4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setUserRechargeCost(gamePromoteTotalSumVO.getUserRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO : gamePromoteTotalSumVO.getCost().divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeUser()), 2, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ gamePromoteTotalSumVO.setRepeatRechargeRate(gamePromoteTotalSumVO.getUserRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO : BigDecimal.valueOf(gamePromoteTotalSumVO.getRepeatRechargeUser()).divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getUserRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
+ gamePromoteTotalSumVO.setUserRepeatRechargeRate(gamePromoteTotalSumVO.getNewUserRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO : BigDecimal.valueOf(gamePromoteTotalSumVO.getRepeatRechargeUser()).divide(BigDecimal.valueOf(gamePromoteTotalSumVO.getNewUserRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
+ return gamePromoteTotalSumVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SimpleCriteria getSimpleCriteria(GamePromoteTotalSumDTO dto) {
|
|
|
+ SimpleCriteria cri = Cnd.cri();
|
|
|
+ // 组装条件
|
|
|
+ if (null != dto.getSysUserId()) {
|
|
|
+ cri.where().andEquals("a.pitcher_id", dto.getSysUserId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountId())) {
|
|
|
+ cri.where().andEquals("a.account_id", dto.getAccountId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getAccountType())) {
|
|
|
+ cri.where().andEquals("account_type", dto.getAccountType());
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getAgentId())) {
|
|
|
+ cri.where().andInList("agent_id", dto.getAgentId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getCpName())) {
|
|
|
+ cri.where().andLike("a.game_cp", dto.getCpName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
|
+ cri.where().andLike("a.game_name", dto.getGameName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameType())) {
|
|
|
+ cri.where().andEquals("a.game_type", dto.getGameType());
|
|
|
+ }
|
|
|
+ if (null != dto.getGameId()) {
|
|
|
+ cri.where().andEquals("a.game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+ cri.where().andEquals("a.source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ return cri;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化List数据
|
|
|
* @param list 需要初始化的数据
|
|
@@ -635,6 +852,7 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
source_system,
|
|
|
agent_id,
|
|
|
agent_name,
|
|
|
+ account_type,
|
|
|
account_id,
|
|
|
agent_id,
|
|
|
pitcher AS sys_user_name,
|
|
@@ -789,20 +1007,109 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
round(if(sum(first_new_user_amount_count) > 0, sum(first_new_user_amount) / sum(first_new_user_amount_count), 0), 4) as avg_first_user_recharge,
|
|
|
round(if(sum(buy_new_user_total_amount_count) > 0, sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_count), 0), 4) as avg_buy_user_recharge,
|
|
|
round(if(sum(amount_count) > 0, sum(amount) / sum(amount_count), 0), 4) as avg_show_user_recharge,
|
|
|
- round(if(sum(first_new_user_amount_num) > 0, sum(cost) / sum(first_new_user_amount_num), 0), 4) as first_recharge_cost,
|
|
|
- round(if(sum(buy_new_user_total_amount_num) > 0, sum(cost) / sum(buy_new_user_total_amount_num), 0), 4) as buy_user_recharge_cost,
|
|
|
+ round(if(sum(first_new_user_amount_num) > 0, sum(cost) / sum(first_new_user_amount_num), 0), 2) as first_recharge_cost,
|
|
|
+ round(if(sum(buy_new_user_total_amount_num) > 0, sum(cost) / sum(buy_new_user_total_amount_num), 0), 2) as buy_user_recharge_cost,
|
|
|
round(if(sum(new_user_total_amount_num) > 0, sum(reg_order_user_again) / sum(new_user_total_amount_num), 0), 4) as repeat_recharge_rate,
|
|
|
round(if(sum(register_num) > 0, sum(new_user_total_amount) / sum(register_num), 0), 4) as new_reg_arpu,
|
|
|
round(if(sum(first_new_user_amount_num) > 0, sum(first_new_user_amount) / sum(first_new_user_amount_num), 0), 4) as first_recharge_arpu,
|
|
|
round(if(sum(new_user_total_amount_num) > 0, sum(new_user_total_amount) / sum(new_user_total_amount_num), 0), 4) as today_recharge_arpu,
|
|
|
round(if(sum(amount_num) > 0, sum(amount) / sum(amount_num), 0), 4) as show_recharge_arpu,
|
|
|
sum(hundred_user_num) as hundred_user_num,
|
|
|
- round(if(sum(hundred_user_num) > 0, sum(cost) / sum(hundred_user_num), 0), 4) as hundred_user_num_cost
|
|
|
+ round(if(sum(hundred_user_num) > 0, sum(cost) / sum(hundred_user_num), 0), 2) as hundred_user_num_cost
|
|
|
from
|
|
|
ads_account_agent_day
|
|
|
""";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 推广总数据SQL
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String accountAgentTotalSumDayNSql() {
|
|
|
+ return """
|
|
|
+ select
|
|
|
+ a.source_system as source_system,
|
|
|
+ a.agent_id as agent_id,
|
|
|
+ a.account_id as account_id
|
|
|
+ from
|
|
|
+ ads_account_agent_day a
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推广总数据SQL
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String accountAgentTotalSumSql() {
|
|
|
+ return """
|
|
|
+ select
|
|
|
+ sum(a.cost) as cost,
|
|
|
+ sum(a.plan_count) as ad_plan_count,
|
|
|
+ sum(a.view_count) as view_count,
|
|
|
+ sum(a.click_count) as click_count,
|
|
|
+ sum(a.change_count) as convert_count,
|
|
|
+ round(if(sum(a.click_count) > 0, sum(a.change_count) / sum(a.click_count), 0), 4) as convert_rate,
|
|
|
+ round(if(sum(a.change_count) > 0, sum(a.cost) / sum(a.change_count), 0), 2) as avg_convert_cost,
|
|
|
+ sum(a.depth_change_count) as deep_convert_count,
|
|
|
+ round(if(sum(a.change_count) > 0, sum(a.depth_change_count) / sum(a.change_count), 0), 4) as deep_convert_rate,
|
|
|
+ round(if(sum(a.depth_change_count) > 0, sum(a.cost) / sum(a.depth_change_count), 0), 2) as deep_convert_cost,
|
|
|
+ round(if(sum(a.view_count) > 0, sum(a.cost) / sum(a.view_count) * 1000, 0), 2) as thousand_view_cost,
|
|
|
+ round(if(sum(a.view_count) > 0, sum(a.click_count) / sum(a.view_count), 0), 4) as click_rate,
|
|
|
+ round(if(sum(a.click_count) > 0, sum(a.cost) / sum(a.click_count), 0), 2) as avg_click_cost,
|
|
|
+ sum(a.download_start) as app_download_count,
|
|
|
+ round(if(sum(a.download_start) > 0, sum(a.cost) / sum(a.download_start), 0), 2) as app_download_cost,
|
|
|
+ round(if(sum(a.click_count) > 0, sum(a.download_start) / sum(a.click_count), 0), 4) as app_download_rate,
|
|
|
+ sum(a.download_finish) as download_finish,
|
|
|
+ round(if(sum(a.download_finish) > 0, sum(a.cost) / sum(a.download_finish), 0), 2) as download_finish_cost,
|
|
|
+ round(if(sum(a.download_start) > 0, sum(a.download_finish) / sum(a.download_start), 0), 4) as download_finish_rate,
|
|
|
+ sum(a.install_finish) as app_install_count,
|
|
|
+ round(if(sum(a.install_finish) > 0, sum(a.cost) / sum(a.install_finish), 0), 2) as app_install_cost,
|
|
|
+ round(if(sum(a.download_finish) > 0, sum(a.install_finish) / sum(a.download_finish), 0), 4) as app_install_rate,
|
|
|
+ sum(a.active) as app_active_count,
|
|
|
+ round(if(sum(a.active) > 0, sum(a.cost) / sum(a.active), 0), 2) as app_active_cost,
|
|
|
+ round(if(sum(a.click_count) > 0, sum(a.active) / sum(a.click_count), 0), 4) as app_active_rate,
|
|
|
+ sum(a.register_num) as reg_user_count,
|
|
|
+ round(if(sum(a.register_num) > 0, sum(a.cost) / sum(a.register_num), 0), 2) as reg_cost,
|
|
|
+ sum(a.first_new_user_amount_count) as first_user_recharge_count,
|
|
|
+ sum(a.first_new_user_amount_num) as first_user_recharge_user,
|
|
|
+ sum(a.first_new_user_amount) as first_user_recharge_money,
|
|
|
+ sum(a.first_new_user_amount_count) as user_recharge_count,
|
|
|
+ sum(a.first_new_user_amount_num) as user_recharge_user,
|
|
|
+ sum(a.first_new_user_amount) as user_recharge_money,
|
|
|
+ sum(a.old_amount_count) as old_user_recharge_count,
|
|
|
+ sum(a.old_amount_num) as old_user_recharge_user,
|
|
|
+ sum(a.old_amount) as old_user_recharge_money,
|
|
|
+ sum(a.new_user_total_amount_count) as new_user_recharge_count,
|
|
|
+ sum(a.new_user_total_amount_num) as new_user_recharge_user,
|
|
|
+ sum(a.new_user_total_amount) as new_user_recharge_money,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.first_new_user_amount) / sum(a.cost), 0), 4) as first_recovery_rate,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.new_user_total_amount) / sum(a.cost), 0), 4) as today_recovery_rate,
|
|
|
+ sum(a.gross_profit) as gross_margin,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_d3, '/', 1)) / sum(a.cost), 0), 4) as roi_day3,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_d5, '/', 1)) / sum(a.cost), 0), 4) as roi_day5,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_d7, '/', 1)) / sum(a.cost), 0), 4) as roi_day7,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_d15, '/', 1)) / sum(a.cost), 0), 4) as roi_day15,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_m1, '/', 1)) / sum(a.cost), 0), 4) as roi_day30,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_m2, '/', 1)) / sum(a.cost), 0), 4) as roi_day60,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_m6, '/', 1)) / sum(a.cost), 0), 4) as roi_day180,
|
|
|
+ round(if(sum(a.cost) > 0, sum(a.SPLIT_PART(a.amount_y1, '/', 1)) / sum(a.cost), 0), 4) as roi_year1,
|
|
|
+ round(if(sum(a.register_num) > 0, sum(a.first_new_user_amount_num) / sum(a.register_num), 0), 4) as first_recharge_rate,
|
|
|
+ round(if(sum(a.register_num) > 0, sum(a.new_user_total_amount_num) / sum(a.register_num), 0), 4) as today_recharge_rate,
|
|
|
+ round(if(sum(a.first_new_user_amount_count) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_count), 0), 4) as avg_first_user_recharge,
|
|
|
+ round(if(sum(a.new_user_total_amount_count) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_count), 0), 4) as avg_today_recharge,
|
|
|
+ round(if(sum(a.first_new_user_amount_num) > 0, sum(a.cost) / sum(a.first_new_user_amount_num), 0), 2) as first_recharge_cost,
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0, sum(a.cost) / sum(a.new_user_total_amount_num), 0), 2) as today_recharge_cost,
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0, sum(a.reg_order_user_again) / sum(a.new_user_total_amount_num), 0), 4) as today_repeat_recharge_rate,
|
|
|
+ round(if(sum(a.register_num) > 0, sum(a.new_user_total_amount) / sum(a.register_num), 0), 4) as new_reg_arpu,
|
|
|
+ round(if(sum(a.first_new_user_amount_num) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_num), 0), 4) as first_recharge_arpu,
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_num), 0), 4) as today_recharge_arpu,
|
|
|
+ sum(a.hundred_user_num) as hundred_user_num,
|
|
|
+ round(if(sum(a.hundred_user_num) > 0, sum(a.cost) / sum(a.hundred_user_num), 0), 2) as hundred_user_num_cost
|
|
|
+ from
|
|
|
+ ads_account_agent_day a
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 推广总数据SQL
|
|
|
* @return
|
|
@@ -876,26 +1183,28 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
round(if(sum(a.register_num) > 0, sum(a.new_user_total_amount_num) / sum(a.register_num), 0), 4) as today_recharge_rate,
|
|
|
round(if(sum(a.first_new_user_amount_count) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_count), 0), 4) as avg_first_user_recharge,
|
|
|
round(if(sum(a.new_user_total_amount_count) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_count), 0), 4) as avg_today_recharge,
|
|
|
- round(if(sum(a.first_new_user_amount_num) > 0, sum(a.cost) / sum(a.first_new_user_amount_num), 0), 4) as first_recharge_cost,
|
|
|
- round(if(sum(a.new_user_total_amount_num) > 0, sum(a.cost) / sum(a.new_user_total_amount_num), 0), 4) as today_recharge_cost,
|
|
|
+ round(if(sum(a.first_new_user_amount_num) > 0, sum(a.cost) / sum(a.first_new_user_amount_num), 0), 2) as first_recharge_cost,
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0, sum(a.cost) / sum(a.new_user_total_amount_num), 0), 2) as today_recharge_cost,
|
|
|
round(if(sum(a.new_user_total_amount_num) > 0, sum(a.reg_order_user_again) / sum(a.new_user_total_amount_num), 0), 4) as today_repeat_recharge_rate,
|
|
|
round(if(sum(a.register_num) > 0, sum(a.new_user_total_amount) / sum(a.register_num), 0), 4) as new_reg_arpu,
|
|
|
round(if(sum(a.first_new_user_amount_num) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_num), 0), 4) as first_recharge_arpu,
|
|
|
round(if(sum(a.new_user_total_amount_num) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_num), 0), 4) as today_recharge_arpu,
|
|
|
sum(a.hundred_user_num) as hundred_user_num,
|
|
|
- round(if(sum(a.hundred_user_num) > 0, sum(a.cost) / sum(a.hundred_user_num), 0), 4) as hundred_user_num_cost
|
|
|
+ round(if(sum(a.hundred_user_num) > 0, sum(a.cost) / sum(a.hundred_user_num), 0), 2) as hundred_user_num_cost
|
|
|
from
|
|
|
ads_account_agent_day a
|
|
|
""";
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
+ @NoArgsConstructor
|
|
|
+ @AllArgsConstructor
|
|
|
@Builder
|
|
|
public static class DayN{
|
|
|
- private BigDecimal rechargeMoney;
|
|
|
- private Long rechargeCount;
|
|
|
- private Long rechargeNum;
|
|
|
- private Long repeatNum;
|
|
|
+ private BigDecimal rechargeMoney = BigDecimal.ZERO;
|
|
|
+ private Long rechargeCount = 0L;
|
|
|
+ private Long rechargeNum = 0L;
|
|
|
+ private Long repeatNum = 0L;
|
|
|
}
|
|
|
|
|
|
@Data
|
|
@@ -913,4 +1222,16 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
|
|
|
private BigDecimal showRechargeArpu;
|
|
|
}
|
|
|
+
|
|
|
+ @Data
|
|
|
+ @NoArgsConstructor
|
|
|
+ @AllArgsConstructor
|
|
|
+ @Builder
|
|
|
+ public static class AgentAccount{
|
|
|
+ private String sourceSystem;
|
|
|
+
|
|
|
+ private Long accountId;
|
|
|
+
|
|
|
+ private Long agentId;
|
|
|
+ }
|
|
|
}
|