超市优化

This commit is contained in:
zengtao01
2024-11-15 10:12:10 +08:00
parent 6475ee3da3
commit 06a85788f1

View File

@ -28,8 +28,6 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -48,9 +46,6 @@ public class AppStoreOrderController {
@Resource
private MemberAsyncService memberAsyncService;
private final Lock createLock = new ReentrantLock();
private final Lock cancelLock = new ReentrantLock();
@GetMapping("/page")
@Operation(summary = "获得商品订单分页")
@ -71,15 +66,13 @@ public class AppStoreOrderController {
@PostMapping("/appCreate")
@Operation(summary = "购物车订单")
public CommonResult<Boolean> appCreate(@RequestBody CardDto dto) {
createLock.lock();
try {
public synchronized CommonResult<Boolean> appCreate(@RequestBody CardDto dto) {
AddReqVO addReqVO = storeOrderService.appCreate(dto);
//记录
memberAsyncService.batchRecord(addReqVO);
}finally {
createLock.unlock();
}
return success(true);
}
@ -103,15 +96,12 @@ public class AppStoreOrderController {
@GetMapping("/cancel")
@Operation(summary = "取消订单")
public CommonResult<Boolean> cancel(Integer orderId) {
cancelLock.lock();
try {
public synchronized CommonResult<Boolean> cancel(Integer orderId) {
AddReqVO cancel = storeOrderService.cancel(orderId);
//记录
memberAsyncService.batchRecord(cancel);
}finally {
cancelLock.unlock();
}
return success(true);
}