package com.huihe.exam.task; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.huihe.exam.core.Result; import com.huihe.exam.mapper.ScheduleMapper; import com.huihe.exam.service.OnlineTestService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @Component("com.huihe.exam.task.ExamInitializeTask") @Scope("prototype") public class ExamInitializeTask extends AbstractTask { private final Logger log = LoggerFactory.getLogger(ExamInitializeTask.class); @Autowired OnlineTestService service; @Autowired ScheduleMapper mapper; public ExamInitializeTask(){ super(); } @Override public void run(){ try { JSONObject param = JSON.parseObject(getTask().getParam()); Result result = service.cacheQuestion(param.getString("id"), param.getString("examType")); if(result.getCode() == 200){ success(); } else { error(); } } catch (Exception e) { log.error(e.getMessage()); error(); } } @Override public void doing(){ log.info("【{}:{}】任务开始执行...", this.getTask().getTaskName(), this.getTask().getId()); if(this.getTask().getExecTm() == 1){ mapper.setTaskFlag(TASK_DOING, this.getTask().getId()); } else if(this.getTask().getExecTm() > 1) { mapper.setTaskFlag(TASK_WAITING, this.getTask().getId()); } } @Override public void success(){ SchedulerTask task = this.getTask(); String taskId = task.getId(); log.info("【{}:{}】任务执行成功...", this.getTask().getTaskName(), this.getTask().getId()); mapper.setTaskFlag(TASK_SUCCESS, taskId); stop(); } @Override public void error(){ log.info("【{}:{}】任务执行出错...", this.getTask().getTaskName(), this.getTask().getId()); mapper.setTaskFlag(TASK_ERROR, this.getTask().getId()); stop(); } }
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