ApiServiceImpl.java 1.09 KB
package com.huaheng.control.management.service.impl;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.huaheng.control.management.dto.Task;
import com.huaheng.control.management.service.ApiService;
import com.huaheng.control.management.utils.HuahengRedisUtils;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

@Service
public class ApiServiceImpl implements ApiService {

    @Resource
    private HuahengRedisUtils huahengRedisUtils;

    @Override
    public void saveTaskInfo(Task task) {
        long timestamp = System.currentTimeMillis();
        task.setTimestamp(timestamp);
        task.setTimestampFormat(DateUtil.format(new Date(timestamp), DatePattern.NORM_DATETIME_MS_PATTERN));
        huahengRedisUtils.saveTaskStatus(task.getTaskId(), task.getTaskStatus(), task);
    }

    @Override
    public Map<String, Map<Object, Object>> queryTaskInfos() {
        return huahengRedisUtils.getTaskDetailsWithTaskKeys(huahengRedisUtils.getAllTaskKeys());
    }
}