From 2cd4ec573182950966c8f60a02f1b4e0cf2fa0bd Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Tue, 12 Dec 2023 10:03:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-IT?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E8=B7=A8=E7=8E=AF=E5=A2=83=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=86=8D=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1031708374171648]后端-IT服务跨环境导出再导入 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1031708374171648 --- .../combop/AutoexecCombopBasicInfoGetApi.java | 31 +- .../AutoexecCombopBasicInfoSaveApi.java | 43 +-- .../combop/AutoexecCombopDetailGetApi.java | 11 +- .../combop/AutoexecCombopVersionSaveApi.java | 108 +----- .../handler/CombopImportExportHandler.java | 363 ++++++++++++++++++ .../service/AutoexecCombopService.java | 6 + .../service/AutoexecCombopServiceImpl.java | 120 +++++- 7 files changed, 529 insertions(+), 153 deletions(-) create mode 100644 src/main/java/neatlogic/module/autoexec/importexport/handler/CombopImportExportHandler.java diff --git a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoGetApi.java b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoGetApi.java index 0788d096..fbc880ba 100644 --- a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoGetApi.java +++ b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoGetApi.java @@ -16,17 +16,20 @@ limitations under the License. package neatlogic.module.autoexec.api.combop; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.autoexec.auth.AUTOEXEC_BASE; import neatlogic.framework.autoexec.constvalue.ScriptVersionStatus; import neatlogic.framework.autoexec.dao.mapper.AutoexecCombopMapper; import neatlogic.framework.autoexec.dao.mapper.AutoexecTypeMapper; import neatlogic.framework.autoexec.dto.AutoexecTypeVo; -import neatlogic.framework.autoexec.dto.combop.AutoexecCombopAuthorityVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopConfigVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVo; -import neatlogic.framework.autoexec.exception.*; +import neatlogic.framework.autoexec.exception.AutoexecCombopActiveVersionNotFoundException; +import neatlogic.framework.autoexec.exception.AutoexecCombopDraftVersionNotFoundException; +import neatlogic.framework.autoexec.exception.AutoexecCombopRejectedVersionNotFoundException; +import neatlogic.framework.autoexec.exception.AutoexecCombopSubmittedVersionNotFoundException; import neatlogic.framework.autoexec.exception.combop.AutoexecCombopNotFoundEditTargetException; import neatlogic.framework.autoexec.exception.combop.AutoexecCombopVersionNotFoundEditTargetException; import neatlogic.framework.common.constvalue.ApiParamType; @@ -40,13 +43,10 @@ import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.module.autoexec.notify.handler.AutoexecCombopNotifyPolicyHandler; import neatlogic.module.autoexec.service.AutoexecCombopService; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; import java.util.Objects; @Service @@ -98,7 +98,7 @@ public class AutoexecCombopBasicInfoGetApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject jsonObj) throws Exception { Long id = jsonObj.getLong("id"); - AutoexecCombopVo autoexecCombopVo = autoexecCombopMapper.getAutoexecCombopById(id); + AutoexecCombopVo autoexecCombopVo = autoexecCombopService.getAutoexecCombopById(id); if (autoexecCombopVo == null) { throw new AutoexecCombopNotFoundEditTargetException(id); } @@ -111,24 +111,7 @@ public class AutoexecCombopBasicInfoGetApi extends PrivateApiComponentBase { autoexecCombopService.setOperableButtonList(autoexecCombopVo); // owner字段必须在校验权限后,再加上前缀user# autoexecCombopVo.setOwner(GroupSearch.USER.getValuePlugin() + autoexecCombopVo.getOwner()); - List viewAuthorityList = new ArrayList<>(); - List editAuthorityList = new ArrayList<>(); - List executeAuthorityList = new ArrayList<>(); - List authorityList = autoexecCombopMapper.getAutoexecCombopAuthorityListByCombopId(id); - for (AutoexecCombopAuthorityVo authorityVo : authorityList) { - if ("view".equals(authorityVo.getAction())) { - viewAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); - } else if ("edit".equals(authorityVo.getAction())) { - editAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); - } else if ("execute".equals(authorityVo.getAction())) { - executeAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); - } - } - autoexecCombopVo.setViewAuthorityList(viewAuthorityList); - autoexecCombopVo.setEditAuthorityList(editAuthorityList); - autoexecCombopVo.setExecuteAuthorityList(executeAuthorityList); - Long activeVersionId = autoexecCombopVersionMapper.getAutoexecCombopActiveVersionIdByCombopId(id); - autoexecCombopVo.setActiveVersionId(activeVersionId); + Long activeVersionId = autoexecCombopVo.getActiveVersionId(); Long versionId = jsonObj.getLong("versionId"); if (versionId != null) { AutoexecCombopVersionVo versionVo = autoexecCombopVersionMapper.getAutoexecCombopVersionById(versionId); diff --git a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoSaveApi.java b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoSaveApi.java index 85f04c49..95416344 100644 --- a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoSaveApi.java +++ b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopBasicInfoSaveApi.java @@ -16,6 +16,8 @@ limitations under the License. package neatlogic.module.autoexec.api.combop; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.core.AuthActionChecker; @@ -25,7 +27,10 @@ import neatlogic.framework.autoexec.constvalue.CombopOperationType; import neatlogic.framework.autoexec.constvalue.ScriptVersionStatus; import neatlogic.framework.autoexec.dao.mapper.AutoexecCombopMapper; import neatlogic.framework.autoexec.dao.mapper.AutoexecTypeMapper; -import neatlogic.framework.autoexec.dto.combop.*; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopConfigVo; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionConfigVo; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo; +import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVo; import neatlogic.framework.autoexec.exception.AutoexecCombopNameRepeatException; import neatlogic.framework.autoexec.exception.AutoexecCombopNotFoundException; import neatlogic.framework.autoexec.exception.AutoexecTypeNotFoundException; @@ -47,8 +52,6 @@ import neatlogic.framework.util.RegexUtils; import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.module.autoexec.notify.handler.AutoexecCombopNotifyPolicyHandler; import neatlogic.module.autoexec.service.AutoexecCombopService; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -127,20 +130,6 @@ public class AutoexecCombopBasicInfoSaveApi extends PrivateApiComponentBase { autoexecCombopVo.setOperationType(CombopOperationType.COMBOP.getValue()); autoexecCombopVo.setOwner(UserContext.get().getUserUuid(true)); autoexecCombopVo.setIsActive(0); - autoexecCombopVo.setConfigStr(null); - autoexecCombopMapper.insertAutoexecCombop(autoexecCombopVo); - autoexecCombopService.saveDependency(autoexecCombopVo); - autoexecCombopService.saveAuthority(autoexecCombopVo); - // 创建一个新的组合工具的同时创建一个空草稿版本 - AutoexecCombopVersionVo autoexecCombopVersionVo = new AutoexecCombopVersionVo(); - autoexecCombopVersionVo.setCombopId(autoexecCombopVo.getId()); - autoexecCombopVersionVo.setVersion(1); - autoexecCombopVersionVo.setStatus(ScriptVersionStatus.DRAFT.getValue()); - autoexecCombopVersionVo.setIsActive(0); - autoexecCombopVersionVo.setName(autoexecCombopVo.getName()); - autoexecCombopVersionVo.setConfig(new AutoexecCombopVersionConfigVo()); - autoexecCombopVersionVo.setLcu(UserContext.get().getUserUuid()); - autoexecCombopVersionMapper.insertAutoexecCombopVersion(autoexecCombopVersionVo); } else { String owner = autoexecCombopVo.getOwner(); if (owner == null) { @@ -159,14 +148,20 @@ public class AutoexecCombopBasicInfoSaveApi extends PrivateApiComponentBase { if (oldAutoexecCombopVo.getEditable() == 0) { throw new PermissionDeniedException(); } - autoexecCombopService.deleteDependency(oldAutoexecCombopVo); - autoexecCombopVo.setConfigStr(null); - autoexecCombopMapper.updateAutoexecCombopById(autoexecCombopVo); - autoexecCombopService.saveDependency(autoexecCombopVo); - autoexecCombopMapper.deleteAutoexecCombopAuthorityByCombopId(id); - autoexecCombopService.saveAuthority(autoexecCombopVo); } - + autoexecCombopService.saveAutoexecCombop(autoexecCombopVo); + if (id == null) { + // 创建一个新的组合工具的同时创建一个空草稿版本 + AutoexecCombopVersionVo autoexecCombopVersionVo = new AutoexecCombopVersionVo(); + autoexecCombopVersionVo.setCombopId(autoexecCombopVo.getId()); + autoexecCombopVersionVo.setVersion(1); + autoexecCombopVersionVo.setStatus(ScriptVersionStatus.DRAFT.getValue()); + autoexecCombopVersionVo.setIsActive(0); + autoexecCombopVersionVo.setName(autoexecCombopVo.getName()); + autoexecCombopVersionVo.setConfig(new AutoexecCombopVersionConfigVo()); + autoexecCombopVersionVo.setLcu(UserContext.get().getUserUuid()); + autoexecCombopVersionMapper.insertAutoexecCombopVersion(autoexecCombopVersionVo); + } return autoexecCombopVo.getId(); } diff --git a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopDetailGetApi.java b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopDetailGetApi.java index 0d52d351..66eab2e7 100644 --- a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopDetailGetApi.java +++ b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopDetailGetApi.java @@ -72,7 +72,7 @@ public class AutoexecCombopDetailGetApi extends PrivateApiComponentBase { public Object myDoService(JSONObject paramObj) throws Exception { Long id = paramObj.getLong("id"); Long versionId = paramObj.getLong("versionId"); - AutoexecCombopVo autoexecCombopVo = autoexecCombopMapper.getAutoexecCombopById(id); + AutoexecCombopVo autoexecCombopVo = autoexecCombopService.getAutoexecCombopById(id); if (autoexecCombopVo == null) { throw new AutoexecCombopNotFoundEditTargetException(id); } @@ -83,12 +83,9 @@ public class AutoexecCombopDetailGetApi extends PrivateApiComponentBase { autoexecCombopVo.setTypeName(autoexecCombopVo.getTypeId().toString()); } autoexecCombopService.setOperableButtonList(autoexecCombopVo); - Long activeVersionId = autoexecCombopVersionMapper.getAutoexecCombopActiveVersionIdByCombopId(id); - if (activeVersionId != null) { - autoexecCombopVo.setActiveVersionId(activeVersionId); - if (versionId == null) { - versionId = activeVersionId; - } + Long activeVersionId = autoexecCombopVo.getActiveVersionId(); + if (activeVersionId != null && versionId == null) { + versionId = activeVersionId; } if (versionId != null) { AutoexecCombopVersionVo autoexecCombopVersionVo = autoexecCombopService.getAutoexecCombopVersionById(versionId); diff --git a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopVersionSaveApi.java b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopVersionSaveApi.java index cbce0069..40a6aa50 100644 --- a/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopVersionSaveApi.java +++ b/src/main/java/neatlogic/module/autoexec/api/combop/AutoexecCombopVersionSaveApi.java @@ -16,6 +16,7 @@ limitations under the License. package neatlogic.module.autoexec.api.combop; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.core.AuthActionChecker; @@ -23,29 +24,27 @@ import neatlogic.framework.autoexec.auth.AUTOEXEC_BASE; import neatlogic.framework.autoexec.auth.AUTOEXEC_COMBOP_ADD; import neatlogic.framework.autoexec.constvalue.ScriptVersionStatus; import neatlogic.framework.autoexec.dao.mapper.AutoexecCombopMapper; -import neatlogic.framework.config.ConfigManager; -import neatlogic.framework.autoexec.constvalue.AutoexecTenantConfig; -import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopPhaseVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionConfigVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVersionVo; import neatlogic.framework.autoexec.dto.combop.AutoexecCombopVo; -import neatlogic.framework.autoexec.exception.*; +import neatlogic.framework.autoexec.exception.AutoexecCombopHasSubmittedVersionException; +import neatlogic.framework.autoexec.exception.AutoexecCombopNotFoundException; +import neatlogic.framework.autoexec.exception.AutoexecCombopPhaseNameRepeatException; +import neatlogic.framework.autoexec.exception.AutoexecCombopVersionNotFoundException; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.exception.type.PermissionDeniedException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.util.RegexUtils; +import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.module.autoexec.service.AutoexecCombopService; -import com.alibaba.fastjson.JSONObject; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -93,10 +92,6 @@ public class AutoexecCombopVersionSaveApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject jsonObj) throws Exception { AutoexecCombopVersionVo autoexecCombopVersionVo = jsonObj.toJavaObject(AutoexecCombopVersionVo.class); - -// if (autoexecCombopVersionMapper.checkAutoexecCombopVersionNameIsRepeat(autoexecCombopVersionVo) != null) { -// throw new AutoexecCombopVersionNameRepeatException(autoexecCombopVersionVo.getName()); -// } AutoexecCombopVo autoexecCombopVo = autoexecCombopMapper.getAutoexecCombopById(autoexecCombopVersionVo.getCombopId()); if (autoexecCombopVo == null) { throw new AutoexecCombopNotFoundException(autoexecCombopVersionVo.getCombopId()); @@ -116,84 +111,23 @@ public class AutoexecCombopVersionSaveApi extends PrivateApiComponentBase { if (!AuthActionChecker.checkByUserUuid(UserContext.get().getUserUuid(true), AUTOEXEC_COMBOP_ADD.class.getSimpleName())) { throw new PermissionDeniedException(AUTOEXEC_COMBOP_ADD.class); } - AutoexecCombopVersionConfigVo config = autoexecCombopVersionVo.getConfig(); - String configStr = JSONObject.toJSONString(config); - /** 保存前,校验组合工具是否配置正确,不正确不可以保存 **/ - autoexecCombopService.verifyAutoexecCombopVersionConfig(config, false); - autoexecCombopVersionVo.setConfigStr(configStr); - config = autoexecCombopVersionVo.getConfig(); - autoexecCombopService.resetIdAutoexecCombopVersionConfig(config); - autoexecCombopService.setAutoexecCombopPhaseGroupId(config); - autoexecCombopService.passwordParamEncrypt(config); - autoexecCombopVersionVo.setConfigStr(null); - Integer version = autoexecCombopVersionMapper.getAutoexecCombopMaxVersionByCombopId(autoexecCombopVersionVo.getCombopId()); - if (version == null) { - version = 1; - } else { - version++; - } - autoexecCombopVersionVo.setVersion(version); - autoexecCombopVersionVo.setIsActive(0); - autoexecCombopVersionMapper.insertAutoexecCombopVersion(autoexecCombopVersionVo); - autoexecCombopService.saveDependency(autoexecCombopVersionVo); - Integer maxNum = null; - String maxNumOfCombopVersion = ConfigManager.getConfig(AutoexecTenantConfig.MAX_NUM_OF_COMBOP_VERSION); - if (StringUtils.isNotBlank(maxNumOfCombopVersion)) { - try { - maxNum = Integer.parseInt(maxNumOfCombopVersion); - } catch (NumberFormatException e) { - - } - } - List versionList = autoexecCombopVersionMapper.getAutoexecCombopVersionListByCombopId(autoexecCombopVersionVo.getCombopId()); - if (versionList.size() > maxNum) { - // 需要删除个数 - int deleteCount = versionList.size() - maxNum; - // 根据版本id升序排序 - versionList.sort(Comparator.comparing(AutoexecCombopVersionVo::getId)); - // 遍历版本列表,删除最旧的非激活版本 - for (AutoexecCombopVersionVo versionVo : versionList) { - if (Objects.equals(versionVo.getIsActive(), 1)) { - continue; - } - autoexecCombopVersionMapper.deleteAutoexecCombopVersionById(versionVo.getId()); - autoexecCombopService.deleteDependency(versionVo); - deleteCount--; - if (deleteCount == 0) { - break; - } - } - } } else { AutoexecCombopVersionVo oldAutoexecCombopVersionVo = autoexecCombopVersionMapper.getAutoexecCombopVersionById(id); if (oldAutoexecCombopVersionVo == null) { throw new AutoexecCombopVersionNotFoundException(id); } - AutoexecCombopVersionConfigVo config = autoexecCombopVersionVo.getConfig(); - List combopPhaseList = config.getCombopPhaseList(); - List nameList = new ArrayList<>(); - for (AutoexecCombopPhaseVo autoexecCombopPhaseVo : combopPhaseList) { - String name = autoexecCombopPhaseVo.getName(); - if (nameList.contains(name)) { - throw new AutoexecCombopPhaseNameRepeatException(name); - } - nameList.add(name); + } + AutoexecCombopVersionConfigVo config = autoexecCombopVersionVo.getConfig(); + List combopPhaseList = config.getCombopPhaseList(); + List nameList = new ArrayList<>(); + for (AutoexecCombopPhaseVo autoexecCombopPhaseVo : combopPhaseList) { + String name = autoexecCombopPhaseVo.getName(); + if (nameList.contains(name)) { + throw new AutoexecCombopPhaseNameRepeatException(name); } - - autoexecCombopService.updateAutoexecCombopExecuteConfigProtocolAndProtocolPort(config); - String configStr = JSONObject.toJSONString(config); - /** 保存前,校验组合工具是否配置正确,不正确不可以保存 **/ - autoexecCombopService.verifyAutoexecCombopVersionConfig(config, false); - autoexecCombopVersionVo.setConfigStr(configStr); - autoexecCombopService.deleteDependency(oldAutoexecCombopVersionVo); - config = autoexecCombopVersionVo.getConfig(); - autoexecCombopService.setAutoexecCombopPhaseGroupId(config); - autoexecCombopService.passwordParamEncrypt(config); -// autoexecCombopService.prepareAutoexecCombopVersionConfig(autoexecCombopVersionVo.getConfig(), false); - autoexecCombopVersionVo.setConfigStr(null); - autoexecCombopVersionMapper.updateAutoexecCombopVersionById(autoexecCombopVersionVo); - autoexecCombopService.saveDependency(autoexecCombopVersionVo); + nameList.add(name); } + autoexecCombopService.saveAutoexecCombopVersion(autoexecCombopVersionVo); JSONObject resultObj = new JSONObject(); resultObj.put("id", autoexecCombopVersionVo.getId()); if (Objects.equals(autoexecCombopVersionVo.getStatus(), ScriptVersionStatus.SUBMITTED.getValue())) { @@ -202,14 +136,4 @@ public class AutoexecCombopVersionSaveApi extends PrivateApiComponentBase { return resultObj; } -// public IValid name() { -// return jsonObj -> { -// AutoexecCombopVersionVo autoexecCombopVersionVo = JSON.toJavaObject(jsonObj, AutoexecCombopVersionVo.class); -// if (autoexecCombopVersionMapper.checkAutoexecCombopVersionNameIsRepeat(autoexecCombopVersionVo) != null) { -// return new FieldValidResultVo(new AutoexecCombopVersionNameRepeatException(autoexecCombopVersionVo.getName())); -// } -// return new FieldValidResultVo(); -// }; -// } - } diff --git a/src/main/java/neatlogic/module/autoexec/importexport/handler/CombopImportExportHandler.java b/src/main/java/neatlogic/module/autoexec/importexport/handler/CombopImportExportHandler.java new file mode 100644 index 00000000..8cbe07cb --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/importexport/handler/CombopImportExportHandler.java @@ -0,0 +1,363 @@ +package neatlogic.module.autoexec.importexport.handler; + +import neatlogic.framework.asynchronization.threadlocal.UserContext; +import neatlogic.framework.autoexec.constvalue.*; +import neatlogic.framework.autoexec.dao.mapper.AutoexecCombopMapper; +import neatlogic.framework.autoexec.dto.AutoexecParamConfigVo; +import neatlogic.framework.autoexec.dto.AutoexecParamVo; +import neatlogic.framework.autoexec.dto.combop.*; +import neatlogic.framework.autoexec.exception.AutoexecCombopActiveVersionNotFoundException; +import neatlogic.framework.autoexec.exception.AutoexecCombopNotFoundException; +import neatlogic.framework.cmdb.enums.CmdbImportExportHandlerType; +import neatlogic.framework.importexport.constvalue.FrameworkImportExportHandlerType; +import neatlogic.framework.importexport.core.ImportExportHandlerBase; +import neatlogic.framework.importexport.core.ImportExportHandlerType; +import neatlogic.framework.importexport.dto.ImportExportBaseInfoVo; +import neatlogic.framework.importexport.dto.ImportExportPrimaryChangeVo; +import neatlogic.framework.importexport.dto.ImportExportVo; +import neatlogic.framework.notify.dto.InvokeNotifyPolicyConfigVo; +import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; +import neatlogic.module.autoexec.service.AutoexecCombopService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.zip.ZipOutputStream; + +@Component +public class CombopImportExportHandler extends ImportExportHandlerBase { + + @Resource + private AutoexecCombopService autoexecCombopService; + + @Resource + private AutoexecCombopMapper autoexecCombopMapper; + + @Resource + private AutoexecCombopVersionMapper autoexecCombopVersionMapper; + + @Override + public ImportExportHandlerType getType() { + return FrameworkImportExportHandlerType.AUTOEXEC_COMBOP; + } + + @Override + public boolean checkImportAuth(ImportExportVo importExportVo) { + return true; + } + + @Override + public boolean checkExportAuth(Object primaryKey) { + return true; + } + + @Override + public boolean checkIsExists(ImportExportBaseInfoVo importExportBaseInfoVo) { + return autoexecCombopMapper.getAutoexecCombopByName(importExportBaseInfoVo.getName()) != null; + } + + @Override + public Object getPrimaryByName(ImportExportVo importExportVo) { + AutoexecCombopVo autoexecCombop = autoexecCombopMapper.getAutoexecCombopByName(importExportVo.getName()); + if (autoexecCombop == null) { + throw new AutoexecCombopNotFoundException(importExportVo.getName()); + } + return autoexecCombop.getId(); + } + + @Override + public Object importData(ImportExportVo importExportVo, List primaryChangeList) { + AutoexecCombopVo autoexecCombop = importExportVo.getData().toJavaObject(AutoexecCombopVo.class); + AutoexecCombopVo oldAutoexecCombop = autoexecCombopMapper.getAutoexecCombopByName(importExportVo.getName()); + if (oldAutoexecCombop != null) { + autoexecCombop.setId(oldAutoexecCombop.getId()); + } else { + if (autoexecCombopMapper.checkAutoexecCombopIsExists(autoexecCombop.getId()) > 0) { + autoexecCombop.setId(null); + } + } + importHandle(autoexecCombop, primaryChangeList); + autoexecCombopService.saveAutoexecCombop(autoexecCombop); + AutoexecCombopVersionVo version = autoexecCombop.getVersionList().get(0); + version.setCombopId(autoexecCombop.getId()); + autoexecCombopService.saveAutoexecCombopVersion(version); + autoexecCombopVersionMapper.disableAutoexecCombopVersionByCombopId(version.getCombopId()); + autoexecCombopVersionMapper.enableAutoexecCombopVersionById(version.getId()); + version.setStatus(ScriptVersionStatus.PASSED.getValue()); + version.setReviewer(UserContext.get().getUserUuid()); + autoexecCombopVersionMapper.updateAutoexecCombopVersionStatusById(version); + return autoexecCombop.getId(); + } + + @Override + protected ImportExportVo myExportData(Object primaryKey, List dependencyList, ZipOutputStream zipOutputStream) { + Long id = (Long) primaryKey; + AutoexecCombopVo autoexecCombop = autoexecCombopService.getAutoexecCombopById(id); + if (autoexecCombop == null) { + throw new AutoexecCombopNotFoundException(id); + } + if (autoexecCombop.getActiveVersionId() == null) { + throw new AutoexecCombopActiveVersionNotFoundException(autoexecCombop.getName()); + } + AutoexecCombopVersionVo version = autoexecCombopVersionMapper.getAutoexecCombopVersionById(autoexecCombop.getActiveVersionId()); + List versionList = new ArrayList<>(); + versionList.add(version); + autoexecCombop.setVersionList(versionList); + exportHandle(autoexecCombop, dependencyList, zipOutputStream); + ImportExportVo importExportVo = new ImportExportVo(this.getType().getValue(), primaryKey, autoexecCombop.getName()); + importExportVo.setDataWithObject(autoexecCombop); + return importExportVo; + } + + private void importHandle(AutoexecCombopVo autoexecCombop, List primaryChangeList) { + handleDependency(IMPORT, autoexecCombop, null, null, primaryChangeList); + } + + private void exportHandle(AutoexecCombopVo autoexecCombop, List dependencyList, ZipOutputStream zipOutputStream) { + handleDependency(EXPORT, autoexecCombop, dependencyList, zipOutputStream, null); + } + + private void handleDependency(String action, AutoexecCombopVo autoexecCombop, List dependencyList, ZipOutputStream zipOutputStream, List primaryChangeList) { + if (autoexecCombop.getTypeId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_TYPE, autoexecCombop.getTypeId(), primaryChangeList); + if (newPrimaryKey != null) { + autoexecCombop.setTypeId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_TYPE, autoexecCombop.getTypeId(), dependencyList, zipOutputStream); + } + } + AutoexecCombopConfigVo combopConfig = autoexecCombop.getConfig(); + if (combopConfig != null) { + InvokeNotifyPolicyConfigVo invokeNotifyPolicyConfig = combopConfig.getInvokeNotifyPolicyConfig(); + if (invokeNotifyPolicyConfig != null && invokeNotifyPolicyConfig.getIsCustom() == 1 && invokeNotifyPolicyConfig.getPolicyId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(FrameworkImportExportHandlerType.NOTIFY_POLICY, invokeNotifyPolicyConfig.getPolicyId(), primaryChangeList); + if (newPrimaryKey != null) { + autoexecCombop.setTypeId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(FrameworkImportExportHandlerType.NOTIFY_POLICY, invokeNotifyPolicyConfig.getPolicyId(), dependencyList, zipOutputStream); + } + } + } + AutoexecCombopVersionVo version = autoexecCombop.getVersionList().get(0); + AutoexecCombopVersionConfigVo config = version.getConfig(); + if (config != null) { + // 阶段 + List combopPhaseList = config.getCombopPhaseList(); + if (CollectionUtils.isNotEmpty(combopPhaseList)) { + for (AutoexecCombopPhaseVo combopPhase : combopPhaseList) { + handleCombopPhase(action, combopPhase, dependencyList, zipOutputStream, primaryChangeList); + } + } + // 阶段组 + List combopGroupList = config.getCombopGroupList(); + if (CollectionUtils.isNotEmpty(combopGroupList)) { + for (AutoexecCombopGroupVo combopGroup : combopGroupList) { + handleCombopGroup(action, combopGroup, dependencyList, zipOutputStream, primaryChangeList); + } + } + // 执行账户 + if (config.getExecuteConfig() != null && config.getExecuteConfig().getProtocolId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(CmdbImportExportHandlerType.PROTOCOL, config.getExecuteConfig().getProtocolId(), primaryChangeList); + if (newPrimaryKey != null) { + config.getExecuteConfig().setProtocolId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(CmdbImportExportHandlerType.PROTOCOL, config.getExecuteConfig().getProtocolId(), dependencyList, zipOutputStream); + } + } + // 场景 + List scenarioList = config.getScenarioList(); + if (CollectionUtils.isNotEmpty(scenarioList)) { + for (AutoexecCombopScenarioVo combopScenario : scenarioList) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_SCENARIO, combopScenario.getScenarioId(), primaryChangeList); + if (newPrimaryKey != null) { + combopScenario.setScenarioId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_SCENARIO, combopScenario.getScenarioId(), dependencyList, zipOutputStream); + } + } + if (config.getDefaultScenarioId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_SCENARIO, config.getDefaultScenarioId(), primaryChangeList); + if (newPrimaryKey != null) { + config.setDefaultScenarioId((Long) newPrimaryKey); + } + } + } + } + // 作业参数 + List paramList = config.getRuntimeParamList(); + if (CollectionUtils.isNotEmpty(paramList)) { + List paramTypeList = new ArrayList<>(); + paramTypeList.add(ParamType.SELECT.getValue()); + paramTypeList.add(ParamType.MULTISELECT.getValue()); + paramTypeList.add(ParamType.RADIO.getValue()); + paramTypeList.add(ParamType.CHECKBOX.getValue()); + for (AutoexecParamVo param : paramList) { + if (!paramTypeList.contains(param.getType())) { + continue; + } + AutoexecParamConfigVo paramConfig = param.getConfig(); + if (paramConfig == null) { + continue; + } + if (!Objects.equals(paramConfig.getDataSource(), "matrix")) { + continue; + } + if (paramConfig.getMatrixUuid() == null) { + continue; + } + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(FrameworkImportExportHandlerType.MATRIX, paramConfig.getMatrixUuid(), primaryChangeList); + if (newPrimaryKey != null) { + paramConfig.setMatrixUuid((String) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(FrameworkImportExportHandlerType.MATRIX, paramConfig.getMatrixUuid(), dependencyList, zipOutputStream); + } + } + } + } + } + + private void handleCombopGroup(String action, AutoexecCombopGroupVo combopGroup, List dependencyList, ZipOutputStream zipOutputStream, List primaryChangeList) { + if (Objects.equals(combopGroup.getPolicy(), AutoexecJobGroupPolicy.ONESHOT.getName())) { + return; + } + AutoexecCombopGroupConfigVo config = combopGroup.getConfig(); + if (config == null) { + return; + } + AutoexecCombopExecuteConfigVo executeConfig = config.getExecuteConfig(); + if (executeConfig == null) { + return; + } + if (!Objects.equals(executeConfig.getIsPresetExecuteConfig(), 1)) { + return; + } + if (executeConfig.getProtocolId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(CmdbImportExportHandlerType.PROTOCOL, executeConfig.getProtocolId(), primaryChangeList); + if (newPrimaryKey != null) { + executeConfig.setProtocolId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(CmdbImportExportHandlerType.PROTOCOL, executeConfig.getProtocolId(), dependencyList, zipOutputStream); + } + } + } + + private void handleCombopPhase(String action, AutoexecCombopPhaseVo combopPhase, List dependencyList, ZipOutputStream zipOutputStream, List primaryChangeList) { + AutoexecCombopPhaseConfigVo config = combopPhase.getConfig(); + if (config == null) { + return; + } + // 执行目标配置 + AutoexecCombopExecuteConfigVo executeConfig = config.getExecuteConfig(); + if (executeConfig != null) { + if (Objects.equals(executeConfig.getIsPresetExecuteConfig(), 1)) { + if (executeConfig.getProtocolId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(CmdbImportExportHandlerType.PROTOCOL, executeConfig.getProtocolId(), primaryChangeList); + if (newPrimaryKey != null) { + executeConfig.setProtocolId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(CmdbImportExportHandlerType.PROTOCOL, executeConfig.getProtocolId(), dependencyList, zipOutputStream); + } + } + } + } + List phaseOperationList = config.getPhaseOperationList(); + for (AutoexecCombopPhaseOperationVo phaseOperationVo : phaseOperationList) { + handlerCombopPhaseOperation(action, phaseOperationVo, dependencyList, zipOutputStream, primaryChangeList); + } + } + + private void handlerCombopPhaseOperation(String action, AutoexecCombopPhaseOperationVo phaseOperationVo, List dependencyList, ZipOutputStream zipOutputStream, List primaryChangeList) { + if (Objects.equals(phaseOperationVo.getOperationType(), ToolType.SCRIPT.getValue())) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_SCRIPT, phaseOperationVo.getOperationId(), primaryChangeList); + if (newPrimaryKey != null) { + phaseOperationVo.setOperationId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_SCRIPT, phaseOperationVo.getOperationId(), dependencyList, zipOutputStream); + } + } else if (Objects.equals(phaseOperationVo.getOperationType(), ToolType.TOOL.getValue())) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_TOOL, phaseOperationVo.getOperationId(), primaryChangeList); + if (newPrimaryKey != null) { + phaseOperationVo.setOperationId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_TOOL, phaseOperationVo.getOperationId(), dependencyList, zipOutputStream); + } + } + AutoexecCombopPhaseOperationConfigVo phaseOperationConfig = phaseOperationVo.getConfig(); + if (phaseOperationConfig == null) { + if (phaseOperationConfig.getProfileId() != null) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_PROFILE, phaseOperationConfig.getProfileId(), primaryChangeList); + if (newPrimaryKey != null) { + phaseOperationConfig.setProfileId((Long) newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_PROFILE, phaseOperationConfig.getProfileId(), dependencyList, zipOutputStream); + } + } + List paramMappingList = phaseOperationConfig.getParamMappingList(); + if (CollectionUtils.isNotEmpty(paramMappingList)) { + for (ParamMappingVo paramMappingVo : paramMappingList) { + if (Objects.equals(paramMappingVo.getMappingMode(), ParamMappingMode.GLOBAL_PARAM.getValue())) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_GLOBAL_PARAM, paramMappingVo.getValue(), primaryChangeList); + if (newPrimaryKey != null) { + paramMappingVo.setValue(newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_GLOBAL_PARAM, paramMappingVo.getValue(), dependencyList, zipOutputStream); + } + } + } + } + List argumentMappingList = phaseOperationConfig.getArgumentMappingList(); + if (CollectionUtils.isNotEmpty(argumentMappingList)) { + for (ParamMappingVo paramMappingVo : argumentMappingList) { + if (Objects.equals(paramMappingVo.getMappingMode(), ParamMappingMode.GLOBAL_PARAM.getValue())) { + if (action == IMPORT) { + Object newPrimaryKey = getNewPrimaryKey(AutoexecImportExportHandlerType.AUTOEXEC_GLOBAL_PARAM, paramMappingVo.getValue(), primaryChangeList); + if (newPrimaryKey != null) { + paramMappingVo.setValue(newPrimaryKey); + } + } else if (action == EXPORT) { + doExportData(AutoexecImportExportHandlerType.AUTOEXEC_GLOBAL_PARAM, paramMappingVo.getValue(), dependencyList, zipOutputStream); + } + } + } + } + List ifList = phaseOperationConfig.getIfList(); + if (CollectionUtils.isNotEmpty(ifList)) { + for (AutoexecCombopPhaseOperationVo ifPhaseOperationVo : ifList) { + handlerCombopPhaseOperation(action, ifPhaseOperationVo, dependencyList, zipOutputStream, primaryChangeList); + } + } + List elseList = phaseOperationConfig.getElseList(); + if (CollectionUtils.isNotEmpty(elseList)) { + for (AutoexecCombopPhaseOperationVo elsePhaseOperationVo : elseList) { + handlerCombopPhaseOperation(action, elsePhaseOperationVo, dependencyList, zipOutputStream, primaryChangeList); + } + } + } + } +} diff --git a/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopService.java b/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopService.java index b9504445..2a8b1841 100644 --- a/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopService.java +++ b/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopService.java @@ -167,4 +167,10 @@ public interface AutoexecCombopService { * @param config */ void passwordParamEncrypt(AutoexecCombopVersionConfigVo config); + + AutoexecCombopVo getAutoexecCombopById(Long id); + + void saveAutoexecCombop(AutoexecCombopVo autoexecCombopVo); + + void saveAutoexecCombopVersion(AutoexecCombopVersionVo autoexecCombopVersionVo); } diff --git a/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopServiceImpl.java b/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopServiceImpl.java index aeb36b0f..7e97d77b 100644 --- a/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopServiceImpl.java +++ b/src/main/java/neatlogic/module/autoexec/service/AutoexecCombopServiceImpl.java @@ -42,15 +42,13 @@ import neatlogic.framework.common.constvalue.GroupSearch; import neatlogic.framework.common.constvalue.SystemUser; import neatlogic.framework.common.constvalue.UserType; import neatlogic.framework.common.util.RC4Util; +import neatlogic.framework.config.ConfigManager; import neatlogic.framework.crossover.CrossoverServiceFactory; import neatlogic.framework.dao.mapper.RoleMapper; import neatlogic.framework.dao.mapper.TeamMapper; import neatlogic.framework.dao.mapper.UserMapper; import neatlogic.framework.dependency.core.DependencyManager; import neatlogic.framework.dto.AuthenticationInfoVo; -import neatlogic.framework.exception.role.RoleNotFoundException; -import neatlogic.framework.exception.team.TeamNotFoundException; -import neatlogic.framework.exception.user.UserNotFoundException; import neatlogic.framework.notify.dto.InvokeNotifyPolicyConfigVo; import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.module.autoexec.dao.mapper.AutoexecGlobalParamMapper; @@ -1449,15 +1447,18 @@ public class AutoexecCombopServiceImpl implements AutoexecCombopService, IAutoex String[] split = authority.split("#"); if (GroupSearch.USER.getValue().equals(split[0])) { if (userMapper.checkUserIsExists(split[1]) == 0) { - throw new UserNotFoundException(split[1]); +// throw new UserNotFoundException(split[1]); + return null; } } else if (GroupSearch.TEAM.getValue().equals(split[0])) { if (teamMapper.checkTeamIsExists(split[1]) == 0) { - throw new TeamNotFoundException(split[1]); +// throw new TeamNotFoundException(split[1]); + return null; } } else if (GroupSearch.ROLE.getValue().equals(split[0])) { if (roleMapper.checkRoleIsExists(split[1]) == 0) { - throw new RoleNotFoundException(split[1]); +// throw new RoleNotFoundException(split[1]); + return null; } } else if (GroupSearch.COMMON.getValue().equals(split[0])) { if (!UserType.ALL.getValue().equals(split[1])) { @@ -1574,4 +1575,111 @@ public class AutoexecCombopServiceImpl implements AutoexecCombopService, IAutoex } } } + + @Override + public AutoexecCombopVo getAutoexecCombopById(Long id) { + AutoexecCombopVo autoexecCombopVo = autoexecCombopMapper.getAutoexecCombopById(id); + if (autoexecCombopVo == null) { + return null; + } + List viewAuthorityList = new ArrayList<>(); + List editAuthorityList = new ArrayList<>(); + List executeAuthorityList = new ArrayList<>(); + List authorityList = autoexecCombopMapper.getAutoexecCombopAuthorityListByCombopId(id); + for (AutoexecCombopAuthorityVo authorityVo : authorityList) { + if ("view".equals(authorityVo.getAction())) { + viewAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); + } else if ("edit".equals(authorityVo.getAction())) { + editAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); + } else if ("execute".equals(authorityVo.getAction())) { + executeAuthorityList.add(authorityVo.getType() + "#" + authorityVo.getUuid()); + } + } + autoexecCombopVo.setViewAuthorityList(viewAuthorityList); + autoexecCombopVo.setEditAuthorityList(editAuthorityList); + autoexecCombopVo.setExecuteAuthorityList(executeAuthorityList); + Long activeVersionId = autoexecCombopVersionMapper.getAutoexecCombopActiveVersionIdByCombopId(id); + autoexecCombopVo.setActiveVersionId(activeVersionId); + return autoexecCombopVo; + } + + @Override + public void saveAutoexecCombop(AutoexecCombopVo autoexecCombopVo) { + Long id = autoexecCombopVo.getId(); + AutoexecCombopVo oldAutoexecCombop = autoexecCombopMapper.getAutoexecCombopById(id); + if (oldAutoexecCombop == null) { + autoexecCombopVo.setConfigStr(null); + autoexecCombopMapper.insertAutoexecCombop(autoexecCombopVo); + saveDependency(autoexecCombopVo); + saveAuthority(autoexecCombopVo); + } else { + deleteDependency(oldAutoexecCombop); + autoexecCombopVo.setConfigStr(null); + autoexecCombopMapper.updateAutoexecCombopById(autoexecCombopVo); + saveDependency(autoexecCombopVo); + autoexecCombopMapper.deleteAutoexecCombopAuthorityByCombopId(id); + saveAuthority(autoexecCombopVo); + } + } + + @Override + public void saveAutoexecCombopVersion(AutoexecCombopVersionVo autoexecCombopVersionVo) { + AutoexecCombopVersionVo oldAutoexecCombopVersion = autoexecCombopVersionMapper.getAutoexecCombopVersionById(autoexecCombopVersionVo.getId()); + AutoexecCombopVersionConfigVo config = autoexecCombopVersionVo.getConfig(); + String configStr = JSONObject.toJSONString(config); + /** 保存前,校验组合工具是否配置正确,不正确不可以保存 **/ + verifyAutoexecCombopVersionConfig(config, false); + autoexecCombopVersionVo.setConfigStr(configStr); + config = autoexecCombopVersionVo.getConfig(); + passwordParamEncrypt(config); + updateAutoexecCombopExecuteConfigProtocolAndProtocolPort(config); + if (oldAutoexecCombopVersion == null) { + resetIdAutoexecCombopVersionConfig(config); + setAutoexecCombopPhaseGroupId(config); + autoexecCombopVersionVo.setConfigStr(null); + Integer version = autoexecCombopVersionMapper.getAutoexecCombopMaxVersionByCombopId(autoexecCombopVersionVo.getCombopId()); + if (version == null) { + version = 1; + } else { + version++; + } + autoexecCombopVersionVo.setVersion(version); + autoexecCombopVersionVo.setIsActive(0); + autoexecCombopVersionMapper.insertAutoexecCombopVersion(autoexecCombopVersionVo); + Integer maxNum = null; + String maxNumOfCombopVersion = ConfigManager.getConfig(AutoexecTenantConfig.MAX_NUM_OF_COMBOP_VERSION); + if (StringUtils.isNotBlank(maxNumOfCombopVersion)) { + try { + maxNum = Integer.parseInt(maxNumOfCombopVersion); + } catch (NumberFormatException e) { + + } + } + List versionList = autoexecCombopVersionMapper.getAutoexecCombopVersionListByCombopId(autoexecCombopVersionVo.getCombopId()); + if (versionList.size() > maxNum) { + // 需要删除个数 + int deleteCount = versionList.size() - maxNum; + // 根据版本id升序排序 + versionList.sort(Comparator.comparing(AutoexecCombopVersionVo::getId)); + // 遍历版本列表,删除最旧的非激活版本 + for (AutoexecCombopVersionVo versionVo : versionList) { + if (Objects.equals(versionVo.getIsActive(), 1)) { + continue; + } + autoexecCombopVersionMapper.deleteAutoexecCombopVersionById(versionVo.getId()); + deleteDependency(versionVo); + deleteCount--; + if (deleteCount == 0) { + break; + } + } + } + } else { + deleteDependency(oldAutoexecCombopVersion); + setAutoexecCombopPhaseGroupId(config); + autoexecCombopVersionVo.setConfigStr(null); + autoexecCombopVersionMapper.updateAutoexecCombopVersionById(autoexecCombopVersionVo); + } + saveDependency(autoexecCombopVersionVo); + } } -- Gitee