|
@@ -3,19 +3,17 @@ package com.zanxiang.game.data.serve.service.impl;
|
|
|
import com.google.common.base.CaseFormat;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
+import com.zanxiang.game.data.serve.pojo.dto.AgentDayAgainDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GamePromoteDayDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GamePromoteDayTotalDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GamePromoteTotalDTO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.entity.AdsAccountAgentDay;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.*;
|
|
|
import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
|
-import com.zanxiang.game.data.serve.pojo.vo.GamePromoteDayTotalVO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.vo.GamePromoteDayVO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.vo.GamePromoteTotalVO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.vo.RechargeTrendVO;
|
|
|
+import com.zanxiang.game.data.serve.pojo.vo.*;
|
|
|
import com.zanxiang.game.data.serve.service.IAccountAgentDayService;
|
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
|
import com.zanxiang.module.util.DateUtil;
|
|
|
-import io.swagger.annotations.ApiModelProperty;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Data;
|
|
@@ -27,6 +25,7 @@ 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.Criteria;
|
|
|
import org.nutz.dao.sql.Sql;
|
|
|
import org.nutz.dao.util.Daos;
|
|
|
import org.nutz.dao.util.cri.SimpleCriteria;
|
|
@@ -34,7 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
@@ -441,6 +442,172 @@ public class AccountAgentDayServiceImpl implements IAccountAgentDayService {
|
|
|
return new Page<>(hasRechargeDayList, pager);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<LocalDate, List<AgentDayAgainVO>> accountAgentDayAgain(AgentDayAgainDTO dto) {
|
|
|
+
|
|
|
+ //如果查询时间不传递默认从今天开始查询
|
|
|
+ if (dto.getBeginDate() == null) {
|
|
|
+ dto.setBeginDate(LocalDate.now());
|
|
|
+ }
|
|
|
+ //判断开始时间后的30天是否超过当前日期
|
|
|
+ if (dto.getBeginDate().plusDays(30).isAfter(LocalDate.now())) {
|
|
|
+ //只查询到当前的数据
|
|
|
+ dto.setEndDate(LocalDate.now());
|
|
|
+ } else {
|
|
|
+ //只考虑30天的数据
|
|
|
+ dto.setEndDate(dto.getBeginDate().plusDays(30));
|
|
|
+ }
|
|
|
+ //拼接查询条件
|
|
|
+ Criteria cri = Cnd.cri();
|
|
|
+ if (dto.getAccountId() != null){
|
|
|
+ cri.where().andEquals("account_id",dto.getAccountId());
|
|
|
+ }
|
|
|
+ if (dto.getAgentId() != null){
|
|
|
+ cri.where().andEquals("agent_id",dto.getAgentId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
+ //拼接SDK来源
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
+ }
|
|
|
+ if (dto.getBeginDate() != null) {
|
|
|
+ cri.where().andEquals("dt", dto.getBeginDate());
|
|
|
+ cri.where().andBetween("ddf", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ //按 "ddf" 升序排序
|
|
|
+ cri.getOrderBy().asc("ddf");
|
|
|
+
|
|
|
+ //获取推广每日复充表的查询结果
|
|
|
+ Sql againSql = Sqls.create( agentDayAgainSql() + cri);
|
|
|
+ againSql.setCallback(Sqls.callback.entities());
|
|
|
+ againSql.setEntity(dao.getEntity(AdsAgentDayAgain.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(againSql);
|
|
|
+ //获取到原始数据list
|
|
|
+ List<AdsAgentDayAgain> list = againSql.getList(AdsAgentDayAgain.class);
|
|
|
+
|
|
|
+ //创建Map记录数据
|
|
|
+ Map<LocalDate, List<AgentDayAgainVO>> map = new HashMap<>();
|
|
|
+ //有序存储每个list,每个list包含当天的所有充值次数的复充数据
|
|
|
+ List<List<AgentDayAgainVO>> tempList = new ArrayList<>();
|
|
|
+ //记录查询出的记录条数
|
|
|
+ int count = list.size();
|
|
|
+ //初始化list
|
|
|
+ initList(tempList, count);
|
|
|
+
|
|
|
+ //外层循环8次 表示不同复充次数的数据
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ //用来计算Ci
|
|
|
+ int ci = i + 1;
|
|
|
+ //第一天的所有充值次数都是先计算的
|
|
|
+ AgentDayAgainVO tempVO = tempList.get(0).get(i);
|
|
|
+ //"原": Ci
|
|
|
+ tempList.get(0).get(i).setOriginal(getCnByNum(list.get(0), ci));
|
|
|
+ //"增":初始为 0
|
|
|
+ tempList.get(0).get(i).setIncrease(BigInteger.ZERO);
|
|
|
+ //"移":下一个充值次数的Ci 即C(i+1)
|
|
|
+ tempList.get(0).get(i).setDecrease(getCnByNum(list.get(0), ci + 1));
|
|
|
+ //"现":公式计算 = 原 + 增 - 移
|
|
|
+ tempList.get(0).get(i).setPresent(
|
|
|
+ tempVO.getOriginal().add(tempVO.getIncrease()).subtract(tempVO.getDecrease())
|
|
|
+ );
|
|
|
+ //"比"
|
|
|
+ tempList.get(0).get(i).setRate(getCnByNum(list.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempVO.getPresent().doubleValue() / getCnByNum(list.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+
|
|
|
+ //计算第2-n天的数据 复充次数i的数据
|
|
|
+ for (int j = 1; j < count; j++) {
|
|
|
+ //"原":前一天的"现"
|
|
|
+ tempList.get(j).get(i).setOriginal(tempList.get(j - 1).get(i).getPresent());
|
|
|
+ //"现":当天的Ci - 当天的C(i+1)
|
|
|
+ tempList.get(j).get(i).setPresent(
|
|
|
+ getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j), ci + 1)));
|
|
|
+ //"增":当天的Ci - 前一天的Ci
|
|
|
+ tempList.get(j).get(i).setIncrease(
|
|
|
+ getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j - 1), ci)));
|
|
|
+ //"移":当天的C(i+1) - 前一天的C(i+1)
|
|
|
+ tempList.get(j).get(i).setDecrease(
|
|
|
+ getCnByNum(list.get(j), ci + 1).subtract(getCnByNum(list.get(j - 1), ci + 1)));
|
|
|
+ //"比":当天的现 / 前一天的C1
|
|
|
+ tempList.get(j).get(i).setRate(getCnByNum(list.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempList.get(j).get(i).getPresent().doubleValue() / getCnByNum(list.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //赋值时间数据
|
|
|
+ for (int i = 0; i < tempList.size(); i++) {
|
|
|
+ map.put(list.get(i).getDdf(), tempList.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化List数据
|
|
|
+ * @param list 需要初始化的数据
|
|
|
+ * @param num 多少天的数据
|
|
|
+ */
|
|
|
+ private void initList(List<List<AgentDayAgainVO>> list, Integer num) {
|
|
|
+ //外层循环 num 次 表示多少天的数据
|
|
|
+ for (int i = 0; i < num; i++) {
|
|
|
+ list.add(new ArrayList<>());
|
|
|
+ //内层循环8次 一共初始化8种复充次数数据对象
|
|
|
+ for (int j = 0; j < 8; j++) {
|
|
|
+ list.get(i).add(
|
|
|
+ AgentDayAgainVO.builder()
|
|
|
+ .decrease(BigInteger.ZERO)
|
|
|
+ .increase(BigInteger.ZERO)
|
|
|
+ .original(BigInteger.ZERO)
|
|
|
+ .present(BigInteger.ZERO)
|
|
|
+ .rate(BigDecimal.ZERO)
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过反射来获取Cn的值
|
|
|
+ * @param dto 数据库查询出来的原始数据对象实体
|
|
|
+ * @param num 1-9
|
|
|
+ * @return Cn
|
|
|
+ */
|
|
|
+ private BigInteger getCnByNum(Object dto, int num) {
|
|
|
+ try {
|
|
|
+ Method m1 = AdsAgentDayAgain.class.getDeclaredMethod(String.format("getC%s", num));
|
|
|
+ //返回对应的Cn值
|
|
|
+ return (BigInteger) m1.invoke(dto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException("发生错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推广每日复充趋势sql
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String agentDayAgainSql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ ddf,
|
|
|
+ account_id,
|
|
|
+ agent_id,
|
|
|
+ agent_name,
|
|
|
+ source_system,
|
|
|
+ c1,
|
|
|
+ c2,
|
|
|
+ c3,
|
|
|
+ c4,
|
|
|
+ c5,
|
|
|
+ c6,
|
|
|
+ c7,
|
|
|
+ c8,
|
|
|
+ c9
|
|
|
+ FROM
|
|
|
+ ads_agent_day_again
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 推广每日数据SQL
|
|
|
* @return
|