|
|
@@ -21,6 +21,13 @@ import org.dromara.system.domain.SysDept;
|
|
|
import org.dromara.system.domain.SysUserRole;
|
|
|
import org.dromara.system.mapper.SysDeptMapper;
|
|
|
import org.dromara.system.mapper.SysUserRoleMapper;
|
|
|
+import org.dromara.xg.domain.XgStudentManager;
|
|
|
+import org.dromara.xg.domain.XgStudentManagerSource;
|
|
|
+import org.dromara.xg.domain.XgClassTeacherCounselorRel;
|
|
|
+import org.dromara.xg.mapper.XgStudentManagerMapper;
|
|
|
+import org.dromara.xg.mapper.XgStudentManagerSourceMapper;
|
|
|
+import org.dromara.xg.mapper.XgClassTeacherCounselorRelMapper;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -29,6 +36,8 @@ import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.HashSet;
|
|
|
|
|
|
/**
|
|
|
* 班级干部信息Service业务层处理
|
|
|
@@ -44,6 +53,9 @@ public class XgClassPosMsgServiceImpl implements IXgClassPosMsgService {
|
|
|
private final XgClassPosMsgMapper baseMapper;
|
|
|
private final SysDeptMapper sysDeptMapper;
|
|
|
private final SysUserRoleMapper sysUserRoleMapper;
|
|
|
+ private final XgStudentManagerMapper xgStudentManagerMapper;
|
|
|
+ private final XgStudentManagerSourceMapper xgStudentManagerSourceMapper;
|
|
|
+ private final XgClassTeacherCounselorRelMapper xgClassTeacherCounselorRelMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询班级干部信息
|
|
|
@@ -66,9 +78,149 @@ public class XgClassPosMsgServiceImpl implements IXgClassPosMsgService {
|
|
|
*/
|
|
|
@Override
|
|
|
public TableDataInfo<XgClassPosMsgVo> queryPageList(XgClassPosMsgBo bo, PageQuery pageQuery, Long deptId) {
|
|
|
- // 第一步:获取dept_id并查找所有子组织
|
|
|
+ // 调用权限过滤方法,获取过滤后的deptIds
|
|
|
+ List<Long> filteredDeptIds = filterDeptIdsByPermission(deptId);
|
|
|
+
|
|
|
+ log.info("权限过滤后的部门ID列表: {}", filteredDeptIds);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ LambdaQueryWrapper<XgClassPosMsg> lqw = buildQueryWrapper(bo, filteredDeptIds);
|
|
|
+ // 使用XML配置的联表查询方法,确保能获取到班级名称和职务名称
|
|
|
+ Page<XgClassPosMsgVo> result = baseMapper.selectVoPageWithJoin(pageQuery.build(), lqw);
|
|
|
+
|
|
|
+ log.info("查询到班级干部信息 {} 条,使用XML配置的联表查询", result.getTotal());
|
|
|
+
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 权限过滤方法
|
|
|
+ * 根据当前用户的权限范围过滤部门ID列表
|
|
|
+ *
|
|
|
+ * @param deptId 入参的部门ID
|
|
|
+ * @return 过滤后的部门ID列表
|
|
|
+ */
|
|
|
+ private List<Long> filterDeptIdsByPermission(Long deptId) {
|
|
|
+ // 获取当前登录用户ID
|
|
|
+ Long currentUserId = LoginHelper.getUserId();
|
|
|
+ log.info("当前登录用户ID: {}", currentUserId);
|
|
|
+
|
|
|
+ // 第一步:判断当前用户是否为全校管理员
|
|
|
+ boolean isSchoolManager = checkIsSchoolManager(currentUserId);
|
|
|
+ if (isSchoolManager) {
|
|
|
+ log.info("用户 {} 是全校管理员,不进行权限过滤", currentUserId);
|
|
|
+ // 全校管理员不进行过滤,返回包含入参deptId及其子组织的列表
|
|
|
+ return getDeptIdsWithChildren(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步:获取用户的总权限集合
|
|
|
+ Set<Long> userAuthDeptIds = getUserAuthDeptIds(currentUserId);
|
|
|
+ log.info("用户 {} 的权限范围: {}", currentUserId, userAuthDeptIds);
|
|
|
+
|
|
|
+ // 第三步:判断入参deptId是否在用户权限范围内
|
|
|
+ if (deptId != null && userAuthDeptIds.contains(deptId)) {
|
|
|
+ log.info("入参deptId {} 在用户权限范围内,不进行过滤", deptId);
|
|
|
+ // 在权限范围内,返回包含入参deptId及其子组织的列表
|
|
|
+ return getDeptIdsWithChildren(deptId);
|
|
|
+ } else {
|
|
|
+ log.info("入参deptId {} 不在用户权限范围内,进行权限过滤", deptId);
|
|
|
+ // 不在权限范围内,过滤deptIds,只保留在权限范围内的
|
|
|
+ List<Long> filteredDeptIds = new ArrayList<>();
|
|
|
+ if (deptId != null) {
|
|
|
+ // 如果入参deptId不为空,检查其子组织是否在权限范围内
|
|
|
+ List<Long> deptIdsWithChildren = getDeptIdsWithChildren(deptId);
|
|
|
+ for (Long deptIdWithChild : deptIdsWithChildren) {
|
|
|
+ if (userAuthDeptIds.contains(deptIdWithChild)) {
|
|
|
+ filteredDeptIds.add(deptIdWithChild);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果入参deptId为空,直接使用用户权限范围内的所有部门
|
|
|
+ filteredDeptIds.addAll(userAuthDeptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对过滤后的deptIds,查找所有子组织包括他们自己
|
|
|
+ Set<Long> finalDeptIds = new HashSet<>();
|
|
|
+ for (Long filteredDeptId : filteredDeptIds) {
|
|
|
+ List<Long> deptIdsWithChildren = getDeptIdsWithChildren(filteredDeptId);
|
|
|
+ finalDeptIds.addAll(deptIdsWithChildren);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ArrayList<>(finalDeptIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查用户是否为全校管理员
|
|
|
+ *
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @return 是否为全校管理员
|
|
|
+ */
|
|
|
+ private boolean checkIsSchoolManager(Long userId) {
|
|
|
+ LambdaQueryWrapper<XgStudentManager> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(XgStudentManager::getUserId, userId)
|
|
|
+ .eq(XgStudentManager::getDeleted, "0")
|
|
|
+ .eq(XgStudentManager::getStatus, "0")
|
|
|
+ .eq(XgStudentManager::getManagerType, "1");
|
|
|
+
|
|
|
+ return xgStudentManagerMapper.selectCount(lqw) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户的总权限集合
|
|
|
+ *
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @return 用户权限范围内的部门ID集合
|
|
|
+ */
|
|
|
+ private Set<Long> getUserAuthDeptIds(Long userId) {
|
|
|
+ Set<Long> authDeptIds = new HashSet<>();
|
|
|
+
|
|
|
+ // 第三步:通过xg_student_manager和xg_student_manager_source关联,获取用户的权限范围
|
|
|
+ LambdaQueryWrapper<XgStudentManager> managerWrapper = Wrappers.lambdaQuery();
|
|
|
+ managerWrapper.eq(XgStudentManager::getUserId, userId)
|
|
|
+ .eq(XgStudentManager::getDeleted, "0")
|
|
|
+ .eq(XgStudentManager::getStatus, "0");
|
|
|
+
|
|
|
+ List<XgStudentManager> managers = xgStudentManagerMapper.selectList(managerWrapper);
|
|
|
+
|
|
|
+ for (XgStudentManager manager : managers) {
|
|
|
+ LambdaQueryWrapper<XgStudentManagerSource> sourceWrapper = Wrappers.lambdaQuery();
|
|
|
+ sourceWrapper.eq(XgStudentManagerSource::getManagerId, manager.getId())
|
|
|
+ .eq(XgStudentManagerSource::getDeleted, "0")
|
|
|
+ .eq(XgStudentManagerSource::getStatus, "0");
|
|
|
+
|
|
|
+ List<XgStudentManagerSource> sources = xgStudentManagerSourceMapper.selectList(sourceWrapper);
|
|
|
+ for (XgStudentManagerSource source : sources) {
|
|
|
+ if (source.getAuthSource() != null) {
|
|
|
+ authDeptIds.add(source.getAuthSource());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第四步:通过xg_class_teacher_counselor_rel,teacher_id=当前登录人id,deleted=0,获取class_id
|
|
|
+ LambdaQueryWrapper<XgClassTeacherCounselorRel> relWrapper = Wrappers.lambdaQuery();
|
|
|
+ relWrapper.eq(XgClassTeacherCounselorRel::getTeacherId, userId)
|
|
|
+ .eq(XgClassTeacherCounselorRel::getDeleted, 0L);
|
|
|
+
|
|
|
+ List<XgClassTeacherCounselorRel> relations = xgClassTeacherCounselorRelMapper.selectList(relWrapper);
|
|
|
+ for (XgClassTeacherCounselorRel relation : relations) {
|
|
|
+ if (relation.getClassId() != null) {
|
|
|
+ authDeptIds.add(relation.getClassId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return authDeptIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门ID及其所有子组织的ID列表
|
|
|
+ *
|
|
|
+ * @param deptId 部门ID
|
|
|
+ * @return 包含部门ID及其子组织的ID列表
|
|
|
+ */
|
|
|
+ private List<Long> getDeptIdsWithChildren(Long deptId) {
|
|
|
List<Long> deptIds = new ArrayList<>();
|
|
|
- if (ObjectUtil.isNotNull(deptId)) {
|
|
|
+ if (deptId != null) {
|
|
|
deptIds.add(deptId); // 包含自己
|
|
|
|
|
|
// 查找所有子组织
|
|
|
@@ -79,18 +231,8 @@ public class XgClassPosMsgServiceImpl implements IXgClassPosMsgService {
|
|
|
.collect(Collectors.toList());
|
|
|
deptIds.addAll(childDeptIds);
|
|
|
}
|
|
|
-
|
|
|
- log.info("组织ID {} 及其子组织共 {} 个: {}", deptId, deptIds.size(), deptIds);
|
|
|
}
|
|
|
-
|
|
|
- // 构建查询条件
|
|
|
- LambdaQueryWrapper<XgClassPosMsg> lqw = buildQueryWrapper(bo, deptIds);
|
|
|
- // 使用XML配置的联表查询方法,确保能获取到班级名称和职务名称
|
|
|
- Page<XgClassPosMsgVo> result = baseMapper.selectVoPageWithJoin(pageQuery.build(), lqw);
|
|
|
-
|
|
|
- log.info("查询到班级干部信息 {} 条,使用XML配置的联表查询", result.getTotal());
|
|
|
-
|
|
|
- return TableDataInfo.build(result);
|
|
|
+ return deptIds;
|
|
|
}
|
|
|
|
|
|
/**
|