From abfedddb15ff90b7810a231dac964d2450372b94 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 10 九月 2024 09:01:42 +0800
Subject: [PATCH] 修改

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDataGeneratorServiceImpl.java |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 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 e58f7b3..837f187 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
@@ -22,6 +22,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -63,6 +64,8 @@
     @Autowired
     private TGoodsTypeService goodsTypeService;
     @Autowired
+    private TShopService shopService;
+    @Autowired
     private RedisCache redisCache;
 
     @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
@@ -72,7 +75,7 @@
         TDataGenerator dataGenerator = new TDataGenerator();
         dataGenerator.setUserId(dto.getUserId());
         dataGenerator.setUserName(dto.getNickName());
-        dataGenerator.setShopId(dataGenerator.getShopId());
+        dataGenerator.setShopId(dto.getShopId());
         dataGenerator.setStartTime(dto.getStartTime());
         dataGenerator.setEndTime(dto.getEndTime());
         dataGenerator.setMinMoney(dto.getMinMoney());
@@ -109,7 +112,9 @@
                 orderMeal.setOrderNum(OrderNumConstants.MEAL + CodeGenerateUtils.generateVolumeSn());
                 orderMeal.setStatus(2);
                 List<TOrderMealGoods> orderMealGoods = new ArrayList<>();
+                // 获取当前桌的菜品
                 List<TFoundationConfigVO> foundationConfigVOS = foundationConfigs.stream().filter(e -> e.getMealCount().equals(random)).collect(Collectors.toList());
+                // 每种菜品分类需要几个菜的生成
                 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());
@@ -130,6 +135,7 @@
                             tOrderMealGoods.setGoodsPicture(typeGood.getGoodsPicture());
                             tOrderMealGoods.setGoodsSalePrice(typeGood.getSalePrice());
                             tOrderMealGoods.setGoodsCount(1);
+                            tOrderMealGoods.setTypeId(typeGood.getTypeId());
                             orderMealGoods.add(tOrderMealGoods);
                         }
                     }
@@ -426,6 +432,9 @@
         PageInfo<TDataGeneratorVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
         List<TDataGeneratorVO> list = this.baseMapper.pageList(query,pageInfo);
         List<Long> ids = list.stream().map(TDataGeneratorVO::getId).collect(Collectors.toList());
+        if(CollectionUtils.isEmpty(ids)){
+            return new PageInfo<>();
+        }
         if(query.getOrderType() == 1){
             List<TOrderMeal> orderMeals = orderMealService.list(Wrappers.lambdaQuery(TOrderMeal.class)
                     .in(TOrderMeal::getGeneratorId, ids));
@@ -479,16 +488,21 @@
         TDataGenerator dataGenerator = this.getById(query.getGeneratorId());
         TDataGeneratorMealDetailVO data = new TDataGeneratorMealDetailVO();
         BeanUtils.copyProperties(dataGenerator,data);
+        // 查询店铺
+        TShop shop = shopService.getById(dataGenerator.getShopId());
+        if(Objects.nonNull(shop)){
+            data.setShopName(shop.getShopName());
+        }
         // 查询订单
         PageInfo<TOrderMealVO> pageInfo = orderMealService.pageListGenerator(query);
         data.setOrderMealList(pageInfo);
         // 统计支付金额
-        Map<String, BigDecimal> map = orderMealService.getDataGeneratorMealDetail(query);
-        BigDecimal money = map.get("moneyPay");
-        BigDecimal card = map.get("cardPay");
-        BigDecimal weiXin = map.get("weiXinPay");
-        BigDecimal ali = map.get("aliPay");
-        BigDecimal other = map.get("otherPay");
+        Map<String, Double> map = orderMealService.getDataGeneratorMealDetail(query);
+        BigDecimal money = new BigDecimal(map.get("moneyPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal card = new BigDecimal(map.get("cardPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal weiXin = new BigDecimal(map.get("weiXinPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal ali = new BigDecimal(map.get("aliPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal other = new BigDecimal(map.get("otherPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
         data.setMoneyPayAmount(money);
         data.setCardPayAmount(card);
         data.setWeiXinPayAmount(weiXin);
@@ -510,12 +524,12 @@
         PageInfo<TOrderSaleVO> pageInfo = orderSaleService.pageList(orderSaleQuery);
         data.setOrderMealList(pageInfo);
         // 统计支付金额
-        Map<String, BigDecimal> map = orderSaleService.getDataGeneratorMealDetail(query);
-        BigDecimal money = map.get("moneyPay");
-        BigDecimal card = map.get("cardPay");
-        BigDecimal weiXin = map.get("weiXinPay");
-        BigDecimal ali = map.get("aliPay");
-        BigDecimal other = map.get("otherPay");
+        Map<String, Double> map = orderSaleService.getDataGeneratorSaleDetail(query);
+        BigDecimal money = new BigDecimal(map.get("moneyPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal card = new BigDecimal(map.get("cardPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal weiXin = new BigDecimal(map.get("weiXinPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal ali = new BigDecimal(map.get("aliPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
+        BigDecimal other = new BigDecimal(map.get("otherPay")).setScale(2,BigDecimal.ROUND_HALF_UP);
         data.setMoneyPayAmount(money);
         data.setCardPayAmount(card);
         data.setWeiXinPayAmount(weiXin);
@@ -550,7 +564,7 @@
     }
 
     private int getRandomPayType(Integer size,BigDecimal count) {
-        BigDecimal bigDecimal = new BigDecimal(size).multiply(count.divide(new BigDecimal(100))).setScale(0, RoundingMode.HALF_UP);
+        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