From 6e1229b33237b06b34094c244acb1d5df078a552 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 8 Sep 2023 16:19:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8=E5=85=B3=E8=81=94SQL?= =?UTF-8?q?=E6=8B=86=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/service/ProjectMemberService.java | 2 +- .../service/ProjectUserRoleService.java | 2 + .../system/dto/OrganizationCountDTO.java | 27 ++++++ .../system/mapper/ExtOrganizationMapper.java | 21 ++++- .../system/mapper/ExtOrganizationMapper.xml | 94 ++++++++++++------- .../system/service/OrganizationService.java | 25 +++-- 6 files changed, 127 insertions(+), 44 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/OrganizationCountDTO.java diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java index 5566ab1433..7e3f68a481 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectMemberService.java @@ -13,6 +13,7 @@ import io.metersphere.sdk.constants.UserRoleEnum; import io.metersphere.sdk.constants.UserRoleType; import io.metersphere.sdk.dto.LogDTO; import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserExtend; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.log.constants.OperationLogModule; import io.metersphere.sdk.log.constants.OperationLogType; @@ -22,7 +23,6 @@ import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.*; -import io.metersphere.sdk.dto.UserExtend; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java index 8157204224..cab94d14aa 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectUserRoleService.java @@ -31,6 +31,7 @@ import static io.metersphere.system.controller.result.SystemResultCode.NO_PROJEC /** * 项目-用户组与权限 + * * @author song-cc-rock */ @Service @@ -185,6 +186,7 @@ public class ProjectUserRoleService extends BaseUserRoleService { /** * 校验是否项目下用户组 + * * @param userRole 用户组 */ private void checkProjectUserRole(UserRole userRole) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/OrganizationCountDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/OrganizationCountDTO.java new file mode 100644 index 0000000000..7ea3e94ba6 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/OrganizationCountDTO.java @@ -0,0 +1,27 @@ +package io.metersphere.system.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author song-cc-rock + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class OrganizationCountDTO { + + /** + * 成员数量 + */ + private Integer memberCount; + + /** + * 项目数量 + */ + private Integer projectCount; + + /** + * 组织ID + */ + private String id; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java index 3ca8aedf0f..7ec413860d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.java @@ -17,38 +17,52 @@ public interface ExtOrganizationMapper { /** * 查询组织列表 + * * @param request 列表请求参数 * @return 组织列表数据 */ List list(@Param("request") OrganizationRequest request); + /** + * 通过组织ID获取项目及成员数量 + * + * @param ids 组织ID集合 + * @return 项目及成员数量 + */ + List getCountByIds(@Param("ids") List ids); + /** * 获取系统下所有组织 + * * @return 组织列表数据 */ List listAll(); /** * 删除组织 + * * @param organizationDeleteRequest 组织删除参数 */ void delete(@Param("request") OrganizationDeleteRequest organizationDeleteRequest); /** * 恢复组织 + * * @param id 组织ID */ void recover(String id); /** * 更新组织启用/禁用状态 - * @param id 组织ID + * + * @param id 组织ID * @param enable 是否启用 */ void updateEnable(String id, boolean enable); /** * 获取组织成员列表(角色) + * * @param request 组织成员列表请求参数 * @return 组织成员列表数据 */ @@ -57,6 +71,7 @@ public interface ExtOrganizationMapper { /** * 获取组织成员列表(角色) + * * @param request 组织成员列表请求参数 * @return 组织成员列表数据 */ @@ -64,6 +79,7 @@ public interface ExtOrganizationMapper { /** * 获取组织成员下拉列表(角色) + * * @param keyword 组织成员列表请求参数 * @return 组织成员列表数据 */ @@ -71,6 +87,7 @@ public interface ExtOrganizationMapper { /** * 获取组织管理员 + * * @param orgId 组织ID * @return 组织管理员数据 */ @@ -78,12 +95,14 @@ public interface ExtOrganizationMapper { /** * 获取组织列表(下拉框) + * * @return 组织列表数据 */ List selectOrganizationOptions(); /** * 获取组织下拉选项 + * * @param ids 组织ID集合 * @return 组织下拉选项 */ diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml index 8bc7e4ef83..db3aa2ea49 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtOrganizationMapper.xml @@ -1,55 +1,77 @@ - + select o.id, o.num, o.name, o.description, o.create_time, + o.update_time, o.create_user, o.deleted, o.delete_user, o.delete_time, o.enable + from organization o + + - update organization set deleted = true , delete_time = #{request.deleteTime} , delete_user = #{request.deleteUserId} where id = #{request.organizationId} + update organization + set deleted = true, + delete_time = #{request.deleteTime}, + delete_user = #{request.deleteUserId} + where id = #{request.organizationId} - update organization set deleted = false where id = #{id} + update organization + set deleted = false + where id = #{id} - update organization set `enable` = #{enable} where id = #{id} + update organization + set `enable` = #{enable} + where id = #{id} select u.* from user_role_relation urr - join `user` u on urr.user_id = u.id - where urr.role_id = 'org_admin'and urr.source_id = #{orgId} and u.deleted = false + join `user` u on urr.user_id = u.id + where urr.role_id = 'org_admin' + and urr.source_id = #{orgId} + and u.deleted = false