CeDo
2021-04-19 96c23f980f38cfd00fbb27c62fa6a4902d0ecb93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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.PageComShopStoreDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.service_community.dao.ComShopGoodsDAO;
import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
import com.panzhihua.common.model.vos.shop.ShopStoreVO;
import com.panzhihua.service_community.dao.ComShopStoreDAO;
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
 * @create 2021-04-14 15:03:55
 * @describe 店铺表服务实现类
 */
@Slf4j
@Service
public class ComShopStoreServiceImpl extends ServiceImpl<ComShopStoreDAO, ComShopStoreDO> implements ComShopStoreService {
 
    @Resource
    private ComShopGoodsDAO shopGoodsDAO;
 
    /**
     * 查询店铺列表
     * @param pageComShopStoreDTO   请求参数
     * @return  店铺列表
     */
 
    @Override
    public R pageStoreList(PageComShopStoreDTO pageComShopStoreDTO) {
        Page page = new Page<>(pageComShopStoreDTO.getPageNum(), pageComShopStoreDTO.getPageSize());
        IPage<PageShopStoreVO> comShopStoreVOIPage = this.baseMapper.pageShopStore(page, pageComShopStoreDTO);
        return R.ok(comShopStoreVOIPage);
    }
 
    /**
     * 查询店铺详情
     * @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,"店铺已被禁用");
        }
        PageShopStoreVO shopStoreVO = new PageShopStoreVO();
        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);
    }
 
    @Override
    public R getUserStoreInfo(Long userId) {
        ComShopStoreDO comShopStoreDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopStoreDO>().eq(ComShopStoreDO::getDeleteStatus, 1).eq(ComShopStoreDO::getSysUserId, userId));
        if (comShopStoreDO == null) {
            R.fail(500,"商铺不存在");
        }
        ShopStoreVO shopStoreVO = new ShopStoreVO();
        BeanUtils.copyProperties(comShopStoreDO,shopStoreVO);
        return R.ok(shopStoreVO);
    }
}