例如不同状态的订单量。
创建一个实体作为出参
/**
* Created by xxs on 2021/9/30 10:05
*
* @Description 订单数据统计出参
*/
@Data
public class OrderDataStatisticsVo {
/**
* 待支付
*/
private Long toBePaidNum = 0L;
/**
* 已支付
*/
private Long paidNum = 0L;
/**
* 已取消
*/
private Long cancelNum = 0L;
/**
* 已发货
*/
private Long shippedNum = 0L;
/**
* 已签收
*/
private Long signedInNum = 0L;
/**
* 已退款
*/
private Long refundedNum = 0L;
}
实体:
/**
* 订单表
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("tb_orders")
public class OrdersEntity implements Serializable {
private static final long serialVersionUID = 1L;
@TableId
private Long id;
/**
* 订单状态
* @see io.lease.common.enums.OrderStateEnum
*/
private Integer orderState;
//其他字段省略
}
controller:
@GetMapping("dataStatistics")
@ApiOperation("数据统计")
public R<OrderDataStatisticsVo> dataStatistics(OrdersDTO ordersDTO){
return ordersService.dataStatistics(ordersDTO);
}
Service:
R<OrderDataStatisticsVo> dataStatistics(OrdersDTO ordersDTO);
两种实现方式:
第一种(sql实现)
Service的实现:
@Service
public class OrdersServiceImpl extends CrudServiceImpl<OrdersDao, OrdersEntity, OrdersDTO> implements OrdersService {
private static final Logger logger = LoggerFactory.getLogger(OrdersServiceImpl.class);
@Autowired
private OrdersDao ordersDao;
public R<OrderDataStatistic