jiaosong
2023-09-08 cbf7bd4c7d62670b26292d4738cc062bf965591c
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
package com.doumee.service.business.impl;
 
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.BaseGoodsMapper;
import com.doumee.dao.business.join.BaseGoodsJoinMapper;
import com.doumee.dao.business.model.BaseGoods;
import com.doumee.dao.business.model.Goods;
import com.doumee.service.business.BaseGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
 
/**
 * 素材库-商品信息表Service实现
 * @author 江蹄蹄
 * @date 2023/09/07 11:41
 */
@Service
public class BaseGoodsServiceImpl implements BaseGoodsService {
 
    @Autowired
    private BaseGoodsMapper baseGoodsMapper;
 
 
    @Autowired
    private BaseGoodsJoinMapper baseGoodsJoinMapper;
 
    @Override
    public Integer create(BaseGoods baseGoods) {
        baseGoodsMapper.insert(baseGoods);
        return baseGoods.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        baseGoodsMapper.deleteById(id);
    }
 
    @Override
    public void delete(BaseGoods baseGoods) {
        UpdateWrapper<BaseGoods> deleteWrapper = new UpdateWrapper<>(baseGoods);
        baseGoodsMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        baseGoodsMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(BaseGoods baseGoods) {
        baseGoodsMapper.updateById(baseGoods);
    }
 
    @Override
    public void updateByIdInBatch(List<BaseGoods> baseGoodss) {
        if (CollectionUtils.isEmpty(baseGoodss)) {
            return;
        }
        for (BaseGoods baseGoods: baseGoodss) {
            this.updateById(baseGoods);
        }
    }
 
    @Override
    public BaseGoods findById(Integer id) {
        return baseGoodsMapper.selectById(id);
    }
 
    @Override
    public BaseGoods findOne(BaseGoods baseGoods) {
        QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods);
        return baseGoodsMapper.selectOne(wrapper);
    }
 
    @Override
    public List<BaseGoods> findList(BaseGoods baseGoods) {
        QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods);
        return baseGoodsMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<BaseGoods> findPage(PageWrap<BaseGoods> pageWrap) {
        IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.eq(BaseGoods::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.eq(BaseGoods::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(BaseGoods::getStatus, pageWrap.getModel().getStatus());
        }
 
 
        if (pageWrap.getModel().getCategoryId() != null) {
            queryWrapper.eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId());
        }
        if (pageWrap.getModel().getBrandId() != null) {
            queryWrapper.eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId());
        }
 
        queryWrapper.orderByDesc(Goods::getId);
        return PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper));
    }
 
    @Override
    public long count(BaseGoods baseGoods) {
        QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods);
        return baseGoodsMapper.selectCount(wrapper);
    }
}