完善了订单信息
This commit is contained in:
parent
d065219e71
commit
791b8009be
|
@ -10,8 +10,13 @@ import com.cultural.heritage.model.dto.CommonRequest;
|
|||
import com.cultural.heritage.model.dto.cart.CartRecordAddRequest;
|
||||
import com.cultural.heritage.model.dto.cart.CartRecordUpdateRequest;
|
||||
import com.cultural.heritage.model.entity.CartRecord;
|
||||
import com.cultural.heritage.model.entity.Good;
|
||||
import com.cultural.heritage.model.vo.CartOrderVO;
|
||||
import com.cultural.heritage.model.vo.CartRecordQueryVO;
|
||||
import com.cultural.heritage.model.vo.CartRecordVO;
|
||||
import com.cultural.heritage.model.vo.GoodVO;
|
||||
import com.cultural.heritage.service.good.CartRecordService;
|
||||
import com.cultural.heritage.service.good.GoodService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -36,6 +41,9 @@ public class CartRecordController {
|
|||
private CartRecordService cartRecordService;
|
||||
|
||||
|
||||
@Resource
|
||||
private GoodService goodService;
|
||||
|
||||
/**
|
||||
* 用户添加商品至购物车
|
||||
* @param cartRecordAddRequest 购物车记录添加请求体
|
||||
|
@ -112,6 +120,31 @@ public class CartRecordController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 展示用户批量购买后的订单信息
|
||||
* @param cartRecordQueryVOList 订单商品查询列表
|
||||
* @return 订单商品信息列表
|
||||
*/
|
||||
@PostMapping("/cart/list")
|
||||
public BaseResponse<List<CartOrderVO>> listCartRecord(@RequestBody List<CartRecordQueryVO> cartRecordQueryVOList) {
|
||||
if (cartRecordQueryVOList == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
List<CartOrderVO> cartOrderVOList = cartRecordQueryVOList.stream().map(cartRecordQueryVO -> {
|
||||
Long goodId = cartRecordQueryVO.getGoodId();
|
||||
Integer quantity = cartRecordQueryVO.getQuantity();
|
||||
Good good = goodService.getById(goodId);
|
||||
ThrowUtils.throwIf(good == null, ErrorCode.OPERATION_ERROR, "找不到该商品");
|
||||
CartOrderVO cartOrderVO = new CartOrderVO();
|
||||
GoodVO goodVO = new GoodVO();
|
||||
BeanUtils.copyProperties(good, goodVO);
|
||||
|
||||
cartOrderVO.setGoodVO(goodVO);
|
||||
cartOrderVO.setQuantity(quantity);
|
||||
return cartOrderVO;
|
||||
}).toList();
|
||||
return ResultUtils.success(cartOrderVOList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,10 +18,8 @@ import com.cultural.heritage.model.dto.good.GoodQueryRequest;
|
|||
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
|
||||
import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest;
|
||||
import com.cultural.heritage.model.entity.AppointmentDate;
|
||||
import com.cultural.heritage.model.entity.AppointmentNumber;
|
||||
import com.cultural.heritage.model.entity.Good;
|
||||
import com.cultural.heritage.service.good.AppointmentDateService;
|
||||
import com.cultural.heritage.service.good.AppointmentNumberService;
|
||||
import com.cultural.heritage.service.good.GoodService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
@ -50,9 +48,6 @@ public class GoodController {
|
|||
private GoodService goodService;
|
||||
|
||||
|
||||
@Resource
|
||||
private AppointmentNumberService appointmentNumberService;
|
||||
|
||||
|
||||
@Resource
|
||||
private AppointmentDateService appointmentDateService;
|
||||
|
@ -98,14 +93,7 @@ public class GoodController {
|
|||
boolean save = goodService.save(good);
|
||||
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
|
||||
|
||||
// 向预约人数范围表插入服务类商品的预约人数信息
|
||||
Long id = good.getId();
|
||||
AppointmentNumber appointmentNumber = new AppointmentNumber();
|
||||
BeanUtils.copyProperties(serviceGoodAddRequest, appointmentNumber);
|
||||
appointmentNumber.setGoodId(id);
|
||||
boolean result = appointmentNumberService.save(appointmentNumber);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
|
||||
// 向预约日期表中批量插入服务类商品的预约信息
|
||||
List<AppointmentDateAddRequest> appointmentDateAddRequestList = serviceGoodAddRequest.getAppointmentDateAddRequestList();
|
||||
List<AppointmentDate> appointmentDates = appointmentDateAddRequestList.stream().map(appointmentDateAddRequest -> {
|
||||
|
@ -158,12 +146,6 @@ public class GoodController {
|
|||
boolean result = goodService.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
|
||||
// 删除预约人数范围表中与该商品关联的记录
|
||||
QueryWrapper<AppointmentNumber> numberQueryWrapper = new QueryWrapper<>();
|
||||
numberQueryWrapper.eq("goodId", id);
|
||||
boolean remove = appointmentNumberService.remove(numberQueryWrapper);
|
||||
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR);
|
||||
|
||||
// 删除预约日期表中与该商品关联的记录
|
||||
QueryWrapper<AppointmentDate> dateQueryWrapper = new QueryWrapper<>();
|
||||
dateQueryWrapper.eq("goodId", id);
|
||||
|
@ -253,4 +235,7 @@ public class GoodController {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.cultural.heritage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cultural.heritage.model.entity.AppointmentNumber;
|
||||
|
||||
public interface AppointmentNumberMapper extends BaseMapper<AppointmentNumber> {
|
||||
}
|
|
@ -7,7 +7,7 @@ import java.io.Serial;
|
|||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Schema(description = "预约日期请求体", requiredProperties = {"specificDate", "timeSlot", "isAvailable"})
|
||||
@Schema(description = "预约日期请求体", requiredProperties = {"specificDate", "timeSlot", "isAvailable", "minNumber", "maxNumber"})
|
||||
public class AppointmentDateAddRequest implements Serializable {
|
||||
|
||||
|
||||
|
@ -32,6 +32,20 @@ public class AppointmentDateAddRequest implements Serializable {
|
|||
private Integer isAvailable;
|
||||
|
||||
|
||||
/**
|
||||
* 最小预约人数
|
||||
*/
|
||||
@Schema(description = "最小预约人数", example = "5")
|
||||
private Integer minNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 最大预约人数
|
||||
*/
|
||||
@Schema(description = "最大预约人数", example = "10")
|
||||
private Integer maxNumber;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -10,26 +10,12 @@ import java.io.Serializable;
|
|||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "服务类商品添加请求体", requiredProperties = {"minNumber", "maxNumber", "appointmentDateAddRequestList"})
|
||||
@Schema(description = "服务类商品添加请求体", requiredProperties = {"appointmentDateAddRequestList"})
|
||||
public class ServiceGoodAddRequest extends GoodAddRequest implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 最小预约人数
|
||||
*/
|
||||
@Schema(description = "最小预约人数", example = "5")
|
||||
private Integer minNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 最大预约人数
|
||||
*/
|
||||
@Schema(description = "最大预约人数", example = "10")
|
||||
private Integer maxNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 未来n个月的预约详情
|
||||
* 未来几天的预约详情
|
||||
*/
|
||||
@Schema(description = "未来n个月的预约详情")
|
||||
private List<AppointmentDateAddRequest> appointmentDateAddRequestList;
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AppointmentDate implements Serializable {
|
|||
|
||||
|
||||
/**
|
||||
* 具体日期
|
||||
* 预约具体日期
|
||||
*/
|
||||
private String specificDate;
|
||||
|
||||
|
@ -41,6 +41,17 @@ public class AppointmentDate implements Serializable {
|
|||
*/
|
||||
private Integer isAvailable;
|
||||
|
||||
/**
|
||||
* 最小预约人数
|
||||
*/
|
||||
private Integer minNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 最大预约人数
|
||||
*/
|
||||
private Integer maxNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package com.cultural.heritage.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 预约人数范围表
|
||||
* @TableName appointment_number
|
||||
*/
|
||||
@Data
|
||||
@TableName("appointment_number")
|
||||
public class AppointmentNumber implements Serializable {
|
||||
|
||||
/**
|
||||
* 预约人数范围id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 最小预约人数
|
||||
*/
|
||||
private Integer minNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 最大预约人数
|
||||
*/
|
||||
private Integer maxNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long goodId;
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.cultural.heritage.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CartOrderVO implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 商品详细信息
|
||||
*/
|
||||
private GoodVO goodVO;
|
||||
|
||||
|
||||
/**
|
||||
* 商品购买数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.cultural.heritage.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CartRecordQueryVO implements Serializable {
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long goodId;
|
||||
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.cultural.heritage.service.good;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cultural.heritage.model.entity.AppointmentNumber;
|
||||
|
||||
public interface AppointmentNumberService extends IService<AppointmentNumber> {
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cultural.heritage.service.good.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cultural.heritage.mapper.AppointmentNumberMapper;
|
||||
import com.cultural.heritage.model.entity.AppointmentNumber;
|
||||
import com.cultural.heritage.service.good.AppointmentNumberService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AppointmentNumberServiceImpl extends ServiceImpl<AppointmentNumberMapper, AppointmentNumber> implements AppointmentNumberService {
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cultural.heritage.mapper.AppointmentNumberMapper">
|
||||
|
||||
</mapper>
|
|
@ -16,5 +16,7 @@ public class Test {
|
|||
|
||||
// System.out.println(StringUtils.isBlank(null));
|
||||
|
||||
double num = 3.1415926;
|
||||
System.out.printf("%.2f", num); // 输出:3.14
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user