cp空间处理

(cherry picked from commit 7ca7b1a196041787d4e727b9df7480792a8ffa05)
This commit is contained in:
tianfeng 2026-04-29 18:55:45 +08:00
parent 0ff77e6605
commit 16c82d32b4

View File

@ -4,9 +4,9 @@ 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.clientobject.user.relation.cp.CoupleSpaceCO;
import com.red.circle.other.app.dto.cmd.user.relation.cp.CoupleSpaceQryCmd; 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.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.CpRingBackpack;
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord; 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.CpRingBackpackService;
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; 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.asserts.user.UserErrorCode;
import com.red.circle.other.inner.enums.material.PropsCommodityType; import com.red.circle.other.inner.enums.material.PropsCommodityType;
@ -30,7 +30,7 @@ import java.util.stream.Collectors;
public class CoupleSpaceQryExe { public class CoupleSpaceQryExe {
private final CpRelationshipCacheService cpRelationshipCacheService; private final CpRelationshipCacheService cpRelationshipCacheService;
private final PropsBackpackService propsBackpackService; private final CpRingBackpackService cpRingBackpackService;
private final PropsSourceRecordService propsSourceRecordService; private final PropsSourceRecordService propsSourceRecordService;
public CoupleSpaceCO execute(CoupleSpaceQryCmd cmd) { public CoupleSpaceCO execute(CoupleSpaceQryCmd cmd) {
@ -74,44 +74,23 @@ public class CoupleSpaceQryExe {
} }
private List<UserBackpackProps> buildSharedRingBackpack(Long meUserId, Long cpUserId) { private List<UserBackpackProps> buildSharedRingBackpack(Long meUserId, Long cpUserId) {
List<PropsBackpack> meBackpack = propsBackpackService List<CpRingBackpack> meRings = cpRingBackpackService.listNotExpired(meUserId, cpUserId);
.listNotExpiredByUserIdAndType(meUserId, PropsCommodityType.CP_RING); if (CollectionUtils.isEmpty(meRings)) {
if (CollectionUtils.isEmpty(meBackpack)) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<PropsBackpack> cpBackpack = propsBackpackService Set<Long> propsIds = meRings.stream().map(CpRingBackpack::getPropsId).collect(Collectors.toSet());
.listNotExpiredByUserIdAndType(cpUserId, PropsCommodityType.CP_RING);
if (CollectionUtils.isEmpty(cpBackpack)) {
return Collections.emptyList();
}
// 取双方共同拥有的 propsId 交集
Set<Long> cpPropsIds = cpBackpack.stream()
.map(PropsBackpack::getPropsId)
.collect(Collectors.toSet());
List<PropsBackpack> shared = meBackpack.stream()
.filter(b -> cpPropsIds.contains(b.getPropsId()))
.toList();
if (CollectionUtils.isEmpty(shared)) {
return Collections.emptyList();
}
// 批量查资源信息
Set<Long> propsIds = shared.stream().map(PropsBackpack::getPropsId).collect(Collectors.toSet());
Map<Long, PropsSourceRecord> sourceMap = propsSourceRecordService.mapByIds(propsIds); Map<Long, PropsSourceRecord> sourceMap = propsSourceRecordService.mapByIds(propsIds);
return shared.stream().map(backpack -> { return meRings.stream().map(ring -> {
PropsSourceRecord source = sourceMap.get(backpack.getPropsId()); PropsSourceRecord source = sourceMap.get(ring.getPropsId());
if (source == null) { if (source == null) {
return null; return null;
} }
return new UserBackpackProps() return new UserBackpackProps()
.setUserId(backpack.getUserId()) .setUserId(ring.getUserId())
.setType(backpack.getType()) .setType(PropsCommodityType.CP_RING.name())
.setExpireTime(backpack.getExpireTime()) .setExpireTime(ring.getExpireTime())
.setUseProps(backpack.getUseProps())
.setAllowGive(backpack.getAllowGive())
.setPropsResources(new PropsResources() .setPropsResources(new PropsResources()
.setId(source.getId()) .setId(source.getId())
.setType(source.getType()) .setType(source.getType())