修改定时拉取逻辑

master
bynt 3 years ago
parent 6af7ea1e04
commit 67d83fa97f

@ -151,7 +151,7 @@ public class SlaverTest {
@Test @Test
public void findUserList() { public void findUserList() {
taoBaoRdsPushService.turnOnPushService("50008301b31rk9pRecixBK0WlkFRHzfvTjjwFOTePoX17adf61appvZWSIB0F8x8sx",15L); taoBaoRdsPushService.turnOnPushService("500081016120qBdWPaxsHcjj146e0b2bUdPxTGleKn3kssGebCTtcLo4ZTDVE07pAg",20L);
} }
@Test @Test

@ -1,6 +1,7 @@
package com.hchbox.task; package com.hchbox.task;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
@ -27,6 +28,9 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -42,7 +46,6 @@ import java.util.concurrent.atomic.AtomicInteger;
/** /**
* *
*
* @author Enzo * @author Enzo
* @date : 2021/6/23 * @date : 2021/6/23
*/ */
@ -81,7 +84,7 @@ public class SyncTask {
*/ */
@Async("pullOrderTaskExecutor") @Async("pullOrderTaskExecutor")
@Scheduled(cron = "0 0/10 * * * *") @Scheduled(cron = "0 0/10 * * * *")
//@Scheduled(cron = "0 0/1 * * * *") // @Scheduled(cron = "0 0/1 * * * *")
public void pullOrdersRegularly() throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException { public void pullOrdersRegularly() throws ApiException, SecretException, NoSuchFieldException, IllegalAccessException {
if (flag != null && flag) { if (flag != null && flag) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -108,10 +111,15 @@ public class SyncTask {
Date startTime; Date startTime;
Date endTime = new Date(); Date endTime = new Date();
Multimap<String, Trade> multimap = ArrayListMultimap.create(); Multimap<String, Trade> multimap = ArrayListMultimap.create();
Pageable pageable = PageRequest.of(DefaultNumberConstants.ZERO_NUMBER, DefaultNumberConstants.FIVE_THOUSAND);
// 第一次任务往前10分钟 // 第一次任务往前10分钟
startTime = lastUpdateTime == null ? DateUtil.offsetMinute(date, -DefaultNumberConstants.TEN_NUMBER) : lastUpdateTime; startTime = lastUpdateTime == null ? DateUtil.offsetMinute(date, -DefaultNumberConstants.TEN_NUMBER) : lastUpdateTime;
lastUpdateTime = endTime; lastUpdateTime = endTime;
List<JdpTrade> jdpOrderList = jdpTradeService.findJdpOrderByTime(startTime, endTime); while (true) {
// 分页查询数据
Slice<JdpTrade> jdpTradeSlice = jdpTradeService.findJdpOrderByTime(startTime, endTime, pageable);
List<JdpTrade> jdpOrderList = jdpTradeSlice.getContent();
if (CollUtil.isNotEmpty(jdpOrderList)) {
log.info("================== the orderList size as {} =======================", jdpOrderList.size()); log.info("================== the orderList size as {} =======================", jdpOrderList.size());
if (!CollectionUtils.isEmpty(jdpOrderList)) { if (!CollectionUtils.isEmpty(jdpOrderList)) {
for (JdpTrade jdpTrade : jdpOrderList) { for (JdpTrade jdpTrade : jdpOrderList) {
@ -159,7 +167,12 @@ public class SyncTask {
} }
} }
} }
}
if (!jdpTradeSlice.hasNext()) {
break;
}
pageable = jdpTradeSlice.nextPageable();
}
count.decrementAndGet(); count.decrementAndGet();
} }
} }

Loading…
Cancel
Save