优化店务预约作品快照与图片维护

This commit is contained in:
2026-07-21 16:26:56 +08:00
parent 7415b6b451
commit 1c6dabe7d9
20 changed files with 873 additions and 161 deletions
@@ -17,6 +17,7 @@ import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleVO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO;
import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerUpdateDTO;
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;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
@@ -112,9 +113,20 @@ public class AdminManagerController {
@PathVariable Long orderItemId,
@RequestBody PlanningAppointmentMoveDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
requireManagerOperator(currentUser);
return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto));
}
@PutMapping("/planning/appointments/{orderItemId}/images")
@RequirePermission("order:process")
@OperationGuard(action = "manager-planning-update-appointment-images", ttlSeconds = 10, message = "预约图片保存处理中,请勿重复提交")
public Result<PlanningAppointmentVO> updateAppointmentImages(HttpServletRequest request,
@PathVariable Long orderItemId,
@RequestBody PlanningAppointmentImageDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
return Result.success(planningService.updateAppointmentImages(currentUser, orderItemId, dto));
}
@PutMapping("/planning/appointments/{orderId}/status")
@RequirePermission("order:process")
@OperationGuard(action = "manager-planning-update-appointment-status", ttlSeconds = 10, message = "预约状态处理中,请勿重复提交")
@@ -432,6 +444,13 @@ public class AdminManagerController {
}
}
private void requireManagerOperator(UserDO currentUser) {
if (Integer.valueOf(2).equals(currentUser.getType())) {
return;
}
throw new RuntimeException("只有店长可以改派预约");
}
private boolean hasEmployeeUserBasicChanges(NailArtistInfoDTO dto) {
return dto.getNickname() != null
|| dto.getAvatar() != null
@@ -37,6 +37,11 @@ public class OrderItemDO extends BaseEntity {
private Boolean depositPaid;
private Boolean needRemoval;
private Boolean fromMeituan;
private String appointmentProductTitle;
private String appointmentProductDescription;
private String appointmentProductTags;
private String appointmentProductPrecautions;
private String appointmentProductImageFileIds;
/**
* Field `artistId` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
*/
@@ -79,6 +79,7 @@ public class AdminPlanningController {
@PathVariable Long orderItemId,
@RequestBody PlanningAppointmentMoveDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
requireManagerOperator(currentUser);
return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto));
}
@@ -91,4 +92,11 @@ public class AdminPlanningController {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
return Result.success(planningService.updateStatus(currentUser, orderId, dto));
}
private void requireManagerOperator(UserDO currentUser) {
if (Integer.valueOf(2).equals(currentUser.getType())) {
return;
}
throw new RuntimeException("只有店长可以改派预约");
}
}
@@ -0,0 +1,8 @@
package com.xiaowang.jayucloud.core.modules.planning.dto;
import lombok.Data;
@Data
public class PlanningAppointmentImageDTO {
private String imageFileIds;
}
@@ -1,6 +1,7 @@
package com.xiaowang.jayucloud.core.modules.planning.service;
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;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
@@ -21,5 +22,7 @@ public interface PlanningService {
PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto);
PlanningAppointmentVO updateAppointmentImages(UserDO currentUser, Long orderItemId, PlanningAppointmentImageDTO dto);
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
}
@@ -2,6 +2,7 @@ package com.xiaowang.jayucloud.core.modules.planning.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
@@ -10,6 +11,9 @@ import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleException
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO;
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO;
import com.xiaowang.jayucloud.core.modules.artist.entity.NailArtistInfoDO;
import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO;
import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO;
import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO;
@@ -57,6 +61,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -75,7 +80,6 @@ public class PlanningServiceImpl implements PlanningService {
private static final int MONTH_AVAILABLE_MINUTES = 90;
private static final String RESERVATION_PENDING_QUOTE = "PENDING_QUOTE";
private static final String RESERVATION_CONFIRMED = "CONFIRMED";
private static final String PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT = "MANAGER_APPOINTMENT";
private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW";
private static final List<String> ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_PENDING_QUOTE, RESERVATION_CONFIRMED);
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -93,6 +97,8 @@ public class PlanningServiceImpl implements PlanningService {
private final OrderMapper orderMapper;
private final OrderItemMapper orderItemMapper;
private final ProductMapper productMapper;
private final ObjectStorageFileService objectStorageFileService;
private final ObjectStorageUrlSupport objectStorageUrlSupport;
private final ShopMapper shopMapper;
private final ShopScheduleExceptionMapper shopScheduleExceptionMapper;
private final AppointmentCapacityService appointmentCapacityService;
@@ -192,7 +198,7 @@ public class PlanningServiceImpl implements PlanningService {
OrderItemDO item = new OrderItemDO();
item.setOrderId(order.getId());
item.setProductId(product.getId());
item.setProductId(product == null ? null : product.getId());
item.setQuantity(quantity);
item.setPrice(unitPrice);
item.setArtistId(artist.getId());
@@ -200,6 +206,7 @@ public class PlanningServiceImpl implements PlanningService {
item.setDepositPaid(Boolean.TRUE.equals(dto.getDepositPaid()));
item.setNeedRemoval(Boolean.TRUE.equals(dto.getNeedRemoval()));
item.setFromMeituan(Boolean.TRUE.equals(dto.getFromMeituan()));
applyAppointmentProductSnapshot(item, product, dto);
item.setIsDelete(0);
orderItemMapper.insert(item);
@@ -208,7 +215,7 @@ public class PlanningServiceImpl implements PlanningService {
item.getId(),
shopId,
artist.getId(),
product.getTitle(),
resolveAppointmentProductTitle(product, dto),
startTime,
endTime,
trimToNull(dto.getClientRequestId())
@@ -260,7 +267,9 @@ public class PlanningServiceImpl implements PlanningService {
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
ensureWithinBusinessHours(order.getShopId(), startTime, endTime);
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
BigDecimal unitPrice = product == null
? resolveAppointmentUnitPrice(null, dto)
: product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
appointmentCapacityService.moveReservationForArtistChange(
@@ -269,7 +278,7 @@ public class PlanningServiceImpl implements PlanningService {
order.getShopId(),
item.getArtistId(),
artist.getId(),
product.getTitle(),
resolveAppointmentProductTitle(product, dto),
startTime,
endTime
);
@@ -282,11 +291,12 @@ public class PlanningServiceImpl implements PlanningService {
order.setPayAmount(amount);
orderMapper.updateById(order);
item.setProductId(product.getId());
item.setProductId(product == null ? null : product.getId());
item.setQuantity(quantity);
item.setPrice(unitPrice);
item.setArtistId(artist.getId());
item.setAppointmentTime(startTime);
applyAppointmentProductSnapshot(item, product, dto);
if (dto.getDepositPaid() != null) {
item.setDepositPaid(dto.getDepositPaid());
}
@@ -312,7 +322,7 @@ public class PlanningServiceImpl implements PlanningService {
}
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
requireEditableAppointment(order);
ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId());
ProductDO product = item.getProductId() == null ? null : requireActiveProduct(item.getProductId(), order.getShopId());
Long targetArtistId = dto.getArtistId() == null ? item.getArtistId() : dto.getArtistId();
UserDO artist = requireActiveArtist(targetArtistId, order.getShopId());
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) *
@@ -332,7 +342,7 @@ public class PlanningServiceImpl implements PlanningService {
order.getShopId(),
item.getArtistId(),
artist.getId(),
product.getTitle(),
resolveAppointmentDisplayTitle(null, item, product),
startTime,
endTime
);
@@ -343,6 +353,23 @@ public class PlanningServiceImpl implements PlanningService {
return getAppointment(currentUser, item.getId());
}
@Override
@Transactional
public PlanningAppointmentVO updateAppointmentImages(UserDO currentUser, Long orderItemId, PlanningAppointmentImageDTO dto) {
if (orderItemId == null || dto == null) {
throw new RuntimeException("预约图片信息不能为空");
}
OrderItemDO item = orderItemMapper.selectByIdForUpdate(orderItemId);
if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) {
throw new RuntimeException("预约不存在");
}
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
requireEditableAppointment(order);
item.setAppointmentProductImageFileIds(trimToNull(dto.getImageFileIds()));
orderItemMapper.updateById(item);
return getAppointment(currentUser, item.getId());
}
@Override
@Transactional
public Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto) {
@@ -670,9 +697,7 @@ public class PlanningServiceImpl implements PlanningService {
vo.setCustomerName(resolveAppointmentCustomerName(order, customer));
vo.setCustomerPhone(customer == null ? null : firstNonBlank(customer.getContactPhone(), customer.getPhone(), ""));
vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId());
vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle())
? reservation.getProductTitle()
: product == null ? "预约作品" : product.getTitle());
vo.setProductTitle(resolveAppointmentDisplayTitle(reservation, item, product));
vo.setArtistId(artistId);
vo.setArtistName(artist == null ? "未分配" : artist.getName());
vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor());
@@ -693,6 +718,11 @@ public class PlanningServiceImpl implements PlanningService {
vo.setConflictReason(resolveAppointmentConflictReason(occupancyStatus));
vo.setAmount(order == null ? null : order.getActualAmount());
vo.setRemark(order == null ? null : order.getCustomerRemark());
vo.setProductDescription(resolveAppointmentProductDescription(item, product));
vo.setProductTags(resolveAppointmentProductTags(item, product));
vo.setProductPrecautions(resolveAppointmentProductPrecautions(item, product));
vo.setProductImageFileIds(resolveAppointmentProductImageFileIds(item, product));
vo.setProductImageUrls(resolveImageUrls(parseLongTokens(vo.getProductImageFileIds())));
return vo;
}
@@ -857,10 +887,11 @@ public class PlanningServiceImpl implements PlanningService {
if (dto.getProductId() != null) {
return requireActiveProduct(dto.getProductId(), shopId);
}
return createManualAppointmentProduct(dto, shopId);
requireManualAppointmentProduct(dto);
return null;
}
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
private void requireManualAppointmentProduct(PlanningAppointmentCreateDTO dto) {
String title = trimToNull(dto.getManualProductTitle());
if (!hasText(title)) {
throw new RuntimeException("请选择预约作品或填写手动作品名称");
@@ -869,30 +900,11 @@ public class PlanningServiceImpl implements PlanningService {
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("手动作品价格不能小于0");
}
int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes());
ProductDO product = new ProductDO();
product.setShopId(shopId);
product.setTitle(title);
product.setDescription(trimToNull(dto.getManualProductDescription()));
product.setTags(trimToNull(dto.getManualProductTags()));
product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience()));
product.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
product.setPrice(price);
product.setLikeCount(0);
product.setCollectCount(0);
product.setApproximateDuration(durationMinutes + "分钟");
product.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId()));
product.setFrontVisible(0);
product.setSourceType(PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT);
product.setIsDelete(0);
productMapper.insert(product);
return product;
}
private BigDecimal resolveAppointmentUnitPrice(ProductDO product, PlanningAppointmentCreateDTO dto) {
if (dto.getManualProductPrice() == null) {
return product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
return product == null || product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
}
if (dto.getManualProductPrice().compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("本次价格不能小于0");
@@ -900,6 +912,30 @@ public class PlanningServiceImpl implements PlanningService {
return dto.getManualProductPrice();
}
private void applyAppointmentProductSnapshot(OrderItemDO item, ProductDO product, PlanningAppointmentCreateDTO dto) {
item.setAppointmentProductTitle(resolveAppointmentProductTitle(product, dto));
item.setAppointmentProductDescription(product == null
? trimToNull(dto.getManualProductDescription())
: trimToNull(product.getDescription()));
item.setAppointmentProductTags(product == null
? trimToNull(dto.getManualProductTags())
: trimToNull(product.getTags()));
item.setAppointmentProductPrecautions(product == null
? trimToNull(dto.getManualProductPrecautions())
: trimToNull(product.getPrecautions()));
item.setAppointmentProductImageFileIds(product == null
? trimToNull(dto.getManualProductImageFileIds())
: trimToNull(product.getImageFileIds()));
}
private String resolveAppointmentProductTitle(ProductDO product, PlanningAppointmentCreateDTO dto) {
return firstNonBlank(
dto == null ? null : dto.getManualProductTitle(),
product == null ? null : product.getTitle(),
"预约作品"
);
}
private int requireAppointmentDuration(Integer durationMinutes) {
if (durationMinutes == null || durationMinutes <= 0) {
throw new RuntimeException("预约时长不能为空且必须大于0分钟");
@@ -984,6 +1020,47 @@ public class PlanningServiceImpl implements PlanningService {
);
}
private String resolveAppointmentDisplayTitle(AppointmentReservationDO reservation, OrderItemDO item, ProductDO product) {
return firstNonBlank(
reservation == null ? null : reservation.getProductTitle(),
item == null ? null : item.getAppointmentProductTitle(),
product == null ? null : product.getTitle(),
"预约作品"
);
}
private String resolveAppointmentProductDescription(OrderItemDO item, ProductDO product) {
return firstNonBlank(
item == null ? null : item.getAppointmentProductDescription(),
product == null ? null : product.getDescription(),
""
);
}
private String resolveAppointmentProductTags(OrderItemDO item, ProductDO product) {
return firstNonBlank(
item == null ? null : item.getAppointmentProductTags(),
product == null ? null : product.getTags(),
""
);
}
private String resolveAppointmentProductPrecautions(OrderItemDO item, ProductDO product) {
return firstNonBlank(
item == null ? null : item.getAppointmentProductPrecautions(),
product == null ? null : product.getPrecautions(),
""
);
}
private String resolveAppointmentProductImageFileIds(OrderItemDO item, ProductDO product) {
return firstNonBlank(
item == null ? null : item.getAppointmentProductImageFileIds(),
product == null ? null : product.getImageFileIds(),
""
);
}
private OrderDO requireAccessibleOrder(UserDO currentUser, Long orderId) {
OrderDO order = orderMapper.selectById(orderId);
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
@@ -1176,6 +1253,45 @@ public class PlanningServiceImpl implements PlanningService {
return list == null ? List.of() : list;
}
private List<Long> parseLongTokens(String value) {
if (!hasText(value)) {
return List.of();
}
List<Long> result = new ArrayList<>();
String[] tokens = value.split(",");
for (int index = 0; index < tokens.length; index += 1) {
String token = tokens[index].trim();
if (token.isEmpty()) {
continue;
}
try {
result.add(Long.parseLong(token));
} catch (NumberFormatException e) {
throw new RuntimeException("预约作品图片文件ID格式不正确:" + token);
}
}
return result;
}
private List<String> resolveImageUrls(List<Long> fileIds) {
if (fileIds == null || fileIds.isEmpty()) {
return List.of();
}
Map<Long, ObjectStorageFileVO> fileMap = objectStorageFileService.getObjectStorageFileMapByIds(new LinkedHashSet<>(fileIds));
List<String> urls = new ArrayList<>();
for (Long fileId : fileIds) {
ObjectStorageFileVO file = fileMap.get(fileId);
if (file == null) {
continue;
}
String imageUrl = objectStorageUrlSupport.toAccessibleUrl(file);
if (hasText(imageUrl)) {
urls.add(imageUrl);
}
}
return urls;
}
private String firstNonBlank(String... values) {
for (String value : values) {
if (hasText(value)) {
@@ -3,6 +3,8 @@ package com.xiaowang.jayucloud.core.modules.planning.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Data
public class PlanningAppointmentVO {
@@ -33,4 +35,9 @@ public class PlanningAppointmentVO {
private String conflictReason;
private BigDecimal amount;
private String remark;
private String productDescription;
private String productTags;
private String productPrecautions;
private String productImageFileIds;
private List<String> productImageUrls = new ArrayList<>();
}
@@ -6,12 +6,16 @@ import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleException
import com.xiaowang.jayucloud.core.modules.artist.mapper.NailArtistInfoMapper;
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO;
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO;
import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService;
import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport;
import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO;
import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO;
import com.xiaowang.jayucloud.core.modules.order.mapper.OrderItemMapper;
import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper;
import com.xiaowang.jayucloud.core.modules.order.service.OrderService;
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.PlanningAppointmentUpdateDTO;
import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO;
import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper;
@@ -37,6 +41,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -76,6 +81,12 @@ class PlanningServiceImplTest {
@Mock
private ProductMapper productMapper;
@Mock
private ObjectStorageFileService objectStorageFileService;
@Mock
private ObjectStorageUrlSupport objectStorageUrlSupport;
@Mock
private ShopMapper shopMapper;
@@ -106,6 +117,8 @@ class PlanningServiceImplTest {
orderMapper,
orderItemMapper,
productMapper,
objectStorageFileService,
objectStorageUrlSupport,
shopMapper,
shopScheduleExceptionMapper,
appointmentCapacityService,
@@ -115,7 +128,7 @@ class PlanningServiceImplTest {
}
@Test
void createAppointmentShouldHideManualProductFromFront() {
void createAppointmentShouldStoreManualProductSnapshotWithoutCreatingProduct() {
UserDO manager = user(2, 8L);
UserDO artist = user(3, 8L);
artist.setId(20L);
@@ -132,14 +145,14 @@ class PlanningServiceImplTest {
dto.setDurationMinutes(90);
dto.setManualProductTitle(" 日落贝壳 ");
dto.setManualProductPrice(new BigDecimal("168.00"));
dto.setManualProductDescription(" 轻透贝壳款 ");
dto.setManualProductTags(" 贝壳 ");
dto.setManualProductPrecautions(" 避免磕碰 ");
dto.setManualProductImageFileIds("501,502");
dto.setClientRequestId("manual-product-test");
OrderItemDO[] storedItem = new OrderItemDO[1];
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
return 1;
});
when(userMapper.selectById(20L)).thenReturn(artist);
when(userMapper.selectById(30L)).thenReturn(customer);
when(shopMapper.selectById(8L)).thenReturn(shop);
@@ -152,19 +165,10 @@ class PlanningServiceImplTest {
when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> {
OrderItemDO item = invocation.getArgument(0);
item.setId(300L);
storedItem[0] = item;
return 1;
});
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> {
OrderItemDO item = new OrderItemDO();
item.setId(300L);
item.setOrderId(200L);
item.setProductId(100L);
item.setArtistId(20L);
item.setQuantity(1);
item.setAppointmentTime(LocalDateTime.of(2026, 6, 26, 13, 0));
item.setIsDelete(0);
return item;
});
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]);
when(orderMapper.selectById(200L)).thenAnswer(invocation -> {
OrderDO order = new OrderDO();
order.setId(200L);
@@ -175,18 +179,6 @@ class PlanningServiceImplTest {
order.setIsDelete(0);
return order;
});
when(productMapper.selectById(100L)).thenAnswer(invocation -> {
ProductDO product = new ProductDO();
product.setId(100L);
product.setShopId(8L);
product.setTitle("日落贝壳");
product.setPrice(new BigDecimal("168.00"));
product.setApproximateDuration("90分钟");
product.setFrontVisible(0);
product.setSourceType("MANAGER_APPOINTMENT");
product.setIsDelete(0);
return product;
});
AppointmentReservationDO reservation = new AppointmentReservationDO();
reservation.setOrderItemId(300L);
reservation.setArtistId(20L);
@@ -195,20 +187,33 @@ class PlanningServiceImplTest {
reservation.setAppointmentEndTime(LocalDateTime.of(2026, 6, 26, 14, 30));
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
ObjectStorageFileVO firstFile = new ObjectStorageFileVO();
firstFile.setId(501L);
ObjectStorageFileVO secondFile = new ObjectStorageFileVO();
secondFile.setId(502L);
when(objectStorageFileService.getObjectStorageFileMapByIds(any())).thenReturn(Map.of(
501L, firstFile,
502L, secondFile
));
when(objectStorageUrlSupport.toAccessibleUrl(firstFile)).thenReturn("https://img.example/501.jpg");
when(objectStorageUrlSupport.toAccessibleUrl(secondFile)).thenReturn("https://img.example/502.jpg");
var appointment = planningService.createAppointment(manager, dto);
ArgumentCaptor<ProductDO> captor = ArgumentCaptor.forClass(ProductDO.class);
org.mockito.Mockito.verify(productMapper).insert(captor.capture());
ProductDO product = captor.getValue();
assertThat(product.getTitle()).isEqualTo("日落贝壳");
assertThat(product.getFrontVisible()).isZero();
assertThat(product.getSourceType()).isEqualTo("MANAGER_APPOINTMENT");
assertThat(product.getImageFileIds()).isNull();
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class));
assertThat(storedItem[0].getProductId()).isNull();
assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("日落贝壳");
assertThat(storedItem[0].getAppointmentProductDescription()).isEqualTo("轻透贝壳款");
assertThat(storedItem[0].getAppointmentProductTags()).isEqualTo("贝壳");
assertThat(storedItem[0].getAppointmentProductPrecautions()).isEqualTo("避免磕碰");
assertThat(storedItem[0].getAppointmentProductImageFileIds()).isEqualTo("501,502");
ArgumentCaptor<OrderDO> orderCaptor = ArgumentCaptor.forClass(OrderDO.class);
org.mockito.Mockito.verify(orderMapper).insert(orderCaptor.capture());
assertThat(orderCaptor.getValue().getCustomerName()).isEqualTo("王女士");
assertThat(appointment.getCustomerName()).isEqualTo("王女士");
assertThat(appointment.getProductTitle()).isEqualTo("日落贝壳");
assertThat(appointment.getProductImageFileIds()).isEqualTo("501,502");
assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/501.jpg", "https://img.example/502.jpg");
}
@Test
@@ -230,17 +235,10 @@ class PlanningServiceImplTest {
dto.setNeedRemoval(true);
dto.setFromMeituan(true);
ProductDO[] storedProduct = new ProductDO[1];
UserDO[] storedCustomer = new UserDO[1];
OrderDO[] storedOrder = new OrderDO[1];
OrderItemDO[] storedItem = new OrderItemDO[1];
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
storedProduct[0] = product;
return 1;
});
when(userMapper.selectById(20L)).thenReturn(artist);
when(shopMapper.selectById(8L)).thenReturn(shop);
when(snowflakeIdGenerator.nextIdString()).thenReturn("202607200001", "202607200002");
@@ -264,10 +262,10 @@ class PlanningServiceImplTest {
});
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]);
when(orderMapper.selectById(200L)).thenAnswer(invocation -> storedOrder[0]);
when(productMapper.selectById(100L)).thenAnswer(invocation -> storedProduct[0]);
AppointmentReservationDO reservation = reservation(20L, 200L, 300L,
LocalDateTime.of(2026, 7, 20, 15, 0),
LocalDateTime.of(2026, 7, 20, 16, 0));
reservation.setProductTitle("净色护理");
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
when(userMapper.selectBatchIds(any())).thenAnswer(invocation -> List.of(storedCustomer[0]));
@@ -279,10 +277,14 @@ class PlanningServiceImplTest {
assertThat(customerCaptor.getValue().getPhone()).isNull();
assertThat(customerCaptor.getValue().getContactPhone()).isNull();
assertThat(customerCaptor.getValue().getAccount()).isEqualTo("guest202607200001");
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class));
assertThat(storedItem[0].getProductId()).isNull();
assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("净色护理");
assertThat(storedItem[0].getDepositPaid()).isTrue();
assertThat(storedItem[0].getNeedRemoval()).isTrue();
assertThat(storedItem[0].getFromMeituan()).isTrue();
assertThat(appointment.getCustomerName()).isEqualTo("到店王女士");
assertThat(appointment.getProductTitle()).isEqualTo("净色护理");
assertThat(appointment.getDepositPaid()).isTrue();
assertThat(appointment.getNeedRemoval()).isTrue();
assertThat(appointment.getFromMeituan()).isTrue();
@@ -368,11 +370,6 @@ class PlanningServiceImplTest {
dto.setManualProductPrice(new BigDecimal("100.00"));
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> {
ProductDO product = invocation.getArgument(0);
product.setId(100L);
return 1;
});
when(userMapper.selectById(20L)).thenReturn(artist);
when(userMapper.selectById(30L)).thenReturn(customer);
when(shopMapper.selectById(8L)).thenReturn(shop);
@@ -404,6 +401,53 @@ class PlanningServiceImplTest {
org.mockito.Mockito.verify(orderItemMapper, org.mockito.Mockito.never()).updateById(any());
}
@Test
void updateAppointmentImagesShouldPersistSnapshotImageIdsAndReturnUrls() {
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("王女士");
OrderDO order = order(200L, 8L, 30L);
OrderItemDO item = orderItem(300L, 200L, null, 20L, LocalDateTime.of(2026, 7, 21, 13, 0));
item.setAppointmentProductTitle("手绘款");
item.setAppointmentProductImageFileIds("501");
PlanningAppointmentImageDTO dto = new PlanningAppointmentImageDTO();
dto.setImageFileIds("601,602");
AppointmentReservationDO reservation = reservation(20L, 200L, 300L,
LocalDateTime.of(2026, 7, 21, 13, 0),
LocalDateTime.of(2026, 7, 21, 14, 0));
reservation.setProductTitle("手绘款");
ObjectStorageFileVO firstFile = new ObjectStorageFileVO();
firstFile.setId(601L);
ObjectStorageFileVO secondFile = new ObjectStorageFileVO();
secondFile.setId(602L);
when(orderItemMapper.selectByIdForUpdate(300L)).thenReturn(item);
when(orderMapper.selectById(200L)).thenReturn(order);
when(orderItemMapper.selectById(300L)).thenReturn(item);
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));
when(objectStorageFileService.getObjectStorageFileMapByIds(any())).thenReturn(Map.of(
601L, firstFile,
602L, secondFile
));
when(objectStorageUrlSupport.toAccessibleUrl(firstFile)).thenReturn("https://img.example/601.jpg");
when(objectStorageUrlSupport.toAccessibleUrl(secondFile)).thenReturn("https://img.example/602.jpg");
var appointment = planningService.updateAppointmentImages(manager, 300L, dto);
assertThat(item.getAppointmentProductImageFileIds()).isEqualTo("601,602");
org.mockito.Mockito.verify(orderItemMapper).updateById(item);
assertThat(appointment.getProductTitle()).isEqualTo("手绘款");
assertThat(appointment.getProductImageFileIds()).isEqualTo("601,602");
assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/601.jpg", "https://img.example/602.jpg");
}
@Test
void calendarMarksMonthAvailabilityByContinuousNinetyMinuteWindow() {
UserDO manager = user(2, 8L);