Browse Source

Merge branch 'package' of GameCenter/game-center into dev

zhimo 1 year ago
parent
commit
ba1ae47f13

+ 532 - 117
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/GameDataServiceImpl.java

@@ -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;
+
     }
 
+
     /**
      * 拼接查询条件
      *

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <新增客服气泡接口> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <解决线上BUg> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 1 - 3
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/OrderPayServiceImpl.java

@@ -102,7 +102,7 @@ public class OrderPayServiceImpl implements IOrderPayService {
 
     private void payParamCreate(String code, String openId, Order order, HttpServletRequest request) {
         //上锁
-        if (!distributedLockComponent.doLock(RedisKeyConstant.GET_PAY_PARAM_LOCK + order.getOrderId(), 0L, 1L, TimeUnit.MINUTES)) {
+        if (!distributedLockComponent.doLock(RedisKeyConstant.GET_PAY_PARAM_LOCK + order.getOrderId(), 0L, 3L, TimeUnit.MINUTES)) {
             return;
         }
         //创建支付参数
@@ -111,8 +111,6 @@ public class OrderPayServiceImpl implements IOrderPayService {
         PayTypeEnum payTypeEnum = PayTypeEnum.getByPayType(productPayParamDTO.getPayWay().intValue());
         PayBaseService service = SpringUtils.getBean(payTypeEnum.getClazz());
         service.payCreate(productPayParamDTO);
-        //释放锁
-        distributedLockComponent.unlock(RedisKeyConstant.GET_PAY_PARAM_LOCK + order.getOrderId());
     }
 
     private ProductPayParamDTO transform(Order order, String code, String openId, String ip) {

+ 43 - 53
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserTokenServiceImpl.java

@@ -29,6 +29,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import reactor.util.function.Tuple2;
+import reactor.util.function.Tuples;
 
 import java.time.LocalDateTime;
 import java.util.Objects;
@@ -66,47 +68,24 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
             log.error("token验证失败 , 游戏拓展信息不存在, appId : {}, userId : {}", appId, userId);
             return ResultVO.fail(TokenCheckEnum.PARAM_LACK.getMsg());
         }
-        //用户信息
-        User user = userService.getById(userId);
-        //查询token是否存在
-        UserToken userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
-                .eq(UserToken::getToken, token)
-                .eq(UserToken::getUserId, userId));
-        //导量用户携带的是 relationUserId 匹配的token
-        if (userToken == null && user.getRelationUserId() != null) {
-            userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
-                    .eq(UserToken::getToken, token)
-                    .eq(UserToken::getUserId, user.getRelationUserId()));
-        }
+        //获取检测token
+        UserToken userToken = this.getCheckUserToken(userId, token);
         //判断token是否存在, 并且没有过期
         if (userToken == null || userToken.getExpireTime() < DateUtils.localDateTimeToSecond(LocalDateTime.now())) {
             log.error("token验证失败 , token不存在或者已经失效, appId : {}, userId : {}, token : {}", appId, userId, token);
             return ResultVO.fail(TokenCheckEnum.SIGN_ERROR.getMsg());
         }
-        //登录密钥
-        String loginKey = gameExt.getLoginKey();
-        //计算用户签名
-        StringBuilder sb = new StringBuilder();
-        sb.append("loginKey=").append(loginKey);
-        sb.append("&appId=").append(appId);
-        sb.append("&userId=").append(userId);
-        sb.append("&token=").append(token);
-        String mySign;
-        try {
-            mySign = SignUtil.MD5(sb.toString());
-        } catch (Exception e) {
-            log.error("md5工具类加密异常, str : {}, e : {}", sb.toString(), e.getMessage());
-            throw new BaseException("MD5加密异常");
-        }
+        //获取计算签名
+        Tuple2<String, String> tuple2 = this.getMySign(gameExt, userId, token);
         //签名错误
-        if (!Objects.equals(mySign, sign)) {
-            log.error("token验证失败 , str : {}, mySign : {}, sign : {}", sb.toString(), mySign, sign);
+        if (!Objects.equals(tuple2.getT2(), sign)) {
+            log.error("token验证失败 , str : {}, mySign : {}, sign : {}", tuple2.getT1(), tuple2.getT2(), sign);
             return ResultVO.fail(TokenCheckEnum.CHECK_FAIL.getMsg());
         }
         //构造返回
         return ResultVO.ok(CpTokenCheckVO.builder()
                 .userId(userId)
-                .appId(gameExtService.getByGameId(user.getGameId()).getAppId())
+                .appId(gameExt.getAppId())
                 .build());
     }
 
@@ -118,29 +97,28 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
             log.error("token验证失败 , 游戏拓展信息不存在, appId : {}, userId : {}", appId, userId);
             return ResultVO.fail(TokenCheckEnum.PARAM_LACK.getMsg());
         }
-        //用户信息
-        User user = userService.getById(userId);
-        //查询token是否存在
-        UserToken userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
-                .eq(UserToken::getToken, token)
-                .eq(UserToken::getUserId, userId));
-        //导量用户携带的是 relationUserId 匹配的token
-        if (userToken == null && user.getRelationUserId() != null) {
-            userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
-                    .eq(UserToken::getToken, token)
-                    .eq(UserToken::getUserId, user.getRelationUserId()));
-        }
+        //获取检测token
+        UserToken userToken = this.getCheckUserToken(userId, token);
         //判断token是否存在, 并且没有过期
         if (userToken == null || userToken.getExpireTime() < DateUtils.localDateTimeToSecond(LocalDateTime.now())) {
             log.error("token验证失败 , token不存在或者已经失效, appId : {}, userId : {}, token : {}", appId, userId, token);
             return ResultVO.fail(TokenCheckEnum.SIGN_ERROR.getMsg());
         }
-        //登录密钥
-        String loginKey = gameExt.getLoginKey();
+        //获取计算签名
+        Tuple2<String, String> tuple2 = this.getMySign(gameExt, userId, token);
+        //签名错误
+        if (!Objects.equals(tuple2.getT2(), sign)) {
+            log.error("token验证失败 , str : {}, mySign : {}, sign : {}", tuple2.getT1(), tuple2.getT2(), sign);
+            return ResultVO.fail(TokenCheckEnum.CHECK_FAIL.getMsg());
+        }
+        return ResultVO.ok(userId);
+    }
+
+    private Tuple2<String, String> getMySign(GameExt gameExt, Long userId, String token) {
         //计算用户签名
         StringBuilder sb = new StringBuilder();
-        sb.append("loginKey=").append(loginKey);
-        sb.append("&appId=").append(appId);
+        sb.append("loginKey=").append(gameExt.getLoginKey());
+        sb.append("&appId=").append(gameExt.getAppId());
         sb.append("&userId=").append(userId);
         sb.append("&token=").append(token);
         String mySign;
@@ -150,14 +128,26 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
             log.error("md5工具类加密异常, str : {}, e : {}", sb.toString(), e.getMessage());
             throw new BaseException("MD5加密异常");
         }
-        //签名错误
-        if (!Objects.equals(mySign, sign)) {
-            log.error("token验证失败 , str : {}, mySign : {}, sign : {}", sb.toString(), mySign, sign);
-            return ResultVO.fail(TokenCheckEnum.CHECK_FAIL.getMsg());
+        return Tuples.of(sb.toString(), mySign);
+    }
+
+    private UserToken getCheckUserToken(Long userId, String token) {
+        //用户信息
+        User user = userService.getById(userId);
+        //查询token是否存在
+        UserToken userToken = super.getOne(new LambdaQueryWrapper<UserToken>()
+                .eq(UserToken::getToken, token)
+                .eq(user.getRelationUserId() == null, UserToken::getUserId, userId));
+        //非导量玩家
+        if (Objects.equals(userToken.getUserId(), userId)) {
+            return userToken;
+        }
+        //导量玩家
+        User relationUser = userService.getById(userToken.getUserId());
+        if (Objects.equals(relationUser.getRelationUserId(), userId)) {
+            return userToken;
         }
-        ResultVO<Long> re = ResultVO.ok(userId);
-        log.error("token验证成功, str : {}, mySign : {}, sign : {}, re : {}", sb.toString(), mySign, sign, JsonUtil.toString(re));
-        return re;
+        return null;
     }
 
     @Override