|
@@ -1,8 +1,6 @@
|
|
|
package com.zanxiang.game.data.serve.service.impl;
|
|
|
|
|
|
-import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
import com.zanxiang.game.data.serve.pojo.dto.OverallSummaryDTO;
|
|
|
-import com.zanxiang.game.data.serve.pojo.entity.AdsGamePushNum;
|
|
|
import com.zanxiang.game.data.serve.pojo.entity.AdsOverallSummary;
|
|
|
import com.zanxiang.game.data.serve.pojo.vo.OverallSummaryLineDataVO;
|
|
|
import com.zanxiang.game.data.serve.pojo.vo.OverallSummaryVO;
|
|
@@ -44,7 +42,7 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
public OverallSummaryVO getOverallSummaryTotalData(OverallSummaryDTO dto) {
|
|
|
|
|
|
//获取查询条件 整体数据查询 不需要日期 需要gameId
|
|
|
- Condition totalDataCon = myCondition(dto, true,false, -1);
|
|
|
+ Condition totalDataCon = myCondition(dto, true, false, -1);
|
|
|
//查询条件转换为sql语句 设置映射 Entity为 AdsOverallSummary对象
|
|
|
String totalDataConString = totalDataCon.toSql(dao.getEntity(AdsOverallSummary.class));
|
|
|
//自定义sql语句
|
|
@@ -67,7 +65,7 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
OverallSummaryVO totalDataVO = totalDataSql.getObject(OverallSummaryVO.class);
|
|
|
|
|
|
//获取查询条件 查询今日数据 需要按当前日期查询
|
|
|
- Condition todayDataCon = myCondition(dto,true, false, 1);
|
|
|
+ Condition todayDataCon = myCondition(dto, true, false, 1);
|
|
|
//查询条件转换为sql语句 设置映射 Entity为 AdsOverallSummary对象
|
|
|
String todayDataConString = todayDataCon.toSql(dao.getEntity(AdsOverallSummary.class));
|
|
|
Sql todayDataSql = Sqls.create("""
|
|
@@ -99,16 +97,16 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
|
|
|
//7日和30日Roi数据需要手动计算
|
|
|
//7日内新用户累计充值
|
|
|
- BigDecimal d7NewPlayerAmount = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayAmount", myCondition(dto,true, false, 7));
|
|
|
+ BigDecimal d7NewPlayerAmount = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayAmount", myCondition(dto, true, false, 7));
|
|
|
//7日内总消耗
|
|
|
- BigDecimal d7TotalCost = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(dto, true,false, 7));
|
|
|
+ BigDecimal d7TotalCost = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(dto, true, false, 7));
|
|
|
//cost 查询出的结果为null或者为0.00 设置为默认值0
|
|
|
overallSummaryVO.setD7TotalRoi((d7TotalCost == null || BigDecimal.ZERO.compareTo(d7TotalCost) == 0) ? BigDecimal.ZERO : d7NewPlayerAmount.multiply(BigDecimal.valueOf(100)).divide(d7TotalCost, 4, RoundingMode.HALF_UP));
|
|
|
|
|
|
//30日内新用户累计充值
|
|
|
- BigDecimal d30NewPlayerAmount = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayAmount", myCondition(dto,true, false, 30));
|
|
|
+ BigDecimal d30NewPlayerAmount = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayAmount", myCondition(dto, true, false, 30));
|
|
|
//30日内总消耗
|
|
|
- BigDecimal d30TotalCost = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(dto, true,false, 30));
|
|
|
+ BigDecimal d30TotalCost = (BigDecimal) dao.func2(AdsOverallSummary.class, "sum", "todayTotalCost", myCondition(dto, true, false, 30));
|
|
|
//计算30日Roi
|
|
|
//cost 查询出的结果为null或者为0.00 设置为默认值0
|
|
|
overallSummaryVO.setD30TotalRoi((d30TotalCost == null || BigDecimal.ZERO.compareTo(d30TotalCost) == 0) ? BigDecimal.ZERO : d30NewPlayerAmount.multiply(BigDecimal.valueOf(100)).divide(d30TotalCost, 4, RoundingMode.HALF_UP));
|
|
@@ -117,36 +115,51 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
overallSummaryVO.setFirstRoi(overallSummaryVO.getFirstRoi().multiply(BigDecimal.valueOf(100)));
|
|
|
overallSummaryVO.setTotalRoi(overallSummaryVO.getTotalRoi().multiply(BigDecimal.valueOf(100)));
|
|
|
|
|
|
+ //计算总计条件
|
|
|
+ Condition totalCri = myCondition(dto, true, false, -1);
|
|
|
+ //计算今日数据条件
|
|
|
+ Condition todayCri = myCondition(dto, true, false, 1);
|
|
|
+ //计算昨日数据条件
|
|
|
+ Condition yesterdayCri = myCondition(dto, true, false, 0);
|
|
|
+
|
|
|
//计算游戏数量相关数据
|
|
|
//查询总投游戏数量
|
|
|
- Sql gameCountTotalSql = Sqls.create(gameCountSql() +
|
|
|
- myCondition(dto,false,false,-1).toSql(dao.getEntity(AdsGamePushNum.class))
|
|
|
- );
|
|
|
- //自定义回显对象 结果自动封装到给定的Entity对象中
|
|
|
- gameCountTotalSql.setCallback(Sqls.callback.integer());
|
|
|
- //执行自定义sql语句
|
|
|
- dao.execute(gameCountTotalSql);
|
|
|
- overallSummaryVO.setTotalGameCount(Long.valueOf(gameCountTotalSql.getInt()));
|
|
|
-
|
|
|
+ overallSummaryVO.setTotalGameCount(getResultBySql(2, null, myCondition(dto, false, false, -1)));
|
|
|
//查询今日在投游戏数量
|
|
|
- Sql gameCountTodaySql = Sqls.create(gameCountSql() +
|
|
|
- myCondition(dto,false,false,1).toSql(dao.getEntity(AdsGamePushNum.class))
|
|
|
- );
|
|
|
- //自定义回显对象 结果自动封装到给定的Entity对象中
|
|
|
- gameCountTodaySql.setCallback(Sqls.callback.integer());
|
|
|
- //执行自定义sql语句
|
|
|
- dao.execute(gameCountTodaySql);
|
|
|
- overallSummaryVO.setTodayGameCount(Long.valueOf(gameCountTodaySql.getInt()));
|
|
|
-
|
|
|
+ overallSummaryVO.setTodayGameCount(getResultBySql(2, null, myCondition(dto, false, false, 1)));
|
|
|
//查询昨日在投游戏数量
|
|
|
- Sql gameCountYesterdaySql = Sqls.create(gameCountSql() +
|
|
|
- myCondition(dto,false,false,0).toSql(dao.getEntity(AdsGamePushNum.class))
|
|
|
- );
|
|
|
- //自定义回显对象 结果自动封装到给定的Entity对象中
|
|
|
- gameCountYesterdaySql.setCallback(Sqls.callback.integer());
|
|
|
- //执行自定义sql语句
|
|
|
- dao.execute(gameCountYesterdaySql);
|
|
|
- overallSummaryVO.setYesterdayGameCount(Long.valueOf(gameCountYesterdaySql.getInt()));
|
|
|
+ overallSummaryVO.setYesterdayGameCount(getResultBySql(2, null, myCondition(dto, false, false, 0)));
|
|
|
+
|
|
|
+ //计算玩家数量相关数据
|
|
|
+ //查询玩家总计数
|
|
|
+ overallSummaryVO.setTotalPlayers(getResultBySql(1, "today_user_count-ads_overall_summary_user", totalCri));
|
|
|
+ //查询今日新增玩家总计数
|
|
|
+ overallSummaryVO.setTodayPlayerCount(getResultBySql(1, "today_user_count-ads_overall_summary_user", todayCri));
|
|
|
+ //查询昨日新增玩家总计数
|
|
|
+ overallSummaryVO.setYesterdayPlayerCount(getResultBySql(1, "today_user_count-ads_overall_summary_user", yesterdayCri));
|
|
|
+
|
|
|
+ //计算渠道数量相关数据
|
|
|
+ //查询渠道总计数
|
|
|
+ overallSummaryVO.setTotalAgentCount(getResultBySql(1, "today_agent_count-ads_overall_summary_agent", totalCri));
|
|
|
+ //查询今日新增渠道
|
|
|
+ overallSummaryVO.setTotalAgentCount(getResultBySql(1, "today_agent_count-ads_overall_summary_agent", todayCri));
|
|
|
+ //查询昨日新增渠道
|
|
|
+ overallSummaryVO.setTotalAgentCount(getResultBySql(1, "today_agent_count-ads_overall_summary_agent", yesterdayCri));
|
|
|
+
|
|
|
+ //计算充值相关数据
|
|
|
+ //查询充值总计
|
|
|
+ overallSummaryVO.setTotalAmount(getResultBySql("today_amount-ads_overall_summary_amount",totalCri));
|
|
|
+ //查询今日充值
|
|
|
+ overallSummaryVO.setTodayAmount(getResultBySql("today_amount-ads_overall_summary_amount",totalCri));
|
|
|
+ //查询昨日充值
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return overallSummaryVO;
|
|
|
}
|
|
@@ -155,7 +168,7 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
public List<OverallSummaryLineDataVO> getOverallSummaryLineData(OverallSummaryDTO dto) {
|
|
|
|
|
|
//根据条件获取数据
|
|
|
- Condition lineCon = myCondition(dto,true, true, -1);
|
|
|
+ Condition lineCon = myCondition(dto, true, true, -1);
|
|
|
//查询条件变为字符串
|
|
|
String lineConString = lineCon.toSql(dao.getEntity(AdsOverallSummary.class));
|
|
|
//自定义sql语句 加上条件字符串
|
|
@@ -185,44 +198,56 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
/**
|
|
|
* 自定义查询条件
|
|
|
*
|
|
|
- * @param dto 前端传递的查询参数实体
|
|
|
- * @param needGameId 是否需要拼接gameId查询条件
|
|
|
+ * @param dto 前端传递的查询参数实体
|
|
|
+ * @param needGameId 是否需要拼接gameId查询条件
|
|
|
* @param needLocalDate 是否拼接日期查询条件
|
|
|
* @param queryDays 拼接需要查询数据的天数条件(给今日昨日、首日Roi、7日Roi以及30日Roi使用)
|
|
|
* @return Condition 查询条件
|
|
|
*/
|
|
|
- private Condition myCondition(OverallSummaryDTO dto,Boolean needGameId, Boolean needLocalDate, Integer queryDays) {
|
|
|
+ private Condition myCondition(OverallSummaryDTO dto, Boolean needGameId, Boolean needLocalDate, Integer queryDays) {
|
|
|
|
|
|
Criteria cri = Cnd.cri();
|
|
|
//默认查询条件
|
|
|
if (dto.getGameId() != null && needGameId) {
|
|
|
//拼接游戏查询条件
|
|
|
- cri.where().andEquals("gameId", dto.getGameId());
|
|
|
+ cri.where().andEquals("game_id", dto.getGameId());
|
|
|
}
|
|
|
if (dto.getAgentId() != null) {
|
|
|
//拼接渠道查询条件
|
|
|
- cri.where().andEquals("agentId", dto.getAgentId());
|
|
|
+ cri.where().andEquals("agent_id", dto.getAgentId());
|
|
|
}
|
|
|
if (dto.getAccountId() != null) {
|
|
|
//拼接广告账户查询条件
|
|
|
- cri.where().andEquals("accountId", dto.getAccountId());
|
|
|
+ cri.where().andEquals("account_id", dto.getAccountId());
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(dto.getSourceSystem())){
|
|
|
+ if (StringUtils.isNotBlank(dto.getSourceSystem())) {
|
|
|
//拼接查询 sdk 来源条件
|
|
|
- cri.where().andEquals("sourceSystem", dto.getSourceSystem());
|
|
|
+ cri.where().andEquals("source_system", dto.getSourceSystem());
|
|
|
}
|
|
|
- //前端传递 pitcherId 根据 pitcherId 查询
|
|
|
+ /*//前端传递 pitcherId 根据 pitcherId 查询
|
|
|
if (dto.getPitcherId() != null) {
|
|
|
//拼接投手查询条件
|
|
|
- cri.where().andEquals("pitcherId", dto.getPitcherId());
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
} else if (SecurityUtil.isManager()) {
|
|
|
//前端没有传递 pitcherId 参数并且是管理员 查看所有数据 排除掉 pitcherId = -2 的数据
|
|
|
- cri.where().andNotEquals("pitcherId", -2);
|
|
|
+ cri.where().andNotEquals("pitcher_id", -2);
|
|
|
} else {
|
|
|
//前端没有传递 pitcherId 并且不是管理员 只能看自己的数据
|
|
|
- cri.where().andEquals("pitcherId", SecurityUtil.getUserId());
|
|
|
+ cri.where().andEquals("pitcher_id", SecurityUtil.getUserId());
|
|
|
+ }*/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试
|
|
|
+ */
|
|
|
+ //前端传递 pitcherId 根据 pitcherId 查询
|
|
|
+ if (dto.getPitcherId() != null) {
|
|
|
+ //拼接投手查询条件
|
|
|
+ cri.where().andEquals("pitcher_id", dto.getPitcherId());
|
|
|
+ } else {
|
|
|
+ cri.where().andNotEquals("pitcher_id", -2);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//根据参数拼接条件
|
|
|
switch (queryDays) {
|
|
|
//前一天时间
|
|
@@ -293,8 +318,8 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
* 检查前端查询日期内的数据是否在数据库中都存在
|
|
|
* 不存在要设置默认值 0
|
|
|
*
|
|
|
- * @param list 需要判断的list
|
|
|
- * @param dto 前端传递的查询参数实体
|
|
|
+ * @param list 需要判断的list
|
|
|
+ * @param dto 前端传递的查询参数实体
|
|
|
* @return 返回给前端的折线图数据 list
|
|
|
*/
|
|
|
private List<OverallSummaryLineDataVO> checkAllDateData(List<OverallSummaryLineDataVO> list, OverallSummaryDTO dto) {
|
|
@@ -340,17 +365,80 @@ public class OverallSummaryServiceImpl implements IOverallSummaryService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 共用的查询方法
|
|
|
+ *
|
|
|
+ * @param type 查询的字段类型 {1 -> 查询其他表long类型数据 ; 2 -> 查询游戏在投数量表}
|
|
|
+ * @param queryString 参数字符串 格式:"xxx-xxx" 前面代表查询的字段 后面代表查询的表名
|
|
|
+ * @param cri 查询条件
|
|
|
+ * @return 查询结果 Long
|
|
|
+ */
|
|
|
+ private Long getResultBySql(int type, String queryString, Condition cri) {
|
|
|
+ //创建sql
|
|
|
+ Sql sql;
|
|
|
+ if (type == 1) {
|
|
|
+ sql = Sqls.create(sumByItemsAndTablesSql() + cri);
|
|
|
+ //设置查询字段及表名
|
|
|
+ sql.params().set("item", queryString.split("-")[0]);
|
|
|
+ sql.vars().set("tableName", queryString.split("-")[1]);
|
|
|
+ } else {
|
|
|
+ sql = Sqls.create(gameCountSql() + cri);
|
|
|
+ }
|
|
|
+ //设置回传对象
|
|
|
+ sql.setCallback(Sqls.callback.longValue());
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sql);
|
|
|
+ //返回结果
|
|
|
+ return sql.getLong();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 共用的查询方法
|
|
|
+ *
|
|
|
+ * @param queryString 参数字符串 格式:"xxx-xxx" 前面代表查询的字段 后面代表查询的表名
|
|
|
+ * @param cri 查询条件
|
|
|
+ * @return 查询结果 BigDecimal
|
|
|
+ */
|
|
|
+ private BigDecimal getResultBySql(String queryString, Condition cri) {
|
|
|
+ //创建sql
|
|
|
+ Sql sql = Sqls.create(sumByItemsAndTablesSql() + cri);
|
|
|
+ //设置查询字段及表名
|
|
|
+ sql.params().set("item", queryString.split("-")[0]);
|
|
|
+ sql.vars().set("tableName", queryString.split("-")[1]);
|
|
|
+
|
|
|
+ //设置回传对象
|
|
|
+ sql.setCallback(Sqls.callback.doubleValue());
|
|
|
+ //执行sql
|
|
|
+ dao.execute(sql);
|
|
|
+ //返回结果
|
|
|
+ return BigDecimal.valueOf(sql.getDouble()).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 共用的gameCount sql语句
|
|
|
+ *
|
|
|
* @return String
|
|
|
*/
|
|
|
- private String gameCountSql(){
|
|
|
+ private String gameCountSql() {
|
|
|
+ return """
|
|
|
+ SELECT
|
|
|
+ COUNT(DISTINCT game_id)
|
|
|
+ FROM
|
|
|
+ game_ads.ads_game_push_num
|
|
|
+ """;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 共用计算总计sql
|
|
|
+ */
|
|
|
+ private String sumByItemsAndTablesSql() {
|
|
|
return """
|
|
|
- SELECT
|
|
|
- COUNT(DISTINCT a.game_id)
|
|
|
- FROM
|
|
|
- game_ads.ads_game_push_num a
|
|
|
- """;
|
|
|
+ SELECT
|
|
|
+ SUM(@item)
|
|
|
+ FROM
|
|
|
+ $tableName
|
|
|
+ """;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|