From 1303323df02b2fb52d1352128c6346d2eb3f1aff Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 22 Apr 2026 17:34:35 +0800 Subject: [PATCH] =?UTF-8?q?cp=E6=96=B0=E5=8A=9F=E8=83=BD-cp=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit a8a14ae4126c54e65a38985c2fa0a92bfa636960) --- .../CpRelationshipRestController.java | 15 +++ .../command/user/query/CoupleSpaceQryExe.java | 125 ++++++++++++++++++ .../relation/UserCpRelationServiceImpl.java | 8 ++ .../user/relation/cp/CoupleSpaceCO.java | 26 ++++ .../user/relation/cp/CoupleSpaceQryCmd.java | 23 ++++ .../user/relation/UserCpRelationService.java | 4 + 6 files changed, 201 insertions(+) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CoupleSpaceQryExe.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CoupleSpaceCO.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CoupleSpaceQryCmd.java diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java index d9114b6b..fbbba91a 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java @@ -4,7 +4,9 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.common.business.dto.cmd.UserIdCmd; import com.red.circle.framework.web.controller.BaseController; import com.red.circle.other.app.command.user.LoveLetterQueryCmdExe; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CoupleSpaceCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CoupleSpaceQryCmd; import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; import com.red.circle.other.domain.model.cp.loveletter.LoveLetterWallCO; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; @@ -146,4 +148,17 @@ public class CpRelationshipRestController extends BaseController { return loveLetterQueryCmdExe.queryLatestReceived(cmd); } + /** + * CP空间. + * + * @eo.name CP空间 + * @eo.url /couple-space + * @eo.method get + * @eo.request-type formdata + */ + @GetMapping("/couple-space") + public CoupleSpaceCO getCoupleSpace(@Validated CoupleSpaceQryCmd cmd) { + return userCpRelationService.getCoupleSpace(cmd); + } + } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CoupleSpaceQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CoupleSpaceQryExe.java new file mode 100644 index 00000000..5581b5ae --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CoupleSpaceQryExe.java @@ -0,0 +1,125 @@ +package com.red.circle.other.app.command.user.query; + +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CoupleSpaceCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CoupleSpaceQryCmd; +import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService; +import com.red.circle.other.infra.database.rds.entity.props.PropsBackpack; +import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord; +import com.red.circle.other.infra.database.rds.service.props.PropsBackpackService; +import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; +import com.red.circle.other.inner.asserts.user.UserErrorCode; +import com.red.circle.other.inner.enums.material.PropsCommodityType; +import com.red.circle.other.inner.model.dto.material.props.PropsResources; +import com.red.circle.other.inner.model.dto.material.props.UserBackpackProps; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; +import com.red.circle.tool.core.collection.CollectionUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * CP空间查询. + * + * @author tf + */ +@Component +@RequiredArgsConstructor +public class CoupleSpaceQryExe { + + private final CpRelationshipCacheService cpRelationshipCacheService; + private final PropsBackpackService propsBackpackService; + private final PropsSourceRecordService propsSourceRecordService; + + public CoupleSpaceCO execute(CoupleSpaceQryCmd cmd) { + List cpList = cpRelationshipCacheService.getUserCpList(cmd.requiredReqUserId()); + + CpSimpleUserProfileCO cpInfo = cpList.stream() + .filter(cp -> cp.getCpUserId().equals(cmd.getCpUserId())) + .findFirst() + .orElse(null); + ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, cpInfo); + + CoupleSpaceCO co = new CoupleSpaceCO(); + // 复制 CpSimpleUserProfileCO 所有字段 + co.setMeUserId(cpInfo.getMeUserId()); + co.setMeAccount(cpInfo.getMeAccount()); + co.setMeUserAvatar(cpInfo.getMeUserAvatar()); + co.setMeUserNickname(cpInfo.getMeUserNickname()); + co.setCpUserId(cpInfo.getCpUserId()); + co.setCpAccount(cpInfo.getCpAccount()); + co.setCpUserAvatar(cpInfo.getCpUserAvatar()); + co.setCpUserNickname(cpInfo.getCpUserNickname()); + co.setCpValId(cpInfo.getCpValId()); + co.setCpValue(cpInfo.getCpValue()); + co.setDays(cpInfo.getDays()); + co.setFirstDay(cpInfo.getFirstDay()); + co.setCreateTime(cpInfo.getCreateTime()); + co.setCpLevel(cpInfo.getCpLevel()); + co.setNextLevelExp(cpInfo.getNextLevelExp()); + co.setLoveHeartLevel(cpInfo.getLoveHeartLevel()); + co.setMicEffectLevel(cpInfo.getMicEffectLevel()); + co.setProfileCardLevel(cpInfo.getProfileCardLevel()); + co.setGiftWindowLevel(cpInfo.getGiftWindowLevel()); + co.setHasNonMicEffect(cpInfo.getHasNonMicEffect()); + co.setSelfRing(cpInfo.getSelfRing()); + + // 查双方共同拥有的 CP 戒指背包(取交集) + co.setRingBackpackList(buildSharedRingBackpack(cmd.requiredReqUserId(), cmd.getCpUserId())); + + return co; + } + + private List buildSharedRingBackpack(Long meUserId, Long cpUserId) { + List meBackpack = propsBackpackService + .listNotExpiredByUserIdAndType(meUserId, PropsCommodityType.CP_RING); + if (CollectionUtils.isEmpty(meBackpack)) { + return Collections.emptyList(); + } + + List cpBackpack = propsBackpackService + .listNotExpiredByUserIdAndType(cpUserId, PropsCommodityType.CP_RING); + if (CollectionUtils.isEmpty(cpBackpack)) { + return Collections.emptyList(); + } + + // 取双方共同拥有的 propsId 交集 + Set cpPropsIds = cpBackpack.stream() + .map(PropsBackpack::getPropsId) + .collect(Collectors.toSet()); + List shared = meBackpack.stream() + .filter(b -> cpPropsIds.contains(b.getPropsId())) + .toList(); + if (CollectionUtils.isEmpty(shared)) { + return Collections.emptyList(); + } + + // 批量查资源信息 + Set propsIds = shared.stream().map(PropsBackpack::getPropsId).collect(Collectors.toSet()); + Map sourceMap = propsSourceRecordService.mapByIds(propsIds); + + return shared.stream().map(backpack -> { + PropsSourceRecord source = sourceMap.get(backpack.getPropsId()); + if (source == null) { + return null; + } + return new UserBackpackProps() + .setUserId(backpack.getUserId()) + .setType(backpack.getType()) + .setExpireTime(backpack.getExpireTime()) + .setUseProps(backpack.getUseProps()) + .setAllowGive(backpack.getAllowGive()) + .setPropsResources(new PropsResources() + .setId(source.getId()) + .setType(source.getType()) + .setName(source.getName()) + .setCover(source.getCover()) + .setSourceUrl(source.getSourceUrl()) + .setAmount(source.getAmount()) + ); + }).filter(Objects::nonNull).toList(); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java index 5e280092..2126af47 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java @@ -8,15 +8,18 @@ import com.red.circle.other.app.command.user.LoveLetterQueryCmdExe; import com.red.circle.other.app.command.user.ProcessCpApplyCmd; import com.red.circle.other.app.command.user.SendCpApplyCmdExe; import com.red.circle.other.app.command.user.SendLoveLetterCmdExe; +import com.red.circle.other.app.command.user.query.CoupleSpaceQryExe; import com.red.circle.other.app.command.user.query.CpApplyIdQryExe; import com.red.circle.other.app.command.user.query.UserCpPairUserProfileQryExe; import com.red.circle.other.app.command.user.query.UserCpRelationQryExe; import com.red.circle.other.app.command.user.query.UserCpRelationQueryV4Exe; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CoupleSpaceCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinUserProfileCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; import com.red.circle.other.domain.model.cp.loveletter.LoveLetterWallCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CoupleSpaceQryCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; @@ -46,6 +49,7 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { private final DistributedLockUtil distributedLockUtil; private final SendLoveLetterCmdExe sendLoveLetterCmdExe; private final LoveLetterQueryCmdExe loveLetterQueryCmdExe; + private final CoupleSpaceQryExe coupleSpaceQryExe; @Override public CpUserProfileCO getCpUser(UserIdCmd cmd) { @@ -94,7 +98,11 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { distributedLockUtil.executeWithLock(key, () -> { sendLoveLetterCmdExe.execute(cmd); }); + } + @Override + public CoupleSpaceCO getCoupleSpace(CoupleSpaceQryCmd cmd) { + return coupleSpaceQryExe.execute(cmd); } } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CoupleSpaceCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CoupleSpaceCO.java new file mode 100644 index 00000000..dd0c5ec2 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CoupleSpaceCO.java @@ -0,0 +1,26 @@ +package com.red.circle.other.app.dto.clientobject.user.relation.cp; + +import com.red.circle.other.inner.model.dto.material.props.UserBackpackProps; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * CP空间页面数据. + * + * @author tf + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class CoupleSpaceCO extends CpSimpleUserProfileCO { + + /** + * 当前CP组双方共同拥有的戒指背包列表(双方都有才展示). + */ + private List ringBackpackList; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CoupleSpaceQryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CoupleSpaceQryCmd.java new file mode 100644 index 00000000..cb7be7d1 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CoupleSpaceQryCmd.java @@ -0,0 +1,23 @@ +package com.red.circle.other.app.dto.cmd.user.relation.cp; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * CP空间查询. + * + * @author tf + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CoupleSpaceQryCmd extends AppExtCommand { + + /** + * CP用户id. + */ + @NotNull(message = "cpUserId required.") + private Long cpUserId; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java index a1d8219f..55f08cd9 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java @@ -3,9 +3,11 @@ package com.red.circle.other.app.service.user.relation; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.common.business.dto.cmd.UserIdCmd; import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CoupleSpaceCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinUserProfileCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CoupleSpaceQryCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; @@ -36,4 +38,6 @@ public interface UserCpRelationService { void sendLoveLetter(SendLoveLetterCmd cmd); + CoupleSpaceCO getCoupleSpace(CoupleSpaceQryCmd cmd); + }