feat(health):新增统计不同订单状态订单的数量的功能
This commit is contained in:
parent
db85c197a8
commit
9d3d19ef7a
@ -1,12 +1,15 @@
|
||||
package com.jzo2o.health.controller.admin;
|
||||
|
||||
import com.jzo2o.health.model.dto.response.OrdersCountResDTO;
|
||||
import com.jzo2o.health.service.IOrderManagerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author itcast
|
||||
*/
|
||||
@ -14,10 +17,12 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/admin/orders")
|
||||
@Api(tags = "管理端 - 根据状态统计订单数量")
|
||||
public class OrdersStatsController {
|
||||
@Resource
|
||||
private IOrderManagerService orderManagerService;
|
||||
|
||||
@GetMapping("/countByStatus")
|
||||
@ApiOperation("根据状态统计数量")
|
||||
public OrdersCountResDTO countByStatus() {
|
||||
return null;
|
||||
return orderManagerService.countByStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@ import com.jzo2o.health.model.dto.OrderCountDTO;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -17,7 +16,6 @@ import java.util.Map;
|
||||
* @since 2023-11-02
|
||||
*/
|
||||
public interface OrdersMapper extends BaseMapper<Orders> {
|
||||
|
||||
@Select("SELECT order_status AS orderStatus,COUNT(id) AS count FROM orders GROUP BY order_status")
|
||||
List<OrderCountDTO> countByStatus();
|
||||
}
|
||||
List<OrderCountDTO> countStatus();
|
||||
}
|
||||
@ -4,14 +4,11 @@ import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单数量响应
|
||||
*
|
||||
* @author itcast
|
||||
* @create 2023/11/9 16:54
|
||||
**/
|
||||
@Data
|
||||
public class OrderCountDTO {
|
||||
|
||||
private Integer orderStatus;
|
||||
|
||||
private Integer count;
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.jzo2o.common.model.PageResult;
|
||||
import com.jzo2o.health.model.domain.Orders;
|
||||
import com.jzo2o.health.model.dto.request.OrdersPageQueryReqDTO;
|
||||
import com.jzo2o.health.model.dto.response.AdminOrdersDetailResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersCountResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersDetailResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersResDTO;
|
||||
|
||||
@ -34,4 +35,9 @@ public interface IOrderManagerService extends IService<Orders> {
|
||||
* 用户端获取订单详情
|
||||
*/
|
||||
OrdersDetailResDTO getOrderById(Long id);
|
||||
|
||||
/**
|
||||
* 获取每种状态的订单数
|
||||
*/
|
||||
OrdersCountResDTO countByStatus();
|
||||
}
|
||||
@ -14,8 +14,10 @@ import com.jzo2o.health.mapper.OrdersMapper;
|
||||
import com.jzo2o.health.model.UserThreadLocal;
|
||||
import com.jzo2o.health.model.domain.Orders;
|
||||
import com.jzo2o.health.model.domain.OrdersCancelled;
|
||||
import com.jzo2o.health.model.dto.OrderCountDTO;
|
||||
import com.jzo2o.health.model.dto.request.OrdersPageQueryReqDTO;
|
||||
import com.jzo2o.health.model.dto.response.AdminOrdersDetailResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersCountResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersDetailResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersResDTO;
|
||||
import com.jzo2o.health.service.IOrderCancelService;
|
||||
@ -27,6 +29,7 @@ import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -162,4 +165,34 @@ public class OrderManagerServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
|
||||
return ordersDetailResDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrdersCountResDTO countByStatus() {
|
||||
OrdersCountResDTO ordersCountResDTO = new OrdersCountResDTO();
|
||||
|
||||
List<OrderCountDTO> orderCountList = baseMapper.countStatus();
|
||||
if (CollUtils.isEmpty(orderCountList)) {
|
||||
return ordersCountResDTO;
|
||||
}
|
||||
|
||||
Map<Integer, Integer> map = orderCountList
|
||||
.stream()
|
||||
.collect(Collectors
|
||||
.toMap(OrderCountDTO::getOrderStatus, OrderCountDTO::getCount));
|
||||
|
||||
Integer noPayCount = map.getOrDefault(OrderStatusEnum.NO_PAY.getStatus(), 0);
|
||||
Integer waitingCheckupCount = map.getOrDefault(OrderStatusEnum.WAITING_CHECKUP.getStatus(), 0);
|
||||
Integer completedCheckupCount = map.getOrDefault(OrderStatusEnum.COMPLETED_CHECKUP.getStatus(), 0);
|
||||
Integer closedCount = map.getOrDefault(OrderStatusEnum.CLOSED.getStatus(), 0);
|
||||
Integer cancelledCount = map.getOrDefault(OrderStatusEnum.CANCELLED.getStatus(), 0);
|
||||
|
||||
ordersCountResDTO.setNoPayCount(noPayCount);
|
||||
ordersCountResDTO.setWaitingCheckupCount(waitingCheckupCount);
|
||||
ordersCountResDTO.setCompletedCheckupCount(completedCheckupCount);
|
||||
ordersCountResDTO.setClosedCount(closedCount);
|
||||
ordersCountResDTO.setCancelledCount(cancelledCount);
|
||||
ordersCountResDTO.setTotalCount(noPayCount + waitingCheckupCount + completedCheckupCount + closedCount + cancelledCount);
|
||||
|
||||
return ordersCountResDTO;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user