修改了商品类别接口

This commit is contained in:
chen-xin-zhi 2024-11-06 01:15:18 +08:00
parent c19164fd08
commit e63b31e637
4 changed files with 128 additions and 26 deletions

View File

@ -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<Boolean> addOrder(@RequestBody OrderAddRequest orderAddRequest) {
public BaseResponse<Long> 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<Page<Order>> listOrder(@RequestBody OrderQueryRequest orderQueryRequest) {
public BaseResponse<List<OrderVO>> 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<Order> page = orderService.page(new Page<>(current, pageSize),
orderService.getQueryWrapper(orderQueryRequest));
return ResultUtils.success(page);
List<Order> orders = page.getRecords();
List<OrderVO> orderVOS = orders.stream().map(order -> {
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(order, orderVO);
return orderVO;
}).toList();
orderVOS.forEach(orderVO -> {
Long id = orderVO.getId();
QueryWrapper<OrderItems> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("orderId", id);
List<OrderItems> 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<List<OrderItems>> listOrderItem(@RequestBody CommonRequest orderIdRequest) {
if (orderIdRequest == null || orderIdRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = orderIdRequest.getId();
QueryWrapper<OrderItems> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("orderId", id);
List<OrderItems> 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<List<OrderItems>> listOrderItem(@RequestBody CommonRequest orderIdRequest) {
// if (orderIdRequest == null || orderIdRequest.getId() <= 0) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
// }
// Long id = orderIdRequest.getId();
// QueryWrapper<OrderItems> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("orderId", id);
// List<OrderItems> list = orderItemService.list(queryWrapper);
// return ResultUtils.success(list);
// }
//

View File

@ -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;
/**
* 订单编号
*/

View File

@ -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<OrderItems> orderItemList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -29,6 +29,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> 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<OrderMapper, Order> implements
String sortField = orderQueryRequest.getSortField();
QueryWrapper<Order> 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);