yujian
2019-11-06 54e6398cabe1b32b1dbc9857c6a99d8f15b549f7
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
package com.yeshi.fanli.service.impl.shop;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.yeshi.utils.tencentcloud.COSManager;
 
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsClassMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsClass;
import com.yeshi.fanli.exception.shop.BanLiShopGoodsClassException;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class BanLiShopGoodsClassServiceImpl implements BanLiShopGoodsClassService {
 
    @Resource
    private BanLiShopGoodsClassMapper banLiShopGoodsClassMapper;
 
    @Override
    public BanLiShopGoodsClass selectByPrimaryKey(Long id) {
        return banLiShopGoodsClassMapper.selectByPrimaryKey(id);
    }
 
    
    @Override
    public List<BanLiShopGoodsClass> listAllGoodsClass() {
        return banLiShopGoodsClassMapper.listAllGoodsClass();
    }
    
    @Override
    public List<BanLiShopGoodsClass> listGoodsClass(int page, int pageSize, String key) {
        return banLiShopGoodsClassMapper.listGoodsClass((page - 1) * pageSize, pageSize, key);
    }
    
    @Override
    public long countGoodsClass(String key) {
        return banLiShopGoodsClassMapper.countGoodsClass(key);
    }
    
    
    @Override
    public void save( BanLiShopGoodsClass record) throws BanLiShopGoodsClassException {
        String name = record.getName();
        if (StringUtil.isNullOrEmpty(name))
            throw new BanLiShopGoodsClassException(1, "名称不能为空");
 
        record.setUpdateTime(new Date());
        if (record.getId() == null) {
            record.setCreateTime(new Date());
            banLiShopGoodsClassMapper.insert(record);
        } else {
            BanLiShopGoodsClass resultObj = banLiShopGoodsClassMapper.selectByPrimaryKey(record.getId());
            if (resultObj == null)
                throw new BanLiShopGoodsClassException(1, "修改内容已不存在");
 
            if (StringUtil.isNullOrEmpty(record.getPicture())) {
                record.setPicture(resultObj.getPicture());
            } else if (!StringUtil.isNullOrEmpty(resultObj.getPicture())) {
                COSManager.getInstance().deleteFile(resultObj.getPicture());
            }
            record.setCreateTime(resultObj.getCreateTime());
            banLiShopGoodsClassMapper.updateByPrimaryKey(record);
        }
    }
    
    
    @Override
    public void delete(List<Long> idsList) {
        if (idsList != null)
            for (Long id : idsList)
                banLiShopGoodsClassMapper.deleteByPrimaryKey(id);
 
    }
}