admin
2021-08-27 8fee151ffae0c3818694b7318583814bf92663e2
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.*;
 
import javax.annotation.Resource;
 
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.yeshi.buwan.domain.HomeVideo;
import com.yeshi.buwan.domain.VideoResource;
import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
import com.yeshi.buwan.domain.solr.SolrShortVideo;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.domain.video.VideoInfoExtra;
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.exception.video.IqiyiVideoSolrException;
import com.yeshi.buwan.videos.iqiyi.IqiYiNewAPI;
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2;
import com.yeshi.buwan.service.imp.VideoResourceService;
import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service;
import com.yeshi.buwan.service.inter.video.VideoInfoExtraService;
import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager;
import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager;
import com.yeshi.buwan.service.manager.search.SolrShortVideoDataManager;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.vo.video.VideoAdminInfoVO;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil;
import com.yeshi.buwan.service.imp.ClassService;
import com.yeshi.buwan.service.imp.VideoManager;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.web.tag.PageEntity;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/video")
public class VideoAdminController {
 
    @Resource
    private VideoManager videoManager;
 
    @Resource
    private ClassService classService;
 
 
    @Resource
    private VideoResourceService videoResourceService;
 
    @Resource
    private IqiyiUtil iqiyiUtil;
 
 
    @Resource
    private ThreadPoolTaskExecutor taskExecutor;
 
    @Resource
    private SolrAlbumVideoDataManager solrAlbumDataManager;
 
    @Resource
    private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
 
    @Resource
    private SolrShortVideoDataManager solrShortVideoDataManager;
 
 
    @Resource
    private VideoInfoExtraService videoInfoExtraService;
 
    @Resource
    private Iqiyi2Service iqiyi2Service;
 
    @Resource
    private IqiyiUtil2 iqiyiUtil2;
 
    @RequestMapping(value = "/changevideoshow", method = RequestMethod.POST)
    public void changeVideoShow(String id, int show, PrintWriter out) {
        VideoInfo vi = videoManager.getVideoInfo(id);
        if (vi != null) {
            vi.setShow(show + "");
            videoManager.changeVideoShow(vi);
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "修改成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/deletevideo", method = RequestMethod.POST)
    public void deleteVideo(String id, PrintWriter out) {
        String[] ids = id.split(",");
        for (String idStr : ids)
            videoManager.deleteVideo(idStr);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "删除成功");
        out.print(object);
    }
 
