package com.zanxiang.game.data.serve.service.impl;

import com.google.common.base.CaseFormat;
import com.google.gson.Gson;
import com.zanxiang.game.data.serve.component.DataPowerComponent;
import com.zanxiang.game.data.serve.pojo.dto.*;
import com.zanxiang.game.data.serve.pojo.entity.*;
import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
import com.zanxiang.game.data.serve.pojo.vo.*;
import com.zanxiang.game.data.serve.service.IGameDataService;
import com.zanxiang.game.data.serve.utils.Page;
import com.zanxiang.module.util.DateUtil;
import com.zanxiang.module.util.exception.BaseException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.Daos;
import org.nutz.dao.util.cri.SimpleCriteria;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

import javax.annotation.Resource;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author tianhua
 * @time 2023/7/12
 * @Description 游戏数据逻辑处理
 **/
@Service
@Slf4j
public class GameDataServiceImpl implements IGameDataService {

    @Lazy
    @Resource
    private IGameDataService basicService;


    //用来存储映射
    private static final List<Tuple2<Field, Field>> dayNFieldMapList;
    private static final List<Tuple2<Field, Field>> dayNTotalFieldMapList;
    private static final List<Tuple2<Field, Field>> firstNewUserAgainFieldMapList;
    private static final List<Tuple2<Field, Field>> firstNewUserAgainTotalFieldMapList;

    static {
        //解析游戏每日数据dayN映射
        Map<String, Field> fieldMap = new HashMap<>();
        List<Field> dayNFieldList = new ArrayList<>();
        Class<?> tempClazz = GameDataDayVO.class;
        while (tempClazz != null) {
            Field[] fields = tempClazz.getDeclaredFields();
            for (Field field : fields) {
                if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                    continue;
                }
                fieldMap.put(field.getName(), field);
                if (field.getType() == RechargeTrendVO.class) {
                    dayNFieldList.add(field);
                }
            }
            tempClazz = tempClazz.getSuperclass();
        }
        if (dayNFieldList.isEmpty()) {
            dayNFieldMapList = Collections.emptyList();
        } else {
            dayNFieldMapList = new ArrayList<>(dayNFieldList.size());
            for (Field dayNField : dayNFieldList) {
                dayNField.setAccessible(true);
                Field sourceField = fieldMap.get(dayNField.getName().replace("Trend", ""));
                sourceField.setAccessible(true);
                if (sourceField != null) {
                    dayNFieldMapList.add(Tuples.of(sourceField, dayNField));
                }
            }
        }
        //解析游戏每日总计dayN映射
        Map<String, Field> fieldTotalMap = new HashMap<>();
        List<Field> dayNTotalFieldList = new ArrayList<>();
        Class<?> tempTotalClazz = GameDataDayTotalVO.class;
        while (tempTotalClazz != null) {
            Field[] fields = tempTotalClazz.getDeclaredFields();
            for (Field field : fields) {
                if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                    continue;
                }
                fieldTotalMap.put(field.getName(), field);
                if (field.getType() == RechargeTrendVO.class) {
                    dayNTotalFieldList.add(field);
                }
            }
            tempTotalClazz = tempTotalClazz.getSuperclass();
        }
        if (dayNTotalFieldList.isEmpty()) {
            dayNTotalFieldMapList = Collections.emptyList();
        } else {
            dayNTotalFieldMapList = new ArrayList<>(dayNTotalFieldList.size());
            for (Field dayNTotalField : dayNTotalFieldList) {
                dayNTotalField.setAccessible(true);
                Field sourceField = fieldTotalMap.get(dayNTotalField.getName().replace("Trend", ""));
                sourceField.setAccessible(true);
                if (sourceField != null) {
                    dayNTotalFieldMapList.add(Tuples.of(sourceField, dayNTotalField));
                }
            }
        }
        //解析游戏首日复充again映射
        Map<String, Field> againFieldMap = new HashMap<>();
        List<Field> againFieldList = new ArrayList<>();
        Class<?> againClazz = GameDataFirstNewUserAgainVO.class;
        while (againClazz != null) {
            Field[] fields = againClazz.getDeclaredFields();
            for (Field field : fields) {
                if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                    continue;
                }
                againFieldMap.put(field.getName(), field);
                if (field.getType() == FirstNewUserAgainTrendVO.class) {
                    againFieldList.add(field);
                }
            }
            againClazz = againClazz.getSuperclass();
        }
        if (againFieldList.isEmpty()) {
            firstNewUserAgainFieldMapList = Collections.emptyList();
        } else {
            firstNewUserAgainFieldMapList = new ArrayList<>(againFieldList.size());
            for (Field againField : againFieldList) {
                againField.setAccessible(true);
                Field sourceField = againFieldMap.get(againField.getName().replace("Trend", ""));
                sourceField.setAccessible(true);
                if (sourceField != null) {
                    firstNewUserAgainFieldMapList.add(Tuples.of(sourceField, againField));
                }
            }
        }
        //解析游戏首日复充总计again映射
        Map<String, Field> againTotalFieldMap = new HashMap<>();
        List<Field> againTotalFieldList = new ArrayList<>();
        Class<?> againTotalClazz = GameDataFirstNewUserAgainTotalVO.class;
        while (againTotalClazz != null) {
            Field[] fields = againTotalClazz.getDeclaredFields();
            for (Field field : fields) {
                if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                    continue;
                }
                againTotalFieldMap.put(field.getName(), field);
                if (field.getType() == FirstNewUserAgainTrendVO.class) {
                    againTotalFieldList.add(field);
                }
            }
            againTotalClazz = againTotalClazz.getSuperclass();
        }
        if (againTotalFieldList.isEmpty()) {
            firstNewUserAgainTotalFieldMapList = Collections.emptyList();
        } else {
            firstNewUserAgainTotalFieldMapList = new ArrayList<>(againTotalFieldList.size());
            for (Field againTotalField : againTotalFieldList) {
                againTotalField.setAccessible(true);
                Field sourceField = againTotalFieldMap.get(againTotalField.getName().replace("Trend", ""));
                sourceField.setAccessible(true);
                if (sourceField != null) {
                    firstNewUserAgainTotalFieldMapList.add(Tuples.of(sourceField, againTotalField));
                }
            }
        }
    }

    @Autowired
    private Dao dao;
    @Autowired
    private DataPowerComponent dataPowerComponent;

    /**
     * 游戏每日数据
     *
     * @param dto 前端传递查询参数
     * @return 返回给前端的数据
     */
    @Override
    public Page<GameDataDayVO> getGameDataDay(GameDataDayDTO dto) {
        if (dto.getGameDimension() == null) {
            //不传维度默认查看子游戏维度
            dto.setGameDimension(1L);
        }
        if (dto.getGameDimension() == 2L) {
            return getGameDataDayForParent(dto);
        } else if (dto.getGameDimension() == 3L) {
            return getGameDataDayForSuper(dto);
        }
        return getGameDataDayForSon(dto);
    }

    /**
     * 游戏每日数据-子游戏维度
     *
     * @param dto 前端传递查询参数
     * @return 返回给前端的数据
     */
    private Page<GameDataDayVO> getGameDataDayForSon(GameDataDayDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();

        //默认查询 total 总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //根据dto拼接查询条件
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotBlank(dto.getGameName())) {
            //拼接游戏名称查询条件
            cri.where().andEquals("game_name", dto.getGameName());
        }
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList("game_id", gameIds);
        }
        if (dto.getGameClassify() != null) {
            //拼接游戏类型查询条件
            cri.where().andEquals("game_classify", dto.getGameClassify());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //按时间分组
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            cri.getGroupBy().groupBy("dt", "source_system");
        } else {
            cri.getGroupBy().groupBy("dt", "game_id", "source_system");
        }
        //拼接排序条件
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            cri.getOrderBy().orderBy("cost_date", dto.getSortFiled());
            cri.getOrderBy().orderBy("cost", dto.getSortFiled());
        } else {
            cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        }
        //编写sql语句 拼接查询条件1
        Sql sql = Sqls.create(gameDataDayForSonSql(dto.getTableTypes()) + cri);
        //设置自定义回显对象
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(GameDataDayVO.class));
        //设置pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<GameDataDayVO> list = sql.getList(GameDataDayVO.class);
        //设置查询总数
        Sql sqlCount = Sqls.create(
                """
                        SELECT
                            COUNT(1)
                        FROM (
                            SELECT
                                COUNT(1)
                            FROM game_ads.ads_game_day
                        """ + cri +
                        """
                                ) a;
                                """);
        sqlCount.setCallback(Sqls.callback.integer());
        dao.execute(sqlCount);
        pager.setRecordCount(sqlCount.getInt());

        //查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id
        //只查询Day1的数据
        //不选游戏查询的结果 --> (gameId/日期, userId)
        //选游戏查询的结果 --> (日期, userId)
        Map<String, String> gameDateUsersIdMap = findUsersIdForGameData(dto);

        List<GameDataDayVO> gameDataDayVOList = list.stream().map(vo -> {

            Long[] usersID = ArrayUtils.EMPTY_LONG_OBJECT_ARRAY;
            //默认查询的数据-不选择游戏
            if (CollectionUtils.isEmpty(dto.getGameId())) {
                //将gameId和需要查询的注册时间拼接
                String gameIdDate = vo.getGameId() + "/" + vo.getCostDate();
                //取出所有usersId
                if (gameDateUsersIdMap.containsKey(gameIdDate)) {
                    //string[] -> Long[]
                    usersID = Arrays.stream(gameDateUsersIdMap.get(gameIdDate)
                                    .split("/"))
                            .map(Long::parseLong)
                            .toArray(Long[]::new);
                }
            } else {
                //取出所有usersId
                if (gameDateUsersIdMap.containsKey(vo.getCostDate().toString())) {
                    //string[] -> Long[]
                    usersID = Arrays.stream(gameDateUsersIdMap.get(vo.getCostDate().toString())
                                    .split("/"))
                            .map(Long::parseLong)
                            .toArray(Long[]::new);
                }
            }
            formatDayNGroupByDt(vo);

            FirstNewUserAgainTrendVO againTrendVO = FirstNewUserAgainTrendVO.builder()
                    .gameDimension(dto.getGameDimension())
                    .sourceSystem(dto.getSourceSystem())
                    .timeType("da1")
                    .rechargeCount(vo.getAmountD1Trend().getRechargeUserCount())
                    .usersId(usersID)
                    .build();
            vo.setUserDetails(againTrendVO);

            return vo;
        }).collect(Collectors.toList());

        //添加数据

        //返回list结果 封装到page对象里
        return new Page<>(gameDataDayVOList, pager);
    }

    /**
     * 游戏每日数据-父游戏维度
     *
     * @param dto 前端传递查询参数
     * @return 返回给前端的数据
     */
    private Page<GameDataDayVO> getGameDataDayForParent(GameDataDayDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();

        //默认查询 total 总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //根据dto拼接查询条件
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotBlank(dto.getGameName())) {
            //拼接游戏名称查询条件
            cri.where().andEquals("parent_game_name", dto.getGameName());
        }
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList("parent_game_id", gameIds);
        }
        if (dto.getGameClassify() != null) {
            //拼接游戏类型查询条件
            cri.where().andEquals("parent_game_classify", dto.getGameClassify());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //按时间分组
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            cri.getGroupBy().groupBy("dt", "source_system");
        } else {
            cri.getGroupBy().groupBy("dt", "parent_game_id", "source_system");
        }
        //拼接排序条件
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            cri.getOrderBy().orderBy("cost_date", dto.getSortFiled());
            cri.getOrderBy().orderBy("cost", dto.getSortFiled());
        } else {
            cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        }
        //编写sql语句 拼接查询条件
        Sql sql = Sqls.create(gameDataDayForParentSql(dto.getTableTypes()) + cri);
        //设置自定义回显对象
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(GameDataDayVO.class));
        //设置pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<GameDataDayVO> list = sql.getList(GameDataDayVO.class);
        //设置查询总数
        Sql sqlCount = Sqls.create(
                """
                        SELECT
                            COUNT(1)
                        FROM (
                            SELECT
                                COUNT(1)
                            FROM game_ads_parent.ads_game_day_parent
                        """ + cri +
                        """
                                ) a;
                                """);
        sqlCount.setCallback(Sqls.callback.integer());
        dao.execute(sqlCount);
        pager.setRecordCount(sqlCount.getInt());

        //查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id
        //只查询Day1的数据
        //不选游戏查询的结果 --> (gameId/日期, userId)
        //选游戏查询的结果 --> (日期, userId)
        Map<String, String> gameDateUsersIdMap = findUsersIdForGameData(dto);

        List<GameDataDayVO> gameDataDayVOList = list.stream().map(vo -> {

            Long[] usersID = ArrayUtils.EMPTY_LONG_OBJECT_ARRAY;
            //默认查询的数据-不选择游戏
            if (CollectionUtils.isEmpty(dto.getGameId())) {
                //将gameId和需要查询的注册时间拼接
                String gameIdDate = vo.getGameId() + "/" + vo.getCostDate();
                //取出所有usersId
                if (gameDateUsersIdMap.containsKey(gameIdDate)) {
                    //string[] -> Long[]
                    usersID = Arrays.stream(gameDateUsersIdMap.get(gameIdDate)
                                    .split("/"))
                            .map(Long::parseLong)
                            .toArray(Long[]::new);
                }
            } else {
                //取出所有usersId
                if (gameDateUsersIdMap.containsKey(vo.getCostDate().toString())) {
                    //string[] -> Long[]
                    usersID = Arrays.stream(gameDateUsersIdMap.get(vo.getCostDate().toString())
                                    .split("/"))
                            .map(Long::parseLong)
                            .toArray(Long[]::new);
                }
            }
            formatDayNGroupByDt(vo);

            FirstNewUserAgainTrendVO againTrendVO = FirstNewUserAgainTrendVO.builder()
                    .gameDimension(dto.getGameDimension())
                    .sourceSystem(dto.getSourceSystem())
                    .timeType("da1")
                    .rechargeCount(vo.getAmountD1Trend().getRechargeUserCount())
                    .usersId(usersID)
                    .build();
            vo.setUserDetails(againTrendVO);

            return vo;
        }).collect(Collectors.toList());

        //返回list结果 封装到page对象里
        return new Page<>(gameDataDayVOList, pager);
    }

    /**
     * 游戏每日数据-超父游戏维度
     *
     * @param dto 前端传递查询参数
     * @return 返回给前端的数据
     */
    private Page<GameDataDayVO> getGameDataDayForSuper(GameDataDayDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();

        //用来确定实体类的超父游戏名
        Map<LocalDate, String> superGameNameMap = new HashMap<>();
        //默认查询 total 总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //根据dto拼接查询条件
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotBlank(dto.getGameName())) {
            //拼接游戏名称查询条件
            cri.where().andEquals("super_game_name", dto.getGameName());
        }
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList("super_game_id", gameIds);
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //不选游戏的时候，默认按照一天一条游戏数据展示
        //选择游戏的时候，按照时间、游戏分组 即多个游戏同一天合并为一条数据
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            //主SQL
            cri.getGroupBy().groupBy("dt", "source_system");

            Criteria superGameNameCri = Cnd.cri();
            superGameNameCri.where().andInList("super_game_id", gameIds);
            if (StringUtils.isNotBlank(dto.getSourceSystem())) {
                //拼接SDK来源
                superGameNameCri.where().andEquals("source_system", dto.getSourceSystem());
            }
            if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
                superGameNameCri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
            }
            //先从表中将名字选取出来
            Sql superGameNameSql = Sqls.create("""
                    SELECT
                    	dt,
                    	source_system,
                    	GROUP_CONCAT(super_game_name) as super_game_name
                    FROM (
                    	SELECT
                    		source_system,
                    	    dt,
                    	    super_game_id,
                    	    super_game_name
                    	FROM (
                    	    SELECT
                    	        IFNULL(c.id, a.parent_game_id) as super_game_id ,
                    	        IFNULL(c.name, a.parent_game_name) as super_game_name,
                    	        a.*
                    	    FROM game_ads_parent.ads_game_day_parent a
                    	    LEFT JOIN (
                    	        SELECT
                    	            id,
                    	            source_system,
                    	            parent_id ,
                    	            game_name ,
                    	            super_game_id,
                    	            ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                    	        FROM dm_game_order.t_game
                    	    ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                    	    LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                    	) a
                    """ + superGameNameCri +
                    """
                            	GROUP BY dt, super_game_id, super_game_name,source_system
                            ) a
                            GROUP BY dt, source_system;
                            """);

            superGameNameSql.setCallback(Sqls.callback.entities());
            superGameNameSql.setEntity(dao.getEntity(superGameNameForDt.class));
            dao.execute(superGameNameSql);
            List<superGameNameForDt> list = superGameNameSql.getList(superGameNameForDt.class);
            if (CollectionUtils.isNotEmpty(list)) {
                superGameNameMap = list.stream().collect(Collectors.toMap(superGameNameForDt::getDt,
                        superGameNameForDt::getSuperGameName));
            }
        } else {
            cri.getGroupBy().groupBy("dt", "super_game_id", "source_system");
        }
        //拼接排序条件
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            cri.getOrderBy().orderBy("cost_date", dto.getSortFiled());
            cri.getOrderBy().orderBy("cost", dto.getSortFiled());
        } else {
            cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        }
        //编写sql语句 拼接查询条件
        Sql sql = Sqls.create(gameDataDayForSuperSql(dto.getTableTypes()) + cri);
        //设置自定义回显对象
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(GameDataDayVO.class));
        //设置pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<GameDataDayVO> list = sql.getList(GameDataDayVO.class);
        //设置查询总数
        Sql sqlCount = Sqls.create(
                """
                        SELECT
                            COUNT(1)
                        FROM (
                            SELECT
                                COUNT(1)
                            FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                        """ + cri +
                        """
                                ) a
                                """);
        sqlCount.setCallback(Sqls.callback.integer());
        dao.execute(sqlCount);
        pager.setRecordCount(sqlCount.getInt());

        Map<LocalDate, String> finalSuperGameNameMap = superGameNameMap;
        List<GameDataDayVO> gameDataDayVOList = list.stream().map(vo -> {
            String superGameName = finalSuperGameNameMap.get(vo.getCostDate());
            if (StringUtils.isNotBlank(superGameName)) {
                vo.setGameName(superGameName);
            }
            formatDayNGroupByDt(vo);
            return vo;
        }).collect(Collectors.toList());

        //返回list结果 封装到page对象里
        return new Page<>(gameDataDayVOList, pager);
    }

    /**
     * 游戏每日数据总计
     *
     * @param dto 前端传递的查询条件
     * @return 返回给前端的总计数据实体
     */
    public GameDataDayTotalVO getGameDataDayTotal(GameDataDayTotalDTO dto) {
        Criteria cri = getGameDataDayTotalCriteria(dto);
        //创建sql
        Sql gameDataDayTotalsql;
        //判断查询的维度
        if (dto.getGameDimension() == 3) {
            //超父维度
            gameDataDayTotalsql = Sqls.create(gameDataDayTotalSqlForSuper(dto.getTableTypes()) + cri);
        } else if (dto.getGameDimension() == 2) {
            //父游戏维度
            gameDataDayTotalsql = Sqls.create(gameDataDayTotalSqlParent(dto.getTableTypes()) + cri);
        } else {
            //子游戏维度
            gameDataDayTotalsql = Sqls.create(gameDataDayTotalSqlSubgame(dto.getTableTypes()) + cri);
        }
        //设置自定义回传对象
        gameDataDayTotalsql.setCallback(Sqls.callback.entity());
        gameDataDayTotalsql.setEntity(dao.getEntity(GameDataDayTotalVO.class));
        //执行sql
        dao.execute(gameDataDayTotalsql);
        //得到每日总计对象
        GameDataDayTotalVO vo = gameDataDayTotalsql.getObject(GameDataDayTotalVO.class);
        if (vo.getAmountD1() != null) {
            formatDayNTotal(vo);

            //得到所有userID
            Long[] usersIdTotal = ArrayUtils.EMPTY_LONG_OBJECT_ARRAY;
            //得到所有用户的id整合字符串
            String usersIdTotalStr = findUsersIdTotalForGameData(dto);
            if (StringUtils.isNotBlank(usersIdTotalStr)) {
                usersIdTotal = Arrays.stream(usersIdTotalStr.split("/"))
                        .map(Long::parseLong)
                        .toArray(Long[]::new);
            }
            FirstNewUserAgainTrendVO againTrendVO = FirstNewUserAgainTrendVO.builder()
                    .gameDimension(dto.getGameDimension())
                    .sourceSystem(dto.getSourceSystem())
                    .timeType("da1")
                    .rechargeCount(vo.getAmountD1Trend().getRechargeUserCount())
                    .usersId(usersIdTotal)
                    .build();
            vo.setUserDetails(againTrendVO);
        }

        return vo;
    }


    /**
     * 获取游戏每日数据总计条件str
     */
    private Criteria getGameDataDayTotalCriteria(GameDataDayTotalDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
//          List<Long> gameIds = dto.getGameId();
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();


        //默认查询 total 总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //默认查询 子游戏维度 数据
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        Criteria cri = Cnd.cri();
        if (CollectionUtils.isNotEmpty(gameIds)) {
            if (dto.getGameDimension() == 1L) {
                //拼接游戏id
                cri.where().andInList("a.game_id", gameIds);
            } else if (dto.getGameDimension() == 2L) {
                //拼接游戏id
                cri.where().andInList("a.parent_game_id", gameIds);
            } else {
                //拼接游戏id
                cri.where().andInList("a.super_game_id", gameIds);
            }
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("a.source_system", dto.getSourceSystem());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接查询时间
            cri.where().andBetween("a.dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }

        return cri;
    }

    /**
     * 游戏总数据
     *
     * @param dto 前端传递的查询参数
     * @return 返回给前端的数据
     */
    @Override
    public Page<GameDataTotalVO> getGameDataTotal(GameDataTotalDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();
//        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? null : dto.getGameId();
        if (dto.getGameDimension() == null) {
            //默认查询子游戏维度
            dto.setGameDimension(1L);
        }
        //如果注册时间参数为空，默认设置查询当天数据
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //如果充值时间参数为空，默认设置查询当天数据
        if (dto.getRechargeBeginDate() == null || dto.getRechargeEndDate() == null) {
            dto.setRechargeBeginDate(LocalDate.now());
            dto.setRechargeEndDate(LocalDate.now());
        }
        //默认查询 total 总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //主表查询条件
        Criteria criA = myCri(gameIds, dto, "criA", true);
        //账面相关查询条件 时间条件只和充值时间相关
        Criteria criB = myCri(gameIds, dto, "criB", true);
        //账面人数相关 时间只需要充值时间条件,不需要注册时间条件
        Criteria criAmount = myCriRecharge(gameIds, dto, false);
        //新用户充值人数和新用户复充人数 时间条件需要注册时间和充值时间
        Criteria criNewUser = myCriRecharge(gameIds, dto, true);
        //创角人数查询条件
        Criteria criRoleNum = myCriRole(gameIds, dto);
        //拼接排序条件
        Criteria orderByCri = Cnd.cri();
        //如果没有排序条件给默认值
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            dto.setSortFiled("cost");
        }
        orderByCri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        //创建sql语句 执行sql
        Sql sql;
        if (dto.getGameDimension() == 1L) {
            sql = Sqls.create(getGameDataTotalSql(dto.getTableTypes(), criA, criB, criAmount, criNewUser, criRoleNum) + orderByCri);
        } else {
            sql = Sqls.create(getGameDataTotalSqlForParent(dto.getTableTypes(), criA, criB, criAmount, criNewUser, criRoleNum) + orderByCri);
        }
        //设置自定义回显对象
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(GameDataTotalVO.class));
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<GameDataTotalVO> list = sql.getList(GameDataTotalVO.class);
        //设置查询总数
        Sql sqlCount;
        if (dto.getGameDimension() == 1L) {
            sqlCount = Sqls.queryEntity("select count(*) from ads_game_day" + criA);
        } else {
            sqlCount = Sqls.queryEntity("select count(*) from game_ads_parent.ads_game_day_parent" + criA);
        }
        pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));

        //不同类型的数据查询不同的dayN表
        Map<String, DayN> dayNMap;
        if (dto.getGameDimension() == 1L) {
            switch (dto.getTableTypes()) {
                case "buy" -> dayNMap = tempDayNData(dto, "ads_dayn_game_buy");
                case "nature" -> dayNMap = tempDayNDataNature(dto, "ads_dayn_game_nature");
                case "total" -> dayNMap = tempDayNData(dto, "ads_dayn_game");
                default -> dayNMap = tempDayNData(dto, "ads_dayn_game");
            }
        } else {
            switch (dto.getTableTypes()) {
                case "buy" -> dayNMap = tempDayNData(dto, "game_ads_parent.ads_dayn_game_buy_parent");
                case "nature" -> dayNMap = tempDayNDataNature(dto, "game_ads_parent.ads_dayn_game_nature_parent");
                case "total" -> dayNMap = tempDayNData(dto, "game_ads_parent.ads_dayn_game_parent");
                default -> dayNMap = tempDayNData(dto, "game_ads_parent.ads_dayn_game_parent");
            }
        }

        //根据充值时间修改值
        List<GameDataTotalVO> gameDataTotalVOList = list.stream().map(vo -> {

            //总量表的充值相关数据
            DayN dayN = dayNMap.get(vo.getGameId().toString());

            //账面ARPPU
            //设置账面ARPU
            vo.setAmountArpu(vo.getAmountNum() == 0L ? BigDecimal.ZERO :
                    vo.getAmount().divide(BigDecimal.valueOf(vo.getAmountNum()), 2, RoundingMode.HALF_UP));
            //创角成本
            vo.setRoleNumCost(vo.getRoleNum() == 0L ? BigDecimal.ZERO :
                    vo.getCost().divide(BigDecimal.valueOf(vo.getRoleNum()), 2, RoundingMode.HALF_UP));
            //创角率
            vo.setRoleNumRate(vo.getRegNum() == 0L ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getRoleNum().doubleValue() / vo.getRegNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户充值次数、金额
            vo.setNewUserAmount(dayN == null ? BigDecimal.ZERO : dayN.getRechargeMoney());
            vo.setNewUserAmountCount(dayN == null ? 0L : dayN.getRechargeCount());
            //支付宝支付金额
            vo.setAlipayAmount(dayN == null ? BigDecimal.ZERO : dayN.getAlipayAmount());
            //微信支付金额
            vo.setWxAmount(dayN == null ? BigDecimal.ZERO : dayN.getWxAmount());
            //米大师支付金额
            vo.setMiMasterAmount(dayN == null ? BigDecimal.ZERO : dayN.getMiMasterAmount());
            //老用户充值次数、人数、金额
            vo.setOldUserAmount(vo.getAmount().subtract(vo.getNewUserAmount()));
            vo.setOldUserCount(vo.getAmountCount() - (vo.getNewUserAmountCount()));
            vo.setOldUserNum(vo.getAmountNum() - (vo.getNewUserAmountNum()));
            //新用户付费比
            vo.setNewUserRate(vo.getAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAmountNum().doubleValue() / vo.getAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户付费率
            vo.setNewUserRoi(vo.getRegNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAmountNum().doubleValue() / vo.getRegNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户客单价
            vo.setNewUserAvgAmount(vo.getNewUserAmountCount().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAmount().doubleValue() / vo.getNewUserAmountCount().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //复充率
            vo.setUserAgainRate(vo.getNewUserAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAgainNum().doubleValue() / vo.getNewUserAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户复充率
            vo.setNewUserAgainRate(vo.getNewUserTotalAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAgainNum().doubleValue() / vo.getNewUserTotalAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户付费ARPU
            vo.setNewUserAmountArpu(vo.getNewUserAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                    BigDecimal.valueOf(vo.getNewUserAmount().doubleValue() / vo.getNewUserAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
            //新用户回收率
            vo.setNewUserRechargeRate(vo.getCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                    vo.getNewUserAmount().divide(vo.getCost(), 4, RoundingMode.HALF_UP));
            //新用户充值成本
            vo.setNewUserRechargeCost(vo.getNewUserAmountNum() == 0 ? BigDecimal.ZERO :
                    vo.getCost().divide(BigDecimal.valueOf(vo.getNewUserAmountNum()), 4, RoundingMode.HALF_UP));


            return vo;
        }).collect(Collectors.toList());

        //返回list结果封装到page对象里
        return new Page<>(gameDataTotalVOList, pager);
    }

    /**
     * 游戏总数据总计
     *
     * @param dto 前端传递的查询参数
     * @return 返回给前端额数据
     */
    public GameDataTotalTotalVO getGameDataTotalTotal(GameDataTotalTotalDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();
        if (dto.getGameDimension() == null) {
            //默认查询子游戏维度
            dto.setGameDimension(1L);
        }
        String tableName = "game_ads.ads_game_day";
        if (dto.getGameDimension() == 2L) {
            tableName = "game_ads_parent.ads_game_day_parent";
        }
        //如果注册时间参数为空，默认设置查询当天数据
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //如果充值时间参数为空，默认设置查询当天数据
        if (dto.getRechargeBeginDate() == null || dto.getRechargeEndDate() == null) {
            dto.setRechargeBeginDate(LocalDate.now());
            dto.setRechargeEndDate(LocalDate.now());
        }
        //默认查询总量数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //将查询条件GameDataTotalTotalDTO 复制为 GameDataTotalDTO
        GameDataTotalDTO totalDTO = new GameDataTotalDTO();
        copyNullProperties(dto, totalDTO);
        //主表查询条件
        Criteria criA = myCri(gameIds, totalDTO, "criA", false);
        //账面相关查询条件 时间条件只和充值时间相关
        Criteria criB = myCri(gameIds, totalDTO, "criB", false);
        //账面人数相关 时间只需要充值时间条件,不需要注册时间条件
        Criteria criAmount = myCriRecharge(gameIds, totalDTO, false);
        //新用户充值人数和新用户复充人数 时间条件需要注册时间和充值时间
        Criteria criNewUser = myCriRecharge(gameIds, totalDTO, true);
        //创角人数查询条件
        Criteria criRoleNum = myCriRole(gameIds, totalDTO);
        //创建sql语句 执行sql
        Sql sql = Sqls.create(gameDataTotalTotalSql(dto.getTableTypes(), tableName) + criA);
        //设置自定义回显对象
        sql.setCallback(Sqls.callback.entity());
        sql.setEntity(dao.getEntity(GameDataTotalTotalVO.class));
        //执行sql
        dao.execute(sql);
        //得到含有部分总数据总计结果的GameDataTotalTotalVO
        GameDataTotalTotalVO vo = sql.getObject(GameDataTotalTotalVO.class);
        //处理账面、新用户充值人数、新用户复充人数、创角人数相关数据
        GameDataTotalTotalVO tempVO = getGameDataTotalSumAmountData(dto, criB, criAmount, criNewUser, criRoleNum);
        //将两个处理的对象合并
        copyNullProperties(tempVO, vo);
        //得到dayN相关数据
        getGameDataTotalTotalRechargeData(dto, vo);

        //返回结果
        return vo;
    }

    /**
     * 得到账面相关数据、账面人数、新用户人数、新用户复充人数、创角人数数据（游戏总数据总计）
     *
     * @return PitcherDataTotalSumVO
     */
    private GameDataTotalTotalVO getGameDataTotalSumAmountData(GameDataTotalTotalDTO dto, Criteria criB, Criteria criAmount, Criteria criNewUser, Criteria criRoleNum) {
        //不同类型的数据需要额外添加条件
        if ("buy".equals(dto.getTableTypes())) {
            criAmount.where().andNotEquals("agent_id", 0);
            criNewUser.where().andNotEquals("agent_id", 0);
            criRoleNum.where().andNotEquals("user_agent_id", 0);
        } else if ("nature".equals(dto.getTableTypes())) {
            criAmount.where().andEquals("agent_id", 0);
            criNewUser.where().andEquals("agent_id", 0);
            criRoleNum.where().andEquals("user_agent_id", 0);
        }
        //默认查询的表-子游戏维度
        String tableName = "game_ads.ads_game_day";
        if (dto.getGameDimension() == 2L) {
            tableName = "game_ads_parent.ads_game_day_parent";
        }
        //得到账面相关数据
        Sql sqlAmountData = Sqls.create(gameDataTotalSumAmountSql(dto.getTableTypes(), tableName) + criB);
        //设置回传对象
        sqlAmountData.setCallback(Sqls.callback.entity());
        sqlAmountData.setEntity(dao.getEntity(GameDataTotalTotalVO.class));
        //执行sql
        dao.execute(sqlAmountData);
        GameDataTotalTotalVO vo = sqlAmountData.getObject(GameDataTotalTotalVO.class);

        //账面人数数据(总量)
        Sql sqlAmountNum = Sqls.create("""
                SELECT
                    IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                FROM
                    game_ads.ads_information
                """ + criAmount);
        //设置回传对象
        sqlAmountNum.setCallback(Sqls.callback.longValue());
        //执行sql
        dao.execute(sqlAmountNum);
        //设置账面充值人数
        vo.setAmountNum(sqlAmountNum.getLong());
        //账面ARPU
        vo.setAmountArpu(vo.getAmountNum() == 0L ? BigDecimal.ZERO :
                vo.getAmount().divide(BigDecimal.valueOf(vo.getAmountNum()), 2, RoundingMode.HALF_UP));

        //新用户充值人数(总量)
        Sql sqlNewUserNum = Sqls.create("""
                SELECT
                    COUNT(DISTINCT user_id) new_user_amount_num
                FROM
                    game_ads.ads_information
                """ + criNewUser);
        //设置回传对象
        sqlNewUserNum.setCallback(Sqls.callback.longValue());
        //执行sql
        dao.execute(sqlNewUserNum);
        //设置新用户充值人数
        vo.setNewUserAmountNum(sqlNewUserNum.getLong());

        //新用户复充人数(总量)
        Sql sqlNewUserAgainNum = Sqls.create("""
                SELECT
                    COUNT(tempA.num) as new_user_again_num
                FROM (
                    SELECT
                        COUNT(user_id) num
                    FROM
                        game_ads.ads_information
                """ + criNewUser +
                """
                         GROUP BY user_id
                        HAVING
                            COUNT(user_id) > 1 ) tempA
                        """);
        //设置回传对象
        sqlNewUserAgainNum.setCallback(Sqls.callback.longValue());
        //执行sql
        dao.execute(sqlNewUserAgainNum);
        //设置新用户复充人数
        vo.setNewUserAgainNum(sqlNewUserAgainNum.getLong());

        //创角人数(总量)
        Sql sqlRoleNum = Sqls.create("""
                SELECT
                    COUNT(DISTINCT role_user_id) as role_num
                FROM
                    dw_create_role_detail
                """ + criRoleNum);
        //设置回传对象
        sqlRoleNum.setCallback(Sqls.callback.longValue());
        //执行sql
        dao.execute(sqlRoleNum);
        //设置创角人数
        vo.setRoleNum(sqlRoleNum.getLong());
        //返回结果
        return vo;
    }

    /**
     * 游戏总数据总计的新用户充值人数相关数据的计算方法
     *
     * @param dto 前端查询条件
     * @param vo  返回给前端得实体
     */
    private void getGameDataTotalTotalRechargeData(GameDataTotalTotalDTO dto, GameDataTotalTotalVO vo) {

        //设置查询参数map
        Map<String, Object> dayNMap = new HashMap<>(6);
        dayNMap.put("registerBeginDate", dto.getRegisteredBeginDate());
        dayNMap.put("registerEndDate", dto.getRegisteredEndDate());
        dayNMap.put("rechargeBeginDate", dto.getRechargeBeginDate());
        dayNMap.put("rechargeEndDate", dto.getRechargeEndDate());
        dayNMap.put("gameId", dto.getGameId());
        dayNMap.put("gameDimension", dto.getGameDimension());
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            dayNMap.put("sourceSystem", dto.getSourceSystem());
        }

        //得到dayN数据
        DayN dayN;
        if (dto.getGameDimension() == 1L) {
            switch (dto.getTableTypes()) {
                case "buy" -> dayN = getDayNByTableName(dayNMap, "ads_dayn_game_buy");
                case "nature" -> dayN = getDayNByTableNameNature(dayNMap, "ads_dayn_game_nature");
                case "total" -> dayN = getDayNByTableName(dayNMap, "ads_dayn_game");
                default -> dayN = getDayNByTableName(dayNMap, "ads_dayn_game");
            }
        } else {
            //父游戏维度
            switch (dto.getTableTypes()) {
                case "buy" -> dayN = getDayNByTableName(dayNMap, "game_ads_parent.ads_dayn_game_buy_parent");
                case "nature" ->
                        dayN = getDayNByTableNameNature(dayNMap, "game_ads_parent.ads_dayn_game_nature_parent");
                case "total" -> dayN = getDayNByTableName(dayNMap, "game_ads_parent.ads_dayn_game_parent");
                default -> dayN = getDayNByTableName(dayNMap, "game_ads_parent.ads_dayn_game_parent");
            }
        }
        //设置总量数据
        //新用户充值次数、金额
        vo.setNewUserAmount(dayN == null ? BigDecimal.ZERO : dayN.getRechargeMoney());
        //支付宝、微信、米大师新用户充值金额
        vo.setAlipayAmount(dayN == null ? BigDecimal.ZERO : dayN.getAlipayAmount());
        vo.setWxAmount(dayN == null ? BigDecimal.ZERO : dayN.getWxAmount());
        vo.setMiMasterAmount(dayN == null ? BigDecimal.ZERO : dayN.getMiMasterAmount());

        vo.setNewUserAmountCount(dayN == null ? 0L : dayN.getRechargeCount());
        //老用户充值次数、人数、金额
        vo.setOldUserAmount(vo.getAmount().subtract(vo.getNewUserAmount()));
        vo.setOldUserCount(vo.getAmountCount() - (vo.getNewUserAmountCount()));
        vo.setOldUserNum(vo.getAmountNum() - (vo.getNewUserAmountNum()));
        //新用户付费比
        vo.setNewUserRate(vo.getAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAmountNum().doubleValue() / vo.getAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //新用户付费率
        vo.setNewUserRoi(vo.getRegNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAmountNum().doubleValue() / vo.getRegNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //新用户客单价
        vo.setNewUserAvgAmount(vo.getNewUserAmountCount().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAmount().doubleValue() / vo.getNewUserAmountCount().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //复充率
        vo.setUserAgainRate(vo.getNewUserAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAgainNum().doubleValue() / vo.getNewUserAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //新用户复充率
        vo.setNewUserAgainRate(vo.getNewUserTotalAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAgainNum().doubleValue() / vo.getNewUserTotalAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //新用户付费ARPU
        vo.setNewUserAmountArpu(vo.getNewUserAmountNum().compareTo(0L) == 0 ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getNewUserAmount().doubleValue() / vo.getNewUserAmountNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //新用户回收率
        vo.setNewUserRechargeRate(vo.getCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                vo.getNewUserAmount().divide(vo.getCost(), 4, RoundingMode.HALF_UP));
        //新用户充值成本
        vo.setNewUserRechargeCost(vo.getNewUserAmountNum() == 0 ? BigDecimal.ZERO :
                vo.getCost().divide(BigDecimal.valueOf(vo.getNewUserAmountNum()), 4, RoundingMode.HALF_UP));
        //创角率
        vo.setRoleNumRate(vo.getRegNum() == 0L ? BigDecimal.ZERO :
                BigDecimal.valueOf(vo.getRoleNum().doubleValue() / vo.getRegNum().doubleValue()).setScale(4, RoundingMode.HALF_UP));
        //创角成本
        vo.setRoleNumCost(vo.getRoleNum() == 0L ? BigDecimal.ZERO :
                vo.getCost().divide(BigDecimal.valueOf(vo.getRoleNum()), 4, RoundingMode.HALF_UP));
    }

    /**
     * 每日流水贡献
     *
     * @param dto 前端传递的查询参数
     * @return 返回给前端的数据
     */
    @Override
    public Page<GameDataWaterVO> getGameDataWater(GameDataWaterDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();

        if (dto.getGameDimension() == null) {
            //默认查询子游戏维度
            dto.setGameDimension(1L);
        }
        //默认查询的字段
        String gameColumn = "game_id";
        String classifyColumn = "game_classify";
        String gameNameColumn = "game_name";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
            gameNameColumn = "parent_game_name";
        }
        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(gameNameColumn, dto.getGameName());
        }
        if (StringUtils.isNotBlank(dto.getGameClassify())) {
            cri.where().andEquals(classifyColumn, dto.getGameClassify());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        if (CollectionUtils.isNotEmpty(userGameIds)) {
            cri.where().andInList(gameColumn, userGameIds);
        }
        cri.where().and("dt", "=", dto.getRechargeDate());
        cri.groupBy("source_system", gameColumn);
        cri.orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        Sql sql;
        if (dto.getGameDimension() == 1L) {
            sql = Sqls.queryEntity(waterSql() + "$condition");
        } else {
            sql = Sqls.queryEntity(waterSqlForParent() + "$condition");
        }
        sql.setPager(pager);
        Entity<GameDataWaterVO> entity = dao.getEntity(GameDataWaterVO.class);
        sql.setEntity(entity).setCondition(cri);
        dao.execute(sql);

        Sql sqlCount;
        if (dto.getGameDimension() == 1L) {
            sqlCount = Sqls.queryEntity("select count(*) from ads_everyday_water " + "$condition");
        } else {
            sqlCount = Sqls.queryEntity("select count(*) from game_ads_parent.ads_everyday_water_parent " + "$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(gameColumn, gameIds);
        Sql templateSql;
        if (dto.getGameDimension() == 1L) {
            templateSql = Sqls.queryEntity(waterTemplateSql() + "$condition");
        } else {
            templateSql = Sqls.queryEntity(waterTemplateSqlForParent() + "$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.stream().filter(amountOrder -> null != amountOrder.getAmountOrderBy()).forEach(adsEverydayWater -> {
                            if (StringUtils.isNotBlank(adsEverydayWater.getAmountOrderBy())) {
                                rechargeTemplateVOList.add(RechargeTemplateVO.builder()
                                        .amountCount(adsEverydayWater.getAmountCount())
                                        .amountNum(adsEverydayWater.getAmountNum())
                                        .amountOrderBy(Integer.valueOf(adsEverydayWater.getAmountOrderBy()))
                                        .amountPost(adsEverydayWater.getAmountPost())
                                        .build());
                            }
                        });
                        adsEverydayWaters.stream().filter(playerOrder -> null != playerOrder.getUserOrderBy()).forEach(adsEverydayWater -> {
                            if (StringUtils.isNotBlank(adsEverydayWater.getUserOrderBy())) {
                                playerTemplateVOS.add(PlayerTemplateVO.builder()
                                        .userId(adsEverydayWater.getUserId())
                                        .userAmount(adsEverydayWater.getUserAmount())
                                        .userOrderBy(Integer.valueOf(adsEverydayWater.getUserOrderBy()))
                                        .userName(adsEverydayWater.getUserName())
                                        .roleName(adsEverydayWater.getRoleName())
                                        .serverName(adsEverydayWater.getServerName())
                                        .proportion(
                                                item.getAmount().compareTo(BigDecimal.ZERO) == 0 ?
                                                        BigDecimal.ZERO :
                                                        adsEverydayWater.getUserAmount().divide(item.getAmount(), 4, RoundingMode.DOWN)
                                        )
                                        .build());
                            }
                        });
                        item.setRechargeTemplateVOList(rechargeTemplateVOList.stream().sorted(Comparator.comparing(RechargeTemplateVO::getAmountOrderBy)).collect(Collectors.toList()));
                        item.setPlayerTemplateVOS(playerTemplateVOS.stream().sorted(Comparator.comparing(PlayerTemplateVO::getUserOrderBy)).collect(Collectors.toList()));
                    }
                    return item;
                }).collect(Collectors.toList());

        return new Page<>(result, pager);
    }

    /**
     * 游戏每日复充数据
     *
     * @param dto 前端传递查询参数实体
     * @return 返回给前端的数据
     */
    @Override
    public Map<LocalDate, List<GameDataAgainDayVO>> getGameDataAgainDay(GameDataAgainDayDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = dto.getGameId() == null ? poerInfo.second : Collections.singletonList(dto.getGameId());

        //如果查询时间不传递默认从今天开始查询
        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 (userGameIds != null) {
            cri.where().andInList("game_id", userGameIds);
        }
        if (dto.getBeginDate() != null) {
            cri.where().andEquals("dt", dto.getBeginDate());
            cri.where().andBetween("ddf", dto.getBeginDate(), dto.getEndDate());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //按 "ddf" 升序排序
        cri.getOrderBy().asc("ddf");

        //获取三张表的查询结果
        List<AdsGameDayAgain> list = getListByTableType("total", cri);
        List<AdsGameDayAgainBuy> listBuySql = getListByTableType("buy", cri);
        List<AdsGameDayAgainNature> listNatureSql = getListByTableType("nature", cri);
        //创建Map记录数据
        Map<LocalDate, List<GameDataAgainDayVO>> map = new TreeMap<>(
                (o1, o2) -> o1.isBefore(o2) == true ? -1 : 1);
        //有序存储每个list,每个list包含当天的所有充值次数的复充数据
        List<List<GameDataAgainDayVO>> tempList = new ArrayList<>();
        //记录查询出的记录条数
        int count = list.size();
        //如果总复充list长度为0返回空结果
        if (count == 0) {
            return map;
        }
        //初始化tempList
        initList(tempList, count);
        //补全缺少的数据
        List resList = findMissDateAgainData(list, listBuySql, listNatureSql);
        List<AdsGameDayAgainBuy> listBuy = (List<AdsGameDayAgainBuy>) resList.get(0);
        List<AdsGameDayAgainNature> listNature = (List<AdsGameDayAgainNature>) resList.get(1);

        //外层循环8次 表示不同复充次数的数据
        for (int i = 0; i < 8; i++) {
            //用来计算Ci
            int ci = i + 1;
            //第一天的所有充值次数都是先计算的
            GameDataAgainDayVO tempVO = tempList.get(0).get(i);
            //设置充值次数
            tempList.get(0).get(i).setCn("C" + ci);
            //"原": 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(0L);
            tempList.get(0).get(i).setBuyIncrease(0L);
            tempList.get(0).get(i).setNatureIncrease(0L);
            //"移":下一个充值次数的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() + (tempVO.getIncrease()) - (tempVO.getDecrease())
            );
            tempList.get(0).get(i).setBuyPresent(
                    tempVO.getBuyOriginal() + (tempVO.getBuyIncrease()) - (tempVO.getBuyDecrease())
            );
            tempList.get(0).get(i).setNaturePresent(
                    tempVO.getNatureOriginal() + (tempVO.getNatureIncrease()) - (tempVO.getNatureDecrease())
            );
            //"比"
            tempList.get(0).get(i).setRate(getCnByNum(list.get(0), 1).compareTo(0L) == 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(0L) == 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(0L) == 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).setCn("C" + ci);
                //"原":前一天的"现"
                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) - (getCnByNum(list.get(j), ci + 1)));
                tempList.get(j).get(i).setBuyPresent(
                        getCnByNum(listBuy.get(j), ci) - (getCnByNum(listBuy.get(j), ci + 1)));
                tempList.get(j).get(i).setNaturePresent(
                        getCnByNum(listNature.get(j), ci) - (getCnByNum(listNature.get(j), ci + 1)));
                //"增":当天的Ci - 前一天的Ci
                tempList.get(j).get(i).setIncrease(
                        getCnByNum(list.get(j), ci) - (getCnByNum(list.get(j - 1), ci)));
                tempList.get(j).get(i).setBuyIncrease(
                        getCnByNum(listBuy.get(j), ci) - (getCnByNum(listBuy.get(j - 1), ci)));
                tempList.get(j).get(i).setNatureIncrease(
                        getCnByNum(listNature.get(j), ci) - (getCnByNum(listNature.get(j - 1), ci)));
                //"移":当天的C(i+1) - 前一天的C(i+1)
                tempList.get(j).get(i).setDecrease(
                        getCnByNum(list.get(j), ci + 1) - (getCnByNum(list.get(j - 1), ci + 1)));
                tempList.get(j).get(i).setBuyDecrease(
                        getCnByNum(listBuy.get(j), ci + 1) - (getCnByNum(listBuy.get(j - 1), ci + 1)));
                tempList.get(j).get(i).setNatureDecrease(
                        getCnByNum(listNature.get(j), ci + 1) - (getCnByNum(listNature.get(j - 1), ci + 1)));
                //"比":当天的现 / 前一天的C1
                tempList.get(j).get(i).setRate(getCnByNum(list.get(j - 1), 1).compareTo(0L) == 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(0L) == 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(0L) == 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;
    }

    /**
     * 生成DayN数据方法
     *
     * @param dto       前端查询参数
     * @param tableName 表名
     * @return Map
     */
    private Map<String, DayN> tempDayNDataNature(GameDataTotalDTO dto, String tableName) {
        String gameColumn = "game_id";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
        }
        //创建查询条件
        Criteria cri = Cnd.cri();
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接注册时间查询条件
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            //拼接游戏ID查询条件
            cri.where().andInList(gameColumn, dto.getGameId());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源查询条件
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }

        Sql dayNSql;
        if (dto.getGameDimension() == 1L) {
            dayNSql = Sqls.create("""
                    SELECT
                        dt,
                        game_id,
                        source_system,
                        day_n
                    FROM
                        $tableName
                    """ + cri);
        } else {
            dayNSql = Sqls.create("""
                    SELECT
                        dt,
                        parent_game_id as game_id,
                        source_system,
                        day_n
                    FROM
                        $tableName
                    """ + cri);
        }
        //给定查询的表名
        dayNSql.vars().set("tableName", tableName);
        //设置回传
        dayNSql.setCallback(Sqls.callback.entities());
        dayNSql.setEntity(dao.getEntity(AdsDaynGame.class));
        //执行sql 获取数据到list中
        dao.execute(dayNSql);

        //将数据库中获取的所有结果封装到一个List中
        List<AdsDaynGame> list = dayNSql.getList(AdsDaynGame.class);

        Map<String, Map<String, String>> tempMap = new HashMap<>();

        //循环遍历 list 按照 gameId 进行存储
        for (AdsDaynGame adsDaynGame : list) {
            if (!tempMap.containsKey(adsDaynGame.getGameId())) {
                //Map中没有改游戏的相关数据，初始化dayNMap
                Map<String, String> resMap = new HashMap<>();
                //对应的参数说明：  日期：每天充值金额-充值次数
                resMap.put("dayN", "0.00-0.00-0.00-0.00-0");
                //保存初始化结果
                tempMap.put(adsDaynGame.getGameId(), resMap);
            }
            //解析 dayN
            Map<String, String> resMap = tempMap.get(adsDaynGame.getGameId());
            //解析每个 adsDaynGame 的 dayN
            parseJsonDataNature(adsDaynGame, resMap, dto);
            //将解析的结果保存
            tempMap.put(adsDaynGame.getGameId(), resMap);
        }

        //生成dayN对象
        Map<String, DayN> gameIdToDayNMap = new HashMap<>();
        for (Map.Entry<String, Map<String, String>> entry : tempMap.entrySet()) {
            //根据解析出来的dayN值构建DayN对象
            String[] values = entry.getValue().get("dayN").split("-");
            gameIdToDayNMap.put(entry.getKey(), DayN.builder()
                    .rechargeMoney(new BigDecimal(values[0]))
                    .alipayAmount(new BigDecimal(values[1]))
                    .wxAmount(new BigDecimal(values[2]))
                    .miMasterAmount(new BigDecimal(values[3]))
                    .rechargeCount(Long.valueOf(values[4]))
                    .build());
        }

        return gameIdToDayNMap;
    }

    /**
     * 生成DayN数据方法
     *
     * @param dto       前端查询参数
     * @param tableName 表名
     * @return Map
     */
    private Map<String, DayN> tempDayNData(GameDataTotalDTO dto, String tableName) {
        String gameColumn = "game_id";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
        }
        //创建查询条件
        Criteria cri = Cnd.cri();
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接注册时间查询条件
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            //拼接游戏ID查询条件
            cri.where().andInList(gameColumn, dto.getGameId());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源查询条件
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }

        Sql dayNSql;
        if (dto.getGameDimension() == 1L) {
            dayNSql = Sqls.create("""
                    SELECT
                        dt,
                        game_id,
                        source_system,
                        day_n
                    FROM
                        $tableName
                    """ + cri);
        } else {
            dayNSql = Sqls.create("""
                    SELECT
                        dt,
                        parent_game_id as game_id,
                        source_system,
                        day_n
                    FROM
                        $tableName
                    """ + cri);
        }
        //给定查询的表名
        dayNSql.vars().set("tableName", tableName);
        //设置回传
        dayNSql.setCallback(Sqls.callback.entities());
        dayNSql.setEntity(dao.getEntity(AdsDaynGame.class));
        //执行sql 获取数据到list中
        dao.execute(dayNSql);

        //将数据库中获取的所有结果封装到一个List中
        List<AdsDaynGame> list = dayNSql.getList(AdsDaynGame.class);

        Map<String, Map<String, String>> tempMap = new HashMap<>();

        //循环遍历 list 按照 gameId 进行存储
        for (AdsDaynGame adsDaynGame : list) {
            if (!tempMap.containsKey(adsDaynGame.getGameId())) {
                //Map中没有改游戏的相关数据，初始化dayNMap
                Map<String, String> resMap = new HashMap<>();
                //对应的参数说明：  日期：每天充值金额-充值次数
                resMap.put("dayN", "0.00-0");
                //保存初始化结果
                tempMap.put(adsDaynGame.getGameId(), resMap);
            }
            //解析 dayN
            Map<String, String> resMap = tempMap.get(adsDaynGame.getGameId());
            //解析每个 adsDaynGame 的 dayN
            parseJsonData(adsDaynGame, resMap, dto);
            //将解析的结果保存
            tempMap.put(adsDaynGame.getGameId(), resMap);
        }

        //生成dayN对象
        Map<String, DayN> gameIdToDayNMap = new HashMap<>();
        for (Map.Entry<String, Map<String, String>> entry : tempMap.entrySet()) {
            //根据解析出来的dayN值构建DayN对象
            String[] values = entry.getValue().get("dayN").split("-");
            gameIdToDayNMap.put(entry.getKey(), DayN.builder()
                    .rechargeMoney(new BigDecimal(values[0]))
                    .rechargeCount(Long.valueOf(values[1]))
                    .build());
        }

        return gameIdToDayNMap;
    }

    /**
     * 解析dayN json字符串数据
     *
     * @param adsDaynGame 对象
     * @param resMap      记录最终结果Map
     * @param dto         前端查询条件
     */
    private void parseJsonDataNature(AdsDaynGame adsDaynGame, Map<String, String> resMap, GameDataTotalDTO dto) {
        //将每一个adsDaynGame中的dayN属性值 由json转为 Map 型
        Gson gson = new Gson();
        Map<String, String> jsonList = gson.fromJson(adsDaynGame.getDayN(), Map.class);
        //解析 jsonList
        for (Map.Entry<String, String> entry : jsonList.entrySet()) {
            //key是充值日期
            String key = entry.getKey();
            String value = entry.getValue();
            //将value按“-”分割
            String[] resValues = value.split("-");
            //判断充值日期 在充值日期内的数据进行计算
            if (DateUtil.parseLocalDate(key).compareTo(dto.getRechargeBeginDate()) >= 0
                    && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                //获取原先的dayN的值
                String[] oldValues = resMap.get("dayN").split("-");
                //充值的金额
                BigDecimal chargeMoney = new BigDecimal(oldValues[0]).add(new BigDecimal(resValues[0])).setScale(2, RoundingMode.HALF_UP);
                //支付宝金额
                BigDecimal alipayMoney = new BigDecimal(oldValues[1]).add(new BigDecimal(resValues[1])).setScale(2, RoundingMode.HALF_UP);
                //微信金额
                BigDecimal wechatMoney = new BigDecimal(oldValues[2]).add(new BigDecimal(resValues[2])).setScale(2, RoundingMode.HALF_UP);
                //米大师金额
                BigDecimal miMasterMoney = new BigDecimal(oldValues[3]).add(new BigDecimal(resValues[3])).setScale(2, RoundingMode.HALF_UP);
                //充值的次数
                long count = Long.parseLong(oldValues[4]) + Long.parseLong(resValues[4]);
                String newValue = chargeMoney + "-" + alipayMoney + "-" + wechatMoney + "-" + miMasterMoney + "-" + count;
                //合并成字符串 更新dayN的值
                resMap.put("dayN", newValue);
            }
        }

    }

    /**
     * 解析dayN json字符串数据
     *
     * @param adsDaynGame 对象
     * @param resMap      记录最终结果Map
     * @param dto         前端查询条件
     */
    private void parseJsonData(AdsDaynGame adsDaynGame, Map<String, String> resMap, GameDataTotalDTO dto) {
        //将每一个adsDaynGame中的dayN属性值 由json转为 Map 型
        Gson gson = new Gson();
        Map<String, String> jsonList = gson.fromJson(adsDaynGame.getDayN(), Map.class);
        //解析 jsonList
        for (Map.Entry<String, String> entry : jsonList.entrySet()) {
            //key是充值日期
            String key = entry.getKey();
            String value = entry.getValue();
            //将value按“-”分割
            String[] resValues = value.split("-");
            //判断充值日期 在充值日期内的数据进行计算
            if (DateUtil.parseLocalDate(key).compareTo(dto.getRechargeBeginDate()) >= 0
                    && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                //获取原先的dayN的值
                String[] oldValues = resMap.get("dayN").split("-");
                //充值的金额
                BigDecimal chargeMoney = new BigDecimal(oldValues[0]).add(new BigDecimal(resValues[0])).setScale(2, RoundingMode.HALF_UP);
                //充值的次数
                long count = Long.parseLong(oldValues[1]) + Long.parseLong(resValues[1]);
                //合并成字符串 更新dayN的值
                String newValue = chargeMoney + "-" + count;
                resMap.put("dayN", newValue);
            }
        }

    }

    /**
     * 主表 账面相关 查询条件
     *
     * @param dto         前端传递的查询条件
     * @param type        criA 查询主表  criB 查询账面相关
     * @param needGroupBy 是否需要分组条件
     * @return 查询条件
     */
    private Criteria myCri(List<Long> gameIds, GameDataTotalDTO dto, String type, Boolean needGroupBy) {
        String gameColumn = "game_id";
        String gameNameColumn = "game_name";
        String classifyColumn = "game_classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            gameNameColumn = "parent_game_name";
            classifyColumn = "parent_game_name_classify";
        }

        //根据传入的dto拼接查询参数
        Criteria cri = Cnd.cri();
        if (StringUtils.isNotBlank(dto.getGameName())) {
            //拼接游戏名称查询条件
            cri.where().andEquals(gameNameColumn, dto.getGameName());
        }
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList(gameColumn, gameIds);
        }
        if (dto.getGameClassify() != null) {
            //拼接游戏类型查询条件
            cri.where().andEquals(classifyColumn, dto.getGameClassify());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //根据type拼接不同的时间查询条件
        if ("criA".equals(type)) {
            if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
                //拼接注册日期查询条件
                cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
            }
        } else if ("criB".equals(type)) {
            if (dto.getRechargeBeginDate() != null && dto.getRechargeEndDate() != null) {
                //拼接充值日期查询条件
                cri.where().andBetween("dt", dto.getRechargeBeginDate(), dto.getRechargeEndDate());
            }
        }
        if (needGroupBy) {
            //拼接分组条件
            cri.getGroupBy().groupBy(gameColumn, classifyColumn, "source_system");
        }

        return cri;
    }

    /**
     * 账面充值人数、新用户充值人数、新用户复充人数的查询条件
     *
     * @param dto         前端传递的查询条件参数实体
     * @param needRegTime 是否需要拼接注册时间
     * @return 查询条件
     */
    private Criteria myCriRecharge(List<Long> gameIds, GameDataTotalDTO dto, Boolean needRegTime) {
        String gameColumn = "game_id";
        String classifyColumn = "classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }

        //根据传入的dto拼接查询参数
        Criteria cri = Cnd.cri();
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList(gameColumn, gameIds);
        }
        if (dto.getGameClassify() != null) {
            //拼接游戏类型查询条件
            cri.where().andEquals(classifyColumn, dto.getGameClassify());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接不同的时间查询条件
        if (needRegTime && dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接注册日期查询条件
            cri.where().andBetween("reg_time", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (dto.getRechargeBeginDate() != null && dto.getRechargeEndDate() != null) {
            //拼接充值日期查询条件
            cri.where().andBetween("order_time", dto.getRechargeBeginDate(), dto.getRechargeEndDate());
        }

        return cri;
    }

    /**
     * 创角人数相关查询条件
     *
     * @param dto 前端传递的查询条件
     * @return 查询条件
     */
    private Criteria myCriRole(List<Long> gameIds, GameDataTotalDTO dto) {
        String gameColumn = "user_game_id";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
        }
        //根据传入的dto拼接查询参数
        Criteria cri = Cnd.cri();
        if (CollectionUtils.isNotEmpty(gameIds)) {
            //拼接游戏id查询条件
            cri.where().andInList(gameColumn, gameIds);
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        if (dto.getGameClassify() != null) {
            cri.where().andEquals("user_game_classify", dto.getGameClassify());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接注册日期查询条件
            cri.where().andBetween("user_dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        if (dto.getRechargeBeginDate() != null && dto.getRechargeEndDate() != null) {
            //拼接充值日期查询条件 在充值时间内创角
            cri.where().andBetween("DATE(role_create_time)", dto.getRechargeBeginDate(), dto.getRechargeEndDate());
        }

        return cri;
    }

    /**
     * 所有为空值的属性都不copy
     *
     * @param source 原数据
     * @param target 目标数据
     */
    private void copyNullProperties(Object source, Object target) {
        BeanUtils.copyProperties(source, target, getNullField(source));
    }

    /**
     * 获取属性中为空的字段
     *
     * @param target 目标对象
     * @return 不需要替换的字段数组
     */
    private static String[] getNullField(Object target) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(target);
        PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors();
        Set<String> notNullFieldSet = new HashSet<>();
        if (propertyDescriptors.length > 0) {
            for (PropertyDescriptor p : propertyDescriptors) {
                String name = p.getName();
                Object value = beanWrapper.getPropertyValue(name);
                if (Objects.isNull(value)) {
                    notNullFieldSet.add(name);
                }
            }
        }
        String[] notNullField = new String[notNullFieldSet.size()];

        return notNullFieldSet.toArray(notNullField);
    }

    /**
     * 三张表共用查询dayN数据的方法
     *
     * @param dayNMap   参数Map
     * @param tableName 查询的表名
     * @return DayN数据
     */
    private DayN getDayNByTableNameNature(Map<String, Object> dayNMap, String tableName) {
        //查询的游戏维度
        Long gameDimension = (Long) dayNMap.get("gameDimension");

        //创建查询条件
        Criteria cri = Cnd.cri();
        if (dayNMap.get("registerBeginDate") != null && dayNMap.get("registerEndDate") != null) {
            //拼接注册时间查询条件
            cri.where().andBetween("dt", dayNMap.get("registerBeginDate"), dayNMap.get("registerEndDate"));
        }
        if (CollectionUtils.isNotEmpty((List<?>) dayNMap.get("gameId"))) {
            if (gameDimension == 1L) {
                // 子游戏维度
                cri.where().andInList("game_id", (List<Long>) dayNMap.get("gameId"));
            } else {
                // 父游戏维度
                cri.where().andInList("parent_game_id", (List<Long>) dayNMap.get("gameId"));
            }
        }
        if (dayNMap.get("sourceSystem") != null) {
            //拼接SDK来源查询条件
            cri.where().andEquals("source_system", dayNMap.get("sourceSystem"));
        }

        Sql dayNSql = Sqls.create("""
                SELECT
                    day_n as dayN
                FROM
                    $tableName
                """ + cri);

        //sql语句传入参数
        dayNSql.setParams(dayNMap);
        //给定查询的表名
        dayNSql.vars().set("tableName", tableName);
        //设置回传
        dayNSql.setCallback(Sqls.callback.strList());
        //执行sql 获取数据到list中
        dao.execute(dayNSql);

        //将数据库中获取的所有结果封装到一个List中
        List<String> dayNList = dayNSql.getList(String.class);
        //构建一个内部类
        DayN dayN = null;
        //解析dayNList
        if (!CollectionUtils.isEmpty(dayNList)) {
            //将dayNList中json格式数据转换为 Map
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(dayNList.toString(), ArrayList.class);
            //用来存储数据的map
            Map<String, String> resMap = new HashMap<>();
            //对应的参数说明：  日期：每天充值金额-充值次数-充值人数-新用户复充人数
            resMap.put("dayN", "0.00-0.00-0.00-0.00-0-0-0");
            for (Map<String, String> jsonMap : jsonList) {
                for (Map.Entry<String, String> entry : jsonMap.entrySet()) {
                    //key是充值日期
                    String key = entry.getKey();
                    String value = entry.getValue();
                    //将value按“-”分割
                    String[] resValues = value.split("-");
                    //判断充值日期 在充值日期内的数据进行计算
                    if (DateUtil.parseLocalDate(key).compareTo((LocalDate) dayNMap.get("rechargeBeginDate")) >= 0
                            && DateUtil.parseLocalDate(key).compareTo((LocalDate) dayNMap.get("rechargeEndDate")) <= 0) {
                        //获取原先的dayN的值
                        String[] oldValues = resMap.get("dayN").split("-");
                        //充值的金额
                        BigDecimal chargeMoney = new BigDecimal(oldValues[0]).add(new BigDecimal(resValues[0]));
                        //支付宝金额
                        BigDecimal alipayMoney = new BigDecimal(oldValues[1]).add(new BigDecimal(resValues[1])).setScale(2, RoundingMode.HALF_UP);
                        //微信金额
                        BigDecimal wechatMoney = new BigDecimal(oldValues[2]).add(new BigDecimal(resValues[2])).setScale(2, RoundingMode.HALF_UP);
                        //米大师金额
                        BigDecimal miMasterMoney = new BigDecimal(oldValues[3]).add(new BigDecimal(resValues[3])).setScale(2, RoundingMode.HALF_UP);
                        //充值的次数
                        long count = Long.parseLong(oldValues[4]) + Long.parseLong(resValues[4]);
                        //充值的人数
                        long num = Long.parseLong(oldValues[5]) + Long.parseLong(resValues[5]);
                        //新用户复充人数
                        long againNum = Long.parseLong(oldValues[6]) + Long.parseLong(resValues[6]);
                        //合并成字符串 更新dayN的值
                        String newValue = chargeMoney + "-" + alipayMoney + "-" + wechatMoney + "-" + miMasterMoney + "-" + count + "-" + num + "-" + againNum;
                        resMap.put("dayN", newValue);
                    }
                }
            }
            //设置dayN的参数
            if (!resMap.isEmpty() && !resMap.get("dayN").isEmpty()) {
                String[] values = resMap.get("dayN").split("-");
                dayN = DayN.builder()
                        .rechargeMoney(new BigDecimal(values[0]))
                        .alipayAmount(new BigDecimal(values[1]))
                        .wxAmount(new BigDecimal(values[2]))
                        .miMasterAmount(new BigDecimal(values[3]))
                        .rechargeCount(Long.valueOf(values[4]))
                        .build();
            }
        }

        return dayN;
    }


    /**
     * 三张表共用查询dayN数据的方法
     *
     * @param dayNMap   参数Map
     * @param tableName 查询的表名
     * @return DayN数据
     */
    private DayN getDayNByTableName(Map<String, Object> dayNMap, String tableName) {
        //查询的游戏维度
        Long gameDimension = (Long) dayNMap.get("gameDimension");

        //创建查询条件
        Criteria cri = Cnd.cri();
        if (dayNMap.get("registerBeginDate") != null && dayNMap.get("registerEndDate") != null) {
            //拼接注册时间查询条件
            cri.where().andBetween("dt", dayNMap.get("registerBeginDate"), dayNMap.get("registerEndDate"));
        }
        if (CollectionUtils.isNotEmpty((List<?>) dayNMap.get("gameId"))) {
            if (gameDimension == 1L) {
                // 子游戏维度
                cri.where().andInList("game_id", (List<Long>) dayNMap.get("gameId"));
            } else {
                // 父游戏维度
                cri.where().andInList("parent_game_id", (List<Long>) dayNMap.get("gameId"));
            }
        }
        if (dayNMap.get("sourceSystem") != null) {
            //拼接SDK来源查询条件
            cri.where().andEquals("source_system", dayNMap.get("sourceSystem"));
        }

        Sql dayNSql = Sqls.create("""
                SELECT
                    day_n as dayN
                FROM
                    $tableName
                """ + cri);

        //sql语句传入参数
        dayNSql.setParams(dayNMap);
        //给定查询的表名
        dayNSql.vars().set("tableName", tableName);
        //设置回传
        dayNSql.setCallback(Sqls.callback.strList());
        //执行sql 获取数据到list中
        dao.execute(dayNSql);

        //将数据库中获取的所有结果封装到一个List中
        List<String> dayNList = dayNSql.getList(String.class);
        //构建一个内部类
        DayN dayN = null;
        //解析dayNList
        if (!CollectionUtils.isEmpty(dayNList)) {
            //将dayNList中json格式数据转换为 Map
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(dayNList.toString(), ArrayList.class);
            //用来存储数据的map
            Map<String, String> resMap = new HashMap<>();
            //对应的参数说明：  日期：每天充值金额-充值次数-充值人数-新用户复充人数
            resMap.put("dayN", "0.00-0-0-0");
            for (Map<String, String> jsonMap : jsonList) {
                for (Map.Entry<String, String> entry : jsonMap.entrySet()) {
                    //key是充值日期
                    String key = entry.getKey();
                    String value = entry.getValue();
                    //将value按“-”分割
                    String[] resValues = value.split("-");
                    //判断充值日期 在充值日期内的数据进行计算
                    if (DateUtil.parseLocalDate(key).compareTo((LocalDate) dayNMap.get("rechargeBeginDate")) >= 0
                            && DateUtil.parseLocalDate(key).compareTo((LocalDate) dayNMap.get("rechargeEndDate")) <= 0) {
                        //获取原先的dayN的值
                        String[] oldValues = resMap.get("dayN").split("-");
                        //充值的金额
                        BigDecimal chargeMoney = new BigDecimal(oldValues[0]).add(new BigDecimal(resValues[0]));
                        //充值的次数
                        long count = Long.parseLong(oldValues[1]) + Long.parseLong(resValues[1]);
                        //充值的人数
                        long num = Long.parseLong(oldValues[2]) + Long.parseLong(resValues[2]);
                        //新用户复充人数
                        long againNum = Long.parseLong(oldValues[3]) + Long.parseLong(resValues[3]);
                        //合并成字符串 更新dayN的值
                        String newValue = chargeMoney + "-" + count + "-" + num + "-" + againNum;
                        resMap.put("dayN", newValue);
                    }
                }
            }
            //设置dayN的参数
            if (!resMap.isEmpty() && !resMap.get("dayN").isEmpty()) {
                String[] values = resMap.get("dayN").split("-");
                dayN = DayN.builder()
                        .rechargeMoney(new BigDecimal(values[0]))
                        .rechargeCount(Long.valueOf(values[1]))
                        .build();
            }
        }

        return dayN;
    }

    /**
     * 通过反射来获取Cn的值
     *
     * @param vo  数据库查询出来的原始数据对象实体
     * @param num 1-9
     * @return Cn
     */
    private Long getCnByNum(Object vo, int num) {
        try {
            Field f = null;
            if (vo instanceof AdsGameDayAgain) {
                f = AdsGameDayAgain.class.getDeclaredField(String.format("c%s", num));
            } else if (vo instanceof AdsGameDayAgainBuy) {
                f = AdsGameDayAgainBuy.class.getDeclaredField(String.format("buyC%s", num));
            } else if (vo instanceof AdsGameDayAgainNature) {
                f = AdsGameDayAgainNature.class.getDeclaredField(String.format("natureC%s", num));
            }
            f.setAccessible(true);
            //返回对应的Cn值
            return (Long) f.get(vo);
        } catch (Exception e) {
            throw new BaseException("get方法出错，映射出错");
        }
    }

    /**
     * 通过反射赋值每日总计趋势（游戏每日按日期聚合数据）
     */
    private void formatDayNGroupByDt(GameDataDayVO vo) {
        if (CollectionUtils.isEmpty(dayNFieldMapList)) {
            return;
        }
        dayNFieldMapList.forEach(dayNTotalFieldMap -> {
            try {
                //得到需要计算的值
                String[] temps = ((String) dayNTotalFieldMap.getT1().get(vo)).split("/");
                //dn的金额总计
                BigDecimal dNAmount = new BigDecimal(temps[0]);
                //d1-dn的金额总计
                BigDecimal d1ToDNTotalAmount = new BigDecimal(temps[1]);
                //d1-dn的消耗总计（排除了未到时间的cost）
                BigDecimal d1ToDNTotalCost = new BigDecimal(temps[3]);
                //d1的金额总计（排除了未到时间的d1）
                BigDecimal d1Amount = new BigDecimal(temps[4]);
                //赋值
                dayNTotalFieldMap.getT2().set(vo, RechargeTrendVO.builder()
                        .rechargeMoney(dNAmount)
                        .rechargeUserCount(Long.valueOf(temps[2]))
                        .increase(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                dNAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
                        .back(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                d1ToDNTotalAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
                        .multiples(d1Amount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                d1ToDNTotalAmount.divide(d1Amount, 4, RoundingMode.HALF_UP))
                        .build());

            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 通过反射赋值每日总计趋势
     */
    private void formatDayNTotal(GameDataDayTotalVO vo) {
        if (CollectionUtils.isEmpty(dayNTotalFieldMapList)) {
            return;
        }

        for (Tuple2<Field, Field> dayNTotalFieldMap : dayNTotalFieldMapList) {
            try {
                String str = (String) dayNTotalFieldMap.getT1().get(vo);
                if (StringUtils.isNotEmpty(str)) {
                    //得到需要计算的值
                    String[] temps = str.split("/");
                    //dn的金额总计
                    BigDecimal dNAmount = new BigDecimal(temps[0]);
                    //d1-dn的金额总计
                    BigDecimal d1ToDNTotalAmount = new BigDecimal(temps[1]);
                    //d1-dn的消耗总计（排除了未到时间的cost）
                    BigDecimal d1ToDNTotalCost = new BigDecimal(temps[3]);
                    //d1的金额总计（排除了未到时间的d1）
                    BigDecimal d1Amount = new BigDecimal(temps[4]);
                    //赋值
                    dayNTotalFieldMap.getT2().set(vo, RechargeTrendVO.builder()
                            .rechargeMoney(dNAmount)
                            .rechargeUserCount(Long.valueOf(temps[2]))
                            .increase(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                    dNAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
                            .back(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                    d1ToDNTotalAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
                            .multiples(d1Amount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
                                    d1ToDNTotalAmount.divide(d1Amount, 4, RoundingMode.HALF_UP))
                            .build());
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }

    /**
     * 通过反射赋值游戏首日复充数据
     */
    private void formatFirstNewUserAgain(GameDataFirstNewUserAgainVO vo, Long[] usersId, GameDataFirstNewUserAgainDTO dto) {
        if (CollectionUtils.isEmpty(firstNewUserAgainFieldMapList)) {
            return;
        }
        firstNewUserAgainFieldMapList.forEach(againFieldMap -> {
            try {
                String name = againFieldMap.getT1().getName();
                String[] temps = ((String) againFieldMap.getT1().get(vo)).split("/");
                againFieldMap.getT2().set(vo, FirstNewUserAgainTrendVO.builder()
                        .rechargeMoney(new BigDecimal(temps[0]))
                        .rechargeCount(Long.valueOf(temps[1]))
                        .percentage(new BigDecimal(temps[2]))
                        .usersId(usersId)
                        .timeType(name)
                        .sourceSystem(vo.getSourceSystem())
                        .gameDimension(dto.getGameDimension() == null ? 1L : dto.getGameDimension())
                        .build());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 通过反射赋值游戏首日复充总计数据
     */
    private void formatFirstNewUserAgainTotal(GameDataFirstNewUserAgainTotalVO vo,
                                              Long[] usersIdTotal, GameDataFirstNewUserAgainTotalDTO dto) {
        if (CollectionUtils.isEmpty(firstNewUserAgainTotalFieldMapList)) {
            return;
        }
        firstNewUserAgainTotalFieldMapList.forEach(againTotalFieldMap -> {
            try {
                String name = againTotalFieldMap.getT1().getName();
                String[] temps = ((String) againTotalFieldMap.getT1().get(vo)).split("/");
                //总充值人数
                Long count = Long.valueOf(temps[1]);
                //da1的总充值人数
                Long da1Count = Long.valueOf(temps[2]);
                //赋值
                againTotalFieldMap.getT2().set(vo, FirstNewUserAgainTrendVO.builder()
                        .rechargeMoney(new BigDecimal(temps[0]))
                        .rechargeCount(count)
                        .percentage(da1Count == 0L ? BigDecimal.ZERO :
                                BigDecimal.valueOf(count.doubleValue() / da1Count.doubleValue()).setScale(4, RoundingMode.HALF_UP))
                        .timeType(name)
                        .usersId(usersIdTotal)
                        .gameDimension(dto.getGameDimension() == null ? 1L : dto.getGameDimension())
                        .build());
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 初始化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(0L)
                                .buyPresent(0L)
                                .buyIncrease(0L)
                                .buyDecrease(0L)
                                .buyRate(BigDecimal.ZERO)
                                .natureOriginal(0L)
                                .naturePresent(0L)
                                .natureIncrease(0L)
                                .natureDecrease(0L)
                                .natureRate(BigDecimal.ZERO)
                                .original(0L)
                                .present(0L)
                                .increase(0L)
                                .decrease(0L)
                                .rate(BigDecimal.ZERO)
                                .build()
                );
            }
        }
    }

    /**
     * 补全缺少的日期数据
     *
     * @param list       查询到的复充趋势总量原始数据
     * @param listBuy    查询到的复充趋势买量量原始数据
     * @param listNature 查询到的复充趋势自然量原始数据
     * @return 返回处理好的结果list
     */
    private List findMissDateAgainData(List<AdsGameDayAgain> list, List<AdsGameDayAgainBuy> listBuy, List<AdsGameDayAgainNature> listNature) {
        //初始化买量和自然量复充数据list
        int count = list.size();
        List<AdsGameDayAgainBuy> listBuyFinal = new ArrayList<>();
        List<AdsGameDayAgainNature> listNatureFinal = new ArrayList<>();

        //先判断三个list的数据量是否相同
        if (count == listBuy.size() && count == listNature.size()) {
            //不少数据
            List resList = new ArrayList();
            resList.add(listBuy);
            resList.add(listNature);
            return resList;
        }

        //循环赋初值
        for (int i = 0; i < count; i++) {
            listBuyFinal.add(i, AdsGameDayAgainBuy.builder()
                    .dt(list.get(i).getDt())
                    .ddf(list.get(i).getDdf())
                    .gameId(list.get(i).getGameId())
                    .gameName(list.get(i).getGameName())
                    .sourceSystem(list.get(i).getSourceSystem())
                    .buyC1(0L)
                    .buyC2(0L)
                    .buyC3(0L)
                    .buyC4(0L)
                    .buyC5(0L)
                    .buyC6(0L)
                    .buyC7(0L)
                    .buyC8(0L)
                    .buyC9(0L)
                    .build());
            listNatureFinal.add(i, AdsGameDayAgainNature.builder()
                    .dt(list.get(i).getDt())
                    .ddf(list.get(i).getDdf())
                    .gameId(list.get(i).getGameId())
                    .gameName(list.get(i).getGameName())
                    .sourceSystem(list.get(i).getSourceSystem())
                    .natureC1(0L)
                    .natureC2(0L)
                    .natureC3(0L)
                    .natureC4(0L)
                    .natureC5(0L)
                    .natureC6(0L)
                    .natureC7(0L)
                    .natureC8(0L)
                    .natureC9(0L)
                    .build());
        }

        //替换已经查询到的数据
        int tempBuy = 0;
        int tempNature = 0;
        for (int i = 0; i < count; i++) {
            if (tempBuy < listBuy.size() && listBuyFinal.get(i).getDdf().equals(listBuy.get(tempBuy).getDdf())) {
                listBuyFinal.set(i, listBuy.get(tempBuy));
                tempBuy++;
            }
            if (tempNature < listNature.size() && listNatureFinal.get(i).getDdf().equals(listNature.get(tempNature).getDdf())) {
                listNatureFinal.set(i, listNature.get(tempNature));
                tempNature++;
            }
        }
        List resList = new ArrayList();
        resList.add(listBuyFinal);
        resList.add(listNatureFinal);

        return resList;
    }

    /**
     * 不同表获取不同的list结果
     *
     * @param tableName 表明
     * @param cri       查询条件
     * @return 查询结果
     */
    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;
    }

    /**
     * 游戏每日数据-子游戏维度
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataDayForSonSql(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(game_id) as game_id,
                        GROUP_CONCAT(game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDay("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                ANY_VALUE(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                ANY_VALUE(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                ANY_VALUE(buy_effective_role_num) as effective_role_num,  -- 有效创角人数
                                
                                round(ANY_VALUE(buy_first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                                round(ANY_VALUE(buy_new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                                round(ANY_VALUE(buy_effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                                ANY_VALUE(buy_first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                                ANY_VALUE(buy_new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                                ANY_VALUE(buy_effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                                
                                ANY_VALUE(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                ANY_VALUE(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                ANY_VALUE(buy_first_effective_role_amount_num_cost) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本
                                ANY_VALUE(buy_new_user_total_effective_role_amount_num_cost) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本
                                
                                round(ANY_VALUE(buy_first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                                round(ANY_VALUE(buy_new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                                ANY_VALUE(buy_first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                                ANY_VALUE(buy_new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                                
                                round(IF(SUM(buy_first_new_user_amount_num) >0, SUM(buy_first_new_user_amount_count) / SUM(buy_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM
                                ads_game_day
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(game_id) as game_id,
                        GROUP_CONCAT(game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDay("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                ANY_VALUE(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                ANY_VALUE(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                ANY_VALUE(nature_effective_role_num) as effective_role_num,  -- 有效创角人数
                                
                                round(ANY_VALUE(nature_first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                                round(ANY_VALUE(nature_new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                                round(ANY_VALUE(nature_effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                                ANY_VALUE(nature_first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                                ANY_VALUE(nature_new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                                ANY_VALUE(nature_effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                                
                                ANY_VALUE(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                ANY_VALUE(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                ANY_VALUE(nature_first_effective_role_amount_num_cost) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本
                                ANY_VALUE(nature_new_user_total_effective_role_amount_num_cost) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本
                                
                                round(ANY_VALUE(nature_first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                                round(ANY_VALUE(nature_new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                                ANY_VALUE(nature_first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                                ANY_VALUE(nature_new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                                
                                round(IF(SUM(nature_first_new_user_amount_num) >0, SUM(nature_first_new_user_amount_count) / SUM(nature_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM
                                ads_game_day
                            """;
        }
        //总量数据
        return """
                SELECT
                    dt as cost_date,
                    source_system,
                    MAX(game_id) as game_id,
                    GROUP_CONCAT(game_name) as game_name,
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDay("") +
                """
                            IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                            IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                            IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                            IFNULL(SUM(old_user_count), 0) old_user_count,
                            IFNULL(SUM(old_user_num), 0) old_user_num,
                            IFNULL(SUM(old_user_amount), 0) old_user_amount,
                            IFNULL(SUM(amount_count), 0) amount_count,
                            IFNULL(SUM(amount_num), 0) amount_num,
                            IFNULL(SUM(amount), 0) amount,
                            IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                            IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                            IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                            round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                            round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                            round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                            round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                            round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                            round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                            round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            SUM(hundred_user_num) hundred_user_num,
                            round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(first_role_num) first_role_num,
                            SUM(role_num) role_num,
                            SUM(new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                            round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                            
                            ANY_VALUE(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            ANY_VALUE(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            ANY_VALUE(effective_role_num) as effective_role_num,  -- 有效创角人数
                            
                            round(ANY_VALUE(first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                            round(ANY_VALUE(new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                            round(ANY_VALUE(effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                            
                            ANY_VALUE(first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                            ANY_VALUE(new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                            ANY_VALUE(effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                            
                            ANY_VALUE(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            ANY_VALUE(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            
                             round(ANY_VALUE(first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                             round(ANY_VALUE(new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                             ANY_VALUE(first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                             ANY_VALUE(new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                             
                             round(IF(SUM(first_new_user_amount_num) >0, SUM(first_new_user_amount_count) / SUM(first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                        FROM
                            ads_game_day
                        """;
    }

    /**
     * 游戏每日数据-父游戏维度
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataDayForParentSql(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(parent_game_id) as game_id,
                        GROUP_CONCAT(parent_game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDay("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                ANY_VALUE(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                ANY_VALUE(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                ANY_VALUE(buy_effective_role_num) as effective_role_num,  -- 有效创角人数
                                
                                round(ANY_VALUE(buy_first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                                round(ANY_VALUE(buy_new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                                round(ANY_VALUE(buy_effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                                ANY_VALUE(buy_first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                                ANY_VALUE(buy_new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                                ANY_VALUE(buy_effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                                
                                ANY_VALUE(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                ANY_VALUE(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                ANY_VALUE(buy_first_effective_role_amount_num_cost) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本
                                ANY_VALUE(buy_new_user_total_effective_role_amount_num_cost) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本
                                
                                round(ANY_VALUE(buy_first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                                round(ANY_VALUE(buy_new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                                ANY_VALUE(buy_first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                                ANY_VALUE(buy_new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                                
                                round(IF(SUM(buy_first_new_user_amount_num) >0, SUM(buy_first_new_user_amount_count) / SUM(buy_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                                
                            FROM
                                game_ads_parent.ads_game_day_parent
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(parent_game_id) as game_id,
                        GROUP_CONCAT(parent_game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDay("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                ANY_VALUE(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                ANY_VALUE(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                ANY_VALUE(nature_effective_role_num) as effective_role_num,  -- 有效创角人数
                                
                                round(ANY_VALUE(nature_first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                                round(ANY_VALUE(nature_new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                                round(ANY_VALUE(nature_effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                                ANY_VALUE(nature_first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                                ANY_VALUE(nature_new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                                ANY_VALUE(nature_effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                                
                                ANY_VALUE(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                ANY_VALUE(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                ANY_VALUE(nature_first_effective_role_amount_num_cost) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本
                                ANY_VALUE(nature_new_user_total_effective_role_amount_num_cost) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本
                                
                                round(ANY_VALUE(nature_first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                                round(ANY_VALUE(nature_new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                                ANY_VALUE(nature_first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                                ANY_VALUE(nature_new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                                
                                round(IF(SUM(nature_first_new_user_amount_num) >0, SUM(nature_first_new_user_amount_count) / SUM(nature_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM
                                game_ads_parent.ads_game_day_parent
                            """;
        }
        //总量数据
        return """
                SELECT
                    dt as cost_date,
                    source_system,
                    MAX(parent_game_id) as game_id,
                    GROUP_CONCAT(parent_game_name) as game_name,
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDay("") +
                """
                            IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                            IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                            IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                            IFNULL(SUM(old_user_count), 0) old_user_count,
                            IFNULL(SUM(old_user_num), 0) old_user_num,
                            IFNULL(SUM(old_user_amount), 0) old_user_amount,
                            IFNULL(SUM(amount_count), 0) amount_count,
                            IFNULL(SUM(amount_num), 0) amount_num,
                            IFNULL(SUM(amount), 0) amount,
                            IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                            IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                            IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                            round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                            round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                            round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                            round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                            round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                            round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                            round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            SUM(hundred_user_num) hundred_user_num,
                            round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(first_role_num) first_role_num,
                            SUM(role_num) role_num,
                            SUM(new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                            round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                            
                            ANY_VALUE(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            ANY_VALUE(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            ANY_VALUE(effective_role_num) as effective_role_num,  -- 有效创角人数
                            
                            round(ANY_VALUE(first_effective_role_num_rate)*100,2) AS first_effective_role_rate, -- 首日有效创角率
                            round(ANY_VALUE(new_user_total_effective_role_num_rate)*100,2) as new_user_total_effective_role_num_rate, -- 新用户累计有效创角率
                            round(ANY_VALUE(effective_role_num_rate)*100,2) as effective_role_num_rate, -- 有效创角率
                                
                            
                            ANY_VALUE(first_effective_role_num_cost) AS first_effective_role_num_cost, -- 首日有效创角成本
                            ANY_VALUE(new_user_total_effective_role_num_cost) as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本
                            ANY_VALUE(effective_role_num_cost) as effective_role_num_cost,    -- 有效创角成本
                            
                            ANY_VALUE(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            ANY_VALUE(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            
                             round(ANY_VALUE(first_effective_role_amount_num_rate)*100,2) as first_effective_role_amount_num_rate, -- 首日有效创角付费比
                             round(ANY_VALUE(new_user_total_effective_role_amount_num_rate)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比
                             ANY_VALUE(first_effective_role_arpu) as first_effective_role_arpu, -- 首日有效创角ARPU
                             ANY_VALUE(new_user_total_effective_role_arpu) as new_user_total_effective_role_arpu, -- 新用户累计有效创角ARPU
                             
                             round(IF(SUM(first_new_user_amount_num) >0, SUM(first_new_user_amount_count) / SUM(first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                        FROM
                            game_ads_parent.ads_game_day_parent
                        """;
    }

    /**
     * 游戏每日数据-超父游戏维度
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataDayForSuperSql(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(super_game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDay("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate
                            FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        dt as cost_date,
                        source_system,
                        MAX(super_game_name) as game_name,
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDay("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate
                            FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                            """;
        }
        //总量数据
        return """
                SELECT
                    dt as cost_date,
                    source_system,
                    MAX(super_game_name) as game_name,
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDay("") +
                """
                            IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                            IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                            IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                            IFNULL(SUM(old_user_count), 0) old_user_count,
                            IFNULL(SUM(old_user_num), 0) old_user_num,
                            IFNULL(SUM(old_user_amount), 0) old_user_amount,
                            IFNULL(SUM(amount_count), 0) amount_count,
                            IFNULL(SUM(amount_num), 0) amount_num,
                            IFNULL(SUM(amount), 0) amount,
                            IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                            IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                            IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                            round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                            round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                            round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                            round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                            round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                            round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                            round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            SUM(hundred_user_num) hundred_user_num,
                            round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(first_role_num) first_role_num,
                            SUM(role_num) role_num,
                            SUM(new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                            round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate
                        FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                        ) a
                        """;
    }

    /**
     * 游戏每日数据总计sql-子游戏 (新)
     *
     * @param tableType 查询类型
     * @return String
     */
    private String gameDataDayTotalSqlSubgame(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDayStr("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                sum(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                sum(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                SUM(buy_effective_role_num) as effective_role_num, -- 有效创角人数
                                
                                ROUND(IFNULL(SUM(buy_first_effective_role_num)/sum(buy_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                                round(IFNULL(SUM(buy_new_user_total_effective_role_num)/SUM(buy_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                                round(IFNULL(SUM(buy_effective_role_num)/SUM(buy_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                                
                                round(IFNULL(SUM(cost)/SUM(buy_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                                round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                                round(IFNULL(SUM(cost)/sum(buy_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                                
                                SUM(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                sum(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(cost)/sum(buy_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                                round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(buy_first_effective_role_amount_num)/SUM(buy_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                                round(IFNULL(SUM(buy_new_user_total_effective_role_amount_num)/SUM(buy_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                                ROUND(IFNULL(SUM(buy_new_user_total_amount)/SUM(buy_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                                ROUND(IFNULL(SUM(buy_first_new_user_amount)/SUM(buy_first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                                
                                round(IF(SUM(buy_first_new_user_amount_num) >0, SUM(buy_first_new_user_amount_count) / SUM(buy_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                                
                            FROM game_ads.ads_game_day as a
                                LEFT JOIN game_dw.dw_game_amount_day_buy
                                b on a.source_system = b.source_system
                                and a.dt = b.dt and a.game_id = b.buy_game_id
                                """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDayStr("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                sum(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                sum(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                SUM(nature_effective_role_num) as effective_role_num, -- 有效创角人数
                                
                                ROUND(IFNULL(SUM(nature_first_effective_role_num)/sum(nature_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                                round(IFNULL(SUM(nature_new_user_total_effective_role_num)/SUM(nature_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                                round(IFNULL(SUM(nature_effective_role_num)/SUM(nature_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                                
                                round(IFNULL(SUM(cost)/SUM(nature_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                                round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                                round(IFNULL(SUM(cost)/sum(nature_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                                
                                SUM(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                sum(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(cost)/sum(nature_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                                round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(nature_first_effective_role_amount_num)/SUM(nature_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                                round(IFNULL(SUM(nature_new_user_total_effective_role_amount_num)/SUM(nature_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                                ROUND(IFNULL(SUM(nature_new_user_total_amount)/SUM(nature_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                                ROUND(IFNULL(SUM(nature_first_new_user_amount)/SUM(nature_first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                                
                                round(IF(SUM(nature_first_new_user_amount_num) >0, SUM(nature_first_new_user_amount_count) / SUM(nature_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM game_ads.ads_game_day as a
                                left join  game_dw.dw_game_amount_day_nature d
                                on a.dt=d.dt and a.game_id = d.nature_game_id
                              """;
        }
        //总量数据
        return """
                SELECT
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDayStr("") +
                """
                              IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                              IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                              IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                              IFNULL(SUM(old_user_count), 0) old_user_count,
                              IFNULL(SUM(old_user_num), 0) old_user_num,
                              IFNULL(SUM(old_user_amount), 0) old_user_amount,
                              IFNULL(SUM(amount_count), 0) amount_count,
                              IFNULL(SUM(amount_num), 0) amount_num,
                              IFNULL(SUM(amount), 0) amount,
                              IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                              IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                              IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                              round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                              round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                              round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                              round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                              round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                              round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                              round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                              round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                              round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                              round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                              round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                              round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                              round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                              round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                              round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                              round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                              SUM(hundred_user_num) hundred_user_num,
                              round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                              SUM(first_role_num) first_role_num,
                              SUM(role_num) role_num,
                              SUM(new_user_total_role_num) new_user_total_role_num,
                              round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                              round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                              round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                              round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                              round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                              round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                              
                              sum(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                              sum(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                              SUM(effective_role_num) as effective_role_num, -- 有效创角人数
                          
                              ROUND(IFNULL(SUM(first_effective_role_num)/sum(first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                              round(IFNULL(SUM(new_user_total_effective_role_num)/SUM(new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                              round(IFNULL(SUM(effective_role_num)/SUM(role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                          
                              round(IFNULL(SUM(cost)/SUM(first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                              round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                              round(IFNULL(SUM(cost)/sum(effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                          
                              SUM(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                              sum(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                          
                          
                              round(IFNULL(SUM(cost)/sum(first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                              round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                          
                              round(IFNULL(SUM(first_effective_role_amount_num)/SUM(first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                              round(IFNULL(SUM(new_user_total_effective_role_amount_num)/SUM(new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                              ROUND(IFNULL(SUM(new_user_total_amount)/SUM(new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                              ROUND(IFNULL(SUM(first_new_user_amount)/SUM(first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                              
                               round(IF(SUM(first_new_user_amount_num) >0, SUM(first_new_user_amount_count) / SUM(first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                          FROM game_ads.ads_game_day as a
                          left join   game_dw.dw_game_amount_day
                          b on a.dt=b.dt and a.game_id = b.game_id
                        """;
    }

    /**
     * 游戏每日数据总计sql - 父游戏维度 (新)
     *
     * @param tableType 查询类型
     * @return
     */
    private String gameDataDayTotalSqlParent(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDayStr("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                sum(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                sum(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                SUM(buy_effective_role_num) as effective_role_num, -- 有效创角人数
                                
                                ROUND(IFNULL(SUM(buy_first_effective_role_num)/sum(buy_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                                round(IFNULL(SUM(buy_new_user_total_effective_role_num)/SUM(buy_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                                round(IFNULL(SUM(buy_effective_role_num)/SUM(buy_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                                
                                round(IFNULL(SUM(cost)/SUM(buy_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                                round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                                round(IFNULL(SUM(cost)/sum(buy_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                                
                                SUM(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                sum(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                
                                round(IFNULL(SUM(cost)/sum(buy_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                                round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(buy_first_effective_role_amount_num)/SUM(buy_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                                round(IFNULL(SUM(buy_new_user_total_effective_role_amount_num)/SUM(buy_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                                ROUND(IFNULL(SUM(buy_new_user_total_amount)/SUM(buy_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                                ROUND(IFNULL(SUM(buy_first_new_user_amount)/SUM(buy_first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                                
                                round(IF(SUM(buy_first_new_user_amount_num) >0, SUM(buy_first_new_user_amount_count) / SUM(buy_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM game_ads_parent.ads_game_day_parent as a
                            LEFT JOIN  game_dw_parent.dw_game_amount_day_buy_parent b
                            on a.source_system = b.source_system
                            and a.dt = b.dt and a.parent_game_id = b.buy_parent_game_id
                                """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDayStr("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                                
                                sum(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                                sum(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                                SUM(nature_effective_role_num) as effective_role_num, -- 有效创角人数
                                
                                ROUND(IFNULL(SUM(nature_first_effective_role_num)/sum(nature_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                                round(IFNULL(SUM(nature_new_user_total_effective_role_num)/SUM(nature_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                                round(IFNULL(SUM(nature_effective_role_num)/SUM(nature_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                                
                                round(IFNULL(SUM(cost)/SUM(nature_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                                round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                                round(IFNULL(SUM(cost)/sum(nature_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                                
                                SUM(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                                sum(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(cost)/sum(nature_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                                round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                                
                                round(IFNULL(SUM(nature_first_effective_role_amount_num)/SUM(nature_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                                round(IFNULL(SUM(nature_new_user_total_effective_role_amount_num)/SUM(nature_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                                ROUND(IFNULL(SUM(nature_new_user_total_amount)/SUM(nature_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                                ROUND(IFNULL(SUM(nature_first_new_user_amount)/SUM(nature_first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                                
                                round(IF(SUM(nature_first_new_user_amount_num) >0, SUM(nature_first_new_user_amount_count) / SUM(nature_first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                            FROM game_ads_parent.ads_game_day_parent as a
                                left join   game_dw_parent.dw_game_amount_day_nature_parent d
                                on a.dt=d.dt and a.parent_game_id = d.nature_parent_game_id
                              """;
        }
        //总量数据
        return """
                SELECT
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDayStr("") +
                """
                              IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                              IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                              IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                              IFNULL(SUM(old_user_count), 0) old_user_count,
                              IFNULL(SUM(old_user_num), 0) old_user_num,
                              IFNULL(SUM(old_user_amount), 0) old_user_amount,
                              IFNULL(SUM(amount_count), 0) amount_count,
                              IFNULL(SUM(amount_num), 0) amount_num,
                              IFNULL(SUM(amount), 0) amount,
                              IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                              IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                              IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                              round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                              round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                              round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                              round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                              round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                              round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                              round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                              round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                              round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                              round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                              round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                              round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                              round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                              round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                              round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                              round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                              SUM(hundred_user_num) hundred_user_num,
                              round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                              SUM(first_role_num) first_role_num,
                              SUM(role_num) role_num,
                              SUM(new_user_total_role_num) new_user_total_role_num,
                              round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                              round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                              round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                              round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                              round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                              round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                              
                              sum(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                              sum(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                              SUM(effective_role_num) as effective_role_num, -- 有效创角人数
                              
                              ROUND(IFNULL(SUM(first_effective_role_num)/sum(first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                              round(IFNULL(SUM(new_user_total_effective_role_num)/SUM(new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                              round(IFNULL(SUM(effective_role_num)/SUM(role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                              
                              round(IFNULL(SUM(cost)/SUM(first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                              round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                              round(IFNULL(SUM(cost)/sum(effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                              
                              SUM(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                              sum(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                              
                              
                              round(IFNULL(SUM(cost)/sum(first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                              round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                              
                              round(IFNULL(SUM(first_effective_role_amount_num)/SUM(first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                              round(IFNULL(SUM(new_user_total_effective_role_amount_num)/SUM(new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                              ROUND(IFNULL(SUM(new_user_total_amount)/SUM(new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                              ROUND(IFNULL(SUM(first_new_user_amount)/SUM(first_effective_role_num),0),2) as new_user_total_effective_role_arpu, -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                              
                              round(IF(SUM(first_new_user_amount_num) >0, SUM(first_new_user_amount_count) / SUM(first_new_user_amount_num), 0), 4) as first_day_avg_cost_count -- 首日人均付费次数
                          FROM game_ads_parent.ads_game_day_parent as a
                          left join   game_dw_parent.dw_game_amount_day_parent as b
                          on a.dt = b.dt and a.parent_game_id = b.parent_game_id 
                        """;
    }

    /**
     * 游戏每日数据总计sql-超父游戏维度
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataDayTotalSqlForSuper(String tableType) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                    """
                    + amountDay("buy_") +
                    """
                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(buy_amount_count), 0) amount_count,
                                IFNULL(SUM(buy_amount_num), 0) amount_num,
                                IFNULL(SUM(buy_amount), 0) amount,
                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                                IFNULL(SUM(buy_role_num), 0) role_num,
                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate
                            FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                    """
                    + amountDay("nature_") +
                    """
                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                                IFNULL(SUM(nature_amount_count), 0) amount_count,
                                IFNULL(SUM(nature_amount_num), 0) amount_num,
                                IFNULL(SUM(nature_amount), 0) amount,
                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                                SUM(nature_hundred_user_num) hundred_user_num,
                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                                SUM(nature_first_role_num) first_role_num,
                                SUM(nature_role_num) role_num,
                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate
                            FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                            """;
        }
        //总量数据
        return """
                SELECT
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                """
                + amountDay("") +
                """
                            IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                            IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                            IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                            IFNULL(SUM(old_user_count), 0) old_user_count,
                            IFNULL(SUM(old_user_num), 0) old_user_num,
                            IFNULL(SUM(old_user_amount), 0) old_user_amount,
                            IFNULL(SUM(amount_count), 0) amount_count,
                            IFNULL(SUM(amount_num), 0) amount_num,
                            IFNULL(SUM(amount), 0) amount,
                            IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                            IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                            IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                            round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                            round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                            round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                            round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                            round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                            round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                            round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            SUM(hundred_user_num) hundred_user_num,
                            round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(first_role_num) first_role_num,
                            SUM(role_num) role_num,
                            SUM(new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                            round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                            round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate
                        FROM (
                                SELECT
                                    a.*,
                                    IFNULL(c.id, a.parent_game_id) as super_game_id ,
                                    IFNULL(c.name, a.parent_game_name) as super_game_name
                                FROM game_ads_parent.ads_game_day_parent a
                                LEFT JOIN (
                                    SELECT
                                        id,
                                        source_system,
                                        parent_id ,
                                        game_name ,
                                        super_game_id,
                                        ROW_NUMBER()over(partition by parent_id, source_system order by id asc) as num
                                    FROM dm_game_order.t_game
                                ) b on a.parent_game_id = b.parent_id AND a.source_system = b.source_system AND b.num = 1
                                LEFT JOIN dm_game_order.t_game_super c on b.source_system = c.source_system AND b.super_game_id = c.id
                            ) a
                        """;
    }

    /**
     * 游戏每日总计趋势sql
     *
     * @param type 输入的参数表示选择表的类型
     * @return String : Dn的充值金额 / D1-Dn的充值总金额 / Dn的充值人数 /当前消耗(剔除不存在的天数数据) /D1充值金额总和(剔除不存在的天数数据)/type
     */
    private String amountDay(String type) {
        //拼接查询条件
        StringBuilder trendDay = new StringBuilder(StringUtils.EMPTY);
        for (int day = 1; day <= 90; day++) {
            trendDay.append("""
                    CONCAT(
                        SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= DATE(NOW()), SPLIT_PART(%samount_d%s , '/', 1), 0 )),'/',
                        SUM(SPLIT_PART(%samount_d%s, '/', 6)),'/',
                        SUM(SPLIT_PART(%samount_d%s, '/', 2)),'/',
                        SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= DATE(NOW()), cost, 0)),'/',
                        SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= DATE(NOW()), SPLIT_PART(%samount_d1 , '/', 1), 0))
                    ) AS amount_d%s ,
                    """.formatted(day - 1, type, day, type, day, type, day, day - 1, day - 1, type, day));
        }
        for (int month = 4; month <= 12; month++) {
            trendDay.append("""
                    CONCAT(
                        SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= DATE(NOW()), SPLIT_PART(%samount_m%s , '/', 1), 0 )),'/',
                        SUM(SPLIT_PART(%samount_m%s, '/', 6)),'/',
                        SUM(SPLIT_PART(%samount_m%s, '/', 2)),'/',
                        SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= DATE(NOW()), cost, 0)),'/',
                        SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= DATE(NOW()), SPLIT_PART(%samount_d1 , '/', 1), 0))
                    ) AS amount_m%s ,
                    """.formatted(month, type, month, type, month, type, month, month, month, type, month));
        }
        //拼接sum数据
        trendDay.append("""
                CONCAT(
                    SUM(SPLIT_PART(%samount_sum, '/', 1)), '/',
                    SUM(SPLIT_PART(%samount_sum, '/', 6)), '/',
                    SUM(SPLIT_PART(%samount_sum, '/', 2)), '/',
                    SUM(cost), '/',
                    SUM(SPLIT_PART(%samount_d1, '/', 1))
                ) AS amount_sum ,
                """.formatted(type, type, type, type));

        return trendDay.toString();
    }

    /**
     * Dn的充值金额 / D1-Dn的充值总金额 / Dn的充值人数 /当前消耗(剔除不存在的天数数据) /D1充值金额总和(剔除不存在的天数数据)
     * 游戏每日总计趋势sql
     */
    private static String amountDayStr(String type) {
        //拼接查询条件
        StringBuilder trendDay = new StringBuilder(StringUtils.EMPTY);
        trendDay.append("""
                CONCAT(
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), %sda1, 0)),'/',
                  IFNULL(sum(%sda1),0),'/', 
                  sum(ifnull(%sda1_num,0)),'/',
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), cost, 0)),'/',
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), %sda1, 0))
                ) AS amount_d1 ,
                """.formatted(type, type, type, type));

        for (int day = 2; day < 90; day++) {
            trendDay.append("""
                    CONCAT(
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), %sda%d - %sda%d, 0)),'/',
                      IFNULL(sum(%sda%d),0),'/',
                      sum(ifnull(%sda%d_num,0)),'/',
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), cost, 0)),'/',
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), %sda1, 0))
                    ) AS amount_d%s ,
                    """.formatted(day - 1, type, day, type, day - 1, type, day, type, day, day - 1, day - 1, type, day));
        }

        //三月
        trendDay.append("""
                CONCAT(
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 2 month) <= DATE(NOW()), %sm3-%sda89, 0)),'/',
                  IFNULL(sum(%sm3),0),'/',
                  sum(ifnull(%sda90_num,0)),'/',
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 2 month) <= DATE(NOW()), cost, 0)),'/',
                  SUM(IF(DATE_ADD(a.dt, INTERVAL 2 month) <= DATE(NOW()), %sda1, 0))
                ) AS amount_d90 ,
                """.formatted(type, type, type, type, type));
        for (int month = 4; month <= 12; month++) {
            trendDay.append("""
                    CONCAT(
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), %sm%d - %sm%d, 0)),'/',
                      IFNULL(sum(%sm%d),0),'/',
                      sum(ifnull(%sm%d_num,0)),'/',
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), cost, 0)),'/',
                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), %sda1, 0))
                    ) AS amount_m%s ,
                    """.formatted(month, type, month, type, month - 1, type, month, type, month, month, month, type, month));
        }
//        //拼接sum数据
        trendDay.append("""
                CONCAT(
                    SUM(%stotal), '/',
                    SUM(%stotal), '/',
                    SUM(ifnull(%stotal_num,0)), '/',
                    SUM(cost), '/',
                    SUM(%sda1)
                ) AS amount_sum ,
                """.formatted(type, type, type, type));

        return trendDay.toString();

    }

    /**
     * 游戏总数据SQL
     *
     * @param tableType  查询类型
     * @param criA       主表查询条件
     * @param criB       账面相关查询条件
     * @param criAmount  账面充值人数查询条件
     * @param criNewUser 新用户相关查询条件
     * @param criRoleNum 创角人数相关查询条件
     * @return String
     */
    private String getGameDataTotalSql(String tableType, Criteria criA, Criteria criB, Criteria criAmount, Criteria criNewUser, Criteria criRoleNum) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        a.*,
                        IFNULL(amount_count, 0) amount_count,
                        IFNULL(amount, 0) amount,
                        IFNULL(avg_amount, 0) avg_amount,
                        IFNULL(new_user_amount_num, 0) new_user_amount_num,
                        IFNULL(new_user_again_num, 0) new_user_again_num,
                        IFNULL(amount_num, 0) amount_num,
                        IFNULL(role_num, 0) role_num
                    FROM(
                        SELECT
                            source_system,
                            game_id,
                            MAX(game_name) as game_name,
                            game_classify,
                            sum(buy_reg_num) reg_num,
                            sum(cost) cost,
                            sum(buy_first_new_user_amount_count) first_new_user_amount_count,
                            sum(buy_first_new_user_amount_num) first_new_user_amount_num,
                            sum(buy_first_new_user_amount) first_new_user_amount,
                            sum(buy_new_user_total_amount_count) new_user_total_amount_count,
                            sum(buy_new_user_total_amount_num) new_user_total_amount_num,
                            sum(buy_new_user_total_amount) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                            round(if(sum(buy_reg_num) > 0 , sum(buy_first_new_user_amount_num) / sum(buy_reg_num), 0), 4) first_amount_rate,
                            round(if(sum(buy_reg_num) > 0, sum(buy_new_user_total_amount_num) / sum(buy_reg_num), 0), 4) today_amount_rate,
                            round(if(sum(buy_first_new_user_amount_count) > 0, sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(sum(buy_new_user_total_amount_count) > 0, sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_reg_order_user_again) / sum(buy_new_user_total_amount_num), 0), 4) today_again_rate,
                            round(if(sum(buy_reg_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_reg_num), 0), 2) reg_user_arpu,
                            round(if(sum(buy_first_new_user_amount_num) > 0 , sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                            round(if(SUM(cost) > 0 , SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                            IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                            round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                            IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                            IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                            round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                            
                            sum(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            sum(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            SUM(buy_effective_role_num) as effective_role_num, -- 有效创角人数
                            
                            ROUND(IFNULL(SUM(buy_first_effective_role_num)/sum(buy_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                            round(IFNULL(SUM(buy_new_user_total_effective_role_num)/SUM(buy_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                            round(IFNULL(SUM(buy_effective_role_num)/SUM(buy_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                            
                            round(IFNULL(SUM(cost)/SUM(buy_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                            round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                            round(IFNULL(SUM(cost)/sum(buy_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                            
                            SUM(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            sum(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(cost)/sum(buy_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                            round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(buy_first_effective_role_amount_num)/SUM(buy_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                            round(IFNULL(SUM(buy_new_user_total_effective_role_amount_num)/SUM(buy_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                            ROUND(IFNULL(SUM(buy_new_user_total_amount)/SUM(buy_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                            ROUND(IFNULL(SUM(buy_first_new_user_amount)/SUM(buy_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                        FROM
                            ads_game_day
                    """ + criA +
                    """
                                 ) a
                            LEFT JOIN (
                                SELECT
                                    source_system as b_source_system,
                                    game_id as b_game_id,
                                    MAX(game_name) as b_game_name,
                                    IFNULL(sum(buy_amount_count), 0) amount_count,
                                    IFNULL(sum(buy_amount), 0) amount,
                                    round(if(sum(buy_amount_count) > 0, sum(buy_amount) / sum(buy_amount_count), 0), 2) avg_amount
                                FROM
                                    game_ads.ads_game_day
                            """ + criB +
                    """
                                ) b
                            ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as d_source_system,
                                    game_id as d_game_id,
                                    IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criAmount +
                    """
                                    AND NOT agent_id = 0
                                GROUP BY game_id, source_system) d
                            ON a.game_id = d.d_game_id and a.source_system = d.d_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as f_source_system,
                                    game_id as f_game_id,
                                    COUNT(DISTINCT user_id) new_user_amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criNewUser +
                    """
                                    AND NOT agent_id = 0
                                GROUP BY game_id, source_system) f
                            ON a.game_id = f.f_game_id and a.source_system = f.f_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as g_source_system,
                                    game_id as g_game_id,
                                    COUNT(tempA.num) as new_user_again_num
                                FROM (
                                        SELECT
                                            source_system,
                                            game_id,
                                            COUNT(user_id) num
                                        FROM
                                            game_ads.ads_information
                            """ + criNewUser +
                    """
                                            AND NOT agent_id = 0
                                        GROUP BY
                                            user_id,
                                            game_id,
                                            source_system
                                        HAVING
                                            COUNT(user_id) > 1 ) tempA
                                GROUP BY tempA.game_id, tempA.source_system) g
                            ON a.game_id = g.g_game_id and a.source_system = g.g_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as n_source_system,
                                    user_game_id ,
                                    COUNT(DISTINCT role_user_id) as role_num
                                FROM
                                    dw_create_role_detail
                            """ + criRoleNum +
                    """
                                    AND NOT user_agent_id = 0
                                GROUP BY user_game_id,source_system
                            ) n
                            ON a.game_id = n.user_game_id and a.source_system = n.n_source_system
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        a.*,
                        IFNULL(amount_count, 0) amount_count,
                        IFNULL(amount, 0) amount,
                        IFNULL(avg_amount, 0) avg_amount,
                        IFNULL(new_user_amount_num, 0) new_user_amount_num,
                        IFNULL(new_user_again_num, 0) new_user_again_num,
                        IFNULL(amount_num, 0) amount_num,
                        IFNULL(role_num, 0) role_num,
                        IFNULL(nature_new_user_total_wx_amount,0) nature_new_user_total_wx_amount,
                        IFNULL(nature_new_user_total_zfb_amount,0) nature_new_user_total_zfb_amount,
                        IFNULL(nature_new_user_total_mds_amount,0) nature_new_user_total_mds_amount
                    FROM(
                        SELECT
                            source_system,
                            game_id,
                            MAX(game_name) as game_name,
                            game_classify,
                            sum(nature_reg_num) reg_num,
                            sum(cost) cost,
                            sum(nature_first_new_user_amount_count) first_new_user_amount_count,
                            sum(nature_first_new_user_amount_num) first_new_user_amount_num,
                            sum(nature_first_new_user_amount) first_new_user_amount,
                            sum(nature_new_user_total_amount_count) new_user_total_amount_count,
                            sum(nature_new_user_total_amount_num) new_user_total_amount_num,
                            sum(nature_new_user_total_amount) new_user_total_amount,
                            
                            sum(nature_new_user_total_wx_amount) nature_new_user_total_wx_amount,
                            sum(nature_new_user_total_zfb_amount) nature_new_user_total_zfb_amount,
                            sum(nature_new_user_total_mds_amount) nature_new_user_total_mds_amount,
                            
                            round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                            round(if(sum(nature_reg_num) > 0 , sum(nature_first_new_user_amount_num) / sum(nature_reg_num), 0), 4) first_amount_rate,
                            round(if(sum(nature_reg_num) > 0, sum(nature_new_user_total_amount_num) / sum(nature_reg_num), 0), 4) today_amount_rate,
                            round(if(sum(nature_first_new_user_amount_count) > 0, sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(sum(nature_new_user_total_amount_count) > 0, sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_reg_order_user_again) / sum(nature_new_user_total_amount_num), 0), 4) today_again_rate,
                            round(if(sum(nature_reg_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_reg_num), 0), 2) reg_user_arpu,
                            round(if(sum(nature_first_new_user_amount_num) > 0 , sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                            round(if(SUM(cost) > 0 , SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                            IFNULL(SUM(nature_hundred_user_num), 0) hundred_user_num,
                            round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(nature_first_role_num) first_role_num,
                            SUM(nature_new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                            
                            sum(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            sum(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            SUM(nature_effective_role_num) as effective_role_num, -- 有效创角人数
                            
                            ROUND(IFNULL(SUM(nature_first_effective_role_num)/sum(nature_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                            round(IFNULL(SUM(nature_new_user_total_effective_role_num)/SUM(nature_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                            round(IFNULL(SUM(nature_effective_role_num)/SUM(nature_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                            
                            round(IFNULL(SUM(cost)/SUM(nature_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                            round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                            round(IFNULL(SUM(cost)/sum(nature_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                            
                            SUM(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            sum(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(cost)/sum(nature_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                            round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(nature_first_effective_role_amount_num)/SUM(nature_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                            round(IFNULL(SUM(nature_new_user_total_effective_role_amount_num)/SUM(nature_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                            ROUND(IFNULL(SUM(nature_new_user_total_amount)/SUM(nature_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                            ROUND(IFNULL(SUM(nature_first_new_user_amount)/SUM(nature_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                        FROM
                            ads_game_day
                    """ + criA +
                    """
                                 ) a
                            LEFT JOIN (
                                SELECT
                                    source_system as b_source_system,
                                    game_id as b_game_id,
                                    MAX(game_name) as b_game_name,
                                    IFNULL(sum(nature_amount_count), 0) amount_count,
                                    IFNULL(sum(nature_amount), 0) amount,
                                    round(if(sum(nature_amount_count) > 0, sum(nature_amount) / sum(nature_amount_count), 0), 2) avg_amount
                                FROM
                                    game_ads.ads_game_day
                            """ + criB +
                    """
                                ) b
                            ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as e_source_system,
                                    game_id as e_game_id,
                                    IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criAmount +
                    """
                                    AND agent_id = 0
                                GROUP BY game_id, source_system ) e
                            ON a.game_id = e.e_game_id and a.source_system = e.e_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as h_source_system,
                                    game_id as h_game_id,
                                    COUNT(DISTINCT user_id) as new_user_amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criNewUser +
                    """
                                    AND agent_id = 0
                                GROUP BY game_id, source_system) h
                            ON a.game_id = h.h_game_id and a.source_system = h.h_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as i_source_system,
                                    game_id as i_game_id,
                                    COUNT(tempB.num) as new_user_again_num
                                FROM (
                                        SELECT
                                            source_system,
                                            game_id,
                                            COUNT(user_id) num
                                        FROM
                                            game_ads.ads_information
                            """ + criNewUser +
                    """
                                            AND agent_id = 0
                                        GROUP BY
                                            user_id,
                                            game_id,
                                            source_system
                                        HAVING
                                            COUNT(user_id) > 1 ) tempB
                                    GROUP BY tempB.game_id, tempB.source_system ) i
                            ON a.game_id = i.i_game_id and a.source_system = i.i_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as m_source_system,
                                    user_game_id ,
                                    COUNT(DISTINCT role_user_id) as role_num
                                FROM
                                    dw_create_role_detail
                            """ + criRoleNum +
                    """
                                    AND user_agent_id = 0
                                GROUP BY user_game_id, source_system
                            ) m
                            ON a.game_id = m.user_game_id and a.source_system = m.m_source_system
                            """;
        }
        //总量
        return """
                SELECT
                    a.*,
                    IFNULL(amount_count, 0) amount_count,
                    IFNULL(amount, 0) amount,
                    IFNULL(avg_amount, 0) avg_amount,
                 	IFNULL(new_user_amount_num, 0) new_user_amount_num,
                 	IFNULL(new_user_again_num, 0) new_user_again_num,
                 	IFNULL(amount_num, 0) amount_num,
                  	IFNULL(role_num, 0) role_num
                FROM(
                	SELECT
                	    source_system,
                		game_id,
                		MAX(game_name) as game_name,
                		game_classify,
                		sum(reg_num) reg_num,
                		sum(cost) cost,
                		sum(first_new_user_amount_count) first_new_user_amount_count,
                		sum(first_new_user_amount_num) first_new_user_amount_num,
                		sum(first_new_user_amount) first_new_user_amount,
                		sum(new_user_total_amount_count) new_user_total_amount_count,
                		sum(new_user_total_amount_num) new_user_total_amount_num,
                		sum(new_user_total_amount) new_user_total_amount,
                		round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                		round(if(sum(reg_num) > 0 , sum(first_new_user_amount_num) / sum(reg_num), 0), 4) first_amount_rate,
                		round(if(sum(reg_num) > 0, sum(new_user_total_amount_num) / sum(reg_num), 0), 4) today_amount_rate,
                		round(if(sum(first_new_user_amount_count) > 0, sum(first_new_user_amount) / sum(first_new_user_amount_count), 0), 2) first_avg_amount,
                		round(if(sum(new_user_total_amount_count) > 0, sum(new_user_total_amount) / sum(new_user_total_amount_count), 0), 2) today_avg_amount,
                		round(if(sum(new_user_total_amount_num) > 0 , sum(reg_order_user_again) / sum(new_user_total_amount_num), 0), 4) today_again_rate,
                		round(if(sum(reg_num) > 0 , sum(new_user_total_amount) / sum(reg_num), 0), 2) reg_user_arpu,
                		round(if(sum(first_new_user_amount_num) > 0 , sum(first_new_user_amount) / sum(first_new_user_amount_num), 0), 2) first_amount_arpu,
                		round(if(sum(new_user_total_amount_num) > 0 , sum(new_user_total_amount) / sum(new_user_total_amount_num), 0), 2) today_amount_arpu,
                		round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                		round(if(SUM(cost) > 0 , SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                		round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                		round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                		SUM(hundred_user_num) hundred_user_num,
                		round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                		SUM(first_role_num) first_role_num,
                		SUM(new_user_total_role_num) new_user_total_role_num,
                		round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                		round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                		round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                		round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                		
                		sum(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                        sum(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                        SUM(effective_role_num) as effective_role_num, -- 有效创角人数
                       
                        ROUND(IFNULL(SUM(first_effective_role_num)/sum(first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                        round(IFNULL(SUM(new_user_total_effective_role_num)/SUM(new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                        round(IFNULL(SUM(effective_role_num)/SUM(role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                       
                        round(IFNULL(SUM(cost)/SUM(first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                        round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                        round(IFNULL(SUM(cost)/sum(effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                       
                        SUM(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                        sum(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                       
                       
                        round(IFNULL(SUM(cost)/sum(first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                        round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                       
                        round(IFNULL(SUM(first_effective_role_amount_num)/SUM(first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                        round(IFNULL(SUM(new_user_total_effective_role_amount_num)/SUM(new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                        ROUND(IFNULL(SUM(new_user_total_amount)/SUM(new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                        ROUND(IFNULL(SUM(first_new_user_amount)/SUM(first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                	FROM
                		ads_game_day
                """ + criA +
                """
                             ) a
                        LEFT JOIN (
                            SELECT
                                source_system as b_source_system,
                                game_id as b_game_id,
                                MAX(game_name) as b_game_name,
                                IFNULL(sum(amount_count), 0) amount_count,
                                IFNULL(sum(amount), 0) amount,
                                round(if(sum(amount_count) > 0, sum(amount) / sum(amount_count), 0), 2) avg_amount
                            FROM
                                game_ads.ads_game_day
                        """ + criB +
                """
                            ) b
                        ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as c_source_system,
                                game_id as c_game_id,
                                IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                            FROM
                                game_ads.ads_information
                        """ + criAmount +
                """
                            GROUP BY game_id, source_system) c
                        ON a.game_id = c.c_game_id and a.source_system = c.c_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as j_source_system,
                                game_id as j_game_id,
                                COUNT(DISTINCT user_id) new_user_amount_num
                            FROM
                                game_ads.ads_information
                        """
                + criNewUser +
                """
                            GROUP BY game_id, source_system) j
                        ON a.game_id = j.j_game_id and a.source_system = j.j_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as k_source_system,
                                game_id as k_game_id,
                                COUNT(tempC.num) as new_user_again_num
                            FROM (
                                    SELECT
                                        source_system,
                                        game_id,
                                        COUNT(user_id) num
                                    FROM
                                        game_ads.ads_information
                        """ + criNewUser +
                """
                                    GROUP BY
                                        user_id,
                                        game_id,
                                        source_system
                                    HAVING
                                        COUNT(user_id) > 1 ) tempC
                                GROUP BY tempC.game_id, tempC.source_system ) k
                        ON a.game_id = k.k_game_id and a.source_system = k.k_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as l_source_system,
                                user_game_id ,
                                COUNT(DISTINCT role_user_id) as role_num
                            FROM
                                dw_create_role_detail
                        """ + criRoleNum +
                """
                            GROUP BY user_game_id, source_system
                        ) l
                        ON a.game_id = l.user_game_id and a.source_system = l.l_source_system
                        """;
    }

    /**
     * 游戏总数据SQL-父游戏维度
     *
     * @param tableType  查询类型
     * @param criA       主表查询条件
     * @param criB       账面相关查询条件
     * @param criAmount  账面充值人数查询条件
     * @param criNewUser 新用户相关查询条件
     * @param criRoleNum 创角人数相关查询条件
     * @return String
     */
    private String getGameDataTotalSqlForParent(String tableType, Criteria criA, Criteria criB, Criteria criAmount, Criteria criNewUser, Criteria criRoleNum) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        a.*,
                        IFNULL(amount_count, 0) amount_count,
                        IFNULL(amount, 0) amount,
                        IFNULL(avg_amount, 0) avg_amount,
                        IFNULL(new_user_amount_num, 0) new_user_amount_num,
                        IFNULL(new_user_again_num, 0) new_user_again_num,
                        IFNULL(amount_num, 0) amount_num,
                        IFNULL(role_num, 0) role_num
                    FROM(
                        SELECT
                            source_system,
                            parent_game_id as game_id,
                            MAX(parent_game_name) as game_name,
                            parent_game_name_classify as game_classify,
                            sum(buy_reg_num) reg_num,
                            sum(cost) cost,
                            sum(buy_first_new_user_amount_count) first_new_user_amount_count,
                            sum(buy_first_new_user_amount_num) first_new_user_amount_num,
                            sum(buy_first_new_user_amount) first_new_user_amount,
                            sum(buy_new_user_total_amount_count) new_user_total_amount_count,
                            sum(buy_new_user_total_amount_num) new_user_total_amount_num,
                            sum(buy_new_user_total_amount) new_user_total_amount,
                            round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                            round(if(sum(buy_reg_num) > 0 , sum(buy_first_new_user_amount_num) / sum(buy_reg_num), 0), 4) first_amount_rate,
                            round(if(sum(buy_reg_num) > 0, sum(buy_new_user_total_amount_num) / sum(buy_reg_num), 0), 4) today_amount_rate,
                            round(if(sum(buy_first_new_user_amount_count) > 0, sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(sum(buy_new_user_total_amount_count) > 0, sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_reg_order_user_again) / sum(buy_new_user_total_amount_num), 0), 4) today_again_rate,
                            round(if(sum(buy_reg_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_reg_num), 0), 2) reg_user_arpu,
                            round(if(sum(buy_first_new_user_amount_num) > 0 , sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                            round(if(SUM(cost) > 0 , SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                            IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                            round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                            IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                            IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                            round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                              sum(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            sum(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            SUM(buy_effective_role_num) as effective_role_num, -- 有效创角人数
                            
                            ROUND(IFNULL(SUM(buy_first_effective_role_num)/sum(buy_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                            round(IFNULL(SUM(buy_new_user_total_effective_role_num)/SUM(buy_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                            round(IFNULL(SUM(buy_effective_role_num)/SUM(buy_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                            
                            round(IFNULL(SUM(cost)/SUM(buy_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                            round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                            round(IFNULL(SUM(cost)/sum(buy_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                            
                            SUM(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            sum(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(cost)/sum(buy_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                            round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(buy_first_effective_role_amount_num)/SUM(buy_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                            round(IFNULL(SUM(buy_new_user_total_effective_role_amount_num)/SUM(buy_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                            ROUND(IFNULL(SUM(buy_new_user_total_amount)/SUM(buy_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                            ROUND(IFNULL(SUM(buy_first_new_user_amount)/SUM(buy_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + criA +
                    """
                                 ) a
                            LEFT JOIN (
                                SELECT
                                    source_system as b_source_system,
                                    parent_game_id as b_game_id,
                                    MAX(parent_game_name) as b_game_name,
                                    IFNULL(sum(buy_amount_count), 0) amount_count,
                                    IFNULL(sum(buy_amount), 0) amount,
                                    round(if(sum(buy_amount_count) > 0, sum(buy_amount) / sum(buy_amount_count), 0), 2) avg_amount
                                FROM
                                    game_ads_parent.ads_game_day_parent
                            """ + criB +
                    """
                                ) b
                            ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as d_source_system,
                                    parent_game_id as d_game_id,
                                    IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criAmount +
                    """
                                    AND NOT agent_id = 0
                                GROUP BY parent_game_id, source_system) d
                            ON a.game_id = d.d_game_id and a.source_system = d.d_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as f_source_system,
                                    parent_game_id as f_game_id,
                                    COUNT(DISTINCT user_id) new_user_amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criNewUser +
                    """
                                    AND NOT agent_id = 0
                                GROUP BY parent_game_id, source_system) f
                            ON a.game_id = f.f_game_id and a.source_system = f.f_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as g_source_system,
                                    parent_game_id as g_game_id,
                                    COUNT(tempA.num) as new_user_again_num
                                FROM (
                                        SELECT
                                            source_system,
                                            parent_game_id,
                                            COUNT(user_id) num
                                        FROM
                                            game_ads.ads_information
                            """ + criNewUser +
                    """
                                            AND NOT agent_id = 0
                                        GROUP BY
                                            user_id,
                                            parent_game_id,
                                            source_system
                                        HAVING
                                            COUNT(user_id) > 1 ) tempA
                                GROUP BY tempA.parent_game_id, tempA.source_system) g
                            ON a.game_id = g.g_game_id and a.source_system = g.g_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as n_source_system,
                                    parent_game_id ,
                                    COUNT(DISTINCT role_user_id) as role_num
                                FROM
                                    dw_create_role_detail
                            """ + criRoleNum +
                    """
                                    AND NOT user_agent_id = 0
                                GROUP BY parent_game_id,source_system
                            ) n
                            ON a.game_id = n.parent_game_id and a.source_system = n.n_source_system
                            """;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        a.*,
                        IFNULL(amount_count, 0) amount_count,
                        IFNULL(amount, 0) amount,
                        IFNULL(avg_amount, 0) avg_amount,
                        IFNULL(new_user_amount_num, 0) new_user_amount_num,
                        IFNULL(new_user_again_num, 0) new_user_again_num,
                        IFNULL(amount_num, 0) amount_num,
                        IFNULL(role_num, 0) role_num,
                        IFNULL(nature_new_user_total_wx_amount,0) nature_new_user_total_wx_amount,
                        IFNULL(nature_new_user_total_zfb_amount,0) nature_new_user_total_zfb_amount,
                        IFNULL(nature_new_user_total_mds_amount,0) nature_new_user_total_mds_amount
                    FROM(
                        SELECT
                            source_system,
                            parent_game_id as game_id,
                            MAX(parent_game_name) as game_name,
                            parent_game_name_classify as game_classify,
                            sum(nature_reg_num) reg_num,
                            sum(cost) cost,
                            sum(nature_first_new_user_amount_count) first_new_user_amount_count,
                            sum(nature_first_new_user_amount_num) first_new_user_amount_num,
                            sum(nature_first_new_user_amount) first_new_user_amount,
                            sum(nature_new_user_total_amount_count) new_user_total_amount_count,
                            sum(nature_new_user_total_amount_num) new_user_total_amount_num,
                            sum(nature_new_user_total_amount) new_user_total_amount,
                            
                            sum(nature_new_user_total_wx_amount) nature_new_user_total_wx_amount,
                            sum(nature_new_user_total_zfb_amount) nature_new_user_total_zfb_amount,
                            sum(nature_new_user_total_mds_amount) nature_new_user_total_mds_amount,
                            
                            round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                            round(if(sum(nature_reg_num) > 0 , sum(nature_first_new_user_amount_num) / sum(nature_reg_num), 0), 4) first_amount_rate,
                            round(if(sum(nature_reg_num) > 0, sum(nature_new_user_total_amount_num) / sum(nature_reg_num), 0), 4) today_amount_rate,
                            round(if(sum(nature_first_new_user_amount_count) > 0, sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                            round(if(sum(nature_new_user_total_amount_count) > 0, sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                            round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_reg_order_user_again) / sum(nature_new_user_total_amount_num), 0), 4) today_again_rate,
                            round(if(sum(nature_reg_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_reg_num), 0), 2) reg_user_arpu,
                            round(if(sum(nature_first_new_user_amount_num) > 0 , sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                            round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                            round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                            round(if(SUM(cost) > 0 , SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                            round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                            round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                            IFNULL(SUM(nature_hundred_user_num), 0) hundred_user_num,
                            round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                            SUM(nature_first_role_num) first_role_num,
                            SUM(nature_new_user_total_role_num) new_user_total_role_num,
                            round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                            round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                            round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                            round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                            
                            sum(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                            sum(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                            SUM(nature_effective_role_num) as effective_role_num, -- 有效创角人数
                            
                            ROUND(IFNULL(SUM(nature_first_effective_role_num)/sum(nature_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                            round(IFNULL(SUM(nature_new_user_total_effective_role_num)/SUM(nature_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                            round(IFNULL(SUM(nature_effective_role_num)/SUM(nature_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                            
                            round(IFNULL(SUM(cost)/SUM(nature_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                            round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                            round(IFNULL(SUM(cost)/sum(nature_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                            
                            SUM(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                            sum(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(cost)/sum(nature_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                            round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                            
                            round(IFNULL(SUM(nature_first_effective_role_amount_num)/SUM(nature_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                            round(IFNULL(SUM(nature_new_user_total_effective_role_amount_num)/SUM(nature_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                            ROUND(IFNULL(SUM(nature_new_user_total_amount)/SUM(nature_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                            ROUND(IFNULL(SUM(nature_first_new_user_amount)/SUM(nature_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + criA +
                    """
                                 ) a
                            LEFT JOIN (
                                SELECT
                                    source_system as b_source_system,
                                    parent_game_id as b_game_id,
                                    MAX(parent_game_name) as b_game_name,
                                    IFNULL(sum(nature_amount_count), 0) amount_count,
                                    IFNULL(sum(nature_amount), 0) amount,
                                    round(if(sum(nature_amount_count) > 0, sum(nature_amount) / sum(nature_amount_count), 0), 2) avg_amount
                                FROM
                                    game_ads_parent.ads_game_day_parent
                            """ + criB +
                    """
                                ) b
                            ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as e_source_system,
                                    parent_game_id as e_game_id,
                                    IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criAmount +
                    """
                                    AND agent_id = 0
                                GROUP BY parent_game_id, source_system ) e
                            ON a.game_id = e.e_game_id and a.source_system = e.e_source_system
                            LEFT JOIN(
                                SELECT
                                    source_system as h_source_system,
                                    parent_game_id as h_game_id,
                                    COUNT(DISTINCT user_id) as new_user_amount_num
                                FROM
                                    game_ads.ads_information
                            """ + criNewUser +
                    """
                                    AND agent_id = 0
                                GROUP BY parent_game_id, source_system) h
                            ON a.game_id = h.h_game_id and a.source_system = h.h_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as i_source_system,
                                    parent_game_id as i_game_id,
                                    COUNT(tempB.num) as new_user_again_num
                                FROM (
                                        SELECT
                                            source_system,
                                            parent_game_id,
                                            COUNT(user_id) num
                                        FROM
                                            game_ads.ads_information
                            """ + criNewUser +
                    """
                                            AND agent_id = 0
                                        GROUP BY
                                            user_id,
                                            parent_game_id,
                                            source_system
                                        HAVING
                                            COUNT(user_id) > 1 ) tempB
                                    GROUP BY tempB.parent_game_id, tempB.source_system ) i
                            ON a.game_id = i.i_game_id and a.source_system = i.i_source_system
                            LEFT JOIN (
                                SELECT
                                    source_system as m_source_system,
                                    parent_game_id ,
                                    COUNT(DISTINCT role_user_id) as role_num
                                FROM
                                    dw_create_role_detail
                            """ + criRoleNum +
                    """
                                    AND user_agent_id = 0
                                GROUP BY parent_game_id, source_system
                            ) m
                            ON a.game_id = m.parent_game_id and a.source_system = m.m_source_system
                            """;
        }
        //总量
        return """
                SELECT
                    a.*,
                    IFNULL(amount_count, 0) amount_count,
                    IFNULL(amount, 0) amount,
                    IFNULL(avg_amount, 0) avg_amount,
                 	IFNULL(new_user_amount_num, 0) new_user_amount_num,
                 	IFNULL(new_user_again_num, 0) new_user_again_num,
                 	IFNULL(amount_num, 0) amount_num,
                  	IFNULL(role_num, 0) role_num
                FROM(
                	SELECT
                	    source_system,
                		parent_game_id as game_id,
                		MAX(parent_game_name) as game_name,
                		parent_game_name_classify as game_classify,
                		sum(reg_num) reg_num,
                		sum(cost) cost,
                		sum(first_new_user_amount_count) first_new_user_amount_count,
                		sum(first_new_user_amount_num) first_new_user_amount_num,
                		sum(first_new_user_amount) first_new_user_amount,
                		sum(new_user_total_amount_count) new_user_total_amount_count,
                		sum(new_user_total_amount_num) new_user_total_amount_num,
                		sum(new_user_total_amount) new_user_total_amount,
                		round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) , 0), 4) first_roi,
                		round(if(sum(reg_num) > 0 , sum(first_new_user_amount_num) / sum(reg_num), 0), 4) first_amount_rate,
                		round(if(sum(reg_num) > 0, sum(new_user_total_amount_num) / sum(reg_num), 0), 4) today_amount_rate,
                		round(if(sum(first_new_user_amount_count) > 0, sum(first_new_user_amount) / sum(first_new_user_amount_count), 0), 2) first_avg_amount,
                		round(if(sum(new_user_total_amount_count) > 0, sum(new_user_total_amount) / sum(new_user_total_amount_count), 0), 2) today_avg_amount,
                		round(if(sum(new_user_total_amount_num) > 0 , sum(reg_order_user_again) / sum(new_user_total_amount_num), 0), 4) today_again_rate,
                		round(if(sum(reg_num) > 0 , sum(new_user_total_amount) / sum(reg_num), 0), 2) reg_user_arpu,
                		round(if(sum(first_new_user_amount_num) > 0 , sum(first_new_user_amount) / sum(first_new_user_amount_num), 0), 2) first_amount_arpu,
                		round(if(sum(new_user_total_amount_num) > 0 , sum(new_user_total_amount) / sum(new_user_total_amount_num), 0), 2) today_amount_arpu,
                		round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                		round(if(SUM(cost) > 0 , SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                		round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                		round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                		SUM(hundred_user_num) hundred_user_num,
                		round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                		SUM(first_role_num) first_role_num,
                		SUM(new_user_total_role_num) new_user_total_role_num,
                		round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                		round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                		round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                		round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                		
                		sum(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                        sum(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                        SUM(effective_role_num) as effective_role_num, -- 有效创角人数
                       
                        ROUND(IFNULL(SUM(first_effective_role_num)/sum(first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                        round(IFNULL(SUM(new_user_total_effective_role_num)/SUM(new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                        round(IFNULL(SUM(effective_role_num)/SUM(role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                       
                        round(IFNULL(SUM(cost)/SUM(first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                        round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                        round(IFNULL(SUM(cost)/sum(effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                       
                        SUM(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                        sum(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                       
                       
                        round(IFNULL(SUM(cost)/sum(first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                        round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                       
                        round(IFNULL(SUM(first_effective_role_amount_num)/SUM(first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                        round(IFNULL(SUM(new_user_total_effective_role_amount_num)/SUM(new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                        ROUND(IFNULL(SUM(new_user_total_amount)/SUM(new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                        ROUND(IFNULL(SUM(first_new_user_amount)/SUM(first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                	FROM
                		game_ads_parent.ads_game_day_parent
                """ + criA +
                """
                             ) a
                        LEFT JOIN (
                            SELECT
                                source_system as b_source_system,
                                parent_game_id as b_game_id,
                                MAX(parent_game_name) as b_game_name,
                                IFNULL(sum(amount_count), 0) amount_count,
                                IFNULL(sum(amount), 0) amount,
                                round(if(sum(amount_count) > 0, sum(amount) / sum(amount_count), 0), 2) avg_amount
                            FROM
                                game_ads_parent.ads_game_day_parent
                        """ + criB +
                """
                            ) b
                        ON a.game_id = b.b_game_id and a.game_name = b.b_game_name and a.source_system = b.b_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as c_source_system,
                                parent_game_id as c_game_id,
                                IFNULL(COUNT(DISTINCT user_id), 0) amount_num
                            FROM
                                game_ads.ads_information
                        """ + criAmount +
                """
                            GROUP BY parent_game_id, source_system) c
                        ON a.game_id = c.c_game_id and a.source_system = c.c_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as j_source_system,
                                parent_game_id as j_game_id,
                                COUNT(DISTINCT user_id) new_user_amount_num
                            FROM
                                game_ads.ads_information
                        """
                + criNewUser +
                """
                            GROUP BY parent_game_id, source_system) j
                        ON a.game_id = j.j_game_id and a.source_system = j.j_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as k_source_system,
                                parent_game_id as k_game_id,
                                COUNT(tempC.num) as new_user_again_num
                            FROM (
                                    SELECT
                                        source_system,
                                        parent_game_id,
                                        COUNT(user_id) num
                                    FROM
                                        game_ads.ads_information
                        """ + criNewUser +
                """
                                    GROUP BY
                                        user_id,
                                        parent_game_id,
                                        source_system
                                    HAVING
                                        COUNT(user_id) > 1 ) tempC
                                GROUP BY tempC.parent_game_id, tempC.source_system ) k
                        ON a.game_id = k.k_game_id and a.source_system = k.k_source_system
                        LEFT JOIN (
                            SELECT
                                source_system as l_source_system,
                                parent_game_id ,
                                COUNT(DISTINCT role_user_id) as role_num
                            FROM
                                dw_create_role_detail
                        """ + criRoleNum +
                """
                            GROUP BY parent_game_id, source_system
                        ) l
                        ON a.game_id = l.parent_game_id and a.source_system = l.l_source_system
                        """;
    }

    /**
     * 游戏总数据总计一栏sql
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataTotalTotalSql(String tableType, String tableName) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(sum(buy_reg_num), 0) reg_num,
                        IFNULL(sum(cost), 0) cost,
                        IFNULL(sum(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                        IFNULL(sum(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                        IFNULL(sum(buy_first_new_user_amount), 0) first_new_user_amount,
                        IFNULL(sum(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                        IFNULL(sum(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                        IFNULL(sum(buy_new_user_total_amount), 0) new_user_total_amount,
                        round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                        round(if(sum(buy_reg_num) > 0 ,sum(buy_first_new_user_amount_num) / sum(buy_reg_num), 0), 4) first_amount_rate,
                        round(if(sum(buy_reg_num) > 0, sum(buy_new_user_total_amount_num) / sum(buy_reg_num), 0), 4) today_amount_rate,
                        round(if(sum(buy_first_new_user_amount_count) > 0, sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                        round(if(sum(buy_new_user_total_amount_count) > 0, sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                        round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_reg_order_user_again) / sum(buy_new_user_total_amount_num), 0), 4) today_again_rate,
                        round(if(sum(buy_reg_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_reg_num), 0), 2) reg_user_arpu,
                        round(if(sum(buy_first_new_user_amount_num) > 0 , sum(buy_first_new_user_amount) / sum(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                        round(if(sum(buy_new_user_total_amount_num) > 0 , sum(buy_new_user_total_amount) / sum(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                        round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                        round(if(SUM(cost) > 0 , SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                        round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                        round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                        IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                        round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                        IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                        IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                        round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                        round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                        round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                        round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate,
                        
                        sum(buy_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                        sum(buy_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                        SUM(buy_effective_role_num) as effective_role_num, -- 有效创角人数
                        
                        ROUND(IFNULL(SUM(buy_first_effective_role_num)/sum(buy_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                        round(IFNULL(SUM(buy_new_user_total_effective_role_num)/SUM(buy_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                        round(IFNULL(SUM(buy_effective_role_num)/SUM(buy_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                        
                        round(IFNULL(SUM(cost)/SUM(buy_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                        round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                        round(IFNULL(SUM(cost)/sum(buy_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                        
                        SUM(buy_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                        sum(buy_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                        
                        
                        round(IFNULL(SUM(cost)/sum(buy_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                        round(IFNULL(SUM(cost)/SUM(buy_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                        
                        round(IFNULL(SUM(buy_first_effective_role_amount_num)/SUM(buy_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                        round(IFNULL(SUM(buy_new_user_total_effective_role_amount_num)/SUM(buy_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                        ROUND(IFNULL(SUM(buy_new_user_total_amount)/SUM(buy_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                        ROUND(IFNULL(SUM(buy_first_new_user_amount)/SUM(buy_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                    FROM 
                    """ + tableName;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(sum(nature_reg_num), 0) reg_num,
                        IFNULL(sum(cost), 0) cost,
                        IFNULL(sum(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                        IFNULL(sum(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                        IFNULL(sum(nature_first_new_user_amount), 0) first_new_user_amount,
                        IFNULL(sum(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                        IFNULL(sum(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                        IFNULL(sum(nature_new_user_total_amount), 0) new_user_total_amount,
                        
                        IFNULL(sum(nature_new_user_total_wx_amount),0) nature_new_user_total_wx_amount,
                        IFNULL(sum(nature_new_user_total_zfb_amount),0) nature_new_user_total_zfb_amount,
                        IFNULL(sum(nature_new_user_total_mds_amount),0) nature_new_user_total_mds_amount,
                        
                        round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                        round(if(sum(nature_reg_num) > 0 ,sum(nature_first_new_user_amount_num) / sum(nature_reg_num), 0), 4) first_amount_rate,
                        round(if(sum(nature_reg_num) > 0, sum(nature_new_user_total_amount_num) / sum(nature_reg_num), 0), 4) today_amount_rate,
                        round(if(sum(nature_first_new_user_amount_count) > 0, sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                        round(if(sum(nature_new_user_total_amount_count) > 0, sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                        round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_reg_order_user_again) / sum(nature_new_user_total_amount_num), 0), 4) today_again_rate,
                        round(if(sum(nature_reg_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_reg_num), 0), 2) reg_user_arpu,
                        round(if(sum(nature_first_new_user_amount_num) > 0 , sum(nature_first_new_user_amount) / sum(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                        round(if(sum(nature_new_user_total_amount_num) > 0 , sum(nature_new_user_total_amount) / sum(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                        round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                        round(if(SUM(cost) > 0 , SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                        round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                        round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                        IFNULL(SUM(nature_hundred_user_num), 0) hundred_user_num,
                        round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                        IFNULL(SUM(nature_first_role_num), 0) first_role_num,
                        IFNULL(SUM(nature_new_user_total_role_num), 0) new_user_total_role_num,
                        round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                        round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                        round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                        round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate,
                        
                        sum(nature_first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                        sum(nature_new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                        SUM(nature_effective_role_num) as effective_role_num, -- 有效创角人数
                        
                        ROUND(IFNULL(SUM(nature_first_effective_role_num)/sum(nature_first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                        round(IFNULL(SUM(nature_new_user_total_effective_role_num)/SUM(nature_new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                        round(IFNULL(SUM(nature_effective_role_num)/SUM(nature_role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                        
                        round(IFNULL(SUM(cost)/SUM(nature_first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                        round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                        round(IFNULL(SUM(cost)/sum(nature_effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                        
                        SUM(nature_first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                        sum(nature_new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                        
                        round(IFNULL(SUM(cost)/sum(nature_first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                        round(IFNULL(SUM(cost)/SUM(nature_new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                        
                        round(IFNULL(SUM(nature_first_effective_role_amount_num)/SUM(nature_first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                        round(IFNULL(SUM(nature_new_user_total_effective_role_amount_num)/SUM(nature_new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                        ROUND(IFNULL(SUM(nature_new_user_total_amount)/SUM(nature_new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                        ROUND(IFNULL(SUM(nature_first_new_user_amount)/SUM(nature_first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                    FROM 
                    """ + tableName;
        }
        //总量数据
        return """
                SELECT
                    IFNULL(sum(reg_num), 0) reg_num,
                    IFNULL(sum(cost), 0) cost,
                    IFNULL(sum(first_new_user_amount_count), 0) first_new_user_amount_count,
                    IFNULL(sum(first_new_user_amount_num), 0) first_new_user_amount_num,
                    IFNULL(sum(first_new_user_amount), 0) first_new_user_amount,
                    IFNULL(sum(new_user_total_amount_count), 0) new_user_total_amount_count,
                    IFNULL(sum(new_user_total_amount_num), 0) new_user_total_amount_num,
                    IFNULL(sum(new_user_total_amount), 0) new_user_total_amount,
                    round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                    round(if(sum(reg_num) > 0 ,sum(first_new_user_amount_num) / sum(reg_num), 0), 4) first_amount_rate,
                    round(if(sum(reg_num) > 0, sum(new_user_total_amount_num) / sum(reg_num), 0), 4) today_amount_rate,
                    round(if(sum(first_new_user_amount_count) > 0, sum(first_new_user_amount) / sum(first_new_user_amount_count), 0), 2) first_avg_amount,
                    round(if(sum(new_user_total_amount_count) > 0, sum(new_user_total_amount) / sum(new_user_total_amount_count), 0), 2) today_avg_amount,
                    round(if(sum(new_user_total_amount_num) > 0 , sum(reg_order_user_again) / sum(new_user_total_amount_num), 0), 4) today_again_rate,
                    round(if(sum(reg_num) > 0 , sum(new_user_total_amount) / sum(reg_num), 0), 2) reg_user_arpu,
                    round(if(sum(first_new_user_amount_num) > 0 , sum(first_new_user_amount) / sum(first_new_user_amount_num), 0), 2) first_amount_arpu,
                    round(if(sum(new_user_total_amount_num) > 0 , sum(new_user_total_amount) / sum(new_user_total_amount_num), 0), 2) today_amount_arpu,
                    round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                    round(if(SUM(cost) > 0 , SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                    round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                    round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                    IFNULL(SUM(hundred_user_num), 0) hundred_user_num,
                    round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                    IFNULL(SUM(first_role_num), 0) first_role_num,
                    IFNULL(SUM(new_user_total_role_num), 0) new_user_total_role_num,
                    round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                    round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                    round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                    round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate,
                    
                    sum(first_effective_role_num) as first_effective_role_num,  -- 首日有效创角人数
                    sum(new_user_total_effective_role_num) as new_user_total_effective_role_num,  -- 新用户累计有效创角人数
                    SUM(effective_role_num) as effective_role_num, -- 有效创角人数
                    
                    ROUND(IFNULL(SUM(first_effective_role_num)/sum(first_role_num),0)*100,2) as first_effective_role_rate,   -- 首日有效创角率 = 首日有效创角人数/首日创角人数
                    round(IFNULL(SUM(new_user_total_effective_role_num)/SUM(new_user_total_role_num),0)*100,2) as new_user_total_effective_role_num_rate,         -- 新用户累计有效创角率 = 新用户累计有效创角人数/新用户累计创角人数
                    round(IFNULL(SUM(effective_role_num)/SUM(role_num),0)*100,2) as effective_role_num_rate,        -- 有效创角率 = 有效创角人数/创角人数
                    
                    round(IFNULL(SUM(cost)/SUM(first_effective_role_num),0),2) as first_effective_role_num_cost, -- 首日有效创角成本= 消耗/首日有效创角人数
                    round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_num),0),2)  as new_user_total_effective_role_num_cost, -- 新用户累计有效创角成本 = 消耗/新用户累计有效创角人数
                    round(IFNULL(SUM(cost)/sum(effective_role_num),0),2) as effective_role_num_cost, -- 有效创角成本 = 消耗/有效创角人数
                    
                    SUM(first_effective_role_amount_num) as first_effective_role_amount_num, -- 首日有效创角付费人数
                    sum(new_user_total_effective_role_amount_num) as new_user_total_effective_role_amount_num, -- 新用户累计有效创角付费人数
                    
                    round(IFNULL(SUM(cost)/sum(first_effective_role_amount_num),0),2) as first_effective_role_amount_num_cost, -- 首日有效创角付费成本=消耗/首日有效创角付费人数
                    round(IFNULL(SUM(cost)/SUM(new_user_total_effective_role_amount_num),0),2) as new_user_total_effective_role_amount_num_cost, -- 新用户累计有效创角付费成本=消耗/新用户累计有效创角付费人数
                    
                    round(IFNULL(SUM(first_effective_role_amount_num)/SUM(first_new_user_amount_count),0)*100,2) as first_effective_role_amount_num_rate,  -- 首日有效创角付费比=首日有效创角付费人数/首日新用户充值人数
                    round(IFNULL(SUM(new_user_total_effective_role_amount_num)/SUM(new_user_total_amount_count),0)*100,2) as new_user_total_effective_role_amount_num_rate, -- 新用户累计有效创角付费比=新用户累计有效创角付费人数/新用户累计充值人数
                    ROUND(IFNULL(SUM(new_user_total_amount)/SUM(new_user_total_effective_role_num),0),2) as first_effective_role_arpu,    -- 新用户累计有效创角ARPU=新用户累计充值金额/新用户累计有效创角人数
                    ROUND(IFNULL(SUM(first_new_user_amount)/SUM(first_effective_role_num),0),2) as new_user_total_effective_role_arpu -- 首日有效创角ARPU=首日新用户充值金额/首日有效创角人数
                FROM 
                """ + tableName;
    }

    /**
     * 和充值时间有关的sql(游戏总数据总计账面相关数据)
     *
     * @param tableType 查询的类型
     * @return String
     */
    private String gameDataTotalSumAmountSql(String tableType, String tableName) {
        if ("buy".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(sum(buy_amount_count),0) amount_count,
                        IFNULL(sum(buy_amount),0) amount,
                        round(if(sum(buy_amount_count) > 0, sum(buy_amount) / sum(buy_amount_count), 0), 2) avg_amount
                    FROM 
                    """ + tableName;
        } else if ("nature".equals(tableType)) {
            return """
                    SELECT
                        IFNULL(sum(nature_amount_count),0) amount_count,
                        IFNULL(sum(nature_amount),0) amount,
                        round(if(sum(nature_amount_count) > 0, sum(nature_amount) / sum(nature_amount_count), 0), 2) avg_amount
                    FROM 
                    """ + tableName;
        }
        //总量数据
        return """
                SELECT
                    IFNULL(sum(amount_count),0) amount_count,
                    IFNULL(sum(amount),0) amount,
                    round(if(sum(amount_count) > 0, sum(amount) / sum(amount_count), 0), 2) avg_amount
                FROM 
                """ + tableName;
    }

    /**
     * 复充表sql（总量）
     *
     * @return String
     */
    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
                """;
    }

    /**
     * 复充表sql（买量）
     *
     * @return String
     */
    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 String
     */
    private String adsGameDataAgainNatureSql() {
        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
                """;
    }

    @Override
    public Page<GameDataH5VO> getH5Recharge(GameDataH5DTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> gameIds = dto.getGameId() == null ? poerInfo.second : Collections.singletonList(dto.getGameId());
        if (null == dto.getCostBeginDate() || null == dto.getCostEndDate()) {
            dto.setCostEndDate(LocalDate.now());
            dto.setCostBeginDate(LocalDate.now());
        }
        if (null == dto.getRechargeBeginDate() || null == dto.getRechargeEndDate()) {
            dto.setRechargeEndDate(LocalDate.now());
            dto.setRechargeBeginDate(LocalDate.now());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            dto.setSortFiled("h5_nature_new_user_total_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("a.game_name", dto.getGameName());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("a.source_system", dto.getSourceSystem());
        }
        if (null != gameIds) {
            cri.where().andInList("a.game_id", gameIds);
        }
        cri.where().and("a.dt", ">=", dto.getCostBeginDate()).and("a.dt", "<=", dto.getCostEndDate());
        cri.where().andEquals("a.id", 1);
        cri.groupBy("a.source_system,a.game_id");
        cri.orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        Sql sql = Sqls.queryEntity(h5RechargeSql() + "$condition");
        sql.setPager(pager);
        Entity<GameDataH5VO> entity = dao.getEntity(GameDataH5VO.class);
        sql.setEntity(entity).setCondition(cri);
        sql.setParam("rechargeBeginDay", dto.getRechargeBeginDate());
        sql.setParam("rechargeEndDay", dto.getRechargeEndDate());
        dao.execute(sql);
        Sql sqlCount = Sqls.queryEntity("select count(*) from ads_h5_game_day a " + "$condition");
        sqlCount.setCondition(cri);
        pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
        if (pager.getRecordCount() < 1) {
            // 没数据，直接返回
            return new Page<>();
        }

        //h5注册时间内的dayn充值数据，dayn的json数据
        Map<String, Object> dayNMap = new HashMap<>(4);
        dayNMap.put("beginDay", dto.getCostBeginDate());
        dayNMap.put("endDay", dto.getCostEndDate());

        //h5导量注册时间内的dayn充值数据，dayn的json数据
        Map<String, Object> importDayNMap = new HashMap<>(4);
        importDayNMap.put("beginDay", dto.getCostBeginDate());
        importDayNMap.put("endDay", dto.getCostEndDate());

        //h5账面
        String show = """
                select
                sum(a.h5_buy_amount) as h5_buy_amount,
                (select count(distinct user_id) from ads_information
                where
                source_system = a.source_system
                and h5_game_id = a.game_id
                and agent_id != 0
                and classify = 5
                and order_time >= @rechargeBeginDay
                and order_time <= @rechargeEndDay) as h5_buy_amount_num,
                sum(a.h5_nature_amount) as h5_nature_amount,
                (select count(distinct user_id) from ads_information
                where
                source_system = a.source_system
                and h5_game_id = a.game_id
                and agent_id = 0
                and classify = 5
                and order_time >= @rechargeBeginDay
                and order_time <= @rechargeEndDay) as h5_nature_amount_num
                from ads_h5_game_day a
                """;
        Sql showSql = Sqls.queryEntity(show + "$condition");
        showSql.setParam("rechargeBeginDay", dto.getRechargeBeginDate());
        showSql.setParam("rechargeEndDay", dto.getRechargeEndDate());
        Entity<ShowRecharge> showEntity = dao.getEntity(ShowRecharge.class);
        List<GameDataH5VO> gameDataH5VOList = sql.getList(GameDataH5VO.class).stream().map(item -> {
            {
                SimpleCriteria showCri = Cnd.cri();
                if (StringUtils.isNotBlank(dto.getGameName())) {
                    showCri.where().andLike("a.game_name", dto.getGameName());
                }
                showCri.where().and("a.dt", ">=", dto.getRechargeBeginDate()).and("a.dt", "<=", dto.getRechargeEndDate());
                showCri.groupBy("a.source_system,a.game_id");
                Long h5GameId = item.getGameId();
                showCri.where().andEquals("a.game_id", h5GameId);
                showCri.where().andEquals("a.id", 1);
                String sourceSystem = item.getSourceSystem();
                showCri.where().andEquals("a.source_system", sourceSystem);
                showSql.setEntity(showEntity).setCondition(showCri);
                dao.execute(showSql);
                ShowRecharge showRecharge = showSql.getObject(ShowRecharge.class);
                if (null != showRecharge) {
                    item.setH5NatureAmount(showRecharge.getH5NatureAmount());
                    item.setH5NatureAmountNum(showRecharge.getH5NatureAmountNum());
                    item.setH5BuyAmount(showRecharge.getH5BuyAmount());
                    item.setH5BuyAmountNum(showRecharge.getH5BuyAmountNum());
                } else {
                    item.setH5NatureAmount(BigDecimal.ZERO);
                    item.setH5NatureAmountNum(0L);
                    item.setH5BuyAmount(BigDecimal.ZERO);
                    item.setH5BuyAmountNum(0L);
                }

                dayNMap.put("sourceSystem", sourceSystem);
                dayNMap.put("h5GameId", h5GameId);

                H5DayN h5PayDayN = getH5PayDayN(dto, dayNMap);
                //h5充值时间范围内存在买量充值数据
                if (null != h5PayDayN) {
                    item.setH5NewUserRechargeMoney(h5PayDayN.getRechargeMoney());
                    item.setH5NewUserRechargeNum(h5PayDayN.getRechargeNum());
                } else {
                    item.setH5NewUserRechargeMoney(BigDecimal.ZERO);
                    item.setH5NewUserRechargeNum(0L);
                }
                H5DayN h5NatureDayN = getNatureH5DayN(dto, dayNMap);
                //h5充值时间范围内存在自然量充值数据
                if (null != h5NatureDayN) {
                    item.setH5NewUserNatureRechargeMoney(h5NatureDayN.getRechargeMoney());
                    item.setH5NewUserNatureRechargeNum(h5NatureDayN.getRechargeNum());
                } else {
                    item.setH5NewUserNatureRechargeMoney(BigDecimal.ZERO);
                    item.setH5NewUserNatureRechargeNum(0L);
                }
                item.setH5NewUserNatureRechargeRate(null == item.getH5NewUserNatureRechargeMoney() || null == item.getH5NewUserRechargeMoney() || item.getH5NewUserRechargeMoney().compareTo(BigDecimal.ZERO) == 0 ?
                        BigDecimal.ZERO : item.getH5NewUserNatureRechargeMoney().divide(item.getH5NewUserRechargeMoney(), 4, RoundingMode.DOWN));
                item.setH5NewUserNatureNewUserRate(null == item.getH5NewUserRechargeNum() || null == item.getH5NewUserNatureRechargeNum() || item.getH5NewUserRechargeNum() == 0 ?
                        BigDecimal.ZERO : BigDecimal.valueOf(item.getH5NewUserNatureRechargeNum()).divide(BigDecimal.valueOf(item.getH5NewUserRechargeNum()), 4, RoundingMode.DOWN));

                //买量导入用户数据
                List<H5BuyUserVO> buyGameList = getH5BuyUserVOList(dto, importDayNMap, item);
                //官方导入用户数据
                List<H5NatureUserVO> natureGameList = getH5NatureUserVOList(dto, importDayNMap, item);

                item.setH5BuyUserVOList(buyGameList);
                item.setH5NatureUserVOList(natureGameList);
                return item;
            }
        }).collect(Collectors.toList());

        return new Page<>(gameDataH5VOList, pager);
    }

    /**
     * ltv数据
     *
     * @param dto 前端查询条件参数实体
     * @return 分页数据
     */
    @Override
    public Page<LtvDataVO> getLtvData(LtvDataDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = dto.getGameId() == null ? poerInfo.second : dto.getGameId();

        //默认查询的字段及表名
        String gameColumn = "game_id";
        String classifyColumn = "game_classify";

        if (dto.getGameDimension() == null) {
            //默认查询子游戏维度
            dto.setGameDimension(1L);
        }
        if (dto.getGameDimension() == 2L) {
            //父游戏维度
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            //查询时间不传递默认传递当天
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //默认查询总数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //创建查询条件
        Criteria cri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(userGameIds)) {
            cri.where().andInList(gameColumn, userGameIds);
        }
        //拼接游戏应用类型
        if (dto.getClassify() != null) {
            cri.where().andEquals(classifyColumn, dto.getClassify());
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //拼接排序条件
        Criteria orderByCri = Cnd.cri();
        //如果没有排序条件给默认值
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            orderByCri.getOrderBy().orderBy("cost_date", dto.getSortType());
            orderByCri.getOrderBy().orderBy("cost", dto.getSortType());
        } else {
            orderByCri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        }
        //设置pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        //创建sql查询数据
        Sql sql;
        if (dto.getGameDimension() == 1L) {
            sql = Sqls.create(getLtvDataByTableTypesSql(dto.getTableTypes(), cri) + orderByCri);
            //设置查询总数
            pager.setRecordCount(dao.count(AdsGameDay.class, cri));
        } else {
            sql = Sqls.create(getLtvDataByTableTypesSqlForParent(dto.getTableTypes(), cri) + orderByCri);
            //设置查询总数
            pager.setRecordCount(dao.count(AdsGameDayParent.class, cri));
        }
        //设置自定义回传类型
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(LtvDataVO.class));
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<LtvDataVO> list = sql.getList(LtvDataVO.class);

        return new Page<>(list, pager);
    }

    /**
     * ltv数据总计一栏
     *
     * @param dto 前端查询参数实体
     * @return 总计对象
     */
    @Override
    public LtvDataTotalVO getLtvTotalData(LtvDataTotalDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = dto.getGameId() == null ? poerInfo.second : dto.getGameId();

        //默认查询的字段及表名
        String gameColumn = "game_id";
        String classifyColumn = "game_classify";
        String tableName = "ads_game_day";
        String tableNameForLTVData = "game_ads.ads_user_role_ltv_trend";

        if (dto.getGameDimension() == null) {
            //默认子游戏维度
            dto.setGameDimension(1L);
        }
        if (dto.getGameDimension() == 2L) {
            //父游戏维度
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_name_classify";
            tableName = "game_ads_parent.ads_game_day_parent";
            tableNameForLTVData = "game_ads_parent.ads_user_role_ltv_trend_parent";
        }
        //如果没有传入查询时间默认查询当天
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //默认查询总数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //新增查询条件
        Criteria cri = Cnd.cri();
        if (CollectionUtils.isNotEmpty(userGameIds)) {
            //拼接游戏id
            cri.where().andInList(gameColumn, userGameIds);
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        if (dto.getClassify() != null) {
            cri.where().andEquals(classifyColumn, dto.getClassify());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接查询时间
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }

        //创建sql 获取游戏数据部分的数据
        Sql sqlGameData = Sqls.create(getTotalGameData(dto.getTableTypes(), tableName) + cri);
        //设置自定义回传对象
        sqlGameData.setCallback(Sqls.callback.entity());
        sqlGameData.setEntity(dao.getEntity(LtvDataTotalVO.class));
        //执行sql
        dao.execute(sqlGameData);
        //得到每日总计对象
        LtvDataTotalVO voGameData = sqlGameData.getObject(LtvDataTotalVO.class);

        //创建sql 获取ltv数据部分的数据
        Sql sqlLtvData = Sqls.create(getLtvDataTotalAboutLtv(dto.getTableTypes(), tableNameForLTVData) + cri);
        //设置自定义回传对象
        sqlLtvData.setCallback(Sqls.callback.entity());
        sqlLtvData.setEntity(dao.getEntity(LtvDataTotalVO.class));
        //执行sql
        dao.execute(sqlLtvData);
        //得到每日总计对象
        LtvDataTotalVO voLtvData = sqlLtvData.getObject(LtvDataTotalVO.class);
        //将两个对象的属性结合
        copyNullProperties(voLtvData, voGameData);
        //返回
        return voGameData;
    }

    /**
     * 游戏首日复充
     *
     * @param dto GameDataFirstNewUserAgainDTO
     * @return Page<GameDataFirstNewUserAgainVO>
     */
    @Override
    public Page<GameDataFirstNewUserAgainVO> getFirstNewUserAgain(GameDataFirstNewUserAgainDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = dto.getGameId() == null ? poerInfo.second : dto.getGameId();

        //默认查看子游戏维度数据
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            //查询时间不传递默认传递当天
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //默认查询总数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //创建查询条件
        Criteria cri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(userGameIds)) {
            if (dto.getGameDimension() == 1L) {
                cri.where().andInList("game_id", userGameIds);
            } else if (dto.getGameDimension() == 2L) {
                cri.where().andInList("parent_game_id", userGameIds);
            }
        }
        //拼接游戏应用类型
        if (dto.getClassify() != null) {
            if (dto.getGameDimension() == 1L) {
                cri.where().andEquals("game_classify", dto.getClassify());
            } else if (dto.getGameDimension() == 2L) {
                cri.where().andEquals("parent_game_name_classify", dto.getClassify());
            }
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //拼接排序条件
        Criteria orderByCri = Cnd.cri();
        //如果没有排序条件给默认值
        if (StringUtils.isBlank(dto.getSortType())) {
            dto.setSortType(OrderByEnum.DESC.getOrderType());
        }
        if (StringUtils.isBlank(dto.getSortFiled())) {
            orderByCri.getOrderBy().orderBy("cost_date", dto.getSortType());
            orderByCri.getOrderBy().orderBy("cost", dto.getSortType());
        } else {
            orderByCri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
        }
        //创建sql查询数据
        Sql sql;
        if (dto.getGameDimension() == 1L) {
            sql = Sqls.create(getFirstNewUserAgainByTableTypesSql(dto.getTableTypes(), cri) + orderByCri);
        } else {
            sql = Sqls.create(getFirstNewUserAgainByTableTypesSqlForParent(dto.getTableTypes(), cri) + orderByCri);
        }
        //设置自定义回传类型
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(GameDataFirstNewUserAgainVO.class));
        //设置pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        sql.setPager(pager);
        //执行sql
        dao.execute(sql);
        //得到结果集list
        List<GameDataFirstNewUserAgainVO> list = sql.getList(GameDataFirstNewUserAgainVO.class);
        //设置查询总数
        if (dto.getGameDimension() == 1L) {
            pager.setRecordCount(dao.count(AdsGameDay.class, cri));
        } else {
            pager.setRecordCount(dao.count(AdsGameDayParent.class, cri));
        }
        //查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id
        Map<String, String> gameDateUsersIdMap = findUsersId(dto);
        List<GameDataFirstNewUserAgainVO> gameDataFirstNewUserAgainVOList = list.stream().map(vo -> {
            //将gameId和需要查询的注册时间拼接
            String gameIdDate = vo.getGameId() + "/" + vo.getCostDate();
            //取出所有usersId
            Long[] usersID = ArrayUtils.EMPTY_LONG_OBJECT_ARRAY;
            if (gameDateUsersIdMap.containsKey(gameIdDate)) {
                //string[] -> Long[]
                usersID = Arrays.stream(gameDateUsersIdMap.get(gameIdDate)
                                .split("/"))
                        .map(Long::parseLong)
                        .toArray(Long[]::new);
            }
            //将string转成 FirstNewUserAgainTrendVO 对象
            formatFirstNewUserAgain(vo, usersID, dto);

            return vo;
        }).collect(Collectors.toList());

        return new Page<>(gameDataFirstNewUserAgainVOList, pager);
    }

    /**
     * 游戏首日复充总计
     *
     * @param dto GameDataFirstNewUserAgainTotalDTO
     * @return GameDataFirstNewUserAgainTotalVO
     */
    @Override
    public GameDataFirstNewUserAgainTotalVO getFirstNewUserAgainTotal(GameDataFirstNewUserAgainTotalDTO dto) {
        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo();
        List<Long> userGameIds = dto.getGameId() == null ? poerInfo.second : dto.getGameId();

        //默认查询的字段及表名
        String gameColumn = "game_id";
        String classifyColumn = "game_classify";
        String tableName = "ads_game_day";
        String tableNameForAgainData = "game_ads.ads_game_first_new_user_again_day";

        //默认查询 子游戏维度 数据
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        if (dto.getGameDimension() == 2L) {
            //父游戏维度
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_name_classify";
            tableName = "game_ads_parent.ads_game_day_parent";
            tableNameForAgainData = "game_ads_parent.ads_game_first_new_user_again_day_parent";
        }
        //如果没有传入查询时间默认查询当天
        if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
            dto.setRegisteredBeginDate(LocalDate.now());
            dto.setRegisteredEndDate(LocalDate.now());
        }
        //默认查询总数据
        if (StringUtils.isBlank(dto.getTableTypes())) {
            dto.setTableTypes("total");
        }
        //新增查询条件
        Criteria cri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(userGameIds)) {
            cri.where().andInList(gameColumn, userGameIds);
        }
        //拼接游戏应用类型
        if (dto.getClassify() != null) {
            cri.where().andEquals(classifyColumn, dto.getClassify());
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            //拼接SDK来源
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            //拼接查询时间
            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }

        //创建sql 获取游戏数据部分的数据
        Sql sqlGameData = Sqls.create(getTotalGameData(dto.getTableTypes(), tableName) + cri);
        //设置自定义回传对象
        sqlGameData.setCallback(Sqls.callback.entity());
        sqlGameData.setEntity(dao.getEntity(GameDataFirstNewUserAgainTotalVO.class));
        //执行sql
        dao.execute(sqlGameData);
        //得到每日总计对象
        GameDataFirstNewUserAgainTotalVO voGameData = sqlGameData.getObject(GameDataFirstNewUserAgainTotalVO.class);

        //创建sql 获取首日复充数据部分的数据
        Sql sqlAgainData = Sqls.create(firstNewUserAgainSql(dto.getTableTypes(), tableNameForAgainData) + cri);
        //设置自定义回传对象
        sqlAgainData.setCallback(Sqls.callback.entity());
        sqlAgainData.setEntity(dao.getEntity(GameDataFirstNewUserAgainTotalVO.class));
        //执行sql
        dao.execute(sqlAgainData);
        //得到每日总计对象
        GameDataFirstNewUserAgainTotalVO voAgainData = sqlAgainData.getObject(GameDataFirstNewUserAgainTotalVO.class);
        //得到所有userID
        Long[] usersIdTotal = ArrayUtils.EMPTY_LONG_OBJECT_ARRAY;
        //得到所有用户的id整合字符串
        String usersIdTotalStr = findUsersIdTotal(dto);
        if (StringUtils.isNotBlank(usersIdTotalStr)) {
            usersIdTotal = Arrays.stream(usersIdTotalStr.split("/"))
                    .map(Long::parseLong)
                    .toArray(Long[]::new);
        }
        //voAgainData有值时进行映射的取值处理
        if (StringUtils.isNotBlank(voAgainData.getDa1())) {
            //计算游戏首日复充总计
            formatFirstNewUserAgainTotal(voAgainData, usersIdTotal, dto);
        }
        //将两个对象的属性结合
        copyNullProperties(voAgainData, voGameData);
        //返回
        return voGameData;
    }

    /**
     * 用户详情
     *
     * @param dto 前端传递传销参数实体
     * @return Page对象
     */
    @Override
    public Page<GameDataUserDetailsVO> getUserDetails(GameDataUserDetailsDTO dto) {

        if (dto.getAgainTrendVO() == null || StringUtils.isBlank(dto.getAgainTrendVO().getTimeType())) {
            return new Page<>(null, dto.toPage());
        }
        //得到需要查询的usersID内容
        FirstNewUserAgainTrendVO againTrendVO = dto.getAgainTrendVO();
        if (againTrendVO.getGameDimension() == null) {
            //默认子游戏维度
            againTrendVO.setGameDimension(1L);
        }
        //处理时间条件
        String timeType = againTrendVO.getTimeType();
        //用来处理日期的字符串
        StringBuilder queryStr = new StringBuilder(StringUtils.EMPTY);
        if (timeType.startsWith("da")) {
            queryStr.append(""" 
                    INTERVAL %s day)""".formatted(
                    Integer.parseInt(timeType.substring(2)) - 1));
        } else if (timeType.startsWith("m")) {
            queryStr.append(""" 
                    INTERVAL %s month)""".formatted(timeType.substring(1)));
        } else if (timeType.startsWith("y")) {
            queryStr.append(" INTERVAL 1 year)");
        } else {
            queryStr.append(" INTERVAL 0 day)");
        }
        //拼接sourceSystem条件
        if (StringUtils.isNotBlank(againTrendVO.getSourceSystem())) {
            queryStr.append(" and source_system = '")
                    .append(againTrendVO.getSourceSystem())
                    .append("'");
        } else if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            queryStr.append(" and source_system = '")
                    .append(dto.getSourceSystem())
                    .append("'");
        }
        //拼接投手id
        if (StringUtils.isNotBlank(againTrendVO.getPitcherId())) {
            queryStr.append("and pitcher_id = '")
                    .append(againTrendVO.getPitcherId().trim())
                    .append("'");
        }
        //拼接排序条件
        //如果没有排序条件给默认值
        if (againTrendVO.getGameDimension() == 1L) {
            if (StringUtils.isBlank(dto.getSortType())) {
                dto.setSortType(OrderByEnum.DESC.getOrderType());
            }
            if (StringUtils.isBlank(dto.getSortFiled())) {
                queryStr.append(" ORDER BY today_total_amount DESC, player_id DESC");
            } else {
                queryStr.append("""
                         ORDER BY %s %s, player_id DESC
                        """.formatted(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()),
                        dto.getSortType()));
            }
        } else {
            //父游戏维度
            if (StringUtils.isBlank(dto.getSortType())) {
                dto.setSortType(OrderByEnum.DESC.getOrderType());
            }
            if (StringUtils.isBlank(dto.getSortFiled())) {
                queryStr.append(" ORDER BY today_total_amount DESC, parent_player_id DESC");
            } else {
                queryStr.append("""
                         ORDER BY %s %s, parent_player_id DESC
                        """.formatted(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()),
                        dto.getSortType()));
            }
        }
        //得到用户id数组
        Long[] usersId = againTrendVO.getUsersId();
        //查询具体的数据
        Sql userDetilsSql;
        if (againTrendVO.getGameDimension() == 1L) {
            userDetilsSql = Sqls.create(userDetailSql() + queryStr);
        } else {
            userDetilsSql = Sqls.create(userDetailSqlForParent() + queryStr);
        }
        //设置参数
        if ("total".equals(timeType)) {
            userDetilsSql.vars().set("amount", "total_amount");
        } else {
            userDetilsSql.vars().set("amount", "today_total_amount");
        }
        if (ArrayUtils.isNotEmpty(usersId)) {
            userDetilsSql.params().set("usersId", usersId);
        } else {
            //用户不存在赋空值
            userDetilsSql.params().set("usersId", null);
        }
        //设置回传对象
        userDetilsSql.setCallback(Sqls.callback.entities());
        userDetilsSql.setEntity(dao.getEntity(GameDataUserDetailsVO.class));
        //Pager对象
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        userDetilsSql.setPager(pager);
        //执行sql
        dao.execute(userDetilsSql);
        //设置总记录数
        pager.setRecordCount(Math.toIntExact(againTrendVO.getRechargeCount()));
        //返回结果
        return new Page<>(userDetilsSql.getList(GameDataUserDetailsVO.class), pager);
    }

    /**
     * 流水监控
     *
     * @param dto 查询条件
     * @return vo
     */
    @Override
    public Page<FlowMonitorVO> getFlowMonitor(FlowMonitorDTO dto) {
        LocalDate today = LocalDate.now();
        //如果消耗时间为空，那么就给默认值
        if (dto.getCostBeginDate() == null && dto.getCostEndDate() == null) {
            LocalDate oneMonthAgo = today.minusMonths(1);
            //消耗时间如果为空，那么就给默认值当天前一个月
            dto.setCostBeginDate(oneMonthAgo);
            dto.setCostEndDate(today);
        }
        //如果订单时间为空，那么就最多查询消耗结束时间当天和前一天的数据
        if (dto.getOrderBeginDate() == null && dto.getOrderEndDate() == null) {
            //订单结束时间默认为消耗结束时间
            dto.setOrderEndDate(dto.getCostEndDate());
            //获取前一天
            LocalDate oneDaysAgo = dto.getCostEndDate().minusDays(1);
            //如果前一天在消耗开始之后或等于，那么就将订单开始时间设置为前一天
            if (oneDaysAgo.isEqual(dto.getCostBeginDate()) || oneDaysAgo.isAfter(dto.getCostBeginDate())) {
                dto.setOrderBeginDate(oneDaysAgo);
            } else {
                dto.setOrderBeginDate(dto.getCostEndDate());
            }
        }
        //分页条件
        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
        //订单表查询条件
        Criteria cri = getOrderQueryStr(dto);
        //昨日总充值金额查询条件
        Criteria yesterdayTotalAmountCri = getYesterdayTotalAmountQueryStr(dto);

        //查询总记录数SQL
        Sql countSql = dto.getGameDimension() == 2 ? Sqls.create("select count(*) from (" + flowMonitorSql(cri, yesterdayTotalAmountCri) + ") ct")
                : Sqls.create("select count(*) from (" + flowMonitorSubgameSql2(cri, yesterdayTotalAmountCri) + ") ct");
        countSql.setCallback(Sqls.callback.integer());
        log.error("充值流水执行查询总记录数, SQL : {}", countSql);
        dao.execute(countSql);
        pager.setRecordCount(countSql.getInt());

        //查询数据SQL
        Sql sql = dto.getGameDimension() == 2 ? Sqls.create(flowMonitorSql(cri, yesterdayTotalAmountCri))
                : Sqls.create(flowMonitorSubgameSql2(cri, yesterdayTotalAmountCri));
        //设置自定义回传类型
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(FlowMonitorVO.class));
        sql.setPager(pager);
        //执行sql
        log.error("充值流水执行查询记录数据, SQL : {}", sql);
        dao.execute(sql);
        //得到结果集list
        List<FlowMonitorVO> list = sql.getList(FlowMonitorVO.class);

        //获取总消耗
        Double costCount = getCostCount(dto);
        //计算回收率  充值金额/总消耗
        for (FlowMonitorVO vo : list) {
            DecimalFormat df = new DecimalFormat("#.####");

            vo.setCostCount(costCount);
            vo.setCostBeginDate(dto.getCostBeginDate());
            vo.setCostEndDate(dto.getCostEndDate());
            if (costCount != null && costCount > 0) {
                if (vo.getTenAmount() != null && vo.getTenAmount() > 0) {
                    vo.setTenRecovery(Double.parseDouble(df.format(vo.getTenAmount() / costCount)) * 100);
                }
                if (vo.getFourteenAmount() != null && vo.getFourteenAmount() > 0) {
                    vo.setFourteenRecovery(Double.parseDouble(df.format(vo.getFourteenAmount() / costCount)) * 100);
                }
                if (vo.getSeventeenAmount() != null && vo.getSeventeenAmount() > 0) {
                    vo.setSeventeenRecovery(Double.parseDouble(df.format(vo.getSeventeenAmount() / costCount)) * 100);
                }
                if (vo.getTwentyfourAmount() != null && vo.getTwentyfourAmount() > 0) {
                    vo.setTwentyfourRecovery(Double.parseDouble(df.format(vo.getTwentyfourAmount() / costCount)) * 100);
                }
            }

        }
        return new Page<>(list, pager);

    }

    /**
     * 流水监控子游戏sql
     *
     * @param cri
     * @param yesterdayTotalAmountCri
     * @return
     */
    private String flowMonitorSubgameSql2(Criteria cri, Criteria yesterdayTotalAmountCri) {
        String sql = """
                SELECT
                    day AS order_date,
                    source_system,
                    ten_amount,
                    IF(yesterday_amount > 0, ROUND(ten_amount / yesterday_amount, 4), 0) * 100 AS ten_rate,
                    fourteen_amount,
                    IF(yesterday_amount > 0, ROUND(fourteen_amount / yesterday_amount, 4), 0) * 100 AS fourteen_rate,
                    seventeen_amount,
                    IF(yesterday_amount > 0, ROUND(seventeen_amount / yesterday_amount, 4), 0) * 100 AS seventeen_rate,
                    twentyfour_amount,
                    IF(yesterday_amount > 0, ROUND(twentyfour_amount / yesterday_amount, 4), 0) * 100 AS twentyfour_rate,
                    yesterday_amount
                FROM (
                    SELECT
                        source_system,
                        day,
                        SUM(ten_amount) AS ten_amount,
                        SUM(fourteen_amount) AS fourteen_amount,
                        SUM(seventeen_amount) AS seventeen_amount,
                        SUM(twentyfour_amount) AS twentyfour_amount,
                        ANY_VALUE(yesterday_amount) AS yesterday_amount
                    FROM (
                        SELECT
                            x.source_system,
                            x.day,
                            ten_amount,
                            fourteen_amount,
                            seventeen_amount,
                            twentyfour_amount,
                            (
                                SELECT SUM(amount) 
                                FROM game_dw.dw_order_day_amount
                                """ + yesterdayTotalAmountCri + """
                        AND day = adddate(x.day, -1)
                    ) AS yesterday_amount
                FROM (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        zx_pitcher_name AS pitcher_name,
                        order_agent_id,
                        agent_name,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS twentyfour_amount,
                        game_id
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        zx_pitcher_name, 
                        order_agent_id, 
                        agent_name,
                        account_id, 
                        parent_game_id, 
                        account_type, 
                        game_id
                ) x
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS ten_amount,
                        game_id
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                    AND hour(order_create_time) < 10
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        order_agent_id,
                        account_id, 
                        parent_game_id,
                        account_type, 
                        game_id
                ) b ON x.source_system = b.source_system 
                    AND x.day = b.day 
                    AND x.order_agent_id = b.order_agent_id
                    AND x.game_id = b.game_id
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS fourteen_amount,
                        game_id
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """    
                    AND hour(order_create_time) < 14
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        order_agent_id,
                        account_id, 
                        parent_game_id,
                        account_type, 
                        game_id
                ) c ON x.source_system = c.source_system 
                    AND x.day = c.day 
                    AND x.order_agent_id = c.order_agent_id
                    AND x.game_id = c.game_id
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS seventeen_amount,
                        game_id
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                                AND hour(order_create_time) < 17
                                GROUP BY 
                                    source_system, 
                                    day, 
                                    pitcher_id, 
                                    order_agent_id,
                                    account_id, 
                                    parent_game_id,
                                    account_type, 
                                    game_id
                            ) d ON x.source_system = d.source_system 
                                AND x.day = d.day 
                                AND x.order_agent_id = d.order_agent_id
                                AND x.game_id = d.game_id
                            WHERE x.source_system IS NOT NULL
                        ) a
                        GROUP BY day, source_system
                    ) abc
                    ORDER BY `day` DESC
                """;
        return sql;
    }

    /**
     * 昨日总充值金额查询条件
     *
     * @param dto
     * @return
     */
    private Criteria getYesterdayTotalAmountQueryStr(FlowMonitorDTO dto) {
        Criteria cri = Cnd.cri();

        //SDK类型
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }


        String gameColumn = "game_id";
        if (dto.getGameDimension() != 1) {
            gameColumn = "parent_game_id";
        }

        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            cri.where().andInList(gameColumn, dto.getGameId());
        }

        //消耗时间
        if (dto.getCostBeginDate() != null && dto.getCostEndDate() != null) {
            cri.where().andBetween("to_date(reg_time)", dto.getCostBeginDate(), dto.getCostEndDate());
        }


        //拼接投手ID
        if (CollectionUtils.isNotEmpty(dto.getPitcherId())) {
            cri.where().andInList("pitcher_id", dto.getPitcherId());
        }
        //拼接渠道ID
        if (CollectionUtils.isNotEmpty(dto.getAgentId())) {
            cri.where().andInList("agent_id", dto.getAgentId());
        }
        //拼接广告账号id
        if (CollectionUtils.isNotEmpty(dto.getAccountId())) {
            cri.where().andInList("account_id", dto.getAccountId());
        }

        return cri;
    }


    public Double getCostCount(FlowMonitorDTO dto) {
        //根据维度选择 子表父表
        String costTable = "game_ads.ads_recharge_monitoring_cost";
        if (dto.getGameDimension() != null && dto.getGameDimension() != 1) {
            costTable = "game_ads_parent.ads_recharge_monitoring_cost_parent";
        }
        //消耗表查询条件
        Criteria costCri = getCostQueryStr(dto);
        //查询总消耗
        Sql costSql = Sqls.create(getTotalCostSql(costCri, costTable));
        costSql.setCallback(Sqls.callback.doubleValue());
        log.error("充值流水执行查询消耗SQL : {}", costSql);
        dao.execute(costSql);
        return costSql.getDouble(0.00);
    }

    private String getTotalCostSql(Criteria costCri, String costTable) {
        String sql = """
                SELECT
                        IFNULL(sum(cost),0) costCount
                FROM 
                """ + costTable + """
                """ + costCri + """
                GROUP BY source_system
                """;
        return sql;
    }

    /**
     * 流水监控总计
     *
     * @param dto 条件参数
     * @return vo
     */
    @Override
    public FlowMonitorCountVo getFlowMonitorCount(FlowMonitorDTO dto) {
        //查询所有，所以给分页默认值
        dto.setPageNum(1);
        dto.setPageSize(100000);

        FlowMonitorCountVo vo = new FlowMonitorCountVo();
        Page<FlowMonitorVO> flowMonitor = basicService.getFlowMonitor(dto);
        List<FlowMonitorVO> records = flowMonitor.getRecords();
        if (CollectionUtils.isEmpty(records)) {
            return vo;
        }
        Double amountCount = 0.0;
        //取出24点充值，累计
        for (FlowMonitorVO record : records) {
            amountCount += record.getTwentyfourAmount();
        }
        //把amountCount的小数点后保留四位
        amountCount = new BigDecimal(amountCount).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
        vo.setAmountCount(amountCount);

        //取出总消耗
        Double costCount = records.get(0).getCostCount();
        vo.setCostCount(costCount);
        //用充值总数/总消耗
        if (amountCount != 0 && costCount != 0) {
            //防止double转成科学计数法
            BigDecimal costBigDecimal = new BigDecimal(costCount);
            BigDecimal amountBigDecimal = new BigDecimal(amountCount);
            BigDecimal bd = amountBigDecimal.divide(costBigDecimal, 4, RoundingMode.HALF_UP);
            vo.setRecoveryCount(bd.doubleValue() * 100);
        }
        return vo;
    }

    private Criteria getCostQueryStr(FlowMonitorDTO dto) {
        //消耗表条件
        Criteria criCost = Cnd.cri();
        //拼接查询时间
        if (dto.getCostBeginDate() != null && dto.getCostEndDate() != null) {
            criCost.where().andBetween("day", dto.getCostBeginDate(), dto.getCostEndDate());
        }

        String gameColumn = "game_id";
        if (dto.getGameDimension() != 1) {
            gameColumn = "parent_game_id";
        }
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            criCost.where().andInList(gameColumn, dto.getGameId());
        }
        //拼接投手ID
        if (CollectionUtils.isNotEmpty(dto.getPitcherId())) {
            criCost.where().andInList("pitcher_id", dto.getPitcherId());
        }
        //拼接渠道ID
        if (CollectionUtils.isNotEmpty(dto.getAgentId())) {
            criCost.where().andInList("agent_id", dto.getAgentId());
        }
        //拼接广告账号id
        if (CollectionUtils.isNotEmpty(dto.getAccountId())) {
            criCost.where().andInList("account_id", dto.getAccountId());
        }
        return criCost;
    }


    /**
     * 流水监控父游戏sql
     *
     * @param cri 条件
     * @return sql
     */
    public String flowMonitorSql(Criteria cri, Criteria yesterdayTotalAmountCri) {
        String sql = """
                SELECT 
                    day AS order_date,
                    source_system,
                    ten_amount,
                    IF(yesterday_amount > 0, ROUND(ten_amount / yesterday_amount, 4), 0) * 100 AS ten_rate,
                    fourteen_amount,
                    IF(yesterday_amount > 0, ROUND(fourteen_amount / yesterday_amount, 4), 0) * 100 AS fourteen_rate,
                    seventeen_amount,
                    IF(yesterday_amount > 0, ROUND(seventeen_amount / yesterday_amount, 4), 0) * 100 AS seventeen_rate,
                    twentyfour_amount,
                    IF(yesterday_amount > 0, ROUND(twentyfour_amount / yesterday_amount, 4), 0) * 100 AS twentyfour_rate,
                    yesterday_amount
                FROM (
                    SELECT 
                        day,
                        source_system,
                        SUM(ten_amount) AS ten_amount,
                        SUM(fourteen_amount) AS fourteen_amount,
                        SUM(seventeen_amount) AS seventeen_amount,
                        SUM(twentyfour_amount) AS twentyfour_amount,
                        SUM(yesterday_amount) AS yesterday_amount
                    FROM (
                        SELECT 
                            a.source_system,
                            a.day,
                            IFNULL(b.ten_amount, 0) AS ten_amount,
                            IFNULL(c.fourteen_amount, 0) AS fourteen_amount,
                            IFNULL(d.seventeen_amount, 0) AS seventeen_amount,
                            IFNULL(a.twentyfour_amount, 0) AS twentyfour_amount,
                            IFNULL(e.yesterday_amount, 0) AS yesterday_amount
                        FROM (
                            SELECT
                                source_system,
                                day,
                                pitcher_id,
                                zx_pitcher_name AS pitcher_name,
                                order_agent_id AS agent_id,
                                agent_name,
                                account_id,
                                parent_game_id AS game_id,
                                account_type,
                                SUM(amount) AS twentyfour_amount
                            FROM game_dw.dw_order_day_amount
                            """ + cri + """
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        zx_pitcher_name, 
                        order_agent_id, 
                        agent_name,
                        account_id, 
                        parent_game_id, 
                        account_type
                ) a
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS ten_amount
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                    AND HOUR(order_create_time) < 10
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        order_agent_id, 
                        account_id, 
                        parent_game_id,
                        account_type
                ) b ON a.source_system = b.source_system 
                    AND a.day = b.day 
                    AND a.agent_id = b.order_agent_id
                    AND a.game_id = b.parent_game_id
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS fourteen_amount
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                    AND HOUR(order_create_time) < 14
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        order_agent_id, 
                        account_id, 
                        parent_game_id,
                        account_type
                ) c ON a.source_system = c.source_system 
                    AND a.day = c.day 
                    AND a.agent_id = c.order_agent_id
                    AND a.game_id = c.parent_game_id
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS seventeen_amount
                    FROM game_dw.dw_order_day_amount
                    """ + cri + """
                    AND HOUR(order_create_time) < 17
                    GROUP BY 
                        source_system, 
                        day, 
                        pitcher_id, 
                        order_agent_id, 
                        account_id, 
                        parent_game_id,
                        account_type
                ) d ON a.source_system = d.source_system 
                    AND a.day = d.day 
                    AND a.agent_id = d.order_agent_id
                    AND a.game_id = d.parent_game_id
                LEFT JOIN (
                    SELECT
                        source_system,
                        day,
                        pitcher_id,
                        order_agent_id,
                        account_id,
                        parent_game_id,
                        account_type,
                        SUM(amount) AS yesterday_amount
                    FROM game_dw.dw_order_day_amount
                    """ + yesterdayTotalAmountCri + """
                            GROUP BY 
                                source_system, 
                                day, 
                                pitcher_id, 
                                order_agent_id, 
                                account_id, 
                                parent_game_id,
                                account_type
                        ) e ON a.source_system = e.source_system 
                            AND a.day = DATE(ADDDATE(e.day, 1))
                            AND a.agent_id = e.order_agent_id
                            AND a.game_id = e.parent_game_id
                    ) f
                    GROUP BY 
                        day, 
                        source_system
                ) ab  
                ORDER BY 
                    day DESC
                """;
        return sql;
    }


    /**
     * 拼接查询条件
     *
     * @param dto
     * @return
     */
    public Criteria getOrderQueryStr(FlowMonitorDTO dto) {
        Criteria cri = Cnd.cri();
        //SDK类型
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cri.where().andEquals("source_system", dto.getSourceSystem());
        }

        String gameColumn = "game_id";
        if (dto.getGameDimension() != 1) {
            gameColumn = "parent_game_id";
        }

        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            cri.where().andInList(gameColumn, dto.getGameId());
        }

        //拼接查询时间
        if (dto.getOrderBeginDate() != null && dto.getOrderEndDate() != null) {
            cri.where().andBetween("day", dto.getOrderBeginDate(), dto.getOrderEndDate());
        }
        //消耗时间
        if (dto.getCostBeginDate() != null && dto.getCostEndDate() != null) {
            cri.where().andBetween("to_date(reg_time)", dto.getCostBeginDate(), dto.getCostEndDate());
        }

        //拼接投手ID
        if (CollectionUtils.isNotEmpty(dto.getPitcherId())) {
            cri.where().andInList("pitcher_id", dto.getPitcherId());
        }
        //拼接渠道ID
        if (CollectionUtils.isNotEmpty(dto.getAgentId())) {
            cri.where().andInList("agent_id", dto.getAgentId());
        }
        //拼接广告账号id
        if (CollectionUtils.isNotEmpty(dto.getAccountId())) {
            cri.where().andInList("account_id", dto.getAccountId());
        }

        return cri;
    }


    /**
     * 查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id
     *
     * @param dto 前端查询参数
     * @return map
     */
    private Map findUsersId(GameDataFirstNewUserAgainDTO dto) {

        //默认查询子游戏维度
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        //默认查询字段
        String gameColumn = "reg_game_id";
        String classifyColumn = "classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }

        //查询每个游戏的注册首日充值用户id,在玩家充值排行榜里查找
        Criteria findUsersCri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            findUsersCri.where().andInList(gameColumn, dto.getGameId());
        }
        //拼接游戏应用类型
        if (dto.getClassify() != null) {
            findUsersCri.where().andEquals(classifyColumn, dto.getClassify());
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            findUsersCri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            findUsersCri.where().andBetween("DATE(reg_user_time)", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //不同数据类型 查询条件不同 buy、nature、total
        if ("buy".equals(dto.getTableTypes())) {
            findUsersCri.where().andNotEquals("reg_agent_id", 0);
        } else if ("nature".equals(dto.getTableTypes())) {
            findUsersCri.where().andEquals("reg_agent_id", 0);
        }
        //拼接分组条件
        Criteria groupByCri = Cnd.cri();
        if (dto.getGameDimension() == 2L) {
            //父维度
            groupByCri.getGroupBy().groupBy("parent_game_id", "DATE(reg_user_time)");
        } else {
            //子维度
            groupByCri.getGroupBy().groupBy("reg_game_id", "DATE(reg_user_time)");
        }
        Sql findUsersIdSql;
        if (dto.getGameDimension() == 1L) {
            findUsersIdSql = Sqls.create(findUsersIdSql(findUsersCri, groupByCri));
        } else {
            findUsersIdSql = Sqls.create(findUsersIdSqlForParent(findUsersCri, groupByCri));
        }
        //自定义回传
        findUsersIdSql.setCallback((connection, resultSet, sql) -> {
            Map<String, String> tempMap = new HashMap<>();
            while (resultSet.next()) {
                tempMap.put(resultSet.getString(1), resultSet.getString(2));
            }
            return tempMap;
        });
        //运行sql
        dao.execute(findUsersIdSql);
        //返回结果
        return findUsersIdSql.getObject(Map.class);
    }

    /**
     * 查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id-游戏每日
     *
     * @param dto 前端查询参数
     * @return map
     */
    private Map findUsersIdForGameData(GameDataDayDTO dto) {

        //默认查询子游戏维度
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        //默认查询字段
        String gameColumn = "reg_game_id";
        String classifyColumn = "classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }

        //查询每个游戏的注册首日充值用户id,在玩家充值排行榜里查找
        Criteria findUsersCri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            findUsersCri.where().andInList(gameColumn, dto.getGameId());
        }
        //拼接游戏应用类型
        if (dto.getGameClassify() != null) {
            findUsersCri.where().andEquals(classifyColumn, dto.getGameClassify());
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            findUsersCri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            findUsersCri.where().andBetween("DATE(reg_user_time)", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //不同数据类型 查询条件不同 buy、nature、total
        if ("buy".equals(dto.getTableTypes())) {
            findUsersCri.where().andNotEquals("reg_agent_id", 0);
        } else if ("nature".equals(dto.getTableTypes())) {
            findUsersCri.where().andEquals("reg_agent_id", 0);
        }

        Sql findUsersIdSql;
        Criteria groupByCri = Cnd.cri();
        //如果是默认查询，需要按游戏、日期分组
        if (CollectionUtils.isEmpty(dto.getGameId())) {
            //拼接分组条件
            if (dto.getGameDimension() == 2L) {
                //父维度
                groupByCri.getGroupBy().groupBy("parent_game_id", "DATE(reg_user_time)");
                findUsersIdSql = Sqls.create(findUsersIdSqlForParent(findUsersCri, groupByCri));
            } else {
                //子维度
                groupByCri.getGroupBy().groupBy("reg_game_id", "DATE(reg_user_time)");
                findUsersIdSql = Sqls.create(findUsersIdSql(findUsersCri, groupByCri));
            }
        } else {
            //选择游戏后，只按照日期分组
            //拼接分组条件
            groupByCri.getGroupBy().groupBy("DATE(reg_user_time)");
            if (dto.getGameDimension() == 1L) {
                findUsersIdSql = Sqls.create(findUsersIdSqlForGameData(findUsersCri, groupByCri));
            } else {
                findUsersIdSql = Sqls.create(findUsersIdSqlForParentForGameData(findUsersCri, groupByCri));
            }
        }
        //自定义回传
        findUsersIdSql.setCallback((connection, resultSet, sql) -> {
            Map<String, String> tempMap = new HashMap<>();
            while (resultSet.next()) {
                tempMap.put(resultSet.getString(1), resultSet.getString(2));
            }
            return tempMap;
        });
        //运行sql
        dao.execute(findUsersIdSql);
        //返回结果
        return findUsersIdSql.getObject(Map.class);
    }

    /**
     * 查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id(游戏每日总计)
     *
     * @param dto 前端查询参数
     * @return map
     */
    private String findUsersIdTotalForGameData(GameDataDayTotalDTO dto) {

        //默认查询子游戏维度
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        //默认查询字段
        String gameColumn = "reg_game_id";
        String classifyColumn = "classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }

        //查询每个游戏的注册首日充值用户id,在玩家充值排行榜里查找
        Criteria findUsersCri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            findUsersCri.where().andInList(gameColumn, dto.getGameId());
        }
        //拼接游戏应用类型
        if (dto.getGameClassify() != null) {
            findUsersCri.where().andEquals(classifyColumn, dto.getGameClassify());
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            findUsersCri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            findUsersCri.where().andBetween("DATE(reg_user_time)", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //不同数据类型 查询条件不同 buy、nature、total
        if ("buy".equals(dto.getTableTypes())) {
            findUsersCri.where().andNotEquals("reg_agent_id", 0);
        } else if ("nature".equals(dto.getTableTypes())) {
            findUsersCri.where().andEquals("reg_agent_id", 0);
        }
        Sql findUsersIdTotalSql;
        if (dto.getGameDimension() == 1L) {
            findUsersIdTotalSql = Sqls.create(findUsersIdTotalSql(findUsersCri));
        } else {
            findUsersIdTotalSql = Sqls.create(findUsersIdTotalSqlForParent(findUsersCri));
        }
        //自定义回传
        findUsersIdTotalSql.setCallback(Sqls.callback.str());
        //运行sql
        dao.execute(findUsersIdTotalSql);
        //返回结果
        return findUsersIdTotalSql.getString();
    }

    /**
     * 查询出每个游戏的注册查询时间内，注册当天且充值的所有用户id(总计一栏)
     *
     * @param dto 前端查询参数
     * @return map
     */
    private String findUsersIdTotal(GameDataFirstNewUserAgainTotalDTO dto) {

        //默认查询子游戏维度
        if (dto.getGameDimension() == null) {
            dto.setGameDimension(1L);
        }
        //默认查询字段
        String gameColumn = "reg_game_id";
        String classifyColumn = "classify";
        if (dto.getGameDimension() == 2L) {
            gameColumn = "parent_game_id";
            classifyColumn = "parent_game_classify";
        }

        //查询每个游戏的注册首日充值用户id,在玩家充值排行榜里查找
        Criteria findUsersCri = Cnd.cri();
        //拼接游戏ID
        if (CollectionUtils.isNotEmpty(dto.getGameId())) {
            findUsersCri.where().andInList(gameColumn, dto.getGameId());
        }
        //拼接游戏应用类型
        if (dto.getClassify() != null) {
            findUsersCri.where().andEquals(classifyColumn, dto.getClassify());
        }
        //拼接SDK来源
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            findUsersCri.where().andEquals("source_system", dto.getSourceSystem());
        }
        //拼接查询时间
        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
            findUsersCri.where().andBetween("DATE(reg_user_time)", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
        }
        //不同数据类型 查询条件不同 buy、nature、total
        if ("buy".equals(dto.getTableTypes())) {
            findUsersCri.where().andNotEquals("reg_agent_id", 0);
        } else if ("nature".equals(dto.getTableTypes())) {
            findUsersCri.where().andEquals("reg_agent_id", 0);
        }
        Sql findUsersIdTotalSql;
        if (dto.getGameDimension() == 1L) {
            findUsersIdTotalSql = Sqls.create(findUsersIdTotalSql(findUsersCri));
        } else {
            findUsersIdTotalSql = Sqls.create(findUsersIdTotalSqlForParent(findUsersCri));
        }
        //自定义回传
        findUsersIdTotalSql.setCallback(Sqls.callback.str());
        //运行sql
        dao.execute(findUsersIdTotalSql);
        //返回结果
        return findUsersIdTotalSql.getString();
    }

    /**
     * ltv每日数据查询sql
     *
     * @param type 查询的类型 buy -> 买量  ;  nature ->  自然量 ; total -> 总量
     * @param cri  查询条件
     * @return String
     */
    private String getLtvDataByTableTypesSql(String type, Criteria cri) {
        if ("buy".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            game_name,
                            game_id,
                            game_classify,
                            source_system,
                            cost,
                            buy_reg_num as reg_num,
                            buy_first_new_user_amount_count as first_new_user_amount_count,
                            buy_first_new_user_amount_num as first_new_user_amount_num,
                            buy_first_new_user_amount as first_new_user_amount,
                            buy_old_user_count as old_user_count,
                            buy_old_user_num as old_user_num,
                            buy_old_user_amount as old_user_amount,
                            buy_amount_count as amount_count,
                            buy_amount_num as amount_num,
                            buy_amount as amount,
                            buy_new_user_total_amount_count as new_user_total_amount_count,
                            buy_new_user_total_amount_num as new_user_total_amount_num,
                            buy_new_user_total_amount as new_user_total_amount,
                            buy_total_roi as total_roi,
                            buy_first_roi as first_roi,
                            buy_first_amount_rate as first_amount_rate,
                            buy_today_amount_rate as today_amount_rate,
                            buy_new_user_rate as new_user_rate,
                            buy_first_avg_amount as first_avg_amount,
                            buy_today_avg_amount as today_avg_amount,
                            buy_avg_amount as avg_amount,
                            buy_user_again_rate as user_again_rate,
                            buy_reg_user_arpu as reg_user_arpu,
                            buy_first_amount_arpu as first_amount_arpu,
                            buy_today_amount_arpu as today_amount_arpu,
                            buy_amount_arpu as amount_arpu,
                            buy_reg_cost as reg_cost,
                            buy_first_amount_cost as first_new_user_recharge_cost,
                            buy_total_amount_cost as total_recharge_cost,
                            buy_hundred_user_num as hundred_user_num,
                            buy_hundred_user_num_cost as hundred_user_num_cost,
                            buy_first_role_num as first_role_num,
                            buy_role_num as role_num,
                            buy_new_user_total_role_num as new_user_total_role_num,
                            round(IF(buy_first_role_num > 0, cost / buy_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(buy_role_num > 0, cost / buy_role_num, 0), 2) role_num_cost,
                            round(IF(buy_new_user_total_role_num >0, cost / buy_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(buy_reg_num >0, buy_first_role_num / buy_reg_num, 0), 4) first_role_num_rate,
                            round(IF(buy_reg_num >0, buy_role_num / buy_reg_num, 0), 4) role_num_rate,
                            round(IF(buy_reg_num >0, buy_new_user_total_role_num / buy_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            ads_game_day
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    game_id,
                                    game_name,
                                    dt,
                                    buy_user_ltv_1 as user_ltv1,
                                    buy_user_ltv_2 as user_ltv2,
                                    buy_user_ltv_3 as user_ltv3,
                                    buy_user_ltv_4 as user_ltv4,
                                    buy_user_ltv_5 as user_ltv5,
                                    buy_user_ltv_6 as user_ltv6,
                                    buy_user_ltv_7 as user_ltv7,
                                    buy_user_ltv_8 as user_ltv8,
                                    buy_user_ltv_9 as user_ltv9,
                                    buy_user_ltv_10 as user_ltv10,
                                    buy_user_ltv_11 as user_ltv11,
                                    buy_user_ltv_12 as user_ltv12,
                                    buy_user_ltv_13 as user_ltv13,
                                    buy_user_ltv_14 as user_ltv14,
                                    buy_user_ltv_15 as user_ltv15,
                                    buy_user_ltv_16 as user_ltv16,
                                    buy_user_ltv_17 as user_ltv17,
                                    buy_user_ltv_18 as user_ltv18,
                                    buy_user_ltv_19 as user_ltv19,
                                    buy_user_ltv_20 as user_ltv20,
                                    buy_user_ltv_21 as user_ltv21,
                                    buy_user_ltv_22 as user_ltv22,
                                    buy_user_ltv_23 as user_ltv23,
                                    buy_user_ltv_24 as user_ltv24,
                                    buy_user_ltv_25 as user_ltv25,
                                    buy_user_ltv_26 as user_ltv26,
                                    buy_user_ltv_27 as user_ltv27,
                                    buy_user_ltv_28 as user_ltv28,
                                    buy_user_ltv_29 as user_ltv29,
                                    buy_user_ltv_30 as user_ltv30,
                                    buy_user_ltv_31 as user_ltv31,
                                    buy_user_ltv_32 as user_ltv32,
                                    buy_user_ltv_33 as user_ltv33,
                                    buy_user_ltv_34 as user_ltv34,
                                    buy_user_ltv_35 as user_ltv35,
                                    buy_user_ltv_36 as user_ltv36,
                                    buy_user_ltv_37 as user_ltv37,
                                    buy_user_ltv_38 as user_ltv38,
                                    buy_user_ltv_39 as user_ltv39,
                                    buy_user_ltv_40 as user_ltv40,
                                    buy_user_ltv_41 as user_ltv41,
                                    buy_user_ltv_42 as user_ltv42,
                                    buy_user_ltv_43 as user_ltv43,
                                    buy_user_ltv_44 as user_ltv44,
                                    buy_user_ltv_45 as user_ltv45,
                                    buy_user_ltv_46 as user_ltv46,
                                    buy_user_ltv_47 as user_ltv47,
                                    buy_user_ltv_48 as user_ltv48,
                                    buy_user_ltv_49 as user_ltv49,
                                    buy_user_ltv_50 as user_ltv50,
                                    buy_user_ltv_51 as user_ltv51,
                                    buy_user_ltv_52 as user_ltv52,
                                    buy_user_ltv_53 as user_ltv53,
                                    buy_user_ltv_54 as user_ltv54,
                                    buy_user_ltv_55 as user_ltv55,
                                    buy_user_ltv_56 as user_ltv56,
                                    buy_user_ltv_57 as user_ltv57,
                                    buy_user_ltv_58 as user_ltv58,
                                    buy_user_ltv_59 as user_ltv59,
                                    buy_user_ltv_60 as user_ltv60,
                                    buy_user_ltv_61 as user_ltv61,
                                    buy_user_ltv_62 as user_ltv62,
                                    buy_user_ltv_63 as user_ltv63,
                                    buy_user_ltv_64 as user_ltv64,
                                    buy_user_ltv_65 as user_ltv65,
                                    buy_user_ltv_66 as user_ltv66,
                                    buy_user_ltv_67 as user_ltv67,
                                    buy_user_ltv_68 as user_ltv68,
                                    buy_user_ltv_69 as user_ltv69,
                                    buy_user_ltv_70 as user_ltv70,
                                    buy_user_ltv_71 as user_ltv71,
                                    buy_user_ltv_72 as user_ltv72,
                                    buy_user_ltv_73 as user_ltv73,
                                    buy_user_ltv_74 as user_ltv74,
                                    buy_user_ltv_75 as user_ltv75,
                                    buy_user_ltv_76 as user_ltv76,
                                    buy_user_ltv_77 as user_ltv77,
                                    buy_user_ltv_78 as user_ltv78,
                                    buy_user_ltv_79 as user_ltv79,
                                    buy_user_ltv_80 as user_ltv80,
                                    buy_user_ltv_81 as user_ltv81,
                                    buy_user_ltv_82 as user_ltv82,
                                    buy_user_ltv_83 as user_ltv83,
                                    buy_user_ltv_84 as user_ltv84,
                                    buy_user_ltv_85 as user_ltv85,
                                    buy_user_ltv_86 as user_ltv86,
                                    buy_user_ltv_87 as user_ltv87,
                                    buy_user_ltv_88 as user_ltv88,
                                    buy_user_ltv_89 as user_ltv89,
                                    buy_user_ltv_90 as user_ltv90,
                                    buy_user_ltv_m4 as user_ltv_m4,
                                    buy_user_ltv_m5 as user_ltv_m5,
                                    buy_user_ltv_m6 as user_ltv_m6,
                                    buy_user_ltv_m7 as user_ltv_m7,
                                    buy_user_ltv_m8 as user_ltv_m8,
                                    buy_user_ltv_m9 as user_ltv_m9,
                                    buy_user_ltv_m10 as user_ltv_m10,
                                    buy_user_ltv_m11 as user_ltv_m11,
                                    buy_user_ltv_y1 as user_ltv_y1,
                                    buy_user_ltv_total as user_ltv_total,
                                    buy_role_ltv_1 as role_ltv1,
                                    buy_role_ltv_2 as role_ltv2,
                                    buy_role_ltv_3 as role_ltv3,
                                    buy_role_ltv_4 as role_ltv4,
                                    buy_role_ltv_5 as role_ltv5,
                                    buy_role_ltv_6 as role_ltv6,
                                    buy_role_ltv_7 as role_ltv7,
                                    buy_role_ltv_8 as role_ltv8,
                                    buy_role_ltv_9 as role_ltv9,
                                    buy_role_ltv_10 as role_ltv10,
                                    buy_role_ltv_11 as role_ltv11,
                                    buy_role_ltv_12 as role_ltv12,
                                    buy_role_ltv_13 as role_ltv13,
                                    buy_role_ltv_14 as role_ltv14,
                                    buy_role_ltv_15 as role_ltv15,
                                    buy_role_ltv_16 as role_ltv16,
                                    buy_role_ltv_17 as role_ltv17,
                                    buy_role_ltv_18 as role_ltv18,
                                    buy_role_ltv_19 as role_ltv19,
                                    buy_role_ltv_20 as role_ltv20,
                                    buy_role_ltv_21 as role_ltv21,
                                    buy_role_ltv_22 as role_ltv22,
                                    buy_role_ltv_23 as role_ltv23,
                                    buy_role_ltv_24 as role_ltv24,
                                    buy_role_ltv_25 as role_ltv25,
                                    buy_role_ltv_26 as role_ltv26,
                                    buy_role_ltv_27 as role_ltv27,
                                    buy_role_ltv_28 as role_ltv28,
                                    buy_role_ltv_29 as role_ltv29,
                                    buy_role_ltv_30 as role_ltv30,
                                    buy_role_ltv_31 as role_ltv31,
                                    buy_role_ltv_32 as role_ltv32,
                                    buy_role_ltv_33 as role_ltv33,
                                    buy_role_ltv_34 as role_ltv34,
                                    buy_role_ltv_35 as role_ltv35,
                                    buy_role_ltv_36 as role_ltv36,
                                    buy_role_ltv_37 as role_ltv37,
                                    buy_role_ltv_38 as role_ltv38,
                                    buy_role_ltv_39 as role_ltv39,
                                    buy_role_ltv_40 as role_ltv40,
                                    buy_role_ltv_41 as role_ltv41,
                                    buy_role_ltv_42 as role_ltv42,
                                    buy_role_ltv_43 as role_ltv43,
                                    buy_role_ltv_44 as role_ltv44,
                                    buy_role_ltv_45 as role_ltv45,
                                    buy_role_ltv_46 as role_ltv46,
                                    buy_role_ltv_47 as role_ltv47,
                                    buy_role_ltv_48 as role_ltv48,
                                    buy_role_ltv_49 as role_ltv49,
                                    buy_role_ltv_50 as role_ltv50,
                                    buy_role_ltv_51 as role_ltv51,
                                    buy_role_ltv_52 as role_ltv52,
                                    buy_role_ltv_53 as role_ltv53,
                                    buy_role_ltv_54 as role_ltv54,
                                    buy_role_ltv_55 as role_ltv55,
                                    buy_role_ltv_56 as role_ltv56,
                                    buy_role_ltv_57 as role_ltv57,
                                    buy_role_ltv_58 as role_ltv58,
                                    buy_role_ltv_59 as role_ltv59,
                                    buy_role_ltv_60 as role_ltv60,
                                    buy_role_ltv_61 as role_ltv61,
                                    buy_role_ltv_62 as role_ltv62,
                                    buy_role_ltv_63 as role_ltv63,
                                    buy_role_ltv_64 as role_ltv64,
                                    buy_role_ltv_65 as role_ltv65,
                                    buy_role_ltv_66 as role_ltv66,
                                    buy_role_ltv_67 as role_ltv67,
                                    buy_role_ltv_68 as role_ltv68,
                                    buy_role_ltv_69 as role_ltv69,
                                    buy_role_ltv_70 as role_ltv70,
                                    buy_role_ltv_71 as role_ltv71,
                                    buy_role_ltv_72 as role_ltv72,
                                    buy_role_ltv_73 as role_ltv73,
                                    buy_role_ltv_74 as role_ltv74,
                                    buy_role_ltv_75 as role_ltv75,
                                    buy_role_ltv_76 as role_ltv76,
                                    buy_role_ltv_77 as role_ltv77,
                                    buy_role_ltv_78 as role_ltv78,
                                    buy_role_ltv_79 as role_ltv79,
                                    buy_role_ltv_80 as role_ltv80,
                                    buy_role_ltv_81 as role_ltv81,
                                    buy_role_ltv_82 as role_ltv82,
                                    buy_role_ltv_83 as role_ltv83,
                                    buy_role_ltv_84 as role_ltv84,
                                    buy_role_ltv_85 as role_ltv85,
                                    buy_role_ltv_86 as role_ltv86,
                                    buy_role_ltv_87 as role_ltv87,
                                    buy_role_ltv_88 as role_ltv88,
                                    buy_role_ltv_89 as role_ltv89,
                                    buy_role_ltv_90 as role_ltv90,
                                    buy_role_ltv_m4 as role_ltv_m4,
                                    buy_role_ltv_m5 as role_ltv_m5,
                                    buy_role_ltv_m6 as role_ltv_m6,
                                    buy_role_ltv_m7 as role_ltv_m7,
                                    buy_role_ltv_m8 as role_ltv_m8,
                                    buy_role_ltv_m9 as role_ltv_m9,
                                    buy_role_ltv_m10 as role_ltv_m10,
                                    buy_role_ltv_m11 as role_ltv_m11,
                                    buy_role_ltv_y1 as role_ltv_y1,
                                    buy_role_ltv_total as role_ltv_total,
                                    buy_da1 as da1,
                                    buy_da2 as da2,
                                    buy_da3 as da3,
                                    buy_da4 as da4,
                                    buy_da5 as da5,
                                    buy_da6 as da6,
                                    buy_da7 as da7,
                                    buy_da8 as da8,
                                    buy_da9 as da9,
                                    buy_da10 as da10,
                                    buy_da11 as da11,
                                    buy_da12 as da12,
                                    buy_da13 as da13,
                                    buy_da14 as da14,
                                    buy_da15 as da15,
                                    buy_da16 as da16,
                                    buy_da17 as da17,
                                    buy_da18 as da18,
                                    buy_da19 as da19,
                                    buy_da20 as da20,
                                    buy_da21 as da21,
                                    buy_da22 as da22,
                                    buy_da23 as da23,
                                    buy_da24 as da24,
                                    buy_da25 as da25,
                                    buy_da26 as da26,
                                    buy_da27 as da27,
                                    buy_da28 as da28,
                                    buy_da29 as da29,
                                    buy_da30 as da30,
                                    buy_da31 as da31,
                                    buy_da32 as da32,
                                    buy_da33 as da33,
                                    buy_da34 as da34,
                                    buy_da35 as da35,
                                    buy_da36 as da36,
                                    buy_da37 as da37,
                                    buy_da38 as da38,
                                    buy_da39 as da39,
                                    buy_da40 as da40,
                                    buy_da41 as da41,
                                    buy_da42 as da42,
                                    buy_da43 as da43,
                                    buy_da44 as da44,
                                    buy_da45 as da45,
                                    buy_da46 as da46,
                                    buy_da47 as da47,
                                    buy_da48 as da48,
                                    buy_da49 as da49,
                                    buy_da50 as da50,
                                    buy_da51 as da51,
                                    buy_da52 as da52,
                                    buy_da53 as da53,
                                    buy_da54 as da54,
                                    buy_da55 as da55,
                                    buy_da56 as da56,
                                    buy_da57 as da57,
                                    buy_da58 as da58,
                                    buy_da59 as da59,
                                    buy_da60 as da60,
                                    buy_da61 as da61,
                                    buy_da62 as da62,
                                    buy_da63 as da63,
                                    buy_da64 as da64,
                                    buy_da65 as da65,
                                    buy_da66 as da66,
                                    buy_da67 as da67,
                                    buy_da68 as da68,
                                    buy_da69 as da69,
                                    buy_da70 as da70,
                                    buy_da71 as da71,
                                    buy_da72 as da72,
                                    buy_da73 as da73,
                                    buy_da74 as da74,
                                    buy_da75 as da75,
                                    buy_da76 as da76,
                                    buy_da77 as da77,
                                    buy_da78 as da78,
                                    buy_da79 as da79,
                                    buy_da80 as da80,
                                    buy_da81 as da81,
                                    buy_da82 as da82,
                                    buy_da83 as da83,
                                    buy_da84 as da84,
                                    buy_da85 as da85,
                                    buy_da86 as da86,
                                    buy_da87 as da87,
                                    buy_da88 as da88,
                                    buy_da89 as da89,
                                    buy_da90 as da90,
                                    buy_m4 as m4,
                                    buy_m5 as m5,
                                    buy_m6 as m6,
                                    buy_m7 as m7,
                                    buy_m8 as m8,
                                    buy_m9 as m9,
                                    buy_m10 as m10,
                                    buy_m11 as m11,
                                    buy_y1 as y1,
                                    buy_total as total,
                                    buy_first_role_num as first_role_num_ltv,
                                    buy_reg_user_cnt as reg_user_cnt
                                FROM
                                    ads_user_role_ltv_trend
                            """ + cri +
                    """
                                ) b
                            ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        } else if ("nature".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            game_name,
                            game_id,
                            game_classify,
                            source_system,
                            cost,
                            nature_reg_num as reg_num,
                            nature_first_new_user_amount_count as first_new_user_amount_count,
                            nature_first_new_user_amount_num as first_new_user_amount_num,
                            nature_first_new_user_amount as first_new_user_amount,
                            nature_old_user_count as old_user_count,
                            nature_old_user_num as old_user_num,
                            nature_old_user_amount as old_user_amount,
                            nature_amount_count as amount_count,
                            nature_amount_num as amount_num,
                            nature_amount as amount,
                            nature_new_user_total_amount_count as new_user_total_amount_count,
                            nature_new_user_total_amount_num as new_user_total_amount_num,
                            nature_new_user_total_amount as new_user_total_amount,
                            nature_total_roi as total_roi,
                            nature_first_roi as first_roi,
                            nature_first_amount_rate as first_amount_rate,
                            nature_today_amount_rate as today_amount_rate,
                            nature_new_user_rate as new_user_rate,
                            nature_first_avg_amount as first_avg_amount,
                            nature_today_avg_amount as today_avg_amount,
                            nature_avg_amount as avg_amount,
                            nature_user_again_rate as user_again_rate,
                            nature_reg_user_arpu as reg_user_arpu,
                            nature_first_amount_arpu as first_amount_arpu,
                            nature_today_amount_arpu as today_amount_arpu,
                            nature_amount_arpu as amount_arpu,
                            nature_reg_cost as reg_cost,
                            nature_first_amount_cost as first_new_user_recharge_cost,
                            nature_total_amount_cost as total_recharge_cost,
                            nature_hundred_user_num as hundred_user_num,
                            nature_hundred_user_num_cost as hundred_user_num_cost,
                            nature_first_role_num as first_role_num,
                            nature_role_num as role_num,
                            nature_new_user_total_role_num as new_user_total_role_num,
                            round(IF(nature_first_role_num > 0, cost / nature_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(nature_role_num > 0, cost / nature_role_num, 0), 2) role_num_cost,
                            round(IF(nature_new_user_total_role_num >0, cost / nature_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(nature_reg_num >0, nature_first_role_num / nature_reg_num, 0), 4) first_role_num_rate,
                            round(IF(nature_reg_num >0, nature_role_num / nature_reg_num, 0), 4) role_num_rate,
                            round(IF(nature_reg_num >0, nature_new_user_total_role_num / nature_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            ads_game_day
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    game_id,
                                    game_name,
                                    dt,
                                    nature_user_ltv_1 as user_ltv1,
                                    nature_user_ltv_2 as user_ltv2,
                                    nature_user_ltv_3 as user_ltv3,
                                    nature_user_ltv_4 as user_ltv4,
                                    nature_user_ltv_5 as user_ltv5,
                                    nature_user_ltv_6 as user_ltv6,
                                    nature_user_ltv_7 as user_ltv7,
                                    nature_user_ltv_8 as user_ltv8,
                                    nature_user_ltv_9 as user_ltv9,
                                    nature_user_ltv_10 as user_ltv10,
                                    nature_user_ltv_11 as user_ltv11,
                                    nature_user_ltv_12 as user_ltv12,
                                    nature_user_ltv_13 as user_ltv13,
                                    nature_user_ltv_14 as user_ltv14,
                                    nature_user_ltv_15 as user_ltv15,
                                    nature_user_ltv_16 as user_ltv16,
                                    nature_user_ltv_17 as user_ltv17,
                                    nature_user_ltv_18 as user_ltv18,
                                    nature_user_ltv_19 as user_ltv19,
                                    nature_user_ltv_20 as user_ltv20,
                                    nature_user_ltv_21 as user_ltv21,
                                    nature_user_ltv_22 as user_ltv22,
                                    nature_user_ltv_23 as user_ltv23,
                                    nature_user_ltv_24 as user_ltv24,
                                    nature_user_ltv_25 as user_ltv25,
                                    nature_user_ltv_26 as user_ltv26,
                                    nature_user_ltv_27 as user_ltv27,
                                    nature_user_ltv_28 as user_ltv28,
                                    nature_user_ltv_29 as user_ltv29,
                                    nature_user_ltv_30 as user_ltv30,
                                    nature_user_ltv_31 as user_ltv31,
                                    nature_user_ltv_32 as user_ltv32,
                                    nature_user_ltv_33 as user_ltv33,
                                    nature_user_ltv_34 as user_ltv34,
                                    nature_user_ltv_35 as user_ltv35,
                                    nature_user_ltv_36 as user_ltv36,
                                    nature_user_ltv_37 as user_ltv37,
                                    nature_user_ltv_38 as user_ltv38,
                                    nature_user_ltv_39 as user_ltv39,
                                    nature_user_ltv_40 as user_ltv40,
                                    nature_user_ltv_41 as user_ltv41,
                                    nature_user_ltv_42 as user_ltv42,
                                    nature_user_ltv_43 as user_ltv43,
                                    nature_user_ltv_44 as user_ltv44,
                                    nature_user_ltv_45 as user_ltv45,
                                    nature_user_ltv_46 as user_ltv46,
                                    nature_user_ltv_47 as user_ltv47,
                                    nature_user_ltv_48 as user_ltv48,
                                    nature_user_ltv_49 as user_ltv49,
                                    nature_user_ltv_50 as user_ltv50,
                                    nature_user_ltv_51 as user_ltv51,
                                    nature_user_ltv_52 as user_ltv52,
                                    nature_user_ltv_53 as user_ltv53,
                                    nature_user_ltv_54 as user_ltv54,
                                    nature_user_ltv_55 as user_ltv55,
                                    nature_user_ltv_56 as user_ltv56,
                                    nature_user_ltv_57 as user_ltv57,
                                    nature_user_ltv_58 as user_ltv58,
                                    nature_user_ltv_59 as user_ltv59,
                                    nature_user_ltv_60 as user_ltv60,
                                    nature_user_ltv_61 as user_ltv61,
                                    nature_user_ltv_62 as user_ltv62,
                                    nature_user_ltv_63 as user_ltv63,
                                    nature_user_ltv_64 as user_ltv64,
                                    nature_user_ltv_65 as user_ltv65,
                                    nature_user_ltv_66 as user_ltv66,
                                    nature_user_ltv_67 as user_ltv67,
                                    nature_user_ltv_68 as user_ltv68,
                                    nature_user_ltv_69 as user_ltv69,
                                    nature_user_ltv_70 as user_ltv70,
                                    nature_user_ltv_71 as user_ltv71,
                                    nature_user_ltv_72 as user_ltv72,
                                    nature_user_ltv_73 as user_ltv73,
                                    nature_user_ltv_74 as user_ltv74,
                                    nature_user_ltv_75 as user_ltv75,
                                    nature_user_ltv_76 as user_ltv76,
                                    nature_user_ltv_77 as user_ltv77,
                                    nature_user_ltv_78 as user_ltv78,
                                    nature_user_ltv_79 as user_ltv79,
                                    nature_user_ltv_80 as user_ltv80,
                                    nature_user_ltv_81 as user_ltv81,
                                    nature_user_ltv_82 as user_ltv82,
                                    nature_user_ltv_83 as user_ltv83,
                                    nature_user_ltv_84 as user_ltv84,
                                    nature_user_ltv_85 as user_ltv85,
                                    nature_user_ltv_86 as user_ltv86,
                                    nature_user_ltv_87 as user_ltv87,
                                    nature_user_ltv_88 as user_ltv88,
                                    nature_user_ltv_89 as user_ltv89,
                                    nature_user_ltv_90 as user_ltv90,
                                    nature_user_ltv_m4 as user_ltv_m4,
                                    nature_user_ltv_m5 as user_ltv_m5,
                                    nature_user_ltv_m6 as user_ltv_m6,
                                    nature_user_ltv_m7 as user_ltv_m7,
                                    nature_user_ltv_m8 as user_ltv_m8,
                                    nature_user_ltv_m9 as user_ltv_m9,
                                    nature_user_ltv_m10 as user_ltv_m10,
                                    nature_user_ltv_m11 as user_ltv_m11,
                                    nature_user_ltv_y1 as user_ltv_y1,
                                    nature_user_ltv_total as user_ltv_total,
                                    nature_role_ltv_1 as role_ltv1,
                                    nature_role_ltv_2 as role_ltv2,
                                    nature_role_ltv_3 as role_ltv3,
                                    nature_role_ltv_4 as role_ltv4,
                                    nature_role_ltv_5 as role_ltv5,
                                    nature_role_ltv_6 as role_ltv6,
                                    nature_role_ltv_7 as role_ltv7,
                                    nature_role_ltv_8 as role_ltv8,
                                    nature_role_ltv_9 as role_ltv9,
                                    nature_role_ltv_10 as role_ltv10,
                                    nature_role_ltv_11 as role_ltv11,
                                    nature_role_ltv_12 as role_ltv12,
                                    nature_role_ltv_13 as role_ltv13,
                                    nature_role_ltv_14 as role_ltv14,
                                    nature_role_ltv_15 as role_ltv15,
                                    nature_role_ltv_16 as role_ltv16,
                                    nature_role_ltv_17 as role_ltv17,
                                    nature_role_ltv_18 as role_ltv18,
                                    nature_role_ltv_19 as role_ltv19,
                                    nature_role_ltv_20 as role_ltv20,
                                    nature_role_ltv_21 as role_ltv21,
                                    nature_role_ltv_22 as role_ltv22,
                                    nature_role_ltv_23 as role_ltv23,
                                    nature_role_ltv_24 as role_ltv24,
                                    nature_role_ltv_25 as role_ltv25,
                                    nature_role_ltv_26 as role_ltv26,
                                    nature_role_ltv_27 as role_ltv27,
                                    nature_role_ltv_28 as role_ltv28,
                                    nature_role_ltv_29 as role_ltv29,
                                    nature_role_ltv_30 as role_ltv30,
                                    nature_role_ltv_31 as role_ltv31,
                                    nature_role_ltv_32 as role_ltv32,
                                    nature_role_ltv_33 as role_ltv33,
                                    nature_role_ltv_34 as role_ltv34,
                                    nature_role_ltv_35 as role_ltv35,
                                    nature_role_ltv_36 as role_ltv36,
                                    nature_role_ltv_37 as role_ltv37,
                                    nature_role_ltv_38 as role_ltv38,
                                    nature_role_ltv_39 as role_ltv39,
                                    nature_role_ltv_40 as role_ltv40,
                                    nature_role_ltv_41 as role_ltv41,
                                    nature_role_ltv_42 as role_ltv42,
                                    nature_role_ltv_43 as role_ltv43,
                                    nature_role_ltv_44 as role_ltv44,
                                    nature_role_ltv_45 as role_ltv45,
                                    nature_role_ltv_46 as role_ltv46,
                                    nature_role_ltv_47 as role_ltv47,
                                    nature_role_ltv_48 as role_ltv48,
                                    nature_role_ltv_49 as role_ltv49,
                                    nature_role_ltv_50 as role_ltv50,
                                    nature_role_ltv_51 as role_ltv51,
                                    nature_role_ltv_52 as role_ltv52,
                                    nature_role_ltv_53 as role_ltv53,
                                    nature_role_ltv_54 as role_ltv54,
                                    nature_role_ltv_55 as role_ltv55,
                                    nature_role_ltv_56 as role_ltv56,
                                    nature_role_ltv_57 as role_ltv57,
                                    nature_role_ltv_58 as role_ltv58,
                                    nature_role_ltv_59 as role_ltv59,
                                    nature_role_ltv_60 as role_ltv60,
                                    nature_role_ltv_61 as role_ltv61,
                                    nature_role_ltv_62 as role_ltv62,
                                    nature_role_ltv_63 as role_ltv63,
                                    nature_role_ltv_64 as role_ltv64,
                                    nature_role_ltv_65 as role_ltv65,
                                    nature_role_ltv_66 as role_ltv66,
                                    nature_role_ltv_67 as role_ltv67,
                                    nature_role_ltv_68 as role_ltv68,
                                    nature_role_ltv_69 as role_ltv69,
                                    nature_role_ltv_70 as role_ltv70,
                                    nature_role_ltv_71 as role_ltv71,
                                    nature_role_ltv_72 as role_ltv72,
                                    nature_role_ltv_73 as role_ltv73,
                                    nature_role_ltv_74 as role_ltv74,
                                    nature_role_ltv_75 as role_ltv75,
                                    nature_role_ltv_76 as role_ltv76,
                                    nature_role_ltv_77 as role_ltv77,
                                    nature_role_ltv_78 as role_ltv78,
                                    nature_role_ltv_79 as role_ltv79,
                                    nature_role_ltv_80 as role_ltv80,
                                    nature_role_ltv_81 as role_ltv81,
                                    nature_role_ltv_82 as role_ltv82,
                                    nature_role_ltv_83 as role_ltv83,
                                    nature_role_ltv_84 as role_ltv84,
                                    nature_role_ltv_85 as role_ltv85,
                                    nature_role_ltv_86 as role_ltv86,
                                    nature_role_ltv_87 as role_ltv87,
                                    nature_role_ltv_88 as role_ltv88,
                                    nature_role_ltv_89 as role_ltv89,
                                    nature_role_ltv_90 as role_ltv90,
                                    nature_role_ltv_m4 as role_ltv_m4,
                                    nature_role_ltv_m5 as role_ltv_m5,
                                    nature_role_ltv_m6 as role_ltv_m6,
                                    nature_role_ltv_m7 as role_ltv_m7,
                                    nature_role_ltv_m8 as role_ltv_m8,
                                    nature_role_ltv_m9 as role_ltv_m9,
                                    nature_role_ltv_m10 as role_ltv_m10,
                                    nature_role_ltv_m11 as role_ltv_m11,
                                    nature_role_ltv_y1 as role_ltv_y1,
                                    nature_role_ltv_total as role_ltv_total,
                                    nature_da1 as da1,
                                    nature_da2 as da2,
                                    nature_da3 as da3,
                                    nature_da4 as da4,
                                    nature_da5 as da5,
                                    nature_da6 as da6,
                                    nature_da7 as da7,
                                    nature_da8 as da8,
                                    nature_da9 as da9,
                                    nature_da10 as da10,
                                    nature_da11 as da11,
                                    nature_da12 as da12,
                                    nature_da13 as da13,
                                    nature_da14 as da14,
                                    nature_da15 as da15,
                                    nature_da16 as da16,
                                    nature_da17 as da17,
                                    nature_da18 as da18,
                                    nature_da19 as da19,
                                    nature_da20 as da20,
                                    nature_da21 as da21,
                                    nature_da22 as da22,
                                    nature_da23 as da23,
                                    nature_da24 as da24,
                                    nature_da25 as da25,
                                    nature_da26 as da26,
                                    nature_da27 as da27,
                                    nature_da28 as da28,
                                    nature_da29 as da29,
                                    nature_da30 as da30,
                                    nature_da31 as da31,
                                    nature_da32 as da32,
                                    nature_da33 as da33,
                                    nature_da34 as da34,
                                    nature_da35 as da35,
                                    nature_da36 as da36,
                                    nature_da37 as da37,
                                    nature_da38 as da38,
                                    nature_da39 as da39,
                                    nature_da40 as da40,
                                    nature_da41 as da41,
                                    nature_da42 as da42,
                                    nature_da43 as da43,
                                    nature_da44 as da44,
                                    nature_da45 as da45,
                                    nature_da46 as da46,
                                    nature_da47 as da47,
                                    nature_da48 as da48,
                                    nature_da49 as da49,
                                    nature_da50 as da50,
                                    nature_da51 as da51,
                                    nature_da52 as da52,
                                    nature_da53 as da53,
                                    nature_da54 as da54,
                                    nature_da55 as da55,
                                    nature_da56 as da56,
                                    nature_da57 as da57,
                                    nature_da58 as da58,
                                    nature_da59 as da59,
                                    nature_da60 as da60,
                                    nature_da61 as da61,
                                    nature_da62 as da62,
                                    nature_da63 as da63,
                                    nature_da64 as da64,
                                    nature_da65 as da65,
                                    nature_da66 as da66,
                                    nature_da67 as da67,
                                    nature_da68 as da68,
                                    nature_da69 as da69,
                                    nature_da70 as da70,
                                    nature_da71 as da71,
                                    nature_da72 as da72,
                                    nature_da73 as da73,
                                    nature_da74 as da74,
                                    nature_da75 as da75,
                                    nature_da76 as da76,
                                    nature_da77 as da77,
                                    nature_da78 as da78,
                                    nature_da79 as da79,
                                    nature_da80 as da80,
                                    nature_da81 as da81,
                                    nature_da82 as da82,
                                    nature_da83 as da83,
                                    nature_da84 as da84,
                                    nature_da85 as da85,
                                    nature_da86 as da86,
                                    nature_da87 as da87,
                                    nature_da88 as da88,
                                    nature_da89 as da89,
                                    nature_da90 as da90,
                                    nature_m4 as m4,
                                    nature_m5 as m5,
                                    nature_m6 as m6,
                                    nature_m7 as m7,
                                    nature_m8 as m8,
                                    nature_m9 as m9,
                                    nature_m10 as m10,
                                    nature_m11 as m11,
                                    nature_y1 as y1,
                                    nature_total as total,
                                    nature_first_role_num as first_role_num_ltv,
                                    nature_reg_user_cnt as reg_user_cnt
                                FROM
                                    ads_user_role_ltv_trend
                            """ + cri +
                    """
                                    ) b
                                ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        }

        return """
                SELECT
                    a.*,
                    b.*
                FROM (
                    SELECT
                        dt cost_date,
                        game_name,
                        game_id,
                        game_classify,
                        source_system,
                        cost,
                        reg_num,
                        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,
                        total_roi,
                        first_roi,
                        first_amount_rate,
                        today_amount_rate,
                        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,
                        reg_cost,
                        first_amount_cost as first_new_user_recharge_cost,
                        total_amount_cost as total_recharge_cost,
                        hundred_user_num,
                        hundred_user_num_cost,
                        first_role_num,
                        role_num,
                        new_user_total_role_num,
                        round(IF(first_role_num > 0, cost / first_role_num, 0), 2) first_role_num_cost,
                        round(IF(role_num > 0, cost / role_num, 0), 2) role_num_cost,
                        round(IF(new_user_total_role_num >0, cost / new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                        round(IF(reg_num >0, first_role_num / reg_num, 0), 4) first_role_num_rate,
                        round(IF(reg_num >0, role_num / reg_num, 0), 4) role_num_rate,
                        round(IF(reg_num >0, new_user_total_role_num / reg_num, 0), 4) new_user_total_role_num_rate
                    FROM
                        ads_game_day
                """ + cri +
                """
                                ) a
                        LEFT JOIN (
                            SELECT
                                game_id,
                                game_name,
                                dt,
                                user_ltv_1 as user_ltv1,
                                user_ltv_2 as user_ltv2,
                                user_ltv_3 as user_ltv3,
                                user_ltv_4 as user_ltv4,
                                user_ltv_5 as user_ltv5,
                                user_ltv_6 as user_ltv6,
                                user_ltv_7 as user_ltv7,
                                user_ltv_8 as user_ltv8,
                                user_ltv_9 as user_ltv9,
                                user_ltv_10 as user_ltv10,
                                user_ltv_11 as user_ltv11,
                                user_ltv_12 as user_ltv12,
                                user_ltv_13 as user_ltv13,
                                user_ltv_14 as user_ltv14,
                                user_ltv_15 as user_ltv15,
                                user_ltv_16 as user_ltv16,
                                user_ltv_17 as user_ltv17,
                                user_ltv_18 as user_ltv18,
                                user_ltv_19 as user_ltv19,
                                user_ltv_20 as user_ltv20,
                                user_ltv_21 as user_ltv21,
                                user_ltv_22 as user_ltv22,
                                user_ltv_23 as user_ltv23,
                                user_ltv_24 as user_ltv24,
                                user_ltv_25 as user_ltv25,
                                user_ltv_26 as user_ltv26,
                                user_ltv_27 as user_ltv27,
                                user_ltv_28 as user_ltv28,
                                user_ltv_29 as user_ltv29,
                                user_ltv_30 as user_ltv30,
                                user_ltv_31 as user_ltv31,
                                user_ltv_32 as user_ltv32,
                                user_ltv_33 as user_ltv33,
                                user_ltv_34 as user_ltv34,
                                user_ltv_35 as user_ltv35,
                                user_ltv_36 as user_ltv36,
                                user_ltv_37 as user_ltv37,
                                user_ltv_38 as user_ltv38,
                                user_ltv_39 as user_ltv39,
                                user_ltv_40 as user_ltv40,
                                user_ltv_41 as user_ltv41,
                                user_ltv_42 as user_ltv42,
                                user_ltv_43 as user_ltv43,
                                user_ltv_44 as user_ltv44,
                                user_ltv_45 as user_ltv45,
                                user_ltv_46 as user_ltv46,
                                user_ltv_47 as user_ltv47,
                                user_ltv_48 as user_ltv48,
                                user_ltv_49 as user_ltv49,
                                user_ltv_50 as user_ltv50,
                                user_ltv_51 as user_ltv51,
                                user_ltv_52 as user_ltv52,
                                user_ltv_53 as user_ltv53,
                                user_ltv_54 as user_ltv54,
                                user_ltv_55 as user_ltv55,
                                user_ltv_56 as user_ltv56,
                                user_ltv_57 as user_ltv57,
                                user_ltv_58 as user_ltv58,
                                user_ltv_59 as user_ltv59,
                                user_ltv_60 as user_ltv60,
                                user_ltv_61 as user_ltv61,
                                user_ltv_62 as user_ltv62,
                                user_ltv_63 as user_ltv63,
                                user_ltv_64 as user_ltv64,
                                user_ltv_65 as user_ltv65,
                                user_ltv_66 as user_ltv66,
                                user_ltv_67 as user_ltv67,
                                user_ltv_68 as user_ltv68,
                                user_ltv_69 as user_ltv69,
                                user_ltv_70 as user_ltv70,
                                user_ltv_71 as user_ltv71,
                                user_ltv_72 as user_ltv72,
                                user_ltv_73 as user_ltv73,
                                user_ltv_74 as user_ltv74,
                                user_ltv_75 as user_ltv75,
                                user_ltv_76 as user_ltv76,
                                user_ltv_77 as user_ltv77,
                                user_ltv_78 as user_ltv78,
                                user_ltv_79 as user_ltv79,
                                user_ltv_80 as user_ltv80,
                                user_ltv_81 as user_ltv81,
                                user_ltv_82 as user_ltv82,
                                user_ltv_83 as user_ltv83,
                                user_ltv_84 as user_ltv84,
                                user_ltv_85 as user_ltv85,
                                user_ltv_86 as user_ltv86,
                                user_ltv_87 as user_ltv87,
                                user_ltv_88 as user_ltv88,
                                user_ltv_89 as user_ltv89,
                                user_ltv_90 as user_ltv90,
                                user_ltv_m4,
                                user_ltv_m5,
                                user_ltv_m6,
                                user_ltv_m7,
                                user_ltv_m8,
                                user_ltv_m9,
                                user_ltv_m10,
                                user_ltv_m11,
                                user_ltv_y1,
                                user_ltv_total,
                                role_ltv_1 as role_ltv1,
                                role_ltv_2 as role_ltv2,
                                role_ltv_3 as role_ltv3,
                                role_ltv_4 as role_ltv4,
                                role_ltv_5 as role_ltv5,
                                role_ltv_6 as role_ltv6,
                                role_ltv_7 as role_ltv7,
                                role_ltv_8 as role_ltv8,
                                role_ltv_9 as role_ltv9,
                                role_ltv_10 as role_ltv10,
                                role_ltv_11 as role_ltv11,
                                role_ltv_12 as role_ltv12,
                                role_ltv_13 as role_ltv13,
                                role_ltv_14 as role_ltv14,
                                role_ltv_15 as role_ltv15,
                                role_ltv_16 as role_ltv16,
                                role_ltv_17 as role_ltv17,
                                role_ltv_18 as role_ltv18,
                                role_ltv_19 as role_ltv19,
                                role_ltv_20 as role_ltv20,
                                role_ltv_21 as role_ltv21,
                                role_ltv_22 as role_ltv22,
                                role_ltv_23 as role_ltv23,
                                role_ltv_24 as role_ltv24,
                                role_ltv_25 as role_ltv25,
                                role_ltv_26 as role_ltv26,
                                role_ltv_27 as role_ltv27,
                                role_ltv_28 as role_ltv28,
                                role_ltv_29 as role_ltv29,
                                role_ltv_30 as role_ltv30,
                                role_ltv_31 as role_ltv31,
                                role_ltv_32 as role_ltv32,
                                role_ltv_33 as role_ltv33,
                                role_ltv_34 as role_ltv34,
                                role_ltv_35 as role_ltv35,
                                role_ltv_36 as role_ltv36,
                                role_ltv_37 as role_ltv37,
                                role_ltv_38 as role_ltv38,
                                role_ltv_39 as role_ltv39,
                                role_ltv_40 as role_ltv40,
                                role_ltv_41 as role_ltv41,
                                role_ltv_42 as role_ltv42,
                                role_ltv_43 as role_ltv43,
                                role_ltv_44 as role_ltv44,
                                role_ltv_45 as role_ltv45,
                                role_ltv_46 as role_ltv46,
                                role_ltv_47 as role_ltv47,
                                role_ltv_48 as role_ltv48,
                                role_ltv_49 as role_ltv49,
                                role_ltv_50 as role_ltv50,
                                role_ltv_51 as role_ltv51,
                                role_ltv_52 as role_ltv52,
                                role_ltv_53 as role_ltv53,
                                role_ltv_54 as role_ltv54,
                                role_ltv_55 as role_ltv55,
                                role_ltv_56 as role_ltv56,
                                role_ltv_57 as role_ltv57,
                                role_ltv_58 as role_ltv58,
                                role_ltv_59 as role_ltv59,
                                role_ltv_60 as role_ltv60,
                                role_ltv_61 as role_ltv61,
                                role_ltv_62 as role_ltv62,
                                role_ltv_63 as role_ltv63,
                                role_ltv_64 as role_ltv64,
                                role_ltv_65 as role_ltv65,
                                role_ltv_66 as role_ltv66,
                                role_ltv_67 as role_ltv67,
                                role_ltv_68 as role_ltv68,
                                role_ltv_69 as role_ltv69,
                                role_ltv_70 as role_ltv70,
                                role_ltv_71 as role_ltv71,
                                role_ltv_72 as role_ltv72,
                                role_ltv_73 as role_ltv73,
                                role_ltv_74 as role_ltv74,
                                role_ltv_75 as role_ltv75,
                                role_ltv_76 as role_ltv76,
                                role_ltv_77 as role_ltv77,
                                role_ltv_78 as role_ltv78,
                                role_ltv_79 as role_ltv79,
                                role_ltv_80 as role_ltv80,
                                role_ltv_81 as role_ltv81,
                                role_ltv_82 as role_ltv82,
                                role_ltv_83 as role_ltv83,
                                role_ltv_84 as role_ltv84,
                                role_ltv_85 as role_ltv85,
                                role_ltv_86 as role_ltv86,
                                role_ltv_87 as role_ltv87,
                                role_ltv_88 as role_ltv88,
                                role_ltv_89 as role_ltv89,
                                role_ltv_90 as role_ltv90,
                                role_ltv_m4,
                                role_ltv_m5,
                                role_ltv_m6,
                                role_ltv_m7,
                                role_ltv_m8,
                                role_ltv_m9,
                                role_ltv_m10,
                                role_ltv_m11,
                                role_ltv_y1,
                                role_ltv_total,
                                da1,
                                da2,
                                da3,
                                da4,
                                da5,
                                da6,
                                da7,
                                da8,
                                da9,
                                da10,
                                da11,
                                da12,
                                da13,
                                da14,
                                da15,
                                da16,
                                da17,
                                da18,
                                da19,
                                da20,
                                da21,
                                da22,
                                da23,
                                da24,
                                da25,
                                da26,
                                da27,
                                da28,
                                da29,
                                da30,
                                da31,
                                da32,
                                da33,
                                da34,
                                da35,
                                da36,
                                da37,
                                da38,
                                da39,
                                da40,
                                da41,
                                da42,
                                da43,
                                da44,
                                da45,
                                da46,
                                da47,
                                da48,
                                da49,
                                da50,
                                da51,
                                da52,
                                da53,
                                da54,
                                da55,
                                da56,
                                da57,
                                da58,
                                da59,
                                da60,
                                da61,
                                da62,
                                da63,
                                da64,
                                da65,
                                da66,
                                da67,
                                da68,
                                da69,
                                da70,
                                da71,
                                da72,
                                da73,
                                da74,
                                da75,
                                da76,
                                da77,
                                da78,
                                da79,
                                da80,
                                da81,
                                da82,
                                da83,
                                da84,
                                da85,
                                da86,
                                da87,
                                da88,
                                da89,
                                da90,
                                m4,
                                m5,
                                m6,
                                m7,
                                m8,
                                m9,
                                m10,
                                m11,
                                y1,
                                total,
                                first_role_num first_role_num_ltv,
                                reg_user_cnt
                            FROM
                                ads_user_role_ltv_trend
                        """ + cri +
                """
                            ) b
                        ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                        """;
    }

    /**
     * ltv每日数据查询sql
     *
     * @param type 查询的类型 buy -> 买量  ;  nature ->  自然量 ; total -> 总量
     * @param cri  查询条件
     * @return String
     */
    private String getLtvDataByTableTypesSqlForParent(String type, Criteria cri) {
        if ("buy".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            parent_game_name as game_name,
                            parent_game_id as game_id,
                            parent_game_name_classify as game_classify,
                            source_system,
                            cost,
                            buy_reg_num as reg_num,
                            buy_first_new_user_amount_count as first_new_user_amount_count,
                            buy_first_new_user_amount_num as first_new_user_amount_num,
                            buy_first_new_user_amount as first_new_user_amount,
                            buy_old_user_count as old_user_count,
                            buy_old_user_num as old_user_num,
                            buy_old_user_amount as old_user_amount,
                            buy_amount_count as amount_count,
                            buy_amount_num as amount_num,
                            buy_amount as amount,
                            buy_new_user_total_amount_count as new_user_total_amount_count,
                            buy_new_user_total_amount_num as new_user_total_amount_num,
                            buy_new_user_total_amount as new_user_total_amount,
                            buy_total_roi as total_roi,
                            buy_first_roi as first_roi,
                            buy_first_amount_rate as first_amount_rate,
                            buy_today_amount_rate as today_amount_rate,
                            buy_new_user_rate as new_user_rate,
                            buy_first_avg_amount as first_avg_amount,
                            buy_today_avg_amount as today_avg_amount,
                            buy_avg_amount as avg_amount,
                            buy_user_again_rate as user_again_rate,
                            buy_reg_user_arpu as reg_user_arpu,
                            buy_first_amount_arpu as first_amount_arpu,
                            buy_today_amount_arpu as today_amount_arpu,
                            buy_amount_arpu as amount_arpu,
                            buy_reg_cost as reg_cost,
                            buy_first_amount_cost as first_new_user_recharge_cost,
                            buy_total_amount_cost as total_recharge_cost,
                            buy_hundred_user_num as hundred_user_num,
                            buy_hundred_user_num_cost as hundred_user_num_cost,
                            buy_first_role_num as first_role_num,
                            buy_role_num as role_num,
                            buy_new_user_total_role_num as new_user_total_role_num,
                            round(IF(buy_first_role_num > 0, cost / buy_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(buy_role_num > 0, cost / buy_role_num, 0), 2) role_num_cost,
                            round(IF(buy_new_user_total_role_num >0, cost / buy_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(buy_reg_num >0, buy_first_role_num / buy_reg_num, 0), 4) first_role_num_rate,
                            round(IF(buy_reg_num >0, buy_role_num / buy_reg_num, 0), 4) role_num_rate,
                            round(IF(buy_reg_num >0, buy_new_user_total_role_num / buy_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    parent_game_id as game_id,
                                    parent_game_name as game_name,
                                    dt,
                                    buy_user_ltv_1 as user_ltv1,
                                    buy_user_ltv_2 as user_ltv2,
                                    buy_user_ltv_3 as user_ltv3,
                                    buy_user_ltv_4 as user_ltv4,
                                    buy_user_ltv_5 as user_ltv5,
                                    buy_user_ltv_6 as user_ltv6,
                                    buy_user_ltv_7 as user_ltv7,
                                    buy_user_ltv_8 as user_ltv8,
                                    buy_user_ltv_9 as user_ltv9,
                                    buy_user_ltv_10 as user_ltv10,
                                    buy_user_ltv_11 as user_ltv11,
                                    buy_user_ltv_12 as user_ltv12,
                                    buy_user_ltv_13 as user_ltv13,
                                    buy_user_ltv_14 as user_ltv14,
                                    buy_user_ltv_15 as user_ltv15,
                                    buy_user_ltv_16 as user_ltv16,
                                    buy_user_ltv_17 as user_ltv17,
                                    buy_user_ltv_18 as user_ltv18,
                                    buy_user_ltv_19 as user_ltv19,
                                    buy_user_ltv_20 as user_ltv20,
                                    buy_user_ltv_21 as user_ltv21,
                                    buy_user_ltv_22 as user_ltv22,
                                    buy_user_ltv_23 as user_ltv23,
                                    buy_user_ltv_24 as user_ltv24,
                                    buy_user_ltv_25 as user_ltv25,
                                    buy_user_ltv_26 as user_ltv26,
                                    buy_user_ltv_27 as user_ltv27,
                                    buy_user_ltv_28 as user_ltv28,
                                    buy_user_ltv_29 as user_ltv29,
                                    buy_user_ltv_30 as user_ltv30,
                                    buy_user_ltv_31 as user_ltv31,
                                    buy_user_ltv_32 as user_ltv32,
                                    buy_user_ltv_33 as user_ltv33,
                                    buy_user_ltv_34 as user_ltv34,
                                    buy_user_ltv_35 as user_ltv35,
                                    buy_user_ltv_36 as user_ltv36,
                                    buy_user_ltv_37 as user_ltv37,
                                    buy_user_ltv_38 as user_ltv38,
                                    buy_user_ltv_39 as user_ltv39,
                                    buy_user_ltv_40 as user_ltv40,
                                    buy_user_ltv_41 as user_ltv41,
                                    buy_user_ltv_42 as user_ltv42,
                                    buy_user_ltv_43 as user_ltv43,
                                    buy_user_ltv_44 as user_ltv44,
                                    buy_user_ltv_45 as user_ltv45,
                                    buy_user_ltv_46 as user_ltv46,
                                    buy_user_ltv_47 as user_ltv47,
                                    buy_user_ltv_48 as user_ltv48,
                                    buy_user_ltv_49 as user_ltv49,
                                    buy_user_ltv_50 as user_ltv50,
                                    buy_user_ltv_51 as user_ltv51,
                                    buy_user_ltv_52 as user_ltv52,
                                    buy_user_ltv_53 as user_ltv53,
                                    buy_user_ltv_54 as user_ltv54,
                                    buy_user_ltv_55 as user_ltv55,
                                    buy_user_ltv_56 as user_ltv56,
                                    buy_user_ltv_57 as user_ltv57,
                                    buy_user_ltv_58 as user_ltv58,
                                    buy_user_ltv_59 as user_ltv59,
                                    buy_user_ltv_60 as user_ltv60,
                                    buy_user_ltv_61 as user_ltv61,
                                    buy_user_ltv_62 as user_ltv62,
                                    buy_user_ltv_63 as user_ltv63,
                                    buy_user_ltv_64 as user_ltv64,
                                    buy_user_ltv_65 as user_ltv65,
                                    buy_user_ltv_66 as user_ltv66,
                                    buy_user_ltv_67 as user_ltv67,
                                    buy_user_ltv_68 as user_ltv68,
                                    buy_user_ltv_69 as user_ltv69,
                                    buy_user_ltv_70 as user_ltv70,
                                    buy_user_ltv_71 as user_ltv71,
                                    buy_user_ltv_72 as user_ltv72,
                                    buy_user_ltv_73 as user_ltv73,
                                    buy_user_ltv_74 as user_ltv74,
                                    buy_user_ltv_75 as user_ltv75,
                                    buy_user_ltv_76 as user_ltv76,
                                    buy_user_ltv_77 as user_ltv77,
                                    buy_user_ltv_78 as user_ltv78,
                                    buy_user_ltv_79 as user_ltv79,
                                    buy_user_ltv_80 as user_ltv80,
                                    buy_user_ltv_81 as user_ltv81,
                                    buy_user_ltv_82 as user_ltv82,
                                    buy_user_ltv_83 as user_ltv83,
                                    buy_user_ltv_84 as user_ltv84,
                                    buy_user_ltv_85 as user_ltv85,
                                    buy_user_ltv_86 as user_ltv86,
                                    buy_user_ltv_87 as user_ltv87,
                                    buy_user_ltv_88 as user_ltv88,
                                    buy_user_ltv_89 as user_ltv89,
                                    buy_user_ltv_90 as user_ltv90,
                                    buy_user_ltv_m4 as user_ltv_m4,
                                    buy_user_ltv_m5 as user_ltv_m5,
                                    buy_user_ltv_m6 as user_ltv_m6,
                                    buy_user_ltv_m7 as user_ltv_m7,
                                    buy_user_ltv_m8 as user_ltv_m8,
                                    buy_user_ltv_m9 as user_ltv_m9,
                                    buy_user_ltv_m10 as user_ltv_m10,
                                    buy_user_ltv_m11 as user_ltv_m11,
                                    buy_user_ltv_y1 as user_ltv_y1,
                                    buy_user_ltv_total as user_ltv_total,
                                    buy_role_ltv_1 as role_ltv1,
                                    buy_role_ltv_2 as role_ltv2,
                                    buy_role_ltv_3 as role_ltv3,
                                    buy_role_ltv_4 as role_ltv4,
                                    buy_role_ltv_5 as role_ltv5,
                                    buy_role_ltv_6 as role_ltv6,
                                    buy_role_ltv_7 as role_ltv7,
                                    buy_role_ltv_8 as role_ltv8,
                                    buy_role_ltv_9 as role_ltv9,
                                    buy_role_ltv_10 as role_ltv10,
                                    buy_role_ltv_11 as role_ltv11,
                                    buy_role_ltv_12 as role_ltv12,
                                    buy_role_ltv_13 as role_ltv13,
                                    buy_role_ltv_14 as role_ltv14,
                                    buy_role_ltv_15 as role_ltv15,
                                    buy_role_ltv_16 as role_ltv16,
                                    buy_role_ltv_17 as role_ltv17,
                                    buy_role_ltv_18 as role_ltv18,
                                    buy_role_ltv_19 as role_ltv19,
                                    buy_role_ltv_20 as role_ltv20,
                                    buy_role_ltv_21 as role_ltv21,
                                    buy_role_ltv_22 as role_ltv22,
                                    buy_role_ltv_23 as role_ltv23,
                                    buy_role_ltv_24 as role_ltv24,
                                    buy_role_ltv_25 as role_ltv25,
                                    buy_role_ltv_26 as role_ltv26,
                                    buy_role_ltv_27 as role_ltv27,
                                    buy_role_ltv_28 as role_ltv28,
                                    buy_role_ltv_29 as role_ltv29,
                                    buy_role_ltv_30 as role_ltv30,
                                    buy_role_ltv_31 as role_ltv31,
                                    buy_role_ltv_32 as role_ltv32,
                                    buy_role_ltv_33 as role_ltv33,
                                    buy_role_ltv_34 as role_ltv34,
                                    buy_role_ltv_35 as role_ltv35,
                                    buy_role_ltv_36 as role_ltv36,
                                    buy_role_ltv_37 as role_ltv37,
                                    buy_role_ltv_38 as role_ltv38,
                                    buy_role_ltv_39 as role_ltv39,
                                    buy_role_ltv_40 as role_ltv40,
                                    buy_role_ltv_41 as role_ltv41,
                                    buy_role_ltv_42 as role_ltv42,
                                    buy_role_ltv_43 as role_ltv43,
                                    buy_role_ltv_44 as role_ltv44,
                                    buy_role_ltv_45 as role_ltv45,
                                    buy_role_ltv_46 as role_ltv46,
                                    buy_role_ltv_47 as role_ltv47,
                                    buy_role_ltv_48 as role_ltv48,
                                    buy_role_ltv_49 as role_ltv49,
                                    buy_role_ltv_50 as role_ltv50,
                                    buy_role_ltv_51 as role_ltv51,
                                    buy_role_ltv_52 as role_ltv52,
                                    buy_role_ltv_53 as role_ltv53,
                                    buy_role_ltv_54 as role_ltv54,
                                    buy_role_ltv_55 as role_ltv55,
                                    buy_role_ltv_56 as role_ltv56,
                                    buy_role_ltv_57 as role_ltv57,
                                    buy_role_ltv_58 as role_ltv58,
                                    buy_role_ltv_59 as role_ltv59,
                                    buy_role_ltv_60 as role_ltv60,
                                    buy_role_ltv_61 as role_ltv61,
                                    buy_role_ltv_62 as role_ltv62,
                                    buy_role_ltv_63 as role_ltv63,
                                    buy_role_ltv_64 as role_ltv64,
                                    buy_role_ltv_65 as role_ltv65,
                                    buy_role_ltv_66 as role_ltv66,
                                    buy_role_ltv_67 as role_ltv67,
                                    buy_role_ltv_68 as role_ltv68,
                                    buy_role_ltv_69 as role_ltv69,
                                    buy_role_ltv_70 as role_ltv70,
                                    buy_role_ltv_71 as role_ltv71,
                                    buy_role_ltv_72 as role_ltv72,
                                    buy_role_ltv_73 as role_ltv73,
                                    buy_role_ltv_74 as role_ltv74,
                                    buy_role_ltv_75 as role_ltv75,
                                    buy_role_ltv_76 as role_ltv76,
                                    buy_role_ltv_77 as role_ltv77,
                                    buy_role_ltv_78 as role_ltv78,
                                    buy_role_ltv_79 as role_ltv79,
                                    buy_role_ltv_80 as role_ltv80,
                                    buy_role_ltv_81 as role_ltv81,
                                    buy_role_ltv_82 as role_ltv82,
                                    buy_role_ltv_83 as role_ltv83,
                                    buy_role_ltv_84 as role_ltv84,
                                    buy_role_ltv_85 as role_ltv85,
                                    buy_role_ltv_86 as role_ltv86,
                                    buy_role_ltv_87 as role_ltv87,
                                    buy_role_ltv_88 as role_ltv88,
                                    buy_role_ltv_89 as role_ltv89,
                                    buy_role_ltv_90 as role_ltv90,
                                    buy_role_ltv_m4 as role_ltv_m4,
                                    buy_role_ltv_m5 as role_ltv_m5,
                                    buy_role_ltv_m6 as role_ltv_m6,
                                    buy_role_ltv_m7 as role_ltv_m7,
                                    buy_role_ltv_m8 as role_ltv_m8,
                                    buy_role_ltv_m9 as role_ltv_m9,
                                    buy_role_ltv_m10 as role_ltv_m10,
                                    buy_role_ltv_m11 as role_ltv_m11,
                                    buy_role_ltv_y1 as role_ltv_y1,
                                    buy_role_ltv_total as role_ltv_total,
                                    buy_da1 as da1,
                                    buy_da2 as da2,
                                    buy_da3 as da3,
                                    buy_da4 as da4,
                                    buy_da5 as da5,
                                    buy_da6 as da6,
                                    buy_da7 as da7,
                                    buy_da8 as da8,
                                    buy_da9 as da9,
                                    buy_da10 as da10,
                                    buy_da11 as da11,
                                    buy_da12 as da12,
                                    buy_da13 as da13,
                                    buy_da14 as da14,
                                    buy_da15 as da15,
                                    buy_da16 as da16,
                                    buy_da17 as da17,
                                    buy_da18 as da18,
                                    buy_da19 as da19,
                                    buy_da20 as da20,
                                    buy_da21 as da21,
                                    buy_da22 as da22,
                                    buy_da23 as da23,
                                    buy_da24 as da24,
                                    buy_da25 as da25,
                                    buy_da26 as da26,
                                    buy_da27 as da27,
                                    buy_da28 as da28,
                                    buy_da29 as da29,
                                    buy_da30 as da30,
                                    buy_da31 as da31,
                                    buy_da32 as da32,
                                    buy_da33 as da33,
                                    buy_da34 as da34,
                                    buy_da35 as da35,
                                    buy_da36 as da36,
                                    buy_da37 as da37,
                                    buy_da38 as da38,
                                    buy_da39 as da39,
                                    buy_da40 as da40,
                                    buy_da41 as da41,
                                    buy_da42 as da42,
                                    buy_da43 as da43,
                                    buy_da44 as da44,
                                    buy_da45 as da45,
                                    buy_da46 as da46,
                                    buy_da47 as da47,
                                    buy_da48 as da48,
                                    buy_da49 as da49,
                                    buy_da50 as da50,
                                    buy_da51 as da51,
                                    buy_da52 as da52,
                                    buy_da53 as da53,
                                    buy_da54 as da54,
                                    buy_da55 as da55,
                                    buy_da56 as da56,
                                    buy_da57 as da57,
                                    buy_da58 as da58,
                                    buy_da59 as da59,
                                    buy_da60 as da60,
                                    buy_da61 as da61,
                                    buy_da62 as da62,
                                    buy_da63 as da63,
                                    buy_da64 as da64,
                                    buy_da65 as da65,
                                    buy_da66 as da66,
                                    buy_da67 as da67,
                                    buy_da68 as da68,
                                    buy_da69 as da69,
                                    buy_da70 as da70,
                                    buy_da71 as da71,
                                    buy_da72 as da72,
                                    buy_da73 as da73,
                                    buy_da74 as da74,
                                    buy_da75 as da75,
                                    buy_da76 as da76,
                                    buy_da77 as da77,
                                    buy_da78 as da78,
                                    buy_da79 as da79,
                                    buy_da80 as da80,
                                    buy_da81 as da81,
                                    buy_da82 as da82,
                                    buy_da83 as da83,
                                    buy_da84 as da84,
                                    buy_da85 as da85,
                                    buy_da86 as da86,
                                    buy_da87 as da87,
                                    buy_da88 as da88,
                                    buy_da89 as da89,
                                    buy_da90 as da90,
                                    buy_m4 as m4,
                                    buy_m5 as m5,
                                    buy_m6 as m6,
                                    buy_m7 as m7,
                                    buy_m8 as m8,
                                    buy_m9 as m9,
                                    buy_m10 as m10,
                                    buy_m11 as m11,
                                    buy_y1 as y1,
                                    buy_total as total,
                                    buy_first_role_num as first_role_num_ltv,
                                    buy_reg_user_cnt as reg_user_cnt
                                FROM
                                    game_ads_parent.ads_user_role_ltv_trend_parent
                            """ + cri +
                    """
                                ) b
                            ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        } else if ("nature".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt as cost_date,
                            parent_game_name as game_name,
                            parent_game_id as game_id,
                            parent_game_name_classify as game_classify,
                            source_system,
                            cost,
                            nature_reg_num as reg_num,
                            nature_first_new_user_amount_count as first_new_user_amount_count,
                            nature_first_new_user_amount_num as first_new_user_amount_num,
                            nature_first_new_user_amount as first_new_user_amount,
                            nature_old_user_count as old_user_count,
                            nature_old_user_num as old_user_num,
                            nature_old_user_amount as old_user_amount,
                            nature_amount_count as amount_count,
                            nature_amount_num as amount_num,
                            nature_amount as amount,
                            nature_new_user_total_amount_count as new_user_total_amount_count,
                            nature_new_user_total_amount_num as new_user_total_amount_num,
                            nature_new_user_total_amount as new_user_total_amount,
                            nature_total_roi as total_roi,
                            nature_first_roi as first_roi,
                            nature_first_amount_rate as first_amount_rate,
                            nature_today_amount_rate as today_amount_rate,
                            nature_new_user_rate as new_user_rate,
                            nature_first_avg_amount as first_avg_amount,
                            nature_today_avg_amount as today_avg_amount,
                            nature_avg_amount as avg_amount,
                            nature_user_again_rate as user_again_rate,
                            nature_reg_user_arpu as reg_user_arpu,
                            nature_first_amount_arpu as first_amount_arpu,
                            nature_today_amount_arpu as today_amount_arpu,
                            nature_amount_arpu as amount_arpu,
                            nature_reg_cost as reg_cost,
                            nature_first_amount_cost as first_new_user_recharge_cost,
                            nature_total_amount_cost as total_recharge_cost,
                            nature_hundred_user_num as hundred_user_num,
                            nature_hundred_user_num_cost as hundred_user_num_cost,
                            nature_first_role_num as first_role_num,
                            nature_role_num as role_num,
                            nature_new_user_total_role_num as new_user_total_role_num,
                            round(IF(nature_first_role_num > 0, cost / nature_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(nature_role_num > 0, cost / nature_role_num, 0), 2) role_num_cost,
                            round(IF(nature_new_user_total_role_num >0, cost / nature_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(nature_reg_num >0, nature_first_role_num / nature_reg_num, 0), 4) first_role_num_rate,
                            round(IF(nature_reg_num >0, nature_role_num / nature_reg_num, 0), 4) role_num_rate,
                            round(IF(nature_reg_num >0, nature_new_user_total_role_num / nature_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    parent_game_id as game_id,
                                    parent_game_name as game_name,
                                    dt,
                                    nature_user_ltv_1 as user_ltv1,
                                    nature_user_ltv_2 as user_ltv2,
                                    nature_user_ltv_3 as user_ltv3,
                                    nature_user_ltv_4 as user_ltv4,
                                    nature_user_ltv_5 as user_ltv5,
                                    nature_user_ltv_6 as user_ltv6,
                                    nature_user_ltv_7 as user_ltv7,
                                    nature_user_ltv_8 as user_ltv8,
                                    nature_user_ltv_9 as user_ltv9,
                                    nature_user_ltv_10 as user_ltv10,
                                    nature_user_ltv_11 as user_ltv11,
                                    nature_user_ltv_12 as user_ltv12,
                                    nature_user_ltv_13 as user_ltv13,
                                    nature_user_ltv_14 as user_ltv14,
                                    nature_user_ltv_15 as user_ltv15,
                                    nature_user_ltv_16 as user_ltv16,
                                    nature_user_ltv_17 as user_ltv17,
                                    nature_user_ltv_18 as user_ltv18,
                                    nature_user_ltv_19 as user_ltv19,
                                    nature_user_ltv_20 as user_ltv20,
                                    nature_user_ltv_21 as user_ltv21,
                                    nature_user_ltv_22 as user_ltv22,
                                    nature_user_ltv_23 as user_ltv23,
                                    nature_user_ltv_24 as user_ltv24,
                                    nature_user_ltv_25 as user_ltv25,
                                    nature_user_ltv_26 as user_ltv26,
                                    nature_user_ltv_27 as user_ltv27,
                                    nature_user_ltv_28 as user_ltv28,
                                    nature_user_ltv_29 as user_ltv29,
                                    nature_user_ltv_30 as user_ltv30,
                                    nature_user_ltv_31 as user_ltv31,
                                    nature_user_ltv_32 as user_ltv32,
                                    nature_user_ltv_33 as user_ltv33,
                                    nature_user_ltv_34 as user_ltv34,
                                    nature_user_ltv_35 as user_ltv35,
                                    nature_user_ltv_36 as user_ltv36,
                                    nature_user_ltv_37 as user_ltv37,
                                    nature_user_ltv_38 as user_ltv38,
                                    nature_user_ltv_39 as user_ltv39,
                                    nature_user_ltv_40 as user_ltv40,
                                    nature_user_ltv_41 as user_ltv41,
                                    nature_user_ltv_42 as user_ltv42,
                                    nature_user_ltv_43 as user_ltv43,
                                    nature_user_ltv_44 as user_ltv44,
                                    nature_user_ltv_45 as user_ltv45,
                                    nature_user_ltv_46 as user_ltv46,
                                    nature_user_ltv_47 as user_ltv47,
                                    nature_user_ltv_48 as user_ltv48,
                                    nature_user_ltv_49 as user_ltv49,
                                    nature_user_ltv_50 as user_ltv50,
                                    nature_user_ltv_51 as user_ltv51,
                                    nature_user_ltv_52 as user_ltv52,
                                    nature_user_ltv_53 as user_ltv53,
                                    nature_user_ltv_54 as user_ltv54,
                                    nature_user_ltv_55 as user_ltv55,
                                    nature_user_ltv_56 as user_ltv56,
                                    nature_user_ltv_57 as user_ltv57,
                                    nature_user_ltv_58 as user_ltv58,
                                    nature_user_ltv_59 as user_ltv59,
                                    nature_user_ltv_60 as user_ltv60,
                                    nature_user_ltv_61 as user_ltv61,
                                    nature_user_ltv_62 as user_ltv62,
                                    nature_user_ltv_63 as user_ltv63,
                                    nature_user_ltv_64 as user_ltv64,
                                    nature_user_ltv_65 as user_ltv65,
                                    nature_user_ltv_66 as user_ltv66,
                                    nature_user_ltv_67 as user_ltv67,
                                    nature_user_ltv_68 as user_ltv68,
                                    nature_user_ltv_69 as user_ltv69,
                                    nature_user_ltv_70 as user_ltv70,
                                    nature_user_ltv_71 as user_ltv71,
                                    nature_user_ltv_72 as user_ltv72,
                                    nature_user_ltv_73 as user_ltv73,
                                    nature_user_ltv_74 as user_ltv74,
                                    nature_user_ltv_75 as user_ltv75,
                                    nature_user_ltv_76 as user_ltv76,
                                    nature_user_ltv_77 as user_ltv77,
                                    nature_user_ltv_78 as user_ltv78,
                                    nature_user_ltv_79 as user_ltv79,
                                    nature_user_ltv_80 as user_ltv80,
                                    nature_user_ltv_81 as user_ltv81,
                                    nature_user_ltv_82 as user_ltv82,
                                    nature_user_ltv_83 as user_ltv83,
                                    nature_user_ltv_84 as user_ltv84,
                                    nature_user_ltv_85 as user_ltv85,
                                    nature_user_ltv_86 as user_ltv86,
                                    nature_user_ltv_87 as user_ltv87,
                                    nature_user_ltv_88 as user_ltv88,
                                    nature_user_ltv_89 as user_ltv89,
                                    nature_user_ltv_90 as user_ltv90,
                                    nature_user_ltv_m4 as user_ltv_m4,
                                    nature_user_ltv_m5 as user_ltv_m5,
                                    nature_user_ltv_m6 as user_ltv_m6,
                                    nature_user_ltv_m7 as user_ltv_m7,
                                    nature_user_ltv_m8 as user_ltv_m8,
                                    nature_user_ltv_m9 as user_ltv_m9,
                                    nature_user_ltv_m10 as user_ltv_m10,
                                    nature_user_ltv_m11 as user_ltv_m11,
                                    nature_user_ltv_y1 as user_ltv_y1,
                                    nature_user_ltv_total as user_ltv_total,
                                    nature_role_ltv_1 as role_ltv1,
                                    nature_role_ltv_2 as role_ltv2,
                                    nature_role_ltv_3 as role_ltv3,
                                    nature_role_ltv_4 as role_ltv4,
                                    nature_role_ltv_5 as role_ltv5,
                                    nature_role_ltv_6 as role_ltv6,
                                    nature_role_ltv_7 as role_ltv7,
                                    nature_role_ltv_8 as role_ltv8,
                                    nature_role_ltv_9 as role_ltv9,
                                    nature_role_ltv_10 as role_ltv10,
                                    nature_role_ltv_11 as role_ltv11,
                                    nature_role_ltv_12 as role_ltv12,
                                    nature_role_ltv_13 as role_ltv13,
                                    nature_role_ltv_14 as role_ltv14,
                                    nature_role_ltv_15 as role_ltv15,
                                    nature_role_ltv_16 as role_ltv16,
                                    nature_role_ltv_17 as role_ltv17,
                                    nature_role_ltv_18 as role_ltv18,
                                    nature_role_ltv_19 as role_ltv19,
                                    nature_role_ltv_20 as role_ltv20,
                                    nature_role_ltv_21 as role_ltv21,
                                    nature_role_ltv_22 as role_ltv22,
                                    nature_role_ltv_23 as role_ltv23,
                                    nature_role_ltv_24 as role_ltv24,
                                    nature_role_ltv_25 as role_ltv25,
                                    nature_role_ltv_26 as role_ltv26,
                                    nature_role_ltv_27 as role_ltv27,
                                    nature_role_ltv_28 as role_ltv28,
                                    nature_role_ltv_29 as role_ltv29,
                                    nature_role_ltv_30 as role_ltv30,
                                    nature_role_ltv_31 as role_ltv31,
                                    nature_role_ltv_32 as role_ltv32,
                                    nature_role_ltv_33 as role_ltv33,
                                    nature_role_ltv_34 as role_ltv34,
                                    nature_role_ltv_35 as role_ltv35,
                                    nature_role_ltv_36 as role_ltv36,
                                    nature_role_ltv_37 as role_ltv37,
                                    nature_role_ltv_38 as role_ltv38,
                                    nature_role_ltv_39 as role_ltv39,
                                    nature_role_ltv_40 as role_ltv40,
                                    nature_role_ltv_41 as role_ltv41,
                                    nature_role_ltv_42 as role_ltv42,
                                    nature_role_ltv_43 as role_ltv43,
                                    nature_role_ltv_44 as role_ltv44,
                                    nature_role_ltv_45 as role_ltv45,
                                    nature_role_ltv_46 as role_ltv46,
                                    nature_role_ltv_47 as role_ltv47,
                                    nature_role_ltv_48 as role_ltv48,
                                    nature_role_ltv_49 as role_ltv49,
                                    nature_role_ltv_50 as role_ltv50,
                                    nature_role_ltv_51 as role_ltv51,
                                    nature_role_ltv_52 as role_ltv52,
                                    nature_role_ltv_53 as role_ltv53,
                                    nature_role_ltv_54 as role_ltv54,
                                    nature_role_ltv_55 as role_ltv55,
                                    nature_role_ltv_56 as role_ltv56,
                                    nature_role_ltv_57 as role_ltv57,
                                    nature_role_ltv_58 as role_ltv58,
                                    nature_role_ltv_59 as role_ltv59,
                                    nature_role_ltv_60 as role_ltv60,
                                    nature_role_ltv_61 as role_ltv61,
                                    nature_role_ltv_62 as role_ltv62,
                                    nature_role_ltv_63 as role_ltv63,
                                    nature_role_ltv_64 as role_ltv64,
                                    nature_role_ltv_65 as role_ltv65,
                                    nature_role_ltv_66 as role_ltv66,
                                    nature_role_ltv_67 as role_ltv67,
                                    nature_role_ltv_68 as role_ltv68,
                                    nature_role_ltv_69 as role_ltv69,
                                    nature_role_ltv_70 as role_ltv70,
                                    nature_role_ltv_71 as role_ltv71,
                                    nature_role_ltv_72 as role_ltv72,
                                    nature_role_ltv_73 as role_ltv73,
                                    nature_role_ltv_74 as role_ltv74,
                                    nature_role_ltv_75 as role_ltv75,
                                    nature_role_ltv_76 as role_ltv76,
                                    nature_role_ltv_77 as role_ltv77,
                                    nature_role_ltv_78 as role_ltv78,
                                    nature_role_ltv_79 as role_ltv79,
                                    nature_role_ltv_80 as role_ltv80,
                                    nature_role_ltv_81 as role_ltv81,
                                    nature_role_ltv_82 as role_ltv82,
                                    nature_role_ltv_83 as role_ltv83,
                                    nature_role_ltv_84 as role_ltv84,
                                    nature_role_ltv_85 as role_ltv85,
                                    nature_role_ltv_86 as role_ltv86,
                                    nature_role_ltv_87 as role_ltv87,
                                    nature_role_ltv_88 as role_ltv88,
                                    nature_role_ltv_89 as role_ltv89,
                                    nature_role_ltv_90 as role_ltv90,
                                    nature_role_ltv_m4 as role_ltv_m4,
                                    nature_role_ltv_m5 as role_ltv_m5,
                                    nature_role_ltv_m6 as role_ltv_m6,
                                    nature_role_ltv_m7 as role_ltv_m7,
                                    nature_role_ltv_m8 as role_ltv_m8,
                                    nature_role_ltv_m9 as role_ltv_m9,
                                    nature_role_ltv_m10 as role_ltv_m10,
                                    nature_role_ltv_m11 as role_ltv_m11,
                                    nature_role_ltv_y1 as role_ltv_y1,
                                    nature_role_ltv_total as role_ltv_total,
                                    nature_da1 as da1,
                                    nature_da2 as da2,
                                    nature_da3 as da3,
                                    nature_da4 as da4,
                                    nature_da5 as da5,
                                    nature_da6 as da6,
                                    nature_da7 as da7,
                                    nature_da8 as da8,
                                    nature_da9 as da9,
                                    nature_da10 as da10,
                                    nature_da11 as da11,
                                    nature_da12 as da12,
                                    nature_da13 as da13,
                                    nature_da14 as da14,
                                    nature_da15 as da15,
                                    nature_da16 as da16,
                                    nature_da17 as da17,
                                    nature_da18 as da18,
                                    nature_da19 as da19,
                                    nature_da20 as da20,
                                    nature_da21 as da21,
                                    nature_da22 as da22,
                                    nature_da23 as da23,
                                    nature_da24 as da24,
                                    nature_da25 as da25,
                                    nature_da26 as da26,
                                    nature_da27 as da27,
                                    nature_da28 as da28,
                                    nature_da29 as da29,
                                    nature_da30 as da30,
                                    nature_da31 as da31,
                                    nature_da32 as da32,
                                    nature_da33 as da33,
                                    nature_da34 as da34,
                                    nature_da35 as da35,
                                    nature_da36 as da36,
                                    nature_da37 as da37,
                                    nature_da38 as da38,
                                    nature_da39 as da39,
                                    nature_da40 as da40,
                                    nature_da41 as da41,
                                    nature_da42 as da42,
                                    nature_da43 as da43,
                                    nature_da44 as da44,
                                    nature_da45 as da45,
                                    nature_da46 as da46,
                                    nature_da47 as da47,
                                    nature_da48 as da48,
                                    nature_da49 as da49,
                                    nature_da50 as da50,
                                    nature_da51 as da51,
                                    nature_da52 as da52,
                                    nature_da53 as da53,
                                    nature_da54 as da54,
                                    nature_da55 as da55,
                                    nature_da56 as da56,
                                    nature_da57 as da57,
                                    nature_da58 as da58,
                                    nature_da59 as da59,
                                    nature_da60 as da60,
                                    nature_da61 as da61,
                                    nature_da62 as da62,
                                    nature_da63 as da63,
                                    nature_da64 as da64,
                                    nature_da65 as da65,
                                    nature_da66 as da66,
                                    nature_da67 as da67,
                                    nature_da68 as da68,
                                    nature_da69 as da69,
                                    nature_da70 as da70,
                                    nature_da71 as da71,
                                    nature_da72 as da72,
                                    nature_da73 as da73,
                                    nature_da74 as da74,
                                    nature_da75 as da75,
                                    nature_da76 as da76,
                                    nature_da77 as da77,
                                    nature_da78 as da78,
                                    nature_da79 as da79,
                                    nature_da80 as da80,
                                    nature_da81 as da81,
                                    nature_da82 as da82,
                                    nature_da83 as da83,
                                    nature_da84 as da84,
                                    nature_da85 as da85,
                                    nature_da86 as da86,
                                    nature_da87 as da87,
                                    nature_da88 as da88,
                                    nature_da89 as da89,
                                    nature_da90 as da90,
                                    nature_m4 as m4,
                                    nature_m5 as m5,
                                    nature_m6 as m6,
                                    nature_m7 as m7,
                                    nature_m8 as m8,
                                    nature_m9 as m9,
                                    nature_m10 as m10,
                                    nature_m11 as m11,
                                    nature_y1 as y1,
                                    nature_total as total,
                                    nature_first_role_num as first_role_num_ltv,
                                    nature_reg_user_cnt as reg_user_cnt
                                FROM
                                    game_ads_parent.ads_user_role_ltv_trend_parent
                            """ + cri +
                    """
                                    ) b
                                ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        }

        return """
                SELECT
                    a.*,
                    b.*
                FROM (
                    SELECT
                        dt cost_date,
                        parent_game_name as game_name,
                        parent_game_id as game_id,
                        parent_game_name_classify as game_classify,
                        source_system,
                        cost,
                        reg_num,
                        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,
                        total_roi,
                        first_roi,
                        first_amount_rate,
                        today_amount_rate,
                        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,
                        reg_cost,
                        first_amount_cost as first_new_user_recharge_cost,
                        total_amount_cost as total_recharge_cost,
                        hundred_user_num,
                        hundred_user_num_cost,
                        first_role_num,
                        role_num,
                        new_user_total_role_num,
                        round(IF(first_role_num > 0, cost / first_role_num, 0), 2) first_role_num_cost,
                        round(IF(role_num > 0, cost / role_num, 0), 2) role_num_cost,
                        round(IF(new_user_total_role_num >0, cost / new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                        round(IF(reg_num >0, first_role_num / reg_num, 0), 4) first_role_num_rate,
                        round(IF(reg_num >0, role_num / reg_num, 0), 4) role_num_rate,
                        round(IF(reg_num >0, new_user_total_role_num / reg_num, 0), 4) new_user_total_role_num_rate
                    FROM
                        game_ads_parent.ads_game_day_parent
                """ + cri +
                """
                                ) a
                        LEFT JOIN (
                            SELECT
                                parent_game_id as game_id,
                                parent_game_name as game_name,
                                dt,
                                user_ltv_1 as user_ltv1,
                                user_ltv_2 as user_ltv2,
                                user_ltv_3 as user_ltv3,
                                user_ltv_4 as user_ltv4,
                                user_ltv_5 as user_ltv5,
                                user_ltv_6 as user_ltv6,
                                user_ltv_7 as user_ltv7,
                                user_ltv_8 as user_ltv8,
                                user_ltv_9 as user_ltv9,
                                user_ltv_10 as user_ltv10,
                                user_ltv_11 as user_ltv11,
                                user_ltv_12 as user_ltv12,
                                user_ltv_13 as user_ltv13,
                                user_ltv_14 as user_ltv14,
                                user_ltv_15 as user_ltv15,
                                user_ltv_16 as user_ltv16,
                                user_ltv_17 as user_ltv17,
                                user_ltv_18 as user_ltv18,
                                user_ltv_19 as user_ltv19,
                                user_ltv_20 as user_ltv20,
                                user_ltv_21 as user_ltv21,
                                user_ltv_22 as user_ltv22,
                                user_ltv_23 as user_ltv23,
                                user_ltv_24 as user_ltv24,
                                user_ltv_25 as user_ltv25,
                                user_ltv_26 as user_ltv26,
                                user_ltv_27 as user_ltv27,
                                user_ltv_28 as user_ltv28,
                                user_ltv_29 as user_ltv29,
                                user_ltv_30 as user_ltv30,
                                user_ltv_31 as user_ltv31,
                                user_ltv_32 as user_ltv32,
                                user_ltv_33 as user_ltv33,
                                user_ltv_34 as user_ltv34,
                                user_ltv_35 as user_ltv35,
                                user_ltv_36 as user_ltv36,
                                user_ltv_37 as user_ltv37,
                                user_ltv_38 as user_ltv38,
                                user_ltv_39 as user_ltv39,
                                user_ltv_40 as user_ltv40,
                                user_ltv_41 as user_ltv41,
                                user_ltv_42 as user_ltv42,
                                user_ltv_43 as user_ltv43,
                                user_ltv_44 as user_ltv44,
                                user_ltv_45 as user_ltv45,
                                user_ltv_46 as user_ltv46,
                                user_ltv_47 as user_ltv47,
                                user_ltv_48 as user_ltv48,
                                user_ltv_49 as user_ltv49,
                                user_ltv_50 as user_ltv50,
                                user_ltv_51 as user_ltv51,
                                user_ltv_52 as user_ltv52,
                                user_ltv_53 as user_ltv53,
                                user_ltv_54 as user_ltv54,
                                user_ltv_55 as user_ltv55,
                                user_ltv_56 as user_ltv56,
                                user_ltv_57 as user_ltv57,
                                user_ltv_58 as user_ltv58,
                                user_ltv_59 as user_ltv59,
                                user_ltv_60 as user_ltv60,
                                user_ltv_61 as user_ltv61,
                                user_ltv_62 as user_ltv62,
                                user_ltv_63 as user_ltv63,
                                user_ltv_64 as user_ltv64,
                                user_ltv_65 as user_ltv65,
                                user_ltv_66 as user_ltv66,
                                user_ltv_67 as user_ltv67,
                                user_ltv_68 as user_ltv68,
                                user_ltv_69 as user_ltv69,
                                user_ltv_70 as user_ltv70,
                                user_ltv_71 as user_ltv71,
                                user_ltv_72 as user_ltv72,
                                user_ltv_73 as user_ltv73,
                                user_ltv_74 as user_ltv74,
                                user_ltv_75 as user_ltv75,
                                user_ltv_76 as user_ltv76,
                                user_ltv_77 as user_ltv77,
                                user_ltv_78 as user_ltv78,
                                user_ltv_79 as user_ltv79,
                                user_ltv_80 as user_ltv80,
                                user_ltv_81 as user_ltv81,
                                user_ltv_82 as user_ltv82,
                                user_ltv_83 as user_ltv83,
                                user_ltv_84 as user_ltv84,
                                user_ltv_85 as user_ltv85,
                                user_ltv_86 as user_ltv86,
                                user_ltv_87 as user_ltv87,
                                user_ltv_88 as user_ltv88,
                                user_ltv_89 as user_ltv89,
                                user_ltv_90 as user_ltv90,
                                user_ltv_m4,
                                user_ltv_m5,
                                user_ltv_m6,
                                user_ltv_m7,
                                user_ltv_m8,
                                user_ltv_m9,
                                user_ltv_m10,
                                user_ltv_m11,
                                user_ltv_y1,
                                user_ltv_total,
                                role_ltv_1 as role_ltv1,
                                role_ltv_2 as role_ltv2,
                                role_ltv_3 as role_ltv3,
                                role_ltv_4 as role_ltv4,
                                role_ltv_5 as role_ltv5,
                                role_ltv_6 as role_ltv6,
                                role_ltv_7 as role_ltv7,
                                role_ltv_8 as role_ltv8,
                                role_ltv_9 as role_ltv9,
                                role_ltv_10 as role_ltv10,
                                role_ltv_11 as role_ltv11,
                                role_ltv_12 as role_ltv12,
                                role_ltv_13 as role_ltv13,
                                role_ltv_14 as role_ltv14,
                                role_ltv_15 as role_ltv15,
                                role_ltv_16 as role_ltv16,
                                role_ltv_17 as role_ltv17,
                                role_ltv_18 as role_ltv18,
                                role_ltv_19 as role_ltv19,
                                role_ltv_20 as role_ltv20,
                                role_ltv_21 as role_ltv21,
                                role_ltv_22 as role_ltv22,
                                role_ltv_23 as role_ltv23,
                                role_ltv_24 as role_ltv24,
                                role_ltv_25 as role_ltv25,
                                role_ltv_26 as role_ltv26,
                                role_ltv_27 as role_ltv27,
                                role_ltv_28 as role_ltv28,
                                role_ltv_29 as role_ltv29,
                                role_ltv_30 as role_ltv30,
                                role_ltv_31 as role_ltv31,
                                role_ltv_32 as role_ltv32,
                                role_ltv_33 as role_ltv33,
                                role_ltv_34 as role_ltv34,
                                role_ltv_35 as role_ltv35,
                                role_ltv_36 as role_ltv36,
                                role_ltv_37 as role_ltv37,
                                role_ltv_38 as role_ltv38,
                                role_ltv_39 as role_ltv39,
                                role_ltv_40 as role_ltv40,
                                role_ltv_41 as role_ltv41,
                                role_ltv_42 as role_ltv42,
                                role_ltv_43 as role_ltv43,
                                role_ltv_44 as role_ltv44,
                                role_ltv_45 as role_ltv45,
                                role_ltv_46 as role_ltv46,
                                role_ltv_47 as role_ltv47,
                                role_ltv_48 as role_ltv48,
                                role_ltv_49 as role_ltv49,
                                role_ltv_50 as role_ltv50,
                                role_ltv_51 as role_ltv51,
                                role_ltv_52 as role_ltv52,
                                role_ltv_53 as role_ltv53,
                                role_ltv_54 as role_ltv54,
                                role_ltv_55 as role_ltv55,
                                role_ltv_56 as role_ltv56,
                                role_ltv_57 as role_ltv57,
                                role_ltv_58 as role_ltv58,
                                role_ltv_59 as role_ltv59,
                                role_ltv_60 as role_ltv60,
                                role_ltv_61 as role_ltv61,
                                role_ltv_62 as role_ltv62,
                                role_ltv_63 as role_ltv63,
                                role_ltv_64 as role_ltv64,
                                role_ltv_65 as role_ltv65,
                                role_ltv_66 as role_ltv66,
                                role_ltv_67 as role_ltv67,
                                role_ltv_68 as role_ltv68,
                                role_ltv_69 as role_ltv69,
                                role_ltv_70 as role_ltv70,
                                role_ltv_71 as role_ltv71,
                                role_ltv_72 as role_ltv72,
                                role_ltv_73 as role_ltv73,
                                role_ltv_74 as role_ltv74,
                                role_ltv_75 as role_ltv75,
                                role_ltv_76 as role_ltv76,
                                role_ltv_77 as role_ltv77,
                                role_ltv_78 as role_ltv78,
                                role_ltv_79 as role_ltv79,
                                role_ltv_80 as role_ltv80,
                                role_ltv_81 as role_ltv81,
                                role_ltv_82 as role_ltv82,
                                role_ltv_83 as role_ltv83,
                                role_ltv_84 as role_ltv84,
                                role_ltv_85 as role_ltv85,
                                role_ltv_86 as role_ltv86,
                                role_ltv_87 as role_ltv87,
                                role_ltv_88 as role_ltv88,
                                role_ltv_89 as role_ltv89,
                                role_ltv_90 as role_ltv90,
                                role_ltv_m4,
                                role_ltv_m5,
                                role_ltv_m6,
                                role_ltv_m7,
                                role_ltv_m8,
                                role_ltv_m9,
                                role_ltv_m10,
                                role_ltv_m11,
                                role_ltv_y1,
                                role_ltv_total,
                                da1,
                                da2,
                                da3,
                                da4,
                                da5,
                                da6,
                                da7,
                                da8,
                                da9,
                                da10,
                                da11,
                                da12,
                                da13,
                                da14,
                                da15,
                                da16,
                                da17,
                                da18,
                                da19,
                                da20,
                                da21,
                                da22,
                                da23,
                                da24,
                                da25,
                                da26,
                                da27,
                                da28,
                                da29,
                                da30,
                                da31,
                                da32,
                                da33,
                                da34,
                                da35,
                                da36,
                                da37,
                                da38,
                                da39,
                                da40,
                                da41,
                                da42,
                                da43,
                                da44,
                                da45,
                                da46,
                                da47,
                                da48,
                                da49,
                                da50,
                                da51,
                                da52,
                                da53,
                                da54,
                                da55,
                                da56,
                                da57,
                                da58,
                                da59,
                                da60,
                                da61,
                                da62,
                                da63,
                                da64,
                                da65,
                                da66,
                                da67,
                                da68,
                                da69,
                                da70,
                                da71,
                                da72,
                                da73,
                                da74,
                                da75,
                                da76,
                                da77,
                                da78,
                                da79,
                                da80,
                                da81,
                                da82,
                                da83,
                                da84,
                                da85,
                                da86,
                                da87,
                                da88,
                                da89,
                                da90,
                                m4,
                                m5,
                                m6,
                                m7,
                                m8,
                                m9,
                                m10,
                                m11,
                                y1,
                                total,
                                first_role_num first_role_num_ltv,
                                reg_user_cnt
                            FROM
                                game_ads_parent.ads_user_role_ltv_trend_parent
                        """ + cri +
                """
                            ) b
                        ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                        """;
    }

    /**
     * 游戏数据每日总计一栏（按类型返回sql）
     *
     * @param type      查询的类型 buy、nature、total
     * @param tableName 查询的表名 子游戏维度、父游戏维度
     * @return String
     */
    private String getTotalGameData(String type, String tableName) {
        if ("buy".equals(type)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(buy_reg_num), 0) reg_num,
                        IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
                        IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
                        IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
                        IFNULL(SUM(buy_old_user_count), 0) old_user_count,
                        IFNULL(SUM(buy_old_user_num), 0) old_user_num,
                        IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
                        IFNULL(SUM(buy_amount_count), 0) amount_count,
                        IFNULL(SUM(buy_amount_num), 0) amount_num,
                        IFNULL(SUM(buy_amount), 0) amount,
                        IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
                        IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
                        IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
                        round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                        round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
                        round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
                        round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
                        round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
                        round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
                        round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
                        round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
                        round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
                        round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
                        round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
                        round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
                        round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
                        round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                        round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
                        round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                        IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
                        round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
                        IFNULL(SUM(buy_first_role_num), 0) first_role_num,
                        IFNULL(SUM(buy_role_num), 0) role_num,
                        IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
                        round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
                        round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
                        round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                        round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
                        round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
                        round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate
                    FROM 
                    """ + tableName;
        } else if ("nature".equals(type)) {
            return """
                    SELECT
                        IFNULL(SUM(cost), 0) cost,
                        IFNULL(SUM(nature_reg_num), 0) reg_num,
                        IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
                        IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
                        IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
                        IFNULL(SUM(nature_old_user_count), 0) old_user_count,
                        IFNULL(SUM(nature_old_user_num), 0) old_user_num,
                        IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
                        IFNULL(SUM(nature_amount_count), 0) amount_count,
                        IFNULL(SUM(nature_amount_num), 0) amount_num,
                        IFNULL(SUM(nature_amount), 0) amount,
                        IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
                        IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
                        IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
                        round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                        round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
                        round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
                        round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
                        round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
                        round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
                        round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
                        round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
                        round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
                        round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
                        round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
                        round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
                        round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
                        round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                        round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
                        round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                        IFNULL(SUM(nature_hundred_user_num), 0) hundred_user_num,
                        round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
                        IFNULL(SUM(nature_first_role_num), 0) first_role_num,
                        IFNULL(SUM(nature_role_num), 0) role_num,
                        IFNULL(SUM(nature_new_user_total_role_num), 0) new_user_total_role_num,
                        round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
                        round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
                        round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                        round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
                        round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
                        round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate
                    FROM 
                    """ + tableName;
        }
        //total总量数据
        return """
                SELECT
                    IFNULL(SUM(cost), 0) cost,
                    IFNULL(SUM(reg_num), 0) reg_num,
                    IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
                    IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
                    IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
                    IFNULL(SUM(old_user_count), 0) old_user_count,
                    IFNULL(SUM(old_user_num), 0) old_user_num,
                    IFNULL(SUM(old_user_amount), 0) old_user_amount,
                    IFNULL(SUM(amount_count), 0) amount_count,
                    IFNULL(SUM(amount_num), 0) amount_num,
                    IFNULL(SUM(amount), 0) amount,
                    IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
                    IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
                    IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
                    round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
                    round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
                    round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
                    round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
                    round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
                    round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
                    round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
                    round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
                    round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
                    round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
                    round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
                    round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
                    round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
                    round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
                    round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
                    round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
                    IFNULL(SUM(hundred_user_num), 0) hundred_user_num,
                    round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
                    IFNULL(SUM(first_role_num), 0) first_role_num,
                    IFNULL(SUM(role_num), 0) role_num,
                    IFNULL(SUM(new_user_total_role_num), 0) new_user_total_role_num,
                    round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
                    round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
                    round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
                    round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
                    round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
                    round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate
                FROM 
                """ + tableName;

    }

    /**
     * ltv总计一栏sql,(ltv部分)
     *
     * @param type                查询的类型 buy、nature、total
     * @param tableNameForLTVData 查询ltv数据的维度表
     * @return String
     */
    private String getLtvDataTotalAboutLtv(String type, String tableNameForLTVData) {
        if ("buy".equals(type)) {
            type = "buy_";
        } else if ("nature".equals(type)) {
            type = "nature_";
        } else {
            type = "";
        }
        StringBuilder temp = new StringBuilder(StringUtils.EMPTY);
        temp.append("""
                SELECT  
                """);
        //拼接da1-da90数据
        for (int i = 1; i <= 90; i++) {
            temp.append("""
                    ROUND(IF(SUM(%sreg_user_cnt) > 0,
                        SUM(%sda%s) / SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= Local.now(), %sreg_user_cnt, 0)) , 0), 2) as user_ltv%s,
                    ROUND(IF(SUM(%sfirst_role_num) > 0,
                        SUM(%sda%s) / SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= Local.now(), %sfirst_role_num, 0)) , 0), 2) as role_ltv%s,
                    """.formatted(type, type, i, i - 1, type, i, type, type, i, i - 1, type, i));
        }
        //拼接m4-m11数据
        for (int i = 4; i <= 11; i++) {
            temp.append("""
                    ROUND(IF(SUM(%sreg_user_cnt) > 0,
                        SUM(%sm%s) / SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= Local.now(), %sreg_user_cnt, 0)) , 0), 2) as user_ltv_m%s,
                    ROUND(IF(SUM(%sfirst_role_num) > 0,
                        SUM(%sm%s) / SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= Local.now(), %sfirst_role_num, 0)) , 0), 2) as role_ltv_m%s,
                    """.formatted(type, type, i, i, type, i, type, type, i, i, type, i));
        }
        //拼接y1数据
        temp.append("""
                ROUND(IF(SUM(%sreg_user_cnt) > 0,
                    SUM(%sy1) / SUM(IF(DATE_ADD(dt, INTERVAL 1 year) <= Local.now(), %sreg_user_cnt, 0)) , 0), 2) as user_ltv_y1,
                ROUND(IF(SUM(%sfirst_role_num) > 0,
                    SUM(%sy1) / SUM(IF(DATE_ADD(dt, INTERVAL 1 year) <= Local.now(), %sfirst_role_num, 0)) , 0), 2) as role_ltv_y1,
                """.formatted(type, type, type, type, type, type));
        //拼接total数据
        temp.append("""
                ROUND(IF(SUM(%sreg_user_cnt) > 0, SUM(%stotal) / SUM(%sreg_user_cnt) , 0), 2) as user_ltv_total,
                ROUND(IF(SUM(%sfirst_role_num) > 0, SUM(%stotal) / SUM(%sfirst_role_num) , 0), 2) as role_ltv_total,
                """.formatted(type, type, type, type, type, type));
        //拼接注册人数、创角人数
        temp.append("""
                IFNULL(SUM(%sfirst_role_num), 0) as first_role_num_ltv,
                IFNULL(SUM(%sreg_user_cnt), 0) as reg_user_cnt
                """.formatted(type, type));
        temp.append(" FROM ");
        temp.append(tableNameForLTVData);

        return temp.toString();
    }

    /**
     * 游戏首日复充每日数据sql-子游戏维度
     *
     * @param type 查询的类型 buy -> 买量  ;  nature ->  自然量 ; total -> 总量
     * @param cri  查询条件
     * @return String
     */
    private String getFirstNewUserAgainByTableTypesSql(String type, Criteria cri) {
        if ("buy".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            game_name,
                            game_id,
                            game_classify,
                            source_system,
                            cost,
                            buy_reg_num as reg_num,
                            buy_first_new_user_amount_count as first_new_user_amount_count,
                            buy_first_new_user_amount_num as first_new_user_amount_num,
                            buy_first_new_user_amount as first_new_user_amount,
                            buy_old_user_count as old_user_count,
                            buy_old_user_num as old_user_num,
                            buy_old_user_amount as old_user_amount,
                            buy_amount_count as amount_count,
                            buy_amount_num as amount_num,
                            buy_amount as amount,
                            buy_new_user_total_amount_count as new_user_total_amount_count,
                            buy_new_user_total_amount_num as new_user_total_amount_num,
                            buy_new_user_total_amount as new_user_total_amount,
                            buy_total_roi as total_roi,
                            buy_first_roi as first_roi,
                            buy_first_amount_rate as first_amount_rate,
                            buy_today_amount_rate as today_amount_rate,
                            buy_new_user_rate as new_user_rate,
                            buy_first_avg_amount as first_avg_amount,
                            buy_today_avg_amount as today_avg_amount,
                            buy_avg_amount as avg_amount,
                            buy_user_again_rate as user_again_rate,
                            buy_reg_user_arpu as reg_user_arpu,
                            buy_first_amount_arpu as first_amount_arpu,
                            buy_today_amount_arpu as today_amount_arpu,
                            buy_amount_arpu as amount_arpu,
                            buy_reg_cost as reg_cost,
                            buy_first_amount_cost as first_new_user_recharge_cost,
                            buy_total_amount_cost as total_recharge_cost,
                            buy_hundred_user_num as hundred_user_num,
                            buy_hundred_user_num_cost as hundred_user_num_cost,
                            buy_first_role_num as first_role_num,
                            buy_role_num as role_num,
                            buy_new_user_total_role_num as new_user_total_role_num,
                            round(IF(buy_first_role_num > 0, cost / buy_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(buy_role_num > 0, cost / buy_role_num, 0), 2) role_num_cost,
                            round(IF(buy_new_user_total_role_num >0, cost / buy_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(buy_reg_num >0, buy_first_role_num / buy_reg_num, 0), 4) first_role_num_rate,
                            round(IF(buy_reg_num >0, buy_role_num / buy_reg_num, 0), 4) role_num_rate,
                            round(IF(buy_reg_num >0, buy_new_user_total_role_num / buy_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            ads_game_day
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    game_id,
                                    game_name,
                                    dt,
                                    buy_da1 as da1,
                                    buy_da2 as da2,
                                    buy_da3 as da3,
                                    buy_da4 as da4,
                                    buy_da5 as da5,
                                    buy_da6 as da6,
                                    buy_da7 as da7,
                                    buy_da8 as da8,
                                    buy_da9 as da9,
                                    buy_da10 as da10,
                                    buy_da11 as da11,
                                    buy_da12 as da12,
                                    buy_da13 as da13,
                                    buy_da14 as da14,
                                    buy_da15 as da15,
                                    buy_da16 as da16,
                                    buy_da17 as da17,
                                    buy_da18 as da18,
                                    buy_da19 as da19,
                                    buy_da20 as da20,
                                    buy_da21 as da21,
                                    buy_da22 as da22,
                                    buy_da23 as da23,
                                    buy_da24 as da24,
                                    buy_da25 as da25,
                                    buy_da26 as da26,
                                    buy_da27 as da27,
                                    buy_da28 as da28,
                                    buy_da29 as da29,
                                    buy_da30 as da30,
                                    buy_da31 as da31,
                                    buy_da32 as da32,
                                    buy_da33 as da33,
                                    buy_da34 as da34,
                                    buy_da35 as da35,
                                    buy_da36 as da36,
                                    buy_da37 as da37,
                                    buy_da38 as da38,
                                    buy_da39 as da39,
                                    buy_da40 as da40,
                                    buy_da41 as da41,
                                    buy_da42 as da42,
                                    buy_da43 as da43,
                                    buy_da44 as da44,
                                    buy_da45 as da45,
                                    buy_da46 as da46,
                                    buy_da47 as da47,
                                    buy_da48 as da48,
                                    buy_da49 as da49,
                                    buy_da50 as da50,
                                    buy_da51 as da51,
                                    buy_da52 as da52,
                                    buy_da53 as da53,
                                    buy_da54 as da54,
                                    buy_da55 as da55,
                                    buy_da56 as da56,
                                    buy_da57 as da57,
                                    buy_da58 as da58,
                                    buy_da59 as da59,
                                    buy_da60 as da60,
                                    buy_da61 as da61,
                                    buy_da62 as da62,
                                    buy_da63 as da63,
                                    buy_da64 as da64,
                                    buy_da65 as da65,
                                    buy_da66 as da66,
                                    buy_da67 as da67,
                                    buy_da68 as da68,
                                    buy_da69 as da69,
                                    buy_da70 as da70,
                                    buy_da71 as da71,
                                    buy_da72 as da72,
                                    buy_da73 as da73,
                                    buy_da74 as da74,
                                    buy_da75 as da75,
                                    buy_da76 as da76,
                                    buy_da77 as da77,
                                    buy_da78 as da78,
                                    buy_da79 as da79,
                                    buy_da80 as da80,
                                    buy_da81 as da81,
                                    buy_da82 as da82,
                                    buy_da83 as da83,
                                    buy_da84 as da84,
                                    buy_da85 as da85,
                                    buy_da86 as da86,
                                    buy_da87 as da87,
                                    buy_da88 as da88,
                                    buy_da89 as da89,
                                    buy_da90 as da90,
                                    buy_m4 as m4,
                                    buy_m5 as m5,
                                    buy_m6 as m6,
                                    buy_m7 as m7,
                                    buy_m8 as m8,
                                    buy_m9 as m9,
                                    buy_m10 as m10,
                                    buy_m11 as m11,
                                    buy_m12 as m12,
                                    buy_total as total
                                FROM
                                    ads_game_first_new_user_again_day
                            """ + cri +
                    """
                                ) b
                            ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        } else if ("nature".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            game_name,
                            game_id,
                            game_classify,
                            source_system,
                            cost,
                            nature_reg_num as reg_num,
                            nature_first_new_user_amount_count as first_new_user_amount_count,
                            nature_first_new_user_amount_num as first_new_user_amount_num,
                            nature_first_new_user_amount as first_new_user_amount,
                            nature_old_user_count as old_user_count,
                            nature_old_user_num as old_user_num,
                            nature_old_user_amount as old_user_amount,
                            nature_amount_count as amount_count,
                            nature_amount_num as amount_num,
                            nature_amount as amount,
                            nature_new_user_total_amount_count as new_user_total_amount_count,
                            nature_new_user_total_amount_num as new_user_total_amount_num,
                            nature_new_user_total_amount as new_user_total_amount,
                            nature_total_roi as total_roi,
                            nature_first_roi as first_roi,
                            nature_first_amount_rate as first_amount_rate,
                            nature_today_amount_rate as today_amount_rate,
                            nature_new_user_rate as new_user_rate,
                            nature_first_avg_amount as first_avg_amount,
                            nature_today_avg_amount as today_avg_amount,
                            nature_avg_amount as avg_amount,
                            nature_user_again_rate as user_again_rate,
                            nature_reg_user_arpu as reg_user_arpu,
                            nature_first_amount_arpu as first_amount_arpu,
                            nature_today_amount_arpu as today_amount_arpu,
                            nature_amount_arpu as amount_arpu,
                            nature_reg_cost as reg_cost,
                            nature_first_amount_cost as first_new_user_recharge_cost,
                            nature_total_amount_cost as total_recharge_cost,
                            nature_hundred_user_num as hundred_user_num,
                            nature_hundred_user_num_cost as hundred_user_num_cost,
                            nature_first_role_num as first_role_num,
                            nature_role_num as role_num,
                            nature_new_user_total_role_num as new_user_total_role_num,
                            round(IF(nature_first_role_num > 0, cost / nature_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(nature_role_num > 0, cost / nature_role_num, 0), 2) role_num_cost,
                            round(IF(nature_new_user_total_role_num >0, cost / nature_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(nature_reg_num >0, nature_first_role_num / nature_reg_num, 0), 4) first_role_num_rate,
                            round(IF(nature_reg_num >0, nature_role_num / nature_reg_num, 0), 4) role_num_rate,
                            round(IF(nature_reg_num >0, nature_new_user_total_role_num / nature_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            ads_game_day
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    game_id,
                                    game_name,
                                    dt,
                                    nature_da1 as da1,
                                    nature_da2 as da2,
                                    nature_da3 as da3,
                                    nature_da4 as da4,
                                    nature_da5 as da5,
                                    nature_da6 as da6,
                                    nature_da7 as da7,
                                    nature_da8 as da8,
                                    nature_da9 as da9,
                                    nature_da10 as da10,
                                    nature_da11 as da11,
                                    nature_da12 as da12,
                                    nature_da13 as da13,
                                    nature_da14 as da14,
                                    nature_da15 as da15,
                                    nature_da16 as da16,
                                    nature_da17 as da17,
                                    nature_da18 as da18,
                                    nature_da19 as da19,
                                    nature_da20 as da20,
                                    nature_da21 as da21,
                                    nature_da22 as da22,
                                    nature_da23 as da23,
                                    nature_da24 as da24,
                                    nature_da25 as da25,
                                    nature_da26 as da26,
                                    nature_da27 as da27,
                                    nature_da28 as da28,
                                    nature_da29 as da29,
                                    nature_da30 as da30,
                                    nature_da31 as da31,
                                    nature_da32 as da32,
                                    nature_da33 as da33,
                                    nature_da34 as da34,
                                    nature_da35 as da35,
                                    nature_da36 as da36,
                                    nature_da37 as da37,
                                    nature_da38 as da38,
                                    nature_da39 as da39,
                                    nature_da40 as da40,
                                    nature_da41 as da41,
                                    nature_da42 as da42,
                                    nature_da43 as da43,
                                    nature_da44 as da44,
                                    nature_da45 as da45,
                                    nature_da46 as da46,
                                    nature_da47 as da47,
                                    nature_da48 as da48,
                                    nature_da49 as da49,
                                    nature_da50 as da50,
                                    nature_da51 as da51,
                                    nature_da52 as da52,
                                    nature_da53 as da53,
                                    nature_da54 as da54,
                                    nature_da55 as da55,
                                    nature_da56 as da56,
                                    nature_da57 as da57,
                                    nature_da58 as da58,
                                    nature_da59 as da59,
                                    nature_da60 as da60,
                                    nature_da61 as da61,
                                    nature_da62 as da62,
                                    nature_da63 as da63,
                                    nature_da64 as da64,
                                    nature_da65 as da65,
                                    nature_da66 as da66,
                                    nature_da67 as da67,
                                    nature_da68 as da68,
                                    nature_da69 as da69,
                                    nature_da70 as da70,
                                    nature_da71 as da71,
                                    nature_da72 as da72,
                                    nature_da73 as da73,
                                    nature_da74 as da74,
                                    nature_da75 as da75,
                                    nature_da76 as da76,
                                    nature_da77 as da77,
                                    nature_da78 as da78,
                                    nature_da79 as da79,
                                    nature_da80 as da80,
                                    nature_da81 as da81,
                                    nature_da82 as da82,
                                    nature_da83 as da83,
                                    nature_da84 as da84,
                                    nature_da85 as da85,
                                    nature_da86 as da86,
                                    nature_da87 as da87,
                                    nature_da88 as da88,
                                    nature_da89 as da89,
                                    nature_da90 as da90,
                                    nature_m4 as m4,
                                    nature_m5 as m5,
                                    nature_m6 as m6,
                                    nature_m7 as m7,
                                    nature_m8 as m8,
                                    nature_m9 as m9,
                                    nature_m10 as m10,
                                    nature_m11 as m11,
                                    nature_m12 as m12,
                                    nature_total as total
                                FROM
                                    ads_game_first_new_user_again_day
                            """ + cri +
                    """
                                    ) b
                                ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                            """;
        }
        //总量 total
        return """
                SELECT
                    a.*,
                    b.*
                FROM (
                    SELECT
                        dt cost_date,
                        game_name,
                        game_id,
                        game_classify,
                        source_system,
                        cost,
                        reg_num,
                        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,
                        total_roi,
                        first_roi,
                        first_amount_rate,
                        today_amount_rate,
                        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,
                        reg_cost,
                        first_amount_cost as first_new_user_recharge_cost,
                        total_amount_cost as total_recharge_cost,
                        hundred_user_num,
                        hundred_user_num_cost,
                        first_role_num,
                        role_num,
                        new_user_total_role_num,
                        round(IF(first_role_num > 0, cost / first_role_num, 0), 2) first_role_num_cost,
                        round(IF(role_num > 0, cost / role_num, 0), 2) role_num_cost,
                        round(IF(new_user_total_role_num >0, cost / new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                        round(IF(reg_num >0, first_role_num / reg_num, 0), 4) first_role_num_rate,
                        round(IF(reg_num >0, role_num / reg_num, 0), 4) role_num_rate,
                        round(IF(reg_num >0, new_user_total_role_num / reg_num, 0), 4) new_user_total_role_num_rate
                    FROM
                        ads_game_day
                """ + cri +
                """
                                ) a
                        LEFT JOIN (
                            SELECT
                                game_id,
                                game_name,
                                dt,
                                da1,
                                da2,
                                da3,
                                da4,
                                da5,
                                da6,
                                da7,
                                da8,
                                da9,
                                da10,
                                da11,
                                da12,
                                da13,
                                da14,
                                da15,
                                da16,
                                da17,
                                da18,
                                da19,
                                da20,
                                da21,
                                da22,
                                da23,
                                da24,
                                da25,
                                da26,
                                da27,
                                da28,
                                da29,
                                da30,
                                da31,
                                da32,
                                da33,
                                da34,
                                da35,
                                da36,
                                da37,
                                da38,
                                da39,
                                da40,
                                da41,
                                da42,
                                da43,
                                da44,
                                da45,
                                da46,
                                da47,
                                da48,
                                da49,
                                da50,
                                da51,
                                da52,
                                da53,
                                da54,
                                da55,
                                da56,
                                da57,
                                da58,
                                da59,
                                da60,
                                da61,
                                da62,
                                da63,
                                da64,
                                da65,
                                da66,
                                da67,
                                da68,
                                da69,
                                da70,
                                da71,
                                da72,
                                da73,
                                da74,
                                da75,
                                da76,
                                da77,
                                da78,
                                da79,
                                da80,
                                da81,
                                da82,
                                da83,
                                da84,
                                da85,
                                da86,
                                da87,
                                da88,
                                da89,
                                da90,
                                m4,
                                m5,
                                m6,
                                m7,
                                m8,
                                m9,
                                m10,
                                m11,
                                m12,
                                total
                            FROM
                                ads_game_first_new_user_again_day
                        """ + cri +
                """
                            ) b
                        ON a.game_id = b.game_id and a.cost_date = b.dt and a.game_name = b.game_name
                        """;
    }

    /**
     * 游戏首日复充每日数据sql- 父游戏维度
     *
     * @param type 查询的类型 buy -> 买量  ;  nature ->  自然量 ; total -> 总量
     * @param cri  查询条件
     * @return String
     */
    private String getFirstNewUserAgainByTableTypesSqlForParent(String type, Criteria cri) {
        if ("buy".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            parent_game_name as game_name,
                            parent_game_id as game_id,
                            parent_game_name_classify as game_classify,
                            source_system,
                            cost,
                            buy_reg_num as reg_num,
                            buy_first_new_user_amount_count as first_new_user_amount_count,
                            buy_first_new_user_amount_num as first_new_user_amount_num,
                            buy_first_new_user_amount as first_new_user_amount,
                            buy_old_user_count as old_user_count,
                            buy_old_user_num as old_user_num,
                            buy_old_user_amount as old_user_amount,
                            buy_amount_count as amount_count,
                            buy_amount_num as amount_num,
                            buy_amount as amount,
                            buy_new_user_total_amount_count as new_user_total_amount_count,
                            buy_new_user_total_amount_num as new_user_total_amount_num,
                            buy_new_user_total_amount as new_user_total_amount,
                            buy_total_roi as total_roi,
                            buy_first_roi as first_roi,
                            buy_first_amount_rate as first_amount_rate,
                            buy_today_amount_rate as today_amount_rate,
                            buy_new_user_rate as new_user_rate,
                            buy_first_avg_amount as first_avg_amount,
                            buy_today_avg_amount as today_avg_amount,
                            buy_avg_amount as avg_amount,
                            buy_user_again_rate as user_again_rate,
                            buy_reg_user_arpu as reg_user_arpu,
                            buy_first_amount_arpu as first_amount_arpu,
                            buy_today_amount_arpu as today_amount_arpu,
                            buy_amount_arpu as amount_arpu,
                            buy_reg_cost as reg_cost,
                            buy_first_amount_cost as first_new_user_recharge_cost,
                            buy_total_amount_cost as total_recharge_cost,
                            buy_hundred_user_num as hundred_user_num,
                            buy_hundred_user_num_cost as hundred_user_num_cost,
                            buy_first_role_num as first_role_num,
                            buy_role_num as role_num,
                            buy_new_user_total_role_num as new_user_total_role_num,
                            round(IF(buy_first_role_num > 0, cost / buy_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(buy_role_num > 0, cost / buy_role_num, 0), 2) role_num_cost,
                            round(IF(buy_new_user_total_role_num >0, cost / buy_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(buy_reg_num >0, buy_first_role_num / buy_reg_num, 0), 4) first_role_num_rate,
                            round(IF(buy_reg_num >0, buy_role_num / buy_reg_num, 0), 4) role_num_rate,
                            round(IF(buy_reg_num >0, buy_new_user_total_role_num / buy_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    parent_game_id,
                                    parent_game_name,
                                    dt,
                                    buy_da1 as da1,
                                    buy_da2 as da2,
                                    buy_da3 as da3,
                                    buy_da4 as da4,
                                    buy_da5 as da5,
                                    buy_da6 as da6,
                                    buy_da7 as da7,
                                    buy_da8 as da8,
                                    buy_da9 as da9,
                                    buy_da10 as da10,
                                    buy_da11 as da11,
                                    buy_da12 as da12,
                                    buy_da13 as da13,
                                    buy_da14 as da14,
                                    buy_da15 as da15,
                                    buy_da16 as da16,
                                    buy_da17 as da17,
                                    buy_da18 as da18,
                                    buy_da19 as da19,
                                    buy_da20 as da20,
                                    buy_da21 as da21,
                                    buy_da22 as da22,
                                    buy_da23 as da23,
                                    buy_da24 as da24,
                                    buy_da25 as da25,
                                    buy_da26 as da26,
                                    buy_da27 as da27,
                                    buy_da28 as da28,
                                    buy_da29 as da29,
                                    buy_da30 as da30,
                                    buy_da31 as da31,
                                    buy_da32 as da32,
                                    buy_da33 as da33,
                                    buy_da34 as da34,
                                    buy_da35 as da35,
                                    buy_da36 as da36,
                                    buy_da37 as da37,
                                    buy_da38 as da38,
                                    buy_da39 as da39,
                                    buy_da40 as da40,
                                    buy_da41 as da41,
                                    buy_da42 as da42,
                                    buy_da43 as da43,
                                    buy_da44 as da44,
                                    buy_da45 as da45,
                                    buy_da46 as da46,
                                    buy_da47 as da47,
                                    buy_da48 as da48,
                                    buy_da49 as da49,
                                    buy_da50 as da50,
                                    buy_da51 as da51,
                                    buy_da52 as da52,
                                    buy_da53 as da53,
                                    buy_da54 as da54,
                                    buy_da55 as da55,
                                    buy_da56 as da56,
                                    buy_da57 as da57,
                                    buy_da58 as da58,
                                    buy_da59 as da59,
                                    buy_da60 as da60,
                                    buy_da61 as da61,
                                    buy_da62 as da62,
                                    buy_da63 as da63,
                                    buy_da64 as da64,
                                    buy_da65 as da65,
                                    buy_da66 as da66,
                                    buy_da67 as da67,
                                    buy_da68 as da68,
                                    buy_da69 as da69,
                                    buy_da70 as da70,
                                    buy_da71 as da71,
                                    buy_da72 as da72,
                                    buy_da73 as da73,
                                    buy_da74 as da74,
                                    buy_da75 as da75,
                                    buy_da76 as da76,
                                    buy_da77 as da77,
                                    buy_da78 as da78,
                                    buy_da79 as da79,
                                    buy_da80 as da80,
                                    buy_da81 as da81,
                                    buy_da82 as da82,
                                    buy_da83 as da83,
                                    buy_da84 as da84,
                                    buy_da85 as da85,
                                    buy_da86 as da86,
                                    buy_da87 as da87,
                                    buy_da88 as da88,
                                    buy_da89 as da89,
                                    buy_da90 as da90,
                                    buy_m4 as m4,
                                    buy_m5 as m5,
                                    buy_m6 as m6,
                                    buy_m7 as m7,
                                    buy_m8 as m8,
                                    buy_m9 as m9,
                                    buy_m10 as m10,
                                    buy_m11 as m11,
                                    buy_m12 as m12,
                                    buy_total as total
                                FROM
                                    game_ads_parent.ads_game_first_new_user_again_day_parent
                            """ + cri +
                    """
                                ) b
                            ON a.game_id = b.parent_game_id and a.cost_date = b.dt and a.game_name = b.parent_game_name
                            """;
        } else if ("nature".equals(type)) {
            return """
                    SELECT
                        a.*,
                        b.*
                    FROM (
                        SELECT
                            dt cost_date,
                            parent_game_name as game_name,
                            parent_game_id as game_id,
                            parent_game_name_classify as game_classify,
                            source_system,
                            cost,
                            nature_reg_num as reg_num,
                            nature_first_new_user_amount_count as first_new_user_amount_count,
                            nature_first_new_user_amount_num as first_new_user_amount_num,
                            nature_first_new_user_amount as first_new_user_amount,
                            nature_old_user_count as old_user_count,
                            nature_old_user_num as old_user_num,
                            nature_old_user_amount as old_user_amount,
                            nature_amount_count as amount_count,
                            nature_amount_num as amount_num,
                            nature_amount as amount,
                            nature_new_user_total_amount_count as new_user_total_amount_count,
                            nature_new_user_total_amount_num as new_user_total_amount_num,
                            nature_new_user_total_amount as new_user_total_amount,
                            nature_total_roi as total_roi,
                            nature_first_roi as first_roi,
                            nature_first_amount_rate as first_amount_rate,
                            nature_today_amount_rate as today_amount_rate,
                            nature_new_user_rate as new_user_rate,
                            nature_first_avg_amount as first_avg_amount,
                            nature_today_avg_amount as today_avg_amount,
                            nature_avg_amount as avg_amount,
                            nature_user_again_rate as user_again_rate,
                            nature_reg_user_arpu as reg_user_arpu,
                            nature_first_amount_arpu as first_amount_arpu,
                            nature_today_amount_arpu as today_amount_arpu,
                            nature_amount_arpu as amount_arpu,
                            nature_reg_cost as reg_cost,
                            nature_first_amount_cost as first_new_user_recharge_cost,
                            nature_total_amount_cost as total_recharge_cost,
                            nature_hundred_user_num as hundred_user_num,
                            nature_hundred_user_num_cost as hundred_user_num_cost,
                            nature_first_role_num as first_role_num,
                            nature_role_num as role_num,
                            nature_new_user_total_role_num as new_user_total_role_num,
                            round(IF(nature_first_role_num > 0, cost / nature_first_role_num, 0), 2) first_role_num_cost,
                            round(IF(nature_role_num > 0, cost / nature_role_num, 0), 2) role_num_cost,
                            round(IF(nature_new_user_total_role_num >0, cost / nature_new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                            round(IF(nature_reg_num >0, nature_first_role_num / nature_reg_num, 0), 4) first_role_num_rate,
                            round(IF(nature_reg_num >0, nature_role_num / nature_reg_num, 0), 4) role_num_rate,
                            round(IF(nature_reg_num >0, nature_new_user_total_role_num / nature_reg_num, 0), 4) new_user_total_role_num_rate
                        FROM
                            game_ads_parent.ads_game_day_parent
                    """ + cri +
                    """
                                    ) a
                            LEFT JOIN (
                                SELECT
                                    parent_game_id,
                                    parent_game_name,
                                    dt,
                                    nature_da1 as da1,
                                    nature_da2 as da2,
                                    nature_da3 as da3,
                                    nature_da4 as da4,
                                    nature_da5 as da5,
                                    nature_da6 as da6,
                                    nature_da7 as da7,
                                    nature_da8 as da8,
                                    nature_da9 as da9,
                                    nature_da10 as da10,
                                    nature_da11 as da11,
                                    nature_da12 as da12,
                                    nature_da13 as da13,
                                    nature_da14 as da14,
                                    nature_da15 as da15,
                                    nature_da16 as da16,
                                    nature_da17 as da17,
                                    nature_da18 as da18,
                                    nature_da19 as da19,
                                    nature_da20 as da20,
                                    nature_da21 as da21,
                                    nature_da22 as da22,
                                    nature_da23 as da23,
                                    nature_da24 as da24,
                                    nature_da25 as da25,
                                    nature_da26 as da26,
                                    nature_da27 as da27,
                                    nature_da28 as da28,
                                    nature_da29 as da29,
                                    nature_da30 as da30,
                                    nature_da31 as da31,
                                    nature_da32 as da32,
                                    nature_da33 as da33,
                                    nature_da34 as da34,
                                    nature_da35 as da35,
                                    nature_da36 as da36,
                                    nature_da37 as da37,
                                    nature_da38 as da38,
                                    nature_da39 as da39,
                                    nature_da40 as da40,
                                    nature_da41 as da41,
                                    nature_da42 as da42,
                                    nature_da43 as da43,
                                    nature_da44 as da44,
                                    nature_da45 as da45,
                                    nature_da46 as da46,
                                    nature_da47 as da47,
                                    nature_da48 as da48,
                                    nature_da49 as da49,
                                    nature_da50 as da50,
                                    nature_da51 as da51,
                                    nature_da52 as da52,
                                    nature_da53 as da53,
                                    nature_da54 as da54,
                                    nature_da55 as da55,
                                    nature_da56 as da56,
                                    nature_da57 as da57,
                                    nature_da58 as da58,
                                    nature_da59 as da59,
                                    nature_da60 as da60,
                                    nature_da61 as da61,
                                    nature_da62 as da62,
                                    nature_da63 as da63,
                                    nature_da64 as da64,
                                    nature_da65 as da65,
                                    nature_da66 as da66,
                                    nature_da67 as da67,
                                    nature_da68 as da68,
                                    nature_da69 as da69,
                                    nature_da70 as da70,
                                    nature_da71 as da71,
                                    nature_da72 as da72,
                                    nature_da73 as da73,
                                    nature_da74 as da74,
                                    nature_da75 as da75,
                                    nature_da76 as da76,
                                    nature_da77 as da77,
                                    nature_da78 as da78,
                                    nature_da79 as da79,
                                    nature_da80 as da80,
                                    nature_da81 as da81,
                                    nature_da82 as da82,
                                    nature_da83 as da83,
                                    nature_da84 as da84,
                                    nature_da85 as da85,
                                    nature_da86 as da86,
                                    nature_da87 as da87,
                                    nature_da88 as da88,
                                    nature_da89 as da89,
                                    nature_da90 as da90,
                                    nature_m4 as m4,
                                    nature_m5 as m5,
                                    nature_m6 as m6,
                                    nature_m7 as m7,
                                    nature_m8 as m8,
                                    nature_m9 as m9,
                                    nature_m10 as m10,
                                    nature_m11 as m11,
                                    nature_m12 as m12,
                                    nature_total as total
                                FROM
                                    game_ads_parent.ads_game_first_new_user_again_day_parent
                            """ + cri +
                    """
                                ) b
                            ON a.game_id = b.parent_game_id and a.cost_date = b.dt and a.game_name = b.parent_game_name
                            """;
        }
        //总量 total
        return """
                SELECT
                    a.*,
                    b.*
                FROM (
                    SELECT
                        dt cost_date,
                        parent_game_name as game_name,
                        parent_game_id as game_id,
                        parent_game_name_classify as game_classify,
                        source_system,
                        cost,
                        reg_num,
                        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,
                        total_roi,
                        first_roi,
                        first_amount_rate,
                        today_amount_rate,
                        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,
                        reg_cost,
                        first_amount_cost as first_new_user_recharge_cost,
                        total_amount_cost as total_recharge_cost,
                        hundred_user_num,
                        hundred_user_num_cost,
                        first_role_num,
                        role_num,
                        new_user_total_role_num,
                        round(IF(first_role_num > 0, cost / first_role_num, 0), 2) first_role_num_cost,
                        round(IF(role_num > 0, cost / role_num, 0), 2) role_num_cost,
                        round(IF(new_user_total_role_num >0, cost / new_user_total_role_num, 0), 2) new_user_total_role_num_cost,
                        round(IF(reg_num >0, first_role_num / reg_num, 0), 4) first_role_num_rate,
                        round(IF(reg_num >0, role_num / reg_num, 0), 4) role_num_rate,
                        round(IF(reg_num >0, new_user_total_role_num / reg_num, 0), 4) new_user_total_role_num_rate
                    FROM
                        game_ads_parent.ads_game_day_parent
                """ + cri +
                """
                                ) a
                        LEFT JOIN (
                            SELECT
                                parent_game_id,
                                parent_game_name,
                                dt,
                                da1,
                                da2,
                                da3,
                                da4,
                                da5,
                                da6,
                                da7,
                                da8,
                                da9,
                                da10,
                                da11,
                                da12,
                                da13,
                                da14,
                                da15,
                                da16,
                                da17,
                                da18,
                                da19,
                                da20,
                                da21,
                                da22,
                                da23,
                                da24,
                                da25,
                                da26,
                                da27,
                                da28,
                                da29,
                                da30,
                                da31,
                                da32,
                                da33,
                                da34,
                                da35,
                                da36,
                                da37,
                                da38,
                                da39,
                                da40,
                                da41,
                                da42,
                                da43,
                                da44,
                                da45,
                                da46,
                                da47,
                                da48,
                                da49,
                                da50,
                                da51,
                                da52,
                                da53,
                                da54,
                                da55,
                                da56,
                                da57,
                                da58,
                                da59,
                                da60,
                                da61,
                                da62,
                                da63,
                                da64,
                                da65,
                                da66,
                                da67,
                                da68,
                                da69,
                                da70,
                                da71,
                                da72,
                                da73,
                                da74,
                                da75,
                                da76,
                                da77,
                                da78,
                                da79,
                                da80,
                                da81,
                                da82,
                                da83,
                                da84,
                                da85,
                                da86,
                                da87,
                                da88,
                                da89,
                                da90,
                                m4,
                                m5,
                                m6,
                                m7,
                                m8,
                                m9,
                                m10,
                                m11,
                                m12,
                                total
                            FROM
                                game_ads_parent.ads_game_first_new_user_again_day_parent
                        """ + cri +
                """
                            ) b
                        ON a.game_id = b.parent_game_id and a.cost_date = b.dt and a.game_name = b.parent_game_name
                        """;
    }

    /**
     * 游戏首日复充总计sql（首日复充数据部分）
     *
     * @param type 查询的类型 buy、nature、total
     * @return String : 查询出来的结果 第n天的 充值金额/充值人数
     */
    private String firstNewUserAgainSql(String type, String tableName) {
        //修改类型，与数据库字段名相匹配
        if ("buy".equals(type)) {
            type = type + "_";
        } else if ("nature".equals(type)) {
            type = type + "_";
        } else {
            type = "";
        }
        //拼接查询条件
        StringBuilder trendDay = new StringBuilder(StringUtils.EMPTY);
        trendDay.append("SELECT ");
        //30天数据
        for (int day = 1; day <= 90; day++) {
            trendDay.append("""
                    CONCAT( SUM(CAST(SPLIT_PART(%sda%s, '/', 1) AS DECIMAL(10, 2))), '/',
                            SUM(CAST(SPLIT_PART(%sda%s, '/', 2) AS BIGINT)), '/',
                            SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= Local.now(), CAST(SPLIT_PART(%sda1, '/', 2) AS BIGINT), 0))
                    ) AS da%s,
                       """.formatted(type, day, type, day, day - 1, type, day));
        }
        //m2-m11数据
        for (int month = 4; month <= 12; month++) {
            trendDay.append("""
                    CONCAT( SUM(CAST(SPLIT_PART(%sm%s, '/', 1) AS DECIMAL(10, 2))), '/',
                            SUM(CAST(SPLIT_PART(%sm%s, '/', 2) AS BIGINT)), '/',
                            SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= Local.now(), CAST(SPLIT_PART(%sda1, '/', 2) AS BIGINT), 0))
                    ) AS m%s,
                       """.formatted(type, month, type, month, month, type, month));
        }
        //total数据
        trendDay.append("""
                CONCAT( SUM(CAST(SPLIT_PART(%stotal, '/', 1) AS DECIMAL(10, 2))), '/',
                        SUM(CAST(SPLIT_PART(%stotal, '/', 2) AS BIGINT)), '/',
                        SUM(CAST(SPLIT_PART(%sda1, '/', 2) AS BIGINT))
                ) AS total
                   """.formatted(type, type, type));
        trendDay.append("FROM ");
        trendDay.append(tableName);

        return trendDay.toString();
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id
     *
     * @return String
     */
    private String findUsersIdSql(Criteria cri, Criteria groupByCri) {
        return """
                SELECT
                    CONCAT(reg_game_id,'/',DATE(reg_user_time)) as game_id_date,
                    GROUP_CONCAT(CONVERT (player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads.ads_player_recharge_ranking
                """ + cri +
                """
                            and dt = DATE(reg_user_time) 
                        """ + groupByCri;
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id-父游戏维度
     *
     * @return String
     */
    private String findUsersIdSqlForParent(Criteria cri, Criteria groupByCri) {
        return """
                SELECT
                    CONCAT(parent_game_id,'/',DATE(reg_user_time)) as game_id_date,
                    GROUP_CONCAT(CONVERT (parent_player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads_parent.ads_player_recharge_ranking_parent
                """ + cri +
                """
                            and dt = DATE(reg_user_time) 
                        """ + groupByCri;
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id-游戏每日
     *
     * @return String
     */
    private String findUsersIdSqlForGameData(Criteria cri, Criteria groupByCri) {
        return """
                SELECT
                    DATE(reg_user_time) as reg_user_time,
                    GROUP_CONCAT(CONVERT (player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads.ads_player_recharge_ranking
                """ + cri +
                """
                            and dt = DATE(reg_user_time) 
                        """ + groupByCri;
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id-游戏每日-父游戏维度
     *
     * @return String
     */
    private String findUsersIdSqlForParentForGameData(Criteria cri, Criteria groupByCri) {
        return """
                SELECT
                    DATE(reg_user_time) as reg_user_time,
                    GROUP_CONCAT(CONVERT (parent_player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads_parent.ads_player_recharge_ranking_parent
                """ + cri +
                """
                            and dt = DATE(reg_user_time) 
                        """ + groupByCri;
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id(总计)
     *
     * @return String
     */
    private String findUsersIdTotalSql(Criteria cri) {
        return """
                SELECT
                    GROUP_CONCAT(CONVERT (player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads.ads_player_recharge_ranking
                """ + cri +
                """
                            AND dt = DATE(reg_user_time)
                        """;
    }

    /**
     * 找出每个游戏注册时间内的注册当天且充值的用户id(总计一栏)-父游戏维度
     *
     * @return String
     */
    private String findUsersIdTotalSqlForParent(Criteria cri) {
        return """
                SELECT
                    GROUP_CONCAT(CONVERT (parent_player_id, varchar) SEPARATOR "/") as amount_users_id
                FROM
                    game_ads_parent.ads_player_recharge_ranking_parent
                """ + cri +
                """
                            AND dt = DATE(reg_user_time)
                        """;
    }

    private List<H5NatureUserVO> getH5NatureUserVOList(GameDataH5DTO dto, Map<String, Object> importDayNMap, GameDataH5VO item) {
        Sql natureGameSql = Sqls.queryEntity("""
                select
                nature_source_system,
                nature_game_id,
                max(nature_game_name) as nature_game_name,
                max(nature_classify) as nature_classify,
                sum(h5_lead_nature_new_user_total_amount) as h5_lead_nature_new_user_total_amount,
                sum(h5_lead_nature_new_user_total_amount_num) as h5_lead_nature_new_user_total_amount_num
                from ads_h5_game_day
                where
                game_id = @gameId
                and
                dt>=@beginDay and dt<=@endDay
                group by nature_source_system,nature_game_id
                """);
        natureGameSql.setParam("gameId", item.getGameId());
        natureGameSql.setParam("beginDay", dto.getCostBeginDate());
        natureGameSql.setParam("endDay", dto.getCostEndDate());
        Entity<H5NatureUserVO> natureGameEntity = dao.getEntity(H5NatureUserVO.class);
        natureGameSql.setEntity(natureGameEntity);
        dao.execute(natureGameSql);

        Sql natureShowGameSql = Sqls.queryEntity("""
                select
                a.nature_source_system,
                a.nature_game_id,
                sum(a.h5_lead_nature_amount) as h5_lead_nature_amount,
                (select count(distinct user_id) from ads_information
                where
                source_system = a.nature_source_system
                and game_id = a.nature_game_id
                and order_h5_game_id = @gameId
                and agent_id = 0
                and classify != 5
                and order_game_classify = 5
                and order_time >= @beginDay
                and order_time <= @endDay) as h5_lead_nature_amount_num
                from ads_h5_game_day a
                where
                a.game_id = @gameId
                and
                a.dt>=@beginDay and a.dt<=@endDay
                group by a.nature_source_system,a.nature_game_id
                """);
        natureShowGameSql.setParam("gameId", item.getGameId());
        natureShowGameSql.setParam("beginDay", dto.getRechargeBeginDate());
        natureShowGameSql.setParam("endDay", dto.getRechargeEndDate());
        Entity<H5NatureUserVO> buyShowGameEntity = dao.getEntity(H5NatureUserVO.class);
        natureShowGameSql.setEntity(buyShowGameEntity);
        dao.execute(natureShowGameSql);
        Map<Long, List<H5NatureUserVO>> showBuyGameMap = natureShowGameSql.getList(H5NatureUserVO.class).stream()
                .filter(tt -> null != tt.getNatureGameId())
                .collect(Collectors.groupingBy(H5NatureUserVO::getNatureGameId));

        Map<String, Object> natureNewUserMap = new HashMap<>(7);
        natureNewUserMap.put("h5GameId", item.getGameId());
        natureNewUserMap.put("rechargeBeginDay", dto.getRechargeBeginDate());
        natureNewUserMap.put("rechargeEndDay", dto.getRechargeEndDate());
        natureNewUserMap.put("costBeginDay", dto.getCostBeginDate());
        natureNewUserMap.put("costEndDay", dto.getCostEndDate());
        List<H5NatureUserVO> natureGameList = natureGameSql.getList(H5NatureUserVO.class).stream()
                .filter(tt -> null != tt.getNatureGameId())
                .map(natureGame -> {
                    natureNewUserMap.put("natureSourceSystem", natureGame.getNatureSourceSystem());
                    natureNewUserMap.put("natureGameId", natureGame.getNatureGameId());

                    importDayNMap.put("sourceSystem", natureGame.getNatureSourceSystem());
                    importDayNMap.put("gameId", natureGame.getNatureGameId());
                    H5DayN importNatureH5DayN = getImportNatureH5DayN(dto, importDayNMap, natureNewUserMap);
                    if (null != showBuyGameMap && null != showBuyGameMap.get(natureGame.getNatureGameId()) && !showBuyGameMap.get(natureGame.getNatureGameId()).isEmpty()) {
                        natureGame.setH5LeadNatureAmount(showBuyGameMap.get(natureGame.getNatureGameId()).get(0).getH5LeadNatureAmount());
                        natureGame.setH5LeadNatureAmountNum(showBuyGameMap.get(natureGame.getNatureGameId()).get(0).getH5LeadNatureAmountNum());
                    } else {
                        natureGame.setH5LeadNatureAmount(BigDecimal.ZERO);
                        natureGame.setH5LeadNatureAmountNum(0L);
                    }
                    //充值时间范围内存在官方导量充值数据
                    if (null != importNatureH5DayN) {
                        natureGame.setNewUserRechargeMoney(importNatureH5DayN.getRechargeMoney());
                        natureGame.setNewUserRechargeNum(importNatureH5DayN.getRechargeNum());
                    } else {
                        natureGame.setNewUserRechargeMoney(BigDecimal.ZERO);
                        natureGame.setNewUserRechargeNum(0L);
                    }
                    return natureGame;
                }).collect(Collectors.toList());
        return natureGameList;
    }

    private List<H5BuyUserVO> getH5BuyUserVOList(GameDataH5DTO dto, Map<String, Object> importDayNMap, GameDataH5VO item) {
        //买量导入游戏
        Sql buyGameSql = Sqls.queryEntity("""
                select
                buy_source_system,
                buy_game_id,
                max(buy_game_name) as buy_game_name,
                max(buy_classify) as buy_classify,
                sum(h5_lead_buy_new_user_total_amount) as h5_lead_buy_new_user_total_amount,
                sum(h5_lead_buy_new_user_total_amount_num) as h5_lead_buy_new_user_total_amount_num
                from ads_h5_game_day
                where
                game_id = @gameId
                and
                dt>=@beginDay and dt<=@endDay
                group by buy_source_system,buy_game_id
                """);
        buyGameSql.setParam("gameId", item.getGameId());
        buyGameSql.setParam("beginDay", dto.getCostBeginDate());
        buyGameSql.setParam("endDay", dto.getCostEndDate());
        Entity<H5BuyUserVO> buyGameEntity = dao.getEntity(H5BuyUserVO.class);
        buyGameSql.setEntity(buyGameEntity);
        dao.execute(buyGameSql);

        //买量导入游戏账面
        Sql buyShowGameSql = Sqls.queryEntity("""
                select
                a.buy_source_system as buy_source_system,
                a.buy_game_id as buy_game_id,
                sum(a.h5_lead_buy_amount) as h5_lead_buy_amount,
                (select count(distinct user_id) from ads_information
                where
                source_system = a.buy_source_system
                and game_id = a.buy_game_id
                and order_h5_game_id = @gameId
                and agent_id != 0
                and classify != 5
                and order_game_classify = 5
                and order_time >= @beginDay
                and order_time <= @endDay) as h5_lead_buy_amount_num
                from ads_h5_game_day a
                where
                a.game_id = @gameId
                and
                a.dt>=@beginDay and a.dt<=@endDay
                group by a.buy_source_system,a.buy_game_id
                """);
        buyShowGameSql.setParam("gameId", item.getGameId());
        buyShowGameSql.setParam("beginDay", dto.getRechargeBeginDate());
        buyShowGameSql.setParam("endDay", dto.getRechargeEndDate());
        Entity<H5BuyUserVO> buyShowGameEntity = dao.getEntity(H5BuyUserVO.class);
        buyShowGameSql.setEntity(buyShowGameEntity);
        dao.execute(buyShowGameSql);
        Map<Long, List<H5BuyUserVO>> showBuyGameMap = buyShowGameSql.getList(H5BuyUserVO.class).stream()
                .filter(tt -> null != tt.getBuyGameId())
                .collect(Collectors.groupingBy(H5BuyUserVO::getBuyGameId));

        Map<String, Object> buyNewUserMap = new HashMap<>(7);
        buyNewUserMap.put("h5GameId", item.getGameId());
        buyNewUserMap.put("rechargeBeginDay", dto.getRechargeBeginDate());
        buyNewUserMap.put("rechargeEndDay", dto.getRechargeEndDate());
        buyNewUserMap.put("costBeginDay", dto.getCostBeginDate());
        buyNewUserMap.put("costEndDay", dto.getCostEndDate());
        List<H5BuyUserVO> buyGameList = buyGameSql.getList(H5BuyUserVO.class).stream()
                .filter(tt -> null != tt.getBuyGameId())
                .map(buyGame -> {
                    importDayNMap.put("sourceSystem", buyGame.getBuySourceSystem());
                    importDayNMap.put("gameId", buyGame.getBuyGameId());

                    buyNewUserMap.put("buySourceSystem", buyGame.getBuySourceSystem());
                    buyNewUserMap.put("buyGameId", buyGame.getBuyGameId());
                    H5DayN importBuyH5DayN = getImportBuyH5DayN(dto, importDayNMap, buyNewUserMap);
                    if (null != showBuyGameMap && null != showBuyGameMap.get(buyGame.getBuyGameId()) && !showBuyGameMap.get(buyGame.getBuyGameId()).isEmpty()) {
                        buyGame.setH5LeadBuyAmount(showBuyGameMap.get(buyGame.getBuyGameId()).get(0).getH5LeadBuyAmount());
                        buyGame.setH5LeadBuyAmountNum(showBuyGameMap.get(buyGame.getBuyGameId()).get(0).getH5LeadBuyAmountNum());
                    } else {
                        buyGame.setH5LeadBuyAmount(BigDecimal.ZERO);
                        buyGame.setH5LeadBuyAmountNum(0L);
                    }
                    //买量导入游戏充值时间范围内存在新用户充值数据
                    if (null != importBuyH5DayN) {
                        buyGame.setNewUserRechargeMoney(importBuyH5DayN.getRechargeMoney());
                        buyGame.setNewUserRechargeNum(importBuyH5DayN.getRechargeNum());
                    } else {
                        buyGame.setNewUserRechargeMoney(BigDecimal.ZERO);
                        buyGame.setNewUserRechargeNum(0L);
                    }
                    return buyGame;
                }).collect(Collectors.toList());
        return buyGameList;
    }

    private H5DayN getImportNatureH5DayN(GameDataH5DTO dto, Map<String, Object> dayNMap, Map<String, Object> natureNewUserMap) {
        Sql importNatureSqlDayN = Sqls.queryString("""
                select day_n as dayN from ads_dayn_h5_lead_nature_game
                where
                dt>=@beginDay and dt<=@endDay
                and source_system = @sourceSystem
                and h5_lead_nature_game_id = @gameId
                """);
        importNatureSqlDayN.setParams(dayNMap);
        dao.execute(importNatureSqlDayN);
        List<String> importNatureDayNList = importNatureSqlDayN.getList(String.class);

        Sql newUserNum = Sqls.fetchLong("""
                select
                	count(DISTINCT user_id)
                from
                	ads_information
                where
                source_system = @natureSourceSystem
                and game_id = @natureGameId
                and order_h5_game_id = @h5GameId
                and agent_id = 0
                and classify != 5
                and order_game_classify = 5
                and order_time >= @rechargeBeginDay
                and order_time <= @rechargeEndDay
                and reg_time >= @costBeginDay
                and reg_time <= @costEndDay
                """);
        newUserNum.setParams(natureNewUserMap);
        dao.execute(newUserNum);
        Long newUserNumLong = newUserNum.getLong();

        H5DayN importNatureDayN = null;
        //ads_dayn_h5_nature_game 存在充值数据
        if (!CollectionUtils.isEmpty(importNatureDayNList)) {
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(importNatureDayNList.toString(), ArrayList.class);

            Map<String, String> resultMap = new HashMap<>();
            resultMap.put("dayN", "0.00-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.getRechargeBeginDate()) >= 0
                            && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                        String[] existingParts = resultMap.get("dayN").split("-");
                        BigDecimal money = new BigDecimal(existingParts[0]).add(new BigDecimal(parts[0]));
                        int num = Integer.parseInt(existingParts[1]) + Integer.parseInt(parts[1]);
                        String newValue = money + "-" + num;
                        resultMap.put("dayN", newValue);
                    }
                }
            }
            if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
                String[] parts = resultMap.get("dayN").split("-");
                importNatureDayN = H5DayN.builder()
                        .rechargeMoney(new BigDecimal(parts[0]))
                        .rechargeNum(newUserNumLong)
                        .build();
            }
        }
        return importNatureDayN;
    }

    private H5DayN getImportBuyH5DayN(GameDataH5DTO dto, Map<String, Object> dayNMap, Map<String, Object> buyNewUserMap) {
        Sql importBuySqlDayN = Sqls.queryString("""
                select day_n as dayN from ads_dayn_h5_lead_buy_game
                where
                dt>=@beginDay and dt<=@endDay
                and source_system = @sourceSystem
                and h5_lead_buy_game_id = @gameId
                """);
        importBuySqlDayN.setParams(dayNMap);
        dao.execute(importBuySqlDayN);
        List<String> importBuyDayNList = importBuySqlDayN.getList(String.class);

        Sql newUserNum = Sqls.fetchLong("""
                select
                	count(DISTINCT user_id)
                from
                	ads_information
                where
                source_system = @buySourceSystem
                and game_id = @buyGameId
                and order_h5_game_id = @h5GameId
                and agent_id != 0
                and classify != 5
                and order_game_classify = 5
                and order_time >= @rechargeBeginDay
                and order_time <= @rechargeEndDay
                and reg_time >= @costBeginDay
                and reg_time <= @costEndDay
                """);
        newUserNum.setParams(buyNewUserMap);
        dao.execute(newUserNum);
        Long newUserNumLong = newUserNum.getLong();

        H5DayN importBuyDayN = null;
        //ads_dayn_h5_nature_game 存在充值数据
        if (!CollectionUtils.isEmpty(importBuyDayNList)) {
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(importBuyDayNList.toString(), ArrayList.class);

            Map<String, String> resultMap = new HashMap<>();
            resultMap.put("dayN", "0.00-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.getRechargeBeginDate()) >= 0
                            && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                        String[] existingParts = resultMap.get("dayN").split("-");
                        BigDecimal money = new BigDecimal(existingParts[0]).add(new BigDecimal(parts[0]));
                        int num = Integer.parseInt(existingParts[1]) + Integer.parseInt(parts[1]);
                        String newValue = money + "-" + num;
                        resultMap.put("dayN", newValue);
                    }
                }
            }
            if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
                String[] parts = resultMap.get("dayN").split("-");
                importBuyDayN = H5DayN.builder()
                        .rechargeMoney(new BigDecimal(parts[0]))
                        .rechargeNum(newUserNumLong)
                        .build();
            }
        }
        return importBuyDayN;
    }

    private H5DayN getNatureH5DayN(GameDataH5DTO dto, Map<String, Object> dayNMap) {
        Sql natureSqlDayN = Sqls.queryString("""
                select day_n as dayN from ads_dayn_h5_nature_game
                where
                dt>=@beginDay and dt<=@endDay
                and source_system = @sourceSystem
                and h5_nature_game_id = @h5GameId
                """);
        natureSqlDayN.setParams(dayNMap);
        dao.execute(natureSqlDayN);
        List<String> natureDayNList = natureSqlDayN.getList(String.class);

        Sql newUserNum = Sqls.fetchLong("""
                select
                	count(DISTINCT user_id)
                from
                	ads_information
                where
                    source_system = @sourceSystem
                    and h5_game_id = @h5GameId
                    and agent_id = 0
                    and classify = 5
                    and order_time >= @rechargeBeginDay
                    and order_time <= @rechargeEndDay
                    and reg_time >= @costBeginDay
                    and reg_time <= @costEndDay
                """);
        Map<String, Object> newUserNumMap = new HashMap<>(6);
        newUserNumMap.put("costBeginDay", dto.getCostBeginDate());
        newUserNumMap.put("costEndDay", dto.getCostEndDate());
        newUserNumMap.put("rechargeBeginDay", dto.getRechargeBeginDate());
        newUserNumMap.put("rechargeEndDay", dto.getRechargeEndDate());

        H5DayN h5NatureDayN = null;
        //ads_dayn_h5_nature_game 存在充值数据
        if (!CollectionUtils.isEmpty(natureDayNList)) {
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(natureDayNList.toString(), ArrayList.class);

            Map<String, String> resultMap = new HashMap<>();
            resultMap.put("dayN", "0.00-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.getRechargeBeginDate()) >= 0
                            && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                        String[] existingParts = resultMap.get("dayN").split("-");
                        BigDecimal money = new BigDecimal(existingParts[0]).add(new BigDecimal(parts[0]));
                        int num = Integer.parseInt(existingParts[1]) + Integer.parseInt(parts[1]);
                        String newValue = money + "-" + num;
                        resultMap.put("dayN", newValue);
                    }
                }
            }
            newUserNumMap.put("sourceSystem", dayNMap.get("sourceSystem"));
            newUserNumMap.put("h5GameId", dayNMap.get("h5GameId"));
            newUserNum.setParams(newUserNumMap);
            dao.execute(newUserNum);
            Long newUserNumLong = newUserNum.getLong();
            if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
                String[] parts = resultMap.get("dayN").split("-");
                h5NatureDayN = H5DayN.builder()
                        .rechargeMoney(new BigDecimal(parts[0]))
                        .rechargeNum(newUserNumLong)
                        .build();
            }
        }
        return h5NatureDayN;
    }

    private H5DayN getH5PayDayN(GameDataH5DTO dto, Map<String, Object> dayNMap) {
        H5DayN h5PayDayN = null;
        Sql paySqlDayN = Sqls.queryString("""
                select day_n as dayN from ads_dayn_h5_pay_game
                where
                dt>=@beginDay and dt<=@endDay
                and source_system = @sourceSystem
                and h5_game_id = @h5GameId
                """);
        paySqlDayN.setParams(dayNMap);
        dao.execute(paySqlDayN);
        List<String> payDayNList = paySqlDayN.getList(String.class);

        Sql newUserNum = Sqls.fetchLong("""
                select
                	count(DISTINCT user_id)
                from
                	ads_information
                where
                    source_system = @sourceSystem
                    and h5_game_id = @h5GameId
                    and agent_id != 0
                    and classify = 5
                    and order_time >= @rechargeBeginDay
                    and order_time <= @rechargeEndDay
                    and reg_time >= @costBeginDay
                    and reg_time <= @costEndDay
                """);
        Map<String, Object> newUserNumMap = new HashMap<>(6);
        newUserNumMap.put("costBeginDay", dto.getCostBeginDate());
        newUserNumMap.put("costEndDay", dto.getCostEndDate());
        newUserNumMap.put("rechargeBeginDay", dto.getRechargeBeginDate());
        newUserNumMap.put("rechargeEndDay", dto.getRechargeEndDate());
        //ads_dayn_h5_pay_game存在充值数据
        if (!CollectionUtils.isEmpty(payDayNList)) {
            Gson gson = new Gson();
            List<Map<String, String>> jsonList = gson.fromJson(payDayNList.toString(), ArrayList.class);

            Map<String, String> resultMap = new HashMap<>();
            resultMap.put("dayN", "0.00-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.getRechargeBeginDate()) >= 0
                            && DateUtil.parseLocalDate(key).compareTo(dto.getRechargeEndDate()) <= 0) {
                        String[] existingParts = resultMap.get("dayN").split("-");
                        BigDecimal money = new BigDecimal(existingParts[0]).add(new BigDecimal(parts[0]));
                        int num = Integer.parseInt(existingParts[1]) + Integer.parseInt(parts[1]);
                        String newValue = money + "-" + num;
                        resultMap.put("dayN", newValue);
                    }
                }
            }
            newUserNumMap.put("sourceSystem", dayNMap.get("sourceSystem"));
            newUserNumMap.put("h5GameId", dayNMap.get("h5GameId"));
            newUserNum.setParams(newUserNumMap);
            dao.execute(newUserNum);
            Long newUserNumLong = newUserNum.getLong();
            if (!resultMap.isEmpty() && !resultMap.get("dayN").isEmpty()) {
                String[] parts = resultMap.get("dayN").split("-");
                h5PayDayN = H5DayN.builder()
                        .rechargeMoney(new BigDecimal(parts[0]))
                        .rechargeNum(newUserNumLong)
                        .build();
            }
        }
        return h5PayDayN;
    }

    private String h5RechargeSql() {
        return """
                select
                a.game_id as id,
                a.game_id as game_id,
                max(a.game_name) as game_name,
                max(a.source_system) as source_system,
                sum(a.h5_buy_new_user_total_amount) as h5_buy_new_user_total_amount,
                sum(a.h5_buy_new_user_total_amount_num) as h5_buy_new_user_total_amount_num,
                round(if(sum(a.h5_buy_new_user_total_amount) > 0, sum(a.h5_nature_new_user_total_amount) / sum(a.h5_buy_new_user_total_amount), 0), 4) as h5_nature_new_user_total_amount_rate,
                sum(a.h5_nature_new_user_total_amount) as h5_nature_new_user_total_amount,
                sum(a.h5_nature_new_user_total_amount_num) as h5_nature_new_user_total_amount_num
                from ads_h5_game_day a
                """;
    }

    /**
     * 子游戏维度
     */
    private String waterSql() {
        return """
                select
                game_id as id,
                source_system,
                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 waterSqlForParent() {
        return """
                select
                parent_game_id as id,
                source_system,
                parent_game_id as game_id,
                max(parent_game_name) as game_name,
                max(parent_game_classify) as game_classify,
                max(amount) as amount,
                max(buy_amount) as buy_amount,
                max(nature_amount) as nature_amount
                from game_ads_parent.ads_everyday_water_parent
                """;
    }

    /**
     * 流水临时sql
     *
     * @return String
     */
    private String waterTemplateSql() {
        return """
                select
                game_id,
                user_order_by,
                user_id,
                user_name,
                user_amount,
                amount_order_by,
                amount_post,
                amount_count,
                role_name,
                server_name,
                amount_num
                from ads_everyday_water
                """;
    }

    /**
     * 流水临时sql-父游戏维度
     *
     * @return String
     */
    private String waterTemplateSqlForParent() {
        return """
                select
                parent_game_id as game_id,
                user_order_by,
                user_id,
                user_name,
                user_amount,
                amount_order_by,
                amount_post,
                amount_count,
                role_name,
                server_name,
                amount_num
                from game_ads_parent.ads_everyday_water_parent
                """;
    }

    /**
     * 用户详情sql-子游戏维度
     */
    private String userDetailSql() {
        return """
                SELECT
                    player_id,
                    reg_agent_id,
                    reg_agent_name,
                    server_name,
                    role_name,
                    $amount as today_total_amount,
                    player_os,
                    total_amount_count,
                    ROW_NUMBER() over(order by today_total_amount desc, total_amount_count desc, player_id desc) as num
                FROM
                    game_ads.ads_player_recharge_ranking
                WHERE player_id IN (@usersId)
                and dt = DATE_ADD(DATE(reg_user_time),
                """;
    }

    /**
     * 用户详情sql-子游戏维度
     */
    private String userDetailSqlForParent() {
        return """
                SELECT
                    parent_player_id as player_id,
                    reg_agent_id,
                    reg_agent_name,
                    server_name,
                    role_name,
                    $amount as today_total_amount,
                    player_os,
                    total_amount_count,
                    ROW_NUMBER() over(order by today_total_amount desc, total_amount_count desc, parent_player_id desc) as num
                FROM
                    game_ads_parent.ads_player_recharge_ranking_parent
                WHERE parent_player_id IN (@usersId)
                and dt = DATE_ADD(DATE(reg_user_time),
                """;
    }

    /**
     * DayN内部类
     */
    @Data
    @Builder
    public static class DayN {
        /**
         * 充值金额
         */
        private BigDecimal rechargeMoney;

        /**
         * 充值次数
         */
        private Long rechargeCount;

        /**
         * 新用户充值金额（支付宝金额）
         */
        
        private BigDecimal alipayAmount;
        /**
         * 新用户充值金额（微信金额）
         */
        
        private BigDecimal wxAmount;
        /**
         * 新用户充值金额（米大师金额）
         */
        
        private BigDecimal miMasterAmount;


        /**
         * 充值人数
         */
        private Long rechargeNum;

        /**
         * 新用户复充人数
         */
        private Long rechargeAgainNum;
    }


    @Data
    @Builder
    public static class H5DayN {
        private BigDecimal rechargeMoney;
        private Long rechargeNum;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class ShowRecharge {
        private BigDecimal h5NatureAmount;

        private Long h5NatureAmountNum;

        private BigDecimal h5BuyAmount;

        private Long h5BuyAmountNum;
    }

    /**
     * 用来确定每天有多少超父游戏的内部类
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class superGameNameForDt {
        private LocalDate dt;

        private String superGameName;
    }

}
