yanghui
2022-11-17 6e907cce72e42a349123800d697aa99f3360783e
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerGoodsServiceImpl.java
@@ -1,5 +1,6 @@
package com.panzhihua.service_community.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -13,9 +14,9 @@
import com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO;
import com.panzhihua.common.model.vos.shop.*;
import com.panzhihua.common.utlis.DifferentLongListUtil;
import com.panzhihua.service_community.dao.ComShopFlowerGoodsAttrDAO;
import com.panzhihua.service_community.dao.ComShopFlowerGoodsDAO;
import com.panzhihua.service_community.dao.ConvenientMerchantDAO;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.dao.*;
import com.panzhihua.service_community.model.dos.*;
import com.panzhihua.service_community.service.ComShopFlowerGoodsAttrService;
import com.panzhihua.service_community.service.ComShopFlowerGoodsService;
@@ -27,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Objects.nonNull;
/**
 * @ClassName: ComShopFlowerGoodsServiceImpl
@@ -44,6 +47,12 @@
    private ComShopFlowerGoodsAttrDAO shopFlowerGoodsAttrDAO;
    @Resource
    private ConvenientMerchantDAO convenientMerchantDAO;
    @Resource
    private ConvenientGoodsCategoryDAO convenientGoodsCategoryDAO;
    @Resource
    private ComShopFlowerOrderGoodsDAO comShopFlowerOrderGoodsDAO;
    @Resource
    private ComShopFlowerEvaluateDAO comShopFlowerEvaluateDAO;
    @Override
    public R saveShopFlowerGoods(AddShopFlowerGoodsVO addShopFlowerGoodsVO) {
@@ -62,6 +71,8 @@
        shopGoodsDO.setDetails(addShopFlowerGoodsVO.getDetails());
        int goodsId = this.baseMapper.insert(shopGoodsDO);
        if (goodsId > 0) {
            //保存规格
            ArrayList<ComShopFlowerGoodsAttrDO> goodsAttrDOS = Lists.newArrayList();
            ComShopFlowerGoodsDO goodDO = this.baseMapper.selectById(shopGoodsDO.getId());
            addShopFlowerGoodsVO.getGoodsAttrVOList().forEach(goodsAttr -> {
@@ -86,7 +97,21 @@
            if (goodsAttrDOS.size() > 0) {
                comShopFlowerGoodsAttrService.saveBatch(goodsAttrDOS);
            }
            //保存商品分类
            Long goodId = shopGoodsDO.getId();
            if (nonNull(goodId)) {
                //添加分类
                List<Long> categoryIds = addShopFlowerGoodsVO.getCategoryIds();
                categoryIds.forEach(categoryId -> {
                    ConvenientGoodsCategoryDO convenientGoodsCategoryDO = convenientGoodsCategoryDAO.selectById(categoryId);
                    convenientGoodsCategoryDAO.createGoodsCategoryRelation(Snowflake.getId(),goodId, categoryId,
                            convenientGoodsCategoryDO.getName(), convenientGoodsCategoryDO.getCreatedBy());
                });
            }
        }
        return R.ok();
    }
@@ -114,6 +139,9 @@
                    goodsAttrVOList.add(goodsAttrVO);
                }
                shopGoods.setGoodsAttrs(goodsAttrVOList);
                if (CollUtil.isNotEmpty(goodsAttrDOs)){
                    shopGoods.setGoodsPic(goodsAttrDOs.get(0).getAttrPic());
                }
            });
        }
        return R.ok(comShopStoreVOIPage);
@@ -132,15 +160,16 @@
        IPage<ComShopFlowerGoodsVO> goodsVOIPage = this.baseMapper.pageShopGoodByApps(page, comShopFlowerGoodsDTO);
        if (!goodsVOIPage.getRecords().isEmpty()) {
            goodsVOIPage.getRecords().forEach(goodsVo -> {
                List<ComShopFlowerGoodsAttrVO> goodsAttrList = shopFlowerGoodsAttrDAO.getGoodsAttr(goodsVo.getId());
                Long goodsId = goodsVo.getId();
                List<ComShopFlowerGoodsAttrVO> goodsAttrList = shopFlowerGoodsAttrDAO.getGoodsAttr(goodsId);
                if (!goodsAttrList.isEmpty()) {
                    ComShopFlowerGoodsAttrVO comShopFlowerGoodsAttrVO = goodsAttrList.get(0);
                    goodsVo.setGoodsAttrList(goodsAttrList);
                    goodsVo.setGoodsPic(comShopFlowerGoodsAttrVO.getAttrPic());
                    goodsVo.setOriginalPrice(comShopFlowerGoodsAttrVO.getPrice());
                    goodsVo.setPrice(comShopFlowerGoodsAttrVO.getCollatePrice());
                }
            });
        }
        return R.ok(goodsVOIPage);
@@ -161,11 +190,15 @@
        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 -> {
            ComShopFlowerGoodsAttrVO goodsAttrVO = new ComShopFlowerGoodsAttrVO();
            BeanUtils.copyProperties(attrDO, goodsAttrVO);
            String attrPic = attrDO.getAttrPic();
            images.add(attrPic);
            goodsAttrList.add(goodsAttrVO);
        });
        // 查询商品店铺信息
        ConvenientMerchantDO convenientMerchantDO = convenientMerchantDAO.selectById(goodsDO.getStoreId());
@@ -177,6 +210,11 @@
        BeanUtils.copyProperties(goodsDO, shopGoods);
        shopGoods.setGoodsAttrList(goodsAttrList);
        shopGoods.setConvenientMerchantVO(convenientMerchantVO);
        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);
        return R.ok(shopGoods);
    }