    @RequestMapping(value = "/videolist", method = RequestMethod.POST)
    public void videoList(int videotype, int page, String key, String type, String resourceIds, int fromtype, int contenttype, String freeType, String area, PrintWriter out) {
 
        if (StringUtil.isNullOrEmpty(type)) {
            type = "name";
        }
 
        Integer freeTypeInt = null;
        if (!StringUtil.isNullOrEmpty(freeType)) {
            freeTypeInt = Integer.parseInt(freeType);
        }
 
 
        List<VideoInfo> list = null;
        long count = 0;
        List<VideoAdminInfoVO> voList = new ArrayList<>();
        //正片搜索
        if (contenttype == 1) {
            SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
 
            switch (type) {
                case "name":
                    filter.setKey(key);
                    break;
                case "actor":
                    filter.setActor(key);
                    break;
                case "director":
                    filter.setDirector(key);
                    break;
            }
 
 
            filter.setVideoType(videotype == 0 ? null : videotype);
            filter.setContentType(1);
            if (!StringUtil.isNullOrEmpty(resourceIds)) {
                JSONArray array = JSONArray.fromObject(resourceIds);
                String[] rids = new String[array.size()];
                for (int i = 0; i < array.size(); i++) {
                    rids[i] = array.optString(i);
                }
                filter.setResourceIds(Arrays.asList(rids));
            }
 
            filter.setSortKey("updateTime");
 
            filter.setFreeType(freeTypeInt);
 
            filter.setArea(StringUtil.isNullOrEmpty(area) ? null : area.trim());
 
            List<VideoResource> resourceList = videoResourceService.getResourceList();
            Map<Long, String> resourceMap = new HashMap<>();
            for (VideoResource vr : resourceList) {
                resourceMap.put(Long.parseLong(vr.getId()), vr.getName());
            }
            if (fromtype == HomeVideo.FROM_TYPE_LOCAL) {
                SolrResultDTO dto = solrAlbumDataManager.find(filter, page, Constant.pageCount);
                if (dto.getVideoList() != null)
                    for (SolrAlbumVideo videoInfo : (List<SolrAlbumVideo>) dto.getVideoList())
                        voList.add(VideoAdminInfoVO.create(videoInfo, resourceMap));
                count = dto.getTotalCount();
            } else if (fromtype == HomeVideo.FROM_TYPE_INTERNET) {
                SolrResultDTO dto = solrInternetSearchVideoDataManager.find(filter, page, Constant.pageCount);
                if (dto.getVideoList() != null)
                    for (InternetSearchVideo videoInfo : (List<InternetSearchVideo>) dto.getVideoList())
                        voList.add(VideoAdminInfoVO.create(videoInfo, resourceMap));
                count = dto.getTotalCount();
            } else if (fromtype == HomeVideo.FROM_TYPE_SHORT) {
                SolrShortVideoSearchFilter shortFilter = new SolrShortVideoSearchFilter();
                shortFilter.setRootVideoType(filter.getVideoType());
                if (!StringUtil.isNullOrEmpty(key)) {
                    String[] keys = key.split(" ");
                    if (!StringUtil.isNullOrEmpty(keys[0]))
                        shortFilter.setTag(keys[0].trim());
                    if (keys.length > 1) {
                        shortFilter.setKey(key.substring(key.indexOf(keys[0])).trim());
                    }
                }
 
 
                if (!StringUtil.isNullOrEmpty(filter.getArea())) {
                    shortFilter.setAreas(Arrays.asList(new String[]{filter.getArea()}));
                    //某些短视频分类为日韩
                    if (filter.getArea().equalsIgnoreCase("韩国")) {
                        shortFilter.getAreas().add("日韩");
                    }
                }
                shortFilter.setFuzzy(true);
                SolrResultDTO dto = solrShortVideoDataManager.find(shortFilter, page, Constant.pageCount);
                if (dto.getVideoList() != null)
                    for (SolrShortVideo videoInfo : (List<SolrShortVideo>) dto.getVideoList())
                        voList.add(VideoAdminInfoVO.create(videoInfo, resourceMap));
                count = dto.getTotalCount();
            }
        } else {
            list = classService.getTypeVideoListAdmin(videotype == 0 ? "" : videotype + "", page, key,
                    contenttype);
            count = classService.getTypeVideoListAdminCount(videotype == 0 ? "" : videotype + "", key, contenttype);
            if (list != null)
                for (VideoInfo videoInfo : list)
                    voList.add(VideoAdminInfoVO.create(videoInfo));
        }
 
        List<String> ids = new ArrayList<>();
        for (VideoAdminInfoVO a : voList) {
            ids.add(a.getId());
        }
 
        List<VideoInfoExtra> extraList = videoInfoExtraService.listByIds(ids);
 
        Map<String, VideoInfoExtra> maps = Maps.uniqueIndex(extraList.iterator(), new Function<VideoInfoExtra, String>() {
            @Override
            public String apply(VideoInfoExtra extra) {
                return extra.getId();
            }
        });
        //过滤图片
        for (VideoAdminInfoVO a : voList) {
            VideoInfoExtra extra = maps.get(a.getId());
            if (extra != null) {
 
                if (a.getHpicture() != null) {
                    if (!StringUtil.isNullOrEmpty(extra.gethPosterPicture()))
                        a.setHpicture(extra.gethPosterPicture());
                }
 
                if (a.getVpicture() != null) {
                    if (!StringUtil.isNullOrEmpty(extra.getvPosterPicture()))
                        a.setVpicture(extra.getvPosterPicture());
                }
            }
        }
 
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        JSONArray array = new JSONArray();
 
        PageEntity entity = new PageEntity();
        entity.setPageIndex(page);
        entity.setPageSize(20);
        entity.setTotalCount((int) count);
 
        data.put("pageEntity", new GsonBuilder().create().toJson(entity));
        data.put("data", new Gson().toJson(voList));
        object.put("data", data);
        out.println(object);
    }
 
