优化佩戴勋章和卸载勋章逻辑

This commit is contained in:
tianfeng 2026-01-22 11:12:56 +08:00
parent 85f3e58190
commit bf65d36868

View File

@ -31,6 +31,7 @@ import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.date.TimestampUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
/**
* 徽章操作处理.
@ -125,15 +126,9 @@ public class BadgeOperateListener implements MessageListener {
badgeBackpackService.save(buildSaveUserBadgeBackpack(badgeId, userId, days));
// 我的勋章
Set<Long> badgeIdSet = getUseBadgeIdSet(userId);
UserProfile userProfile = userProfileGateway.getByUserId(userId);
List<UserUseBadgeDTO> wearBadge = userProfile.getWearBadge();
List<UserUseBadgeDTO> honorBadge = userProfile.getWearHonor();
wearBadge.addAll(honorBadge);
Set<Long> badgeIdSet = wearBadge.stream().map(UserUseBadgeDTO::getId).collect(Collectors.toSet());
//新增得勋章
badgeIdSet.add(badgeId);
userRunProfileService.updateUserWearBadgesOverlay(userId,
userBadgeCommon.listUseBadge(userId, userProfile.getSysOriginChild(), badgeIdSet)
);
@ -142,26 +137,26 @@ public class BadgeOperateListener implements MessageListener {
});
}
@NotNull
private Set<Long> getUseBadgeIdSet(Long userId) {
List<BadgeBackpack> ownBadgeList = badgeBackpackService.query()
.eq(BadgeBackpack::getUserId, userId)
.eq(BadgeBackpack::getUseProps, Boolean.TRUE)
.list();
return ownBadgeList.stream().map(BadgeBackpack::getBadgeId).collect(Collectors.toSet());
}
/**
* 移除徽章.
*/
private void handleRemoveBadge(Long userId, Long badgeId) {
badgeBackpackService.deleteBadges(userId, Sets.newHashSet(badgeId));
userProfileGateway.removeCache(userId);
Set<Long> badgeIdSet = getUseBadgeIdSet(userId);
UserProfile userProfile = userProfileGateway.getByUserId(userId);
if (Objects.isNull(userProfile)) {
return;
}
List<UserUseBadgeDTO> wearBadge = userProfile.getWearBadge();
List<UserUseBadgeDTO> honorBadge = userProfile.getWearHonor();
wearBadge.addAll(honorBadge);
if (CollectionUtils.isEmpty(wearBadge)) {
return;
}
Set<Long> saveWear = wearBadge.stream().map(UserUseBadgeDTO::getId)
.filter(id -> !badgeId.equals(id)).collect(Collectors.toSet());
userRunProfileService.updateUserWearBadgesOverlay(userId,
userBadgeCommon.listUseBadge(userId, userProfile.getSysOriginChild(), saveWear)
userBadgeCommon.listUseBadge(userId, userProfile.getSysOriginChild(), badgeIdSet)
);
}