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