|
@@ -0,0 +1,98 @@
|
|
|
+package com.zanxiang.game.data.serve.service.impl;
|
|
|
+
|
|
|
+import com.google.common.base.CaseFormat;
|
|
|
+import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
+import com.zanxiang.game.data.serve.pojo.dto.AdsAccountRechargeRankingListDTO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsAccountRechargeRanking;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.AdsAccountRechargeRankingVO;
|
|
|
+import com.zanxiang.game.data.serve.service.IAdsAccountRechargeRankingService;
|
|
|
+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.entity.Entity;
|
|
|
+import org.nutz.dao.pager.Pager;
|
|
|
+import org.nutz.dao.sql.Sql;
|
|
|
+import org.nutz.dao.util.Daos;
|
|
|
+import org.nutz.dao.util.cri.SimpleCriteria;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class AdsAccountRechargeRankingServiceImpl implements IAdsAccountRechargeRankingService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Dao dao;
|
|
|
+
|
|
|
+ public Page<AdsAccountRechargeRankingVO> listOfPage(AdsAccountRechargeRankingListDTO dto) {
|
|
|
+ if (StringUtils.isBlank(dto.getPitcherId()) && !SecurityUtil.isManager()) {
|
|
|
+ dto.setPitcherId(SecurityUtil.getUserId().toString());
|
|
|
+ }
|
|
|
+ Pager pager = dto.toPage();
|
|
|
+ String sqlStr = """
|
|
|
+ select account_id, pitcher_id, max(pitcher) as pitcher, `type`, game_id, max(game_name), max(game_classify) as game_classify , max(game_cp) as game_cp,
|
|
|
+ sum(cost) as cost,
|
|
|
+ sum(ad_count) as ad_count,
|
|
|
+ sum(view_count) as view_count,
|
|
|
+ sum(click_count) as click_count,
|
|
|
+ sum(click_count) / sum(view_count) as click_rate,
|
|
|
+ if(sum(view_count) > 0, sum(cost)/sum(view_count) * 1000, '--') as thousand_display_price,
|
|
|
+ sum(reg_user_cnt) as reg_user_cnt,
|
|
|
+ sum(cost) / sum(reg_user_cnt) as reg_cost,
|
|
|
+ sum(first_role) as first_role,
|
|
|
+ sum(total_role) as total_role,
|
|
|
+ sum(first_amount) as first_amount,
|
|
|
+ sum(first_amount_user) as first_amount_user,
|
|
|
+ sum(first_amount_count) as first_amount_count,
|
|
|
+ sum(total_amount) as total_amount,
|
|
|
+ sum(total_amount_user) as total_amount_user,
|
|
|
+ sum(total_amount_count) as total_amount_count,
|
|
|
+ sum(cost) / sum(first_amount) as first_roi,
|
|
|
+ sum(total_amount) / sum(total_amount_count) as avg_amount,
|
|
|
+ sum(total_amount) / sum(cost) as roi
|
|
|
+ from ads_account_recharge_ranking
|
|
|
+ """;
|
|
|
+ SimpleCriteria cri = Cnd.cri();
|
|
|
+ if (null != dto.getBeginDay() && null != dto.getEndDay()) {
|
|
|
+ cri.where().and(AdsAccountRechargeRanking::getDt, ">=", dto.getBeginDay()).and(AdsAccountRechargeRanking::getDt, "<=", dto.getEndDay());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getPitcherId())) {
|
|
|
+ cri.where().and(AdsAccountRechargeRanking::getPitcherId, "=", dto.getPitcherId());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(dto.getAccountId())) {
|
|
|
+ cri.where().and(AdsAccountRechargeRanking::getAccountId, "=", dto.getAccountId());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(dto.getGameId())) {
|
|
|
+ cri.where().and(AdsAccountRechargeRanking::getGameId, "=", dto.getGameId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getType())) {
|
|
|
+ cri.where().and(AdsAccountRechargeRanking::getType, "=", dto.getType());
|
|
|
+ }
|
|
|
+ cri.groupBy(AdsAccountRechargeRanking::getAccountId, AdsAccountRechargeRanking::getPitcherId, AdsAccountRechargeRanking::getType, AdsAccountRechargeRanking::getGameId);
|
|
|
+ cri.orderBy(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dto.getSortFiled()), dto.getSortType());
|
|
|
+ Sql sql = Sqls.queryEntity(sqlStr + "$condition");
|
|
|
+ sql.setPager(pager);
|
|
|
+
|
|
|
+ Entity<AdsAccountRechargeRankingVO> entity = dao.getEntity(AdsAccountRechargeRankingVO.class);
|
|
|
+ sql.setEntity(entity).setCondition(cri);
|
|
|
+ dao.execute(sql);
|
|
|
+
|
|
|
+
|
|
|
+ Sql pagerSql = Sqls.queryEntity("select count(*) from ads_agent_recharge_ranking " + "$condition");
|
|
|
+ pagerSql.setCondition(cri);
|
|
|
+ pager.setRecordCount(((Long) Daos.queryCount(dao, pagerSql)).intValue());
|
|
|
+
|
|
|
+ List<AdsAccountRechargeRankingVO> result = sql.getList(AdsAccountRechargeRankingVO.class);
|
|
|
+ int beginIndex = (dto.getPageNum() - 1) * dto.getPageSize();
|
|
|
+ int size = result.size();
|
|
|
+ while (--size >= 0) {
|
|
|
+ result.get(size).setIndex(beginIndex + size);
|
|
|
+ }
|
|
|
+ return new Page<>(result, pager);
|
|
|
+ }
|
|
|
+}
|