增加formily json schema生成

This commit is contained in:
dengqichen 2025-01-20 17:57:30 +08:00
parent 1b0cb4452e
commit 50e0d99712
5 changed files with 35 additions and 177 deletions

View File

@ -4,10 +4,17 @@ import com.qqchen.deploy.backend.deploy.dto.DeployAppConfigDTO;
import com.qqchen.deploy.backend.deploy.entity.DeployAppConfig; import com.qqchen.deploy.backend.deploy.entity.DeployAppConfig;
import com.qqchen.deploy.backend.framework.converter.BaseConverter; import com.qqchen.deploy.backend.framework.converter.BaseConverter;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
/** /**
* 应用配置转换器 * 应用配置转换器
*/ */
@Mapper(config = BaseConverter.class) @Mapper(config = BaseConverter.class, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface DeployAppConfigConverter extends BaseConverter<DeployAppConfig, DeployAppConfigDTO> { public interface DeployAppConfigConverter extends BaseConverter<DeployAppConfig, DeployAppConfigDTO> {
}
@Override
@Mapping(target = "formVariablesSchema", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void updateEntity(@MappingTarget DeployAppConfig entity, DeployAppConfigDTO dto);
}

View File

@ -12,136 +12,13 @@ import java.util.Map;
@FormilyForm(name = "Jenkins构建配置") @FormilyForm(name = "Jenkins构建配置")
public class JenkinsBaseBuildVariables { public class JenkinsBaseBuildVariables {
// @FormilyField( private String externalSystemId;
// title = "绑定三方Jenkins系统",
// component = "Select", private String viewId;
// order = 1,
// props = @FormilyComponentProps( private String jobId;
// labelField = "name",
// valueField = "id", private Map<String, String> envs;
// allowClear = true,
// showSearch = true, private String script;
// placeholder = "请选择Jenkins系统"
// ),
// validators = {
// @FormilyValidator(
// required = true,
// message = "请选择Jenkins系统"
// )
// },
// reactions = {
// @FormilyReaction(
// state = "dataSource",
// value = "{{$fetch('/api/v1/external-system/list?type=JENKINS').then(data => data.data)}}",
// when = "{{$form.mounted && $form.values.__modalVisible}}"
// )
// }
// )
// private String externalSystemId;
//
// @FormilyField(
// title = "绑定Jenkins视图",
// component = "Select",
// order = 2,
// props = @FormilyComponentProps(
// labelField = "viewName",
// valueField = "id",
// allowClear = true,
// showSearch = true,
// placeholder = "请选择Jenkins视图"
// ),
// validators = {
// @FormilyValidator(
// required = true,
// message = "请选择Jenkins视图"
// )
// },
// reactions = {
// @FormilyReaction(
// dependencies = {"externalSystemId"},
// state = "dataSource",
// value = "{{$fetch('/api/v1/jenkins-view/list?externalSystemId=' + $deps.externalSystemId).then(data => data.data)}}"
// )
// }
// )
// private String viewId;
//
// @FormilyField(
// title = "绑定Jenkins任务",
// component = "Select",
// order = 3,
// props = @FormilyComponentProps(
// labelField = "jobName",
// valueField = "id",
// allowClear = true,
// showSearch = true,
// placeholder = "请选择Jenkins任务"
// ),
// validators = {
// @FormilyValidator(
// required = true,
// message = "请选择Jenkins任务"
// )
// },
// reactions = {
// @FormilyReaction(
// dependencies = {"externalSystemId", "viewId"},
// state = "dataSource",
// value = "{{$fetch('/api/v1/jenkins-job/list?externalSystemId=' + $deps.externalSystemId + '&viewId=' + $deps.viewId).then(data => data.data)}}"
// )
// }
// )
// private String jobId;
//
// @FormilyField(
// title = "环境变量",
// type = "map",
// order = 4,
// mapConfig = @FormilyMapConfig(
// keyTitle = "变量名",
// valueTitle = "变量值",
// keyComponent = "Select",
// valueComponent = "Input",
// keyProps = @FormilyComponentProps(
//// api = "/api/v1/env-vars/keys",
// showSearch = true,
// allowClear = true,
// placeholder = "请选择或输入变量名"
// ),
// valueProps = @FormilyComponentProps(
// placeholder = "请输入变量值"
// ),
// addText = "添加环境变量",
// allowCustomKey = true
// )
// )
// private Map<String, String> envVars;
//
// @FormilyField(
// title = "Pipeline script",
// type = "string",
// component = "MonacoEditor",
// order = 5,
// props = @FormilyComponentProps(
// editor = @FormilyEditorProps(
// language = "groovy",
// theme = "vs-dark",
// minimap = false,
// lineNumbers = true,
// wordWrap = true,
// fontSize = 14,
// tabSize = 4,
// automaticLayout = true,
// folding = true,
// placeholder = "请输入Pipeline脚本"
// )
// ),
// validators = {
// @FormilyValidator(
// required = true,
// message = "请输入Pipeline脚本"
// )
// }
// )
// private String script;
} }

View File

@ -22,6 +22,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
@ -42,6 +43,7 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import java.nio.charset.Charset;
import java.util.Base64; import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -187,10 +189,19 @@ public class JenkinsServiceIntegrationImpl implements IJenkinsServiceIntegration
// 获取Job配置 // 获取Job配置
String configUrl = String.format("%s/job/%s/config.xml", externalSystem.getUrl(), jobName); String configUrl = String.format("%s/job/%s/config.xml", externalSystem.getUrl(), jobName);
HttpHeaders headers = createHeaders(externalSystem); HttpHeaders headers = createHeaders(externalSystem);
// 设置请求和响应的字符编码
headers.set(HttpHeaders.ACCEPT_CHARSET, "UTF-8"); headers.set(HttpHeaders.ACCEPT_CHARSET, "UTF-8");
headers.set(HttpHeaders.CONTENT_TYPE, "application/xml;charset=UTF-8");
headers.setAcceptCharset(Collections.singletonList(Charset.forName("UTF-8")));
headers.set("Jenkins-Crumb", jenkinsCrumbIssue.getCrumb()); headers.set("Jenkins-Crumb", jenkinsCrumbIssue.getCrumb());
headers.set("Cookie", jenkinsCrumbIssue.getCookie()); headers.set("Cookie", jenkinsCrumbIssue.getCookie());
HttpEntity<String> entity = new HttpEntity<>(headers); HttpEntity<String> entity = new HttpEntity<>(headers);
// 配置RestTemplate确保使用UTF-8编码
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
ResponseEntity<String> response = restTemplate.exchange( ResponseEntity<String> response = restTemplate.exchange(
configUrl, configUrl,
HttpMethod.GET, HttpMethod.GET,

View File

@ -31,6 +31,7 @@ import com.qqchen.deploy.backend.workflow.entity.WorkflowInstance;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository; import com.qqchen.deploy.backend.workflow.repository.IWorkflowDefinitionRepository;
import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository; import com.qqchen.deploy.backend.workflow.repository.IWorkflowInstanceRepository;
import com.qqchen.deploy.backend.workflow.service.IWorkflowInstanceService; import com.qqchen.deploy.backend.workflow.service.IWorkflowInstanceService;
import com.qqchen.deploy.backend.workflow.util.GenerateSchemaUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -175,7 +176,7 @@ public class DeployAppConfigServiceImpl extends BaseServiceImpl<DeployAppConfig,
public DeployAppConfigDTO create(DeployAppConfigDTO dto) { public DeployAppConfigDTO create(DeployAppConfigDTO dto) {
DeployAppConfig entity = converter.toEntity(dto); DeployAppConfig entity = converter.toEntity(dto);
// 使用新的FormilySchemaFactory生成Schema // 使用新的FormilySchemaFactory生成Schema
entity.setFormVariablesSchema(FormilySchemaFactory.generateSchema(dto.getBuildType().getFormVariablesSchema())); entity.setFormVariablesSchema(GenerateSchemaUtils.generateSchema(dto.getBuildType().getFormVariablesSchema()));
this.repository.save(entity); this.repository.save(entity);
return converter.toDto(entity); return converter.toDto(entity);
} }

View File

@ -1,62 +1,24 @@
package com.qqchen.deploy.backend.workflow.dto.definition.node.localVariables; package com.qqchen.deploy.backend.workflow.dto.definition.node.localVariables;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.qqchen.deploy.backend.workflow.annotation.CodeEditorConfig;
import com.qqchen.deploy.backend.workflow.annotation.SchemaProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.util.Map;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class DeployNodeLocalVariables extends BaseNodeLocalVariables { public class DeployNodeLocalVariables extends BaseNodeLocalVariables {
@SchemaProperty(
title = "三方Jenkins系统",
description = "三方Jenkins系统",
required = true
)
private Long externalSystemId; private Long externalSystemId;
@SchemaProperty(
title = "绑定Jenkins视图",
description = "Jenkins视图",
required = true,
order = 3
)
private Long viewId; private Long viewId;
@SchemaProperty(
title = "绑定Jenkins任务",
description = "Jenkins任务",
required = true,
order = 4
)
private Long jobId; private Long jobId;
@SchemaProperty( private Map<String, String> envs;
title = "Pipeline script",
description = "流水线脚本",
required = true,
format = "monaco-editor", // 使用 Monaco Editor
defaultValue = "#!/bin/bash\n\necho \"Hello World\"",
codeEditor = @CodeEditorConfig(
language = "groovy",
theme = "vs-dark",
minimap = false,
lineNumbers = true,
wordWrap = true,
fontSize = 14,
tabSize = 2,
autoComplete = true,
folding = true
),
order = 6
)
private String script; private String script;
} }