From 6035415969553ecc95f6477f9011739c15fc58e7 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Tue, 13 Jan 2026 17:11:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ecp=E6=B4=BB=E5=8A=A8=E5=91=A8?= =?UTF-8?q?=E6=A6=9C=E5=AD=A3=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gift/strategy/RankCountStrategy.java | 36 +++-- .../circle/other/app/util/SeasonUtils.java | 135 ++++++++++++++++++ .../domain/ranking/RankingActivityType.java | 4 + .../other-start/src/test/java/ApiTest.java | 7 + 4 files changed, 170 insertions(+), 12 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java 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 d0b631a6..67adb918 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 @@ -7,6 +7,7 @@ import com.red.circle.mq.business.model.event.gift.OfflineProcessGiftEvent; import com.red.circle.other.app.common.gift.GameLuckyGiftCommon; import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd; import com.red.circle.other.app.service.activity.RankingActivityService; +import com.red.circle.other.app.util.SeasonUtils; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.domain.ranking.RankingActivityType; @@ -46,6 +47,8 @@ import com.red.circle.tool.core.json.JacksonUtils; import com.red.circle.tool.core.regex.RegexConstant; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -103,7 +106,7 @@ public class RankCountStrategy implements GiftStrategy { // 幸运礼物比例 boolean isLuckyGift = isLuckyGift(giftValue); - BigDecimal luckyGiftRatio = gameLuckyGiftCommon.getLuckyGiftShareRatio(runningWater.getSysOrigin()); + BigDecimal luckyGiftRatio = getLuckyGiftShareRatio(runningWater); log.info("RankCountStrategy.processor---幸运礼物比例:{}", luckyGiftRatio); // 周星礼物排行榜计算 @@ -147,6 +150,10 @@ public class RankCountStrategy implements GiftStrategy { giftGiveRunningWaterService.addLog(runningWater.getId(), "结束:排行榜相关统计"); } + private BigDecimal getLuckyGiftShareRatio(GiftGiveRunningWater runningWater) { + return gameLuckyGiftCommon.getLuckyGiftShareRatio(runningWater.getSysOrigin()); + } + /** * 获得礼物额度. */ @@ -349,7 +356,7 @@ public class RankCountStrategy implements GiftStrategy { return giftValue.getGiftType().contains(GiftTabEnum.LUCKY_GIFT.name()); } - private boolean isCpGift(GiftValue giftValue) { + private static boolean isCpGift(GiftValue giftValue) { return giftValue.getGiftType().contains(GiftTabEnum.CP.name()); } @@ -377,17 +384,17 @@ public class RankCountStrategy implements GiftStrategy { continue; } - //圣诞节特殊处理 - RankingActivityType type = RankingActivityType.getByConstantName(activity.getActivityType()); - if (type == RankingActivityType.CHRISTMAS) { - cycleKey = "20251222"; - } - // 将活动类型转换为RankingActivityType枚举 try { RankingActivityType activityType = RankingActivityType.valueOf(activity.getActivityType()); - // 累计对应活动类型的数据 - getDataUpdateCmd(runningWater, cycleKey, actualAmount, activityType); + Integer cycleType = RankingCycleType.WEEKLY.getCode(); + + if (RankingActivityType.CP_SEASON == activityType) { + cycleType = RankingCycleType.SEASON.getCode(); + cycleKey = SeasonUtils.getCurrentSeasonCycleKey(); + } + + getDataUpdateCmd(runningWater, cycleKey, actualAmount, activityType, cycleType); } catch (IllegalArgumentException e) { log.warn("未识别的活动类型: {}, activityId={}", activity.getActivityType(), activity.getId()); } @@ -410,16 +417,21 @@ public class RankCountStrategy implements GiftStrategy { return false; } + if (Arrays.asList(RankingActivityType.CP_SEASON, RankingActivityType.CP_WEEKLY).contains(activityType)) { + return isCpGift(runningWater.getGiftValue()); + } + // 默认规则 return activity.getGiftIds().contains(String.valueOf(runningWater.getGiftId())); } - private void getDataUpdateCmd(GiftGiveRunningWater runningWater, String cycleKey, Long actualAmount, RankingActivityType activityType) { + private void getDataUpdateCmd(GiftGiveRunningWater runningWater, String cycleKey, Long actualAmount, + RankingActivityType activityType, Integer cycleType) { RankingDataUpdateCmd receiverCmd = new RankingDataUpdateCmd(); receiverCmd.setUserId(runningWater.getUserId()); receiverCmd.setUserSex(1); receiverCmd.setActivityType(activityType.getCode()); - receiverCmd.setCycleType(RankingCycleType.WEEKLY.getCode()); + receiverCmd.setCycleType(cycleType); receiverCmd.setCycleKey(cycleKey); receiverCmd.setDimension(RankingDimension.CONSUME_AMOUNT.getCode()); receiverCmd.setIncrementQuantity(actualAmount); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java new file mode 100644 index 00000000..49928311 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/util/SeasonUtils.java @@ -0,0 +1,135 @@ +package com.red.circle.other.app.util; + +import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.time.LocalDate; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.List; + +/** + * 赛季工具类(基于星座周期) + */ +public class SeasonUtils { + + /** + * 星座赛季定义 + * 每个赛季对应一个星座周期 + */ + private static final List SEASON_PERIODS = Arrays.asList( + new SeasonPeriod("水瓶座", 1, 20, 2, 18), + new SeasonPeriod("双鱼座", 2, 19, 3, 20), + new SeasonPeriod("牡羊座", 3, 21, 4, 19), + new SeasonPeriod("金牛座", 4, 20, 5, 20), + new SeasonPeriod("双子座", 5, 21, 6, 21), + new SeasonPeriod("巨蟹座", 6, 22, 7, 22), + new SeasonPeriod("狮子座", 7, 23, 8, 22), + new SeasonPeriod("处女座", 8, 23, 9, 22), + new SeasonPeriod("天秤座", 9, 23, 10, 22), + new SeasonPeriod("天蝎座", 10, 23, 11, 21), + new SeasonPeriod("射手座", 11, 22, 12, 21), + new SeasonPeriod("摩羯座", 12, 22, 1, 19) + ); + + /** + * 获取当前赛季的cycleKey + * 格式:yyyyMMdd-yyyyMMdd + */ + public static String getCurrentSeasonCycleKey() { + ZonedDateTime now = ZonedDateTimeAsiaRiyadhUtils.now(); + return getSeasonCycleKey(now); + } + + /** + * 获取指定日期所在赛季的cycleKey + */ + public static String getSeasonCycleKey(ZonedDateTime dateTime) { + SeasonPeriod season = getCurrentSeason(dateTime); + + int year = dateTime.getYear(); + + // 处理跨年的赛季(摩羯座和水瓶座) + LocalDate startDate; + LocalDate endDate; + + if (season.startMonth > season.endMonth) { + // 跨年赛季:摩羯座(12/22-1/19) + if (dateTime.getMonthValue() == season.endMonth) { + // 如果当前是结束月份(1月),开始日期在去年 + startDate = LocalDate.of(year - 1, season.startMonth, season.startDay); + endDate = LocalDate.of(year, season.endMonth, season.endDay); + } else { + // 如果当前是开始月份(12月),结束日期在明年 + startDate = LocalDate.of(year, season.startMonth, season.startDay); + endDate = LocalDate.of(year + 1, season.endMonth, season.endDay); + } + } else { + // 同年赛季 + startDate = LocalDate.of(year, season.startMonth, season.startDay); + endDate = LocalDate.of(year, season.endMonth, season.endDay); + } + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + return startDate.format(formatter) + "-" + endDate.format(formatter); + } + + /** + * 获取当前所在的赛季信息 + */ + private static SeasonPeriod getCurrentSeason(ZonedDateTime dateTime) { + int month = dateTime.getMonthValue(); + int day = dateTime.getDayOfMonth(); + + for (SeasonPeriod season : SEASON_PERIODS) { + if (isInSeason(month, day, season)) { + return season; + } + } + + throw new IllegalStateException("无法确定当前赛季"); + } + + /** + * 判断日期是否在赛季内 + */ + private static boolean isInSeason(int month, int day, SeasonPeriod season) { + if (season.startMonth == season.endMonth) { + // 同月份 + return month == season.startMonth && day >= season.startDay && day <= season.endDay; + } else if (season.startMonth < season.endMonth) { + // 跨月但不跨年 + if (month == season.startMonth) { + return day >= season.startDay; + } else if (month == season.endMonth) { + return day <= season.endDay; + } else { + return month > season.startMonth && month < season.endMonth; + } + } else { + // 跨年(摩羯座) + if (month == season.startMonth) { + return day >= season.startDay; + } else if (month == season.endMonth) { + return day <= season.endDay; + } else { + return month > season.startMonth || month < season.endMonth; + } + } + } + + /** + * 赛季周期定义 + */ + @Data + @AllArgsConstructor + private static class SeasonPeriod { + private String name; // 星座名称 + private int startMonth; // 开始月份 + private int startDay; // 开始日期 + private int endMonth; // 结束月份 + private int endDay; // 结束日期 + } +} \ No newline at end of file diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/ranking/RankingActivityType.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/ranking/RankingActivityType.java index 4a5d4fdf..53f9e97d 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/ranking/RankingActivityType.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/ranking/RankingActivityType.java @@ -50,6 +50,10 @@ public enum RankingActivityType { FRUIT_PARTY(11, "FruitParty", "统计游戏数据排行"), CHRISTMAS(12, "圣诞节活动", "统计送礼物消费排行"), + + CP_WEEKLY(13, "CP周榜", "统计送CP礼物消费排行"), + + CP_SEASON(14, "CP季度榜", "统计送CP礼物消费排行"), ; /** diff --git a/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java b/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java index 8d205a9d..d6b06b50 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/ApiTest.java @@ -1,4 +1,5 @@ import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.other.app.util.SeasonUtils; import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils; import com.red.circle.other.inner.asserts.user.UserSpecialErrorCode; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -16,6 +17,12 @@ import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCyc public class ApiTest { + @Test + public void testSeason() { + System.out.println(SeasonUtils.getCurrentSeasonCycleKey()); + + } + @Test public void testPassword() { System.out.println(ZonedDateTimeAsiaRiyadhUtils.now());