From 33cdf7ae15d15d460a8fad8d39fd82ae33c6718a Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Mon, 8 Aug 2022 10:31:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E9=83=A8=E5=88=86=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=92=E5=BA=8F=E5=8A=9F=E8=83=BD(?= =?UTF-8?q?=E7=BD=AE=E9=A1=B6=E3=80=81=E4=B8=8A=E7=A7=BB=E3=80=81=E4=B8=8B?= =?UTF-8?q?=E7=A7=BB)=20#I5KBN9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../controller/build/BuildInfoController.java | 24 ++ .../build/RepositoryController.java | 25 +++ .../controller/node/NodeEditController.java | 25 +++ .../node/NodeProjectInfoController.java | 160 +++++++------ .../java/io/jpom/model/BaseGroupModel.java | 2 +- .../io/jpom/model/data/BuildInfoModel.java | 4 + .../java/io/jpom/model/data/NodeModel.java | 4 + .../io/jpom/model/data/RepositoryModel.java | 68 +----- .../model/node/ProjectInfoCacheModel.java | 210 +++++------------- .../service/h2db/BaseDbCommonService.java | 6 - .../service/h2db/BaseWorkspaceService.java | 100 +++++++++ .../src/main/resources/sql/h2-db-v2.1.sql | 6 + .../src/main/resources/sql/h2-db-v3.1.sql | 6 + web-vue/src/api/build-info.js | 8 + web-vue/src/api/node.js | 18 ++ web-vue/src/api/repository.js | 8 + web-vue/src/pages/build/list-info.vue | 54 ++++- web-vue/src/pages/node/list.vue | 58 ++++- web-vue/src/pages/node/search.vue | 70 +++++- web-vue/src/pages/repository/list.vue | 66 +++++- 21 files changed, 613 insertions(+), 310 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36fd27df4..57e93e904 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ 2. 【server】账号新增状态字段,用于控制禁用账号 3. 【server】重置密码使用系统生成 4. 【server】构建 docker 镜像支持使用构建序号 ID 为 tag 版本号递增(感谢@Y.) +5. 【server】部分列表新增排序功能(置顶、上移、下移)(感谢[@爱琳琳真是太好了](https://gitee.com/qiqi513_admin) [Gitee issues I5KBN9](https://gitee.com/dromara/Jpom/issues/I5KBN9) ) ### 🐞 解决BUG、优化功能 diff --git a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java index 29a0187c5..234e82570 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java +++ b/modules/server/src/main/java/io/jpom/controller/build/BuildInfoController.java @@ -463,4 +463,28 @@ public class BuildInfoController extends BaseServerController { return JsonMessage.getString(200, "清理成功"); } + /** + * 排序 + * + * @param id 节点ID + * @param method 方法 + * @param compareId 比较的ID + * @return msg + */ + @GetMapping(value = "/build/sort-item", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.EDIT) + public JsonMessage sortItem(@ValidatorItem String id, @ValidatorItem String method, String compareId) { + HttpServletRequest request = getRequest(); + if (StrUtil.equalsIgnoreCase(method, "top")) { + buildInfoService.sortToTop(id, request); + } else if (StrUtil.equalsIgnoreCase(method, "up")) { + buildInfoService.sortMoveUp(id, compareId, request); + } else if (StrUtil.equalsIgnoreCase(method, "down")) { + buildInfoService.sortMoveDown(id, compareId, request); + } else { + return new JsonMessage<>(400, "不支持的方式" + method); + } + return new JsonMessage<>(200, "操作成功"); + } + } diff --git a/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java b/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java index dc021d2c3..6607b723e 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java +++ b/modules/server/src/main/java/io/jpom/controller/build/RepositoryController.java @@ -57,6 +57,7 @@ import io.jpom.system.JpomRuntimeException; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -450,6 +451,30 @@ public class RepositoryController extends BaseServerController { return JsonMessage.getString(200, "删除成功"); } + /** + * 排序 + * + * @param id 节点ID + * @param method 方法 + * @param compareId 比较的ID + * @return msg + */ + @GetMapping(value = "/build/repository/sort-item", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.EDIT) + public JsonMessage sortItem(@ValidatorItem String id, @ValidatorItem String method, String compareId) { + HttpServletRequest request = getRequest(); + if (StrUtil.equalsIgnoreCase(method, "top")) { + repositoryService.sortToTop(id, request); + } else if (StrUtil.equalsIgnoreCase(method, "up")) { + repositoryService.sortMoveUp(id, compareId, request); + } else if (StrUtil.equalsIgnoreCase(method, "down")) { + repositoryService.sortMoveDown(id, compareId, request); + } else { + return new JsonMessage<>(400, "不支持的方式" + method); + } + return new JsonMessage<>(200, "操作成功"); + } + /** * Gitee 工具 */ diff --git a/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java b/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java index 68fb02ef6..b55ba4256 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/NodeEditController.java @@ -22,6 +22,7 @@ */ package io.jpom.controller.node; +import cn.hutool.core.util.StrUtil; import cn.jiangzeyin.common.JsonMessage; import cn.jiangzeyin.common.validator.ValidatorItem; import com.alibaba.fastjson.JSONArray; @@ -256,4 +257,28 @@ public class NodeEditController extends BaseServerController { nodeService.syncToWorkspace(ids, nowWorkspaceId, workspaceId); return JsonMessage.getString(200, "操作成功"); } + + /** + * 排序 + * + * @param id 节点ID + * @param method 方法 + * @param compareId 比较的ID + * @return msg + */ + @GetMapping(value = "sort-item", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.EDIT) + public JsonMessage sortItem(@ValidatorItem String id, @ValidatorItem String method, String compareId) { + HttpServletRequest request = getRequest(); + if (StrUtil.equalsIgnoreCase(method, "top")) { + nodeService.sortToTop(id, request); + } else if (StrUtil.equalsIgnoreCase(method, "up")) { + nodeService.sortMoveUp(id, compareId, request); + } else if (StrUtil.equalsIgnoreCase(method, "down")) { + nodeService.sortMoveDown(id, compareId, request); + } else { + return new JsonMessage<>(400, "不支持的方式" + method); + } + return new JsonMessage<>(200, "操作成功"); + } } diff --git a/modules/server/src/main/java/io/jpom/controller/node/NodeProjectInfoController.java b/modules/server/src/main/java/io/jpom/controller/node/NodeProjectInfoController.java index b56a84152..4df726c5e 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/NodeProjectInfoController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/NodeProjectInfoController.java @@ -25,6 +25,7 @@ package io.jpom.controller.node; import cn.hutool.core.util.StrUtil; import cn.hutool.db.Entity; import cn.jiangzeyin.common.JsonMessage; +import cn.jiangzeyin.common.validator.ValidatorItem; import io.jpom.common.BaseServerController; import io.jpom.model.PageResultDto; import io.jpom.model.data.NodeModel; @@ -41,6 +42,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; import java.util.List; /** @@ -54,80 +56,102 @@ import java.util.List; @Feature(cls = ClassFeature.NODE) public class NodeProjectInfoController extends BaseServerController { - private final ProjectInfoCacheService projectInfoCacheService; + private final ProjectInfoCacheService projectInfoCacheService; - public NodeProjectInfoController(ProjectInfoCacheService projectInfoCacheService) { - this.projectInfoCacheService = projectInfoCacheService; - } + public NodeProjectInfoController(ProjectInfoCacheService projectInfoCacheService) { + this.projectInfoCacheService = projectInfoCacheService; + } - /** - * @return json - * @author Hotstrip - * load node project list - * 加载节点项目列表 - */ - @PostMapping(value = "node_project_list", produces = MediaType.APPLICATION_JSON_VALUE) - public String nodeProjectList() { - PageResultDto resultDto = projectInfoCacheService.listPageNode(getRequest()); - return JsonMessage.getString(200, "success", resultDto); - } + /** + * @return json + * @author Hotstrip + * load node project list + * 加载节点项目列表 + */ + @PostMapping(value = "node_project_list", produces = MediaType.APPLICATION_JSON_VALUE) + public String nodeProjectList() { + PageResultDto resultDto = projectInfoCacheService.listPageNode(getRequest()); + return JsonMessage.getString(200, "success", resultDto); + } - /** - * load node project list - * 加载节点项目列表 - * - * @return json - * @author Hotstrip - */ - @PostMapping(value = "project_list", produces = MediaType.APPLICATION_JSON_VALUE) - public String projectList() { - PageResultDto resultDto = projectInfoCacheService.listPage(getRequest()); - return JsonMessage.getString(200, "success", resultDto); - } + /** + * load node project list + * 加载节点项目列表 + * + * @return json + * @author Hotstrip + */ + @PostMapping(value = "project_list", produces = MediaType.APPLICATION_JSON_VALUE) + public String projectList() { + PageResultDto resultDto = projectInfoCacheService.listPage(getRequest()); + return JsonMessage.getString(200, "success", resultDto); + } - /** - * load node project list - * 加载节点项目列表 - * - * @return json - * @author Hotstrip - */ - @GetMapping(value = "project_list_all", produces = MediaType.APPLICATION_JSON_VALUE) - public String projectListAll() { - List projectInfoCacheModels = projectInfoCacheService.listByWorkspace(getRequest()); - return JsonMessage.getString(200, "", projectInfoCacheModels); - } + /** + * load node project list + * 加载节点项目列表 + * + * @return json + * @author Hotstrip + */ + @GetMapping(value = "project_list_all", produces = MediaType.APPLICATION_JSON_VALUE) + public String projectListAll() { + List projectInfoCacheModels = projectInfoCacheService.listByWorkspace(getRequest()); + return JsonMessage.getString(200, "", projectInfoCacheModels); + } - /** - * 同步节点项目 - * - * @return json - */ - @GetMapping(value = "sync_project", produces = MediaType.APPLICATION_JSON_VALUE) - @Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL) - public String syncProject(String nodeId) { - NodeModel nodeModel = nodeService.getByKey(nodeId); - Assert.notNull(nodeModel, "对应的节点不存在"); - int count = projectInfoCacheService.delCache(nodeId, getRequest()); - String msg = projectInfoCacheService.syncExecuteNode(nodeModel); - return JsonMessage.getString(200, "主动清除:" + count + StrUtil.SPACE + msg); - } - - /** - * 删除节点缓存的所有项目 - * - * @return json - */ - @GetMapping(value = "clear_all_project", produces = MediaType.APPLICATION_JSON_VALUE) - @SystemPermission(superUser = true) - @Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL) - public String clearAll() { - Entity where = Entity.create(); - where.set("id", " <> id"); - int del = projectInfoCacheService.del(where); - return JsonMessage.getString(200, "成功删除" + del + "条项目缓存"); - } + /** + * 同步节点项目 + * + * @return json + */ + @GetMapping(value = "sync_project", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL) + public String syncProject(String nodeId) { + NodeModel nodeModel = nodeService.getByKey(nodeId); + Assert.notNull(nodeModel, "对应的节点不存在"); + int count = projectInfoCacheService.delCache(nodeId, getRequest()); + String msg = projectInfoCacheService.syncExecuteNode(nodeModel); + return JsonMessage.getString(200, "主动清除:" + count + StrUtil.SPACE + msg); + } + /** + * 删除节点缓存的所有项目 + * + * @return json + */ + @GetMapping(value = "clear_all_project", produces = MediaType.APPLICATION_JSON_VALUE) + @SystemPermission(superUser = true) + @Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL) + public String clearAll() { + Entity where = Entity.create(); + where.set("id", " <> id"); + int del = projectInfoCacheService.del(where); + return JsonMessage.getString(200, "成功删除" + del + "条项目缓存"); + } + /** + * 排序 + * + * @param id 节点ID + * @param method 方法 + * @param compareId 比较的ID + * @return msg + */ + @GetMapping(value = "project-sort-item", produces = MediaType.APPLICATION_JSON_VALUE) + @Feature(method = MethodFeature.EDIT) + public JsonMessage sortItem(@ValidatorItem String id, @ValidatorItem String method, String compareId) { + HttpServletRequest request = getRequest(); + if (StrUtil.equalsIgnoreCase(method, "top")) { + projectInfoCacheService.sortToTop(id, request); + } else if (StrUtil.equalsIgnoreCase(method, "up")) { + projectInfoCacheService.sortMoveUp(id, compareId, request); + } else if (StrUtil.equalsIgnoreCase(method, "down")) { + projectInfoCacheService.sortMoveDown(id, compareId, request); + } else { + return new JsonMessage<>(400, "不支持的方式" + method); + } + return new JsonMessage<>(200, "操作成功"); + } } diff --git a/modules/server/src/main/java/io/jpom/model/BaseGroupModel.java b/modules/server/src/main/java/io/jpom/model/BaseGroupModel.java index 39387c6f9..8900d935a 100644 --- a/modules/server/src/main/java/io/jpom/model/BaseGroupModel.java +++ b/modules/server/src/main/java/io/jpom/model/BaseGroupModel.java @@ -34,7 +34,7 @@ import lombok.EqualsAndHashCode; public abstract class BaseGroupModel extends BaseWorkspaceModel { /** - * 节点分组 + * 分组 */ private String group; diff --git a/modules/server/src/main/java/io/jpom/model/data/BuildInfoModel.java b/modules/server/src/main/java/io/jpom/model/data/BuildInfoModel.java index 8a5da69ea..77d7dbb25 100644 --- a/modules/server/src/main/java/io/jpom/model/data/BuildInfoModel.java +++ b/modules/server/src/main/java/io/jpom/model/data/BuildInfoModel.java @@ -115,6 +115,10 @@ public class BuildInfoModel extends BaseGroupModel { * 仓库代码最后一次变动信息(ID,git 为 commit hash, svn 最后的版本号) */ private String repositoryLastCommitId; + /** + * 排序 + */ + private Float sortValue; @Tolerate public BuildInfoModel() { diff --git a/modules/server/src/main/java/io/jpom/model/data/NodeModel.java b/modules/server/src/main/java/io/jpom/model/data/NodeModel.java index aa1e931d9..fd9e5f938 100644 --- a/modules/server/src/main/java/io/jpom/model/data/NodeModel.java +++ b/modules/server/src/main/java/io/jpom/model/data/NodeModel.java @@ -90,6 +90,10 @@ public class NodeModel extends BaseGroupModel { * https 代理 类型 */ private String httpProxyType; + /** + * 排序 + */ + private Float sortValue; public boolean isOpenStatus() { return openStatus != null && openStatus == 1; diff --git a/modules/server/src/main/java/io/jpom/model/data/RepositoryModel.java b/modules/server/src/main/java/io/jpom/model/data/RepositoryModel.java index 961fa8700..d461b5b36 100644 --- a/modules/server/src/main/java/io/jpom/model/data/RepositoryModel.java +++ b/modules/server/src/main/java/io/jpom/model/data/RepositoryModel.java @@ -29,6 +29,8 @@ import io.jpom.model.BaseEnum; import io.jpom.model.BaseWorkspaceModel; import io.jpom.model.enums.GitProtocolEnum; import io.jpom.service.h2db.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.HashMap; import java.util.Map; @@ -38,6 +40,8 @@ import java.util.Map; * 仓库地址实体类 */ @TableName(value = "REPOSITORY", name = "仓库信息") +@Data +@EqualsAndHashCode(callSuper = true) public class RepositoryModel extends BaseWorkspaceModel { /** * 名称 @@ -75,29 +79,11 @@ public class RepositoryModel extends BaseWorkspaceModel { */ private String rsaPrv; - public String getName() { - return name; - } + /** + * 排序 + */ + private Float sortValue; - public void setName(String name) { - this.name = name; - } - - public String getGitUrl() { - return gitUrl; - } - - public void setGitUrl(String gitUrl) { - this.gitUrl = gitUrl; - } - - public Integer getRepoType() { - return repoType; - } - - public void setRepoType(Integer repoType) { - this.repoType = repoType; - } /** * 返回协议类型,如果为 null 会尝试识别 http @@ -119,44 +105,6 @@ public class RepositoryModel extends BaseWorkspaceModel { return null; } - public void setProtocol(Integer protocol) { - this.protocol = protocol; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Deprecated - public String getRsaPub() { - return rsaPub; - } - - @Deprecated - public void setRsaPub(String rsaPub) { - this.rsaPub = rsaPub; - } - - public String getRsaPrv() { - return rsaPrv; - } - - public void setRsaPrv(String rsaPrv) { - this.rsaPrv = rsaPrv; - } - /** * 转换为 map * diff --git a/modules/server/src/main/java/io/jpom/model/node/ProjectInfoCacheModel.java b/modules/server/src/main/java/io/jpom/model/node/ProjectInfoCacheModel.java index 8f028634e..efca60dcd 100644 --- a/modules/server/src/main/java/io/jpom/model/node/ProjectInfoCacheModel.java +++ b/modules/server/src/main/java/io/jpom/model/node/ProjectInfoCacheModel.java @@ -24,177 +24,71 @@ package io.jpom.model.node; import io.jpom.model.BaseNodeModel; import io.jpom.service.h2db.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; /** * @author bwcx_jzy * @since 2021/12/5 */ @TableName(value = "PROJECT_INFO", name = "项目信息") +@Data +@EqualsAndHashCode(callSuper = true) public class ProjectInfoCacheModel extends BaseNodeModel { - private String projectId; + private String projectId; - private String name; + private String name; - private String mainClass; - private String lib; - /** - * 白名单目录 - */ - private String whitelistDirectory; - /** - * 日志目录 - */ - private String logPath; - /** - * jvm 参数 - */ - private String jvm; - /** - * java main 方法参数 - */ - private String args; + private String mainClass; + private String lib; + /** + * 白名单目录 + */ + private String whitelistDirectory; + /** + * 日志目录 + */ + private String logPath; + /** + * jvm 参数 + */ + private String jvm; + /** + * java main 方法参数 + */ + private String args; - private String javaCopyItemList; - /** - * WebHooks - */ - private String token; + private String javaCopyItemList; + /** + * WebHooks + */ + private String token; - private String jdkId; + private String jdkId; - private String runMode; - /** - * 节点分发项目,不允许在项目管理中编辑 - */ - private Integer outGivingProject; - /** - * -Djava.ext.dirs=lib -cp conf:run.jar - * 填写【lib:conf】 - */ - private String javaExtDirsCp; + private String runMode; + /** + * 节点分发项目,不允许在项目管理中编辑 + */ + private Integer outGivingProject; + /** + * -Djava.ext.dirs=lib -cp conf:run.jar + * 填写【lib:conf】 + */ + private String javaExtDirsCp; + /** + * 排序 + */ + private Float sortValue; - @Override - public String dataId() { - return getProjectId(); - } + @Override + public String dataId() { + return getProjectId(); + } - @Override - public void dataId(String id) { - setProjectId(id); - } - - public String getProjectId() { - return projectId; - } - - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getMainClass() { - return mainClass; - } - - public void setMainClass(String mainClass) { - this.mainClass = mainClass; - } - - public String getLib() { - return lib; - } - - public void setLib(String lib) { - this.lib = lib; - } - - public String getWhitelistDirectory() { - return whitelistDirectory; - } - - public void setWhitelistDirectory(String whitelistDirectory) { - this.whitelistDirectory = whitelistDirectory; - } - - - public String getLogPath() { - return logPath; - } - - public void setLogPath(String logPath) { - this.logPath = logPath; - } - - public String getJvm() { - return jvm; - } - - public void setJvm(String jvm) { - this.jvm = jvm; - } - - public String getArgs() { - return args; - } - - public void setArgs(String args) { - this.args = args; - } - - public String getJavaCopyItemList() { - return javaCopyItemList; - } - - public void setJavaCopyItemList(String javaCopyItemList) { - this.javaCopyItemList = javaCopyItemList; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public String getJdkId() { - return jdkId; - } - - public void setJdkId(String jdkId) { - this.jdkId = jdkId; - } - - public String getRunMode() { - return runMode; - } - - public void setRunMode(String runMode) { - this.runMode = runMode; - } - - public Integer getOutGivingProject() { - return outGivingProject; - } - - public void setOutGivingProject(Integer outGivingProject) { - this.outGivingProject = outGivingProject; - } - - public String getJavaExtDirsCp() { - return javaExtDirsCp; - } - - public void setJavaExtDirsCp(String javaExtDirsCp) { - this.javaExtDirsCp = javaExtDirsCp; - } + @Override + public void dataId(String id) { + setProjectId(id); + } } diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java index 3a9a0b4c7..137aeaa3e 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseDbCommonService.java @@ -72,12 +72,6 @@ public abstract class BaseDbCommonService { */ protected final String key; - public BaseDbCommonService(String tableName, String key, Class tClass) { - this.tableName = this.covetTableName(tableName, tClass); - this.tClass = tClass; - this.key = key; - } - @SuppressWarnings("unchecked") public BaseDbCommonService(String tableName, String key) { this.tClass = (Class) TypeUtil.getTypeArgument(this.getClass()); diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java index f56cef417..22c34d7dd 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java @@ -22,9 +22,14 @@ */ package io.jpom.service.h2db; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Opt; import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.db.Entity; +import cn.hutool.db.sql.Direction; +import cn.hutool.db.sql.Order; import cn.hutool.extra.servlet.ServletUtil; import cn.jiangzeyin.common.spring.SpringUtil; import io.jpom.common.BaseServerController; @@ -40,7 +45,9 @@ import javax.servlet.http.HttpServletRequest; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; +import java.util.function.Function; /** * 工作空间 通用 service @@ -49,6 +56,23 @@ import java.util.function.Consumer; * @since 2021/8/13 */ public abstract class BaseWorkspaceService extends BaseDbService { + /** + * 是否可以进行排序 + */ + private final boolean canSort; + /** + * 有排序字段的默认排序规则 + */ + private static final Order[] SORT_DEFAULT_ORDERS = new Order[]{ + new Order("sortValue", Direction.DESC), + new Order("createTimeMillis", Direction.DESC), + new Order("modifyTimeMillis", Direction.DESC) + }; + + public BaseWorkspaceService() { + super(); + this.canSort = ReflectUtil.hasField(this.tClass, "sortValue"); + } /** * 根据工作空间查询 @@ -239,4 +263,80 @@ public abstract class BaseWorkspaceService extends String workspaceId = this.getCheckUserWorkspace(request); return super.updateById(info, entity -> entity.set("workspaceId", workspaceId)); } + + // 排序相关方法 --------- + + + @Override + protected Order[] defaultOrders() { + if (canSort) { + return SORT_DEFAULT_ORDERS; + } + return super.defaultOrders(); + } + + /** + * 置顶 + * + * @param id 数据ID + * @param request 请求 + */ + public void sortToTop(String id, HttpServletRequest request) { + Assert.state(canSort, "当前数据不支持排序"); + String workspaceId = this.getCheckUserWorkspace(request); + String maxSql = "select max(sortValue) as sortValue from " + this.tableName + " where workspaceId=?"; + List query = this.query(maxSql, workspaceId); + float maxSortValue = Opt.ofEmptyAble(query) + .map(CollUtil::getFirst) + .map(entity -> entity.getFloat("sortValue")) + .orElse(1f); + // + String updateSql = "update " + this.tableName + " set sortValue=? where id=? and workspaceId=?"; + this.execute(updateSql, maxSortValue + 0.0001f, id, workspaceId); + } + + /** + * 向上移 + * + * @param id 数据ID + * @param beforeId 前面一个数据的ID + * @param request 请求 + */ + public void sortMoveUp(String id, String beforeId, HttpServletRequest request) { + this.sortMove(id, beforeId, request, true); + } + + /** + * 向下移 + * + * @param id 数据ID + * @param afterId 后面一个数据的ID + * @param request 请求 + */ + public void sortMoveDown(String id, String afterId, HttpServletRequest request) { + this.sortMove(id, afterId, request, false); + } + + /** + * 移动排序方法 + * + * @param id 数据ID + * @param compareId 比较的数据ID + * @param request 请求 + * @param up true 上移 + */ + private void sortMove(String id, String compareId, HttpServletRequest request, boolean up) { + Assert.state(canSort, "当前数据不支持排序"); + Assert.hasText(id, "数据id 不存在"); + Assert.hasText(compareId, "比较 id 不存在"); + String workspaceId = this.getCheckUserWorkspace(request); + String sql = "select sortValue as sortValue from " + this.tableName + " where id=? and workspaceId=?"; + List query = this.query(sql, compareId, workspaceId); + float compareSortValue = Opt.ofEmptyAble(query) + .map(CollUtil::getFirst) + .map(entity -> entity.getFloat("sortValue")) + .orElse(1f); + String updateSql = "update " + this.tableName + " set sortValue=? where id=? and workspaceId=?"; + this.execute(updateSql, up ? compareSortValue + 0.0001f : compareSortValue - 0.0001f, id, workspaceId); + } } diff --git a/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v2.1.sql b/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v2.1.sql index 14f12ca73..3a32d720e 100644 --- a/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v2.1.sql +++ b/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v2.1.sql @@ -137,3 +137,9 @@ ALTER TABLE BUILD_INFO ALTER TABLE BUILD_INFO ADD IF NOT EXISTS repositoryLastCommitId varchar(255) comment '仓库代码最后一次变动信息(ID,git 为 commit hash, svn 最后的版本号)'; + +ALTER TABLE BUILD_INFO + ADD IF NOT EXISTS `sortValue` REAL comment '排序值'; + +ALTER TABLE REPOSITORY + ADD IF NOT EXISTS `sortValue` REAL comment '排序值'; diff --git a/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v3.1.sql b/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v3.1.sql index bb9b8839e..1ad68e2f5 100644 --- a/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v3.1.sql +++ b/modules/sub-plugin/db-h2/src/main/resources/sql/h2-db-v3.1.sql @@ -114,6 +114,12 @@ ALTER TABLE COMMAND_INFO ALTER TABLE SERVER_SCRIPT_INFO ADD IF NOT EXISTS triggerToken VARCHAR(200) comment '触发器token'; +ALTER TABLE NODE_INFO + ADD IF NOT EXISTS `sortValue` REAL comment '排序值'; + +ALTER TABLE PROJECT_INFO + ADD IF NOT EXISTS `sortValue` REAL comment '排序值'; + diff --git a/web-vue/src/api/build-info.js b/web-vue/src/api/build-info.js index 846fe9cc6..54c57191c 100644 --- a/web-vue/src/api/build-info.js +++ b/web-vue/src/api/build-info.js @@ -248,6 +248,14 @@ export function deleteBuildHistory(logId) { }); } +export function sortItem(params) { + return axios({ + url: "/build/sort-item", + method: "get", + params: params, + }); +} + export const statusMap = { 1: "构建中", 2: "构建完成", diff --git a/web-vue/src/api/node.js b/web-vue/src/api/node.js index 7ecc33b31..c2777dff5 100644 --- a/web-vue/src/api/node.js +++ b/web-vue/src/api/node.js @@ -104,6 +104,15 @@ export function syncToWorkspace(params) { }); } +// +export function sortItem(params) { + return axios({ + url: "/node/sort-item", + method: "get", + params: params, + }); +} + // 删除节点项目缓存 export function delAllProjectCache() { return axios({ @@ -113,6 +122,15 @@ export function delAllProjectCache() { }); } +// 项目排序 +export function sortItemProject(params) { + return axios({ + url: "/node/project-sort-item", + method: "get", + params: params, + }); +} + /** * 编辑 node * @param { diff --git a/web-vue/src/api/repository.js b/web-vue/src/api/repository.js index e54d8ae5b..2b086e8ea 100644 --- a/web-vue/src/api/repository.js +++ b/web-vue/src/api/repository.js @@ -91,3 +91,11 @@ export function authorizeRepos(param) { params: param, }); } + +export function sortItem(params) { + return axios({ + url: "/build/repository/sort-item", + method: "get", + params: params, + }); +} diff --git a/web-vue/src/pages/build/list-info.vue b/web-vue/src/pages/build/list-info.vue index 6bdb632ff..df1428661 100644 --- a/web-vue/src/pages/build/list-info.vue +++ b/web-vue/src/pages/build/list-info.vue @@ -63,7 +63,7 @@ {{ text }} - + {{ text }} - -