|
@@ -36,6 +36,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -365,28 +366,74 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
dayNMap.put("endDay", dto.getCostEndDay());
|
|
|
|
|
|
String show = """
|
|
|
- select
|
|
|
- ifnull(sum(amount_count),0) as show_recharge_count,
|
|
|
- ifnull(sum(amount_num),0) as show_recharge_user,
|
|
|
- ifnull(sum(amount),0) as show_recharge_money,
|
|
|
- round(if(sum(amount_count) > 0, sum(amount) / sum(amount_count), 0), 4) as avg_show_user_recharge,
|
|
|
- round(if(sum(amount_num) > 0, sum(amount) / sum(amount_num), 0), 4) as show_recharge_arpu
|
|
|
- from
|
|
|
- ads_account_agent_day
|
|
|
- where
|
|
|
- source_system = @sourceSystem
|
|
|
- and agent_id = @agentId
|
|
|
- and account_id = @accountId
|
|
|
- and dt >= @rechargeBeginDay
|
|
|
- and dt <= @rechargeEndDay
|
|
|
- group by
|
|
|
- account_id,agent_id,source_system
|
|
|
- """;
|
|
|
+ select
|
|
|
+ ifnull(sum(a.amount_count), 0) as show_recharge_count,
|
|
|
+ (select count(distinct user_id) from ads_information
|
|
|
+ where
|
|
|
+ source_system = a.source_system
|
|
|
+ and agent_id = a.agent_id
|
|
|
+ and account_id = a.account_id
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay) 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
|
|
|
+ from
|
|
|
+ ads_account_agent_day a
|
|
|
+ where
|
|
|
+ a.source_system = @sourceSystem
|
|
|
+ and a.agent_id = @agentId
|
|
|
+ and a.account_id = @accountId
|
|
|
+ and a.dt >= @rechargeBeginDay
|
|
|
+ and a.dt <= @rechargeEndDay
|
|
|
+ group by
|
|
|
+ a.account_id,
|
|
|
+ a.agent_id,
|
|
|
+ a.source_system
|
|
|
+ """;
|
|
|
Sql showSql = Sqls.queryEntity(show);
|
|
|
Entity<ShowRecharge> showEntity = dao.getEntity(ShowRecharge.class);
|
|
|
showSql.setEntity(showEntity);
|
|
|
showSql.setParam("rechargeBeginDay", dto.getRechargeBeginDay());
|
|
|
showSql.setParam("rechargeEndDay", dto.getRechargeEndDay());
|
|
|
+
|
|
|
+ Map<String, Object> newUserNumMap = new HashMap<>(7);
|
|
|
+ newUserNumMap.put("costBeginDay", dto.getCostBeginDay());
|
|
|
+ newUserNumMap.put("costEndDay", dto.getCostEndDay());
|
|
|
+ newUserNumMap.put("rechargeBeginDay", dto.getRechargeBeginDay());
|
|
|
+ newUserNumMap.put("rechargeEndDay", dto.getRechargeEndDay());
|
|
|
+ Sql newUserNum = Sqls.fetchLong("""
|
|
|
+ select
|
|
|
+ count(DISTINCT user_id) as repeatNum
|
|
|
+ from
|
|
|
+ ads_information
|
|
|
+ where
|
|
|
+ source_system = @sourceSystem
|
|
|
+ and agent_id = @agentId
|
|
|
+ and account_id = @accountId
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay
|
|
|
+ and reg_time <= @costBeginDay
|
|
|
+ and reg_time <= @costEndDay
|
|
|
+ """);
|
|
|
+
|
|
|
+ Sql newUserRepeatNum = Sqls.fetchLong("""
|
|
|
+ SELECT count(*)
|
|
|
+ FROM
|
|
|
+ (select
|
|
|
+ count(user_id) as repeatNum
|
|
|
+ from
|
|
|
+ ads_information
|
|
|
+ where
|
|
|
+ source_system = @sourceSystem
|
|
|
+ and agent_id = @agentId
|
|
|
+ and account_id = @accountId
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay
|
|
|
+ and reg_time >= @costBeginDay
|
|
|
+ and reg_time <= @costEndDay
|
|
|
+ group by user_id) a
|
|
|
+ WHERE a.repeatNum > 1
|
|
|
+ """);
|
|
|
//循环总数据的每条数据
|
|
|
List<GamePromoteTotalVO> hasRechargeDayList = list.stream().map(item -> {
|
|
|
showSql.setParam("sourceSystem", item.getSourceSystem());
|
|
@@ -395,11 +442,12 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
dao.execute(showSql);
|
|
|
ShowRecharge showRecharge = showSql.getObject(ShowRecharge.class);
|
|
|
if (null != showRecharge){
|
|
|
- item.setShowRechargeArpu(showRecharge.showRechargeArpu);
|
|
|
+ item.setShowRechargeArpu(showRecharge.getShowRechargeUser() == 0 ? BigDecimal.ZERO :
|
|
|
+ showRecharge.getShowRechargeMoney().divide(new BigDecimal(showRecharge.getShowRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
item.setShowRechargeCount(showRecharge.getShowRechargeCount());
|
|
|
- item.setShowRechargeMoney(showRecharge.showRechargeMoney);
|
|
|
+ item.setShowRechargeMoney(showRecharge.getShowRechargeMoney());
|
|
|
item.setShowRechargeUser(showRecharge.getShowRechargeUser());
|
|
|
- item.setAvgShowUserRecharge(showRecharge.avgShowUserRecharge);
|
|
|
+ item.setAvgShowUserRecharge(showRecharge.getAvgShowUserRecharge());
|
|
|
}else {
|
|
|
item.setShowRechargeArpu(BigDecimal.ZERO);
|
|
|
item.setShowRechargeCount(0L);
|
|
@@ -409,7 +457,7 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
}
|
|
|
Sql sqlDayN = Sqls.queryString("""
|
|
|
select dayN
|
|
|
- from ads_dayn_amount
|
|
|
+ from ads_dayn_amount
|
|
|
where
|
|
|
dt>=@beginDay and dt<=@endDay
|
|
|
and account_id = @accountId
|
|
@@ -447,13 +495,24 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ newUserNumMap.put("accountId", item.getAccountId());
|
|
|
+ newUserNumMap.put("agentId", item.getAgentId());
|
|
|
+ newUserNumMap.put("sourceSystem", item.getSourceSystem());
|
|
|
+ newUserNum.setParams(newUserNumMap);
|
|
|
+ dao.execute(newUserNum);
|
|
|
+ Long newUserNumLong = newUserNum.getLong();
|
|
|
+
|
|
|
+ newUserRepeatNum.setParams(newUserNumMap);
|
|
|
+ dao.execute(newUserRepeatNum);
|
|
|
+ Long newUserRepeatNumLong = newUserRepeatNum.getLong();
|
|
|
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]))
|
|
|
+ .rechargeNum(newUserNumLong)
|
|
|
+ .repeatNum(newUserRepeatNumLong)
|
|
|
.build();
|
|
|
}
|
|
|
}
|
|
@@ -663,12 +722,25 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
showSql.setEntity(showEntity).setCondition(showCri);
|
|
|
dao.execute(showSql);
|
|
|
ShowRecharge showRecharge = showSql.getObject(ShowRecharge.class);
|
|
|
+
|
|
|
+ String showRechargeUser = """
|
|
|
+ select count(distinct user_id) from ads_information
|
|
|
+ where
|
|
|
+ source_system = @sourceSystem
|
|
|
+ and agent_id = @agentId
|
|
|
+ and account_id = @accountId
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay
|
|
|
+ """;
|
|
|
+ Sql showRechargeUserSql = Sqls.fetchLong(showRechargeUser);
|
|
|
+ showRechargeUserSql.setParam("rechargeBeginDay", dto.getRechargeBeginDay());
|
|
|
+ showRechargeUserSql.setParam("rechargeEndDay", dto.getRechargeEndDay());
|
|
|
if (null != showRecharge) {
|
|
|
- gamePromoteTotalSumVO.setShowRechargeArpu(showRecharge.showRechargeArpu);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeArpu(showRecharge.getShowRechargeArpu());
|
|
|
gamePromoteTotalSumVO.setShowRechargeCount(showRecharge.getShowRechargeCount());
|
|
|
- gamePromoteTotalSumVO.setShowRechargeMoney(showRecharge.showRechargeMoney);
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeMoney(showRecharge.getShowRechargeMoney());
|
|
|
gamePromoteTotalSumVO.setShowRechargeUser(showRecharge.getShowRechargeUser());
|
|
|
- gamePromoteTotalSumVO.setAvgShowUserRecharge(showRecharge.avgShowUserRecharge);
|
|
|
+ gamePromoteTotalSumVO.setAvgShowUserRecharge(showRecharge.getAvgShowUserRecharge());
|
|
|
} else {
|
|
|
gamePromoteTotalSumVO.setShowRechargeArpu(BigDecimal.ZERO);
|
|
|
gamePromoteTotalSumVO.setShowRechargeCount(0L);
|
|
@@ -695,6 +767,12 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
Map<String, Object> dayNMap = new HashMap<>(4);
|
|
|
dayNMap.put("beginDay", dto.getCostBeginDay());
|
|
|
dayNMap.put("endDay", dto.getCostEndDay());
|
|
|
+
|
|
|
+ Map<String, Object> newUserNumMap = new HashMap<>(7);
|
|
|
+ newUserNumMap.put("costBeginDay", dto.getCostBeginDay());
|
|
|
+ newUserNumMap.put("costEndDay", dto.getCostEndDay());
|
|
|
+ newUserNumMap.put("rechargeBeginDay", dto.getRechargeBeginDay());
|
|
|
+ newUserNumMap.put("rechargeEndDay", dto.getRechargeEndDay());
|
|
|
Sql sqlDayN = Sqls.queryString("""
|
|
|
select dayN
|
|
|
from ads_dayn_amount
|
|
@@ -704,7 +782,48 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
and agent_id = @agentId
|
|
|
and source_system = @sourceSystem
|
|
|
""");
|
|
|
+
|
|
|
+ Sql newUserNum = Sqls.fetchLong("""
|
|
|
+ select
|
|
|
+ count(DISTINCT user_id) as repeatNum
|
|
|
+ from
|
|
|
+ ads_information
|
|
|
+ where
|
|
|
+ source_system = @sourceSystem
|
|
|
+ and agent_id = @agentId
|
|
|
+ and account_id = @accountId
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay
|
|
|
+ and reg_time <= @costBeginDay
|
|
|
+ and reg_time <= @costEndDay
|
|
|
+ """);
|
|
|
+
|
|
|
+ Sql newUserRepeatNum = Sqls.fetchLong("""
|
|
|
+ SELECT count(*)
|
|
|
+ FROM
|
|
|
+ (select
|
|
|
+ count(user_id) as repeatNum
|
|
|
+ from
|
|
|
+ ads_information
|
|
|
+ where
|
|
|
+ source_system = @sourceSystem
|
|
|
+ and agent_id = @agentId
|
|
|
+ and account_id = @accountId
|
|
|
+ and order_time >= @rechargeBeginDay
|
|
|
+ and order_time <= @rechargeEndDay
|
|
|
+ and reg_time >= @costBeginDay
|
|
|
+ and reg_time <= @costEndDay
|
|
|
+ group by user_id) a
|
|
|
+ WHERE a.repeatNum > 1
|
|
|
+ """);
|
|
|
+ AtomicReference<Long> showRechargeUserNum = new AtomicReference<>(0L);
|
|
|
DayN dayNTotal = agentAccountList.stream().map(item -> {
|
|
|
+ showRechargeUserSql.setParam("sourceSystem", item.getSourceSystem());
|
|
|
+ showRechargeUserSql.setParam("agentId", item.getAgentId());
|
|
|
+ showRechargeUserSql.setParam("accountId", item.getAccountId());
|
|
|
+ dao.execute(showRechargeUserSql);
|
|
|
+ long showRechargeUserSqlLong = showRechargeUserSql.getLong();
|
|
|
+ showRechargeUserNum.set(showRechargeUserNum.get() + showRechargeUserSqlLong);
|
|
|
dayNMap.put("accountId", item.getAccountId());
|
|
|
dayNMap.put("agentId", item.getAgentId());
|
|
|
dayNMap.put("sourceSystem", item.getSourceSystem());
|
|
@@ -737,26 +856,38 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
}
|
|
|
}
|
|
|
if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
|
|
|
+ newUserNumMap.put("accountId", item.getAccountId());
|
|
|
+ newUserNumMap.put("agentId", item.getAgentId());
|
|
|
+ newUserNumMap.put("sourceSystem", item.getSourceSystem());
|
|
|
+ newUserNum.setParams(newUserNumMap);
|
|
|
+ dao.execute(newUserNum);
|
|
|
+ Long newUserNumLong = newUserNum.getLong();
|
|
|
+
|
|
|
+ newUserRepeatNum.setParams(newUserNumMap);
|
|
|
+ dao.execute(newUserRepeatNum);
|
|
|
+ Long newUserRepeatNumLong = newUserRepeatNum.getLong();
|
|
|
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]))
|
|
|
+ .rechargeNum(newUserNumLong)
|
|
|
+ .repeatNum(newUserRepeatNumLong)
|
|
|
.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.setShowRechargeUser(showRechargeUserNum.get());
|
|
|
+ gamePromoteTotalSumVO.setShowRechargeArpu(gamePromoteTotalSumVO.getShowRechargeUser() == 0 ? BigDecimal.ZERO :
|
|
|
+ gamePromoteTotalSumVO.getShowRechargeMoney().divide(new BigDecimal(gamePromoteTotalSumVO.getShowRechargeUser()), 4, RoundingMode.DOWN));
|
|
|
//充值时间范围内存在充值数据
|
|
|
gamePromoteTotalSumVO.setUserRechargeMoney(dayNTotal.getRechargeMoney());
|
|
|
gamePromoteTotalSumVO.setUserRechargeCount(dayNTotal.getRechargeCount());
|