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
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.mall.entity.MallAddressWorld;
import cc.mrbird.febs.mall.entity.MallGoods;
import cc.mrbird.febs.mall.entity.MallGoodsCategory;
import cc.mrbird.febs.mall.mapper.MallAddressWorldMapper;
import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper;
import cc.mrbird.febs.mall.mapper.MallGoodsMapper;
import cc.mrbird.febs.mall.service.IApiMallGoodsCategoryService;
import cc.mrbird.febs.mall.vo.AdminWorldAddressVo;
import cc.mrbird.febs.mall.vo.MallGoodsCategoryVo;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author wzy
 * @date 2021-09-16
 **/
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiMallGoodsCategoryServiceImpl extends ServiceImpl<MallGoodsCategoryMapper, MallGoodsCategory> implements IApiMallGoodsCategoryService {
 
    private final MallAddressWorldMapper mallAddressWorldMapper;
    private final MallGoodsMapper mallGoodsMapper;
 
    @Override
    public List<MallGoodsCategoryVo> findAllCategoryList() {
        List<MallGoodsCategoryVo> mallGoodsCategoryVos = this.baseMapper.selectAllCategoryList();
        ArrayList<MallGoodsCategoryVo> objects = new ArrayList<>();
        if(CollUtil.isNotEmpty(mallGoodsCategoryVos)){
            mallGoodsCategoryVos.forEach(item -> {
                Long id = item.getId();
                List<MallGoods> mallGoods = mallGoodsMapper.selectList(
                        new LambdaQueryWrapper<MallGoods>()
                                .select(MallGoods::getId)
                                .eq(MallGoods::getCategoryId, id));
                if(CollUtil.isEmpty(mallGoods)){
                    objects.add(item);
                }
            });
        }
        if(CollUtil.isNotEmpty(objects)){
            mallGoodsCategoryVos.removeAll(objects);
        }
        return mallGoodsCategoryVos;
    }
 
    @Override
    public List<MallGoodsCategory> findChildCategoryListById(Long id) {
        return this.baseMapper.selectCategoryListByParentId(id);
    }
 
    @Override
    public List<MallGoodsCategory> findRecommendCategory() {
        return this.baseMapper.selectRecommendCategoryList();
    }
 
    @Override
    public List<AdminWorldAddressVo> findAllAddressList() {
        List<AdminWorldAddressVo> objects = new ArrayList<>();
        LambdaQueryWrapper<MallAddressWorld> addressWorldLambdaQueryWrapper = new LambdaQueryWrapper<>();
        addressWorldLambdaQueryWrapper.eq(MallAddressWorld::getPid, 131)
                .eq(MallAddressWorld::getLevel, 3)
                .orderByAsc(MallAddressWorld::getId);
        // 执行查询
        List<MallAddressWorld> mallAddressWorlds = mallAddressWorldMapper.selectList(addressWorldLambdaQueryWrapper);
        if(CollUtil.isNotEmpty(mallAddressWorlds)){
            mallAddressWorlds.forEach(item -> {
                AdminWorldAddressVo adminWorldAddressVo = new AdminWorldAddressVo();
                adminWorldAddressVo.setId(item.getId());
                adminWorldAddressVo.setName(item.getName()+"-"+item.getNameEn()+"-"+item.getNamePinyin());
                objects.add(adminWorldAddressVo);
            });
        }
        return objects;
    }
}