admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
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
package com.yeshi.fanli.service.impl.homemodule;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.tencentcloud.COSManager;
 
import com.yeshi.fanli.dao.mybatis.homemodule.SwiperBannerMapper;
import com.yeshi.fanli.entity.bus.homemodule.SwiperBanner;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.exception.banner.SwiperBannerException;
import com.yeshi.fanli.service.inter.homemodule.SwiperBannerService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.util.StringUtil;
 
@Service
public class SwiperBannerServiceImpl implements SwiperBannerService {
 
    @Resource
    private SwiperBannerMapper swiperBannerMapper;
    
    @Resource
    private SwiperPictureService swiperPictureService;
    
    
    @Override
    public int deleteByPrimaryKey(Long id){
        return swiperBannerMapper.deleteByPrimaryKey(id);
    }
 
    @Override
    public int insert(SwiperBanner record){
        return swiperBannerMapper.insert(record);
    }
 
    @Override
    public int insertSelective(SwiperBanner record){
        return swiperBannerMapper.insertSelective(record);
    }
 
    @Override
    public SwiperBanner selectByPrimaryKey(Long id){
        return swiperBannerMapper.selectByPrimaryKey(id);
    }
 
    @Override
    public int updateByPrimaryKeySelective(SwiperBanner record){
        return swiperBannerMapper.updateByPrimaryKeySelective(record);
    }
 
    @Override
    public int updateByPrimaryKey(SwiperBanner record) {
        return swiperBannerMapper.updateByPrimaryKey(record);
    }
 
    @Override
    public List<SwiperBanner> query(long start, int count, String key, Integer sort){
        return swiperBannerMapper.query(start, count, key, sort);
    }
 
    @Override
    public long countQuery(String key) {
        return swiperBannerMapper.countQuery(key);
    }
 
    @Override
    public void switchState(Long id) throws SwiperBannerException {
        if (id == null) {
            throw new SwiperBannerException(1, "请传递正确参数");
        }
        
        SwiperBanner resultObj = swiperBannerMapper.selectByPrimaryKey(id);
        if (resultObj == null) {
            throw new SwiperBannerException(1, "此内容已不存在");
        }
        
        Integer state = resultObj.getState();
        if (state == null || state == 0) {
            state = 1;
        } else {
            state = 0;
        }
        
        SwiperBanner updateObj = new SwiperBanner();
        updateObj.setId(id);
        updateObj.setState(state);
        swiperBannerMapper.updateByPrimaryKeySelective(updateObj);
    }
    
    
    @Override
    @Transactional(rollbackFor=Exception.class)
    public int deleteBatchByPrimaryKey(List<Long> list) throws Exception {
        List<Long> listPicID = new ArrayList<Long>();
        List<SwiperPicture> listPic = swiperPictureService.queryByListBannerID(list);
        for (SwiperPicture swiperPicture: listPic) {
            String src = swiperPicture.getSrc();
            if (!StringUtil.isNullOrEmpty(src)) {
                COSManager.getInstance().deleteFile(src);
            }
            listPicID.add(swiperPicture.getId());
        }
        
        if (listPicID.size() > 0) {
            swiperPictureService.deleteBatchByPrimaryKey(listPicID);
        }
        
        return swiperBannerMapper.deleteBatchByPrimaryKey(list);
    }
    
    @Override
    public List<SwiperBanner> getEffectiveOption() {
        return swiperBannerMapper.getEffectiveOption();
    }
}