package com.yingji.quartz; import cn.hutool.core.util.StrUtil; import com.yingji.entity.QuartzLog; import com.yingji.service.AccidentService; import com.yingji.service.QuartzLogService; 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 javax.annotation.Resource; import java.time.LocalDateTime; /** * 120定时任务保存数据 * * @author wu * @since 2024/5/10 上午10:05 */ @Configuration public class AccidentQuartz { public static final Logger log = LoggerFactory.getLogger(AccidentQuartz.class); @Resource private AccidentService accidentService; @Resource private QuartzLogService quartzLogService; @Async @Scheduled(cron = "*/10 * * * * ? ") public void savaData() { 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) { e.printStackTrace(); quartzLog.setStatus(2); } finally { quartzLogService.save(quartzLog); } } }