From 37184400e06f191b7db6a29855b4ae52a6926cc3 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 10 Dec 2025 19:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9Ecp=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/user/CpSimpleUserProfileCO.java | 80 ++++++++++++++++++ .../inner/model/dto/user/UserProfileDTO.java | 6 ++ .../other/domain/model/user/UserProfile.java | 8 ++ .../entity/user/profile/UserRunProfile.java | 6 ++ .../impl/UserRunProfileServiceImpl.java | 4 + .../rds/service/user/user/CpValueService.java | 10 +++ .../user/user/impl/CpValueServiceImpl.java | 18 ++++ .../UserRunProfileTransportGatewayImpl.java | 82 ++++++++++++++++--- 8 files changed, 203 insertions(+), 11 deletions(-) create mode 100644 rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java new file mode 100644 index 00000000..46a1cb9c --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java @@ -0,0 +1,80 @@ +package com.red.circle.other.inner.model.dto.user; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * CP简化用户资料 + */ +@Data +@Accessors(chain = true) +public class CpSimpleUserProfileCO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long meUserId; + + /** + * 账号 + */ + private String meAccount; + + /** + * 用户头像 + */ + private String meUserAvatar; + + /** + * 用户昵称 + */ + private String meUserNickname; + + /** + * CP用户ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long cpUserId; + + /** + * CP账号 + */ + private String cpAccount; + + /** + * CP用户头像 + */ + private String cpUserAvatar; + + /** + * CP用户昵称 + */ + private String cpUserNickname; + + /** + * 心动值 + */ + private BigDecimal cpValue; + + /** + * 组建天数. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long days; + + /** + * 开始组件的日期 + */ + private String firstDay; + +} diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserProfileDTO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserProfileDTO.java index 075b3021..63e0da1b 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserProfileDTO.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/UserProfileDTO.java @@ -111,6 +111,12 @@ public class UserProfileDTO implements Serializable { */ private String hobby; + + /** + * CP列表 + */ + private List cpList; + /** * 背景照片列表(最多9张) */ diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/model/user/UserProfile.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/model/user/UserProfile.java index b2e86338..85c36d4f 100644 --- a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/model/user/UserProfile.java +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/model/user/UserProfile.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.red.circle.common.business.enums.AccountStatusEnum; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.other.inner.model.dto.user.props.UserUseBadgeDTO; @@ -150,6 +151,13 @@ public class UserProfile implements Serializable { */ private String hobby; + + /** + * CP列表 + */ + private List cpList; + + /** * 拥有的靓号. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserRunProfile.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserRunProfile.java index f13cab99..8cb40d95 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserRunProfile.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/entity/user/profile/UserRunProfile.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import com.red.circle.other.inner.model.dto.user.PhotoItem; import com.red.circle.other.inner.model.dto.material.UseBadgeDTO; import com.red.circle.other.inner.model.dto.material.UsePropsDTO; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; import java.io.Serial; @@ -187,6 +188,11 @@ public class UserRunProfile implements Serializable { */ private Timestamp firstRechargeEndTime; + /** + * CP列表 + */ + private List cpList; + /** * 添加使用道具. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/profile/impl/UserRunProfileServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/profile/impl/UserRunProfileServiceImpl.java index b3630d54..3500e4c8 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/profile/impl/UserRunProfileServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/user/profile/impl/UserRunProfileServiceImpl.java @@ -235,6 +235,10 @@ public class UserRunProfileServiceImpl implements UserRunProfileService { update.set("personalPhotos", userRunProfile.getPersonalPhotos()); } + if (CollectionUtils.isNotEmpty(userRunProfile.getCpList())) { + update.set("cpList", userRunProfile.getCpList()); + } + if (Objects.nonNull(userRunProfile.getOwnSpecialId())) { update.set("ownSpecialId", userRunProfile.getOwnSpecialId()); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpValueService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpValueService.java index 88592835..c32cff94 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpValueService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpValueService.java @@ -3,6 +3,8 @@ package com.red.circle.other.infra.database.rds.service.user.user; import com.red.circle.framework.mybatis.service.BaseService; import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; import java.math.BigDecimal; +import java.util.Map; +import java.util.Set; /** *

@@ -32,6 +34,14 @@ public interface CpValueService extends BaseService { */ BigDecimal getCpVal(Long id); + /** + * 批量获取cp值. + * + * @param ids id记录值集合 + * @return Map + */ + Map mapCpVal(Set ids); + /** * 删除指定记录. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpValueServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpValueServiceImpl.java index 563a96ab..90357aa2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpValueServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpValueServiceImpl.java @@ -5,9 +5,14 @@ import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; import com.red.circle.other.infra.database.rds.dao.user.user.CpValueDAO; import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.tool.core.collection.CollectionUtils; import java.math.BigDecimal; +import java.util.Collections; +import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.springframework.stereotype.Service; /** @@ -50,6 +55,19 @@ public class CpValueServiceImpl extends BaseServiceImpl imp .orElse(BigDecimal.ZERO); } + @Override + public Map mapCpVal(Set ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyMap(); + } + return query() + .select(CpValue::getId, CpValue::getCpVal) + .in(CpValue::getId, ids) + .list() + .stream() + .collect(Collectors.toMap(CpValue::getId, CpValue::getCpVal)); + } + @Override public void deleteById(Long id) { delete() diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java index d6eda6dd..55025fd2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/user/UserRunProfileTransportGatewayImpl.java @@ -3,9 +3,6 @@ package com.red.circle.other.infra.gateway.user; import com.alibaba.fastjson.JSON; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.red.circle.framework.dto.ResultResponse; -import com.red.circle.order.inner.endpoint.TotalRechargeClient; -import com.red.circle.order.inner.model.dto.UserTotalRechargeDTO; import com.red.circle.other.domain.gateway.props.PropsNobleVipGateway; import com.red.circle.other.domain.gateway.user.UserRunProfileTransportGateway; import com.red.circle.other.domain.model.user.UserProfile; @@ -23,6 +20,7 @@ import com.red.circle.other.infra.database.mongo.service.user.profile.UserSpecia import com.red.circle.other.infra.database.rds.entity.props.PropsBackpack; import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo; import com.red.circle.other.infra.database.rds.entity.user.user.OneTimeTask; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService; import com.red.circle.other.infra.database.rds.service.badge.BadgePictureConfigService; import com.red.circle.other.infra.database.rds.service.props.PropsBackpackService; @@ -31,6 +29,8 @@ import com.red.circle.other.infra.database.rds.service.props.RoomThemeUserBackpa import com.red.circle.other.infra.database.rds.service.props.RoomThemeUserCustomizeService; import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; import com.red.circle.other.infra.database.rds.service.user.user.OneTimeTaskService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.enums.material.BadgeBackpackExpireType; import com.red.circle.other.inner.enums.material.BadgeConfigTypeEnum; @@ -46,21 +46,18 @@ import com.red.circle.other.inner.model.dto.material.UseBadgeDTO; import com.red.circle.other.inner.model.dto.material.UsePropsDTO; import com.red.circle.other.inner.model.dto.material.props.PropsNobleVipAbilityDTO; import com.red.circle.other.inner.model.dto.user.PhotoItem; -import com.red.circle.other.inner.model.dto.user.UserOneTimeTaskDTO; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.DateUtils; import com.red.circle.tool.core.date.TimestampUtils; -import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; -import com.red.circle.tool.core.date.ZonedId; import com.red.circle.tool.core.json.JacksonUtils; +import java.math.BigDecimal; import java.sql.Timestamp; import java.time.Duration; import java.time.LocalDateTime; -import java.time.ZonedDateTime; -import java.time.temporal.TemporalUnit; +import java.time.ZoneId; import java.util.*; -import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -94,12 +91,13 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo private final RoomThemeUserBackpackService roomThemeUserBackpackService; private final PropsResourcesInfraConvertor propsResourcesInfraConvertor; private final RoomThemeUserCustomizeService roomThemeUserCustomizeService; - private final OneTimeTaskService oneTimeTaskService; + private final OneTimeTaskService oneTimeTaskService; + private final CpRelationshipService cpRelationshipService; + private final CpValueService cpValueService; @Override public UserProfile getByUserId(Long userId) { UserRunProfile userRunProfile = userRunProfileService.getById(userId); - userRunProfile = null; if (Objects.nonNull(userRunProfile)) { // 拥有靓号 UserSpecialId userSpecialId = userSpecialIdService.getByUserId(userId); @@ -281,6 +279,9 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo // 用户是否首充处理 fillUserFirstRecharge(newUserRunProfile); + // 填充CP列表数据 + fillUserCpList(newUserRunProfile); + newUserRunProfile.addUseProps(userUsePropsEntityMap.get(userBaseInfo.getId())); newUserRunProfile.addUseProps(userUseRoomTheme.get(userBaseInfo.getId())); newUserRunProfile.setOwnSpecialId(userSpecialIdMap.get(userBaseInfo.getId())); @@ -317,6 +318,65 @@ public class UserRunProfileTransportGatewayImpl implements UserRunProfileTranspo } } + /** + * 填充用户CP列表数据 + */ + private void fillUserCpList(UserRunProfile userRunProfile) { + try { + List cpRelationshipList = cpRelationshipService.getByUserId(userRunProfile.getId()); + if (CollectionUtils.isEmpty(cpRelationshipList)) { + return; + } + + // 批量获取CP用户信息 + Set cpUserIds = cpRelationshipList.stream() + .map(CpRelationship::getCpUserId) + .collect(Collectors.toSet()); + List cpUserProfiles = userRunProfileService.listByIds(cpUserIds); + Map cpUserProfileMap = cpUserProfiles.stream() + .collect(Collectors.toMap(UserRunProfile::getId, Function.identity())); + + // 批量获取CP值 + Set cpValIds = cpRelationshipList.stream() + .map(CpRelationship::getCpValId) + .collect(Collectors.toSet()); + Map cpValueMap = cpValueService.mapCpVal(cpValIds); + + // 组装CP列表 + List cpList = cpRelationshipList.stream() + .map(cpRelationship -> { + UserRunProfile cpUser = cpUserProfileMap.get(cpRelationship.getCpUserId()); + if (cpUser == null) { + return null; + } + BigDecimal cpValue = cpValueMap.getOrDefault(cpRelationship.getCpValId(), BigDecimal.ZERO); + Long days = DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now()); + String firstDay = cpRelationship.getCreateTime().toInstant() + .atZone(ZoneId.systemDefault()).toLocalDate().toString(); + + return new CpSimpleUserProfileCO() + .setMeUserId(userRunProfile.getId()) + .setMeAccount(userRunProfile.getAccount()) + .setMeUserAvatar(userRunProfile.getUserAvatar()) + .setMeUserNickname(userRunProfile.getUserNickname()) + .setCpUserId(cpUser.getId()) + .setCpAccount(cpUser.getAccount()) + .setCpUserAvatar(cpUser.getUserAvatar()) + .setCpUserNickname(cpUser.getUserNickname()) + .setCpValue(cpValue) + .setDays(days) + .setFirstDay(firstDay); + }) + .filter(Objects::nonNull) + .sorted(Comparator.comparing(CpSimpleUserProfileCO::getCpValue).reversed()) + .toList(); + + userRunProfile.setCpList(cpList); + } catch (Exception e) { + log.error("填充CP数据失败, userId={}", userRunProfile.getId(), e); + } + } + private Map> mapUserUseBadgeEntity(String sysOrigin, Set userIds) { return Optional.ofNullable(this.listUserUseBadgeEntity(sysOrigin, userIds))