Jiaqi Xia

fix: disable methodAutoUnlock for RepeatSubmit on create order/diner/mealorder e…

…ndpoints to prevent resubmit issues
...@@ -38,7 +38,8 @@ public class RepeatSubmitAspect { ...@@ -38,7 +38,8 @@ public class RepeatSubmitAspect {
38 final var lockKey = getLockKey(joinPoint); 38 final var lockKey = getLockKey(joinPoint);
39 final var lock = redissonClient.getLock(lockKey); 39 final var lock = redissonClient.getLock(lockKey);
40 try { 40 try {
41 - if (lock.tryLock(requestLock.expire(), requestLock.timeUnit())) { 41 + // 立即尝试获取锁,如果获取到则设置持有时间
42 + if (lock.tryLock(0, requestLock.expire(), requestLock.timeUnit())) {
42 return joinPoint.proceed(); 43 return joinPoint.proceed();
43 } else { 44 } else {
44 log.error("Failed to acquire lock for method: {}", method.getName()); 45 log.error("Failed to acquire lock for method: {}", method.getName());
......
...@@ -53,7 +53,7 @@ public class DinerController { ...@@ -53,7 +53,7 @@ public class DinerController {
53 53
54 @ApiOperation(value = "添加就餐人") 54 @ApiOperation(value = "添加就餐人")
55 @PutMapping("/mpaccount/diner") 55 @PutMapping("/mpaccount/diner")
56 - @RepeatSubmit(prefix = "create.diner", isLockByLoginUser = false) 56 + @RepeatSubmit(prefix = "create.diner", isLockByLoginUser = false, methodAutoUnlock = false)
57 @ResponseStatus(HttpStatus.CREATED) 57 @ResponseStatus(HttpStatus.CREATED)
58 public CreatedResult<DinerVO> createMpAccountDiner(@RequestBody @Valid final DinerDTO.CreateDinerDTO createDinerDTO) { 58 public CreatedResult<DinerVO> createMpAccountDiner(@RequestBody @Valid final DinerDTO.CreateDinerDTO createDinerDTO) {
59 return dinerService.createMpAccountDiner(createDinerDTO); 59 return dinerService.createMpAccountDiner(createDinerDTO);
......
...@@ -11,7 +11,6 @@ import com.infoloop.tianting.model.vo.MealOrderVO; ...@@ -11,7 +11,6 @@ import com.infoloop.tianting.model.vo.MealOrderVO;
11 import com.infoloop.tianting.service.MealOrderService; 11 import com.infoloop.tianting.service.MealOrderService;
12 import io.swagger.annotations.Api; 12 import io.swagger.annotations.Api;
13 import io.swagger.annotations.ApiOperation; 13 import io.swagger.annotations.ApiOperation;
14 -import io.swagger.annotations.ApiParam;
15 import lombok.RequiredArgsConstructor; 14 import lombok.RequiredArgsConstructor;
16 import lombok.extern.slf4j.Slf4j; 15 import lombok.extern.slf4j.Slf4j;
17 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
...@@ -22,7 +21,6 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -22,7 +21,6 @@ import org.springframework.web.bind.annotation.PostMapping;
22 import org.springframework.web.bind.annotation.PutMapping; 21 import org.springframework.web.bind.annotation.PutMapping;
23 import org.springframework.web.bind.annotation.RequestAttribute; 22 import org.springframework.web.bind.annotation.RequestAttribute;
24 import org.springframework.web.bind.annotation.RequestBody; 23 import org.springframework.web.bind.annotation.RequestBody;
25 -import org.springframework.web.bind.annotation.RequestParam;
26 import org.springframework.web.bind.annotation.ResponseStatus; 24 import org.springframework.web.bind.annotation.ResponseStatus;
27 import org.springframework.web.bind.annotation.RestController; 25 import org.springframework.web.bind.annotation.RestController;
28 26
...@@ -50,7 +48,7 @@ public class MealOrderController { ...@@ -50,7 +48,7 @@ public class MealOrderController {
50 48
51 @ApiOperation(value = "立即订餐") 49 @ApiOperation(value = "立即订餐")
52 @PutMapping("/mealorder") 50 @PutMapping("/mealorder")
53 - @RepeatSubmit(prefix = "create.meal.order", isLockByLoginUser = false) 51 + @RepeatSubmit(prefix = "create.meal.order", isLockByLoginUser = false, methodAutoUnlock = false)
54 @ResponseStatus(HttpStatus.CREATED) 52 @ResponseStatus(HttpStatus.CREATED)
55 public CreatedResult<MealOrderVO> createMealOrder(@RequestBody @Valid final MealOrderDTO.CreateMealOrderDTO createMealOrderDTO) { 53 public CreatedResult<MealOrderVO> createMealOrder(@RequestBody @Valid final MealOrderDTO.CreateMealOrderDTO createMealOrderDTO) {
56 return mealOrderService.createMealOrder(createMealOrderDTO); 54 return mealOrderService.createMealOrder(createMealOrderDTO);
......
...@@ -68,7 +68,7 @@ public class OrderController { ...@@ -68,7 +68,7 @@ public class OrderController {
68 @ApiOperation(value = "小程序创建订单") 68 @ApiOperation(value = "小程序创建订单")
69 @PostMapping("/orders") 69 @PostMapping("/orders")
70 @ResponseStatus(HttpStatus.OK) 70 @ResponseStatus(HttpStatus.OK)
71 - @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false) 71 + @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false, methodAutoUnlock = false)
72 public CreateOrderResponse createOrder(@Valid @RequestBody CreateOrderDto createOrderDto) { 72 public CreateOrderResponse createOrder(@Valid @RequestBody CreateOrderDto createOrderDto) {
73 return orderService.createOrder(createOrderDto); 73 return orderService.createOrder(createOrderDto);
74 } 74 }
...@@ -76,7 +76,7 @@ public class OrderController { ...@@ -76,7 +76,7 @@ public class OrderController {
76 @ApiOperation(value = "院区端创建订单") 76 @ApiOperation(value = "院区端创建订单")
77 @PostMapping("/operator/orders") 77 @PostMapping("/operator/orders")
78 @ResponseStatus(HttpStatus.OK) 78 @ResponseStatus(HttpStatus.OK)
79 - @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false) 79 + @RepeatSubmit(prefix = "createOrder", isLockByLoginUser = false, methodAutoUnlock = false)
80 public CreateOrderResponse createOrderByOperator(@Valid @RequestBody OrderDbDTO.OperatorCreateOrderDto createOrderDto) { 80 public CreateOrderResponse createOrderByOperator(@Valid @RequestBody OrderDbDTO.OperatorCreateOrderDto createOrderDto) {
81 return orderService.orderCreation(createOrderDto); 81 return orderService.orderCreation(createOrderDto);
82 } 82 }
......