|
@@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -132,18 +133,16 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
|
|
|
@Override
|
|
|
public Page<GamePromoteTotalVO> accountAgentTotal(GamePromoteTotalDTO dto) {
|
|
|
- boolean hasRechargeDate = true;
|
|
|
Long sysUserId = SecurityUtil.isAdmin() ? null : SecurityUtil.getUserId();
|
|
|
sysUserId = null == dto.getSysUserId() ? sysUserId : dto.getSysUserId();
|
|
|
dto.setSysUserId(sysUserId);
|
|
|
- if (null == dto.getCostEndDay() || null == dto.getCostBeginDay()){
|
|
|
+ if (null == dto.getCostEndDay() || null == dto.getCostBeginDay()) {
|
|
|
dto.setCostBeginDay(LocalDate.now());
|
|
|
dto.setCostEndDay(LocalDate.now());
|
|
|
}
|
|
|
- if (null == dto.getRechargeEndDay() || null == dto.getRechargeBeginDay()){
|
|
|
- hasRechargeDate = false;
|
|
|
- dto.setRechargeEndDay(dto.getCostEndDay());
|
|
|
- dto.setRechargeBeginDay(dto.getCostBeginDay());
|
|
|
+ if (null == dto.getRechargeEndDay() || null == dto.getRechargeBeginDay()) {
|
|
|
+ dto.setRechargeEndDay(LocalDate.now());
|
|
|
+ dto.setRechargeBeginDay(LocalDate.now());
|
|
|
}
|
|
|
Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
// 创建一个 Criteria 接口实例
|
|
@@ -178,79 +177,93 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
sql.setPager(pager);
|
|
|
Entity<GamePromoteTotalVO> entity = dao.getEntity(GamePromoteTotalVO.class);
|
|
|
sql.setEntity(entity).setCondition(cri);
|
|
|
- sql.setParam("rechargeBeginDay",dto.getRechargeBeginDay());
|
|
|
- sql.setParam("rechargeEndDay",dto.getRechargeEndDay());
|
|
|
+ sql.setParam("rechargeBeginDay", dto.getRechargeBeginDay());
|
|
|
+ sql.setParam("rechargeEndDay", dto.getRechargeEndDay());
|
|
|
dao.execute(sql);
|
|
|
Sql sqlCount = Sqls.queryEntity("select count(*) from ads_account_agent_day a " + "$condition");
|
|
|
sqlCount.setCondition(cri);
|
|
|
- pager.setRecordCount((int) Daos.queryCount(dao,sqlCount));
|
|
|
+ pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
|
|
|
List<GamePromoteTotalVO> list = sql.getList(GamePromoteTotalVO.class);
|
|
|
|
|
|
//存在充值时间,获取表ads_dayn_amount的json数据
|
|
|
- if (hasRechargeDate) {
|
|
|
- Map<String, Object> dayNMap = new HashMap<>(4);
|
|
|
- dayNMap.put("beginDay", dto.getRechargeBeginDay());
|
|
|
- dayNMap.put("endDay", dto.getRechargeEndDay());
|
|
|
+ Map<String, Object> dayNMap = new HashMap<>(4);
|
|
|
+ dayNMap.put("beginDay", dto.getRechargeBeginDay());
|
|
|
+ dayNMap.put("endDay", dto.getRechargeEndDay());
|
|
|
|
|
|
- //循环总数据的每条数据
|
|
|
- List<GamePromoteTotalVO> hasRechargeDayList = list.stream().map(item -> {
|
|
|
- Sql sqlDayN = Sqls.queryString("select dayN from ads_dayn_amount where " +
|
|
|
- "dt>=@beginDay and dt<=@endDay " +
|
|
|
- "and account_id = @accountId " +
|
|
|
- "and agent_id = @agentId");
|
|
|
- dayNMap.put("accountId", item.getAccountId());
|
|
|
- dayNMap.put("agentId", item.getAgentId());
|
|
|
- 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);
|
|
|
+ //循环总数据的每条数据
|
|
|
+ List<GamePromoteTotalVO> hasRechargeDayList = list.stream().map(item -> {
|
|
|
+ Sql sqlDayN = Sqls.queryString("select dayN from ads_dayn_amount where " +
|
|
|
+ "dt>=@beginDay and dt<=@endDay " +
|
|
|
+ "and account_id = @accountId " +
|
|
|
+ "and agent_id = @agentId");
|
|
|
+ dayNMap.put("accountId", item.getAccountId());
|
|
|
+ dayNMap.put("agentId", item.getAgentId());
|
|
|
+ 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");
|
|
|
- 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]);
|
|
|
- String newValue = money + "-" + count + "-" + num;
|
|
|
- resultMap.put("dayN", newValue);
|
|
|
- }
|
|
|
+ Map<String, String> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("dayN", "0.00-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]);
|
|
|
+ String newValue = money + "-" + count + "-" + num;
|
|
|
+ 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]))
|
|
|
- .build();
|
|
|
- }
|
|
|
}
|
|
|
- //充值时间范围内存在充值数据
|
|
|
- if (null != dayN) {
|
|
|
- item.setUserRechargeMoney(dayN.getRechargeMoney());
|
|
|
- item.setUserRechargeCount(dayN.getRechargeCount());
|
|
|
- item.setUserRechargeUser(dayN.getRechargeNum());
|
|
|
-
|
|
|
- item.setOldUserRechargeMoney(item.getShowRechargeMoney().subtract(dayN.getRechargeMoney()));
|
|
|
- item.setOldUserRechargeCount(item.getShowRechargeCount() - dayN.getRechargeCount());
|
|
|
- item.setOldUserRechargeUser(item.getShowRechargeUser() - dayN.getRechargeNum());
|
|
|
+ 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]))
|
|
|
+ .build();
|
|
|
}
|
|
|
- return item;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return new Page<>(hasRechargeDayList, pager);
|
|
|
- }
|
|
|
- return new Page<>(list, pager);
|
|
|
+ }
|
|
|
+ //充值时间范围内存在充值数据
|
|
|
+ if (null != dayN) {
|
|
|
+ item.setUserRechargeMoney(dayN.getRechargeMoney());
|
|
|
+ item.setUserRechargeCount(dayN.getRechargeCount());
|
|
|
+ item.setUserRechargeUser(dayN.getRechargeNum());
|
|
|
+ item.setUserRechargeArpu(item.getUserRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO:item.getUserRechargeMoney().divide(BigDecimal.valueOf(item.getUserRechargeUser()),4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ item.setOldUserRechargeMoney(item.getShowRechargeMoney().subtract(item.getUserRechargeMoney()));
|
|
|
+ item.setOldUserRechargeCount(item.getShowRechargeCount() - item.getUserRechargeCount());
|
|
|
+ item.setOldUserRechargeUser(item.getShowRechargeUser() - item.getUserRechargeUser());
|
|
|
+
|
|
|
+ item.setRecoveryRate(item.getCost().compareTo(BigDecimal.ZERO) == 0 ?
|
|
|
+ BigDecimal.ZERO:item.getUserRechargeMoney().divide(item.getCost(),4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ item.setUserRechargeRate(item.getRegUserCount() == 0 ?
|
|
|
+ BigDecimal.ZERO:BigDecimal.valueOf(item.getUserRechargeUser()).divide(BigDecimal.valueOf(item.getRegUserCount()),4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ item.setNewUserRechargeRatio(item.getShowRechargeUser() == 0 ?
|
|
|
+ BigDecimal.ZERO:BigDecimal.valueOf(item.getUserRechargeUser()).divide(BigDecimal.valueOf(item.getShowRechargeUser()),4, RoundingMode.DOWN));
|
|
|
+
|
|
|
+ item.setAvgUserRecharge(item.getUserRechargeCount() == 0 ?
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return new Page<>(hasRechargeDayList, pager);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -489,7 +502,6 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
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,
|
|
|
- round(if(sum(a.cost) > 0, sum(a.buy_new_user_total_amount) / sum(a.cost), 0), 4) as buy_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,
|
|
@@ -500,14 +512,13 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
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.buy_new_user_total_amount_num) / sum(a.register_num), 0), 4) as buy_user_recharge_rate,
|
|
|
- round(if(sum(a.register_num) > 0, sum(a.new_user_total_amount_num) / sum(a.register_num), 0), 4) as new_user_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.buy_new_user_total_amount_count) > 0, sum(a.buy_new_user_total_amount) / sum(a.buy_new_user_total_amount_count), 0), 4) as avg_buy_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.amount_count) > 0, sum(a.amount) / sum(a.amount_count), 0), 4) as avg_show_user_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.buy_new_user_total_amount_num) > 0, sum(a.cost) / sum(a.buy_new_user_total_amount_num), 0), 4) as buy_user_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 repeat_recharge_rate,
|
|
|
+ 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.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,
|