更新了优惠券模块

This commit is contained in:
chen-xin-zhi 2025-02-25 19:25:38 +08:00
parent c21e809108
commit dc43642574
4 changed files with 106 additions and 12 deletions

View File

@ -10,14 +10,17 @@ import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonBatchRequest; import com.cultural.heritage.model.dto.CommonBatchRequest;
import com.cultural.heritage.model.dto.cartService.CartExperienceAddRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceAddRequest;
import com.cultural.heritage.model.dto.cartService.CartExperienceUpdateRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceUpdateRequest;
import com.cultural.heritage.model.dto.order.BookingOrderQueryRequest;
import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest; import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest;
import com.cultural.heritage.model.entity.*; import com.cultural.heritage.model.entity.*;
import com.cultural.heritage.model.vo.cartService.CartExperienceGoodVO; import com.cultural.heritage.model.vo.cartService.CartExperienceGoodVO;
import com.cultural.heritage.model.vo.cartService.CartExperienceOrderVO; import com.cultural.heritage.model.vo.cartService.CartExperienceOrderVO;
import com.cultural.heritage.model.vo.cartService.CartExperienceVO; import com.cultural.heritage.model.vo.cartService.CartExperienceVO;
import com.cultural.heritage.model.vo.cartService.CartExperienceVOPlus;
import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.common.CommonService;
import com.cultural.heritage.service.good.CartExperienceService; import com.cultural.heritage.service.good.CartExperienceService;
import com.cultural.heritage.service.good.GoodService; import com.cultural.heritage.service.good.GoodService;
import com.cultural.heritage.service.order.PendingServiceGoodService;
import com.cultural.heritage.service.order.PendingServiceOrderService; import com.cultural.heritage.service.order.PendingServiceOrderService;
import com.cultural.heritage.service.user.UserService; import com.cultural.heritage.service.user.UserService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -62,6 +65,10 @@ public class CartExperienceController {
private PendingServiceOrderService pendingServiceOrderService; private PendingServiceOrderService pendingServiceOrderService;
@Resource
private PendingServiceGoodService pendingServiceGoodService;
/** /**
@ -171,7 +178,7 @@ public class CartExperienceController {
*/ */
@PostMapping("/list") @PostMapping("/list")
@Operation(summary = "小程序端用户查询服务类购物车中的商品", description = "参数权限所有人方法名listUserCartRecord") @Operation(summary = "小程序端用户查询服务类购物车中的商品", description = "参数权限所有人方法名listUserCartRecord")
public BaseResponse<List<CartExperienceVO>> listUserCartRecord(HttpServletRequest request) { public BaseResponse<List<CartExperienceVOPlus>> listUserCartRecord(HttpServletRequest request) {
// 根据用户id查询购物车记录 // 根据用户id查询购物车记录
User loginUser = userService.getLoginUser(request); User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId(); Long userId = loginUser.getId();
@ -181,7 +188,45 @@ public class CartExperienceController {
List<CartExperience> cartExperienceList = cartExperienceService.list(queryWrapper); List<CartExperience> cartExperienceList = cartExperienceService.list(queryWrapper);
// 封装用户购物车中的商品信息 // 封装用户购物车中的商品信息
List<CartExperienceVO> cartExperienceVOList = cartExperienceService.transformToCartRecordVOList(cartExperienceList); List<CartExperienceVO> cartExperienceVOList = cartExperienceService.transformToCartRecordVOList(cartExperienceList);
return ResultUtils.success(cartExperienceVOList);
List<PendingServiceGood> pendingServiceGoodList = commonService.findByFieldInTargetField(cartExperienceList, pendingServiceGoodService, CartExperience::getGoodId, "goodId");
List<PendingServiceOrder> pendingServiceOrderList = commonService.findByFieldInTargetField(pendingServiceGoodList, pendingServiceOrderService, PendingServiceGood::getId, "pendingId");
// 封装Map集合服务类商品待处理id预约人数
Map<Long, Integer> 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<String, Integer> bookingNumberMap = new HashMap<>();
for (PendingServiceGood pendingServiceGood : pendingServiceGoodList) {
Long pendingId = pendingServiceGood.getId();
Integer count = countMap.get(pendingId);
Long goodId = pendingServiceGood.getGoodId();
String reservationDate = pendingServiceGood.getReservationDate();
String timeSlot = pendingServiceGood.getTimeSlot();
BookingOrderQueryRequest bookingOrderQueryRequest = new BookingOrderQueryRequest(goodId, reservationDate, timeSlot);
Integer maxNumber = pendingServiceGood.getMaxNumber();
bookingNumberMap.put(bookingOrderQueryRequest.toString(), count == null ? maxNumber : maxNumber - count);
}
List<CartExperienceVOPlus> cartExperienceVOPluses = cartExperienceVOList.stream().map(cartExperienceVO -> {
CartExperienceVOPlus cartExperienceVOPlus = new CartExperienceVOPlus();
BeanUtils.copyProperties(cartExperienceVO, cartExperienceVOPlus);
Long goodId = cartExperienceVO.getGoodId();
String reservationDate = cartExperienceVO.getReservationDate();
String timeSlot = cartExperienceVO.getTimeSlot();
BookingOrderQueryRequest bookingOrderQueryRequest = new BookingOrderQueryRequest(goodId, reservationDate, timeSlot);
Integer restNumber = bookingNumberMap.get(bookingOrderQueryRequest.toString());
cartExperienceVOPlus.setRestNumber(restNumber);
return cartExperienceVOPlus;
}).toList();
return ResultUtils.success(cartExperienceVOPluses);
} }

View File

@ -0,0 +1,55 @@
package com.cultural.heritage.model.vo.cartService;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class CartExperienceVOPlus {
/**
* 购物车记录id
*/
private Long id;
/**
* 商品id
*/
private Long goodId;
/**
* 数量
*/
private Integer quantity;
/**
* 小计
*/
private BigDecimal subtotal;
/**
* 预约日期
*/
private String reservationDate;
/**
* 预约时间段
*/
private String timeSlot;
/**
* 服务类购物车商品详情信息
*/
private CartExperienceGoodVO cartExperienceGoodVO;
/**
* 剩余预约人数
*/
private Integer restNumber;
}

View File

@ -109,11 +109,8 @@ public class CartExperienceServiceImpl extends ServiceImpl<CartExperienceMapper,
@Override @Override
public List<CartExperienceVO> transformToCartRecordVOList(List<CartExperience> cartExperienceList) { public List<CartExperienceVO> transformToCartRecordVOList(List<CartExperience> cartExperienceList) {
// 获取所有商品id // 获取商品列表
List<Long> goodIds = cartExperienceList.stream().map(CartExperience::getGoodId).toList(); List<Good> goodList = commonService.findByFieldInTargetField(cartExperienceList, goodService, CartExperience::getGoodId, "id");
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", goodIds);
List<Good> goodList = goodService.list(queryWrapper);
// 封装map集合商品id, 商品详情信息 // 封装map集合商品id, 商品详情信息
Map<Long, Good> map = new HashMap<>(); Map<Long, Good> map = new HashMap<>();
for (Good good : goodList) { for (Good good : goodList) {

View File

@ -95,11 +95,8 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
@Override @Override
public List<CartRecordVO> transformToCartRecordVOList(List<CartRecord> list) { public List<CartRecordVO> transformToCartRecordVOList(List<CartRecord> list) {
// 获取所有商品id // 获取所有商品列表
List<Long> goodIds = list.stream().map(CartRecord::getGoodId).toList(); List<Good> goodList = commonService.findByFieldInTargetField(list, goodService, CartRecord::getGoodId, "id");
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", goodIds);
List<Good> goodList = goodService.list(queryWrapper);
// 封装map集合商品id, 商品详情信息 // 封装map集合商品id, 商品详情信息
Map<Long, Good> map = new HashMap<>(); Map<Long, Good> map = new HashMap<>();
for (Good good : goodList) { for (Good good : goodList) {