|
@@ -0,0 +1,1080 @@
|
|
|
+package com.zanxiang.game.data.serve.service.impl;
|
|
|
+
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.zanxiang.game.data.serve.pojo.dto.ActiveDataDayDTO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.dto.ActiveDataTotalDTO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsGameActiveDay;
|
|
|
+import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.ActiveDataDayVO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.ActiveDataTotalVO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.ActiveDataTrendVO;
|
|
|
+import com.zanxiang.game.data.serve.service.IActiveDataService;
|
|
|
+import com.zanxiang.game.data.serve.utils.Page;
|
|
|
+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.pager.Pager;
|
|
|
+import org.nutz.dao.sql.Criteria;
|
|
|
+import org.nutz.dao.sql.Sql;
|
|
|
+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.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
+import reactor.util.function.Tuples;
|
|
|
+
|
|
|
+import java.beans.PropertyDescriptor;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Modifier;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author tianhua
|
|
|
+ * @time 2023/8/23
|
|
|
+ * @Description
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class IActiveDataServiceImpl implements IActiveDataService {
|
|
|
+
|
|
|
+ //存储PitcherGameDataDayVO的映射
|
|
|
+ private static final List<Tuple2<Field, Field>> activeDataDayNFieldMapList;
|
|
|
+ //存储PitcherGameDataDayTotalVO的映射
|
|
|
+ private static final List<Tuple2<Field, Field>> activeDataDayNTotalFieldMapList;
|
|
|
+
|
|
|
+ static {
|
|
|
+ //解析ActiveDataDayVO的映射
|
|
|
+ Map<String, Field> fieldMap = new HashMap<>();
|
|
|
+ List<Field> dayNFieldList = new ArrayList<>();
|
|
|
+ Class<?> tempClazz = ActiveDataDayVO.class;
|
|
|
+ while (tempClazz != null) {
|
|
|
+ Field[] fields = tempClazz.getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
|
|
|
+ //属性前面的修饰符为static或final不加入map中
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fieldMap.put(field.getName(), field);
|
|
|
+ if (field.getType() == ActiveDataTrendVO.class) {
|
|
|
+ //存储所有类型为ActiveDataTrendVO属性的映射 以Trend为结尾的
|
|
|
+ dayNFieldList.add(field);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempClazz = tempClazz.getSuperclass();
|
|
|
+ }
|
|
|
+ if (dayNFieldList.isEmpty()) {
|
|
|
+ activeDataDayNFieldMapList = Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ activeDataDayNFieldMapList = new ArrayList<>(dayNFieldList.size());
|
|
|
+ for (Field field : dayNFieldList) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ Field sourceField = fieldMap.get(field.getName().replace("Trend", ""));
|
|
|
+ sourceField.setAccessible(true);
|
|
|
+ activeDataDayNFieldMapList.add(Tuples.of(sourceField, field));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //解析ActiveDataTotalVO的映射
|
|
|
+ Map<String, Field> fieldTotalMap = new HashMap<>();
|
|
|
+ List<Field> dayNTotalFieldList = new ArrayList<>();
|
|
|
+ Class<?> tempTotalClazz = ActiveDataTotalVO.class;
|
|
|
+ while (tempTotalClazz != null) {
|
|
|
+ Field[] fields = tempTotalClazz.getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
|
|
|
+ //属性前面的修饰符为static或final不加入map中
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fieldTotalMap.put(field.getName(), field);
|
|
|
+ if (field.getType() == ActiveDataTrendVO.class) {
|
|
|
+ //存储所有类型为ActiveDataTrendVO属性的映射 以Trend为结尾的
|
|
|
+ dayNTotalFieldList.add(field);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempTotalClazz = tempTotalClazz.getSuperclass();
|
|
|
+ }
|
|
|
+ if (dayNTotalFieldList.isEmpty()) {
|
|
|
+ activeDataDayNTotalFieldMapList = Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ activeDataDayNTotalFieldMapList = new ArrayList<>(dayNTotalFieldList.size());
|
|
|
+ for (Field field : dayNTotalFieldList) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ Field sourceField = fieldTotalMap.get(field.getName().replace("Trend", ""));
|
|
|
+ sourceField.setAccessible(true);
|
|
|
+ activeDataDayNTotalFieldMapList.add(Tuples.of(sourceField, field));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Dao dao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 留存每日数据
|
|
|
+ * @param dto ActiveDataDayDTO
|
|
|
+ * @return Page<ActiveDataDayVO>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<ActiveDataDayVO> getActiveDataDay(ActiveDataDayDTO dto) {
|
|
|
+ //默认查询总数据
|
|
|
+ if (StringUtils.isBlank(dto.getTableTypes())) {
|
|
|
+ dto.setTableTypes("total");
|
|
|
+ }
|
|
|
+ //查询的class
|
|
|
+ Class<?> tempClazz = null;
|
|
|
+ //默认查询注册留存
|
|
|
+ String queryTableName;
|
|
|
+ if (StringUtils.isBlank(dto.getActiveTypes())) {
|
|
|
+ dto.setActiveTypes("reg");
|
|
|
+ }
|
|
|
+ switch (dto.getActiveTypes()) {
|
|
|
+ case "reg" -> {
|
|
|
+ queryTableName = "ads_game_active_day";
|
|
|
+ tempClazz = AdsGameActiveDay.class;
|
|
|
+ }
|
|
|
+ case "role" -> {
|
|
|
+ queryTableName = "";
|
|
|
+ tempClazz = AdsGameActiveDay.class;
|
|
|
+ }
|
|
|
+ case "amount" -> {
|
|
|
+ queryTableName = "";
|
|
|
+ tempClazz = AdsGameActiveDay.class;
|
|
|
+ }
|
|
|
+ default -> {
|
|
|
+ queryTableName = "ads_game_active_day";
|
|
|
+ tempClazz = AdsGameActiveDay.class;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建查询条件
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ //拼接游戏ID
|
|
|
+ if (dto.getGameId() != null) {
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ //拼接游戏应用类型
|
|
|
+ if (dto.getClassify() != null) {
|
|
|
+ cri.where().andEquals("game_classify", dto.getClassify());
|
|
|
+ }
|
|
|
+ //拼接SDK来源
|
|
|
+ if ("reg".equals(dto.getActiveTypes())) {
|
|
|
+ //注册留存只看 ZX_ONE的数据
|
|
|
+ cri.where().andEquals("source_system", "ZX_ONE");
|
|
|
+ } else {
|
|
|
+ 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 = Sqls.create(getActiveDataDaySql(dto.getTableTypes(), queryTableName, cri) + orderByCri);
|
|
|
+ //设置自定义回传类型
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
+ sql.setEntity(dao.getEntity(ActiveDataDayVO.class));
|
|
|
+ //设置pager对象
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
+ sql.setPager(pager);
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sql);
|
|
|
+ //得到结果集list
|
|
|
+ List<ActiveDataDayVO> list = sql.getList(ActiveDataDayVO.class);
|
|
|
+ //设置查询总数 (根据表名)
|
|
|
+ pager.setRecordCount(dao.count(tempClazz, cri));
|
|
|
+ List<ActiveDataDayVO> activeDataDayVOList = list.stream().map(vo -> {
|
|
|
+ //将string转成 ActiveDataTrendVO 对象
|
|
|
+ formatDayN(vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new Page<>(activeDataDayVOList, pager);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ActiveDataTotalVO getActiveDataTotal(ActiveDataTotalDTO dto) {
|
|
|
+ //默认查询总数据
|
|
|
+ if (StringUtils.isBlank(dto.getTableTypes())) {
|
|
|
+ dto.setTableTypes("total");
|
|
|
+ }
|
|
|
+ //默认查询注册留存
|
|
|
+ String queryTableName;
|
|
|
+ if (StringUtils.isBlank(dto.getActiveTypes())) {
|
|
|
+ dto.setActiveTypes("reg");
|
|
|
+ }
|
|
|
+ switch (dto.getActiveTypes()) {
|
|
|
+ case "reg" -> queryTableName = "ads_game_active_day";
|
|
|
+ case "role" -> queryTableName = "";
|
|
|
+ case "amount" -> queryTableName = "";
|
|
|
+ default -> queryTableName = "ads_game_active_day";
|
|
|
+ }
|
|
|
+ //创建查询条件
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ //拼接游戏ID
|
|
|
+ if (dto.getGameId() != null) {
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ //拼接游戏应用类型
|
|
|
+ if (dto.getClassify() != null) {
|
|
|
+ cri.where().andEquals("game_classify", dto.getClassify());
|
|
|
+ }
|
|
|
+ //拼接SDK来源
|
|
|
+ if ("reg".equals(dto.getActiveTypes())) {
|
|
|
+ //注册留存只看 ZX_ONE的数据
|
|
|
+ cri.where().andEquals("source_system", "ZX_ONE");
|
|
|
+ } else {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ //创建sql 获取游戏数据部分的数据
|
|
|
+ Sql sqlGameData = Sqls.create(getTotalGameData(dto.getTableTypes()) + cri);
|
|
|
+ //设置自定义回传对象
|
|
|
+ sqlGameData.setCallback(Sqls.callback.entity());
|
|
|
+ sqlGameData.setEntity(dao.getEntity(ActiveDataTotalVO.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sqlGameData);
|
|
|
+ //得到每日总计对象(游戏部分)
|
|
|
+ ActiveDataTotalVO voGameData = sqlGameData.getObject(ActiveDataTotalVO.class);
|
|
|
+
|
|
|
+ //创建sql 获取留存数据部分的数据
|
|
|
+ Sql sqlActiveData = Sqls.create(activeDataTotalSql(dto.getTableTypes(), queryTableName) + cri);
|
|
|
+ //设置自定义回传对象
|
|
|
+ sqlActiveData.setCallback(Sqls.callback.entity());
|
|
|
+ sqlActiveData.setEntity(dao.getEntity(ActiveDataTotalVO.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sqlActiveData);
|
|
|
+ //得到每日总计对象
|
|
|
+ ActiveDataTotalVO voActiveData = sqlActiveData.getObject(ActiveDataTotalVO.class);
|
|
|
+ //voActiveData有值时进行映射的取值处理
|
|
|
+ if (StringUtils.isNotBlank(voActiveData.getDa1())) {
|
|
|
+ //计算留存dayN数据
|
|
|
+ formatTotalDayN(voActiveData);
|
|
|
+ }
|
|
|
+ //将两个对象的属性结合
|
|
|
+ copyNullProperties(voActiveData, voGameData);
|
|
|
+ //返回
|
|
|
+ return voGameData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 所有为空值的属性都不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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏首日复充总计sql(首日复充数据部分)
|
|
|
+ *
|
|
|
+ * @param type 查询的类型 buy、nature、total
|
|
|
+ * @param tableName 表名
|
|
|
+ * @return String : 查询出来的结果 第n天的 充值金额/充值人数
|
|
|
+ */
|
|
|
+ private String activeDataTotalSql(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 ");
|
|
|
+ //90天数据
|
|
|
+ for (int day = 1; day <= 90; day++) {
|
|
|
+ trendDay.append("""
|
|
|
+ CONCAT( SUM(CAST(SPLIT_PART(%sda%s, '/', 1) AS BIGINT(20))), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= Local.now(), %sreg_num, 0))
|
|
|
+ ) AS da%s,
|
|
|
+ """.formatted(type, day, day-1, type, day));
|
|
|
+ }
|
|
|
+ //m4-m12数据
|
|
|
+ for (int month = 4; month <= 12; month++) {
|
|
|
+ trendDay.append("""
|
|
|
+ CONCAT( SUM(CAST(SPLIT_PART(%sm%s, '/', 1) AS BIGINT(20))), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL %s month) <= Local.now(), %sreg_num, 0))
|
|
|
+ ) AS m%s,
|
|
|
+ """.formatted(type, month, month, type, month));
|
|
|
+ }
|
|
|
+ //total数据
|
|
|
+ trendDay.append("""
|
|
|
+ CONCAT( SUM(CAST(SPLIT_PART(%stotal, '/', 1) AS BIGINT(20))), '/',
|
|
|
+ SUM(%sreg_num)
|
|
|
+ ) AS total
|
|
|
+ """.formatted(type, type));
|
|
|
+ trendDay.append("FROM game_ads.");
|
|
|
+ trendDay.append(tableName);
|
|
|
+
|
|
|
+ return trendDay.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过反射赋值留存数据dayN
|
|
|
+ * @param vo ActiveDataDayVO
|
|
|
+ */
|
|
|
+ private void formatDayN(ActiveDataDayVO vo) {
|
|
|
+ if (CollectionUtils.isEmpty(activeDataDayNFieldMapList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ activeDataDayNFieldMapList.forEach(dayNFieldMapList -> {
|
|
|
+ try {
|
|
|
+ String[] temps = ((String) dayNFieldMapList.getT1().get(vo)).split("/");
|
|
|
+ dayNFieldMapList.getT2().set(vo, ActiveDataTrendVO.builder()
|
|
|
+ .activeNum(Long.valueOf(temps[0]))
|
|
|
+ .activeRate(new BigDecimal(temps[1]))
|
|
|
+ .build());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过反射赋值留存数据总计的dayN
|
|
|
+ * 活跃人数/注册人数(去掉时间没到的数据)
|
|
|
+ * @param vo ActiveDataTotalVO
|
|
|
+ */
|
|
|
+ private void formatTotalDayN(ActiveDataTotalVO vo) {
|
|
|
+ if (CollectionUtils.isEmpty(activeDataDayNTotalFieldMapList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ activeDataDayNTotalFieldMapList.forEach(dayNFieldMapList -> {
|
|
|
+ try {
|
|
|
+ String[] temps = ((String) dayNFieldMapList.getT1().get(vo)).split("/");
|
|
|
+ //活跃人数
|
|
|
+ Long activeNum = Long.valueOf(temps[0]);
|
|
|
+ //注册人数
|
|
|
+ Long regNum = Long.valueOf(temps[1]);
|
|
|
+ dayNFieldMapList.getT2().set(vo, ActiveDataTrendVO.builder()
|
|
|
+ .activeNum(activeNum)
|
|
|
+ .activeRate(regNum == 0L ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(activeNum.doubleValue() / regNum.doubleValue()).setScale(4, RoundingMode.HALF_UP))
|
|
|
+ .build());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 留存每日数据sql
|
|
|
+ *
|
|
|
+ * @param type 查询的类型 buy -> 买量 ; nature -> 自然量 ; total -> 总量
|
|
|
+ * @param tableName 查询的表名
|
|
|
+ * @param cri 查询条件
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String getActiveDataDaySql(String type, String tableName, 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
|
|
|
+ """ + tableName + 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
|
|
|
+ """ + tableName + 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
|
|
|
+ """ + tableName + 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
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String getTotalGameData(String type) {
|
|
|
+ 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
|
|
|
+ ads_game_day
|
|
|
+ """;
|
|
|
+ } 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
|
|
|
+ ads_game_day
|
|
|
+ """;
|
|
|
+ }
|
|
|
+ //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
|
|
|
+ ads_game_day
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|