From 0b00c7532a0330785d0c8cf46bcb05dfc63e65c4 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 31 十月 2024 15:11:24 +0800
Subject: [PATCH] 修改

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 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 72e12d1..59a7751 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
@@ -49,6 +49,8 @@
     @Autowired
     private TFoundationConfigService foundationConfigService;
     @Autowired
+    private TFoundationPersonService foundationPersonService;
+    @Autowired
     private TGoodsService goodsService;
     @Autowired
     private TOrderMealService orderMealService;
@@ -92,10 +94,10 @@
         dataGenerator.setOtherPay(dto.getOtherProportion());
         this.save(dataGenerator);
         long start = System.currentTimeMillis();
-        // 查询所有的人数用餐标准
-        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(dto.getShopId());
+        TShop shop = shopService.getById(dto.getShopId());
+        List<TFoundationConfigVO> foundationConfigs = foundationConfigService.getList(shop.getMealType());
         if(CollectionUtils.isEmpty(foundationConfigs)){
-            throw new ServiceException("请先添加该店铺用餐标准");
+            throw new ServiceException("请先添加中餐或火锅用餐标准");
         }
         // 查询所有桌子
         List<TBoard> boards = boardService.list(Wrappers.lambdaQuery(TBoard.class)
@@ -118,6 +120,9 @@
                 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());
@@ -126,7 +131,13 @@
                 orderMeal.setMealType(1);
                 orderMeal.setMealPerson(random);
                 orderMeal.setMealTime(orderMealGeneratorCountDTO.getTime());
-                orderMeal.setOrderNum(OrderNumConstants.MEAL + CodeGenerateUtils.generateVolumeSn());
+                String num = OrderNumConstants.MEAL + CodeGenerateUtils.generateVolumeSn();
+//                long count1 = orderMealService.count(Wrappers.lambdaQuery(TOrderMeal.class)
+//                        .eq(TOrderMeal::getOrderNum, num));
+//                if(count1>0){
+//                    num = CodeGenerateUtils.generateVolumeSn();
+//                }
+                orderMeal.setOrderNum(num);
                 orderMeal.setStatus(2);
                 List<TOrderMealGoods> orderMealGoods = new ArrayList<>();
                 // 获取当前桌的菜品
@@ -137,15 +148,19 @@
                 // 每种菜品分类需要几个菜的生成
                 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) {
                             if (good.getGoodsNum().equals(typeGood.getGoodsNum())) {
                                 count+=1;
                                 good.setGoodsCount(good.getGoodsCount() + 1);
-                                good.setGoodsSalePrice(good.getGoodsSalePrice().add(typeGood.getSalePrice()));
+//                                good.setGoodsSalePrice(good.getGoodsSalePrice().add(typeGood.getSalePrice()));
                                 break; // 找到后直接跳出循环
                             }
                         }
@@ -474,7 +489,7 @@
             return;
         }
         // 删除上一次的数据生成
-        if(Objects.nonNull(orderStockLast)){
+        if(Objects.nonNull(orderStockLast) && Objects.nonNull(stockDataSet) && stockDataSets.size() > 1){
             orderStockService.removeById(orderStockLast);
         }
         orderSaleService.saveBatch(orderSales);
@@ -687,6 +702,11 @@
         return null;
     }
 
+    @Override
+    public void deleteByShopId(Long shopId) {
+        this.baseMapper.deleteByShopId(shopId);
+    }
+
     private int getRandomPayType(Integer size,BigDecimal count) {
         BigDecimal bigDecimal = new BigDecimal(size).multiply(count.divide(new BigDecimal(100))).setScale(0, BigDecimal.ROUND_FLOOR);
         return Integer.parseInt(bigDecimal.toString());

--
Gitblit v1.7.1