You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
262 lines
11 KiB
262 lines
11 KiB
// 定义包名
|
|
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo; // 导入分页插件
|
|
import com.yanzhen.entity.*; // 导入实体类
|
|
import com.yanzhen.service.*; // 导入服务接口
|
|
import com.yanzhen.utils.Result; // 导入结果封装类
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入自动装配注解
|
|
import org.springframework.web.bind.annotation.*; // 导入Spring MVC相关注解
|
|
|
|
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest类
|
|
import java.util.ArrayList; // 导入ArrayList类
|
|
import java.util.Date; // 导入Date类
|
|
import java.util.HashMap; // 导入HashMap类
|
|
import java.util.List; // 导入List接口
|
|
import java.util.Map; // 导入Map接口
|
|
//学生管理的控制器
|
|
@RestController
|
|
@RequestMapping("/stu")
|
|
public class StuController {
|
|
//注入实例
|
|
//注入学生服务类
|
|
@Autowired
|
|
private StudentService studentService;
|
|
|
|
//注入组织服务类
|
|
@Autowired
|
|
private OrgService orgService;
|
|
//注入 成绩服务类
|
|
@Autowired
|
|
private GradeService gradeService;
|
|
//注入选择宿舍服务类
|
|
@Autowired
|
|
private SelectionDormitoryService selectionDormitoryService;
|
|
//注入宿舍服务类
|
|
@Autowired
|
|
private DormitoryService dormitoryService;
|
|
//注入学生宿舍服务类
|
|
@Autowired
|
|
private DormitoryStudentService dormitoryStudentService;
|
|
//注入缺勤服务类
|
|
@Autowired
|
|
private AbsenceService absenceService;
|
|
//注入报修服务类
|
|
@Autowired
|
|
private RepairService repairService;
|
|
//注入通知公告服务类
|
|
@Autowired
|
|
private NoticeService noticeService;
|
|
//注入用户服务类
|
|
@Autowired
|
|
private UserService userService;
|
|
//注入楼宇服务类
|
|
@Autowired
|
|
private BuildingService buildingService;
|
|
//注入选择服务类
|
|
@Autowired
|
|
private SelectionService selectionService;
|
|
//获取学生信息
|
|
@GetMapping("/info") // 映射GET请求到/info路径
|
|
public Result info(HttpServletRequest request) {
|
|
//从请求属性中获取学生信息
|
|
Student param = (Student)request.getAttribute("student");
|
|
//根据学生ID获取学生详细信息
|
|
Student student = studentService.detail(param.getId());
|
|
//设置学生组织信息
|
|
student.setOrg(orgService.detail(student.getClazzId()));
|
|
//设置学生成绩信息
|
|
student.setGrade(gradeService.detail(student.getGradeId()));
|
|
//返回结果
|
|
return Result.ok(student);
|
|
}
|
|
//获取选择宿舍信息
|
|
@GetMapping("/select_dormitory")
|
|
public Result select_dormitory(HttpServletRequest request) {
|
|
//从请求属性中获取学生信息
|
|
Student param = (Student)request.getAttribute("student");
|
|
//根据学生ID获取学生详细信息
|
|
Student student = studentService.detail(param.getId());
|
|
//创建SelectionDormitory对象
|
|
SelectionDormitory selectionDormitory = new SelectionDormitory();
|
|
//设置班级ID
|
|
selectionDormitory.setClazzId(student.getClazzId());
|
|
//设置查询限制条数
|
|
selectionDormitory.setLimit(1000);
|
|
//查询可选宿舍列表
|
|
PageInfo<SelectionDormitory> pageInfo = selectionDormitoryService.query(selectionDormitory);
|
|
//创建用于存储宿舍信息的列表
|
|
List<Map<String,Object>> list = new ArrayList<>();
|
|
// 获取查询结果列表
|
|
List<SelectionDormitory> selectionDormitorys = pageInfo.getList();
|
|
// 遍历查询结果列表
|
|
for (SelectionDormitory sd : selectionDormitorys) {
|
|
// 创建用于存储单个宿舍信息的Map对象
|
|
Map<String,Object> map = new HashMap<>();
|
|
//查询宿舍的基本信息
|
|
Dormitory dormitory = dormitoryService.detail(sd.getDormitoryId());
|
|
// 设置宿舍容量
|
|
map.put("capacity",dormitory.getCapacity());
|
|
// 设置宿舍ID
|
|
map.put("id",dormitory.getId());
|
|
// 设置宿舍编号
|
|
map.put("no",dormitory.getNo());
|
|
// 设置宿舍性别要求
|
|
map.put("sex",dormitory.getSex());
|
|
// 设置宿舍所在建筑名称
|
|
map.put("buildingName",buildingService.detail(dormitory.getBuildingId()).getName());
|
|
//查询已选择的所有学生
|
|
DormitoryStudent ds = new DormitoryStudent();
|
|
// 设置宿舍ID
|
|
ds.setDormitoryId(sd.getDormitoryId());
|
|
// 设置查询限制条数
|
|
ds.setLimit(1000);
|
|
// 查询已选择的学生列表
|
|
PageInfo<DormitoryStudent> pageInfo1 = dormitoryStudentService.query(ds);
|
|
// 设置已选择的学生数量
|
|
map.put("selected",pageInfo1.getTotal());
|
|
|
|
//构造已经选择的同学信息
|
|
List<Map<String,Object>> studentList = new ArrayList<>();
|
|
// 获取已选择学生列表
|
|
List<DormitoryStudent> list1 = pageInfo1.getList();
|
|
// 遍历已选择学生列表
|
|
for(DormitoryStudent ds1 : list1){
|
|
// 创建用于存储单个学生信息的Map对象
|
|
Map<String,Object> studentMap = new HashMap<>();
|
|
// 根据学生ID获取学生详细信息
|
|
Student detail = studentService.detail(ds1.getStudentId());
|
|
// 设置学生学号
|
|
studentMap.put("stuNo",detail.getStuNo());
|
|
// 设置学生姓名
|
|
studentMap.put("name",detail.getName());
|
|
// 设置学生床位ID
|
|
studentMap.put("bedId",ds1.getBedId());
|
|
// 将学生信息添加到列表中
|
|
studentList.add(studentMap);
|
|
}
|
|
// 将已选择学生信息列表添加到宿舍信息Map中
|
|
map.put("studentList",studentList);
|
|
// 将宿舍信息添加到最终列表中
|
|
list.add(map);
|
|
}
|
|
//返回结果
|
|
return Result.ok(list);
|
|
|
|
}
|
|
//提交选择宿舍信息
|
|
@PostMapping("select_dormitory_submit")
|
|
public Result select_dormitory(@RequestBody Map<String,String> map, HttpServletRequest request){
|
|
// 从请求属性中获取学生信息
|
|
Student param = (Student)request.getAttribute("student");
|
|
// 根据学生ID获取学生详细信息
|
|
Student student = studentService.detail(param.getId());
|
|
// 根据班级ID查询可选时间段列表
|
|
List<Selection> selections = selectionService.queryByClazzId(student.getClazzId());
|
|
// 如果未设置或没有可选时间段
|
|
if(selections != null && selections.size()==0){
|
|
// 返回结果
|
|
return Result.fail("操作失败,未设置!请联系管理员");
|
|
}
|
|
// 获取第一个可选时间段
|
|
Selection selection = selections.get(0);
|
|
//判断当前时间是否在可选时间段内
|
|
if(selection.getStartTime().getTime() > System.currentTimeMillis() || System.currentTimeMillis() > selection.getEndTime().getTime()){
|
|
// 返回结果
|
|
return Result.fail("操作失败,不在时间段内选择");
|
|
}
|
|
// 从请求体中获取床位ID
|
|
String bedId = map.get("bedId");
|
|
// 从请求体中获取宿舍ID
|
|
String dormitoryId = map.get("dormitoryId");
|
|
// 根据学生ID、宿舍ID和床位ID提交选择宿舍请求
|
|
int row = dormitoryStudentService.select_dormitory_submit(student.getId(),Integer.parseInt(dormitoryId),Integer.parseInt(bedId));
|
|
//判断是否提交成功
|
|
if(row > 0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//创建报修记录
|
|
@PostMapping("repair_create")
|
|
public Result repair_create(@RequestBody Repair repair,HttpServletRequest request){
|
|
// 从请求属性中获取学生信息
|
|
Student param = (Student)request.getAttribute("student");
|
|
// 创建DormitoryStudent对象
|
|
DormitoryStudent ds = new DormitoryStudent();
|
|
// 设置学生ID
|
|
ds.setStudentId(param.getId());
|
|
// 查询学生的宿舍信息
|
|
PageInfo<DormitoryStudent> pageInfo = dormitoryStudentService.query(ds);
|
|
// 初始化
|
|
PageInfo<Notice> noticePageInfo = null;
|
|
// 判断是否存在关联的宿舍信息
|
|
if(pageInfo.getList() != null && pageInfo.getList().size() > 0){
|
|
// 获取第一个关联的宿舍信息
|
|
DormitoryStudent dormitoryStudent = pageInfo.getList().get(0);
|
|
// 根据宿舍ID获取宿舍详细信息
|
|
Dormitory detail = dormitoryService.detail(dormitoryStudent.getDormitoryId());
|
|
// 设置维修记录的建筑ID
|
|
repair.setBuildingId(detail.getBuildingId());
|
|
// 设置维修记录的宿舍ID
|
|
repair.setDormitoryId(dormitoryStudent.getDormitoryId());
|
|
// 设置维修记录的学生ID
|
|
repair.setStudentId(param.getId());
|
|
// 设置维修记录的创建日期
|
|
repair.setCreateDate(new Date());
|
|
// 设置维修记录的状态
|
|
repair.setStatus(0);
|
|
// 提交维修记录并获取操作结果标志
|
|
int flag = repairService.create(repair);
|
|
//判断是否提交成功
|
|
if(flag > 0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}else{
|
|
//返回结果
|
|
return Result.fail("操作失败,没有关联的宿舍");
|
|
}
|
|
}
|
|
//查询公告信息
|
|
@PostMapping("notice_query")
|
|
public Map<String, Object> notice_query(@RequestBody Notice notice,HttpServletRequest request){
|
|
// 从请求属性中获取学生信息
|
|
Student param = (Student)request.getAttribute("student");
|
|
// 创建DormitoryStudent对象
|
|
DormitoryStudent ds = new DormitoryStudent();
|
|
// 设置学生ID
|
|
ds.setStudentId(param.getId());
|
|
// 查询学生关联的宿舍信息
|
|
PageInfo<DormitoryStudent> pageInfo = dormitoryStudentService.query(ds);
|
|
// 初始化
|
|
PageInfo<Notice> noticePageInfo = null;
|
|
// 判断是否存在关联的宿舍信息
|
|
if(pageInfo.getList() != null && pageInfo.getList().size() > 0){
|
|
// 获取第一个关联的宿舍信息
|
|
DormitoryStudent dormitoryStudent = pageInfo.getList().get(0);
|
|
// 根据宿舍ID获取宿舍详细信息
|
|
Dormitory detail = dormitoryService.detail(dormitoryStudent.getDormitoryId());
|
|
// 设置通知的建筑ID
|
|
notice.setBuildingId(detail.getBuildingId());
|
|
// 根据建筑ID查询通知列表
|
|
noticePageInfo = noticeService.queryByBuildingId(notice);
|
|
// 遍历通知列表
|
|
noticePageInfo.getList().forEach(entity->{
|
|
// 根据用户ID获取用户详细信息并设置到通知中
|
|
entity.setUser(userService.detail(entity.getUserId()));
|
|
});
|
|
}else{
|
|
// 如果不存在关联的宿舍信息初始化
|
|
noticePageInfo = new PageInfo<>(null);
|
|
}
|
|
//返回结果
|
|
return Result.ok(noticePageInfo);
|
|
}
|
|
} |