diff --git a/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java b/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java index 7e15a0d..b755167 100644 --- a/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java +++ b/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java @@ -9,6 +9,7 @@ import com.cultural.heritage.common.ErrorCode; import com.cultural.heritage.common.ResultUtils; import com.cultural.heritage.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; +import com.cultural.heritage.model.dto.CommonRequest; import com.cultural.heritage.model.dto.order.BookingOrderQueryRequest; import com.cultural.heritage.model.entity.PendingServiceGood; import com.cultural.heritage.model.entity.PendingServiceOrder; @@ -17,9 +18,11 @@ import com.cultural.heritage.model.vo.order.PendingServiceOrderVO; import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.order.PendingServiceGoodService; import com.cultural.heritage.service.order.PendingServiceOrderService; +import com.cultural.heritage.service.user.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; @@ -53,6 +56,9 @@ public class PendingServiceGoodController { private CommonService commonService; + @Resource + private UserService userService; + /** * Web端管理员查询预约情况 @@ -60,7 +66,7 @@ public class PendingServiceGoodController { * @return 服务类商品预约情况列表 */ @PostMapping("/list/advance/detail") - @Operation(summary = "Web端管理员查询预约情况", description = "参数:订单查询请求体,权限:管理员(admin, boss),方法名:listOrder") + @Operation(summary = "Web端管理员查询预约情况", description = "参数:服务类商品预约情况查询请求体,权限:管理员(admin, boss),方法名:listOrder") @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) public BaseResponse> listBookingOrderDetail(@RequestBody BookingOrderQueryRequest bookingOrderQueryRequest) { if (bookingOrderQueryRequest == null) { @@ -109,4 +115,43 @@ public class PendingServiceGoodController { } + /** + * 小程序端用户查看当前商品的预约情况 + * @param commonRequest 商品id + * @return 当前商品不同时间段的预约人数(键:预约日期&预约时间段,值:剩余可预约人数) + */ + @PostMapping("/list/advance/count") + @Operation(summary = "小程序端用户查看当前预约人数", description = "参数:服务类商品预约情况查询请求体,权限:管理员(admin, boss),方法名:listOrder") + public BaseResponse> getCurrentBookingNumberMap(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { + if (commonRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + userService.getLoginUser(request); + Long id = commonRequest.getId(); + // 获取当前服务类商品的预约时间段 + List pendingServiceGoodList = commonService.findByFieldEqTargetField("goodId", id, pendingServiceGoodService); + // 获取当前服务类商品的预约情况 + List pendingServiceOrderList = commonService.findByFieldInTargetField(pendingServiceGoodList, pendingServiceOrderService, PendingServiceGood::getId, "pendingId"); + // 封装Map集合(键:服务类商品待处理id,值:预约人数) + Map countMap = new HashMap<>(); + for (PendingServiceOrder pendingServiceOrder : pendingServiceOrderList) { + Long pendingId = pendingServiceOrder.getPendingId(); + Integer quantity = pendingServiceOrder.getQuantity(); + Integer currentNumber = countMap.get(pendingId); + countMap.put(pendingId, currentNumber == null ? quantity : currentNumber + quantity); + } + // 封装Map集合(键:预约日期&预约时间段,值:剩余可预约人数) + Map bookingNumberMap = new HashMap<>(); + for (PendingServiceGood pendingServiceGood : pendingServiceGoodList) { + Long pendingId = pendingServiceGood.getId(); + Integer count = countMap.get(pendingId); + String reservationDate = pendingServiceGood.getReservationDate(); + String timeSlot = pendingServiceGood.getTimeSlot(); + Integer maxNumber = pendingServiceGood.getMaxNumber(); + bookingNumberMap.put(reservationDate + "&" + timeSlot, count == null ? maxNumber : maxNumber - count); + } + return ResultUtils.success(bookingNumberMap); + } + + }