From 840282cb7e51e74ff21f79b995fe09e4dd3b6b76 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 20 Mar 2026 10:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=96=8B=E8=8A=82=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=E6=B4=BB=E5=8A=A8=E7=B4=AF=E8=AE=A1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gift/strategy/RankCountStrategy.java | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java index 2c981d2d..c6ab2dc1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/RankCountStrategy.java @@ -42,8 +42,11 @@ import com.red.circle.other.inner.enums.material.GiftTabEnum; import com.red.circle.other.inner.model.dto.sys.SysActivityCountType; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; +import com.red.circle.tool.core.date.DateFormatConstant; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.regex.RegexConstant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; @@ -415,39 +418,39 @@ public class RankCountStrategy implements GiftStrategy { } + /** + * 固定周期活动类型集合(使用活动自身的 startTime-endTime 作为周期) + */ + private static final Set FIXED_CYCLE_ACTIVITY_TYPES = Set.of( + RankingActivityType.OPEN_RAMADAN + ); + /** * 累计新排行榜数据 */ private void accumulateNewRankingData(GiftGiveRunningWater runningWater, BigDecimal giftRatio) { try { - // 先查询上架且进行中的活动 List ongoingActivities = activityConfigService.listOngoingActivities(runningWater.getSysOrigin()); if (CollectionUtils.isEmpty(ongoingActivities)) { log.debug("没有进行中的活动,跳过排行榜累计"); return; } - // 计算实际金额 Long actualAmount = runningWater.getGiftValue().getActualAmount().longValue(); - // 遍历活动,找到对应的type再累计对应活动类型的数据 for (ActivityConfig activity : ongoingActivities) { - String cycleKey = generateWeeklyCycleKey(); - - if (!matchActivityRule(runningWater, activity)) { - continue; - } - - // 将活动类型转换为RankingActivityType枚举 - try { - RankingActivityType activityType = RankingActivityType.valueOf(activity.getActivityType()); - Integer cycleType = RankingCycleType.WEEKLY.getCode(); - - getDataUpdateCmd(runningWater, cycleKey, actualAmount, activityType, cycleType); - } catch (IllegalArgumentException e) { - log.warn("未识别的活动类型: {}, activityId={}", activity.getActivityType(), activity.getId()); + if (!matchActivityRule(runningWater, activity)) { + continue; } + + RankingActivityType activityType = RankingActivityType.getByConstantName(activity.getActivityType()); + if (activityType == null) { + continue; + } + + ImmutablePair cycleInfo = resolveCycleInfo(activityType, activity); + getDataUpdateCmd(runningWater, cycleInfo.getRight(), actualAmount, activityType, cycleInfo.getLeft()); } } catch (Exception e) { @@ -455,6 +458,21 @@ public class RankCountStrategy implements GiftStrategy { } } + /** + * 解析活动周期类型和 cycleKey. + * 固定周期活动使用 startTime-endTime,其余默认周榜. + */ + private ImmutablePair resolveCycleInfo(RankingActivityType activityType, ActivityConfig activity) { + if (FIXED_CYCLE_ACTIVITY_TYPES.contains(activityType)) { + DateTimeFormatter fmt = DateTimeFormatter.ofPattern(DateFormatConstant.yyyyMMdd) + .withZone(ZoneId.of("Asia/Riyadh")); + String start = fmt.format(activity.getStartTime().toInstant()); + String end = fmt.format(activity.getEndTime().toInstant()); + return ImmutablePair.of(RankingCycleType.SEASON.getCode(), start + "-" + end); + } + return ImmutablePair.of(RankingCycleType.WEEKLY.getCode(), generateWeeklyCycleKey()); + } + private static boolean matchActivityRule(GiftGiveRunningWater runningWater, ActivityConfig activity) { RankingActivityType activityType = RankingActivityType.getByConstantName(activity.getActivityType());