无台桌模式选择台桌接口修改

This commit is contained in:
2024-10-23 17:32:45 +08:00
parent 24a80cb24a
commit d99771f8e7
11 changed files with 130 additions and 57 deletions

View File

@@ -1098,6 +1098,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbCashierCart> cashierCarts = cashierCartMapper
.selectList(queryWrapper);
if (cashierCarts.isEmpty() || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && cashierCarts.size() < 2)) {
throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费");
}
@@ -1728,50 +1729,41 @@ public class TbShopTableServiceImpl implements TbShopTableService {
@Override
public Object choseTable(ChoseTableDTO choseTableDTO) {
String masterId = getMasterId(choseTableDTO.getShopId(), choseTableDTO.getNewTableId(), null, null).getString("masterId");
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId())
.eq(TbShopTable::getStatus, "idle"));
TbShopTable shopTable = mpShopTableService.selectByStateAndTableId(TableStateEnum.IDLE, choseTableDTO.getTableId(), choseTableDTO.getShopId());
if (shopTable == null) {
throw new BadRequestException("台桌不存在或空闲状态");
throw new BadRequestException("台桌不存在或不处于空闲状态");
}
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getNewTableId());
TbOrderInfo currentOrder = getCurrentOrder(shopEatTypeInfoDTO);
Integer currentOrderId = currentOrder == null ? null : currentOrder.getId();
List<TbCashierCart> tbCashierCarts = mpCashierCartService.selectTakeoutCart(choseTableDTO.getMasterId(), choseTableDTO.getShopId());
if (tbCashierCarts.isEmpty()) {
throw new BadRequestException("购物车为空");
}
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getTableId());
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getTableId, choseTableDTO.getOldTableId())
.in(TbCashierCart::getStatus, "create", "return")
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId())
.and(q -> q.isNull(TbCashierCart::getOrderId)
.or()
.eq(TbCashierCart::getOrderId, currentOrderId))
.and(query2 -> query2.or(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
.isNotNull(TbCashierCart::getMasterId))
.or((query4 -> query4.isNull(TbCashierCart::getTradeDay)
.isNull(TbCashierCart::getMasterId))))
.set(TbCashierCart::getMasterId, masterId)
.set(TbCashierCart::getTableId, choseTableDTO.getNewTableId()));
ArrayList<Integer> cartIds = new ArrayList<>();
Integer orderId = null;
for (TbCashierCart item : tbCashierCarts) {
item.setTableId(choseTableDTO.getTableId());
item.setUseType(shopEatTypeInfoDTO.getUseType());
cartIds.add(item.getId());
if (item.getOrderId() != null) {
orderId = item.getOrderId();
}
}
mpCashierCartService.updateBatchById(tbCashierCarts);
// 修改detail的用餐类型
mpOrderDetailService.updateUseTypeByCartIds(cartIds, shopEatTypeInfoDTO.getUseType());
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId())
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
// 将台桌redis数据迁移
String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString());
setCurrentOrderId(choseTableDTO.getNewTableId(), choseTableDTO.getShopId().toString(), orderId);
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, currentOrderId)
.set(TbOrderInfo::getMasterId, masterId)
.set(TbOrderInfo::getTableId, choseTableDTO.getNewTableId()));
// 修改订单表台桌信息
if(orderId != null) {
mpOrderInfoService.updateTableIdAndUseTypeById(orderId, shopEatTypeInfoDTO.getUseType(), choseTableDTO.getTableId());
mpShopTableService.updateStateByTableId(TableStateEnum.USING, choseTableDTO.getTableId());
// 将台桌redis数据迁移
setCurrentOrderId(choseTableDTO.getTableId(), choseTableDTO.getShopId().toString(), orderId.toString());
}
return true;
}