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.
122 lines
3.7 KiB
122 lines
3.7 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Absence;
|
|
import com.yanzhen.entity.Dormitory;
|
|
import com.yanzhen.entity.Student;
|
|
import com.yanzhen.service.AbsenceService;
|
|
import com.yanzhen.service.DormitoryService;
|
|
import com.yanzhen.service.StudentService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
//导入list和Map集合
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
//缺勤管理的控制器
|
|
@RestController
|
|
@RequestMapping("/absence")
|
|
public class AbsenceController {
|
|
|
|
//注入实例
|
|
//注入缺席的服务类
|
|
@Autowired
|
|
private AbsenceService absenceService;
|
|
//注入学生的服务类
|
|
@Autowired
|
|
private StudentService studentService;
|
|
//注入宿舍的服务类
|
|
@Autowired
|
|
private DormitoryService dormitoryService;
|
|
|
|
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Absence absence){
|
|
//在缺席的服务类中引用create方法啦创建新的实例
|
|
int flag = absenceService.create(absence);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
//根据学生id进行删除缺勤信息
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在缺席的服务类中引用delete方法删除实例
|
|
int flag = absenceService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
//更新缺勤信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Absence absence){
|
|
//在缺席的服务类中引用updateSelective方法更新信息
|
|
int flag = absenceService.updateSelective(absence);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
//根据id删除缺席信息
|
|
@GetMapping("detail")
|
|
public Absence detail(Integer id){
|
|
//返回结果
|
|
return absenceService.detail(id);
|
|
}
|
|
|
|
// 根据name查询学生ID--并分页的形式展示出
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Absence absence){
|
|
//创建分页对象
|
|
PageInfo<Absence> pageInfo = new PageInfo<Absence>();
|
|
//判断absence的页码是否为空
|
|
if(absence.getName() != null){
|
|
//不为空则调取缺席的名字赋给detailId
|
|
Student detailId = studentService.detailByName(absence.getName());
|
|
//如果detailId不为空再获取缺席的id
|
|
if(detailId != null){
|
|
absence.setStudentId(detailId.getId());
|
|
}else{
|
|
//若为空修改值都为null
|
|
pageInfo.setList(null);
|
|
//设置大小为0
|
|
pageInfo.setSize(0);
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
}
|
|
//给pageInfo赋值
|
|
pageInfo = absenceService.query(absence);
|
|
// 遍历查询结果列表
|
|
pageInfo.getList().forEach(entity->{
|
|
//创建对象
|
|
Student detail = studentService.detail(entity.getStudentId());
|
|
// 修改学生信息
|
|
entity.setStudent(detail);
|
|
Dormitory dormitory = dormitoryService.detail(entity.getDormitoryId());
|
|
entity.setDormitory(dormitory);
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
|
|
} |