From 8075103992e9482fddd4a579d97b9a50c5dcf550 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 24 十月 2020 18:26:43 +0800 Subject: [PATCH] 爱奇艺资源更新优化 --- src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java | 62 +++++++++++++++++-------------- 1 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java b/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java index cb54aa3..53ff013 100644 --- a/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java +++ b/src/main/java/com/yeshi/buwan/iqiyi/util/IqiyiUtil2.java @@ -19,9 +19,7 @@ import javax.annotation.Resource; import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; @Component public class IqiyiUtil2 { @@ -40,9 +38,10 @@ for (IqiyiAlbum2 album : list) { if (album.getContentType() != 1) continue; - if (!albumIsValid(album)) + if (!albumIsValid(album)) {//濡傛灉鏄棤鏁堢殑涓撹緫灏遍渶瑕佸垹闄� + iqiyi2Service.deleteByAid(album.getId()); continue; - + } if (album.getTvQipuIds() != null && album.getTvQipuIds().size() > 0) { //鏌ヨ鏈�鏂扮殑涓�闆嗘槸鍚︾紦瀛� boolean needSaveVideos = true; @@ -50,6 +49,7 @@ if (iqiyi2Service.countById(album.getLatestVideo().getId()) > 0L) needSaveVideos = false; } + if (needSaveVideos) { int pageSize = 10; @@ -59,13 +59,22 @@ int toIndex = (startIndex + pageSize) > album.getTvQipuIds().size() ? album.getTvQipuIds().size() : (startIndex + pageSize); List<Long> tvQipuIds = new ArrayList<>(); tvQipuIds.addAll(album.getTvQipuIds().subList(startIndex, toIndex)); - for (int i = 0; i < tvQipuIds.size(); i++) { - long count = iqiyi2Service.countById(tvQipuIds.get(i)); - if (count > 0) { - tvQipuIds.remove(i); - i--; + + //鏌ヨ鏄惁宸茬粡瀛樺湪浜� + List<IqiyiAlbum2> existList = iqiyi2Service.listByIds(tvQipuIds); + Set<Long> sets = new HashSet<>(); + if (existList != null && existList.size() > 0) { + for (IqiyiAlbum2 a : existList) + sets.add(a.getId()); + + //鍒犻櫎宸茬粡瀛樺湪鐨� + for (int i = 0; i < tvQipuIds.size(); i++) { + if (sets.contains(tvQipuIds.get(i))) { + tvQipuIds.remove(i--); + } } } + if (tvQipuIds.size() > 0) { List<IqiyiAlbum2> detailList = IqiYiNewAPI.getAlbumOrVideoDetail(tvQipuIds); if (detailList != null) @@ -132,12 +141,12 @@ } //鏇存柊涓撹緫 - public void updateAlbum(int categoryId, Date startTime, Date endTime) { - IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, true, 10); + public void updateAlbum(int categoryId, boolean isAlbum, Date startTime, Date endTime) { + IqiyiAlbumListResult result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, null, isAlbum, 10); if (result.getAlbum2List() != null) saveAlbumAndVideo(result.getAlbum2List()); while (result.getMinId() != null) { - result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, result.getMinId(), true, 10); + result = IqiYiNewAPI.getUpdateAlbumList(categoryId + "", startTime, endTime, result.getMinId(), isAlbum, 10); if (result.getAlbum2List() != null) saveAlbumAndVideo(result.getAlbum2List()); } @@ -157,25 +166,22 @@ //鏇存柊鏈�杩戜竴澶╃殑鐨勪笓杈戜笌瑙嗛 - public void updateTodayAlbumAndVideo() { + public void updateTodayAlbumAndVideo(int channelId) { long now = System.currentTimeMillis(); for (int i = 0; i < 8; i++) { - Date endTime = new Date(now - i * 1000 * 60 * 60L * 3); + Date endTime = new Date(now - 1000 * 60 * 60L * 3 * i); Date startTime = new Date(endTime.getTime() - 1000 * 60 * 60L * 3); - //鏇存柊鐢靛奖 - updateVideo(IqiYiNewAPI.TYPE_DIANYING, startTime, endTime); - //鏇存柊鐢佃鍓� - updateAlbum(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime); - updateVideo(IqiYiNewAPI.TYPE_DIANSHIJU, startTime, endTime); - - //鏇存柊鍔ㄦ极 - updateAlbum(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime); - updateVideo(IqiYiNewAPI.TYPE_DONGMAN, startTime, endTime); - - //鏇存柊缁艰壓 - updateAlbum(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime); - updateVideo(IqiYiNewAPI.TYPE_ZONGYI, startTime, endTime); + switch (channelId) { + case IqiYiNewAPI.TYPE_DIANYING: + updateAlbum(channelId, false, startTime, endTime); + break; + case IqiYiNewAPI.TYPE_DIANSHIJU: + case IqiYiNewAPI.TYPE_DONGMAN: + case IqiYiNewAPI.TYPE_ZONGYI: + updateAlbum(channelId, true, startTime, endTime); + break; + } } } -- Gitblit v1.8.0