增加团队管理增删改差

This commit is contained in:
dengqichen 2025-10-29 12:17:30 +08:00
parent cae9ce86c5
commit 75d8935ac3
7 changed files with 55 additions and 14 deletions

View File

@ -38,11 +38,22 @@ public class ApplicationCategoryServiceImpl extends BaseServiceImpl<ApplicationC
public ApplicationCategoryDTO create(ApplicationCategoryDTO dto) { public ApplicationCategoryDTO create(ApplicationCategoryDTO dto) {
// 检查编码唯一性 // 检查编码唯一性
if (applicationCategoryRepository.existsByCodeAndDeletedFalse(dto.getCode())) { if (applicationCategoryRepository.existsByCodeAndDeletedFalse(dto.getCode())) {
throw new RuntimeException("分类编码已存在: " + dto.getCode()); throw new BusinessException(ResponseCode.APPLICATION_CATEGORY_CODE_EXISTS, new Object[]{dto.getCode()});
} }
return super.create(dto); return super.create(dto);
} }
@Override
@Transactional
public void delete(Long id) {
// 检查是否有关联的应用
Long applicationCount = applicationRepository.countByApplicationCategoryIdAndDeletedFalse(id);
if (applicationCount > 0) {
throw new BusinessException(ResponseCode.APPLICATION_CATEGORY_HAS_APPLICATIONS);
}
super.delete(id);
}
@Override @Override
public Page<ApplicationCategoryDTO> page(ApplicationCategoryQuery query) { public Page<ApplicationCategoryDTO> page(ApplicationCategoryQuery query) {
Page<ApplicationCategoryDTO> page = super.page(query); Page<ApplicationCategoryDTO> page = super.page(query);

View File

@ -10,6 +10,8 @@ import com.qqchen.deploy.backend.deploy.repository.IApplicationRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamRepository;
import com.qqchen.deploy.backend.deploy.service.ITeamApplicationService; import com.qqchen.deploy.backend.deploy.service.ITeamApplicationService;
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
import com.qqchen.deploy.backend.framework.exception.BusinessException;
import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl; import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -44,7 +46,7 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
public TeamApplicationDTO create(TeamApplicationDTO dto) { public TeamApplicationDTO create(TeamApplicationDTO dto) {
// 检查是否已关联 // 检查是否已关联
if (teamApplicationRepository.existsByTeamIdAndApplicationIdAndDeletedFalse(dto.getTeamId(), dto.getApplicationId())) { if (teamApplicationRepository.existsByTeamIdAndApplicationIdAndDeletedFalse(dto.getTeamId(), dto.getApplicationId())) {
throw new RuntimeException("该应用已关联到此团队"); throw new BusinessException(ResponseCode.TEAM_APPLICATION_ALREADY_EXISTS);
} }
return super.create(dto); return super.create(dto);

View File

@ -8,6 +8,8 @@ import com.qqchen.deploy.backend.deploy.query.TeamMemberQuery;
import com.qqchen.deploy.backend.deploy.repository.ITeamMemberRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamMemberRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamRepository;
import com.qqchen.deploy.backend.deploy.service.ITeamMemberService; import com.qqchen.deploy.backend.deploy.service.ITeamMemberService;
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
import com.qqchen.deploy.backend.framework.exception.BusinessException;
import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl; import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.system.entity.User; import com.qqchen.deploy.backend.system.entity.User;
import com.qqchen.deploy.backend.system.repository.IUserRepository; import com.qqchen.deploy.backend.system.repository.IUserRepository;
@ -45,7 +47,7 @@ public class TeamMemberServiceImpl extends BaseServiceImpl<TeamMember, TeamMembe
public TeamMemberDTO create(TeamMemberDTO dto) { public TeamMemberDTO create(TeamMemberDTO dto) {
// 检查成员是否已加入团队 // 检查成员是否已加入团队
if (teamMemberRepository.existsByTeamIdAndUserIdAndDeletedFalse(dto.getTeamId(), dto.getUserId())) { if (teamMemberRepository.existsByTeamIdAndUserIdAndDeletedFalse(dto.getTeamId(), dto.getUserId())) {
throw new RuntimeException("该用户已是团队成员"); throw new BusinessException(ResponseCode.TEAM_MEMBER_ALREADY_EXISTS);
} }
// 自动填充用户名和加入时间 // 自动填充用户名和加入时间

View File

@ -8,6 +8,7 @@ import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamMemberRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamMemberRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamRepository;
import com.qqchen.deploy.backend.deploy.service.ITeamService; import com.qqchen.deploy.backend.deploy.service.ITeamService;
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
import com.qqchen.deploy.backend.framework.exception.BusinessException; import com.qqchen.deploy.backend.framework.exception.BusinessException;
import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl; import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -42,7 +43,7 @@ public class TeamServiceImpl extends BaseServiceImpl<Team, TeamDTO, TeamQuery, L
public TeamDTO create(TeamDTO dto) { public TeamDTO create(TeamDTO dto) {
// 检查编码唯一性 // 检查编码唯一性
if (teamRepository.existsByTeamCodeAndDeletedFalse(dto.getTeamCode())) { if (teamRepository.existsByTeamCodeAndDeletedFalse(dto.getTeamCode())) {
throw new RuntimeException("团队编码已存在: " + dto.getTeamCode()); throw new BusinessException(ResponseCode.TEAM_CODE_EXISTS, new Object[]{dto.getTeamCode()});
} }
return super.create(dto); return super.create(dto);
} }
@ -53,13 +54,13 @@ public class TeamServiceImpl extends BaseServiceImpl<Team, TeamDTO, TeamQuery, L
// 检查是否有成员 // 检查是否有成员
Long memberCount = teamMemberRepository.countByTeamIdAndDeletedFalse(id); Long memberCount = teamMemberRepository.countByTeamIdAndDeletedFalse(id);
if (memberCount > 0) { if (memberCount > 0) {
throw new RuntimeException("该团队下存在成员,无法删除"); throw new BusinessException(ResponseCode.TEAM_HAS_MEMBERS);
} }
// 检查是否有关联应用 // 检查是否有关联应用
Long applicationCount = teamApplicationRepository.countByTeamIdAndDeletedFalse(id); Long applicationCount = teamApplicationRepository.countByTeamIdAndDeletedFalse(id);
if (applicationCount > 0) { if (applicationCount > 0) {
throw new RuntimeException("该团队下存在关联应用,无法删除"); throw new BusinessException(ResponseCode.TEAM_HAS_APPLICATIONS);
} }
super.delete(id); super.delete(id);

View File

@ -155,7 +155,22 @@ public enum ResponseCode {
FORM_DEFINITION_NOT_FOUND(2800, "form.definition.not.found"), FORM_DEFINITION_NOT_FOUND(2800, "form.definition.not.found"),
FORM_DATA_NOT_FOUND(2801, "form.data.not.found"), FORM_DATA_NOT_FOUND(2801, "form.data.not.found"),
FORM_DEFINITION_KEY_EXISTS(2802, "form.definition.key.exists"), FORM_DEFINITION_KEY_EXISTS(2802, "form.definition.key.exists"),
FORM_DEFINITION_KEY_VERSION_EXISTS(2803, "form.definition.key.version.exists"); FORM_DEFINITION_KEY_VERSION_EXISTS(2803, "form.definition.key.version.exists"),
// 应用分类相关错误码 (2900-2919)
APPLICATION_CATEGORY_NOT_FOUND(2900, "application.category.not.found"),
APPLICATION_CATEGORY_CODE_EXISTS(2901, "application.category.code.exists"),
APPLICATION_CATEGORY_HAS_APPLICATIONS(2902, "application.category.has.applications"),
// 团队管理相关错误码 (2920-2949)
TEAM_NOT_FOUND(2920, "team.not.found"),
TEAM_CODE_EXISTS(2921, "team.code.exists"),
TEAM_HAS_MEMBERS(2922, "team.has.members"),
TEAM_HAS_APPLICATIONS(2923, "team.has.applications"),
TEAM_MEMBER_NOT_FOUND(2924, "team.member.not.found"),
TEAM_MEMBER_ALREADY_EXISTS(2925, "team.member.already.exists"),
TEAM_APPLICATION_NOT_FOUND(2926, "team.application.not.found"),
TEAM_APPLICATION_ALREADY_EXISTS(2927, "team.application.already.exists");
private final int code; private final int code;
private final String messageKey; // 国际化消息key private final String messageKey; // 国际化消息key

View File

@ -181,13 +181,8 @@ INSERT INTO sys_external_system (
'BASIC', 'admin', 'Lianyu!@#~123456', NULL, 'BASIC', 'admin', 'Lianyu!@#~123456', NULL,
'SUCCESS', '2023-12-01 00:00:00', '2023-12-01 00:00:00', '{}' 'SUCCESS', '2023-12-01 00:00:00', '2023-12-01 00:00:00', '{}'
), ( ), (
2, 'admin', '2023-12-01 00:00:00', 0, 'admin', '2023-12-01 00:00:00', 0, 2, 'admin', '2024-12-03 10:35:58.932966', 0, 'admin', '2024-12-03 10:35:58.932966', 0,
'GitLab测试环境', 'GIT', 'http://gitlab.test.com', '测试环境GitLab服务器', 2, 1, '链宇GIT', 'GIT', 'https://ly-gitlab.iscmtech.com/', NULL, 1, 1,
'TOKEN', NULL, NULL, 'test-token',
'SUCCESS', '2023-12-01 00:00:00', '2023-12-01 00:00:00', '{}'
), (
3, 'admin', '2024-12-03 10:35:58.932966', 0, 'admin', '2024-12-03 10:35:58.932966', 0,
'链宇GIT', 'GIT', 'http://119.3.203.210:8088/', NULL, 1, 1,
'TOKEN', NULL, NULL, 'cNSud7D1GmYQKEMco7s5', 'TOKEN', NULL, NULL, 'cNSud7D1GmYQKEMco7s5',
NULL, NULL, NULL, '{}' NULL, NULL, NULL, '{}'
); );

View File

@ -170,3 +170,18 @@ form.definition.not.found=表单定义不存在或已删除
form.data.not.found=表单数据不存在或已删除 form.data.not.found=表单数据不存在或已删除
form.definition.key.exists=表单标识{0}已存在,请使用不同的标识 form.definition.key.exists=表单标识{0}已存在,请使用不同的标识
form.definition.key.version.exists=表单标识{0}的版本{1}已存在 form.definition.key.version.exists=表单标识{0}的版本{1}已存在
# 应用分类相关 (2900-2919)
application.category.not.found=应用分类不存在或已删除
application.category.code.exists=分类编码{0}已存在
application.category.has.applications=该分类下存在应用,无法删除
# 团队管理相关 (2920-2949)
team.not.found=团队不存在或已删除
team.code.exists=团队编码{0}已存在
team.has.members=该团队下存在成员,无法删除
team.has.applications=该团队下存在关联应用,无法删除
team.member.not.found=团队成员不存在或已删除
team.member.already.exists=该用户已是团队成员
team.application.not.found=团队应用关联不存在或已删除
team.application.already.exists=该应用已关联到此团队