From b48213df6754adf2e48677120d32dc3ba9b223e6 Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Fri, 24 Jul 2026 15:34:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=97=E9=93=BA=E4=B8=BB?= =?UTF-8?q?=E5=9B=BE=E4=BF=9D=E5=AD=98=E5=90=8E=E4=B8=8D=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/service/impl/ShopServiceImpl.java | 13 +++++++- .../service/impl/ShopServiceImplTest.java | 31 +++++++++++++++++++ docs/项目变更记录.md | 9 ++++++ memory/bugs.md | 12 +++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java index c7788b82..6da5e734 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImpl.java @@ -289,7 +289,18 @@ public class ShopServiceImpl extends ServiceImpl 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 coverImageFileIds = parseLongIds(shopDO.getCoverImageFileId(), ","); + List imageFileIds = parseLongIds(shopDO.getImageFileIds(), ","); + Set fileIds = new LinkedHashSet<>(); + fileIds.addAll(coverImageFileIds); + fileIds.addAll(imageFileIds); + Map fileMap = fileIds.isEmpty() + ? Collections.emptyMap() + : objectStorageFileService.getObjectStorageFileMapByIds(fileIds); + shopVO.setCoverImageUrls(resolveImageUrls(coverImageFileIds, fileMap)); + shopVO.setImageUrls(resolveImageUrls(imageFileIds, fileMap)); + return shopVO; } ); } diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java index 3a43d875..50ec5146 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/shop/service/impl/ShopServiceImplTest.java @@ -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(); diff --git a/docs/项目变更记录.md b/docs/项目变更记录.md index 293cc6e3..2265ccbf 100644 --- a/docs/项目变更记录.md +++ b/docs/项目变更记录.md @@ -475,3 +475,12 @@ - 数据库说明:本次不新增 SQL,不修改初始化 SQL,不需要执行数据库迁移。 - 影响范围:仅影响店铺档案编辑页底部操作区;不改变保存接口、表单字段、封面上传和其它页面按钮样式。 - 验证方式:执行店铺档案编辑页 JS 语法检查、WXSS BOM 检查、`git diff --check`、微信开发者工具 CLI `preview` 和 GitNexus staged 变更检测。 + +## 2026-07-24 店务小程序店铺主图保存后不回显修复 + +- 变更原因:店铺档案编辑页上传并保存主图后,店铺设置页重新读取店铺详情时 `coverImageUrls` 始终为空,导致页面继续显示旧封面或空封面。 +- 根本原因:`ShopServiceImpl.convertToVO()` 只回填了 `coverImageFileId`,没有把封面文件 ID 查询为可访问图片 URL;设置页依赖 `coverImageUrls` 渲染主图。 +- 处理方式:在 `ShopServiceImpl.getShopById()` 的详情缓存加载链路中批量查询封面和店铺图片文件,并使用现有对象存储 URL 转换逻辑填充 `ShopVO.coverImageUrls`、`imageUrls`;无图片 ID 时不发起对象存储查询。 +- 数据库说明:本次不新增 SQL,不修改初始化 SQL,不需要执行数据库迁移。 +- 影响范围:影响店铺详情回显及复用店铺详情的管理端/用户端读取链路;不改变图片上传接口、店铺图片数据库字段和保存 payload。 +- 验证方式:`ShopServiceImplTest` 定向测试 4/4 通过;店务小程序 JS 语法检查、WXSS/WXML BOM 检查、微信开发者工具 CLI `preview` 和 GitNexus staged 变更检测通过。 diff --git a/memory/bugs.md b/memory/bugs.md index a5679acf..66f8434d 100644 --- a/memory/bugs.md +++ b/memory/bugs.md @@ -575,3 +575,15 @@ 以后避免:小程序固定底部操作条从单按钮改成双按钮时,必须检查全局按钮宽度约束;提交前同时核对 WXML 是否有按钮、WXSS 是否让按钮处于可视范围。 验证方式:静态检查目标页 WXML 只保留保存按钮,WXSS 覆盖全局宽度;运行 JS 语法检查、WXSS BOM 检查、`git diff --check` 和微信开发者工具 CLI `preview`。 + +## 2026-07-24 店铺详情图片字段必须完成文件 ID 到 URL 的回显转换 + +问题:店铺档案页上传主图并保存后,店铺设置页重新进入仍显示旧主图或空封面。 + +原因:后端店铺详情 VO 只回填 `coverImageFileId`,没有根据对象存储文件 ID 填充前端实际渲染使用的 `coverImageUrls`;保存成功不等于图片回显链路完整。 + +处理方式:在店铺详情缓存加载链路中批量读取封面和店铺图片文件,并通过统一对象存储 URL 转换器回填 `coverImageUrls`、`imageUrls`;无文件 ID 时跳过对象存储查询。 + +以后避免:涉及图片设置时必须沿“上传 -> 保存文件 ID -> 清理详情缓存 -> 重新读取 -> URL 回显 -> 页面渲染”完整链路验证,不能只检查上传接口返回成功。 + +验证方式:服务层测试覆盖封面文件 ID 能转换为 URL;保存后重新加载店铺详情确认 URL 非空;同时执行前端编译和 GitNexus 变更检测。