更新了优惠券模块
This commit is contained in:
parent
c21e809108
commit
dc43642574
|
@ -10,14 +10,17 @@ import com.cultural.heritage.exception.ThrowUtils;
|
|||
import com.cultural.heritage.model.dto.CommonBatchRequest;
|
||||
import com.cultural.heritage.model.dto.cartService.CartExperienceAddRequest;
|
||||
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.entity.*;
|
||||
import com.cultural.heritage.model.vo.cartService.CartExperienceGoodVO;
|
||||
import com.cultural.heritage.model.vo.cartService.CartExperienceOrderVO;
|
||||
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.good.CartExperienceService;
|
||||
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.user.UserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -62,6 +65,10 @@ public class CartExperienceController {
|
|||
private PendingServiceOrderService pendingServiceOrderService;
|
||||
|
||||
|
||||
@Resource
|
||||
private PendingServiceGoodService pendingServiceGoodService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -171,7 +178,7 @@ public class CartExperienceController {
|
|||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "小程序端用户查询服务类购物车中的商品", description = "参数:无,权限:所有人,方法名:listUserCartRecord")
|
||||
public BaseResponse<List<CartExperienceVO>> listUserCartRecord(HttpServletRequest request) {
|
||||
public BaseResponse<List<CartExperienceVOPlus>> listUserCartRecord(HttpServletRequest request) {
|
||||
// 根据用户id查询购物车记录
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long userId = loginUser.getId();
|
||||
|
@ -181,7 +188,45 @@ public class CartExperienceController {
|
|||
List<CartExperience> cartExperienceList = cartExperienceService.list(queryWrapper);
|
||||
// 封装用户购物车中的商品信息
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
|
@ -109,11 +109,8 @@ public class CartExperienceServiceImpl extends ServiceImpl<CartExperienceMapper,
|
|||
@Override
|
||||
public List<CartExperienceVO> transformToCartRecordVOList(List<CartExperience> cartExperienceList) {
|
||||
|
||||
// 获取所有商品id
|
||||
List<Long> goodIds = cartExperienceList.stream().map(CartExperience::getGoodId).toList();
|
||||
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", goodIds);
|
||||
List<Good> goodList = goodService.list(queryWrapper);
|
||||
// 获取商品列表
|
||||
List<Good> goodList = commonService.findByFieldInTargetField(cartExperienceList, goodService, CartExperience::getGoodId, "id");
|
||||
// 封装map集合(键:商品id, 值:商品详情信息)
|
||||
Map<Long, Good> map = new HashMap<>();
|
||||
for (Good good : goodList) {
|
||||
|
|
|
@ -95,11 +95,8 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
|
|||
@Override
|
||||
public List<CartRecordVO> transformToCartRecordVOList(List<CartRecord> list) {
|
||||
|
||||
// 获取所有商品id
|
||||
List<Long> goodIds = list.stream().map(CartRecord::getGoodId).toList();
|
||||
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("id", goodIds);
|
||||
List<Good> goodList = goodService.list(queryWrapper);
|
||||
// 获取所有商品列表
|
||||
List<Good> goodList = commonService.findByFieldInTargetField(list, goodService, CartRecord::getGoodId, "id");
|
||||
// 封装map集合(键:商品id, 值:商品详情信息)
|
||||
Map<Long, Good> map = new HashMap<>();
|
||||
for (Good good : goodList) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user