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 org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; /** * 120定时任务保存数据 * * @author wu * @since 2024/5/10 上午10:05 */ @Configuration @Transactional(rollbackFor = Exception.class) 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() { String accessToken = accidentService.getAuthorizeToken(); QuartzLog quartzLog = new QuartzLog(); quartzLog.setInterfaceName(3); quartzLog.setCreateTime(LocalDateTime.now()); if (StrUtil.isNotEmpty(accessToken)) { accidentService.getAccidentUrl(accessToken); quartzLog.setStatus(1); quartzLogService.save(quartzLog); log.info("=================120定时任务结束==============="); } else { quartzLog.setStatus(2); quartzLogService.save(quartzLog); log.info("=================120定时任务获取token失败==============="); } } }