修改权限框架
This commit is contained in:
parent
12e218c6f8
commit
33cd2ecffe
@ -11,7 +11,10 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -27,23 +30,23 @@ public class ApplicationApiController extends BaseController<Application, Applic
|
||||
private IApplicationService applicationService;
|
||||
|
||||
@Override
|
||||
public Response<ApplicationDTO> create(ApplicationDTO dto) {
|
||||
public Response<ApplicationDTO> create(@Validated @RequestBody ApplicationDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ApplicationDTO> update(Long aLong, ApplicationDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<ApplicationDTO> update(@PathVariable Long id, @Validated @RequestBody ApplicationDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ApplicationDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<ApplicationDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -9,6 +9,9 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -26,23 +29,23 @@ public class ApplicationCategoryApiController extends BaseController<Application
|
||||
|
||||
|
||||
@Override
|
||||
public Response<ApplicationCategoryDTO> create(ApplicationCategoryDTO dto) {
|
||||
public Response<ApplicationCategoryDTO> create(@Validated @RequestBody ApplicationCategoryDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ApplicationCategoryDTO> update(Long aLong, ApplicationCategoryDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<ApplicationCategoryDTO> update(Long id, @Validated @RequestBody ApplicationCategoryDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ApplicationCategoryDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<ApplicationCategoryDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -8,6 +8,9 @@ import com.qqchen.deploy.backend.framework.controller.BaseController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -24,23 +27,23 @@ public class EnvironmentApiController extends BaseController<Environment, Enviro
|
||||
|
||||
|
||||
@Override
|
||||
public Response<EnvironmentDTO> create(EnvironmentDTO dto) {
|
||||
public Response<EnvironmentDTO> create(@Validated @RequestBody EnvironmentDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<EnvironmentDTO> update(Long aLong, EnvironmentDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<EnvironmentDTO> update(@PathVariable Long id, @Validated @RequestBody EnvironmentDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@Validated @RequestBody Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<EnvironmentDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<EnvironmentDTO> findById(@Validated @RequestBody Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,6 +13,7 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -39,23 +40,23 @@ public class ExternalSystemApiController extends BaseController<ExternalSystem,
|
||||
private IExternalSystemService externalSystemService;
|
||||
|
||||
@Override
|
||||
public Response<ExternalSystemDTO> create(ExternalSystemDTO dto) {
|
||||
public Response<ExternalSystemDTO> create(@Validated @RequestBody ExternalSystemDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ExternalSystemDTO> update(Long aLong, ExternalSystemDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<ExternalSystemDTO> update(@PathVariable Long id, @Validated @RequestBody ExternalSystemDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<ExternalSystemDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<ExternalSystemDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -31,23 +32,23 @@ public class JenkinsBuildApiController extends BaseController<JenkinsBuild, Jenk
|
||||
private IJenkinsBuildService jenkinsBuildService;
|
||||
|
||||
@Override
|
||||
public Response<JenkinsBuildDTO> create(JenkinsBuildDTO dto) {
|
||||
public Response<JenkinsBuildDTO> create(@Validated @RequestBody JenkinsBuildDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsBuildDTO> update(Long aLong, JenkinsBuildDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<JenkinsBuildDTO> update(@PathVariable Long id, @Validated @RequestBody JenkinsBuildDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsBuildDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<JenkinsBuildDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -31,23 +32,23 @@ public class JenkinsJobApiController extends BaseController<JenkinsJob, JenkinsJ
|
||||
private IJenkinsJobService jenkinsJobService;
|
||||
|
||||
@Override
|
||||
public Response<JenkinsJobDTO> create(JenkinsJobDTO dto) {
|
||||
public Response<JenkinsJobDTO> create(@Validated @RequestBody JenkinsJobDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsJobDTO> update(Long aLong, JenkinsJobDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<JenkinsJobDTO> update(@PathVariable Long id, @Validated @RequestBody JenkinsJobDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsJobDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<JenkinsJobDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -31,23 +32,23 @@ public class JenkinsViewApiController extends BaseController<JenkinsView, Jenkin
|
||||
private IJenkinsViewService jenkinsViewService;
|
||||
|
||||
@Override
|
||||
public Response<JenkinsViewDTO> create(JenkinsViewDTO dto) {
|
||||
public Response<JenkinsViewDTO> create(@Validated @RequestBody JenkinsViewDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsViewDTO> update(Long aLong, JenkinsViewDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<JenkinsViewDTO> update(@PathVariable Long id, @Validated @RequestBody JenkinsViewDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<JenkinsViewDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<JenkinsViewDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -11,48 +11,40 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 团队API控制器
|
||||
* 继承 BaseController 自动具有基础CRUD权限:
|
||||
* - deploy:team:create (创建)
|
||||
* - deploy:team:update (修改)
|
||||
* - deploy:team:delete (删除)
|
||||
* - deploy:team:view (详情)
|
||||
* - deploy:team:list (列表/分页/导出)
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/teams")
|
||||
@Tag(name = "团队管理", description = "团队的增删改查接口")
|
||||
public class TeamApiController extends BaseController<Team, TeamDTO, Long, TeamQuery> {
|
||||
|
||||
@Resource
|
||||
private ITeamService teamService;
|
||||
|
||||
@Override
|
||||
public Response<TeamDTO> create(TeamDTO dto) {
|
||||
public Response<TeamDTO> create(@Validated @RequestBody TeamDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamDTO> update(Long aLong, TeamDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<TeamDTO> update(@PathVariable Long id, @Validated @RequestBody TeamDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<TeamDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -11,6 +11,9 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -30,23 +33,23 @@ public class TeamApplicationApiController extends BaseController<TeamApplication
|
||||
private ITeamApplicationService teamApplicationService;
|
||||
|
||||
@Override
|
||||
public Response<TeamApplicationDTO> create(TeamApplicationDTO dto) {
|
||||
public Response<TeamApplicationDTO> create(@Validated @RequestBody TeamApplicationDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamApplicationDTO> update(Long aLong, TeamApplicationDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<TeamApplicationDTO> update(@PathVariable Long id, @Validated @RequestBody TeamApplicationDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamApplicationDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<TeamApplicationDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,8 +13,10 @@ import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -37,23 +39,23 @@ public class TeamConfigApiController extends BaseController<TeamConfig, TeamConf
|
||||
private ITeamConfigService teamConfigService;
|
||||
|
||||
@Override
|
||||
public Response<TeamConfigDTO> create(TeamConfigDTO dto) {
|
||||
public Response<TeamConfigDTO> create(@Validated @RequestBody TeamConfigDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamConfigDTO> update(Long aLong, TeamConfigDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<TeamConfigDTO> update(@PathVariable Long id, @Validated @RequestBody TeamConfigDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<TeamConfigDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<TeamConfigDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -2,6 +2,7 @@ package com.qqchen.deploy.backend.deploy.dto;
|
||||
|
||||
import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum;
|
||||
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
|
||||
import com.qqchen.deploy.backend.system.model.ExternalSystemDTO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@ -29,6 +30,9 @@ public class ApplicationDTO extends BaseDTO {
|
||||
@Schema(description = "应用分类ID")
|
||||
private Long applicationCategoryId;
|
||||
|
||||
@Schema(description = "三方系统ID")
|
||||
private Long externalSystemId;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean enabled;
|
||||
|
||||
@ -39,6 +43,8 @@ public class ApplicationDTO extends BaseDTO {
|
||||
|
||||
private ApplicationCategoryDTO applicationCategory;
|
||||
|
||||
private ExternalSystemDTO externalSystem;
|
||||
|
||||
@Schema(description = "关联的团队数量")
|
||||
private Long teamCount;
|
||||
|
||||
|
||||
@ -26,6 +26,12 @@ public class TeamApplicationDTO extends BaseDTO {
|
||||
@Schema(description = "分支名称", example = "develop")
|
||||
private String branch;
|
||||
|
||||
@Schema(description = "部署系统ID(Jenkins系统)")
|
||||
private Long deploySystemId;
|
||||
|
||||
@Schema(description = "部署任务ID(Jenkins Job)")
|
||||
private Long deployJobId;
|
||||
|
||||
@Schema(description = "团队名称")
|
||||
private String teamName;
|
||||
|
||||
|
||||
@ -54,6 +54,12 @@ public class Application extends Entity<Long> {
|
||||
@Column(name = "application_category_id")
|
||||
private Long applicationCategoryId;
|
||||
|
||||
/**
|
||||
* 三方系统ID(关联外部系统)
|
||||
*/
|
||||
@Column(name = "external_system_id")
|
||||
private Long externalSystemId;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
|
||||
@ -43,5 +43,17 @@ public class TeamApplication extends Entity<Long> {
|
||||
*/
|
||||
@Column(name = "branch", length = 100)
|
||||
private String branch;
|
||||
|
||||
/**
|
||||
* 部署系统ID(关联sys_external_system,type=JENKINS)
|
||||
*/
|
||||
@Column(name = "deploy_system_id")
|
||||
private Long deploySystemId;
|
||||
|
||||
/**
|
||||
* 部署任务ID(关联deploy_jenkins_job)
|
||||
*/
|
||||
@Column(name = "deploy_job_id")
|
||||
private Long deployJobId;
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,11 @@ public interface IRepositoryProjectRepository extends IBaseRepository<Repository
|
||||
|
||||
Optional<RepositoryProject> findByRepoProjectId(Long repoProjectId);
|
||||
|
||||
/**
|
||||
* 批量根据仓库项目ID查询
|
||||
*/
|
||||
List<RepositoryProject> findByRepoProjectIdIn(Collection<Long> repoProjectIds);
|
||||
|
||||
/**
|
||||
* 根据Git系统项目ID、外部系统ID查询项目
|
||||
*/
|
||||
|
||||
@ -6,6 +6,8 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -68,5 +70,16 @@ public interface ITeamApplicationRepository extends IBaseRepository<TeamApplicat
|
||||
*/
|
||||
@Query("SELECT COUNT(DISTINCT ta.teamId) FROM TeamApplication ta WHERE ta.applicationId = :applicationId")
|
||||
Long countDistinctTeamIdByApplicationId(@Param("applicationId") Long applicationId);
|
||||
|
||||
/**
|
||||
* 批量统计应用被多少个不同团队使用(用于解决N+1查询问题)
|
||||
* @param applicationIds 应用ID集合
|
||||
* @return Object数组列表,[0]=applicationId, [1]=teamCount
|
||||
*/
|
||||
@Query("SELECT ta.applicationId as applicationId, COUNT(DISTINCT ta.teamId) as teamCount " +
|
||||
"FROM TeamApplication ta " +
|
||||
"WHERE ta.applicationId IN :applicationIds " +
|
||||
"GROUP BY ta.applicationId")
|
||||
List<Object[]> countDistinctTeamIdByApplicationIds(@Param("applicationIds") Collection<Long> applicationIds);
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
package com.qqchen.deploy.backend.deploy.service.impl;
|
||||
|
||||
import com.qqchen.deploy.backend.deploy.converter.ApplicationCategoryConverter;
|
||||
import com.qqchen.deploy.backend.deploy.converter.ExternalSystemConverter;
|
||||
import com.qqchen.deploy.backend.deploy.converter.RepositoryProjectConverter;
|
||||
import com.qqchen.deploy.backend.deploy.dto.ApplicationCategoryDTO;
|
||||
import com.qqchen.deploy.backend.deploy.dto.ApplicationDTO;
|
||||
import com.qqchen.deploy.backend.deploy.dto.DevelopmentLanguageTypeDTO;
|
||||
import com.qqchen.deploy.backend.deploy.dto.RepositoryProjectDTO;
|
||||
import com.qqchen.deploy.backend.system.model.ExternalSystemDTO;
|
||||
import com.qqchen.deploy.backend.deploy.entity.Application;
|
||||
import com.qqchen.deploy.backend.deploy.entity.ApplicationCategory;
|
||||
import com.qqchen.deploy.backend.deploy.entity.ExternalSystem;
|
||||
import com.qqchen.deploy.backend.deploy.entity.RepositoryProject;
|
||||
import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum;
|
||||
import com.qqchen.deploy.backend.deploy.query.ApplicationQuery;
|
||||
import com.qqchen.deploy.backend.deploy.repository.IApplicationCategoryRepository;
|
||||
import com.qqchen.deploy.backend.deploy.repository.IApplicationRepository;
|
||||
import com.qqchen.deploy.backend.deploy.repository.IExternalSystemRepository;
|
||||
import com.qqchen.deploy.backend.deploy.repository.IRepositoryProjectRepository;
|
||||
import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository;
|
||||
import com.qqchen.deploy.backend.deploy.service.IApplicationService;
|
||||
@ -48,26 +54,88 @@ public class ApplicationServiceImpl extends BaseServiceImpl<Application, Applica
|
||||
@Resource
|
||||
private ITeamApplicationRepository teamApplicationRepository;
|
||||
|
||||
@Resource
|
||||
private IExternalSystemRepository externalSystemRepository;
|
||||
|
||||
@Resource
|
||||
private ExternalSystemConverter externalSystemConverter;
|
||||
|
||||
public Page<ApplicationDTO> page(ApplicationQuery query) {
|
||||
Page<ApplicationDTO> page = super.page(query);
|
||||
List<ApplicationDTO> result = page.getContent().stream().peek(application -> {
|
||||
// 查询并设置应用分类信息
|
||||
List<ApplicationDTO> content = page.getContent();
|
||||
|
||||
if (content.isEmpty()) {
|
||||
return page;
|
||||
}
|
||||
|
||||
// 批量查询应用分类
|
||||
List<Long> categoryIds = content.stream()
|
||||
.map(ApplicationDTO::getApplicationCategoryId)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(toList());
|
||||
java.util.Map<Long, ApplicationCategoryDTO> categoryMap = new java.util.HashMap<>();
|
||||
if (!categoryIds.isEmpty()) {
|
||||
applicationCategoryRepository.findAllById(categoryIds).forEach(category ->
|
||||
categoryMap.put(category.getId(), applicationCategoryConverter.toDto(category))
|
||||
);
|
||||
}
|
||||
|
||||
// 批量查询代码仓库项目
|
||||
List<Long> repoProjectIds = content.stream()
|
||||
.map(ApplicationDTO::getRepoProjectId)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(toList());
|
||||
java.util.Map<Long, RepositoryProjectDTO> repoProjectMap = new java.util.HashMap<>();
|
||||
if (!repoProjectIds.isEmpty()) {
|
||||
repositoryProjectRepository.findByRepoProjectIdIn(repoProjectIds).forEach(repoProject ->
|
||||
repoProjectMap.put(repoProject.getRepoProjectId(), repositoryProjectConverter.toDto(repoProject))
|
||||
);
|
||||
}
|
||||
|
||||
// 批量查询三方系统
|
||||
List<Long> externalSystemIds = content.stream()
|
||||
.map(ApplicationDTO::getExternalSystemId)
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(toList());
|
||||
java.util.Map<Long, ExternalSystemDTO> externalSystemMap = new java.util.HashMap<>();
|
||||
if (!externalSystemIds.isEmpty()) {
|
||||
externalSystemRepository.findAllById(externalSystemIds).forEach(externalSystem ->
|
||||
externalSystemMap.put(externalSystem.getId(), externalSystemConverter.toDto(externalSystem))
|
||||
);
|
||||
}
|
||||
|
||||
// 批量统计团队数量
|
||||
List<Long> applicationIds = content.stream()
|
||||
.map(ApplicationDTO::getId)
|
||||
.collect(toList());
|
||||
java.util.Map<Long, Long> teamCountMap = new java.util.HashMap<>();
|
||||
if (!applicationIds.isEmpty()) {
|
||||
List<Object[]> teamCountResults = teamApplicationRepository.countDistinctTeamIdByApplicationIds(applicationIds);
|
||||
teamCountResults.forEach(result -> {
|
||||
Long applicationId = ((Number) result[0]).longValue();
|
||||
Long teamCount = ((Number) result[1]).longValue();
|
||||
teamCountMap.put(applicationId, teamCount);
|
||||
});
|
||||
}
|
||||
|
||||
// 设置关联数据
|
||||
content.forEach(application -> {
|
||||
if (application.getApplicationCategoryId() != null) {
|
||||
Optional<ApplicationCategory> categoryOptional = applicationCategoryRepository.findById(application.getApplicationCategoryId());
|
||||
categoryOptional.ifPresent(category -> application.setApplicationCategory(applicationCategoryConverter.toDto(category)));
|
||||
application.setApplicationCategory(categoryMap.get(application.getApplicationCategoryId()));
|
||||
}
|
||||
|
||||
// 查询并设置代码仓库项目信息
|
||||
if (application.getRepoProjectId() != null) {
|
||||
Optional<RepositoryProject> repositoryProjectOptional = repositoryProjectRepository.findByRepoProjectId(application.getRepoProjectId());
|
||||
repositoryProjectOptional.ifPresent(repositoryProject -> application.setRepositoryProject(repositoryProjectConverter.toDto(repositoryProject)));
|
||||
application.setRepositoryProject(repoProjectMap.get(application.getRepoProjectId()));
|
||||
}
|
||||
if (application.getExternalSystemId() != null) {
|
||||
application.setExternalSystem(externalSystemMap.get(application.getExternalSystemId()));
|
||||
}
|
||||
application.setTeamCount(teamCountMap.getOrDefault(application.getId(), 0L));
|
||||
});
|
||||
|
||||
// 统计该应用被多少个不同团队使用(去重 team_id)
|
||||
Long teamCount = teamApplicationRepository.countDistinctTeamIdByApplicationId(application.getId());
|
||||
application.setTeamCount(teamCount != null ? teamCount : 0L);
|
||||
}).collect(toList());
|
||||
return new PageImpl<>(result, page.getPageable(), page.getTotalElements());
|
||||
return new PageImpl<>(content, page.getPageable(), page.getTotalElements());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -33,23 +34,23 @@ public class FormDefinitionApiController extends BaseController<FormDefinition,
|
||||
private IFormDefinitionService formDefinitionService;
|
||||
|
||||
@Override
|
||||
public Response<FormDefinitionDTO> create(FormDefinitionDTO dto) {
|
||||
public Response<FormDefinitionDTO> create(@Validated @RequestBody FormDefinitionDTO dto) {
|
||||
return super.create(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<FormDefinitionDTO> update(Long aLong, FormDefinitionDTO dto) {
|
||||
return super.update(aLong, dto);
|
||||
public Response<FormDefinitionDTO> update(@PathVariable Long id, @Validated @RequestBody FormDefinitionDTO dto) {
|
||||
return super.update(id, dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<Void> delete(Long aLong) {
|
||||
return super.delete(aLong);
|
||||
public Response<Void> delete(@PathVariable Long id) {
|
||||
return super.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<FormDefinitionDTO> findById(Long aLong) {
|
||||
return super.findById(aLong);
|
||||
public Response<FormDefinitionDTO> findById(@PathVariable Long id) {
|
||||
return super.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -725,6 +725,7 @@ CREATE TABLE deploy_application
|
||||
language VARCHAR(50) NULL COMMENT '开发语言:JAVA、PYTHON、NODEJS',
|
||||
repo_project_id BIGINT NULL COMMENT '代码仓库项目ID',
|
||||
application_category_id BIGINT NULL COMMENT '所属应用分类ID',
|
||||
external_system_id BIGINT NULL COMMENT '三方系统ID(关联外部系统)',
|
||||
enabled BIT NOT NULL DEFAULT 1 COMMENT '是否启用(0:禁用,1:启用)',
|
||||
sort INT NOT NULL DEFAULT 0 COMMENT '排序号',
|
||||
-- 基础字段
|
||||
@ -831,11 +832,15 @@ CREATE TABLE deploy_team_application
|
||||
application_id BIGINT NOT NULL COMMENT '应用ID',
|
||||
environment_id BIGINT NOT NULL COMMENT '环境ID',
|
||||
branch VARCHAR(100) NULL COMMENT '分支名称',
|
||||
deploy_system_id BIGINT NULL COMMENT '部署系统ID(关联sys_external_system,type=JENKINS)',
|
||||
deploy_job_id BIGINT NULL COMMENT '部署任务ID(关联deploy_jenkins_job)',
|
||||
|
||||
UNIQUE INDEX uk_team_app_env (team_id, application_id, environment_id),
|
||||
INDEX idx_team (team_id),
|
||||
INDEX idx_application (application_id),
|
||||
INDEX idx_environment (environment_id),
|
||||
INDEX idx_deploy_system (deploy_system_id),
|
||||
INDEX idx_deploy_job (deploy_job_id),
|
||||
CONSTRAINT fk_team_app_team FOREIGN KEY (team_id) REFERENCES deploy_team (id),
|
||||
CONSTRAINT fk_team_app_application FOREIGN KEY (application_id) REFERENCES deploy_application (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='团队应用关联表';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user