录单
This commit is contained in:
@@ -450,41 +450,42 @@ public class JDScheduleJob {
|
||||
return client.execute(request);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 8-20 * * ?") // 每天从 8:00 到 20:00,每小时执行一次
|
||||
public void fetchPL() {
|
||||
// 设置每天最多执行 3 次
|
||||
String cacheKey = "fetchPL:executedHours";
|
||||
Set<String> executedHours = getExecutedHoursFromRedis(); // 从 Redis 获取已执行的小时数
|
||||
@Scheduled(cron = "0 0 8-20 * * ?") // 每天从 8:00 到 20:00,每小时执行一次
|
||||
public void fetchPL() {
|
||||
logger.info("开始执行fetchPL任务");
|
||||
// 设置每天最多执行 3 次
|
||||
Set<String> executedHours = getExecutedHoursFromRedis(); // 从 Redis 获取已执行的小时数
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String currentHour = String.valueOf(now.getHour());
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String currentHour = String.valueOf(now.getHour());
|
||||
|
||||
// 如果今天已经执行了3次,则跳过
|
||||
if (executedHours.size() >= 3) {
|
||||
return;
|
||||
// 如果今天已经执行了3次,则跳过
|
||||
if (executedHours.size() >= 3) {
|
||||
logger.info("今天已经执行了3次,跳过本次任务");
|
||||
return;
|
||||
}
|
||||
|
||||
// 随机决定是否执行本次任务(例如 50% 概率)
|
||||
if (new Random().nextBoolean()) {
|
||||
logger.info("执行fetchPL任务");
|
||||
// 执行任务逻辑
|
||||
executeFetchPL();
|
||||
// 记录该小时已执行
|
||||
executedHours.add(currentHour);
|
||||
saveExecutedHoursToRedis(executedHours); // 存入 Redis
|
||||
}
|
||||
}
|
||||
|
||||
// 随机决定是否执行本次任务(例如 50% 概率)
|
||||
if (new Random().nextBoolean()) {
|
||||
// 执行任务逻辑
|
||||
executeFetchPL();
|
||||
// 记录该小时已执行
|
||||
executedHours.add(currentHour);
|
||||
saveExecutedHoursToRedis(executedHours); // 存入 Redis
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void executeFetchPL() {
|
||||
HashMap<String, String> productTypeMap = jdUtil.getProductTypeMap();
|
||||
int allCommentCount = 0;
|
||||
int usedCommentCount = 0;
|
||||
int canUseComentCount = 0;
|
||||
int addCommentCount = 0;
|
||||
int usedCommentCount;
|
||||
int canUseComentCount;
|
||||
int addCommentCount;
|
||||
for (Map.Entry<String, String> entry : productTypeMap.entrySet()) {
|
||||
|
||||
// 随机睡眠1-5分钟
|
||||
int sleepTime = new Random().nextInt(300) + 60;
|
||||
int sleepTime = new Random().nextInt(3000) + 60;
|
||||
try {
|
||||
Thread.sleep(sleepTime * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -497,8 +498,8 @@ public void fetchPL() {
|
||||
|
||||
canUseComentCount = availableComments.size();
|
||||
usedCommentCount = usedComments.size();
|
||||
if (canUseComentCount > 5){
|
||||
logger.info("商品{} 评论可用数量大于5:{}", product_id, canUseComentCount);
|
||||
if (canUseComentCount > 5) {
|
||||
logger.info("商品{} 评论可用数量大于5:{}", product_id, canUseComentCount);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user