diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java index 1b06a1e4..e3c439a6 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java @@ -17,10 +17,12 @@ import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; /** * 用户cp对查询. @@ -51,27 +53,44 @@ public class UserCpPairUserProfileQryExe { UserProfileDTO meUserProfileDTO = userProfileAppConvertor.toSimpleUserProfileDTO(meUser); - return cpList.stream() - .map(cp -> { - String status = dismissing.stream() - .anyMatch(d -> d.getCpUserId().equals(cp.getCpUserId())) ? "DISMISSING" : "NORMAL"; - return new CpPairUserProfileCO() - .setMeUserProfile(meUserProfileDTO) - .setCpUserProfile(getUserProfile(cp.getCpUserId())) - .setStatus(status) - .setCpValue(cp.getCpValue()) - .setDays(cp.getDays()) - .setFirstDay(cp.getFirstDay()) - .setCpLevel(cp.getCpLevel()) - .setNextLevelExp(cp.getNextLevelExp()) - .setLoveHeartLevel(cp.getLoveHeartLevel()) - .setMicEffectLevel(cp.getMicEffectLevel()) - .setProfileCardLevel(cp.getProfileCardLevel()) - .setGiftWindowLevel(cp.getGiftWindowLevel()) - .setHasNonMicEffect(cp.getHasNonMicEffect()) - .setSelfRing(cp.getSelfRing()); - }) - .sorted(Comparator.comparing(CpPairUserProfileCO::getCpValue).reversed()) + // 已在 cpList 中的 cpUserId(NORMAL),避免 dismissing 重复追加 + Set normalCpUserIds = cpList.stream() + .map(CpSimpleUserProfileCO::getCpUserId) + .collect(Collectors.toSet()); + + List result = new ArrayList<>(); + + // NORMAL CP(cache 数据,status 固定为 NORMAL) + cpList.stream() + .map(cp -> new CpPairUserProfileCO() + .setMeUserProfile(meUserProfileDTO) + .setCpUserProfile(getUserProfile(cp.getCpUserId())) + .setStatus("NORMAL") + .setCpValue(cp.getCpValue()) + .setDays(cp.getDays()) + .setFirstDay(cp.getFirstDay()) + .setCpLevel(cp.getCpLevel()) + .setNextLevelExp(cp.getNextLevelExp()) + .setLoveHeartLevel(cp.getLoveHeartLevel()) + .setMicEffectLevel(cp.getMicEffectLevel()) + .setProfileCardLevel(cp.getProfileCardLevel()) + .setGiftWindowLevel(cp.getGiftWindowLevel()) + .setHasNonMicEffect(cp.getHasNonMicEffect()) + .setSelfRing(cp.getSelfRing())) + .forEach(result::add); + + // DISMISSING CP(不在 NORMAL 列表中的才追加,避免重复) + dismissing.stream() + .filter(d -> !normalCpUserIds.contains(d.getCpUserId())) + .map(d -> new CpPairUserProfileCO() + .setMeUserProfile(meUserProfileDTO) + .setCpUserProfile(getUserProfile(d.getCpUserId())) + .setStatus("DISMISSING")) + .forEach(result::add); + + return result.stream() + .sorted(Comparator.comparing(CpPairUserProfileCO::getCpValue, + Comparator.nullsLast(Comparator.reverseOrder()))) .toList(); }