超市优化
This commit is contained in:
@ -30,7 +30,6 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.module.member.service.amount.LockManager.getStoreOrderLock;
|
||||
|
||||
@Tag(name = "APP超市 - 商品订单")
|
||||
@RestController
|
||||
@ -67,13 +66,13 @@ public class AppStoreOrderController {
|
||||
|
||||
@PostMapping("/appCreate")
|
||||
@Operation(summary = "购物车订单")
|
||||
public CommonResult<Boolean> appCreate(@RequestBody CardDto dto) {
|
||||
public CommonResult<Boolean> appCreate(@RequestBody CardDto dto) {
|
||||
|
||||
|
||||
AddReqVO addReqVO = storeOrderService.appCreate(dto);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(addReqVO);
|
||||
|
||||
synchronized(getStoreOrderLock("create")){
|
||||
AddReqVO addReqVO = storeOrderService.appCreate(dto);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(addReqVO);
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -98,11 +97,11 @@ public class AppStoreOrderController {
|
||||
@GetMapping("/cancel")
|
||||
@Operation(summary = "取消订单")
|
||||
public synchronized CommonResult<Boolean> cancel(Integer orderId) {
|
||||
synchronized(getStoreOrderLock("cancel")){
|
||||
AddReqVO cancel = storeOrderService.cancel(orderId);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(cancel);
|
||||
}
|
||||
|
||||
AddReqVO cancel = storeOrderService.cancel(orderId);
|
||||
//记录
|
||||
memberAsyncService.batchRecord(cancel);
|
||||
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.member.service.amount.LockManager.getStoreOrderLock;
|
||||
|
||||
/**
|
||||
* 商品订单 Service 实现类
|
||||
@ -461,14 +462,18 @@ public class StoreOrderServiceImpl implements StoreOrderService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AddReqVO cancel(Integer orderId) {
|
||||
StoreOrderDO storeOrderDO = storeOrderMapper.selectById(orderId);
|
||||
if(ObjectUtil.isEmpty(storeOrderDO)){
|
||||
throw exception(STORE_ORDER_NOT_EXISTS);
|
||||
}
|
||||
if(storeOrderDO.getStatus().equals(StoreOrderStatusEnum.COMPLETE.getCode())
|
||||
|| storeOrderDO.getStatus().equals(StoreOrderStatusEnum.REFUND.getCode())){
|
||||
throw exception(STATUS_ERROR);
|
||||
StoreOrderDO storeOrderDO;
|
||||
synchronized (getStoreOrderLock("cancel")) {
|
||||
storeOrderDO = storeOrderMapper.selectById(orderId);
|
||||
if(ObjectUtil.isEmpty(storeOrderDO)){
|
||||
throw exception(STORE_ORDER_NOT_EXISTS);
|
||||
}
|
||||
if(storeOrderDO.getStatus().equals(StoreOrderStatusEnum.COMPLETE.getCode())
|
||||
|| storeOrderDO.getStatus().equals(StoreOrderStatusEnum.REFUND.getCode())){
|
||||
throw exception(STATUS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
//修改状态
|
||||
storeOrderDO.setStatus(StoreOrderStatusEnum.CANCEL.getCode());
|
||||
storeOrderMapper.updateById(storeOrderDO);
|
||||
|
Reference in New Issue
Block a user