| | |
| | | package com.yeshi.buwan.util; |
| | | |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.dto.mq.IqiyiAlbum2MQMsg; |
| | | import com.yeshi.buwan.dto.mq.SolrVideoMQMsg; |
| | | import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum2; |
| | | import com.yeshi.buwan.service.imp.JobThreadExecutorServiceImpl; |
| | | import com.yeshi.buwan.service.imp.VideoInfoService; |
| | | 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; |
| | | |
| | | |
| | | private static boolean isInited = false; |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(SpringContext.class); |
| | | |
| | | public void onApplicationEvent(ContextRefreshedEvent arg0) { |
| | | if (arg0.getApplicationContext().getParent() != null) { |
| | |
| | | onApplication(arg0); |
| | | } |
| | | } |
| | | |
| | | @Bean |
| | | public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) { |
| | | return new DataSourceProxy(druidDataSource); |
| | | } |
| | | |
| | | |
| | | private synchronized void onApplication(ContextRefreshedEvent context) { |
| | | if (!isInited) { |
| | |
| | | } |
| | | |
| | | private void init() { |
| | | doSolrJob(); |
| | | doAddIqiyi2Video(); |
| | | logger.error("初始化"); |
| | | } |
| | | |
| | | 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) |
| | | solrDataManager.saveOrUpdate(videoInfo); |
| | | 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().consumeAlbumUpdateMsg(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().deleteAlbumUpdateMsg(iqiyiAlbum2MQMsg.getHandler()); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |