zhangxianyu 1 год назад
Родитель
Сommit
a72057c3fc

+ 265 - 35
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/GameDataServiceImpl.java

@@ -648,39 +648,7 @@ public class GameDataServiceImpl implements IGameDataService {
      * @return 返回给前端的总计数据实体
      */
     public GameDataDayTotalVO getGameDataDayTotal(GameDataDayTotalDTO dto) {
-        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
-        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();
-
-        //默认查询 total 总量数据
-        if (StringUtils.isBlank(dto.getTableTypes())) {
-            dto.setTableTypes("total");
-        }
-        //默认查询 子游戏维度 数据
-        if (dto.getGameDimension() == null) {
-            dto.setGameDimension(1L);
-        }
-        //新增查询条件
-        Criteria cri = Cnd.cri();
-        if (CollectionUtils.isNotEmpty(gameIds)) {
-            if (dto.getGameDimension() == 1L) {
-                //拼接游戏id
-                cri.where().andInList("game_id", gameIds);
-            } else if (dto.getGameDimension() == 2L) {
-                //拼接游戏id
-                cri.where().andInList("parent_game_id", gameIds);
-            } else {
-                //拼接游戏id
-                cri.where().andInList("super_game_id", gameIds);
-            }
-        }
-        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
-            //拼接SDK来源
-            cri.where().andEquals("source_system", dto.getSourceSystem());
-        }
-        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
-            //拼接查询时间
-            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
-        }
+        Criteria cri = getGameDataDayTotalCriteria(dto);
         //创建sql
         Sql gameDataDayTotalsql;
         //判断查询的维度
@@ -726,6 +694,49 @@ public class GameDataServiceImpl implements IGameDataService {
         return vo;
     }
 
