| | |
| | | package com.yeshi.buwan.util; |
| | | |
| | | import com.yeshi.buwan.domain.ResourceVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.dto.mq.FunTVAlbum2MQMsg; |
| | | import com.yeshi.buwan.dto.mq.IqiyiAlbum2MQMsg; |
| | | import com.yeshi.buwan.dto.mq.SolrVideoMQMsg; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.dto.mq.*; |
| | | import com.yeshi.buwan.funtv.entity.FunTVAlbum2; |
| | | import com.yeshi.buwan.funtv.entity.FunTVVideo2; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.service.imp.JobThreadExecutorServiceImpl; |
| | | import com.yeshi.buwan.service.imp.ResourceVideoService; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | import com.yeshi.buwan.service.inter.juhe.FunTV2Service; |
| | | import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service; |
| | | import com.yeshi.buwan.service.manager.SolrAlbumDataManager; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.manager.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.util.mq.CMQManager; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Component |
| | | public class SpringContext implements ApplicationListener<ContextRefreshedEvent> { |
| | | |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private SolrAlbumDataManager solrDataManager; |
| | | private SolrAlbumVideoDataManager solrDataManager; |
| | | |
| | | @Resource |
| | | private Iqiyi2Service iqiyi2Service; |
| | |
| | | @Resource |
| | | private FunTV2Service funTV2Service; |
| | | |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | private static boolean isInited = false; |
| | | |
| | |
| | | } |
| | | |
| | | private void init() { |
| | | doSolrJob(); |
| | | doAddIqiyi2Video(); |
| | | doAddFunTV2Video(); |
| | | logger.error("初始化"); |
| | | if (!Constant.JobTasker) { |
| | | doSolrJob(); |
| | | doAddIqiyi2Video(); |
| | | doAddFunTV2Video(); |
| | | doAddPPTVVideo(); |
| | | doDeleteVideoResource(); |
| | | doUpdateVideoExtraInfo(); |
| | | } |
| | | } |
| | | |
| | | private void doSolrJob() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<SolrVideoMQMsg> solrMsgList = CMQManager.getInstance().consumeSolrMsg(16); |
| | | if (solrMsgList != null) |
| | | for (SolrVideoMQMsg solrVideo : solrMsgList) { |
| | | try { |
| | | VideoInfo videoInfo = videoInfoService.getVideoInfo(solrVideo.getId()); |
| | | if (videoInfo != null) { |
| | | if ("1".equalsIgnoreCase(videoInfo.getShow())) |
| | | solrDataManager.saveOrUpdate(videoInfo); |
| | | else |
| | | solrDataManager.deleteById(videoInfo.getId()); |
| | | for (int i = 0; i < 5; i++) { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | logger.info("doSolrJob"); |
| | | List<SolrVideoMQMsg> solrMsgList = CMQManager.getInstance().consumeSolrMsg(16); |
| | | if (solrMsgList != null) |
| | | for (SolrVideoMQMsg solrVideo : solrMsgList) { |
| | | try { |
| | | VideoInfo videoInfo = videoInfoService.getVideoInfo(solrVideo.getId()); |
| | | if (videoInfo != null) { |
| | | if ("1".equalsIgnoreCase(videoInfo.getShow())) { |
| | | List<VideoResource> resourceList = new ArrayList<>(); |
| | | List<ResourceVideo> rvList = resourceVideoService.getResourceList(videoInfo.getId()); |
| | | if (rvList != null) |
| | | for (ResourceVideo rv : rvList) |
| | | resourceList.add(rv.getResource()); |
| | | videoInfo.setResourceList(resourceList); |
| | | solrDataManager.saveOrUpdate(videoInfo); |
| | | } else |
| | | solrDataManager.deleteById(videoInfo.getId()); |
| | | } else {//视频已经删除 |
| | | solrDataManager.deleteById(solrVideo.getId()); |
| | | } |
| | | CMQManager.getInstance().deleteSolrMsg(solrVideo.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("添加到搜索引擎出错", e); |
| | | } |
| | | CMQManager.getInstance().deleteSolrMsg(solrVideo.getHandler()); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | logger.info("doAddIqiyi2Video"); |
| | | List<IqiyiAlbum2MQMsg> iqiyiAlbumMsgList = CMQManager.getInstance().consumeIqiyiAlbumUpdateMsg(16); |
| | | if (iqiyiAlbumMsgList != null) |
| | | for (IqiyiAlbum2MQMsg iqiyiAlbum2MQMsg : iqiyiAlbumMsgList) { |
| | | try { |
| | | Long qikuID = iqiyiAlbum2MQMsg.getId(); |
| | | IqiyiAlbum2 album2 = iqiyi2Service.selectAlbumById(qikuID); |
| | | logger.info("爱奇艺专辑:" + album2.getName()); |
| | | if (album2 != null) { |
| | | iqiyi2Service.addToVideoInfo(album2); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | private void doAddPPTVVideo() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<PPTVMQMsg> pptvMsgList = CMQManager.getInstance().consumePPTVSeriesUpdateMsg(16); |
| | | if (pptvMsgList != null) |
| | | for (PPTVMQMsg pptvmqMsg : pptvMsgList) { |
| | | try { |
| | | switch (pptvmqMsg.getType()) { |
| | | case PPTVMQMsg.TYPE_ADD_OR_UPDATE: |
| | | PPTVSeries pptvSeries = pptvService.getSeriesDetail(pptvmqMsg.getInfoId()); |
| | | if (pptvSeries != null) { |
| | | pptvService.addToVideoInfo(pptvSeries); |
| | | } |
| | | break; |
| | | |
| | | case PPTVMQMsg.TYPE_DELETE: |
| | | pptvService.offLineSeries(pptvmqMsg.getInfoId()); |
| | | break; |
| | | } |
| | | CMQManager.getInstance().deletePPTVSeriesUpdateMsg(pptvmqMsg.getHandler()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | logger.error("PPTV添加到视频出错:" + e.getMessage()); |
| | | logger.error("infoId:" + pptvmqMsg.getInfoId()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | private void doDeleteVideoResource() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<CMQResult> cmqMsgList = CMQManager.getInstance().consumeVideoResourceDeleteMsg(16); |
| | | if (cmqMsgList != null) |
| | | for (CMQResult msg : cmqMsgList) { |
| | | try { |
| | | String videoId = msg.getData() + ""; |
| | | //查询资源列表 |
| | | List<ResourceVideo> resourceVideoList = resourceVideoService.getResourceList(videoId); |
| | | //隐藏视频 |
| | | if (resourceVideoList == null || resourceVideoList.size() == 0) |
| | | videoInfoService.hiddenVideo(videoId); |
| | | //更新搜索引擎 |
| | | CMQManager.getInstance().addSolrMsg(videoId); |
| | | CMQManager.getInstance().deleteVideoResourceDeleteMsg(msg.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("视频资源删除处理出错:" + e.getMessage()); |
| | | logger.error("ID:" + msg.getData()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | private void doUpdateVideoExtraInfo() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<CMQResult> cmqMsgList = CMQManager.getInstance().consumeUpdateVideoExtraInfoMsg(16); |
| | | if (cmqMsgList != null) |
| | | for (CMQResult msg : cmqMsgList) { |
| | | try { |
| | | VideoExtraInfoChangeMQMsg videoExtraInfoChangeMQMsg = (VideoExtraInfoChangeMQMsg) msg.getData(); |
| | | |
| | | if (videoExtraInfoChangeMQMsg != null) { |
| | | switch (videoExtraInfoChangeMQMsg.getType()) { |
| | | case VideoExtraInfoChangeMQMsg.TYPE_RESOURCE: |
| | | if (VideoExtraInfoChangeMQMsg.ACTION_DELETE.equalsIgnoreCase(videoExtraInfoChangeMQMsg.getAction())) {//删除视频源 |
| | | CMQManager.getInstance().addVideoResourceDeleteMsg(videoExtraInfoChangeMQMsg.getVideoId()); |
| | | } |
| | | break; |
| | | case VideoExtraInfoChangeMQMsg.TYPE_CATEGORY: |
| | | break; |
| | | } |
| | | |
| | | videoInfoService.statisticVideoExtraInfo(videoExtraInfoChangeMQMsg.getVideoId()); |
| | | } |
| | | CMQManager.getInstance().deleteUpdateVideoExtraInfoMsg(msg.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("视频资源删除处理出错:" + e.getMessage()); |
| | | logger.error("ID:" + msg.getData()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | } |