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