From 4d3da3b7201b009401763b69d4f333a15a9b0321 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 14 May 2025 18:04:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=90=8E=E7=AB=AF-DB?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=B0=E5=A2=9E=E5=BF=AB=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=8D=B7=E5=BD=95=E5=85=A5=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1421105015783424]后端-DB配置新增快发布捷录入入口 http://192.168.0.96:8090/demo/rdm.html#/task-detail/939050947543040/939050947543050/1421105015783424 --- .../SaveDeployAppConfigEnvCiEntityApi.java | 181 ++++++++++++++++++ .../service/DeployAppConfigServiceImpl.java | 4 + 2 files changed, 185 insertions(+) create mode 100644 src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvCiEntityApi.java diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvCiEntityApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvCiEntityApi.java new file mode 100644 index 00000000..b9da21ac --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvCiEntityApi.java @@ -0,0 +1,181 @@ +package neatlogic.module.deploy.api.appconfig.env; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.crossover.ICiCrossoverMapper; +import neatlogic.framework.cmdb.crossover.ICiEntityCrossoverMapper; +import neatlogic.framework.cmdb.crossover.ICiEntityCrossoverService; +import neatlogic.framework.cmdb.crossover.IResourceCrossoverMapper; +import neatlogic.framework.cmdb.dto.ci.CiVo; +import neatlogic.framework.cmdb.dto.cientity.CiEntityVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.dto.transaction.CiEntityTransactionVo; +import neatlogic.framework.cmdb.enums.EditModeType; +import neatlogic.framework.cmdb.enums.TransactionActionType; +import neatlogic.framework.cmdb.exception.ci.CiNotFoundException; +import neatlogic.framework.cmdb.exception.cientity.CiEntityNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.AppEnvNotFoundException; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.crossover.CrossoverServiceFactory; +import neatlogic.framework.deploy.auth.DEPLOY_BASE; +import neatlogic.framework.deploy.constvalue.DeployAppConfigAction; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.deploy.service.DeployAppAuthorityService; +import neatlogic.module.deploy.service.DeployAppConfigService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Service +@Transactional +@AuthAction(action = DEPLOY_BASE.class) +@OperationType(type = OperationTypeEnum.CREATE) +public class SaveDeployAppConfigEnvCiEntityApi extends PrivateApiComponentBase { + + @Resource + DeployAppConfigService deployAppConfigService; + + @Resource + DeployAppAuthorityService deployAppAuthorityService; + + @Override + public String getName() { + return "nmdaae.savedeployappconfigenvdbapi.getname"; + } + + @Override + public String getToken() { + return "deploy/app/config/env/cientity/save"; + } + + @Input({ + @Param(name = "appSystemId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.appsystemid"), + @Param(name = "appModuleId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.appmoduleid"), + @Param(name = "envId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.envid"), + @Param(name = "id", type = ApiParamType.LONG, desc = "common.id"), + @Param(name = "ciId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.ciid"), + @Param(name = "ip", type = ApiParamType.STRING, desc = "ip"), + @Param(name = "port", type = ApiParamType.INTEGER, desc = "port"), + @Param(name = "name", type = ApiParamType.STRING, desc = "common.name"), +// @Param(name = "attrList", type = ApiParamType.JSONARRAY, isRequired = true, minSize = 1, desc = "属性列表"), +// @Param(name = "relList", type = ApiParamType.JSONARRAY, desc = "关系列表"), +// @Param(name = "globalAttrList", type = ApiParamType.JSONARRAY, desc = "全局属性列表"), + }) + @Output({ + @Param(name = "transactionGroupId", type = ApiParamType.LONG, desc = "term.cmdb.transactiongroupid") + }) + @Description(desc = "nmdaae.savedeployappconfigenvdbapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long appSystemId = paramObj.getLong("appSystemId"); + Long appModuleId = paramObj.getLong("appModuleId"); + Long envId = paramObj.getLong("envId"); + + //校验环境权限、编辑配置的操作权限 + deployAppAuthorityService.checkEnvAuth(appSystemId, envId); + deployAppAuthorityService.checkOperationAuth(appSystemId, DeployAppConfigAction.EDIT); + + //校验应用系统id、应用模块id、环境id是否存在 + ICiEntityCrossoverMapper iCiEntityCrossoverMapper = CrossoverServiceFactory.getApi(ICiEntityCrossoverMapper.class); + + CiEntityVo appSystemCiEntity = iCiEntityCrossoverMapper.getCiEntityBaseInfoById(appSystemId); + if (appSystemCiEntity == null) { + throw new CiEntityNotFoundException(appSystemId); + } + if (iCiEntityCrossoverMapper.getCiEntityBaseInfoById(appModuleId) == null) { + throw new CiEntityNotFoundException(envId); + } + IResourceCrossoverMapper iResourceCrossoverMapper = CrossoverServiceFactory.getApi(IResourceCrossoverMapper.class); + ResourceVo env = iResourceCrossoverMapper.getAppEnvById(envId); + if (env == null) { + throw new AppEnvNotFoundException(envId); + } + ICiEntityCrossoverService ciEntityService = CrossoverServiceFactory.getApi(ICiEntityCrossoverService.class); + ICiEntityCrossoverMapper ciEntityCrossoverMapper = CrossoverServiceFactory.getApi(ICiEntityCrossoverMapper.class); + //新增实例到cmdb + Long ciId = paramObj.getLong("ciId"); + ICiCrossoverMapper ciCrossoverMapper = CrossoverServiceFactory.getApi(ICiCrossoverMapper.class); + CiVo ciVo = ciCrossoverMapper.getCiById(ciId); + if (ciVo == null) { + throw new CiNotFoundException(ciId); + } +// List attrList = new ArrayList<>(); +// List relList = new ArrayList<>(); +// List globalAttrList = new ArrayList<>(); +// JSONArray attrArray = paramObj.getJSONArray("attrList"); +// if (CollectionUtils.isNotEmpty(attrArray)) { +// attrList = attrArray.toJavaList(String.class); +// } +// JSONArray relArray = paramObj.getJSONArray("relList"); +// if (CollectionUtils.isNotEmpty(relArray)) { +// relList = relArray.toJavaList(String.class); +// } +// JSONArray globalAttrArray = paramObj.getJSONArray("globalAttrList"); +// if (CollectionUtils.isNotEmpty(globalAttrArray)) { +// globalAttrList = globalAttrArray.toJavaList(String.class); +// } + CiEntityTransactionVo ciEntityTransactionVo = new CiEntityTransactionVo(); + Long id = paramObj.getLong("id"); + if (id != null) { + //获取实例的具体信息 + CiEntityVo instanceCiEntity = ciEntityCrossoverMapper.getCiEntityBaseInfoById(id); + if (instanceCiEntity == null) { + throw new CiEntityNotFoundException(id); + } + CiEntityVo ciEntityVo = ciEntityService.getCiEntityById(instanceCiEntity.getCiId(), id); + ciEntityTransactionVo.setCiEntityId(ciEntityVo.getId()); + ciEntityTransactionVo.setCiId(ciEntityVo.getCiId()); + ciEntityTransactionVo.setAllowCommit(true); + ciEntityTransactionVo.setAction(TransactionActionType.UPDATE.getValue()); + ciEntityTransactionVo.setEditMode(EditModeType.GLOBAL.getValue()); + JSONObject attrEntityData = ciEntityVo.getAttrEntityData(); + if (MapUtils.isNotEmpty(attrEntityData)) { + ciEntityTransactionVo.setAttrEntityData(JSONObject.parseObject(attrEntityData.toJSONString())); + } + JSONObject relEntityData = ciEntityVo.getRelEntityData(); + if (MapUtils.isNotEmpty(relEntityData)) { + ciEntityTransactionVo.setRelEntityData(JSONObject.parseObject(relEntityData.toJSONString())); + } + JSONObject globalAttrEntityData = ciEntityVo.getGlobalAttrEntityData(); + if (MapUtils.isNotEmpty(globalAttrEntityData)) { + ciEntityTransactionVo.setGlobalAttrEntityData(JSONObject.parseObject(globalAttrEntityData.toJSONString())); + } + ciEntityTransactionVo.setAction(TransactionActionType.UPDATE.getValue()); + //修改属性值 + deployAppConfigService.addAttrEntityDataAndRelEntityData( + ciEntityTransactionVo, + ciVo.getId(), + paramObj, + Arrays.asList("name", "ip", "port", "maintenance_window"), + Collections.singletonList("APPComponent"), + Collections.singletonList("app_environment") + ); + } else { + ciEntityTransactionVo.setAction(TransactionActionType.INSERT.getValue()); + //添加环境属性、模块关系 + deployAppConfigService.addAttrEntityDataAndRelEntityData( + ciEntityTransactionVo, + ciVo.getId(), + paramObj, + Arrays.asList("name", "ip", "port", "maintenance_window"), + Collections.singletonList("APPComponent"), + Collections.singletonList("app_environment") + ); + } + ciEntityTransactionVo.setEditMode(EditModeType.PARTIAL.getValue()); + List ciEntityTransactionList = new ArrayList<>(); + ciEntityTransactionList.add(ciEntityTransactionVo); + Long transactionGroupId = ciEntityService.saveCiEntity(ciEntityTransactionList); + JSONObject resultObj = new JSONObject(); + resultObj.put("transactionGroupId", transactionGroupId); + return resultObj; + } +} diff --git a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java index 99f113de..bff7ed76 100644 --- a/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java +++ b/src/main/java/neatlogic/module/deploy/service/DeployAppConfigServiceImpl.java @@ -396,6 +396,10 @@ public class DeployAppConfigServiceImpl implements DeployAppConfigService { */ void addGlobalAttrEntityData(CiEntityTransactionVo ciEntityTransactionVo, JSONObject attrAndRelObj, List needUpdateGlobalAttrList) { JSONObject globalAttrEntityData = ciEntityTransactionVo.getGlobalAttrEntityData(); + if (globalAttrEntityData == null) { + globalAttrEntityData = new JSONObject(); + ciEntityTransactionVo.setGlobalAttrEntityData(globalAttrEntityData); + } IGlobalAttrCrossoverMapper globalAttrCrossoverMapper = CrossoverServiceFactory.getApi(IGlobalAttrCrossoverMapper.class); GlobalAttrVo searchVo = new GlobalAttrVo(); searchVo.setIsActive(1); -- Gitee