Parcourir la source

修改内容:调整代码结构

lth il y a 1 an
Parent
commit
dc96691857

+ 642 - 626
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/GameDataServiceImpl.java

@@ -564,217 +564,232 @@ public class GameDataServiceImpl implements IGameDataService {
     }
 
     /**
-     * 游戏每日数据SQL
-     *
-     * @return String
+     * 每日流水贡献
+     * @param dto 前端传递的查询参数
+     * @return 返回给前端的数据
      */
-    private String gameDataDaySql() {
-        return """
-                SELECT
-                    dt cost_date,
-                    game_name,
-                    game_classify,
-                                    
-                    buy_reg_num,
-                    nature_reg_num,
-                    reg_num,
-                        
-                    buy_first_new_user_amount_count,
-                    buy_first_new_user_amount_num,
-                    buy_first_new_user_amount,
-                    buy_old_user_count,
-                    buy_old_user_num,
-                    buy_old_user_amount,
-                    buy_amount_count,
-                    buy_amount_num,
-                    buy_amount,
-                    buy_new_user_total_amount_count,
-                    buy_new_user_total_amount_num,
-                    buy_new_user_total_amount,
-                    buy_first_roi,
-                    buy_today_roi,
-                    buy_new_user_rate,
-                    buy_first_avg_amount,
-                    buy_today_avg_amount,
-                    buy_avg_amount,
-                    buy_user_again_rate,
-                    buy_reg_user_arpu,
-                    buy_first_amount_arpu,
-                    buy_today_amount_arpu,
-                    buy_amount_arpu,
-                    buy_amount_d1,
-                    buy_amount_d3,
-                    buy_amount_d5,
-                    buy_amount_d7,
-                    buy_amount_d15,
-                    buy_amount_m1,
-                    buy_amount_m2,
-                    buy_amount_m3,
-                    buy_amount_m6,
-                    buy_amount_sum,
-                        
-                    nature_first_new_user_amount_count,
-                    nature_first_new_user_amount_num,
-                    nature_first_new_user_amount,
-                    nature_old_user_count,
-                    nature_old_user_num,
-                    nature_old_user_amount,
-                    nature_amount_count,
-                    nature_amount_num,
-                    nature_amount,
-                    nature_new_user_total_amount_count,
-                    nature_new_user_total_amount_num,
-                    nature_new_user_total_amount,
-                    nature_first_roi,
-                    nature_today_roi,
-                    nature_new_user_rate,
-                    nature_first_avg_amount,
-                    nature_today_avg_amount,
-                    nature_avg_amount,
-                    nature_user_again_rate,
-                    nature_reg_user_arpu,
-                    nature_first_amount_arpu,
-                    nature_today_amount_arpu,
-                    nature_amount_arpu,
-                    nature_amount_d1,
-                    nature_amount_d3,
-                    nature_amount_d5,
-                    nature_amount_d7,
-                    nature_amount_d15,
-                    nature_amount_m1,
-                    nature_amount_m2,
-                    nature_amount_m3,
-                    nature_amount_m6,
-                    nature_amount_sum,
-                        
-                    first_new_user_amount_count,
-                    first_new_user_amount_num,
-                    first_new_user_amount,
-                    old_user_count,
-                    old_user_num,
-                    old_user_amount,
-                    amount_count,
-                    amount_num,
-                    amount,
-                    new_user_total_amount_count,
-                    new_user_total_amount_num,
-                    new_user_total_amount,
-                    first_roi,
-                    today_roi,
-                    new_user_rate,
-                    first_avg_amount,
-                    today_avg_amount,
-                    avg_amount,
-                    user_again_rate,
-                    reg_user_arpu,
-                    first_amount_arpu,
-                    today_amount_arpu,
-                    amount_arpu,
-                    amount_d1,
-                    amount_d3,
-                    amount_d5,
-                    amount_d7,
-                    amount_d15,
-                    amount_m1,
-                    amount_m2,
-                    amount_m3,
-                    amount_m6,
-                    amount_sum
-                    
-                FROM
-                    ads_game_day
-                """;
+    @Override
+    public Page<GameDataWaterVO> getGameDataWater(GameDataWaterDTO dto) {
+        if (null == dto.getRechargeDate()) {
+            dto.setRechargeDate(LocalDate.now());
+        }
+        if (StringUtils.isBlank(dto.getSortFiled())) {
+            dto.setSortFiled("amount");
+        }
+        if (StringUtils.isBlank(dto.getSortType())) {
+            dto.setSortType(OrderByEnum.DESC.getOrderType());
+        }
+        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
+        // 创建一个 Criteria 接口实例
+        SimpleCriteria cri = Cnd.cri();
+        if (StringUtils.isNotBlank(dto.getGameName())) {
+            cri.where().andLike("game_name", dto.getGameName());
+        }
+        if (StringUtils.isNotBlank(dto.getGameClassify())) {
+            cri.where().andEquals("game_classify", dto.getGameClassify());
+        }
+        cri.where().and("dt", "=", dto.getRechargeDate());
+        cri.groupBy("game_id");
+        cri.orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
+        Sql sql = Sqls.queryEntity(waterSql() + "$condition");
+        sql.setPager(pager);
+        Entity<GameDataWaterVO> entity = dao.getEntity(GameDataWaterVO.class);
+        sql.setEntity(entity).setCondition(cri);
+        dao.execute(sql);
+
+        Sql sqlCount = Sqls.queryEntity("select count(*) from ads_everyday_water " + "$condition");
+        sqlCount.setCondition(cri);
+        pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
+
+        List<Long> gameIds = sql.getList(GameDataWaterVO.class).stream()
+                .map(GameDataWaterVO::getGameId)
+                .collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(gameIds)) {
+            return new Page<>();
+        }
+
+        SimpleCriteria templateCri = Cnd.cri();
+        templateCri.where().and("dt", "=", dto.getRechargeDate());
+        templateCri.where().andInList("game_id", gameIds);
+        Sql templateSql = Sqls.queryEntity(waterTemplateSql() + "$condition");
+        Entity<AdsEverydayWater> everydayWaterEntity = dao.getEntity(AdsEverydayWater.class);
+        templateSql.setEntity(everydayWaterEntity).setCondition(templateCri);
+        dao.execute(templateSql);
+
+        Map<Long, List<AdsEverydayWater>> collect = templateSql.getList(AdsEverydayWater.class).stream().collect(Collectors.groupingBy(AdsEverydayWater::getGameId));
+        List<GameDataWaterVO> result = sql.getList(GameDataWaterVO.class).stream()
+                .map(item -> {
+                    List<AdsEverydayWater> adsEverydayWaters = collect.get(item.getGameId());
+                    if (!CollectionUtils.isEmpty(adsEverydayWaters)) {
+                        List<RechargeTemplateVO> rechargeTemplateVOList = new ArrayList<>(10);
+
+                        List<PlayerTemplateVO> playerTemplateVOS = new ArrayList<>(10);
+                        adsEverydayWaters.forEach(adsEverydayWater -> {
+                            if (StringUtils.isNotBlank(adsEverydayWater.getAmountOrderBy())) {
+                                rechargeTemplateVOList.add(RechargeTemplateVO.builder()
+                                        .amountCount(adsEverydayWater.getAmountCount())
+                                        .amountNum(adsEverydayWater.getAmountNum())
+                                        .amountOrderBy(adsEverydayWater.getAmountOrderBy())
+                                        .amountPost(adsEverydayWater.getAmountPost())
+                                        .build());
+                            }
+                            if (StringUtils.isNotBlank(adsEverydayWater.getUserOrderBy())) {
+                                playerTemplateVOS.add(PlayerTemplateVO.builder()
+                                        .userId(adsEverydayWater.getUserId())
+                                        .userAmount(adsEverydayWater.getUserAmount())
+                                        .userOrderBy(adsEverydayWater.getUserOrderBy())
+                                        .userName(adsEverydayWater.getUserName())
+                                        .proportion(
+                                                item.getAmount().compareTo(BigDecimal.ZERO) == 0 ?
+                                                        BigDecimal.ZERO :
+                                                        adsEverydayWater.getUserAmount().divide(item.getAmount(), 4, RoundingMode.DOWN)
+                                        )
+                                        .build());
+                            }
+                        });
+                        item.setRechargeTemplateVOList(rechargeTemplateVOList);
+                        item.setPlayerTemplateVOS(playerTemplateVOS);
+                    }
+                    return item;
+                }).collect(Collectors.toList());
+
+        return new Page<>(result, pager);
     }
 
     /**
-     * 游戏总数据SQL
+     * 游戏每日复充数据
      *
-     * @return String
+     * @param dto 前端传递查询参数实体
+     * @return 返回给前端的数据
      */
