From 41c9434e07d89c277ac9779a49228ec84a7bf717 Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Thu, 20 Feb 2025 21:23:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=86=99=E7=9C=9F?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../good/AppointmentDateController.java | 62 +++++++++++++++++++ .../order/PendingServiceGoodController.java | 25 ++++++-- .../listener/OrderStatusListener.java | 19 ++++++ .../dto/order/BookingOrderQueryRequest.java | 5 +- 4 files changed, 103 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java index 1da9558..747ec81 100644 --- a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java +++ b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java @@ -19,6 +19,7 @@ import com.cultural.heritage.model.entity.AppointmentDate; import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.model.entity.PendingServiceGood; import com.cultural.heritage.model.entity.TimePeriod; +import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO; import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.good.AppointmentDateService; import com.cultural.heritage.service.good.GoodService; @@ -319,4 +320,65 @@ public class AppointmentDateController { return ResultUtils.success(true); } + + + + /** + * Web端管理员批量添加预约日期 + * @param appointmentDateSingleAddRequestList 预约日期添加请求体列表 + * @return 是否添加成功 + */ + @PostMapping("/addBatch") + @Operation(summary = "Web端管理员批量添加预约日期", description = "参数:预约日期添加请求体列表,权限:管理员(admin, boss),方法名:addBatchAppointmentDate") + @Transactional(rollbackFor = Exception.class) + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse addBatchAppointmentDate(@RequestBody List appointmentDateSingleAddRequestList) { + if (appointmentDateSingleAddRequestList == null || appointmentDateSingleAddRequestList.isEmpty()) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long goodId = appointmentDateSingleAddRequestList.get(0).getGoodId(); + Good good = goodService.getById(goodId); + ThrowUtils.throwIf(good == null, ErrorCode.OPERATION_ERROR, "当前商品不存在"); + + // 批量添加当前商品的预约日期 + List appointmentDateList = commonService.convertList(appointmentDateSingleAddRequestList, AppointmentDate.class); + boolean save = appointmentDateService.saveBatch(appointmentDateList); + ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "预约日期批量添加失败"); + + // 批量添加当前预约日期的预约时间段 + List timePeriods = new ArrayList<>(); + for (int i = 0; i < appointmentDateList.size(); i++) { + Long appointmentDateId = appointmentDateList.get(i).getId(); + List timePeriodAddRequestList = appointmentDateSingleAddRequestList.get(i).getTimePeriodAddRequestList(); + List timePeriodList = timePeriodAddRequestList.stream().map(timePeriodAddRequest -> { + TimePeriod timePeriod = new TimePeriod(); + BeanUtils.copyProperties(timePeriodAddRequest, timePeriod); + timePeriod.setAppointmentDateId(appointmentDateId); + return timePeriod; + }).toList(); + timePeriods.addAll(timePeriodList); + } + boolean result = timePeriodService.saveBatch(timePeriods); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "批量添加预约时间段失败"); + + // 批量插入服务类商品待处理记录 + List appointmentDateTimePeriodVOList = appointmentDateService.queryAppointmentDateDetailById(good.getId()); + List pendingServiceGoodList = new ArrayList<>(); + for (AppointmentDateTimePeriodVO appointmentDateTimePeriodVO : appointmentDateTimePeriodVOList) { + PendingServiceGood pendingServiceGood = new PendingServiceGood(); + BeanUtils.copyProperties(appointmentDateTimePeriodVO, pendingServiceGood); + pendingServiceGood.setId(null); + pendingServiceGood.setGoodImg(good.getGoodImg()); + pendingServiceGood.setPrice(good.getPrice()); + pendingServiceGood.setReservationDate(appointmentDateTimePeriodVO.getSpecificDate()); + pendingServiceGood.setAppointmentDateId(appointmentDateTimePeriodVO.getId()); + pendingServiceGoodList.add(pendingServiceGood); + } + boolean batch = pendingServiceGoodService.saveBatch(pendingServiceGoodList); + ThrowUtils.throwIf(!batch, ErrorCode.OPERATION_ERROR, "服务类商品待处理记录批量插入失败"); + + + return ResultUtils.success(true); + } + } 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 5826244..7e15a0d 100644 --- a/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java +++ b/src/main/java/com/cultural/heritage/controller/order/PendingServiceGoodController.java @@ -2,6 +2,7 @@ package com.cultural.heritage.controller.order; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cultural.heritage.annotation.AuthCheck; import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.ErrorCode; @@ -61,12 +62,16 @@ public class PendingServiceGoodController { @PostMapping("/list/advance/detail") @Operation(summary = "Web端管理员查询预约情况", description = "参数:订单查询请求体,权限:管理员(admin, boss),方法名:listOrder") @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse> listBookingOrderDetail(@RequestBody BookingOrderQueryRequest bookingOrderQueryRequest) { + public BaseResponse> listBookingOrderDetail(@RequestBody BookingOrderQueryRequest bookingOrderQueryRequest) { if (bookingOrderQueryRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } QueryWrapper queryWrapper = pendingServiceGoodService.getQueryWrapper(bookingOrderQueryRequest); - List pendingServiceGoodList = pendingServiceGoodService.list(queryWrapper); + long current = bookingOrderQueryRequest.getCurrent(); + long pageSize = bookingOrderQueryRequest.getPageSize(); + Page page = pendingServiceGoodService.page(new Page<>(current, pageSize), queryWrapper); + + List pendingServiceGoodList = page.getRecords(); // 获取服务类待处理订单 List pendingServiceOrderList = commonService.findByFieldInTargetField(pendingServiceGoodList, pendingServiceOrderService, PendingServiceGood::getId, "pendingId"); // 封装成服务类待处理订单VO @@ -83,16 +88,24 @@ public class PendingServiceGoodController { map.put(pendingId, pendingServiceOrderVOList); } - List pendingServiceGoodVOList = pendingServiceGoodList.stream().map(pendingServiceGood -> { + List pendingServiceGoodVOList = new ArrayList<>(); + for (PendingServiceGood pendingServiceGood : pendingServiceGoodList) { PendingServiceGoodVO pendingServiceGoodVO = new PendingServiceGoodVO(); BeanUtils.copyProperties(pendingServiceGood, pendingServiceGoodVO); Long goodId = pendingServiceGood.getId(); List pendingServiceOrderVOList = map.get(goodId); + if (pendingServiceOrderVOList == null) continue; pendingServiceGoodVO.setPendingServiceOrderVOList(pendingServiceOrderVOList); - return pendingServiceGoodVO; - }).toList(); + pendingServiceGoodVOList.add(pendingServiceGoodVO); + } - return ResultUtils.success(pendingServiceGoodVOList); + Page voPage = new Page<>(); + voPage.setRecords(pendingServiceGoodVOList); + voPage.setTotal(page.getTotal()); + voPage.setSize(page.getSize()); + voPage.setCurrent(page.getCurrent()); + voPage.setPages(page.getPages()); + return ResultUtils.success(voPage); } diff --git a/src/main/java/com/cultural/heritage/listener/OrderStatusListener.java b/src/main/java/com/cultural/heritage/listener/OrderStatusListener.java index de75fc5..5993911 100644 --- a/src/main/java/com/cultural/heritage/listener/OrderStatusListener.java +++ b/src/main/java/com/cultural/heritage/listener/OrderStatusListener.java @@ -6,9 +6,12 @@ import com.cultural.heritage.constant.MqConstant; import com.cultural.heritage.constant.OrderStatusConstant; import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.entity.Order; +import com.cultural.heritage.model.entity.PendingServiceOrder; import com.cultural.heritage.model.entity.UserCoupon; +import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.good.UserCouponService; import com.cultural.heritage.service.order.OrderService; +import com.cultural.heritage.service.order.PendingServiceOrderService; import com.cultural.heritage.utils.MultiDelayMessage; import jakarta.annotation.Resource; import org.springframework.amqp.rabbit.annotation.Exchange; @@ -34,6 +37,14 @@ public class OrderStatusListener { private UserCouponService userCouponService; + @Resource + private PendingServiceOrderService pendingServiceOrderService; + + + @Resource + private CommonService commonService; + + @RabbitListener(bindings = @QueueBinding( value = @Queue(MqConstant.DELAY_ORDER_QUEUE), @@ -79,6 +90,14 @@ public class OrderStatusListener { boolean result = userCouponService.updateById(userCoupon); ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券状态更新失败"); } + + boolean isGeneral = orderService.isGeneralGood(order.getOrderType()); + if (!isGeneral) { + UpdateWrapper pendingServiceOrderUpdateWrapper = new UpdateWrapper<>(); + pendingServiceOrderUpdateWrapper.eq("orderNumber", order.getOrderNumber()).set("orderStatus", OrderStatusConstant.TRANSACTION_CLOSED); + boolean updateBatch = orderService.update(updateWrapper); + ThrowUtils.throwIf(!updateBatch, ErrorCode.OPERATION_ERROR, "订单状态批量更新失败"); + } } diff --git a/src/main/java/com/cultural/heritage/model/dto/order/BookingOrderQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/BookingOrderQueryRequest.java index 8feff3e..63cc2e2 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/BookingOrderQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/BookingOrderQueryRequest.java @@ -1,5 +1,6 @@ package com.cultural.heritage.model.dto.order; +import com.cultural.heritage.common.PageRequest; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; @@ -11,8 +12,8 @@ import java.io.Serializable; @Data @AllArgsConstructor @NoArgsConstructor -@Schema(description = "服务类商品预约情况查询请求体", requiredProperties = {"goodId", "quantity"}) -public class BookingOrderQueryRequest implements Serializable { +@Schema(description = "服务类商品预约情况查询请求体", requiredProperties = {"goodId", "quantity", "sortField", "sortOrder"}) +public class BookingOrderQueryRequest extends PageRequest implements Serializable { /** * 商品id