From 028137e8a0f6e19d9e1f52c277787708dcbab33e Mon Sep 17 00:00:00 2001 From: asp_ly Date: Thu, 26 Dec 2024 21:37:35 +0800 Subject: [PATCH] 1 --- .../deploy/dto/DeployAppConfigDTO.java | 12 +++- .../variables/JenkinsBaseBuildVariables.java | 5 +- .../variables/JenkinsJavaBuildVariables.java | 58 +++++-------------- .../deploy/entity/DeployAppConfig.java | 7 ++- .../workflow/annotation/SchemaProperty.java | 5 ++ .../BaseNodePanelVariables.java | 9 ++- .../ScriptNodePanelVariables.java | 34 +++++------ .../workflow/util/GenerateSchemaUtils.java | 16 +++++ 8 files changed, 78 insertions(+), 68 deletions(-) diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/DeployAppConfigDTO.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/DeployAppConfigDTO.java index c8b429fb..27297a0b 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/DeployAppConfigDTO.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/DeployAppConfigDTO.java @@ -2,8 +2,11 @@ package com.qqchen.deploy.backend.deploy.dto; import com.fasterxml.jackson.databind.JsonNode; import com.qqchen.deploy.backend.deploy.enums.BuildTypeEnum; +import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum; import com.qqchen.deploy.backend.framework.dto.BaseDTO; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; @@ -16,14 +19,21 @@ import lombok.EqualsAndHashCode; public class DeployAppConfigDTO extends BaseDTO { @Schema(description = "环境ID") + @NotBlank(message = "环境ID不能为空") private Long environmentId; @Schema(description = "应用ID") + @NotBlank(message = "应用ID不能为空") private Long applicationId; @Schema(description = "构建类型") + @NotNull(message = "构建类型不能为空") private BuildTypeEnum buildType; - @Schema(description = "构建变量") + @NotNull(message = "应用语言不能为空") + private DevelopmentLanguageTypeEnum languageType; + + @Schema(description = "构建配置") + @NotBlank(message = "构建配置不能为空") private JsonNode buildVariables; } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsBaseBuildVariables.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsBaseBuildVariables.java index 5a67a86c..e0363a8e 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsBaseBuildVariables.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsBaseBuildVariables.java @@ -12,8 +12,9 @@ public class JenkinsBaseBuildVariables { @SchemaProperty( title = "分支名称", description = "Git分支名称", - required = true + required = true, + order = 1 ) private String branch; - + } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsJavaBuildVariables.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsJavaBuildVariables.java index bfb0f879..933a68c1 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsJavaBuildVariables.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/variables/JenkinsJavaBuildVariables.java @@ -13,52 +13,22 @@ public class JenkinsJavaBuildVariables extends JenkinsBaseBuildVariables { @SchemaProperty( - title = "脚本代码", - description = "脚本代码", - required = true + title = "构建产物路径", + description = "构建产物路径", + order = 2 + ) + private String artifactPath; + + + @SchemaProperty( + title = "Pipeline script", + description = "流水线脚本", + required = true, + format = "monaco-editor", // 使用 Monaco Editor + defaultValue = "#!/bin/bash\n\necho \"Hello World\"", + order = 3 ) private String script; - /** - * 脚本语言 - */ - @SchemaProperty( - title = "脚本语言", - description = "脚本语言类型", - required = true, - enumValues = {"shell", "python", "javascript", "groovy"}, - enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"}, - defaultValue = "shell" - ) - private String language; - /** - * 解释器路径 - */ - @SchemaProperty( - title = "解释器路径", - description = "脚本解释器的路径,例如:/bin/bash, /usr/bin/python3", - required = true - ) - private String interpreter; - - /** - * 成功退出码 - */ - @SchemaProperty( - title = "成功标识", - description = "脚本执行成功时的标识", - required = true - ) - private Integer successExitCode; - - /** - * 支持的脚本语言列表 - */ - @SchemaProperty( - title = "支持的脚本语言", - enumValues = {"shell", "python", "javascript", "groovy"}, - enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"} - ) - private List supportedLanguages; } \ No newline at end of file diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/entity/DeployAppConfig.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/entity/DeployAppConfig.java index da816c73..96964c31 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/entity/DeployAppConfig.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/entity/DeployAppConfig.java @@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.deploy.entity; import com.fasterxml.jackson.databind.JsonNode; import com.qqchen.deploy.backend.deploy.enums.BuildTypeEnum; +import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum; import com.qqchen.deploy.backend.framework.domain.Entity; import com.vladmihalcea.hibernate.type.json.JsonType; import jakarta.persistence.Column; @@ -26,10 +27,14 @@ public class DeployAppConfig extends Entity { @Column(name = "application_id", nullable = false) private Long applicationId; - @Column(nullable = false) + @Column(name = "build_type", nullable = false) @Enumerated(EnumType.STRING) private BuildTypeEnum buildType; + @Column(name = "language_type", nullable = false) + @Enumerated(EnumType.STRING) + private DevelopmentLanguageTypeEnum languageType; + @Type(JsonType.class) @Column(name = "build_variables", columnDefinition = "text", nullable = false) private JsonNode buildVariables; diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/annotation/SchemaProperty.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/annotation/SchemaProperty.java index 3df1fa6f..f61ce7ec 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/annotation/SchemaProperty.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/annotation/SchemaProperty.java @@ -93,4 +93,9 @@ public @interface SchemaProperty { * 枚举值显示名称 */ String[] enumNames() default {}; + + /** + * 字段排序,值越小越靠前 + */ + int order() default Integer.MAX_VALUE; } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/BaseNodePanelVariables.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/BaseNodePanelVariables.java index 065f8f56..f401e9ee 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/BaseNodePanelVariables.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/BaseNodePanelVariables.java @@ -12,7 +12,8 @@ public class BaseNodePanelVariables { @SchemaProperty( title = "节点编码", description = "工作流节点的编码", - required = true + required = true, + order = 1 ) private String code; @@ -22,7 +23,8 @@ public class BaseNodePanelVariables { @SchemaProperty( title = "节点名称", description = "工作流节点的显示名称", - required = true + required = true, + order = 2 ) private String name; @@ -31,7 +33,8 @@ public class BaseNodePanelVariables { */ @SchemaProperty( title = "节点描述", - description = "工作流节点的详细描述" + description = "工作流节点的详细描述", + order = 3 ) private String description; } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/ScriptNodePanelVariables.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/ScriptNodePanelVariables.java index da97d1ea..9b7124b7 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/ScriptNodePanelVariables.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/dto/definition/node/panelVariables/ScriptNodePanelVariables.java @@ -14,13 +14,6 @@ import java.util.List; public class ScriptNodePanelVariables extends BaseNodePanelVariables { - @SchemaProperty( - title = "脚本代码", - description = "脚本代码", - required = true - ) - private String script; - /** * 脚本语言 */ @@ -30,27 +23,33 @@ public class ScriptNodePanelVariables extends BaseNodePanelVariables { required = true, enumValues = {"shell", "python", "javascript", "groovy"}, enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"}, - defaultValue = "shell" + defaultValue = "shell", + order = 10 ) private String language; - /** - * 解释器路径 - */ + @SchemaProperty( + title = "脚本代码", + description = "脚本代码", + required = true, + format = "monaco-editor", + order = 20 + ) + private String script; + @SchemaProperty( title = "解释器路径", description = "脚本解释器的路径,例如:/bin/bash, /usr/bin/python3", - required = true + required = true, + order = 30 ) private String interpreter; - /** - * 成功退出码 - */ @SchemaProperty( title = "成功标识", description = "脚本执行成功时的标识", - required = true + required = true, + order = 40 ) private Integer successExitCode; @@ -60,7 +59,8 @@ public class ScriptNodePanelVariables extends BaseNodePanelVariables { @SchemaProperty( title = "支持的脚本语言", enumValues = {"shell", "python", "javascript", "groovy"}, - enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"} + enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"}, + order = 50 ) private List supportedLanguages; diff --git a/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/GenerateSchemaUtils.java b/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/GenerateSchemaUtils.java index 6ddd5832..5ec3e26e 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/GenerateSchemaUtils.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/workflow/util/GenerateSchemaUtils.java @@ -26,6 +26,22 @@ public class GenerateSchemaUtils { // 获取所有字段,包括父类的字段 List allFields = getAllFields(cls); + + // 按SchemaProperty的order排序 + allFields.sort((a, b) -> { + SchemaProperty annotationA = a.getAnnotation(SchemaProperty.class); + SchemaProperty annotationB = b.getAnnotation(SchemaProperty.class); + if (annotationA == null && annotationB == null) { + return 0; + } + if (annotationA == null) { + return 1; + } + if (annotationB == null) { + return -1; + } + return Integer.compare(annotationA.order(), annotationB.order()); + }); // 遍历所有字段 for (Field field : allFields) {