xuhy
2024-09-19 20cd42287efb95254ea788ce2b6d0c559e378e04
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java
@@ -90,11 +90,19 @@
        this.save(dataGenerator);
        long start = System.currentTimeMillis();
        // 查询所有的人数用餐标准
        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList();
        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(dto.getShopId());
        // 查询所有桌子
        List<TBoard> boards = boardService.list();
        List<TBoard> boards = boardService.list(Wrappers.lambdaQuery(TBoard.class)
                .eq(TBoard::getShopId,dto.getShopId()));
        if(CollectionUtils.isEmpty(boards)){
            throw new ServiceException("请先添加桌台信息");
        }
        // 查询所有菜品
        List<TGoods> goods = goodsService.list();
        List<TGoods> goods = goodsService.list(Wrappers.lambdaQuery(TGoods.class)
                .eq(TGoods::getShopId,dto.getShopId()));
        if(CollectionUtils.isEmpty(goods)){
            throw new ServiceException("请先添加菜品信息");
        }
        // 循环待生成订单列表,添加到集合中,批量插入
        List<OrderMealGeneratorCountDTO> orderMealGeneratorCountDTOS = dto.getOrderMealGeneratorCountDTOS();
        List<TOrderMeal> orderMeals = new ArrayList<>();
@@ -141,14 +149,16 @@
                        }
                    }
                });
                orderMeal.setMealOrderGoods(orderMealGoods);
                orderMeal.setOrderMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                orderMeal.setPayMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                orderMeals.add(orderMeal);
                if(!CollectionUtils.isEmpty(orderMealGoods)){
                    orderMeal.setMealOrderGoods(orderMealGoods);
                    orderMeal.setOrderMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                    orderMeal.setPayMoney(orderMealGoods.stream().map(TOrderMealGoods::getGoodsSalePrice).reduce(BigDecimal::add).get());
                    orderMeals.add(orderMeal);
                }
            }
        }
        BigDecimal sumMoney = orderMeals.stream().map(TOrderMeal::getPayMoney).reduce(BigDecimal::add).get();
        if(sumMoney.compareTo(dto.getMinMoney()) <= 0 || sumMoney.compareTo(dto.getMaxMoney()) >= 0){
        if(sumMoney.compareTo(dto.getMinMoney()) >= 0 && sumMoney.compareTo(dto.getMaxMoney()) <= 0){
            int weiXin = getRandomPayType(orderMeals.size(), dto.getWeiXinProportion());
            int ali = getRandomPayType(orderMeals.size(), dto.getAliProportion());
            int card = getRandomPayType(orderMeals.size(), dto.getCardProportion());
@@ -222,6 +232,7 @@
            long end = System.currentTimeMillis() - start;
            System.err.println("相差时间========="+end);
        }else {
            this.removeById(dataGenerator);
            throw new ServiceException("数据生成不在营业额范围内");
        }