苍穹外卖 各状态的订单数量统计
OrderController
/*** 各状态的订单数量统计** @return*/@GetMapping("/statistics")@ApiOperation("各状态的订单数量统计")// statistic v.统计public Result<OrderStatisticsVO> statistics() {OrderStatisticsVO orderStatisticsVO = orderService.statistics();return Result.success(orderStatisticsVO);}
OrderService
/*** 各状态的订单数量统计** @return*/@Overridepublic 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 orderStatisticsVO = new OrderStatisticsVO();orderStatisticsVO.setToBeConfirmed(toBeConfirmed);orderStatisticsVO.setConfirmed(confirmed);orderStatisticsVO.setDeliveryInProgress(deliveryInProgress);return orderStatisticsVO;}
OrderMapper
/*** 各状态的订单数量统计** @param toBeConfirmed* @return*/@Select("select count(id) from orders where status = #{status}")Integer countStatus(Integer toBeConfirmed);