CeDo
2021-04-20 c624a13eb32b90bb698f9fa9225c5a5ec07fa804
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java
@@ -2,6 +2,8 @@
import java.math.BigDecimal;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -9,14 +11,24 @@
import com.google.common.collect.Lists;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.shop.PageComShopGoodsDTO;
import com.panzhihua.common.model.dtos.shop.ComShopGoodsDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.shop.AddShopGoodsAttrVO;
import com.panzhihua.common.model.vos.shop.PageShopGoodsVO;
import com.panzhihua.common.model.vos.shop.AddShopGoodsVO;
import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
import com.panzhihua.common.model.vos.shop.ComShopGoodsAttrVO;
import com.panzhihua.common.model.vos.shop.ComShopGoodsVO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
import com.panzhihua.common.model.dtos.shop.PageComShopGoodsDTO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.service_community.dao.ComShopGoodsDAO;
import com.panzhihua.service_community.model.dos.ComShopGoodsAttrDO;
import com.panzhihua.service_community.dao.ComShopStoreDAO;
import com.panzhihua.service_community.model.dos.ComShopGoodsAttrDO;
import com.panzhihua.service_community.model.dos.ComShopGoodsDO;
import com.panzhihua.service_community.model.dos.ComShopStoreDO;
import com.panzhihua.service_community.service.ComShopGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -28,6 +40,10 @@
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
 * @auther lyq
 * @create 2021-04-14 15:02:35
@@ -38,6 +54,10 @@
public class ComShopGoodsServiceImpl extends ServiceImpl<ComShopGoodsDAO, ComShopGoodsDO> implements ComShopGoodsService {
    @Resource
    private ComShopGoodsAttrServiceImpl goodsAttrService;
    @Resource
    private ComShopGoodsAttrDAO shopGoodsAttrDAO;
    @Resource
    private ComShopStoreDAO shopStoreDAO;
    @Override
    public R saveShopGoods(AddShopGoodsVO addShopGoodsVO) {
@@ -85,7 +105,7 @@
        comShopStoreVOIPage.getRecords().forEach(vo -> {
            List<ComShopGoodsAttrDO> goodsAttrDOs = goodsAttrDOS.stream().filter(goodsAttr -> goodsAttr.getGoodsId().equals(vo.getId())).collect(Collectors.toList());
            ArrayList<AddShopGoodsAttrVO> goodsAttrVOList = Lists.newArrayList();
            for (ComShopGoodsAttrDO oneGoodsAttrDO :goodsAttrDOs) {
            for (ComShopGoodsAttrDO oneGoodsAttrDO : goodsAttrDOs) {
                AddShopGoodsAttrVO goodsAttrVO = new AddShopGoodsAttrVO();
                goodsAttrVO.setGoodsAttrId(oneGoodsAttrDO.getId());
                goodsAttrVO.setGoodsAttr(oneGoodsAttrDO.getGoodsAttr());
@@ -140,21 +160,76 @@
    @Override
    public R deleteShopGoods(Long[] id) {
        ComShopGoodsDO storeDO = new ComShopGoodsDO();
        storeDO.setDeleteStatus(2);
        LambdaQueryWrapper<ComShopGoodsDO> query = new LambdaQueryWrapper<ComShopGoodsDO>().eq(ComShopGoodsDO::getId, id);
        int update = this.baseMapper.update(storeDO, query);
        return update > 0 ? R.ok() : R.fail();
        LambdaQueryWrapper<ComShopGoodsDO> query = new LambdaQueryWrapper<ComShopGoodsDO>().in(ComShopGoodsDO::getId, id);
        List<ComShopGoodsDO> comShopGoodsDOS = this.baseMapper.selectList(query);
        for (ComShopGoodsDO one : comShopGoodsDOS) {
            one.setDeleteStatus(2);
            this.baseMapper.updateById(one);
        }
        return R.ok();
    }
    @Override
    public R changeStatus(Long id, Integer status) {
        ComShopGoodsDO shopGoodsDO = this.baseMapper.selectById(id);
        if(shopGoodsDO==null){
        if (shopGoodsDO == null) {
            return R.fail("id有误!");
        }
        shopGoodsDO.setStatus(status);
        this.baseMapper.updateById(shopGoodsDO);
        return R.ok();
    }
    /**
     * 分页查询商品列表
     *
     * @param comShopGoodsDTO 请求参数
     * @return 商品列表
     */
    @Override
    public R pageShopGoods(ComShopGoodsDTO comShopGoodsDTO) {
        Page page = new Page<>(comShopGoodsDTO.getPageNum(), comShopGoodsDTO.getPageSize());
        return R.ok(this.baseMapper.pageShopGoodByApps(page, comShopGoodsDTO));
    }
    /**
     * 根据商品id查询商品信息
     *
     * @param goodsId 商品id
     * @return 商品信息
     */
    @Override
    public R shopGoodsDetail(Long goodsId) {
        //根据id查询商品信息
        ComShopGoodsDO goodsDO = this.baseMapper.selectById(goodsId);
        if (goodsDO == null || goodsDO.getDeleteStatus().equals(ComShopGoodsDO.deleteStatus.yes)) {
            return R.fail(403, "商品不存在");
        }
        if (!goodsDO.getStatus().equals(ComShopGoodsDO.status.sell)) {
            return R.fail(405, "商品已下架");
        }
        //根据商品id查询商品规格信息
        List<ComShopGoodsAttrVO> goodsAttrList = new ArrayList<>();
        List<ComShopGoodsAttrDO> goodsAttrDOS = shopGoodsAttrDAO.selectList(new QueryWrapper<ComShopGoodsAttrDO>().eq("goods_id", goodsId));
        goodsAttrDOS.forEach(attrDO -> {
            ComShopGoodsAttrVO goodsAttrVO = new ComShopGoodsAttrVO();
            BeanUtils.copyProperties(attrDO, goodsAttrVO);
            goodsAttrList.add(goodsAttrVO);
        });
        //查询商品店铺信息
        ComShopStoreDO shopStoreDO = shopStoreDAO.selectById(goodsDO.getStoreId());
        PageShopStoreVO shopStoreVO = new PageShopStoreVO();
        BeanUtils.copyProperties(shopStoreDO, shopStoreVO);
        //设置值
        ComShopGoodsVO shopGoods = new ComShopGoodsVO();
        BeanUtils.copyProperties(goodsDO, shopGoods);
        shopGoods.setGoodsAttrList(goodsAttrList);
        shopGoods.setShopStoreVO(shopStoreVO);
        return R.ok(shopGoods);
    }
}