admin
2022-04-16 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3
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
package com.yeshi.buwan.controller.parser;
 
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.special.SearchSpecial;
import com.yeshi.buwan.domain.special.SearchSpecialPositionMap;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.dto.search.SolrResultDTO;
import com.yeshi.buwan.service.inter.search.SearchSpecialPositionMapService;
import com.yeshi.buwan.service.inter.search.SearchSpecialService;
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.*;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import com.yeshi.buwan.vo.AcceptData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
 
@Controller
public class SearchParser {
    @Resource
    private SearchSpecialService searchSpecialService;
 
    @Resource
    private SearchSpecialPositionMapService searchSpecialPositionMapService;
 
    @Resource
    private SolrAlbumVideoDataManager solrAlbumVideoDataManager;
 
    @Resource
    private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
 
    @Resource
    private SolrShortVideoDataManager solrShortVideoDataManager;
 
 
    /**
     * 获取专题视频
     *
     * @param acceptData
     * @param out
     */
    public void getSpecialVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String key = request.getParameter("key");
        SearchSpecial searchSpecial = searchSpecialService.selectByPrimaryKey(key);
        if (searchSpecial == null) {
            out.print(JsonUtil.loadFalseJson("搜索专题不存在"));
            return;
        }
 
        String page = request.getParameter("page");
        if (!NumberUtil.isNumeric(page)) {
            out.print(JsonUtil.loadFalseJson("页码错误"));
            return;
        }
        int pageIndex = Integer.parseInt(page);
        switch (key) {
            case "3#hanju-bagua":
                pageIndex++;
                break;
            case "3#hanju-news":
                pageIndex += 2;
                break;
            case "3#hanju-stars":
                pageIndex += 3;
                break;
            case "3#hanju-hots":
                pageIndex += 4;
 
            case "3#hanju-music":
                pageIndex += 5;
                break;
        }
 
        List<VideoInfo> videoInfoList = new ArrayList<>();
 
        int pageSize = Constant.pageCount;
        boolean hasNextPage = false;
 
        //获取搜索条件
        SearchSpecial.QueryConditions conditions = null;
 
        if (searchSpecial.getContainerList() != null) {
            //按version排序
            Comparator<SearchSpecial.QueryConditionsContainer> cm = (o1, o2) -> o1.getMinVersion() - o2.getMinVersion();
            Collections.sort(searchSpecial.getContainerList(), cm);
 
 
            for (SearchSpecial.QueryConditionsContainer container : searchSpecial.getContainerList()) {
                if (acceptData.getDetailSystem().getId().equalsIgnoreCase(container.getDetailSystemId())) {
                    if (acceptData.getVersion() >= container.getMinVersion()) {
                        if (acceptData.getChannel().equalsIgnoreCase(container.getChannel())) {
                            conditions = container.getQueryConditions();
                            break;
                        }
                    }
                }
            }
 
            if (conditions == null) {
                for (SearchSpecial.QueryConditionsContainer container : searchSpecial.getContainerList()) {
                    if (acceptData.getDetailSystem().getId().equalsIgnoreCase(container.getDetailSystemId())) {
                        if (acceptData.getVersion() >= container.getMinVersion()) {
                            conditions = container.getQueryConditions();
                            break;
                        }
                    }
                }
            }
        }
 
 
        if (conditions.getAlbumQuery() != null) {
            SolrResultDTO solrResultDTO = solrAlbumVideoDataManager.find(conditions.getAlbumQuery(), pageIndex, pageSize);
            if (solrResultDTO != null) {
                List<SolrAlbumVideo> list = solrResultDTO.getVideoList();
                if (list != null) {
                    for (SolrAlbumVideo av : list) {
                        videoInfoList.add(VideoInfoFactory.create(av));
                    }
                    if (list.size() > 0) {
                        hasNextPage = true;
                    }
                }
            }
        }
 
        if (conditions.getInternetQuery() != null) {
            SolrResultDTO solrResultDTO = solrInternetSearchVideoDataManager.find(conditions.getInternetQuery(), pageIndex, pageSize);
            if (solrResultDTO != null) {
                List<InternetSearchVideo> list = solrResultDTO.getVideoList();
                if (list != null) {
                    for (InternetSearchVideo av : list) {
                        videoInfoList.add(VideoInfoFactory.create(av));
                    }
                    if (list.size() > 0) {
                        hasNextPage = true;
                    }
                }
            }
        }
 
        if (conditions.getShortQuery() != null) {
            SolrResultDTO solrResultDTO = solrShortVideoDataManager.find(conditions.getShortQuery(), pageIndex, pageSize);
            if (solrResultDTO != null) {
                List<SolrShortVideo> list = solrResultDTO.getVideoList();
                if (list != null) {
                    for (SolrShortVideo av : list) {
                        videoInfoList.add(VideoInfoFactory.create(av));
                    }
                    Collections.shuffle(videoInfoList);
                    if (list.size() > 0) {
                        hasNextPage = true;
                    }
                }
            }
        }
 
        JSONArray array = new JSONArray();
        for (int i = 0; i < videoInfoList.size(); i++) {
            videoInfoList.get(i).setPicture(VideoPictureUtil.getShowPicture(videoInfoList.get(i), acceptData.getPlatform(), acceptData.getVersion() + ""));
            array.add(StringUtil.outPutResultJson(videoInfoList.get(i)));
        }
        JSONObject data = new JSONObject();
        data.put("hasNextPage", hasNextPage);
        data.put("list", array);
        data.put("column", searchSpecial.getColumn());
        out.print(JsonUtil.loadTrueJson(data.toString()));
    }
 
 
    public void getSearchVideoType(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String pid = request.getParameter("pid");
        if (StringUtil.isNullOrEmpty(pid)) {
            out.print(JsonUtil.loadFalseJson("位置ID不能为空"));
            return;
        }
        JSONArray array = new JSONArray();
        List<SearchSpecialPositionMap> mapList = searchSpecialPositionMapService.listDetailByPosition(pid, 0, 50);
        for (SearchSpecialPositionMap map : mapList) {
            JSONObject item = new JSONObject();
            item.put("name", StringUtil.isNullOrEmpty(map.getShowName()) ? map.getSpecial().getName() : map.getShowName());
            item.put("id", map.getSpecialId());
            item.put("icon", map.getIcon());
            String name = item.optString("name");
            //魅族和小米不添加
            if (("xiaomi" .equalsIgnoreCase(acceptData.getChannel())) && "hanju-video-types" .equalsIgnoreCase(pid)) {
                if (name.contains("电视剧") || name.contains("电影") || name.contains("综艺") || name.contains("少儿")) {
                    array.add(item);
                }
            } else {
                array.add(item);
            }
        }
        JSONObject data = new JSONObject();
        data.put("list", array);
        data.put("count", array.size());
        out.print(JsonUtil.loadTrueJson(data.toString()));
    }
 
 
}