From 29102904897aa6e690bc094762556d8e41b1f8f8 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 21 Dec 2023 14:55:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E9=80=BB=E8=BE=91=E9=80=82=E9=85=8D=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=B1=9E=E6=80=A7=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1050788313399296]发布环境逻辑适配全局属性环境 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1050788313399296 --- .../SaveDeployAppConfigEnvDBConfigApi.java | 2 +- .../env/SaveDeployAppConfigInstanceApi.java | 4 +- .../SaveDeployAppConfigAppSystemApi.java | 4 +- .../api/job/ListDeployJobModuleApi.java | 8 ++- .../dao/mapper/DeployAppConfigMapper.java | 2 + .../dao/mapper/DeployAppConfigMapper.xml | 8 +++ .../service/DeployAppConfigService.java | 3 +- .../service/DeployAppConfigServiceImpl.java | 61 ++++++++++++++++++- 8 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBConfigApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBConfigApi.java index d6d00c22..a97790e5 100644 --- a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBConfigApi.java +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBConfigApi.java @@ -125,7 +125,7 @@ public class SaveDeployAppConfigEnvDBConfigApi extends PrivateApiComponentBase { CiEntityVo DBCiEntityInfo = ciEntityService.getCiEntityById(DBCiEntityVo.getCiId(), DBCiEntityVo.getId()); CiEntityTransactionVo ciEntityTransactionVo = new CiEntityTransactionVo(DBCiEntityInfo); ciEntityTransactionVo.setAttrEntityData(DBCiEntityInfo.getAttrEntityData()); - deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, DBCiEntityInfo.getCiId(), paramObj, Collections.singletonList("app_environment"), Collections.singletonList("APPComponent")); + deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, DBCiEntityInfo.getCiId(), paramObj, Collections.singletonList("app_environment"), Collections.singletonList("APPComponent"), Collections.singletonList("app_environment")); //保存 ciEntityTransactionVo.setAction(TransactionActionType.UPDATE.getValue()); diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigInstanceApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigInstanceApi.java index e62233ab..23b3310d 100644 --- a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigInstanceApi.java +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigInstanceApi.java @@ -119,7 +119,7 @@ public class SaveDeployAppConfigInstanceApi extends PrivateApiComponentBase { ciEntityTransactionVo.setAttrEntityData(attrEntityData); //添加环境属性、模块关系 - deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, instanceCiEntity.getCiId(), paramObj, Collections.singletonList("app_environment"), Collections.singletonList("APPComponent")); + deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, instanceCiEntity.getCiId(), paramObj, Collections.singletonList("app_environment"), Collections.singletonList("APPComponent"), Collections.singletonList("app_environment")); //设置基础信息 @@ -141,7 +141,7 @@ public class SaveDeployAppConfigInstanceApi extends PrivateApiComponentBase { CiEntityTransactionVo ciEntityTransactionVo = new CiEntityTransactionVo(); //添加环境属性、模块关系 - deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, paramCiVo.getId(), paramObj, Arrays.asList("name", "ip", "port", "maintenance_window", "app_environment"), Collections.singletonList("APPComponent")); + deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, paramCiVo.getId(), paramObj, Arrays.asList("name", "ip", "port", "maintenance_window"), Collections.singletonList("APPComponent"), Collections.singletonList("app_environment")); ciEntityTransactionVo.setEditMode(EditModeType.PARTIAL.getValue()); ciEntityTransactionVo.setAction(TransactionActionType.INSERT.getValue()); diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/system/SaveDeployAppConfigAppSystemApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/system/SaveDeployAppConfigAppSystemApi.java index 2cc504a3..79bf4706 100644 --- a/src/main/java/neatlogic/module/deploy/api/appconfig/system/SaveDeployAppConfigAppSystemApi.java +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/system/SaveDeployAppConfigAppSystemApi.java @@ -136,7 +136,7 @@ public class SaveDeployAppConfigAppSystemApi extends PrivateApiComponentBase { /*新增应用系统(配置项)*/ //1、构建事务vo,并添加属性值 ciEntityTransactionVo = new CiEntityTransactionVo(); - deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, appCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>()); + deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, appCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>(), new ArrayList<>()); //2、设置事务vo信息 ciEntityTransactionVo.setEditMode(EditModeType.PARTIAL.getValue()); @@ -152,7 +152,7 @@ public class SaveDeployAppConfigAppSystemApi extends PrivateApiComponentBase { ciEntityTransactionVo = new CiEntityTransactionVo(systemCiEntityInfo); ciEntityTransactionVo.setAttrEntityData(systemCiEntityInfo.getAttrEntityData()); - deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, appCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>()); + deployAppConfigService.addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, appCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>(), new ArrayList<>()); //2、设置事务vo信息 ciEntityTransactionVo.setAction(TransactionActionType.UPDATE.getValue()); diff --git a/src/main/java/neatlogic/module/deploy/api/job/ListDeployJobModuleApi.java b/src/main/java/neatlogic/module/deploy/api/job/ListDeployJobModuleApi.java index 842a974e..a2ac09ed 100644 --- a/src/main/java/neatlogic/module/deploy/api/job/ListDeployJobModuleApi.java +++ b/src/main/java/neatlogic/module/deploy/api/job/ListDeployJobModuleApi.java @@ -91,9 +91,13 @@ public class ListDeployJobModuleApi extends PrivateApiComponentBase { Long scenarioId = paramObj.getLong("scenarioId"); List moduleResourceList = new ArrayList<>(); IResourceCrossoverMapper resourceCrossoverMapper = CrossoverServiceFactory.getApi(IResourceCrossoverMapper.class); + List moduleIdSet = new ArrayList<>(); List moduleIdList = resourceCrossoverMapper.getAppSystemModuleIdListByAppSystemIdAndAppModuleIdListAndEnvId(paramObj.getLong("appSystemId"),paramObj.getLong("envId"), paramObj.getJSONArray("appModuleIdList")); - if (CollectionUtils.isNotEmpty(moduleIdList)) { - moduleResourceList = resourceCrossoverMapper.getAppModuleListByIdListSimple(moduleIdList, true); + moduleIdSet.addAll(moduleIdList); + moduleIdList = deployAppConfigMapper.getAppModuleIdListByAppSystemIdAndEnvId(paramObj.getLong("appSystemId"),paramObj.getLong("envId")); + moduleIdSet.addAll(moduleIdList); + if (CollectionUtils.isNotEmpty(moduleIdSet)) { + moduleResourceList = resourceCrossoverMapper.getAppModuleListByIdListSimple(new ArrayList<>(moduleIdSet), true); } if (CollectionUtils.isNotEmpty(moduleResourceList)) { //判断是否有配流水线 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 15c9468d..7835122d 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java @@ -210,6 +210,8 @@ public interface DeployAppConfigMapper extends IDeployAppConfigCrossoverMapper { List> getDeployAppConfigListForUpdateConfig(BasePageVo searchVo); + List getAppModuleIdListByAppSystemIdAndEnvId(@Param("appSystemId") Long appSystemId, @Param("envId") Long envId); + void updateDeployAppConfigById(@Param("id") Long id, @Param("configStr") String configStr); void deleteAppConfigSystemFavoriteByAppSystemIdAndUserUuid(@Param("appSystemId") Long appSystemId, @Param("userUuid") String userUuid); 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 415bd2b2..ab2d66ef 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml @@ -1520,6 +1520,14 @@ limitations under the License. LIMIT #{startNum}, #{pageSize} + + UPDATE `deploy_app_config` SET `config` = #{configStr} WHERE `id` = #{id} diff --git a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigService.java b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigService.java index cb3e65cd..afed91ba 100644 --- a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigService.java +++ b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigService.java @@ -30,8 +30,9 @@ public interface DeployAppConfigService { * @param attrAndRelObj 属性关系Obj * @param needUpdateAttrList 需要更新的属性列表 * @param needUpdateRelList 需要更新的关系列表 + * @param needUpdateGlobalAttrList 需要更新的全局属性列表 */ - void addAttrEntityDataAndRelEntityData(CiEntityTransactionVo ciEntityTransactionVo, Long ciId, JSONObject attrAndRelObj, List needUpdateAttrList, List needUpdateRelList); + void addAttrEntityDataAndRelEntityData(CiEntityTransactionVo ciEntityTransactionVo, Long ciId, JSONObject attrAndRelObj, List needUpdateAttrList, List needUpdateRelList, List needUpdateGlobalAttrList); /** * 根据应用模块ID获取runner组 diff --git a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java index 9581432a..5ab82525 100644 --- a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java +++ b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java @@ -5,10 +5,13 @@ import neatlogic.framework.cmdb.dto.ci.AttrVo; import neatlogic.framework.cmdb.dto.ci.CiVo; import neatlogic.framework.cmdb.dto.ci.RelVo; import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; +import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrItemVo; +import neatlogic.framework.cmdb.dto.globalattr.GlobalAttrVo; import neatlogic.framework.cmdb.dto.transaction.CiEntityTransactionVo; import neatlogic.framework.cmdb.enums.EditModeType; import neatlogic.framework.cmdb.enums.TransactionActionType; import neatlogic.framework.cmdb.exception.cientity.CiEntityNotFoundException; +import neatlogic.framework.cmdb.exception.globalattr.GlobalAttrValueIrregularException; import neatlogic.framework.crossover.CrossoverServiceFactory; import neatlogic.framework.deploy.dto.app.DeployAppConfigEnvDBConfigVo; import neatlogic.framework.deploy.dto.app.DeployAppConfigVo; @@ -72,12 +75,14 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { } @Override - public void addAttrEntityDataAndRelEntityData(CiEntityTransactionVo ciEntityTransactionVo, Long ciId, JSONObject attrAndRelObj, List needUpdateAttrList, List needUpdateRelList) { + public void addAttrEntityDataAndRelEntityData(CiEntityTransactionVo ciEntityTransactionVo, Long ciId, JSONObject attrAndRelObj, List needUpdateAttrList, List needUpdateRelList, List needUpdateGlobalAttrList) { //添加属性 addAttrEntityData(ciEntityTransactionVo, attrAndRelObj, needUpdateAttrList, ciId); //添加关系 addRelEntityData(ciEntityTransactionVo, attrAndRelObj, needUpdateRelList, ciId); + // 添加全局属性 + addGlobalAttrEntityData(ciEntityTransactionVo, attrAndRelObj, needUpdateGlobalAttrList); //设置基础信息 ciEntityTransactionVo.setCiId(ciId); ciEntityTransactionVo.setAllowCommit(true); @@ -141,7 +146,7 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { //1、构建事务vo,并添加属性值 paramObj.put("needUpdateRelList", new JSONArray(Collections.singletonList("APP"))); ciEntityTransactionVo = new CiEntityTransactionVo(); - addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, ciCrossoverMapper.getCiByName("APPComponent").getId(), paramObj, Arrays.asList("state", "name", "owner", "abbrName", "maintenance_window", "description"), Collections.singletonList("APP")); + addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, ciCrossoverMapper.getCiByName("APPComponent").getId(), paramObj, Arrays.asList("state", "name", "owner", "abbrName", "maintenance_window", "description"), Collections.singletonList("APP"), new ArrayList<>()); //2、设置事务vo信息 ciEntityTransactionVo.setEditMode(EditModeType.PARTIAL.getValue()); @@ -157,7 +162,7 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { //1、构建事务vo,并添加属性值 ciEntityTransactionVo = new CiEntityTransactionVo(moduleCiEntityInfo); ciEntityTransactionVo.setAttrEntityData(moduleCiEntityInfo.getAttrEntityData()); - addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, moduleCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>()); + addAttrEntityDataAndRelEntityData(ciEntityTransactionVo, moduleCiVo.getId(), paramObj, needUpdateAttrList, new ArrayList<>(), new ArrayList<>()); //2、设置事务vo信息 ciEntityTransactionVo.setAction(TransactionActionType.UPDATE.getValue()); @@ -300,6 +305,56 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { } } + /** + * 添加全局属性 + * + * @param ciEntityTransactionVo 配置项 + * @param attrAndRelObj 属性信息Obj + * @param needUpdateGlobalAttrList 需要更新的全局属性列表 + */ + void addGlobalAttrEntityData(CiEntityTransactionVo ciEntityTransactionVo, JSONObject attrAndRelObj, List needUpdateGlobalAttrList) { + JSONObject globalAttrEntityData = new JSONObject(); +// needUpdateGlobalAttrList.add("app_environment"); + IGlobalAttrCrossoverMapper globalAttrCrossoverMapper = CrossoverServiceFactory.getApi(IGlobalAttrCrossoverMapper.class); + GlobalAttrVo searchVo = new GlobalAttrVo(); + searchVo.setIsActive(1); + List globalAttrList = globalAttrCrossoverMapper.searchGlobalAttr(searchVo); + for (GlobalAttrVo globalAttrVo : globalAttrList) { + if (!needUpdateGlobalAttrList.contains(globalAttrVo.getName())) { + continue; + } + String attrParam = getAttrMap().get(globalAttrVo.getName()); + if (StringUtils.isBlank(attrParam)) { + continue; + } + Long envId = attrAndRelObj.getLong(attrParam); + if (envId == null) { + continue; + } + boolean flag = false; + JSONArray valueList = new JSONArray(); + List itemList = globalAttrVo.getItemList(); + for (GlobalAttrItemVo item : itemList) { + if (Objects.equals(item.getId(), envId)) { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("id", item.getId()); + jsonObj.put("value", item.getValue()); + jsonObj.put("sort", item.getSort()); + jsonObj.put("attrId", globalAttrVo.getId()); + valueList.add(jsonObj); + flag = true; + } + } + if (!flag) { + throw new GlobalAttrValueIrregularException(globalAttrVo, envId.toString()); + } + JSONObject globalAttrEntity = new JSONObject(); + globalAttrEntity.put("valueList", valueList); + globalAttrEntityData.put("global_" + globalAttrVo.getId(), globalAttrEntity); + } + ciEntityTransactionVo.setGlobalAttrEntityData(globalAttrEntityData); + } + public static Map getAttrMap() { Map map = new HashMap<>(); //实例 -- Gitee From 5e34d34ffca8443e3367867b5f9b652bc72f14f0 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Thu, 21 Dec 2023 14:57:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E9=80=BB=E8=BE=91=E9=80=82=E9=85=8D=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E5=B1=9E=E6=80=A7=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1050788313399296]发布环境逻辑适配全局属性环境 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1050788313399296 --- .../module/deploy/service/DeployAppConfigServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java index 5ab82525..765f40c9 100644 --- a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java +++ b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java @@ -314,7 +314,6 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { */ void addGlobalAttrEntityData(CiEntityTransactionVo ciEntityTransactionVo, JSONObject attrAndRelObj, List needUpdateGlobalAttrList) { JSONObject globalAttrEntityData = new JSONObject(); -// needUpdateGlobalAttrList.add("app_environment"); IGlobalAttrCrossoverMapper globalAttrCrossoverMapper = CrossoverServiceFactory.getApi(IGlobalAttrCrossoverMapper.class); GlobalAttrVo searchVo = new GlobalAttrVo(); searchVo.setIsActive(1); -- Gitee