diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index ea3751e3..de29036c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -2744,34 +2744,41 @@ public class TbShopTableServiceImpl implements TbShopTableService { if (OrderUseTypeEnum.TAKEOUT.getValue().equals(choseModelDTO.getUseType())) { ArrayList productIds = new ArrayList<>(); cashierCarts.forEach(item -> { - productIds.add(Integer.valueOf(item.getProductId())); + if (item.getProductId() != null) { + productIds.add(Integer.valueOf(item.getProductId())); + } }); - List productList = productMapper.selectBatchIds(productIds); - Map productMap = productList.stream() - .collect(Collectors.toMap(product -> String.valueOf(product.getId()), product -> product)); - cashierCarts.forEach(item -> { - TbProduct product = productMap.get(item.getProductId()); + + Map productMap = new HashMap<>(); + if (!productIds.isEmpty()) { + List productList = productMapper.selectBatchIds(productIds); + productMap = productList.stream() + .collect(Collectors.toMap(product -> String.valueOf(product.getId()), product -> product)); + } + for (TbCashierCart cashierCart : cashierCarts) { + TbProduct product = productMap.get(cashierCart.getProductId()); + // 设置打包费 mpCashierCartService.update(new LambdaUpdateWrapper() - .eq(TbCashierCart::getId, item.getId()) - .set(TbCashierCart::getPackFee, product.getPackFee() != null ? - product.getPackFee().multiply(item.getNumber()) : BigDecimal.ZERO) + .eq(TbCashierCart::getId, cashierCart.getId()) + .set(TbCashierCart::getPackFee, product != null && product.getPackFee() != null ? + product.getPackFee().multiply(cashierCart.getNumber()) : BigDecimal.ZERO) .set(TbCashierCart::getTableId, null) .set(TbCashierCart::getUseType, OrderUseTypeEnum.TAKEOUT.getValue()) .set(TbCashierCart::getIsPack, "true")); - }); + } List detailList = orderDetailMapper.selectList(new LambdaQueryWrapper() .in(TbOrderDetail::getCartId, choseModelDTO.getCartIds()) .eq(TbOrderDetail::getShopId, choseModelDTO.getShopId())); - detailList.forEach(item -> { + for (TbOrderDetail item : detailList) { item.setUseType(OrderUseTypeEnum.TAKEOUT.getValue()); TbProduct product = productMap.get(item.getProductId().toString()); // 设置打包费 - item.setPackAmount(product.getPackFee() != null ? + item.setPackAmount(product != null && product.getPackFee() != null ? product.getPackFee().multiply(item.getNum()) : BigDecimal.ZERO); - }); + } if (!detailList.isEmpty()) { mpOrderDetailService.updateBatchById(detailList);