超市优化
This commit is contained in:
@ -116,7 +116,8 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode AMOUNT_NOT_ENOUGH = new ErrorCode(1_007_904_008, "金额不足");
|
||||
ErrorCode CODE_NOT_TIME = new ErrorCode(1_007_904_008, "二维码过期");
|
||||
ErrorCode STATUS_ERROR = new ErrorCode(1_007_904_007, "订单已完成或已退款");
|
||||
|
||||
ErrorCode ORDER_FAIL = new ErrorCode(1_007_904_008, "下单失败");
|
||||
ErrorCode ORDER_CANCEL_FAIL = new ErrorCode(1_007_904_008, "订单取消失败");
|
||||
|
||||
ErrorCode STORE_ORDER_DETAIL_NOT_EXISTS = new ErrorCode(1_007_904_006,"商品订单详情不存在");
|
||||
//========== 用户余额明细 1-004-014-000 =============
|
||||
|
@ -28,8 +28,13 @@ 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.error;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ORDER_CANCEL_FAIL;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ORDER_FAIL;
|
||||
|
||||
@Tag(name = "APP超市 - 商品订单")
|
||||
@RestController
|
||||
@ -46,6 +51,10 @@ public class AppStoreOrderController {
|
||||
@Resource
|
||||
private MemberAsyncService memberAsyncService;
|
||||
|
||||
private final Lock createLock = new ReentrantLock();
|
||||
|
||||
private final Lock cancelLock = new ReentrantLock();
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品订单分页")
|
||||
public CommonResult<PageResult<StoreOrderRespVO>> getStoreOrderPage(@Valid StoreOrderPageReqVO pageReqVO) {
|
||||
@ -66,9 +75,16 @@ public class AppStoreOrderController {
|
||||
@PostMapping("/appCreate")
|
||||
@Operation(summary = "购物车订单")
|
||||
public CommonResult<Boolean> appCreate(@RequestBody CardDto dto) {
|
||||
AddReqVO addReqVO = storeOrderService.appCreate(dto);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(addReqVO);
|
||||
createLock.lock();
|
||||
try {
|
||||
AddReqVO addReqVO= storeOrderService.appCreate(dto);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(addReqVO);
|
||||
}catch (Exception e){
|
||||
return error(ORDER_FAIL);
|
||||
}finally {
|
||||
createLock.unlock();
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -93,9 +109,16 @@ public class AppStoreOrderController {
|
||||
@GetMapping("/cancel")
|
||||
@Operation(summary = "取消订单")
|
||||
public CommonResult<Boolean> cancel(Integer orderId) {
|
||||
AddReqVO cancel = storeOrderService.cancel(orderId);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(cancel);
|
||||
cancelLock.lock();
|
||||
try {
|
||||
AddReqVO cancel = storeOrderService.cancel(orderId);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(cancel);
|
||||
}catch (Exception e){
|
||||
return error(ORDER_CANCEL_FAIL);
|
||||
}finally {
|
||||
cancelLock.unlock();
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user