| | |
| | | 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.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.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; |
| | |
| | | |
| | | @Service |
| | | public class SearchService { |
| | | private Logger logger= LoggerFactory.getLogger(SearchService.class); |
| | | |
| | | |
| | | @Resource |
| | | private SearchDao searchDao; |
| | | @Resource |
| | |
| | | @Resource |
| | | private DetailSystemDao detailSystemDao; |
| | | @Resource |
| | | private SolrAlbumDataManager solrAlbumDataManager; |
| | | private SolrAlbumVideoDataManager solrAlbumDataManager; |
| | | |
| | | @Resource |
| | | private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService; |
| | | private VideoInfoExtraService videoInfoExtraService; |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | @Cacheable(value = "userCache", key = "'suggestSearch'+'-'+#key+'-'+#system") |
| | |
| | | |
| | | SolrVideoSearchFilter filter = new SolrVideoSearchFilter(); |
| | | filter.setKey(key); |
| | | filter.setVideoType(videoType == 0 ? null : videoType); |
| | | 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())) { |
| | |
| | | |
| | | 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)); |
| | |
| | | } |
| | | |
| | | //获取附加信息 |
| | | list = videoResourceMapExtraInfoService.batchExtraInfo(list, resourceList); |
| | | list = videoInfoExtraService.batchExtra(list, resourceList); |
| | | |
| | | return new VideoListResultVO(list, videoType == 0 ? albumCount : 1000L); |
| | | } |
| | |
| | | } |
| | | |
| | | @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 + "%"}); |
| | |
| | | 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); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 将搜索结果对象转为视频对象 |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | } |