文章目录
- 商家端订单管理模块:
- 订单搜索
- OrderController
- OrderService
- OrderServiceImpl
- 各个状态的订单数量统计
- OrderController
- OrderService
- OrderServiceImpl
- orderMapper
- 查询订单详情
-
- 接单
- OrderController
- OrderServiceImpl
商家端订单管理模块:
订单搜索
OrderController
@GetMapping("/conditionSearch")
@ApiOperation(value = "订单搜索")
public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
return Result.success(pageResult);
}
OrderService
PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);
OrderServiceImpl
@Override
public PageResult conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
Page<Orders> page = new Page<>(ordersPageQueryDTO.getPage(), ordersPageQueryDTO.getPageSize());
LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
if (ordersPageQueryDTO.getStatus() != null) {
queryWrapper.eq(Orders::getStatus, ordersPageQueryDTO.getStatus());
}
if (ordersPageQueryDTO.getNumber() != null && !ordersPageQueryDTO.getNumber().isEmpty()) {
queryWrapper.like(Orders::getNumber, ordersPageQueryDTO.getNumber());
}
if (ordersPageQueryDTO.getPhone() != null && !ordersPageQueryDTO.getPhone().isEmpty()) {
queryWrapper.like(Orders::getPhone, ordersPageQueryDTO.getPhone());
}
if (ordersPageQueryDTO.getBeginTime() != null) {
queryWrapper.ge(Orders::getOrderTime, ordersPageQueryDTO.getBeginTime());
}
if (ordersPageQueryDTO.getEndTime() != null) {
queryWrapper.le(Orders::getOrderTime, ordersPageQueryDTO.getEndTime());
}
Page<Orders> ordersPage = orderMapper.selectPage(page, queryWrapper);
List<OrderVO> orderVOList = getOrderVOList(ordersPage);
return new PageResult(page.getTotal(), orderVOList);
}
private List<OrderVO> getOrderVOList(Page<Orders> page) {
List<OrderVO> orderVOList = new ArrayList<>();
List<Orders> ordersList = page.getRecords();
if (!CollectionUtils.isEmpty(ordersList)) {
for (Orders orders : ordersList) {
OrderVO orderVO = new OrderVO();
BeanUtils.copyProperties(orders, orderVO);
String orderDishes = getOrderDishesStr(orders);
orderVO.setOrderDishes(orderDishes);
orderVOList.add(orderVO);
}
}
return orderVOList;
}
private String getOrderDishesStr(Orders orders) {
LambdaQueryWrapper<OrderDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OrderDetail::getOrderId, orders.getId());
List<OrderDetail> orderDetailList = orderDetailMapper.selectList(queryWrapper);
List<String> orderDishList = orderDetailList.stream().map(x -> {
String orderDish = x.getName() + "*" + x.getNumber() + ";";
return orderDish;
}).toList();
return String.join("", orderDishList);
}
各个状态的订单数量统计
OrderController
@GetMapping("/statistics")
@ApiOperation("各个状态的订单数量统计")
public Result<OrderStatisticsVO> statistics() {
OrderStatisticsVO orderStatisticsVO = orderService.statistics();
return Result.success(orderStatisticsVO);
}
OrderService
OrderStatisticsVO statistics();
OrderServiceImpl
@Override
public OrderStatisticsVO statistics() {
Integer toBeConfirmed = orderMapper.countStatus(Orders.TO_BE_CONFIRMED);
Integer confirmed = orderMapper.countStatus(Orders.CONFIRMED);
Integer deliveryInProgress = orderMapper.countStatus(Orders.DELIVERY_IN_PROGRESS);
OrderStatisticsVO orderStatisticsVO = new OrderStatisticsVO();
orderStatisticsVO.setToBeConfirmed(toBeConfirmed);
orderStatisticsVO.setConfirmed(confirmed);
orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);
return orderStatisticsVO;
}
orderMapper
@Select("select count(id) from orders where status = #{status}")
Integer countStatus(Integer toBeConfirmed);
查询订单详情
OrderController
@GetMapping("/details/{id}")
@ApiOperation("订单详情")
public Result<OrderVO> details(@PathVariable Long id) {
OrderVO orderVO = orderService.details(id);
return Result.success(orderVO);
}
接单
OrderController
@PutMapping("/confirm")
@ApiOperation("接单")
public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
orderService.confirm(ordersConfirmDTO);
return Result.success();
}
### OrderService
```java
void confirm(OrdersConfirmDTO ordersConfirmDTO);
OrderServiceImpl
@Override
public void confirm(OrdersConfirmDTO ordersConfirmDTO) {
Orders orders = Orders.builder()
.id(ordersConfirmDTO.getId())
.status(Orders.CONFIRMED)
.build();
orderMapper.updateById(orders);
}