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.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.CpRingBackpack;
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.inner.asserts.user.UserErrorCode;
import com.red.circle.other.inner.enums.material.PropsCommodityType;
@ -30,7 +30,7 @@ import java.util.stream.Collectors;
public class CoupleSpaceQryExe {
private final CpRelationshipCacheService cpRelationshipCacheService;
private final PropsBackpackService propsBackpackService;
private final CpRingBackpackService cpRingBackpackService;
private final PropsSourceRecordService propsSourceRecordService;
public CoupleSpaceCO execute(CoupleSpaceQryCmd cmd) {
@ -74,44 +74,23 @@ public class CoupleSpaceQryExe {
}
private List<UserBackpackProps> buildSharedRingBackpack(Long meUserId, Long cpUserId) {
List<PropsBackpack> meBackpack = propsBackpackService
.listNotExpiredByUserIdAndType(meUserId, PropsCommodityType.CP_RING);
if (CollectionUtils.isEmpty(meBackpack)) {
List<CpRingBackpack> meRings = cpRingBackpackService.listNotExpired(meUserId, cpUserId);
if (CollectionUtils.isEmpty(meRings)) {
return Collections.emptyList();
}
List<PropsBackpack> cpBackpack = propsBackpackService
.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());
Set<Long> propsIds = meRings.stream().map(CpRingBackpack::getPropsId).collect(Collectors.toSet());
Map<Long, PropsSourceRecord> sourceMap = propsSourceRecordService.mapByIds(propsIds);
return shared.stream().map(backpack -> {
PropsSourceRecord source = sourceMap.get(backpack.getPropsId());
return meRings.stream().map(ring -> {
PropsSourceRecord source = sourceMap.get(ring.getPropsId());
if (source == null) {
return null;
}
return new UserBackpackProps()
.setUserId(backpack.getUserId())
.setType(backpack.getType())
.setExpireTime(backpack.getExpireTime())
.setUseProps(backpack.getUseProps())
.setAllowGive(backpack.getAllowGive())
.setUserId(ring.getUserId())
.setType(PropsCommodityType.CP_RING.name())
.setExpireTime(ring.getExpireTime())
.setPropsResources(new PropsResources()
.setId(source.getId())
.setType(source.getType())