@GetMapping("list")
public HashMap<String, Object> queryOrder( int pageNum,
int pageSize) {
if(pageNum <= 0 || pageSize <= 0){
HashMap<String, Object> response = new HashMap<>();
response.put("msg", "pageNum或pageSize需要大于0");
response.put("code", 400);
return response;
}
List<ChartOrders> list = chartOrdersService.listOrdersSortedByCreateTime(pageNum, pageSize);
int total = list.size();
HashMap<String, Object> map = new HashMap<>();
map.put("msg","操作成功");
map.put("code",200);
map.put("data",list);
map.put("pageNum",pageNum);
map.put("pageSize",pageSize);
map.put("total",total);
return map;
}
List<ChartOrders> listOrdersSortedByCreateTime(int pageNum, int pageSize);
@Override
public List<ChartOrders> listOrdersSortedByCreateTime(int pageNum, int pageSize) {
Long userId = SecurityUtils.getUserId();
Page<ChartOrders> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<ChartOrders> lqw = new LambdaQueryWrapper<>();
lqw.eq(ChartOrders::getUserId, userId);
lqw.orderByDesc(ChartOrders::getCreateTime);
Page<ChartOrders> pagedResult = chartOrdersMapper.selectPage(page, lqw);
List<ChartOrders> ordersList = pagedResult.getRecords();
for (ChartOrders order : ordersList) {
if (order.getTotalPrice() != null) {
BigDecimal priceInYuan = BigDecimal.valueOf(order.getTotalPrice())
.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP);
order.setTotalPriceInYuan(priceInYuan);
}
if (order.getInvoice() == null || order.getInvoice() == 0) {
order.setInvoiceStatus("未开票");
} else if (order.getInvoice() == 1) {
order.setInvoiceStatus("已开票");
}
if (order.getStatus() != null) {
if (order.getStatus() == 0) {
order.setPaymentStatus("未支付");
} else if (order.getStatus() == 1) {
order.setPaymentStatus("已支付");
}
}
}
return ordersList;
}