From 3e7b40fe3cf4476edcb6a0b098aefd0afd241b53 Mon Sep 17 00:00:00 2001 From: xiaowang <2161656029@qq.com> Date: Thu, 23 Jul 2026 11:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E5=BC=8F=E6=9B=B4=E6=96=B0=E9=A2=84?= =?UTF-8?q?=E7=BA=A6=E5=9B=BE=E7=89=87=E5=BF=AB=E7=85=A7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../planning/service/impl/PlanningServiceImpl.java | 8 ++++++-- .../service/impl/PlanningServiceImplTest.java | 4 ++-- memory/bugs.md | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java index f77ce550..1b12614a 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -2,6 +2,7 @@ package com.xiaowang.jayucloud.core.modules.planning.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO; @@ -368,8 +369,11 @@ public class PlanningServiceImpl implements PlanningService { } OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId()); requireEditableAppointment(order); - item.setAppointmentProductImageFileIds(normalizeUpdatedImageFileIds(dto.getImageFileIds())); - orderItemMapper.updateById(item); + String imageFileIds = normalizeUpdatedImageFileIds(dto.getImageFileIds()); + item.setAppointmentProductImageFileIds(imageFileIds); + orderItemMapper.update(null, new UpdateWrapper() + .eq("id", item.getId()) + .set("appointment_product_image_file_ids", imageFileIds)); return getAppointment(currentUser, item.getId()); } diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java index a1e49c3c..324e7351 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -554,7 +554,7 @@ class PlanningServiceImplTest { var appointment = planningService.updateAppointmentImages(manager, 300L, dto); assertThat(item.getAppointmentProductImageFileIds()).isEqualTo("601,602"); - org.mockito.Mockito.verify(orderItemMapper).updateById(item); + org.mockito.Mockito.verify(orderItemMapper).update(org.mockito.ArgumentMatchers.isNull(), any()); assertThat(appointment.getProductTitle()).isEqualTo("手绘款"); assertThat(appointment.getProductImageFileIds()).isEqualTo("601,602"); assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/601.jpg", "https://img.example/602.jpg"); @@ -594,7 +594,7 @@ class PlanningServiceImplTest { var appointment = planningService.updateAppointmentImages(manager, 300L, dto); assertThat(item.getAppointmentProductImageFileIds()).isEmpty(); - org.mockito.Mockito.verify(orderItemMapper).updateById(item); + org.mockito.Mockito.verify(orderItemMapper).update(org.mockito.ArgumentMatchers.isNull(), any()); assertThat(appointment.getProductImageFileIds()).isEmpty(); assertThat(appointment.getProductImageUrls()).isEmpty(); org.mockito.Mockito.verify(objectStorageFileService, org.mockito.Mockito.never()).getObjectStorageFileMapByIds(any()); diff --git a/memory/bugs.md b/memory/bugs.md index 96294411..069fa301 100644 --- a/memory/bugs.md +++ b/memory/bugs.md @@ -400,3 +400,15 @@ 以后避免:有“默认值回退”的快照字段必须区分未设置和显式清空;删除最后一项时前端也要覆盖为空数组,不能只在数组非空时 setData。 验证方式:新增 `updateAppointmentImagesShouldClearSnapshotImagesWithoutProductFallback` 覆盖清空后不回退产品图;运行店务小程序 JS 语法检查、后端定向测试和 `git diff --check`。 + +## 2026-07-23 MyBatis-Plus LambdaUpdateWrapper 在单测里可能先触发 lambda cache + +问题:把预约图片更新改成 `LambdaUpdateWrapper` 后,规划服务单测直接报 `can not find lambda cache for this entity [OrderItemDO]`,还没走到业务断言就失败。 + +原因:当前单测上下文里 MyBatis-Plus 的 lambda 元数据缓存没有准备好;`LambdaUpdateWrapper` 需要先解析实体 lambda 元信息,而纯 mock 场景不一定具备这份缓存。 + +处理方式:显式更新改回列名版 `UpdateWrapper`,直接写 `id` 和 `appointment_product_image_file_ids`,避免依赖 lambda cache。 + +以后避免:在轻量单测或纯 mock 场景里新增 `LambdaUpdateWrapper` 时,先确认 lambda cache 已初始化;如果只是单表显式更新,优先用列名版 `UpdateWrapper`。 + +验证方式:`PlanningServiceImplTest#updateAppointmentImagesShouldPersistSnapshotImageIdsAndReturnUrls` 和 `...ShouldClearSnapshotImagesWithoutProductFallback` 通过,且不会再抛 `can not find lambda cache`。