完善店务预约状态与详情流程
This commit is contained in:
+11
@@ -19,6 +19,7 @@ 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.PlanningAppointmentPriceDTO;
|
||||
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;
|
||||
@@ -137,6 +138,16 @@ public class AdminManagerController {
|
||||
return Result.success(planningService.updateStatus(currentUser, orderId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}/price")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-update-appointment-price", ttlSeconds = 10, message = "预约价格处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updatePrice(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentPriceDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointmentPrice(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/customers")
|
||||
@RequirePermission("user:view")
|
||||
public Result<PageResultVO<UserVO>> customers(HttpServletRequest request,
|
||||
|
||||
+11
@@ -5,6 +5,7 @@ import com.xiaowang.jayucloud.core.annotation.RequirePermission;
|
||||
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.PlanningAppointmentPriceDTO;
|
||||
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;
|
||||
@@ -93,6 +94,16 @@ public class AdminPlanningController {
|
||||
return Result.success(planningService.updateStatus(currentUser, orderId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}/price")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-update-appointment-price", ttlSeconds = 10, message = "预约价格处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updatePrice(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentPriceDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointmentPrice(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
private void requireManagerOperator(UserDO currentUser) {
|
||||
if (Integer.valueOf(2).equals(currentUser.getType())) {
|
||||
return;
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.xiaowang.jayucloud.core.modules.planning.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class PlanningAppointmentPriceDTO {
|
||||
private BigDecimal price;
|
||||
}
|
||||
+3
@@ -61,6 +61,9 @@ public interface AppointmentReservationMapper extends BaseMapper<AppointmentRese
|
||||
"WHERE order_item_id = #{orderItemId} AND is_delete = 0")
|
||||
int releaseByOrderItem(@Param("orderItemId") Long orderItemId, @Param("status") String status);
|
||||
|
||||
@Select("SELECT * FROM t_appointment_reservation WHERE order_item_id = #{orderItemId} ORDER BY id DESC LIMIT 1")
|
||||
AppointmentReservationDO selectLatestByOrderItemIncludingDeleted(@Param("orderItemId") Long orderItemId);
|
||||
|
||||
@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}, " +
|
||||
|
||||
+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.PlanningAppointmentImageDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentPriceDTO;
|
||||
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;
|
||||
@@ -24,5 +25,7 @@ public interface PlanningService {
|
||||
|
||||
PlanningAppointmentVO updateAppointmentImages(UserDO currentUser, Long orderItemId, PlanningAppointmentImageDTO dto);
|
||||
|
||||
PlanningAppointmentVO updateAppointmentPrice(UserDO currentUser, Long orderItemId, PlanningAppointmentPriceDTO dto);
|
||||
|
||||
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
|
||||
}
|
||||
|
||||
+154
-2
@@ -1,9 +1,11 @@
|
||||
package com.xiaowang.jayucloud.core.modules.planning.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
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.PlanningAppointmentPriceDTO;
|
||||
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;
|
||||
@@ -371,6 +373,69 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO updateAppointmentPrice(UserDO currentUser, Long orderItemId, PlanningAppointmentPriceDTO dto) {
|
||||
if (orderItemId == null || dto == null || dto.getPrice() == null) {
|
||||
throw new RuntimeException("预约价格不能为空");
|
||||
}
|
||||
if (dto.getPrice().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("预约价格不能小于0");
|
||||
}
|
||||
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);
|
||||
BigDecimal price = dto.getPrice();
|
||||
|
||||
OrderItemDO itemUpdate = new OrderItemDO();
|
||||
itemUpdate.setPrice(price);
|
||||
int itemUpdated = orderItemMapper.update(itemUpdate, new LambdaUpdateWrapper<OrderItemDO>()
|
||||
.eq(OrderItemDO::getId, item.getId())
|
||||
.eq(OrderItemDO::getOrderId, order.getId())
|
||||
.eq(OrderItemDO::getIsDelete, 0));
|
||||
if (itemUpdated == 0) {
|
||||
throw new RuntimeException("预约项目已变化,请刷新后重试");
|
||||
}
|
||||
|
||||
BigDecimal amount = calculateOrderAmount(order.getId());
|
||||
OrderDO orderUpdate = new OrderDO();
|
||||
orderUpdate.setTotalAmount(amount);
|
||||
orderUpdate.setActualAmount(amount);
|
||||
orderUpdate.setPayAmount(amount);
|
||||
int orderUpdated = orderMapper.update(orderUpdate, new LambdaUpdateWrapper<OrderDO>()
|
||||
.eq(OrderDO::getId, order.getId())
|
||||
.eq(OrderDO::getStatus, order.getStatus())
|
||||
.eq(OrderDO::getIsDelete, 0));
|
||||
if (orderUpdated == 0) {
|
||||
throw new RuntimeException("订单状态已变化,请刷新后重试");
|
||||
}
|
||||
|
||||
item.setPrice(price);
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
order.setPayAmount(amount);
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
private BigDecimal calculateOrderAmount(Long orderId) {
|
||||
List<OrderItemDO> items = orderItemMapper.selectList(new QueryWrapper<OrderItemDO>()
|
||||
.eq("order_id", orderId)
|
||||
.eq("is_delete", 0));
|
||||
if (items == null || items.isEmpty()) {
|
||||
throw new RuntimeException("订单没有可计算金额的项目");
|
||||
}
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
for (OrderItemDO orderItem : items) {
|
||||
BigDecimal itemPrice = orderItem.getPrice() == null ? BigDecimal.ZERO : orderItem.getPrice();
|
||||
int quantity = Math.max(1, orderItem.getQuantity() == null ? 1 : orderItem.getQuantity());
|
||||
amount = amount.add(itemPrice.multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto) {
|
||||
@@ -381,14 +446,88 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
int targetStatus = dto.getStatus();
|
||||
if (targetStatus == OrderStatus.PENDING_SERVICE.getCode()) {
|
||||
if (!Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())) {
|
||||
orderMapper.updateStatusIfCurrent(order.getId(), order.getStatus(), OrderStatus.PENDING_SERVICE.getCode());
|
||||
int updated = orderMapper.updateStatusIfCurrent(order.getId(), order.getStatus(), OrderStatus.PENDING_SERVICE.getCode());
|
||||
if (updated == 0) {
|
||||
throw new RuntimeException("订单状态已变化,请刷新后重试");
|
||||
}
|
||||
order.setStatus(OrderStatus.PENDING_SERVICE.getCode());
|
||||
}
|
||||
restorePendingReservations(order);
|
||||
return true;
|
||||
}
|
||||
orderService.processOrder(orderId, targetStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void restorePendingReservations(OrderDO order) {
|
||||
List<OrderItemDO> items = orderItemMapper.selectList(new QueryWrapper<OrderItemDO>()
|
||||
.eq("order_id", order.getId())
|
||||
.eq("is_delete", 0));
|
||||
if (items == null || items.isEmpty()) {
|
||||
throw new RuntimeException("订单没有可恢复的预约项目");
|
||||
}
|
||||
for (OrderItemDO item : items) {
|
||||
restorePendingReservation(order, item);
|
||||
}
|
||||
}
|
||||
|
||||
private void restorePendingReservation(OrderDO order, OrderItemDO item) {
|
||||
AppointmentReservationDO activeReservation = findActiveReservation(item.getId());
|
||||
if (activeReservation != null && RESERVATION_CONFIRMED.equals(activeReservation.getStatus())) {
|
||||
return;
|
||||
}
|
||||
AppointmentReservationDO latestReservation = activeReservation == null ? findLatestReservation(item.getId()) : activeReservation;
|
||||
if (item.getArtistId() == null) {
|
||||
throw new RuntimeException("预约美甲师不能为空,无法恢复待完成状态");
|
||||
}
|
||||
LocalDateTime startTime = item.getAppointmentTime() == null
|
||||
? latestReservation == null ? null : latestReservation.getAppointmentStartTime()
|
||||
: item.getAppointmentTime();
|
||||
if (startTime == null) {
|
||||
throw new RuntimeException("预约时间不能为空,无法恢复待完成状态");
|
||||
}
|
||||
ProductDO product = item.getProductId() == null ? null : productMapper.selectById(item.getProductId());
|
||||
long durationMinutes = resolveRestoredDurationMinutes(latestReservation, item, product);
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
String productTitle = firstNonBlank(
|
||||
latestReservation == null ? null : latestReservation.getProductTitle(),
|
||||
resolveAppointmentDisplayTitle(null, item, product)
|
||||
);
|
||||
if (activeReservation != null) {
|
||||
appointmentCapacityService.confirmReservationOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
order.getShopId(),
|
||||
item.getArtistId(),
|
||||
productTitle,
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
return;
|
||||
}
|
||||
appointmentCapacityService.reserveConfirmedOrThrow(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
order.getShopId(),
|
||||
item.getArtistId(),
|
||||
productTitle,
|
||||
startTime,
|
||||
endTime,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private long resolveRestoredDurationMinutes(AppointmentReservationDO reservation, OrderItemDO item, ProductDO product) {
|
||||
if (reservation != null
|
||||
&& reservation.getAppointmentStartTime() != null
|
||||
&& reservation.getAppointmentEndTime() != null
|
||||
&& reservation.getAppointmentEndTime().isAfter(reservation.getAppointmentStartTime())) {
|
||||
return Duration.between(reservation.getAppointmentStartTime(), reservation.getAppointmentEndTime()).toMinutes();
|
||||
}
|
||||
int quantity = Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
|
||||
return (long) resolveDurationMinutes(product, null) * quantity;
|
||||
}
|
||||
|
||||
private Long requirePlanningShopId(UserDO currentUser) {
|
||||
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
if (shopId == null || shopId <= 0) {
|
||||
@@ -765,7 +904,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setCanEdit(canEditAppointment(order, occupancyStatus));
|
||||
vo.setCanCancel(canCancelAppointment(order, occupancyStatus));
|
||||
vo.setConflictReason(resolveAppointmentConflictReason(occupancyStatus));
|
||||
vo.setAmount(order == null ? null : order.getActualAmount());
|
||||
vo.setAmount(resolveAppointmentAmount(item, order));
|
||||
vo.setRemark(order == null ? null : order.getCustomerRemark());
|
||||
vo.setProductDescription(resolveAppointmentProductDescription(item, product));
|
||||
vo.setProductTags(resolveAppointmentProductTags(item, product));
|
||||
@@ -775,6 +914,15 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
private BigDecimal resolveAppointmentAmount(OrderItemDO item, OrderDO order) {
|
||||
if (item == null) {
|
||||
return order == null ? null : order.getActualAmount();
|
||||
}
|
||||
BigDecimal price = item.getPrice() == null ? BigDecimal.ZERO : item.getPrice();
|
||||
int quantity = Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
|
||||
return price.multiply(BigDecimal.valueOf(quantity));
|
||||
}
|
||||
|
||||
private List<PlanningDaySummaryVO> buildDaySummaries(LocalDate start, LocalDate end, List<PlanningArtistVO> artists,
|
||||
List<ArtistScheduleDO> schedules, List<PlanningAppointmentVO> appointments,
|
||||
ShopDO shop, Map<LocalDate, ShopScheduleExceptionDO> shopExceptionByDate,
|
||||
@@ -1136,6 +1284,10 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return appointmentReservationMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
private AppointmentReservationDO findLatestReservation(Long orderItemId) {
|
||||
return appointmentReservationMapper.selectLatestByOrderItemIncludingDeleted(orderItemId);
|
||||
}
|
||||
|
||||
private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
List<AppointmentTimeSegment> segments = splitAppointmentSegments(startTime, endTime);
|
||||
|
||||
Reference in New Issue
Block a user