CeDo
2021-04-17 db7f51b20a98d58110db9d38b30caa95f0cbd21d
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopStoreServiceImpl.java
@@ -1,14 +1,26 @@
package com.panzhihua.service_community.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.shop.PageComShopGoodsDTO;
import com.panzhihua.common.model.dtos.shop.PageComShopStoreDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.shop.ComShopStoreVO;
import com.panzhihua.service_community.dao.ComShopGoodsDAO;
import com.panzhihua.common.model.vos.shop.ComShopStoreVO;
import com.panzhihua.common.model.vos.shop.ShopGoodsVO;
import com.panzhihua.common.model.vos.shop.ShopStoreVO;
import com.panzhihua.service_community.dao.ComShopStoreDAO;
import com.panzhihua.service_community.model.dos.ComShopGoodsDO;
import com.panzhihua.service_community.model.dos.ComShopStoreDO;
import com.panzhihua.service_community.service.ComShopStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
 * @auther lyq
@@ -19,10 +31,87 @@
@Service
public class ComShopStoreServiceImpl extends ServiceImpl<ComShopStoreDAO, ComShopStoreDO> implements ComShopStoreService {
    @Resource
    private ComShopGoodsDAO shopGoodsDAO;
    /**
     * 查询店铺列表
     * @param comShopStoreDTO   请求参数
     * @return  店铺列表
     */
    @Override
    public R pageStoreList(PageComShopStoreDTO pageComShopStoreDTO){
        Page page = new Page<>(pageComShopStoreDTO.getPageNum(),pageComShopStoreDTO.getPageSize());
        return R.ok(this.baseMapper.pageShopStore(page,pageComShopStoreDTO));
    public R pageStoreList(PageComShopStoreDTO comShopStoreDTO){
        Page page = new Page<>(comShopStoreDTO.getPageNum(),comShopStoreDTO.getPageSize());
        return R.ok(this.baseMapper.pageShopStore(page,comShopStoreDTO));
    }
    /**
     * 查询店铺详情
     * @param comShopStoreDTO   请求参数
     * @return  店铺详情
     */
    @Override
    public R shopStoreDetail(PageComShopStoreDTO comShopStoreDTO) {
        //查询店铺
        ComShopStoreDO storeDO = this.baseMapper.selectById(comShopStoreDTO.getStoreId());
        if (storeDO == null) {
            return R.fail(401,"店铺不存在");
        }
        if(storeDO.getStatus().equals(ComShopStoreDO.status.no)){
            return R.fail(402,"店铺已被禁用");
        }
        ComShopStoreVO shopStoreVO = new ComShopStoreVO();
        BeanUtils.copyProperties(storeDO, shopStoreVO);
        //查询店铺下商品信息
        Page page = new Page<>(comShopStoreDTO.getPageNum(), comShopStoreDTO.getPageSize());
        shopStoreVO.setGoodsList(shopGoodsDAO.pageShopGoodsByStoreId(page, comShopStoreDTO).getRecords());
        return R.ok(shopStoreVO);
    }
    @Override
    public R saveStore(ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
        }
        ComShopStoreDO storeDO = new ComShopStoreDO();
        BeanUtils.copyProperties(storeVO, storeDO);
        storeDO.setSale(0);
        this.baseMapper.insert(storeDO);
        return R.ok();
    }
    @Override
    public R editStore(Long id, ShopStoreVO storeVO) {
        if (storeVO == null) {
            return R.ok("500", "数据为空!");
        }
        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getId, id);
        ComShopStoreDO storeDO = new ComShopStoreDO();
        BeanUtils.copyProperties(storeVO, storeDO);
        int update = this.baseMapper.update(storeDO, query);
        return update > 0 ? R.ok() : R.fail();
    }
    @Override
    public R deleteStore(Long[] id) {
        ComShopStoreDO storeDO = new ComShopStoreDO();
        storeDO.setDeleteStatus(2);
        LambdaQueryWrapper<ComShopStoreDO> query = new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getId, id);
        int update = this.baseMapper.update(storeDO, query);
        return update > 0 ? R.ok() : R.fail();
    }
    @Override
    public R getOneInfo(Long id) {
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectById(id);
        if (comShopStoreDO == null) {
            R.fail(500,"商铺不存在");
        }
        ShopStoreVO shopStoreVO = new ShopStoreVO();
        BeanUtils.copyProperties(comShopStoreDO,shopStoreVO);
        return R.ok(shopStoreVO);
    }
}