From 32a1094edc46095383af2d6582ae7bb4fbc20ca8 Mon Sep 17 00:00:00 2001 From: hy001 Date: Mon, 18 May 2026 21:57:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datav/CountryDashboardServiceImpl.java | 72 ++++++++++++++++--- .../datav/CountryDashboardMetricCO.java | 2 + 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardServiceImpl.java index 4ce4ef8d..1d357add 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/datav/CountryDashboardServiceImpl.java @@ -58,6 +58,10 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { private static final String COLLECTION_GIFT_GIVE_RUNNING_WATER = "gift_give_running_water"; private static final String COLLECTION_USER_DAILY_ACTIVE_LOG = "user_daily_active_log"; + private static final String COLLECTION_USER_BANK_RUNNING_WATER = "user_bank_running_water"; + private static final String BANK_EXCHANGE_GOLD_EVENT = "EXCHANGE_GOLD_COINS"; + private static final String BANK_TRANSFER_GOLD_EVENT = "TRANSFER_GOLD"; + private static final int RECEIPT_TYPE_EXPENDITURE = 1; private static final String PERIOD_ALL = "ALL"; private static final ZoneId STORAGE_ZONE_ID = ZoneId.of("Asia/Riyadh"); private static final ZoneId DEFAULT_STAT_ZONE_ID = STORAGE_ZONE_ID; @@ -81,6 +85,7 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { condition.countryKeyword, condition.statTimezone, condition.sysOrigin)); } else { mergeLiveSql(rows, condition); + mergeBankSalaryExchange(rows, condition); } if (usePrecomputedMetrics && condition.shouldOverlayLiveSalaryExchange()) { overlayLiveSalaryExchange(rows, condition); @@ -90,6 +95,8 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { (row, amount) -> row.setGiftConsume(add(row.getGiftConsume(), amount))); mergeMongo(rows, condition, listLuckyGiftAnchorShare(condition), (row, amount) -> row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), amount))); + mergeMongo(rows, condition, listBankSalaryTransfer(condition), + (row, amount) -> row.setSalaryTransfer(add(row.getSalaryTransfer(), amount))); mergeDailyActive(rows, condition, listDailyActive(condition)); mergeRetention(rows, condition); @@ -165,20 +172,31 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { private void overlayLiveSalaryExchange(Map rows, QueryCondition condition) { rows.values().forEach(row -> row.setSalaryExchange(BigDecimal.ZERO)); - List metrics = countryDashboardDAO.listSalaryExchange( + mergeSqlSalaryExchange(rows, countryDashboardDAO.listSalaryExchange( condition.periodType, condition.startTime, condition.endTime, condition.countryKeyword, condition.sysOrigin, - condition.storageTimezoneOffset, condition.statTimezoneOffset); + condition.storageTimezoneOffset, condition.statTimezoneOffset)); + mergeBankSalaryExchange(rows, condition); + } + + private void mergeSqlSalaryExchange(Map rows, + List metrics) { if (metrics == null || metrics.isEmpty()) { return; } for (CountryDashboardMetricDTO metric : metrics) { CountryDashboardMetricCO row = getRow(rows, metric.getCountryCode(), metric.getCountryName(), metric.getPeriodKey(), metric.getPeriodName()); - row.setSalaryExchange(safe(metric.getSalaryExchange())); + row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange())); } } + private void mergeBankSalaryExchange(Map rows, + QueryCondition condition) { + mergeMongo(rows, condition, listBankSalaryExchange(condition), + (row, amount) -> row.setSalaryExchange(add(row.getSalaryExchange(), amount))); + } + private boolean shouldUsePrecomputedMetrics(QueryCondition condition) { if (!hasText(condition.sysOrigin)) { return false; @@ -452,6 +470,22 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { return aggregateGiftAmount(criteria, "$acceptUsers.targetAmount", true, condition.statTimezone); } + private List listBankSalaryExchange(QueryCondition condition) { + List criteria = baseBankRunningWaterCriteria(condition); + criteria.add(Criteria.where("event").is(BANK_EXCHANGE_GOLD_EVENT)); + criteria.add(Criteria.where("type").is(RECEIPT_TYPE_EXPENDITURE)); + return aggregateMongoAmount(criteria, "$amount", false, condition.statTimezone, + COLLECTION_USER_BANK_RUNNING_WATER); + } + + private List listBankSalaryTransfer(QueryCondition condition) { + List criteria = baseBankRunningWaterCriteria(condition); + criteria.add(Criteria.where("event").is(BANK_TRANSFER_GOLD_EVENT)); + criteria.add(Criteria.where("type").is(RECEIPT_TYPE_EXPENDITURE)); + return aggregateMongoAmount(criteria, "$amount", false, condition.statTimezone, + COLLECTION_USER_BANK_RUNNING_WATER); + } + private List listDailyActive(QueryCondition condition) { List criteria = baseActiveCriteria(condition); List operations = new ArrayList<>(); @@ -506,18 +540,39 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { return criteria; } + private List baseBankRunningWaterCriteria(QueryCondition condition) { + List criteria = new ArrayList<>(); + criteria.add(Criteria.where("userId").ne(null)); + if (condition.startInstant != null) { + criteria.add(Criteria.where("createTime").gte(Timestamp.from(condition.startInstant))); + } + if (condition.endInstant != null) { + criteria.add(Criteria.where("createTime").lt(Timestamp.from(condition.endInstant))); + } + if (hasText(condition.sysOrigin)) { + criteria.add(Criteria.where("sysOrigin").is(condition.sysOrigin)); + } + return criteria; + } + private List aggregateGiftAmount(List criteria, String amountPath, boolean unwindAcceptUsers, String statTimezone) { + return aggregateMongoAmount(criteria, amountPath, unwindAcceptUsers, statTimezone, + COLLECTION_GIFT_GIVE_RUNNING_WATER); + } + + private List aggregateMongoAmount(List criteria, String amountPath, + boolean unwindAcceptUsers, String statTimezone, String collectionName) { List operations = new ArrayList<>(); operations.add(Aggregation.match(new Criteria().andOperator(criteria.toArray(new Criteria[0])))); if (unwindAcceptUsers) { operations.add(Aggregation.unwind("acceptUsers")); } - operations.add(projectGiftDayAmount(amountPath, statTimezone)); + operations.add(projectMongoDayAmount(amountPath, statTimezone)); operations.add(Aggregation.group("userId", "day").sum("amount").as("amount")); return mongoTemplate.aggregate(Aggregation.newAggregation(operations), - COLLECTION_GIFT_GIVE_RUNNING_WATER, Document.class) + collectionName, Document.class) .getMappedResults() .stream() .map(this::toMongoMetric) @@ -525,7 +580,7 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { .toList(); } - private AggregationOperation projectGiftDayAmount(String amountPath, String statTimezone) { + private AggregationOperation projectMongoDayAmount(String amountPath, String statTimezone) { return context -> new Document("$project", new Document("userId", "$userId") .append("amount", amountPath) @@ -698,6 +753,7 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { total.setGoogleRecharge(add(total.getGoogleRecharge(), row.getGoogleRecharge())); total.setDealerRecharge(add(total.getDealerRecharge(), row.getDealerRecharge())); total.setSalaryExchange(add(total.getSalaryExchange(), row.getSalaryExchange())); + total.setSalaryTransfer(add(total.getSalaryTransfer(), row.getSalaryTransfer())); total.setGiftConsume(add(total.getGiftConsume(), row.getGiftConsume())); total.setLuckyGiftTotalFlow(add(total.getLuckyGiftTotalFlow(), row.getLuckyGiftTotalFlow())); total.setLuckyGiftUser(total.getLuckyGiftUser() + safeLong(row.getLuckyGiftUser())); @@ -916,10 +972,6 @@ public class CountryDashboardServiceImpl implements CountryDashboardService { if (PERIOD_ALL.equals(periodType) || startDateValue == null || endDateValue == null) { return false; } - LocalDate today = LocalDate.now(statZoneId); - if (endDateValue.isBefore(today) || startDateValue.isAfter(today)) { - return false; - } long days = ChronoUnit.DAYS.between(startDateValue, endDateValue.plusDays(1)); return days <= 31; } diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clientobject/datav/CountryDashboardMetricCO.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clientobject/datav/CountryDashboardMetricCO.java index 34880388..efd94c51 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clientobject/datav/CountryDashboardMetricCO.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clientobject/datav/CountryDashboardMetricCO.java @@ -38,6 +38,8 @@ public class CountryDashboardMetricCO implements Serializable { private BigDecimal salaryExchange = BigDecimal.ZERO; + private BigDecimal salaryTransfer = BigDecimal.ZERO; + private BigDecimal totalRecharge = BigDecimal.ZERO; private BigDecimal giftConsume = BigDecimal.ZERO;