Pu Zhibing
2024-11-27 5f21fd4703a6893e4385d55dafbf5b2a1a1d7785
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
package com.ruoyi.order.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.mapper.ShoppingCartMapper;
import com.ruoyi.order.service.ShoppingCartService;
import com.ruoyi.order.vo.MyShoppingCartVo;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.api.feignClient.GoodsClient;
import model.ShoppingCart;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private GoodsClient goodsClient;
    
    
    
    
    
    
    
    /**
     * 获取购物车列表
     * @param type
     * @param shopId
     * @return
     */
    @Override
    public List<MyShoppingCartVo> getMyShoppingCart(Integer type, Integer shopId) {
        Long userid = tokenService.getLoginUserApplet().getUserid();
        //获取对应类型的商品数据
        List<Goods> data = goodsClient.getGoodsByType(type).getData();
        if(null == data){
            throw new RuntimeException("根据类型(1=服务商品,2=单品商品)获取商品数据失败");
        }
        List<Long> goodsIds = data.stream().map(Goods::getId).collect(Collectors.toList());
        //查询符合商品类型的商品数据
        List<ShoppingCart> list = this.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds));
        List<MyShoppingCartVo> page = new ArrayList<>();
        //构建返回数据
        for (ShoppingCart shoppingCart : list) {
            MyShoppingCartVo vo = new MyShoppingCartVo();
            
            
            
            
            page.add(vo);
        }
        return page;
    }
}