modify apple inventory monitor schedule

This commit is contained in:
JiyangTang 2024-06-17 16:12:29 +08:00
parent 4119c70c0e
commit 452a8b5cab

View File

@ -9,11 +9,13 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.baogutang.admin.domain.IphoneProductDto;
import top.baogutang.admin.utils.DingTalkMsgPushUtils;
@ -34,7 +36,7 @@ import java.util.stream.Collectors;
@Slf4j
@Component
@RefreshScope
public class AppleInventorySchedule {
public class AppleInventoryScheduleHandler extends IJobHandler {
@Value("${baogutang.apple.country_code:cn}")
private String countryCode;
@ -57,25 +59,6 @@ public class AppleInventorySchedule {
@Resource
private DingTalkMsgPushUtils dingTalkMsgPushUtils;
@Scheduled(cron = "0 0/30 * * * ? ")
public void appleInventoryMonitor() {
if (!Boolean.TRUE.equals(appleInventoryMonitorSwitch)) {
log.info(">>>>>>>>>>apple inventory monitor switch closed!<<<<<<<<<<");
return;
}
// 获取设备信息
List<IphoneProductDto> products = iphoneProductParserUtils.getProducts(deviceCode, countryCode);
//监视机型型号
products.forEach(product -> {
this.doMonitor(product);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(">>>>>>>>>>apple inventory monitor error:{}<<<<<<<<<<", e.getMessage(), e);
}
});
}
private void doMonitor(IphoneProductDto product) {
@ -190,4 +173,24 @@ public class AppleInventorySchedule {
return CharSequenceUtil.format(messageTemplate, twoLineAddress.replace("\n", " "), daytimePhone, location, distanceWithUnit);
}
@Override
@XxlJob("appleInventoryScheduleHandler")
public ReturnT<String> execute(String params) throws Exception {
if (!Boolean.TRUE.equals(appleInventoryMonitorSwitch)) {
log.info(">>>>>>>>>>apple inventory monitor switch closed!<<<<<<<<<<");
return ReturnT.SUCCESS;
}
// 获取设备信息
List<IphoneProductDto> products = iphoneProductParserUtils.getProducts(deviceCode, countryCode);
//监视机型型号
products.forEach(product -> {
this.doMonitor(product);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(">>>>>>>>>>apple inventory monitor error:{}<<<<<<<<<<", e.getMessage(), e);
}
});
return ReturnT.SUCCESS;
}
}