TASK:aida design统计;

This commit is contained in:
shahaibo
2024-09-29 18:32:06 +08:00
parent 45e3dde03f
commit 373608d989
3 changed files with 42 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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;
}