admin
2024-10-17 b30fb8afd3cd6228bda9b182dc412bb3c8daf69c
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
package com.yeshi.buwan.util.mq.rabbit.consumer;
 
import com.rabbitmq.client.Channel;
import com.yeshi.buwan.domain.ResourceVideo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.service.imp.ResourceVideoService;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager;
import com.yeshi.buwan.util.mq.rabbit.RabbitmqMsgConsumeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author hxh
 * @title: QueueHelloWorldListener
 * @description:
 * @date 2024/9/26 13:47
 */
@Component
public class SolrNewListener {
 
    private final static Logger logger = LoggerFactory.getLogger(SolrNewListener.class);
 
    @Resource
    private RabbitTemplate rabbitTemplate;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @Resource
    private SolrAlbumVideoDataManager solrDataManager;
 
 
    public void onMessage(Message message, Channel channel) throws Exception {
        RabbitmqMsgConsumeUtil.processMessage(message, channel, rabbitTemplate, () -> {
            String result = new String(message.getBody(), StandardCharsets.UTF_8);
            if (!StringUtil.isNullOrEmpty(result)) {
                try {
                    VideoInfo videoInfo = videoInfoService.getVideoInfo(result);
                    if (videoInfo != null) {
                        if ("1".equalsIgnoreCase(videoInfo.getShow())) {
                            List<VideoResource> resourceList = new ArrayList<>();
                            List<ResourceVideo> rvList = resourceVideoService.getResourceList(videoInfo.getId());
                            if (rvList != null)
                                for (ResourceVideo rv : rvList)
                                    resourceList.add(rv.getResource());
                            videoInfo.setResourceList(resourceList);
                            solrDataManager.saveOrUpdate(videoInfo);
                        } else
                            solrDataManager.deleteById(videoInfo.getId());
                    } else {//视频已经删除
                        solrDataManager.deleteById(result);
                    }
                } catch (Exception e) {
                    logger.error("添加到搜索引擎出错", e);
                    throw e;
                }
            }
        });
    }
}