+
+    /**
+     * 获取游戏每日数据总计条件str
+     */
+    private Criteria getGameDataDayTotalCriteria(GameDataDayTotalDTO dto) {
+        com.github.sd4324530.jtuple.Tuple2<List<Long>, List<Long>> poerInfo = dataPowerComponent.getPowerInfo(dto.getSourceSystem());
+//          List<Long> gameIds = dto.getGameId();
+        List<Long> gameIds = CollectionUtils.isEmpty(dto.getGameId()) ? poerInfo.second : dto.getGameId();
+
+
+        //默认查询 total 总量数据
+        if (StringUtils.isBlank(dto.getTableTypes())) {
+            dto.setTableTypes("total");
+        }
+        //默认查询 子游戏维度 数据
+        if (dto.getGameDimension() == null) {
+            dto.setGameDimension(1L);
+        }
+        Criteria cri = Cnd.cri();
+        if (CollectionUtils.isNotEmpty(gameIds)) {
+            if (dto.getGameDimension() == 1L) {
+                //拼接游戏id
+                cri.where().andInList("game_id", gameIds);
+            } else if (dto.getGameDimension() == 2L) {
+                //拼接游戏id
+                cri.where().andInList("parent_game_id", gameIds);
+            } else {
+                //拼接游戏id
+                cri.where().andInList("super_game_id", gameIds);
+            }
+        }
+        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
+            //拼接SDK来源
+            cri.where().andEquals("source_system", dto.getSourceSystem());
+        }
+        if (dto.getRegisteredBeginDate() != null && dto.getRegisteredEndDate() != null) {
+            //拼接查询时间
+            cri.where().andBetween("dt", dto.getRegisteredBeginDate(), dto.getRegisteredEndDate());
+        }
+
+        return cri;
+    }
+
     /**
      * 游戏总数据
      *
@@ -1891,7 +1902,8 @@ public class GameDataServiceImpl implements IGameDataService {
         if (CollectionUtils.isEmpty(dayNTotalFieldMapList)) {
             return;
         }
-        dayNTotalFieldMapList.forEach(dayNTotalFieldMap -> {
+
+        for (Tuple2<Field, Field> dayNTotalFieldMap : dayNTotalFieldMapList) {
             try {
                 //得到需要计算的值
                 String[] temps = ((String) dayNTotalFieldMap.getT1().get(vo)).split("/");
@@ -1918,7 +1930,7 @@ public class GameDataServiceImpl implements IGameDataService {
             } catch (IllegalAccessException e) {
                 throw new RuntimeException(e);
             }
-        });
+        }
     }
 
     /**
@@ -3322,6 +3334,164 @@ public class GameDataServiceImpl implements IGameDataService {
                         """ + tableName;
     }
 
+
+    /**
+     * 游戏每日数据总计sql-子游戏、父游戏维度 (新)
+     *
+     * @param tableType 查询的类型
+     * @return String
+     */
+    private String gameDataDayTotalSql2(String tableType, String tableName) {
+        if ("buy".equals(tableType)) {
+            return """
+                    SELECT
+                        IFNULL(SUM(cost), 0) cost,
+                        IFNULL(SUM(buy_reg_num), 0) reg_num,
+                    """
+                    + amountDay("buy_") +
+                    """
+                                IFNULL(SUM(buy_first_new_user_amount_count), 0) first_new_user_amount_count,
+                                IFNULL(SUM(buy_first_new_user_amount_num), 0) first_new_user_amount_num,
+                                IFNULL(SUM(buy_first_new_user_amount), 0) first_new_user_amount,
+                                IFNULL(SUM(buy_old_user_count), 0) old_user_count,
+                                IFNULL(SUM(buy_old_user_num), 0) old_user_num,
+                                IFNULL(SUM(buy_old_user_amount), 0) old_user_amount,
+                                IFNULL(SUM(buy_amount_count), 0) amount_count,
+                                IFNULL(SUM(buy_amount_num), 0) amount_num,
+                                IFNULL(SUM(buy_amount), 0) amount,
+                                IFNULL(SUM(buy_new_user_total_amount_count), 0) new_user_total_amount_count,
+                                IFNULL(SUM(buy_new_user_total_amount_num), 0) new_user_total_amount_num,
+                                IFNULL(SUM(buy_new_user_total_amount), 0) new_user_total_amount,
+                                round(if(SUM(cost) > 0 , SUM(buy_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
+                                round(if(SUM(buy_reg_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_reg_num) ,0), 4) first_amount_rate,
+                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount_num) / SUM(buy_reg_num), 0) ,4) today_amount_rate,
+                                round(if(SUM(buy_amount_num) > 0 , SUM(buy_first_new_user_amount_num) / SUM(buy_amount_num) ,0), 4) new_user_rate,
+                                round(if(SUM(buy_first_new_user_amount_count) > 0, SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_count), 0), 2) first_avg_amount,
+                                round(if(SUM(buy_new_user_total_amount_count) > 0, SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_count), 0), 2) today_avg_amount,
+                                round(if(SUM(buy_amount_count) > 0, SUM(buy_amount) / SUM(buy_amount_count), 0), 2) avg_amount,
+                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(buy_reg_order_user_again) / SUM(buy_new_user_total_amount_num), 0), 4) user_again_rate,
+                                round(if(SUM(buy_reg_num) > 0, SUM(buy_new_user_total_amount) / SUM(buy_reg_num), 0), 2) reg_user_arpu,
+                                round(if(SUM(buy_first_new_user_amount_num) > 0 , SUM(buy_first_new_user_amount) / SUM(buy_first_new_user_amount_num), 0), 2) first_amount_arpu,
+                                round(if(SUM(buy_new_user_total_amount_num) > 0 , SUM(buy_new_user_total_amount) / SUM(buy_new_user_total_amount_num), 0), 2) today_amount_arpu,
+                                round(if(SUM(buy_amount_num) > 0, SUM(buy_amount) / SUM(buy_amount_num), 0), 2) amount_arpu,
+                                round(if(SUM(buy_reg_num) > 0, SUM(cost) / SUM(buy_reg_num), 0), 2) reg_cost,
+                                round(if(SUM(buy_first_new_user_amount_num) > 0, SUM(cost) / SUM(buy_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
+                                round(if(SUM(buy_new_user_total_amount_num) > 0, SUM(cost) / SUM(buy_new_user_total_amount_num), 0), 2) total_recharge_cost,
+                                round(if(SUM(cost) > 0, SUM(buy_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
+                                IFNULL(SUM(buy_hundred_user_num), 0) hundred_user_num,
+                                round(IF(SUM(buy_hundred_user_num) > 0, SUM(cost) / SUM(buy_hundred_user_num), 0), 2) hundred_user_num_cost,
+                                IFNULL(SUM(buy_first_role_num), 0) first_role_num,
+                                IFNULL(SUM(buy_role_num), 0) role_num,
+                                IFNULL(SUM(buy_new_user_total_role_num), 0) new_user_total_role_num,
+                                round(IF(SUM(buy_first_role_num) > 0, SUM(cost) / SUM(buy_first_role_num), 0), 2) first_role_num_cost,
+                                round(IF(SUM(buy_role_num) > 0, SUM(cost) / SUM(buy_role_num), 0), 2) role_num_cost,
+                                round(IF(SUM(buy_new_user_total_role_num) >0, SUM(cost) / SUM(buy_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
+                                round(IF(SUM(buy_reg_num) >0, SUM(buy_first_role_num) / SUM(buy_reg_num), 0), 4) first_role_num_rate,
+                                round(IF(SUM(buy_reg_num) >0, SUM(buy_role_num) / SUM(buy_reg_num), 0), 4) role_num_rate,
+                                round(IF(SUM(buy_reg_num) >0, SUM(buy_new_user_total_role_num) / SUM(buy_reg_num), 0), 4) new_user_total_role_num_rate
+                            FROM 
+                            """ + tableName;
+        } else if ("nature".equals(tableType)) {
+            return """
+                    SELECT
+                        IFNULL(SUM(cost), 0) cost,
+                        IFNULL(SUM(nature_reg_num), 0) reg_num,
+                    """
+                    + amountDay("nature_") +
+                    """
+                                IFNULL(SUM(nature_first_new_user_amount_count), 0) first_new_user_amount_count,
+                                IFNULL(SUM(nature_first_new_user_amount_num), 0) first_new_user_amount_num,
+                                IFNULL(SUM(nature_first_new_user_amount), 0) first_new_user_amount,
+                                IFNULL(SUM(nature_old_user_count), 0) old_user_count,
+                                IFNULL(SUM(nature_old_user_num), 0) old_user_num,
+                                IFNULL(SUM(nature_old_user_amount), 0) old_user_amount,
+                                IFNULL(SUM(nature_amount_count), 0) amount_count,
+                                IFNULL(SUM(nature_amount_num), 0) amount_num,
+                                IFNULL(SUM(nature_amount), 0) amount,
+                                IFNULL(SUM(nature_new_user_total_amount_count), 0) new_user_total_amount_count,
+                                IFNULL(SUM(nature_new_user_total_amount_num), 0) new_user_total_amount_num,
+                                IFNULL(SUM(nature_new_user_total_amount), 0) new_user_total_amount,
+                                round(if(SUM(cost) > 0 , SUM(nature_first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
+                                round(if(SUM(nature_reg_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_reg_num) ,0), 4) first_amount_rate,
+                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount_num) / SUM(nature_reg_num), 0) ,4) today_amount_rate,
+                                round(if(SUM(nature_amount_num) > 0 , SUM(nature_first_new_user_amount_num) / SUM(nature_amount_num) ,0), 4) new_user_rate,
+                                round(if(SUM(nature_first_new_user_amount_count) > 0, SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_count), 0), 2) first_avg_amount,
+                                round(if(SUM(nature_new_user_total_amount_count) > 0, SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_count), 0), 2) today_avg_amount,
+                                round(if(SUM(nature_amount_count) > 0, SUM(nature_amount) / SUM(nature_amount_count), 0), 2) avg_amount,
+                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(nature_reg_order_user_again) / SUM(nature_new_user_total_amount_num), 0), 4) user_again_rate,
+                                round(if(SUM(nature_reg_num) > 0, SUM(nature_new_user_total_amount) / SUM(nature_reg_num), 0), 2) reg_user_arpu,
+                                round(if(SUM(nature_first_new_user_amount_num) > 0 , SUM(nature_first_new_user_amount) / SUM(nature_first_new_user_amount_num), 0), 2) first_amount_arpu,
+                                round(if(SUM(nature_new_user_total_amount_num) > 0 , SUM(nature_new_user_total_amount) / SUM(nature_new_user_total_amount_num), 0), 2) today_amount_arpu,
+                                round(if(SUM(nature_amount_num) > 0, SUM(nature_amount) / SUM(nature_amount_num), 0), 2) amount_arpu,
+                                round(if(SUM(nature_reg_num) > 0, SUM(cost) / SUM(nature_reg_num), 0), 2) reg_cost,
+                                round(if(SUM(nature_first_new_user_amount_num) > 0, SUM(cost) / SUM(nature_first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
+                                round(if(SUM(nature_new_user_total_amount_num) > 0, SUM(cost) / SUM(nature_new_user_total_amount_num), 0), 2) total_recharge_cost,
+                                round(if(SUM(cost) > 0, SUM(nature_new_user_total_amount) / SUM(cost), 0), 4) total_roi,
+                                SUM(nature_hundred_user_num) hundred_user_num,
+                                round(IF(SUM(nature_hundred_user_num) > 0, SUM(cost) / SUM(nature_hundred_user_num), 0), 2) hundred_user_num_cost,
+                                SUM(nature_first_role_num) first_role_num,
+                                SUM(nature_role_num) role_num,
+                                SUM(nature_new_user_total_role_num) new_user_total_role_num,
+                                round(IF(SUM(nature_first_role_num) > 0, SUM(cost) / SUM(nature_first_role_num), 0), 2) first_role_num_cost,
+                                round(IF(SUM(nature_role_num) > 0, SUM(cost) / SUM(nature_role_num), 0), 2) role_num_cost,
+                                round(IF(SUM(nature_new_user_total_role_num) >0, SUM(cost) / SUM(nature_new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
+                                round(IF(SUM(nature_reg_num) >0, SUM(nature_first_role_num) / SUM(nature_reg_num), 0), 4) first_role_num_rate,
+                                round(IF(SUM(nature_reg_num) >0, SUM(nature_role_num) / SUM(nature_reg_num), 0), 4) role_num_rate,
+                                round(IF(SUM(nature_reg_num) >0, SUM(nature_new_user_total_role_num) / SUM(nature_reg_num), 0), 4) new_user_total_role_num_rate
+                            FROM 
+                            """ + tableName;
+        }
+        //总量数据
+        return """
+                SELECT
+                    IFNULL(SUM(cost), 0) cost,
+                    IFNULL(SUM(reg_num), 0) reg_num,
+                """
+                + amountDay("") +
+                """
+                            IFNULL(SUM(first_new_user_amount_count), 0) first_new_user_amount_count,
+                            IFNULL(SUM(first_new_user_amount_num), 0) first_new_user_amount_num,
+                            IFNULL(SUM(first_new_user_amount), 0) first_new_user_amount,
+                            IFNULL(SUM(old_user_count), 0) old_user_count,
+                            IFNULL(SUM(old_user_num), 0) old_user_num,
+                            IFNULL(SUM(old_user_amount), 0) old_user_amount,
+                            IFNULL(SUM(amount_count), 0) amount_count,
+                            IFNULL(SUM(amount_num), 0) amount_num,
+                            IFNULL(SUM(amount), 0) amount,
+                            IFNULL(SUM(new_user_total_amount_count), 0) new_user_total_amount_count,
+                            IFNULL(SUM(new_user_total_amount_num), 0) new_user_total_amount_num,
+                            IFNULL(SUM(new_user_total_amount), 0) new_user_total_amount,
+                            round(if(SUM(cost) > 0 , SUM(first_new_user_amount) / SUM(cost) ,0), 4) first_roi,
+                            round(if(SUM(reg_num) > 0 , SUM(first_new_user_amount_num) / SUM(reg_num) ,0), 4) first_amount_rate,
+                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount_num) / SUM(reg_num), 0) ,4) today_amount_rate,
+                            round(if(SUM(amount_num) > 0 , SUM(first_new_user_amount_num) / SUM(amount_num) ,0), 4) new_user_rate,
+                            round(if(SUM(first_new_user_amount_count) > 0, SUM(first_new_user_amount) / SUM(first_new_user_amount_count), 0), 2) first_avg_amount,
+                            round(if(SUM(new_user_total_amount_count) > 0, SUM(new_user_total_amount) / SUM(new_user_total_amount_count), 0), 2) today_avg_amount,
+                            round(if(SUM(amount_count) > 0, SUM(amount) / SUM(amount_count), 0), 2) avg_amount,
+                            round(if(SUM(new_user_total_amount_num) > 0, SUM(reg_order_user_again) / SUM(new_user_total_amount_num), 0), 4) user_again_rate,
+                            round(if(SUM(reg_num) > 0, SUM(new_user_total_amount) / SUM(reg_num), 0), 2) reg_user_arpu,
+                            round(if(SUM(first_new_user_amount_num) > 0 , SUM(first_new_user_amount) / SUM(first_new_user_amount_num), 0), 2) first_amount_arpu,
+                            round(if(SUM(new_user_total_amount_num) > 0 , SUM(new_user_total_amount) / SUM(new_user_total_amount_num), 0), 2) today_amount_arpu,
+                            round(if(SUM(amount_num) > 0, SUM(amount) / SUM(amount_num), 0), 2) amount_arpu,
+                            round(if(SUM(reg_num) > 0, SUM(cost) / SUM(reg_num), 0), 2) reg_cost,
+                            round(if(SUM(first_new_user_amount_num) > 0, SUM(cost) / SUM(first_new_user_amount_num), 0), 2) first_new_user_recharge_cost,
+                            round(if(SUM(new_user_total_amount_num) > 0, SUM(cost) / SUM(new_user_total_amount_num), 0), 2) total_recharge_cost,
+                            round(if(SUM(cost) > 0, SUM(new_user_total_amount) / SUM(cost), 0), 4) total_roi,
+                            SUM(hundred_user_num) hundred_user_num,
+                            round(IF(SUM(hundred_user_num) > 0, SUM(cost) / SUM(hundred_user_num), 0), 2) hundred_user_num_cost,
+                            SUM(first_role_num) first_role_num,
+                            SUM(role_num) role_num,
+                            SUM(new_user_total_role_num) new_user_total_role_num,
+                            round(IF(SUM(first_role_num) > 0, SUM(cost) / SUM(first_role_num), 0), 2) first_role_num_cost,
+                            round(IF(SUM(role_num) > 0, SUM(cost) / SUM(role_num), 0), 2) role_num_cost,
+                            round(IF(SUM(new_user_total_role_num) >0, SUM(cost) / SUM(new_user_total_role_num), 0), 2) new_user_total_role_num_cost,
+                            round(IF(SUM(reg_num) >0, SUM(first_role_num) / SUM(reg_num), 0), 4) first_role_num_rate,
+                            round(IF(SUM(reg_num) >0, SUM(role_num) / SUM(reg_num), 0), 4) role_num_rate,
+                            round(IF(SUM(reg_num) >0, SUM(new_user_total_role_num) / SUM(reg_num), 0), 4) new_user_total_role_num_rate
+                        FROM 
+                        """ + tableName;
+    }
+
     /**
      * 游戏每日数据总计sql-超父游戏维度
      *
@@ -3575,6 +3745,66 @@ public class GameDataServiceImpl implements IGameDataService {
         return trendDay.toString();
     }
 
+    public static void main(String[] args) {
+        String s = amountDay2("buy_");
+        System.out.println(s);
+    }
+
+
+    /**
+     *  Dn的充值金额 / D1-Dn的充值总金额 / Dn的充值人数 /当前消耗(剔除不存在的天数数据) /D1充值金额总和(剔除不存在的天数数据)
+     * 游戏每日总计趋势sql
+     */
+    private static String amountDay2(String type){
+        //拼接查询条件
+        StringBuilder trendDay = new StringBuilder(StringUtils.EMPTY);
+        trendDay.append("""
+                    CONCAT(
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), %sda1, 0)),'/',
+                      sum(%sda1),'/', 
+                      sum(ifnull(%sda1_num,0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), cost, 0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL 0 day) <= DATE(NOW()), %sda1, 0))
+                    ) AS amount_d1 ,
+                    """.formatted(type, type, type, type));
+
+        for (int day = 2; day <= 90; day++) {
+            trendDay.append("""
+                    CONCAT(
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), %sda%d - %sda%d, 0)),'/',
+                      sum(%sda%d),'/',
+                      sum(ifnull(%sda%d_num,0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), cost, 0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d day) <= DATE(NOW()), %sda1, 0))
+                    ) AS amount_d%s ,
+                    """.formatted( day - 1,type,day,type,day - 1,type, day, type, day, day - 1, day - 1, type, day));
+        }
+        for (int month = 4; month <= 12; month++) {
+            trendDay.append("""
+                    CONCAT(
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), %sm%d - %sm%d, 0)),'/',
+                      sum(%sm%d),'/',
+                      sum(ifnull(%sm%d_num,0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), cost, 0)),'/',
+                      SUM(IF(DATE_ADD(a.dt, INTERVAL %d month) <= DATE(NOW()), %sda1, 0))
+                    ) AS amount_m%s ,
+                    """.formatted(month -1 , type,month,type,month - 1,type, month, type, month, month - 1,month - 1, type,month));
+        }
+//        //拼接sum数据
+        trendDay.append("""
+                CONCAT(
+                    SUM(%stotal), '/',
+                    SUM(%stotal), '/',
+                    SUM(ifnull(%stotal_num,0)), '/',
+                    SUM(cost), '/',
+                    SUM(%sda1))
+                ) AS amount_sum ,
+                """.formatted(type, type, type, type));
+
+        return trendDay.toString();
+
+    }
+
     /**
      * 游戏总数据SQL
      *

+ 90 - 0
game-data/game-data-serve/src/main/java/com/zanxiang/game/data/serve/service/impl/RoleManageServiceImpl.java

@@ -88,10 +88,13 @@ public class RoleManageServiceImpl implements IRoleManageService {
             criA.getOrderBy().orderBy(dto.getSortFiled(), dto.getSortType());
         }
         //创建sql
+        StopWatch watch2=new StopWatch();
+        watch2.start();
         Sql sql = Sqls.create(getRoleRechargeRankingSql(criA, criTodayAmount));
         sql.setCallback(Sqls.callback.maps());
         sql.setPager(pager);
         dao.execute(sql);
+        watch2.stop();
         //查询结果
         List<Map> list = sql.getList(Map.class);
         //用户id列表
@@ -132,6 +135,91 @@ public class RoleManageServiceImpl implements IRoleManageService {
         }
         //返回结果
         log.info("查询总记录数耗时:{}",watch.getTotalTimeMillis());
+        log.info("查询数据耗时:{}",watch2.getTotalTimeMillis());
+        return new Page<>(list, pager);
+    }
+
+
+    /**
+     * 角色充值排行榜(优化版)
+     * @param dto RoleRechargeRankingDTO
+     * @return Page<List<Map<String, Object>>>
+     */
+    public Page<Map> getRoleRechargeRanking2(RoleRechargeRankingDTO dto) {
+        //创建查询条件 给主表使用
+        Criteria criA = getSqlByQuery(dto);
+        //给充值时间查询条件
+        Criteria criTodayAmount = getDateSqlByQuery(dto);
+        //分页对象
+        Pager pager = dao.createPager(dto.getPageNum(), dto.getPageSize());
+
+        StopWatch watch=new StopWatch();
+        watch.start();
+        //查询总记录数
+        Sql countSql = Sqls.create(getCountNumSql2(criA, criTodayAmount));
+        countSql.setCallback(Sqls.callback.integer());
+        dao.execute(countSql);
+        watch.stop();
+
+        pager.setRecordCount(countSql.getInt());
+        //主表添加排序条件
+        if (StringUtils.isBlank(dto.getSortType())) {
+            dto.setSortType(OrderByEnum.DESC.getOrderType());
+        }
+        if (StringUtils.isBlank(dto.getSortFiled())) {
+            criA.getOrderBy().orderBy("amount", dto.getSortType());
+        } else {
+            criA.getOrderBy().orderBy(dto.getSortFiled(), dto.getSortType());
+        }
+        //创建sql
+        StopWatch watch2=new StopWatch();
+        watch2.start();
+        Sql sql = Sqls.create(getRoleRechargeRankingSql(criA, criTodayAmount));
+        sql.setCallback(Sqls.callback.maps());
+        sql.setPager(pager);
+        dao.execute(sql);
+        watch2.stop();
+        //查询结果
+        List<Map> list = sql.getList(Map.class);
+        //用户id列表
+        List<Long> userIds = new ArrayList<>();
+        for (Map map : list) {
+            //把投手id和运营id和GSID和客服人员ID 转成List
+            List<String> keys = Arrays.asList("put_user_id", "oper_user_id", "gs_id", "customer_service_id");
+            for (String key : keys) {
+                if (map.get(key) != null) {
+                    userIds.add(Long.valueOf(map.get(key).toString()));
+                }
+            }
+            //去掉字符串中的‘[]’
+            String str = (String) map.get("role_amount");
+            if(str!=null&&str.contains("[") && str.contains("]")){
+                map.put("role_amount", str.replaceAll("[\\[\\]]", ""));
+            }
+            //去除‘null’字符串
+            List<String> nullStringKeys = Arrays.asList("add_corp_user_id", "user_wechat", "remark", "user_phone", "country");
+            nullStringKeys.stream()
+                    .filter(key -> "null".equals(map.get(key)))
+                    .forEach(key -> map.put(key, null));
+        }
+        //去重userIds
+        userIds = userIds.stream().distinct().collect(Collectors.toList());
+        //发送RPC接口查询所有用户
+//        ResultVO<Map<Long, String>> userMap = sysUserRpc.getUserNameByIds(userIds);
+//
+//        for (Map map : list) {
+//            //投手名
+//            updateUserName(map, "put_user_id", "put_user_name", userMap);
+//            //运营人员名
+//            updateUserName(map, "oper_user_id", "oper_user_name", userMap);
+//            //GS人员名
+//            updateUserName(map, "gs_id", "gs_name", userMap);
+//            //客服人员名
+//            updateUserName(map, "customer_service_id", "customer_service_name", userMap);
+//        }
+        //返回结果
+        log.info("查询总记录数耗时:{}",watch.getTotalTimeMillis());
+        log.info("查询数据耗时:{}",watch2.getTotalTimeMillis());
         return new Page<>(list, pager);
     }
 
@@ -2136,6 +2224,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                         a.association_user_id as association_user_id, -- 来源的用户id
                         a.source_system as source_system, -- sdk来源
                         a.role_id as role_id, -- 角色id
+                        a.os as os, -- 角色操作系统
                         b.role_name as role_name, -- 角色名
                         a.create_time as role_create_time, -- 角色创建时间
                         b.role_level as role_level, -- 角色等级
@@ -2201,6 +2290,7 @@ public class RoleManageServiceImpl implements IRoleManageService {
                                 a.role_id,
                                 a.role_name,
                                 a.create_time,
+                                a.os,
                                 ROW_NUMBER()over(partition by a.role_id , a.source_system order by a.create_time asc, a.user_id asc) as num
                             FROM dm_game_order.t_game_user_role a
                             LEFT JOIN dm_game_order.t_game_user b on a.source_system = b.source_system AND a.user_id = b.id