-    private String gameDataTotalSql() {
-        return """
-                SELECT
-                    a.game_id game_id,
-                    a.game_name game_name,
-                    a.game_classify game_classify,
-                    
-                    sum(a.buy_reg_num) buy_reg_num,
-                    sum(a.nature_reg_num) nature_reg_num,
-                    sum(a.reg_num) reg_num,
-                    
-                    sum(a.buy_first_new_user_amount_count) buy_first_new_user_amount_count,
-                    sum(a.buy_first_new_user_amount_num) buy_first_new_user_amount_num,
-                    sum(a.buy_first_new_user_amount) buy_first_new_user_amount,
-                    sum(a.nature_first_new_user_amount_count) nature_first_new_user_amount_count,
-                    sum(a.nature_first_new_user_amount_num) nature_first_new_user_amount_num,
-                    sum(a.nature_first_new_user_amount) nature_first_new_user_amount,
-                    sum(a.first_new_user_amount_count) first_new_user_amount_count,
-                    sum(a.first_new_user_amount_num) first_new_user_amount_num,
-                    sum(a.first_new_user_amount) first_new_user_amount,
-                    
-                    sum(b.buy_amount_count) buy_amount_count,
-                    sum(b.buy_amount_num) buy_amount_num,
-                    sum(b.buy_amount) buy_amount,
-                    sum(b.nature_amount_count) nature_amount_count,
-                    sum(b.nature_amount_num) nature_amount_num,
-                    sum(b.nature_amount) nature_amount,
-                    sum(b.amount_count) amount_count,
-                    sum(b.amount_num) amount_num,
-                    sum(b.amount) amount,
-                    
-                    sum(a.buy_new_user_total_amount_count) buy_new_user_total_amount_count,
-                    sum(a.buy_new_user_total_amount_num) buy_new_user_total_amount_num,
-                    sum(a.buy_new_user_total_amount) buy_new_user_total_amount,
-                    sum(a.nature_new_user_total_amount_count) nature_new_user_total_amount_count,
-                    sum(a.nature_new_user_total_amount_num) nature_new_user_total_amount_num,
-                    sum(a.nature_new_user_total_amount) nature_new_user_total_amount,
-                    sum(a.new_user_total_amount_count) new_user_total_amount_count,
-                    sum(a.new_user_total_amount_num) new_user_total_amount_num,
-                    sum(a.new_user_total_amount) new_user_total_amount,
-                    
-                    round(if(sum(a.buy_reg_num) > 0 ,sum(a.buy_first_new_user_amount_num) / sum(a.buy_reg_num), 0), 4) buy_first_roi,
-                    round(if(sum(a.buy_reg_num) > 0, sum(a.buy_new_user_total_amount_num) / sum(a.buy_reg_num), 0), 4) buy_today_roi,
-                    round(if(sum(a.nature_reg_num) > 0 ,sum(a.nature_first_new_user_amount_num) / sum(a.nature_reg_num), 0), 4) nature_first_roi,
-                    round(if(sum(a.nature_reg_num) > 0, sum(a.nature_new_user_total_amount_num) / sum(a.nature_reg_num), 0), 4) nature_today_roi,
-                    round(if(sum(a.reg_num) > 0 ,sum(a.first_new_user_amount_num) / sum(a.reg_num), 0), 4) first_roi,
-                    round(if(sum(a.reg_num) > 0, sum(a.new_user_total_amount_num) / sum(a.reg_num), 0), 4) today_roi,
-                    
-                    round(if(sum(a.buy_first_new_user_amount_count) > 0, sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_count), 0), 2) buy_first_avg_amount,
-                    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), 2) buy_today_avg_amount,
-                    round(if(sum(b.buy_amount_count) > 0, sum(b.buy_amount) / sum(b.buy_amount_count), 0), 2) buy_avg_amount,
-                    round(if(sum(a.nature_first_new_user_amount_count) > 0, sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_count), 0), 2) nature_first_avg_amount,
-                    round(if(sum(a.nature_new_user_total_amount_count) > 0, sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_count), 0), 2) nature_today_avg_amount,
-                    round(if(sum(b.nature_amount_count) > 0, sum(b.nature_amount) / sum(b.nature_amount_count), 0), 2) nature_avg_amount,
-                    round(if(sum(a.first_new_user_amount_count) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_count), 0), 2) first_avg_amount,
-                    round(if(sum(a.new_user_total_amount_count) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_count), 0), 2) today_avg_amount,
-                    round(if(sum(b.amount_count) > 0, sum(b.amount) / sum(b.amount_count), 0), 2) avg_amount,
-                    
-                    round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_reg_order_user_again) / sum(a.buy_new_user_total_amount_num), 0), 4) buy_today_again_rate,
-                    round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_reg_order_user_again) / sum(a.nature_new_user_total_amount_num), 0), 4) nature_today_again_rate,
-                    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) today_again_rate,
-                    
-                    round(if(sum(a.buy_reg_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_reg_num), 0), 2) buy_reg_user_arpu,
-                    round(if(sum(a.buy_first_new_user_amount_num) > 0 , sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_num), 0), 2) buy_first_amount_arpu,
-                    round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_new_user_total_amount_num), 0), 2) buy_today_amount_arpu,
-                    round(if(sum(b.buy_amount_num) > 0 , sum(b.buy_amount) / sum(b.buy_amount_num), 0), 2) buy_amount_arpu,
-                    round(if(sum(a.nature_reg_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_reg_num), 0), 2) nature_reg_user_arpu,
-                    round(if(sum(a.nature_first_new_user_amount_num) > 0 , sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_num), 0), 2) nature_first_amount_arpu,
-                    round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_num), 0), 2) nature_today_amount_arpu,
-                    round(if(sum(b.nature_amount_num) > 0 , sum(b.nature_amount) / sum(b.nature_amount_num), 0), 2) nature_amount_arpu,
-                    round(if(sum(a.reg_num) > 0 , sum(a.new_user_total_amount) / sum(a.reg_num), 0), 2) reg_user_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), 2) first_amount_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), 2) today_amount_arpu,
-                    round(if(sum(b.amount_num) > 0 , sum(b.amount) / sum(b.amount_num), 0), 2) amount_arpu
-                FROM
-                    ads_game_day a
-                left join
-                    ads_game_day b
-                on
-                    a.game_name = b.game_name and
-                    a.game_id = b.game_id and
-                    a.game_classify = b.game_classify and
-                    (b.dt between @rechargeBeginDate and @rechargeEndDate)
-                """;
+    @Override
+    public Map<LocalDate, List<GameDataAgainDayVO>> getGameDataAgainDay(GameDataAgainDayDTO dto) {
+
+        //如果查询时间不传递默认从今天开始查询
+        if (dto.getBeginDate() == null) {
+            dto.setBeginDate(LocalDate.now());
+        }
+        //判断开始时间后的30天是否超过当前日期
+        if (dto.getBeginDate().plusDays(30).isAfter(LocalDate.now())) {
+            //只查询到当前的数据
+            dto.setEndDate(LocalDate.now());
+        } else {
+            //只考虑30天的数据
+            dto.setEndDate(dto.getBeginDate().plusDays(30));
+        }
+        //拼接查询条件
+        Criteria cri = Cnd.cri();
+        if (StringUtils.isNotBlank(dto.getGameName())) {
+            cri.where().andEquals("game_name", dto.getGameName());
+        }
+        if (dto.getBeginDate() != null) {
+            cri.where().andEquals("dt", dto.getBeginDate());
+            cri.where().andBetween("ddf", dto.getBeginDate(), dto.getEndDate());
+        }
+        //按 "ddf" 升序排序
+        cri.getOrderBy().asc("ddf");
+
+        //获取三张表的查询结果
+        List<AdsGameDayAgain> list = getListByTableType("total", cri);
+        List<AdsGameDayAgainBuy> listBuy = getListByTableType("buy", cri);
+        List<AdsGameDayAgainNature> listNature = getListByTableType("nature", cri);
+
+        log.info("list长度:" + list.size());
+        log.info("listBuy长度:" + listBuy.size());
+        log.info("listNature长度:" + listNature.size());
+
+
+        //创建Map记录数据
+        Map<LocalDate, List<GameDataAgainDayVO>> map = new HashMap<>();
+        //有序存储每个list,每个list包含当天的所有充值次数的复充数据
+        List<List<GameDataAgainDayVO>> tempList = new ArrayList<>();
+        //记录查询出的记录条数
+        int count = list.size();
+        //初始化list
+        initList(tempList, count);
+
+        //外层循环8次 表示不同复充次数的数据
+        for (int i = 0; i < 8; i++) {
+            //用来计算Ci
+            int ci = i + 1;
+            //第一天的所有充值次数都是先计算的
+            GameDataAgainDayVO tempVO = tempList.get(0).get(i);
+            //"原": Ci
+            tempList.get(0).get(i).setOriginal(getCnByNum(list.get(0), ci));
+            tempList.get(0).get(i).setBuyOriginal(getCnByNum(listBuy.get(0), ci));
+            tempList.get(0).get(i).setNatureOriginal(getCnByNum(listNature.get(0), ci));
+            //"增":初始为 0
+            tempList.get(0).get(i).setIncrease(BigInteger.ZERO);
+            tempList.get(0).get(i).setBuyIncrease(BigInteger.ZERO);
+            tempList.get(0).get(i).setNatureIncrease(BigInteger.ZERO);
+            //"移":下一个充值次数的Ci 即C(i+1)
+            tempList.get(0).get(i).setDecrease(getCnByNum(list.get(0), ci + 1));
+            tempList.get(0).get(i).setBuyDecrease(getCnByNum(listBuy.get(0), ci + 1));
+            tempList.get(0).get(i).setNatureDecrease(getCnByNum(listNature.get(0), ci + 1));
+            //"现":公式计算 = 原 + 增 - 移
+            tempList.get(0).get(i).setPresent(
+                    tempVO.getOriginal().add(tempVO.getIncrease()).subtract(tempVO.getDecrease())
+            );
+            tempList.get(0).get(i).setBuyPresent(
+                    tempVO.getBuyOriginal().add(tempVO.getBuyIncrease()).subtract(tempVO.getBuyDecrease())
+            );
+            tempList.get(0).get(i).setNaturePresent(
+                    tempVO.getNatureOriginal().add(tempVO.getNatureIncrease()).subtract(tempVO.getNatureDecrease())
+            );
+            //"比"
+            tempList.get(0).get(i).setRate(getCnByNum(list.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                    BigDecimal.valueOf(tempVO.getPresent().doubleValue() / getCnByNum(list.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
+            );
+            tempList.get(0).get(i).setBuyRate(getCnByNum(listBuy.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                    BigDecimal.valueOf(tempVO.getBuyPresent().doubleValue() / getCnByNum(listBuy.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
+            );
+            tempList.get(0).get(i).setNatureRate(getCnByNum(listNature.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                    BigDecimal.valueOf(tempVO.getNaturePresent().doubleValue() / getCnByNum(listNature.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
+            );
+
+            //计算第2-n天的数据 复充次数i的数据
+            for (int j = 1; j < count; j++) {
+                //"原":前一天的"现"
+                tempList.get(j).get(i).setOriginal(tempList.get(j - 1).get(i).getPresent());
+                tempList.get(j).get(i).setBuyOriginal(tempList.get(j - 1).get(i).getBuyPresent());
+                tempList.get(j).get(i).setNatureOriginal(tempList.get(j - 1).get(i).getNaturePresent());
+                //"现":当天的Ci - 当天的C(i+1)
+                tempList.get(j).get(i).setPresent(
+                        getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j), ci + 1)));
+                tempList.get(j).get(i).setBuyPresent(
+                        getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j), ci + 1)));
+                tempList.get(j).get(i).setNaturePresent(
+                        getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.get(j), ci + 1)));
+                //"增":当天的Ci - 前一天的Ci
+                tempList.get(j).get(i).setIncrease(
+                        getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j - 1), ci)));
+                tempList.get(j).get(i).setBuyIncrease(
+                        getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j - 1), ci)));
+                tempList.get(j).get(i).setNatureIncrease(
+                        getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.get(j - 1), ci)));
+                //"移":当天的C(i+1) - 前一天的C(i+1)
+                tempList.get(j).get(i).setDecrease(
+                        getCnByNum(list.get(j), ci + 1).subtract(getCnByNum(list.get(j - 1), ci + 1)));
+                tempList.get(j).get(i).setBuyDecrease(
+                        getCnByNum(listBuy.get(j), ci + 1).subtract(getCnByNum(listBuy.get(j - 1), ci + 1)));
+                tempList.get(j).get(i).setNatureDecrease(
+                        getCnByNum(listNature.get(j), ci + 1).subtract(getCnByNum(listNature.get(j - 1), ci + 1)));
+                //"比":当天的现 / 前一天的C1
+                tempList.get(j).get(i).setRate(getCnByNum(list.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                        BigDecimal.valueOf(tempList.get(j).get(i).getPresent().doubleValue() / getCnByNum(list.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
+                tempList.get(j).get(i).setBuyRate(getCnByNum(listBuy.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                        BigDecimal.valueOf(tempList.get(j).get(i).getBuyPresent().doubleValue() / getCnByNum(listBuy.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
+                tempList.get(j).get(i).setNatureRate(getCnByNum(listNature.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
+                        BigDecimal.valueOf(tempList.get(j).get(i).getNaturePresent().doubleValue() / getCnByNum(listNature.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
+            }
+        }
+        //赋值时间数据
+        for (int i = 0; i < tempList.size(); i++) {
+            map.put(list.get(i).getDdf(), tempList.get(i));
+        }
+
+        //返回数据
+        return map;
     }
 
     /**
@@ -788,13 +803,13 @@ public class GameDataServiceImpl implements IGameDataService {
         //构架SQL语句,查询相关DayN表获取相关充值数据
         Sql dayNSql = Sqls.create(
                 """
-                   SELECT
-                        dayN
-                   FROM
-                        $tableName
-                   where
-                        dt between @registerBeginDate and @registerEndDate
-                        and game_id = @gameId
+                SELECT
+                    dayN
+                FROM
+                    $tableName
+                where
+                    dt between @registerBeginDate and @registerEndDate
+                    and game_id = @gameId
                 """
         );
         //sql语句传入参数
@@ -860,459 +875,460 @@ public class GameDataServiceImpl implements IGameDataService {
     }
 
     /**
-     * DayN内部类
+     * 通过反射来获取Cn的值
+     * @param dto 数据库查询出来的原始数据对象实体
+     * @param num 1-9
+     * @return Cn
      */
-    @Data
-    @Builder
-    public static class DayN {
-        /**
-         * 充值金额
-         */
-        private BigDecimal rechargeMoney;
-
-        /**
-         * 充值次数
-         */
-        private BigInteger rechargeCount;
-
-        /**
-         * 充值人数
-         */
-        private BigInteger rechargeNum;
-
-        /**
-         * 新用户复充人数
-         */
-        private BigInteger rechargeAgainNum;
+    private BigInteger getCnByNum(Object dto, int num) {
+        try {
+            Method m1 = null;
+            //不同对象获取的方法不同
+            if (dto instanceof AdsGameDayAgain) {
+                m1 = AdsGameDayAgain.class.getDeclaredMethod(String.format("getC%s", num));
+            } else if (dto instanceof AdsGameDayAgainBuy) {
+                m1 = AdsGameDayAgainBuy.class.getDeclaredMethod(String.format("getBuyC%s", num));
+            } else if (dto instanceof AdsGameDayAgainNature) {
+                m1 = AdsGameDayAgainNature.class.getDeclaredMethod(String.format("getNatureC%s", num));
+            }
+            //返回对应的Cn值
+            return (BigInteger) m1.invoke(dto);
+        } catch (Exception e) {
+            throw new BaseException("发生错误");
+        }
     }
 
-    @Override
-    public Page<GameDataWaterVO> getGameDataWater(GameDataWaterDTO dto) {
-        if (null == dto.getRechargeDate()) {
-            dto.setRechargeDate(LocalDate.now());
-        }
-        if (StringUtils.isBlank(dto.getSortFiled())) {
-            dto.setSortFiled("amount");
-        }
-        if (StringUtils.isBlank(dto.getSortType())) {
-            dto.setSortType(OrderByEnum.DESC.getOrderType());
-        }
-        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
-        // 创建一个 Criteria 接口实例
-        SimpleCriteria cri = Cnd.cri();
-        if (StringUtils.isNotBlank(dto.getGameName())) {
-            cri.where().andLike("game_name", dto.getGameName());
+    /**
+     * 初始化List数据
+     * @param list 需要初始化的数据
+     * @param num 多少天的数据
+     */
+    private void initList(List<List<GameDataAgainDayVO>> list, Integer num) {
+        //外层循环 num 次 表示多少天的数据
+        for (int i = 0; i < num; i++) {
+            list.add(new ArrayList<>());
+            //内层循环8次 一共初始化8种复充次数数据对象
+            for (int j = 0; j < 8; j++) {
+                list.get(i).add(
+                        GameDataAgainDayVO.builder()
+                                .buyOriginal(BigInteger.ZERO)
+                                .buyPresent(BigInteger.ZERO)
+                                .buyIncrease(BigInteger.ZERO)
+                                .buyDecrease(BigInteger.ZERO)
+                                .buyRate(BigDecimal.ZERO)
+                                .natureOriginal(BigInteger.ZERO)
+                                .naturePresent(BigInteger.ZERO)
+                                .natureIncrease(BigInteger.ZERO)
+                                .natureDecrease(BigInteger.ZERO)
+                                .natureRate(BigDecimal.ZERO)
+                                .original(BigInteger.ZERO)
+                                .present(BigInteger.ZERO)
+                                .increase(BigInteger.ZERO)
+                                .decrease(BigInteger.ZERO)
+                                .rate(BigDecimal.ZERO)
+                                .build()
+                );
+            }
         }
-        if (StringUtils.isNotBlank(dto.getGameClassify())) {
-            cri.where().andEquals("game_classify", dto.getGameClassify());
-        }
-        cri.where().and("dt", "=", dto.getRechargeDate());
-        cri.groupBy("game_id");
-        cri.orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
-        Sql sql = Sqls.queryEntity(waterSql() + "$condition");
-        sql.setPager(pager);
-        Entity<GameDataWaterVO> entity = dao.getEntity(GameDataWaterVO.class);
-        sql.setEntity(entity).setCondition(cri);
-        dao.execute(sql);
-
-        Sql sqlCount = Sqls.queryEntity("select count(*) from ads_everyday_water " + "$condition");
-        sqlCount.setCondition(cri);
-        pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
-
-        List<Long> gameIds = sql.getList(GameDataWaterVO.class).stream()
-                .map(GameDataWaterVO::getGameId)
-                .collect(Collectors.toList());
-        if (CollectionUtils.isEmpty(gameIds)) {
-            return new Page<>();
-        }
-
-        SimpleCriteria templateCri = Cnd.cri();
-        templateCri.where().and("dt", "=", dto.getRechargeDate());
-        templateCri.where().andInList("game_id", gameIds);
-        Sql templateSql = Sqls.queryEntity(waterTemplateSql() + "$condition");
-        Entity<AdsEverydayWater> everydayWaterEntity = dao.getEntity(AdsEverydayWater.class);
-        templateSql.setEntity(everydayWaterEntity).setCondition(templateCri);
-        dao.execute(templateSql);
-
-        Map<Long, List<AdsEverydayWater>> collect = templateSql.getList(AdsEverydayWater.class).stream().collect(Collectors.groupingBy(AdsEverydayWater::getGameId));
-        List<GameDataWaterVO> result = sql.getList(GameDataWaterVO.class).stream()
-                .map(item -> {
-                    List<AdsEverydayWater> adsEverydayWaters = collect.get(item.getGameId());
-                    if (!CollectionUtils.isEmpty(adsEverydayWaters)) {
-                        List<RechargeTemplateVO> rechargeTemplateVOList = new ArrayList<>(10);
-
-                        List<PlayerTemplateVO> playerTemplateVOS = new ArrayList<>(10);
-                        adsEverydayWaters.forEach(adsEverydayWater -> {
-                            if (StringUtils.isNotBlank(adsEverydayWater.getAmountOrderBy())) {
-                                rechargeTemplateVOList.add(RechargeTemplateVO.builder()
-                                        .amountCount(adsEverydayWater.getAmountCount())
-                                        .amountNum(adsEverydayWater.getAmountNum())
-                                        .amountOrderBy(adsEverydayWater.getAmountOrderBy())
-                                        .amountPost(adsEverydayWater.getAmountPost())
-                                        .build());
-                            }
-                            if (StringUtils.isNotBlank(adsEverydayWater.getUserOrderBy())) {
-                                playerTemplateVOS.add(PlayerTemplateVO.builder()
-                                        .userId(adsEverydayWater.getUserId())
-                                        .userAmount(adsEverydayWater.getUserAmount())
-                                        .userOrderBy(adsEverydayWater.getUserOrderBy())
-                                        .userName(adsEverydayWater.getUserName())
-                                        .proportion(
-                                                item.getAmount().compareTo(BigDecimal.ZERO) == 0 ?
-                                                        BigDecimal.ZERO :
-                                                        adsEverydayWater.getUserAmount().divide(item.getAmount(), 4, RoundingMode.DOWN)
-                                        )
-                                        .build());
-                            }
-                        });
-                        item.setRechargeTemplateVOList(rechargeTemplateVOList);
-                        item.setPlayerTemplateVOS(playerTemplateVOS);
-                    }
-                    return item;
-                }).collect(Collectors.toList());
-
-        return new Page<>(result, pager);
-    }
-
-    private String waterSql() {
-        return """
-                select
-                game_id as id,
-                game_id,
-                max(game_name) as game_name,
-                max(game_classify) as game_classify,
-                max(amount) as amount,
-                max(buy_amount) as buy_amount,
-                max(nature_amount) as nature_amount
-                from ads_everyday_water
-                """;
-    }
-
-    private String waterTemplateSql() {
-        return """
-                select
-                game_id,
-                user_order_by,
-                user_id,
-                user_name,
-                user_amount,
-                amount_order_by,
-                amount_post,
-                amount_count,
-                amount_num
-                from ads_everyday_water
-                """;
     }
 
     /**
-     * 游戏每日复充数据
-     *
-     * @param dto 前端传递查询参数实体
-     * @return 返回给前端的数据
+     * 不同表获取不同的list结果
+     * @param tableName 表明
+     * @param cri 查询条件
+     * @return 查询结果
      */
-    @Override
-    public Map<LocalDate, List<GameDataAgainDayVO>> getGameDataAgainDay(GameDataAgainDayDTO dto) {
-
-        //如果查询时间不传递默认从今天开始查询
-        if (dto.getBeginDate() == null) {
-            dto.setBeginDate(LocalDate.now());
-        }
-        //判断开始时间后的30天是否超过当前日期
-        if (dto.getBeginDate().plusDays(30).isAfter(LocalDate.now())) {
-            //只查询到当前的数据
-            dto.setEndDate(LocalDate.now());
-        } else {
-            //只考虑30天的数据
-            dto.setEndDate(dto.getBeginDate().plusDays(30));
-        }
-        //拼接查询条件
-        Criteria cri = Cnd.cri();
-        if (StringUtils.isNotBlank(dto.getGameName())) {
-            cri.where().andEquals("game_name", dto.getGameName());
-        }
-        if (dto.getBeginDate() != null) {
-            cri.where().andEquals("dt", dto.getBeginDate());
-            cri.where().andBetween("ddf", dto.getBeginDate(), dto.getEndDate());
-        }
-        //按 "ddf" 升序排序
-        cri.getOrderBy().asc("ddf");
-
-        //获取三张表的查询结果
-        List<AdsGameDayAgain> list = getListByTableType("total", cri);
-        List<AdsGameDayAgainBuy> listBuy = getListByTableType("buy", cri);
-        List<AdsGameDayAgainNature> listNature = getListByTableType("nature", cri);
-
-        //创建Map记录数据
-        Map<LocalDate, List<GameDataAgainDayVO>> map = new HashMap<>();
-        //有序存储每个list,每个list包含当天的所有充值次数的复充数据
-        List<List<GameDataAgainDayVO>> tempList = new ArrayList<>();
-        //记录查询出的记录条数
-        Integer count = list.size();
-        //初始化list
-        initList(tempList, count);
-
-        //外层循环8次 表示不同复充次数的数据
-        for (int i = 0; i < 8; i++) {
-            //用来计算Ci
-            int ci = i + 1;
-            //第一天的所有充值次数都是先计算的
-            GameDataAgainDayVO tempVO = tempList.get(0).get(i);
-            //"原": Ci
-            tempList.get(0).get(i).setOriginal(getCnByNum(list.get(0), ci));
-            tempList.get(0).get(i).setBuyOriginal(getCnByNum(listBuy.get(0), ci));
-            tempList.get(0).get(i).setNatureOriginal(getCnByNum(listNature.get(0), ci));
-            //"增":初始为 0
-            tempList.get(0).get(i).setIncrease(BigInteger.ZERO);
-            tempList.get(0).get(i).setBuyIncrease(BigInteger.ZERO);
-            tempList.get(0).get(i).setNatureIncrease(BigInteger.ZERO);
-            //"移":下一个充值次数的Ci 即C(i+1)
-            tempList.get(0).get(i).setDecrease(getCnByNum(list.get(0), ci + 1));
-            tempList.get(0).get(i).setBuyDecrease(getCnByNum(listBuy.get(0), ci + 1));
-            tempList.get(0).get(i).setNatureDecrease(getCnByNum(listNature.get(0), ci + 1));
-            //"现":公式计算 = 原 + 增 - 移
-            tempList.get(0).get(i).setPresent(
-                    tempVO.getOriginal().add(tempVO.getIncrease()).subtract(tempVO.getDecrease())
-            );
-            tempList.get(0).get(i).setBuyPresent(
-                    tempVO.getBuyOriginal().add(tempVO.getBuyIncrease()).subtract(tempVO.getBuyDecrease())
-            );
-            tempList.get(0).get(i).setNaturePresent(
-                    tempVO.getNatureOriginal().add(tempVO.getNatureIncrease()).subtract(tempVO.getNatureDecrease())
-            );
-            //"比"
-            tempList.get(0).get(i).setRate(getCnByNum(list.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                    BigDecimal.valueOf(tempVO.getPresent().doubleValue() / getCnByNum(list.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
-            );
-            tempList.get(0).get(i).setBuyRate(getCnByNum(listBuy.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                    BigDecimal.valueOf(tempVO.getBuyPresent().doubleValue() / getCnByNum(listBuy.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
-            );
-            tempList.get(0).get(i).setNatureRate(getCnByNum(listNature.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                    BigDecimal.valueOf(tempVO.getNaturePresent().doubleValue() / getCnByNum(listNature.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
-            );
-
-            //计算第2-n天的数据 复充次数i的数据
-            for (int j = 1; j < count; j++) {
-                //"原":前一天的"现"
-                tempList.get(j).get(i).setOriginal(tempList.get(j - 1).get(i).getPresent());
-                tempList.get(j).get(i).setBuyOriginal(tempList.get(j - 1).get(i).getBuyPresent());
-                tempList.get(j).get(i).setNatureOriginal(tempList.get(j - 1).get(i).getNaturePresent());
-                //"现":当天的Ci - 当天的C(i+1)
-                tempList.get(j).get(i).setPresent(
-                        getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j), ci + 1)));
-                tempList.get(j).get(i).setBuyPresent(
-                        getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j), ci + 1)));
-                tempList.get(j).get(i).setNaturePresent(
-                        getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.get(j), ci + 1)));
-                //"增":当天的Ci - 前一天的Ci
-                tempList.get(j).get(i).setIncrease(
-                        getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j - 1), ci)));
-                tempList.get(j).get(i).setBuyIncrease(
-                        getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j - 1), ci)));
-                tempList.get(j).get(i).setNatureIncrease(
-                        getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.get(j - 1), ci)));
-                //"移":当天的C(i+1) - 前一天的C(i+1)
-                tempList.get(j).get(i).setDecrease(
-                        getCnByNum(list.get(j), ci + 1).subtract(getCnByNum(list.get(j - 1), ci + 1)));
-                tempList.get(j).get(i).setBuyDecrease(
-                        getCnByNum(listBuy.get(j), ci + 1).subtract(getCnByNum(listBuy.get(j - 1), ci + 1)));
-                tempList.get(j).get(i).setNatureDecrease(
-                        getCnByNum(listNature.get(j), ci + 1).subtract(getCnByNum(listNature.get(j - 1), ci + 1)));
-                //"比":当天的现 / 前一天的C1
-                tempList.get(j).get(i).setRate(getCnByNum(list.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                        BigDecimal.valueOf(tempList.get(j).get(i).getPresent().doubleValue() / getCnByNum(list.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
-                tempList.get(j).get(i).setBuyRate(getCnByNum(listBuy.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                        BigDecimal.valueOf(tempList.get(j).get(i).getBuyPresent().doubleValue() / getCnByNum(listBuy.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
-                tempList.get(j).get(i).setNatureRate(getCnByNum(listNature.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
-                        BigDecimal.valueOf(tempList.get(j).get(i).getNaturePresent().doubleValue() / getCnByNum(listNature.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
-            }
-        }
-        //赋值时间数据
-        for (int i = 0; i < tempList.size(); i++) {
-            map.put(list.get(i).getDdf(), tempList.get(i));
+    private List getListByTableType(String tableName, Criteria cri) {
+        //创建sql语句
+        Sql againSql;
+        //查询的结果封装到list中
+        List list = null;
+        //判断具体查询哪张表
+        if (tableName.equals("total")) {
+            againSql = Sqls.create(adsGameDataAgainSql() + cri);
+            //自定义回传对象
+            againSql.setCallback(Sqls.callback.entities());
+            againSql.setEntity(dao.getEntity(AdsGameDayAgain.class));
+            //执行sql
+            dao.execute(againSql);
+            //得到查询的原始结果
+            list = againSql.getList(AdsGameDayAgain.class);
+        } else if (tableName.equals("buy")) {
+            againSql = Sqls.create(adsGameDataAgainBuySql() + cri);
+            //自定义回传对象
+            againSql.setCallback(Sqls.callback.entities());
+            againSql.setEntity(dao.getEntity(AdsGameDayAgainBuy.class));
+            //执行sql
+            dao.execute(againSql);
+            //得到查询的原始结果
+            list = againSql.getList(AdsGameDayAgainBuy.class);
+        } else if (tableName.equals("nature")) {
+            againSql = Sqls.create(adsGameDataAgainNatureSql() + cri);
+            //自定义回传对象
+            againSql.setCallback(Sqls.callback.entities());
+            againSql.setEntity(dao.getEntity(AdsGameDayAgainNature.class));
+            //执行sql
+            dao.execute(againSql);
+            //得到查询的原始结果
+            list = againSql.getList(AdsGameDayAgainNature.class);
         }
+        //返回结果
+        return list;
+    }
 
-        //返回数据
-        return map;
+    /**
+     * 游戏每日数据SQL
+     * @return String
+     */
+    private String gameDataDaySql() {
+        return """
+                SELECT
+                    dt cost_date,
+                    game_name,
+                    game_classify,
+                                    
+                    buy_reg_num,
+                    nature_reg_num,
+                    reg_num,
+                        
+                    buy_first_new_user_amount_count,
+                    buy_first_new_user_amount_num,
+                    buy_first_new_user_amount,
+                    buy_old_user_count,
+                    buy_old_user_num,
+                    buy_old_user_amount,
+                    buy_amount_count,
+                    buy_amount_num,
+                    buy_amount,
+                    buy_new_user_total_amount_count,
+                    buy_new_user_total_amount_num,
+                    buy_new_user_total_amount,
+                    buy_first_roi,
+                    buy_today_roi,
+                    buy_new_user_rate,
+                    buy_first_avg_amount,
+                    buy_today_avg_amount,
+                    buy_avg_amount,
+                    buy_user_again_rate,
+                    buy_reg_user_arpu,
+                    buy_first_amount_arpu,
+                    buy_today_amount_arpu,
+                    buy_amount_arpu,
+                    buy_amount_d1,
+                    buy_amount_d3,
+                    buy_amount_d5,
+                    buy_amount_d7,
+                    buy_amount_d15,
+                    buy_amount_m1,
+                    buy_amount_m2,
+                    buy_amount_m3,
+                    buy_amount_m6,
+                    buy_amount_sum,
+                        
+                    nature_first_new_user_amount_count,
+                    nature_first_new_user_amount_num,
+                    nature_first_new_user_amount,
+                    nature_old_user_count,
+                    nature_old_user_num,
+                    nature_old_user_amount,
+                    nature_amount_count,
+                    nature_amount_num,
+                    nature_amount,
+                    nature_new_user_total_amount_count,
+                    nature_new_user_total_amount_num,
+                    nature_new_user_total_amount,
+                    nature_first_roi,
+                    nature_today_roi,
+                    nature_new_user_rate,
+                    nature_first_avg_amount,
+                    nature_today_avg_amount,
+                    nature_avg_amount,
+                    nature_user_again_rate,
+                    nature_reg_user_arpu,
+                    nature_first_amount_arpu,
+                    nature_today_amount_arpu,
+                    nature_amount_arpu,
+                    nature_amount_d1,
+                    nature_amount_d3,
+                    nature_amount_d5,
+                    nature_amount_d7,
+                    nature_amount_d15,
+                    nature_amount_m1,
+                    nature_amount_m2,
+                    nature_amount_m3,
+                    nature_amount_m6,
+                    nature_amount_sum,
+                        
+                    first_new_user_amount_count,
+                    first_new_user_amount_num,
+                    first_new_user_amount,
+                    old_user_count,
+                    old_user_num,
+                    old_user_amount,
+                    amount_count,
+                    amount_num,
+                    amount,
+                    new_user_total_amount_count,
+                    new_user_total_amount_num,
+                    new_user_total_amount,
+                    first_roi,
+                    today_roi,
+                    new_user_rate,
+                    first_avg_amount,
+                    today_avg_amount,
+                    avg_amount,
+                    user_again_rate,
+                    reg_user_arpu,
+                    first_amount_arpu,
+                    today_amount_arpu,
+                    amount_arpu,
+                    amount_d1,
+                    amount_d3,
+                    amount_d5,
+                    amount_d7,
+                    amount_d15,
+                    amount_m1,
+                    amount_m2,
+                    amount_m3,
+                    amount_m6,
+                    amount_sum
+                    
+                FROM
+                    ads_game_day
+                """;
     }
 
     /**
-     * 通过反射来获取Cn的值
-     * @param dto 数据库查询出来的原始数据对象实体
-     * @param num 1-9
-     * @return Cn
+     * 游戏总数据SQL
+     * @return String
      */
-    private BigInteger getCnByNum(Object dto, int num) {
-        try {
-            Method m1 = null;
-            //不同对象获取的方法不同
-            if (dto instanceof AdsGameDayAgain) {
-                m1 = AdsGameDayAgain.class.getDeclaredMethod(String.format("getC%s", num));
-            } else if (dto instanceof AdsGameDayAgainBuy) {
-                m1 = AdsGameDayAgainBuy.class.getDeclaredMethod(String.format("getBuyC%s", num));
-            } else if (dto instanceof AdsGameDayAgainNature) {
-                m1 = AdsGameDayAgainNature.class.getDeclaredMethod(String.format("getNatureC%s", num));
-            }
-            //返回对应的Cn值
-            return (BigInteger) m1.invoke(dto);
-        } catch (Exception e) {
-            throw new BaseException("发生错误");
-        }
+    private String gameDataTotalSql() {
+        return """
+                SELECT
+                    a.game_id game_id,
+                    a.game_name game_name,
+                    a.game_classify game_classify,
+                    
+                    sum(a.buy_reg_num) buy_reg_num,
+                    sum(a.nature_reg_num) nature_reg_num,
+                    sum(a.reg_num) reg_num,
+                    
+                    sum(a.buy_first_new_user_amount_count) buy_first_new_user_amount_count,
+                    sum(a.buy_first_new_user_amount_num) buy_first_new_user_amount_num,
+                    sum(a.buy_first_new_user_amount) buy_first_new_user_amount,
+                    sum(a.nature_first_new_user_amount_count) nature_first_new_user_amount_count,
+                    sum(a.nature_first_new_user_amount_num) nature_first_new_user_amount_num,
+                    sum(a.nature_first_new_user_amount) nature_first_new_user_amount,
+                    sum(a.first_new_user_amount_count) first_new_user_amount_count,
+                    sum(a.first_new_user_amount_num) first_new_user_amount_num,
+                    sum(a.first_new_user_amount) first_new_user_amount,
+                    
+                    sum(b.buy_amount_count) buy_amount_count,
+                    sum(b.buy_amount_num) buy_amount_num,
+                    sum(b.buy_amount) buy_amount,
+                    sum(b.nature_amount_count) nature_amount_count,
+                    sum(b.nature_amount_num) nature_amount_num,
+                    sum(b.nature_amount) nature_amount,
+                    sum(b.amount_count) amount_count,
+                    sum(b.amount_num) amount_num,
+                    sum(b.amount) amount,
+                    
+                    sum(a.buy_new_user_total_amount_count) buy_new_user_total_amount_count,
+                    sum(a.buy_new_user_total_amount_num) buy_new_user_total_amount_num,
+                    sum(a.buy_new_user_total_amount) buy_new_user_total_amount,
+                    sum(a.nature_new_user_total_amount_count) nature_new_user_total_amount_count,
+                    sum(a.nature_new_user_total_amount_num) nature_new_user_total_amount_num,
+                    sum(a.nature_new_user_total_amount) nature_new_user_total_amount,
+                    sum(a.new_user_total_amount_count) new_user_total_amount_count,
+                    sum(a.new_user_total_amount_num) new_user_total_amount_num,
+                    sum(a.new_user_total_amount) new_user_total_amount,
+                    
+                    round(if(sum(a.buy_reg_num) > 0 ,sum(a.buy_first_new_user_amount_num) / sum(a.buy_reg_num), 0), 4) buy_first_roi,
+                    round(if(sum(a.buy_reg_num) > 0, sum(a.buy_new_user_total_amount_num) / sum(a.buy_reg_num), 0), 4) buy_today_roi,
+                    round(if(sum(a.nature_reg_num) > 0 ,sum(a.nature_first_new_user_amount_num) / sum(a.nature_reg_num), 0), 4) nature_first_roi,
+                    round(if(sum(a.nature_reg_num) > 0, sum(a.nature_new_user_total_amount_num) / sum(a.nature_reg_num), 0), 4) nature_today_roi,
+                    round(if(sum(a.reg_num) > 0 ,sum(a.first_new_user_amount_num) / sum(a.reg_num), 0), 4) first_roi,
+                    round(if(sum(a.reg_num) > 0, sum(a.new_user_total_amount_num) / sum(a.reg_num), 0), 4) today_roi,
+                    
+                    round(if(sum(a.buy_first_new_user_amount_count) > 0, sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_count), 0), 2) buy_first_avg_amount,
+                    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), 2) buy_today_avg_amount,
+                    round(if(sum(b.buy_amount_count) > 0, sum(b.buy_amount) / sum(b.buy_amount_count), 0), 2) buy_avg_amount,
+                    round(if(sum(a.nature_first_new_user_amount_count) > 0, sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_count), 0), 2) nature_first_avg_amount,
+                    round(if(sum(a.nature_new_user_total_amount_count) > 0, sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_count), 0), 2) nature_today_avg_amount,
+                    round(if(sum(b.nature_amount_count) > 0, sum(b.nature_amount) / sum(b.nature_amount_count), 0), 2) nature_avg_amount,
+                    round(if(sum(a.first_new_user_amount_count) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_count), 0), 2) first_avg_amount,
+                    round(if(sum(a.new_user_total_amount_count) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_count), 0), 2) today_avg_amount,
+                    round(if(sum(b.amount_count) > 0, sum(b.amount) / sum(b.amount_count), 0), 2) avg_amount,
+                    
+                    round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_reg_order_user_again) / sum(a.buy_new_user_total_amount_num), 0), 4) buy_today_again_rate,
+                    round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_reg_order_user_again) / sum(a.nature_new_user_total_amount_num), 0), 4) nature_today_again_rate,
+                    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) today_again_rate,
+                    
+                    round(if(sum(a.buy_reg_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_reg_num), 0), 2) buy_reg_user_arpu,
+                    round(if(sum(a.buy_first_new_user_amount_num) > 0 , sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_num), 0), 2) buy_first_amount_arpu,
+                    round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_new_user_total_amount_num), 0), 2) buy_today_amount_arpu,
+                    round(if(sum(b.buy_amount_num) > 0 , sum(b.buy_amount) / sum(b.buy_amount_num), 0), 2) buy_amount_arpu,
+                    round(if(sum(a.nature_reg_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_reg_num), 0), 2) nature_reg_user_arpu,
+                    round(if(sum(a.nature_first_new_user_amount_num) > 0 , sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_num), 0), 2) nature_first_amount_arpu,
+                    round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_num), 0), 2) nature_today_amount_arpu,
+                    round(if(sum(b.nature_amount_num) > 0 , sum(b.nature_amount) / sum(b.nature_amount_num), 0), 2) nature_amount_arpu,
+                    round(if(sum(a.reg_num) > 0 , sum(a.new_user_total_amount) / sum(a.reg_num), 0), 2) reg_user_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), 2) first_amount_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), 2) today_amount_arpu,
+                    round(if(sum(b.amount_num) > 0 , sum(b.amount) / sum(b.amount_num), 0), 2) amount_arpu
+                FROM
+                    ads_game_day a
+                left join
+                    ads_game_day b
+                on
+                    a.game_name = b.game_name and
+                    a.game_id = b.game_id and
+                    a.game_classify = b.game_classify and
+                    (b.dt between @rechargeBeginDate and @rechargeEndDate)
+                """;
     }
 
     /**
-     * 初始化List数据
-     * @param list 需要初始化的数据
-     * @param num 多少天的数据
+     * 复充表sql(总量)
+     * @return String
      */
-    private void initList(List<List<GameDataAgainDayVO>> list, Integer num) {
-        //外层循环 num 次 表示多少天的数据
-        for (int i = 0; i < num; i++) {
-            list.add(new ArrayList<>());
-            //内层循环8次 一共初始化8中复充次数数据对象
-            for (int j = 0; j < 8; j++) {
-                list.get(i).add(
-                        GameDataAgainDayVO.builder()
-                                .buyOriginal(BigInteger.ZERO)
-                                .buyPresent(BigInteger.ZERO)
-                                .buyIncrease(BigInteger.ZERO)
-                                .buyDecrease(BigInteger.ZERO)
-                                .buyRate(BigDecimal.ZERO)
-                                .natureOriginal(BigInteger.ZERO)
-                                .naturePresent(BigInteger.ZERO)
-                                .natureIncrease(BigInteger.ZERO)
-                                .natureDecrease(BigInteger.ZERO)
-                                .natureRate(BigDecimal.ZERO)
-                                .original(BigInteger.ZERO)
-                                .present(BigInteger.ZERO)
-                                .increase(BigInteger.ZERO)
-                                .decrease(BigInteger.ZERO)
-                                .rate(BigDecimal.ZERO)
-                                .build()
-                );
-            }
-        }
+    private String adsGameDataAgainSql() {
+        return
+                """  
+                SELECT
+                    dt,
+                    ddf,
+                    game_id,
+                    game_name,
+                    c1,
+                    c2,
+                    c3,
+                    c4,
+                    c5,
+                    c6,
+                    c7,
+                    c8,
+                    c9
+                FROM
+                    ads_game_day_again
+                """;
     }
 
     /**
-     * 不同表获取不同的list结果
-     * @param tableName 表明
-     * @param cri 查询条件
-     * @return 查询结果
+     * 复充表sql(买量)
+     * @return String
      */
-    private List getListByTableType(String tableName, Criteria cri) {
-        //创建sql语句
-        Sql againSql;
-        //查询的结果封装到list中
-        List list = null;
-        //判断具体查询哪张表
-        if (tableName.equals("total")) {
-            againSql = Sqls.create(adsGameDataAgain() + cri);
-            //自定义回传对象
-            againSql.setCallback(Sqls.callback.entities());
-            againSql.setEntity(dao.getEntity(AdsGameDayAgain.class));
-            //执行sql
-            dao.execute(againSql);
-            //得到查询的原始结果
-            list = againSql.getList(AdsGameDayAgain.class);
-        } else if (tableName.equals("buy")) {
-            againSql = Sqls.create(adsGameDataAgainBuy() + cri);
-            //自定义回传对象
-            againSql.setCallback(Sqls.callback.entities());
-            againSql.setEntity(dao.getEntity(AdsGameDayAgainBuy.class));
-            //执行sql
-            dao.execute(againSql);
-            //得到查询的原始结果
-            list = againSql.getList(AdsGameDayAgainBuy.class);
-        } else if (tableName.equals("nature")) {
-            againSql = Sqls.create(adsGameDataAgainNature() + cri);
-            //自定义回传对象
-            againSql.setCallback(Sqls.callback.entities());
-            againSql.setEntity(dao.getEntity(AdsGameDayAgainNature.class));
-            //执行sql
-            dao.execute(againSql);
-            //得到查询的原始结果
-            list = againSql.getList(AdsGameDayAgainNature.class);
-        }
-        //返回结果
-        return list;
+    private String adsGameDataAgainBuySql() {
+        return
+                """  
+                SELECT
+                    dt,
+                    ddf,
+                    game_id,
+                    game_name,
+                    buy_c1,
+                    buy_c2,
+                    buy_c3,
+                    buy_c4,
+                    buy_c5,
+                    buy_c6,
+                    buy_c7,
+                    buy_c8,
+                    buy_c9
+                FROM
+                    ads_game_day_again_buy
+                """;
     }
 
     /**
-     * 复充表sql(总量)
-     * @return sql
+     * 复充表sql(自然量)
+     * @return String
      */
-    private String adsGameDataAgain() {
+    private String adsGameDataAgainNatureSql() {
         return
                 """  
-                    SELECT
-                        dt,
-                        ddf,
-                        game_id,
-                        game_name,
-                        c1,
-                        c2,
-                        c3,
-                        c4,
-                        c5,
-                        c6,
-                        c7,
-                        c8,
-                        c9
-                    FROM
-                        ads_game_day_again
+                SELECT
+                    dt,
+                    ddf,
+                    game_id,
+                    game_name,
+                    nature_c1,
+                    nature_c2,
+                    nature_c3,
+                    nature_c4,
+                    nature_c5,
+                    nature_c6,
+                    nature_c7,
+                    nature_c8,
+                    nature_c9
+                FROM
+                    ads_game_day_again_nature
                 """;
     }
 
     /**
-     * 复充表sql(买量)
-     * @return sql
+     * 流水sql
+     * @return String
      */
-    private String adsGameDataAgainBuy() {
-        return
-                """  
-                    SELECT
-                        dt,
-                        ddf,
-                        game_id,
-                        game_name,
-                        buy_c1,
-                        buy_c2,
-                        buy_c3,
-                        buy_c4,
-                        buy_c5,
-                        buy_c6,
-                        buy_c7,
-                        buy_c8,
-                        buy_c9
-                    FROM
-                        ads_game_day_again_buy
+    private String waterSql() {
+        return """
+                select
+                game_id as id,
+                game_id,
+                max(game_name) as game_name,
+                max(game_classify) as game_classify,
+                max(amount) as amount,
+                max(buy_amount) as buy_amount,
+                max(nature_amount) as nature_amount
+                from ads_everyday_water
                 """;
     }
 
     /**
-     * 复充表sql(自然量)
-     * @return sql
+     * 流水临时sql
+     * @return String
      */
-    private String adsGameDataAgainNature() {
-        return
-                """  
-                    SELECT
-                        dt,
-                        ddf,
-                        game_id,
-                        game_name,
-                        nature_c1,
-                        nature_c2,
-                        nature_c3,
-                        nature_c4,
-                        nature_c5,
-                        nature_c6,
-                        nature_c7,
-                        nature_c8,
-                        nature_c9
-                    FROM
-                        ads_game_day_again_nature
+    private String waterTemplateSql() {
+        return """
+                select
+                game_id,
+                user_order_by,
+                user_id,
+                user_name,
+                user_amount,
+                amount_order_by,
+                amount_post,
+                amount_count,
+                amount_num
+                from ads_everyday_water
                 """;
     }
 
+    /**
+     * DayN内部类
+     */
+    @Data
+    @Builder
+    public static class DayN {
+        /**
+         * 充值金额
+         */
+        private BigDecimal rechargeMoney;
+
+        /**
+         * 充值次数
+         */
+        private BigInteger rechargeCount;
+
+        /**
+         * 充值人数
+         */
+        private BigInteger rechargeNum;
+
+        /**
+         * 新用户复充人数
+         */
+        private BigInteger rechargeAgainNum;
+    }
+
 }