Commit 79d76579547d7e56feca2e1f5cc40f9ba91a731b

Authored by 王明元
1 parent f1d02cbe

2022年5月26日16:58:28 修复jpa修改数据问题, 更改定时任务为fixRate方式

src/main/java/cn/fw/freya/task/DataCaptureTask.java
@@ -9,6 +9,7 @@ import cn.fw.freya.service.crawl.impl.Common; @@ -9,6 +9,7 @@ import cn.fw.freya.service.crawl.impl.Common;
9 import cn.fw.freya.service.crawl.impl.KuaiShouCrawl; 9 import cn.fw.freya.service.crawl.impl.KuaiShouCrawl;
10 import cn.fw.freya.service.data.AccountService; 10 import cn.fw.freya.service.data.AccountService;
11 import cn.fw.freya.utils.DateUtil; 11 import cn.fw.freya.utils.DateUtil;
  12 +import cn.fw.freya.utils.PublicUtil;
12 import cn.fw.freya.utils.ThreadPoolUtil; 13 import cn.fw.freya.utils.ThreadPoolUtil;
13 import com.alibaba.fastjson.JSONArray; 14 import com.alibaba.fastjson.JSONArray;
14 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
@@ -96,7 +97,7 @@ public class DataCaptureTask { @@ -96,7 +97,7 @@ public class DataCaptureTask {
96 /** 97 /**
97 * 每2分钟执行抓取数据 98 * 每2分钟执行抓取数据
98 */ 99 */
99 - @Scheduled(cron = "0 0/2 * * * ?") 100 + @Scheduled(fixedRate = 2 * 60 * 1000, initialDelay = 5000)
100 public void captureLivePlayback() { 101 public void captureLivePlayback() {
101 final Random random = new Random(); 102 final Random random = new Random();
102 List<LivePool> withoutPlaybackLive = common.getWithoutPlaybackLive(1, 60d) 103 List<LivePool> withoutPlaybackLive = common.getWithoutPlaybackLive(1, 60d)
@@ -120,21 +121,15 @@ public class DataCaptureTask { @@ -120,21 +121,15 @@ public class DataCaptureTask {
120 for (LivePool item : list) { 121 for (LivePool item : list) {
121 JSONObject obj = kuaiShouCrawl.setPlaybackUrl(item, playbackMsg); 122 JSONObject obj = kuaiShouCrawl.setPlaybackUrl(item, playbackMsg);
122 String playbackUrl = obj.getString("playbackUrl"); 123 String playbackUrl = obj.getString("playbackUrl");
  124 + final LivePool livePool = PublicUtil.copy(item, LivePool.class);// 对象拷贝
123 if (Objects.isNull(playbackUrl)) { 125 if (Objects.isNull(playbackUrl)) {
124 - livePoolDao.save(LivePool.builder()  
125 - .id(item.getId())  
126 - .getPlaybackFailTimes(item.getGetPlaybackFailTimes() + 1)  
127 - .build()  
128 - ); 126 + livePool.setGetPlaybackFailTimes(livePool.getGetPlaybackFailTimes() + 1);
129 } else { 127 } else {
130 flag = true; 128 flag = true;
131 - livePoolDao.save(LivePool.builder()  
132 - .id(item.getId())  
133 - .roomCoverImage(obj.getString("coverUrl"))  
134 - .playbackUrl(playbackUrl)  
135 - .build()  
136 - ); 129 + livePool.setRoomCoverImage(obj.getString("coverUrl"));
  130 + livePool.setPlaybackUrl(playbackUrl);
137 } 131 }
  132 + livePoolDao.save(livePool);
138 } 133 }
139 if (flag) { 134 if (flag) {
140 final ArrayList<LivePool> livePools = new ArrayList<>(); 135 final ArrayList<LivePool> livePools = new ArrayList<>();