    @RequestMapping("updateVideos")
    public void updateVideos(PrintWriter out) {
        iqiyiUtil.updateAll("");
        out.print(JsonUtil.loadTrueAdmin("执行成功"));
    }
 
    @RequestMapping("updateIqiyiAlbum")
    public void updateIqiyiAlbum(String url, PrintWriter out) {
        String aid = IqiYiNewAPI.getAidByUrl(url);
        if (StringUtil.isNullOrEmpty(aid)) {
            out.print(JsonUtil.loadFalseAdmin("未能获取到专辑"));
        } else {
            try {
                iqiyi2Service.validAlbumSolrState(Long.parseLong(aid));
                iqiyiUtil2.syncByAid(Long.parseLong(aid),false);
            } catch (IqiyiVideoSolrException e) {
                if (e.getCode() == IqiyiVideoSolrException.CODE_ALBUM_NOT_SAVE ||
                        e.getCode() == IqiyiVideoSolrException.CODE_ALBUM_NOT_EXIST || e.getCode() == IqiyiVideoSolrException.CODE_ALBUM_NOT_ADD_TO_VIDEO) {
                    iqiyiUtil2.syncByAid(Long.parseLong(aid),false);
                } else {
                    out.print(JsonUtil.loadFalseAdmin(e.getMsg()));
                    return;
                }
            }
            out.print(JsonUtil.loadTrueAdmin("专辑更新成功"));
        }
    }
 
    @RequestMapping("addIqiyiShortVideo")
    public void addIqiyiShortVideo(String urlJson, PrintWriter out) {
//        JSONArray array = JSONArray.fromObject(urlJson);
//        int count = 0;
//        for (int i = 0; i < array.size(); i++) {
//            String aid = IqiyiUtil.getAlbumIdFromPlayUrl(array.optString(i));
//            if (!StringUtil.isNullOrEmpty(aid))
//                count++;
//
//            // 添加小视频
//
//        }
//
//        String aid = IqiyiUtil.getAlbumIdFromPlayUrl("");
//        if (StringUtil.isNullOrEmpty(aid)) {
//            out.print(JsonUtil.loadFalseAdmin("未能获取到专辑"));
//        } else {
//            iqiyiUtil.updateAlbum(aid);
//            out.print(JsonUtil.loadTrueAdmin("专辑更新成功"));
//        }
    }
 
    @RequestMapping("iqiyiUpdate")
    public void iqiyiUpdate(PrintWriter out) {
        taskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                iqiyiUtil.updateAll("");
            }
        });
        JSONObject data = new JSONObject();
        data.put("msg", "正在后台更新中");
        out.print(data);
    }
 
    @RequestMapping("getVideoInfoExtra")
    public void getVideoInfoExtra(String id, PrintWriter out) {
        VideoInfoExtra extra = videoInfoExtraService.getById(id);
        JSONObject object = new JSONObject();
        if (extra != null) {
            object.put("code", 0);
            object.put("data", new Gson().toJson(extra));
        } else {
            object.put("code", 1);
            object.put("msg", "无附加信息");
        }
        out.print(object);
    }
 
    @RequestMapping("updateVideoInfoExtra")
    public void updateVideoInfoExtra(String id, String vPicture, String hPicture, PrintWriter out) {
        VideoInfoExtra extra = new VideoInfoExtra();
        extra.setId(id);
        if (StringUtil.isNullOrEmpty(vPicture)) {
            vPicture = "";
        }
 
        extra.setvPosterPicture(vPicture);
 
        if (StringUtil.isNullOrEmpty(hPicture)) {
            hPicture = "";
        }
 
        extra.sethPosterPicture(hPicture);
 
        videoInfoExtraService.save(extra);
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        out.print(object);
    }
 
 
}