国王皇后我的排名字段处理

This commit is contained in:
tianfeng 2025-09-23 11:57:49 +08:00
parent e44e3cfbff
commit 12b9151f21
4 changed files with 72 additions and 8 deletions

View File

@ -32,14 +32,21 @@ public class WeekKingQueenUserContributeQueryExe {
public UserCharmWealthContributeCO execute(AppExtCommand cmd) {
UserProfile baseInfo = userProfileGateway.getByUserId(cmd.getReqUserId());
// 获取带排名的魅力和财富数据
WeekKingQueenCount charmData = getContributeWithRank(cmd, KingQueenType.CHARM);
WeekKingQueenCount wealthData = getContributeWithRank(cmd, KingQueenType.WEALTH);
return new UserCharmWealthContributeCO()
.setUserId(baseInfo.getId())
.setUserSex(baseInfo.getUserSex())
.setAccount(baseInfo.getAccount())
.setUserAvatar(baseInfo.getUserAvatar())
.setUserNickname(baseInfo.getUserNickname())
.setCharmQuantity(getContribute(cmd, KingQueenType.CHARM))
.setWealthQuantity(getContribute(cmd, KingQueenType.WEALTH));
.setCharmQuantity(charmData != null ? NumUtils.formatLong(charmData.getQuantity()) : "0")
.setWealthQuantity(wealthData != null ? NumUtils.formatLong(wealthData.getQuantity()) : "0")
.setCharmRank(charmData != null ? charmData.getRank() : null)
.setWealthRank(wealthData != null ? wealthData.getRank() : null);
}
private String getContribute(AppExtCommand cmd, KingQueenType type) {
@ -50,6 +57,15 @@ public class WeekKingQueenUserContributeQueryExe {
.orElse("0");
}
/**
* 获取带排名的贡献数据.
*/
private WeekKingQueenCount getContributeWithRank(AppExtCommand cmd, KingQueenType type) {
return weekKingQueenCountService
.getUserThisWeekCountWithRank(cmd.getReqSysOrigin().getOrigin(), type,
cmd.getReqUserId());
}
private UserRankCO getUserProfile(WeekKingQueenCount charm,
Map<Long, UserProfileDTO> userBaseMap) {
return Optional.ofNullable(charm)

View File

@ -53,4 +53,14 @@ public class UserCharmWealthContributeCO extends ClientObject {
*/
private String wealthQuantity;
/**
* 魅力排名.
*/
private Integer charmRank;
/**
* 财富排名.
*/
private Integer wealthRank;
}

View File

@ -24,6 +24,11 @@ public interface WeekKingQueenCountService {
*/
WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type, Long userId);
/**
* 获取用户在本周的排名信息.
*/
WeekKingQueenCount getUserThisWeekCountWithRank(String sysOrigin, KingQueenType type, Long userId);
/**
* 获取本周统计记录top.
*/

View File

@ -44,6 +44,15 @@ public class WeekKingQueenCountServiceImpl implements WeekKingQueenCountService
private final MongoPrimaryService mongoPrimaryService;
private final UserProfileGateway userProfileGateway;
@Override
public WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type,
Long userId) {
return mongoTemplate
.findOne(Query.query(getUniquenessCriteria(userId, type)
.and("sysOrigin").is(sysOrigin))
, WeekKingQueenCount.class);
}
@Override
public void incrThisWeekQuantity(String sysOrigin, Long userId, KingQueenType type,
Long quantity) {
@ -57,12 +66,36 @@ public class WeekKingQueenCountServiceImpl implements WeekKingQueenCountService
}
@Override
public WeekKingQueenCount getUserThisWeekCount(String sysOrigin, KingQueenType type,
Long userId) {
return mongoTemplate
.findOne(Query.query(getUniquenessCriteria(userId, type)
.and("sysOrigin").is(sysOrigin))
, WeekKingQueenCount.class);
public WeekKingQueenCount getUserThisWeekCountWithRank(String sysOrigin, KingQueenType type, Long userId) {
// 先获取用户的本周数据
WeekKingQueenCount userCount = getUserThisWeekCount(sysOrigin, type, userId);
if (userCount == null) {
return null;
}
// 构建查询条件根据业务规则过滤性别
Criteria criteria = Criteria.where("sysOrigin").is(sysOrigin)
.and("group").is(getThisWeekDate())
.and("type").is(type);
// 根据类型过滤性别
if (type == KingQueenType.CHARM) {
// 魅力类型只显示女性0
criteria.and("userSex").is(0);
} else if (type == KingQueenType.WEALTH) {
// 财富类型只显示男性1
criteria.and("userSex").is(1);
}
// 统计比用户数量更高的人数即排名
long rank = mongoTemplate.count(
Query.query(criteria.and("quantity").gt(userCount.getQuantity())),
WeekKingQueenCount.class
) + 1;
// 设置排名并返回
userCount.setRank((int) rank);
return userCount;
}
@Override