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.
88 lines
2.6 KiB
88 lines
2.6 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Student;
|
|
import com.yanzhen.entity.Visit;
|
|
import com.yanzhen.service.StudentService;
|
|
import com.yanzhen.service.VisitService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
//来访管理的控制器
|
|
@RestController
|
|
@RequestMapping("/visit")
|
|
public class VisitController {
|
|
//注入实例
|
|
//注入来访管理服务类
|
|
@Autowired
|
|
private VisitService visitService;
|
|
//注入学生服务类
|
|
@Autowired
|
|
private StudentService studentService;
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Visit visit){
|
|
//在来访管理服务类中引用create方法
|
|
int flag = visitService.create(visit);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//删除来访记录信息
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在来访管理服务类中引用delete方法
|
|
int flag = visitService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新来访信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Visit visit){
|
|
//在来访管理服务类中引用update方法
|
|
int flag = visitService.updateSelective(visit);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取来访详细信息
|
|
@GetMapping("detail")
|
|
public Visit detail(Integer id){
|
|
//返回结果
|
|
return visitService.detail(id);
|
|
}
|
|
//查询来访信息
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Visit visit){
|
|
//创建分页对象
|
|
PageInfo<Visit> pageInfo = visitService.query(visit);
|
|
// 遍历查询结果中的每条记录
|
|
pageInfo.getList().forEach(entity->{
|
|
// 根据学生 ID 获取学生的详细信息
|
|
Student detail = studentService.detail(entity.getStudentId());
|
|
// 将学生详细信息设置到访问记录中
|
|
entity.setStudent(detail);
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
|
|
} |