package com.yeshi.buwan.service.imp;
|
|
import com.yeshi.buwan.dao.CategoryVideoDao;
|
import com.yeshi.buwan.domain.CategoryVideo;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoType;
|
import com.yeshi.buwan.dto.mq.VideoDataChangeMQMsg;
|
import com.yeshi.buwan.dto.mq.VideoExtraInfoChangeMQMsg;
|
import com.yeshi.buwan.util.mq.rabbit.RabbitmqManager;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service
|
public class CategoryVideoService {
|
|
@Autowired
|
private CategoryVideoDao categoryVideoDao;
|
|
@Resource
|
private RabbitmqManager rabbitmqManager;
|
|
public void addCategoryVideo(String videoId, long categoryId) {
|
List<CategoryVideo> list = categoryVideoDao.listByVideoIdAndCategoryId(videoId, categoryId);
|
if (list == null || list.size() == 0) {
|
CategoryVideo cv = new CategoryVideo();
|
cv.setVideo(new VideoInfo(videoId));
|
cv.setVideoType(new VideoType(categoryId));
|
categoryVideoDao.save(cv);
|
rabbitmqManager.addVideoExtraInfoChanged(new VideoExtraInfoChangeMQMsg(VideoExtraInfoChangeMQMsg.TYPE_CATEGORY, videoId, VideoExtraInfoChangeMQMsg.ACTION_ADD));
|
rabbitmqManager.addVideoDataChanged(new VideoDataChangeMQMsg(VideoDataChangeMQMsg.TYPE_VIDEO_CATEGORY, videoId, VideoDataChangeMQMsg.ACTION_ADD));
|
}
|
}
|
|
public List<CategoryVideo> getCategoryList(List<VideoInfo> videoInfoList) {
|
String hql = "from CategoryVideo cv where ";
|
List<String> orList = new ArrayList<>();
|
for (VideoInfo videoInfo : videoInfoList) {
|
orList.add("cv.video.id=" + videoInfo.getId());
|
}
|
hql += StringUtil.concat(orList, " or ");
|
return categoryVideoDao.list(hql);
|
}
|
|
public List<CategoryVideo> getCategoryList(String videoId) {
|
String hql = "from CategoryVideo cv where cv.video.id=" + videoId;
|
return categoryVideoDao.list(hql);
|
}
|
|
|
}
|