Skip to content

Commit

Permalink
Merge pull request #1348 from wangyu096/3.5.x
Browse files Browse the repository at this point in the history
perf: 脚本列表,脚本语言的排序需要按照语言名称的字典顺序 #1317
  • Loading branch information
jsonwan authored Sep 22, 2022
2 parents a6be504 + 6e06364 commit 66586a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public enum Order {
DESCENDING(0), ASCENDING(1);

private int order;
private final int order;

Order(int order) {
this.order = order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public enum ScriptTypeEnum {
/**
* 脚本类型枚举类
*/
SHELL(1, "shell", ".sh"), BAT(2, "bat", ".bat"), PERL(3, "perl", ".pl"), PYTHON(4, "python", ".py"),
POWERSHELL(5, "powershell", ".ps1"), SQL(6, "sql", ".sql");
SHELL(1, "shell", ".sh"),
BAT(2, "bat", ".bat"),
PERL(3, "perl", ".pl"),
PYTHON(4, "python", ".py"),
POWERSHELL(5, "powershell", ".ps1"),
SQL(6, "sql", ".sql");

private final Integer value;
private final String name;
Expand Down Expand Up @@ -98,4 +102,16 @@ public static String getExtByValue(int value) {
return "";
}
}

/**
* 获取脚本类型的字典名称的排序
*
* @return 排序
*/
public static ScriptTypeEnum[] getScriptTypeNameAscSort() {
// 按照脚本语言名称字典顺序排序.Bat(2)->Perl(3)->Powershell(5)->Python(4)->Shell(1)->SQL(6)
return new ScriptTypeEnum[]{
BAT, PERL, POWERSHELL, PYTHON, SHELL, SQL
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.tencent.bk.job.manage.dao.impl;

import com.tencent.bk.job.common.constant.Order;
import com.tencent.bk.job.common.model.BaseSearchCondition;
import com.tencent.bk.job.common.model.PageData;
import com.tencent.bk.job.common.util.JobUUID;
Expand Down Expand Up @@ -54,6 +55,7 @@
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -87,25 +89,29 @@ public PageData<ScriptDTO> listPageScript(ScriptQuery scriptQuery,
String orderField = baseSearchCondition.getOrderField();
if ("name".equals(orderField)) {
//升序
if (baseSearchCondition.getOrder() == 1) {
if (baseSearchCondition.getOrder() == Order.ASCENDING.getOrder()) {
orderFields.add(TB_SCRIPT.NAME.asc());
} else {
orderFields.add(TB_SCRIPT.NAME.desc());
}
} else if ("type".equals(orderField)) {
if (baseSearchCondition.getOrder() == 1) {
orderFields.add(TB_SCRIPT.TYPE.asc());
String sortExpr = Arrays.stream(ScriptTypeEnum.getScriptTypeNameAscSort())
.map(scriptTypeEnum -> scriptTypeEnum.getValue().toString())
.reduce((a, b) -> a + "," + b)
.orElse("");
if (baseSearchCondition.getOrder() == Order.ASCENDING.getOrder()) {
orderFields.add(DSL.field("field({0}," + sortExpr + ")", TB_SCRIPT.TYPE).asc());
} else {
orderFields.add(TB_SCRIPT.TYPE.desc());
orderFields.add(DSL.field("field({0}," + sortExpr + ")", TB_SCRIPT.TYPE).desc());
}
} else if ("creator".equals(orderField)) {
if (baseSearchCondition.getOrder() == 1) {
if (baseSearchCondition.getOrder() == Order.ASCENDING.getOrder()) {
orderFields.add(TB_SCRIPT.CREATOR.asc());
} else {
orderFields.add(TB_SCRIPT.CREATOR.desc());
}
} else if ("lastModifyTime".equals(orderField)) {
if (baseSearchCondition.getOrder() == 1) {
if (baseSearchCondition.getOrder() == Order.ASCENDING.getOrder()) {
orderFields.add(TB_SCRIPT.LAST_MODIFY_TIME.asc());
} else {
orderFields.add(TB_SCRIPT.LAST_MODIFY_TIME.desc());
Expand Down

0 comments on commit 66586a5

Please sign in to comment.