完善预约详情只读与修改能力
This commit is contained in:
+11
@@ -18,6 +18,7 @@ import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
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;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningCalendarVO;
|
||||
@@ -92,6 +93,16 @@ public class AdminManagerController {
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-update-appointment", ttlSeconds = 10, message = "预约修改处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updateAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentUpdateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
|
||||
+11
@@ -6,6 +6,7 @@ import com.xiaowang.jayucloud.core.common.Result;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
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;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper;
|
||||
@@ -61,6 +62,16 @@ public class AdminPlanningController {
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-update-appointment", ttlSeconds = 10, message = "预约修改处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updateAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentUpdateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.xiaowang.jayucloud.core.modules.planning.dto;
|
||||
|
||||
public class PlanningAppointmentUpdateDTO extends PlanningAppointmentCreateDTO {
|
||||
}
|
||||
+3
@@ -3,6 +3,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.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningCalendarVO;
|
||||
@@ -16,6 +17,8 @@ public interface PlanningService {
|
||||
|
||||
PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId);
|
||||
|
||||
PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentUpdateDTO dto);
|
||||
|
||||
PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto);
|
||||
|
||||
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
|
||||
|
||||
+65
@@ -4,6 +4,7 @@ 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.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO;
|
||||
@@ -229,6 +230,62 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return toAppointmentVO(reservation, item, order, product, customerMap.get(order.getUserId()), artistMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentUpdateDTO 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);
|
||||
requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = resolveAppointmentProduct(dto, order.getShopId());
|
||||
UserDO artist = requireActiveArtist(dto.getArtistId(), order.getShopId());
|
||||
UserDO customer = resolveCustomer(order.getShopId(), dto);
|
||||
|
||||
int quantity = dto.getQuantity() == null || dto.getQuantity() <= 0
|
||||
? Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity())
|
||||
: dto.getQuantity();
|
||||
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) * quantity;
|
||||
LocalDateTime startTime = parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime());
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
ensureWithinBusinessHours(order.getShopId(), startTime, endTime);
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
|
||||
|
||||
appointmentCapacityService.moveReservationForArtistChange(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
order.getShopId(),
|
||||
item.getArtistId(),
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
|
||||
order.setUserId(customer.getId());
|
||||
order.setCustomerName(buildOrderCustomerNameSnapshot(dto, customer));
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
order.setCustomerRemark(trimToNull(dto.getRemark()));
|
||||
order.setPayAmount(amount);
|
||||
orderMapper.updateById(order);
|
||||
|
||||
item.setProductId(product.getId());
|
||||
item.setQuantity(quantity);
|
||||
item.setPrice(unitPrice);
|
||||
item.setArtistId(artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
orderItemMapper.updateById(item);
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto) {
|
||||
@@ -240,6 +297,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
throw new RuntimeException("预约不存在");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
requireEditableAppointment(order);
|
||||
ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId());
|
||||
Long targetArtistId = dto.getArtistId() == null ? item.getArtistId() : dto.getArtistId();
|
||||
UserDO artist = requireActiveArtist(targetArtistId, order.getShopId());
|
||||
@@ -879,6 +937,13 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return order;
|
||||
}
|
||||
|
||||
private void requireEditableAppointment(OrderDO order) {
|
||||
if (Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
|| Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
|
||||
throw new RuntimeException("已完成或已取消的订单只可查看,不能修改");
|
||||
}
|
||||
}
|
||||
|
||||
private AppointmentReservationDO findActiveReservation(Long orderItemId) {
|
||||
QueryWrapper<AppointmentReservationDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("order_item_id", orderItemId)
|
||||
|
||||
+23
@@ -12,6 +12,7 @@ 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.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.AppointmentCapacityService;
|
||||
@@ -245,6 +246,28 @@ class PlanningServiceImplTest {
|
||||
.hasMessageContaining("当前日期为店铺休息日");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppointmentRejectsCompletedOrder() {
|
||||
UserDO manager = user(2, 8L);
|
||||
OrderItemDO item = orderItem(300L, 200L, 100L, 20L, LocalDateTime.of(2026, 6, 26, 13, 0));
|
||||
OrderDO order = order(200L, 8L, 30L);
|
||||
order.setStatus(2);
|
||||
PlanningAppointmentUpdateDTO dto = new PlanningAppointmentUpdateDTO();
|
||||
dto.setCustomerUserId(30L);
|
||||
dto.setProductId(100L);
|
||||
dto.setArtistId(20L);
|
||||
dto.setAppointmentDate("2026-06-26");
|
||||
dto.setAppointmentTime("13:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
when(orderItemMapper.selectByIdForUpdate(300L)).thenReturn(item);
|
||||
when(orderMapper.selectById(200L)).thenReturn(order);
|
||||
|
||||
assertThatThrownBy(() -> planningService.updateAppointment(manager, 300L, dto))
|
||||
.hasMessageContaining("已完成或已取消的订单只可查看");
|
||||
org.mockito.Mockito.verify(orderItemMapper, org.mockito.Mockito.never()).updateById(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void calendarMarksMonthAvailabilityByContinuousNinetyMinuteWindow() {
|
||||
UserDO manager = user(2, 8L);
|
||||
|
||||
Reference in New Issue
Block a user