From e9c2404b2b5f55aaa58b889a048e7d9d6115d445 Mon Sep 17 00:00:00 2001 From: msh-agent Date: Sun, 3 May 2026 01:19:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(food-encyclopedia):=20=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E9=A3=9F=E7=89=A9=E5=9B=BE=E7=89=87=E8=BE=93=E5=87=BA=E5=BD=92?= =?UTF-8?q?=E4=B8=80=E5=8C=96=EF=BC=8C=E4=BF=AE=E5=A4=8Duniapp=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9B=BE=E7=89=87=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ToolFoodServiceImpl 新增 normalizeImageForOutput:定位 "crmebimage/" 片段,剥掉前面所有 host 前缀,再用 prefixImage 拼上单层 cdnUrl - 应用于 search / getDetail / getSimilar 三处 image 输出 - 处理三类历史脏数据:相对路径、双层 host 前缀、AI OSS URL(原样透传) Co-Authored-By: Claude Opus 4.7 (1M context) --- .../impl/tool/ToolFoodServiceImpl.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/msh_crmeb_22/crmeb-service/src/main/java/com/zbkj/service/service/impl/tool/ToolFoodServiceImpl.java b/msh_crmeb_22/crmeb-service/src/main/java/com/zbkj/service/service/impl/tool/ToolFoodServiceImpl.java index 914292b..80ab819 100644 --- a/msh_crmeb_22/crmeb-service/src/main/java/com/zbkj/service/service/impl/tool/ToolFoodServiceImpl.java +++ b/msh_crmeb_22/crmeb-service/src/main/java/com/zbkj/service/service/impl/tool/ToolFoodServiceImpl.java @@ -7,6 +7,7 @@ import com.zbkj.common.exception.CrmebException; import com.zbkj.common.model.tool.V2Food; import com.zbkj.common.request.PageParamRequest; import com.zbkj.service.dao.tool.V2FoodDao; +import com.zbkj.service.service.SystemAttachmentService; import com.zbkj.service.service.tool.DishImageService; import com.zbkj.service.service.tool.ToolFoodService; import lombok.extern.slf4j.Slf4j; @@ -34,6 +35,29 @@ public class ToolFoodServiceImpl implements ToolFoodService { @Resource private DishImageService dishImageService; + @Resource + private SystemAttachmentService systemAttachmentService; + + /** + * 输出端图片归一化: + * - 空值原样返回 + * - data:/blob: 原样返回 + * - 历史脏数据中包含多层 host 前缀的 "https://h//https://h//crmebimage/..." → 仅保留首段 cdnUrl + 'crmebimage/...' + * - 相对路径 "crmebimage/..." → 拼上 cdnUrl + * - AI 生成 OSS URL(不含 crmebimage/,如 https://uthink.../foods/...)原样返回 + */ + private String normalizeImageForOutput(String image) { + if (StrUtil.isBlank(image)) return image; + String s = image.trim(); + if (s.startsWith("data:") || s.startsWith("blob:")) return s; + int idx = s.indexOf("crmebimage/"); + if (idx >= 0) { + // 剥掉 crmebimage/ 之前的所有内容(包含 http(s)://host// 等),再交由 prefixImage 拼上单层 cdnUrl + return systemAttachmentService.prefixImage(s.substring(idx)); + } + return s; + } + /** * 搜索食物 * @param pageParamRequest 分页参数 @@ -63,7 +87,7 @@ public class ToolFoodServiceImpl implements ToolFoodService { Map map = new HashMap<>(); map.put("id", food.getFoodId()); map.put("name", food.getName()); - map.put("image", food.getImage()); + map.put("image", normalizeImageForOutput(food.getImage())); map.put("category", food.getCategory()); map.put("energy", food.getEnergy()); map.put("protein", food.getProtein()); @@ -108,7 +132,7 @@ public class ToolFoodServiceImpl implements ToolFoodService { Map map = new HashMap<>(); map.put("id", food.getFoodId()); map.put("name", food.getName()); - map.put("image", food.getImage()); + map.put("image", normalizeImageForOutput(food.getImage())); map.put("category", food.getCategory()); map.put("energy", food.getEnergy()); map.put("protein", food.getProtein()); @@ -153,7 +177,7 @@ public class ToolFoodServiceImpl implements ToolFoodService { Map map = new HashMap<>(); map.put("id", item.getFoodId()); map.put("name", item.getName()); - map.put("image", item.getImage()); + map.put("image", normalizeImageForOutput(item.getImage())); similarList.add(map); } result.put("list", similarList);