显式更新预约图片快照字段
This commit is contained in:
+6
-2
@@ -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.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
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.PlanningAppointmentCreateDTO;
|
||||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO;
|
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO;
|
||||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||||
@@ -368,8 +369,11 @@ public class PlanningServiceImpl implements PlanningService {
|
|||||||
}
|
}
|
||||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||||
requireEditableAppointment(order);
|
requireEditableAppointment(order);
|
||||||
item.setAppointmentProductImageFileIds(normalizeUpdatedImageFileIds(dto.getImageFileIds()));
|
String imageFileIds = normalizeUpdatedImageFileIds(dto.getImageFileIds());
|
||||||
orderItemMapper.updateById(item);
|
item.setAppointmentProductImageFileIds(imageFileIds);
|
||||||
|
orderItemMapper.update(null, new UpdateWrapper<OrderItemDO>()
|
||||||
|
.eq("id", item.getId())
|
||||||
|
.set("appointment_product_image_file_ids", imageFileIds));
|
||||||
return getAppointment(currentUser, item.getId());
|
return getAppointment(currentUser, item.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -554,7 +554,7 @@ class PlanningServiceImplTest {
|
|||||||
var appointment = planningService.updateAppointmentImages(manager, 300L, dto);
|
var appointment = planningService.updateAppointmentImages(manager, 300L, dto);
|
||||||
|
|
||||||
assertThat(item.getAppointmentProductImageFileIds()).isEqualTo("601,602");
|
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.getProductTitle()).isEqualTo("手绘款");
|
||||||
assertThat(appointment.getProductImageFileIds()).isEqualTo("601,602");
|
assertThat(appointment.getProductImageFileIds()).isEqualTo("601,602");
|
||||||
assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/601.jpg", "https://img.example/602.jpg");
|
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);
|
var appointment = planningService.updateAppointmentImages(manager, 300L, dto);
|
||||||
|
|
||||||
assertThat(item.getAppointmentProductImageFileIds()).isEmpty();
|
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.getProductImageFileIds()).isEmpty();
|
||||||
assertThat(appointment.getProductImageUrls()).isEmpty();
|
assertThat(appointment.getProductImageUrls()).isEmpty();
|
||||||
org.mockito.Mockito.verify(objectStorageFileService, org.mockito.Mockito.never()).getObjectStorageFileMapByIds(any());
|
org.mockito.Mockito.verify(objectStorageFileService, org.mockito.Mockito.never()).getObjectStorageFileMapByIds(any());
|
||||||
|
|||||||
@@ -400,3 +400,15 @@
|
|||||||
以后避免:有“默认值回退”的快照字段必须区分未设置和显式清空;删除最后一项时前端也要覆盖为空数组,不能只在数组非空时 setData。
|
以后避免:有“默认值回退”的快照字段必须区分未设置和显式清空;删除最后一项时前端也要覆盖为空数组,不能只在数组非空时 setData。
|
||||||
|
|
||||||
验证方式:新增 `updateAppointmentImagesShouldClearSnapshotImagesWithoutProductFallback` 覆盖清空后不回退产品图;运行店务小程序 JS 语法检查、后端定向测试和 `git diff --check`。
|
验证方式:新增 `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`。
|
||||||
|
|||||||
Reference in New Issue
Block a user