From 42521c9b51c1bd9a40036f18fd610cd46601222d Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期一, 28 十一月 2022 14:45:22 +0800
Subject: [PATCH] #feat .

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java
index 4e647a6..146dade 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java
@@ -23,12 +23,14 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static java.util.Objects.isNull;
@@ -60,6 +62,7 @@
     private ComShopFlowerGoodsViewStatisticsDAO comShopFlowerGoodsViewStatisticsDAO;
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R saveShopFlowerGoods(AddShopFlowerGoodsVO addShopFlowerGoodsVO) {
         if (addShopFlowerGoodsVO == null) {
             return R.ok("500", "数据为空!");
@@ -168,7 +171,8 @@
                     goodsVo.setGoodsAttrList(goodsAttrList);
                     goodsVo.setGoodsPic(comShopFlowerGoodsAttrVO.getAttrPic());
                     goodsVo.setOriginalPrice(comShopFlowerGoodsAttrVO.getPrice());
-                    goodsVo.setPrice(comShopFlowerGoodsAttrVO.getCollatePrice());
+                    goodsVo.setCollatePrice(comShopFlowerGoodsAttrVO.getCollatePrice());
+                    goodsVo.setFreeShippingPrice(comShopFlowerGoodsAttrVO.getFreeShippingPrice());
                 }
                 //设置商品总浏览量
                 goodsVo.setViewNum(comShopFlowerGoodsViewStatisticsDAO.selectTotalViewNum(goodsId));
@@ -193,15 +197,15 @@
         List<ComShopFlowerGoodsAttrDO> goodsAttrDOS =
                 shopFlowerGoodsAttrDAO.selectList(new QueryWrapper<ComShopFlowerGoodsAttrDO>().eq("goods_id", goodsId));
         List<String> images = new ArrayList<>();
-        goodsAttrDOS.forEach(attrDO -> {
+        int stock = 0;
+        for (ComShopFlowerGoodsAttrDO attrDO : goodsAttrDOS) {
             ComShopFlowerGoodsAttrVO goodsAttrVO = new ComShopFlowerGoodsAttrVO();
             BeanUtils.copyProperties(attrDO, goodsAttrVO);
             String attrPic = attrDO.getAttrPic();
             images.add(attrPic);
             goodsAttrList.add(goodsAttrVO);
-        });
-
-
+            stock = stock +attrDO.getStock();
+        }
         // 查询商品店铺信息
         ConvenientMerchantDO convenientMerchantDO = convenientMerchantDAO.selectById(goodsDO.getStoreId());
         ConvenientMerchantVO convenientMerchantVO = new ConvenientMerchantVO();
@@ -220,10 +224,18 @@
 
         List<Long> categoryIds = convenientGoodsCategoryDAO.selectCategoryIdsForGoods(goodsId);
         shopGoods.setCategoryIds(categoryIds);
+        ComShopFlowerGoodsAttrVO comShopFlowerGoodsAttrVO = goodsAttrList.get(0);
+        shopGoods.setOriginalPrice(comShopFlowerGoodsAttrVO.getPrice());
+        shopGoods.setCollatePrice(comShopFlowerGoodsAttrVO.getCollatePrice());
+        shopGoods.setFreeShippingPrice(comShopFlowerGoodsAttrVO.getFreeShippingPrice());
+        shopGoods.setStock(stock);
+
+
         return R.ok(shopGoods);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R editFlowerShopGoods(Long id, AddShopFlowerGoodsVO addShopFlowerGoodsVO) {
         if (addShopFlowerGoodsVO == null) {
             return R.ok("500", "数据为空!");
@@ -293,6 +305,7 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R deleteShopFlowerGoods(Long id) {
         ComShopFlowerGoodsDO comShopFlowerGoodsDO = this.baseMapper.selectById(id);
         comShopFlowerGoodsDO.setDeleteStatus(ComShopFlowerGoodsDO.deleteStatus.yes);
@@ -301,6 +314,7 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public R changeStatus(Long id, Integer status) {
         ComShopFlowerGoodsDO shopGoodsDO = this.baseMapper.selectById(id);
         if (shopGoodsDO == null) {
@@ -322,10 +336,17 @@
         ComShopFlowerGoodsViewStatisticsDO statisticsDO = comShopFlowerGoodsViewStatisticsDAO.selectOne(new LambdaQueryWrapper<ComShopFlowerGoodsViewStatisticsDO>()
                 .eq(ComShopFlowerGoodsViewStatisticsDO::getGoodsId, goodsId).eq(ComShopFlowerGoodsViewStatisticsDO::getStatisticDate, nowDate));
         if (isNull(statisticsDO)) {
-            comShopFlowerGoodsViewStatisticsDAO.createTodayStatistic(goodsId);
+            comShopFlowerGoodsViewStatisticsDAO.createTodayStatistic(goodsId,nowDate);
         } else {
             comShopFlowerGoodsViewStatisticsDAO.incrViewNum(goodsId, nowDate);
         }
         return R.ok();
     }
+
+    @Override
+    public R countSaleByUserId(Long userId){
+        List<ComShopOrderStoreIdCountVO> comShopOrderStoreIdCountVOS = this.baseMapper.countSaleByUserId(userId);
+        Map<String, Integer> collect = comShopOrderStoreIdCountVOS.stream().collect(Collectors.toMap(ComShopOrderStoreIdCountVO::getCountName, ComShopOrderStoreIdCountVO::getCountNum));
+        return R.ok(collect);
+    }
 }

--
Gitblit v1.7.1