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.
91 lines
2.6 KiB
91 lines
2.6 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Bed;
|
|
import com.yanzhen.service.BedService;
|
|
import com.yanzhen.service.DormitoryStudentService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
//BedController控制类
|
|
@RestController
|
|
@RequestMapping("/bed")
|
|
public class BedController {
|
|
|
|
//注入实例--处理与学生宿舍相关的业务逻辑
|
|
//注入床位的实例
|
|
@Autowired
|
|
private BedService bedService;
|
|
//注入学生宿舍的实例
|
|
@Autowired
|
|
private DormitoryStudentService dormitoryStudentService;
|
|
|
|
//创建床位对象
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Bed bed){
|
|
//调用床位的服务层create方法删除床位
|
|
int flag = bedService.create(bed);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
//根据床位id删除床位
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//调用床位的服务层delete方法删除床位
|
|
int flag = bedService.delete(ids);
|
|
//判断删除是否成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
// 更新床位记录
|
|
@PostMapping("update")
|
|
// 从请求体中获取更新后的Bed对象
|
|
public Result update(@RequestBody Bed bed){
|
|
//调用床位的服务层update方法更新床位
|
|
int flag = bedService.update(bed);
|
|
//判断更新是否成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
|
|
// 遍历查询--为每个床位设置对应的学生信息
|
|
@GetMapping("detail")
|
|
// 调用bedService的detail方法获取床位详情并返回
|
|
public Bed detail(Integer id){
|
|
return bedService.detail(id);
|
|
}
|
|
//分页查询
|
|
@PostMapping("query")
|
|
// 从请求体中获取查询条件Bed对象--分页显示
|
|
public Map<String,Object> query(@RequestBody Bed bed){
|
|
//创建分页对象
|
|
PageInfo<Bed> pageInfo = bedService.query(bed);
|
|
//遍历
|
|
pageInfo.getList().forEach(entity->{
|
|
entity.setStudent(dormitoryStudentService.queryStudentByBedId(entity.getId()));
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
}
|