修复店铺主图保存后不回显

This commit is contained in:
2026-07-24 15:34:43 +08:00
parent cd05727b98
commit b48213df67
4 changed files with 64 additions and 1 deletions
@@ -289,7 +289,18 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
* @param shopDO parameter `shopDO` supplied by the caller
* @return return result consumed by the caller or returned to the frontend
*/
return convertToVO(shopDO);
ShopVO shopVO = convertToVO(shopDO);
List<Long> coverImageFileIds = parseLongIds(shopDO.getCoverImageFileId(), ",");
List<Long> imageFileIds = parseLongIds(shopDO.getImageFileIds(), ",");
Set<Long> fileIds = new LinkedHashSet<>();
fileIds.addAll(coverImageFileIds);
fileIds.addAll(imageFileIds);
Map<Long, ObjectStorageFileVO> fileMap = fileIds.isEmpty()
? Collections.emptyMap()
: objectStorageFileService.getObjectStorageFileMapByIds(fileIds);
shopVO.setCoverImageUrls(resolveImageUrls(coverImageFileIds, fileMap));
shopVO.setImageUrls(resolveImageUrls(imageFileIds, fileMap));
return shopVO;
}
);
}
@@ -21,6 +21,7 @@ import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.core.modules.shop.support.UserShopBindingSupport;
import com.xiaowang.jayucloud.core.support.cache.MultiLevelCacheService;
import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopVO;
import com.xiaowang.jayucloud.core.modules.shop.vo.ShopTrustProfileVO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -28,6 +29,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -136,6 +138,35 @@ class ShopServiceImplTest {
verify(shopMapper, never()).updateById(disabledShop);
}
@Test
void getShopByIdShouldResolveCoverImageUrls() {
ShopDO shop = new ShopDO();
shop.setId(9L);
shop.setShopName("Yumi Test Shop");
shop.setCoverImageFileId("100");
shop.setIsDelete(0);
when(shopMapper.selectById(9L)).thenReturn(shop);
when(appCacheProperties.getShop()).thenReturn(new AppCacheProperties.CacheSpec(60, 120));
when(multiLevelCacheService.getOrLoad(
anyString(),
any(Duration.class),
any(Duration.class),
any(),
any()
)).thenAnswer(invocation -> ((java.util.function.Supplier<?>) invocation.getArgument(4)).get());
ObjectStorageFileVO cover = new ObjectStorageFileVO();
cover.setId(100L);
cover.setFileUrl("https://img.test/cover.jpg");
when(objectStorageFileService.getObjectStorageFileMapByIds(any()))
.thenReturn(Map.of(100L, cover));
ShopVO shopVO = service.getShopById(9L);
assertThat(shopVO.getCoverImageUrls()).containsExactly("https://img.test/cover.jpg");
verify(objectStorageFileService).getObjectStorageFileMapByIds(any());
}
@Test
void getShopTrustProfileAggregatesPublicTrustDataWithoutContactPhone() {
ShopDO shop = new ShopDO();