Compare commits

...

5 Commits

Author SHA1 Message Date
hy001
1520362d9f Merge branch 'main' of gitea.haiyihy.com:hy/chatapp3-java 2026-05-25 10:40:04 +08:00
hy001
6405052215 vip时间设置 2026-05-25 10:40:03 +08:00
hy001
74fd42330e fix: complete country dashboard derived metrics 2026-05-24 14:08:31 +08:00
hy001
4112160656 Merge branch 'main' of gitea.haiyihy.com:hy/chatapp3-java 2026-05-23 21:26:46 +08:00
hy001
7299b1c088 fix: precompute country dashboard active metrics 2026-05-23 13:27:45 +08:00
9 changed files with 698 additions and 8 deletions

View File

@ -5,7 +5,10 @@ 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.CountryDashboardMetricDTO;
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.sql.Timestamp;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
@ -17,6 +20,7 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.List;
@ -24,9 +28,17 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.bson.types.Decimal128;
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.transaction.support.TransactionTemplate;
@ -49,9 +61,13 @@ public class CountryDashboardDailyMetricService {
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_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 TransactionTemplate transactionTemplate;
private final MongoTemplate mongoTemplate;
@Value("${red-circle.country-dashboard.refresh-sys-origins:LIKEI}")
private String refreshSysOrigins;
@ -159,6 +175,8 @@ public class CountryDashboardDailyMetricService {
countryDashboardDAO.createPeriodMetricTable();
countryDashboardDAO.createPeriodUserMetricTable();
countryDashboardDAO.ensurePeriodMetricTimezoneSchema();
countryDashboardDAO.ensurePeriodMetricUserColumnsSchema();
countryDashboardDAO.ensureMetricValueColumnsSchema();
metricSchemaEnsured = true;
log.info("country dashboard metric tables ensured");
}
@ -215,6 +233,14 @@ public class CountryDashboardDailyMetricService {
PERIOD_DAY, startTime, endTime, startTimeMillis, endTimeMillis, null, sysOrigin,
STORAGE_TIMEZONE_OFFSET, STORAGE_TIMEZONE_OFFSET),
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());
RefreshWriteResult writeResult = transactionTemplate.execute(status -> {
@ -284,6 +310,15 @@ public class CountryDashboardDailyMetricService {
mergePeriodAmounts(rows, countryDashboardDAO.listLuckyBoxGame(
window.periodType(), startTime, endTime, null, sysOrigin,
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 -> {
countryDashboardDAO.deletePeriodUserMetrics(window.periodType(), window.periodKey(),
@ -358,9 +393,11 @@ public class CountryDashboardDailyMetricService {
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
row.setLuckyGiftUser(safeLong(row.getLuckyGiftUser()) + safeLong(metric.getLuckyGiftUser()));
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
row.setGameUser(safeLong(row.getGameUser()) + safeLong(metric.getGameUser()));
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
@ -382,8 +419,10 @@ public class CountryDashboardDailyMetricService {
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
row.setGamePayout(add(row.getGamePayout(), metric.getGamePayout()));
}
@ -404,6 +443,296 @@ 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,
CountryDashboardMetricDTO metric, LocalDate statDate, String sysOrigin) {
String countryCode = hasText(metric.getCountryCode()) ? metric.getCountryCode() : "UNKNOWN";
@ -477,7 +806,9 @@ public class CountryDashboardDailyMetricService {
LocalDateTime.ofInstant(startInstant, STORAGE_ZONE_ID),
LocalDateTime.ofInstant(endInstant, STORAGE_ZONE_ID),
startInstant.toEpochMilli(),
endInstant.toEpochMilli());
endInstant.toEpochMilli(),
startInstant,
endInstant);
}
private List<StatTimezone> resolveStatTimezones(String statTimezonesValue) {
@ -559,6 +890,37 @@ public class CountryDashboardDailyMetricService {
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) {
return value != null && !value.trim().isEmpty();
}
@ -579,9 +941,12 @@ public class CountryDashboardDailyMetricService {
}
private record TimeWindow(LocalDateTime startTime, LocalDateTime endTime,
Long startTimeMillis, Long endTimeMillis) {
Long startTimeMillis, Long endTimeMillis, Instant startInstant, Instant endInstant) {
}
private record RefreshWriteResult(int deleted, int inserted, int userRows) {
}
private record MongoMetric(Long userId, String day, BigDecimal amount) {
}
}

View File

@ -73,9 +73,11 @@ public class CountryDashboardServiceImpl implements CountryDashboardService {
private final CountryDashboardDAO countryDashboardDAO;
private final MongoTemplate mongoTemplate;
private volatile boolean rechargeDetailSchemaEnsured;
private volatile boolean periodMetricSchemaEnsured;
@Override
public CountryDashboardCO query(CountryDashboardQryCmd cmd) {
ensurePeriodMetricSchema();
QueryCondition condition = QueryCondition.of(cmd);
Map<String, CountryDashboardMetricCO> rows = new LinkedHashMap<>();
@ -325,6 +327,21 @@ 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(
CountryDashboardRechargeDetailDTO dto) {
return new CountryDashboardRechargeDetailCO()
@ -351,18 +368,27 @@ public class CountryDashboardServiceImpl implements CountryDashboardService {
CountryDashboardMetricCO row = getRow(rows, metric.getCountryCode(), metric.getCountryName(),
metric.getPeriodKey(), metric.getPeriodName());
row.setCountryNewUser(row.getCountryNewUser() + safeLong(metric.getCountryNewUser()));
row.setDailyActiveUser(row.getDailyActiveUser() + safeLong(metric.getDailyActiveUser()));
row.setNewUserRecharge(add(row.getNewUserRecharge(), metric.getNewUserRecharge()));
row.setOfficialRecharge(add(row.getOfficialRecharge(), metric.getOfficialRecharge()));
row.setMifapayRecharge(add(row.getMifapayRecharge(), metric.getMifapayRecharge()));
row.setGoogleRecharge(add(row.getGoogleRecharge(), metric.getGoogleRecharge()));
row.setDealerRecharge(add(row.getDealerRecharge(), metric.getDealerRecharge()));
row.setSalaryExchange(add(row.getSalaryExchange(), metric.getSalaryExchange()));
row.setGiftConsume(add(row.getGiftConsume(), metric.getGiftConsume()));
row.setLuckyGiftTotalFlow(add(row.getLuckyGiftTotalFlow(), metric.getLuckyGiftTotalFlow()));
row.setLuckyGiftUser(row.getLuckyGiftUser() + safeLong(metric.getLuckyGiftUser()));
row.setLuckyGiftPayout(add(row.getLuckyGiftPayout(), metric.getLuckyGiftPayout()));
row.setLuckyGiftAnchorShare(add(row.getLuckyGiftAnchorShare(), metric.getLuckyGiftAnchorShare()));
row.setGameTotalFlow(add(row.getGameTotalFlow(), metric.getGameTotalFlow()));
row.setGameUser(row.getGameUser() + safeLong(metric.getGameUser()));
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()));
}
}

View File

@ -34,6 +34,10 @@ public interface CountryDashboardDAO extends BaseDAO<IUserBaseInfo> {
int ensurePeriodMetricTimezoneSchema();
int ensurePeriodMetricUserColumnsSchema();
int ensureMetricValueColumnsSchema();
Integer getDashboardBackfillLock(
@Param("lockName") String lockName,
@Param("timeoutSeconds") Integer timeoutSeconds);

View File

@ -36,12 +36,16 @@ public class CountryDashboardDailyMetricDTO {
private BigDecimal salaryExchange;
private BigDecimal giftConsume;
private BigDecimal luckyGiftTotalFlow;
private Long luckyGiftUser;
private BigDecimal luckyGiftPayout;
private BigDecimal luckyGiftAnchorShare;
private BigDecimal gameTotalFlow;
private Long gameUser;

View File

@ -21,6 +21,8 @@ public class CountryDashboardMetricDTO {
private Long countryNewUser;
private Long dailyActiveUser;
private BigDecimal newUserRecharge;
private BigDecimal officialRecharge;
@ -33,15 +35,31 @@ public class CountryDashboardMetricDTO {
private BigDecimal salaryExchange;
private BigDecimal giftConsume;
private BigDecimal luckyGiftTotalFlow;
private Long luckyGiftUser;
private BigDecimal luckyGiftPayout;
private BigDecimal luckyGiftAnchorShare;
private BigDecimal gameTotalFlow;
private Long gameUser;
private BigDecimal gamePayout;
private Long d1RetentionUser;
private Long d1RetentionBaseUser;
private Long d7RetentionUser;
private Long d7RetentionBaseUser;
private Long d30RetentionUser;
private Long d30RetentionBaseUser;
}

View File

@ -32,6 +32,8 @@ public class CountryDashboardPeriodMetricDTO {
private Long countryNewUser;
private Long dailyActiveUser;
private BigDecimal newUserRecharge;
private BigDecimal officialRecharge;
@ -44,15 +46,31 @@ public class CountryDashboardPeriodMetricDTO {
private BigDecimal salaryExchange;
private BigDecimal giftConsume;
private BigDecimal luckyGiftTotalFlow;
private Long luckyGiftUser;
private BigDecimal luckyGiftPayout;
private BigDecimal luckyGiftAnchorShare;
private BigDecimal gameTotalFlow;
private Long gameUser;
private BigDecimal gamePayout;
private Long d1RetentionUser;
private Long d1RetentionBaseUser;
private Long d7RetentionUser;
private Long d7RetentionBaseUser;
private Long d30RetentionUser;
private Long d30RetentionBaseUser;
}

View File

@ -26,9 +26,11 @@
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
`dealer_recharge` 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_user` bigint NOT NULL DEFAULT 0 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_user` bigint NOT NULL DEFAULT 0 COMMENT '游戏用户数',
`game_payout` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '游戏返奖',
@ -55,18 +57,27 @@
`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_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 '新增用户充值',
`official_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT '官方充值',
`mifapay_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'MifaPay充值',
`google_recharge` decimal(20,2) NOT NULL DEFAULT 0.00 COMMENT 'Google充值',
`dealer_recharge` 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_user` bigint NOT NULL DEFAULT 0 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_user` bigint NOT NULL DEFAULT 0 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 '最近刷新时间',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
@ -454,6 +465,185 @@
DO IF(@country_dashboard_schema_lock = 1, RELEASE_LOCK('country_dashboard_period_timezone_schema'), 0);
</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">
NULLIF(u.country_code, '') AS countryCode,
NULLIF(u.country_name, '') AS countryName
@ -868,9 +1058,11 @@
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
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_user), 0) AS luckyGiftUser,
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_user), 0) AS gameUser,
IFNULL(SUM(t.game_payout), 0) AS gamePayout
@ -917,18 +1109,27 @@
t.period_key AS periodKey,
MAX(t.period_name) 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.official_recharge), 0) AS officialRecharge,
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
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_user), 0) AS luckyGiftUser,
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_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
WHERE t.period_type = #{periodType}
AND t.stat_timezone = #{statTimezone}
@ -999,9 +1200,11 @@
google_recharge,
dealer_recharge,
salary_exchange,
gift_consume,
lucky_gift_total_flow,
lucky_gift_user,
lucky_gift_payout,
lucky_gift_anchor_share,
game_total_flow,
game_user,
game_payout,
@ -1022,9 +1225,11 @@
IFNULL(#{item.googleRecharge}, 0),
IFNULL(#{item.dealerRecharge}, 0),
IFNULL(#{item.salaryExchange}, 0),
IFNULL(#{item.giftConsume}, 0),
IFNULL(#{item.luckyGiftTotalFlow}, 0),
IFNULL(#{item.luckyGiftUser}, 0),
IFNULL(#{item.luckyGiftPayout}, 0),
IFNULL(#{item.luckyGiftAnchorShare}, 0),
IFNULL(#{item.gameTotalFlow}, 0),
IFNULL(#{item.gameUser}, 0),
IFNULL(#{item.gamePayout}, 0),
@ -1040,9 +1245,11 @@
google_recharge = VALUES(google_recharge),
dealer_recharge = VALUES(dealer_recharge),
salary_exchange = VALUES(salary_exchange),
gift_consume = VALUES(gift_consume),
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
lucky_gift_user = VALUES(lucky_gift_user),
lucky_gift_payout = VALUES(lucky_gift_payout),
lucky_gift_anchor_share = VALUES(lucky_gift_anchor_share),
game_total_flow = VALUES(game_total_flow),
game_user = VALUES(game_user),
game_payout = VALUES(game_payout),
@ -1071,18 +1278,27 @@
country_code,
country_name,
country_new_user,
daily_active_user,
new_user_recharge,
official_recharge,
mifapay_recharge,
google_recharge,
dealer_recharge,
salary_exchange,
gift_consume,
lucky_gift_total_flow,
lucky_gift_user,
lucky_gift_payout,
lucky_gift_anchor_share,
game_total_flow,
game_user,
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
)
VALUES
@ -1098,18 +1314,27 @@
#{item.countryCode},
#{item.countryName},
IFNULL(#{item.countryNewUser}, 0),
IFNULL(#{item.dailyActiveUser}, 0),
IFNULL(#{item.newUserRecharge}, 0),
IFNULL(#{item.officialRecharge}, 0),
IFNULL(#{item.mifapayRecharge}, 0),
IFNULL(#{item.googleRecharge}, 0),
IFNULL(#{item.dealerRecharge}, 0),
IFNULL(#{item.salaryExchange}, 0),
IFNULL(#{item.giftConsume}, 0),
IFNULL(#{item.luckyGiftTotalFlow}, 0),
IFNULL(#{item.luckyGiftUser}, 0),
IFNULL(#{item.luckyGiftPayout}, 0),
IFNULL(#{item.luckyGiftAnchorShare}, 0),
IFNULL(#{item.gameTotalFlow}, 0),
IFNULL(#{item.gameUser}, 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()
)
</foreach>
@ -1119,18 +1344,27 @@
period_end_date = VALUES(period_end_date),
country_name = VALUES(country_name),
country_new_user = VALUES(country_new_user),
daily_active_user = VALUES(daily_active_user),
new_user_recharge = VALUES(new_user_recharge),
official_recharge = VALUES(official_recharge),
mifapay_recharge = VALUES(mifapay_recharge),
google_recharge = VALUES(google_recharge),
dealer_recharge = VALUES(dealer_recharge),
salary_exchange = VALUES(salary_exchange),
gift_consume = VALUES(gift_consume),
lucky_gift_total_flow = VALUES(lucky_gift_total_flow),
lucky_gift_user = VALUES(lucky_gift_user),
lucky_gift_payout = VALUES(lucky_gift_payout),
lucky_gift_anchor_share = VALUES(lucky_gift_anchor_share),
game_total_flow = VALUES(game_total_flow),
game_user = VALUES(game_user),
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()
</insert>
@ -1324,16 +1558,26 @@
MAX(t.country_name) AS countryName,
'ALL' AS periodKey,
'全部' 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.official_recharge), 0) AS officialRecharge,
IFNULL(SUM(t.mifapay_recharge), 0) AS mifapayRecharge,
IFNULL(SUM(t.google_recharge), 0) AS googleRecharge,
IFNULL(SUM(t.dealer_recharge), 0) AS dealerRecharge,
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_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_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
WHERE t.period_type = 'DAY'
AND t.stat_timezone = #{statTimezone}

View File

@ -257,7 +257,8 @@ public class ActivitySourceGroupGatewayImpl implements ActivitySourceGroupGatewa
ActivityRewardProps activityRewardProps = propsActivityInfraConvertor
.toActivityRewardProps(rewardConfig);
activityRewardProps.setCover(resolveVipCover(vipConfig, vipCoverMap));
activityRewardProps.setQuantity(durationDays(vipConfig));
activityRewardProps.setQuantity(rewardQuantityOrDefault(rewardConfig.getQuantity(),
durationDays(vipConfig)));
activityRewardProps.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
vipConfig.getPriceGold(), 0L)));
activityRewardProps.setRemark(displayName(vipConfig));
@ -507,6 +508,10 @@ public class ActivitySourceGroupGatewayImpl implements ActivitySourceGroupGatewa
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) {
if (Objects.nonNull(vipConfig.getDisplayName()) && !vipConfig.getDisplayName().isBlank()) {
return vipConfig.getDisplayName();

View File

@ -287,7 +287,7 @@ public class PropsActivityRewardGroupClientServiceImpl implements
config);
propsActivity.setSort(Objects.isNull(propsActivity.getSort()) ? 0 : propsActivity.getSort());
if (isVipLevelReward(config, vipConfigMap)) {
setVipConfig(propsActivity, vipConfigMap.get(Long.valueOf(config.getContent())),
setVipConfig(config, propsActivity, vipConfigMap.get(Long.valueOf(config.getContent())),
vipCoverMap);
return propsActivity;
}
@ -429,13 +429,15 @@ public class PropsActivityRewardGroupClientServiceImpl implements
&& vipConfigMap.containsKey(DataTypeUtils.toLong(config.getContent()));
}
private void setVipConfig(PropsActivityRewardConfigInfoDTO propsActivity,
private void setVipConfig(PropsActivityRewardConfig config,
PropsActivityRewardConfigInfoDTO propsActivity,
VipLevelConfig vipConfig, Map<Long, PropsSourceRecord> vipCoverMap) {
propsActivity.setCover(resolveVipCover(vipConfig, vipCoverMap));
propsActivity.setSourceUrl(resolveVipSourceUrl(vipConfig, vipCoverMap));
propsActivity.setAmount(BigDecimal.valueOf(Objects.requireNonNullElse(
vipConfig.getPriceGold(), 0L)));
propsActivity.setQuantity(durationDays(vipConfig));
propsActivity.setQuantity(rewardQuantityOrDefault(config.getQuantity(),
durationDays(vipConfig)));
propsActivity.setName(displayName(vipConfig));
propsActivity.setRemark(displayName(vipConfig));
}
@ -490,6 +492,10 @@ public class PropsActivityRewardGroupClientServiceImpl implements
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) {
if (StringUtils.isNotBlank(vipConfig.getDisplayName())) {
return vipConfig.getDisplayName();