| | |
| | | package com.yeshi.buwan.util; |
| | | |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import com.yeshi.buwan.dao.juhe.iqiyi.VideoIqiyi2Dao; |
| | | import com.yeshi.buwan.domain.ResourceVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.domain.video.InternetSearchVideo; |
| | | import com.yeshi.buwan.dto.mq.*; |
| | | import com.yeshi.buwan.videos.funtv.entity.FunTVAlbum2; |
| | | import com.yeshi.buwan.videos.iqiyi.IqiYiNewAPI; |
| | | import com.yeshi.buwan.videos.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.videos.iqiyi.entity.VideoIqiyi2; |
| | | import com.yeshi.buwan.videos.iqiyi.util.IqiyiUtil2; |
| | | import com.yeshi.buwan.videos.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.InternetSearchVideoService; |
| | | import com.yeshi.buwan.service.inter.juhe.Iqiyi2Service; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.manager.search.SolrAlbumVideoDataManager; |
| | | import com.yeshi.buwan.service.manager.search.SolrInternetSearchVideoDataManager; |
| | | import com.yeshi.buwan.util.mq.CMQManager; |
| | | import io.seata.rm.datasource.DataSourceProxy; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import org.springframework.context.event.ContextRefreshedEvent; |
| | | 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 SolrAlbumVideoDataManager solrDataManager; |
| | | |
| | | @Resource |
| | | private Iqiyi2Service iqiyi2Service; |
| | | |
| | | @Resource |
| | | private IqiyiUtil2 iqiyiUtil2; |
| | | |
| | | @Resource |
| | | private FunTV2Service funTV2Service; |
| | | |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | |
| | | private static boolean isInited = false; |
| | |
| | | |
| | | private void init() { |
| | | logger.error("初始化"); |
| | | // if (!Constant.JobTasker) { |
| | | doSolrJob(); |
| | | doAddIqiyi2Video(); |
| | | doAddFunTV2Video(); |
| | | doAddPPTVVideo(); |
| | | doDeleteVideoResource(); |
| | | doUpdateVideoExtraInfo(); |
| | | doInternetSearchVideoUpdateJob(); |
| | | doUpdateResourceVideoJob(); |
| | | // } |
| | | // doUpdateResourceVideoJob(); |
| | | } |
| | | |
| | | private void doSolrJob() { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private InternetSearchVideoService internetSearchVideoService; |
| | | |
| | | @Resource |
| | | private SolrInternetSearchVideoDataManager solrInternetSearchVideoDataManager; |
| | | |
| | | private void doInternetSearchVideoUpdateJob() { |
| | | for (int i = 0; i < 1; i++) { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<InternetSearchVideoMQMsg> solrMsgList = CMQManager.getInstance().consumeInternetSearchVideoUpdateMsg(16); |
| | | if (solrMsgList != null) |
| | | for (InternetSearchVideoMQMsg solrVideo : solrMsgList) { |
| | | try { |
| | | InternetSearchVideo video = internetSearchVideoService.selectByPrimaryKey(solrVideo.getId()); |
| | | if (video != null) |
| | | solrInternetSearchVideoDataManager.saveOrUpdate(video); |
| | | else |
| | | solrInternetSearchVideoDataManager.deleteById(video.getId()); |
| | | CMQManager.getInstance().deleteInternetSearchVideoUpdateMsg(solrVideo.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("更新全网搜搜索引擎出错", e); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private VideoIqiyi2Dao videoIqiyi2Dao; |
| | | |
| | | private void doUpdateResourceVideoJob() { |
| | | for (int i = 0; i < 1; i++) { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | System.out.println("消费结束:doUpdateResourceVideoJob"); |
| | | List<UpdateResourceVideoMQMsg> msgList = CMQManager.getInstance().consumeUpdateResourceVideoMsg(16); |
| | | System.out.println("消费结束:doUpdateResourceVideoJob"); |
| | | if (msgList != null) |
| | | for (UpdateResourceVideoMQMsg videoMQMsg : msgList) { |
| | | try { |
| | | if (videoMQMsg != null) { |
| | | String key = "resourcevideo-update-" + StringUtil.Md5(videoMQMsg.getResourceId() + "#" + videoMQMsg.getId()); |
| | | //可以更新 |
| | | if (StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) { |
| | | //12小时内不再更新 |
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 12); |
| | | switch (videoMQMsg.getResourceId()) { |
| | | case IqiyiUtil2 |
| | | .RESOURCE_ID: |
| | | //redis查询是否更新过 |
| | | IqiyiAlbum2 iqiyiAlbum2 = IqiYiNewAPI.getAlbumOrVideoDetail(Long.parseLong(videoMQMsg.getId())); |
| | | if (iqiyiAlbum2 == null) { |
| | | VideoIqiyi2 videoIqiyi2 = videoIqiyi2Dao.selectByIqiyiId(Long.parseLong(videoMQMsg.getId())); |
| | | if (videoIqiyi2 != null) { |
| | | //下架 |
| | | resourceVideoService.delete(videoIqiyi2.getVideoId() + "", videoMQMsg.getResourceId() + ""); |
| | | } |
| | | //删除爱奇艺资源 |
| | | iqiyi2Service.offlineIqiyiAlbum(Long.parseLong(videoMQMsg.getId())); |
| | | } else { |
| | | //保存 |
| | | iqiyiUtil2.syncByAid(iqiyiAlbum2.getId(), false); |
| | | } |
| | | break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | } finally { |
| | | CMQManager.getInstance().deleteUpdateResourceVideoMsg(videoMQMsg.getHandler()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void doAddIqiyi2Video() { |
| | | 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); |
| | | } |
| | | CMQManager.getInstance().deleteIqiyiAlbumUpdateMsg(iqiyiAlbum2MQMsg.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("爱奇艺专辑添加到视频出错:" + e.getMessage()); |
| | | logger.error("ID:" + iqiyiAlbum2MQMsg.getId()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | private void doAddFunTV2Video() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<FunTVAlbum2MQMsg> funTVAlbum2MsgList = CMQManager.getInstance().consumeFunTVAlbumUpdateMsg(16); |
| | | if (funTVAlbum2MsgList != null) |
| | | for (FunTVAlbum2MQMsg funTVAlbum2MQMsg : funTVAlbum2MsgList) { |
| | | try { |
| | | String mediaId = funTVAlbum2MQMsg.getId(); |
| | | FunTVAlbum2 album2 = funTV2Service.getAlbumDetail(mediaId); |
| | | if (album2 != null) { |
| | | funTV2Service.processAlbum(album2); |
| | | } |
| | | CMQManager.getInstance().deleteFunTVAlbumUpdateMsg(funTVAlbum2MQMsg.getHandler()); |
| | | } catch (Exception e) { |
| | | logger.error("风行专辑添加到视频出错:" + e.getMessage()); |
| | | logger.error("ID:" + funTVAlbum2MQMsg.getId()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |