修改:hpc任务查询排序优化
This commit is contained in:
@@ -67,8 +67,11 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
|
||||
@Autowired
|
||||
private IFlowableFeignClient flowableFeignClient;
|
||||
|
||||
@Value("#{'${hpc.jobs.ascOrders:Queued,Running,Failed,Canceled,Finished }'.split(',')}")
|
||||
private List<String> ascOrders;
|
||||
@Value("#{'${hpc.jobs.highOrders:Configuring,Queued}'.split(',')}")
|
||||
private List<String> highOrders;
|
||||
|
||||
@Value("#{'${hpc.jobs.middleOrders:Running}'.split(',')}")
|
||||
private List<String> middleOrders;
|
||||
|
||||
// 正则匹配%后的单词(\w+ 匹配字母、数字、下划线)
|
||||
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("%(\\w+)");
|
||||
@@ -555,37 +558,57 @@ public class PbsServiceDecorator implements IPbsServiceDecorator {
|
||||
}
|
||||
|
||||
public SdmResponse<PageDataResp<List<SimulationJob>>> queryJobs(QueryJobReq req){
|
||||
PageHelper.startPage(req.getCurrent(), req.getSize());
|
||||
// 构建查询条件
|
||||
PageHelper.startPage(req.getCurrent(), req.getSize());
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryChainWrapper<SimulationJob> queryChain = simulationJobService.lambdaQuery();
|
||||
|
||||
// ... 你的原有查询条件逻辑保持不变 ...
|
||||
if (req.getJobName() != null && !req.getJobName().trim().isEmpty()) {
|
||||
// like,实现 包含关键词 的模糊查询(%关键词%)
|
||||
queryChain.like(SimulationJob::getJobName, req.getJobName().trim());
|
||||
}
|
||||
if (req.getJobStatus() != null && !req.getJobStatus().trim().isEmpty()) {
|
||||
// like,实现 包含关键词 的模糊查询(%关键词%)
|
||||
queryChain.like(SimulationJob::getJobStatus, req.getJobStatus().trim());
|
||||
}
|
||||
if (req.getSolverName() != null && !req.getSolverName().trim().isEmpty()) {
|
||||
// like,实现 包含关键词 的模糊查询(%关键词%)
|
||||
queryChain.like(SimulationJob::getSolverName, req.getSolverName().trim());
|
||||
}
|
||||
if (req.getRunId() != null && !req.getRunId().trim().isEmpty()) {
|
||||
// like,实现 包含关键词 的模糊查询(%关键词%)
|
||||
queryChain.like(SimulationJob::getRunId, req.getRunId().trim());
|
||||
}
|
||||
// 排序
|
||||
if (CollectionUtils.isNotEmpty(ascOrders)) {
|
||||
String statusValues = String.join("','", ascOrders);
|
||||
String orderBySql = String.format("ORDER BY FIELD(jobStatus, '%s') ASC, createTime DESC", statusValues);
|
||||
queryChain.getWrapper().last(orderBySql);
|
||||
// --- 核心修改部分:动态构建三级状态排序 ---
|
||||
StringBuilder orderBySql = new StringBuilder("ORDER BY ");
|
||||
List<String> caseClauses = new ArrayList<>();
|
||||
|
||||
// 1. 处理高优先级 (High)
|
||||
if (CollectionUtils.isNotEmpty(highOrders)) {
|
||||
String highStr = StringUtils.join(highOrders, "', '");
|
||||
caseClauses.add(String.format("CASE WHEN jobStatus IN ('%s') THEN 1", highStr));
|
||||
}
|
||||
List<SimulationJob> results = queryChain.list();
|
||||
// 时间转换
|
||||
|
||||
// 2. 处理中优先级 (Middle)
|
||||
if (CollectionUtils.isNotEmpty(middleOrders)) {
|
||||
String middleStr = StringUtils.join(middleOrders, "', '");
|
||||
caseClauses.add(String.format("WHEN jobStatus IN ('%s') THEN 2", middleStr));
|
||||
}
|
||||
// 3. 拼接完整的 CASE 语句和后续排序规则
|
||||
if (CollectionUtils.isNotEmpty(caseClauses)) {
|
||||
// 拼接 CASE WHEN ... THEN ... WHEN ... THEN ... ELSE 3 END
|
||||
orderBySql.append(String.join(" ", caseClauses))
|
||||
.append(" ELSE 3 END, ") // 低优先级默认值为3
|
||||
.append("createTime DESC"); // 组内按时间倒序
|
||||
// 将原生SQL拼接到MyBatis-Plus的查询条件最后
|
||||
queryChain.last(orderBySql.toString());
|
||||
} else {
|
||||
// 如果没有传入任何自定义排序,默认按创建时间倒序
|
||||
queryChain.orderByDesc(SimulationJob::getCreateTime);
|
||||
}
|
||||
List<SimulationJob> results = queryChain.list();
|
||||
convertTotalElapsedTimeToCostTime(results);
|
||||
PageInfo<SimulationJob> page = new PageInfo<>(results);
|
||||
return PageUtils.getJsonObjectSdmResponse(results, page);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SdmResponse<SimulationHpcCommand> querySoftConfig(String appUuid) {
|
||||
// app对应hpc命令,一个只会有一个
|
||||
|
||||
Reference in New Issue
Block a user