From b37275dba6b782bf3bb3817c4504f6cdef1bef7c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 18 三月 2021 18:38:51 +0800
Subject: [PATCH] APP首页顶部标签兼容

---
 src/main/java/com/yeshi/buwan/service/imp/SearchService.java |   98 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 74 insertions(+), 24 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/service/imp/SearchService.java b/src/main/java/com/yeshi/buwan/service/imp/SearchService.java
index d514e43..57b6482 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/SearchService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/SearchService.java
@@ -1,17 +1,25 @@
 package com.yeshi.buwan.service.imp;
 
 import com.yeshi.buwan.dao.*;
+import com.yeshi.buwan.dao.system.DetailSystemDao;
 import com.yeshi.buwan.domain.*;
+import com.yeshi.buwan.domain.solr.SolrAlbumVideo;
+import com.yeshi.buwan.domain.system.DetailSystem;
 import com.yeshi.buwan.domain.web.DetailSystemSelect;
 import com.yeshi.buwan.domain.web.HotSearchAdmin;
 import com.yeshi.buwan.dto.search.SolrResultDTO;
-import com.yeshi.buwan.service.manager.SolrAlbumDataManager;
+import com.yeshi.buwan.dto.search.SolrVideoSearchFilter;
+import com.yeshi.buwan.pptv.PPTVUtil;
+import com.yeshi.buwan.service.inter.video.VideoInfoExtraService;
+import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager;
 import com.yeshi.buwan.util.*;
 import com.yeshi.buwan.util.factory.VideoInfoFactory;
 import com.yeshi.buwan.util.video.VideoConstant;
 import com.yeshi.buwan.vo.video.VideoListResultVO;
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
@@ -23,6 +31,9 @@
 
 @Service
 public class SearchService {
+    private Logger logger= LoggerFactory.getLogger(SearchService.class);
+
+
     @Resource
     private SearchDao searchDao;
     @Resource
@@ -38,13 +49,16 @@
     @Resource
     private DetailSystemDao detailSystemDao;
     @Resource
-    private SolrAlbumDataManager solrAlbumDataManager;
+    private SolrAlbumVideoDataManager solrAlbumDataManager;
+
+    @Resource
+    private VideoInfoExtraService videoInfoExtraService;
 
     @SuppressWarnings("rawtypes")
     @Cacheable(value = "userCache", key = "'suggestSearch'+'-'+#key+'-'+#system")
     public List<String> suggestSearch(String key, String system) {
         if (StringUtil.isNullOrEmpty(key) || key.startsWith("%"))
-            return new ArrayList<String>();
+            return new ArrayList<>();
 
         List<String> list;
         Session session = null;
@@ -55,7 +69,7 @@
             sql = "select name as result from wk_video_video where name like ?";
         }
 
-        list = new ArrayList<String>();
+        list = new ArrayList<>();
 
         List li = null;
         try {
@@ -81,7 +95,7 @@
         }
 
         Iterator<String> it = set.iterator();
-        list = new ArrayList<String>();
+        list = new ArrayList<>();
         while (it.hasNext()) {
             list.add(it.next());
             if (list.size() > 10)
@@ -123,7 +137,7 @@
                     .append(") order by REPLACE(v.name,?,'') ,v.watchCount desc").toString();
         else
             sql = "from VideoInfo v where v.show='1' and (v.name like ?) order by REPLACE(v.name,?,''),v.watchCount desc";// 鏀逛负sql
-        List<Serializable> list = new ArrayList<Serializable>();
+        List<Serializable> list = new ArrayList<>();
         BaiduVideoUtil util = new BaiduVideoUtil();
         List<VideoInfo> localList = videoInfoDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                 new String[]{(new StringBuilder("")).append(key).append("%").toString(), key});
@@ -184,7 +198,7 @@
         searchDao.create(sh);
         // 鏌ヨ鏁版嵁搴�
 
-        List<VideoInfo> list = new ArrayList<VideoInfo>();
+        List<VideoInfo> list = new ArrayList<>();
         List<VideoInfo> localList = null;
         try {
             long startt = System.currentTimeMillis();
@@ -208,7 +222,7 @@
                 sql = sql.substring(0, sql.length() - 9);
 
             List rlist = videoInfoDao.sqlList(sql);
-            List<Integer> pList = new ArrayList<Integer>();
+            List<Integer> pList = new ArrayList<>();
             for (int i = 0; i < localList.size(); i++) {
                 if (Integer.parseInt(rlist.get(i) + "") < 1) {
                     pList.add(i);
@@ -263,7 +277,7 @@
 
         //涓撹緫鏁伴噺
         long albumCount = 0L;
-        List<VideoInfo> list = new ArrayList<VideoInfo>();
+        List<VideoInfo> list = new ArrayList<>();
         List<VideoInfo> localList = null;
         try {
             long startt = System.currentTimeMillis();
@@ -275,11 +289,20 @@
             //涓撹緫瑙嗛闆嗗悎
             Set<String> solrAlbumVids = new HashSet<>();
 
-            SolrResultDTO solrResultDTO = solrAlbumDataManager.findByKey(key, 1, videoType == 0 ? null : videoType, page, pageSize);
+            SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
+            filter.setKey(key);
+            if (videoType == Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) {
+                filter.setResourceIds(new String[]{PPTVUtil.RESOURCE_ID + ""});
+                logger.info("楂樻竻鎼滅储# key锛歿}",key);
+            } else
+                filter.setVideoType(videoType == 0 ? null : videoType);
+            filter.setContentType(1);
+
+            SolrResultDTO solrResultDTO = solrAlbumDataManager.find(filter, page, pageSize);
             if (solrResultDTO != null) {
                 albumCount = solrResultDTO.getTotalCount();
 
-                for (SolrVideo sv : solrResultDTO.getVideoList()) {
+                for (SolrAlbumVideo sv : (List<SolrAlbumVideo>) solrResultDTO.getVideoList()) {
                     VideoInfo video = VideoInfoFactory.create(sv);
                     video.setShowType(1);
                     if (!StringUtil.isNullOrEmpty(video.getMainActor())) {
@@ -315,11 +338,15 @@
 
             if (videoType == 0 && commonSolrPage > 0) {
                 //鎼滅储鍘熷鐨�
-                List<VideoInfo> solrList = SolrUtil.search(key, commonSolrPage);
-                for (VideoInfo vi : solrList) {
-                    if (!solrAlbumVids.contains(vi.getId())) {
-                        localList.add(vi);
+                try {
+                    List<VideoInfo> solrList = SolrUtil.search(key, commonSolrPage);
+                    for (VideoInfo vi : solrList) {
+                        if (!solrAlbumVids.contains(vi.getId())) {
+                            localList.add(vi);
+                        }
                     }
+                } catch (Exception e) {
+
                 }
             }
             System.out.println("鎼滅储鑰楁椂:" + (System.currentTimeMillis() - startt));
@@ -335,7 +362,7 @@
                 sql = sql.substring(0, sql.length() - 9);
 
             List rlist = StringUtil.isNullOrEmpty(sql) ? new ArrayList() : videoInfoDao.sqlList(sql);
-            List<Integer> pList = new ArrayList<Integer>();
+            List<Integer> pList = new ArrayList<>();
             for (int i = 0; i < localList.size(); i++) {
                 if (Integer.parseInt(rlist.get(i) + "") < 1) {
                     pList.add(i);
@@ -360,6 +387,10 @@
                 list.add(info);
             }
         }
+
+        //鑾峰彇闄勫姞淇℃伅
+        list = videoInfoExtraService.batchExtra(list, resourceList);
+
         return new VideoListResultVO(list, videoType == 0 ? albumCount : 1000L);
     }
 
@@ -379,7 +410,7 @@
     @SuppressWarnings({"rawtypes"})
     @Cacheable(value = "userCache", key = "'getHotSearchList'+'-'+#system")
     public List<String> getHotSearchList(String system) {
-        List<String> list = new ArrayList<String>();
+        List<String> list = new ArrayList<>();
         try {
             List li = searchDao.sqlList(
                     "SELECT h.`name` FROM wk_video_super_hotsearch sh LEFT JOIN wk_video_hotsearch h ON sh.`hotsearchid`=h.`id`  WHERE sh.`detailsystem`=? ORDER BY h.`orderby` DESC",
@@ -452,16 +483,16 @@
     }
 
     @SuppressWarnings("unchecked")
-    public List<HotSearchAdmin> getHotSearchAdmin(String key, int detailSystem, int page) {
-        List<HotSearchAdmin> zhiBoClassList = new ArrayList<HotSearchAdmin>();
+    public List<HotSearchAdmin> getHotSearchAdmin(String key, String systemId, int detailSystem, int page) {
+        List<HotSearchAdmin> zhiBoClassList = new ArrayList<>();
         try {
-            List<DetailSystem> detailSystemList = detailSystemDao.list("from DetailSystem");
+            List<DetailSystem> detailSystemList = detailSystemDao.list("from DetailSystem ds where ds.system.id=" + systemId);
             String sql = "";
             if (detailSystem > 0)
                 sql = "select sh.hotSearch from SuperHotSearch sh where sh.hotSearch.name like ? and sh.detailSystem.id="
                         + detailSystem + " order by  sh.createtime desc";
             else
-                sql = "from HotSearch zb where zb.name like ? order by zb.createtime desc";
+                sql = "from HotSearch zb where zb.name like ? and zb.system.id=" + systemId + " order by zb.createtime desc";
 
             List<HotSearch> list = hotSearchDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                     new Serializable[]{"%" + key + "%"});
@@ -469,7 +500,7 @@
                 List<DetailSystem> detailSystemS = detailSystemDao
                         .list("select vb.detailSystem from SuperHotSearch vb where vb.hotSearch.id=" + vb.getId());
 
-                List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>();
+                List<DetailSystemSelect> dssList = new ArrayList<>();
 
                 for (DetailSystem ds : detailSystemList) {
                     DetailSystemSelect dss = new DetailSystemSelect();
@@ -499,13 +530,13 @@
         return zhiBoClassList;
     }
 
-    public long getHotSearchAdminCount(String key, int detailSystem) {
+    public long getHotSearchAdminCount(String key, String systemId, int detailSystem) {
         String sql = "";
         if (detailSystem > 0)
             sql = "select count(*) from  (select count(*) from wk_video_super_hotsearch zb left join wk_video_hotsearch c on c.id=zb.hotsearchid where zb.detailsystem="
                     + detailSystem + " and c.name like '%" + key + "%' group by zb.hotsearchid) s";
         else
-            sql = "select count(*) from wk_video_hotsearch h where h.name like '%" + key + "%'";
+            sql = "select count(*) from wk_video_hotsearch h where h.name like '%" + key + "%' and h.system=" + systemId;
 
         return videoBanQuanVideoDao.getCountSQL(sql);
     }
@@ -599,4 +630,23 @@
 
     }
 
+
+    /**
+     * 灏嗘悳绱㈢粨鏋滃璞¤浆涓鸿棰戝璞�
+     *
+     * @param solrAlbumVideoList
+     * @param resourceList
+     * @return
+     */
+    public List<VideoInfo> convertSolrAlbumResultToVideo(List<SolrAlbumVideo> solrAlbumVideoList, List<Long> resourceList) {
+        List<VideoInfo> videoInfoList = new ArrayList<>();
+        for (SolrAlbumVideo sv : solrAlbumVideoList) {
+            VideoInfo video = VideoInfoFactory.create(sv);
+            videoInfoList.add(video);
+        }
+        //鑾峰彇闄勫姞淇℃伅
+        videoInfoList = videoInfoExtraService.batchExtra(videoInfoList, resourceList);
+        return videoInfoList;
+    }
+
 }

--
Gitblit v1.8.0