新增cp活动周榜季度
This commit is contained in:
parent
b53a259726
commit
6035415969
@ -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.common.gift.GameLuckyGiftCommon;
|
||||||
import com.red.circle.other.app.dto.cmd.activity.RankingDataUpdateCmd;
|
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.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.UserProfileGateway;
|
||||||
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
|
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
|
||||||
import com.red.circle.other.domain.ranking.RankingActivityType;
|
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 com.red.circle.tool.core.regex.RegexConstant;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -103,7 +106,7 @@ public class RankCountStrategy implements GiftStrategy {
|
|||||||
|
|
||||||
// 幸运礼物比例
|
// 幸运礼物比例
|
||||||
boolean isLuckyGift = isLuckyGift(giftValue);
|
boolean isLuckyGift = isLuckyGift(giftValue);
|
||||||
BigDecimal luckyGiftRatio = gameLuckyGiftCommon.getLuckyGiftShareRatio(runningWater.getSysOrigin());
|
BigDecimal luckyGiftRatio = getLuckyGiftShareRatio(runningWater);
|
||||||
log.info("RankCountStrategy.processor---幸运礼物比例:{}", luckyGiftRatio);
|
log.info("RankCountStrategy.processor---幸运礼物比例:{}", luckyGiftRatio);
|
||||||
|
|
||||||
// 周星礼物排行榜计算
|
// 周星礼物排行榜计算
|
||||||
@ -147,6 +150,10 @@ public class RankCountStrategy implements GiftStrategy {
|
|||||||
giftGiveRunningWaterService.addLog(runningWater.getId(), "结束:排行榜相关统计");
|
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());
|
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());
|
return giftValue.getGiftType().contains(GiftTabEnum.CP.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,17 +384,17 @@ public class RankCountStrategy implements GiftStrategy {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//圣诞节特殊处理
|
|
||||||
RankingActivityType type = RankingActivityType.getByConstantName(activity.getActivityType());
|
|
||||||
if (type == RankingActivityType.CHRISTMAS) {
|
|
||||||
cycleKey = "20251222";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将活动类型转换为RankingActivityType枚举
|
// 将活动类型转换为RankingActivityType枚举
|
||||||
try {
|
try {
|
||||||
RankingActivityType activityType = RankingActivityType.valueOf(activity.getActivityType());
|
RankingActivityType activityType = RankingActivityType.valueOf(activity.getActivityType());
|
||||||
// 累计对应活动类型的数据
|
Integer cycleType = RankingCycleType.WEEKLY.getCode();
|
||||||
getDataUpdateCmd(runningWater, cycleKey, actualAmount, activityType);
|
|
||||||
|
if (RankingActivityType.CP_SEASON == activityType) {
|
||||||
|
cycleType = RankingCycleType.SEASON.getCode();
|
||||||
|
cycleKey = SeasonUtils.getCurrentSeasonCycleKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
getDataUpdateCmd(runningWater, cycleKey, actualAmount, activityType, cycleType);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.warn("未识别的活动类型: {}, activityId={}", activity.getActivityType(), activity.getId());
|
log.warn("未识别的活动类型: {}, activityId={}", activity.getActivityType(), activity.getId());
|
||||||
}
|
}
|
||||||
@ -410,16 +417,21 @@ public class RankCountStrategy implements GiftStrategy {
|
|||||||
return false;
|
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()));
|
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();
|
RankingDataUpdateCmd receiverCmd = new RankingDataUpdateCmd();
|
||||||
receiverCmd.setUserId(runningWater.getUserId());
|
receiverCmd.setUserId(runningWater.getUserId());
|
||||||
receiverCmd.setUserSex(1);
|
receiverCmd.setUserSex(1);
|
||||||
receiverCmd.setActivityType(activityType.getCode());
|
receiverCmd.setActivityType(activityType.getCode());
|
||||||
receiverCmd.setCycleType(RankingCycleType.WEEKLY.getCode());
|
receiverCmd.setCycleType(cycleType);
|
||||||
receiverCmd.setCycleKey(cycleKey);
|
receiverCmd.setCycleKey(cycleKey);
|
||||||
receiverCmd.setDimension(RankingDimension.CONSUME_AMOUNT.getCode());
|
receiverCmd.setDimension(RankingDimension.CONSUME_AMOUNT.getCode());
|
||||||
receiverCmd.setIncrementQuantity(actualAmount);
|
receiverCmd.setIncrementQuantity(actualAmount);
|
||||||
|
|||||||
@ -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<SeasonPeriod> 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; // 结束日期
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -50,6 +50,10 @@ public enum RankingActivityType {
|
|||||||
FRUIT_PARTY(11, "FruitParty", "统计游戏数据排行"),
|
FRUIT_PARTY(11, "FruitParty", "统计游戏数据排行"),
|
||||||
|
|
||||||
CHRISTMAS(12, "圣诞节活动", "统计送礼物消费排行"),
|
CHRISTMAS(12, "圣诞节活动", "统计送礼物消费排行"),
|
||||||
|
|
||||||
|
CP_WEEKLY(13, "CP周榜", "统计送CP礼物消费排行"),
|
||||||
|
|
||||||
|
CP_SEASON(14, "CP季度榜", "统计送CP礼物消费排行"),
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
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.infra.database.mongo.service.team.TeamBillCycleUtils;
|
||||||
import com.red.circle.other.inner.asserts.user.UserSpecialErrorCode;
|
import com.red.circle.other.inner.asserts.user.UserSpecialErrorCode;
|
||||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
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 {
|
public class ApiTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSeason() {
|
||||||
|
System.out.println(SeasonUtils.getCurrentSeasonCycleKey());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPassword() {
|
public void testPassword() {
|
||||||
System.out.println(ZonedDateTimeAsiaRiyadhUtils.now());
|
System.out.println(ZonedDateTimeAsiaRiyadhUtils.now());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user