选择人数添加锁
This commit is contained in:
@@ -34,6 +34,7 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -123,6 +124,9 @@ public class OrderService {
|
||||
private MpProductMapper mpProductMapper;
|
||||
|
||||
private final MpCashierCartService mpCashierCartService;
|
||||
@Qualifier("stringRedisTemplate")
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
|
||||
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) {
|
||||
@@ -1705,61 +1709,64 @@ public class OrderService {
|
||||
}
|
||||
|
||||
public Object choseCount(ChoseCountDTO choseCountDTO) {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseCountDTO.getShopId(), ShopInfoEatModelEnum.DINE_IN.getValue());
|
||||
return Utils.runFunAndCheckKey(() -> {
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseCountDTO.getShopId(), ShopInfoEatModelEnum.DINE_IN.getValue());
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
|
||||
if (shopInfo == null) throw new NotPrintException("店铺信息不存在");
|
||||
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
|
||||
if (shopInfo == null) throw new NotPrintException("店铺信息不存在");
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new NotPrintException("当前店铺无需选择餐位费");
|
||||
}
|
||||
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new NotPrintException("当前店铺无需选择餐位费");
|
||||
}
|
||||
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
|
||||
if (shopTable == null) {
|
||||
throw new NotPrintException("台桌不存在");
|
||||
}
|
||||
|
||||
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
|
||||
if (shopTable == null) {
|
||||
throw new NotPrintException("台桌不存在");
|
||||
}
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new NotPrintException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new NotPrintException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseCountDTO.getShopId())
|
||||
.and(q -> q.eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId()).or().isNull(TbCashierCart::getMasterId).or().eq(TbCashierCart::getMasterId, ""))
|
||||
.eq(TbCashierCart::getProductId, "-999")
|
||||
.eq(TbCashierCart::getSkuId, "-999")
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = mpCashierCartMapper.selectOne(query);
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseCountDTO.getShopId())
|
||||
.eq(TbCashierCart::getMasterId, choseCountDTO.getMasterId())
|
||||
.eq(TbCashierCart::getProductId, "-999")
|
||||
.eq(TbCashierCart::getSkuId, "-999")
|
||||
.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())
|
||||
.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = mpCashierCartMapper.selectOne(query);
|
||||
if (tbCashierCart == null) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
tbCashierCart.setTableId(choseCountDTO.getTableId());
|
||||
tbCashierCart.setName("客座费");
|
||||
tbCashierCart.setSalePrice(shopInfo.getTableFee());
|
||||
tbCashierCart.setMasterId(choseCountDTO.getMasterId());
|
||||
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
|
||||
tbCashierCart.setTradeDay(DateUtils.getDay());
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setPlaceNum(1);
|
||||
tbCashierCart.setProductId("-999");
|
||||
tbCashierCart.setSkuId("-999");
|
||||
tbCashierCart.setPackFee(BigDecimal.ZERO);
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
mpCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
|
||||
if (tbCashierCart == null) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
tbCashierCart.setTableId(choseCountDTO.getTableId());
|
||||
tbCashierCart.setName("客座费");
|
||||
tbCashierCart.setSalePrice(shopInfo.getTableFee());
|
||||
tbCashierCart.setMasterId(choseCountDTO.getMasterId());
|
||||
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
|
||||
tbCashierCart.setTradeDay(DateUtils.getDay());
|
||||
tbCashierCart.setStatus("create");
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setPlaceNum(1);
|
||||
tbCashierCart.setProductId("-999");
|
||||
tbCashierCart.setSkuId("-999");
|
||||
tbCashierCart.setPackFee(BigDecimal.ZERO);
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
mpCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
return tbCashierCart;
|
||||
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
|
||||
|
||||
return tbCashierCart;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user