Commit 9dfd4a584c7c0c721683cf871b67a63e187eb6f2
1 parent
606cd725
添加幂等性注解
为库存新增和扣减接口添加幂等性注解@Idempotent,防止重复请求导致数据出错。幂等性注解的参数unlockKey设置为false。
Showing
1 changed file
with
3 additions
and
0 deletions
etrade-shop/src/main/java/com/diligrp/etrade/shop/api/StockApi.java
... | ... | @@ -4,6 +4,7 @@ import com.diligrp.etrade.core.domain.Message; |
4 | 4 | import com.diligrp.etrade.shop.domain.request.StockAddRequest; |
5 | 5 | import com.diligrp.etrade.shop.domain.request.StockDeductRequest; |
6 | 6 | import com.diligrp.etrade.shop.service.StockService; |
7 | +import com.diligrp.idempotent.spring.boot.annotation.Idempotent; | |
7 | 8 | import org.springframework.web.bind.annotation.*; |
8 | 9 | |
9 | 10 | import java.util.List; |
... | ... | @@ -32,6 +33,7 @@ public class StockApi { |
32 | 33 | * @return Success message if data is added successfully |
33 | 34 | */ |
34 | 35 | @PostMapping |
36 | + @Idempotent(unlockKey = false) | |
35 | 37 | public Message<?> add(@RequestBody List<StockAddRequest> stock) { |
36 | 38 | stockService.insert(stock); |
37 | 39 | return Message.success(); |
... | ... | @@ -43,6 +45,7 @@ public class StockApi { |
43 | 45 | * @param stock List of stock data to be deducted |
44 | 46 | * @return Success message if data is deducted successfully |
45 | 47 | */ |
48 | + @Idempotent(unlockKey = false) | |
46 | 49 | @PutMapping |
47 | 50 | public Message<?> deduct(@RequestBody List<StockDeductRequest> stock) { |
48 | 51 | stockService.deduct(stock); | ... | ... |