From e11512cdaf44966b5ebdeb36b20c62f11c9d4b5f Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Sat, 2 Nov 2024 20:39:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++ .../controller/good/CategoryController.java | 8 ++- .../controller/order/OrderController.java | 59 +++++++++++++++++++ .../heritage/mapper/OrderItemMapper.java | 7 +++ .../cultural/heritage/mapper/OrderMapper.java | 7 +++ .../model/dto/order/OrderAddRequest.java | 52 ++++++++++++++++ .../model/dto/snapshot/AddressSnapshot.java | 3 - .../model/dto/snapshot/CouponSnapshot.java | 2 + .../model/dto/snapshot/GoodSnapshot.java | 4 -- .../cultural/heritage/model/entity/Order.java | 7 ++- .../heritage/model/entity/OrderItem.java | 2 + .../heritage/service/order/OrderService.java | 7 +++ .../service/order/impl/OrderServiceImpl.java | 11 ++++ src/main/resources/application.yml | 1 + src/main/resources/mapper/OrderMapper.xml | 7 +++ 15 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/cultural/heritage/controller/order/OrderController.java create mode 100644 src/main/java/com/cultural/heritage/mapper/OrderItemMapper.java create mode 100644 src/main/java/com/cultural/heritage/mapper/OrderMapper.java create mode 100644 src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java create mode 100644 src/main/java/com/cultural/heritage/service/order/OrderService.java create mode 100644 src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java create mode 100644 src/main/resources/mapper/OrderMapper.xml diff --git a/pom.xml b/pom.xml index c875b77..04c6d20 100644 --- a/pom.xml +++ b/pom.xml @@ -148,8 +148,12 @@ hutool-all 5.8.26 + + + + diff --git a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java index 9a81f81..2d86143 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java @@ -114,7 +114,7 @@ public class CategoryController { * @return 当前类别的商品列表 */ @PostMapping("/list/type") - public BaseResponse>> listGoodByCategory(@RequestBody CommonRequest categoryQueryRequest) { + public BaseResponse>> 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 goodList = goodService.getGoodListByTypeName(typeName); - Map> map = new HashMap<>(); - map.put(category, goodList); + Map> map = new HashMap<>(); + map.put(id, goodList); return ResultUtils.success(map); } + + } diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java new file mode 100644 index 0000000..9f2d3f1 --- /dev/null +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -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 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> listOrder() { + List list = orderService.list(); + return ResultUtils.success(list); + } +} diff --git a/src/main/java/com/cultural/heritage/mapper/OrderItemMapper.java b/src/main/java/com/cultural/heritage/mapper/OrderItemMapper.java new file mode 100644 index 0000000..af78139 --- /dev/null +++ b/src/main/java/com/cultural/heritage/mapper/OrderItemMapper.java @@ -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 { +} diff --git a/src/main/java/com/cultural/heritage/mapper/OrderMapper.java b/src/main/java/com/cultural/heritage/mapper/OrderMapper.java new file mode 100644 index 0000000..b11fa30 --- /dev/null +++ b/src/main/java/com/cultural/heritage/mapper/OrderMapper.java @@ -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 { +} diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java new file mode 100644 index 0000000..31c7e19 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderAddRequest.java @@ -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; +} diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java index f2caf13..8ad2862 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/AddressSnapshot.java @@ -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 { diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java index 9b566b7..2fe5743 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/CouponSnapshot.java @@ -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; } diff --git a/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java b/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java index c97bccf..82d18bd 100644 --- a/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java +++ b/src/main/java/com/cultural/heritage/model/dto/snapshot/GoodSnapshot.java @@ -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 { diff --git a/src/main/java/com/cultural/heritage/model/entity/Order.java b/src/main/java/com/cultural/heritage/model/entity/Order.java index 654f0eb..e1ca02e 100644 --- a/src/main/java/com/cultural/heritage/model/entity/Order.java +++ b/src/main/java/com/cultural/heritage/model/entity/Order.java @@ -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; diff --git a/src/main/java/com/cultural/heritage/model/entity/OrderItem.java b/src/main/java/com/cultural/heritage/model/entity/OrderItem.java index 3119963..a39dcf0 100644 --- a/src/main/java/com/cultural/heritage/model/entity/OrderItem.java +++ b/src/main/java/com/cultural/heritage/model/entity/OrderItem.java @@ -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 { /** diff --git a/src/main/java/com/cultural/heritage/service/order/OrderService.java b/src/main/java/com/cultural/heritage/service/order/OrderService.java new file mode 100644 index 0000000..c43f11a --- /dev/null +++ b/src/main/java/com/cultural/heritage/service/order/OrderService.java @@ -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 { +} diff --git a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java new file mode 100644 index 0000000..2e11143 --- /dev/null +++ b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java @@ -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 implements OrderService { +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0fc2a7b..a2b213b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,6 +27,7 @@ server: cookie: max-age: 2592000 + mybatis-plus: mapper-locations: classpath:mapper/*.xml configuration: diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderMapper.xml new file mode 100644 index 0000000..8001bea --- /dev/null +++ b/src/main/resources/mapper/OrderMapper.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file