选择人数添加锁
This commit is contained in:
@@ -24,6 +24,9 @@ public interface RedisConstant {
|
||||
// 排队取号全局号码
|
||||
String TABLE_CALL_NUMBER = "TABLE_CALL_NUMBER:";
|
||||
|
||||
// 选择人数锁
|
||||
String CHOSE_TABLE_COUNT = "CHOSE_TABLE_COUNT";
|
||||
|
||||
static String getCurrentOrderKey(String tableId, String shopId) {
|
||||
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
|
||||
}
|
||||
|
||||
@@ -1679,62 +1679,65 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
|
||||
@Override
|
||||
public Object choseCount(ChoseCountDTO choseCountDTO) {
|
||||
TbShopInfo shopInfo = shopInfoRepository.findById(choseCountDTO.getShopId()).orElse(null);
|
||||
if (shopInfo == null) throw new BadRequestException("店铺信息不存在");
|
||||
return Utils.runFunAndCheckKey(() -> {
|
||||
TbShopInfo shopInfo = shopInfoRepository.findById(choseCountDTO.getShopId()).orElse(null);
|
||||
if (shopInfo == null) throw new BadRequestException("店铺信息不存在");
|
||||
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new BadRequestException("当前店铺无需选择餐位费");
|
||||
}
|
||||
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
|
||||
throw new BadRequestException("当前店铺无需选择餐位费");
|
||||
}
|
||||
|
||||
TbShopTable shopTable = mpShopTableService.lambdaQuery().eq(TbShopTable::getQrcode, choseCountDTO.getTableId()).one();
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("台桌不存在");
|
||||
}
|
||||
TbShopTable shopTable = mpShopTableService.lambdaQuery().eq(TbShopTable::getQrcode, choseCountDTO.getTableId()).one();
|
||||
if (shopTable == null) {
|
||||
throw new BadRequestException("台桌不存在");
|
||||
}
|
||||
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new BadRequestException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
|
||||
throw new BadRequestException("当前台桌最大人数为: " + 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, choseCountDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = cashierCartMapper.selectOne(query);
|
||||
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, choseCountDTO.getUseType())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.eq(TbCashierCart::getTableId, choseCountDTO.getTableId());
|
||||
TbCashierCart tbCashierCart = cashierCartMapper.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());
|
||||
tbCashierCart.setUseType(choseCountDTO.getUseType());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setUseType(choseCountDTO.getUseType());
|
||||
tbCashierCartMapper.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());
|
||||
tbCashierCart.setUseType(choseCountDTO.getUseType());
|
||||
tbCashierCartMapper.insert(tbCashierCart);
|
||||
} else {
|
||||
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
|
||||
tbCashierCart.setNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
|
||||
tbCashierCart.setUseType(choseCountDTO.getUseType());
|
||||
tbCashierCartMapper.updateById(tbCashierCart);
|
||||
}
|
||||
|
||||
return tbCashierCart;
|
||||
}, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
|
||||
|
||||
return tbCashierCart;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user