diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/ITeamApplicationRepository.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/ITeamApplicationRepository.java index efe4c8c2..6f1e194f 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/ITeamApplicationRepository.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/ITeamApplicationRepository.java @@ -126,5 +126,15 @@ public interface ITeamApplicationRepository extends IBaseRepository findByDeploySystemIdAndBuildType(Long deploySystemId, BuildTypeEnum buildType); + + /** + * 检查指定团队和环境下是否已存在使用该 Jenkins Job 的配置 + * + * @param teamId 团队ID + * @param environmentId 环境ID + * @param deployJob Jenkins Job 名称 + * @return 是否存在 + */ + boolean existsByTeamIdAndEnvironmentIdAndDeployJobAndDeletedFalse(Long teamId, Long environmentId, String deployJob); } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamApplicationServiceImpl.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamApplicationServiceImpl.java index 09ea02f6..d05b6abf 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamApplicationServiceImpl.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamApplicationServiceImpl.java @@ -7,6 +7,7 @@ import com.qqchen.deploy.backend.deploy.entity.DeployRecord; import com.qqchen.deploy.backend.deploy.entity.Environment; import com.qqchen.deploy.backend.deploy.entity.Team; import com.qqchen.deploy.backend.deploy.entity.TeamApplication; +import com.qqchen.deploy.backend.deploy.enums.BuildTypeEnum; import com.qqchen.deploy.backend.deploy.query.TeamApplicationQuery; import com.qqchen.deploy.backend.deploy.entity.ExternalSystem; import com.qqchen.deploy.backend.deploy.entity.RepositoryProject; @@ -67,12 +68,34 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl校验规则: + * + */ + @Override + protected void validateUniqueConstraints(TeamApplicationDTO dto) { + // 1. 检查团队+应用+环境组合是否已存在 + if (teamApplicationRepository.existsByTeamIdAndApplicationIdAndEnvironmentIdAndDeletedFalse( + dto.getTeamId(), dto.getApplicationId(), dto.getEnvironmentId())) { throw new BusinessException(ResponseCode.TEAM_APPLICATION_ALREADY_EXISTS); } - return super.create(dto); + // 2. 检查团队+环境+Jenkins Job 是否已存在(仅当构建类型为 JENKINS 且 deployJob 不为空时) + if (dto.getBuildType() == BuildTypeEnum.JENKINS + && dto.getDeployJob() != null + && !dto.getDeployJob().trim().isEmpty()) { + if (teamApplicationRepository.existsByTeamIdAndEnvironmentIdAndDeployJobAndDeletedFalse( + dto.getTeamId(), dto.getEnvironmentId(), dto.getDeployJob())) { + throw new BusinessException(ResponseCode.TEAM_APPLICATION_DEPLOY_JOB_EXISTS); + } + } } @Override diff --git a/backend/src/main/java/com/qqchen/deploy/backend/framework/enums/ResponseCode.java b/backend/src/main/java/com/qqchen/deploy/backend/framework/enums/ResponseCode.java index d9495ff9..e798a017 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/framework/enums/ResponseCode.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/framework/enums/ResponseCode.java @@ -208,6 +208,7 @@ public enum ResponseCode { TEAM_APPLICATION_NOT_FOUND(2927, "team.application.not.found"), TEAM_APPLICATION_ALREADY_EXISTS(2928, "team.application.already.exists"), TEAM_CONFIG_NOT_FOUND(2929, "team.config.not.found"), + TEAM_APPLICATION_DEPLOY_JOB_EXISTS(2930, "team.application.deploy.job.exists"), // 服务器管理相关错误码 (2950-2969) SERVER_NOT_FOUND(2950, "server.not.found"), diff --git a/backend/src/main/resources/messages.properties b/backend/src/main/resources/messages.properties index eab4256a..17cd3c4f 100644 --- a/backend/src/main/resources/messages.properties +++ b/backend/src/main/resources/messages.properties @@ -275,3 +275,7 @@ jenkins.queue.timeout=Jenkins构建队列超时,等待时间超过{0}秒 jenkins.build.timeout=Jenkins构建超时:job={0}, buildNumber={1}, 超时时间{2}分钟 jenkins.api.error=Jenkins API调用失败:HTTP {0}, {1} jenkins.response.parse.error=Jenkins响应解析失败:{0} + +# 团队应用相关 (2920-2939) +team.application.already.exists=该应用已配置到此环境 +team.application.deploy.job.exists=该环境下已有其他应用使用此 Jenkins Job,请检查配置 diff --git a/backend/src/main/resources/messages_en_US.properties b/backend/src/main/resources/messages_en_US.properties index 131a5aa5..3dcffc0c 100644 --- a/backend/src/main/resources/messages_en_US.properties +++ b/backend/src/main/resources/messages_en_US.properties @@ -208,3 +208,7 @@ jenkins.queue.timeout=Jenkins build queue timeout, waited more than {0} seconds jenkins.build.timeout=Jenkins build timeout: job={0}, buildNumber={1}, timeout {2} minutes jenkins.api.error=Jenkins API call failed: HTTP {0}, {1} jenkins.response.parse.error=Jenkins response parse error: {0} + +# Team Application Related (2920-2939) +team.application.already.exists=Application already configured for this environment +team.application.deploy.job.exists=This Jenkins Job is already used by another application in this environment, please check the configuration diff --git a/backend/src/main/resources/messages_zh_CN.properties b/backend/src/main/resources/messages_zh_CN.properties index 1897b0c0..4622dd8f 100644 --- a/backend/src/main/resources/messages_zh_CN.properties +++ b/backend/src/main/resources/messages_zh_CN.properties @@ -208,3 +208,7 @@ jenkins.queue.timeout=Jenkins构建队列超时,等待时间超过{0}秒 jenkins.build.timeout=Jenkins构建超时:job={0}, buildNumber={1}, 超时时间{2}分钟 jenkins.api.error=Jenkins API调用失败:HTTP {0}, {1} jenkins.response.parse.error=Jenkins响应解析失败:{0} + +# 团队应用相关 (2920-2939) +team.application.already.exists=该应用已配置到此环境 +team.application.deploy.job.exists=该环境下已有其他应用使用此 Jenkins Job,请检查配置