Browse Source

:fix:
- 流水监控sql修改

zhangxianyu 1 year ago
parent
commit
40abd47c84

+ 472 - 8
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/GameDataServiceImpl.java

@@ -5694,7 +5694,7 @@ public class GameDataServiceImpl implements IGameDataService {
 
         //查询总记录数
         //默认子游戏
-        Sql countSql = Sqls.create(getCountNumSubgameSql(cri, agentCri, subGameSql,yesterdayTotalAmountCri));
+        Sql countSql = Sqls.create(getCountNumSubgameSql2(cri, agentCri, subGameSql,yesterdayTotalAmountCri));
         if (dto.getGameDimension() == 2) {
             countSql = Sqls.create(getCountNumSql(cri, agentCri,yesterdayTotalAmountCri));
         }
@@ -5705,7 +5705,7 @@ public class GameDataServiceImpl implements IGameDataService {
 
         //查询sql
         //默认子游戏
-        Sql sql = Sqls.create(flowMonitorSubgameSql(cri, agentCri, yesterdayTotalAmountCri, subGameSql));
+        Sql sql = Sqls.create(flowMonitorSubgameSql2(cri, agentCri, yesterdayTotalAmountCri, subGameSql));
         if (dto.getGameDimension() == 2) {
             sql = Sqls.create(flowMonitorSql(cri, agentCri, yesterdayTotalAmountCri));
         }
@@ -5959,8 +5959,240 @@ public class GameDataServiceImpl implements IGameDataService {
         return sql;
     }
 
+
     /**
-     * 流水监控父游戏sql
+     * 流水监控子游戏总条数sql
+     *
+     * @param cri
+     * @param agentCri
+     * @return
+     */
+    private String getCountNumSubgameSql2(Criteria cri, Criteria agentCri, Criteria subGameSql,Criteria yesterdayTotalAmountCri) {
+        String sql = """
+                select count(*) from (
+                  select
+                                day as order_date,
+                                       source_system,
+                                       ten_amount,
+                                       if(yesterday_amount>0,round(ten_amount/yesterday_amount,4),0)*100 ten_rate,
+                                       fourteen_amount,
+                                       if(yesterday_amount>0,round(fourteen_amount/yesterday_amount,4),0)*100 fourteen_rate,
+                                       seventeen_amount,
+                                       if(yesterday_amount>0,round(seventeen_amount/yesterday_amount,4),0)*100 seventeen_rate,
+                                       twentyfour_amount,
+                                       if(yesterday_amount>0,round(twentyfour_amount/yesterday_amount,4),0)*100 twentyfour_rate,
+                                       yesterday_amount
+                                from (
+                                    select source_system,
+                                           day,
+                                           sum(ten_amount)             as ten_amount,
+                                           sum(fourteen_amount)        as fourteen_amount,
+                                           sum(seventeen_amount)       as seventeen_amount,
+                                           sum(twentyfour_amount)      as twentyfour_amount,
+                                           ANY_VALUE(yesterday_amount) as yesterday_amount
+                                    from (
+                                         select ifnull(x.source_system, a.source_system) as source_system,
+                                                ifnull(a.day, x.day)                     as day,
+                                                ten_amount,
+                                                fourteen_amount,
+                                                seventeen_amount,
+                                                twentyfour_amount,
+                                                (
+                                                     select sum(amount) from game_dw.dw_order_day_amount
+                                                     """+yesterdayTotalAmountCri+"""
+                                                     AND day = adddate(a.day, -1)
+                                                 )as 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
+                                                          """ + agentCri + """
+                                                         group by source_system, dt, pitcher_id, agent_id, account_id, game_id,account_type
+                                                       ) a
+                                                       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,
+                                                                    game_id
+                                                               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, game_id) 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
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) b
+                                                                                       on x.source_system = b.source_system and x.day = b.day and
+                                                                                          x.order_agent_id = b.order_agent_id
+                                                                                           and x.game_id = b.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
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) c
+                                                                                       on x.source_system = c.source_system and x.day = c.day and
+                                                                                          x.order_agent_id = c.order_agent_id
+                                                                                           and x.game_id = c.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
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) d
+                                                                                       on x.source_system = d.source_system and x.day = d.day and
+                                                                                          x.order_agent_id = d.order_agent_id
+                                                                                           and x.game_id = d.game_id
+                                                                    WHERE x.source_system is not null
+                                             
+                                                                    union all
+                                             
+                                                                    select x.source_system,
+                                                                           x.day,
+                                                                           ten_amount,
+                                                                           fourteen_amount,
+                                                                           seventeen_amount,
+                                                                           twentyfour_amount,
+                                                                           (select sum(amount)
+                                                                            from game_dw.dw_order_day_amount
+                                                                            """+yesterdayTotalAmountCri+"""
+                                                                              AND day = adddate(x.day, -1)) as 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,
+                                                                                 game_id
+                                                                          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, game_id) x
+                                             
+                                                                             left join (select source_system,
+                                                                                               day,
+                                                                                               pitcher_id,
+                                                                                               order_agent_id,
+                                                                                               account_id,
+                                                                                               parent_game_id,
+                                                                                               account_type,
+                                                                                               sum(amount) ten_amount -- 10
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) b
+                                                                                       on x.source_system = b.source_system and x.day = b.day and
+                                                                                          x.order_agent_id = b.order_agent_id
+                                                                                           and x.game_id = b.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
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) c
+                                                                                       on x.source_system = c.source_system and x.day = c.day and
+                                                                                          x.order_agent_id = c.order_agent_id
+                                                                                           and x.game_id = c.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
+                                                                                                ,
+                                                                                               game_id
+                                                                                        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, game_id) d
+                                                                                       on x.source_system = d.source_system and x.day = d.day and
+                                                                                          x.order_agent_id = d.order_agent_id
+                                                                                           and x.game_id = d.game_id
+                                                                    WHERE x.source_system is not null) a
+                                                              group by day, source_system
+                                                         )abc
+                    ) ab
+                """;
+
+        return sql;
+    }
+
+    /**
+     * 流水监控子游戏sql
      *
      * @param cri
      * @param agentCri
@@ -6164,6 +6396,238 @@ public class GameDataServiceImpl implements IGameDataService {
         return sql;
     }
 
+
+    /**
+     * 流水监控子游戏sql
+     *
+     * @param cri
+     * @param agentCri
+     * @param yesterdayTotalAmountCri
+     * @return
+     */
+    private String flowMonitorSubgameSql2(Criteria cri, Criteria agentCri, Criteria yesterdayTotalAmountCri, Criteria subGameSql) {
+        String sql = """
+                select
+                day as order_date,
+                       source_system,
+                       ten_amount,
+                       if(yesterday_amount>0,round(ten_amount/yesterday_amount,4),0)*100 ten_rate,
+                       fourteen_amount,
+                       if(yesterday_amount>0,round(fourteen_amount/yesterday_amount,4),0)*100 fourteen_rate,
+                       seventeen_amount,
+                       if(yesterday_amount>0,round(seventeen_amount/yesterday_amount,4),0)*100 seventeen_rate,
+                       twentyfour_amount,
+                       if(yesterday_amount>0,round(twentyfour_amount/yesterday_amount,4),0)*100 twentyfour_rate,
+                       yesterday_amount
+                from (
+                    select source_system,
+                           day,
+                           sum(ten_amount)             as ten_amount,
+                           sum(fourteen_amount)        as fourteen_amount,
+                           sum(seventeen_amount)       as seventeen_amount,
+                           sum(twentyfour_amount)      as twentyfour_amount,
+                           ANY_VALUE(yesterday_amount) as yesterday_amount
+                    from (
+                         select ifnull(x.source_system, a.source_system) as source_system,
+                                ifnull(a.day, x.day)                     as day,
+                                ten_amount,
+                                fourteen_amount,
+                                seventeen_amount,
+                                twentyfour_amount,
+                                (
+                                     select sum(amount) from game_dw.dw_order_day_amount
+                                     """+yesterdayTotalAmountCri+"""
+                                     AND day = adddate(a.day, -1)
+                                 )as 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
+                                          """ + agentCri + """
+                                         group by source_system, dt, pitcher_id, agent_id, account_id, game_id,account_type
+                                       ) a
+                                       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,
+                                                    game_id
+                                               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, game_id) 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
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) b
+                                                                       on x.source_system = b.source_system and x.day = b.day and
+                                                                          x.order_agent_id = b.order_agent_id
+                                                                           and x.game_id = b.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
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) c
+                                                                       on x.source_system = c.source_system and x.day = c.day and
+                                                                          x.order_agent_id = c.order_agent_id
+                                                                           and x.game_id = c.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
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) d
+                                                                       on x.source_system = d.source_system and x.day = d.day and
+                                                                          x.order_agent_id = d.order_agent_id
+                                                                           and x.game_id = d.game_id
+                                                    WHERE x.source_system is not null
+                                
+                                                    union all
+                                
+                                                    select x.source_system,
+                                                           x.day,
+                                                           ten_amount,
+                                                           fourteen_amount,
+                                                           seventeen_amount,
+                                                           twentyfour_amount,
+                                                           (select sum(amount)
+                                                            from game_dw.dw_order_day_amount
+                                                            """+yesterdayTotalAmountCri+"""
+                                                              AND day = adddate(x.day, -1)) as 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,
+                                                                 game_id
+                                                          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, game_id) x
+                                
+                                                             left join (select source_system,
+                                                                               day,
+                                                                               pitcher_id,
+                                                                               order_agent_id,
+                                                                               account_id,
+                                                                               parent_game_id,
+                                                                               account_type,
+                                                                               sum(amount) ten_amount -- 10
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) b
+                                                                       on x.source_system = b.source_system and x.day = b.day and
+                                                                          x.order_agent_id = b.order_agent_id
+                                                                           and x.game_id = b.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
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) c
+                                                                       on x.source_system = c.source_system and x.day = c.day and
+                                                                          x.order_agent_id = c.order_agent_id
+                                                                           and x.game_id = c.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
+                                                                                ,
+                                                                               game_id
+                                                                        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, game_id) d
+                                                                       on x.source_system = d.source_system and x.day = d.day and
+                                                                          x.order_agent_id = d.order_agent_id
+                                                                           and x.game_id = d.game_id
+                                                    WHERE x.source_system is not null) a
+                                              group by day, source_system
+                                              )abc
+                order by `day` desc
+                    
+                    """;
+        return sql;
+    }
+
     /**
      * 昨日总充值金额查询条件
      *
@@ -6840,11 +7304,11 @@ public class GameDataServiceImpl implements IGameDataService {
         Criteria cri = Cnd.cri();
 
         //如果选择子游戏维度,并且没有选择游戏那么就查询所有游戏拼上条件
-        if(dto.getGameDimension()==1&&CollectionUtils.isEmpty(dto.getGameId())){
-           //查询游戏列表
-            List<Long> subGameId = getSubGameId();
-            dto.setGameId(subGameId);
-        }
+//        if(dto.getGameDimension()==1&&CollectionUtils.isEmpty(dto.getGameId())){
+//           //查询游戏列表
+//            List<Long> subGameId = getSubGameId();
+//            dto.setGameId(subGameId);
+//        }
 
         //SDK类型
         if (StringUtils.isNotBlank(dto.getSourceSystem())) {