199 lines
5.8 KiB
Java
199 lines
5.8 KiB
Java
package com.baiyun.controller.admin;
|
||
|
||
import java.util.List;
|
||
|
||
import javax.servlet.http.HttpSession;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.ui.Model;
|
||
import org.springframework.web.bind.annotation.GetMapping;
|
||
import org.springframework.web.bind.annotation.PostMapping;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||
|
||
import com.baiyun.enity.Admin;
|
||
import com.baiyun.enity.Patients;
|
||
import com.baiyun.enity.Registers;
|
||
import com.baiyun.service.admin.AdminService;
|
||
import com.baiyun.service.front.PatientsService;
|
||
import com.baiyun.service.front.RegisterService;
|
||
import com.github.pagehelper.PageHelper;
|
||
import com.github.pagehelper.PageInfo;
|
||
|
||
/**
|
||
* @Description: TODO
|
||
* @author: bilibili
|
||
* @Date: 2021年6月14日
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/admin")
|
||
public class AdminController {
|
||
|
||
@Autowired
|
||
private AdminService adminService;
|
||
|
||
@Autowired
|
||
private PatientsService patientsService;
|
||
|
||
@Autowired
|
||
private RegisterService registerService;
|
||
|
||
/*
|
||
* 若用户未跳转到登录页
|
||
*/
|
||
@GetMapping("")
|
||
public String toLogin(HttpSession httpSession) {
|
||
Admin admin = (Admin) httpSession.getAttribute("adminUser");
|
||
if (admin != null) {
|
||
System.out.println("登陆成功1!");
|
||
return "redirect:admin/searchAllPatients";
|
||
}
|
||
return "login";
|
||
}
|
||
|
||
/*
|
||
* 登录功能的实现
|
||
*/
|
||
@PostMapping("/login")
|
||
public Object login(Admin admin, HttpSession httpSession, RedirectAttributes redirectAttributes) throws Exception {
|
||
// System.out.println("=========================================================");
|
||
String adminName = admin.getAdminName();
|
||
String adminPassword = admin.getAdminPassword();
|
||
admin = adminService.login(adminName, adminPassword);
|
||
if (admin != null) {
|
||
admin.setAdminPassword("*****");// 隐藏密码
|
||
httpSession.setAttribute("adminUser", admin);
|
||
System.out.println("登陆成功2!");
|
||
return "redirect:/admin/searchAllPatients";
|
||
} else {
|
||
redirectAttributes.addFlashAttribute("msg", "用户或密码错误");
|
||
return "redirect:/admin";
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 退出功能的实现
|
||
*/
|
||
@GetMapping("/logout")
|
||
public String logout(HttpSession session) {
|
||
session.removeAttribute("adminUser");
|
||
return "redirect:/admin";
|
||
}
|
||
|
||
/*
|
||
* 跳转管理员首页
|
||
*/
|
||
@GetMapping("/index")
|
||
public String index() {
|
||
return "admin/listPatients";
|
||
}
|
||
|
||
/*
|
||
* 列出所有患者
|
||
*/
|
||
@GetMapping("/searchAllPatients")
|
||
public String searchAllPatients(@RequestParam(defaultValue = "1") int pageNum,
|
||
@RequestParam(defaultValue = "6") int pageSize, Model model) {
|
||
PageHelper.startPage(pageNum, pageSize);
|
||
List<Patients> patients = patientsService.searchAllPatients();
|
||
PageInfo<Patients> pageInfo = new PageInfo<>(patients);
|
||
model.addAttribute("patients", pageInfo);
|
||
model.addAttribute("search", "");
|
||
// System.out.println("---------------------"+patientsPageInfo);
|
||
return "admin/listPatients";
|
||
}
|
||
|
||
/*
|
||
* 列出所有挂号信息
|
||
*/
|
||
@GetMapping("/searchAllRegisters")
|
||
public String searchAllRegisters(@RequestParam(defaultValue = "1") int pageNum,
|
||
@RequestParam(defaultValue = "6") int pageSize, Model model) {
|
||
PageHelper.startPage(pageNum, pageSize);
|
||
List<Registers> registers = registerService.findAllRegisters();
|
||
PageInfo<Registers> pageInfo = new PageInfo<>(registers);
|
||
model.addAttribute("registers", pageInfo);
|
||
model.addAttribute("search", "");
|
||
// System.out.println("---------------------"+patientsPageInfo);
|
||
return "admin/listRegisters";
|
||
}
|
||
|
||
/*
|
||
* 删除患者
|
||
*/
|
||
@RequestMapping("/deletePatient")
|
||
public String deletePatientById(@RequestParam(defaultValue = "0") int id) {
|
||
int i = adminService.deletePatientById(id);
|
||
System.out.println("------------------------" + i);
|
||
// return "admin/alogin";
|
||
return "redirect:/admin/searchAllPatients";
|
||
}
|
||
|
||
/*
|
||
* 修改患者(进入修改页面 )
|
||
*/
|
||
@RequestMapping("updatePatientById")
|
||
public String updatePatientById(@RequestParam(defaultValue = "0") int id, Model model) {
|
||
Patients patient = adminService.findPatientById(id);
|
||
model.addAttribute("patient", patient);
|
||
return "/admin/updatePatient";
|
||
}
|
||
|
||
/*
|
||
* 修改
|
||
*/
|
||
@RequestMapping("updatePatientByIdIng")
|
||
public String updatePatientByIdIng(Patients patient) {
|
||
adminService.updatePatientById(patient);
|
||
System.out.println("修改成功");
|
||
return "redirect:/admin/searchAllPatients";
|
||
}
|
||
|
||
/*
|
||
* 根据姓名或身份证号查找患者
|
||
*/
|
||
@RequestMapping("SearchPatientsByNameOrID")
|
||
public String SearchPatientsByNameOrID(@RequestParam(defaultValue = "1") int pageNum,
|
||
@RequestParam(defaultValue = "20") int pageSize, @RequestParam(defaultValue = "") String search,
|
||
Model model) {
|
||
PageHelper.startPage(pageNum, pageSize);
|
||
List<Patients> patients = adminService.SearchPatientsByNameOrID(search);
|
||
PageInfo<Patients> patientsPageInfo = new PageInfo<>(patients);
|
||
model.addAttribute("patients", patientsPageInfo);
|
||
|
||
model.addAttribute("search", search);
|
||
System.out.println("---------------------" + patientsPageInfo);
|
||
return "admin/listPatients";
|
||
}
|
||
|
||
/*
|
||
* 跳到管理员添加页面
|
||
*/
|
||
@RequestMapping("/addPatient")
|
||
public String addPatient() {
|
||
return "admin/addPatient";
|
||
}
|
||
|
||
/*
|
||
* 把注册信息写入数据库
|
||
*/
|
||
@RequestMapping("/addPatientIng")
|
||
public String registering(Patients patients) {
|
||
patientsService.registerPatient(patients);
|
||
System.out.println("---------------------" + patients);
|
||
return "redirect:/admin/searchAllPatients";
|
||
}
|
||
|
||
/*
|
||
* 删除医生
|
||
*/
|
||
@RequestMapping("/deleteDoctorById")
|
||
public String deleteDoctorById(@RequestParam(defaultValue = "0") int id) {
|
||
int i = adminService.deletePatientById(id);
|
||
System.out.println("------------------------" + i);
|
||
return "redirect:/doctor/listDoctors";
|
||
}
|
||
}
|