继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ExamInitializeTask

weixin_慕前端4079947
关注TA
已关注
手记 6
粉丝 1
获赞 6
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();
    }
}


打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP