feat: harden appointment flow and refresh handoff docs

This commit is contained in:
xiaowang
2026-06-10 00:19:49 +08:00
parent 784bb0a965
commit 8093e07190
64 changed files with 4537 additions and 77 deletions
@@ -54,7 +54,7 @@ public class OperationGuardAspect {
if (operationGuard.strategy() == OperationGuardStrategy.NOOP_IF_DUPLICATE) {
return Result.success();
}
return Result.error(operationGuard.message());
return Result.error(409, operationGuard.message());
}
try {
@@ -23,6 +23,7 @@ public class OrderDTO {
*/
private String couponSourceType;
private String remark;
private String clientRequestId;
/**
* 订单商品列表
@@ -38,6 +38,7 @@ import com.xiaowang.yuminailcore.modules.shop.mapper.ShopMapper;
import com.xiaowang.yuminailcore.modules.message.mapper.SystemMessageMapper;
import com.xiaowang.yuminailcore.modules.marketing.mapper.UserCouponMapper;
import com.xiaowang.yuminailcore.modules.user.mapper.UserMapper;
import com.xiaowang.yuminailcore.modules.planning.mapper.AppointmentReservationMapper;
import com.xiaowang.yuminailcore.modules.planning.service.AppointmentCapacityService;
import com.xiaowang.yuminailcore.modules.integration.service.BusinessEventOutboxService;
import com.xiaowang.yuminailcore.modules.marketing.service.CouponService;
@@ -416,6 +417,9 @@ public class OrderServiceImpl implements OrderService {
@Resource
private AppointmentCapacityService appointmentCapacityService;
@Resource
private AppointmentReservationMapper appointmentReservationMapper;
@PreDestroy
/**
* Run business method `shutdownOrderLockRenewExecutor`.
@@ -803,6 +807,18 @@ public class OrderServiceImpl implements OrderService {
item.setOrderId(order.getId());
item.setIsDelete(0);
orderItemMapper.insert(item);
ProductDO product = productCache.get(item.getProductId());
long durationMinutes = resolveServiceDurationMinutes(product) * Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
appointmentCapacityService.reservePendingQuoteOrThrow(
order.getId(),
item.getId(),
order.getShopId(),
item.getArtistId(),
product == null ? null : product.getTitle(),
item.getAppointmentTime(),
item.getAppointmentTime() == null ? null : item.getAppointmentTime().plusMinutes(durationMinutes),
trimToNull(orderDTO.getClientRequestId())
);
}
writeQuoteMessage(order.getId(), userId, QUOTE_ACTOR_USER, QUOTE_ACTION_CREATE, order.getCustomerRemark());
@@ -990,6 +1006,24 @@ public class OrderServiceImpl implements OrderService {
return;
}
Set<String> occupiedSlotKeys = new LinkedHashSet<>();
for (BookingValidationSlot requestedSlot : requestedSlots) {
int activeOccupancyCount = appointmentReservationMapper.countOverlappingActive(
artistId,
requestedSlot.getStartTime(),
requestedSlot.getEndTime()
);
if (activeOccupancyCount > 0) {
occupiedSlotKeys.add(bookingSlotKey(requestedSlot));
issues.add(checkoutIssue(
ISSUE_EXISTING_CONFLICT,
"商品「" + requestedSlot.getProductTitle() + "」的预约时间与美甲师已有预约占用冲突,请重新选择",
requestedSlot.getProductId(),
requestedSlot.getProductTitle()
));
}
}
List<OrderItemDO> existingAppointments = orderItemMapper.selectActiveAppointmentItemsByArtistId(artistId);
if (existingAppointments == null || existingAppointments.isEmpty()) {
return;
@@ -1010,6 +1044,9 @@ public class OrderServiceImpl implements OrderService {
LocalDateTime existingEndTime = existingItem.getAppointmentTime().plusMinutes(existingDurationMinutes);
for (BookingValidationSlot requestedSlot : requestedSlots) {
if (occupiedSlotKeys.contains(bookingSlotKey(requestedSlot))) {
continue;
}
if (hasOverlap(existingItem.getAppointmentTime(), existingEndTime, requestedSlot.getStartTime(), requestedSlot.getEndTime())) {
issues.add(checkoutIssue(
ISSUE_EXISTING_CONFLICT,
@@ -1022,6 +1059,10 @@ public class OrderServiceImpl implements OrderService {
}
}
private String bookingSlotKey(BookingValidationSlot requestedSlot) {
return requestedSlot.getProductId() + "|" + requestedSlot.getStartTime() + "|" + requestedSlot.getEndTime();
}
private ProductDO getProductForBookingCheck(Long productId, Map<Long, ProductDO> productCache) {
if (productId == null) {
return null;
@@ -1850,6 +1891,7 @@ public class OrderServiceImpl implements OrderService {
order.setQuoteUserConfirmed(0);
order.setQuoteShopConfirmed(0);
orderMapper.updateById(order);
appointmentCapacityService.releaseByOrder(order.getId());
writeQuoteMessage(order.getId(), 0L, QUOTE_ACTOR_SYSTEM, QUOTE_ACTION_SYSTEM_EXPIRE, "询价预约超过24小时未确认,已自动取消");
expiredCount++;
}
@@ -2757,7 +2799,7 @@ public class OrderServiceImpl implements OrderService {
orderItemMapper.updateById(item);
ProductDO product = productCache.get(item.getProductId());
long durationMinutes = resolveServiceDurationMinutes(product) * Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
appointmentCapacityService.reserveOrThrow(
appointmentCapacityService.confirmReservationOrThrow(
order.getId(),
item.getId(),
order.getShopId(),
@@ -3354,6 +3396,11 @@ public class OrderServiceImpl implements OrderService {
itemVO.setPrice(displayPrice);
itemVO.setTotalPrice(displayPrice.multiply(BigDecimal.valueOf(item.getQuantity())));
itemVO.setAppointmentTime(formatAppointmentTime(item.getAppointmentTime()));
String occupancyStatus = resolveOrderItemOccupancyStatus(order);
itemVO.setOccupancyStatus(occupancyStatus);
itemVO.setCanEdit(canEditOrderItem(order));
itemVO.setCanCancel(canCancelOrderItem(order));
itemVO.setConflictReason(resolveOrderItemConflictReason(occupancyStatus));
filteredTotal = filteredTotal.add(itemVO.getTotalPrice());
if (item.getArtistId() != null) {
@@ -3391,6 +3438,51 @@ public class OrderServiceImpl implements OrderService {
return orderVO;
}
private String resolveOrderItemOccupancyStatus(OrderDO order) {
if (order == null || order.getStatus() == null) {
return "UNKNOWN";
}
if (Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())) {
return "PENDING_QUOTE";
}
if (Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
return "CONFIRMED";
}
if (Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
return "CANCELLED";
}
if (Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())) {
return "COMPLETED";
}
return "UNKNOWN";
}
private Boolean canEditOrderItem(OrderDO order) {
if (order == null || order.getStatus() == null) {
return false;
}
return Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())
|| Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus());
}
private Boolean canCancelOrderItem(OrderDO order) {
if (order == null || order.getStatus() == null) {
return false;
}
return Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())
|| Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus());
}
private String resolveOrderItemConflictReason(String occupancyStatus) {
if ("PENDING_QUOTE".equals(occupancyStatus)) {
return "该时段已作为待报价预约保留";
}
if ("CONFIRMED".equals(occupancyStatus)) {
return "该时段已确认占用";
}
return null;
}
/**
* Run business method `buildRequestedQuantityMap`.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
@@ -3931,6 +4023,17 @@ public class OrderServiceImpl implements OrderService {
return;
}
for (AppointmentSlot requestedSlot : requestedSlots) {
int activeOccupancyCount = appointmentReservationMapper.countOverlappingActive(
artistId,
requestedSlot.getStartTime(),
requestedSlot.getEndTime()
);
if (activeOccupancyCount > 0) {
throw new RuntimeException("商品「" + requestedSlot.getProductTitle() + "」的预约时间与美甲师已有预约占用冲突,请重新选择");
}
}
List<OrderItemDO> existingAppointments = orderItemMapper.selectActiveAppointmentItemsByArtistId(artistId);
if (existingAppointments == null || existingAppointments.isEmpty()) {
return;
@@ -57,6 +57,10 @@ public class OrderItemVO {
* Field `appointmentTime` (String): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled.
*/
private String appointmentTime;
private String occupancyStatus;
private Boolean canEdit;
private Boolean canCancel;
private String conflictReason;
/**
* Purpose: pendingReview supports OrderItemVO.java by holding or executing the pending review business role.
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
@@ -15,4 +15,5 @@ public class PlanningAppointmentCreateDTO {
private String appointmentStartTime;
private Integer durationMinutes;
private String remark;
private String clientRequestId;
}
@@ -9,4 +9,5 @@ public class PlanningAppointmentMoveDTO {
private String appointmentTime;
private String appointmentStartTime;
private Integer durationMinutes;
private String clientRequestId;
}
@@ -29,6 +29,8 @@ public class AppointmentReservationDO extends BaseEntity {
private LocalDateTime appointmentEndTime;
@TableField("status")
private String status;
@TableField("client_request_id")
private String clientRequestId;
@TableField("is_delete")
@TableLogic
private Integer isDelete;
@@ -11,15 +11,17 @@ import java.time.LocalDateTime;
@Mapper
public interface AppointmentReservationMapper extends BaseMapper<AppointmentReservationDO> {
String ACTIVE_STATUS_SQL = "('LOCKED','PENDING_QUOTE','CONFIRMED')";
@Select("SELECT COUNT(*) FROM t_appointment_reservation WHERE artist_id = #{artistId} " +
"AND status IN ('LOCKED','CONFIRMED') AND is_delete = 0 " +
"AND status IN " + ACTIVE_STATUS_SQL + " AND is_delete = 0 " +
"AND appointment_start_time < #{endTime} AND appointment_end_time > #{startTime} FOR UPDATE")
int countOverlappingActiveForUpdate(@Param("artistId") Long artistId,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
@Select("SELECT COUNT(*) FROM t_appointment_reservation WHERE artist_id = #{artistId} " +
"AND order_item_id <> #{orderItemId} AND status IN ('LOCKED','CONFIRMED') AND is_delete = 0 " +
"AND order_item_id <> #{orderItemId} AND status IN " + ACTIVE_STATUS_SQL + " AND is_delete = 0 " +
"AND appointment_start_time < #{endTime} AND appointment_end_time > #{startTime} FOR UPDATE")
int countOverlappingActiveForUpdateExcludingOrderItem(@Param("artistId") Long artistId,
@Param("orderItemId") Long orderItemId,
@@ -27,7 +29,7 @@ public interface AppointmentReservationMapper extends BaseMapper<AppointmentRese
@Param("endTime") LocalDateTime endTime);
@Select("SELECT COUNT(*) FROM t_appointment_reservation WHERE artist_id = #{artistId} " +
"AND status IN ('LOCKED','CONFIRMED') AND is_delete = 0 " +
"AND status IN " + ACTIVE_STATUS_SQL + " AND is_delete = 0 " +
"AND appointment_start_time < #{endTime} AND appointment_end_time > #{startTime}")
int countOverlappingActive(@Param("artistId") Long artistId,
@Param("startTime") LocalDateTime startTime,
@@ -54,4 +56,19 @@ public interface AppointmentReservationMapper extends BaseMapper<AppointmentRese
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime,
@Param("status") String status);
@Update("UPDATE t_appointment_reservation SET order_id = #{orderId}, shop_id = #{shopId}, " +
"artist_id = #{artistId}, product_title = #{productTitle}, " +
"appointment_start_time = #{startTime}, appointment_end_time = #{endTime}, " +
"status = #{status}, client_request_id = COALESCE(#{clientRequestId}, client_request_id), is_delete = 0, update_time = NOW() " +
"WHERE order_item_id = #{orderItemId} AND is_delete = 0")
int updateActiveReservationForOrderItemWithClientRequest(@Param("orderItemId") Long orderItemId,
@Param("orderId") Long orderId,
@Param("shopId") Long shopId,
@Param("artistId") Long artistId,
@Param("productTitle") String productTitle,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime,
@Param("status") String status,
@Param("clientRequestId") String clientRequestId);
}
@@ -6,6 +6,15 @@ public interface AppointmentCapacityService {
void reserveOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime);
void reservePendingQuoteOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime, String clientRequestId);
void reserveConfirmedOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime, String clientRequestId);
void confirmReservationOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime);
void releaseByOrder(Long orderId);
void moveReservationForArtistChange(Long orderId, Long orderItemId, Long shopId, Long fromArtistId,
@@ -16,6 +16,7 @@ import java.time.LocalDateTime;
public class AppointmentCapacityServiceImpl implements AppointmentCapacityService {
private static final int MIN_CAPACITY = 1;
public static final String STATUS_PENDING_QUOTE = "PENDING_QUOTE";
private static final String STATUS_CONFIRMED = "CONFIRMED";
private static final String STATUS_RELEASED = "RELEASED";
private static final String UNAVAILABLE_MESSAGE = "涓嶅彲棰勭害";
@@ -28,10 +29,55 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
@Transactional
public void reserveOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime) {
reserveWithStatusOrThrow(orderId, orderItemId, shopId, artistId, productTitle, startTime, endTime,
STATUS_CONFIRMED, null, null);
}
@Override
@Transactional
public void reservePendingQuoteOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime, String clientRequestId) {
reserveWithStatusOrThrow(orderId, orderItemId, shopId, artistId, productTitle, startTime, endTime,
STATUS_PENDING_QUOTE, clientRequestId, null);
}
@Override
@Transactional
public void reserveConfirmedOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime, String clientRequestId) {
reserveWithStatusOrThrow(orderId, orderItemId, shopId, artistId, productTitle, startTime, endTime,
STATUS_CONFIRMED, clientRequestId, null);
}
@Override
@Transactional
public void confirmReservationOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime) {
reserveWithStatusOrThrow(orderId, orderItemId, shopId, artistId, productTitle, startTime, endTime,
STATUS_CONFIRMED, null, orderItemId);
}
private void reserveWithStatusOrThrow(Long orderId, Long orderItemId, Long shopId, Long artistId, String productTitle,
LocalDateTime startTime, LocalDateTime endTime, String status,
String clientRequestId, Long excludedOrderItemId) {
if (orderId == null || orderItemId == null || shopId == null || artistId == null || startTime == null || endTime == null) {
return;
}
assertCapacityAvailable(shopId, artistId, null, startTime, endTime);
assertCapacityAvailable(shopId, artistId, excludedOrderItemId, startTime, endTime);
int updated = reservationMapper.updateActiveReservationForOrderItemWithClientRequest(
orderItemId,
orderId,
shopId,
artistId,
productTitle,
startTime,
endTime,
status,
clientRequestId
);
if (updated > 0) {
return;
}
AppointmentReservationDO reservation = new AppointmentReservationDO();
reservation.setOrderId(orderId);
reservation.setOrderItemId(orderItemId);
@@ -40,7 +86,8 @@ public class AppointmentCapacityServiceImpl implements AppointmentCapacityServic
reservation.setProductTitle(productTitle);
reservation.setAppointmentStartTime(startTime);
reservation.setAppointmentEndTime(endTime);
reservation.setStatus(STATUS_CONFIRMED);
reservation.setStatus(status);
reservation.setClientRequestId(clientRequestId);
reservation.setIsDelete(0);
reservationMapper.insert(reservation);
}
@@ -63,8 +63,9 @@ public class PlanningServiceImpl implements PlanningService {
private static final int DEFAULT_SLOT_MINUTES = 30;
private static final int DEFAULT_DURATION_MINUTES = 60;
private static final String RESERVATION_PENDING_QUOTE = "PENDING_QUOTE";
private static final String RESERVATION_CONFIRMED = "CONFIRMED";
private static final List<String> ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_CONFIRMED);
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");
private static final List<String> ARTIST_COLORS = List.of(
"#7BA7C7", "#8FB89A", "#A894C7", "#D7A86E", "#D98DA5", "#79A6A3", "#B9A16B", "#9BA9C8"
@@ -176,14 +177,15 @@ public class PlanningServiceImpl implements PlanningService {
item.setIsDelete(0);
orderItemMapper.insert(item);
appointmentCapacityService.reserveOrThrow(
appointmentCapacityService.reserveConfirmedOrThrow(
order.getId(),
item.getId(),
shopId,
artist.getId(),
product.getTitle(),
startTime,
endTime
endTime,
trimToNull(dto.getClientRequestId())
);
return getAppointment(currentUser, item.getId());
@@ -485,6 +487,11 @@ public class PlanningServiceImpl implements PlanningService {
vo.setDurationMinutes(start == null || end == null ? durationMinutes : Math.toIntExact(Duration.between(start, end).toMinutes()));
vo.setStatus(order == null ? null : order.getStatus());
vo.setStatusText(statusText(order == null ? null : order.getStatus()));
String occupancyStatus = resolveOccupancyStatus(reservation, order);
vo.setOccupancyStatus(occupancyStatus);
vo.setCanEdit(canEditAppointment(order, occupancyStatus));
vo.setCanCancel(canCancelAppointment(order, occupancyStatus));
vo.setConflictReason(resolveAppointmentConflictReason(occupancyStatus));
vo.setAmount(order == null ? null : order.getActualAmount());
vo.setRemark(order == null ? null : order.getCustomerRemark());
return vo;
@@ -738,6 +745,49 @@ public class PlanningServiceImpl implements PlanningService {
return "未知";
}
private String resolveOccupancyStatus(AppointmentReservationDO reservation, OrderDO order) {
if (reservation != null && hasText(reservation.getStatus())) {
return reservation.getStatus();
}
if (order != null && Integer.valueOf(OrderStatus.PRICE_CONFIRMING.getCode()).equals(order.getStatus())) {
return RESERVATION_PENDING_QUOTE;
}
if (order != null && Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
return RESERVATION_CONFIRMED;
}
if (order != null && Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
return "CANCELLED";
}
if (order != null && Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())) {
return "COMPLETED";
}
return "UNKNOWN";
}
private Boolean canEditAppointment(OrderDO order, String occupancyStatus) {
return order != null
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
}
private Boolean canCancelAppointment(OrderDO order, String occupancyStatus) {
return order != null
&& (RESERVATION_PENDING_QUOTE.equals(occupancyStatus) || RESERVATION_CONFIRMED.equals(occupancyStatus))
&& !Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
&& !Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus());
}
private String resolveAppointmentConflictReason(String occupancyStatus) {
if (RESERVATION_PENDING_QUOTE.equals(occupancyStatus)) {
return "该时段已有待报价预约占用";
}
if (RESERVATION_CONFIRMED.equals(occupancyStatus)) {
return "该时段已有已确认预约占用";
}
return null;
}
private <T> List<T> safeList(List<T> list) {
return list == null ? List.of() : list;
}
@@ -24,6 +24,10 @@ public class PlanningAppointmentVO {
private Integer durationMinutes;
private Integer status;
private String statusText;
private String occupancyStatus;
private Boolean canEdit;
private Boolean canCancel;
private String conflictReason;
private BigDecimal amount;
private String remark;
}
@@ -1,5 +1,6 @@
package com.xiaowang.yuminailcore.modules.security.support;
import com.xiaowang.yuminailcore.common.BusinessException;
import com.xiaowang.yuminailcore.modules.user.entity.UserDO;
import com.xiaowang.yuminailcore.modules.user.service.UserService;
import lombok.RequiredArgsConstructor;
@@ -128,7 +129,7 @@ public class AdminScopeHelper {
public void ensureShopAccessible(UserDO currentUser, Long targetShopId, String message) {
Long managedShopId = getManagedShopId(currentUser);
if (managedShopId != null && !managedShopId.equals(targetShopId)) {
throw new RuntimeException(message);
throw new BusinessException(403, message);
}
}
@@ -145,7 +146,7 @@ public class AdminScopeHelper {
}
Long managedShopId = getManagedShopId(currentUser);
if (!userShopBindingSupport.isUserAccessibleInShop(targetUserId, managedShopId)) {
throw new RuntimeException(message);
throw new BusinessException(403, message);
}
}
@@ -8,7 +8,7 @@ public final class AdminDefaultPasswordSupport {
public static final String CONFIG_GROUP = "USER";
public static final String CONFIG_KEY = "DEFAULT_PASSWORD";
public static final String FALLBACK_DEFAULT_PASSWORD = "YumiNail@123";
public static final String FALLBACK_DEFAULT_PASSWORD = "Fingertip@123";
private AdminDefaultPasswordSupport() {
}
@@ -1,4 +1,4 @@
-- YumiNail 最小运行初始化 SQL
-- Fingertip Designer 最小运行初始化 SQL
-- 说明:
-- 1. 首次部署空库时,只需要执行本文件即可完成基础建表、结构补丁、权限种子、基础参数、协议、MessageHub、VIP 规则与管理员初始化。
-- 2. 2026-03-20_user_asset_vip_coupon_permission_patch.sql、2026-03-25_user_shop_binding_and_shop_status_patch.sql、
@@ -1498,7 +1498,8 @@ CREATE TABLE IF NOT EXISTS t_appointment_reservation
product_title varchar(200) NULL COMMENT '预约作品标题快照',
appointment_start_time datetime NOT NULL COMMENT '预约开始时间',
appointment_end_time datetime NOT NULL COMMENT '预约结束时间',
status varchar(20) NOT NULL DEFAULT 'LOCKED' COMMENT '状态:LOCKED/CONFIRMED/RELEASED/CANCELLED',
status varchar(20) NOT NULL DEFAULT 'LOCKED' COMMENT '状态:LOCKED/PENDING_QUOTE/CONFIRMED/RELEASED/CANCELLED/EXPIRED',
client_request_id varchar(80) NULL COMMENT '客户端幂等请求ID',
create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
is_delete tinyint unsigned DEFAULT 0 NULL COMMENT '逻辑删除:0-未删,1-已删',
@@ -1662,7 +1663,9 @@ CREATE TABLE IF NOT EXISTS t_user_growth_record
CALL sp_add_unique_index_if_not_exists('t_artist_schedule', 'uk_t_artist_schedule_slot', '(`shop_id`, `artist_id`, `work_date`, `start_time`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_artist_schedule', 'idx_t_artist_schedule_artist_date', '(`artist_id`, `work_date`, `status`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_artist_schedule', 'idx_t_artist_schedule_shop_date', '(`shop_id`, `work_date`, `status`, `is_delete`)');
CALL sp_add_column_if_not_exists('t_appointment_reservation', 'client_request_id', 'varchar(80) NULL COMMENT ''客户端幂等请求ID''');
CALL sp_add_unique_index_if_not_exists('t_appointment_reservation', 'uk_t_appointment_reservation_item', '(`order_item_id`, `is_delete`)');
CALL sp_add_unique_index_if_not_exists('t_appointment_reservation', 'uk_t_appointment_reservation_client_request', '(`shop_id`, `artist_id`, `client_request_id`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_appointment_reservation', 'idx_t_appointment_reservation_artist_time', '(`artist_id`, `status`, `appointment_start_time`, `appointment_end_time`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_appointment_reservation', 'idx_t_appointment_reservation_order', '(`order_id`, `status`, `is_delete`)');
CALL sp_add_index_if_not_exists('t_appointment_reservation', 'idx_t_appointment_reservation_shop_time', '(`shop_id`, `appointment_start_time`, `status`, `is_delete`)');
@@ -1767,7 +1770,7 @@ CREATE TABLE IF NOT EXISTS `t_messagehub_push_config` (
PRIMARY KEY (`id`),
UNIQUE KEY `uk_messagehub_push_config_scene` (`scene_code`),
KEY `idx_messagehub_push_config_enabled` (`enabled`, `is_delete`)
) COMMENT='YumiNail按业务场景投递MessageHub的配置';
) COMMENT='Fingertip Designer按业务场景投递MessageHub的配置';
DROP PROCEDURE IF EXISTS sp_add_column_if_not_exists;
DROP PROCEDURE IF EXISTS sp_add_index_if_not_exists;
@@ -2431,8 +2434,8 @@ DEALLOCATE PREPARE stmt_system_parameter_enabled;
INSERT INTO t_legal_agreement (id, agreement_type, title, version, content, status, effective_time, create_time, update_time, is_delete)
VALUES
(313931273555138001, 'USER_TERMS', '用户协议', '2026.05.18', '欢迎使用 YumiNail。请在使用账号、预约、订单、会员、消息等功能前仔细阅读本协议。继续登录或注册即表示你已理解并同意平台基础服务规则、账号安全要求、订单预约规则和依法合规使用要求。', 1, NOW(), NOW(), NOW(), 0),
(313931273555138002, 'PRIVACY_POLICY', '隐私政策', '2026.05.18', 'YumiNail 会在提供登录注册、预约下单、会员余额、消息通知和客户服务时处理必要的手机号、昵称、门店归属、订单与设备信息。我们仅在业务需要和法律允许范围内使用这些信息,并采取访问控制、脱敏展示和审计记录等措施保护数据安全。', 1, NOW(), NOW(), NOW(), 0)
(313931273555138001, 'USER_TERMS', '用户协议', '2026.05.18', '欢迎使用 Fingertip Designer 指尖设计师。请在使用账号、预约、订单、会员、消息等功能前仔细阅读本协议。继续登录或注册即表示你已理解并同意平台基础服务规则、账号安全要求、订单预约规则和依法合规使用要求。', 1, NOW(), NOW(), NOW(), 0),
(313931273555138002, 'PRIVACY_POLICY', '隐私政策', '2026.05.18', 'Fingertip Designer 指尖设计师会在提供登录注册、预约下单、会员余额、消息通知和客户服务时处理必要的手机号、昵称、门店归属、订单与设备信息。我们仅在业务需要和法律允许范围内使用这些信息,并采取访问控制、脱敏展示和审计记录等措施保护数据安全。', 1, NOW(), NOW(), NOW(), 0)
ON DUPLICATE KEY UPDATE
title = VALUES(title),
content = VALUES(content),
@@ -2459,7 +2462,7 @@ VALUES
(313931273555139001, 'MAP', 'TENCENT_MAP_KEY', '腾讯 Web Key', '', 0, '用于后台腾讯地图选点和 Web 展示;请在后台参数管理中填入真实 Key 后启用', NOW(), NOW(), 0),
(313931273555139002, 'MAP', 'AMAP_WEB_KEY', '高德 Web Key', '', 0, '用于后台高德地图选点和 Web 展示;Web 端 Key 与小程序 Key 分开维护', NOW(), NOW(), 0),
(313931273555139003, 'MAP', 'AMAP_MINI_KEY', '高德小程序 Key', '', 0, '用于后续小程序端高德 SDK/API 调用;不要与 Web Key 混用', NOW(), NOW(), 0),
(313931273555139004, 'USER', 'DEFAULT_PASSWORD', '后台新增用户默认密码', 'YumiNail@123', 1, '后台新增用户不填写密码时使用;需满足 8-32 位且至少包含数字、小写字母、大写字母、特殊符号中的 3 类', NOW(), NOW(), 0)
(313931273555139004, 'USER', 'DEFAULT_PASSWORD', '后台新增用户默认密码', 'Fingertip@123', 1, '后台新增用户不填写密码时使用;需满足 8-32 位且至少包含数字、小写字母、大写字母、特殊符号中的 3 类', NOW(), NOW(), 0)
ON DUPLICATE KEY UPDATE
config_name = VALUES(config_name),
remark = VALUES(remark),
@@ -14,6 +14,7 @@ import com.xiaowang.yuminailcore.modules.order.mapper.OrderItemMapper;
import com.xiaowang.yuminailcore.modules.product.mapper.ProductMapper;
import com.xiaowang.yuminailcore.modules.shop.mapper.ShopMapper;
import com.xiaowang.yuminailcore.modules.user.mapper.UserMapper;
import com.xiaowang.yuminailcore.modules.planning.mapper.AppointmentReservationMapper;
import com.xiaowang.yuminailcore.modules.planning.service.AppointmentCapacityService;
import com.xiaowang.yuminailcore.modules.marketing.service.CouponService;
import com.xiaowang.yuminailcore.modules.artist.support.BookableArtistSupport;
@@ -58,6 +59,8 @@ class OrderServiceImplCheckoutPreviewTest {
private UserShopBindingSupport userShopBindingSupport;
@Mock
private AppointmentCapacityService appointmentCapacityService;
@Mock
private AppointmentReservationMapper appointmentReservationMapper;
private OrderServiceImpl service;
@@ -75,6 +78,7 @@ class OrderServiceImplCheckoutPreviewTest {
ReflectionTestUtils.setField(service, "bookableArtistSupport", bookableArtistSupport);
ReflectionTestUtils.setField(service, "userShopBindingSupport", userShopBindingSupport);
ReflectionTestUtils.setField(service, "appointmentCapacityService", appointmentCapacityService);
ReflectionTestUtils.setField(service, "appointmentReservationMapper", appointmentReservationMapper);
}
@Test
@@ -153,6 +157,41 @@ class OrderServiceImplCheckoutPreviewTest {
verifyNoInteractions(appointmentCapacityService);
}
@Test
void checkoutPreviewReportsReservationOccupancyConflict() {
ProductDO product = product(100L, "Classic", "regular", new BigDecimal("80.00"));
product.setApproximateDuration("60");
product.setBookableArtists("77");
CartDO cartItem = cartItem(100L, 1);
LocalDateTime appointmentTime = LocalDateTime.now().plusDays(1)
.withHour(10)
.withMinute(0)
.withSecond(0)
.withNano(0);
LocalDateTime appointmentEndTime = appointmentTime.plusHours(1);
when(productMapper.selectById(100L)).thenReturn(product);
when(cartMapper.selectByUserIdAndProductId(20L, 100L)).thenReturn(cartItem);
when(userMapper.selectById(77L)).thenReturn(artist(77L));
when(bookableArtistSupport.isBookableServiceUser(any(UserDO.class))).thenReturn(true);
when(userShopBindingSupport.canUserAccessShop(20L, 9L, false, null)).thenReturn(true);
when(userShopBindingSupport.isUserAccessibleInShop(77L, 9L)).thenReturn(true);
when(shopMapper.selectById(9L)).thenReturn(shop("09:00-18:00"));
when(appointmentReservationMapper.countOverlappingActive(77L, appointmentTime, appointmentEndTime)).thenReturn(1);
when(couponService.getAvailableCoupons(20L, "regular", 80.0, 9L)).thenReturn(List.of());
when(couponMapper.selectList(any())).thenReturn(List.of());
CheckoutPreviewVO preview = service.checkoutPreview(20L, order(100L, 1, 77L, appointmentTime));
assertThat(ReflectionTestUtils.getField(preview, "bookingAvailable")).isEqualTo(false);
List<?> bookingIssues = (List<?>) ReflectionTestUtils.getField(preview, "bookingIssues");
assertThat(bookingIssues).hasSize(1);
Object issue = bookingIssues.get(0);
assertThat(ReflectionTestUtils.getField(issue, "code")).isEqualTo("EXISTING_CONFLICT");
assertThat(ReflectionTestUtils.getField(issue, "productId")).isEqualTo(100L);
verifyNoInteractions(appointmentCapacityService);
}
@Test
void createOrderReturnsBusinessCodeForBookingValidationBeforeLocking() {
assertThatThrownBy(() -> service.createOrder(20L, null))
@@ -66,6 +66,39 @@ class AppointmentCapacityServiceImplTest {
assertThat(reservation.getStatus()).isEqualTo("CONFIRMED");
}
@Test
void reservePendingQuoteCreatesPendingReservationWithClientRequestId() {
LocalDateTime start = LocalDateTime.of(2026, 6, 1, 10, 0);
LocalDateTime end = start.plusHours(1);
when(scheduleMapper.selectCoveringSchedule(9L, 30L, start.toLocalDate(), start.toLocalTime(), end.toLocalTime()))
.thenReturn(schedule(2));
when(reservationMapper.countOverlappingActiveForUpdate(30L, start, end)).thenReturn(0);
service.reservePendingQuoteOrThrow(1L, 10L, 9L, 30L, "French", start, end, "req-1");
ArgumentCaptor<AppointmentReservationDO> captor = ArgumentCaptor.forClass(AppointmentReservationDO.class);
verify(reservationMapper).insert(captor.capture());
AppointmentReservationDO reservation = captor.getValue();
assertThat(reservation.getStatus()).isEqualTo("PENDING_QUOTE");
assertThat(reservation.getClientRequestId()).isEqualTo("req-1");
}
@Test
void confirmReservationUpgradesExistingPendingReservationWithoutSelfConflict() {
LocalDateTime start = LocalDateTime.of(2026, 6, 1, 10, 0);
LocalDateTime end = start.plusHours(1);
when(scheduleMapper.selectCoveringSchedule(9L, 30L, start.toLocalDate(), start.toLocalTime(), end.toLocalTime()))
.thenReturn(schedule(2));
when(reservationMapper.countOverlappingActiveForUpdateExcludingOrderItem(30L, 10L, start, end)).thenReturn(0);
when(reservationMapper.updateActiveReservationForOrderItemWithClientRequest(10L, 1L, 9L, 30L, "French", start, end, "CONFIRMED", null))
.thenReturn(1);
service.confirmReservationOrThrow(1L, 10L, 9L, 30L, "French", start, end);
verify(reservationMapper).updateActiveReservationForOrderItemWithClientRequest(10L, 1L, 9L, 30L, "French", start, end, "CONFIRMED", null);
verify(reservationMapper, never()).insert(org.mockito.ArgumentMatchers.any(AppointmentReservationDO.class));
}
@Test
void reserveRejectsWhenNoCoveringScheduleExists() {
LocalDateTime start = LocalDateTime.of(2026, 6, 2, 10, 0);