修复预约详情删除图片回显
This commit is contained in:
+8
-2
@@ -368,7 +368,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
requireEditableAppointment(order);
|
||||
item.setAppointmentProductImageFileIds(trimToNull(dto.getImageFileIds()));
|
||||
item.setAppointmentProductImageFileIds(normalizeUpdatedImageFileIds(dto.getImageFileIds()));
|
||||
orderItemMapper.updateById(item);
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
@@ -1251,8 +1251,10 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
}
|
||||
|
||||
private String resolveAppointmentProductImageFileIds(OrderItemDO item, ProductDO product) {
|
||||
if (item != null && item.getAppointmentProductImageFileIds() != null) {
|
||||
return item.getAppointmentProductImageFileIds().trim();
|
||||
}
|
||||
return firstNonBlank(
|
||||
item == null ? null : item.getAppointmentProductImageFileIds(),
|
||||
product == null ? null : product.getImageFileIds(),
|
||||
""
|
||||
);
|
||||
@@ -1552,6 +1554,10 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return hasText(value) ? value.trim() : null;
|
||||
}
|
||||
|
||||
private String normalizeUpdatedImageFileIds(String value) {
|
||||
return value == null ? null : value.trim();
|
||||
}
|
||||
|
||||
private boolean hasText(String value) {
|
||||
return value != null && !value.trim().isEmpty();
|
||||
}
|
||||
|
||||
+40
@@ -560,6 +560,46 @@ class PlanningServiceImplTest {
|
||||
assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/601.jpg", "https://img.example/602.jpg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppointmentImagesShouldClearSnapshotImagesWithoutProductFallback() {
|
||||
UserDO manager = user(2, 8L);
|
||||
UserDO artist = user(3, 8L);
|
||||
artist.setId(20L);
|
||||
artist.setNickname("小王");
|
||||
UserDO customer = user(0, 8L);
|
||||
customer.setId(30L);
|
||||
customer.setNickname("王女士");
|
||||
ProductDO product = product(100L, 8L, "90分钟");
|
||||
product.setImageFileIds("501");
|
||||
OrderDO order = order(200L, 8L, 30L);
|
||||
OrderItemDO item = orderItem(300L, 200L, 100L, 20L, LocalDateTime.of(2026, 7, 21, 13, 0));
|
||||
item.setAppointmentProductTitle("手绘款");
|
||||
item.setAppointmentProductImageFileIds("501");
|
||||
PlanningAppointmentImageDTO dto = new PlanningAppointmentImageDTO();
|
||||
dto.setImageFileIds("");
|
||||
AppointmentReservationDO reservation = reservation(20L, 200L, 300L,
|
||||
LocalDateTime.of(2026, 7, 21, 13, 0),
|
||||
LocalDateTime.of(2026, 7, 21, 14, 0));
|
||||
reservation.setProductTitle("手绘款");
|
||||
|
||||
when(orderItemMapper.selectByIdForUpdate(300L)).thenReturn(item);
|
||||
when(orderMapper.selectById(200L)).thenReturn(order);
|
||||
when(orderItemMapper.selectById(300L)).thenReturn(item);
|
||||
when(productMapper.selectById(100L)).thenReturn(product);
|
||||
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
|
||||
when(userMapper.selectList(any())).thenReturn(List.of(artist));
|
||||
when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of());
|
||||
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
|
||||
|
||||
var appointment = planningService.updateAppointmentImages(manager, 300L, dto);
|
||||
|
||||
assertThat(item.getAppointmentProductImageFileIds()).isEmpty();
|
||||
org.mockito.Mockito.verify(orderItemMapper).updateById(item);
|
||||
assertThat(appointment.getProductImageFileIds()).isEmpty();
|
||||
assertThat(appointment.getProductImageUrls()).isEmpty();
|
||||
org.mockito.Mockito.verify(objectStorageFileService, org.mockito.Mockito.never()).getObjectStorageFileMapByIds(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppointmentPriceShouldPersistZeroAsPendingQuoteAmount() {
|
||||
UserDO manager = user(2, 8L);
|
||||
|
||||
@@ -344,8 +344,9 @@ Page({
|
||||
},
|
||||
|
||||
async persistAppointmentImages(fileIds, previewImageUrls) {
|
||||
const imageFileIds = fileIds.join(',')
|
||||
const result = await planningApi.updateAppointmentImages(this.data.id, {
|
||||
imageFileIds: fileIds.join(',')
|
||||
imageFileIds
|
||||
})
|
||||
markPlanningRefresh()
|
||||
if (isAppointmentResponse(result)) {
|
||||
@@ -353,8 +354,11 @@ Page({
|
||||
} else {
|
||||
await this.loadDetail()
|
||||
}
|
||||
if (Array.isArray(previewImageUrls) && previewImageUrls.length > 0) {
|
||||
this.setData({ productImageUrls: previewImageUrls })
|
||||
if (Array.isArray(previewImageUrls)) {
|
||||
this.setData({
|
||||
productImageUrls: previewImageUrls,
|
||||
productImageFileIds: imageFileIds
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -418,9 +422,9 @@ Page({
|
||||
const nextImageUrls = currentImageUrls.filter((item, itemIndex) => itemIndex !== index)
|
||||
this.setData({ imageUploading: true })
|
||||
await this.persistAppointmentImages(nextFileIds, nextImageUrls)
|
||||
wx.showToast({ title: '图片已保存' })
|
||||
wx.showToast({ title: '图片已删除' })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '图片保存失败', icon: 'none' })
|
||||
wx.showToast({ title: error.message || '图片删除失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ imageUploading: false })
|
||||
}
|
||||
|
||||
@@ -388,3 +388,15 @@
|
||||
以后避免:小程序写操作确认要区分破坏性/不可逆操作和用户主动选图上传;上传入口有系统选择器且取消不会改数据时,不额外加业务确认弹窗。
|
||||
|
||||
验证方式:检索预约详情页不再存在“确认添加作品图片到此预约?”文案;JS 语法检查和 `git diff --check` 通过,删除图片等破坏性入口仍保留 `confirmAction`。
|
||||
|
||||
## 2026-07-23 预约详情删除最后一张图片不能回退作品默认图
|
||||
|
||||
问题:店务小程序预约详情删除作品图片后提示“图片已保存”,并且删除最后一张后图片仍然显示在作品图片区域。
|
||||
|
||||
原因:前端删除成功复用了上传保存文案,且只在预览数组非空时覆盖本地图片;后端把空 `imageFileIds` 归一化为 `null`,详情回显又把 `null` 当作未设置并回退到作品默认图片。
|
||||
|
||||
处理方式:图片更新接口把空字符串保存为显式清空状态,详情回显区分 `null` 和空字符串;小程序删除成功提示改为“图片已删除”,并同步更新本地图片 URL 和文件 ID。
|
||||
|
||||
以后避免:有“默认值回退”的快照字段必须区分未设置和显式清空;删除最后一项时前端也要覆盖为空数组,不能只在数组非空时 setData。
|
||||
|
||||
验证方式:新增 `updateAppointmentImagesShouldClearSnapshotImagesWithoutProductFallback` 覆盖清空后不回退产品图;运行店务小程序 JS 语法检查、后端定向测试和 `git diff --check`。
|
||||
|
||||
Reference in New Issue
Block a user