|
@@ -7,8 +7,19 @@ import com.zanxiang.game.data.serve.pojo.vo.GameDataTotalVO;
|
|
|
import com.zanxiang.game.data.serve.service.IGameDataService;
|
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+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.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author tianhua
|
|
|
* @time 2023/7/12
|
|
@@ -18,13 +29,337 @@ import org.springframework.stereotype.Service;
|
|
|
@Slf4j
|
|
|
public class GameDataServiceImpl implements IGameDataService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private Dao dao;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<GameDataDayVO> getGameDataDay(GameDataDayDTO dto) {
|
|
|
- return null;
|
|
|
+
|
|
|
+ //传入的注册时间为空时,给一个默认值 当天数据
|
|
|
+ if (dto.getRegisteredBeginDate() == null || dto.getRegisteredEndDate() == null) {
|
|
|
+ dto.setRegisteredBeginDate(LocalDate.now());
|
|
|
+ dto.setRegisteredEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+ //根据dto拼接查询条件
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
|
+ //拼接游戏名称查询条件
|
|
|
+ cri.where().andEquals("game_name", dto.getGameName());
|
|
|
+ }
|
|
|
+ if (dto.getGameClassify() != null) {
|
|
|
+ //拼接游戏类型查询条件
|
|
|
+ cri.where().andEquals("game_classify", dto.getGameClassify());
|
|
|
+ }
|
|
|
+ if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
|
|
|
+ cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
|
|
|
+ }
|
|
|
+ //结果按日期排序
|
|
|
+ cri.getOrderBy().desc("dt");
|
|
|
+
|
|
|
+ //编写sql语句 拼接查询条件
|
|
|
+ Sql sql = Sqls.create(gameDataDaySql() + cri);
|
|
|
+ //设置自定义回显对象
|
|
|
+ sql.setCallback(Sqls.callback.entities());
|
|
|
+ sql.setEntity(dao.getEntity(GameDataDayVO.class));
|
|
|
+ //设置pager对象
|
|
|
+ Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
+ sql.setPager(pager);
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sql);
|
|
|
+ //得到结果集list
|
|
|
+ List<GameDataDayVO> list = sql.getList(GameDataDayVO.class);
|
|
|
+ //设置查询总数
|
|
|
+ pager.setRecordCount(list.size());
|
|
|
+
|
|
|
+ //返回list结果 封装到page对象里
|
|
|
+ return new Page<>(list, pager);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Page<GameDataTotalVO> getGameDataTotal(GameDataTotalDTO dto) {
|
|
|
- return null;
|
|
|
+ //如果注册时间参数为空,默认设置为当天
|
|
|
+ if (dto.getRegisteredBeginDate() == null || dto.getRechargeEndDate() == null) {
|
|
|
+ dto.setRegisteredBeginDate(LocalDate.now());
|
|
|
+ dto.setRegisteredEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+ //如果充值时间参数为空,默认设置为注册时间
|
|
|
+ if (dto.getRechargeBeginDate() == null || dto.getRechargeEndDate() == null) {
|
|
|
+ dto.setRechargeBeginDate(LocalDate.now());
|
|
|
+ dto.setRechargeEndDate(LocalDate.now());
|
|
|
+ }
|
|
|
+ //根据传入的dto拼接查询参数
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (StringUtils.isNotBlank(dto.getGameName())) {
|
|
|
+ //拼接游戏名称查询条件
|
|
|
+ cri.where().andEquals("a.game_name", dto.getGameName());
|
|
|
+ }
|
|
|
+ if (dto.getGameClassify() != null) {
|
|
|
+ //拼接游戏类型查询条件
|
|
|
+ cri.where().andEquals("a.game_classify", dto.getGameClassify());
|
|
|
+ }
|
|
|
+ if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
|
|
|
+ //拼接注册日期查询条件
|
|
|
+ cri.where().andBetween("a.dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
|
|
|
+ }
|
|
|
+ //拼接分组条件
|
|
|
+ cri.getGroupBy().groupBy("a.game_name", "a.game_id", "a.game_classify");
|
|
|
+ //创建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
|
|
|
+ dao.execute(sql);
|
|
|
+ //得到结果集list
|
|
|
+ List<GameDataTotalVO> list = sql.getList(GameDataTotalVO.class);
|
|
|
+ //设置查询总数
|
|
|
+ pager.setRecordCount(list.size());
|
|
|
+
|
|
|
+ /*//根据充值时间修改值
|
|
|
+ list.stream().map(new Function<GameDataTotalVO, Object>() {
|
|
|
+ //第一个参数 转换之前的参数
|
|
|
+ //第二个参数,转换之后的参数
|
|
|
+ //apply中的传入参数 就是流中的每一个数据
|
|
|
+ //返回值类型就是需要转换之后的类型
|
|
|
+ @Override
|
|
|
+ public Object apply(GameDataTotalVO gameDataTotalVO) {
|
|
|
+
|
|
|
+ //联表查询根据充值时间查询出相关参数
|
|
|
+
|
|
|
+
|
|
|
+ //设置新用户相关数据
|
|
|
+
|
|
|
+
|
|
|
+ //联表查询新用户复充人数
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });*/
|
|
|
+
|
|
|
+ //返回list结果封装到page对象里
|
|
|
+ return new Page<>(list, pager);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏每日数据SQL
|
|
|
+ *
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String gameDataDaySql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ dt cost_date,
|
|
|
+ game_name,
|
|
|
+ game_classify,
|
|
|
+
|
|
|
+ buy_reg_num,
|
|
|
+ nature_reg_num,
|
|
|
+ reg_num,
|
|
|
+
|
|
|
+ buy_first_new_user_amount_count,
|
|
|
+ buy_first_new_user_amount_num,
|
|
|
+ buy_first_new_user_amount,
|
|
|
+ buy_old_user_count,
|
|
|
+ buy_old_user_num,
|
|
|
+ buy_old_user_amount,
|
|
|
+ buy_amount_count,
|
|
|
+ buy_amount_num,
|
|
|
+ buy_amount,
|
|
|
+ buy_new_user_total_amount_count,
|
|
|
+ buy_new_user_total_amount_num,
|
|
|
+ buy_new_user_total_amount,
|
|
|
+ buy_first_roi,
|
|
|
+ buy_today_roi,
|
|
|
+ buy_new_user_rate,
|
|
|
+ buy_first_avg_amount,
|
|
|
+ buy_today_avg_amount,
|
|
|
+ buy_avg_amount,
|
|
|
+ buy_user_again_rate,
|
|
|
+ buy_reg_user_arpu,
|
|
|
+ buy_first_amount_arpu,
|
|
|
+ buy_today_amount_arpu,
|
|
|
+ buy_amount_arpu,
|
|
|
+ buy_amount_d1,
|
|
|
+ buy_amount_d3,
|
|
|
+ buy_amount_d5,
|
|
|
+ buy_amount_d7,
|
|
|
+ buy_amount_d15,
|
|
|
+ buy_amount_m1,
|
|
|
+ buy_amount_m2,
|
|
|
+ buy_amount_m3,
|
|
|
+ buy_amount_m6,
|
|
|
+ buy_amount_sum,
|
|
|
+
|
|
|
+ nature_first_new_user_amount_count,
|
|
|
+ nature_first_new_user_amount_num,
|
|
|
+ nature_first_new_user_amount,
|
|
|
+ nature_old_user_count,
|
|
|
+ nature_old_user_num,
|
|
|
+ nature_old_user_amount,
|
|
|
+ nature_amount_count,
|
|
|
+ nature_amount_num,
|
|
|
+ nature_amount,
|
|
|
+ nature_new_user_total_amount_count,
|
|
|
+ nature_new_user_total_amount_num,
|
|
|
+ nature_new_user_total_amount,
|
|
|
+ nature_first_roi,
|
|
|
+ nature_today_roi,
|
|
|
+ nature_new_user_rate,
|
|
|
+ nature_first_avg_amount,
|
|
|
+ nature_today_avg_amount,
|
|
|
+ nature_avg_amount,
|
|
|
+ nature_user_again_rate,
|
|
|
+ nature_reg_user_arpu,
|
|
|
+ nature_first_amount_arpu,
|
|
|
+ nature_today_amount_arpu,
|
|
|
+ nature_amount_arpu,
|
|
|
+ nature_amount_d1,
|
|
|
+ nature_amount_d3,
|
|
|
+ nature_amount_d5,
|
|
|
+ nature_amount_d7,
|
|
|
+ nature_amount_d15,
|
|
|
+ nature_amount_m1,
|
|
|
+ nature_amount_m2,
|
|
|
+ nature_amount_m3,
|
|
|
+ nature_amount_m6,
|
|
|
+ nature_amount_sum,
|
|
|
+
|
|
|
+ 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,
|
|
|
+ first_roi,
|
|
|
+ today_roi,
|
|
|
+ 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,
|
|
|
+ amount_d1,
|
|
|
+ amount_d3,
|
|
|
+ amount_d5,
|
|
|
+ amount_d7,
|
|
|
+ amount_d15,
|
|
|
+ amount_m1,
|
|
|
+ amount_m2,
|
|
|
+ amount_m3,
|
|
|
+ amount_m6,
|
|
|
+ amount_sum
|
|
|
+
|
|
|
+ FROM ads_game_day
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏总数居SQL
|
|
|
+ *
|
|
|
+ * @return String
|
|
|
+ */
|
|
|
+ private String gameDataTotalSql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ a.game_id game_id,
|
|
|
+ a.game_name game_name,
|
|
|
+ a.game_classify game_classify,
|
|
|
+
|
|
|
+ sum(a.buy_reg_num) buy_reg_num,
|
|
|
+ sum(a.nature_reg_num) nature_reg_num,
|
|
|
+ sum(a.reg_num) reg_num,
|
|
|
+
|
|
|
+ sum(a.buy_first_new_user_amount_count) buy_first_new_user_amount_count,
|
|
|
+ sum(a.buy_first_new_user_amount_num) buy_first_new_user_amount_num,
|
|
|
+ sum(a.buy_first_new_user_amount) buy_first_new_user_amount,
|
|
|
+ sum(a.nature_first_new_user_amount_count) nature_first_new_user_amount_count,
|
|
|
+ sum(a.nature_first_new_user_amount_num) nature_first_new_user_amount_num,
|
|
|
+ sum(a.nature_first_new_user_amount) nature_first_new_user_amount,
|
|
|
+ sum(a.first_new_user_amount_count) first_new_user_amount_count,
|
|
|
+ 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,
|
|
|
+ sum(a.nature_new_user_total_amount_count) nature_new_user_total_amount_count,
|
|
|
+ sum(a.nature_new_user_total_amount_num) nature_new_user_total_amount_num,
|
|
|
+ sum(a.nature_new_user_total_amount) nature_new_user_total_amount,
|
|
|
+ sum(a.new_user_total_amount_count) new_user_total_amount_count,
|
|
|
+ sum(a.new_user_total_amount_num) new_user_total_amount_num,
|
|
|
+ sum(a.new_user_total_amount) new_user_total_amount,
|
|
|
+
|
|
|
+ round(if(sum(a.buy_reg_num) > 0 ,sum(a.buy_first_new_user_amount_num) / sum(a.buy_reg_num), 0), 4) buy_first_roi,
|
|
|
+ round(if(sum(a.buy_reg_num) > 0, sum(a.buy_new_user_total_amount_num) / sum(a.buy_reg_num), 0), 4) buy_today_roi,
|
|
|
+ round(if(sum(a.nature_reg_num) > 0 ,sum(a.nature_first_new_user_amount_num) / sum(a.nature_reg_num), 0), 4) nature_first_roi,
|
|
|
+ round(if(sum(a.nature_reg_num) > 0, sum(a.nature_new_user_total_amount_num) / sum(a.nature_reg_num), 0), 4) nature_today_roi,
|
|
|
+ round(if(sum(a.reg_num) > 0 ,sum(a.first_new_user_amount_num) / sum(a.reg_num), 0), 4) first_roi,
|
|
|
+ round(if(sum(a.reg_num) > 0, sum(a.new_user_total_amount_num) / sum(a.reg_num), 0), 4) today_roi,
|
|
|
+
|
|
|
+ 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,
|
|
|
+ round(if(sum(a.new_user_total_amount_num) > 0 , sum(a.reg_order_user_again) / sum(a.new_user_total_amount_num), 0), 4) today_again_rate,
|
|
|
+
|
|
|
+ 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
|
|
|
+ FROM
|
|
|
+ ads_game_day a
|
|
|
+ left join
|
|
|
+ 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)
|
|
|
+ """;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|