zlwu 1 год назад
Родитель
Сommit
be63faf496

+ 27 - 9
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgClassPosMsgServiceImpl.java

@@ -29,7 +29,8 @@ import org.dromara.xg.mapper.XgStudentManagerSourceMapper;
 import org.dromara.xg.mapper.XgClassTeacherCounselorRelMapper;
 import org.dromara.xg.mapper.XgClassTeacherCounselorRelMapper;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.satoken.utils.LoginHelper;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
-
+import org.dromara.xg.domain.XgClassMsg;
+import org.dromara.xg.mapper.XgClassMsgMapper;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.ArrayList;
 import java.util.ArrayList;
@@ -56,6 +57,7 @@ public class XgClassPosMsgServiceImpl implements IXgClassPosMsgService {
     private final XgStudentManagerMapper xgStudentManagerMapper;
     private final XgStudentManagerMapper xgStudentManagerMapper;
     private final XgStudentManagerSourceMapper xgStudentManagerSourceMapper;
     private final XgStudentManagerSourceMapper xgStudentManagerSourceMapper;
     private final XgClassTeacherCounselorRelMapper xgClassTeacherCounselorRelMapper;
     private final XgClassTeacherCounselorRelMapper xgClassTeacherCounselorRelMapper;
+    private final XgClassMsgMapper xgClassMsgMapper;
 
 
     /**
     /**
      * 查询班级干部信息
      * 查询班级干部信息
@@ -197,15 +199,31 @@ public class XgClassPosMsgServiceImpl implements IXgClassPosMsgService {
             }
             }
         }
         }
 
 
+        // //
         // 第四步:通过xg_class_teacher_counselor_rel,teacher_id=当前登录人id,deleted=0,获取class_id
         // 第四步:通过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());
+        // LambdaQueryWrapper<XgClassTeacherCounselorRel> relWrapper =
+        // Wrappers.lambdaQuery();
+        // relWrapper.eq(XgClassTeacherCounselorRel::getTeacherId, userId)
+        // .eq(XgClassTeacherCounselorRel::getTeacherType, "class_teacher")
+        // .eq(XgClassTeacherCounselorRel::getDeleted, 0L);
+
+        // List<XgClassTeacherCounselorRel> relations =
+        // xgClassTeacherCounselorRelMapper.selectList(relWrapper);
+        // for (XgClassTeacherCounselorRel relation : relations) {
+        // if (relation.getClassId() != null) {
+        // authDeptIds.add(relation.getClassId());
+        // }
+        // }
+        // 第四步:通过xg_class_msg表,class_teacher_id=当前登录人id,deleted='0',class_status='1',获取id
+        LambdaQueryWrapper<XgClassMsg> classWrapper = Wrappers.lambdaQuery();
+        classWrapper.eq(XgClassMsg::getClassTeacherId, userId)
+                .eq(XgClassMsg::getDeleted, 0L)
+                .eq(XgClassMsg::getClassStatus, "1");
+
+        List<XgClassMsg> classes = xgClassMsgMapper.selectList(classWrapper);
+        for (XgClassMsg classMsg : classes) {
+            if (classMsg.getId() != null) {
+                authDeptIds.add(classMsg.getId());
             }
             }
         }
         }
 
 

+ 182 - 9
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgStudentMsgBatchServiceImpl.java

@@ -21,7 +21,26 @@ import org.dromara.xg.mapper.XgStudentMsgMapper;
 import org.dromara.xg.service.IXgStudentMsgBatchService;
 import org.dromara.xg.service.IXgStudentMsgBatchService;
 import org.dromara.system.service.ISysUserService;
 import org.dromara.system.service.ISysUserService;
 import org.dromara.xg.service.IXgStudentMsgService;
 import org.dromara.xg.service.IXgStudentMsgService;
-
+import org.dromara.xg.mapper.XgStudentManagerMapper;
+import org.dromara.xg.mapper.XgStudentManagerSourceMapper;
+import org.dromara.xg.mapper.XgClassTeacherCounselorRelMapper;
+import org.dromara.xg.mapper.XgClassMsgMapper;
+import org.dromara.xg.domain.XgStudentManager;
+import org.dromara.xg.domain.XgStudentManagerSource;
+import org.dromara.xg.domain.XgClassTeacherCounselorRel;
+import org.dromara.xg.domain.XgClassMsg;
+import org.dromara.common.satoken.utils.LoginHelper;
+import java.util.stream.Collectors;
+import org.dromara.system.domain.SysDept;
+import org.dromara.system.mapper.SysDeptMapper;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Set;
+import java.util.HashSet;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Collection;
 import java.util.Collection;
@@ -45,6 +64,11 @@ public class XgStudentMsgBatchServiceImpl implements IXgStudentMsgBatchService {
     private final XgStudentMsgMapper xgStudentMsgMapper;
     private final XgStudentMsgMapper xgStudentMsgMapper;
     private final ISysUserService sysUserService;
     private final ISysUserService sysUserService;
     private final IXgStudentMsgService xgStudentMsgService;
     private final IXgStudentMsgService xgStudentMsgService;
+    private final XgStudentManagerMapper xgStudentManagerMapper;
+    private final XgStudentManagerSourceMapper xgStudentManagerSourceMapper;
+    private final XgClassTeacherCounselorRelMapper xgClassTeacherCounselorRelMapper;
+    private final XgClassMsgMapper xgClassMsgMapper;
+    private final SysDeptMapper sysDeptMapper;
 
 
     /**
     /**
      * 查询学生信息批次收集
      * 查询学生信息批次收集
@@ -853,27 +877,176 @@ public class XgStudentMsgBatchServiceImpl implements IXgStudentMsgBatchService {
     public TableDataInfo<XgStudentMsgBatchVo> queryPageListByDeptId(Long batchId, Long deptId, String name,
     public TableDataInfo<XgStudentMsgBatchVo> queryPageListByDeptId(Long batchId, Long deptId, String name,
             String studentNo, String phone, String infoStatus, PageQuery pageQuery) {
             String studentNo, String phone, String infoStatus, PageQuery pageQuery) {
         // 第一步:根据deptId查询所有子部门ID(包括自己)
         // 第一步:根据deptId查询所有子部门ID(包括自己)
-        List<Long> deptIds = baseMapper.selectChildDeptIds(deptId);
+        // List<Long> deptIds = baseMapper.selectChildDeptIds(deptId);
 
 
-        if (deptIds == null || deptIds.isEmpty()) {
-            log.warn("部门ID: {} 没有找到任何子部门或自身不存在", deptId);
-            // 返回空的分页结果
-            return TableDataInfo.build(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>());
-        }
+        // if (deptIds == null || deptIds.isEmpty()) {
+        // log.warn("部门ID: {} 没有找到任何子部门或自身不存在", deptId);
+        // // 返回空的分页结果
+        // return TableDataInfo.build(new
+        // com.baomidou.mybatisplus.extension.plugins.pagination.Page<>());
+        // }
+
+        // log.info("部门ID: {} 查询到的子部门列表: {}", deptId, deptIds);
+
+        // 调用权限过滤方法,获取过滤后的deptIds
+        List<Long> filteredDeptIds = filterDeptIdsByPermission(deptId);
 
 
-        log.info("部门ID: {} 查询到的子部门列表: {}", deptId, deptIds);
+        log.info("权限过滤后的部门ID列表: {}", filteredDeptIds);
 
 
         // 第二步:根据部门ID列表和条件分页查询学生信息批次数据
         // 第二步:根据部门ID列表和条件分页查询学生信息批次数据
         com.baomidou.mybatisplus.extension.plugins.pagination.Page<XgStudentMsgBatchVo> page = pageQuery
         com.baomidou.mybatisplus.extension.plugins.pagination.Page<XgStudentMsgBatchVo> page = pageQuery
                 .build();
                 .build();
         com.baomidou.mybatisplus.extension.plugins.pagination.Page<XgStudentMsgBatchVo> result = baseMapper
         com.baomidou.mybatisplus.extension.plugins.pagination.Page<XgStudentMsgBatchVo> result = baseMapper
-                .selectPageByDeptIds(page, batchId, deptIds, name, studentNo, phone, infoStatus);
+                .selectPageByDeptIds(page, batchId, filteredDeptIds, name, studentNo, phone, infoStatus);
 
 
         log.info("根据部门ID: {} 和批次ID: {} 查询到 {} 条学生数据", deptId, batchId, result.getTotal());
         log.info("根据部门ID: {} 和批次ID: {} 查询到 {} 条学生数据", deptId, batchId, result.getTotal());
 
 
         return TableDataInfo.build(result);
         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_msg表,class_teacher_id=当前登录人id,deleted='0',class_status='1',获取id
+        LambdaQueryWrapper<XgClassMsg> classWrapper = Wrappers.lambdaQuery();
+        classWrapper.eq(XgClassMsg::getClassTeacherId, userId)
+                .eq(XgClassMsg::getDeleted, 0L)
+                .eq(XgClassMsg::getClassStatus, "1");
+
+        List<XgClassMsg> classes = xgClassMsgMapper.selectList(classWrapper);
+        for (XgClassMsg classMsg : classes) {
+            if (classMsg.getId() != null) {
+                authDeptIds.add(classMsg.getId());
+            }
+        }
+
+        return authDeptIds;
+    }
+
+    /**
+     * 获取部门ID及其所有子组织的ID列表
+     *
+     * @param deptId 部门ID
+     * @return 包含部门ID及其子组织的ID列表
+     */
+    private List<Long> getDeptIdsWithChildren(Long deptId) {
+        List<Long> deptIds = new ArrayList<>();
+        if (deptId != null) {
+            deptIds.add(deptId); // 包含自己
+
+            // 查找所有子组织
+            List<SysDept> childDepts = sysDeptMapper.selectListByParentId(deptId);
+            if (!childDepts.isEmpty()) {
+                List<Long> childDeptIds = childDepts.stream()
+                        .map(SysDept::getDeptId)
+                        .collect(Collectors.toList());
+                deptIds.addAll(childDeptIds);
+            }
+        }
+        return deptIds;
+    }
+
     /**
     /**
      * 驳回学生信息提交
      * 驳回学生信息提交
      *
      *

+ 171 - 11
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgStudentMsgServiceImpl.java

@@ -29,6 +29,25 @@ import java.util.Collection;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.xg.mapper.XgStudentManagerMapper;
+import org.dromara.xg.mapper.XgStudentManagerSourceMapper;
+import org.dromara.xg.mapper.XgClassTeacherCounselorRelMapper;
+import org.dromara.xg.mapper.XgClassMsgMapper;
+import org.dromara.xg.domain.XgStudentManager;
+import org.dromara.xg.domain.XgStudentManagerSource;
+import org.dromara.xg.domain.XgClassTeacherCounselorRel;
+import org.dromara.xg.domain.XgClassMsg;
+import org.dromara.common.satoken.utils.LoginHelper;
+import java.util.stream.Collectors;
+
+import java.util.List;
+import java.util.Map;
+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业务层处理
  * 学生信息Service业务层处理
@@ -44,6 +63,10 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
     private final XgStudentMsgMapper baseMapper;
     private final XgStudentMsgMapper baseMapper;
     private final ISysUserService sysUserService;
     private final ISysUserService sysUserService;
     private final SysDeptMapper sysDeptMapper;
     private final SysDeptMapper sysDeptMapper;
+    private final XgStudentManagerMapper xgStudentManagerMapper;
+    private final XgStudentManagerSourceMapper xgStudentManagerSourceMapper;
+    private final XgClassTeacherCounselorRelMapper xgClassTeacherCounselorRelMapper;
+    private final XgClassMsgMapper xgClassMsgMapper;
 
 
     /**
     /**
      * 查询学生信息
      * 查询学生信息
@@ -93,11 +116,156 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
     @Override
     @Override
     public TableDataInfo<XgStudentMsgVo> queryPageListByDeptId(XgStudentMsgBo bo, Map<String, Object> params,
     public TableDataInfo<XgStudentMsgVo> queryPageListByDeptId(XgStudentMsgBo bo, Map<String, Object> params,
             PageQuery pageQuery) {
             PageQuery pageQuery) {
-        // 第一步:获取dept_id并查找所有子组织
+        // 第一步:调用权限过滤方法,获取过滤后的deptIds
         List<Long> deptIds = new ArrayList<>();
         List<Long> deptIds = new ArrayList<>();
         Object deptIdObj = params.get("dept_id");
         Object deptIdObj = params.get("dept_id");
+        Long deptId = null;
         if (ObjectUtil.isNotNull(deptIdObj)) {
         if (ObjectUtil.isNotNull(deptIdObj)) {
-            Long deptId = Long.valueOf(deptIdObj.toString());
+            deptId = Long.valueOf(deptIdObj.toString());
+        }
+
+        // 调用权限过滤方法,获取过滤后的deptIds
+        List<Long> filteredDeptIds = filterDeptIdsByPermission(deptId);
+
+        log.info("权限过滤后的部门ID列表: {}", filteredDeptIds);
+
+        // 第二步:构建查询条件
+        LambdaQueryWrapper<XgStudentMsg> lqw = buildQueryWrapperForDeptQuery(bo);
+
+        // 第三步:分页查询学生信息
+        Page<XgStudentMsgVo> result = baseMapper.selectPageByDeptIds(pageQuery.build(), lqw, filteredDeptIds);
+        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_msg表,class_teacher_id=当前登录人id,deleted='0',class_status='1',获取id
+        LambdaQueryWrapper<XgClassMsg> classWrapper = Wrappers.lambdaQuery();
+        classWrapper.eq(XgClassMsg::getClassTeacherId, userId)
+                .eq(XgClassMsg::getDeleted, 0L)
+                .eq(XgClassMsg::getClassStatus, "1");
+
+        List<XgClassMsg> classes = xgClassMsgMapper.selectList(classWrapper);
+        for (XgClassMsg classMsg : classes) {
+            if (classMsg.getId() != null) {
+                authDeptIds.add(classMsg.getId());
+            }
+        }
+
+        return authDeptIds;
+    }
+
+    /**
+     * 获取部门ID及其所有子组织的ID列表
+     *
+     * @param deptId 部门ID
+     * @return 包含部门ID及其子组织的ID列表
+     */
+    private List<Long> getDeptIdsWithChildren(Long deptId) {
+        List<Long> deptIds = new ArrayList<>();
+        if (deptId != null) {
             deptIds.add(deptId); // 包含自己
             deptIds.add(deptId); // 包含自己
 
 
             // 查找所有子组织
             // 查找所有子组织
@@ -108,16 +276,8 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
                         .collect(Collectors.toList());
                         .collect(Collectors.toList());
                 deptIds.addAll(childDeptIds);
                 deptIds.addAll(childDeptIds);
             }
             }
-
-            log.info("组织ID {} 及其子组织共 {} 个: {}", deptId, deptIds.size(), deptIds);
         }
         }
