提交代码

This commit is contained in:
zlwu committed 2025-08-13 05:03:06 +08:00
1 parent c3735b0ac1
commit 8374ab31b1
20 files changed
+1452 -303

No files matched your search

@@ -18,6 +18,7 @@ import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xg.domain.vo.XgDormBedVo;
import org.dromara.xg.domain.vo.XgDormBedDetailVo;
import org.dromara.xg.domain.bo.XgDormBedBo;
import org.dromara.xg.service.IXgDormBedService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -63,8 +64,7 @@ public class XgDormBedController extends BaseController {
*/
@SaCheckPermission("dormbed:dormBed:query")
@GetMapping("/{id}")
public R<XgDormBedVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long id) {
public R<XgDormBedVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
return R.ok(xgDormBedService.queryById(id));
}
@@ -98,8 +98,32 @@ public class XgDormBedController extends BaseController {
@SaCheckPermission("dormbed:dormBed:remove")
@Log(title = "宿舍床位信息", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public R<Void> remove(@NotEmpty(message = "主键不能为空")
@PathVariable Long[] ids) {
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
return toAjax(xgDormBedService.deleteWithValidByIds(List.of(ids), true));
}
/**
* 查询指定房间的床位详细信息列表(包含学生信息)
*
* @param roomId 房间ID
*/
@SaCheckPermission("dormbed:dormBed:query")
@GetMapping("/details/room/{roomId}")
public R<List<XgDormBedDetailVo>> getBedDetailsByRoomId(@NotNull(message = "房间ID不能为空") @PathVariable Long roomId) {
List<XgDormBedDetailVo> list = xgDormBedService.queryBedDetailsByRoomId(roomId);
return R.ok(list);
}
/**
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
*
* @param buildingId 宿舍楼ID
*/
@SaCheckPermission("dormbed:dormBed:query")
@GetMapping("/details/building/{buildingId}")
public R<List<XgDormBedDetailVo>> getBedDetailsByBuildingId(
@NotNull(message = "宿舍楼ID不能为空") @PathVariable Long buildingId) {
List<XgDormBedDetailVo> list = xgDormBedService.queryBedDetailsByBuildingId(buildingId);
return R.ok(list);
}
}
@@ -33,6 +33,7 @@ import org.dromara.common.excel.core.ExcelResult;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.xg.domain.vo.XgStudentMsgExportVo;
import org.dromara.xg.domain.vo.XgStudentMsgImportVo;
import org.dromara.xg.domain.vo.XgStudentTreeVo;
import org.dromara.xg.listener.XgStudentMsgImportListener;
import org.dromara.common.excel.service.BaseExportService;
import org.dromara.common.excel.convert.ExcelDictPreloadConvert;
@@ -1274,4 +1275,15 @@ public class XgStudentMsgController extends BaseController {
xgStudentMsgService.batchCancelBed(studentIds);
return R.ok();
}
/**
* 获取学生信息树(二级学院下的学院、专业、班级统计信息)
*/
@SaCheckPermission("studentMsg:studentMsg:list")
@GetMapping("/getStudentTree")
public R<List<XgStudentTreeVo>> getStudentTree(@RequestParam(defaultValue = "101") Long secondaryCollegeId) {
log.info("获取学生信息树,二级学院ID: {}", secondaryCollegeId);
List<XgStudentTreeVo> studentTree = xgStudentMsgService.getStudentTree(secondaryCollegeId);
return R.ok(studentTree);
}
}
@@ -0,0 +1,202 @@
package org.dromara.xg.domain.vo;
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 宿舍床位详细信息视图对象 XgDormBedDetailVo
* 包含床位基本信息和分配的学生详细信息
*
* @author zlwu
* @date 2025-01-27
*/
@Data
@ExcelIgnoreUnannotated
public class XgDormBedDetailVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
// =============== 床位基本信息 ===============
/**
* 床位主键ID
*/
@ExcelProperty(value = "床位ID")
private Long id;
/**
* 床位编号
*/
@ExcelProperty(value = "床位编号")
private String bedCode;
/**
* 床位名称
*/
@ExcelProperty(value = "床位名称")
private String bedName;
/**
* 所属房间ID
*/
@ExcelProperty(value = "房间ID")
private Long roomId;
/**
* 房间名称
*/
@ExcelProperty(value = "房间名称")
private String roomName;
/**
* 床位类型(1下铺 2上铺 3中铺 4独立床)
*/
@ExcelProperty(value = "床位类型")
private String bedType;
/**
* 床位状态(0空闲 1已分配 2维修中)
*/
@ExcelProperty(value = "床位状态")
private String bedStatus;
/**
* 床位备注
*/
@ExcelProperty(value = "床位备注")
private String bedRemark;
// =============== 分配信息 ===============
/**
* 分配关系ID
*/
private Long assignmentId;
/**
* 分配时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date assignTime;
/**
* 分配状态(0正常 1已退宿)
*/
private String assignmentStatus;
// =============== 学院信息 ===============
/**
* 学院ID
*/
@ExcelProperty(value = "学院ID")
private Long collegeId;
/**
* 学院名称
*/
@ExcelProperty(value = "学院名称")
private String collegeName;
// =============== 专业信息 ===============
/**
* 专业ID
*/
@ExcelProperty(value = "专业ID")
private Long majorId;
/**
* 专业名称
*/
@ExcelProperty(value = "专业名称")
private String majorName;
// =============== 班级信息 ===============
/**
* 班级ID
*/
@ExcelProperty(value = "班级ID")
private Long classId;
/**
* 班级名称
*/
@ExcelProperty(value = "班级名称")
private String className;
/**
* 班级代码
*/
@ExcelProperty(value = "班级代码")
private String classCode;
/**
* 年级
*/
@ExcelProperty(value = "年级")
private String grade;
// =============== 学生信息 ===============
/**
* 学生ID
*/
@ExcelProperty(value = "学生ID")
private Long studentId;
/**
* 学号
*/
@ExcelProperty(value = "学号")
private String studentNo;
/**
* 学生姓名
*/
@ExcelProperty(value = "学生姓名")
private String studentName;
/**
* 学生性别(0男 1女)
*/
@ExcelProperty(value = "性别")
private String studentGender;
/**
* 学生手机号
*/
@ExcelProperty(value = "手机号")
private String studentPhone;
/**
* 身份证号
*/
@ExcelProperty(value = "身份证号")
private String studentIdCard;
// =============== 基础字段 ===============
/**
* 创建者
*/
private Long createBy;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新者
*/
private Long updateBy;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}
@@ -0,0 +1,100 @@
package org.dromara.xg.domain.vo;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
/**
* 学生信息树视图对象 Student Tree VO
*
* @author zlwu
* @date 2025-01-03
*/
@Data
public class XgStudentTreeVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 节点ID
*/
private String id;
/**
* 节点显示名称
*/
private String label;
/**
* 节点类型:grade-年级、college-学院、major-专业、class-班级
*/
private String type;
/**
* 已分配男生数
*/
private Integer maleAssigned;
/**
* 男生总数
*/
private Integer maleTotal;
/**
* 已分配女生数
*/
private Integer femaleAssigned;
/**
* 女生总数
*/
private Integer femaleTotal;
/**
* 年级
*/
private String grade;
/**
* 学院ID
*/
private Long collegeId;
/**
* 学院名称
*/
private String collegeName;
/**
* 专业ID
*/
private Long majorId;
/**
* 专业名称
*/
private String majorName;
/**
* 班级ID
*/
private Long classId;
/**
* 班级名称
*/
private String className;
/**
* 排序权重
*/
private Integer sortOrder;
/**
* 子节点列表
*/
private List<XgStudentTreeVo> children;
}
@@ -2,7 +2,12 @@ package org.dromara.xg.mapper;
import org.dromara.xg.domain.XgDormBed;
import org.dromara.xg.domain.vo.XgDormBedVo;
import org.dromara.xg.domain.vo.XgDormBedDetailVo;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 宿舍床位信息Mapper接口
@@ -12,4 +17,110 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
*/
public interface XgDormBedMapper extends BaseMapperPlus<XgDormBed, XgDormBedVo> {
/**
* 查询指定房间的床位详细信息列表(包含学生信息)
*
* @param roomId 房间ID
* @return 床位详细信息列表
*/
@Select("""
SELECT
b.id,
b.bed_code,
b.bed_name,
b.room_id,
r.room_name,
b.bed_type,
b.bed_status,
b.remark as bed_remark,
b.create_by,
b.create_time,
b.update_by,
b.update_time,
bs.id as assignment_id,
bs.assign_time,
bs.status as assignment_status,
bs.college_id,
c.college_name,
bs.major_id,
c.major_name,
bs.class_id,
c.class_name,
c.class_code,
c.grade,
bs.student_id,
s.student_no,
s.name as student_name,
s.gender as student_gender,
s.phone as student_phone,
s.id_card as student_id_card
FROM xg_dorm_bed b
LEFT JOIN xg_dorm_room r ON b.room_id = r.id
LEFT JOIN xg_dorm_bed_student bs ON b.id = bs.bed_id AND bs.status = '0' AND bs.deleted = '0'
LEFT JOIN xg_class_msg c ON bs.class_id = c.id AND c.deleted = 0
LEFT JOIN xg_student_msg s ON bs.student_id = s.id AND s.deleted = 0
WHERE b.room_id = #{roomId}
AND b.deleted = '0'
ORDER BY b.bed_code
""")
List<XgDormBedDetailVo> selectBedDetailsByRoomId(@Param("roomId") Long roomId);
/**
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
*
* @param buildingId 宿舍楼ID
* @return 床位详细信息列表
*/
@Select("""
SELECT
b.id,
b.bed_code,
b.bed_name,
b.room_id,
r.room_name,
b.bed_type,
b.bed_status,
b.remark as bed_remark,
b.create_by,
b.create_time,
b.update_by,
b.update_time,
bs.id as assignment_id,
bs.assign_time,
bs.status as assignment_status,
bs.college_id,
c.college_name,
bs.major_id,
c.major_name,
bs.class_id,
c.class_name,
c.class_code,
c.grade,
bs.student_id,
s.student_no,
s.name as student_name,
s.gender as student_gender,
s.phone as student_phone,
s.id_card as student_id_card
FROM xg_dorm_bed b
LEFT JOIN xg_dorm_room r ON b.room_id = r.id
LEFT JOIN xg_dorm_bed_student bs ON b.id = bs.bed_id AND bs.status = '0' AND bs.deleted = '0'
LEFT JOIN xg_class_msg c ON bs.class_id = c.id AND c.deleted = 0
LEFT JOIN xg_student_msg s ON bs.student_id = s.id AND s.deleted = 0
WHERE r.building_id = #{buildingId}
AND b.deleted = '0'
ORDER BY r.room_name, b.bed_code
""")
List<XgDormBedDetailVo> selectBedDetailsByBuildingId(@Param("buildingId") Long buildingId);
}
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 学生信息Mapper接口
@@ -77,4 +78,12 @@ public interface XgStudentMsgMapper extends BaseMapperPlus<XgStudentMsg, XgStude
List<Long> selectUserIdsByCollegeIdAndRoleKey(@Param("collegeId") Long collegeId,
@Param("roleKey") String roleKey);
/**
* 查询二级学院下的学院、专业、班级学生统计信息
*
* @param secondaryCollegeId 二级学院ID
* @return 学生统计信息列表
*/
List<Map<String, Object>> getCollegeStudentStats(@Param("secondaryCollegeId") Long secondaryCollegeId);
}
@@ -1,6 +1,7 @@
package org.dromara.xg.service;
import org.dromara.xg.domain.vo.XgDormBedVo;
import org.dromara.xg.domain.vo.XgDormBedDetailVo;
import org.dromara.xg.domain.bo.XgDormBedBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
@@ -65,4 +66,20 @@ public interface IXgDormBedService {
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 查询指定房间的床位详细信息列表(包含学生信息)
*
* @param roomId 房间ID
* @return 床位详细信息列表
*/
List<XgDormBedDetailVo> queryBedDetailsByRoomId(Long roomId);
/**
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
*
* @param buildingId 宿舍楼ID
* @return 床位详细信息列表
*/
List<XgDormBedDetailVo> queryBedDetailsByBuildingId(Long buildingId);
}
@@ -2,6 +2,7 @@ package org.dromara.xg.service;
import org.dromara.xg.domain.vo.XgStudentMsgExportVo;
import org.dromara.xg.domain.vo.XgStudentMsgVo;
import org.dromara.xg.domain.vo.XgStudentTreeVo;
import org.dromara.xg.domain.bo.XgStudentMsgBo;
import org.dromara.xg.domain.bo.XgStudentMsgAdvancedSearchBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -152,4 +153,12 @@ public interface IXgStudentMsgService {
* @param studentIds 学生ID列表
*/
void batchCancelBed(List<Long> studentIds);
/**
* 获取学生信息树(二级学院下的学院、专业、班级统计信息)
*
* @param secondaryCollegeId 二级学院ID,默认101
* @return 学生信息树
*/
List<XgStudentTreeVo> getStudentTree(Long secondaryCollegeId);
}
@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.dromara.xg.domain.bo.XgDormBedBo;
import org.dromara.xg.domain.vo.XgDormBedVo;
import org.dromara.xg.domain.vo.XgDormBedDetailVo;
import org.dromara.xg.domain.XgDormBed;
import org.dromara.xg.mapper.XgDormBedMapper;
import org.dromara.xg.service.IXgDormBedService;
@@ -134,4 +135,26 @@ public class XgDormBedServiceImpl implements IXgDormBedService {
}
return baseMapper.deleteByIds(ids) > 0;
}
/**
* 查询指定房间的床位详细信息列表(包含学生信息)
*
* @param roomId 房间ID
* @return 床位详细信息列表
*/
@Override
public List<XgDormBedDetailVo> queryBedDetailsByRoomId(Long roomId) {
return baseMapper.selectBedDetailsByRoomId(roomId);
}
/**
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
*
* @param buildingId 宿舍楼ID
* @return 床位详细信息列表
*/
@Override
public List<XgDormBedDetailVo> queryBedDetailsByBuildingId(Long buildingId) {
return baseMapper.selectBedDetailsByBuildingId(buildingId);
}
}
@@ -15,6 +15,7 @@ import org.dromara.xg.domain.bo.XgStudentMsgBo;
import org.dromara.xg.domain.bo.XgStudentMsgAdvancedSearchBo;
import org.dromara.xg.domain.vo.XgStudentMsgExportVo;
import org.dromara.xg.domain.vo.XgStudentMsgVo;
import org.dromara.xg.domain.vo.XgStudentTreeVo;
import org.dromara.xg.domain.XgStudentMsg;
import org.dromara.xg.mapper.XgStudentMsgMapper;
import org.dromara.xg.service.IXgStudentMsgService;
@@ -1156,4 +1157,164 @@ public class XgStudentMsgServiceImpl implements IXgStudentMsgService {
int bedUpdateCount = xgDormBedStudentMapper.update(bedUpdateEntity, bedUpdateWrapper);
log.info("批量取消床位 - 更新宿舍床位状态完成,共更新 {} 条床位记录", bedUpdateCount);
}
/**
* 获取学生信息树(二级学院下的学院、专业、班级统计信息)
*
* @param secondaryCollegeId 二级学院ID,默认101
* @return 学生信息树
*/
@Override
public List<XgStudentTreeVo> getStudentTree(Long secondaryCollegeId) {
log.info("开始构建学生信息树,二级学院ID: {}", secondaryCollegeId);
List<XgStudentTreeVo> result = new ArrayList<>();
try {
// 1. 查询二级学院下的所有学院信息,并统计男女生人数
List<Map<String, Object>> collegeStats = baseMapper.getCollegeStudentStats(secondaryCollegeId);
log.info("查询到 {} 个学院", collegeStats.size());
// 按学院分组
Map<String, List<Map<String, Object>>> collegeMap = collegeStats.stream()
.collect(Collectors.groupingBy(item -> {
Object collegeIdObj = item.get("college_id");
Long collegeId = collegeIdObj instanceof Long ? (Long) collegeIdObj
: Long.valueOf(collegeIdObj.toString());
String collegeName = (String) item.get("college_name");
return collegeId + "_" + collegeName;
}));
// 2. 构建学院节点
for (Map.Entry<String, List<Map<String, Object>>> collegeEntry : collegeMap.entrySet()) {
String collegeKey = collegeEntry.getKey();
List<Map<String, Object>> collegeMajors = collegeEntry.getValue();
if (!collegeMajors.isEmpty()) {
Map<String, Object> firstItem = collegeMajors.get(0);
Object collegeIdObj = firstItem.get("college_id");
Long collegeId = collegeIdObj instanceof Long ? (Long) collegeIdObj
: Long.valueOf(collegeIdObj.toString());
String collegeName = (String) firstItem.get("college_name");
XgStudentTreeVo collegeNode = new XgStudentTreeVo();
collegeNode.setId("college-" + collegeId);
collegeNode.setLabel(collegeName);
collegeNode.setType("college");
collegeNode.setCollegeId(collegeId);
collegeNode.setCollegeName(collegeName);
collegeNode.setChildren(new ArrayList<>());
// 统计学院人数
int collegeMaleTotal = 0, collegeFemaleTotal = 0;
int collegeMaleAssigned = 0, collegeFemaleAssigned = 0;
// 按专业分组
Map<String, List<Map<String, Object>>> majorMap = collegeMajors.stream()
.collect(Collectors.groupingBy(item -> {
Object majorIdObj = item.get("major_id");
Long majorId = majorIdObj instanceof Long ? (Long) majorIdObj
: Long.valueOf(majorIdObj.toString());
String majorName = (String) item.get("major_name");
return majorId + "_" + majorName;
}));
// 3. 构建专业节点
for (Map.Entry<String, List<Map<String, Object>>> majorEntry : majorMap.entrySet()) {
String majorKey = majorEntry.getKey();
List<Map<String, Object>> majorClasses = majorEntry.getValue();
if (!majorClasses.isEmpty()) {
Map<String, Object> firstMajorItem = majorClasses.get(0);
Object majorIdObj = firstMajorItem.get("major_id");
Long majorId = majorIdObj instanceof Long ? (Long) majorIdObj
: Long.valueOf(majorIdObj.toString());
String majorName = (String) firstMajorItem.get("major_name");
XgStudentTreeVo majorNode = new XgStudentTreeVo();
majorNode.setId("major-" + majorId);
majorNode.setLabel(majorName);
majorNode.setType("major");
majorNode.setCollegeId(collegeId);
majorNode.setCollegeName(collegeName);
majorNode.setMajorId(majorId);
majorNode.setMajorName(majorName);
majorNode.setChildren(new ArrayList<>());
// 统计专业人数
int majorMaleTotal = 0, majorFemaleTotal = 0;
int majorMaleAssigned = 0, majorFemaleAssigned = 0;
// 4. 构建班级节点
for (Map<String, Object> classItem : majorClasses) {
Object classIdObj = classItem.get("class_id");
Long classId = classIdObj instanceof Long ? (Long) classIdObj
: Long.valueOf(classIdObj.toString());
String className = (String) classItem.get("class_name");
String grade = (String) classItem.get("grade");
Integer maleTotal = ((Number) classItem.get("male_total")).intValue();
Integer femaleTotal = ((Number) classItem.get("female_total")).intValue();
Integer maleAssigned = ((Number) classItem.get("male_assigned")).intValue();
Integer femaleAssigned = ((Number) classItem.get("female_assigned")).intValue();
XgStudentTreeVo classNode = new XgStudentTreeVo();
classNode.setId("class-" + classId);
classNode.setLabel(className);
classNode.setType("class");
classNode.setCollegeId(collegeId);
classNode.setCollegeName(collegeName);
classNode.setMajorId(majorId);
classNode.setMajorName(majorName);
classNode.setClassId(classId);
classNode.setClassName(className);
classNode.setGrade(grade);
classNode.setMaleTotal(maleTotal);
classNode.setFemaleTotal(femaleTotal);
classNode.setMaleAssigned(maleAssigned);
classNode.setFemaleAssigned(femaleAssigned);
majorNode.getChildren().add(classNode);
// 累计专业人数
majorMaleTotal += maleTotal;
majorFemaleTotal += femaleTotal;
majorMaleAssigned += maleAssigned;
majorFemaleAssigned += femaleAssigned;
}
// 设置专业统计
majorNode.setMaleTotal(majorMaleTotal);
majorNode.setFemaleTotal(majorFemaleTotal);
majorNode.setMaleAssigned(majorMaleAssigned);
majorNode.setFemaleAssigned(majorFemaleAssigned);
collegeNode.getChildren().add(majorNode);
// 累计学院人数
collegeMaleTotal += majorMaleTotal;
collegeFemaleTotal += majorFemaleTotal;
collegeMaleAssigned += majorMaleAssigned;
collegeFemaleAssigned += majorFemaleAssigned;
}
}
// 设置学院统计
collegeNode.setMaleTotal(collegeMaleTotal);
collegeNode.setFemaleTotal(collegeFemaleTotal);
collegeNode.setMaleAssigned(collegeMaleAssigned);
collegeNode.setFemaleAssigned(collegeFemaleAssigned);
result.add(collegeNode);
}
}
log.info("学生信息树构建完成,共 {} 个学院节点", result.size());
} catch (Exception e) {
log.error("构建学生信息树失败", e);
throw new RuntimeException("构建学生信息树失败: " + e.getMessage());
}
return result;
}
}
@@ -171,4 +171,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND (d.dept_id = #{collegeId} OR FIND_IN_SET(#{collegeId}, d.ancestors))
</select>
<!-- 查询二级学院下的学院、专业、班级学生统计信息 -->
<select id="getCollegeStudentStats" resultType="java.util.Map">
SELECT
c.grade,
sm.college_id,
sm.college_name,
sm.major_id,
sm.major_name,
sm.class_id,
sm.class_name,
COALESCE(SUM(CASE WHEN sm.gender = '0' AND sm.is_boarder = 1 THEN 1 ELSE 0 END), 0) AS male_total,
COALESCE(SUM(CASE WHEN sm.gender = '1' AND sm.is_boarder = 1 THEN 1 ELSE 0 END), 0) AS female_total,
COALESCE(SUM(CASE WHEN sm.gender = '0' AND dbs.student_id IS NOT NULL AND dbs.status = '0' THEN 1 ELSE 0 END), 0) AS male_assigned,
COALESCE(SUM(CASE WHEN sm.gender = '1' AND dbs.student_id IS NOT NULL AND dbs.status = '0' THEN 1 ELSE 0 END), 0) AS female_assigned
FROM xg_student_msg sm
LEFT JOIN xg_class_msg c ON sm.class_id = c.id
LEFT JOIN sys_dept d ON sm.college_id = d.dept_id
LEFT JOIN xg_dorm_bed_student dbs ON sm.id = dbs.student_id AND dbs.deleted = '0' AND dbs.status = '0'
WHERE sm.deleted = 0
AND sm.student_status = '1'
AND sm.is_boarder = 1
AND (d.parent_id = #{secondaryCollegeId} OR d.dept_id = #{secondaryCollegeId} OR FIND_IN_SET(#{secondaryCollegeId}, d.ancestors))
AND sm.college_id IS NOT NULL
AND sm.major_id IS NOT NULL
AND sm.class_id IS NOT NULL
GROUP BY c.grade, sm.college_id, sm.college_name, sm.major_id, sm.major_name, sm.class_id, sm.class_name
ORDER BY c.grade DESC, sm.college_name, sm.major_name, sm.class_name
</select>
</mapper>
+3
View File
@@ -12,6 +12,7 @@
- [班级信息管理API](./班级信息管理API.md)
- [班级干部信息管理API](./班级干部信息管理API.md)
- [宿舍管理API](./宿舍管理API.md)
- [宿舍房间管理API](./宿舍房间管理API.md) - **新增床位详细信息查询接口**(2025-01-27)
- [宿舍管理员信息API](./宿舍管理员信息API.md)
- [宿舍管理员授权API](./宿舍管理员授权API.md)
- [学生管理员授权关系API](./学生管理员授权关系API.md)
@@ -79,6 +80,8 @@
| 获取可预约时段 | GET | /api/xljk/consultation/appointment/slots | 预约管理 | xljk:consultation:appointment:list |
| 提交预约申请 | POST | /api/xljk/consultation/appointment/apply | 预约管理 | xljk:consultation:appointment:apply |
| 处理预约申请 | POST | /api/xljk/consultation/appointment/process | 预约管理 | xljk:consultation:appointment:process |
| **获取房间床位详细信息** | GET | /dormbed/dormBed/details/room/{roomId} | 宿舍管理 | dormbed:dormBed:query |
| **获取宿舍楼床位详细信息** | GET | /dormbed/dormBed/details/building/{buildingId} | 宿舍管理 | dormbed:dormBed:query |
| 记录咨询结果 | POST | /api/xljk/consultation/appointment/record | 预约管理 | xljk:consultation:appointment:record |
| 查询未到访记录列表 | GET | /api/xljk/consultation/no-show/list | 预约限制 | xljk:consultation:noshow:list |
| 获取未到访记录详情 | GET | /api/xljk/consultation/no-show/{id} | 预约限制 | xljk:consultation:noshow:query |
+231 -2
View File
@@ -614,12 +614,241 @@ updateSupport: true
- `name LIKE '%入参的name%'` (姓名模糊查询,可选)
- **排序方式**: 按创建时间倒序排列
## 17. 获取学生信息树 ⭐ 新增
### 接口描述
获取按年级、学院、专业、班级层级组织的学生信息树结构,用于宿舍分配等场景的学生选择。
### 接口URL
```
GET /studentMsg/studentMsg/getStudentTree
```
### 请求参数
| 参数名 | 类型 | 是否必填 | 说明 | 示例值 |
|-------|------|---------|------|-------|
| secondaryCollegeId | Long | 否 | 二级学院ID,默认为101 | 101 |
### 请求示例
```javascript
// GET请求
/studentMsg/studentMsg/getStudentTree?secondaryCollegeId=101
```
### 响应参数
| 参数名 | 类型 | 说明 | 示例值 |
|-------|------|------|-------|
| code | Integer | 响应码,200表示成功 | 200 |
| msg | String | 响应消息 | "操作成功" |
| data | Array | 学生信息树数据 | 见下方详细结构 |
### 学生树节点结构
| 参数名 | 类型 | 说明 | 示例值 |
|-------|------|------|-------|
| id | String | 节点唯一标识 | "college-101" |
| label | String | 节点显示名称 | "计算机学院" |
| type | String | 节点类型:college/major/class | "college" |
| maleAssigned | Integer | 已分配男生数量 | 45 |
| maleTotal | Integer | 男生总数 | 120 |
| femaleAssigned | Integer | 已分配女生数量 | 25 |
| femaleTotal | Integer | 女生总数 | 60 |
| grade | String | 年级信息(仅班级节点有值) | "2025" |
| collegeId | Long | 学院ID | 101 |
| collegeName | String | 学院名称 | "计算机学院" |
| majorId | Long | 专业ID(专业和班级节点有值) | 1001 |
| majorName | String | 专业名称(专业和班级节点有值) | "计算机科学与技术" |
| classId | Long | 班级ID(仅班级节点有值) | 10001 |
| className | String | 班级名称(仅班级节点有值) | "计算机科学与技术1班" |
| sortOrder | Integer | 排序序号 | 1 |
| children | Array | 子节点数组 | [] |
### 后端实现
```java
// Controller
@GetMapping("/getStudentTree")
@SaCheckPermission("studentMsg:studentMsg:query")
public R<List<XgStudentTreeVo>> getStudentTree(@RequestParam(defaultValue = "101") Long secondaryCollegeId) {
List<XgStudentTreeVo> tree = studentService.getStudentTree(secondaryCollegeId);
return R.ok(tree);
}
// Service实现
@Override
public List<XgStudentTreeVo> getStudentTree(Long secondaryCollegeId) {
return baseMapper.getStudentTree(secondaryCollegeId);
}
```
### 数据库查询
```sql
<select id="getCollegeStudentStats" resultType="java.util.Map">
SELECT
s.college_id,
s.college_name,
s.major_id,
s.major_name,
s.class_id,
s.class_name,
s.grade,
COUNT(CASE WHEN s.gender = '1' THEN 1 END) as male_total,
COUNT(CASE WHEN s.gender = '0' THEN 1 END) as female_total,
COUNT(CASE WHEN s.gender = '1' AND s.is_boarder = 1 THEN 1 END) as male_assigned,
COUNT(CASE WHEN s.gender = '0' AND s.is_boarder = 1 THEN 1 END) as female_assigned
FROM xg_student s
WHERE s.secondary_college_id = #{secondaryCollegeId}
AND s.deleted = 0
AND s.student_status = '1'
GROUP BY s.college_id, s.college_name, s.major_id, s.major_name, s.class_id, s.class_name, s.grade
ORDER BY s.college_id, s.major_id, s.class_id
</select>
```
### 前端调用
```typescript
// API定义
export function getStudentTree(secondaryCollegeId: number = 101): AxiosPromise<R<XgStudentTreeVO[]>> {
return request({
url: '/studentMsg/studentMsg/getStudentTree',
method: 'get',
params: {
secondaryCollegeId
}
});
}
// 组件中使用
const getStudentTreeData = async () => {
try {
const res = await getStudentTree(101);
if (res.data.code === 200) {
studentTreeData.value = res.data.data || [];
} else {
ElMessage.error(res.data.msg || '获取学生信息树失败');
}
} catch (error) {
console.error('获取学生信息树失败:', error);
ElMessage.error('获取学生信息树失败');
}
};
```
### 响应示例
```json
{
"code": 200,
"msg": "操作成功",
"data": [
{
"id": "college-101",
"label": "计算机学院",
"type": "college",
"collegeId": 101,
"collegeName": "计算机学院",
"maleAssigned": 45,
"maleTotal": 120,
"femaleAssigned": 25,
"femaleTotal": 60,
"children": [
{
"id": "major-1001",
"label": "计算机科学与技术",
"type": "major",
"collegeId": 101,
"collegeName": "计算机学院",
"majorId": 1001,
"majorName": "计算机科学与技术",
"maleAssigned": 45,
"maleTotal": 80,
"femaleAssigned": 15,
"femaleTotal": 40,
"children": [
{
"id": "class-10001",
"label": "计算机科学与技术1班",
"type": "class",
"collegeId": 101,
"collegeName": "计算机学院",
"majorId": 1001,
"majorName": "计算机科学与技术",
"classId": 10001,
"className": "计算机科学与技术1班",
"grade": "2025",
"maleAssigned": 20,
"maleTotal": 40,
"femaleAssigned": 10,
"femaleTotal": 20
},
{
"id": "class-10002",
"label": "计算机科学与技术2班",
"type": "class",
"collegeId": 101,
"collegeName": "计算机学院",
"majorId": 1001,
"majorName": "计算机科学与技术",
"classId": 10002,
"className": "计算机科学与技术2班",
"grade": "2025",
"maleAssigned": 25,
"maleTotal": 40,
"femaleAssigned": 5,
"femaleTotal": 20
}
]
}
]
}
]
}
```
### 错误响应
```json
{
"code": 500,
"msg": "获取学生信息树失败",
"data": null
}
```
### 注意事项
1. **权限控制**: 需要 `studentMsg:studentMsg:query` 权限
2. **树结构**: 按学院->专业->班级的层级组织(移除年级分组)
3. **统计信息**: 每个节点包含已分配和总数的男女生统计信息
4. **排序规则**: 按学院ID、专业ID、班级ID顺序排列
5. **应用场景**: 主要用于宿舍分配时显示各班级的入住统计
6. **数据过滤**: 支持按二级学院过滤数据范围,默认为101
7. **逻辑删除**: 查询时排除已删除的学生记录
8. **学籍状态**: 只统计在籍学生(student_status='1')
9. **住宿统计逻辑**:
- **total**: 需要住宿的学生总数(is_boarder=1)
- **assigned**: 实际已分配住宿的学生数(通过xg_dorm_bed_student表关联,status='0')
---
**文档更新时间**: 2025-01-07
**文档版本**: 1.2.0
## 📋 更新日志
### 2025-01-27 - 学生信息树接口优化
- **功能优化**: 优化 `GET /studentMsg/studentMsg/getStudentTree` 接口
- **结构调整**: 移除年级分组,调整为学院->专业->班级的三级层级结构
- **性能优化**: 减少嵌套层级,提升前端渲染性能
- **统计信息**: 保持各层级男女生人数和住宿分配统计
- **逻辑修正**: 修正住宿统计逻辑,通过xg_dorm_bed_student表准确统计已分配住宿学生数
### 2025-01-27 - 新增班级学生查询接口
- **新增功能**: 新增 `GET /studentMsg/studentMsg/listByClassId` 接口
- **功能描述**: 查询指定班级中所有在籍学生信息
- **过滤条件**: 支持按班级ID和学生姓名查询
- **排序方式**: 按创建时间倒序排列
---
**文档更新时间**: 2025-01-27
**文档版本**: 1.4.0
**维护人员**: Cursor AI
**更新说明**:
- 优化学生信息树接口,移除年级分组,简化层级结构
- 新增学生信息树查询接口,支持宿舍分配场景
- 新增高级检索导出接口文档
- 修复高级检索导出分页限制问题
- 之前版本:新增学生信息导入功能,完善学生信息管理API文档
+273 -1
View File
@@ -8,6 +8,9 @@
- [2.1 获取宿舍楼列表](#21-获取宿舍楼列表)
- [3. 宿舍房间管理](#3-宿舍房间管理)
- [3.1 获取宿舍房间列表](#31-获取宿舍房间列表)
- [4. 宿舍床位管理](#4-宿舍床位管理)
- [4.1 获取房间床位详细信息列表](#41-获取房间床位详细信息列表)
- [4.2 获取宿舍楼床位详细信息列表](#42-获取宿舍楼床位详细信息列表)
## 1. 宿舍楼树形结构
@@ -406,4 +409,273 @@ async function getDormRoomList(params) {
}
return { total: 0, rows: [] };
}
```
```
## 4. 宿舍床位管理
### 4.1 获取房间床位详细信息列表
#### 接口说明
该接口用于获取指定房间的床位详细信息列表,包含床位基本信息和分配的学生详细信息(学院、专业、班级、学号、姓名等)。
#### 请求方式
```
GET /dormbed/dormBed/details/room/{roomId}
```
#### 权限要求
```
dormbed:dormBed:query
```
#### 请求参数
| 参数名 | 类型 | 必须 | 描述 |
| ------- | ---- | ---- | ------ |
| roomId | Long | 是 | 房间ID |
#### 返回结果
```json
{
"code": 200,
"msg": "操作成功",
"data": [
{
"id": "1947459199879495684",
"bedCode": "bed-101-01",
"bedName": "101-1号床",
"roomId": "1947459199879495682",
"roomName": "101",
"bedType": "1",
"bedStatus": "1",
"bedRemark": "下铺",
"assignmentId": "1947459199879495685",
"assignTime": "2025-01-15 09:00:00",
"assignmentStatus": "0",
"collegeId": "1001",
"collegeName": "计算机学院",
"majorId": "2001",
"majorName": "计算机科学与技术",
"classId": "3001",
"className": "计算机科学与技术1班",
"classCode": "CS2024-01",
"grade": "2024",
"studentId": "4001",
"studentNo": "2024001001",
"studentName": "张三",
"studentGender": "0",
"studentPhone": "13800138001",
"studentIdCard": "330101199901011234",
"createBy": 1,
"createTime": "2025-07-22 10:00:00",
"updateBy": 1,
"updateTime": "2025-07-22 10:00:00"
},
{
"id": "1947459199879495686",
"bedCode": "bed-101-02",
"bedName": "101-2号床",
"roomId": "1947459199879495682",
"roomName": "101",
"bedType": "2",
"bedStatus": "0",
"bedRemark": "上铺",
"assignmentId": null,
"assignTime": null,
"assignmentStatus": null,
"collegeId": null,
"collegeName": null,
"majorId": null,
"majorName": null,
"classId": null,
"className": null,
"classCode": null,
"grade": null,
"studentId": null,
"studentNo": null,
"studentName": null,
"studentGender": null,
"studentPhone": null,
"studentIdCard": null,
"createBy": 1,
"createTime": "2025-07-22 10:00:00",
"updateBy": 1,
"updateTime": "2025-07-22 10:00:00"
}
]
}
```
#### 返回参数说明
| 参数名 | 类型 | 描述 |
| ---------------- | ------- | ------------------------------------------------------- |
| **床位基本信息** | | |
| id | Long | 床位主键ID |
| bedCode | String | 床位编号 |
| bedName | String | 床位名称 |
| roomId | Long | 所属房间ID |
| roomName | String | 房间名称 |
| bedType | String | 床位类型(1下铺 2上铺 3中铺 4独立床) |
| bedStatus | String | 床位状态(0空闲 1已分配 2维修中) |
| bedRemark | String | 床位备注 |
| **分配信息** | | |
| assignmentId | Long | 分配关系ID(空闲床位为null) |
| assignTime | String | 分配时间(空闲床位为null) |
| assignmentStatus | String | 分配状态(0正常 1已退宿)(空闲床位为null) |
| **学院信息** | | |
| collegeId | Long | 学院ID(空闲床位为null) |
| collegeName | String | 学院名称(空闲床位为null) |
| **专业信息** | | |
| majorId | Long | 专业ID(空闲床位为null) |
| majorName | String | 专业名称(空闲床位为null) |
| **班级信息** | | |
| classId | Long | 班级ID(空闲床位为null) |
| className | String | 班级名称(空闲床位为null) |
| classCode | String | 班级代码(空闲床位为null) |
| grade | String | 年级(空闲床位为null) |
| **学生信息** | | |
| studentId | Long | 学生ID(空闲床位为null) |
| studentNo | String | 学号(空闲床位为null) |
| studentName | String | 学生姓名(空闲床位为null) |
| studentGender | String | 学生性别(0男 1女)(空闲床位为null) |
| studentPhone | String | 学生手机号(空闲床位为null) |
| studentIdCard | String | 身份证号(空闲床位为null) |
| **基础字段** | | |
| createBy | Long | 创建者ID |
| createTime | String | 创建时间 |
| updateBy | Long | 更新者ID |
| updateTime | String | 更新时间 |
#### 错误码
| 错误码 | 描述 |
| ------ | -------------------- |
| 401 | 未授权,需要登录 |
| 403 | 无权限访问该接口 |
| 404 | 房间ID不存在 |
| 500 | 服务器内部错误 |
#### 使用示例
```javascript
// 前端代码示例(使用axios)
import axios from 'axios';
// 获取房间床位详细信息列表
async function getBedDetailsByRoomId(roomId) {
try {
const response = await axios.get(`/dormbed/dormBed/details/room/${roomId}`);
if (response.data.code === 200) {
return response.data.data;
}
} catch (error) {
console.error('获取房间床位详细信息失败:', error);
}
return [];
}
```
### 4.2 获取宿舍楼床位详细信息列表
#### 接口说明
该接口用于获取指定宿舍楼的所有床位详细信息列表,包含床位基本信息和分配的学生详细信息(学院、专业、班级、学号、姓名等)。
#### 请求方式
```
GET /dormbed/dormBed/details/building/{buildingId}
```
#### 权限要求
```
dormbed:dormBed:query
```
#### 请求参数
| 参数名 | 类型 | 必须 | 描述 |
| ---------- | ---- | ---- | -------- |
| buildingId | Long | 是 | 宿舍楼ID |
#### 返回结果
返回结果格式与 [4.1 获取房间床位详细信息列表](#41-获取房间床位详细信息列表) 相同,但包含指定宿舍楼下所有房间的床位信息,按房间名称、床位编号排序。
#### 返回参数说明
参数说明与 [4.1 获取房间床位详细信息列表](#41-获取房间床位详细信息列表) 相同。
#### 排序规则
床位详细信息列表按照以下顺序排序:
1. 优先按房间名称(roomName)升序排列
2. 其次按床位编号(bedCode)升序排列
这确保了在宿舍管理系统中床位按照房间顺序展示,方便管理员查看和管理。
#### 错误码
| 错误码 | 描述 |
| ------ | -------------------- |
| 401 | 未授权,需要登录 |
| 403 | 无权限访问该接口 |
| 404 | 宿舍楼ID不存在 |
| 500 | 服务器内部错误 |
#### 使用示例
```javascript
// 前端代码示例(使用axios)
import axios from 'axios';
// 获取宿舍楼床位详细信息列表
async function getBedDetailsByBuildingId(buildingId) {
try {
const response = await axios.get(`/dormbed/dormBed/details/building/${buildingId}`);
if (response.data.code === 200) {
return response.data.data;
}
} catch (error) {
console.error('获取宿舍楼床位详细信息失败:', error);
}
return [];
}
// 在前端界面中使用示例
async function loadBedDetailsByBuilding(buildingId) {
const bedDetails = await getBedDetailsByBuildingId(buildingId);
// 处理床位详细信息数据
bedDetails.forEach(bed => {
if (bed.bedStatus === '1' && bed.studentName) {
// 已分配床位,显示学生信息
console.log(`床位 ${bed.bedName} 已分配给:${bed.studentName}(${bed.studentNo}) - ${bed.collegeName} ${bed.majorName} ${bed.className}`);
} else {
// 空闲床位
console.log(`床位 ${bed.bedName} 状态:空闲`);
}
});
}
```
#### 接口特点
1. **完整信息查询**:一次接口调用获取床位基本信息和学生详细信息
2. **多表关联**:关联床位表、床位分配表、学生信息表、班级信息表等
3. **状态区分**:清晰区分已分配和空闲床位,空闲床位的学生相关字段为null
4. **权限控制**:需要相应权限才能访问接口
5. **数据完整性**:包含学院、专业、班级、学生等完整层级信息
#### 应用场景
1. **宿舍管理**:管理员查看房间或宿舍楼的床位分配情况
2. **学生信息核查**:快速查看入住学生的基本信息
3. **统计分析**:进行床位利用率、学院分布等数据分析
4. **报表生成**:生成宿舍入住情况报表
@@ -145,7 +145,7 @@ create table `xg_dorm_bed_student` (
`update_time` datetime default null comment '更新时间',
`remark` varchar(500) default null comment '备注',
primary key (`id`),
unique key `uk_student_bed` (`student_id`, `bed_id`),
key `uk_student_bed` (`student_id`, `bed_id`),
key `idx_college_id` (`college_id`),
key `idx_student_id` (`student_id`),
key `idx_bed_id` (`bed_id`),
+23 -1
View File
@@ -1,6 +1,6 @@
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DormBedVO, DormBedForm, DormBedQuery } from '@/api/xg/xgss/dormBed/types';
import { DormBedVO, DormBedDetailVO, DormBedForm, DormBedQuery } from '@/api/xg/xgss/dormBed/types';
/**
* 查询宿舍床位信息列表
@@ -61,3 +61,25 @@ export const delDormBed = (id: string | number | Array<string | number>) => {
method: 'delete'
});
};
/**
* 查询指定房间的床位详细信息列表(包含学生信息)
* @param roomId 房间ID
*/
export const getBedDetailsByRoomId = (roomId: string | number): AxiosPromise<DormBedDetailVO[]> => {
return request({
url: '/dormbed/dormBed/details/room/' + roomId,
method: 'get'
});
};
/**
* 查询指定宿舍楼的床位详细信息列表(包含学生信息)
* @param buildingId 宿舍楼ID
*/
export const getBedDetailsByBuildingId = (buildingId: string | number): AxiosPromise<DormBedDetailVO[]> => {
return request({
url: '/dormbed/dormBed/details/building/' + buildingId,
method: 'get'
});
};
+77
View File
@@ -42,6 +42,83 @@ export interface DormBedVO {
updateTime: Date;
}
/**
* 宿舍床位详细信息对象(包含学生信息)
*/
export interface DormBedDetailVO {
// =============== 床位基本信息 ===============
/** 床位ID */
id: string | number;
/** 床位编号 */
bedCode: string;
/** 床位名称 */
bedName: string;
/** 所属房间ID */
roomId: string | number;
/** 房间名称 */
roomName?: string;
/** 床位类型(1=下铺,2=上铺,3=中铺,4=独立床) */
bedType: string;
/** 床位状态(0=空闲,1=已分配,2=维修中) */
bedStatus: string;
/** 床位备注 */
bedRemark?: string;
// =============== 分配信息 ===============
/** 分配关系ID */
assignmentId?: string | number;
/** 分配时间 */
assignTime?: string;
/** 分配状态(0=正常,1=已退宿) */
assignmentStatus?: string;
// =============== 学院信息 ===============
/** 学院ID */
collegeId?: string | number;
/** 学院名称 */
collegeName?: string;
// =============== 专业信息 ===============
/** 专业ID */
majorId?: string | number;
/** 专业名称 */
majorName?: string;
// =============== 班级信息 ===============
/** 班级ID */
classId?: string | number;
/** 班级名称 */
className?: string;
/** 班级代码 */
classCode?: string;
/** 年级 */
grade?: string;
// =============== 学生信息 ===============
/** 学生ID */
studentId?: string | number;
/** 学号 */
studentNo?: string;
/** 学生姓名 */
studentName?: string;
/** 学生性别(0=男,1=女) */
studentGender?: string;
/** 学生手机号 */
studentPhone?: string;
/** 身份证号 */
studentIdCard?: string;
// =============== 基础字段 ===============
/** 创建者 */
createBy?: number;
/** 创建时间 */
createTime?: string;
/** 更新者 */
updateBy?: number;
/** 更新时间 */
updateTime?: string;
}
/**
* 宿舍床位信息表单对象
*/
+14 -2
View File
@@ -1,6 +1,6 @@
import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { StudentQuery, StudentVO, StudentForm, XgDeptTreeVO, R, TableDataInfo } from './types';
import { StudentQuery, StudentVO, StudentForm, XgDeptTreeVO, XgStudentTreeVO, R, TableDataInfo } from './types';
/**
* 查询部门下拉树结构
@@ -196,6 +196,17 @@ export function downloadImportTemplate(): AxiosPromise<any> {
});
}
// 获取学生信息树
export function getStudentTree(secondaryCollegeId: number = 101): AxiosPromise<R<XgStudentTreeVO[]>> {
return request({
url: '/studentMsg/studentMsg/getStudentTree',
method: 'get',
params: {
secondaryCollegeId
}
});
}
// 学生状态修改
export function changeStudentStatus(studentId: string | number, status: string): AxiosPromise<R<any>> {
// 实际使用时连接后端接口
@@ -444,5 +455,6 @@ export default {
deptTreeSelect,
exportStudent,
changeStudentStatus,
XgDeptTreeSelect
XgDeptTreeSelect,
getStudentTree
};
+20
View File
@@ -176,3 +176,23 @@ export interface TableDataInfo<T> {
total: number;
rows: T;
}
// 学生信息树节点类型
export interface XgStudentTreeVO {
id: string;
label: string;
type: 'grade' | 'college' | 'major' | 'class';
maleAssigned?: number;
maleTotal?: number;
femaleAssigned?: number;
femaleTotal?: number;
grade?: string;
collegeId?: number;
collegeName?: string;
majorId?: number;
majorName?: string;
classId?: number;
className?: string;
sortOrder?: number;
children?: XgStudentTreeVO[];
}
+109 -292
View File
@@ -80,7 +80,7 @@
<template #default="{ node, data }">
<span class="custom-tree-node">
<span>{{ node.label }}</span>
<span v-if="data.type === 'college' || data.type === 'class'" class="bed-count">
<span v-if="data.type === 'college' || data.type === 'major' || data.type === 'class'" class="bed-count">
<template v-if="selectedBuilding?.buildingType === '2'">
<el-tag size="small" class="female-tag ml-2">女:{{ data.femaleAssigned }}/{{ data.femaleTotal }}</el-tag>
<el-tag size="small" type="primary" class="ml-2">男:{{ data.maleAssigned }}/{{ data.maleTotal }}</el-tag>
@@ -168,7 +168,7 @@
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" :selectable="checkSelectable" />
<el-table-column prop="roomName" label="房间/宿舍名称" min-width="180">
<el-table-column prop="roomName" label="房间/宿舍名称" min-width="120">
<template #default="scope">
<span v-if="!scope.row.isBed">{{ scope.row.roomName }} (房间)</span>
<span v-else>{{ scope.row.bedName }} (床位)</span>
@@ -207,12 +207,57 @@
</template>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="150" :show-overflow-tooltip="true">
<!-- 新增学院信息列 -->
<el-table-column label="学院" width="120" align="center">
<template #default="scope">
{{ scope.row.remark }}
<span v-if="scope.row.isBed && scope.row.collegeName">{{ scope.row.collegeName }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center">
<!-- 新增专业信息列 -->
<el-table-column label="专业" width="120" align="center">
<template #default="scope">
<span v-if="scope.row.isBed && scope.row.majorName">{{ scope.row.majorName }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<!-- 新增班级信息列 -->
<el-table-column label="班级" width="120" align="center">
<template #default="scope">
<span v-if="scope.row.isBed && scope.row.className">{{ scope.row.className }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<!-- 新增学号信息列 -->
<el-table-column label="学号" width="120" align="center">
<template #default="scope">
<span v-if="scope.row.isBed && scope.row.studentNo">{{ scope.row.studentNo }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<!-- 新增学生姓名列 -->
<el-table-column label="学生姓名" width="100" align="center">
<template #default="scope">
<span v-if="scope.row.isBed && scope.row.studentName">{{ scope.row.studentName }}</span>
<span v-else>-</span>
</template>
</el-table-column>
<!-- 新增性别列 -->
<el-table-column label="性别" width="60" align="center">
<template #default="scope">
<span v-if="scope.row.isBed && scope.row.studentGender !== undefined">
<el-tag v-if="scope.row.studentGender === '0'" type="primary" size="small">男</el-tag>
<el-tag v-else-if="scope.row.studentGender === '1'" class="female-tag" size="small">女</el-tag>
</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="150" :show-overflow-tooltip="true">
<template #default="scope">
{{ scope.row.remark || scope.row.bedRemark }}
</template>
</el-table-column>
<el-table-column label="操作" width="180" align="center" fixed="right">
<template #default="scope">
<template v-if="!scope.row.isBed">
<!-- <el-button type="primary" link icon="Plus" @click="handleAddBed(scope.row)" /> -->
@@ -258,15 +303,20 @@ import { ref, computed, reactive, onMounted, nextTick, watch, getCurrentInstance
import { InfoFilled } from '@element-plus/icons-vue';
import type { DormTreeNode, BedInfo } from '@/api/xg/xgss/xsssfjgl/types';
import type { DormRoomVO } from '@/api/xg/xgss/dormRoom/types';
import type { DormBedDetailVO } from '@/api/xg/xgss/dormBed/types';
import type { XgStudentTreeVO } from '@/api/xg/xsjcxx/studentMsg/types';
import { getDormTree } from '@/api/xg/xgss/xsssfjgl';
import { listDormBed, delDormBed, getDormBed } from '@/api/xg/xgss/dormBed';
import { getBedDetailsByRoomId, delDormBed, getDormBed } from '@/api/xg/xgss/dormBed';
import { listDormRoom, delDormRoom } from '@/api/xg/xgss/dormRoom';
import { getStudentTree } from '@/api/xg/xsjcxx/studentMsg';
import ElMessage from 'element-plus/es/components/message/index';
import ElMessageBox from 'element-plus/es/components/message-box/index';
// 引入子组件
import RoomDialog from './components/RoomDialog.vue';
import BedDialog from './components/BedDialog.vue';
const { proxy } = getCurrentInstance();
// const { proxy } = getCurrentInstance();
// 组件状态
const dormTreeRef = ref();
@@ -329,181 +379,7 @@ const bedDialog = reactive({
// 学生树相关数据
const studentTreeRef = ref();
const studentSearchKey = ref('');
const studentTreeData = ref<any[]>([
{
id: 'grade-2025',
label: '2025级',
type: 'grade',
children: [
{
id: 'college-cs-2025',
label: '计算机学院',
type: 'college',
maleAssigned: 45,
maleTotal: 120,
femaleAssigned: 25,
femaleTotal: 60,
children: [
{
id: 'class-cs-1-2025',
label: '计算机科学与技术1班',
type: 'class',
maleAssigned: 20,
maleTotal: 40,
femaleAssigned: 10,
femaleTotal: 15
},
{
id: 'class-cs-2-2025',
label: '计算机科学与技术2班',
type: 'class',
maleAssigned: 25,
maleTotal: 40,
femaleAssigned: 15,
femaleTotal: 20
}
]
},
{
id: 'college-ee-2025',
label: '电子工程学院',
type: 'college',
maleAssigned: 55,
maleTotal: 100,
femaleAssigned: 35,
femaleTotal: 50,
children: [
{
id: 'class-ee-1-2025',
label: '电子信息工程1班',
type: 'class',
maleAssigned: 30,
maleTotal: 50,
femaleAssigned: 20,
femaleTotal: 25
},
{
id: 'class-ee-2-2025',
label: '电子信息工程2班',
type: 'class',
maleAssigned: 25,
maleTotal: 50,
femaleAssigned: 15,
femaleTotal: 25
}
]
}
]
},
{
id: 'grade-2024',
label: '2024级',
type: 'grade',
children: [
{
id: 'college-cs-2024',
label: '计算机学院',
type: 'college',
maleAssigned: 110,
maleTotal: 120,
femaleAssigned: 58,
femaleTotal: 60,
children: [
{
id: 'class-cs-1-2024',
label: '计算机科学与技术1班',
type: 'class',
maleAssigned: 38,
maleTotal: 40,
femaleAssigned: 14,
femaleTotal: 15
},
{
id: 'class-cs-2-2024',
label: '计算机科学与技术2班',
type: 'class',
maleAssigned: 37,
maleTotal: 40,
femaleAssigned: 18,
femaleTotal: 20
}
]
}
]
},
{
id: 'grade-2024',
label: '2024级',
type: 'grade',
children: [
{
id: 'college-cs-2024',
label: '计算机学院',
type: 'college',
maleAssigned: 110,
maleTotal: 120,
femaleAssigned: 58,
femaleTotal: 60,
children: [
{
id: 'class-cs-1-2024',
label: '计算机科学与技术1班',
type: 'class',
maleAssigned: 38,
maleTotal: 40,
femaleAssigned: 14,
femaleTotal: 15
},
{
id: 'class-cs-2-2024',
label: '计算机科学与技术2班',
type: 'class',
maleAssigned: 37,
maleTotal: 40,
femaleAssigned: 18,
femaleTotal: 20
}
]
}
]
},
{
id: 'grade-2024',
label: '2024级',
type: 'grade',
children: [
{
id: 'college-cs-2024',
label: '计算机学院',
type: 'college',
maleAssigned: 110,
maleTotal: 120,
femaleAssigned: 58,
femaleTotal: 60,
children: [
{
id: 'class-cs-1-2024',
label: '计算机科学与技术1班',
type: 'class',
maleAssigned: 38,
maleTotal: 40,
femaleAssigned: 14,
femaleTotal: 15
},
{
id: 'class-cs-2-2024',
label: '计算机科学与技术2班',
type: 'class',
maleAssigned: 37,
maleTotal: 40,
femaleAssigned: 18,
femaleTotal: 20
}
]
}
]
}
]);
const studentTreeData = ref<XgStudentTreeVO[]>([]);
/** 通过条件过滤节点 */
const filterNode = (value: string, data: DormTreeNode) => {
@@ -546,9 +422,9 @@ const getDormTreeData = async () => {
}
// 如果是宿舍楼但没有性别信息,添加宿舍楼性别类型
if (node.type === 'building' && !node.buildingType) {
if (node.type === 'building' && !(node as any).buildingType) {
// 实际项目中应该从后端获取,这里先用随机分配,后续可以修改为从后端获取
node.buildingType = Math.random() > 0.5 ? '1' : '2';
(node as any).buildingType = Math.random() > 0.5 ? '1' : '2';
}
// 递归处理子节点
@@ -565,20 +441,6 @@ const getDormTreeData = async () => {
}
};
/** 处理节点单击事件 */
// const handleNodeClick = (data: DormTreeNode) => {
// if (data.type !== 'building') {
// // 如果不是宿舍楼,不进行操作
// return;
// }
// // 设置选中的宿舍楼
// selectedBuilding.value = data;
// // 更新查询参数
// queryParams.buildingId = data.id;
// // 加载房间数据
// handleQuery();
// };
/** 处理节点单击事件 - 增加请求取消机制 */
const handleNodeClick = (data: DormTreeNode) => {
if (data.type !== 'building') {
@@ -613,11 +475,6 @@ const handleStudentNodeClick = (data: any) => {
// 这里可以实现学生节点点击后的相关功能
};
/** 查询房间数据 */
// const handleQuery = () => {
// loadRoomData();
// };
/** 重置查询条件 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
@@ -627,62 +484,7 @@ const resetQuery = () => {
handleQuery();
};
/** 加载房间数据 */
// const loadRoomData = async () => {
// if (!queryParams.buildingId) return;
// loading.value = true;
// try {
// // 获取房间列表
// const res = await listDormRoom(queryParams);
// const rooms = res.rows || [];
// // 存储临时结果
// const tempList: any[] = [];
// // 处理每个房间
// for (const room of rooms) {
// // 添加房间记录
// const roomRecord = {
// ...room,
// isBed: false,
// children: []
// };
// // 获取房间的床位信息
// try {
// const bedRes = await listDormBed({ roomId: room.id });
// const beds = bedRes.rows || [];
// // 将床位信息添加为房间的子项
// if (beds.length > 0) {
// roomRecord.children = beds.map((bed: any) => ({
// ...bed,
// isBed: true,
// roomName: room.roomName // 保留房间名称,方便展示
// }));
// }
// } catch (error) {
// console.error(`获取房间 ${room.id} 的床位信息失败`, error);
// }
// tempList.push(roomRecord);
// }
// roomList.value = tempList;
// // 重置选择状态
// selectedRows.value = [];
// selectedRoomCount.value = 0;
// selectedBedCount.value = 0;
// } catch (error) {
// console.error('加载房间数据失败', error);
// } finally {
// loading.value = false;
// }
// };
/** 加载房间数据 - 使用并行请求 */
/** 加载房间数据 - 使用新的床位详细信息API */
const loadRoomData = async () => {
if (!queryParams.buildingId) return;
@@ -692,14 +494,13 @@ const loadRoomData = async () => {
try {
// 获取房间列表
const res = await listDormRoom({
...queryParams,
signal: controller?.signal
...queryParams
});
const rooms = res.rows || [];
if (controller?.signal?.aborted) return;
// 并行获取所有房间的床位信息
// 并行获取所有房间的床位详细信息
const roomPromises = rooms.map(async (room) => {
// 创建房间记录
const roomRecord = {
@@ -709,26 +510,23 @@ const loadRoomData = async () => {
};
try {
const bedRes = await listDormBed({
roomId: room.id,
signal: controller?.signal
});
const bedDetailRes = await getBedDetailsByRoomId(room.id);
// 如果请求已被取消,不继续处理
if (controller?.signal?.aborted) return roomRecord;
// 将床位信息添加为房间的子项
if (bedRes.rows?.length > 0) {
roomRecord.children = bedRes.rows.map((bed: any) => ({
...bed,
// 将床位详细信息添加为房间的子项
if (bedDetailRes.data?.length > 0) {
roomRecord.children = bedDetailRes.data.map((bedDetail: DormBedDetailVO) => ({
...bedDetail,
isBed: true,
roomName: room.roomName // 保留房间名称,方便展示
}));
}
} catch (error) {
} catch (error: any) {
// 忽略请求被取消的错误
if (error.name !== 'AbortError') {
console.error(`获取房间 ${room.id} 的床位信息失败`, error);
console.error(`获取房间 ${room.id} 的床位详细信息失败`, error);
}
}
@@ -747,7 +545,7 @@ const loadRoomData = async () => {
selectedRows.value = [];
selectedRoomCount.value = 0;
selectedBedCount.value = 0;
} catch (error) {
} catch (error: any) {
// 忽略请求被取消的错误
if (error.name !== 'AbortError') {
console.error('加载房间数据失败', error);
@@ -764,7 +562,7 @@ const loadRoomData = async () => {
const handleAddRoom = () => {
if (!selectedBuilding.value) {
// 使用全局自动导入的 ElMessage
proxy.$modal.msgWarning('请先选择宿舍楼');
ElMessage.warning('请先选择宿舍楼');
return;
}
roomDialog.title = '添加房间';
@@ -787,16 +585,15 @@ const handleEditRoom = (row: any) => {
/** 删除房间 */
const handleDeleteRoom = (row: any) => {
proxy.$modal
.confirm(`确定删除房间 ${row.roomName} 吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
ElMessageBox.confirm(`确定删除房间 ${row.roomName} 吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
try {
await delDormRoom(row.id);
proxy.$modal.msgSuccess('删除成功');
ElMessage.success('删除成功');
loadRoomData(); // 刷新数据
} catch (error) {
console.error('删除房间失败', error);
@@ -828,16 +625,15 @@ const handleEditBed = (row: any) => {
/** 删除床位 */
const handleDeleteBed = (row: any) => {
proxy.$modal
.confirm(`确定删除床位 ${row.bedName} 吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
ElMessageBox.confirm(`确定删除床位 ${row.bedName} 吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
try {
await delDormBed(row.id);
proxy.$modal.msgSuccess('删除成功');
ElMessage.success('删除成功');
loadRoomData(); // 刷新数据
} catch (error) {
console.error('删除床位失败', error);
@@ -930,9 +726,25 @@ watch(
{ deep: true }
);
// 组件挂载时获取宿舍树数据
// 获取学生信息树数据
const getStudentTreeData = async () => {
try {
const res = await getStudentTree(101); // 默认使用二级学院ID 101
if (res.code === 200) {
studentTreeData.value = res.data || [];
} else {
ElMessage.error(res.msg || '获取学生信息树失败');
}
} catch (error) {
console.error('获取学生信息树失败:', error);
ElMessage.error('获取学生信息树失败');
}
};
// 组件挂载时获取宿舍树数据和学生树数据
onMounted(() => {
getDormTreeData();
getStudentTreeData();
if (currentController) {
currentController.abort();
currentController = null;
@@ -980,17 +792,22 @@ onMounted(() => {
height: 100%;
}
/* 添加表格横向滚动样式 */
/* 修复表格横向滚动样式 - 移除头部滚动条 */
.el-card :deep(.el-table) {
width: 100%;
overflow-x: auto;
}
.el-card :deep(.el-table__body-wrapper),
.el-card :deep(.el-table__header-wrapper) {
.el-card :deep(.el-table__body-wrapper) {
overflow-x: auto !important;
}
/* 移除头部横向滚动,只保留纵向滚动 */
.el-card :deep(.el-table__header-wrapper) {
overflow-x: visible !important;
overflow-y: visible !important;
}
.el-card :deep(.el-table__body),
.el-card :deep(.el-table__header) {
min-width: 100%;