admin
2021-09-03 b41a6efe17ba61d150c5a9b7309651cebae54e0d
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
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 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);
    }
    
}