Pu Zhibing
2024-11-27 64a71565792d4f2e9fd31eab6e98e972c12daa86
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
package com.ruoyi.other.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.enums.GoodsStatus;
import com.ruoyi.other.mapper.GoodsMapper;
import com.ruoyi.other.service.GoodsService;
import com.ruoyi.other.service.VipSettingService;
import com.ruoyi.other.vo.GoodsVO;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    @Resource
    private TokenService tokenService;
    @Resource
    private VipSettingService vipSettingService;
 
    @Override
    public List<GoodsVO> goodsList(Goods search) {
        List<Goods> goodsList = this.list(new LambdaQueryWrapper<Goods>()
                .eq(Goods::getStatus, GoodsStatus.UP)
                .eq(Objects.nonNull(search.getGoodsCategoryId()) ,Goods::getGoodsCategoryId, search.getGoodsCategoryId())
                .like(StringUtils.isNotEmpty(search.getName()), Goods::getName, search.getName()));
 
        List<GoodsVO> result = new ArrayList<>();
        for (Goods goods : goodsList) {
            GoodsVO goodsVO = new GoodsVO();
            BeanUtils.copyBeanProp(goodsVO, goods);
            result.add(goodsVO);
        }
        return result;
    }
 
    @Override
    public GoodsVO goodsDetail(Long goodsId) {
        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
        VipSetting vipSetting = vipSettingService.getVipSettingByUserId(loginUserApplet.getUserid());
 
        // TODO 根据会员等级计算价格、积分
        Goods goods = this.getById(goodsId);
        if (Objects.nonNull(goods)){
            GoodsVO goodsVO = new GoodsVO();
            BeanUtils.copyBeanProp(goodsVO, goods);
            return goodsVO;
        }
        return new GoodsVO();
    }
 
    @Override
    public List<Goods> getGoodsListByShopId(Integer shopId) {
        return goodsMapper.selectListByShopId(shopId);
    }
}