用户列表新增cp字段

This commit is contained in:
tianfeng 2025-12-10 19:08:09 +08:00
parent 22690760fd
commit 37184400e0
8 changed files with 203 additions and 11 deletions

View File

@ -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;
}

View File

@ -111,6 +111,12 @@ public class UserProfileDTO implements Serializable {
*/
private String hobby;
/**
* CP列表
*/
private List<CpSimpleUserProfileCO> cpList;
/**
* 背景照片列表最多9张
*/

View File

@ -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<CpSimpleUserProfileCO> cpList;
/**
* 拥有的靓号.
*/

View File

@ -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<CpSimpleUserProfileCO> cpList;
/**
* 添加使用道具.
*/

View File

@ -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());
}

View File

@ -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;
/**
* <p>
@ -32,6 +34,14 @@ public interface CpValueService extends BaseService<CpValue> {
*/
BigDecimal getCpVal(Long id);
/**
* 批量获取cp值.
*
* @param ids id记录值集合
* @return Map<id, cpVal>
*/
Map<Long, BigDecimal> mapCpVal(Set<Long> ids);
/**
* 删除指定记录.
*/

View File

@ -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<CpValueDAO, CpValue> imp
.orElse(BigDecimal.ZERO);
}
@Override
public Map<Long, BigDecimal> mapCpVal(Set<Long> 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()

View File

@ -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<CpRelationship> cpRelationshipList = cpRelationshipService.getByUserId(userRunProfile.getId());
if (CollectionUtils.isEmpty(cpRelationshipList)) {
return;
}
// 批量获取CP用户信息
Set<Long> cpUserIds = cpRelationshipList.stream()
.map(CpRelationship::getCpUserId)
.collect(Collectors.toSet());
List<UserRunProfile> cpUserProfiles = userRunProfileService.listByIds(cpUserIds);
Map<Long, UserRunProfile> cpUserProfileMap = cpUserProfiles.stream()
.collect(Collectors.toMap(UserRunProfile::getId, Function.identity()));
// 批量获取CP值
Set<Long> cpValIds = cpRelationshipList.stream()
.map(CpRelationship::getCpValId)
.collect(Collectors.toSet());
Map<Long, BigDecimal> cpValueMap = cpValueService.mapCpVal(cpValIds);
// 组装CP列表
List<CpSimpleUserProfileCO> 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<Long, List<UseBadgeDTO>> mapUserUseBadgeEntity(String sysOrigin,
Set<Long> userIds) {
return Optional.ofNullable(this.listUserUseBadgeEntity(sysOrigin, userIds))