Commit 28bc8e9caa45707438bb20b43d60b93d90a0bc97
1 parent
93103ae7
批量查询库存数据
重构了StockApi中的库存查询功能,将单个产品查询改为批量查询。现在通过提供一组产品ID,可以一次性获取多个产品的库存信息。这一改动提高了查询效率和功能的实用性。
Showing
1 changed file
with
7 additions
and
10 deletions
etrade-shop/src/main/java/com/diligrp/etrade/shop/api/StockApi.java
... | ... | @@ -57,18 +57,15 @@ public class StockApi { |
57 | 57 | |
58 | 58 | |
59 | 59 | /** |
60 | - * Query stock data for a single product. | |
60 | + * Batch query stock data | |
61 | 61 | * |
62 | - * @param productId The ID of the product to query stock data for. | |
63 | - * @return Stock data for the specified product. | |
62 | + * @param productIds List of product IDs to query stock for | |
63 | + * @return List of Stock information associated with the given product IDs | |
64 | 64 | */ |
65 | - @GetMapping("/{productId}") | |
66 | - public Message<Stock> getStockByProductId(@PathVariable Long productId) { | |
67 | - List<Stock> stocks = stockService.listByProductIds(Collections.singletonList(productId)); | |
68 | - if (CollUtil.isEmpty(stocks)) { | |
69 | - return Message.failure("Stock data not found for the product ID: " + productId); | |
70 | - } | |
71 | - return Message.success(stocks.get(0)); | |
65 | + @PostMapping("/batch-query") | |
66 | + public Message<List<Stock>> batchQuery(@RequestBody List<Long> productIds) { | |
67 | + List<Stock> stockList = stockService.listByProductIds(productIds); | |
68 | + return Message.success(stockList); | |
72 | 69 | } |
73 | 70 | |
74 | 71 | } | ... | ... |