From 33a80f6b0585a320872477f85a50aa10ca1d20b1 Mon Sep 17 00:00:00 2001
From: yanghui <2536613402@qq.com>
Date: 星期一, 28 十一月 2022 18:01:51 +0800
Subject: [PATCH] Merge branch 'local_20221104' into huacheng_test
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java | 72 +++++++++++++++++++++++++++++++----
1 files changed, 63 insertions(+), 9 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 beb2596..f14db43 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
@@ -1,6 +1,7 @@
package com.panzhihua.service_community.service.impl;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -23,12 +24,17 @@
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;
import static java.util.Objects.nonNull;
/**
@@ -53,8 +59,11 @@
private ComShopFlowerOrderGoodsDAO comShopFlowerOrderGoodsDAO;
@Resource
private ComShopFlowerEvaluateDAO comShopFlowerEvaluateDAO;
+ @Resource
+ private ComShopFlowerGoodsViewStatisticsDAO comShopFlowerGoodsViewStatisticsDAO;
@Override
+ @Transactional(rollbackFor = Exception.class)
public R saveShopFlowerGoods(AddShopFlowerGoodsVO addShopFlowerGoodsVO) {
if (addShopFlowerGoodsVO == null) {
return R.ok("500", "数据为空!");
@@ -163,9 +172,11 @@
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));
});
}
return R.ok(goodsVOIPage);
@@ -186,16 +197,16 @@
List<ComShopFlowerGoodsAttrVO> goodsAttrList = new ArrayList<>();
List<ComShopFlowerGoodsAttrDO> goodsAttrDOS =
shopFlowerGoodsAttrDAO.selectList(new QueryWrapper<ComShopFlowerGoodsAttrDO>().eq("goods_id", goodsId));
- List<String> images = new ArrayList<>();
- goodsAttrDOS.forEach(attrDO -> {
+// List<String> images = new ArrayList<>();
+ int stock = 0;
+ for (ComShopFlowerGoodsAttrDO attrDO : goodsAttrDOS) {
ComShopFlowerGoodsAttrVO goodsAttrVO = new ComShopFlowerGoodsAttrVO();
BeanUtils.copyProperties(attrDO, goodsAttrVO);
String attrPic = attrDO.getAttrPic();
- images.add(attrPic);
+// images.add(attrPic);
goodsAttrList.add(goodsAttrVO);
- });
-
-
+ stock = stock +attrDO.getStock();
+ }
// 查询商品店铺信息
ConvenientMerchantDO convenientMerchantDO = convenientMerchantDAO.selectById(goodsDO.getStoreId());
ConvenientMerchantVO convenientMerchantVO = new ConvenientMerchantVO();
@@ -206,15 +217,28 @@
BeanUtils.copyProperties(goodsDO, shopGoods);
shopGoods.setGoodsAttrList(goodsAttrList);
shopGoods.setConvenientMerchantVO(convenientMerchantVO);
- shopGoods.setImages(StringUtils.join(images,","));
+// shopGoods.setImages(StringUtils.join(images,","));
Integer orderNum = comShopFlowerOrderGoodsDAO.selectCount(new LambdaQueryWrapper<ComShopFlowerOrderGoodsDO>().eq(ComShopFlowerOrderGoodsDO::getGoodsId, goodsId));
shopGoods.setOrderNum(orderNum);
List<ComShopFlowerEvaluateVO> comShopFlowerEvaluateVOList = comShopFlowerEvaluateDAO.selectListLimit(goodsId);
shopGoods.setShopFlowerEvaluateVOList(comShopFlowerEvaluateVOList);
+ Integer evaluateNum = comShopFlowerEvaluateDAO.selectCountByGoodsId(goodsId);
+ shopGoods.setEvaluateNum(evaluateNum);
+
+ 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", "数据为空!");
@@ -224,6 +248,9 @@
ComShopFlowerGoodsDO shopGoodsDO = new ComShopFlowerGoodsDO();
BeanUtils.copyProperties(addShopFlowerGoodsVO, shopGoodsDO);
shopGoodsDO.setOriginalPrice(addShopFlowerGoodsVO.getPrice());
+ if (StrUtil.isEmpty(addShopFlowerGoodsVO.getImages())){
+ shopGoodsDO.setImages("");
+ }
int update = this.baseMapper.update(shopGoodsDO, query);
if (update < 1) {
throw new ServiceException("修改失败");
@@ -284,6 +311,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public R deleteShopFlowerGoods(Long id) {
ComShopFlowerGoodsDO comShopFlowerGoodsDO = this.baseMapper.selectById(id);
comShopFlowerGoodsDO.setDeleteStatus(ComShopFlowerGoodsDO.deleteStatus.yes);
@@ -292,6 +320,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public R changeStatus(Long id, Integer status) {
ComShopFlowerGoodsDO shopGoodsDO = this.baseMapper.selectById(id);
if (shopGoodsDO == null) {
@@ -301,4 +330,29 @@
this.baseMapper.updateById(shopGoodsDO);
return R.ok();
}
+
+ @Override
+ public R incrGoodsView(Long goodsId) {
+ ComShopFlowerGoodsDO comShopFlowerGoodsDO = this.baseMapper.selectById(goodsId);
+ if (isNull(comShopFlowerGoodsDO)) {
+ return R.fail("商品不存在");
+ }
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ String nowDate = simpleDateFormat.format(new Date());
+ ComShopFlowerGoodsViewStatisticsDO statisticsDO = comShopFlowerGoodsViewStatisticsDAO.selectOne(new LambdaQueryWrapper<ComShopFlowerGoodsViewStatisticsDO>()
+ .eq(ComShopFlowerGoodsViewStatisticsDO::getGoodsId, goodsId).eq(ComShopFlowerGoodsViewStatisticsDO::getStatisticDate, nowDate));
+ if (isNull(statisticsDO)) {
+ 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