84 lines
2.7 KiB
Java
84 lines
2.7 KiB
Java
package com.baiyun.controller.admin;
|
|
|
|
import java.util.List;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import com.baiyun.enity.Departments;
|
|
import com.baiyun.service.admin.DepartmentService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
/**
|
|
* @Description: TODO
|
|
* @author: bilibili
|
|
* @Date: 2021年6月14日
|
|
*/
|
|
@Controller
|
|
@RequestMapping("/department")
|
|
public class DepartmentController {
|
|
@Autowired
|
|
DepartmentService departmentService;
|
|
|
|
@RequestMapping("/listDepartments")
|
|
public String listDepartments(@RequestParam(defaultValue = "1") int pageNum,
|
|
@RequestParam(defaultValue = "6") int pageSize, Model model) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
List<Departments> departments = departmentService.listAllDepartments();
|
|
PageInfo<Departments> departmentsPageInfo = new PageInfo<>(departments);
|
|
model.addAttribute("departments", departmentsPageInfo);
|
|
model.addAttribute("search", "");
|
|
return "admin/listDepartment";
|
|
}
|
|
|
|
// 修改科室(回显数据)
|
|
@RequestMapping("updateDepartmentById")
|
|
public String updateDepartmentById(@RequestParam(defaultValue = "0") int id, Model model) {
|
|
Departments department = departmentService.findDepartmentById(id);
|
|
model.addAttribute("department", department);
|
|
return "admin/updateDepartment";
|
|
}
|
|
|
|
// 修改
|
|
@RequestMapping("updateDepartmentByIdIng")
|
|
public String updateDepartmentByIdIng(Departments department) {
|
|
int i = departmentService.updateDepartment(department);
|
|
return "redirect:/department/listDepartments";
|
|
}
|
|
|
|
// 根据科室名查找科室
|
|
@RequestMapping("findDepartmentByName")
|
|
public String findDepartmentByName(@RequestParam(defaultValue = "hello") String search, Model model) {
|
|
List<Departments> departments = departmentService.findDepartmentByName(search);
|
|
model.addAttribute("departments", departments);
|
|
model.addAttribute("search", search);
|
|
return "admin/listDepartment";
|
|
}
|
|
|
|
// 跳转添加科室页面
|
|
@RequestMapping("toAddDepartment")
|
|
public String toAddDepartment() {
|
|
return "admin/addDepartment";
|
|
}
|
|
|
|
// 添加科室
|
|
@RequestMapping("addDepartment")
|
|
@ResponseBody
|
|
public String addDepartment(Departments department) {
|
|
int i = departmentService.addDepartment(department);
|
|
return "admin/listDepartment";
|
|
}
|
|
|
|
// 根据id删除科室
|
|
@RequestMapping("deleteDepartmentById")
|
|
public String deleteDepartmentById(int id) {
|
|
int i = departmentService.deleteDepartmentById(id);
|
|
return "redirect:/department/listDepartments";
|
|
}
|
|
}
|