| | |
| | | package com.yeshi.buwan.util; |
| | | |
| | | import com.yeshi.buwan.domain.ResourceVideo; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.dto.mq.*; |
| | | import com.yeshi.buwan.funtv.entity.FunTVAlbum2; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2; |
| | | 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.util.mq.CMQManager; |
| | | import com.alibaba.druid.pool.DruidDataSource; |
| | | import io.seata.rm.datasource.DataSourceProxy; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.event.ContextRefreshedEvent; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 系统初始化 |
| | |
| | | @Component |
| | | public class SpringContext implements ApplicationListener<ContextRefreshedEvent> { |
| | | |
| | | @Resource |
| | | private VideoInfoService videoInfoService; |
| | | |
| | | @Resource |
| | | private SolrAlbumDataManager solrDataManager; |
| | | |
| | | @Resource |
| | | private Iqiyi2Service iqiyi2Service; |
| | | |
| | | @Resource |
| | | private FunTV2Service funTV2Service; |
| | | |
| | | @Resource |
| | | private ResourceVideoService resourceVideoService; |
| | | |
| | | private static boolean isInited = false; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Bean |
| | | public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) { |
| | | return new DataSourceProxy(druidDataSource); |
| | | } |
| | | |
| | | |
| | | private synchronized void onApplication(ContextRefreshedEvent context) { |
| | | if (!isInited) { |
| | | isInited = true; |
| | |
| | | } |
| | | |
| | | private void init() { |
| | | if (!Constant.JobTasker) { |
| | | doSolrJob(); |
| | | doAddIqiyi2Video(); |
| | | doAddFunTV2Video(); |
| | | 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()); |
| | | } |
| | | CMQManager.getInstance().deleteSolrMsg(solrVideo.getHandler()); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void doAddIqiyi2Video() { |
| | | new JobThreadExecutorServiceImpl().run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | List<IqiyiAlbum2MQMsg> iqiyiAlbumMsgList = CMQManager.getInstance().consumeIqiyiAlbumUpdateMsg(16); |
| | | if (iqiyiAlbumMsgList != null) |
| | | for (IqiyiAlbum2MQMsg iqiyiAlbum2MQMsg : iqiyiAlbumMsgList) { |
| | | try { |
| | | Long qikuID = iqiyiAlbum2MQMsg.getId(); |
| | | IqiyiAlbum2 album2 = iqiyi2Service.selectAlbumById(qikuID); |
| | | 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 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()); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | logger.error("初始化"); |
| | | } |
| | | |
| | | |