|
@@ -2,15 +2,20 @@ 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.GameDataAgainDayDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GameDataDayDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GameDataTotalDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.GameDataWaterDTO;
|
|
|
import com.zanxiang.game.data.serve.pojo.entity.AdsEverydayWater;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsGameDayAgain;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsGameDayAgainBuy;
|
|
|
+import com.zanxiang.game.data.serve.pojo.entity.AdsGameDayAgainNature;
|
|
|
import com.zanxiang.game.data.serve.pojo.enums.OrderByEnum;
|
|
|
import com.zanxiang.game.data.serve.pojo.vo.*;
|
|
|
import com.zanxiang.game.data.serve.service.IGameDataService;
|
|
|
import com.zanxiang.game.data.serve.utils.Page;
|
|
|
import com.zanxiang.module.util.DateUtil;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -28,6 +33,7 @@ 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;
|
|
@@ -52,6 +58,7 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
|
|
|
/**
|
|
|
* 游戏每日数据
|
|
|
+ *
|
|
|
* @param dto 前端传递查询参数
|
|
|
* @return 返回给前端的数据
|
|
|
*/
|
|
@@ -377,6 +384,7 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
|
|
|
/**
|
|
|
* 游戏总数据
|
|
|
+ *
|
|
|
* @param dto 前端传递的查询参数
|
|
|
* @return 返回给前端的数据
|
|
|
*/
|
|
@@ -769,7 +777,8 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
""";
|
|
|
}
|
|
|
|
|
|
- /** 三张表共用的方法
|
|
|
+ /**
|
|
|
+ * 三张表共用的方法
|
|
|
* @param dayNMap 参数Map
|
|
|
* @param tableName 查询的表名
|
|
|
* @return DayN数据
|
|
@@ -994,4 +1003,316 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
from ads_everyday_water
|
|
|
""";
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏每日复充数据
|
|
|
+ *
|
|
|
+ * @param dto 前端传递查询参数实体
|
|
|
+ * @return 返回给前端的数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<LocalDate, List<GameDataAgainDayVO>> getGameDataAgainDay(GameDataAgainDayDTO 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 (StringUtils.isNotBlank(dto.getGameName())) {
|
|
|
+ cri.where().andEquals("game_name", dto.getGameName());
|
|
|
+ }
|
|
|
+ if (dto.getBeginDate() != null) {
|
|
|
+ cri.where().andEquals("dt", dto.getBeginDate());
|
|
|
+ cri.where().andBetween("ddf", dto.getBeginDate(), dto.getEndDate());
|
|
|
+ }
|
|
|
+ //按 "ddf" 升序排序
|
|
|
+ cri.getOrderBy().asc("ddf");
|
|
|
+
|
|
|
+ //获取三张表的查询结果
|
|
|
+ List<AdsGameDayAgain> list = getListByTableType("total", cri);
|
|
|
+ List<AdsGameDayAgainBuy> listBuy = getListByTableType("buy", cri);
|
|
|
+ List<AdsGameDayAgainNature> listNature = getListByTableType("nature", cri);
|
|
|
+
|
|
|
+ //创建Map记录数据
|
|
|
+ Map<LocalDate, List<GameDataAgainDayVO>> map = new HashMap<>();
|
|
|
+ //有序存储每个list,每个list包含当天的所有充值次数的复充数据
|
|
|
+ List<List<GameDataAgainDayVO>> tempList = new ArrayList<>();
|
|
|
+ //记录查询出的记录条数
|
|
|
+ Integer count = list.size();
|
|
|
+ //初始化list
|
|
|
+ initList(tempList, count);
|
|
|
+
|
|
|
+ //外层循环8次 表示不同复充次数的数据
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ //用来计算Ci
|
|
|
+ int ci = i + 1;
|
|
|
+ //第一天的所有充值次数都是先计算的
|
|
|
+ GameDataAgainDayVO tempVO = tempList.get(0).get(i);
|
|
|
+ //"原": Ci
|
|
|
+ tempList.get(0).get(i).setOriginal(getCnByNum(list.get(0), ci));
|
|
|
+ tempList.get(0).get(i).setBuyOriginal(getCnByNum(listBuy.get(0), ci));
|
|
|
+ tempList.get(0).get(i).setNatureOriginal(getCnByNum(listNature.get(0), ci));
|
|
|
+ //"增":初始为 0
|
|
|
+ tempList.get(0).get(i).setIncrease(BigInteger.ZERO);
|
|
|
+ tempList.get(0).get(i).setBuyIncrease(BigInteger.ZERO);
|
|
|
+ tempList.get(0).get(i).setNatureIncrease(BigInteger.ZERO);
|
|
|
+ //"移":下一个充值次数的Ci 即C(i+1)
|
|
|
+ tempList.get(0).get(i).setDecrease(getCnByNum(list.get(0), ci + 1));
|
|
|
+ tempList.get(0).get(i).setBuyDecrease(getCnByNum(listBuy.get(0), ci + 1));
|
|
|
+ tempList.get(0).get(i).setNatureDecrease(getCnByNum(listNature.get(0), ci + 1));
|
|
|
+ //"现":公式计算 = 原 + 增 - 移
|
|
|
+ tempList.get(0).get(i).setPresent(
|
|
|
+ tempVO.getOriginal().add(tempVO.getIncrease()).subtract(tempVO.getDecrease())
|
|
|
+ );
|
|
|
+ tempList.get(0).get(i).setBuyPresent(
|
|
|
+ tempVO.getBuyOriginal().add(tempVO.getBuyIncrease()).subtract(tempVO.getBuyDecrease())
|
|
|
+ );
|
|
|
+ tempList.get(0).get(i).setNaturePresent(
|
|
|
+ tempVO.getNatureOriginal().add(tempVO.getNatureIncrease()).subtract(tempVO.getNatureDecrease())
|
|
|
+ );
|
|
|
+ //"比"
|
|
|
+ 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)
|
|
|
+ );
|
|
|
+ tempList.get(0).get(i).setBuyRate(getCnByNum(listBuy.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempVO.getBuyPresent().doubleValue() / getCnByNum(listBuy.get(0), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ tempList.get(0).get(i).setNatureRate(getCnByNum(listNature.get(0), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempVO.getNaturePresent().doubleValue() / getCnByNum(listNature.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());
|
|
|
+ tempList.get(j).get(i).setBuyOriginal(tempList.get(j - 1).get(i).getBuyPresent());
|
|
|
+ tempList.get(j).get(i).setNatureOriginal(tempList.get(j - 1).get(i).getNaturePresent());
|
|
|
+ //"现":当天的Ci - 当天的C(i+1)
|
|
|
+ tempList.get(j).get(i).setPresent(
|
|
|
+ getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j), ci + 1)));
|
|
|
+ tempList.get(j).get(i).setBuyPresent(
|
|
|
+ getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j), ci + 1)));
|
|
|
+ tempList.get(j).get(i).setNaturePresent(
|
|
|
+ getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.get(j), ci + 1)));
|
|
|
+ //"增":当天的Ci - 前一天的Ci
|
|
|
+ tempList.get(j).get(i).setIncrease(
|
|
|
+ getCnByNum(list.get(j), ci).subtract(getCnByNum(list.get(j - 1), ci)));
|
|
|
+ tempList.get(j).get(i).setBuyIncrease(
|
|
|
+ getCnByNum(listBuy.get(j), ci).subtract(getCnByNum(listBuy.get(j - 1), ci)));
|
|
|
+ tempList.get(j).get(i).setNatureIncrease(
|
|
|
+ getCnByNum(listNature.get(j), ci).subtract(getCnByNum(listNature.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)));
|
|
|
+ tempList.get(j).get(i).setBuyDecrease(
|
|
|
+ getCnByNum(listBuy.get(j), ci + 1).subtract(getCnByNum(listBuy.get(j - 1), ci + 1)));
|
|
|
+ tempList.get(j).get(i).setNatureDecrease(
|
|
|
+ getCnByNum(listNature.get(j), ci + 1).subtract(getCnByNum(listNature.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));
|
|
|
+ tempList.get(j).get(i).setBuyRate(getCnByNum(listBuy.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempList.get(j).get(i).getBuyPresent().doubleValue() / getCnByNum(listBuy.get(j - 1), 1).doubleValue()).setScale(4, RoundingMode.HALF_UP));
|
|
|
+ tempList.get(j).get(i).setNatureRate(getCnByNum(listNature.get(j - 1), 1).compareTo(BigInteger.ZERO) == 0 ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(tempList.get(j).get(i).getNaturePresent().doubleValue() / getCnByNum(listNature.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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过反射来获取Cn的值
|
|
|
+ * @param dto 数据库查询出来的原始数据对象实体
|
|
|
+ * @param num 1-9
|
|
|
+ * @return Cn
|
|
|
+ */
|
|
|
+ private BigInteger getCnByNum(Object dto, int num) {
|
|
|
+ try {
|
|
|
+ Method m1 = null;
|
|
|
+ //不同对象获取的方法不同
|
|
|
+ if (dto instanceof AdsGameDayAgain) {
|
|
|
+ m1 = AdsGameDayAgain.class.getDeclaredMethod(String.format("getC%s", num));
|
|
|
+ } else if (dto instanceof AdsGameDayAgainBuy) {
|
|
|
+ m1 = AdsGameDayAgainBuy.class.getDeclaredMethod(String.format("getBuyC%s", num));
|
|
|
+ } else if (dto instanceof AdsGameDayAgainNature) {
|
|
|
+ m1 = AdsGameDayAgainNature.class.getDeclaredMethod(String.format("getNatureC%s", num));
|
|
|
+ }
|
|
|
+ //返回对应的Cn值
|
|
|
+ return (BigInteger) m1.invoke(dto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException("发生错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化List数据
|
|
|
+ * @param list 需要初始化的数据
|
|
|
+ * @param num 多少天的数据
|
|
|
+ */
|
|
|
+ private void initList(List<List<GameDataAgainDayVO>> 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(
|
|
|
+ GameDataAgainDayVO.builder()
|
|
|
+ .buyOriginal(BigInteger.ZERO)
|
|
|
+ .buyPresent(BigInteger.ZERO)
|
|
|
+ .buyIncrease(BigInteger.ZERO)
|
|
|
+ .buyDecrease(BigInteger.ZERO)
|
|
|
+ .buyRate(BigDecimal.ZERO)
|
|
|
+ .natureOriginal(BigInteger.ZERO)
|
|
|
+ .naturePresent(BigInteger.ZERO)
|
|
|
+ .natureIncrease(BigInteger.ZERO)
|
|
|
+ .natureDecrease(BigInteger.ZERO)
|
|
|
+ .natureRate(BigDecimal.ZERO)
|
|
|
+ .original(BigInteger.ZERO)
|
|
|
+ .present(BigInteger.ZERO)
|
|
|
+ .increase(BigInteger.ZERO)
|
|
|
+ .decrease(BigInteger.ZERO)
|
|
|
+ .rate(BigDecimal.ZERO)
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 不同表获取不同的list结果
|
|
|
+ * @param tableName 表明
|
|
|
+ * @param cri 查询条件
|
|
|
+ * @return 查询结果
|
|
|
+ */
|
|
|
+ private List getListByTableType(String tableName, Criteria cri) {
|
|
|
+ //创建sql语句
|
|
|
+ Sql againSql;
|
|
|
+ //查询的结果封装到list中
|
|
|
+ List list = null;
|
|
|
+ //判断具体查询哪张表
|
|
|
+ if (tableName.equals("total")) {
|
|
|
+ againSql = Sqls.create(adsGameDataAgain() + cri);
|
|
|
+ //自定义回传对象
|
|
|
+ againSql.setCallback(Sqls.callback.entities());
|
|
|
+ againSql.setEntity(dao.getEntity(AdsGameDayAgain.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(againSql);
|
|
|
+ //得到查询的原始结果
|
|
|
+ list = againSql.getList(AdsGameDayAgain.class);
|
|
|
+ } else if (tableName.equals("buy")) {
|
|
|
+ againSql = Sqls.create(adsGameDataAgainBuy() + cri);
|
|
|
+ //自定义回传对象
|
|
|
+ againSql.setCallback(Sqls.callback.entities());
|
|
|
+ againSql.setEntity(dao.getEntity(AdsGameDayAgainBuy.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(againSql);
|
|
|
+ //得到查询的原始结果
|
|
|
+ list = againSql.getList(AdsGameDayAgainBuy.class);
|
|
|
+ } else if (tableName.equals("nature")) {
|
|
|
+ againSql = Sqls.create(adsGameDataAgainNature() + cri);
|
|
|
+ //自定义回传对象
|
|
|
+ againSql.setCallback(Sqls.callback.entities());
|
|
|
+ againSql.setEntity(dao.getEntity(AdsGameDayAgainNature.class));
|
|
|
+ //执行sql
|
|
|
+ dao.execute(againSql);
|
|
|
+ //得到查询的原始结果
|
|
|
+ list = againSql.getList(AdsGameDayAgainNature.class);
|
|
|
+ }
|
|
|
+ //返回结果
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复充表sql(总量)
|
|
|
+ * @return sql
|
|
|
+ */
|
|
|
+ private String adsGameDataAgain() {
|
|
|
+ return
|
|
|
+ """
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ ddf,
|
|
|
+ game_id,
|
|
|
+ game_name,
|
|
|
+ c1,
|
|
|
+ c2,
|
|
|
+ c3,
|
|
|
+ c4,
|
|
|
+ c5,
|
|
|
+ c6,
|
|
|
+ c7,
|
|
|
+ c8,
|
|
|
+ c9
|
|
|
+ FROM
|
|
|
+ ads_game_day_again
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复充表sql(买量)
|
|
|
+ * @return sql
|
|
|
+ */
|
|
|
+ private String adsGameDataAgainBuy() {
|
|
|
+ return
|
|
|
+ """
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ ddf,
|
|
|
+ game_id,
|
|
|
+ game_name,
|
|
|
+ buy_c1,
|
|
|
+ buy_c2,
|
|
|
+ buy_c3,
|
|
|
+ buy_c4,
|
|
|
+ buy_c5,
|
|
|
+ buy_c6,
|
|
|
+ buy_c7,
|
|
|
+ buy_c8,
|
|
|
+ buy_c9
|
|
|
+ FROM
|
|
|
+ ads_game_day_again_buy
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复充表sql(自然量)
|
|
|
+ * @return sql
|
|
|
+ */
|
|
|
+ private String adsGameDataAgainNature() {
|
|
|
+ return
|
|
|
+ """
|
|
|
+ SELECT
|
|
|
+ dt,
|
|
|
+ ddf,
|
|
|
+ game_id,
|
|
|
+ game_name,
|
|
|
+ nature_c1,
|
|
|
+ nature_c2,
|
|
|
+ nature_c3,
|
|
|
+ nature_c4,
|
|
|
+ nature_c5,
|
|
|
+ nature_c6,
|
|
|
+ nature_c7,
|
|
|
+ nature_c8,
|
|
|
+ nature_c9
|
|
|
+ FROM
|
|
|
+ ads_game_day_again_nature
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
}
|