TASK:aida design统计;
This commit is contained in:
@@ -268,4 +268,14 @@ public class RedisUtil {
|
||||
// 每天允许通知3次
|
||||
public final static String UPLOAD_TIMEOUT_REMINDER_COUNTER = "UploadTimeoutReminderCounter";
|
||||
|
||||
public void addProcessId(String processId, int progress) {
|
||||
// Redis 中的键,可以通过 processId 来唯一标识
|
||||
String redisKey = "process:progress:" + processId;
|
||||
|
||||
// 将当前进度存储到 Redis
|
||||
redisTemplate.opsForValue().set(redisKey, String.valueOf(progress));
|
||||
|
||||
// 设置过期时间为 5 分钟(300 秒)
|
||||
redisTemplate.expire(redisKey, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,9 @@ public class PythonService {
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 生成打印的图片 二合一 (废弃于2024/01/02)
|
||||
*
|
||||
@@ -260,6 +263,7 @@ public class PythonService {
|
||||
|
||||
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory);
|
||||
objects.add(pythonObject);
|
||||
redisUtil.addProcessId(processId, i);
|
||||
}
|
||||
return designPythonObjects;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
@Value("${access.python.port:''}")
|
||||
private String accessPythonPort;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
@@ -1117,6 +1120,24 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
|
||||
@Override
|
||||
public Integer designProcess(String processId) {
|
||||
// 假设 Redis 中存储的最大进度为 8,分配前 50%
|
||||
int redisMaxProgress = 8;
|
||||
int totalProgress = 100;
|
||||
int redisWeight = 50; // Redis 进度占 50%
|
||||
int pythonWeight = 50; // Python 接口进度占 50%
|
||||
|
||||
// 先从 Redis 中查询当前进度
|
||||
String redisKey = "process:progress:" + processId;
|
||||
String redisProgressString = redisUtil.getFromString(redisKey);
|
||||
int redisProgress = redisProgressString != null ? Integer.parseInt(redisProgressString) : 0;
|
||||
|
||||
// 如果 Redis 进度未达到最大值,则返回前 50% 的部分
|
||||
if (redisProgress < redisMaxProgress) {
|
||||
int progressPercentage = (redisProgress * redisWeight) / redisMaxProgress;
|
||||
return progressPercentage;
|
||||
}
|
||||
|
||||
// Redis 进度已经达到 8,查询 Python 接口获取后 50% 的进度
|
||||
ProcessIdObject object = new ProcessIdObject();
|
||||
object.setProcess_id(processId);
|
||||
|
||||
@@ -1144,13 +1165,18 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
String responseBody = Objects.requireNonNull(response.body()).string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
String num = responseObject.getString("data");
|
||||
return Integer.valueOf(num);
|
||||
int pythonProgress = Integer.parseInt(num);
|
||||
|
||||
// Redis 进度占前 50%,Python 进度占后 50%
|
||||
int combinedProgress = redisWeight + (pythonProgress * pythonWeight) / totalProgress;
|
||||
return combinedProgress;
|
||||
}
|
||||
} catch (IOException | JSONException e) {
|
||||
log.error("PythonService##design进度条异常###{}", ExceptionUtil.getThrowableList(e));
|
||||
}
|
||||
|
||||
return 0;
|
||||
// 如果 Python 请求失败,仍然返回前 50% 的 Redis 进度
|
||||
return redisWeight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user