From d54d93a78c799a21239b6bc5eb8ac0f4f4457c7a Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Mon, 10 Mar 2025 08:25:11 +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=E7=89=B9=E6=AE=8A=E4=BA=A7=E5=93=81=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heritage/constant/MqConstant.java | 2 +- .../book/PhotoProductsController.java | 9 +- .../controller/good/GoodController.java | 50 +++++++ .../order/AdvanceOrderController.java | 132 ++++++++++++++++-- .../advanceOrder/AdvanceOrderAddRequest.java | 12 +- .../heritage/service/good/GoodService.java | 6 + .../service/good/impl/GoodServiceImpl.java | 17 +++ 7 files changed, 204 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/cultural/heritage/constant/MqConstant.java b/src/main/java/com/cultural/heritage/constant/MqConstant.java index 208295c..dd66fdb 100644 --- a/src/main/java/com/cultural/heritage/constant/MqConstant.java +++ b/src/main/java/com/cultural/heritage/constant/MqConstant.java @@ -6,7 +6,7 @@ public interface MqConstant { // List DELAY_MILLIS = List.of(10000L, 10000L, 10000L, 15000L, 15000L, 30000L, 30000L, 60000L, 60000L, 120000L, 300000L, 600000L, 600000L)); - List DELAY_MILLIS = List.of(10000L, 10000L, 10000L, 15000L, 15000L, 30000L, 30000L); + List DELAY_MILLIS = List.of(10000L, 10000L, 10000L, 15000L, 15000L); String DELAY_EXCHANGE = "delay.topic"; diff --git a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java index 4eacb06..80a3145 100644 --- a/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java +++ b/src/main/java/com/cultural/heritage/controller/book/PhotoProductsController.java @@ -364,9 +364,9 @@ public class PhotoProductsController { List bookingDateVOList = new ArrayList<>(); // 过滤掉不合理的预约时间 for (BookingDateVO bookingDateVO : bookingDateVOS) { - // 过滤掉没有空闲的预约时间 + // 过滤掉没有空闲的预约日期 if (bookingDateVO.getIsAvailable() == 0) continue; - // 过滤掉已过期的预约时间 + // 过滤掉已过期的预约日期 String specificDate = bookingDateVO.getSpecificDate(); String today = DateUtil.today(); int result = DateUtil.compare(DateUtil.parse(specificDate), DateUtil.parse(today)); @@ -375,11 +375,12 @@ public class PhotoProductsController { List bookingTimeVOS = bookingDateVO.getBookingTimeVOList(); if (result == 0) { bookingTimeVOS = bookingTimeVOS.stream().filter(bookingTimeVO -> { - String timePoint = bookingTimeVO.getTimePoint() + ":00"; + String point = bookingTimeVO.getTimePoint(); + String timePoint = point + ":00"; DateTime targetTime = DateUtil.parse(timePoint, "HH:mm:ss"); DateTime now = DateUtil.date(); DateTime currentTime = DateUtil.parse(now.toString("HH:mm:ss"), "HH:mm:ss"); - return currentTime.compareTo(targetTime) < 0 && isOccupiedMap.get(specificDate + "&" + timePoint) == null; + return currentTime.compareTo(targetTime) < 0 && isOccupiedMap.get(specificDate + "&" + point) == null; }).toList(); } else { bookingTimeVOS = bookingTimeVOS.stream().filter(bookingTimeVO -> { diff --git a/src/main/java/com/cultural/heritage/controller/good/GoodController.java b/src/main/java/com/cultural/heritage/controller/good/GoodController.java index 9392c91..f2e612c 100644 --- a/src/main/java/com/cultural/heritage/controller/good/GoodController.java +++ b/src/main/java/com/cultural/heritage/controller/good/GoodController.java @@ -26,6 +26,7 @@ import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest; import com.cultural.heritage.model.dto.good.service.ServiceGoodQueryRequest; import com.cultural.heritage.model.dto.good.service.ServiceGoodSingleUpdateRequest; import com.cultural.heritage.model.dto.good.service.ServiceGoodUpdateRequest; +import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest; import com.cultural.heritage.model.dto.timePeriod.TimePeriodAddRequest; import com.cultural.heritage.model.entity.*; import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO; @@ -94,6 +95,55 @@ public class GoodController { + /** + * 小程序端校验常规类商品立即购买 + * @param commonRequest 商品id + * @return 商品是否通过校验 + */ + @PostMapping("/checkGeneralGood") + @Operation(summary = "小程序端校验常规类商品立即购买", description = "参数:商品id,权限:所有人,方法名:checkGeneralGood") + public BaseResponse checkGeneralGood(@RequestBody CommonRequest commonRequest) { + if (commonRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = commonRequest.getId(); + Good good = goodService.getById(id); + goodService.checkGoodIsExist(good); + goodService.checkInventoryIsEnough(1, good.getInventory()); + return ResultUtils.success(true); + } + + + + /** + * 小程序端校验服务类商品立即购买 + * @param buySingleServiceGoodVerifyRequest 服务类商品校验请求体 + * @return 商品是否通过校验 + */ + @PostMapping("/checkServiceGood") + @Operation(summary = "小程序端校验服务类商品立即购买", description = "参数:服务类商品校验请求体,权限:所有人,方法名:BuySingleServiceGoodVerifyRequest") + public BaseResponse checkServiceGood(@RequestBody BuySingleServiceGoodVerifyRequest buySingleServiceGoodVerifyRequest) { + if (buySingleServiceGoodVerifyRequest == null) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + // 校验服务类商品预约参数 + goodService.validServiceGoodBookingParameter(buySingleServiceGoodVerifyRequest); + Long goodId = buySingleServiceGoodVerifyRequest.getGoodId(); + String reservationDate = buySingleServiceGoodVerifyRequest.getReservationDate(); + String timeSlot = buySingleServiceGoodVerifyRequest.getTimeSlot(); + Integer quantity = buySingleServiceGoodVerifyRequest.getQuantity(); + + Good good = goodService.getById(goodId); + goodService.checkGoodIsExist(good); + goodService.checkServiceGoodBookingDetailIsProperly(goodId, reservationDate, timeSlot, quantity); + return ResultUtils.success(true); + } + + + + + + /** * Web端管理员添加常规类商品 diff --git a/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java b/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java index e33771e..a79b01b 100644 --- a/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/AdvanceOrderController.java @@ -1,6 +1,8 @@ package com.cultural.heritage.controller.order; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.cultural.heritage.annotation.AuthCheck; @@ -16,13 +18,12 @@ import com.cultural.heritage.model.dto.advanceOrder.AdvanceOrderAddRequest; import com.cultural.heritage.model.dto.advanceOrder.AdvanceOrderQueryRequest; import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot; import com.cultural.heritage.model.dto.snapshot.PhotoProductsSnapshot; -import com.cultural.heritage.model.entity.AdvanceOrder; -import com.cultural.heritage.model.entity.Contacts; -import com.cultural.heritage.model.entity.PhotoProducts; -import com.cultural.heritage.model.entity.User; +import com.cultural.heritage.model.entity.*; import com.cultural.heritage.model.vo.advanceorder.AdvanceOrderVO; import com.cultural.heritage.service.address.ContactsService; import com.cultural.heritage.service.book.AdvanceOrderService; +import com.cultural.heritage.service.book.BookingDateService; +import com.cultural.heritage.service.book.BookingTimeService; import com.cultural.heritage.service.book.PhotoProductsService; import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.user.UserService; @@ -40,7 +41,9 @@ import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/advanceOrder") @@ -69,6 +72,14 @@ public class AdvanceOrderController { private CommonService commonService; + @Resource + private BookingDateService bookingDateService; + + + @Resource + private BookingTimeService bookingTimeService; + + /** @@ -85,9 +96,36 @@ public class AdvanceOrderController { // 获取用户id User loginUser = userService.getLoginUser(request); Long userId = loginUser.getId(); - // 校验当前订单时间是否被预约过或者已过期 - String specificDate = addAdvanceOrderRequest.getSpecificDate(); - String timePoint = addAdvanceOrderRequest.getTimePoint(); + + // 获取写真产品信息 + Long photoProductId = addAdvanceOrderRequest.getPhotoProductId(); + PhotoProducts photoProducts = photoProductsService.getById(photoProductId); + ThrowUtils.throwIf(photoProducts == null || photoProducts.getIsShelves() == 0, ErrorCode.OPERATION_ERROR, "当前写真产品不存在或者已下架"); + PhotoProductsSnapshot photoProductsSnapshot = new PhotoProductsSnapshot(); + BeanUtils.copyProperties(photoProducts, photoProductsSnapshot); + + // 校验当前订单的预约日期和预约时间是否存在 + Long bookingDateId = addAdvanceOrderRequest.getBookingDateId(); + Long bookingTimeId = addAdvanceOrderRequest.getBookingTimeId(); + BookingDate bookingDate = bookingDateService.getById(bookingDateId); + ThrowUtils.throwIf(bookingDate == null || bookingDate.getIsAvailable() == 0, ErrorCode.OPERATION_ERROR, "当前预约日期不存在或者已不可预约"); + BookingTime bookingTime = bookingTimeService.getById(bookingTimeId); + ThrowUtils.throwIf(bookingTime == null, ErrorCode.OPERATION_ERROR, "当前预约时间不存在"); + + // 校验当前订单的拍摄场景是否存在 + String shotScene = photoProducts.getShotScene(); + Integer isIndoors = addAdvanceOrderRequest.getIsIndoors(); + ThrowUtils.throwIf(shotScene.equals("室内") && isIndoors == 0 || shotScene.equals("室外") && isIndoors == 1, ErrorCode.OPERATION_ERROR, "拍摄场景不存在"); + + // 校验当前订单的的拍摄人数是否合理 + Integer number = addAdvanceOrderRequest.getQuantity(); + Integer maxNumber = photoProducts.getMaxNumber(); + Integer minNumber = photoProducts.getMinNumber(); + ThrowUtils.throwIf(number < minNumber || number > maxNumber, ErrorCode.OPERATION_ERROR, "预约人数不在范围内"); + + // 校验当前订单预约时间是否被预约过或者已过期 + String specificDate = bookingDate.getSpecificDate(); + String timePoint = bookingTime.getTimePoint(); advanceOrderService.validBookingTime(specificDate, timePoint); // 获取联系人信息 Long contactsId = addAdvanceOrderRequest.getContactsId(); @@ -95,12 +133,6 @@ public class AdvanceOrderController { ThrowUtils.throwIf(contacts == null, ErrorCode.OPERATION_ERROR, "联系人信息不存在"); ContactsSnapshot contactsSnapshot = new ContactsSnapshot(); BeanUtils.copyProperties(contacts, contactsSnapshot); - // 获取写真产品信息 - Long photoProductId = addAdvanceOrderRequest.getPhotoProductId(); - PhotoProducts photoProducts = photoProductsService.getById(photoProductId); - ThrowUtils.throwIf(photoProducts == null, ErrorCode.OPERATION_ERROR, "当前写真产品不存在"); - PhotoProductsSnapshot photoProductsSnapshot = new PhotoProductsSnapshot(); - BeanUtils.copyProperties(photoProducts, photoProductsSnapshot); // 计算订单总金额 BigDecimal price = photoProducts.getPrice(); Integer quantity = addAdvanceOrderRequest.getQuantity(); @@ -111,6 +143,8 @@ public class AdvanceOrderController { AdvanceOrder advanceOrder = new AdvanceOrder(); BeanUtils.copyProperties(addAdvanceOrderRequest, advanceOrder); advanceOrder.setUserId(userId); + advanceOrder.setSpecificDate(specificDate); + advanceOrder.setTimePoint(timePoint); advanceOrder.setContactsSnapshot(contactsSnapshot); advanceOrder.setPhotoProductsSnapshot(photoProductsSnapshot); advanceOrder.setTotalAmount(totalAmount); @@ -229,4 +263,76 @@ public class AdvanceOrderController { } + + + /** + * 小程序端校验写真产品立即预约 + * @param commonRequest 写真产品id + * @return 产品是否通过校验 + */ + @PostMapping ("/check/photoProducts") + @Operation(summary = "小程序端校验写真产品立即预约", description = "参数:写真产品id,权限:所有人,方法名:cancelOrderById") + public BaseResponse checkPhotoProducts(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { + if (commonRequest == null || commonRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = commonRequest.getId(); + userService.getLoginUser(request); + PhotoProducts photoProducts = photoProductsService.getById(id); + ThrowUtils.throwIf(photoProducts == null || photoProducts.getIsShelves() == 0, ErrorCode.OPERATION_ERROR, "当前写真产品不存在或者已下架"); + // 判断当前写真产品是否存在预约时间段 + + // 获取所有写真预约类订单 + Map isOccupiedMap = new HashMap<>(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("orderStatus", OrderStatusConstant.PENDING_PAYMENT).or().eq("orderStatus", OrderStatusConstant.PENDING_SHIPMENT); + List advanceOrderList = advanceOrderService.list(queryWrapper); + for (AdvanceOrder advanceOrder : advanceOrderList) { + String specificDate = advanceOrder.getSpecificDate(); + String timePoint = advanceOrder.getTimePoint(); + isOccupiedMap.put(specificDate + "&" + timePoint, 1); + } + + // 获取预约日期表 + List bookingDateList = commonService.findByFieldEqTargetField("photoProductId", id, bookingDateService); + // 获取预约时间表 + List bookingTimeList = commonService.findByFieldInTargetField(bookingDateList, bookingTimeService, BookingDate::getId, "bookingDateId"); + + boolean isExistAvailable = false; + for (BookingDate bookingDate : bookingDateList) { + Long bookingDateId = bookingDate.getId(); + // 过滤掉没有空闲的预约日期 + if (bookingDate.getIsAvailable() == 0) continue; + // 过滤掉已过期的预约日期 + String specificDate = bookingDate.getSpecificDate(); + String today = DateUtil.today(); + int result = DateUtil.compare(DateUtil.parse(specificDate), DateUtil.parse(today)); + if (result < 0) continue; + // 如果预约日期相同,过滤掉预约时间以及被占用的时间 + List bookingTimes = bookingTimeList.stream().filter(bookingTime -> bookingTime.getBookingDateId().equals(bookingDateId)).toList(); + if (result == 0) { + for (BookingTime bookingTime : bookingTimes) { + String point = bookingTime.getTimePoint(); + String timePoint = point + ":00"; + DateTime targetTime = DateUtil.parse(timePoint, "HH:mm:ss"); + DateTime now = DateUtil.date(); + DateTime currentTime = DateUtil.parse(now.toString("HH:mm:ss"), "HH:mm:ss"); + isExistAvailable = currentTime.compareTo(targetTime) < 0 && isOccupiedMap.get(specificDate + "&" + point) == null; + if (isExistAvailable) break; + } + } else { + for (BookingTime bookingTime : bookingTimes) { + String timePoint = bookingTime.getTimePoint(); + isExistAvailable = isOccupiedMap.get(specificDate + "&" + timePoint) == null; + if (isExistAvailable) break; + } + } + if (isExistAvailable) break; + } + ThrowUtils.throwIf(!isExistAvailable, ErrorCode.OPERATION_ERROR, "当前写真产品的所有时段已约满"); + return ResultUtils.success(true); + } + + + } diff --git a/src/main/java/com/cultural/heritage/model/dto/advanceOrder/AdvanceOrderAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/advanceOrder/AdvanceOrderAddRequest.java index 0270bf2..9210b53 100644 --- a/src/main/java/com/cultural/heritage/model/dto/advanceOrder/AdvanceOrderAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/advanceOrder/AdvanceOrderAddRequest.java @@ -27,17 +27,17 @@ public class AdvanceOrderAddRequest implements Serializable { /** - * 预约具体日期 + * 预约日期id */ - @Schema(description = "预约具体日期", example = "2024-11-18") - private String specificDate; + @Schema(description = "预约日期id", example = "44") + private Long bookingDateId; /** - * 预约时间段 + * 预约时间id */ - @Schema(description = "预约时间段", example = "8:00-10:00") - private String timePoint; + @Schema(description = "预约时间id", example = "33") + private Long bookingTimeId; /** diff --git a/src/main/java/com/cultural/heritage/service/good/GoodService.java b/src/main/java/com/cultural/heritage/service/good/GoodService.java index 7cffb62..3abfb76 100644 --- a/src/main/java/com/cultural/heritage/service/good/GoodService.java +++ b/src/main/java/com/cultural/heritage/service/good/GoodService.java @@ -3,6 +3,7 @@ package com.cultural.heritage.service.good; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.IService; import com.cultural.heritage.model.dto.good.GoodQueryRequest; +import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest; import com.cultural.heritage.model.entity.*; import java.math.BigDecimal; @@ -69,4 +70,9 @@ public interface GoodService extends IService { boolean checkServiceGoodCartBookingDetailIsProperly(Long goodId, String reservationDate, String timeSlot, Integer quantity, Map pendingServiceGoodMap, List pendingServiceOrderList); + + /** + * 校验服务类商品预约参数 + */ + void validServiceGoodBookingParameter(BuySingleServiceGoodVerifyRequest buySingleServiceGoodVerifyRequest); } diff --git a/src/main/java/com/cultural/heritage/service/good/impl/GoodServiceImpl.java b/src/main/java/com/cultural/heritage/service/good/impl/GoodServiceImpl.java index 418f579..25d95bd 100644 --- a/src/main/java/com/cultural/heritage/service/good/impl/GoodServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/good/impl/GoodServiceImpl.java @@ -13,6 +13,7 @@ import com.cultural.heritage.mapper.CartRecordMapper; import com.cultural.heritage.mapper.GoodMapper; import com.cultural.heritage.model.dto.good.GoodQueryRequest; import com.cultural.heritage.model.dto.order.BookingOrderQueryRequest; +import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest; import com.cultural.heritage.model.entity.*; import com.cultural.heritage.service.good.GoodService; import com.cultural.heritage.service.order.PendingServiceGoodService; @@ -272,4 +273,20 @@ public class GoodServiceImpl extends ServiceImpl implements Go } + + /** + * 校验服务类商品预约参数 + */ + @Override + public void validServiceGoodBookingParameter(BuySingleServiceGoodVerifyRequest buySingleServiceGoodVerifyRequest) { + Long goodId = buySingleServiceGoodVerifyRequest.getGoodId(); + String reservationDate = buySingleServiceGoodVerifyRequest.getReservationDate(); + String timeSlot = buySingleServiceGoodVerifyRequest.getTimeSlot(); + Integer quantity = buySingleServiceGoodVerifyRequest.getQuantity(); + ThrowUtils.throwIf(goodId == null, ErrorCode.OPERATION_ERROR, "商品id为null"); + ThrowUtils.throwIf(StringUtils.isAnyBlank(reservationDate, timeSlot), ErrorCode.OPERATION_ERROR, "预约日期或预约时间段为空"); + ThrowUtils.throwIf(quantity <= 0, ErrorCode.OPERATION_ERROR, "商品数量小于等于0"); + } + + }