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
93
94
95
package com.yeshi.buwan.service.imp.live;
 
import com.yeshi.buwan.dao.live.TVLiveCategoryChannelMapDao;
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.service.inter.live.TVLiveCategoryChannelService;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
@Service
public class TVLiveCategoryChannelServiceImpl implements TVLiveCategoryChannelService {
 
    @Resource
    private TVLiveCategoryChannelMapDao tvLiveCategoryChannelMapDao;
 
    @Resource
    private TVLiveChannelDao tvLiveChannelDao;
 
    @Override
    public void addMap(TVLiveCategoryChannelMap map) {
        if (map.getId() == null)
            map.setId(TVLiveCategoryChannelMap.createId(map.getCategoryId(), map.getChannelId()));
        if (tvLiveCategoryChannelMapDao.get(map.getId()) != null)
            return;
 
        if (map.getCreateTime() == null)
            map.setCreateTime(new Date());
        tvLiveCategoryChannelMapDao.save(map);
    }
 
    @Override
    public void deleteByPrimaryKey(String id) {
 
        tvLiveCategoryChannelMapDao.deleteByPrimaryKey(id);
    }
 
    @Override
    public void update(TVLiveCategoryChannelMap map) {
        if (map == null)
            return;
        tvLiveCategoryChannelMapDao.updateSelective(map);
    }
 
    @Override
    public List<TVLiveChannel> listChannelByCid(String cid, String nameKey, int page, int pageSize) {
        //查询Map
        List<TVLiveCategoryChannelMap> mapList = tvLiveCategoryChannelMapDao.listByCid(cid, (page-1)*pageSize, pageSize);
        if (mapList == null || mapList.size() == 0)
            return null;
        List<String> cids = new ArrayList<>();
 
        for (TVLiveCategoryChannelMap sc : mapList) {
            cids.add(sc.getChannelId());
        }
        List<TVLiveChannel> categoryList = tvLiveChannelDao.listByIds(cids);
        Map<String, TVLiveChannel> map = new HashMap<>();
        for (TVLiveChannel tc : categoryList) {
            map.put(tc.getId(), tc);
        }
 
 
        List<TVLiveChannel> resultList = new ArrayList<>();
        for (TVLiveCategoryChannelMap sc : mapList) {
            resultList.add(map.get(sc.getChannelId()));
        }
        return resultList;
    }
 
    @Override
    public long countChannelByCid(String cid, String nameKey) {
        return tvLiveCategoryChannelMapDao.countByCid(cid);
    }
 
    @Override
    public List<TVLiveCategoryChannelMap> listByChannelId(String channelId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("channelId").is(channelId));
 
        return tvLiveCategoryChannelMapDao.findList(query);
    }
 
    @Override
    public TVLiveCategoryChannelMap selectByCategoryIdAndChannelId(String categoryId, String channelId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("channelId").is(channelId).and("categoryId").is(categoryId));
        return tvLiveCategoryChannelMapDao.findOne(query);
    }
 
 
}