完善了订单类

This commit is contained in:
chen-xin-zhi 2024-11-02 20:39:54 +08:00
parent 3ff932ea7e
commit e11512cdaf
15 changed files with 170 additions and 11 deletions

View File

@ -148,8 +148,12 @@
<artifactId>hutool-all</artifactId>
<version>5.8.26</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -114,7 +114,7 @@ public class CategoryController {
* @return 当前类别的商品列表
*/
@PostMapping("/list/type")
public BaseResponse<Map<Category, List<Good>>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest) {
public BaseResponse<Map<Long, List<Good>>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest) {
if (categoryQueryRequest == null || categoryQueryRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
@ -125,11 +125,13 @@ public class CategoryController {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
List<Good> goodList = goodService.getGoodListByTypeName(typeName);
Map<Category, List<Good>> map = new HashMap<>();
map.put(category, goodList);
Map<Long, List<Good>> map = new HashMap<>();
map.put(id, goodList);
return ResultUtils.success(map);
}
}

View File

@ -0,0 +1,59 @@
package com.cultural.heritage.controller.order;
import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.order.OrderAddRequest;
import com.cultural.heritage.model.entity.Order;
import com.cultural.heritage.service.order.OrderService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/order")
@Slf4j
@Tag(name = "订单接口")
public class OrderController {
@Resource
private OrderService orderService;
/**
* 用户创建订单
* @param orderAddRequest 订单创建请求体
* @return 是否创建成功
*/
@PostMapping("/add")
public BaseResponse<Boolean> addOrder(@RequestBody OrderAddRequest orderAddRequest) {
if (orderAddRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Order order = new Order();
BeanUtils.copyProperties(orderAddRequest, order);
boolean save = orderService.save(order);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* 查询所有订单
* @return
*/
@PostMapping("/list")
public BaseResponse<List<Order>> listOrder() {
List<Order> list = orderService.list();
return ResultUtils.success(list);
}
}

View File

@ -0,0 +1,7 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.OrderItem;
public interface OrderItemMapper extends BaseMapper<OrderItem> {
}

View File

@ -0,0 +1,7 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.Order;
public interface OrderMapper extends BaseMapper<Order> {
}

View File

@ -0,0 +1,52 @@
package com.cultural.heritage.model.dto.order;
import com.cultural.heritage.model.dto.snapshot.AddressSnapshot;
import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot;
import com.cultural.heritage.model.dto.snapshot.CouponSnapshot;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class OrderAddRequest implements Serializable {
/**
* 用户id
*/
private Long userId;
/**
* 地址信息快照
*/
private AddressSnapshot addressSnapshot;
/**
* 联系人信息快照
*/
private ContactsSnapshot contactsSnapshot;
/**
* 优惠券信息快照
*/
private CouponSnapshot couponSnapshot;
/**
* 订单总金额
*/
private Double totalAmount;
/**
* 订单状态
*/
private String orderStatus;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,12 +1,9 @@
package com.cultural.heritage.model.dto.snapshot;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
@Data
public class AddressSnapshot implements Serializable {

View File

@ -9,6 +9,7 @@ import java.util.Date;
@Data
public class CouponSnapshot implements Serializable {
/**
* 优惠券名称
*/
@ -52,6 +53,7 @@ public class CouponSnapshot implements Serializable {
private String description;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,13 +1,9 @@
package com.cultural.heritage.model.dto.snapshot;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
@Data
public class GoodSnapshot implements Serializable {

View File

@ -1,8 +1,10 @@
package com.cultural.heritage.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.cultural.heritage.model.dto.snapshot.AddressSnapshot;
import com.cultural.heritage.model.dto.snapshot.ContactsSnapshot;
import com.cultural.heritage.model.dto.snapshot.CouponSnapshot;
@ -19,7 +21,7 @@ import java.util.Date;
* @TableName order_total
*/
@Data
@TableName("order_total")
@TableName(value = "order_total", autoResultMap = true)
public class Order implements Serializable {
@ -39,17 +41,20 @@ public class Order implements Serializable {
/**
* 地址信息快照
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private AddressSnapshot addressSnapshot;
/**
* 联系人信息快照
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private ContactsSnapshot contactsSnapshot;
/**
* 优惠券信息快照
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private CouponSnapshot couponSnapshot;

View File

@ -2,6 +2,7 @@ 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 com.cultural.heritage.model.dto.snapshot.GoodSnapshot;
import lombok.Data;
@ -13,6 +14,7 @@ import java.io.Serializable;
* @TableName order_item
*/
@Data
@TableName("order_item")
public class OrderItem implements Serializable {
/**

View File

@ -0,0 +1,7 @@
package com.cultural.heritage.service.order;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.Order;
public interface OrderService extends IService<Order> {
}

View File

@ -0,0 +1,11 @@
package com.cultural.heritage.service.order.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.mapper.OrderMapper;
import com.cultural.heritage.model.entity.Order;
import com.cultural.heritage.service.order.OrderService;
import org.springframework.stereotype.Service;
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
}

View File

@ -27,6 +27,7 @@ server:
cookie:
max-age: 2592000
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:

View File

@ -0,0 +1,7 @@
<?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.OrderMapper">
</mapper>