|
@@ -46,6 +46,7 @@ import java.lang.reflect.Modifier;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -5227,22 +5228,34 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<FlowMonitorVO> getFlowMonitor(FlowMonitorDTO dto) {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ //如果消耗时间和订单时间都为空,那么就给默认值
|
|
|
+ if(dto.getCostBeginDate()==null && dto.getCostEndDate()==null){
|
|
|
+ LocalDate oneMonthAgo = today.minusMonths(1);
|
|
|
+ //消耗时间如果为空,那么就给默认值当天前一个月
|
|
|
+ dto.setCostBeginDate(oneMonthAgo);
|
|
|
+ dto.setCostEndDate(today);
|
|
|
+ }
|
|
|
+ if(dto.getOrderBeginDate()==null && dto.getOrderEndDate()==null){
|
|
|
+ LocalDate twoDaysAgo = today.minusDays(1);
|
|
|
+ //订单时间如果为空,那么就给默认值当天和前一天
|
|
|
+ dto.setOrderBeginDate(twoDaysAgo);
|
|
|
+ dto.setOrderEndDate(today);
|
|
|
+ }
|
|
|
//分页条件
|
|
|
Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
|
|
|
- //根据维度选择 子表父表
|
|
|
- String costTable = "game_ads.ads_recharge_monitoring_cost";
|
|
|
- String orderTable = "game_ads.ads_recharge_monitoring_amount";
|
|
|
- if (dto.getGameDimension() != null && dto.getGameDimension() != 1) {
|
|
|
- costTable = "game_ads_parent.ads_recharge_monitoring_cost_parent";
|
|
|
- orderTable = "game_ads_parent.ads_recharge_monitoring_amount_parent";
|
|
|
- }
|
|
|
+
|
|
|
//订单表查询条件
|
|
|
Criteria cri = getOrderQueryStr(dto);
|
|
|
- //消耗表查询条件
|
|
|
- Criteria costCri = getCostQueryStr(dto);
|
|
|
+
|
|
|
+ //查询总记录数
|
|
|
+ Sql countSql = Sqls.create(getCountNumSql(cri));
|
|
|
+ countSql.setCallback(Sqls.callback.integer());
|
|
|
+ dao.execute(countSql);
|
|
|
+ pager.setRecordCount(countSql.getInt());
|
|
|
+
|
|
|
//查询sql
|
|
|
- Sql sql = Sqls.create(flowMonitorSql(dto, cri, costCri, costTable, orderTable));
|
|
|
- pager.setRecordCount(dao.count(orderTable, cri));
|
|
|
+ Sql sql = Sqls.create(flowMonitorSql(cri));
|
|
|
//设置自定义回传类型
|
|
|
sql.setCallback(Sqls.callback.entities());
|
|
|
sql.setEntity(dao.getEntity(FlowMonitorVO.class));
|
|
@@ -5251,10 +5264,291 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
dao.execute(sql);
|
|
|
//得到结果集list
|
|
|
List<FlowMonitorVO> list = sql.getList(FlowMonitorVO.class);
|
|
|
+
|
|
|
+ //获取总消耗
|
|
|
+ Double costCount = getCostCount(dto);
|
|
|
+ if(costCount==null || costCount==0){
|
|
|
+ return new Page<>(list, pager);
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算回收率 充值金额/总消耗
|
|
|
+ for (FlowMonitorVO vo : list) {
|
|
|
+ DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+
|
|
|
+ vo.setCostCount(costCount);
|
|
|
+ vo.setCostBeginDate(dto.getCostBeginDate());
|
|
|
+ vo.setCostEndDate(dto.getCostEndDate());
|
|
|
+ if (vo.getTenAmount() != null && vo.getTenAmount() > 0) {
|
|
|
+ vo.setTenRecovery(Double.parseDouble(df.format(vo.getTenAmount() / costCount))*100);
|
|
|
+ }
|
|
|
+ if (vo.getFourteenAmount()!=null && vo.getFourteenAmount()>0){
|
|
|
+ vo.setFourteenRecovery(Double.parseDouble(df.format(vo.getFourteenAmount()/costCount))*100);
|
|
|
+ }
|
|
|
+ if (vo.getSeventeenAmount()!=null && vo.getSeventeenAmount()>0){
|
|
|
+ vo.setSeventeenRecovery(Double.parseDouble(df.format(vo.getSeventeenAmount()/costCount))*100);
|
|
|
+ }
|
|
|
+ if(vo.getTwentyfourAmount()!=null && vo.getTwentyfourAmount()>0){
|
|
|
+ vo.setTwentyfourRecovery(Double.parseDouble(df.format(vo.getTwentyfourAmount()/costCount))*100);
|
|
|
+ }
|
|
|
+ }
|
|
|
return new Page<>(list, pager);
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public Double getCostCount(FlowMonitorDTO dto){
|
|
|
+ //根据维度选择 子表父表
|
|
|
+ String costTable = "game_ads.ads_recharge_monitoring_cost";
|
|
|
+ if (dto.getGameDimension() != null && dto.getGameDimension() != 1) {
|
|
|
+ costTable = "game_ads_parent.ads_recharge_monitoring_cost_parent";
|
|
|
+ }
|
|
|
+ //消耗表查询条件
|
|
|
+ Criteria costCri = getCostQueryStr(dto);
|
|
|
+ //查询总消耗
|
|
|
+ Sql costSql = Sqls.create(getTotalCostSql(costCri, costTable));
|
|
|
+ costSql.setCallback(Sqls.callback.doubleValue());
|
|
|
+ dao.execute(costSql);
|
|
|
+ //总消耗
|
|
|
+ return costSql.getDouble();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTotalCostSql(Criteria costCri, String costTable) {
|
|
|
+ String sql = """
|
|
|
+ SELECT
|
|
|
+ sum(cost) costCount
|
|
|
+ FROM
|
|
|
+ """ + costTable + """
|
|
|
+ """ + costCri + """
|
|
|
+ GROUP BY source_system
|
|
|
+ """;
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getCountNumSql(Criteria cri){
|
|
|
+ String sql = """
|
|
|
+
|
|
|
+ SELECT COUNT(*) FROM (
|
|
|
+ select day as order_date,
|
|
|
+ source_system,
|
|
|
+ ten_amount,
|
|
|
+ if(yesterday_amount>0,round(ten_amount/yesterday_amount,2),0)*100 ten_rate,
|
|
|
+ fourteen_amount,
|
|
|
+ if(yesterday_amount>0,round(fourteen_amount/yesterday_amount,2),0)*100 fourteen_rate,
|
|
|
+ seventeen_amount,
|
|
|
+ if(yesterday_amount>0,round(seventeen_amount/yesterday_amount,2),0)*100 seventeen_rate,
|
|
|
+ twentyfour_amount,
|
|
|
+ if(yesterday_amount>0,round(twentyfour_amount/yesterday_amount,2),0)*100 twentyfour_rate,
|
|
|
+ yesterday_amount
|
|
|
+ from (
|
|
|
+ select day,
|
|
|
+ source_system,
|
|
|
+ sum(ten_amount) as ten_amount,
|
|
|
+ sum(fourteen_amount) as fourteen_amount,
|
|
|
+ sum(seventeen_amount) as seventeen_amount,
|
|
|
+ sum(twentyfour_amount)as twentyfour_amount,
|
|
|
+ sum(yesterday_amount) as yesterday_amount
|
|
|
+ from (select a.source_system,
|
|
|
+ a.day,
|
|
|
+ ifnull(b.ten_amount, 0) ten_amount,
|
|
|
+ ifnull(c.fourteen_amount, 0) fourteen_amount,
|
|
|
+ ifnull(d.seventeen_amount, 0) seventeen_amount,
|
|
|
+ ifnull(x.twentyfour_amount, 0) twentyfour_amount,
|
|
|
+ ifnull(e.yesterday_amount, 0) yesterday_amount
|
|
|
+ from (
|
|
|
+ select source_system,
|
|
|
+ dt as day,
|
|
|
+ pitcher_id,
|
|
|
+ agent_id,
|
|
|
+ account_id,
|
|
|
+ game_id,
|
|
|
+ account_type
|
|
|
+ from game_dw.dw_agent_day
|
|
|
+ group by source_system, dt, pitcher_id, agent_id,account_id, game_id, account_type
|
|
|
+ ) a left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ zx_pitcher_name pitcher_name,
|
|
|
+ order_agent_id,
|
|
|
+ agent_name,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) twentyfour_amount
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ group by source_system, day, pitcher_id, zx_pitcher_name, order_agent_id, agent_name,
|
|
|
+ account_id, parent_game_id, account_type
|
|
|
+ )x on a.source_system = x.source_system and a.day = x.day and a.agent_id = x.order_agent_id
|
|
|
+ and a.game_id=x.parent_game_id
|
|
|
+ left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) ten_amount -- 10
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 10
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) b
|
|
|
+ on a.source_system = b.source_system and a.day = b.day and a.agent_id = b.order_agent_id
|
|
|
+ and a.game_id=b.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) fourteen_amount -- 14
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 14
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) c
|
|
|
+ on a.source_system = c.source_system and a.day = c.day and a.agent_id = c.order_agent_id
|
|
|
+ and a.game_id=c.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) seventeen_amount -- 17
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 17
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) d
|
|
|
+ on a.source_system = d.source_system and a.day = d.day and a.agent_id = d.order_agent_id
|
|
|
+ and a.game_id=d.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) yesterday_amount -- 昨日
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) e
|
|
|
+ on a.source_system = e.source_system and a.day = Date(adddate(e.day, 1))
|
|
|
+ and a.agent_id = e.order_agent_id
|
|
|
+ and a.game_id=e.parent_game_id
|
|
|
+
|
|
|
+ union all
|
|
|
+
|
|
|
+ select a.source_system,
|
|
|
+ a.day,
|
|
|
+ ifnull(b.ten_amount, 0) ten_amount,
|
|
|
+ ifnull(c.fourteen_amount, 0) fourteen_amount,
|
|
|
+ ifnull(d.seventeen_amount, 0) seventeen_amount,
|
|
|
+ ifnull(a.twentyfour_amount, 0) twentyfour_amount,
|
|
|
+ ifnull(e.yesterday_amount, 0) yesterday_amount
|
|
|
+ from (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ zx_pitcher_name pitcher_name,
|
|
|
+ order_agent_id,
|
|
|
+ agent_name,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) twentyfour_amount
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, zx_pitcher_name, order_agent_id, agent_name,
|
|
|
+ account_id, parent_game_id, account_type
|
|
|
+ )a
|
|
|
+ left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) ten_amount -- 10
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 10 and order_agent_id=0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) b
|
|
|
+ on a.source_system = b.source_system and a.day = b.day and a.order_agent_id = b.order_agent_id
|
|
|
+ and a.parent_game_id=b.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) fourteen_amount -- 14
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 14 and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) c
|
|
|
+ on a.source_system = c.source_system and a.day = c.day and a.order_agent_id = c.order_agent_id
|
|
|
+ and a.parent_game_id=c.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) seventeen_amount -- 17
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 17 and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) d
|
|
|
+ on a.source_system = d.source_system and a.day = d.day and a.order_agent_id = d.order_agent_id
|
|
|
+ and a.parent_game_id=d.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) yesterday_amount -- 昨日
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) e
|
|
|
+ on a.source_system = e.source_system and a.day = Date(adddate(e.day, 1))
|
|
|
+ and a.order_agent_id = e.order_agent_id
|
|
|
+ and a.parent_game_id=e.parent_game_id
|
|
|
+ ) f
|
|
|
+ group by day, source_system
|
|
|
+ ) ab
|
|
|
+ """+ cri +"""
|
|
|
+ order by day desc
|
|
|
+
|
|
|
+
|
|
|
+ ) abc
|
|
|
+ """;
|
|
|
+
|
|
|
+ return sql;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 流水监控总计
|
|
|
*
|
|
@@ -5320,117 +5614,238 @@ public class GameDataServiceImpl implements IGameDataService {
|
|
|
return criCost;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 拼接sql
|
|
|
+ * 流水监控sql
|
|
|
+ *
|
|
|
+ * @param cri 条件
|
|
|
+ * @return sql
|
|
|
*/
|
|
|
- public String flowMonitorSql(FlowMonitorDTO dto, Criteria cri, Criteria criCost, String costTable, String orderTable) {
|
|
|
- String gameColumn = "game_id ";
|
|
|
- if (dto.getGameDimension() != 1) {
|
|
|
- gameColumn = "parent_game_id ";
|
|
|
- }
|
|
|
-
|
|
|
- String sql =
|
|
|
- """
|
|
|
- select
|
|
|
- cost_begin_date, -- 消耗开始时间
|
|
|
- cost_end_date, -- 消耗结束时间
|
|
|
- order_date,
|
|
|
- source_system,
|
|
|
- ten_amount, -- 10点充值金额
|
|
|
- ROUND(IF(ten_amount>0,ten_amount/cost_count,cost_count),2)*100 as ten_recovery, -- 10点回报率(充值/消耗)
|
|
|
- ROUND(IF(cost_count>0,ten_amount/yesterday_amount,cost_count),2)*100 as ten_rate, -- 10点环比(前一天充值总额/消耗)
|
|
|
- fourteen_amount, -- 14点充值金额
|
|
|
- ROUND(IF(cost_count>0,fourteen_amount/cost_count,cost_count),2)*100 as fourteen_recovery, -- 14点回报率(充值/消耗)
|
|
|
- ROUND(IF(cost_count>0,fourteen_amount/yesterday_amount,cost_count),2)*100 as fourteen_rate, -- 14点环比(前一天充值总额/消耗)
|
|
|
- seventeen_amount, -- 17点充值金额
|
|
|
- ROUND(IF(cost_count>0,seventeen_amount/cost_count,cost_count),2)*100 as seventeen_recovery, -- 17点回报率(充值/消耗)
|
|
|
- ROUND(IF(cost_count>0,seventeen_amount/yesterday_amount,cost_count),2)*100 as seventeen_rate, -- 17点环比(前一天充值总额/消耗)
|
|
|
- twentyfour_amount, -- 24点充值金额
|
|
|
- ROUND(IF(cost_count>0,twentyfour_amount/cost_count,cost_count),2)*100 as twentyfour_recovery, -- 24点回报率(充值/消耗)
|
|
|
- ROUND(IF(cost_count>0,twentyfour_amount/yesterday_amount,cost_count),2)*100 as twentyfour_rate, -- 17点环比(前一天充值总额/消耗)
|
|
|
- cost_count, -- 消耗总计
|
|
|
- yesterday_amount -- 昨日充值总额
|
|
|
- from (
|
|
|
- SELECT
|
|
|
- order_date,
|
|
|
- ANY_VALUE(cost_begin_date) cost_begin_date , -- 消耗开始时间
|
|
|
- ANY_VALUE(cost_end_date) cost_end_date, -- 消耗结束时间
|
|
|
- sum(ten_amount) ten_amount,
|
|
|
- sum(fourteen_amount) fourteen_amount ,
|
|
|
- sum(seventeen_amount) seventeen_amount,
|
|
|
- sum(twentyfour_amount) twentyfour_amount,
|
|
|
- any_value(cost_count) cost_count,
|
|
|
- any_value(source_system) source_system,
|
|
|
- sum(yesterday_amount) yesterday_amount
|
|
|
- from (
|
|
|
- SELECT
|
|
|
- s.source_system,-- SDK类型
|
|
|
- s.minDay cost_begin_date, -- 消耗开始时间
|
|
|
- s.maxDay cost_end_date, -- 消耗结束时间
|
|
|
- s.day as order_date, -- 订单时间
|
|
|
- s.ten_amount, -- 10点充值
|
|
|
- s.fourteen_amount, -- 14点充值
|
|
|
- s.seventeen_amount, -- 17点充值
|
|
|
- s.twentyfour_amount, -- 24点充值
|
|
|
- IFNULL(s.costCount,0) as cost_count , -- 消耗总计
|
|
|
- s.yesterday_amount -- 昨日充值总额
|
|
|
- from (
|
|
|
- SELECT
|
|
|
- a.source_system,
|
|
|
- b.minDay,
|
|
|
- b.maxDay,
|
|
|
- a.day,
|
|
|
- a.ten_amount,
|
|
|
- a.fourteen_amount, -- 14点充值
|
|
|
- a.seventeen_amount, -- 17点充值
|
|
|
- a.twentyfour_amount, -- 24点充值
|
|
|
- b.costCount,
|
|
|
- a.pitcher_id, -- 投手id
|
|
|
- a.agent_id,
|
|
|
- a.account_id,
|
|
|
- a.yesterday_amount,
|
|
|
- a.""" + gameColumn + """
|
|
|
-
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- day,
|
|
|
- source_system,
|
|
|
- ten_amount,
|
|
|
- fourteen_amount,
|
|
|
- seventeen_amount,
|
|
|
- twentyfour_amount,
|
|
|
- ten_rate,
|
|
|
- fourteen_rate,
|
|
|
- seventeen_rate,
|
|
|
- twentyfour_rate,
|
|
|
- pitcher_id,
|
|
|
- agent_id,
|
|
|
- account_id,
|
|
|
- yesterday_amount,
|
|
|
- """ + gameColumn + """
|
|
|
- FROM
|
|
|
- """ + orderTable + """
|
|
|
- ) a
|
|
|
- LEFT JOIN (
|
|
|
- SELECT
|
|
|
- source_system,
|
|
|
- sum(cost) costCount,
|
|
|
- max(day) maxDay,
|
|
|
- min(day) minDay
|
|
|
- FROM
|
|
|
- """ + costTable + """
|
|
|
- """ + criCost + """
|
|
|
- GROUP BY source_system
|
|
|
- ) b on a.source_system = b.source_system
|
|
|
- )s""" + cri + """
|
|
|
- )a group by order_date
|
|
|
-
|
|
|
- ) aa ORDER BY order_date DESC
|
|
|
- """;
|
|
|
+ public String flowMonitorSql(Criteria cri){
|
|
|
+
|
|
|
+ String sql = """
|
|
|
+ select day as order_date,
|
|
|
+ source_system,
|
|
|
+ ten_amount,
|
|
|
+ if(yesterday_amount>0,round(ten_amount/yesterday_amount,2),0)*100 ten_rate,
|
|
|
+ fourteen_amount,
|
|
|
+ if(yesterday_amount>0,round(fourteen_amount/yesterday_amount,2),0)*100 fourteen_rate,
|
|
|
+ seventeen_amount,
|
|
|
+ if(yesterday_amount>0,round(seventeen_amount/yesterday_amount,2),0)*100 seventeen_rate,
|
|
|
+ twentyfour_amount,
|
|
|
+ if(yesterday_amount>0,round(twentyfour_amount/yesterday_amount,2),0)*100 twentyfour_rate,
|
|
|
+ yesterday_amount
|
|
|
+ from (
|
|
|
+ select day,
|
|
|
+ source_system,
|
|
|
+ sum(ten_amount) as ten_amount,
|
|
|
+ sum(fourteen_amount) as fourteen_amount,
|
|
|
+ sum(seventeen_amount) as seventeen_amount,
|
|
|
+ sum(twentyfour_amount)as twentyfour_amount,
|
|
|
+ sum(yesterday_amount) as yesterday_amount
|
|
|
+ from (select a.source_system,
|
|
|
+ a.day,
|
|
|
+ ifnull(b.ten_amount, 0) ten_amount,
|
|
|
+ ifnull(c.fourteen_amount, 0) fourteen_amount,
|
|
|
+ ifnull(d.seventeen_amount, 0) seventeen_amount,
|
|
|
+ ifnull(x.twentyfour_amount, 0) twentyfour_amount,
|
|
|
+ ifnull(e.yesterday_amount, 0) yesterday_amount
|
|
|
+ from (
|
|
|
+ select source_system,
|
|
|
+ dt as day,
|
|
|
+ pitcher_id,
|
|
|
+ agent_id,
|
|
|
+ account_id,
|
|
|
+ game_id,
|
|
|
+ account_type
|
|
|
+ from game_dw.dw_agent_day
|
|
|
+ group by source_system, dt, pitcher_id, agent_id,account_id, game_id, account_type
|
|
|
+ ) a left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ zx_pitcher_name pitcher_name,
|
|
|
+ order_agent_id,
|
|
|
+ agent_name,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) twentyfour_amount
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ group by source_system, day, pitcher_id, zx_pitcher_name, order_agent_id, agent_name,
|
|
|
+ account_id, parent_game_id, account_type
|
|
|
+ )x on a.source_system = x.source_system and a.day = x.day and a.agent_id = x.order_agent_id
|
|
|
+ and a.game_id=x.parent_game_id
|
|
|
+ left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) ten_amount -- 10
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 10
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) b
|
|
|
+ on a.source_system = b.source_system and a.day = b.day and a.agent_id = b.order_agent_id
|
|
|
+ and a.game_id=b.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) fourteen_amount -- 14
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 14
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) c
|
|
|
+ on a.source_system = c.source_system and a.day = c.day and a.agent_id = c.order_agent_id
|
|
|
+ and a.game_id=c.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) seventeen_amount -- 17
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 17
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) d
|
|
|
+ on a.source_system = d.source_system and a.day = d.day and a.agent_id = d.order_agent_id
|
|
|
+ and a.game_id=d.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) yesterday_amount -- 昨日
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) e
|
|
|
+ on a.source_system = e.source_system and a.day = Date(adddate(e.day, 1))
|
|
|
+ and a.agent_id = e.order_agent_id
|
|
|
+ and a.game_id=e.parent_game_id
|
|
|
+
|
|
|
+ union all
|
|
|
+
|
|
|
+ select a.source_system,
|
|
|
+ a.day,
|
|
|
+ ifnull(b.ten_amount, 0) ten_amount,
|
|
|
+ ifnull(c.fourteen_amount, 0) fourteen_amount,
|
|
|
+ ifnull(d.seventeen_amount, 0) seventeen_amount,
|
|
|
+ ifnull(a.twentyfour_amount, 0) twentyfour_amount,
|
|
|
+ ifnull(e.yesterday_amount, 0) yesterday_amount
|
|
|
+ from (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ zx_pitcher_name pitcher_name,
|
|
|
+ order_agent_id,
|
|
|
+ agent_name,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) twentyfour_amount
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, zx_pitcher_name, order_agent_id, agent_name,
|
|
|
+ account_id, parent_game_id, account_type
|
|
|
+ )a
|
|
|
+ left join (
|
|
|
+ select
|
|
|
+ source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) ten_amount -- 10
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 10 and order_agent_id=0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) b
|
|
|
+ on a.source_system = b.source_system and a.day = b.day and a.order_agent_id = b.order_agent_id
|
|
|
+ and a.parent_game_id=b.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) fourteen_amount -- 14
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 14 and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) c
|
|
|
+ on a.source_system = c.source_system and a.day = c.day and a.order_agent_id = c.order_agent_id
|
|
|
+ and a.parent_game_id=c.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) seventeen_amount -- 17
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and hour(order_create_time) < 17 and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) d
|
|
|
+ on a.source_system = d.source_system and a.day = d.day and a.order_agent_id = d.order_agent_id
|
|
|
+ and a.parent_game_id=d.parent_game_id
|
|
|
+ left join (select source_system,
|
|
|
+ day,
|
|
|
+ pitcher_id,
|
|
|
+ order_agent_id,
|
|
|
+ account_id,
|
|
|
+ parent_game_id,
|
|
|
+ account_type,
|
|
|
+ sum(amount) yesterday_amount -- 昨日
|
|
|
+ from game_dw.dw_order_day_amount
|
|
|
+ """ + cri + """
|
|
|
+ and order_agent_id = 0
|
|
|
+ group by source_system, day, pitcher_id, order_agent_id, account_id, parent_game_id,
|
|
|
+ account_type) e
|
|
|
+ on a.source_system = e.source_system and a.day = Date(adddate(e.day, 1))
|
|
|
+ and a.order_agent_id = e.order_agent_id
|
|
|
+ and a.parent_game_id=e.parent_game_id
|
|
|
+
|
|
|
+ ) f
|
|
|
+ group by day, source_system
|
|
|
+ ) ab
|
|
|
+ """+ cri +"""
|
|
|
+ order by day desc
|
|
|
+
|
|
|
+ """;
|
|
|
return sql;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 拼接查询条件
|
|
|
*
|