cp榜单修改
This commit is contained in:
parent
3ba78182c1
commit
d43fba354f
@ -52,6 +52,7 @@ public class SeasonCpTop1QueryExe {
|
|||||||
List<ActivityCpUserRankingCO> results = weekCpValueCounts.stream().map(weekCpValueCount -> {
|
List<ActivityCpUserRankingCO> results = weekCpValueCounts.stream().map(weekCpValueCount -> {
|
||||||
WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId());
|
WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId());
|
||||||
return new ActivityCpUserRankingCO()
|
return new ActivityCpUserRankingCO()
|
||||||
|
.setRank(1)
|
||||||
.setUserId(userIdPair.getUserIdOne())
|
.setUserId(userIdPair.getUserIdOne())
|
||||||
.setCpUserId(userIdPair.getUserIdTwo())
|
.setCpUserId(userIdPair.getUserIdTwo())
|
||||||
.setTotalNumber(weekCpValueCount.getQuantity())
|
.setTotalNumber(weekCpValueCount.getQuantity())
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -31,6 +32,9 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WeekCpUserGiftQueryExe {
|
public class WeekCpUserGiftQueryExe {
|
||||||
|
|
||||||
|
private static final int TOP_SIZE = 50;
|
||||||
|
private static final int OUT_OF_RANK = 99;
|
||||||
|
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
private final CpRelationshipService cpRelationshipService;
|
private final CpRelationshipService cpRelationshipService;
|
||||||
private final WeekCpValueCountService weekCpValueCountService;
|
private final WeekCpValueCountService weekCpValueCountService;
|
||||||
@ -45,75 +49,122 @@ public class WeekCpUserGiftQueryExe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ActivityWeekCpGiftCO getWeekRanking(CpRankingQueryCmd cmd) {
|
private ActivityWeekCpGiftCO getWeekRanking(CpRankingQueryCmd cmd) {
|
||||||
|
List<ActivityCpUserRankingCO> topList = getThisWeekUser(cmd);
|
||||||
|
ActivityCpUserRankingCO currentUser = getThisWeekCurrentUser(cmd, topList);
|
||||||
|
|
||||||
return new ActivityWeekCpGiftCO()
|
return new ActivityWeekCpGiftCO()
|
||||||
.setThisWeekUserTop(getThisWeekUser(cmd))
|
.setThisWeekUserTop(topList)
|
||||||
.setThisUser(getThisWeekCurrentUser(cmd));
|
.setThisUser(currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActivityWeekCpGiftCO getSeasonRanking(CpRankingQueryCmd cmd) {
|
private ActivityWeekCpGiftCO getSeasonRanking(CpRankingQueryCmd cmd) {
|
||||||
|
List<ActivityCpUserRankingCO> topList = getThisSeasonUser(cmd);
|
||||||
|
ActivityCpUserRankingCO currentUser = getThisSeasonCurrentUser(cmd, topList);
|
||||||
|
|
||||||
return new ActivityWeekCpGiftCO()
|
return new ActivityWeekCpGiftCO()
|
||||||
.setThisWeekUserTop(getThisSeasonUser(cmd))
|
.setThisWeekUserTop(topList)
|
||||||
.setThisUser(getThisSeasonCurrentUser(cmd));
|
.setThisUser(currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActivityCpUserRankingCO getThisWeekCurrentUser(CpRankingQueryCmd cmd) {
|
private ActivityCpUserRankingCO getThisWeekCurrentUser(CpRankingQueryCmd cmd,
|
||||||
|
List<ActivityCpUserRankingCO> topList) {
|
||||||
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
||||||
if (cpUserIdList.isEmpty()) {
|
if (cpUserIdList.isEmpty()) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
|
|
||||||
Long cpUserId = cpUserIdList.get(0);
|
Long cpUserId = cpUserIdList.get(0);
|
||||||
|
|
||||||
|
// 先在Top榜单中查找
|
||||||
|
ActivityCpUserRankingCO userInTop = findUserInTopList(cmd.getReqUserId(), cpUserId, topList);
|
||||||
|
if (Objects.nonNull(userInTop)) {
|
||||||
|
return userInTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不在Top榜单,单独查询并设置排名为99
|
||||||
WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount(
|
WeekCpValueCount thisUser = weekCpValueCountService.getUserThisWeekCount(
|
||||||
cmd.getReqSysOrigin().getOrigin(),
|
cmd.getReqSysOrigin().getOrigin(),
|
||||||
cmd.getReqUserId(), cpUserId);
|
cmd.getReqUserId(), cpUserId);
|
||||||
if (Objects.isNull(thisUser)) {
|
if (Objects.isNull(thisUser)) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
List<ActivityCpUserRankingCO> users = assemble(Lists.newArrayList(thisUser));
|
|
||||||
|
List<ActivityCpUserRankingCO> users = assemble(Lists.newArrayList(thisUser), OUT_OF_RANK);
|
||||||
if (CollectionUtils.isEmpty(users)) {
|
if (CollectionUtils.isEmpty(users)) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
return users.get(0);
|
return users.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActivityCpUserRankingCO getThisSeasonCurrentUser(CpRankingQueryCmd cmd) {
|
private ActivityCpUserRankingCO getThisSeasonCurrentUser(CpRankingQueryCmd cmd,
|
||||||
|
List<ActivityCpUserRankingCO> topList) {
|
||||||
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
List<Long> cpUserIdList = cpRelationshipService.getCpUserId(cmd.getReqUserId());
|
||||||
if (cpUserIdList.isEmpty()) {
|
if (cpUserIdList.isEmpty()) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
|
|
||||||
Long cpUserId = cpUserIdList.get(0);
|
Long cpUserId = cpUserIdList.get(0);
|
||||||
|
|
||||||
|
// 先在Top榜单中查找
|
||||||
|
ActivityCpUserRankingCO userInTop = findUserInTopList(cmd.getReqUserId(), cpUserId, topList);
|
||||||
|
if (Objects.nonNull(userInTop)) {
|
||||||
|
return userInTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不在Top榜单,单独查询并设置排名为99
|
||||||
WeekCpValueCount thisSeason = weekCpValueCountService.getUserThisSeasonCount(
|
WeekCpValueCount thisSeason = weekCpValueCountService.getUserThisSeasonCount(
|
||||||
cmd.getReqSysOrigin().getOrigin(),
|
cmd.getReqSysOrigin().getOrigin(),
|
||||||
cmd.getReqUserId(), cpUserId);
|
cmd.getReqUserId(), cpUserId);
|
||||||
if (Objects.isNull(thisSeason)) {
|
if (Objects.isNull(thisSeason)) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
List<ActivityCpUserRankingCO> users = assemble(Lists.newArrayList(thisSeason));
|
|
||||||
|
List<ActivityCpUserRankingCO> users = assemble(Lists.newArrayList(thisSeason), OUT_OF_RANK);
|
||||||
if (CollectionUtils.isEmpty(users)) {
|
if (CollectionUtils.isEmpty(users)) {
|
||||||
return new ActivityCpUserRankingCO();
|
return new ActivityCpUserRankingCO();
|
||||||
}
|
}
|
||||||
return users.get(0);
|
return users.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ActivityCpUserRankingCO findUserInTopList(Long userId, Long cpUserId,
|
||||||
|
List<ActivityCpUserRankingCO> topList) {
|
||||||
|
if (CollectionUtils.isEmpty(topList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return topList.stream()
|
||||||
|
.filter(ranking ->
|
||||||
|
(ranking.getUserId().equals(userId) && ranking.getCpUserId().equals(cpUserId)) ||
|
||||||
|
(ranking.getUserId().equals(cpUserId) && ranking.getCpUserId().equals(userId))
|
||||||
|
)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
private List<ActivityCpUserRankingCO> getThisWeekUser(CpRankingQueryCmd cmd) {
|
private List<ActivityCpUserRankingCO> getThisWeekUser(CpRankingQueryCmd cmd) {
|
||||||
return assemble(weekCpValueCountService.listThisWeekTop(cmd.getReqSysOrigin().getOrigin(), 20)
|
List<WeekCpValueCount> topList = weekCpValueCountService.listThisWeekTop(
|
||||||
);
|
cmd.getReqSysOrigin().getOrigin(), TOP_SIZE);
|
||||||
|
return assemble(topList, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ActivityCpUserRankingCO> getThisSeasonUser(CpRankingQueryCmd cmd) {
|
private List<ActivityCpUserRankingCO> getThisSeasonUser(CpRankingQueryCmd cmd) {
|
||||||
return assemble(weekCpValueCountService.listThisSeasonTop(cmd.getReqSysOrigin().getOrigin(), 20)
|
List<WeekCpValueCount> topList = weekCpValueCountService.listThisSeasonTop(
|
||||||
);
|
cmd.getReqSysOrigin().getOrigin(), TOP_SIZE);
|
||||||
|
return assemble(topList, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ActivityCpUserRankingCO> assemble(List<WeekCpValueCount> weekCpValueCounts) {
|
private List<ActivityCpUserRankingCO> assemble(List<WeekCpValueCount> weekCpValueCounts,
|
||||||
|
int startRank) {
|
||||||
if (CollectionUtils.isEmpty(weekCpValueCounts)) {
|
if (CollectionUtils.isEmpty(weekCpValueCounts)) {
|
||||||
return Lists.newArrayList();
|
return Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AtomicInteger rankCounter = new AtomicInteger(startRank);
|
||||||
|
|
||||||
List<ActivityCpUserRankingCO> results = weekCpValueCounts.stream().map(weekCpValueCount -> {
|
List<ActivityCpUserRankingCO> results = weekCpValueCounts.stream().map(weekCpValueCount -> {
|
||||||
WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId());
|
WeekCpUserIdDTO userIdPair = UserCpUtils.parseUserIdPair(weekCpValueCount.getId());
|
||||||
return new ActivityCpUserRankingCO()
|
return new ActivityCpUserRankingCO()
|
||||||
|
.setRank(rankCounter.getAndIncrement())
|
||||||
.setUserId(userIdPair.getUserIdOne())
|
.setUserId(userIdPair.getUserIdOne())
|
||||||
.setCpUserId(userIdPair.getUserIdTwo())
|
.setCpUserId(userIdPair.getUserIdTwo())
|
||||||
.setTotalNumber(weekCpValueCount.getQuantity())
|
.setTotalNumber(weekCpValueCount.getQuantity())
|
||||||
@ -122,8 +173,7 @@ public class WeekCpUserGiftQueryExe {
|
|||||||
).toList();
|
).toList();
|
||||||
|
|
||||||
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
|
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
|
||||||
userProfileGateway.mapByUserIds(
|
userProfileGateway.mapByUserIds(getAllUserIds(results))
|
||||||
getAllUserIds(results))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return results.stream().map(ranking -> {
|
return results.stream().map(ranking -> {
|
||||||
|
|||||||
@ -24,6 +24,11 @@ public class ActivityCpUserRankingCO implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排名.
|
||||||
|
*/
|
||||||
|
private Integer rank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID.
|
* ID.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user