Commit 9dfd4a584c7c0c721683cf871b67a63e187eb6f2

Authored by shaofan
1 parent 606cd725

添加幂等性注解

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