修改:hpc任务耗时,后端增加逻辑动态计算时间
This commit is contained in:
@@ -173,4 +173,7 @@ public class SimulationJob implements Serializable {
|
||||
@TableField("dirId")
|
||||
private Long dirId;
|
||||
|
||||
@Schema(description = "任务耗时,前端展示字段")
|
||||
private String costTime;
|
||||
|
||||
}
|
||||
@@ -572,6 +572,8 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
|
||||
queryChain.like(SimulationJob::getRunId, req.getRunId().trim());
|
||||
}
|
||||
List<SimulationJob> results = queryChain.list();
|
||||
// 时间转换
|
||||
convertTotalElapsedTimeToCostTime(results);
|
||||
PageInfo<SimulationJob> page = new PageInfo<>(results);
|
||||
return PageUtils.getJsonObjectSdmResponse(results, page);
|
||||
}
|
||||
@@ -774,6 +776,46 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将SimulationJob列表中的totalElapsedTime(秒)转换为人性化的耗时格式,并赋值给costTime字段
|
||||
* @param jobs 仿真任务列表
|
||||
*/
|
||||
public static void convertTotalElapsedTimeToCostTime(List<SimulationJob> jobs) {
|
||||
try {
|
||||
// 空列表直接返回,避免空指针
|
||||
if (CollectionUtils.isEmpty(jobs)) {
|
||||
return;
|
||||
}
|
||||
for (SimulationJob job : jobs) {
|
||||
// 获取总耗时秒数,先做空值和负数判断
|
||||
Long totalSeconds = job.getTotalElapsedTime();
|
||||
if (totalSeconds == null || totalSeconds < 0) {
|
||||
job.setCostTime("");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 时间单位换算:1小时=3600秒,1分钟=60秒
|
||||
long hours = totalSeconds / 3600;
|
||||
long remainingSecondsAfterHour = totalSeconds % 3600;
|
||||
long minutes = remainingSecondsAfterHour / 60;
|
||||
long seconds = remainingSecondsAfterHour % 60;
|
||||
// 拼接耗时字符串
|
||||
StringBuilder costTime = new StringBuilder();
|
||||
if (hours > 0) {
|
||||
costTime.append(hours).append("小时");
|
||||
}
|
||||
if (minutes > 0 || (hours > 0 && seconds > 0)) { // 有小时且有秒时,分钟即使为0也展示?按需调整
|
||||
costTime.append(minutes).append("分钟");
|
||||
}
|
||||
if (seconds > 0 || (hours == 0 && minutes == 0)) { // 只有秒数时必须展示
|
||||
costTime.append(seconds).append("秒");
|
||||
}
|
||||
// 赋值给costTime字段
|
||||
job.setCostTime(costTime.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("convertTotalElapsedTimeToCostTime 耗时数据转换异常:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user