-
-        // 第二步:构建查询条件
-        LambdaQueryWrapper<XgStudentMsg> lqw = buildQueryWrapperForDeptQuery(bo);
-
-        // 第三步:分页查询学生信息
-        Page<XgStudentMsgVo> result = baseMapper.selectPageByDeptIds(pageQuery.build(), lqw, deptIds);
-        return TableDataInfo.build(result);
+        return deptIds;
     }
     }
 
 
     /**
     /**

+ 88 - 1
docs/变更管理/code-adjust-record-2025-01-27-cursor.md

@@ -240,4 +240,91 @@ collegeName: string;
 **验证方法**:
 **验证方法**:
 1. 启动后端服务,测试班级干部信息查询接口
 1. 启动后端服务,测试班级干部信息查询接口
 2. 检查返回数据是否包含专业和学院信息
 2. 检查返回数据是否包含专业和学院信息
-3. 验证前端页面是否正确显示新增字段 
+3. 验证前端页面是否正确显示新增字段 
+
+## 变更概述
+修改 `XgStudentMsgServiceImpl.getUserAuthDeptIds` 方法中的第四步权限获取逻辑,从 `xg_class_teacher_counselor_rel` 表改为从 `xg_class_msg` 表获取权限信息。
+
+## 变更详情
+
+### 修改文件
+- `backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgStudentMsgServiceImpl.java`
+
+### 变更内容
+
+#### 1. 添加依赖注入
+- 添加 `XgClassMsgMapper` 的导入
+- 添加 `XgClassMsg` 实体类的导入
+- 在类字段中添加 `XgClassMsgMapper` 的依赖注入
+
+#### 2. 修改权限获取逻辑
+**原逻辑(第四步)**:
+```java
+// 第四步:通过xg_class_teacher_counselor_rel,teacher_id=当前登录人id,deleted=0,获取class_id
+LambdaQueryWrapper<XgClassTeacherCounselorRel> relWrapper = Wrappers.lambdaQuery();
+relWrapper.eq(XgClassTeacherCounselorRel::getTeacherId, userId)
+        .eq(XgClassTeacherCounselorRel::getTeacherType, "class_teacher")
+        .eq(XgClassTeacherCounselorRel::getDeleted, 0L);
+
+List<XgClassTeacherCounselorRel> relations = xgClassTeacherCounselorRelMapper.selectList(relWrapper);
+for (XgClassTeacherCounselorRel relation : relations) {
+    if (relation.getClassId() != null) {
+        authDeptIds.add(relation.getClassId());
+    }
+}
+```
+
+**新逻辑(第四步)**:
+```java
+// 第四步:通过xg_class_msg表,class_teacher_id=当前登录人id,deleted='0',class_status='1',获取id
+LambdaQueryWrapper<XgClassMsg> classWrapper = Wrappers.lambdaQuery();
+classWrapper.eq(XgClassMsg::getClassTeacherId, userId)
+        .eq(XgClassMsg::getDeleted, 0L)
+        .eq(XgClassMsg::getClassStatus, "1");
+
+List<XgClassMsg> classes = xgClassMsgMapper.selectList(classWrapper);
+for (XgClassMsg classMsg : classes) {
+    if (classMsg.getId() != null) {
+        authDeptIds.add(classMsg.getId());
+    }
+}
+```
+
+### 变更原因
+根据用户需求,将权限获取方式从关联表查询改为直接从班级信息表查询,提高查询效率并简化逻辑。
+
+### SQL查询对比
+**原SQL逻辑**:
+```sql
+SELECT class_id FROM xg_class_teacher_counselor_rel 
+WHERE teacher_id = 当前登录人id 
+AND deleted = 0 
+AND teacher_type = 'class_teacher'
+```
+
+**新SQL逻辑**:
+```sql
+SELECT id FROM xg_class_msg 
+WHERE class_teacher_id = 当前登录人id 
+AND deleted = '0' 
+AND class_status = '1'
+```
+
+### 影响范围
+- 学生信息管理模块的权限过滤功能
+- 班主任权限范围内的学生信息查询
+- 组织架构相关的权限控制
+
+### 测试建议
+1. 验证班主任用户登录后能正确获取其管理的班级权限
+2. 验证学生信息查询功能在权限过滤后正常工作
+3. 确认全校管理员权限不受影响
+
+## 变更时间
+2025-01-27 14:30:00
+
+## 变更人员
+Cursor AI
+
+## 备注
+此次变更是对权限获取逻辑的优化,从多表关联查询改为单表直接查询,提高了查询效率。 

+ 4 - 4
web/src/views/stuMsgAudit/auditDialog.vue

@@ -484,10 +484,10 @@ const handleNodeClick = (data: any) => {
   // alert(1);
   // alert(1);
   // console.log('handleNodeClick', data);
   // console.log('handleNodeClick', data);
   // 只有班级节点才可以点击(disabled=false的节点)
   // 只有班级节点才可以点击(disabled=false的节点)
-  if (data.disabled) {
-    ElMessage.warning('没有该节点权限,请联系管理员');
-    return;
-  }
+  // if (data.disabled) {
+  //   ElMessage.warning('没有该节点权限,请联系管理员');
+  //   return;
+  // }
   // 保存当前选中的节点信息
   // 保存当前选中的节点信息
   currentSelectedNode.value = data;
   currentSelectedNode.value = data;
   queryParams.deptId = data.id;
   queryParams.deptId = data.id;

+ 5 - 4
web/src/views/studentMsg/studentMsg/index.vue

@@ -2029,10 +2029,11 @@ const getDormBuildingTree = async () => {
 /** 节点单击事件 */
 /** 节点单击事件 */
 const handleNodeClick = (data: any) => {
 const handleNodeClick = (data: any) => {
   // 只有班级节点才可以点击(disabled=false的节点)
   // 只有班级节点才可以点击(disabled=false的节点)
-  if (data.disabled) {
-    ElMessage.warning('没有该节点权限,请联系管理员');
-    return;
-  }
+  // if (data.disabled) {
+  //   ElMessage.warning('没有该节点权限,请联系管理员');
+  //   return;
+  // }
+
   // 保存当前选中的节点信息
   // 保存当前选中的节点信息
   currentSelectedNode.value = data;
   currentSelectedNode.value = data;
   queryParams.deptId = data.id;
   queryParams.deptId = data.id;