소스 검색

修改内容:修改广告排序逻辑

lth 1 년 전
부모
커밋
a5153c7141
1개의 변경된 파일164개의 추가작업 그리고 230개의 파일을 삭제
  1. 164 230
      game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/PromotionDayServiceImpl.java

+ 164 - 230
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/PromotionDayServiceImpl.java

@@ -1,5 +1,6 @@
 package com.zanxiang.game.data.serve.service.impl;
 
+import com.google.common.base.CaseFormat;
 import com.zanxiang.game.data.serve.pojo.dto.PromotionDayDTO;
 import com.zanxiang.game.data.serve.pojo.dto.PromotionDayTotalDTO;
 import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
@@ -8,7 +9,6 @@ import com.zanxiang.game.data.serve.pojo.vo.PromotionDayVO;
 import com.zanxiang.game.data.serve.pojo.vo.PromotionRechargeTrendVO;
 import com.zanxiang.game.data.serve.service.IAdsPromotionDayService;
 import com.zanxiang.game.data.serve.utils.Page;
-import com.zanxiang.module.util.exception.BaseException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.nutz.dao.Cnd;
@@ -25,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
@@ -58,12 +57,21 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         }
         //如果没有排序条件给默认值
         if (StringUtils.isBlank(dto.getSortFiled())) {
-            dto.setSortFiled("todayCost");
+            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);
         //添加自定义回传对象
@@ -76,20 +84,12 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         dao.execute(sql);
         //获取到结果list
         List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
-        //分页对象设置总条数
-        Sql sqlCount = Sqls.create("select count(*) from ads_promotion_day" + cri);
-        sqlCount.setCallback(Sqls.callback.integer());
-        //执行sql
-        dao.execute(sqlCount);
+        //分页对象设置总记录条数
         pager.setRecordCount(sqlCount.getInt());
 
         //处理List中的每个vo对象缺少的数据
         list.stream().map(vo -> {
 
-            //总充值次数成本
-            vo.setTotalAmountCountCost(vo.getTotalAmountCount() == 0L ? BigDecimal.ZERO :
-                    vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getTotalAmountCount()), 2, RoundingMode.HALF_UP));
-
             //计算d2(次日)数据
             vo.setD2Trend(PromotionRechargeTrendVO.builder()
                     .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
@@ -127,9 +127,6 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
             return vo;
         }).collect(Collectors.toList());
 
-        //排序
-        listSort(dto, list);
-
         //返回查询得结果
         return new Page<>(list, pager);
     }
@@ -150,14 +147,18 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         }
         //如果没有排序条件给默认值
         if (StringUtils.isBlank(dto.getSortFiled())) {
-            dto.setSortFiled("todayCost");
+            dto.setSortFiled("today_cost");
         }
         if (StringUtils.isBlank(dto.getSortType())) {
             dto.setSortType(OrderByEnum.DESC.getOrderType());
         }
-        Criteria cri = myCri(dto, true);
+        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));
@@ -169,22 +170,12 @@ 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));
 
-        //得到查询条件内所有广告最新的一条数据
-        Map<String, PromotionDayVO> latestDateDataMap = getLatestDateData(myCri(dto, false));
-
         //处理List中的每个vo对象缺少的数据
         list.stream().map(vo -> {
 
-            //找到相同的广告ID,取出对象并合并属性值
-            copyNullProperties(latestDateDataMap.get(vo.getPromotionId()), vo);
-
-            //总充值次数成本
-            vo.setTotalAmountCountCost(vo.getTotalAmountCount() == 0L ? BigDecimal.ZERO :
-                    vo.getPromotionTotalCost().divide(BigDecimal.valueOf(vo.getTotalAmountCount()), 2, RoundingMode.HALF_UP));
-
             //计算d2(次日)数据
             vo.setD2Trend(PromotionRechargeTrendVO.builder()
                     .roi(vo.getTodayCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
@@ -222,9 +213,6 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
             return vo;
         }).collect(Collectors.toList());
 
-        //排序
-        listSort(dto, list);
-
         //返回查询得结果
         return new Page<>(list, pager);
     }
@@ -516,70 +504,6 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
         return notNullFieldSet.toArray(notNullField);
     }
 
-    /**
-     * 获取最新数据得到Map
-     * @param cri 查询条件
-     * @return Map结果
-     */
-    private Map<String, PromotionDayVO> getLatestDateData(Criteria cri) {
-        Sql sql = Sqls.create("""
-                SELECT
-                *
-                FROM(
-                """
-                +  getLatestDateDataSql() + cri +
-                """
-                 ) a
-                WHERE a.num = 1
-                """);
-        //设置回传对象
-        sql.setCallback(Sqls.callback.entities());
-        sql.setEntity(dao.getEntity(PromotionDayVO.class));
-        //执行sql
-        dao.execute(sql);
-        //得到sql查询的结果
-        List<PromotionDayVO> list = sql.getList(PromotionDayVO.class);
-        Map<String, PromotionDayVO> resMap = new HashMap<>(list.size());
-        //循环赋值得到最终map
-        for (PromotionDayVO vo : list) {
-            resMap.put(vo.getPromotionId(), vo);
-        }
-        return resMap;
-    }
-
-    /**
-     * 排序
-     * @param dto 前端传递的查询条件
-     * @param list 排序后的list
-     */
-    private void listSort(PromotionDayDTO dto, List<PromotionDayVO> list) {
-        try {
-            //得到排序字段得反射
-            Field field = PromotionDayVO.class.getDeclaredField(dto.getSortFiled());
-            field.setAccessible(true);
-            //是否升序
-            boolean isASC = !dto.getSortType().equals("desc");
-
-            list.sort((o1, o2) -> {
-                try {
-                    //字段属性得get方法得到的值
-                    Object value1 = field.get(o1);
-                    Object value2 = field.get(o2);
-                    if (value1 instanceof BigDecimal num1 && value2 instanceof BigDecimal num2) {
-                        return isASC ? num1.compareTo(num2) : num2.compareTo(num1);
-                    } else if (value1 instanceof Long l1 && value2 instanceof Long l2) {
-                        return isASC ? l1.compareTo(l2) : l2.compareTo(l1);
-                    }
-                } catch (IllegalAccessException e) {
-                    throw new BaseException("排序出错");
-                }
-                return 0;
-            });
-        } catch (NoSuchFieldException e) {
-            throw new BaseException("排序出错");
-        }
-    }
-
     /**
      * 广告监控每日数据sql
      *
@@ -700,149 +624,159 @@ public class PromotionDayServiceImpl implements IAdsPromotionDayService {
                     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
-                FROM
-                	game_ads.ads_promotion_day
-                """;
-    }
-
-    /**
-     * 查询广告监控数据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
+                    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
                 """;
     }
 
     /**
-     * 获取到最新数据的sql
-     * @return String
+     * 获取广告监控数据的SQL
+     * @param criA
+     * @param criB
+     * @return
      */
-    private String getLatestDateDataSql() {
+    private String getPromotionDayDataSql(Criteria criA, Criteria criB) {
         return """
                 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,
-                    total_recharge_cost
-                FROM
-                	game_ads.ads_promotion_day
-                """;
+                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
+            """;
     }
 
     /**