package com.ruoyi.system.task.jobs; import com.google.common.collect.ImmutableMap; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.system.model.TDeliberationVote; import com.ruoyi.system.task.base.AbstractJob; import com.ruoyi.system.task.base.QuartzManager; import com.ruoyi.system.task.base.TimeJobType; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import java.time.LocalDateTime; import java.util.Map; import java.util.Objects; /** * 直播推送定时任务 * @author Administrator * */ public class DeliberationVotePush extends AbstractJob { public static final String name = "deliberationVotePush_"; @Override public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap maps = context.getMergedJobDataMap(); String voteId = maps.getString("id"); String type = maps.getString("type"); try { TDeliberationVote deliberationVote = deliberationVoteService.getById(voteId); if(Objects.isNull(deliberationVote)){ return; } LocalDateTime startTime = deliberationVote.getStartTime(); LocalDateTime endTime = deliberationVote.getEndTime(); LocalDateTime now = LocalDateTime.now(); if("1".equals(type) && now.compareTo(startTime) > -1 && now.compareTo(endTime) < 1){ deliberationVote.setStatus(2); // 添加定时任务 Map map = new ImmutableMap.Builder(). put("id", deliberationVote.getId()).put("type","2") .build(); QuartzManager.addJob( DeliberationVotePush.class, (DeliberationVotePush.name+deliberationVote.getId()).toUpperCase(), TimeJobType.DELIBERATION_VOTE_PUSH, DateUtils.localDateTimeToDate(deliberationVote.getEndTime()), map ); } if("2".equals(type) && now.isAfter(endTime)){ deliberationVote.setStatus(3); } deliberationVoteService.updateById(deliberationVote); }catch(Exception e){ e.printStackTrace(); } } }