diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/DeleteDeployAppConfigEnvDBPrivateAccountApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/DeleteDeployAppConfigEnvDBPrivateAccountApi.java new file mode 100644 index 0000000000000000000000000000000000000000..059cc611e911a0e166aca71ce3581f27f7fb12fb --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/DeleteDeployAppConfigEnvDBPrivateAccountApi.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.deploy.api.appconfig.env; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.crossover.IResourceAccountCrossoverMapper; +import neatlogic.framework.cmdb.crossover.IResourceCenterAccountCrossoverService; +import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; +import neatlogic.framework.cmdb.enums.resourcecenter.AccountType; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterAccountNotFoundException; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterAccountNotPrivateException; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterResourceNotExistAccountException; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceNotFoundException; +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.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.deploy.dao.mapper.DeployAppConfigMapper; +import neatlogic.module.deploy.service.DeployAppAuthorityService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +@Service +@Transactional +@AuthAction(action = DEPLOY_BASE.class) +@OperationType(type = OperationTypeEnum.UPDATE) +public class DeleteDeployAppConfigEnvDBPrivateAccountApi extends PrivateApiComponentBase { + + @Resource + DeployAppAuthorityService deployAppAuthorityService; + + @Resource + private DeployAppConfigMapper deployAppConfigMapper; + + @Override + public String getName() { + return "nmdaae.deletedeployappconfigenvdbprivateaccountapi.getname"; + } + + @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 = "resourceId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.resourceid"), + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id") + }) + @Description(desc = "nmdaae.deletedeployappconfigenvdbprivateaccountapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long appSystemId = paramObj.getLong("appSystemId"); + Long envId = paramObj.getLong("envId"); + //校验环境权限、编辑配置的操作权限 + deployAppAuthorityService.checkEnvAuth(appSystemId, envId); + deployAppAuthorityService.checkOperationAuth(appSystemId, DeployAppConfigAction.EDIT); + Long resourceId = paramObj.getLong("resourceId"); + ResourceVo resourceVo = deployAppConfigMapper.getDatabaseById(resourceId); + if (resourceVo == null) { + throw new ResourceNotFoundException(resourceId); + } + Long id = paramObj.getLong("id"); + IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class); + AccountVo account = resourceAccountCrossoverMapper.getAccountById(id); + if (account == null) { + throw new ResourceCenterAccountNotFoundException(id); + } + if (!Objects.equals(account.getType(), AccountType.PRIVATE.getValue())) { + throw new ResourceCenterAccountNotPrivateException(account.getName()); + } + List resourcePrivateAccountList = resourceAccountCrossoverMapper.getResourceAccountListByResourceIdAndType(resourceId, AccountType.PRIVATE.getValue()); + List privateAccountIdList = resourcePrivateAccountList.stream().map(AccountVo::getId).collect(Collectors.toList()); + if (!privateAccountIdList.contains(id)) { + throw new ResourceCenterResourceNotExistAccountException(resourceVo.getName(), account.getName()); + } + List idList = new ArrayList<>(); + idList.add(id); + IResourceCenterAccountCrossoverService resourceCenterAccountCrossoverService = CrossoverServiceFactory.getApi(IResourceCenterAccountCrossoverService.class); + resourceCenterAccountCrossoverService.deleteAccount(idList); + return null; + } + + @Override + public String getToken() { + return "deploy/app/config/env/db/privateaccount/delete"; + } +} diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPrivateAccountApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPrivateAccountApi.java new file mode 100644 index 0000000000000000000000000000000000000000..836125b0cf4fbcd3f89d0dbc696da7dfd281f97e --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPrivateAccountApi.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.deploy.api.appconfig.env; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.crossover.IResourceAccountCrossoverMapper; +import neatlogic.framework.cmdb.crossover.IResourceCenterAccountCrossoverService; +import neatlogic.framework.cmdb.dto.resourcecenter.AccountVo; +import neatlogic.framework.cmdb.enums.resourcecenter.AccountType; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceCenterAccountNameRepeatsException; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceNotFoundException; +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.dto.FieldValidResultVo; +import neatlogic.framework.exception.type.ParamNotExistsException; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +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.service.DeployAppAuthorityService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; + +@Service +@Transactional +@AuthAction(action = DEPLOY_BASE.class) +@OperationType(type = OperationTypeEnum.UPDATE) +public class SaveDeployAppConfigEnvDBPrivateAccountApi extends PrivateApiComponentBase { + + @Resource + DeployAppAuthorityService deployAppAuthorityService; + + @Resource + private DeployAppConfigMapper deployAppConfigMapper; + + @Override + public String getName() { + return "nmdaae.savedeployappconfigenvdbprivateaccountapi.getname"; + } + + @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 = "resourceId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.resourceid"), + @Param(name = "id", type = ApiParamType.LONG, desc = "common.id"), + @Param(name = "name", type = ApiParamType.STRING, maxLength = 200, isRequired = true, desc = "common.name"), + @Param(name = "account", type = ApiParamType.STRING, maxLength = 80, desc = "common.username"), + @Param(name = "passwordPlain", type = ApiParamType.STRING, isRequired = false, desc = "common.password"), + @Param(name = "protocolId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.protocol"), + @Param(name = "port", type = ApiParamType.INTEGER, isRequired = false, desc = "term.cmdb.port"), + @Param(name = "tagIdList", type = ApiParamType.JSONARRAY, isRequired = false, desc = "common.tagidlist"), + @Param(name = "type", type = ApiParamType.ENUM, member = AccountType.class, isRequired = true, desc = "common.type"), + @Param(name = "isDefault", type = ApiParamType.INTEGER, desc = "common.isdefault"), + }) + @Description(desc = "nmdaae.savedeployappconfigenvdbprivateaccountapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long appSystemId = paramObj.getLong("appSystemId"); + Long envId = paramObj.getLong("envId"); + //校验环境权限、编辑配置的操作权限 + deployAppAuthorityService.checkEnvAuth(appSystemId, envId); + deployAppAuthorityService.checkOperationAuth(appSystemId, DeployAppConfigAction.EDIT); + Long resourceId = paramObj.getLong("resourceId"); + if (deployAppConfigMapper.getDatabaseById(resourceId) == null) { + throw new ResourceNotFoundException(resourceId); + } + IResourceCenterAccountCrossoverService resourceCenterAccountCrossoverService = CrossoverServiceFactory.getApi(IResourceCenterAccountCrossoverService.class); + AccountVo paramAccountVo = JSON.toJavaObject(paramObj, AccountVo.class); + Long id = paramObj.getLong("id"); + return resourceCenterAccountCrossoverService.saveAccount(id, paramAccountVo); + } + + @Override + public String getToken() { + return "deploy/app/config/env/db/privateaccount/save"; + } + + public IValid name() { + return value -> { + IResourceAccountCrossoverMapper resourceAccountCrossoverMapper = CrossoverServiceFactory.getApi(IResourceAccountCrossoverMapper.class); + AccountVo vo = JSON.toJavaObject(value, AccountVo.class); + if (Objects.equals(AccountType.PUBLIC.getValue(), vo.getType())) { + if (resourceAccountCrossoverMapper.checkAccountNameIsRepeats(vo) > 0) { + return new FieldValidResultVo(new ResourceCenterAccountNameRepeatsException(vo.getName())); + } + } else { + Long resourceId = vo.getResourceId(); + if (resourceId == null) { + throw new ParamNotExistsException("资产ID(resourceId)"); + } + List accountVoList = resourceAccountCrossoverMapper.getResourceAccountListByResourceId(resourceId); + for (AccountVo accountVo : accountVoList) { + if (Objects.equals(vo.getName(), accountVo.getName()) && !Objects.equals(vo.getId(), accountVo.getId())) { + return new FieldValidResultVo(new ResourceCenterAccountNameRepeatsException(vo.getName())); + } + } + } + return new FieldValidResultVo(); + }; + } +} diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPublicAccountApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPublicAccountApi.java new file mode 100644 index 0000000000000000000000000000000000000000..f5a9e303bb2f93b4e346e928ad38de90a382aabb --- /dev/null +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/env/SaveDeployAppConfigEnvDBPublicAccountApi.java @@ -0,0 +1,101 @@ +/*Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.module.deploy.api.appconfig.env; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.cmdb.crossover.IResourceCenterAccountCrossoverService; +import neatlogic.framework.cmdb.exception.resourcecenter.ResourceNotFoundException; +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.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.module.deploy.dao.mapper.DeployAppConfigMapper; +import neatlogic.module.deploy.service.DeployAppAuthorityService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @author linbq + * @since 2021/6/22 15:55 + **/ +@Service +@Transactional +@AuthAction(action = DEPLOY_BASE.class) +@OperationType(type = OperationTypeEnum.UPDATE) +public class SaveDeployAppConfigEnvDBPublicAccountApi extends PrivateApiComponentBase { + + @Resource + DeployAppAuthorityService deployAppAuthorityService; + + @Resource + private DeployAppConfigMapper deployAppConfigMapper; + + @Override + public String getToken() { + return "deploy/app/config/env/db/publicaccount/save"; + } + + @Override + public String getName() { + return "nmdaae.savedeployappconfigenvdbpublicaccountapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @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 = "resourceId", type = ApiParamType.LONG, isRequired = true, desc = "term.cmdb.resourceid"), + @Param(name = "accountIdList", type = ApiParamType.JSONARRAY, desc = "term.cmdb.accountidlist") + }) + @Description(desc = "nmdaae.savedeployappconfigenvdbpublicaccountapi.getname") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long appSystemId = paramObj.getLong("appSystemId"); + Long envId = paramObj.getLong("envId"); + //校验环境权限、编辑配置的操作权限 + deployAppAuthorityService.checkEnvAuth(appSystemId, envId); + deployAppAuthorityService.checkOperationAuth(appSystemId, DeployAppConfigAction.EDIT); + Long resourceId = paramObj.getLong("resourceId"); + if (deployAppConfigMapper.getDatabaseById(resourceId) == null) { + throw new ResourceNotFoundException(resourceId); + } + List accountIdList = new ArrayList<>(); + JSONArray accountIdArray = paramObj.getJSONArray("accountIdList"); + if (CollectionUtils.isNotEmpty(accountIdArray)) { + accountIdList = accountIdArray.toJavaList(Long.class); + } + IResourceCenterAccountCrossoverService resourceCenterAccountCrossoverService = CrossoverServiceFactory.getApi(IResourceCenterAccountCrossoverService.class); + return resourceCenterAccountCrossoverService.saveResourceAccount(resourceId, accountIdList); + } +} diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/system/ListDeployAppConfigAuthorityApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/system/ListDeployAppConfigAuthorityApi.java index 3f9a48006c3c57463c53ebfad62641c3d670e0a6..167e7981795644bfb1b2a04b2929f37c805fcc1b 100644 --- a/src/main/java/neatlogic/module/deploy/api/appconfig/system/ListDeployAppConfigAuthorityApi.java +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/system/ListDeployAppConfigAuthorityApi.java @@ -115,6 +115,7 @@ public class ListDeployAppConfigAuthorityApi extends PrivateApiComponentBase { JSONObject envValueText = new JSONObject(); envValueText.put("text", env.getName()); envValueText.put("value", env.getId()); + envValueText.put("description", DeployAppConfigActionType.ENV.getDescription()); envAuthList.add(envValueText); } returnObj.put("envAuthList", envAuthList); diff --git a/src/main/java/neatlogic/module/deploy/api/appconfig/system/SearchDeployAppConfigAuthorityApi.java b/src/main/java/neatlogic/module/deploy/api/appconfig/system/SearchDeployAppConfigAuthorityApi.java index 302facc8f90d83609d3c5e04b8f1414311a95983..3f2a9eb1cf88560b0ec62965ce6317a1288d01bc 100644 --- a/src/main/java/neatlogic/module/deploy/api/appconfig/system/SearchDeployAppConfigAuthorityApi.java +++ b/src/main/java/neatlogic/module/deploy/api/appconfig/system/SearchDeployAppConfigAuthorityApi.java @@ -55,6 +55,7 @@ import java.util.stream.Collectors; @AuthAction(action = DEPLOY_BASE.class) @OperationType(type = OperationTypeEnum.SEARCH) public class SearchDeployAppConfigAuthorityApi extends PrivateApiComponentBase { + @Resource private DeployAppConfigMapper deployAppConfigMapper; @@ -84,9 +85,9 @@ public class SearchDeployAppConfigAuthorityApi extends PrivateApiComponentBase { }) @Output({ @Param(explode = BasePageVo.class), - @Param(name = "tbodyList", explode = DeployAppConfigAuthorityVo[].class, desc = "应用配置授权列表") + @Param(name = "tbodyList", explode = DeployAppConfigAuthorityVo[].class, desc = "common.tbodylist") }) - @Description(desc = "查询应用配置权限接口") + @Description(desc = "nmdaas.searchdeployappconfigauthorityapi.getname") @Override public Object myDoService(JSONObject paramObj) { JSONArray includeActionList = paramObj.getJSONArray("includeActionList"); @@ -121,6 +122,7 @@ public class SearchDeployAppConfigAuthorityApi extends PrivateApiComponentBase { JSONObject envKeyValue = new JSONObject(); envKeyValue.put("name", environmentVo.getId()); envKeyValue.put("displayName", environmentVo.getName()); + envKeyValue.put("description", DeployAppConfigActionType.ENV.getDescription()); finalTheadList.add(envKeyValue); } 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 7f4967df7c781c4162f1eb82e99caee09147a441..eb6b415e637ac81b0fdb6e3b3567994015f440dc 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.java @@ -1,5 +1,6 @@ package neatlogic.module.deploy.dao.mapper; +import neatlogic.framework.cmdb.dto.resourcecenter.ResourceVo; import neatlogic.framework.cmdb.dto.resourcecenter.entity.AppEnvironmentVo; import neatlogic.framework.common.dto.BasePageVo; import neatlogic.framework.deploy.crossover.IDeployAppConfigCrossoverMapper; @@ -206,6 +207,8 @@ public interface DeployAppConfigMapper extends IDeployAppConfigCrossoverMapper { // int getAppModuleCountBySystemIdAndEnvId(@Param("appSystemId") Long appSystemId, @Param("envId") Long envId); + ResourceVo getDatabaseById(Long id); + /** * 查询发布应用配置DB库下的无模块无环境、无模块同环境、同模块无环境、同模块同环境且发布没配置的数据库的数量 * 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 45c6459a225f7fe9177074067bb24eaf15a685ec..822b41c6898e96f6d8d5affe727268c11ee268fd 100644 --- a/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml +++ b/src/main/java/neatlogic/module/deploy/dao/mapper/DeployAppConfigMapper.xml @@ -1064,6 +1064,13 @@ along with this program. If not, see .--> + +