| | |
| | | |
| | | import com.xxl.job.core.biz.model.ReturnT; |
| | | import com.xxl.job.core.handler.annotation.XxlJob; |
| | | import com.yeshi.buwan.videos.funtv.FunTVNewApi; |
| | | import com.yeshi.buwan.videos.funtv.entity.FunTVAlbum2; |
| | | import com.yeshi.buwan.videos.funtv.entity.FunTVShortVideo2; |
| | | import com.yeshi.buwan.videos.funtv.entity.FunTVVideo2; |
| | | import com.yeshi.buwan.service.inter.juhe.FunTV2Service; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.mq.CMQManager; |
| | | import com.yeshi.buwan.vo.video.funtv.Funtv2ResultVO; |
| | | import com.yeshi.buwan.videos.funtv.entity.FunTVShortVideo2; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | @XxlJob("video-update-funtv2-updateLatestVideo") |
| | | public ReturnT<String> updateLatestVideo(String param) throws Exception { |
| | | int d = 1; |
| | | if (!StringUtil.isNullOrEmpty(param)) |
| | | d = Integer.parseInt(param); |
| | | //获取最近1天的专辑 |
| | | List<FunTVAlbum2> list = getLatestAlbum(d); |
| | | for (FunTVAlbum2 album2 : list) { |
| | | funTV2Service.saveAlbum(album2); |
| | | if (album2.getEpisodes() != null) |
| | | for (FunTVVideo2 video2 : album2.getEpisodes()) |
| | | funTV2Service.saveVideo(video2); |
| | | CMQManager.getInstance().addFunTVAlbumUpdateMsg(album2.getId()); |
| | | } |
| | | |
| | | //获取最近一天的短视频 |
| | | List<FunTVShortVideo2> shortVideo2List = getLatestShortVideo(d); |
| | | if (shortVideo2List != null) |
| | | for (FunTVShortVideo2 video2 : shortVideo2List) |
| | | funTV2Service.saveShortVideo(video2); |
| | | return ReturnT.SUCCESS; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据专辑ID更新 |
| | | * @param param |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | // @XxlJob("video-update-funtv2-updateAlbumById") |
| | | // public ReturnT<String> updateAlbumById(String param) throws Exception { |
| | | // FunTVAlbum2 album2 = FunTVNewApi.getAlbumsDetail(param); |
| | | // if (album2 != null) { |
| | | // funTV2Service.saveAlbum(album2); |
| | | // if (album2.getEpisodes() != null) |
| | | // for (FunTVVideo2 video2 : album2.getEpisodes()) |
| | | // funTV2Service.saveVideo(video2); |
| | | // CMQManager.getInstance().addFunTVAlbumUpdateMsg(album2.getId()); |
| | | // } |
| | | // return ReturnT.SUCCESS; |
| | | // } |
| | | |
| | | /** |
| | | * 获取最近的短视频 |
| | |
| | | // page++; |
| | | // } |
| | | return shortVideo2List; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取最近的专辑 |
| | | * |
| | | * @return |
| | | */ |
| | | private List<FunTVAlbum2> getLatestAlbum(int d) { |
| | | List<FunTVAlbum2> funTVAlbum2List = new ArrayList<>(); |
| | | int pageSize = 100; |
| | | long now = System.currentTimeMillis(); |
| | | int page = 1; |
| | | int totalPage = -1; |
| | | while (true) { |
| | | Funtv2ResultVO result = FunTVNewApi.getAlbums(page, pageSize, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), null); |
| | | if (result != null) { |
| | | for (Serializable a : result.getList()) { |
| | | FunTVAlbum2 video2 = (FunTVAlbum2) a; |
| | | funTVAlbum2List.add(video2); |
| | | } |
| | | } |
| | | int count = result.getCount(); |
| | | if (totalPage < 0) |
| | | totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; |
| | | if (page > totalPage) |
| | | break; |
| | | page++; |
| | | } |
| | | return funTVAlbum2List; |
| | | } |
| | | |
| | | } |