From 82756445c8069c778f9f47faa37fab0479bfda7c Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期一, 30 九月 2024 18:27:49 +0800 Subject: [PATCH] 修改接口 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java | 27 ++++++++++++++++++++++----- 1 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java index 8113736..db5de50 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java @@ -113,8 +113,14 @@ List<OrderMealGeneratorCountDTO> orderMealGeneratorCountDTOS = dto.getOrderMealGeneratorCountDTOS(); List<TOrderMeal> orderMeals = new ArrayList<>(); for (OrderMealGeneratorCountDTO orderMealGeneratorCountDTO : orderMealGeneratorCountDTOS) { - TBoard board = boards.stream().filter(e -> e.getId().equals(orderMealGeneratorCountDTO.getBoardId())).findFirst().get(); + TBoard board = boards.stream().filter(e -> e.getId().equals(orderMealGeneratorCountDTO.getBoardId())).findFirst().orElse(null); + if(Objects.isNull(board)){ + throw new ServiceException("该桌台信息不存在"); + } Integer orderCount = orderMealGeneratorCountDTO.getOrderCount(); + if(orderCount == 0){ + continue; + } // 查询当前桌的用餐人数 for (int i = 1; i <= orderCount; i++) { int random = getRandom(board.getMinPerson(), board.getMaxPerson()); @@ -128,11 +134,18 @@ List<TOrderMealGoods> orderMealGoods = new ArrayList<>(); // 获取当前桌的菜品 List<TFoundationConfigVO> foundationConfigVOS = foundationConfigs.stream().filter(e -> e.getMealCount().equals(random)).collect(Collectors.toList()); + if(CollectionUtils.isEmpty(foundationConfigVOS)){ + throw new ServiceException("桌台"+random+"人餐,人数配置不存在"); + } // 每种菜品分类需要几个菜的生成 foundationConfigVOS.forEach(e -> { int random1 = getRandom(e.getMinCount(), e.getMaxCount()); - List<TGoods> typeGoods = goods.stream().filter(m -> e.getTypeId().equals(m.getTypeId())).collect(Collectors.toList()); - typeGoods = randomSelection(typeGoods, random1); + List<TGoods> typeGoodsList = goods.stream().filter(m -> e.getTypeId().equals(m.getTypeId())).collect(Collectors.toList()); + List<TGoods> typeGoods = randomSelection(typeGoodsList, random1); + if(typeGoods.size() != random1){ + List<TGoods> goods1 = randomSelection(typeGoodsList, random1 - typeGoods.size()); + typeGoods.addAll(goods1); + } for (TGoods typeGood : typeGoods) { int count = 0; for (TOrderMealGoods good : orderMealGoods) { @@ -468,7 +481,7 @@ return; } // 删除上一次的数据生成 - if(Objects.nonNull(orderStockLast)){ + if(Objects.nonNull(orderStockLast) && Objects.nonNull(stockDataSet) && stockDataSets.size() > 1){ orderStockService.removeById(orderStockLast); } orderSaleService.saveBatch(orderSales); @@ -526,7 +539,11 @@ // BigDecimal money = orderSaleGoods.stream().filter(e -> collect.contains(e.getOrderId())) // .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsCostPrice().multiply(new BigDecimal(y.getGoodsCount()))), BigDecimal::add); if(!CollectionUtils.isEmpty(orderSales)){ - BigDecimal money = orderSales.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get(); + List<TOrderSale> collect = orderSales.stream().filter(e -> e.getGeneratorId().equals(tDataGeneratorVO.getId())).collect(Collectors.toList()); + BigDecimal money = BigDecimal.ZERO; + if(!CollectionUtils.isEmpty(collect)){ + money = collect.stream().map(TOrderSale::getPayMoney).reduce(BigDecimal::add).get(); + } tDataGeneratorVO.setTotalRevenue(money); } } -- Gitblit v1.7.1