TASK:模块化;
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.ai.da.common.utils;
|
||||
|
||||
import com.ai.da.model.dto.ProgressDTO;
|
||||
import com.ai.da.python.vo.DesignPythonObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
@@ -14,6 +17,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -500,4 +504,23 @@ public class RedisUtil {
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTaskProgressDTO(String taskId, ProgressDTO dto) {
|
||||
String key = "task:progress:" + taskId;
|
||||
redisTemplate.opsForValue().set(key, JSON.toJSONString(dto), Duration.ofDays(1));
|
||||
}
|
||||
|
||||
public ProgressDTO getTaskProgressDTO(String taskId) {
|
||||
String key = "task:progress:" + taskId;
|
||||
String json = redisTemplate.opsForValue().get(key);
|
||||
if (StringUtils.isBlank(json)) {
|
||||
return new ProgressDTO(0, 0, false);
|
||||
}
|
||||
try {
|
||||
return JSON.parseObject(json, ProgressDTO.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("任务进度解析失败 key={}, json={}", key, json);
|
||||
return new ProgressDTO(0, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user