diff --git a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/DatavRestController.java b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/DatavRestController.java index 2fd70cb2..22bc97e4 100644 --- a/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/DatavRestController.java +++ b/rc-service/rc-service-console/console-adapter/src/main/java/com/red/circle/console/adapter/app/user/DatavRestController.java @@ -73,6 +73,18 @@ public class DatavRestController extends BaseController { return countryDashboardGameMetricService.pageGameMetrics(cmd); } + @GetMapping("/country-dashboard/game-metrics/games") + public PageResult countryDashboardGameMetricGames( + CountryDashboardGameMetricQryCmd cmd) { + return countryDashboardGameMetricService.pageGameSummaries(cmd); + } + + @GetMapping("/country-dashboard/game-metrics/country-rank") + public List countryDashboardGameMetricCountryRanks( + CountryDashboardGameMetricQryCmd cmd) { + return countryDashboardGameMetricService.listGameCountryRanks(cmd); + } + @PostMapping("/country-dashboard/backfill") public Map backfillCountryDashboard( @RequestParam String startDate, diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricServiceImpl.java index 9bd669e9..0186b0ff 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricServiceImpl.java @@ -83,10 +83,7 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa SortSpec sortSpec = normalizeSort(cmd == null ? null : cmd.getSortField(), cmd == null ? null : cmd.getSortOrder()); String countryCodes = normalizeCsv(cmd == null ? null : cmd.getCountryCodes()); - String gameProvider = trimToNull(cmd == null ? null : cmd.getGameProvider()); - if (gameProvider != null) { - gameProvider = gameProvider.toUpperCase(Locale.ROOT); - } + String gameProvider = normalizeGameProvider(cmd == null ? null : cmd.getGameProvider()); String gameKeyword = trimToNull(cmd == null ? null : cmd.getGameKeyword()); Long total = countryDashboardDAO.countGamePeriodMetrics( @@ -108,6 +105,76 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa return result; } + @Override + public PageResult pageGameSummaries( + CountryDashboardGameMetricQryCmd cmd) { + ensureMetricSchema(); + QueryCondition condition = QueryCondition.of(cmd); + int cursor = Math.max(1, cmd == null || cmd.getCursor() == null ? 1 : cmd.getCursor()); + int limit = Math.max(1, cmd == null || cmd.getLimit() == null ? 50 : cmd.getLimit()); + limit = Math.min(200, limit); + int offset = (cursor - 1) * limit; + + PageResult result = new PageResult<>(); + result.setCurrent(cursor); + result.setSize(limit); + if (!hasText(condition.sysOrigin)) { + result.setTotal(0L); + result.setRecords(List.of()); + return result; + } + + SortSpec sortSpec = normalizeSummarySort(cmd == null ? null : cmd.getSortField(), + cmd == null ? null : cmd.getSortOrder()); + String countryCodes = normalizeCsv(cmd == null ? null : cmd.getCountryCodes()); + String gameProvider = normalizeGameProvider(cmd == null ? null : cmd.getGameProvider()); + String gameKeyword = trimToNull(cmd == null ? null : cmd.getGameKeyword()); + + Long total = countryDashboardDAO.countGameSummaryMetrics( + condition.periodType, condition.startTime, condition.endTime, + PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null, + condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword, + condition.sysOrigin); + List records = countryDashboardDAO.listGameSummaryMetrics( + condition.periodType, condition.startTime, condition.endTime, + PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null, + condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, gameKeyword, + condition.sysOrigin, sortSpec.column(), sortSpec.direction(), offset, limit) + .stream() + .map(this::toCO) + .toList(); + + result.setTotal(total == null ? 0L : total); + result.setRecords(records); + return result; + } + + @Override + public List listGameCountryRanks( + CountryDashboardGameMetricQryCmd cmd) { + ensureMetricSchema(); + QueryCondition condition = QueryCondition.of(cmd); + if (!hasText(condition.sysOrigin)) { + return List.of(); + } + String gameProvider = normalizeGameProvider(cmd == null ? null : cmd.getGameProvider()); + String gameId = trimToNull(cmd == null ? null : cmd.getGameId()); + if (gameProvider == null || gameId == null) { + return List.of(); + } + int limit = Math.max(1, cmd.getRankLimit() == null ? 100 : cmd.getRankLimit()); + limit = Math.min(500, limit); + String countryCodes = normalizeCsv(cmd.getCountryCodes()); + return countryDashboardDAO.listGameCountryRankMetrics( + condition.periodType, condition.startTime, condition.endTime, + PERIOD_ALL.equals(condition.periodType) ? PERIOD_ALL : null, + condition.statTimezone, condition.countryKeyword, countryCodes, gameProvider, null, + gameId, condition.sysOrigin, limit) + .stream() + .map(this::toCO) + .toList(); + } + @Override public void refreshRecentDays(int days) { ensureMetricSchema(); @@ -457,6 +524,24 @@ public class CountryDashboardGameMetricServiceImpl implements CountryDashboardGa return new SortSpec(column, direction); } + private static SortSpec normalizeSummarySort(String sortField, String sortOrder) { + String column = switch (Objects.toString(sortField, "")) { + case "payoutAmount" -> "payoutAmount"; + case "profitAmount" -> "profitAmount"; + case "userCount" -> "userCount"; + case "orderCount" -> "orderCount"; + case "consumeAmount" -> "consumeAmount"; + default -> null; + }; + String direction = "ascend".equalsIgnoreCase(sortOrder) ? "ASC" : "DESC"; + return new SortSpec(column, direction); + } + + private static String normalizeGameProvider(String gameProvider) { + String value = trimToNull(gameProvider); + return value == null ? null : value.toUpperCase(Locale.ROOT); + } + private static StatTimezone normalizeStatTimezone(String statTimezone) { String value = trimToNull(statTimezone); if (value == null) { diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/datav/CountryDashboardGameMetricQryCmd.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/datav/CountryDashboardGameMetricQryCmd.java index c89511e8..63b45208 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/datav/CountryDashboardGameMetricQryCmd.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/datav/CountryDashboardGameMetricQryCmd.java @@ -36,11 +36,21 @@ public class CountryDashboardGameMetricQryCmd extends CountryDashboardQryCmd { */ private String gameProvider; + /** + * 游戏 ID. + */ + private String gameId; + /** * 游戏 ID 或名称关键字. */ private String gameKeyword; + /** + * 国家排名返回条数. + */ + private Integer rankLimit; + /** * 排序字段. */ diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricService.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricService.java index 8dd5f347..b8b5ac11 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricService.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardGameMetricService.java @@ -13,6 +13,10 @@ public interface CountryDashboardGameMetricService { PageResult pageGameMetrics(CountryDashboardGameMetricQryCmd cmd); + PageResult pageGameSummaries(CountryDashboardGameMetricQryCmd cmd); + + List listGameCountryRanks(CountryDashboardGameMetricQryCmd cmd); + void refreshRecentDays(int days); List refreshRange(LocalDate startDate, LocalDate endDate, String sysOrigin, diff --git a/rc-service/rc-service-console/console-infrastructure/src/main/java/com/red/circle/console/infra/database/rds/dao/datav/CountryDashboardDAO.java b/rc-service/rc-service-console/console-infrastructure/src/main/java/com/red/circle/console/infra/database/rds/dao/datav/CountryDashboardDAO.java index 1bfeb414..728b2a01 100644 --- a/rc-service/rc-service-console/console-infrastructure/src/main/java/com/red/circle/console/infra/database/rds/dao/datav/CountryDashboardDAO.java +++ b/rc-service/rc-service-console/console-infrastructure/src/main/java/com/red/circle/console/infra/database/rds/dao/datav/CountryDashboardDAO.java @@ -364,4 +364,46 @@ public interface CountryDashboardDAO extends BaseDAO { @Param("sortDirection") String sortDirection, @Param("offset") int offset, @Param("limit") int limit); + + Long countGameSummaryMetrics( + @Param("periodType") String periodType, + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime, + @Param("periodKey") String periodKey, + @Param("statTimezone") String statTimezone, + @Param("countryKeyword") String countryKeyword, + @Param("countryCodes") String countryCodes, + @Param("gameProvider") String gameProvider, + @Param("gameKeyword") String gameKeyword, + @Param("sysOrigin") String sysOrigin); + + List listGameSummaryMetrics( + @Param("periodType") String periodType, + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime, + @Param("periodKey") String periodKey, + @Param("statTimezone") String statTimezone, + @Param("countryKeyword") String countryKeyword, + @Param("countryCodes") String countryCodes, + @Param("gameProvider") String gameProvider, + @Param("gameKeyword") String gameKeyword, + @Param("sysOrigin") String sysOrigin, + @Param("sortColumn") String sortColumn, + @Param("sortDirection") String sortDirection, + @Param("offset") int offset, + @Param("limit") int limit); + + List listGameCountryRankMetrics( + @Param("periodType") String periodType, + @Param("startTime") LocalDateTime startTime, + @Param("endTime") LocalDateTime endTime, + @Param("periodKey") String periodKey, + @Param("statTimezone") String statTimezone, + @Param("countryKeyword") String countryKeyword, + @Param("countryCodes") String countryCodes, + @Param("gameProvider") String gameProvider, + @Param("gameKeyword") String gameKeyword, + @Param("gameId") String gameId, + @Param("sysOrigin") String sysOrigin, + @Param("limit") int limit); } diff --git a/rc-service/rc-service-console/console-infrastructure/src/main/resources/dao/datav/CountryDashboardDAO.xml b/rc-service/rc-service-console/console-infrastructure/src/main/resources/dao/datav/CountryDashboardDAO.xml index ffde7b2d..ea5537d0 100644 --- a/rc-service/rc-service-console/console-infrastructure/src/main/resources/dao/datav/CountryDashboardDAO.xml +++ b/rc-service/rc-service-console/console-infrastructure/src/main/resources/dao/datav/CountryDashboardDAO.xml @@ -1846,6 +1846,71 @@ LIMIT #{limit} OFFSET #{offset} + + + + + +