From 759f8df85ddb840682f91bad31e874fa0b58c075 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 14 四月 2021 19:16:12 +0800
Subject: [PATCH] 订单系统修改
---
src/main/java/com/yeshi/buwan/service/imp/SearchService.java | 329 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 237 insertions(+), 92 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 a47c440..be9f7af 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/SearchService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/SearchService.java
@@ -1,19 +1,27 @@
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.video.InternetSearchVideo;
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.dto.search.SolrVideoSearchFilter;
-import com.yeshi.buwan.service.inter.VideoResourceMapExtraInfoService;
-import com.yeshi.buwan.service.manager.SolrAlbumDataManager;
+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.service.manager.SolrInternetSearchVideoDataManager;
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;
@@ -25,6 +33,9 @@
@Service
public class SearchService {
+ private Logger logger = LoggerFactory.getLogger(SearchService.class);
+
+
@Resource
private SearchDao searchDao;
@Resource
@@ -40,10 +51,13 @@
@Resource
private DetailSystemDao detailSystemDao;
@Resource
- private SolrAlbumDataManager solrAlbumDataManager;
+ private SolrAlbumVideoDataManager solrAlbumDataManager;
@Resource
- private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService;
+ private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager;
+
+ @Resource
+ private VideoInfoExtraService videoInfoExtraService;
@SuppressWarnings("rawtypes")
@Cacheable(value = "userCache", key = "'suggestSearch'+'-'+#key+'-'+#system")
@@ -242,9 +256,118 @@
}
- @Cacheable(value = "userCache", key = "'searchNew'+'-'+#detailSystem+'-'+#key+'-'+#page+'-'+#videoType+'-'+#system+'-'+#cacheMD5")
- public VideoListResultVO searchNew(String detailSystem, String ip, String uid, String key, int page, int videoType,
- String system, List<Long> resourceList, String cacheMD5) {
+ 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;
+
+ }
+
+
+ public SearchResult searchAlbum(int videoType, String key, int page, int pageSize) {
+ List<VideoInfo> localList = new ArrayList<>();
+ //涓撹緫瑙嗛闆嗗悎
+ Set<String> solrAlbumVids = new HashSet<>();
+
+ 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);
+ Set<String> albumSet = new HashSet<>();
+ int albumCount = 0;
+ if (solrResultDTO != null) {
+ albumCount = solrResultDTO.getTotalCount();
+ 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);
+ solrAlbumVids.add(video.getId());
+ }
+ }
+
+ //绗竴椤�,涓嶄负楂樻竻,涓绘悳绱㈠紩鎿庢棤娉曟悳绱㈠埌鍐呭鏃舵悳绱�
+ if (page == 1 && videoType != Constant.SEARCH_RESULT_TYPE_HIGH_DEFINITION) {
+ //page涓�1鏃� 鍏ㄧ綉鎼�
+ SolrResultDTO internetSearchResultDTO = solrInternetSearchVideoDataManager.find(filter, 1, 20);
+ if (internetSearchResultDTO != null && internetSearchResultDTO.getVideoList().size() > 0) {
+ List<InternetSearchVideo> iList = internetSearchResultDTO.getVideoList();
+ List<InternetSearchVideo> isvList = new ArrayList<>();
+ if (iList != null && iList.size() > 0)
+ isvList.addAll(iList);
+ //鍒犻櫎鍓嶉潰鏈夌殑鏁版嵁锛屾牴鎹畆ootType涓庡悕绉扮瓫閫�
+ 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);
+ if (albumCount < 3) {
+ localList.add(video);
+ } else {
+ if (video.getName().equalsIgnoreCase(key))
+ localList.add(video);
+ }
+ }
+ }
+ //鎸夊叧閿瘝鐨勫尮閰嶅害鎺掑簭
+ Comparator<VideoInfo> cm = new Comparator<VideoInfo>() {
+ @Override
+ public int compare(VideoInfo o1, VideoInfo o2) {
+ float s1 = CompareStrSimUtil.getSimilarityRatio(o1.getName(), key, true);
+ float s2 = CompareStrSimUtil.getSimilarityRatio(o2.getName(), key, true);
+ if (s1 != s2)//鐩镐技搴﹁秺楂樿秺闈犲墠
+ return s2 > s1 ? 1 : -1;
+ else
+ return o1.getDefinition() - o2.getDefinition();//楂樻竻鎺掑湪鍓�
+ }
+ };
+
+ Collections.sort(localList, cm);
+ }
+ //鏈悳绱㈠埌鍐呭
+ if (localList == null || localList.size() == 0) {
+ logger.warn("涓撹緫鎼滅储鏃犵粨鏋�#{}", key);
+ }
+ return new SearchResult(albumCount, localList);
+ }
+
+ private void filterSearchResult(List<VideoInfo> localList, List<Long> resourceList) {
+ String sql = "";
String resourceWhere = "";
for (Long re : resourceList) {
resourceWhere += " rv.resourceid=" + re + " or";
@@ -253,6 +376,40 @@
if (resourceWhere.endsWith("or"))
resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2);
+
+ List<String> filterVideoIdList = new ArrayList<>();
+
+ for (int i = 0; i < localList.size(); i++) {
+ if (NumberUtil.isNumeric(localList.get(i).getId())) {
+ filterVideoIdList.add(localList.get(i).getId());
+ sql += " select count(*) from wk_resource_video rv left join wk_video_video v on rv.videoid=v.id where v.id is not null and v.show=1 and rv.videoid="
+ + localList.get(i).getId() + " and (" + resourceWhere + ") union all";
+ }
+ }
+
+ if (sql.endsWith("union all"))
+ sql = sql.substring(0, sql.length() - 9);
+
+ List rlist = StringUtil.isNullOrEmpty(sql) ? new ArrayList() : videoInfoDao.sqlList(sql);
+ Set<String> deleteVids = new HashSet<>();
+ for (int i = 0; i < filterVideoIdList.size(); i++) {
+ if (Integer.parseInt(rlist.get(i) + "") < 1) {
+ deleteVids.add(filterVideoIdList.get(i));
+ }
+ }
+
+ for (int i = 0; i < localList.size(); i++) {
+ if (deleteVids.contains(localList.get(i).getId())) {
+ localList.remove(i);
+ i--;
+ }
+ }
+ }
+
+
+ @Cacheable(value = "userCache", key = "'searchNew'+'-'+#detailSystem+'-'+#key+'-'+#page+'-'+#videoType+'-'+#system+'-'+#cacheMD5")
+ public VideoListResultVO searchNew(String detailSystem, String ip, String uid, String key, int page, int videoType,
+ String system, List<Long> resourceList, String cacheMD5) {
SearchHistory sh = new SearchHistory();
sh.setCreatetime((new StringBuilder(String.valueOf(System.currentTimeMillis()))).toString());
sh.setIp(ip);
@@ -277,102 +434,44 @@
localList = new ArrayList<>();
//鍏堟悳绱笓杈�
int pageSize = 20;
- //涓撹緫瑙嗛闆嗗悎
- Set<String> solrAlbumVids = new HashSet<>();
-
- SolrVideoSearchFilter filter = new SolrVideoSearchFilter();
- filter.setKey(key);
- 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()) {
- VideoInfo video = VideoInfoFactory.create(sv);
- video.setShowType(1);
- if (!StringUtil.isNullOrEmpty(video.getMainActor())) {
- video.setMainActor("涓绘紨锛�" + video.getMainActor());
- }
-
- //璁剧疆tag
- String tag = "";
- if (!StringUtil.isNullOrEmpty(sv.getYear())) {
- tag += sv.getYear() + "/";
- }
-
- if (video.getVideoType() != null) {
- String vt = VideoConstant.getMainCategoryName(sv.getRootVideoType());
- 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);
-
- localList.add(video);
- solrAlbumVids.add(video.getId());
- }
+ SearchResult searchResult = searchAlbum(videoType, key, page, pageSize);
+ if (searchResult != null && searchResult.videoInfoList != null) {
+ localList.addAll(searchResult.videoInfoList);
}
- int commonSolrPage = page - solrResultDTO.getTotalCount() / pageSize;
+
+ Set<String> solrAlbumVids = new HashSet<>();
+ for (VideoInfo videoInfo : localList) {
+ solrAlbumVids.add(videoInfo.getId());
+ }
+
+
+ int commonSolrPage = page - searchResult.getTotalCount() / pageSize;
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));
-
- String sql = "";
- startt = System.currentTimeMillis();
- for (int i = 0; i < localList.size(); i++) {
- sql += " select count(*) from wk_resource_video rv left join wk_video_video v on rv.videoid=v.id where v.id is not null and v.show=1 and rv.videoid="
- + localList.get(i).getId() + " and (" + resourceWhere + ") union all";
- }
-
- if (sql.endsWith("union all"))
- sql = sql.substring(0, sql.length() - 9);
-
- List rlist = StringUtil.isNullOrEmpty(sql) ? new ArrayList() : videoInfoDao.sqlList(sql);
- List<Integer> pList = new ArrayList<>();
- for (int i = 0; i < localList.size(); i++) {
- if (Integer.parseInt(rlist.get(i) + "") < 1) {
- pList.add(i);
- // localList.remove(i);
- // i--;
- }
- }
-
- Collections.sort(pList);
- for (int i = pList.size() - 1; i >= 0; i--) {
- localList.remove((int) pList.get(i));
- }
-
- System.out.println("鎺掗櫎鑰楁椂:" + (System.currentTimeMillis() - startt));
-
+ filterSearchResult(localList, resourceList);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
if (localList != null && localList.size() > 0) {
- for (VideoInfo info : localList) {
- list.add(info);
- }
+ list.addAll(localList);
}
//鑾峰彇闄勫姞淇℃伅
- list = videoResourceMapExtraInfoService.batchExtraInfo(list, resourceList);
+ list = videoInfoExtraService.batchExtra(list, resourceList);
return new VideoListResultVO(list, videoType == 0 ? albumCount : 1000L);
}
@@ -466,16 +565,16 @@
}
@SuppressWarnings("unchecked")
- public List<HotSearchAdmin> getHotSearchAdmin(String key, int detailSystem, int page) {
+ 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 + "%"});
@@ -513,13 +612,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);
}
@@ -613,4 +712,50 @@
}
+
+ /**
+ * 灏嗘悳绱㈢粨鏋滃璞¤浆涓鸿棰戝璞�
+ *
+ * @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;
+ }
+
+
+ public static class SearchResult {
+ private int totalCount;
+ private List<VideoInfo> videoInfoList;
+
+ public SearchResult(int totalCount, List<VideoInfo> videoInfoList) {
+ this.totalCount = totalCount;
+ this.videoInfoList = videoInfoList;
+ }
+
+ public int getTotalCount() {
+ return totalCount;
+ }
+
+ public void setTotalCount(int totalCount) {
+ this.totalCount = totalCount;
+ }
+
+ public List<VideoInfo> getVideoInfoList() {
+ return videoInfoList;
+ }
+
+ public void setVideoInfoList(List<VideoInfo> videoInfoList) {
+ this.videoInfoList = videoInfoList;
+ }
+ }
+
}
--
Gitblit v1.8.0