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 d6d00c222bce0f0f9908298b2e66d0238213cb2c..a97790e5e9afeb9a5a29066d227a409a227006c6 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 e62233ab433209019dfe82494a6dc0922ce23eaa..23b3310d35b45236c3af19a9f22fad9a9bffe49c 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 2cc504a30f05e5dd574cc1b2a42a66d1a0c04ac9..79bf4706b3f7b8c575f4e35e48c4acc61c366749 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 842a974e3b2b87b91f2180338682960e35be8362..a2ac09edc1f51aa63125482e5c160929229b878a 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 15c9468decc07e83f91a2788c1e2db82f460fe89..7835122d0209d5570c30ec670b9ae791bba600c2 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 415bd2b227368570843743151db605b23aae98fe..ab2d66ef7450390d2610bf2b3a75dd021703b651 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 cb3e65cdfee926204945526971942e2761d6cd40..afed91ba79ecf02fbd787eff39f7aad2b94bf25b 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 9581432a93c3411d4a273eede1fbb3cb4dbcd4b0..765f40c97d821dad177e9f0a76d39fa8ff43aa3a 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,55 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { } } + /** + * 添加全局属性 + * + * @param ciEntityTransactionVo 配置项 + * @param attrAndRelObj 属性信息Obj + * @param needUpdateGlobalAttrList 需要更新的全局属性列表 + */ + void addGlobalAttrEntityData(CiEntityTransactionVo ciEntityTransactionVo, JSONObject attrAndRelObj, List needUpdateGlobalAttrList) { + JSONObject globalAttrEntityData = new JSONObject(); + 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<>(); //实例