package com.qmth.teachcloud.cas.mq.gdpu.cache;

import com.qmth.teachcloud.exchange.common.bean.dto.flow.DoneTaskDto;
import com.qmth.teachcloud.exchange.common.bean.dto.flow.ToDoTaskDto;
import com.qmth.teachcloud.exchange.common.cache.RedisKeyHelper;
import com.qmth.teachcloud.exchange.common.contant.SpringContextHolder;
import com.qmth.teachcloud.exchange.common.enums.flow.FlowMqFieldEnum;
import com.qmth.teachcloud.cas.util.RedisUtil;

/**
 * 考试记录缓存hash值操作
 *
 * @Description:
 * @Author: xiatian
 * @Date: 2020-07-29
 */
public class FlowMqCacheUtil {

    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);

    public static void setSchoolId(Long flowId, String schoolId) {
        redisUtil.set(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.schoolId.name(), schoolId);
        setUpdateTime(flowId, System.currentTimeMillis());
    }

    public static String getSchoolId(Long flowId) {
        return (String) redisUtil.get(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.schoolId.name());
    }

    public static void setToDoTask(Long flowId, ToDoTaskDto toDoTaskDto) {
        redisUtil.set(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.todotask.name(), toDoTaskDto);
    }

    public static ToDoTaskDto getToDoTask(Long flowId) {
        return (ToDoTaskDto) redisUtil.get(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.todotask.name());
    }

    public static void setDoneTask(Long flowId, DoneTaskDto doneTaskDto) {
        redisUtil.set(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.donetask.name(), doneTaskDto);
    }

    public static DoneTaskDto getDoneTask(Long flowId) {
        return (DoneTaskDto) redisUtil.get(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.donetask.name());
    }

    public static void setUpdateTime(Long flowId, Long time) {
        redisUtil.set(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.updateTime.name(), time);
    }

    public static Long getUpdateTime(Long flowId) {
        return (Long) redisUtil.get(RedisKeyHelper.flowIdCacheKey(flowId), FlowMqFieldEnum.updateTime.name());
    }
}