From c2974a26502074c1872012e591969de29404872d Mon Sep 17 00:00:00 2001 From: WendyYang Date: Thu, 27 Apr 2023 11:30:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AE=AE=E5=88=97=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=A7=92=E8=89=B2=E6=8E=A7=E5=88=B6=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/model/entity/ViewRegionDTO.java | 24 ++++++++ .../impl/OrgAdminDataScopeProviderImpl.java | 2 +- .../impl/RegionAdminDataScopeProviderImpl.java | 7 ++- .../impl/SuperAdminDataScopeProviderImpl.java | 6 +- .../meeting/helper/MeetingDataScopeHelper.java | 66 ++++++++++++++++++++++ .../pmapi/meeting/manage/MeetingManage.java | 17 ++++-- 6 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/ViewRegionDTO.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingDataScopeHelper.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/ViewRegionDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/ViewRegionDTO.java new file mode 100644 index 0000000..9901790 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/ViewRegionDTO.java @@ -0,0 +1,24 @@ +package com.ningdatech.pmapi.common.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Collection; + +/** + *

+ * ViewRegionDTO + *

+ * + * @author WendyYang + * @since 2023/4/27 + **/ +@Data +@AllArgsConstructor +public class ViewRegionDTO { + + private Collection regions; + + private Integer regionLevel; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java index 7bcfb21..387af6b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java @@ -34,7 +34,7 @@ public class OrgAdminDataScopeProviderImpl implements DataScopeProvider { ds.setUserId(userFullInfo.getUserId()); ds.setEmployeeCode(userFullInfo.getEmployeeCode()); ds.setRole(RoleEnum.COMPANY_MANAGER); - return Optional.ofNullable(ds); + return Optional.of(ds); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java index 5350444..c79bbce 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java @@ -13,9 +13,10 @@ import com.ningdatech.pmapi.user.util.LoginUserUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; + +import java.util.ArrayList; import java.util.Collection; import java.util.Optional; -import java.util.stream.Collectors; /** *

@@ -46,11 +47,11 @@ public class RegionAdminDataScopeProviderImpl implements DataScopeProvider { } DataScopeDTO ds = new DataScopeDTO(); - ds.setRegionCodes(regionCodes.stream().collect(Collectors.toList())); + ds.setRegionCodes(new ArrayList<>(regionCodes)); ds.setUserId(userFullInfo.getUserId()); ds.setEmployeeCode(userFullInfo.getEmployeeCode()); ds.setRole(RoleEnum.REGION_MANAGER); - return Optional.ofNullable(ds); + return Optional.of(ds); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java index 3bd3efc..73168dc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java @@ -12,9 +12,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.Collection; import java.util.Optional; -import java.util.stream.Collectors; /** *

@@ -41,11 +41,11 @@ public class SuperAdminDataScopeProviderImpl implements DataScopeProvider { RegionConst.RL_CITY); DataScopeDTO ds = new DataScopeDTO(); - ds.setRegionCodes(regionCodes.stream().collect(Collectors.toList())); + ds.setRegionCodes(new ArrayList<>(regionCodes)); ds.setUserId(userFullInfo.getUserId()); ds.setEmployeeCode(userFullInfo.getEmployeeCode()); ds.setRole(RoleEnum.SUPER_ADMIN); - return Optional.ofNullable(ds); + return Optional.of(ds); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingDataScopeHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingDataScopeHelper.java new file mode 100644 index 0000000..6c4d68e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingDataScopeHelper.java @@ -0,0 +1,66 @@ +package com.ningdatech.pmapi.meeting.helper; + +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.model.entity.ViewRegionDTO; +import com.ningdatech.pmapi.sys.model.entity.Role; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + *

+ * MeetingDataScopeHelper + *

+ * + * @author WendyYang + * @since 2023/4/27 + **/ +@Component +@AllArgsConstructor +public class MeetingDataScopeHelper { + + private final RegionCacheHelper regionCacheHelper; + + private static RoleEnum getRolePriorityMax() { + List roleList = LoginUserUtil.loginUserDetail().getUserRoleList(); + List roleCodeList = CollUtils.fieldList(roleList, Role::getCode); + if (roleCodeList.contains(RoleEnum.SUPER_ADMIN.name())) { + return RoleEnum.SUPER_ADMIN; + } + if (roleCodeList.contains(RoleEnum.REGION_MANAGER.name())) { + return RoleEnum.REGION_MANAGER; + } + return RoleEnum.EXPERT_ADMIN; + } + + public ViewRegionDTO meetingListViewRegions() { + RoleEnum role = getRolePriorityMax(); + UserInfoDetails user = LoginUserUtil.loginUserDetail(); + String regionCode = user.getRegionCode(); + Integer regionLevel = user.getRegionLevel(); + Collection regions; + switch (role) { + case SUPER_ADMIN: + regions = null; + break; + case REGION_MANAGER: + regions = regionCacheHelper.listChildRegionCodeList(regionCode, regionLevel); + break; + case EXPERT_ADMIN: + regions = Collections.singletonList(regionCode); + break; + default: + regions = Collections.emptyList(); + break; + } + return new ViewRegionDTO(regions, regionLevel); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java index fd3a36b..cfd2abc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java @@ -19,9 +19,9 @@ import com.ningdatech.basic.util.StrPool; import com.ningdatech.basic.util.ValidUtil; import com.ningdatech.cache.lock.DistributedLock; import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.model.entity.ViewRegionDTO; import com.ningdatech.pmapi.expert.constant.ReviewResultEnum; import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo; -import com.ningdatech.pmapi.expert.helper.PermissionCheckHelper; import com.ningdatech.pmapi.expert.model.entity.ExpertReview; import com.ningdatech.pmapi.expert.service.IExpertReviewService; import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService; @@ -36,8 +36,8 @@ import com.ningdatech.pmapi.meeting.entity.req.*; import com.ningdatech.pmapi.meeting.entity.vo.*; import com.ningdatech.pmapi.meeting.helper.ExpertInviteHelper; import com.ningdatech.pmapi.meeting.helper.MeetingCallOrMsgHelper; +import com.ningdatech.pmapi.meeting.helper.MeetingDataScopeHelper; import com.ningdatech.pmapi.meeting.helper.MeetingManageHelper; -import com.ningdatech.pmapi.meeting.helper.YxtCallOrSmsHelper; import com.ningdatech.pmapi.meeting.service.*; import com.ningdatech.pmapi.meeting.task.ExpertRandomInviteTask; import com.ningdatech.pmapi.meta.helper.DictionaryCache; @@ -87,9 +87,7 @@ public class MeetingManage { private final ExpertInviteManage expertInviteManage; private final ExpertRandomInviteTask expertRandomInviteTask; private final MeetingManageHelper meetingManageHelper; - private final YxtCallOrSmsHelper yxtCallOrSmsHelper; private final DistributedLock distributedLock; - private final PermissionCheckHelper permissionCheckHelper; private final IProjectService projectService; private final IMeetingInnerProjectService meetingInnerProjectService; private final IMeetingOuterProjectService meetingOuterProjectService; @@ -98,6 +96,7 @@ public class MeetingManage { private final IExpertReviewService expertReviewService; private final ExpertInviteHelper expertInviteHelper; private final MeetingCallOrMsgHelper meetingCallOrMsgHelper; + private final MeetingDataScopeHelper meetingDataScopeHelper; private static final String INVITED_RULE_CREATE = "INVITED_RULE_CREATE:"; private static final String MEETING_CREATE_KEY = "MEETING_CREATE:"; @@ -388,11 +387,17 @@ public class MeetingManage { * @author WendyYang */ public PageVo meetingListForManager(MeetingListReq req) { + ViewRegionDTO viewRegions = meetingDataScopeHelper.meetingListViewRegions(); + Collection regions; + if ((regions = viewRegions.getRegions()) != null && regions.isEmpty()) { + return PageVo.empty(); + } LambdaQueryWrapper query = new LambdaQueryWrapper() .orderByDesc(Meeting::getCreateOn); // 补充逻辑 如果拥有超级管理员权限可以看到所有事务 - if (!permissionCheckHelper.isSuperAdmin()) { - query.eq(Meeting::getCreateBy, LoginUserUtil.getUserId()); + if (regions != null) { + query.in(Meeting::getRegionCode, regions); + query.ge(Meeting::getRegionLevel, viewRegions.getRegionLevel()); } query.eq(req.getStatus() != null, Meeting::getStatus, req.getStatus()); meetingManageHelper.buildMeetingQuery(query, req);