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);
|
}
|
|
|
}
|