admin
2024-10-30 010ef2a907e66efd4702443c06cdd18f8a7ffa5b
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
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);
    }
 
 
}