cp 榜单重写
This commit is contained in:
parent
17f1b83a6e
commit
76f357497d
@ -5,9 +5,11 @@ import com.red.circle.framework.web.controller.BaseController;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO;
|
||||
import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd;
|
||||
import com.red.circle.other.app.service.activity.WeekCpUserGiftService;
|
||||
import com.red.circle.other.inner.enums.activity.PropsActivityTypeEnum;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -45,29 +47,29 @@ public class WeekCpGiftRestController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 上周与这周.
|
||||
* cp排行榜(周榜和赛季榜)
|
||||
*
|
||||
* @eo.name 上周与这周
|
||||
* @eo.url /week-data
|
||||
* @eo.name CP排行榜
|
||||
* @eo.url /ranking-data
|
||||
* @eo.method get
|
||||
* @eo.request-type formdata
|
||||
*/
|
||||
@GetMapping("/week-data")
|
||||
public ActivityWeekCpGiftCO weekData(AppExtCommand cmd) {
|
||||
return weekCpUserGiftService.weekData(cmd);
|
||||
@GetMapping("/ranking-data")
|
||||
public ActivityWeekCpGiftCO rankingData(@Valid CpRankingQueryCmd cmd) {
|
||||
return weekCpUserGiftService.rankingData(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上周前三名用户.
|
||||
* 赛季榜Top1
|
||||
*
|
||||
* @eo.name 上周前三名用户
|
||||
* @eo.url /last-week-users-top3
|
||||
* @eo.name 赛季榜Top1
|
||||
* @eo.url /season-top1
|
||||
* @eo.method get
|
||||
* @eo.request-type formdata
|
||||
*/
|
||||
@GetMapping("/last-week-users-top3")
|
||||
public List<ActivityCpUserRankingCO> lastWeekUsersTop3(AppExtCommand cmd) {
|
||||
return weekCpUserGiftService.lastWeekUsersTop3(cmd);
|
||||
@GetMapping("/season-top1")
|
||||
public List<ActivityCpUserRankingCO> seasonTop1(AppExtCommand cmd) {
|
||||
return weekCpUserGiftService.seasonTop1(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class LastWeekCpUsersTop3QueryExe {
|
||||
public List<ActivityCpUserRankingCO> execute(AppExtCommand cmd) {
|
||||
|
||||
return assemble(weekCpValueCountService.listLastWeekTop(
|
||||
cmd.getReqSysOrigin().getOrigin(), 3)
|
||||
cmd.getReqSysOrigin().getOrigin(), 1)
|
||||
);
|
||||
}
|
||||
|
||||
@ -78,8 +78,7 @@ public class LastWeekCpUsersTop3QueryExe {
|
||||
ranking.setCpUserNickname(cpUserProfile.getUserNickname());
|
||||
ranking.setCpUserSex(cpUserProfile.getUserSex());
|
||||
|
||||
ranking.setUserProfiles(List.of(userProfile,
|
||||
cpUserProfile));
|
||||
// ranking.setUserProfiles(List.of(userProfile,cpUserProfile));
|
||||
return ranking;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
|
||||
@ -0,0 +1,92 @@
|
||||
package com.red.circle.other.app.command.activity.query;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.infra.common.user.UserCpUtils;
|
||||
import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount;
|
||||
import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService;
|
||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO;
|
||||
import com.red.circle.tool.core.collection.CollectionUtils;
|
||||
import com.red.circle.tool.core.num.NumUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 赛季榜Top1查询.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SeasonCpTop1QueryExe {
|
||||
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final WeekCpValueCountService weekCpValueCountService;
|
||||
private final UserProfileAppConvertor userProfileAppConvertor;
|
||||
|
||||
public List<ActivityCpUserRankingCO> execute(AppExtCommand cmd) {
|
||||
List<WeekCpValueCount> lastSeasonTop = weekCpValueCountService
|
||||
.listLastSeasonTop(cmd.getReqSysOrigin().getOrigin(), 1);
|
||||
|
||||
if (CollectionUtils.isEmpty(lastSeasonTop)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
return assemble(lastSeasonTop);
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> assemble(List<WeekCpValueCount> weekCpValueCounts) {
|
||||
if (CollectionUtils.isEmpty(weekCpValueCounts)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
List<ActivityCpUserRankingCO> results = weekCpValueCounts.stream().map(weekCpValueCount -> {
|
||||
WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId());
|
||||
return new ActivityCpUserRankingCO()
|
||||
.setUserId(userIdPair.getUserIdOne())
|
||||
.setCpUserId(userIdPair.getUserIdTwo())
|
||||
.setTotalNumber(weekCpValueCount.getQuantity())
|
||||
.setTotal(NumUtils.formatLong(weekCpValueCount.getQuantity()));
|
||||
}
|
||||
).toList();
|
||||
|
||||
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
|
||||
userProfileGateway.mapByUserIds(getAllUserIds(results))
|
||||
);
|
||||
|
||||
return results.stream().map(ranking -> {
|
||||
UserProfileDTO userProfile = userProfileMap.get(ranking.getUserId());
|
||||
UserProfileDTO cpUserProfile = userProfileMap.get(ranking.getCpUserId());
|
||||
if (Objects.isNull(userProfile) || Objects.isNull(cpUserProfile)) {
|
||||
return null;
|
||||
}
|
||||
ranking.setUserAvatar(userProfile.getUserAvatar());
|
||||
ranking.setUserNickname(userProfile.getUserNickname());
|
||||
ranking.setUserSex(userProfile.getUserSex());
|
||||
|
||||
ranking.setCpUserAvatar(cpUserProfile.getUserAvatar());
|
||||
ranking.setCpUserNickname(cpUserProfile.getUserNickname());
|
||||
ranking.setCpUserSex(cpUserProfile.getUserSex());
|
||||
return ranking;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Set<Long> getAllUserIds(List<ActivityCpUserRankingCO> results) {
|
||||
return results.stream()
|
||||
.map(ranking -> Arrays.asList(ranking.getUserId(), ranking.getCpUserId()))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,16 +1,14 @@
|
||||
package com.red.circle.other.app.command.activity.query;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import com.red.circle.other.infra.common.user.UserCpUtils;
|
||||
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO;
|
||||
import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
|
||||
import com.red.circle.other.infra.database.mongo.entity.user.count.WeekCpValueCount;
|
||||
import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService;
|
||||
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.WeekCpUserIdDTO;
|
||||
@ -27,101 +25,45 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 每周CP用户礼物护送消耗.
|
||||
*
|
||||
* @author pengshigang on 2021/08/28
|
||||
* @since pengliang on 2022-03-25
|
||||
* CP排行榜查询.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WeekCpUserGiftQueryExe {
|
||||
|
||||
private final UserRegionGateway userRegionGateway;
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final CpRelationshipService cpRelationshipService;
|
||||
private final WeekCpValueCountService weekCpValueCountService;
|
||||
private final UserProfileAppConvertor userProfileAppConvertor;
|
||||
|
||||
public ActivityWeekCpGiftCO execute(AppExtCommand cmd) {
|
||||
public ActivityWeekCpGiftCO execute(CpRankingQueryCmd cmd) {
|
||||
if (cmd.getType() == CpRankingQueryCmd.RankingType.WEEK) {
|
||||
return getWeekRanking(cmd);
|
||||
} else {
|
||||
return getSeasonRanking(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
private ActivityWeekCpGiftCO getWeekRanking(CpRankingQueryCmd cmd) {
|
||||
return new ActivityWeekCpGiftCO()
|
||||
.setThisWeekUserTop(getThisWeekUser(cmd))
|
||||
.setLastWeekUserTop(getLastWeekUser(cmd))
|
||||
.setThisUser(getThisUser(cmd));
|
||||
.setThisUser(getThisWeekCurrentUser(cmd));
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> fill(AppExtCommand cmd,
|
||||
List<ActivityCpUserRankingCO> rankings) {
|
||||
int resultSize = 20;
|
||||
if (CollectionUtils.isEmpty(rankings)) {
|
||||
return assembleFill(cpRelationshipService.listLatestCp(
|
||||
cmd.getReqSysOrigin().getOrigin(), resultSize
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (rankings.size() >= resultSize) {
|
||||
return rankings;
|
||||
}
|
||||
|
||||
int fillSize = resultSize - rankings.size();
|
||||
List<ActivityCpUserRankingCO> fillCo = assembleFill(
|
||||
cpRelationshipService.listLatestCp(
|
||||
cmd.getReqSysOrigin().getOrigin(),
|
||||
getAllUserIds(rankings),
|
||||
fillSize
|
||||
)
|
||||
);
|
||||
if (CollectionUtils.isEmpty(fillCo)) {
|
||||
return rankings;
|
||||
}
|
||||
rankings.addAll(fillCo);
|
||||
return rankings;
|
||||
private ActivityWeekCpGiftCO getSeasonRanking(CpRankingQueryCmd cmd) {
|
||||
return new ActivityWeekCpGiftCO()
|
||||
.setThisWeekUserTop(getThisSeasonUser(cmd))
|
||||
.setThisUser(getThisSeasonCurrentUser(cmd));
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> assembleFill(
|
||||
List<CpRelationship> cpRelationships) {
|
||||
if (CollectionUtils.isEmpty(cpRelationships)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
|
||||
userProfileGateway.mapByUserIds(
|
||||
cpRelationships.stream().map(
|
||||
cpRelationship -> Arrays.asList(cpRelationship.getUserId(),
|
||||
cpRelationship.getCpUserId())
|
||||
).flatMap(Collection::stream).collect(Collectors.toSet())));
|
||||
|
||||
return cpRelationships.stream().map(cpRelationship -> {
|
||||
UserProfileDTO userProfile = userProfileMap.get(cpRelationship.getUserId());
|
||||
UserProfileDTO cpUserProfile = userProfileMap.get(cpRelationship.getCpUserId());
|
||||
if (Objects.isNull(userProfile) || Objects.isNull(cpUserProfile)) {
|
||||
return null;
|
||||
}
|
||||
return new ActivityCpUserRankingCO()
|
||||
.setUserId(userProfile.getId())
|
||||
.setUserAvatar(userProfile.getUserAvatar())
|
||||
.setUserNickname(userProfile.getUserNickname())
|
||||
.setUserSex(userProfile.getUserSex())
|
||||
.setTotalNumber(0L)
|
||||
.setTotal("0")
|
||||
.setCpUserId(cpUserProfile.getId())
|
||||
.setCpUserAvatar(cpUserProfile.getUserAvatar())
|
||||
.setCpUserNickname(cpUserProfile.getUserNickname())
|
||||
.setCpUserSex(cpUserProfile.getUserSex())
|
||||
.setUserProfiles(List.of(userProfile,
|
||||
cpUserProfile));
|
||||
}).filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private ActivityCpUserRankingCO getThisUser(AppExtCommand cmd) {
|
||||
|
||||
private ActivityCpUserRankingCO getThisWeekCurrentUser(CpRankingQueryCmd cmd) {
|
||||
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
||||
if (cpUserIdList.isEmpty()) {
|
||||
return new ActivityCpUserRankingCO();
|
||||
}
|
||||
|
||||
Long cpUserId = cpUserIdList.get(0);
|
||||
WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount(
|
||||
Long cpUserId = cpUserIdList.get(0);
|
||||
WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount(
|
||||
cmd.getReqSysOrigin().getOrigin(),
|
||||
cmd.getReqUserId(), cpUserId);
|
||||
if (Objects.isNull(thisUser)) {
|
||||
@ -134,19 +76,33 @@ public class WeekCpUserGiftQueryExe {
|
||||
return users.get(0);
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> getThisWeekUser(AppExtCommand cmd) {
|
||||
return assemble(weekCpValueCountService.listThisWeekTop(
|
||||
private ActivityCpUserRankingCO getThisSeasonCurrentUser(CpRankingQueryCmd cmd) {
|
||||
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
||||
if (cpUserIdList.isEmpty()) {
|
||||
return new ActivityCpUserRankingCO();
|
||||
}
|
||||
|
||||
Long cpUserId = cpUserIdList.get(0);
|
||||
WeekCpValueCount thisSeason = weekCpValueCountService.getUserThisSeasonCount(
|
||||
cmd.getReqSysOrigin().getOrigin(),
|
||||
userRegionGateway.getRegionCode(cmd.getReqUserId()),
|
||||
20)
|
||||
cmd.getReqUserId(), cpUserId);
|
||||
if (Objects.isNull(thisSeason)) {
|
||||
return new ActivityCpUserRankingCO();
|
||||
}
|
||||
List<ActivityCpUserRankingCO> users = assemble(Lists.newArrayList(thisSeason));
|
||||
if (CollectionUtils.isEmpty(users)) {
|
||||
return new ActivityCpUserRankingCO();
|
||||
}
|
||||
return users.get(0);
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> getThisWeekUser(CpRankingQueryCmd cmd) {
|
||||
return assemble(weekCpValueCountService.listThisWeekTop(cmd.getReqSysOrigin().getOrigin(), 20)
|
||||
);
|
||||
}
|
||||
|
||||
private List<ActivityCpUserRankingCO> getLastWeekUser(AppExtCommand cmd) {
|
||||
return assemble(weekCpValueCountService.listLastWeekTop(
|
||||
cmd.getReqSysOrigin().getOrigin(),
|
||||
userRegionGateway.getRegionCode(cmd.getReqUserId()),
|
||||
3)
|
||||
private List<ActivityCpUserRankingCO> getThisSeasonUser(CpRankingQueryCmd cmd) {
|
||||
return assemble(weekCpValueCountService.listThisSeasonTop(cmd.getReqSysOrigin().getOrigin(), 20)
|
||||
);
|
||||
}
|
||||
|
||||
@ -183,8 +139,6 @@ public class WeekCpUserGiftQueryExe {
|
||||
ranking.setCpUserAvatar(cpUserProfile.getUserAvatar());
|
||||
ranking.setCpUserNickname(cpUserProfile.getUserNickname());
|
||||
ranking.setCpUserSex(cpUserProfile.getUserSex());
|
||||
ranking.setUserProfiles(List.of(userProfile,
|
||||
cpUserProfile));
|
||||
return ranking;
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
@ -198,5 +152,4 @@ public class WeekCpUserGiftQueryExe {
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ 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;
|
||||
@ -320,6 +319,16 @@ public class RankCountStrategy implements GiftStrategy {
|
||||
acceptAmount.longValue());
|
||||
|
||||
cpRelationshipCacheService.remove(Arrays.asList(cp.getUserId(), cp.getCpUserId()));
|
||||
|
||||
weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(),
|
||||
cp.getUserId(),
|
||||
cp.getCpUserId(),
|
||||
acceptAmount.longValue());
|
||||
|
||||
weekCpValueCountService.incrThisSeasonQuantity(runningWater.getSysOrigin(),
|
||||
cp.getUserId(),
|
||||
cp.getCpUserId(),
|
||||
acceptAmount.longValue());
|
||||
});
|
||||
// 更新cp用户赠送的礼物价值
|
||||
// cpRelationshipService.updateAccountByUserId(cpRelationship.getUserId(),
|
||||
@ -331,13 +340,6 @@ public class RankCountStrategy implements GiftStrategy {
|
||||
// ? userRegionGateway.getRegionCode(cpRelationship.getUserId()) :
|
||||
// userRegionGateway.getRegionCode(relationship.getUserId());
|
||||
|
||||
/*weekCpValueCountService.incrThisWeekQuantity(runningWater.getSysOrigin(),
|
||||
userRegionCode,
|
||||
cpRelationship.getUserId(),
|
||||
cpRelationship.getCpUserId(),
|
||||
acceptAmount.longValue());*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean isWeekStar(GiftValue giftValue) {
|
||||
|
||||
@ -70,6 +70,9 @@ public class CleanExpiredDismissingCpTask {
|
||||
weekCpValueCountService.removeThisWeek(cpRelationship.getUserId(),
|
||||
cpRelationship.getCpUserId());
|
||||
|
||||
weekCpValueCountService.removeThisSeason(cpRelationship.getUserId(),
|
||||
cpRelationship.getCpUserId());
|
||||
|
||||
// 删除CP值
|
||||
cpValueService.deleteById(cpRelationship.getCpValId());
|
||||
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
package com.red.circle.other.app.service.activity;
|
||||
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import com.red.circle.other.app.command.activity.query.LastWeekCpUsersTop3QueryExe;
|
||||
import com.red.circle.other.app.command.activity.query.RewardPoolQueryExe;
|
||||
import com.red.circle.other.app.command.activity.query.SeasonCpTop1QueryExe;
|
||||
import com.red.circle.other.app.command.activity.query.WeekCpUserGiftQueryExe;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO;
|
||||
import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 首充奖励池.
|
||||
*
|
||||
* @author pengshigang on 2021/8/3
|
||||
* CP排行榜服务.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -23,7 +22,7 @@ public class WeekCpUserGiftServiceImpl implements WeekCpUserGiftService {
|
||||
|
||||
private final RewardPoolQueryExe rewardPoolQueryExe;
|
||||
private final WeekCpUserGiftQueryExe weekCpUserGiftQueryExe;
|
||||
private final LastWeekCpUsersTop3QueryExe lastWeekCpUsersTop3QueryExe;
|
||||
private final SeasonCpTop1QueryExe seasonCpTop1QueryExe;
|
||||
|
||||
@Override
|
||||
public List<RewardPoolCO> listRewardPool(RewardPoolCmd cmd) {
|
||||
@ -31,12 +30,12 @@ public class WeekCpUserGiftServiceImpl implements WeekCpUserGiftService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityWeekCpGiftCO weekData(AppExtCommand cmd) {
|
||||
public ActivityWeekCpGiftCO rankingData(CpRankingQueryCmd cmd) {
|
||||
return weekCpUserGiftQueryExe.execute(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActivityCpUserRankingCO> lastWeekUsersTop3(AppExtCommand cmd) {
|
||||
return lastWeekCpUsersTop3QueryExe.execute(cmd);
|
||||
public List<ActivityCpUserRankingCO> seasonTop1(AppExtCommand cmd) {
|
||||
return seasonCpTop1QueryExe.execute(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package com.red.circle.other.app.dto.cmd.activity;
|
||||
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* CP排行榜查询
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CpRankingQueryCmd extends AppExtCommand {
|
||||
|
||||
/**
|
||||
* 榜单类型: WEEK-周榜, SEASON-赛季榜
|
||||
*/
|
||||
@NotNull(message = "榜单类型不能为空")
|
||||
private RankingType type;
|
||||
|
||||
public enum RankingType {
|
||||
WEEK,
|
||||
SEASON
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityCpUserRankingCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.ActivityWeekCpGiftCO;
|
||||
import com.red.circle.other.app.dto.clientobject.activity.RewardPoolCO;
|
||||
import com.red.circle.other.app.dto.cmd.activity.CpRankingQueryCmd;
|
||||
import com.red.circle.other.app.dto.cmd.activity.RewardPoolCmd;
|
||||
import java.util.List;
|
||||
|
||||
@ -16,8 +17,8 @@ public interface WeekCpUserGiftService {
|
||||
|
||||
List<RewardPoolCO> listRewardPool(RewardPoolCmd cmd);
|
||||
|
||||
ActivityWeekCpGiftCO weekData(AppExtCommand cmd);
|
||||
ActivityWeekCpGiftCO rankingData(CpRankingQueryCmd cmd);
|
||||
|
||||
List<ActivityCpUserRankingCO> lastWeekUsersTop3(AppExtCommand cmd);
|
||||
List<ActivityCpUserRankingCO> seasonTop1(AppExtCommand cmd);
|
||||
|
||||
}
|
||||
|
||||
@ -52,6 +52,31 @@ public interface WeekCpValueCountService {
|
||||
*/
|
||||
void removeThisWeek(Long userIdOne, Long userIdTwo);
|
||||
|
||||
/**
|
||||
* 累计本赛季统计.
|
||||
*/
|
||||
void incrThisSeasonQuantity(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity);
|
||||
|
||||
/**
|
||||
* 移除本赛季cp值.
|
||||
*/
|
||||
void removeThisSeason(Long userIdOne, Long userIdTwo);
|
||||
|
||||
/**
|
||||
* 获取我的本赛季贡献.
|
||||
*/
|
||||
WeekCpValueCount getUserThisSeasonCount(String sysOrigin, Long userIdOne, Long userIdTwo);
|
||||
|
||||
/**
|
||||
* 获取本赛季统计记录top.
|
||||
*/
|
||||
List<WeekCpValueCount> listThisSeasonTop(String sysOrigin, Integer size);
|
||||
|
||||
/**
|
||||
* 获取上赛季统计记录top.
|
||||
*/
|
||||
List<WeekCpValueCount> listLastSeasonTop(String sysOrigin, Integer size);
|
||||
|
||||
/**
|
||||
* 解析id中cp用户id.
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.red.circle.other.infra.database.mongo.service.user.count.impl;
|
||||
|
||||
import com.red.circle.other.infra.utils.SeasonUtils;
|
||||
import com.red.circle.tool.core.date.DateFormatConstant;
|
||||
import com.red.circle.tool.core.date.TimestampUtils;
|
||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||
@ -57,6 +58,50 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService {
|
||||
addThisWeekV2(sysOrigin, userRegionCode, userIdOne, userIdTwo, quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrThisSeasonQuantity(String sysOrigin, Long userIdOne, Long userIdTwo,
|
||||
Long quantity) {
|
||||
if (existsThisSeason(userIdOne, userIdTwo)) {
|
||||
mongoTemplate.updateFirst(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)),
|
||||
new Update().inc("quantity", quantity),
|
||||
WeekCpValueCount.class);
|
||||
return;
|
||||
}
|
||||
addThisSeason(sysOrigin, userIdOne, userIdTwo, quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeThisSeason(Long userIdOne, Long userIdTwo) {
|
||||
mongoTemplate.remove(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)
|
||||
.and("group").is(getThisSeasonCycleKey())), WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeekCpValueCount getUserThisSeasonCount(String sysOrigin, Long userIdOne, Long userIdTwo) {
|
||||
return mongoTemplate
|
||||
.findOne(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)
|
||||
.and("sysOrigin").is(sysOrigin))
|
||||
, WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WeekCpValueCount> listThisSeasonTop(String sysOrigin, Integer size) {
|
||||
return mongoTemplate
|
||||
.find(Query.query(Criteria.where("sysOrigin").is(sysOrigin)
|
||||
.and("group").is(getThisSeasonCycleKey()))
|
||||
.with(Sort.by(Sort.Order.desc("quantity")))
|
||||
.limit(size), WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WeekCpValueCount> listLastSeasonTop(String sysOrigin, Integer size) {
|
||||
return mongoTemplate
|
||||
.find(Query.query(Criteria.where("sysOrigin").is(sysOrigin)
|
||||
.and("group").is(getLastSeasonCycleKey()))
|
||||
.with(Sort.by(Sort.Order.desc("quantity")))
|
||||
.limit(size), WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
private void addThisWeek(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity) {
|
||||
mongoTemplate.save(new WeekCpValueCount()
|
||||
.setId(getWeekUniqueId(userIdOne, userIdTwo))
|
||||
@ -81,6 +126,16 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService {
|
||||
);
|
||||
}
|
||||
|
||||
private void addThisSeason(String sysOrigin, Long userIdOne, Long userIdTwo, Long quantity) {
|
||||
mongoTemplate.save(new WeekCpValueCount()
|
||||
.setId(getSeasonUniqueId(userIdOne, userIdTwo))
|
||||
.setSysOrigin(sysOrigin)
|
||||
.setQuantity(quantity)
|
||||
.setGroup(getThisSeasonCycleKey())
|
||||
.setCreateTime(TimestampUtils.now())
|
||||
.setExpiredTime(TimestampUtils.nowPlusDays(60))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeekCpValueCount getUserThisWeekCount(String sysOrigin, Long userIdOne, Long userIdTwo) {
|
||||
@ -178,19 +233,43 @@ public class WeekCpValueCountServiceImpl implements WeekCpValueCountService {
|
||||
.concat(getThisWeekDate());
|
||||
}
|
||||
|
||||
private String getSeasonUniqueId(Long userOne, Long userIdTwo) {
|
||||
return StringUtils.sortAscNumberJoin("_", userOne, userIdTwo)
|
||||
.concat("_")
|
||||
.concat(getThisSeasonCycleKey());
|
||||
}
|
||||
|
||||
private boolean existsThisWeek(Long userIdOne, Long userIdTwo) {
|
||||
return mongoTemplate
|
||||
.exists(Query.query(getUniquenessCriteria(userIdOne, userIdTwo)),
|
||||
WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
private boolean existsThisSeason(Long userIdOne, Long userIdTwo) {
|
||||
return mongoTemplate
|
||||
.exists(Query.query(getSeasonUniquenessCriteria(userIdOne, userIdTwo)),
|
||||
WeekCpValueCount.class);
|
||||
}
|
||||
|
||||
private Criteria getUniquenessCriteria(Long userIdOne, Long userIdTwo) {
|
||||
return Criteria.where("id").is(getWeekUniqueId(userIdOne, userIdTwo));
|
||||
}
|
||||
|
||||
private Criteria getSeasonUniquenessCriteria(Long userIdOne, Long userIdTwo) {
|
||||
return Criteria.where("id").is(getSeasonUniqueId(userIdOne, userIdTwo));
|
||||
}
|
||||
|
||||
private String getThisWeekDate() {
|
||||
return ZonedDateTimeUtils.format(ZonedDateTimeAsiaRiyadhUtils.nowWeekMonday(),
|
||||
DateFormatConstant.yyyyMMdd);
|
||||
}
|
||||
|
||||
private String getThisSeasonCycleKey() {
|
||||
return SeasonUtils.getCurrentSeasonCycleKey();
|
||||
}
|
||||
|
||||
private String getLastSeasonCycleKey() {
|
||||
return SeasonUtils.getLastSeasonCycleKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.red.circle.other.app.util;
|
||||
package com.red.circle.other.infra.utils;
|
||||
|
||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||
import com.red.circle.tool.core.date.ZonedId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.ZoneId;import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -43,6 +44,24 @@ public class SeasonUtils {
|
||||
return getSeasonCycleKey(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上一个赛季的cycleKey
|
||||
* 通过获取当前赛季开始日期前一天,来定位到上一个赛季
|
||||
*/
|
||||
public static String getLastSeasonCycleKey() {
|
||||
ZonedDateTime now = ZonedDateTimeAsiaRiyadhUtils.now();
|
||||
SeasonPeriod currentSeason = getCurrentSeason(now);
|
||||
|
||||
// 获取当前赛季的开始日期
|
||||
LocalDate currentSeasonStart = getSeasonStartDate(now, currentSeason);
|
||||
|
||||
// 当前赛季开始日期前一天,一定在上一个赛季内
|
||||
ZonedDateTime lastSeasonDate = currentSeasonStart.minusDays(1)
|
||||
.atStartOfDay(ZonedId.ASIA_RIYADH.getZonedId());
|
||||
|
||||
return getSeasonCycleKey(lastSeasonDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在赛季的cycleKey
|
||||
*/
|
||||
@ -76,6 +95,27 @@ public class SeasonUtils {
|
||||
return startDate.format(formatter) + "-" + endDate.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定日期所在赛季的开始日期
|
||||
*/
|
||||
private static LocalDate getSeasonStartDate(ZonedDateTime dateTime, SeasonPeriod season) {
|
||||
int year = dateTime.getYear();
|
||||
|
||||
if (season.startMonth > season.endMonth) {
|
||||
// 跨年赛季:摩羯座(12/22-1/19)
|
||||
if (dateTime.getMonthValue() == season.endMonth) {
|
||||
// 如果当前是结束月份(1月),开始日期在去年
|
||||
return LocalDate.of(year - 1, season.startMonth, season.startDay);
|
||||
} else {
|
||||
// 如果当前是开始月份(12月)
|
||||
return LocalDate.of(year, season.startMonth, season.startDay);
|
||||
}
|
||||
} else {
|
||||
// 同年赛季
|
||||
return LocalDate.of(year, season.startMonth, season.startDay);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前所在的赛季信息
|
||||
*/
|
||||
Loading…
x
Reference in New Issue
Block a user