Compare commits
No commits in common. "1520362d9f33bd9cd1800d0952d509c98a87cb4e" and "98d80c673233f7b5bcdbdfa01a1fcfb6cebcd981" have entirely different histories.
1520362d9f
...
98d80c6732
@ -5,10 +5,7 @@ import com.red.circle.console.infra.database.rds.dao.datav.CountryDashboardDAO;
|
|||||||
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardDailyMetricDTO;
|
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardDailyMetricDTO;
|
||||||
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardMetricDTO;
|
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardMetricDTO;
|
||||||
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardPeriodMetricDTO;
|
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardPeriodMetricDTO;
|
||||||
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardRetentionUserDTO;
|
|
||||||
import com.red.circle.console.infra.database.rds.dto.datav.CountryDashboardUserCountryDTO;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@ -20,7 +17,6 @@ import java.time.temporal.ChronoUnit;
|
|||||||
import java.time.temporal.WeekFields;
|
import java.time.temporal.WeekFields;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,17 +24,9 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
|
||||||
import org.bson.types.Decimal128;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
||||||
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
||||||
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
|
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.support.TransactionTemplate;
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
@ -61,13 +49,9 @@ public class CountryDashboardDailyMetricService {
|
|||||||
private static final ZoneId STORAGE_ZONE_ID = ZoneId.of("Asia/Riyadh");
|
private static final ZoneId STORAGE_ZONE_ID = ZoneId.of("Asia/Riyadh");
|
||||||
private static final String STORAGE_TIMEZONE = "Asia/Riyadh";
|
private static final String STORAGE_TIMEZONE = "Asia/Riyadh";
|
||||||
private static final String STORAGE_TIMEZONE_OFFSET = "+03:00";
|
private static final String STORAGE_TIMEZONE_OFFSET = "+03:00";
|
||||||
private static final String COLLECTION_USER_DAILY_ACTIVE_LOG = "user_daily_active_log";
|
|
||||||
private static final String COLLECTION_GIFT_GIVE_RUNNING_WATER = "gift_give_running_water";
|
|
||||||
private static final int USER_BATCH_SIZE = 1000;
|
|
||||||
|
|
||||||
private final CountryDashboardDAO countryDashboardDAO;
|
private final CountryDashboardDAO countryDashboardDAO;
|
||||||
private final TransactionTemplate transactionTemplate;
|
private final TransactionTemplate transactionTemplate;
|
||||||
private final MongoTemplate mongoTemplate;
|
|
||||||
|
|
||||||
@Value("${red-circle.country-dashboard.refresh-sys-origins:LIKEI}")
|
@Value("${red-circle.country-dashboard.refresh-sys-origins:LIKEI}")
|
||||||
private String refreshSysOrigins;
|
private String refreshSysOrigins;
|
||||||
@ -175,8 +159,6 @@ public class CountryDashboardDailyMetricService {
|
|||||||
countryDashboardDAO.createPeriodMetricTable();
|
countryDashboardDAO.createPeriodMetricTable();
|
||||||
countryDashboardDAO.createPeriodUserMetricTable();
|
countryDashboardDAO.createPeriodUserMetricTable();
|
||||||
countryDashboardDAO.ensurePeriodMetricTimezoneSchema();
|
countryDashboardDAO.ensurePeriodMetricTimezoneSchema();
|
||||||
countryDashboardDAO.ensurePeriodMetricUserColumnsSchema();
|
|
||||||
countryDashboardDAO.ensureMetricValueColumnsSchema();
|
|
||||||
metricSchemaEnsured = true;
|
metricSchemaEnsured = true;
|
||||||
log.info("country dashboard metric tables ensured");
|
log.info("country dashboard metric tables ensured");
|
||||||
}
|
}
|
||||||
@ -233,14 +215,6 @@ public class CountryDashboardDailyMetricService {
|
|||||||
PERIOD_DAY, startTime, endTime, startTimeMillis, endTimeMillis, null, sysOrigin,
|
PERIOD_DAY, startTime, endTime, startTimeMillis, endTimeMillis, null, sysOrigin,
|
||||||
STORAGE_TIMEZONE_OFFSET, STORAGE_TIMEZONE_OFFSET),
|
STORAGE_TIMEZONE_OFFSET, STORAGE_TIMEZONE_OFFSET),
|
||||||
statDate, sysOrigin);
|
statDate, sysOrigin);
|
||||||
TimeWindow timeWindow = new TimeWindow(startTime, endTime, startTimeMillis, endTimeMillis,
|
|
||||||
statDate.atStartOfDay(STORAGE_ZONE_ID).toInstant(),
|
|
||||||
statDate.plusDays(1).atStartOfDay(STORAGE_ZONE_ID).toInstant());
|
|
||||||
mergeDailyMongo(rows, listGiftConsume(timeWindow, sysOrigin, STORAGE_TIMEZONE),
|
|
||||||
(row, amount) -> row.setGiftConsume(add(row.getGiftConsume(), amount)), statDate, sysOrigin);
|
|
||||||
mergeDailyMongo(rows, listLuckyGiftAnchorShare(timeWindow, sysOrigin, STORAGE_TIMEZONE),
|
|
||||||
(row, amount) -> row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), amount)),
|
|
||||||
statDate, sysOrigin);
|
|
||||||
|
|
||||||
List<CountryDashboardDailyMetricDTO> metrics = new ArrayList<>(rows.values());
|
List<CountryDashboardDailyMetricDTO> metrics = new ArrayList<>(rows.values());
|
||||||
RefreshWriteResult writeResult = transactionTemplate.execute(status -> {
|
RefreshWriteResult writeResult = transactionTemplate.execute(status -> {
|
||||||
@ -310,15 +284,6 @@ public class CountryDashboardDailyMetricService {
|
|||||||
mergePeriodAmounts(rows, countryDashboardDAO.listLuckyBoxGame(
|
mergePeriodAmounts(rows, countryDashboardDAO.listLuckyBoxGame(
|
||||||
window.periodType(), startTime, endTime, null, sysOrigin,
|
window.periodType(), startTime, endTime, null, sysOrigin,
|
||||||
STORAGE_TIMEZONE_OFFSET, statTimezone.offset()), window, sysOrigin, statTimezone);
|
STORAGE_TIMEZONE_OFFSET, statTimezone.offset()), window, sysOrigin, statTimezone);
|
||||||
mergePeriodMongo(rows, listGiftConsume(timeWindow, sysOrigin, statTimezone.id()),
|
|
||||||
(row, amount) -> row.setGiftConsume(add(row.getGiftConsume(), amount)),
|
|
||||||
window, sysOrigin, statTimezone);
|
|
||||||
mergePeriodMongo(rows, listLuckyGiftAnchorShare(timeWindow, sysOrigin, statTimezone.id()),
|
|
||||||
(row, amount) -> row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), amount)),
|
|
||||||
window, sysOrigin, statTimezone);
|
|
||||||
mergePeriodDailyActive(rows, listDailyActive(window, sysOrigin), window, sysOrigin,
|
|
||||||
statTimezone);
|
|
||||||
mergePeriodRetention(rows, window, sysOrigin, statTimezone, startTime, endTime);
|
|
||||||
|
|
||||||
RefreshWriteResult writeResult = transactionTemplate.execute(status -> {
|
RefreshWriteResult writeResult = transactionTemplate.execute(status -> {
|
||||||
countryDashboardDAO.deletePeriodUserMetrics(window.periodType(), window.periodKey(),
|
countryDashboardDAO.deletePeriodUserMetrics(window.periodType(), window.periodKey(),
|
||||||
@ -393,11 +358,9 @@ public class CountryDashboardDailyMetricService {
|
|||||||
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
||||||
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
||||||
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
||||||
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
|
|
||||||
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
||||||
row.setLuckyGiftUser(safeLong(row.getLuckyGiftUser()) + safeLong(metric.getLuckyGiftUser()));
|
row.setLuckyGiftUser(safeLong(row.getLuckyGiftUser()) + safeLong(metric.getLuckyGiftUser()));
|
||||||
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
||||||
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
|
|
||||||
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
||||||
row.setGameUser(safeLong(row.getGameUser()) + safeLong(metric.getGameUser()));
|
row.setGameUser(safeLong(row.getGameUser()) + safeLong(metric.getGameUser()));
|
||||||
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
||||||
@ -419,10 +382,8 @@ public class CountryDashboardDailyMetricService {
|
|||||||
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
||||||
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
||||||
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
||||||
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
|
|
||||||
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
||||||
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
||||||
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
|
|
||||||
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
||||||
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
||||||
}
|
}
|
||||||
@ -443,296 +404,6 @@ public class CountryDashboardDailyMetricService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergePeriodDailyActive(Map<String, CountryDashboardPeriodMetricDTO> rows,
|
|
||||||
List<CountryDashboardMetricDTO> metrics, PeriodWindow window, String sysOrigin,
|
|
||||||
StatTimezone statTimezone) {
|
|
||||||
if (metrics == null || metrics.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (CountryDashboardMetricDTO metric : metrics) {
|
|
||||||
CountryDashboardPeriodMetricDTO row = getPeriodRow(rows, metric, window, sysOrigin,
|
|
||||||
statTimezone);
|
|
||||||
row.setDailyActiveUser(safeLong(row.getDailyActiveUser()) + safeLong(metric.getDailyActiveUser()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeDailyMongo(Map<String, CountryDashboardDailyMetricDTO> rows,
|
|
||||||
List<MongoMetric> metrics, BiConsumer<CountryDashboardDailyMetricDTO, BigDecimal> merger,
|
|
||||||
LocalDate statDate, String sysOrigin) {
|
|
||||||
if (metrics == null || metrics.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<Long, CountryDashboardUserCountryDTO> countryMap = mapUserCountries(
|
|
||||||
metrics.stream().map(MongoMetric::userId).filter(Objects::nonNull).distinct().toList());
|
|
||||||
for (MongoMetric metric : metrics) {
|
|
||||||
CountryDashboardUserCountryDTO country = countryMap.get(metric.userId());
|
|
||||||
if (country == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
CountryDashboardMetricDTO rowKey = new CountryDashboardMetricDTO()
|
|
||||||
.setCountryCode(country.getCountryCode())
|
|
||||||
.setCountryName(country.getCountryName());
|
|
||||||
merger.accept(getRow(rows, rowKey, statDate, sysOrigin), metric.amount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergePeriodMongo(Map<String, CountryDashboardPeriodMetricDTO> rows,
|
|
||||||
List<MongoMetric> metrics, BiConsumer<CountryDashboardPeriodMetricDTO, BigDecimal> merger,
|
|
||||||
PeriodWindow window, String sysOrigin, StatTimezone statTimezone) {
|
|
||||||
if (metrics == null || metrics.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<Long, CountryDashboardUserCountryDTO> countryMap = mapUserCountries(
|
|
||||||
metrics.stream().map(MongoMetric::userId).filter(Objects::nonNull).distinct().toList());
|
|
||||||
for (MongoMetric metric : metrics) {
|
|
||||||
CountryDashboardUserCountryDTO country = countryMap.get(metric.userId());
|
|
||||||
if (country == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
CountryDashboardMetricDTO rowKey = new CountryDashboardMetricDTO()
|
|
||||||
.setCountryCode(country.getCountryCode())
|
|
||||||
.setCountryName(country.getCountryName());
|
|
||||||
merger.accept(getPeriodRow(rows, rowKey, window, sysOrigin, statTimezone), metric.amount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergePeriodRetention(Map<String, CountryDashboardPeriodMetricDTO> rows,
|
|
||||||
PeriodWindow window, String sysOrigin, StatTimezone statTimezone, LocalDateTime startTime,
|
|
||||||
LocalDateTime endTime) {
|
|
||||||
mergePeriodRetentionDays(rows, window, sysOrigin, statTimezone, startTime.minusDays(1),
|
|
||||||
endTime.minusDays(1), 1);
|
|
||||||
mergePeriodRetentionDays(rows, window, sysOrigin, statTimezone, startTime.minusDays(7),
|
|
||||||
endTime.minusDays(7), 7);
|
|
||||||
mergePeriodRetentionDays(rows, window, sysOrigin, statTimezone, startTime.minusDays(30),
|
|
||||||
endTime.minusDays(30), 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergePeriodRetentionDays(Map<String, CountryDashboardPeriodMetricDTO> rows,
|
|
||||||
PeriodWindow window, String sysOrigin, StatTimezone statTimezone, LocalDateTime cohortStartTime,
|
|
||||||
LocalDateTime cohortEndTime, int retentionDays) {
|
|
||||||
List<CountryDashboardRetentionUserDTO> cohorts = countryDashboardDAO.listNewUserCohorts(
|
|
||||||
window.periodType(), cohortStartTime, cohortEndTime, null, sysOrigin,
|
|
||||||
STORAGE_TIMEZONE_OFFSET, statTimezone.offset());
|
|
||||||
if (cohorts == null || cohorts.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalDate today = LocalDate.now(statTimezone.zoneId());
|
|
||||||
Set<Long> userIds = new HashSet<>();
|
|
||||||
Set<String> activeDates = new HashSet<>();
|
|
||||||
for (CountryDashboardRetentionUserDTO cohort : cohorts) {
|
|
||||||
if (cohort.getUserId() == null || !hasText(cohort.getRegisterDate())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
userIds.add(cohort.getUserId());
|
|
||||||
collectRetentionActiveDate(activeDates, cohort.getRegisterDate(), retentionDays, today);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> activeUserDates = listActiveUserDateSet(userIds, activeDates, sysOrigin);
|
|
||||||
for (CountryDashboardRetentionUserDTO cohort : cohorts) {
|
|
||||||
if (cohort.getUserId() == null || !hasText(cohort.getRegisterDate())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
CountryDashboardMetricDTO metric = new CountryDashboardMetricDTO()
|
|
||||||
.setCountryCode(cohort.getCountryCode())
|
|
||||||
.setCountryName(cohort.getCountryName());
|
|
||||||
CountryDashboardPeriodMetricDTO row = getPeriodRow(rows, metric, window, sysOrigin,
|
|
||||||
statTimezone);
|
|
||||||
mergeRetentionDay(row, cohort.getUserId(), cohort.getRegisterDate(), retentionDays, today,
|
|
||||||
activeUserDates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<CountryDashboardMetricDTO> listDailyActive(PeriodWindow window, String sysOrigin) {
|
|
||||||
if (window.periodStartDate() == null || window.periodEndDate() == null) {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
List<Criteria> criteria = new ArrayList<>();
|
|
||||||
criteria.add(Criteria.where("activeDate")
|
|
||||||
.gte(window.periodStartDate().format(DATE_FORMATTER))
|
|
||||||
.lt(window.periodEndDate().format(DATE_FORMATTER)));
|
|
||||||
if (hasText(sysOrigin)) {
|
|
||||||
criteria.add(Criteria.where("sysOrigin").is(sysOrigin));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AggregationOperation> operations = new ArrayList<>();
|
|
||||||
operations.add(Aggregation.match(new Criteria().andOperator(criteria.toArray(new Criteria[0]))));
|
|
||||||
operations.add(Aggregation.group("registerCountryCode", "userId"));
|
|
||||||
operations.add(Aggregation.group("_id.registerCountryCode").count().as("dailyActiveUser"));
|
|
||||||
|
|
||||||
return mongoTemplate.aggregate(Aggregation.newAggregation(operations),
|
|
||||||
COLLECTION_USER_DAILY_ACTIVE_LOG, Document.class)
|
|
||||||
.getMappedResults()
|
|
||||||
.stream()
|
|
||||||
.map(this::toDailyActiveMetric)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CountryDashboardMetricDTO toDailyActiveMetric(Document document) {
|
|
||||||
String countryCode = normalizeCountryCode(document.get("_id"));
|
|
||||||
Long dailyActiveUser = toLong(document.get("dailyActiveUser"));
|
|
||||||
if (dailyActiveUser == null || dailyActiveUser <= 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new CountryDashboardMetricDTO()
|
|
||||||
.setCountryCode(countryCode)
|
|
||||||
.setCountryName(countryCode)
|
|
||||||
.setDailyActiveUser(dailyActiveUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MongoMetric> listGiftConsume(TimeWindow timeWindow, String sysOrigin,
|
|
||||||
String statTimezone) {
|
|
||||||
List<Criteria> criteria = baseGiftCriteria(timeWindow, sysOrigin);
|
|
||||||
criteria.add(Criteria.where("luckyGift").ne(Boolean.TRUE));
|
|
||||||
criteria.add(Criteria.where("originId").regex("^\\d+$"));
|
|
||||||
criteria.add(new Criteria().orOperator(
|
|
||||||
Criteria.where("dynamicContentId").exists(false),
|
|
||||||
Criteria.where("dynamicContentId").is(null),
|
|
||||||
Criteria.where("dynamicContentId").is("")
|
|
||||||
));
|
|
||||||
return aggregateGiftAmount(criteria, "$giftValue.actualAmount", false, statTimezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MongoMetric> listLuckyGiftAnchorShare(TimeWindow timeWindow, String sysOrigin,
|
|
||||||
String statTimezone) {
|
|
||||||
List<Criteria> criteria = baseGiftCriteria(timeWindow, sysOrigin);
|
|
||||||
criteria.add(Criteria.where("luckyGift").is(Boolean.TRUE));
|
|
||||||
return aggregateGiftAmount(criteria, "$acceptUsers.targetAmount", true, statTimezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Criteria> baseGiftCriteria(TimeWindow timeWindow, String sysOrigin) {
|
|
||||||
List<Criteria> criteria = new ArrayList<>();
|
|
||||||
criteria.add(Criteria.where("refunded").ne(Boolean.TRUE));
|
|
||||||
criteria.add(Criteria.where("userId").ne(null));
|
|
||||||
criteria.add(Criteria.where("createTime").gte(Timestamp.from(timeWindow.startInstant())));
|
|
||||||
criteria.add(Criteria.where("createTime").lt(Timestamp.from(timeWindow.endInstant())));
|
|
||||||
if (hasText(sysOrigin)) {
|
|
||||||
criteria.add(Criteria.where("sysOrigin").is(sysOrigin));
|
|
||||||
}
|
|
||||||
return criteria;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MongoMetric> aggregateGiftAmount(List<Criteria> criteria, String amountPath,
|
|
||||||
boolean unwindAcceptUsers, String statTimezone) {
|
|
||||||
List<AggregationOperation> operations = new ArrayList<>();
|
|
||||||
operations.add(Aggregation.match(new Criteria().andOperator(criteria.toArray(new Criteria[0]))));
|
|
||||||
if (unwindAcceptUsers) {
|
|
||||||
operations.add(Aggregation.unwind("acceptUsers"));
|
|
||||||
}
|
|
||||||
operations.add(context -> new Document("$project",
|
|
||||||
new Document("userId", "$userId")
|
|
||||||
.append("amount", amountPath)
|
|
||||||
.append("day", new Document("$dateToString",
|
|
||||||
new Document("format", "%Y-%m-%d")
|
|
||||||
.append("date", "$createTime")
|
|
||||||
.append("timezone", statTimezone)))));
|
|
||||||
operations.add(Aggregation.group("userId", "day").sum("amount").as("amount"));
|
|
||||||
|
|
||||||
return mongoTemplate.aggregate(Aggregation.newAggregation(operations),
|
|
||||||
COLLECTION_GIFT_GIVE_RUNNING_WATER, Document.class)
|
|
||||||
.getMappedResults()
|
|
||||||
.stream()
|
|
||||||
.map(this::toMongoMetric)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MongoMetric toMongoMetric(Document document) {
|
|
||||||
Object id = document.get("_id");
|
|
||||||
if (!(id instanceof Document idDoc)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Long userId = toLong(idDoc.get("userId"));
|
|
||||||
String day = Objects.toString(idDoc.get("day"), null);
|
|
||||||
BigDecimal amount = toBigDecimal(document.get("amount"));
|
|
||||||
if (userId == null || !hasText(day) || amount == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new MongoMetric(userId, day, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void collectRetentionActiveDate(Set<String> activeDates, String registerDate,
|
|
||||||
int retentionDays, LocalDate today) {
|
|
||||||
LocalDate targetDate = LocalDate.parse(registerDate, DATE_FORMATTER).plusDays(retentionDays);
|
|
||||||
if (!targetDate.isAfter(today)) {
|
|
||||||
activeDates.add(targetDate.format(DATE_FORMATTER));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeRetentionDay(CountryDashboardPeriodMetricDTO row, Long userId,
|
|
||||||
String registerDate, int retentionDays, LocalDate today, Set<String> activeUserDates) {
|
|
||||||
LocalDate targetDate = LocalDate.parse(registerDate, DATE_FORMATTER).plusDays(retentionDays);
|
|
||||||
if (targetDate.isAfter(today)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String activeKey = userId + "|" + targetDate.format(DATE_FORMATTER);
|
|
||||||
boolean retained = activeUserDates.contains(activeKey);
|
|
||||||
if (retentionDays == 1) {
|
|
||||||
row.setD1RetentionBaseUser(safeLong(row.getD1RetentionBaseUser()) + 1);
|
|
||||||
row.setD1RetentionUser(safeLong(row.getD1RetentionUser()) + (retained ? 1 : 0));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (retentionDays == 7) {
|
|
||||||
row.setD7RetentionBaseUser(safeLong(row.getD7RetentionBaseUser()) + 1);
|
|
||||||
row.setD7RetentionUser(safeLong(row.getD7RetentionUser()) + (retained ? 1 : 0));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
row.setD30RetentionBaseUser(safeLong(row.getD30RetentionBaseUser()) + 1);
|
|
||||||
row.setD30RetentionUser(safeLong(row.getD30RetentionUser()) + (retained ? 1 : 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> listActiveUserDateSet(Set<Long> userIds, Set<String> activeDates,
|
|
||||||
String sysOrigin) {
|
|
||||||
Set<String> result = new HashSet<>();
|
|
||||||
if (userIds == null || userIds.isEmpty() || activeDates == null || activeDates.isEmpty()) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
List<Long> ids = new ArrayList<>(userIds);
|
|
||||||
for (int start = 0; start < ids.size(); start += USER_BATCH_SIZE) {
|
|
||||||
int end = Math.min(start + USER_BATCH_SIZE, ids.size());
|
|
||||||
List<Criteria> criteria = new ArrayList<>();
|
|
||||||
criteria.add(Criteria.where("userId").in(ids.subList(start, end)));
|
|
||||||
criteria.add(Criteria.where("activeDate").in(activeDates));
|
|
||||||
if (hasText(sysOrigin)) {
|
|
||||||
criteria.add(Criteria.where("sysOrigin").is(sysOrigin));
|
|
||||||
}
|
|
||||||
Query query = Query.query(new Criteria().andOperator(criteria.toArray(new Criteria[0])));
|
|
||||||
query.fields().include("userId").include("activeDate");
|
|
||||||
List<Document> documents = mongoTemplate.find(query, Document.class,
|
|
||||||
COLLECTION_USER_DAILY_ACTIVE_LOG);
|
|
||||||
for (Document document : documents) {
|
|
||||||
Long userId = toLong(document.get("userId"));
|
|
||||||
String activeDate = Objects.toString(document.get("activeDate"), null);
|
|
||||||
if (userId != null && hasText(activeDate)) {
|
|
||||||
result.add(userId + "|" + activeDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<Long, CountryDashboardUserCountryDTO> mapUserCountries(List<Long> userIds) {
|
|
||||||
Map<Long, CountryDashboardUserCountryDTO> result = new LinkedHashMap<>();
|
|
||||||
if (userIds == null || userIds.isEmpty()) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
for (int start = 0; start < userIds.size(); start += USER_BATCH_SIZE) {
|
|
||||||
int end = Math.min(start + USER_BATCH_SIZE, userIds.size());
|
|
||||||
List<CountryDashboardUserCountryDTO> batch = countryDashboardDAO.listUserCountryByIds(
|
|
||||||
userIds.subList(start, end));
|
|
||||||
if (batch == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (CountryDashboardUserCountryDTO item : batch) {
|
|
||||||
if (item.getUserId() != null) {
|
|
||||||
result.put(item.getUserId(), item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CountryDashboardDailyMetricDTO getRow(Map<String, CountryDashboardDailyMetricDTO> rows,
|
private CountryDashboardDailyMetricDTO getRow(Map<String, CountryDashboardDailyMetricDTO> rows,
|
||||||
CountryDashboardMetricDTO metric, LocalDate statDate, String sysOrigin) {
|
CountryDashboardMetricDTO metric, LocalDate statDate, String sysOrigin) {
|
||||||
String countryCode = hasText(metric.getCountryCode()) ? metric.getCountryCode() : "UNKNOWN";
|
String countryCode = hasText(metric.getCountryCode()) ? metric.getCountryCode() : "UNKNOWN";
|
||||||
@ -806,9 +477,7 @@ public class CountryDashboardDailyMetricService {
|
|||||||
LocalDateTime.ofInstant(startInstant, STORAGE_ZONE_ID),
|
LocalDateTime.ofInstant(startInstant, STORAGE_ZONE_ID),
|
||||||
LocalDateTime.ofInstant(endInstant, STORAGE_ZONE_ID),
|
LocalDateTime.ofInstant(endInstant, STORAGE_ZONE_ID),
|
||||||
startInstant.toEpochMilli(),
|
startInstant.toEpochMilli(),
|
||||||
endInstant.toEpochMilli(),
|
endInstant.toEpochMilli());
|
||||||
startInstant,
|
|
||||||
endInstant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<StatTimezone> resolveStatTimezones(String statTimezonesValue) {
|
private List<StatTimezone> resolveStatTimezones(String statTimezonesValue) {
|
||||||
@ -890,37 +559,6 @@ public class CountryDashboardDailyMetricService {
|
|||||||
return value == null ? 0L : value;
|
return value == null ? 0L : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long toLong(Object value) {
|
|
||||||
if (value instanceof Number number) {
|
|
||||||
return number.longValue();
|
|
||||||
}
|
|
||||||
if (value == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Long.valueOf(Objects.toString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BigDecimal toBigDecimal(Object value) {
|
|
||||||
if (value == null) {
|
|
||||||
return BigDecimal.ZERO;
|
|
||||||
}
|
|
||||||
if (value instanceof BigDecimal bigDecimal) {
|
|
||||||
return bigDecimal;
|
|
||||||
}
|
|
||||||
if (value instanceof Decimal128 decimal128) {
|
|
||||||
return decimal128.bigDecimalValue();
|
|
||||||
}
|
|
||||||
if (value instanceof Number number) {
|
|
||||||
return new BigDecimal(number.toString());
|
|
||||||
}
|
|
||||||
return new BigDecimal(Objects.toString(value, "0"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String normalizeCountryCode(Object value) {
|
|
||||||
String countryCode = Objects.toString(value, "").trim();
|
|
||||||
return countryCode.isEmpty() ? "UNKNOWN" : countryCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean hasText(String value) {
|
private static boolean hasText(String value) {
|
||||||
return value != null && !value.trim().isEmpty();
|
return value != null && !value.trim().isEmpty();
|
||||||
}
|
}
|
||||||
@ -941,12 +579,9 @@ public class CountryDashboardDailyMetricService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private record TimeWindow(LocalDateTime startTime, LocalDateTime endTime,
|
private record TimeWindow(LocalDateTime startTime, LocalDateTime endTime,
|
||||||
Long startTimeMillis, Long endTimeMillis, Instant startInstant, Instant endInstant) {
|
Long startTimeMillis, Long endTimeMillis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private record RefreshWriteResult(int deleted, int inserted, int userRows) {
|
private record RefreshWriteResult(int deleted, int inserted, int userRows) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private record MongoMetric(Long userId, String day, BigDecimal amount) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,11 +73,9 @@ public class CountryDashboardServiceImpl implements CountryDashboardService {
|
|||||||
private final CountryDashboardDAO countryDashboardDAO;
|
private final CountryDashboardDAO countryDashboardDAO;
|
||||||
private final MongoTemplate mongoTemplate;
|
private final MongoTemplate mongoTemplate;
|
||||||
private volatile boolean rechargeDetailSchemaEnsured;
|
private volatile boolean rechargeDetailSchemaEnsured;
|
||||||
private volatile boolean periodMetricSchemaEnsured;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CountryDashboardCO query(CountryDashboardQryCmd cmd) {
|
public CountryDashboardCO query(CountryDashboardQryCmd cmd) {
|
||||||
ensurePeriodMetricSchema();
|
|
||||||
QueryCondition condition = QueryCondition.of(cmd);
|
QueryCondition condition = QueryCondition.of(cmd);
|
||||||
Map<String, CountryDashboardMetricCO> rows = new LinkedHashMap<>();
|
Map<String, CountryDashboardMetricCO> rows = new LinkedHashMap<>();
|
||||||
|
|
||||||
@ -327,21 +325,6 @@ public class CountryDashboardServiceImpl implements CountryDashboardService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensurePeriodMetricSchema() {
|
|
||||||
if (periodMetricSchemaEnsured) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
synchronized (this) {
|
|
||||||
if (periodMetricSchemaEnsured) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
countryDashboardDAO.createPeriodMetricTable();
|
|
||||||
countryDashboardDAO.ensurePeriodMetricUserColumnsSchema();
|
|
||||||
countryDashboardDAO.ensureMetricValueColumnsSchema();
|
|
||||||
periodMetricSchemaEnsured = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private CountryDashboardRechargeDetailCO toRechargeDetailCO(
|
private CountryDashboardRechargeDetailCO toRechargeDetailCO(
|
||||||
CountryDashboardRechargeDetailDTO dto) {
|
CountryDashboardRechargeDetailDTO dto) {
|
||||||
return new CountryDashboardRechargeDetailCO()
|
return new CountryDashboardRechargeDetailCO()
|
||||||
@ -368,27 +351,18 @@ public class CountryDashboardServiceImpl implements CountryDashboardService {
|
|||||||
CountryDashboardMetricCO row = getRow(rows, metric.getCountryCode(), metric.getCountryName(),
|
CountryDashboardMetricCO row = getRow(rows, metric.getCountryCode(), metric.getCountryName(),
|
||||||
metric.getPeriodKey(), metric.getPeriodName());
|
metric.getPeriodKey(), metric.getPeriodName());
|
||||||
row.setCountryNewUser(row.getCountryNewUser() + safeLong(metric.getCountryNewUser()));
|
row.setCountryNewUser(row.getCountryNewUser() + safeLong(metric.getCountryNewUser()));
|
||||||
row.setDailyActiveUser(row.getDailyActiveUser() + safeLong(metric.getDailyActiveUser()));
|
|
||||||
row.setNewUserRecharge(add(row.getNewUserRecharge(), metric.getNewUserRecharge()));
|
row.setNewUserRecharge(add(row.getNewUserRecharge(), metric.getNewUserRecharge()));
|
||||||
row.setOfficialRecharge(add(row.getOfficialRecharge(), metric.getOfficialRecharge()));
|
row.setOfficialRecharge(add(row.getOfficialRecharge(), metric.getOfficialRecharge()));
|
||||||
row.setMifapayRecharge(add(row.getMifapayRecharge(), metric.getMifapayRecharge()));
|
row.setMifapayRecharge(add(row.getMifapayRecharge(), metric.getMifapayRecharge()));
|
||||||
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
|
||||||
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
|
||||||
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
|
||||||
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
|
|
||||||
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
|
||||||
row.setLuckyGiftUser(row.getLuckyGiftUser() + safeLong(metric.getLuckyGiftUser()));
|
row.setLuckyGiftUser(row.getLuckyGiftUser() + safeLong(metric.getLuckyGiftUser()));
|
||||||
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
|
||||||
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
|
|
||||||
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
|
||||||
row.setGameUser(row.getGameUser() + safeLong(metric.getGameUser()));
|
row.setGameUser(row.getGameUser() + safeLong(metric.getGameUser()));
|
||||||
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
|
||||||
row.setD1RetentionUser(row.getD1RetentionUser() + safeLong(metric.getD1RetentionUser()));
|
|
||||||
row.setD1RetentionBaseUser(row.getD1RetentionBaseUser() + safeLong(metric.getD1RetentionBaseUser()));
|
|
||||||
row.setD7RetentionUser(row.getD7RetentionUser() + safeLong(metric.getD7RetentionUser()));
|
|
||||||
row.setD7RetentionBaseUser(row.getD7RetentionBaseUser() + safeLong(metric.getD7RetentionBaseUser()));
|
|
||||||
row.setD30RetentionUser(row.getD30RetentionUser() + safeLong(metric.getD30RetentionUser()));
|
|
||||||
row.setD30RetentionBaseUser(row.getD30RetentionBaseUser() + safeLong(metric.getD30RetentionBaseUser()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,10 +34,6 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
|
|||||||
|
|
||||||
int ensurePeriodMetricTimezoneSchema();
|
int ensurePeriodMetricTimezoneSchema();
|
||||||
|
|
||||||
int ensurePeriodMetricUserColumnsSchema();
|
|
||||||
|
|
||||||
int ensureMetricValueColumnsSchema();
|
|
||||||
|
|
||||||
Integer getDashboardBackfillLock(
|
Integer getDashboardBackfillLock(
|
||||||
@Param("lockName") String lockName,
|
@Param("lockName") String lockName,
|
||||||
@Param("timeoutSeconds") Integer timeoutSeconds);
|
@Param("timeoutSeconds") Integer timeoutSeconds);
|
||||||
|
|||||||
@ -36,16 +36,12 @@ public class CountryDashboardDailyMetricDTO {
|
|||||||
|
|
||||||
private BigDecimal salaryExchange;
|
private BigDecimal salaryExchange;
|
||||||
|
|
||||||
private BigDecimal giftConsume;
|
|
||||||
|
|
||||||
private BigDecimal luckyGiftTotalFlow;
|
private BigDecimal luckyGiftTotalFlow;
|
||||||
|
|
||||||
private Long luckyGiftUser;
|
private Long luckyGiftUser;
|
||||||
|
|
||||||
private BigDecimal luckyGiftPayout;
|
private BigDecimal luckyGiftPayout;
|
||||||
|
|
||||||
private BigDecimal luckyGiftAnchorShare;
|
|
||||||
|
|
||||||
private BigDecimal gameTotalFlow;
|
private BigDecimal gameTotalFlow;
|
||||||
|
|
||||||
private Long gameUser;
|
private Long gameUser;
|
||||||
|
|||||||
@ -21,8 +21,6 @@ public class CountryDashboardMetricDTO {
|
|||||||
|
|
||||||
private Long countryNewUser;
|
private Long countryNewUser;
|
||||||
|
|
||||||
private Long dailyActiveUser;
|
|
||||||
|
|
||||||
private BigDecimal newUserRecharge;
|
private BigDecimal newUserRecharge;
|
||||||
|
|
||||||
private BigDecimal officialRecharge;
|
private BigDecimal officialRecharge;
|
||||||
@ -35,31 +33,15 @@ public class CountryDashboardMetricDTO {
|
|||||||
|
|
||||||
private BigDecimal salaryExchange;
|
private BigDecimal salaryExchange;
|
||||||
|
|
||||||
private BigDecimal giftConsume;
|
|
||||||
|
|
||||||
private BigDecimal luckyGiftTotalFlow;
|
private BigDecimal luckyGiftTotalFlow;
|
||||||
|
|
||||||
private Long luckyGiftUser;
|
private Long luckyGiftUser;
|
||||||
|
|
||||||
private BigDecimal luckyGiftPayout;
|
private BigDecimal luckyGiftPayout;
|
||||||
|
|
||||||
private BigDecimal luckyGiftAnchorShare;
|
|
||||||
|
|
||||||
private BigDecimal gameTotalFlow;
|
private BigDecimal gameTotalFlow;
|
||||||
|
|
||||||
private Long gameUser;
|
private Long gameUser;
|
||||||
|
|
||||||
private BigDecimal gamePayout;
|
private BigDecimal gamePayout;
|
||||||
|
|
||||||
private Long d1RetentionUser;
|
|
||||||
|
|
||||||
private Long d1RetentionBaseUser;
|
|
||||||
|
|
||||||
private Long d7RetentionUser;
|
|
||||||
|
|
||||||
private Long d7RetentionBaseUser;
|
|
||||||
|
|
||||||
private Long d30RetentionUser;
|
|
||||||
|
|
||||||
private Long d30RetentionBaseUser;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,8 +32,6 @@ public class CountryDashboardPeriodMetricDTO {
|
|||||||
|
|
||||||
private Long countryNewUser;
|
private Long countryNewUser;
|
||||||
|
|
||||||
private Long dailyActiveUser;
|
|
||||||
|
|
||||||
private BigDecimal newUserRecharge;
|
private BigDecimal newUserRecharge;
|
||||||
|
|
||||||
private BigDecimal officialRecharge;
|
private BigDecimal officialRecharge;
|
||||||
@ -46,31 +44,15 @@ public class CountryDashboardPeriodMetricDTO {
|
|||||||
|
|
||||||
private BigDecimal salaryExchange;
|
private BigDecimal salaryExchange;
|
||||||
|
|
||||||
private BigDecimal giftConsume;
|
|
||||||
|
|
||||||
private BigDecimal luckyGiftTotalFlow;
|
private BigDecimal luckyGiftTotalFlow;
|
||||||
|
|
||||||
private Long luckyGiftUser;
|
private Long luckyGiftUser;
|
||||||
|
|
||||||
private BigDecimal luckyGiftPayout;
|
private BigDecimal luckyGiftPayout;
|
||||||
|
|
||||||
private BigDecimal luckyGiftAnchorShare;
|
|
||||||
|
|
||||||
private BigDecimal gameTotalFlow;
|
private BigDecimal gameTotalFlow;
|
||||||
|
|
||||||
private Long gameUser;
|
private Long gameUser;
|
||||||
|
|
||||||
private BigDecimal gamePayout;
|
private BigDecimal gamePayout;
|
||||||
|
|
||||||
private Long d1RetentionUser;
|
|
||||||
|
|
||||||
private Long d1RetentionBaseUser;
|
|
||||||
|
|
||||||
private Long d7RetentionUser;
|
|
||||||
|
|
||||||
private Long d7RetentionBaseUser;
|
|
||||||
|
|
||||||
private Long d30RetentionUser;
|
|
||||||
|
|
||||||
private Long d30RetentionBaseUser;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,11 +26,9 @@
|
|||||||
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
|
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
|
||||||
`dealer_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '代理充值',
|
`dealer_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '代理充值',
|
||||||
`salary_exchange` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '工资兑换',
|
`salary_exchange` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '工资兑换',
|
||||||
`gift_consume` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '礼物消耗',
|
|
||||||
`lucky_gift_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物流水',
|
`lucky_gift_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物流水',
|
||||||
`lucky_gift_user` bigint NOT NULL DEFAULT 0 COMMENT '幸运礼物用户数',
|
`lucky_gift_user` bigint NOT NULL DEFAULT 0 COMMENT '幸运礼物用户数',
|
||||||
`lucky_gift_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物返奖',
|
`lucky_gift_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物返奖',
|
||||||
`lucky_gift_anchor_share` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物主播分成',
|
|
||||||
`game_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏流水',
|
`game_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏流水',
|
||||||
`game_user` bigint NOT NULL DEFAULT 0 COMMENT '游戏用户数',
|
`game_user` bigint NOT NULL DEFAULT 0 COMMENT '游戏用户数',
|
||||||
`game_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏返奖',
|
`game_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏返奖',
|
||||||
@ -57,27 +55,18 @@
|
|||||||
`country_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UNKNOWN' COMMENT '国家码',
|
`country_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UNKNOWN' COMMENT '国家码',
|
||||||
`country_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UNKNOWN' COMMENT '国家名称',
|
`country_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UNKNOWN' COMMENT '国家名称',
|
||||||
`country_new_user` bigint NOT NULL DEFAULT 0 COMMENT '新增用户数',
|
`country_new_user` bigint NOT NULL DEFAULT 0 COMMENT '新增用户数',
|
||||||
`daily_active_user` bigint NOT NULL DEFAULT 0 COMMENT '当日活跃用户数',
|
|
||||||
`new_user_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '新增用户充值',
|
`new_user_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '新增用户充值',
|
||||||
`official_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '官方充值',
|
`official_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '官方充值',
|
||||||
`mifapay_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'MifaPay充值',
|
`mifapay_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'MifaPay充值',
|
||||||
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
|
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
|
||||||
`dealer_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '代理充值',
|
`dealer_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '代理充值',
|
||||||
`salary_exchange` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '工资兑换',
|
`salary_exchange` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '工资兑换',
|
||||||
`gift_consume` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '礼物消耗',
|
|
||||||
`lucky_gift_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物流水',
|
`lucky_gift_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物流水',
|
||||||
`lucky_gift_user` bigint NOT NULL DEFAULT 0 COMMENT '幸运礼物用户数',
|
`lucky_gift_user` bigint NOT NULL DEFAULT 0 COMMENT '幸运礼物用户数',
|
||||||
`lucky_gift_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物返奖',
|
`lucky_gift_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物返奖',
|
||||||
`lucky_gift_anchor_share` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '幸运礼物主播分成',
|
|
||||||
`game_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏流水',
|
`game_total_flow` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏流水',
|
||||||
`game_user` bigint NOT NULL DEFAULT 0 COMMENT '游戏用户数',
|
`game_user` bigint NOT NULL DEFAULT 0 COMMENT '游戏用户数',
|
||||||
`game_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏返奖',
|
`game_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏返奖',
|
||||||
`d1_retention_user` bigint NOT NULL DEFAULT 0 COMMENT '次日留存用户数',
|
|
||||||
`d1_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT '次日留存基数',
|
|
||||||
`d7_retention_user` bigint NOT NULL DEFAULT 0 COMMENT '7日留存用户数',
|
|
||||||
`d7_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT '7日留存基数',
|
|
||||||
`d30_retention_user` bigint NOT NULL DEFAULT 0 COMMENT '30日留存用户数',
|
|
||||||
`d30_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT '30日留存基数',
|
|
||||||
`refreshed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最近刷新时间',
|
`refreshed_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最近刷新时间',
|
||||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
@ -465,185 +454,6 @@
|
|||||||
DO IF(@country_dashboard_schema_lock = 1, RELEASE_LOCK('country_dashboard_period_timezone_schema'), 0);
|
DO IF(@country_dashboard_schema_lock = 1, RELEASE_LOCK('country_dashboard_period_timezone_schema'), 0);
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="ensurePeriodMetricUserColumnsSchema">
|
|
||||||
SET @country_dashboard_user_columns_schema_lock = GET_LOCK('country_dashboard_period_user_columns_schema', 60);
|
|
||||||
SET @current_schema = DATABASE();
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'daily_active_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `daily_active_user` bigint NOT NULL DEFAULT 0 COMMENT ''当日活跃用户数'' AFTER `country_new_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd1_retention_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d1_retention_user` bigint NOT NULL DEFAULT 0 COMMENT ''次日留存用户数'' AFTER `game_payout`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd1_retention_base_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d1_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT ''次日留存基数'' AFTER `d1_retention_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd7_retention_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d7_retention_user` bigint NOT NULL DEFAULT 0 COMMENT ''7日留存用户数'' AFTER `d1_retention_base_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd7_retention_base_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d7_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT ''7日留存基数'' AFTER `d7_retention_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd30_retention_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d30_retention_user` bigint NOT NULL DEFAULT 0 COMMENT ''30日留存用户数'' AFTER `d7_retention_base_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_user_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'd30_retention_base_user'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `d30_retention_base_user` bigint NOT NULL DEFAULT 0 COMMENT ''30日留存基数'' AFTER `d30_retention_user`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
DO IF(@country_dashboard_user_columns_schema_lock = 1, RELEASE_LOCK('country_dashboard_period_user_columns_schema'), 0);
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="ensureMetricValueColumnsSchema">
|
|
||||||
SET @country_dashboard_value_columns_schema_lock = GET_LOCK('country_dashboard_value_columns_schema', 60);
|
|
||||||
SET @current_schema = DATABASE();
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_value_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_daily_metric'
|
|
||||||
AND COLUMN_NAME = 'gift_consume'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_daily_metric` ADD COLUMN `gift_consume` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT ''礼物消耗'' AFTER `salary_exchange`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_value_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_daily_metric'
|
|
||||||
AND COLUMN_NAME = 'lucky_gift_anchor_share'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_daily_metric` ADD COLUMN `lucky_gift_anchor_share` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT ''幸运礼物主播分成'' AFTER `lucky_gift_payout`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_value_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'gift_consume'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `gift_consume` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT ''礼物消耗'' AFTER `salary_exchange`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
SET @ddl = IF(
|
|
||||||
@country_dashboard_value_columns_schema_lock = 1
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE TABLE_SCHEMA = @current_schema
|
|
||||||
AND TABLE_NAME = 'country_dashboard_period_metric'
|
|
||||||
AND COLUMN_NAME = 'lucky_gift_anchor_share'
|
|
||||||
),
|
|
||||||
'ALTER TABLE `country_dashboard_period_metric` ADD COLUMN `lucky_gift_anchor_share` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT ''幸运礼物主播分成'' AFTER `lucky_gift_payout`',
|
|
||||||
'SELECT 1'
|
|
||||||
);
|
|
||||||
PREPARE stmt FROM @ddl;
|
|
||||||
EXECUTE stmt;
|
|
||||||
DEALLOCATE PREPARE stmt;
|
|
||||||
|
|
||||||
DO IF(@country_dashboard_value_columns_schema_lock = 1, RELEASE_LOCK('country_dashboard_value_columns_schema'), 0);
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<sql id="CountryColumns">
|
<sql id="CountryColumns">
|
||||||
NULLIF(u.country_code, '') AS countryCode,
|
NULLIF(u.country_code, '') AS countryCode,
|
||||||
NULLIF(u.country_name, '') AS countryName
|
NULLIF(u.country_name, '') AS countryName
|
||||||
@ -1058,11 +868,9 @@
|
|||||||
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
||||||
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
||||||
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
||||||
IFNULL(SUM(t.gift_consume), 0) AS giftConsume,
|
|
||||||
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
||||||
IFNULL(SUM(t.lucky_gift_user), 0) AS luckyGiftUser,
|
IFNULL(SUM(t.lucky_gift_user), 0) AS luckyGiftUser,
|
||||||
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
||||||
IFNULL(SUM(t.lucky_gift_anchor_share), 0) AS luckyGiftAnchorShare,
|
|
||||||
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
||||||
IFNULL(SUM(t.game_user), 0) AS gameUser,
|
IFNULL(SUM(t.game_user), 0) AS gameUser,
|
||||||
IFNULL(SUM(t.game_payout), 0) AS gamePayout
|
IFNULL(SUM(t.game_payout), 0) AS gamePayout
|
||||||
@ -1109,27 +917,18 @@
|
|||||||
t.period_key AS periodKey,
|
t.period_key AS periodKey,
|
||||||
MAX(t.period_name) AS periodName,
|
MAX(t.period_name) AS periodName,
|
||||||
IFNULL(SUM(t.country_new_user), 0) AS countryNewUser,
|
IFNULL(SUM(t.country_new_user), 0) AS countryNewUser,
|
||||||
IFNULL(SUM(t.daily_active_user), 0) AS dailyActiveUser,
|
|
||||||
IFNULL(SUM(t.new_user_recharge), 0) AS newUserRecharge,
|
IFNULL(SUM(t.new_user_recharge), 0) AS newUserRecharge,
|
||||||
IFNULL(SUM(t.official_recharge), 0) AS officialRecharge,
|
IFNULL(SUM(t.official_recharge), 0) AS officialRecharge,
|
||||||
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
|
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
|
||||||
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
||||||
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
||||||
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
||||||
IFNULL(SUM(t.gift_consume), 0) AS giftConsume,
|
|
||||||
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
||||||
IFNULL(SUM(t.lucky_gift_user), 0) AS luckyGiftUser,
|
IFNULL(SUM(t.lucky_gift_user), 0) AS luckyGiftUser,
|
||||||
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
||||||
IFNULL(SUM(t.lucky_gift_anchor_share), 0) AS luckyGiftAnchorShare,
|
|
||||||
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
||||||
IFNULL(SUM(t.game_user), 0) AS gameUser,
|
IFNULL(SUM(t.game_user), 0) AS gameUser,
|
||||||
IFNULL(SUM(t.game_payout), 0) AS gamePayout,
|
IFNULL(SUM(t.game_payout), 0) AS gamePayout
|
||||||
IFNULL(SUM(t.d1_retention_user), 0) AS d1RetentionUser,
|
|
||||||
IFNULL(SUM(t.d1_retention_base_user), 0) AS d1RetentionBaseUser,
|
|
||||||
IFNULL(SUM(t.d7_retention_user), 0) AS d7RetentionUser,
|
|
||||||
IFNULL(SUM(t.d7_retention_base_user), 0) AS d7RetentionBaseUser,
|
|
||||||
IFNULL(SUM(t.d30_retention_user), 0) AS d30RetentionUser,
|
|
||||||
IFNULL(SUM(t.d30_retention_base_user), 0) AS d30RetentionBaseUser
|
|
||||||
FROM country_dashboard_period_metric t
|
FROM country_dashboard_period_metric t
|
||||||
WHERE t.period_type = #{periodType}
|
WHERE t.period_type = #{periodType}
|
||||||
AND t.stat_timezone = #{statTimezone}
|
AND t.stat_timezone = #{statTimezone}
|
||||||
@ -1200,11 +999,9 @@
|
|||||||
google_recharge,
|
google_recharge,
|
||||||
dealer_recharge,
|
dealer_recharge,
|
||||||
salary_exchange,
|
salary_exchange,
|
||||||
gift_consume,
|
|
||||||
lucky_gift_total_flow,
|
lucky_gift_total_flow,
|
||||||
lucky_gift_user,
|
lucky_gift_user,
|
||||||
lucky_gift_payout,
|
lucky_gift_payout,
|
||||||
lucky_gift_anchor_share,
|
|
||||||
game_total_flow,
|
game_total_flow,
|
||||||
game_user,
|
game_user,
|
||||||
game_payout,
|
game_payout,
|
||||||
@ -1225,11 +1022,9 @@
|
|||||||
IFNULL(#{item.googleRecharge}, 0),
|
IFNULL(#{item.googleRecharge}, 0),
|
||||||
IFNULL(#{item.dealerRecharge}, 0),
|
IFNULL(#{item.dealerRecharge}, 0),
|
||||||
IFNULL(#{item.salaryExchange}, 0),
|
IFNULL(#{item.salaryExchange}, 0),
|
||||||
IFNULL(#{item.giftConsume}, 0),
|
|
||||||
IFNULL(#{item.luckyGiftTotalFlow}, 0),
|
IFNULL(#{item.luckyGiftTotalFlow}, 0),
|
||||||
IFNULL(#{item.luckyGiftUser}, 0),
|
IFNULL(#{item.luckyGiftUser}, 0),
|
||||||
IFNULL(#{item.luckyGiftPayout}, 0),
|
IFNULL(#{item.luckyGiftPayout}, 0),
|
||||||
IFNULL(#{item.luckyGiftAnchorShare}, 0),
|
|
||||||
IFNULL(#{item.gameTotalFlow}, 0),
|
IFNULL(#{item.gameTotalFlow}, 0),
|
||||||
IFNULL(#{item.gameUser}, 0),
|
IFNULL(#{item.gameUser}, 0),
|
||||||
IFNULL(#{item.gamePayout}, 0),
|
IFNULL(#{item.gamePayout}, 0),
|
||||||
@ -1245,11 +1040,9 @@
|
|||||||
google_recharge = VALUES(google_recharge),
|
google_recharge = VALUES(google_recharge),
|
||||||
dealer_recharge = VALUES(dealer_recharge),
|
dealer_recharge = VALUES(dealer_recharge),
|
||||||
salary_exchange = VALUES(salary_exchange),
|
salary_exchange = VALUES(salary_exchange),
|
||||||
gift_consume = VALUES(gift_consume),
|
|
||||||
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
|
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
|
||||||
lucky_gift_user = VALUES(lucky_gift_user),
|
lucky_gift_user = VALUES(lucky_gift_user),
|
||||||
lucky_gift_payout = VALUES(lucky_gift_payout),
|
lucky_gift_payout = VALUES(lucky_gift_payout),
|
||||||
lucky_gift_anchor_share = VALUES(lucky_gift_anchor_share),
|
|
||||||
game_total_flow = VALUES(game_total_flow),
|
game_total_flow = VALUES(game_total_flow),
|
||||||
game_user = VALUES(game_user),
|
game_user = VALUES(game_user),
|
||||||
game_payout = VALUES(game_payout),
|
game_payout = VALUES(game_payout),
|
||||||
@ -1278,27 +1071,18 @@
|
|||||||
country_code,
|
country_code,
|
||||||
country_name,
|
country_name,
|
||||||
country_new_user,
|
country_new_user,
|
||||||
daily_active_user,
|
|
||||||
new_user_recharge,
|
new_user_recharge,
|
||||||
official_recharge,
|
official_recharge,
|
||||||
mifapay_recharge,
|
mifapay_recharge,
|
||||||
google_recharge,
|
google_recharge,
|
||||||
dealer_recharge,
|
dealer_recharge,
|
||||||
salary_exchange,
|
salary_exchange,
|
||||||
gift_consume,
|
|
||||||
lucky_gift_total_flow,
|
lucky_gift_total_flow,
|
||||||
lucky_gift_user,
|
lucky_gift_user,
|
||||||
lucky_gift_payout,
|
lucky_gift_payout,
|
||||||
lucky_gift_anchor_share,
|
|
||||||
game_total_flow,
|
game_total_flow,
|
||||||
game_user,
|
game_user,
|
||||||
game_payout,
|
game_payout,
|
||||||
d1_retention_user,
|
|
||||||
d1_retention_base_user,
|
|
||||||
d7_retention_user,
|
|
||||||
d7_retention_base_user,
|
|
||||||
d30_retention_user,
|
|
||||||
d30_retention_base_user,
|
|
||||||
refreshed_at
|
refreshed_at
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
@ -1314,27 +1098,18 @@
|
|||||||
#{item.countryCode},
|
#{item.countryCode},
|
||||||
#{item.countryName},
|
#{item.countryName},
|
||||||
IFNULL(#{item.countryNewUser}, 0),
|
IFNULL(#{item.countryNewUser}, 0),
|
||||||
IFNULL(#{item.dailyActiveUser}, 0),
|
|
||||||
IFNULL(#{item.newUserRecharge}, 0),
|
IFNULL(#{item.newUserRecharge}, 0),
|
||||||
IFNULL(#{item.officialRecharge}, 0),
|
IFNULL(#{item.officialRecharge}, 0),
|
||||||
IFNULL(#{item.mifapayRecharge}, 0),
|
IFNULL(#{item.mifapayRecharge}, 0),
|
||||||
IFNULL(#{item.googleRecharge}, 0),
|
IFNULL(#{item.googleRecharge}, 0),
|
||||||
IFNULL(#{item.dealerRecharge}, 0),
|
IFNULL(#{item.dealerRecharge}, 0),
|
||||||
IFNULL(#{item.salaryExchange}, 0),
|
IFNULL(#{item.salaryExchange}, 0),
|
||||||
IFNULL(#{item.giftConsume}, 0),
|
|
||||||
IFNULL(#{item.luckyGiftTotalFlow}, 0),
|
IFNULL(#{item.luckyGiftTotalFlow}, 0),
|
||||||
IFNULL(#{item.luckyGiftUser}, 0),
|
IFNULL(#{item.luckyGiftUser}, 0),
|
||||||
IFNULL(#{item.luckyGiftPayout}, 0),
|
IFNULL(#{item.luckyGiftPayout}, 0),
|
||||||
IFNULL(#{item.luckyGiftAnchorShare}, 0),
|
|
||||||
IFNULL(#{item.gameTotalFlow}, 0),
|
IFNULL(#{item.gameTotalFlow}, 0),
|
||||||
IFNULL(#{item.gameUser}, 0),
|
IFNULL(#{item.gameUser}, 0),
|
||||||
IFNULL(#{item.gamePayout}, 0),
|
IFNULL(#{item.gamePayout}, 0),
|
||||||
IFNULL(#{item.d1RetentionUser}, 0),
|
|
||||||
IFNULL(#{item.d1RetentionBaseUser}, 0),
|
|
||||||
IFNULL(#{item.d7RetentionUser}, 0),
|
|
||||||
IFNULL(#{item.d7RetentionBaseUser}, 0),
|
|
||||||
IFNULL(#{item.d30RetentionUser}, 0),
|
|
||||||
IFNULL(#{item.d30RetentionBaseUser}, 0),
|
|
||||||
NOW()
|
NOW()
|
||||||
)
|
)
|
||||||
</foreach>
|
</foreach>
|
||||||
@ -1344,27 +1119,18 @@
|
|||||||
period_end_date = VALUES(period_end_date),
|
period_end_date = VALUES(period_end_date),
|
||||||
country_name = VALUES(country_name),
|
country_name = VALUES(country_name),
|
||||||
country_new_user = VALUES(country_new_user),
|
country_new_user = VALUES(country_new_user),
|
||||||
daily_active_user = VALUES(daily_active_user),
|
|
||||||
new_user_recharge = VALUES(new_user_recharge),
|
new_user_recharge = VALUES(new_user_recharge),
|
||||||
official_recharge = VALUES(official_recharge),
|
official_recharge = VALUES(official_recharge),
|
||||||
mifapay_recharge = VALUES(mifapay_recharge),
|
mifapay_recharge = VALUES(mifapay_recharge),
|
||||||
google_recharge = VALUES(google_recharge),
|
google_recharge = VALUES(google_recharge),
|
||||||
dealer_recharge = VALUES(dealer_recharge),
|
dealer_recharge = VALUES(dealer_recharge),
|
||||||
salary_exchange = VALUES(salary_exchange),
|
salary_exchange = VALUES(salary_exchange),
|
||||||
gift_consume = VALUES(gift_consume),
|
|
||||||
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
|
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
|
||||||
lucky_gift_user = VALUES(lucky_gift_user),
|
lucky_gift_user = VALUES(lucky_gift_user),
|
||||||
lucky_gift_payout = VALUES(lucky_gift_payout),
|
lucky_gift_payout = VALUES(lucky_gift_payout),
|
||||||
lucky_gift_anchor_share = VALUES(lucky_gift_anchor_share),
|
|
||||||
game_total_flow = VALUES(game_total_flow),
|
game_total_flow = VALUES(game_total_flow),
|
||||||
game_user = VALUES(game_user),
|
game_user = VALUES(game_user),
|
||||||
game_payout = VALUES(game_payout),
|
game_payout = VALUES(game_payout),
|
||||||
d1_retention_user = VALUES(d1_retention_user),
|
|
||||||
d1_retention_base_user = VALUES(d1_retention_base_user),
|
|
||||||
d7_retention_user = VALUES(d7_retention_user),
|
|
||||||
d7_retention_base_user = VALUES(d7_retention_base_user),
|
|
||||||
d30_retention_user = VALUES(d30_retention_user),
|
|
||||||
d30_retention_base_user = VALUES(d30_retention_base_user),
|
|
||||||
refreshed_at = NOW()
|
refreshed_at = NOW()
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -1558,26 +1324,16 @@
|
|||||||
MAX(t.country_name) AS countryName,
|
MAX(t.country_name) AS countryName,
|
||||||
'ALL' AS periodKey,
|
'ALL' AS periodKey,
|
||||||
'全部' AS periodName,
|
'全部' AS periodName,
|
||||||
IFNULL(SUM(t.country_new_user), 0) AS countryNewUser,
|
|
||||||
IFNULL(SUM(t.daily_active_user), 0) AS dailyActiveUser,
|
|
||||||
IFNULL(SUM(t.new_user_recharge), 0) AS newUserRecharge,
|
IFNULL(SUM(t.new_user_recharge), 0) AS newUserRecharge,
|
||||||
IFNULL(SUM(t.official_recharge), 0) AS officialRecharge,
|
IFNULL(SUM(t.official_recharge), 0) AS officialRecharge,
|
||||||
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
|
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
|
||||||
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
|
||||||
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
|
||||||
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
IFNULL(SUM(t.salary_exchange), 0) AS salaryExchange,
|
||||||
IFNULL(SUM(t.gift_consume), 0) AS giftConsume,
|
|
||||||
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
IFNULL(SUM(t.lucky_gift_total_flow), 0) AS luckyGiftTotalFlow,
|
||||||
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
IFNULL(SUM(t.lucky_gift_payout), 0) AS luckyGiftPayout,
|
||||||
IFNULL(SUM(t.lucky_gift_anchor_share), 0) AS luckyGiftAnchorShare,
|
|
||||||
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
IFNULL(SUM(t.game_total_flow), 0) AS gameTotalFlow,
|
||||||
IFNULL(SUM(t.game_payout), 0) AS gamePayout,
|
IFNULL(SUM(t.game_payout), 0) AS gamePayout
|
||||||
IFNULL(SUM(t.d1_retention_user), 0) AS d1RetentionUser,
|
|
||||||
IFNULL(SUM(t.d1_retention_base_user), 0) AS d1RetentionBaseUser,
|
|
||||||
IFNULL(SUM(t.d7_retention_user), 0) AS d7RetentionUser,
|
|
||||||
IFNULL(SUM(t.d7_retention_base_user), 0) AS d7RetentionBaseUser,
|
|
||||||
IFNULL(SUM(t.d30_retention_user), 0) AS d30RetentionUser,
|
|
||||||
IFNULL(SUM(t.d30_retention_base_user), 0) AS d30RetentionBaseUser
|
|
||||||
FROM country_dashboard_period_metric t
|
FROM country_dashboard_period_metric t
|
||||||
WHERE t.period_type = 'DAY'
|
WHERE t.period_type = 'DAY'
|
||||||
AND t.stat_timezone = #{statTimezone}
|
AND t.stat_timezone = #{statTimezone}
|
||||||
|
|||||||
@ -257,8 +257,7 @@ public class ActivitySourceGroupGatewayImpl implements ActivitySourceGroupGatewa
|
|||||||
ActivityRewardProps activityRewardProps = propsActivityInfraConvertor
|
ActivityRewardProps activityRewardProps = propsActivityInfraConvertor
|
||||||
.toActivityRewardProps(rewardConfig);
|
.toActivityRewardProps(rewardConfig);
|
||||||
activityRewardProps.setCover(resolveVipCover(vipConfig, vipCoverMap));
|
activityRewardProps.setCover(resolveVipCover(vipConfig, vipCoverMap));
|
||||||
activityRewardProps.setQuantity(rewardQuantityOrDefault(rewardConfig.getQuantity(),
|
activityRewardProps.setQuantity(durationDays(vipConfig));
|
||||||
durationDays(vipConfig)));
|
|
||||||
activityRewardProps.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
|
activityRewardProps.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
|
||||||
vipConfig.getPriceGold(), 0L)));
|
vipConfig.getPriceGold(), 0L)));
|
||||||
activityRewardProps.setRemark(displayName(vipConfig));
|
activityRewardProps.setRemark(displayName(vipConfig));
|
||||||
@ -508,10 +507,6 @@ public class ActivitySourceGroupGatewayImpl implements ActivitySourceGroupGatewa
|
|||||||
return Objects.nonNull(days) && days > 0 ? days : 30;
|
return Objects.nonNull(days) && days > 0 ? days : 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int rewardQuantityOrDefault(Integer quantity, int defaultQuantity) {
|
|
||||||
return Objects.nonNull(quantity) && quantity > 0 ? quantity : defaultQuantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String displayName(VipLevelConfig vipConfig) {
|
private String displayName(VipLevelConfig vipConfig) {
|
||||||
if (Objects.nonNull(vipConfig.getDisplayName()) && !vipConfig.getDisplayName().isBlank()) {
|
if (Objects.nonNull(vipConfig.getDisplayName()) && !vipConfig.getDisplayName().isBlank()) {
|
||||||
return vipConfig.getDisplayName();
|
return vipConfig.getDisplayName();
|
||||||
|
|||||||
@ -287,7 +287,7 @@ public class PropsActivityRewardGroupClientServiceImpl implements
|
|||||||
config);
|
config);
|
||||||
propsActivity.setSort(Objects.isNull(propsActivity.getSort()) ? 0 : propsActivity.getSort());
|
propsActivity.setSort(Objects.isNull(propsActivity.getSort()) ? 0 : propsActivity.getSort());
|
||||||
if (isVipLevelReward(config, vipConfigMap)) {
|
if (isVipLevelReward(config, vipConfigMap)) {
|
||||||
setVipConfig(config, propsActivity, vipConfigMap.get(Long.valueOf(config.getContent())),
|
setVipConfig(propsActivity, vipConfigMap.get(Long.valueOf(config.getContent())),
|
||||||
vipCoverMap);
|
vipCoverMap);
|
||||||
return propsActivity;
|
return propsActivity;
|
||||||
}
|
}
|
||||||
@ -429,15 +429,13 @@ public class PropsActivityRewardGroupClientServiceImpl implements
|
|||||||
&& vipConfigMap.containsKey(DataTypeUtils.toLong(config.getContent()));
|
&& vipConfigMap.containsKey(DataTypeUtils.toLong(config.getContent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setVipConfig(PropsActivityRewardConfig config,
|
private void setVipConfig(PropsActivityRewardConfigInfoDTO propsActivity,
|
||||||
PropsActivityRewardConfigInfoDTO propsActivity,
|
|
||||||
VipLevelConfig vipConfig, Map<Long, PropsSourceRecord> vipCoverMap) {
|
VipLevelConfig vipConfig, Map<Long, PropsSourceRecord> vipCoverMap) {
|
||||||
propsActivity.setCover(resolveVipCover(vipConfig, vipCoverMap));
|
propsActivity.setCover(resolveVipCover(vipConfig, vipCoverMap));
|
||||||
propsActivity.setSourceUrl(resolveVipSourceUrl(vipConfig, vipCoverMap));
|
propsActivity.setSourceUrl(resolveVipSourceUrl(vipConfig, vipCoverMap));
|
||||||
propsActivity.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
|
propsActivity.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
|
||||||
vipConfig.getPriceGold(), 0L)));
|
vipConfig.getPriceGold(), 0L)));
|
||||||
propsActivity.setQuantity(rewardQuantityOrDefault(config.getQuantity(),
|
propsActivity.setQuantity(durationDays(vipConfig));
|
||||||
durationDays(vipConfig)));
|
|
||||||
propsActivity.setName(displayName(vipConfig));
|
propsActivity.setName(displayName(vipConfig));
|
||||||
propsActivity.setRemark(displayName(vipConfig));
|
propsActivity.setRemark(displayName(vipConfig));
|
||||||
}
|
}
|
||||||
@ -492,10 +490,6 @@ public class PropsActivityRewardGroupClientServiceImpl implements
|
|||||||
return Objects.nonNull(days) && days > 0 ? days : 30;
|
return Objects.nonNull(days) && days > 0 ? days : 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int rewardQuantityOrDefault(Integer quantity, int defaultQuantity) {
|
|
||||||
return Objects.nonNull(quantity) && quantity > 0 ? quantity : defaultQuantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String displayName(VipLevelConfig vipConfig) {
|
private String displayName(VipLevelConfig vipConfig) {
|
||||||
if (StringUtils.isNotBlank(vipConfig.getDisplayName())) {
|
if (StringUtils.isNotBlank(vipConfig.getDisplayName())) {
|
||||||
return vipConfig.getDisplayName();
|
return vipConfig.getDisplayName();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user