|
@@ -1,13 +1,38 @@
|
|
|
package com.zanxiang.game.data.serve.service.impl;
|
|
|
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.*;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsGamePitcherDay;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsPitcherGameDayn;
|
|
|
+import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
|
import com.zanxiang.game.data.serve.pojo.vo.*;
|
|
|
import com.zanxiang.game.data.serve.service.IPitcherDataService;
|
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
|
+import com.zanxiang.module.util.DateUtil;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.dubbo.common.utils.CollectionUtils;
|
|
|
+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.nutz.dao.util.Daos;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
+import reactor.util.function.Tuples;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Modifier;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
* @author tianhua
|
|
@@ -17,6 +42,79 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class PitcherDataServiceImpl implements IPitcherDataService {
|
|
|
+
|
|
|
+ private static final List<Tuple2<Field, Field>> dayNFieldMapList;
|
|
|
+
|
|
|
+ private static final List<Tuple2<Field, Field>> dayNTotalFieldMapList;
|
|
|
+
|
|
|
+ static {
|
|
|
+
|
|
|
+ Map<String, Field> fieldMap = new HashMap<>();
|
|
|
+ List<Field> dayNFieldList = new ArrayList<>();
|
|
|
+ Class<?> tempClazz = PitcherGameDataDayVO.class;
|
|
|
+ while (tempClazz != null) {
|
|
|
+ Field[] fields = tempClazz.getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fieldMap.put(field.getName(), field);
|
|
|
+ if (field.getType() == RechargeTrendVO.class) {
|
|
|
+
|
|
|
+ dayNFieldList.add(field);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempClazz = tempClazz.getSuperclass();
|
|
|
+ }
|
|
|
+ if (dayNFieldList.isEmpty()) {
|
|
|
+ dayNFieldMapList = Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ dayNFieldMapList = new ArrayList<>(dayNFieldList.size());
|
|
|
+ for (Field field : dayNFieldList) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ Field sourceField = fieldMap.get(field.getName().replace("Trend", ""));
|
|
|
+ sourceField.setAccessible(true);
|
|
|
+ if (sourceField != null) {
|
|
|
+ dayNFieldMapList.add(Tuples.of(sourceField, field));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Field> fieldTotalMap = new HashMap<>();
|
|
|
+ List<Field> dayNTotalFieldList = new ArrayList<>();
|
|
|
+ Class<?> tempTotalClazz = PitcherGameDataDayTotalVO.class;
|
|
|
+ while (tempTotalClazz != null) {
|
|
|
+ Field[] fields = tempTotalClazz.getDeclaredFields();
|
|
|
+ for (Field field : fields) {
|
|
|
+ if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ fieldTotalMap.put(field.getName(), field);
|
|
|
+ if (field.getType() == RechargeTrendVO.class) {
|
|
|
+
|
|
|
+ dayNTotalFieldList.add(field);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempTotalClazz = tempTotalClazz.getSuperclass();
|
|
|
+ }
|
|
|
+ if (dayNTotalFieldList.isEmpty()) {
|
|
|
+ dayNTotalFieldMapList = Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ dayNTotalFieldMapList = new ArrayList<>(dayNTotalFieldList.size());
|
|
|
+ for (Field field : dayNTotalFieldList) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ Field sourceField = fieldTotalMap.get(field.getName().replace("Trend", ""));
|
|
|
+ sourceField.setAccessible(true);
|
|
|
+ if (sourceField != null) {
|
|
|
+ dayNTotalFieldMapList.add(Tuples.of(sourceField, field));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
@Autowired
|
|
|
private Dao dao;
|
|
@@ -68,7 +166,61 @@ public class PitcherDataServiceImpl implements IPitcherDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<PitcherGameDataDayVO> getPitcherGameDataDay(PitcherGameDataDayDTO dto) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ if (dto.getBeginDate() == null || dto.getEndDate() == null ) {
|
|
|
+ dto.setBeginDate(LocalDate.now());
|
|
|
+ dto.setEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())) {
|
|
|
+ dto.setSortFiled("dt");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())) {
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
+ }
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+ cri.where().andBetween("dt", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameCp())) {
|
|
|
+ cri.where().andEquals("game_cp", dto.getGameCp());
|
|
|
+ }
|
|
|
+ if (dto.getGameType() != null) {
|
|
|
+ cri.where().andEquals("game_type", dto.getGameType());
|
|
|
+ }
|
|
|
+
|
|
|
+ cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
|
|
|
+
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
+
|
|
|
+ Sql sql = Sqls.create(pitcherGameDataDaySql() + cri);
|
|
|
+
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
+ sql.setEntity(dao.getEntity(PitcherGameDataDayVO.class));
|
|
|
+
|
|
|
+ sql.setPager(pager);
|
|
|
+
|
|
|
+ dao.execute(sql);
|
|
|
+
|
|
|
+ pager.setRecordCount(dao.count(AdsGamePitcherDay.class, cri));
|
|
|
+
|
|
|
+ List<PitcherGameDataDayVO> tempList = sql.getList(PitcherGameDataDayVO.class);
|
|
|
+ List<PitcherGameDataDayVO> list = tempList.stream().map(vo -> {
|
|
|
+ formatPitcherGameDataDayDayN(vo);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new Page<>(list, pager);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -78,7 +230,45 @@ public class PitcherDataServiceImpl implements IPitcherDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public PitcherGameDataDayTotalVO getPitcherGameDataDayTotal(PitcherGameDataDayTotalDTO dto) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ if (dto.getBeginDate() == null || dto.getEndDate() == null ) {
|
|
|
+ dto.setBeginDate(LocalDate.now());
|
|
|
+ dto.setEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+ cri.where().andBetween("dt", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameCp())) {
|
|
|
+ cri.where().andEquals("game_cp", dto.getGameCp());
|
|
|
+ }
|
|
|
+ if (dto.getGameType() != null) {
|
|
|
+ cri.where().andEquals("game_type", dto.getGameType());
|
|
|
+ }
|
|
|
+
|
|
|
+ Sql sql = Sqls.create(pitcherGameDataDayTotalSql() + cri);
|
|
|
+
|
|
|
+ sql.setCallback(Sqls.callback.entity());
|
|
|
+ sql.setEntity(dao.getEntity(PitcherGameDataDayTotalVO.class));
|
|
|
+
|
|
|
+ dao.execute(sql);
|
|
|
+ PitcherGameDataDayTotalVO vo = sql.getObject(PitcherGameDataDayTotalVO.class);
|
|
|
+ if (StringUtils.isNotBlank(vo.getAmountD1())) {
|
|
|
+
|
|
|
+ formatPitcherGameDataDayTotalDayN(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -88,7 +278,93 @@ public class PitcherDataServiceImpl implements IPitcherDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<PitcherGameDataTotalVO> getPitcherGameDataTotal(PitcherGameDataTotalDTO dto) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ if (dto.getBeginDate() == null || dto.getEndDate() == null) {
|
|
|
+ dto.setBeginDate(LocalDate.now());
|
|
|
+ dto.setEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dto.getAmountBeginDate() == null || dto.getAmountEndDate() == null) {
|
|
|
+ dto.setAmountBeginDate(LocalDate.now());
|
|
|
+ dto.setAmountEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+
|
|
|
+ Criteria criA = myCri(dto, "criA");
|
|
|
+
|
|
|
+ Criteria criB = myCri(dto, "criB");
|
|
|
+
|
|
|
+ Criteria criAmount = myCriRecharge(dto, false);
|
|
|
+
|
|
|
+ Criteria criNewUser = myCriRecharge(dto, true);
|
|
|
+
|
|
|
+ Criteria criRoleNum = myCriRole(dto);
|
|
|
+
|
|
|
+ Criteria orderByCri = Cnd.cri();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())) {
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())) {
|
|
|
+ orderByCri.getOrderBy().orderBy("pitcher_id", 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 = Sqls.create(pitcherGameDataTotalSql(criA, criB, criAmount, criNewUser, criRoleNum) + orderByCri);
|
|
|
+
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
+ sql.setEntity(dao.getEntity(PitcherGameDataTotalVO.class));
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
+ sql.setPager(pager);
|
|
|
+
|
|
|
+ dao.execute(sql);
|
|
|
+
|
|
|
+ List<PitcherGameDataTotalVO> list = sql.getList(PitcherGameDataTotalVO.class);
|
|
|
+
|
|
|
+ Sql sqlCount = Sqls.queryEntity("select count(*) from game_ads.ads_game_pitcher_day" + criA);
|
|
|
+ pager.setRecordCount((int) Daos.queryCount(dao, sqlCount));
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Map<String, String>> pitcherGameDataTotalDayNMap = tempDayNData(dto);
|
|
|
+
|
|
|
+ List<PitcherGameDataTotalVO> pitcherGameDataTotalVOList = list.stream().map(vo -> {
|
|
|
+
|
|
|
+ Map<String, String> gameIDToDayNData = pitcherGameDataTotalDayNMap.get(vo.getPitcherId().toString());
|
|
|
+
|
|
|
+ String dayNStr;
|
|
|
+ if (CollectionUtils.isEmptyMap(gameIDToDayNData)) {
|
|
|
+ dayNStr = "0.00-0";
|
|
|
+ } else {
|
|
|
+ dayNStr = gameIDToDayNData.get(vo.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dayNStr)) {
|
|
|
+ dayNStr = "0.00-0";
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setNewUserAmount(new BigDecimal(dayNStr.split("-")[0]));
|
|
|
+
|
|
|
+ vo.setNewUserAmountCount(Long.parseLong(dayNStr.split("-")[1]));
|
|
|
+
|
|
|
+ vo.setOldAmount(vo.getAmount().subtract(vo.getNewUserAmount()));
|
|
|
+ vo.setOldAmountCount(vo.getAmountCount() - vo.getNewUserAmountCount());
|
|
|
+ vo.setOldAmountNum(vo.getAmountNum() - vo.getNewUserAmountNum());
|
|
|
+
|
|
|
+ vo.setNewUserRoi(vo.getCost().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ vo.getNewUserAmount().divide(vo.getCost(), 4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ vo.setNewUserAvg(vo.getNewUserAmountCount() == 0L ? BigDecimal.ZERO :
|
|
|
+ vo.getNewUserAmount().divide(BigDecimal.valueOf(vo.getNewUserAmountCount()), 4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ vo.setNewUserArpu(vo.getNewUserAmountNum() == 0L ? BigDecimal.ZERO :
|
|
|
+ vo.getNewUserAmount().divide(BigDecimal.valueOf(vo.getNewUserAmountNum()), 4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return new Page<>(pitcherGameDataTotalVOList, pager);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -101,4 +377,955 @@ public class PitcherDataServiceImpl implements IPitcherDataService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 主表 账面相关 查询条件
|
|
|
+ *
|
|
|
+ * @param dto 前端传递的查询条件
|
|
|
+ * @param type criA 查询主表 criB 查询账面相关
|
|
|
+ * @return 查询条件
|
|
|
+ */
|
|
|
+ private Criteria myCri(PitcherGameDataTotalDTO dto, String type) {
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameCp())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("game_cp", dto.getGameCp());
|
|
|
+ }
|
|
|
+ if (dto.getGameType() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("game_type", dto.getGameType());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type.equals("criA")) {
|
|
|
+ if (dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("dt", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ } else if (type.equals("criB")) {
|
|
|
+ if (dto.getAmountBeginDate() != null && dto.getAmountEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("dt", dto.getAmountBeginDate(), dto.getAmountEndDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cri.getGroupBy().groupBy("game_id", "pitcher_id");
|
|
|
+
|
|
|
+ return cri;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 账面充值人数、新用户充值人数、新用户复充人数的查询条件
|
|
|
+ *
|
|
|
+ * @param dto 前端传递的查询条件参数实体
|
|
|
+ * @param needRegTime 是否需要拼接注册时间
|
|
|
+ * @return 查询条件
|
|
|
+ */
|
|
|
+ private Criteria myCriRecharge(PitcherGameDataTotalDTO dto, Boolean needRegTime) {
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameCp())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("cp_name", dto.getGameCp());
|
|
|
+ }
|
|
|
+ if (dto.getGameType() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("classify", dto.getGameType());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needRegTime && dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("reg_time", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ if (dto.getAmountBeginDate() != null && dto.getAmountEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("order_time", dto.getAmountBeginDate(), dto.getAmountEndDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ return cri;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 创角人数相关查询条件
|
|
|
+ *
|
|
|
+ * @param dto 前端传递的查询条件
|
|
|
+ * @return 查询条件
|
|
|
+ */
|
|
|
+ private Criteria myCriRole(PitcherGameDataTotalDTO dto) {
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("user_game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameCp())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("cp_name", dto.getGameCp());
|
|
|
+ }
|
|
|
+ if (dto.getGameType() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("user_game_classify", dto.getGameType());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+
|
|
|
+ cri.where().andEquals("user_zx_pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+ if (dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("user_dt", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ if (dto.getAmountBeginDate() != null && dto.getAmountEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("DATE(role_create_time)", dto.getAmountBeginDate(), dto.getAmountEndDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ return cri;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 生成DayN数据方法
|
|
|
+ *
|
|
|
+ * @param dto 前端查询参数
|
|
|
+ * @return Map
|
|
|
+ */
|
|
|
+ private Map<String, Map<String, String>> tempDayNData(PitcherGameDataTotalDTO dto) {
|
|
|
+
|
|
|
+
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (dto.getBeginDate() != null && dto.getEndDate() != null) {
|
|
|
+
|
|
|
+ cri.where().andBetween("dt", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ }
|
|
|
+ Sql dayNSql = Sqls.create("""
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ game_id,
|
|
|
+ pitcher_id,
|
|
|
+ source_system,
|
|
|
+ dayN
|
|
|
+ FROM
|
|
|
+ game_ads.ads_pitcher_game_dayn
|
|
|
+ """ + cri);
|
|
|
+
|
|
|
+
|
|
|
+ dayNSql.setCallback(Sqls.callback.entities());
|
|
|
+ dayNSql.setEntity(dao.getEntity(AdsPitcherGameDayn.class));
|
|
|
+
|
|
|
+ dao.execute(dayNSql);
|
|
|
+
|
|
|
+
|
|
|
+ List<AdsPitcherGameDayn> list = dayNSql.getList(AdsPitcherGameDayn.class);
|
|
|
+
|
|
|
+ Map<String, Map<String, String>> tempMap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ for (AdsPitcherGameDayn adsPitcherGameDayn : list) {
|
|
|
+ if (!tempMap.containsKey(adsPitcherGameDayn.getPitcherId())) {
|
|
|
+
|
|
|
+ Map<String, String> resMap = new HashMap<>();
|
|
|
+
|
|
|
+ tempMap.put(adsPitcherGameDayn.getPitcherId(), resMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> resMap = tempMap.get(adsPitcherGameDayn.getPitcherId());
|
|
|
+ if (!resMap.containsKey(adsPitcherGameDayn.getGameId())) {
|
|
|
+
|
|
|
+ resMap.put(adsPitcherGameDayn.getGameId(), "0.00-0");
|
|
|
+ }
|
|
|
+
|
|
|
+ parseJsonData(adsPitcherGameDayn, resMap, dto);
|
|
|
+
|
|
|
+ tempMap.put(adsPitcherGameDayn.getPitcherId(), resMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ return tempMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 解析dayN json字符串数据
|
|
|
+ *
|
|
|
+ * @param adsPitcherGameDayn 对象
|
|
|
+ * @param resMap 记录最终结果Map
|
|
|
+ * @param dto 前端查询条件
|
|
|
+ */
|
|
|
+ private void parseJsonData(AdsPitcherGameDayn adsPitcherGameDayn, Map<String, String> resMap, PitcherGameDataTotalDTO dto) {
|
|
|
+
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Map<String, String> jsonList = gson.fromJson(adsPitcherGameDayn.getDayn(), Map.class);
|
|
|
+
|
|
|
+ for (Map.Entry<String, String> entry : jsonList.entrySet()) {
|
|
|
+
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+
|
|
|
+ String[] resValues = value.split("-");
|
|
|
+
|
|
|
+ if (DateUtil.parseLocalDate(key).compareTo(dto.getAmountBeginDate()) >= 0
|
|
|
+ && DateUtil.parseLocalDate(key).compareTo(dto.getAmountEndDate()) <= 0) {
|
|
|
+
|
|
|
+ String[] oldValues = resMap.get(adsPitcherGameDayn.getGameId()).split("-");
|
|
|
+
|
|
|
+ BigDecimal chargeMoney = new BigDecimal(oldValues[0]).add(new BigDecimal(resValues[0])).setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ long count = Long.parseLong(oldValues[1]) + Long.parseLong(resValues[1]);
|
|
|
+
|
|
|
+ String newValue = chargeMoney + "-" + count;
|
|
|
+ resMap.put(adsPitcherGameDayn.getGameId(), newValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 处理DayN
|
|
|
+ *
|
|
|
+ * @param vo PitcherGameDataDayVO
|
|
|
+ */
|
|
|
+ private void formatPitcherGameDataDayDayN(PitcherGameDataDayVO vo) {
|
|
|
+ if (CollectionUtils.isEmpty(dayNFieldMapList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dayNFieldMapList.forEach(dayNFieldMap -> {
|
|
|
+ try {
|
|
|
+ String[] temps = ((String) dayNFieldMap.getT1().get(vo)).split("/");
|
|
|
+ dayNFieldMap.getT2().set(vo, RechargeTrendVO.builder()
|
|
|
+ .rechargeMoney(new BigDecimal(temps[0]))
|
|
|
+ .rechargeUserCount(Long.valueOf(temps[1]))
|
|
|
+ .increase(new BigDecimal(temps[2]))
|
|
|
+ .back(new BigDecimal(temps[3]))
|
|
|
+ .multiples(new BigDecimal(temps[4]))
|
|
|
+ .build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException("映射出错");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 处理DayN
|
|
|
+ *
|
|
|
+ * @param vo PitcherGameDataDayTotalVO
|
|
|
+ */
|
|
|
+ private void formatPitcherGameDataDayTotalDayN(PitcherGameDataDayTotalVO vo) {
|
|
|
+ if (CollectionUtils.isEmpty(dayNTotalFieldMapList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dayNTotalFieldMapList.forEach(dayNTotalFieldMap -> {
|
|
|
+ try {
|
|
|
+
|
|
|
+ String[] temps = ((String) dayNTotalFieldMap.getT1().get(vo)).split("/");
|
|
|
+
|
|
|
+ BigDecimal dNAmount = new BigDecimal(temps[0]);
|
|
|
+
|
|
|
+ BigDecimal d1ToDNTotalAmount = new BigDecimal(temps[1]);
|
|
|
+
|
|
|
+ BigDecimal d1ToDNTotalCost = new BigDecimal(temps[3]);
|
|
|
+
|
|
|
+ BigDecimal d1Amount = new BigDecimal(temps[4]);
|
|
|
+
|
|
|
+ dayNTotalFieldMap.getT2().set(vo, RechargeTrendVO.builder()
|
|
|
+ .rechargeMoney(dNAmount)
|
|
|
+ .rechargeUserCount(Long.valueOf(temps[2]))
|
|
|
+ .increase(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ dNAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
|
|
|
+ .back(d1ToDNTotalCost.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ d1ToDNTotalAmount.divide(d1ToDNTotalCost, 4, RoundingMode.HALF_UP))
|
|
|
+ .multiples(d1Amount.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ d1ToDNTotalAmount.divide(d1Amount, 4, RoundingMode.HALF_UP))
|
|
|
+ .build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException("映射出错");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询投手游戏每日数据SQL
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String pitcherGameDataDaySql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ source_system,
|
|
|
+ pitcher_id,
|
|
|
+ game_id,
|
|
|
+ pitcher,
|
|
|
+ game_name,
|
|
|
+ game_cp,
|
|
|
+ game_type,
|
|
|
+ cost,
|
|
|
+ plan_count,
|
|
|
+ account_count,
|
|
|
+ agent_count,
|
|
|
+ register_num,
|
|
|
+ first_new_user_amount_count,
|
|
|
+ first_new_user_amount_num,
|
|
|
+ first_new_user_amount,
|
|
|
+ amount_count,
|
|
|
+ amount_num,
|
|
|
+ amount,
|
|
|
+ old_amount_count,
|
|
|
+ old_amount_num,
|
|
|
+ old_amount,
|
|
|
+ new_user_total_amount_count,
|
|
|
+ new_user_total_amount_num,
|
|
|
+ new_user_total_amount,
|
|
|
+ hundred_user_num,
|
|
|
+ buy_new_user_total_amount,
|
|
|
+ buy_new_user_total_amount_num,
|
|
|
+ buy_new_user_total_amount_count,
|
|
|
+ reg_order_user_again,
|
|
|
+ first_role_num,
|
|
|
+ new_user_total_role_num,
|
|
|
+ role_num,
|
|
|
+ register_cost,
|
|
|
+ first_roi,
|
|
|
+ buy_roi,
|
|
|
+ today_roi,
|
|
|
+ gross_profit,
|
|
|
+ first_rate,
|
|
|
+ buy_user_rate,
|
|
|
+ today_rate,
|
|
|
+ first_avg,
|
|
|
+ buy_avg,
|
|
|
+ today_avg,
|
|
|
+ paper_avg,
|
|
|
+ first_amount_cost,
|
|
|
+ buy_amount_cost,
|
|
|
+ today_amount_cost,
|
|
|
+ today_again_rate,
|
|
|
+ new_reg_arpu,
|
|
|
+ first_arpu,
|
|
|
+ today_arpu,
|
|
|
+ paper_arpu,
|
|
|
+ hundred_user_num_cost,
|
|
|
+ roi1,
|
|
|
+ roi2,
|
|
|
+ roi3,
|
|
|
+ roi4,
|
|
|
+ roi5,
|
|
|
+ roi6,
|
|
|
+ roi7,
|
|
|
+ roi8,
|
|
|
+ roi9,
|
|
|
+ roi10,
|
|
|
+ roi11,
|
|
|
+ roi12,
|
|
|
+ roi13,
|
|
|
+ roi14,
|
|
|
+ roi15,
|
|
|
+ roi16,
|
|
|
+ roi17,
|
|
|
+ roi18,
|
|
|
+ roi19,
|
|
|
+ roi20,
|
|
|
+ roi21,
|
|
|
+ roi22,
|
|
|
+ roi23,
|
|
|
+ roi24,
|
|
|
+ roi25,
|
|
|
+ roi26,
|
|
|
+ roi27,
|
|
|
+ roi28,
|
|
|
+ roi29,
|
|
|
+ roi30,
|
|
|
+ roi60,
|
|
|
+ roi90,
|
|
|
+ roi180,
|
|
|
+ roi1yaer,
|
|
|
+ roi_total,
|
|
|
+ amount_d1,
|
|
|
+ amount_d2,
|
|
|
+ amount_d3,
|
|
|
+ amount_d4,
|
|
|
+ amount_d5,
|
|
|
+ amount_d6,
|
|
|
+ amount_d7,
|
|
|
+ amount_d8,
|
|
|
+ amount_d9,
|
|
|
+ amount_d10,
|
|
|
+ amount_d11,
|
|
|
+ amount_d12,
|
|
|
+ amount_d13,
|
|
|
+ amount_d14,
|
|
|
+ amount_d15,
|
|
|
+ amount_d16,
|
|
|
+ amount_d17,
|
|
|
+ amount_d18,
|
|
|
+ amount_d19,
|
|
|
+ amount_d20,
|
|
|
+ amount_d21,
|
|
|
+ amount_d22,
|
|
|
+ amount_d23,
|
|
|
+ amount_d24,
|
|
|
+ amount_d25,
|
|
|
+ amount_d26,
|
|
|
+ amount_d27,
|
|
|
+ amount_d28,
|
|
|
+ amount_d29,
|
|
|
+ amount_m1,
|
|
|
+ amount_m2,
|
|
|
+ amount_m3,
|
|
|
+ amount_m6,
|
|
|
+ amount_y1,
|
|
|
+ amount_sum,
|
|
|
+ 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,
|
|
|
+ m2,
|
|
|
+ m3,
|
|
|
+ m6,
|
|
|
+ y1,
|
|
|
+ total,
|
|
|
+ da1_num,
|
|
|
+ da2_num,
|
|
|
+ da3_num,
|
|
|
+ da4_num,
|
|
|
+ da5_num,
|
|
|
+ da6_num,
|
|
|
+ da7_num,
|
|
|
+ da8_num,
|
|
|
+ da9_num,
|
|
|
+ da10_num,
|
|
|
+ da11_num,
|
|
|
+ da12_num,
|
|
|
+ da13_num,
|
|
|
+ da14_num,
|
|
|
+ da15_num,
|
|
|
+ da16_num,
|
|
|
+ da17_num,
|
|
|
+ da18_num,
|
|
|
+ da19_num,
|
|
|
+ da20_num,
|
|
|
+ da21_num,
|
|
|
+ da22_num,
|
|
|
+ da23_num,
|
|
|
+ da24_num,
|
|
|
+ da25_num,
|
|
|
+ da26_num,
|
|
|
+ da27_num,
|
|
|
+ da28_num,
|
|
|
+ da29_num,
|
|
|
+ da30_num,
|
|
|
+ m2_num,
|
|
|
+ m3_num,
|
|
|
+ m6_num,
|
|
|
+ y1_num,
|
|
|
+ total_num,
|
|
|
+ first_role_cost,
|
|
|
+ new_user_total_role_cost,
|
|
|
+ role_num_cost,
|
|
|
+ first_role_rate,
|
|
|
+ new_user_total_role_rate,
|
|
|
+ role_num_rate,
|
|
|
+ new_user_amount_ratio
|
|
|
+ FROM
|
|
|
+ game_ads.ads_game_pitcher_day
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询投手游戏每日数据总计SQL
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String pitcherGameDataDayTotalSql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ SUM(cost) as cost,
|
|
|
+ SUM(plan_count) as plan_count,
|
|
|
+ SUM(account_count) as account_count,
|
|
|
+ SUM(agent_count) as agent_count,
|
|
|
+ SUM(register_num) as register_num,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(cost) / SUM(register_num), 0), 2) as register_cost,
|
|
|
+ SUM(first_role_num) as first_role_num,
|
|
|
+ SUM(new_user_total_role_num) as new_user_total_role_num,
|
|
|
+ SUM(role_num) as role_num,
|
|
|
+ ROUND(IF(SUM(role_num) > 0 , SUM(cost) / SUM(role_num), 0), 2) as role_num_cost,
|
|
|
+ ROUND(IF(SUM(first_role_num) > 0 , SUM(cost) / SUM(first_role_num), 0), 2) as first_role_cost,
|
|
|
+ ROUND(IF(SUM(new_user_total_role_num) > 0 , SUM(cost) / SUM(new_user_total_role_num), 0), 2) as new_user_total_role_cost,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(first_role_num) / SUM(register_num), 0), 4) as first_role_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(new_user_total_role_num) / SUM(register_num), 0), 4) as new_user_total_role_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(role_num) / SUM(register_num), 0), 4) as role_num_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(amount_count) as amount_count,
|
|
|
+ SUM(amount_num) as amount_num,
|
|
|
+ SUM(amount) as amount,
|
|
|
+ SUM(old_amount_count) as old_amount_count,
|
|
|
+ SUM(old_amount_num) as old_amount_num,
|
|
|
+ SUM(old_amount) as old_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,
|
|
|
+ SUM(buy_new_user_total_amount) as buy_new_user_total_amount,
|
|
|
+ SUM(buy_new_user_total_amount_num) as buy_new_user_total_amount_num,
|
|
|
+ SUM(buy_new_user_total_amount_count) as buy_new_user_total_amount_count,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(first_new_user_amount) / SUM(cost), 0), 4) as first_roi,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) as buy_roi,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) as today_roi,
|
|
|
+ (SUM(new_user_total_amount) - SUM(cost)) as gross_profit,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(first_new_user_amount_num) / SUM(register_num), 0), 4) as first_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(register_num), 0), 4) as buy_user_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(new_user_total_amount_num) / SUM(register_num), 0), 4) as today_rate,
|
|
|
+ ROUND(IF(SUM(amount_num) > 0, SUM(first_new_user_amount_num) / SUM(amount_num), 0), 4) as new_user_amount_ratio,
|
|
|
+ ROUND(IF(SUM(first_new_user_amount_count) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) as first_avg,
|
|
|
+ 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) as buy_avg,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_count) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as today_avg,
|
|
|
+ ROUND(IF(SUM(amount_count) > 0 , SUM(amount) / SUM(amount_count), 0), 2) as paper_avg,
|
|
|
+ ROUND(IF(SUM(first_new_user_amount_num) > 0 , SUM(cost) / SUM(first_new_user_amount_num), 0), 2) as first_amount_cost,
|
|
|
+ ROUND(IF(SUM(buy_new_user_total_amount_num) > 0 , SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) as buy_amount_cost,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 , SUM(cost) / SUM(new_user_total_amount_num), 0), 2) as today_amount_cost,
|
|
|
+ SUM(reg_order_user_again) as reg_order_user_again,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 ,SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) as today_again_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(new_user_total_amount) / SUM(register_num), 0), 2) as new_reg_arpu,
|
|
|
+ ROUND(IF(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) as first_arpu,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) as today_arpu,
|
|
|
+ ROUND(IF(SUM(amount_num) > 0 , SUM(amount) / SUM(amount_num), 0), 2) as paper_arpu,
|
|
|
+ SUM(hundred_user_num) as hundred_user_num,
|
|
|
+ ROUND(IF(SUM(hundred_user_num) > 0 , SUM(cost) / SUM(hundred_user_num), 0), 2) as hundred_user_num_cost,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da1) / SUM(cost), 0), 4) as roi1,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da2) / SUM(cost), 0), 4) as roi2,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da3) / SUM(cost), 0), 4) as roi3,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da4) / SUM(cost), 0), 4) as roi4,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da5) / SUM(cost), 0), 4) as roi5,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da6) / SUM(cost), 0), 4) as roi6,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da7) / SUM(cost), 0), 4) as roi7,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da8) / SUM(cost), 0), 4) as roi8,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da9) / SUM(cost), 0), 4) as roi9,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da10) / SUM(cost), 0), 4) as roi10,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da11) / SUM(cost), 0), 4) as roi11,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da12) / SUM(cost), 0), 4) as roi12,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da13) / SUM(cost), 0), 4) as roi13,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da14) / SUM(cost), 0), 4) as roi14,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da15) / SUM(cost), 0), 4) as roi15,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da16) / SUM(cost), 0), 4) as roi16,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da17) / SUM(cost), 0), 4) as roi17,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da18) / SUM(cost), 0), 4) as roi18,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da19) / SUM(cost), 0), 4) as roi19,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da20) / SUM(cost), 0), 4) as roi20,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da21) / SUM(cost), 0), 4) as roi21,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da22) / SUM(cost), 0), 4) as roi22,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da23) / SUM(cost), 0), 4) as roi23,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da24) / SUM(cost), 0), 4) as roi24,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da25) / SUM(cost), 0), 4) as roi25,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da26) / SUM(cost), 0), 4) as roi26,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da27) / SUM(cost), 0), 4) as roi27,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da28) / SUM(cost), 0), 4) as roi28,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da29) / SUM(cost), 0), 4) as roi29,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da30) / SUM(cost), 0), 4) as roi30,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m2) / SUM(cost), 0), 4) as roi60,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m3) / SUM(cost), 0), 4) as roi90,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m6) / SUM(cost), 0), 4) as roi180,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(y1) / SUM(cost), 0), 4) as roi1yaer,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(total) / SUM(cost), 0), 4) as roi_total,
|
|
|
+ SUM(da1) as da1,
|
|
|
+ SUM(da2) as da2,
|
|
|
+ SUM(da3) as da3,
|
|
|
+ SUM(da4) as da4,
|
|
|
+ SUM(da5) as da5,
|
|
|
+ SUM(da6) as da6,
|
|
|
+ SUM(da7) as da7,
|
|
|
+ SUM(da8) as da8,
|
|
|
+ SUM(da9) as da9,
|
|
|
+ SUM(da10) as da10,
|
|
|
+ SUM(da11) as da11,
|
|
|
+ SUM(da12) as da12,
|
|
|
+ SUM(da13) as da13,
|
|
|
+ SUM(da14) as da14,
|
|
|
+ SUM(da15) as da15,
|
|
|
+ SUM(da16) as da16,
|
|
|
+ SUM(da17) as da17,
|
|
|
+ SUM(da18) as da18,
|
|
|
+ SUM(da19) as da19,
|
|
|
+ SUM(da20) as da20,
|
|
|
+ SUM(da21) as da21,
|
|
|
+ SUM(da22) as da22,
|
|
|
+ SUM(da23) as da23,
|
|
|
+ SUM(da24) as da24,
|
|
|
+ SUM(da25) as da25,
|
|
|
+ SUM(da26) as da26,
|
|
|
+ SUM(da27) as da27,
|
|
|
+ SUM(da28) as da28,
|
|
|
+ SUM(da29) as da29,
|
|
|
+ SUM(da30) as da30,
|
|
|
+ SUM(m2) as m2,
|
|
|
+ SUM(m3) as m3,
|
|
|
+ SUM(m6) as m6,
|
|
|
+ SUM(y1) as y1,
|
|
|
+ SUM(total) as total,
|
|
|
+ SUM(da1_num) as da1_num,
|
|
|
+ SUM(da2_num) as da2_num,
|
|
|
+ SUM(da3_num) as da3_num,
|
|
|
+ SUM(da4_num) as da4_num,
|
|
|
+ SUM(da5_num) as da5_num,
|
|
|
+ SUM(da6_num) as da6_num,
|
|
|
+ SUM(da7_num) as da7_num,
|
|
|
+ SUM(da8_num) as da8_num,
|
|
|
+ SUM(da9_num) as da9_num,
|
|
|
+ SUM(da10_num) as da10_num,
|
|
|
+ SUM(da11_num) as da11_num,
|
|
|
+ SUM(da12_num) as da12_num,
|
|
|
+ SUM(da13_num) as da13_num,
|
|
|
+ SUM(da14_num) as da14_num,
|
|
|
+ SUM(da15_num) as da15_num,
|
|
|
+ SUM(da16_num) as da16_num,
|
|
|
+ SUM(da17_num) as da17_num,
|
|
|
+ SUM(da18_num) as da18_num,
|
|
|
+ SUM(da19_num) as da19_num,
|
|
|
+ SUM(da20_num) as da20_num,
|
|
|
+ SUM(da21_num) as da21_num,
|
|
|
+ SUM(da22_num) as da22_num,
|
|
|
+ SUM(da23_num) as da23_num,
|
|
|
+ SUM(da24_num) as da24_num,
|
|
|
+ SUM(da25_num) as da25_num,
|
|
|
+ SUM(da26_num) as da26_num,
|
|
|
+ SUM(da27_num) as da27_num,
|
|
|
+ SUM(da28_num) as da28_num,
|
|
|
+ SUM(da29_num) as da29_num,
|
|
|
+ SUM(da30_num) as da30_num,
|
|
|
+ SUM(m2_num) as m2_num,
|
|
|
+ SUM(m3_num) as m3_num,
|
|
|
+ SUM(m6_num) as m6_num,
|
|
|
+ SUM(y1_num) as y1_num,
|
|
|
+ SUM(total_num) as total_num,
|
|
|
+ """ + getPitcherGameDataDayTotalDayNsql() +
|
|
|
+ """
|
|
|
+ FROM
|
|
|
+ game_ads.ads_game_pitcher_day
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 投手游戏每日数据总计付费趋势sql
|
|
|
+ * @return String : Dn的充值金额 / D1-Dn的充值总金额 / Dn的充值人数 /当前消耗(剔除不存在的天数数据) /D1充值金额总和(剔除不存在的天数数据)
|
|
|
+ */
|
|
|
+ private String getPitcherGameDataDayTotalDayNsql() {
|
|
|
+ StringBuilder totalDayN = new StringBuilder(StringUtils.EMPTY);
|
|
|
+ for (int day = 1; day <= 29 ; day++) {
|
|
|
+ totalDayN.append("""
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= LocalDate.now() , CAST(SPLIT_PART(amount_d%s , '/', 1) AS DECIMAL(10, 2)), 0 )),'/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_d%s, '/', 6) AS DECIMAL(10, 2))),'/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_d%s, '/', 2) AS BIGINT)),'/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= LocalDate.now(), cost, 0)),'/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL %s day) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_d%s ,
|
|
|
+ """.formatted(day - 1, day, day, day, day - 1, day - 1, day));
|
|
|
+ }
|
|
|
+ totalDayN.append("""
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 29 day) <= LocalDate.now() , CAST(SPLIT_PART(amount_m1 , '/', 1) AS DECIMAL(10, 2)), 0 )), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m1, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m1, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 29 day) <= LocalDate.now(), cost, 0)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 29 day) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_m1,
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 59 day) <= LocalDate.now() , CAST(SPLIT_PART(amount_m2 , '/', 1) AS DECIMAL(10, 2)), 0 )), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m2, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m2, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 59 day) <= LocalDate.now(), cost, 0)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 59 day) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_m2,
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 89 day) <= LocalDate.now() , CAST(SPLIT_PART(amount_m3 , '/', 1) AS DECIMAL(10, 2)), 0 )), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m3, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m3, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 89 day) <= LocalDate.now(), cost, 0)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 89 day) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_m3,
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 179 day) <= LocalDate.now() , CAST(SPLIT_PART(amount_m6 , '/', 1) AS DECIMAL(10, 2)), 0 )), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m6, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_m6, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 179 day) <= LocalDate.now(), cost, 0)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 179 day) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_m6,
|
|
|
+ CONCAT(
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 1 year) <= LocalDate.now() , CAST(SPLIT_PART(amount_y1 , '/', 1) AS DECIMAL(10, 2)), 0 )), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_y1, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_y1, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 1 year) <= LocalDate.now(), cost, 0)), '/',
|
|
|
+ SUM(IF(DATE_ADD(dt, INTERVAL 1 year) <= LocalDate.now(), CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)) , 0))
|
|
|
+ ) AS amount_y1,
|
|
|
+ CONCAT(
|
|
|
+ SUM(CAST(SPLIT_PART(amount_sum , '/', 1) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_sum, '/', 6) AS DECIMAL(10, 2))), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_sum, '/', 2) AS BIGINT)), '/',
|
|
|
+ SUM(cost), '/',
|
|
|
+ SUM(CAST(SPLIT_PART(amount_d1 , '/', 1) AS DECIMAL(10, 2)))
|
|
|
+ ) AS amount_sum
|
|
|
+ """);
|
|
|
+
|
|
|
+ return totalDayN.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询投手游戏总数据SQL
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String pitcherGameDataTotalSql(Criteria criA, Criteria criB, Criteria criAmount, Criteria criNewUser, Criteria criRoleNum) {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ a.*,
|
|
|
+ IFNULL(amount, 0) as amount,
|
|
|
+ IFNULL(amount_count, 0) as amount_count,
|
|
|
+ IFNULL(amount_num, 0) as amount_num,
|
|
|
+ IFNULL(paper_avg, 0) as paper_avg,
|
|
|
+ ROUND(IF(amount_num > 0 , IFNULL(amount, 0) / amount_num, 0), 2) as paper_arpu,
|
|
|
+ IFNULL(new_user_amount_num, 0) as new_user_amount_num,
|
|
|
+ ROUND(IF(new_user_amount_num > 0, IFNULL(cost, 0) / new_user_amount_num, 0), 2) as new_user_amount_cost,
|
|
|
+ ROUND(IF(register_num > 0, IFNULL(new_user_amount_num, 0) / register_num, 0), 4) as new_user_amount_rate,
|
|
|
+ ROUND(IF(amount_num > 0, IFNULL(new_user_amount_num, 0) / amount_num, 0), 4) as new_user_amount_ratio,
|
|
|
+ IFNULL(new_user_order_again, 0) as new_user_order_again,
|
|
|
+ ROUND(IF(new_user_total_amount_num > 0, IFNULL(new_user_order_again, 0) / new_user_total_amount_num, 0), 4) as new_user_again_rate,
|
|
|
+ IFNULL(role_num, 0) as role_num,
|
|
|
+ ROUND(IF(register_num > 0, IFNULL(role_num, 0) / register_num, 0), 4) as role_num_rate,
|
|
|
+ ROUND(IF(role_num > 0, IFNULL(cost, 0) / role_num, 0), 2) as role_num_cost
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ pitcher_id,
|
|
|
+ game_id,
|
|
|
+ MAX(pitcher) as pitcher,
|
|
|
+ MAX(game_name) as game_name,
|
|
|
+ MAX(game_cp) as game_cp,
|
|
|
+ MAX(game_type) as game_type,
|
|
|
+ SUM(cost) as cost,
|
|
|
+ SUM(plan_count) as plan_count,
|
|
|
+ SUM(account_count) as account_count,
|
|
|
+ SUM(agent_count) as agent_count,
|
|
|
+ SUM(register_num) as register_num,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(cost) / SUM(register_num), 0), 2) as register_cost,
|
|
|
+ SUM(first_role_num) as first_role_num,
|
|
|
+ SUM(new_user_total_role_num) as new_user_total_role_num,
|
|
|
+ ROUND(IF(SUM(first_role_num) > 0 , SUM(cost) / SUM(first_role_num), 0), 2) as first_role_cost,
|
|
|
+ ROUND(IF(SUM(new_user_total_role_num) > 0 , SUM(cost) / SUM(new_user_total_role_num), 0), 2) as new_user_total_role_cost,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(first_role_num) / SUM(register_num), 0), 4) as first_role_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(new_user_total_role_num) / SUM(register_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,
|
|
|
+ SUM(buy_new_user_total_amount) as buy_new_user_total_amount,
|
|
|
+ SUM(buy_new_user_total_amount_num) as buy_new_user_total_amount_num,
|
|
|
+ SUM(buy_new_user_total_amount_count) as buy_new_user_total_amount_count,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(first_new_user_amount) / SUM(cost), 0), 4) as first_roi,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) as buy_roi,
|
|
|
+ ROUND(IF(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) as today_roi,
|
|
|
+ (SUM(new_user_total_amount) - SUM(cost)) as gross_profit,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(first_new_user_amount_num) / SUM(register_num), 0), 4) as first_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(register_num), 0), 4) as buy_user_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0, SUM(new_user_total_amount_num) / SUM(register_num), 0), 4) as today_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_avg,
|
|
|
+ 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) as buy_avg,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_count) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) as today_avg,
|
|
|
+ ROUND(IF(SUM(first_new_user_amount_num) > 0 , SUM(cost) / SUM(first_new_user_amount_num), 0), 2) as first_amount_cost,
|
|
|
+ ROUND(IF(SUM(buy_new_user_total_amount_num) > 0 , SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) as buy_amount_cost,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 , SUM(cost) / SUM(new_user_total_amount_num), 0), 2) as today_amount_cost,
|
|
|
+ SUM(reg_order_user_again) as reg_order_user_again,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 ,SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) as today_again_rate,
|
|
|
+ ROUND(IF(SUM(register_num) > 0 , SUM(new_user_total_amount) / SUM(register_num), 0), 2) as new_reg_arpu,
|
|
|
+ ROUND(IF(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) as first_arpu,
|
|
|
+ ROUND(IF(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) as today_arpu,
|
|
|
+ SUM(hundred_user_num) as hundred_user_num,
|
|
|
+ ROUND(IF(SUM(hundred_user_num) > 0 , SUM(cost) / SUM(hundred_user_num), 0), 2) as hundred_user_num_cost,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da1) / SUM(cost), 0), 4) as roi1,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da2) / SUM(cost), 0), 4) as roi2,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da3) / SUM(cost), 0), 4) as roi3,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da4) / SUM(cost), 0), 4) as roi4,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da5) / SUM(cost), 0), 4) as roi5,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da6) / SUM(cost), 0), 4) as roi6,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da7) / SUM(cost), 0), 4) as roi7,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da8) / SUM(cost), 0), 4) as roi8,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da9) / SUM(cost), 0), 4) as roi9,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da10) / SUM(cost), 0), 4) as roi10,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da11) / SUM(cost), 0), 4) as roi11,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da12) / SUM(cost), 0), 4) as roi12,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da13) / SUM(cost), 0), 4) as roi13,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da14) / SUM(cost), 0), 4) as roi14,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da15) / SUM(cost), 0), 4) as roi15,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da16) / SUM(cost), 0), 4) as roi16,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da17) / SUM(cost), 0), 4) as roi17,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da18) / SUM(cost), 0), 4) as roi18,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da19) / SUM(cost), 0), 4) as roi19,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da20) / SUM(cost), 0), 4) as roi20,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da21) / SUM(cost), 0), 4) as roi21,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da22) / SUM(cost), 0), 4) as roi22,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da23) / SUM(cost), 0), 4) as roi23,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da24) / SUM(cost), 0), 4) as roi24,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da25) / SUM(cost), 0), 4) as roi25,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da26) / SUM(cost), 0), 4) as roi26,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da27) / SUM(cost), 0), 4) as roi27,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da28) / SUM(cost), 0), 4) as roi28,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da29) / SUM(cost), 0), 4) as roi29,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(da30) / SUM(cost), 0), 4) as roi30,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m2) / SUM(cost), 0), 4) as roi60,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m3) / SUM(cost), 0), 4) as roi90,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(m6) / SUM(cost), 0), 4) as roi180,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(y1) / SUM(cost), 0), 4) as roi1yaer,
|
|
|
+ ROUND(IF(SUM(cost) > 0 , SUM(total) / SUM(cost), 0), 4) as roi_total
|
|
|
+ FROM
|
|
|
+ game_ads.ads_game_pitcher_day
|
|
|
+ WHERE
|
|
|
+ source_system='ZX_ONE'
|
|
|
+ AND dt BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ GROUP BY
|
|
|
+ game_id,pitcher_id
|
|
|
+ ) a
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pitcher_id as b_pitcher_id,
|
|
|
+ game_id as b_game_id,
|
|
|
+ IFNULL(SUM(amount), 0) as amount,
|
|
|
+ IFNULL(SUM(amount_count), 0) as amount_count,
|
|
|
+ ROUND(IF(SUM(amount_count) > 0 , SUM(amount) / SUM(amount_count), 0), 2) as paper_avg
|
|
|
+ FROM
|
|
|
+ game_ads.ads_game_pitcher_day
|
|
|
+ WHERE
|
|
|
+ source_system = 'ZX_ONE'
|
|
|
+ AND dt BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ GROUP BY
|
|
|
+ pitcher_id , game_id
|
|
|
+ ) b ON a.pitcher_id = b.b_pitcher_id AND a.game_id = b.b_game_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pitcher_id as c_pitcher_id,
|
|
|
+ game_id as c_game_id,
|
|
|
+ IFNULL(COUNT(DISTINCT user_id), 0) amount_num
|
|
|
+ FROM
|
|
|
+ game_ads.ads_information
|
|
|
+ WHERE
|
|
|
+ source_system = 'ZX_ONE' AND
|
|
|
+ order_time BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND NOT agent_id = 0
|
|
|
+ GROUP BY pitcher_id , game_id
|
|
|
+ ) c ON a.pitcher_id = c.c_pitcher_id AND a.game_id = c.c_game_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ pitcher_id as d_pitcher_id,
|
|
|
+ game_id as d_game_id,
|
|
|
+ COUNT(DISTINCT user_id) new_user_amount_num
|
|
|
+ FROM
|
|
|
+ game_ads.ads_information
|
|
|
+ WHERE
|
|
|
+ source_system = 'ZX_ONE' AND
|
|
|
+ order_time BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND reg_time BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND NOT agent_id = 0
|
|
|
+ GROUP BY
|
|
|
+ pitcher_id , game_id
|
|
|
+ ) d ON a.pitcher_id = d.d_pitcher_id AND a.game_id = d.d_game_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ game_id as e_game_id,
|
|
|
+ pitcher_id as e_pitcher_id,
|
|
|
+ COUNT(tempA.num) as new_user_order_again
|
|
|
+ FROM (
|
|
|
+ SELECT
|
|
|
+ game_id,
|
|
|
+ pitcher_id,
|
|
|
+ COUNT(user_id) num
|
|
|
+ FROM
|
|
|
+ game_ads.ads_information
|
|
|
+ WHERE
|
|
|
+ source_system = 'ZX_ONE' AND
|
|
|
+ order_time BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND reg_time BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND NOT agent_id = 0
|
|
|
+ GROUP BY
|
|
|
+ user_id,
|
|
|
+ pitcher_id,
|
|
|
+ game_id
|
|
|
+ HAVING
|
|
|
+ COUNT(user_id) > 1 ) tempA
|
|
|
+ GROUP BY
|
|
|
+ tempA.game_id, tempA.pitcher_id
|
|
|
+ ) e ON a.game_id = e.e_game_id AND a.pitcher_id = e.e_pitcher_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ user_game_id as f_game_id,
|
|
|
+ user_zx_pitcher_id as f_pitcher_id,
|
|
|
+ COUNT(DISTINCT role_user_id) as role_num
|
|
|
+ FROM
|
|
|
+ dw_create_role_detail
|
|
|
+ WHERE
|
|
|
+ source_system = 'ZX_ONE' AND
|
|
|
+ user_dt BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND DATE(role_create_time) BETWEEN '2023-08-15' AND '2023-08-16'
|
|
|
+ AND NOT user_agent_id = 0
|
|
|
+ GROUP BY
|
|
|
+ user_game_id, user_zx_pitcher_id
|
|
|
+ ) f ON a.game_id = f.f_game_id AND a.pitcher_id = f.f_pitcher_id
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|