|  | @@ -43,13 +43,103 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private Dao dao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 广告监控每日数据列表
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param dto
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public Page<PromotionDayVO> getPromotionDayListData(PromotionDayDTO dto) {
 | 
	
		
			
				|  |  | +        //不传递查询条件默认查询当天数据
 | 
	
		
			
				|  |  | +        if (dto.getCostBeginDate() == null || dto.getCostEndDate() == null) {
 | 
	
		
			
				|  |  | +            dto.setCostBeginDate(LocalDate.now());
 | 
	
		
			
				|  |  | +            dto.setCostEndDate(LocalDate.now());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //如果没有排序条件给默认值
 | 
	
		
			
				|  |  | +        if (StringUtils.isBlank(dto.getSortFiled())) {
 | 
	
		
			
				|  |  | +            dto.setSortFiled("dt");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (StringUtils.isBlank(dto.getSortType())) {
 | 
	
		
			
				|  |  | +            dto.setSortType(OrderByEnum.DESC.getOrderType());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Criteria cri = myCri(dto, false);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //计算总记录条数
 | 
	
		
			
				|  |  | +        Sql sqlCount = Sqls.create("select count(*) from ads_promotion_day" + cri);
 | 
	
		
			
				|  |  | +        sqlCount.setCallback(Sqls.callback.integer());
 | 
	
		
			
				|  |  | +        //执行sql
 | 
	
		
			
				|  |  | +        dao.execute(sqlCount);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //拼接排序条件
 | 
	
		
			
				|  |  | +        cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
 | 
	
		
			
				|  |  | +        //创建sql语句
 | 
	
		
			
				|  |  | +        Sql sql = Sqls.create(getPromotionDayListSql() + cri);
 | 
	
		
			
				|  |  | +        //添加自定义回传对象
 | 
	
		
			
				|  |  | +        sql.setCallback(Sqls.callback.entities());
 | 
	
		
			
				|  |  | +        sql.setEntity(dao.getEntity(PromotionDayVO.class));
 | 
	
		
			
				|  |  | +        //设置pager对象
 | 
	
		
			
				|  |  | +        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
 | 
	
		
			
				|  |  | +        sql.setPager(pager);
 | 
	
		
			
				|  |  | +        //执行sql
 | 
	
		
			
				|  |  | +        dao.execute(sql);
 | 
	
		
			
				|  |  | +        //获取到结果list
 | 
	
		
			
				|  |  | +        List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
 | 
	
		
			
				|  |  | +        //分页对象设置总记录条数
 | 
	
		
			
				|  |  | +        pager.setRecordCount(sqlCount.getInt());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //处理List中的每个vo对象缺少的数据
 | 
	
		
			
				|  |  | +        list.stream().map(vo -> {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //计算d2(次日)数据
 | 
	
		
			
				|  |  | +            vo.setD2Trend(PromotionRechargeTrendVO.builder()
 | 
	
		
			
				|  |  | +                    .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD2().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .rechargeMoney(vo.getD2())
 | 
	
		
			
				|  |  | +                    .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD2().divide(vo.getD1(), 2, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .build());
 | 
	
		
			
				|  |  | +            //计算d3数据
 | 
	
		
			
				|  |  | +            vo.setD3Trend(PromotionRechargeTrendVO.builder()
 | 
	
		
			
				|  |  | +                    .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD3().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .rechargeMoney(vo.getD3())
 | 
	
		
			
				|  |  | +                    .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD3().divide(vo.getD1(), 2, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .build());
 | 
	
		
			
				|  |  | +            //计算d7数据
 | 
	
		
			
				|  |  | +            vo.setD7Trend(PromotionRechargeTrendVO.builder()
 | 
	
		
			
				|  |  | +                    .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD7().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .rechargeMoney(vo.getD7())
 | 
	
		
			
				|  |  | +                    .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD7().divide(vo.getD1(), 2, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .build());
 | 
	
		
			
				|  |  | +            //计算d15数据
 | 
	
		
			
				|  |  | +            vo.setD15Trend(PromotionRechargeTrendVO.builder()
 | 
	
		
			
				|  |  | +                    .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD15().divide(vo.getTodayCost(), 4, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .rechargeMoney(vo.getD15())
 | 
	
		
			
				|  |  | +                    .multiples(vo.getD1().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            vo.getD15().divide(vo.getD1(), 2, RoundingMode.HALF_UP))
 | 
	
		
			
				|  |  | +                    .build());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //返回最终数据
 | 
	
		
			
				|  |  | +            return vo;
 | 
	
		
			
				|  |  | +        }).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //返回查询得结果
 | 
	
		
			
				|  |  | +        return new Page<>(list, pager);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 广告监控数据
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  |       * @param dto
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Page<PromotionDayVO> getPromotionDayData(PromotionDayDTO dto) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //不传递查询条件默认查询当天数据
 | 
	
		
			
				|  |  |          if (dto.getCostBeginDate() == null || dto.getCostEndDate() == null) {
 | 
	
		
			
				|  |  |              dto.setCostBeginDate(LocalDate.now());
 | 
	
	
		
			
				|  | @@ -62,9 +152,13 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |          if (StringUtils.isBlank(dto.getSortType())) {
 | 
	
		
			
				|  |  |              dto.setSortType(OrderByEnum.DESC.getOrderType());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        Criteria cri = myCri(dto);
 | 
	
		
			
				|  |  | +        Criteria criA = myCri(dto, true);
 | 
	
		
			
				|  |  | +        Criteria criB = myCri(dto, false);
 | 
	
		
			
				|  |  | +        Criteria criOrderBy = Cnd.cri();
 | 
	
		
			
				|  |  | +        //拼接排序条件
 | 
	
		
			
				|  |  | +        criOrderBy.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
 | 
	
		
			
				|  |  |          //创建sql语句
 | 
	
		
			
				|  |  | -        Sql sql = Sqls.create(getPromotionDayDataSql() + cri);
 | 
	
		
			
				|  |  | +        Sql sql = Sqls.create(getPromotionDayDataSql(criA,criB) + criOrderBy);
 | 
	
		
			
				|  |  |          //添加自定义回传对象
 | 
	
		
			
				|  |  |          sql.setCallback(Sqls.callback.entities());
 | 
	
		
			
				|  |  |          sql.setEntity(dao.getEntity(PromotionDayVO.class));
 | 
	
	
		
			
				|  | @@ -76,37 +170,11 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |          //获取到结果list
 | 
	
		
			
				|  |  |          List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
 | 
	
		
			
				|  |  |          //分页对象设置总条数
 | 
	
		
			
				|  |  | -        Sql sqlCount = Sqls.queryEntity("select count(*) from ads_promotion_day" + cri);
 | 
	
		
			
				|  |  | +        Sql sqlCount = Sqls.queryEntity("select count(*) from ads_promotion_day" + criA);
 | 
	
		
			
				|  |  |          pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //处理List中的每个vo对象缺少的数据
 | 
	
		
			
				|  |  |          list.stream().map(vo -> {
 | 
	
		
			
				|  |  | -            //记录最近有数据的LocalDate
 | 
	
		
			
				|  |  | -            LocalDate latestDate = dto.getCostEndDate();
 | 
	
		
			
				|  |  | -            Boolean hasDataDate = findDate(vo.getPromotionId(), latestDate);
 | 
	
		
			
				|  |  | -            while (!hasDataDate) {
 | 
	
		
			
				|  |  | -                latestDate = latestDate.minusDays(1);
 | 
	
		
			
				|  |  | -                hasDataDate = findDate(vo.getPromotionId(), latestDate);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            //构建查询条件
 | 
	
		
			
				|  |  | -            Criteria totalCri = Cnd.cri();
 | 
	
		
			
				|  |  | -            totalCri.where().andEquals("dt", latestDate);
 | 
	
		
			
				|  |  | -            totalCri.where().andEquals("promotion_id", vo.getPromotionId());
 | 
	
		
			
				|  |  | -            //查询出最近一条包含总数据的记录
 | 
	
		
			
				|  |  | -            Sql totalDataSql = Sqls.create(getTotalDataSql() + totalCri);
 | 
	
		
			
				|  |  | -            //设置回传对象
 | 
	
		
			
				|  |  | -            totalDataSql.setCallback(Sqls.callback.entity());
 | 
	
		
			
				|  |  | -            totalDataSql.setEntity(dao.getEntity(PromotionDayVO.class));
 | 
	
		
			
				|  |  | -            //执行sql
 | 
	
		
			
				|  |  | -            dao.execute(totalDataSql);
 | 
	
		
			
				|  |  | -            //得到对象
 | 
	
		
			
				|  |  | -            PromotionDayVO tempVO = totalDataSql.getObject(PromotionDayVO.class);
 | 
	
		
			
				|  |  | -            //将两个对象内容合并
 | 
	
		
			
				|  |  | -            copyNullProperties(tempVO, vo);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            //总充值次数成本
 | 
	
		
			
				|  |  | -            vo.setTotalAmountCountCost(vo.getTotalAmountCount() == 0L ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | -                    vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getTotalAmountCount()), 2, RoundingMode.HALF_UP));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              //计算d2(次日)数据
 | 
	
		
			
				|  |  |              vo.setD2Trend(PromotionRechargeTrendVO.builder()
 | 
	
	
		
			
				|  | @@ -339,10 +407,11 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 广告监控用到的查询条件
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  | -     * @param dto 前端传递的查询条件
 | 
	
		
			
				|  |  | +     * @param dto         前端传递的查询条件
 | 
	
		
			
				|  |  | +     * @param needGroupBy 需要聚合分组
 | 
	
		
			
				|  |  |       * @return 查询条件
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private Criteria myCri(PromotionDayDTO dto) {
 | 
	
		
			
				|  |  | +    private Criteria myCri(PromotionDayDTO dto, Boolean needGroupBy) {
 | 
	
		
			
				|  |  |          //创建查询条件
 | 
	
		
			
				|  |  |          Criteria cri = Cnd.cri();
 | 
	
		
			
				|  |  |          if (dto.getAccountId() != null) {
 | 
	
	
		
			
				|  | @@ -393,42 +462,14 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |          if (StringUtils.isNotBlank(dto.getSourceSystem())) {
 | 
	
		
			
				|  |  |              cri.where().andEquals("source_system", dto.getSourceSystem());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //拼接分组条件
 | 
	
		
			
				|  |  | -        cri.getGroupBy().groupBy("promotion_id");
 | 
	
		
			
				|  |  | -        //拼接排序条件
 | 
	
		
			
				|  |  | -        cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
 | 
	
		
			
				|  |  | +        if (needGroupBy) {
 | 
	
		
			
				|  |  | +            //拼接分组条件
 | 
	
		
			
				|  |  | +            cri.getGroupBy().groupBy("promotion_id");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return cri;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 用来判断当前日期有没有数据
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  | -     * @param promotionId 查询的广告id
 | 
	
		
			
				|  |  | -     * @param latestDate  时间参数
 | 
	
		
			
				|  |  | -     * @return Boolean
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private Boolean findDate(String promotionId, LocalDate latestDate) {
 | 
	
		
			
				|  |  | -        //创建查询条件
 | 
	
		
			
				|  |  | -        Criteria cri = Cnd.cri();
 | 
	
		
			
				|  |  | -        cri.where().andEquals("promotion_id", Long.valueOf(promotionId));
 | 
	
		
			
				|  |  | -        cri.where().andEquals("dt", latestDate);
 | 
	
		
			
				|  |  | -        Sql sql = Sqls.create("""
 | 
	
		
			
				|  |  | -                SELECT
 | 
	
		
			
				|  |  | -                    promotion_id
 | 
	
		
			
				|  |  | -                FROM
 | 
	
		
			
				|  |  | -                    game_ads.ads_promotion_day
 | 
	
		
			
				|  |  | -                """ + cri);
 | 
	
		
			
				|  |  | -        sql.setCallback(Sqls.callback.str());
 | 
	
		
			
				|  |  | -        dao.execute(sql);
 | 
	
		
			
				|  |  | -        String tempStr = sql.getString();
 | 
	
		
			
				|  |  | -        //查询结果判断
 | 
	
		
			
				|  |  | -        if (tempStr != null) {
 | 
	
		
			
				|  |  | -            return true;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return false;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 所有为空值的属性都不copy
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -464,115 +505,14 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | -     * 查询广告监控数据sql
 | 
	
		
			
				|  |  | +     * 广告监控每日数据sql
 | 
	
		
			
				|  |  |       *
 | 
	
		
			
				|  |  |       * @return String
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private String getPromotionDayDataSql() {
 | 
	
		
			
				|  |  | -        return """
 | 
	
		
			
				|  |  | -                SELECT
 | 
	
		
			
				|  |  | -                	promotion_id,
 | 
	
		
			
				|  |  | -                	MAX(promotion_name) as promotion_name,
 | 
	
		
			
				|  |  | -                	MAX(project_id) as project_id,
 | 
	
		
			
				|  |  | -                	MAX(project_name) as project_name,
 | 
	
		
			
				|  |  | -                	MAX(account_name) as account_name,
 | 
	
		
			
				|  |  | -                	MAX(account_id) as account_id,
 | 
	
		
			
				|  |  | -                	MAX(account_type) as account_type,
 | 
	
		
			
				|  |  | -                	MAX(pitcher_id) as pitcher_id,
 | 
	
		
			
				|  |  | -                	MAX(pitcher_name) as pitcher_name,
 | 
	
		
			
				|  |  | -                	MAX(agent_id) as agent_id,
 | 
	
		
			
				|  |  | -                	MAX(agent_name) as agent_name,
 | 
	
		
			
				|  |  | -                	MAX(agent_key) as agent_key,
 | 
	
		
			
				|  |  | -                	MAX(cp_name) as cp_name,
 | 
	
		
			
				|  |  | -                	MAX(game_id) as game_id,
 | 
	
		
			
				|  |  | -                	MAX(game_name) as game_name,
 | 
	
		
			
				|  |  | -                	MAX(classify) as classify,
 | 
	
		
			
				|  |  | -                	SUM(today_cost) as today_cost,
 | 
	
		
			
				|  |  | -                	SUM(show_count) as show_count,
 | 
	
		
			
				|  |  | -                	round(if(SUM(show_count) > 0, SUM(today_cost) / SUM(show_count), 0), 2) as thousand_display_price,
 | 
	
		
			
				|  |  | -                	SUM(click_count) as click_count,
 | 
	
		
			
				|  |  | -                	round(if(SUM(click_count) > 0, SUM(today_cost) / SUM(click_count), 0), 2) as avg_click_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(show_count) > 0, SUM(click_count) / SUM(show_count), 0), 4) as ctr,
 | 
	
		
			
				|  |  | -                	SUM(convert_count) as convert_count,
 | 
	
		
			
				|  |  | -                	ROUND(IF(SUM(convert_count) > 0, SUM(today_cost) / SUM(convert_count), 0), 2) as convert_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(click_count) > 0, SUM(convert_count) / SUM(click_count), 0), 4) as convert_rate,
 | 
	
		
			
				|  |  | -                	SUM(reg_num) as reg_num,
 | 
	
		
			
				|  |  | -                	SUM(first_role_num) as first_role_num,
 | 
	
		
			
				|  |  | -                	SUM(new_user_total_role_num) as new_user_total_role_num,
 | 
	
		
			
				|  |  | -                	round(if(SUM(reg_num) > 0, SUM(today_cost) / SUM(reg_num), 0), 2) as reg_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_role_num) > 0, SUM(today_cost) / SUM(first_role_num), 0), 2) as first_role_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_role_num) > 0, SUM(today_cost) / SUM(new_user_total_role_num), 0), 2) as new_user_total_role_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(reg_num) > 0, SUM(first_role_num) / SUM(reg_num), 0), 4) as first_role_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(reg_num) > 0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) as new_user_total_role_rate,
 | 
	
		
			
				|  |  | -                	SUM(first_new_user_amount_count) as first_new_user_amount_count,
 | 
	
		
			
				|  |  | -                	SUM(first_new_user_amount_num) as first_new_user_amount_num,
 | 
	
		
			
				|  |  | -                	SUM(first_new_user_amount) as first_new_user_amount,
 | 
	
		
			
				|  |  | -                	SUM(new_user_total_amount_count) as new_user_total_amount_count,
 | 
	
		
			
				|  |  | -                	SUM(new_user_total_amount_num) as new_user_total_amount_num,
 | 
	
		
			
				|  |  | -                	SUM(new_user_total_amount) as new_user_total_amount,
 | 
	
		
			
				|  |  | -                	round(if(SUM(today_cost) > 0, SUM(first_new_user_amount) / SUM(today_cost), 0), 4) as first_roi,
 | 
	
		
			
				|  |  | -                	SUM(twenty_four_hours_amount) as twenty_four_hours_amount,
 | 
	
		
			
				|  |  | -                	round(if(SUM(today_cost) > 0, SUM(twenty_four_hours_amount) / SUM(today_cost), 0), 4) as twenty_four_hours_roi,
 | 
	
		
			
				|  |  | -                	round(if(SUM(today_cost) > 0, SUM(new_user_total_amount) / SUM(today_cost), 0), 4) as total_roi,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount_num) > 0, SUM(today_cost) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_recharge_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_amount_num) > 0, SUM(today_cost) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_recharge_cost,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount_num) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_arppu,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_amount_num) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_amount_arppu,
 | 
	
		
			
				|  |  | -                	SUM(first_new_user_hundred_user_num) as first_new_user_hundred_user_num,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_hundred_user_num), 0), 2) as first_new_user_hundred_user_cost,
 | 
	
		
			
				|  |  | -                	SUM(first_recharge_fifty_hundred_num) as first_recharge_fifty_hundred_num,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_amount_num) > 0, SUM(first_recharge_fifty_hundred_num) / SUM(new_user_total_amount_num), 0), 4) as first_recharge_fifty_hundred_rate,
 | 
	
		
			
				|  |  | -                	SUM(first_new_user_two_hundred_user_num) as first_new_user_two_hundred_user_num,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_two_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_two_hundred_user_num), 0), 2) as first_new_user_two_hundred_user_cost,
 | 
	
		
			
				|  |  | -                	SUM(new_user_total_hundred_user_num) as new_user_total_hundred_user_num,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_hundred_user_num) > 0, SUM(today_cost) / SUM(new_user_total_hundred_user_num), 0), 2) as new_user_total_hundred_user_cost,
 | 
	
		
			
				|  |  | -                	SUM(first_ios_amount_num) as first_ios_amount_num,
 | 
	
		
			
				|  |  | -                	SUM(first_ios_amount_count) as first_ios_amount_count,
 | 
	
		
			
				|  |  | -                	SUM(first_ios_amount) as first_ios_amount,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount_num) > 0, SUM(first_ios_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_ios_amount_num_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount) > 0, SUM(first_ios_amount) / SUM(first_new_user_amount), 0), 4) as first_ios_amount_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(today_cost)> 0, SUM(first_ios_amount) / SUM(today_cost), 0), 4) as first_ios_amount_roi,
 | 
	
		
			
				|  |  | -                	SUM(first_android_amount_count) as first_android_amount_count,
 | 
	
		
			
				|  |  | -                	SUM(first_android_amount_num) as first_android_amount_num,
 | 
	
		
			
				|  |  | -                	SUM(first_android_amount) as first_android_amount,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount_num) > 0,SUM(first_android_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_android_amount_num_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount) > 0, SUM(first_android_amount) / SUM(first_new_user_amount), 0), 4) as first_android_amount_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(today_cost) > 0, SUM(first_android_amount) / SUM(today_cost), 0), 4) as first_android_amount_roi,
 | 
	
		
			
				|  |  | -                	round(if(SUM(reg_num) > 0, SUM(first_new_user_amount_num) / SUM(reg_num), 0), 4) as first_amount_rate,
 | 
	
		
			
				|  |  | -                	round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_avg_price,
 | 
	
		
			
				|  |  | -                	round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_avg_price,
 | 
	
		
			
				|  |  | -                	SUM(d1) as d1,
 | 
	
		
			
				|  |  | -                	SUM(d2) as d2,
 | 
	
		
			
				|  |  | -                	SUM(d3) as d3,
 | 
	
		
			
				|  |  | -                	SUM(d7) as d7,
 | 
	
		
			
				|  |  | -                	SUM(d15) as d15,
 | 
	
		
			
				|  |  | -                	IFNULL(SUM(active), 0) as active,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(active) > 0, SUM(today_cost) / SUM(active), 0), 2) as active_cost,
 | 
	
		
			
				|  |  | -                    IFNULL(SUM(first_convert_count), 0) as first_convert_count,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(first_convert_count) > 0, SUM(today_cost) / SUM(first_convert_count), 0), 2) as first_convert_cost,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(active) > 0, SUM(game_pay_count) / SUM(active), 0), 4) as first_active_pay_rate,
 | 
	
		
			
				|  |  | -                    SUM(first_attribution_game_in_app_ltv1day) as first_attribution_game_in_app_ltv1day,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(today_cost) > 0 , SUM(first_attribution_game_in_app_ltv1day) / SUM(today_cost), 0), 4) as first_attribution_game_in_app_roi1day,
 | 
	
		
			
				|  |  | -                    SUM(game_pay_count) as game_pay_count,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(game_pay_count) > 0, SUM(today_cost) / SUM(game_pay_count), 0), 2) as game_pay_count_cost,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(reg_num) > 0, SUM(first_attribution_game_in_app_ltv1day) / SUM(reg_num), 0), 2) as ltv_day1,
 | 
	
		
			
				|  |  | -                    (SUM(first_new_user_amount_count) - SUM(first_sub_amount_count)) as sub_order_num,
 | 
	
		
			
				|  |  | -                    (SUM(first_new_user_amount) - SUM(first_sub_amount)) as sub_order_amount,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(first_new_user_amount_count) > 0, SUM(today_cost) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_amount_count_cost,
 | 
	
		
			
				|  |  | -                    ROUND(IF(SUM(new_user_total_amount_count) > 0, SUM(today_cost) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_amount_count_cost
 | 
	
		
			
				|  |  | -                FROM
 | 
	
		
			
				|  |  | -                	game_ads.ads_promotion_day
 | 
	
		
			
				|  |  | -                """;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 查询广告每日里总数据sql
 | 
	
		
			
				|  |  | -     *
 | 
	
		
			
				|  |  | -     * @return String
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private String getTotalDataSql() {
 | 
	
		
			
				|  |  | +    private String getPromotionDayListSql() {
 | 
	
		
			
				|  |  |          return """
 | 
	
		
			
				|  |  |                  SELECT
 | 
	
		
			
				|  |  | +                    dt,
 | 
	
		
			
				|  |  |                      status,
 | 
	
		
			
				|  |  |                      creative_preview,
 | 
	
		
			
				|  |  |                      landing_type,
 | 
	
	
		
			
				|  | @@ -595,12 +535,250 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
 | 
	
		
			
				|  |  |                      total_amount_num,
 | 
	
		
			
				|  |  |                      total_amount,
 | 
	
		
			
				|  |  |                      promotion_total_roi,
 | 
	
		
			
				|  |  | -                    total_recharge_cost
 | 
	
		
			
				|  |  | +                    total_recharge_cost,
 | 
	
		
			
				|  |  | +                	promotion_id,
 | 
	
		
			
				|  |  | +                	promotion_name,
 | 
	
		
			
				|  |  | +                	project_id,
 | 
	
		
			
				|  |  | +                	project_name,
 | 
	
		
			
				|  |  | +                	account_name,
 | 
	
		
			
				|  |  | +                	account_id,
 | 
	
		
			
				|  |  | +                	account_type,
 | 
	
		
			
				|  |  | +                	pitcher_id,
 | 
	
		
			
				|  |  | +                	pitcher_name,
 | 
	
		
			
				|  |  | +                	agent_id,
 | 
	
		
			
				|  |  | +                	agent_name,
 | 
	
		
			
				|  |  | +                	agent_key,
 | 
	
		
			
				|  |  | +                	cp_name,
 | 
	
		
			
				|  |  | +                	game_id,
 | 
	
		
			
				|  |  | +                	game_name,
 | 
	
		
			
				|  |  | +                	classify,
 | 
	
		
			
				|  |  | +                	today_cost,
 | 
	
		
			
				|  |  | +                	show_count,
 | 
	
		
			
				|  |  | +                	thousand_display_price,
 | 
	
		
			
				|  |  | +                	click_count,
 | 
	
		
			
				|  |  | +                	avg_click_cost,
 | 
	
		
			
				|  |  | +                	ctr,
 | 
	
		
			
				|  |  | +                	convert_count,
 | 
	
		
			
				|  |  | +                	convert_cost,
 | 
	
		
			
				|  |  | +                	convert_rate,
 | 
	
		
			
				|  |  | +                	reg_num,
 | 
	
		
			
				|  |  | +                	first_role_num,
 | 
	
		
			
				|  |  | +                	new_user_total_role_num,
 | 
	
		
			
				|  |  | +                	reg_cost,
 | 
	
		
			
				|  |  | +                	first_role_cost,
 | 
	
		
			
				|  |  | +                	new_user_total_role_cost,
 | 
	
		
			
				|  |  | +                	first_role_rate,
 | 
	
		
			
				|  |  | +                	new_user_total_role_rate,
 | 
	
		
			
				|  |  | +                	first_new_user_amount_count,
 | 
	
		
			
				|  |  | +                	first_new_user_amount_num,
 | 
	
		
			
				|  |  | +                	first_new_user_amount,
 | 
	
		
			
				|  |  | +                	new_user_total_amount_count,
 | 
	
		
			
				|  |  | +                	new_user_total_amount_num,
 | 
	
		
			
				|  |  | +                	new_user_total_amount,
 | 
	
		
			
				|  |  | +                	first_roi,
 | 
	
		
			
				|  |  | +                	twenty_four_hours_amount,
 | 
	
		
			
				|  |  | +                	twenty_four_hours_roi,
 | 
	
		
			
				|  |  | +                	total_roi,
 | 
	
		
			
				|  |  | +                	first_new_user_recharge_cost,
 | 
	
		
			
				|  |  | +                	new_user_total_recharge_cost,
 | 
	
		
			
				|  |  | +                	first_new_user_arppu,
 | 
	
		
			
				|  |  | +                	new_user_total_amount_arppu,
 | 
	
		
			
				|  |  | +                	first_new_user_hundred_user_num,
 | 
	
		
			
				|  |  | +                	first_new_user_hundred_user_cost,
 | 
	
		
			
				|  |  | +                	first_recharge_fifty_hundred_num,
 | 
	
		
			
				|  |  | +                	first_recharge_fifty_hundred_rate,
 | 
	
		
			
				|  |  | +                	first_new_user_two_hundred_user_num,
 | 
	
		
			
				|  |  | +                	first_new_user_two_hundred_user_cost,
 | 
	
		
			
				|  |  | +                	new_user_total_hundred_user_num,
 | 
	
		
			
				|  |  | +                	new_user_total_hundred_user_cost,
 | 
	
		
			
				|  |  | +                	first_ios_amount_num,
 | 
	
		
			
				|  |  | +                	first_ios_amount_count,
 | 
	
		
			
				|  |  | +                	first_ios_amount,
 | 
	
		
			
				|  |  | +                	first_ios_amount_num_rate,
 | 
	
		
			
				|  |  | +                	first_ios_amount_rate,
 | 
	
		
			
				|  |  | +                	first_ios_amount_roi,
 | 
	
		
			
				|  |  | +                	first_android_amount_count,
 | 
	
		
			
				|  |  | +                	first_android_amount_num,
 | 
	
		
			
				|  |  | +                	first_android_amount,
 | 
	
		
			
				|  |  | +                	first_android_amount_num_rate,
 | 
	
		
			
				|  |  | +                	first_android_amount_rate,
 | 
	
		
			
				|  |  | +                	first_android_amount_roi,
 | 
	
		
			
				|  |  | +                	first_amount_rate,
 | 
	
		
			
				|  |  | +                	first_new_user_avg_price,
 | 
	
		
			
				|  |  | +                	new_user_total_avg_price,
 | 
	
		
			
				|  |  | +                	d1,
 | 
	
		
			
				|  |  | +                	d2,
 | 
	
		
			
				|  |  | +                	d3,
 | 
	
		
			
				|  |  | +                	d7,
 | 
	
		
			
				|  |  | +                	d15,
 | 
	
		
			
				|  |  | +                	active,
 | 
	
		
			
				|  |  | +                    active_cost,
 | 
	
		
			
				|  |  | +                    first_convert_count,
 | 
	
		
			
				|  |  | +                    first_convert_cost,
 | 
	
		
			
				|  |  | +                    first_active_pay_rate,
 | 
	
		
			
				|  |  | +                    first_attribution_game_in_app_ltv1day,
 | 
	
		
			
				|  |  | +                    first_attribution_game_in_app_roi1day,
 | 
	
		
			
				|  |  | +                    game_pay_count,
 | 
	
		
			
				|  |  | +                    ROUND(IF(game_pay_count > 0, today_cost / game_pay_count, 0), 2) as game_pay_count_cost,
 | 
	
		
			
				|  |  | +                    ltv_day1,
 | 
	
		
			
				|  |  | +                    sub_order_num,
 | 
	
		
			
				|  |  | +                    sub_order_amount,
 | 
	
		
			
				|  |  | +                    ROUND(IF(first_new_user_amount_count > 0, today_cost / first_new_user_amount_count, 0), 2) as first_new_user_amount_count_cost,
 | 
	
		
			
				|  |  | +                    ROUND(IF(new_user_total_amount_count > 0, today_cost / new_user_total_amount_count, 0), 2) as new_user_total_amount_count_cost,
 | 
	
		
			
				|  |  | +                    ROUND(IF(total_amount_count > 0, promotion_total_cost / total_amount_count, 0), 2) as total_amount_count_cost
 | 
	
		
			
				|  |  |                  FROM
 | 
	
		
			
				|  |  | -                    game_ads.ads_promotion_day
 | 
	
		
			
				|  |  | +                	game_ads.ads_promotion_day
 | 
	
		
			
				|  |  |                  """;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 获取广告监控数据的SQL
 | 
	
		
			
				|  |  | +     * @param criA
 | 
	
		
			
				|  |  | +     * @param criB
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private String getPromotionDayDataSql(Criteria criA, Criteria criB) {
 | 
	
		
			
				|  |  | +        return """
 | 
	
		
			
				|  |  | +                SELECT
 | 
	
		
			
				|  |  | +                b.*,
 | 
	
		
			
				|  |  | +                c.*
 | 
	
		
			
				|  |  | +                FROM(
 | 
	
		
			
				|  |  | +                	SELECT
 | 
	
		
			
				|  |  | +                		promotion_id,
 | 
	
		
			
				|  |  | +                		MAX(promotion_name) as promotion_name,
 | 
	
		
			
				|  |  | +                		MAX(project_id) as project_id,
 | 
	
		
			
				|  |  | +                		MAX(project_name) as project_name,
 | 
	
		
			
				|  |  | +                		MAX(account_name) as account_name,
 | 
	
		
			
				|  |  | +                		MAX(account_id) as account_id,
 | 
	
		
			
				|  |  | +                		MAX(account_type) as account_type,
 | 
	
		
			
				|  |  | +                		MAX(pitcher_id) as pitcher_id,
 | 
	
		
			
				|  |  | +                		MAX(pitcher_name) as pitcher_name,
 | 
	
		
			
				|  |  | +                		MAX(agent_id) as agent_id,
 | 
	
		
			
				|  |  | +                		MAX(agent_name) as agent_name,
 | 
	
		
			
				|  |  | +                		MAX(agent_key) as agent_key,
 | 
	
		
			
				|  |  | +                		MAX(cp_name) as cp_name,
 | 
	
		
			
				|  |  | +                		MAX(game_id) as game_id,
 | 
	
		
			
				|  |  | +                		MAX(game_name) as game_name,
 | 
	
		
			
				|  |  | +                		MAX(classify) as classify,
 | 
	
		
			
				|  |  | +                		SUM(today_cost) as today_cost,
 | 
	
		
			
				|  |  | +                		SUM(show_count) as show_count,
 | 
	
		
			
				|  |  | +                		round(if(SUM(show_count) > 0, SUM(today_cost) / SUM(show_count), 0), 2) as thousand_display_price,
 | 
	
		
			
				|  |  | +                		SUM(click_count) as click_count,
 | 
	
		
			
				|  |  | +                		round(if(SUM(click_count) > 0, SUM(today_cost) / SUM(click_count), 0), 2) as avg_click_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(show_count) > 0, SUM(click_count) / SUM(show_count), 0), 4) as ctr,
 | 
	
		
			
				|  |  | +                		SUM(convert_count) as convert_count,
 | 
	
		
			
				|  |  | +                		ROUND(IF(SUM(convert_count) > 0, SUM(today_cost) / SUM(convert_count), 0), 2) as convert_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(click_count) > 0, SUM(convert_count) / SUM(click_count), 0), 4) as convert_rate,
 | 
	
		
			
				|  |  | +                		SUM(reg_num) as reg_num,
 | 
	
		
			
				|  |  | +                		SUM(first_role_num) as first_role_num,
 | 
	
		
			
				|  |  | +                		SUM(new_user_total_role_num) as new_user_total_role_num,
 | 
	
		
			
				|  |  | +                		round(if(SUM(reg_num) > 0, SUM(today_cost) / SUM(reg_num), 0), 2) as reg_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_role_num) > 0, SUM(today_cost) / SUM(first_role_num), 0), 2) as first_role_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_role_num) > 0, SUM(today_cost) / SUM(new_user_total_role_num), 0), 2) as new_user_total_role_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(reg_num) > 0, SUM(first_role_num) / SUM(reg_num), 0), 4) as first_role_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(reg_num) > 0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) as new_user_total_role_rate,
 | 
	
		
			
				|  |  | +                		SUM(first_new_user_amount_count) as first_new_user_amount_count,
 | 
	
		
			
				|  |  | +                		SUM(first_new_user_amount_num) as first_new_user_amount_num,
 | 
	
		
			
				|  |  | +                		SUM(first_new_user_amount) as first_new_user_amount,
 | 
	
		
			
				|  |  | +                		SUM(new_user_total_amount_count) as new_user_total_amount_count,
 | 
	
		
			
				|  |  | +                		SUM(new_user_total_amount_num) as new_user_total_amount_num,
 | 
	
		
			
				|  |  | +                		SUM(new_user_total_amount) as new_user_total_amount,
 | 
	
		
			
				|  |  | +                		round(if(SUM(today_cost) > 0, SUM(first_new_user_amount) / SUM(today_cost), 0), 4) as first_roi,
 | 
	
		
			
				|  |  | +                		SUM(twenty_four_hours_amount) as twenty_four_hours_amount,
 | 
	
		
			
				|  |  | +                		round(if(SUM(today_cost) > 0, SUM(twenty_four_hours_amount) / SUM(today_cost), 0), 4) as twenty_four_hours_roi,
 | 
	
		
			
				|  |  | +                		round(if(SUM(today_cost) > 0, SUM(new_user_total_amount) / SUM(today_cost), 0), 4) as total_roi,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount_num) > 0, SUM(today_cost) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_recharge_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_amount_num) > 0, SUM(today_cost) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_recharge_cost,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount_num) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) as first_new_user_arppu,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_amount_num) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) as new_user_total_amount_arppu,
 | 
	
		
			
				|  |  | +                		SUM(first_new_user_hundred_user_num) as first_new_user_hundred_user_num,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_hundred_user_num), 0), 2) as first_new_user_hundred_user_cost,
 | 
	
		
			
				|  |  | +                		SUM(first_recharge_fifty_hundred_num) as first_recharge_fifty_hundred_num,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_amount_num) > 0, SUM(first_recharge_fifty_hundred_num) / SUM(new_user_total_amount_num), 0), 4) as first_recharge_fifty_hundred_rate,
 | 
	
		
			
				|  |  | +                		SUM(first_new_user_two_hundred_user_num) as first_new_user_two_hundred_user_num,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_two_hundred_user_num) > 0, SUM(today_cost) / SUM(first_new_user_two_hundred_user_num), 0), 2) as first_new_user_two_hundred_user_cost,
 | 
	
		
			
				|  |  | +                		SUM(new_user_total_hundred_user_num) as new_user_total_hundred_user_num,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_hundred_user_num) > 0, SUM(today_cost) / SUM(new_user_total_hundred_user_num), 0), 2) as new_user_total_hundred_user_cost,
 | 
	
		
			
				|  |  | +                		SUM(first_ios_amount_num) as first_ios_amount_num,
 | 
	
		
			
				|  |  | +                		SUM(first_ios_amount_count) as first_ios_amount_count,
 | 
	
		
			
				|  |  | +                		SUM(first_ios_amount) as first_ios_amount,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount_num) > 0, SUM(first_ios_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_ios_amount_num_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount) > 0, SUM(first_ios_amount) / SUM(first_new_user_amount), 0), 4) as first_ios_amount_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(today_cost)> 0, SUM(first_ios_amount) / SUM(today_cost), 0), 4) as first_ios_amount_roi,
 | 
	
		
			
				|  |  | +                		SUM(first_android_amount_count) as first_android_amount_count,
 | 
	
		
			
				|  |  | +                		SUM(first_android_amount_num) as first_android_amount_num,
 | 
	
		
			
				|  |  | +                		SUM(first_android_amount) as first_android_amount,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount_num) > 0,SUM(first_android_amount_num) / SUM(first_new_user_amount_num), 0), 4) as first_android_amount_num_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount) > 0, SUM(first_android_amount) / SUM(first_new_user_amount), 0), 4) as first_android_amount_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(today_cost) > 0, SUM(first_android_amount) / SUM(today_cost), 0), 4) as first_android_amount_roi,
 | 
	
		
			
				|  |  | +                		round(if(SUM(reg_num) > 0, SUM(first_new_user_amount_num) / SUM(reg_num), 0), 4) as first_amount_rate,
 | 
	
		
			
				|  |  | +                		round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_avg_price,
 | 
	
		
			
				|  |  | +                		round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_avg_price,
 | 
	
		
			
				|  |  | +                		SUM(d1) as d1,
 | 
	
		
			
				|  |  | +                		SUM(d2) as d2,
 | 
	
		
			
				|  |  | +                		SUM(d3) as d3,
 | 
	
		
			
				|  |  | +                		SUM(d7) as d7,
 | 
	
		
			
				|  |  | +                		SUM(d15) as d15,
 | 
	
		
			
				|  |  | +                		IFNULL(SUM(active), 0) as active,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(active) > 0, SUM(today_cost) / SUM(active), 0), 2) as active_cost,
 | 
	
		
			
				|  |  | +                	    IFNULL(SUM(first_convert_count), 0) as first_convert_count,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(first_convert_count) > 0, SUM(today_cost) / SUM(first_convert_count), 0), 2) as first_convert_cost,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(active) > 0, SUM(game_pay_count) / SUM(active), 0), 4) as first_active_pay_rate,
 | 
	
		
			
				|  |  | +                	    SUM(first_attribution_game_in_app_ltv1day) as first_attribution_game_in_app_ltv1day,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(today_cost) > 0 , SUM(first_attribution_game_in_app_ltv1day) / SUM(today_cost), 0), 4) as first_attribution_game_in_app_roi1day,
 | 
	
		
			
				|  |  | +                	    SUM(game_pay_count) as game_pay_count,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(game_pay_count) > 0, SUM(today_cost) / SUM(game_pay_count), 0), 2) as game_pay_count_cost,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(reg_num) > 0, SUM(first_attribution_game_in_app_ltv1day) / SUM(reg_num), 0), 2) as ltv_day1,
 | 
	
		
			
				|  |  | +                	    (SUM(first_new_user_amount_count) - SUM(first_sub_amount_count)) as sub_order_num,
 | 
	
		
			
				|  |  | +                	    (SUM(first_new_user_amount) - SUM(first_sub_amount)) as sub_order_amount,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(first_new_user_amount_count) > 0, SUM(today_cost) / SUM(first_new_user_amount_count), 0), 2) as first_new_user_amount_count_cost,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(SUM(new_user_total_amount_count) > 0, SUM(today_cost) / SUM(new_user_total_amount_count), 0), 2) as new_user_total_amount_count_cost
 | 
	
		
			
				|  |  | +                	FROM
 | 
	
		
			
				|  |  | +                		game_ads.ads_promotion_day
 | 
	
		
			
				|  |  | +                """ + criA +
 | 
	
		
			
				|  |  | +                """
 | 
	
		
			
				|  |  | +                	 ) b
 | 
	
		
			
				|  |  | +                LEFT JOIN(
 | 
	
		
			
				|  |  | +                	SELECT
 | 
	
		
			
				|  |  | +                	*
 | 
	
		
			
				|  |  | +                	FROM(
 | 
	
		
			
				|  |  | +                	SELECT
 | 
	
		
			
				|  |  | +                	    ROW_NUMBER()over(partition by promotion_id order by dt desc) as num,
 | 
	
		
			
				|  |  | +                	    promotion_id,
 | 
	
		
			
				|  |  | +                	    status,
 | 
	
		
			
				|  |  | +                	    creative_preview,
 | 
	
		
			
				|  |  | +                	    landing_type,
 | 
	
		
			
				|  |  | +                	    pricing,
 | 
	
		
			
				|  |  | +                	    cpa_bid,
 | 
	
		
			
				|  |  | +                	    roi_goal,
 | 
	
		
			
				|  |  | +                	    budget,
 | 
	
		
			
				|  |  | +                	    concat(start_time,'/',end_time) as schedule_time,
 | 
	
		
			
				|  |  | +                	    notes,
 | 
	
		
			
				|  |  | +                	    service,
 | 
	
		
			
				|  |  | +                	    balance,
 | 
	
		
			
				|  |  | +                	    promotion_total_cost,
 | 
	
		
			
				|  |  | +                	    convert_target,
 | 
	
		
			
				|  |  | +                	    reg_total_num,
 | 
	
		
			
				|  |  | +                	    role_total_num,
 | 
	
		
			
				|  |  | +                	    reg_total_cost,
 | 
	
		
			
				|  |  | +                	    role_total_cost,
 | 
	
		
			
				|  |  | +                	    role_total_rate,
 | 
	
		
			
				|  |  | +                	    total_amount_count,
 | 
	
		
			
				|  |  | +                	    total_amount_num,
 | 
	
		
			
				|  |  | +                	    total_amount,
 | 
	
		
			
				|  |  | +                	    promotion_total_roi,
 | 
	
		
			
				|  |  | +                	    ROUND(IF(total_amount_count > 0, promotion_total_cost / total_amount_count, 0), 2) as total_amount_count_cost,
 | 
	
		
			
				|  |  | +                	    total_recharge_cost
 | 
	
		
			
				|  |  | +                	FROM
 | 
	
		
			
				|  |  | +                		game_ads.ads_promotion_day
 | 
	
		
			
				|  |  | +                	""" + criB +
 | 
	
		
			
				|  |  | +                """
 | 
	
		
			
				|  |  | +                 ) a
 | 
	
		
			
				|  |  | +                WHERE a.num = 1) c
 | 
	
		
			
				|  |  | +            ON b.promotion_id = c.promotion_id
 | 
	
		
			
				|  |  | +            """;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 查询广告监控每日总计一栏sql
 | 
	
		
			
				|  |  |       *
 |