diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index 09b8dfe..fc271e2 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -10,13 +10,13 @@ import com.cultural.heritage.common.ResultUtils; import com.cultural.heritage.constant.UserConstant; import com.cultural.heritage.exception.BusinessException; import com.cultural.heritage.exception.ThrowUtils; -import com.cultural.heritage.model.dto.CommonRequest; import com.cultural.heritage.model.dto.order.OrderAddRequest; import com.cultural.heritage.model.dto.order.OrderItemAddRequest; import com.cultural.heritage.model.dto.order.OrderQueryRequest; import com.cultural.heritage.model.dto.order.OrderUpdateRequest; import com.cultural.heritage.model.entity.Order; import com.cultural.heritage.model.entity.OrderItems; +import com.cultural.heritage.model.vo.OrderVO; import com.cultural.heritage.service.order.OrderItemService; import com.cultural.heritage.service.order.OrderService; import io.swagger.v3.oas.annotations.Operation; @@ -97,7 +97,7 @@ public class OrderController { @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @Operation(summary = "小程序端创建用户订单", description = "参数:订单创建请求体,排序字段 sortField: totalAmount,权限:所有人,方法名:addOrder") - public BaseResponse addOrder(@RequestBody OrderAddRequest orderAddRequest) { + public BaseResponse addOrder(@RequestBody OrderAddRequest orderAddRequest) { if (orderAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } @@ -117,20 +117,20 @@ public class OrderController { }).toList(); boolean save = orderItemService.saveBatch(newOrderItemsList); ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR); - return ResultUtils.success(true); + return ResultUtils.success(id); } /** - * 分页查询所有订单 + * 分页查询所有订单(包括订单明细) * @param orderQueryRequest 订单查询请求体 * @return 订单列表信息 */ @PostMapping("/list/page") @Operation(summary = "Web端管理员分页查询订单", description = "参数:订单查询请求体,权限:管理员(admin, boss),方法名:listOrder") @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse> listOrder(@RequestBody OrderQueryRequest orderQueryRequest) { + public BaseResponse> listOrder(@RequestBody OrderQueryRequest orderQueryRequest) { if (orderQueryRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } @@ -138,30 +138,43 @@ public class OrderController { long pageSize = orderQueryRequest.getPageSize(); Page page = orderService.page(new Page<>(current, pageSize), orderService.getQueryWrapper(orderQueryRequest)); - return ResultUtils.success(page); + List orders = page.getRecords(); + List orderVOS = orders.stream().map(order -> { + OrderVO orderVO = new OrderVO(); + BeanUtils.copyProperties(order, orderVO); + return orderVO; + }).toList(); + orderVOS.forEach(orderVO -> { + Long id = orderVO.getId(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("orderId", id); + List list = orderItemService.list(queryWrapper); + orderVO.setOrderItemList(list); + }); + return ResultUtils.success(orderVOS); } - - /** - * 查询当前订单的订单明细 - * @param orderIdRequest 订单编号请求体 - * @return 订单明细列表信息 - */ - @PostMapping("/list/item") - @Operation(summary = "Web端管理员查询订单明细", description = "参数:订单编号请求体,权限:管理员(admin, boss),方法名:listOrderItem") - @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) - public BaseResponse> listOrderItem(@RequestBody CommonRequest orderIdRequest) { - if (orderIdRequest == null || orderIdRequest.getId() <= 0) { - throw new BusinessException(ErrorCode.PARAMS_ERROR); - } - Long id = orderIdRequest.getId(); - QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("orderId", id); - List list = orderItemService.list(queryWrapper); - return ResultUtils.success(list); - } - +// +// /** +// * 查询当前订单的订单明细 +// * @param orderIdRequest 订单编号请求体 +// * @return 订单明细列表信息 +// */ +// @PostMapping("/list/item") +// @Operation(summary = "Web端管理员查询订单明细", description = "参数:订单编号请求体,权限:管理员(admin, boss),方法名:listOrderItem") +// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) +// public BaseResponse> listOrderItem(@RequestBody CommonRequest orderIdRequest) { +// if (orderIdRequest == null || orderIdRequest.getId() <= 0) { +// throw new BusinessException(ErrorCode.PARAMS_ERROR); +// } +// Long id = orderIdRequest.getId(); +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("orderId", id); +// List list = orderItemService.list(queryWrapper); +// return ResultUtils.success(list); +// } +// diff --git a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java index 3eaf95d..991466c 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/OrderQueryRequest.java @@ -20,6 +20,15 @@ public class OrderQueryRequest extends PageRequest implements Serializable { @Schema(description = "用户id(id > 0)", example = "2") private Long userId; + + + /** + * 订单id + */ + @Schema(description = "订单id(id > 0)", example = "2") + private Long orderId; + + /** * 订单编号 */ diff --git a/src/main/java/com/cultural/heritage/model/vo/OrderVO.java b/src/main/java/com/cultural/heritage/model/vo/OrderVO.java new file mode 100644 index 0000000..1db7f21 --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/vo/OrderVO.java @@ -0,0 +1,78 @@ +package com.cultural.heritage.model.vo; + + +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 com.cultural.heritage.model.entity.OrderItems; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +@Data +public class OrderVO implements Serializable { + + + /** + * 订单id + */ + private Long id; + + /** + * 用户id + */ + private Long userId; + + + /** + * 用户昵称 + */ + private String userName; + + /** + * 订单编号 + */ + private String orderNumber; + + + /** + * 地址信息快照 + */ + private AddressSnapshot addressSnapshot; + + + /** + * 联系人信息快照 + */ + private ContactsSnapshot contactsSnapshot; + + + /** + * 优惠券信息快照 + */ + private CouponSnapshot couponSnapshot; + + + /** + * 订单总金额 + */ + private Double totalAmount; + + /** + * 订单状态 + */ + private String orderStatus; + + + /** + * 订单明细信息 + */ + private List orderItemList; + + + + @Serial + private static final long serialVersionUID = 1L; +} \ No newline at end of file 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 index 95d69fc..4e9fefc 100644 --- a/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/order/impl/OrderServiceImpl.java @@ -29,6 +29,7 @@ public class OrderServiceImpl extends ServiceImpl implements throw new BusinessException(ErrorCode.PARAMS_ERROR); } Long userId = orderQueryRequest.getUserId(); + Long orderId = orderQueryRequest.getOrderId(); Double minTotalAmount = orderQueryRequest.getMinTotalAmount(); Double maxTotalAmount = orderQueryRequest.getMaxTotalAmount(); String orderStatus = orderQueryRequest.getOrderStatus(); @@ -39,6 +40,7 @@ public class OrderServiceImpl extends ServiceImpl implements String sortField = orderQueryRequest.getSortField(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId); + queryWrapper.eq(ObjectUtils.isNotEmpty(orderId), "id", orderId); queryWrapper.ge(ObjectUtils.isNotEmpty(minTotalAmount), "totalAmount", minTotalAmount); queryWrapper.le(ObjectUtils.isNotEmpty(maxTotalAmount), "totalAmount", maxTotalAmount); queryWrapper.eq(StringUtils.isNotBlank(orderStatus), "orderStatus", orderStatus);