admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package com.hxh.spring.test;
 
import com.yeshi.buwan.dao.HomeNoticeDao;
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
import com.yeshi.buwan.domain.solr.SolrShortVideo;
import com.yeshi.buwan.domain.video.AlbumVideoMap;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.dto.search.SolrResultDTO;
import com.yeshi.buwan.dto.search.SolrShortVideoSearchFilter;
import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
import com.yeshi.buwan.job.video.ShortVideoUpdateJob;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.inter.juhe.AlbumVideoMapService;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager;
import com.yeshi.buwan.service.manager.SolrCommonVideoDataManager;
import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager;
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.util.video.VideoConstant;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
 
import javax.annotation.Resource;
import java.util.*;
 
 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class SolrTest {
 
    @Resource
    private SolrAlbumVideoDataManager solrDataManager;
 
    @Resource
    private SolrCommonVideoDataManager solrCommonVideoDataManager;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @Resource
    private HomeNoticeDao homeNoticeDao;
    @Resource
    private AlbumVideoMapService albumVideoMapService;
 
    @Resource
    private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
 
    @Resource
    private SolrShortVideoDataManager solrShortVideoDataManager;
 
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
 
    @Test
    public void test1() {
        SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
        filter.setKey("");
        filter.setVideoType(null);
        filter.setContentType(1);
//        filter.setResourceIds(new String[]{"24"});
 
        SolrResultDTO dto = solrDataManager.find(filter, 1, 10);
        System.out.println(dto);
    }
 
    @Test
    public void addSolrAlbum() {
        solrDataManager.syncAlbum("8268378");
        System.out.println();
    }
 
 
    @Test
    public void syncSolrCommonVideo() {
//        solrCommonVideoDataManager.syncAllVideo();
    }
 
 
    private VideoInfo loadAlbumData(VideoInfo video) {
        video.setShowType(1);
        if (!StringUtil.isNullOrEmpty(video.getMainActor())) {
            video.setMainActor("主演:" + video.getMainActor());
        }
 
        //设置tag
        String tag = "";
        if (!StringUtil.isNullOrEmpty(video.getYear())) {
            tag += video.getYear() + "/";
        }
 
        if (video.getVideoType() != null) {
            String vt = VideoConstant.getMainCategoryName(video.getVideoType().getId());
            if (!StringUtil.isNullOrEmpty(vt)) {
                tag += vt + "/";
            }
        }
 
        if (!StringUtil.isNullOrEmpty(video.getArea())) {
            tag += video.getArea() + "/";
        }
 
        if (tag.endsWith("/"))
            tag = tag.substring(0, tag.length() - 1);
        video.setTag(tag);
 
        return video;
    }
 
 
    private int searchAll(String key) {
        int page = 1;
        int pageSize = 20;
        SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
        filter.setKey(key);
        filter.setContentType(1);
        List<VideoInfo> localList = new ArrayList<>();
        SolrResultDTO solrResultDTO = solrDataManager.find(filter, page, pageSize);
        Set<String> albumSet = new HashSet<>();
        if (solrResultDTO != null) {
            for (SolrAlbumVideo sv : (List<SolrAlbumVideo>) solrResultDTO.getVideoList()) {
                VideoInfo video = VideoInfoFactory.create(sv);
                albumSet.add(video.getName() + "#" + video.getVideoType().getId());
                video = loadAlbumData(video);
                localList.add(video);
            }
        }
 
 
        //全网搜
        SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, page, pageSize);
        if (internetSearchResultDTO != null && internetSearchResultDTO.getVideoList().size() > 0) {
            List<InternetSearchVideo> isvList = internetSearchResultDTO.getVideoList();
            //删除前面有的数据,根据rootType与名称筛选
            for (int i = 0; i < isvList.size(); i++) {
                String uniqueId = isvList.get(i).getName() + "#" + isvList.get(i).getRootType();
                if (albumSet.contains(uniqueId)) {
                    isvList.remove(i);
                    i--;
                }
            }
            for (InternetSearchVideo sv : isvList) {
                VideoInfo video = VideoInfoFactory.create(sv);
                video = loadAlbumData(video);
                localList.add(video);
            }
        }
        return localList.size();
    }
 
 
    @Test
    public void search() {
 
    }
 
 
    @Test
    public void addInternet() {
        InternetSearchVideo list = internetSearchVideoService.selectByPrimaryKey("38ac0127d0cc3433e09964e757ab3505"); //listAll(1, 10);
        solrInternetSearchVideoDataManager.saveOrUpdate(list);
    }
 
    @Test
    public void deleteInternet() {
        String st = "161469b4aa35ca7ae1cc5d3ddaa23276,3b57b603b4eef496ce0de50f06ca40c0";
 
 
        for (String id : st.split(","))
            solrInternetSearchVideoDataManager.deleteById(id);
    }
 
 
    @Resource
    private AlbumVideoMapDao albumVideoMapDao;
 
    @Test
    public void test2() {
 
        for (int i = 0; i < 100; i++) {
            Query query = new Query();
            query.addCriteria(Criteria.where("id").type(7));
            query.limit(100);
            List<AlbumVideoMap> list = albumVideoMapDao.findList(query);
 
 
            for (AlbumVideoMap map : list) {
                AlbumVideoMap newMap = new AlbumVideoMap();
                newMap.setVideoCount(map.getVideoCount());
                newMap.setRootVideoType(map.getRootVideoType());
                newMap.setVideoId(map.getVideoId());
                newMap.setCreateTime(new Date());
                newMap.setId(map.getVideoId());
                albumVideoMapDao.save(newMap);
                albumVideoMapDao.deleteByPrimaryKey(map.getId());
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
//    @Test
//    public void clear(){
//        solrDataManager.clear();
//    }
 
    @Resource
    private com.yeshi.buwan.job.video.ShortVideoUpdateJob shortVideoUpdateJob;
 
    @Test
    public void iqiyiShortVideo() {
 
        JSONObject params = new JSONObject();
        params.put("videoType", 155);
        params.put("url", "https://list.iqiyi.com/www/7/186-------------24-1-2-iqiyi--.html?s_source=PCW_LC");
 
        try {
            shortVideoUpdateJob.updateIqiyiShortVideo(params.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    //https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&listpage=1&sort=40
    @Test
    public void tencentShortVideo() {
        JSONObject params = new JSONObject();
        params.put("videoType", 155);
        params.put("area", "日韩");
        params.put("url", "https://v.qq.com/channel/ent?_all=1&channel=ent&iarea=2&listpage=1&sort=40");
 
        try {
            shortVideoUpdateJob.updateTencentShortVideo(params.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    @Test
    public void clearShortVideo() {
        SolrShortVideoSearchFilter filter = new SolrShortVideoSearchFilter();
        for (int i = 0; i < 4; i++) {
            SolrResultDTO dto = solrShortVideoDataManager.find(filter, 1, 500);
            List<SolrShortVideo> list = (List<SolrShortVideo>) dto.getVideoList();
            for (SolrShortVideo video : list) {
                solrShortVideoDataManager.deleteById(video.getId());
            }
        }
    }
 
 
    @Test
    public void addToAlbum() {
        albumVideoMapService.add(videoInfoService.getVideoInfo("8441251"));
    }
 
 
    @Test
    public void getById() {
 
        SolrAlbumVideo solrAlbumVideo = solrDataManager.findOne("8441251");
        System.out.println(solrAlbumVideo);
    }
 
}