|
@@ -29,10 +29,14 @@ import org.nutz.dao.sql.Criteria;
|
|
|
import org.nutz.dao.sql.Sql;
|
|
|
import org.nutz.dao.util.Daos;
|
|
|
import org.nutz.dao.util.cri.SimpleCriteria;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.BeanWrapper;
|
|
|
+import org.springframework.beans.BeanWrapperImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.beans.PropertyDescriptor;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
@@ -67,6 +71,13 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
dto.setRegisteredBeginDate(LocalDate.now());
|
|
|
dto.setRegisteredEndDate(LocalDate.now());
|
|
|
}
|
|
|
+ //如果没有排序条件给默认值
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())){
|
|
|
+ dto.setSortFiled("dt");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())){
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
+ }
|
|
|
//根据dto拼接查询条件
|
|
|
Criteria cri = Cnd.cri();
|
|
|
if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
@@ -80,8 +91,8 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
|
|
|
cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
|
|
|
}
|
|
|
- //结果按日期排序
|
|
|
- cri.getOrderBy().desc("dt");
|
|
|
+ //拼接排序条件
|
|
|
+ cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
|
|
|
|
|
|
//编写sql语句 拼接查询条件
|
|
|
Sql sql = Sqls.create(gameDataDaySql() + cri);
|
|
@@ -387,16 +398,25 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<GameDataTotalVO> getGameDataTotal(GameDataTotalDTO dto) {
|
|
|
+
|
|
|
//如果注册时间参数为空,默认设置查询当天数据
|
|
|
- if (dto.getRegisteredBeginDate() == null || dto.getRechargeEndDate() == null) {
|
|
|
- dto.setRegisteredBeginDate(LocalDate.now());
|
|
|
+ if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
|
|
|
+ dto.setRegisteredBeginDate(LocalDate.now().minusDays(30));
|
|
|
dto.setRegisteredEndDate(LocalDate.now());
|
|
|
}
|
|
|
//如果充值时间参数为空,默认设置查询当天数据
|
|
|
if (dto.getRechargeBeginDate() == null || dto.getRechargeEndDate() == null) {
|
|
|
- dto.setRechargeBeginDate(LocalDate.now());
|
|
|
+ dto.setRechargeBeginDate(LocalDate.now().minusDays(30));
|
|
|
dto.setRechargeEndDate(LocalDate.now());
|
|
|
}
|
|
|
+ //如果没有排序条件给默认值
|
|
|
+ if (StringUtils.isBlank(dto.getSortFiled())){
|
|
|
+ //待查看
|
|
|
+ dto.setSortFiled("game_id");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSortType())){
|
|
|
+ dto.setSortType(OrderByEnum.DESC.getOrderType());
|
|
|
+ }
|
|
|
//根据传入的dto拼接查询参数
|
|
|
Criteria cri = Cnd.cri();
|
|
|
if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
@@ -413,15 +433,13 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
}
|
|
|
//拼接分组条件
|
|
|
cri.getGroupBy().groupBy("a.game_name", "a.game_id", "a.game_classify");
|
|
|
+ //拼接排序条件
|
|
|
+ cri.getOrderBy().orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
|
|
|
//创建sql语句 执行sql
|
|
|
Sql sql = Sqls.create(gameDataTotalSql() + cri);
|
|
|
- //设置自定义参数
|
|
|
- sql.setParam("rechargeBeginDate", dto.getRechargeBeginDate());
|
|
|
- sql.setParam("rechargeEndDate", dto.getRechargeEndDate());
|
|
|
//设置自定义回显对象
|
|
|
sql.setCallback(Sqls.callback.entities());
|
|
|
sql.setEntity(dao.getEntity(GameDataTotalVO.class));
|
|
|
- //设置pager对象
|
|
|
Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
sql.setPager(pager);
|
|
|
//执行sql
|
|
@@ -433,6 +451,12 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
|
|
|
//根据充值时间修改值
|
|
|
List<GameDataTotalVO> gameDataTotalVOList = list.stream().map(vo -> {
|
|
|
+
|
|
|
+ //获取到一个只含有与充值时间有关的数据对象
|
|
|
+ GameDataTotalVO tempVO = getRechargeData(vo, dto);
|
|
|
+ //将tempVO中查出的数据添加到vo上
|
|
|
+ copyNullProperties(tempVO,vo);
|
|
|
+
|
|
|
//设置查询参数map
|
|
|
Map<String, Object> dayNMap = new HashMap<>(4);
|
|
|
dayNMap.put("registerBeginDate", dto.getRegisteredBeginDate());
|
|
@@ -789,6 +813,75 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询只与充值时间相关的数据
|
|
|
+ * @param vo 返回给前端的实体
|
|
|
+ * @param dto 前端查询实体
|
|
|
+ * @return GameDataTotalVO
|
|
|
+ */
|
|
|
+ private GameDataTotalVO getRechargeData(GameDataTotalVO vo, GameDataTotalDTO dto){
|
|
|
+ //查询条件
|
|
|
+ Criteria criRc = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(vo.getGameName())) {
|
|
|
+ //拼接游戏名称查询条件
|
|
|
+ criRc.where().andEquals("b.game_name", vo.getGameName());
|
|
|
+ }
|
|
|
+ if (vo.getGameClassify() != null) {
|
|
|
+ //拼接游戏类型查询条件
|
|
|
+ criRc.where().andEquals("b.game_classify", vo.getGameClassify());
|
|
|
+ }
|
|
|
+ if (vo.getGameId() != null){
|
|
|
+ //拼接游戏id查询条件
|
|
|
+ criRc.where().andEquals("b.game_id", vo.getGameId());
|
|
|
+ }
|
|
|
+ if (dto.getRechargeBeginDate() != null && dto.getRechargeEndDate() != null) {
|
|
|
+ //拼接充值日期查询条件
|
|
|
+ criRc.where().andBetween("b.dt", dto.getRechargeBeginDate(), dto.getRechargeEndDate());
|
|
|
+ }
|
|
|
+ //创建sql语句
|
|
|
+ Sql sqlWithRechargeDate = Sqls.create(gameDataTotalSqlRecharge() + criRc);
|
|
|
+
|
|
|
+ sqlWithRechargeDate.setCallback(Sqls.callback.entity());
|
|
|
+ sqlWithRechargeDate.setEntity(dao.getEntity(GameDataTotalVO.class));
|
|
|
+ dao.execute(sqlWithRechargeDate);
|
|
|
+
|
|
|
+ return sqlWithRechargeDate.getObject(GameDataTotalVO.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 所有为空值的属性都不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);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 三张表共用的方法
|
|
|
* @param dayNMap 参数Map
|
|
@@ -1120,16 +1213,6 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
sum(a.first_new_user_amount_num) first_new_user_amount_num,
|
|
|
sum(a.first_new_user_amount) first_new_user_amount,
|
|
|
|
|
|
- sum(b.buy_amount_count) buy_amount_count,
|
|
|
- sum(b.buy_amount_num) buy_amount_num,
|
|
|
- sum(b.buy_amount) buy_amount,
|
|
|
- sum(b.nature_amount_count) nature_amount_count,
|
|
|
- sum(b.nature_amount_num) nature_amount_num,
|
|
|
- sum(b.nature_amount) nature_amount,
|
|
|
- sum(b.amount_count) amount_count,
|
|
|
- sum(b.amount_num) amount_num,
|
|
|
- sum(b.amount) amount,
|
|
|
-
|
|
|
sum(a.buy_new_user_total_amount_count) buy_new_user_total_amount_count,
|
|
|
sum(a.buy_new_user_total_amount_num) buy_new_user_total_amount_num,
|
|
|
sum(a.buy_new_user_total_amount) buy_new_user_total_amount,
|
|
@@ -1149,13 +1232,13 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
|
|
|
round(if(sum(a.buy_first_new_user_amount_count) > 0, sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_count), 0), 2) buy_first_avg_amount,
|
|
|
round(if(sum(a.buy_new_user_total_amount_count) > 0, sum(a.buy_new_user_total_amount) / sum(a.buy_new_user_total_amount_count), 0), 2) buy_today_avg_amount,
|
|
|
- round(if(sum(b.buy_amount_count) > 0, sum(b.buy_amount) / sum(b.buy_amount_count), 0), 2) buy_avg_amount,
|
|
|
+
|
|
|
round(if(sum(a.nature_first_new_user_amount_count) > 0, sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_count), 0), 2) nature_first_avg_amount,
|
|
|
round(if(sum(a.nature_new_user_total_amount_count) > 0, sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_count), 0), 2) nature_today_avg_amount,
|
|
|
- round(if(sum(b.nature_amount_count) > 0, sum(b.nature_amount) / sum(b.nature_amount_count), 0), 2) nature_avg_amount,
|
|
|
+
|
|
|
round(if(sum(a.first_new_user_amount_count) > 0, sum(a.first_new_user_amount) / sum(a.first_new_user_amount_count), 0), 2) first_avg_amount,
|
|
|
round(if(sum(a.new_user_total_amount_count) > 0, sum(a.new_user_total_amount) / sum(a.new_user_total_amount_count), 0), 2) today_avg_amount,
|
|
|
- round(if(sum(b.amount_count) > 0, sum(b.amount) / sum(b.amount_count), 0), 2) avg_amount,
|
|
|
+
|
|
|
|
|
|
round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_reg_order_user_again) / sum(a.buy_new_user_total_amount_num), 0), 4) buy_today_again_rate,
|
|
|
round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_reg_order_user_again) / sum(a.nature_new_user_total_amount_num), 0), 4) nature_today_again_rate,
|
|
@@ -1164,24 +1247,47 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
round(if(sum(a.buy_reg_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_reg_num), 0), 2) buy_reg_user_arpu,
|
|
|
round(if(sum(a.buy_first_new_user_amount_num) > 0 , sum(a.buy_first_new_user_amount) / sum(a.buy_first_new_user_amount_num), 0), 2) buy_first_amount_arpu,
|
|
|
round(if(sum(a.buy_new_user_total_amount_num) > 0 , sum(a.buy_new_user_total_amount) / sum(a.buy_new_user_total_amount_num), 0), 2) buy_today_amount_arpu,
|
|
|
- round(if(sum(b.buy_amount_num) > 0 , sum(b.buy_amount) / sum(b.buy_amount_num), 0), 2) buy_amount_arpu,
|
|
|
+
|
|
|
round(if(sum(a.nature_reg_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_reg_num), 0), 2) nature_reg_user_arpu,
|
|
|
round(if(sum(a.nature_first_new_user_amount_num) > 0 , sum(a.nature_first_new_user_amount) / sum(a.nature_first_new_user_amount_num), 0), 2) nature_first_amount_arpu,
|
|
|
round(if(sum(a.nature_new_user_total_amount_num) > 0 , sum(a.nature_new_user_total_amount) / sum(a.nature_new_user_total_amount_num), 0), 2) nature_today_amount_arpu,
|
|
|
- round(if(sum(b.nature_amount_num) > 0 , sum(b.nature_amount) / sum(b.nature_amount_num), 0), 2) nature_amount_arpu,
|
|
|
+
|
|
|
round(if(sum(a.reg_num) > 0 , sum(a.new_user_total_amount) / sum(a.reg_num), 0), 2) reg_user_arpu,
|
|
|
round(if(sum(a.first_new_user_amount_num) > 0 , sum(a.first_new_user_amount) / sum(a.first_new_user_amount_num), 0), 2) first_amount_arpu,
|
|
|
- round(if(sum(a.new_user_total_amount_num) > 0 , sum(a.new_user_total_amount) / sum(a.new_user_total_amount_num), 0), 2) today_amount_arpu,
|
|
|
- round(if(sum(b.amount_num) > 0 , sum(b.amount) / sum(b.amount_num), 0), 2) amount_arpu
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0 , sum(a.new_user_total_amount) / sum(a.new_user_total_amount_num), 0), 2) today_amount_arpu
|
|
|
+
|
|
|
FROM
|
|
|
ads_game_day a
|
|
|
- left join
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 和充值时间有关的sql
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String gameDataTotalSqlRecharge(){
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ sum(b.buy_amount_count) buy_amount_count,
|
|
|
+ sum(b.buy_amount_num) buy_amount_num,
|
|
|
+ sum(b.buy_amount) buy_amount,
|
|
|
+ sum(b.nature_amount_count) nature_amount_count,
|
|
|
+ sum(b.nature_amount_num) nature_amount_num,
|
|
|
+ sum(b.nature_amount) nature_amount,
|
|
|
+ sum(b.amount_count) amount_count,
|
|
|
+ sum(b.amount_num) amount_num,
|
|
|
+ sum(b.amount) amount,
|
|
|
+
|
|
|
+ round(if(sum(b.buy_amount_count) > 0, sum(b.buy_amount) / sum(b.buy_amount_count), 0), 2) buy_avg_amount,
|
|
|
+ round(if(sum(b.nature_amount_count) > 0, sum(b.nature_amount) / sum(b.nature_amount_count), 0), 2) nature_avg_amount,
|
|
|
+ round(if(sum(b.amount_count) > 0, sum(b.amount) / sum(b.amount_count), 0), 2) avg_amount,
|
|
|
+ round(if(sum(b.buy_amount_num) > 0 , sum(b.buy_amount) / sum(b.buy_amount_num), 0), 2) buy_amount_arpu,
|
|
|
+ round(if(sum(b.nature_amount_num) > 0 , sum(b.nature_amount) / sum(b.nature_amount_num), 0), 2) nature_amount_arpu,
|
|
|
+ round(if(sum(b.amount_num) > 0 , sum(b.amount) / sum(b.amount_num), 0), 2) amount_arpu
|
|
|
+
|
|
|
+ FROM
|
|
|
ads_game_day b
|
|
|
- on
|
|
|
- a.game_name = b.game_name and
|
|
|
- a.game_id = b.game_id and
|
|
|
- a.game_classify = b.game_classify and
|
|
|
- (b.dt between @rechargeBeginDate and @rechargeEndDate)
|
|
|
+
|
|
|
""";
|
|
|
}
|
|
|
|