YingjiAlgorithms/rescue/src/main/java/com/yingji/quartz/AccidentQuartz.java

58 lines
1.8 KiB

12 months ago
package com.yingji.quartz;
11 months ago
import cn.hutool.core.util.StrUtil;
11 months ago
import com.yingji.entity.QuartzLog;
12 months ago
import com.yingji.service.AccidentService;
11 months ago
import com.yingji.service.QuartzLogService;
12 months ago
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
12 months ago
import javax.annotation.Resource;
11 months ago
import java.time.LocalDateTime;
12 months ago
/**
* 120
*
* @author wu
* @since 2024/5/10 10:05
*/
@Configuration
@Transactional(rollbackFor = Exception.class)
12 months ago
public class AccidentQuartz {
public static final Logger log = LoggerFactory.getLogger(AccidentQuartz.class);
@Resource
private AccidentService accidentService;
11 months ago
@Resource
private QuartzLogService quartzLogService;
@Async
@Scheduled(cron = "*/10 * * * * ? ")
12 months ago
public void savaData() {
11 months ago
QuartzLog quartzLog = new QuartzLog();
quartzLog.setInterfaceName(3);
quartzLog.setCreateTime(LocalDateTime.now());
try {
String accessToken = accidentService.getAuthorizeToken();
if (StrUtil.isNotEmpty(accessToken)) {
accidentService.getAccidentUrl(accessToken);
quartzLog.setStatus(1);
log.info("=================120定时任务结束===============");
} else {
quartzLog.setStatus(2);
log.info("=================120定时任务获取token失败===============");
}
} catch (Exception e) {
11 months ago
quartzLog.setStatus(2);
} finally {
11 months ago
quartzLogService.save(quartzLog);
11 months ago
}
12 months ago
}
}