diff --git a/src/main/java/neatlogic/module/deploy/api/pipeline/GetPipelineApi.java b/src/main/java/neatlogic/module/deploy/api/pipeline/GetPipelineApi.java index b8bfdbdce31bbe80362eb9ff59e8b33d0ed060e2..d9ca7ef9f60a0df39f26552be8007589e63ff23c 100644 --- a/src/main/java/neatlogic/module/deploy/api/pipeline/GetPipelineApi.java +++ b/src/main/java/neatlogic/module/deploy/api/pipeline/GetPipelineApi.java @@ -17,17 +17,27 @@ package neatlogic.module.deploy.api.pipeline; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.autoexec.dto.AutoexecParamVo; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.deploy.auth.DEPLOY_BASE; +import neatlogic.framework.deploy.dto.app.DeployAppConfigVo; +import neatlogic.framework.deploy.dto.app.DeployPipelineConfigVo; +import neatlogic.framework.deploy.dto.pipeline.PipelineGroupVo; +import neatlogic.framework.deploy.dto.pipeline.PipelineJobTemplateVo; +import neatlogic.framework.deploy.dto.pipeline.PipelineLaneVo; import neatlogic.framework.deploy.dto.pipeline.PipelineVo; import neatlogic.framework.deploy.exception.pipeline.DeployPipelineNotFoundEditTargetException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.deploy.dao.mapper.DeployAppConfigMapper; import neatlogic.module.deploy.dao.mapper.DeployPipelineMapper; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; @Service @AuthAction(action = DEPLOY_BASE.class) @@ -36,6 +46,8 @@ public class GetPipelineApi extends PrivateApiComponentBase { @Resource private DeployPipelineMapper deployPipelineMapper; + @Resource + private DeployAppConfigMapper deployAppConfigMapper; @Override public String getName() { @@ -63,6 +75,43 @@ public class GetPipelineApi extends PrivateApiComponentBase { if (pipelineVo == null) { throw new DeployPipelineNotFoundEditTargetException(id); } + List appConfigList = new ArrayList<>(); + List appSystemIdList = new ArrayList<>(); + List laneList = pipelineVo.getLaneList(); + if (CollectionUtils.isNotEmpty(laneList)) { + for (PipelineLaneVo pipelineLaneVo : laneList) { + List groupList = pipelineLaneVo.getGroupList(); + if (CollectionUtils.isNotEmpty(groupList)) { + for (PipelineGroupVo pipelineGroupVo : groupList) { + List jobTemplateList = pipelineGroupVo.getJobTemplateList(); + if (CollectionUtils.isNotEmpty(jobTemplateList)) { + for (PipelineJobTemplateVo pipelineJobTemplateVo : jobTemplateList) { + Long appSystemId = pipelineJobTemplateVo.getAppSystemId(); + if (appSystemId != null && !appSystemIdList.contains(appSystemId)) { + appSystemIdList.add(appSystemId); + } + } + } + } + } + } + } + if (CollectionUtils.isNotEmpty(appSystemIdList)) { + appConfigList = deployAppConfigMapper.getAppConfigListByAppSystemIdList(appSystemIdList); + if (CollectionUtils.isNotEmpty(appConfigList)) { + for (DeployAppConfigVo deployAppConfigVo : appConfigList) { + DeployPipelineConfigVo newConfig = new DeployPipelineConfigVo(); + List runtimeParamList = new ArrayList<>(); + DeployPipelineConfigVo config = deployAppConfigVo.getConfig(); + if (config != null && CollectionUtils.isNotEmpty(config.getRuntimeParamList())) { + runtimeParamList = config.getRuntimeParamList(); + } + newConfig.setRuntimeParamList(runtimeParamList); + deployAppConfigVo.setConfig(newConfig); + } + } + } + pipelineVo.setAppConfigList(appConfigList); return pipelineVo; } diff --git a/src/main/java/neatlogic/module/deploy/api/pipeline/SavePipelineApi.java b/src/main/java/neatlogic/module/deploy/api/pipeline/SavePipelineApi.java index 38d141fd8b50f6b70419ed9eb56afbaccc237c79..3192588fbcce7c35c02d04b589c5edfb0f513dc3 100644 --- a/src/main/java/neatlogic/module/deploy/api/pipeline/SavePipelineApi.java +++ b/src/main/java/neatlogic/module/deploy/api/pipeline/SavePipelineApi.java @@ -20,28 +20,34 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.core.AuthActionChecker; +import neatlogic.framework.autoexec.dto.AutoexecParamVo; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.deploy.auth.DEPLOY_BASE; import neatlogic.framework.deploy.auth.PIPELINE_MODIFY; import neatlogic.framework.deploy.constvalue.DeployAppConfigAction; import neatlogic.framework.deploy.constvalue.PipelineType; +import neatlogic.framework.deploy.dto.app.DeployAppConfigVo; +import neatlogic.framework.deploy.dto.app.DeployPipelineConfigVo; import neatlogic.framework.deploy.dto.pipeline.*; import neatlogic.framework.deploy.exception.DeployPipelineNotFoundException; import neatlogic.framework.deploy.exception.DeployScheduleNameRepeatException; +import neatlogic.framework.deploy.exception.pipeline.DeployPipelineParamCannotBeEmptyException; import neatlogic.framework.dto.FieldValidResultVo; import neatlogic.framework.exception.type.PermissionDeniedException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.IValid; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.deploy.dao.mapper.DeployAppConfigMapper; import neatlogic.module.deploy.dao.mapper.DeployPipelineMapper; import neatlogic.module.deploy.service.DeployAppAuthorityService; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Objects; +import java.util.*; @Service @Transactional @@ -53,6 +59,9 @@ public class SavePipelineApi extends PrivateApiComponentBase { @Resource private DeployAppAuthorityService deployAppAuthorityService; + @Resource + private DeployAppConfigMapper deployAppConfigMapper; + @Override public String getName() { return "保存超级流水线"; @@ -95,6 +104,7 @@ public class SavePipelineApi extends PrivateApiComponentBase { } else if (Objects.equals(type, PipelineType.APPSYSTEM.getValue())) { deployAppAuthorityService.checkOperationAuth(pipelineVo.getAppSystemId(), DeployAppConfigAction.PIPELINE); } + verifyPipelineConfig(pipelineVo); if (id == null) { pipelineVo.setFcu(UserContext.get().getUserUuid(true)); pipelineMapper.insertPipeline(pipelineVo); @@ -155,4 +165,72 @@ public class SavePipelineApi extends PrivateApiComponentBase { }; } + private void verifyPipelineConfig(PipelineVo pipelineVo) { + List appSystemIdList = new ArrayList<>(); + List laneList = pipelineVo.getLaneList(); + if (CollectionUtils.isNotEmpty(laneList)) { + for (PipelineLaneVo pipelineLaneVo : laneList) { + List groupList = pipelineLaneVo.getGroupList(); + if (CollectionUtils.isNotEmpty(groupList)) { + for (PipelineGroupVo pipelineGroupVo : groupList) { + List jobTemplateList = pipelineGroupVo.getJobTemplateList(); + if (CollectionUtils.isNotEmpty(jobTemplateList)) { + for (PipelineJobTemplateVo pipelineJobTemplateVo : jobTemplateList) { + Long appSystemId = pipelineJobTemplateVo.getAppSystemId(); + if (appSystemId != null && !appSystemIdList.contains(appSystemId)) { + appSystemIdList.add(appSystemId); + } + } + } + } + } + } + } + if (CollectionUtils.isNotEmpty(appSystemIdList)) { + Map> appSystemId2RuntimeParamListMap = new HashMap<>(); + List appConfigList = deployAppConfigMapper.getAppConfigListByAppSystemIdList(appSystemIdList); + for (DeployAppConfigVo deployAppConfigVo : appConfigList) { + DeployPipelineConfigVo config = deployAppConfigVo.getConfig(); + if (config != null && CollectionUtils.isNotEmpty(config.getRuntimeParamList())) { + appSystemId2RuntimeParamListMap.put(deployAppConfigVo.getAppSystemId(), config.getRuntimeParamList()); + } + } + if (CollectionUtils.isNotEmpty(laneList)) { + for (int i = 0; i < laneList.size(); i++) { + PipelineLaneVo laneVo = laneList.get(i); + List groupList = laneVo.getGroupList(); + if (CollectionUtils.isNotEmpty(groupList)) { + for (int j = 0; j < groupList.size(); j++) { + PipelineGroupVo groupVo = groupList.get(j); + List jobTemplateList = groupVo.getJobTemplateList(); + if (CollectionUtils.isNotEmpty(jobTemplateList)) { + for (int k = 0; k < jobTemplateList.size(); k++) { + PipelineJobTemplateVo jobVo = jobTemplateList.get(k); + Long appSystemId = jobVo.getAppSystemId(); + List runtimeParamList = appSystemId2RuntimeParamListMap.get(appSystemId); + if (CollectionUtils.isNotEmpty(runtimeParamList)) { + JSONObject param = null; + JSONObject config = jobVo.getConfig(); + if (MapUtils.isNotEmpty(config)) { + param = config.getJSONObject("param"); + } + if (param == null) { + param = new JSONObject(); + } + for (AutoexecParamVo runtimeParam : runtimeParamList) { + if (Objects.equals(runtimeParam.getIsRequired(), 1)) { + if (!param.containsKey(runtimeParam.getKey())) { + throw new DeployPipelineParamCannotBeEmptyException(i + 1, j + 1, k + 1, runtimeParam.getName(), runtimeParam.getKey()); + } + } + } + } + } + } + } + } + } + } + } + } } diff --git a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java index 5f1f9dbf19f519c065cdc24550d4a4678c1522ff..0d2f920f9ce411431b179a267ac19b8c7a3f6914 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java @@ -96,6 +96,8 @@ public interface DeployAppConfigMapper extends IDeployAppConfigCrossoverMapper { List getAppConfigAppSystemIdListByAppSystemIdList(List list); + List getAppConfigListByAppSystemIdList(List list); + List getAppConfigUserAppSystemIdList(@Param("userUuid") String userUuid, @Param("appSystemIdList") List appSystemIdList); List getAppEnvAutoConfigBySystemIdAndModuleIdAndEnvId(@Param("systemId") Long systemId, @Param("moduleId") Long moduleId, @Param("envId") Long envId); diff --git a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml index a4d6e3ec05b036d57f4d6a31c5eac6da74a36b6b..68c330898a807f6d31e8a8d9e181298a7b8a39b9 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml @@ -1087,6 +1087,28 @@ along with this program. If not, see .--> + +