fix: sync profile background update response

This commit is contained in:
hy001 2026-05-16 00:54:00 +08:00
parent ec7e1b6983
commit 3692e61b1c
2 changed files with 83 additions and 12 deletions

View File

@ -134,10 +134,10 @@ public class UpdateUserProfileCmdExe {
userProfileGateway.removeCacheAll(cmd.requiredReqUserId());
}
syncProperty(userProfile, cmd);
log.warn("cmd {},{}", cmd, userProfile);
updateUserProfile.setOriginSys(cmd.requireReqSysOrigin());
submitApproval(updateUserProfile, userProfile);
syncProperty(userProfile, updateUserProfile, cmd);
if (cmd.getCountryId() != null && cmd.getCountryId() > 0) {
// 更改国家 设置redis表示已修改 两年过期
redisService.setString("IS_UPDATE_COUNTRY:" + cmd.requiredReqUserId(), "1", 730, TimeUnit.DAYS);
@ -236,27 +236,43 @@ public class UpdateUserProfileCmdExe {
|| originalPhotos.stream().noneMatch(item -> Objects.equals(item.getUrl(), photo.getUrl()));
}
private void syncProperty(UserProfile oldProfile, UserProfileModifyCmd cmd) {
private void syncProperty(UserProfile oldProfile, UserProfile updateProfile,
UserProfileModifyCmd cmd) {
if (StringUtils.isNotBlank(cmd.getUserNickname())) {
oldProfile.setUserNickname(cmd.getUserNickname());
if (StringUtils.isNotBlank(updateProfile.getUserNickname())) {
oldProfile.setUserNickname(updateProfile.getUserNickname());
}
if (StringUtils.isNotBlank(cmd.getUserAvatar())) {
oldProfile.setUserAvatar(cmd.getUserAvatar());
if (StringUtils.isNotBlank(updateProfile.getUserAvatar())) {
oldProfile.setUserAvatar(updateProfile.getUserAvatar());
}
if (cmd.age() > 0) {
oldProfile.setAge(cmd.age());
oldProfile.setBornYear(cmd.getBornYear());
oldProfile.setBornMonth(cmd.getBornMonth());
oldProfile.setBornDay(cmd.getBornDay());
oldProfile.setAge(updateProfile.getAge());
oldProfile.setBornYear(updateProfile.getBornYear());
oldProfile.setBornMonth(updateProfile.getBornMonth());
oldProfile.setBornDay(updateProfile.getBornDay());
}
if (Objects.nonNull(cmd.getUserSex())) {
oldProfile.setUserSex(cmd.getUserSex());
if (Objects.nonNull(updateProfile.getUserSex())) {
oldProfile.setUserSex(updateProfile.getUserSex());
}
if (StringUtils.isNotBlank(updateProfile.getAutograph())) {
oldProfile.setAutograph(updateProfile.getAutograph());
}
if (StringUtils.isNotBlank(updateProfile.getHobby())) {
oldProfile.setHobby(updateProfile.getHobby());
}
if (cmd.getBackgroundPhotos() != null) {
oldProfile.setBackgroundPhotos(updateProfile.getBackgroundPhotos());
}
if (cmd.getPersonalPhotos() != null) {
oldProfile.setPersonalPhotos(updateProfile.getPersonalPhotos());
}
}
private void processAge(UserProfile userProfile) {

View File

@ -1,6 +1,7 @@
package com.red.circle.other.app.command.user;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -17,8 +18,11 @@ import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManager
import com.red.circle.other.infra.database.rds.entity.sys.SysCountryCode;
import com.red.circle.other.infra.database.rds.service.sys.SysCountryCodeService;
import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService;
import com.red.circle.other.inner.model.dto.user.PhotoItem;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.component.redis.service.RedisService;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@ -78,4 +82,55 @@ class UpdateUserProfileCmdExeTest {
assertEquals("Japan", persistedUpdate.getCountryName());
verify(roomProfileManagerService).updateUserCountry(1L, "JP", "Japan");
}
@Test
void execute_shouldSyncBackgroundPhotosToReturnedProfileWhenBackgroundChanges() {
OssServiceClient ossServiceClient = mock(OssServiceClient.class);
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
RedisService redisService = mock(RedisService.class);
BaseInfoService baseInfoService = mock(BaseInfoService.class);
SysCountryCodeService sysCountryCodeService = mock(SysCountryCodeService.class);
ProfileApprovalGateway profileApprovalGateway = mock(ProfileApprovalGateway.class);
UserProfileAppConvertor userProfileAppConvertor = mock(UserProfileAppConvertor.class);
RoomProfileManagerService roomProfileManagerService = mock(RoomProfileManagerService.class);
CpRelationshipCacheService cpRelationshipCacheService = mock(CpRelationshipCacheService.class);
UpdateUserProfileCmdExe exe = new UpdateUserProfileCmdExe(
ossServiceClient,
userProfileGateway,
redisService,
baseInfoService,
sysCountryCodeService,
profileApprovalGateway,
userProfileAppConvertor,
roomProfileManagerService,
cpRelationshipCacheService
);
String backgroundUrl = "https://example.com/profile-bg.jpg";
UserProfileModifyCmd cmd = new UserProfileModifyCmd();
cmd.setReqUserId(1L);
cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI"));
cmd.setBackgroundPhotos(Collections.singletonList(backgroundUrl));
UserProfile currentUserProfile = new UserProfile();
currentUserProfile.setId(1L);
UserProfile updateUserProfile = new UserProfile();
List<PhotoItem> updatedPhotos = Collections.singletonList(
new PhotoItem().setUrl(backgroundUrl)
);
when(userProfileGateway.getByUserId(1L)).thenReturn(currentUserProfile);
when(userProfileAppConvertor.toUserProfile(cmd)).thenReturn(updateUserProfile);
when(userProfileAppConvertor.toPhotoItems(cmd.getBackgroundPhotos())).thenReturn(updatedPhotos);
when(userProfileAppConvertor.toUserProfileDTO(currentUserProfile)).thenReturn(new UserProfileDTO());
exe.execute(cmd);
ArgumentCaptor<UserProfile> updateCaptor = ArgumentCaptor.forClass(UserProfile.class);
verify(userProfileGateway).updateSelectiveById(updateCaptor.capture());
assertEquals(updatedPhotos, updateCaptor.getValue().getBackgroundPhotos());
assertEquals(updatedPhotos, currentUserProfile.getBackgroundPhotos());
verify(profileApprovalGateway).submitApprovalBatch(anyList());
verify(userProfileAppConvertor).toUserProfileDTO(currentUserProfile);
}
}