TASK:aida design统计;
This commit is contained in:
@@ -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