admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
128
129
130
131
132
133
package com.yeshi.buwan.service.imp.live;
 
import com.yeshi.buwan.dao.live.TVLiveChannelDao;
import com.yeshi.buwan.domain.live.TVLiveCategoryChannelMap;
import com.yeshi.buwan.domain.live.TVLiveChannel;
import com.yeshi.buwan.domain.live.TVLiveChannelResourceMap;
import com.yeshi.buwan.exception.ParamsException;
import com.yeshi.buwan.service.inter.live.TVLiveCategoryChannelService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelResourceService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelService;
import com.yeshi.buwan.util.StringUtil;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
@Service
public class TVLiveChannelServiceImpl implements TVLiveChannelService {
 
    @Resource
    private TVLiveChannelDao tvLiveChannelDao;
 
    @Resource
    private TVLiveChannelResourceService tvLiveChannelResourceService;
 
    @Resource
    private TVLiveCategoryChannelService tvLiveCategoryChannelService;
 
    @Override
    public TVLiveChannel save(TVLiveChannel channel) throws ParamsException {
        if (channel.getId() == null) {
            channel.setId(StringUtil.Md5(channel.getName()));
        }
 
        if (channel.getCreateTime() == null) {
            channel.setCreateTime(new Date());
        }
 
        if (channel.getUpdateTime() == null) {
            channel.setUpdateTime(new Date());
        }
 
 
        tvLiveChannelDao.save(channel);
        return channel;
    }
 
    @Override
    public TVLiveChannel addChannel(TVLiveChannel channel) throws ParamsException, Exception {
        if (channel == null || StringUtil.isNullOrEmpty(channel.getName())) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "名称不能为空");
        }
 
        if (StringUtil.isNullOrEmpty(channel.gethPicture())) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "横图不能为空");
        }
 
        if (channel.getId() == null) {
            channel.setId(StringUtil.Md5(channel.getName()));
        }
 
        if (channel.getState() == null) {
            channel.setState(TVLiveChannel.STATE_NORMAL);
        }
 
 
        if (tvLiveChannelDao.get(channel.getId()) != null) {
            throw new Exception("频道已经存在");
        }
 
 
        return save(channel);
    }
 
    @Override
    public void delete(String id) {
        //删除来源
        List<TVLiveChannelResourceMap> resourceMapList = tvLiveChannelResourceService.listByChannelId(id);
        for (TVLiveChannelResourceMap map : resourceMapList) {
            tvLiveChannelResourceService.delete(map.getId());
        }
        //删除分类
        List<TVLiveCategoryChannelMap> cmapList = tvLiveCategoryChannelService.listByChannelId(id);
        for (TVLiveCategoryChannelMap map : cmapList) {
            tvLiveCategoryChannelService.deleteByPrimaryKey(map.getId());
        }
 
        tvLiveChannelDao.delete(id);
    }
 
    @Override
    public void update(TVLiveChannel channel) {
        if (channel == null)
            return;
        tvLiveChannelDao.updateSelective(channel);
    }
 
    @Override
    public List<TVLiveChannel> list(String name, Integer state, int page, int pageSize) {
        TVLiveChannelDao.DaoQuery daoQuery = new TVLiveChannelDao.DaoQuery();
        daoQuery.state = state;
        daoQuery.name = name;
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{new Sort.Order(Sort.Direction.DESC, "createTime")});
        return tvLiveChannelDao.list(daoQuery);
    }
 
    @Override
    public long count(String name, Integer state) {
        TVLiveChannelDao.DaoQuery daoQuery = new TVLiveChannelDao.DaoQuery();
        daoQuery.state = state;
        daoQuery.name = name;
        return tvLiveChannelDao.count(daoQuery);
    }
 
    @Override
    public TVLiveChannel selectByPrimaryKey(String id) {
        return tvLiveChannelDao.get(id);
    }
 
    @Override
    public void savePrograms(String id, List<TVLiveChannel.TVLiveProgram> tvLivePrograms) {
        TVLiveChannel channel = new TVLiveChannel();
        channel.setId(id);
        channel.setProgramList(tvLivePrograms);
        tvLiveChannelDao.updateSelective(channel);
    }
 
}