Registered-reservation-syst.../src/Springboot_hosptial/src/main/java/com/baiyun/controller/front/PatientController.java

109 lines
3.0 KiB
Java

package com.baiyun.controller.front;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.baiyun.enity.Departments;
import com.baiyun.enity.Doctors;
import com.baiyun.enity.Patients;
import com.baiyun.service.admin.DepartmentService;
import com.baiyun.service.admin.DoctorService;
import com.baiyun.service.front.PatientsService;
/**
* @Description: TODO
* @author: bilibili
* @Date: 2021年6月14日
*/
@Controller
@RequestMapping("/patient")
public class PatientController {
@Autowired
private PatientsService patientsService;
@Autowired
private DepartmentService departmentService;
@Autowired
private DoctorService doctorService;
@RequestMapping("toLogin")
public String toLogin() {
return "front/patientLogin";
}
@RequestMapping("/login")
public String login(@RequestParam String name, @RequestParam String password, HttpSession httpSession,
RedirectAttributes redirectAttributes) {
Patients plogin = patientsService.plogin(name, password);
if (plogin != null) {
plogin.setPassword("*****");// 隐藏密码
httpSession.setAttribute("patientUser", plogin);
System.out.println("登陆成功!");
return "redirect:/index";
} else {
redirectAttributes.addFlashAttribute("msg", "用户名或者密码错误");
return "redirect:/patient/toLogin";
}
}
@RequestMapping("/logout")
public String logout(HttpSession session) {
session.removeAttribute("patientUser");
return "redirect:/patient/toLogin";
}
@RequestMapping("/index")
public String toIndex() {
return "redirect:/index";
}
// 跳到注册页面
@RequestMapping("/register")
public String register() {
return "front/register";
}
// 把注册信息写入数据库
@RequestMapping("/registering")
public String registering(Patients patients) {
patientsService.registerPatient(patients);
System.out.println("---------------------" + patients);
return "front/index";
}
// 跳到挂号界面(先选科室)
@RequestMapping("/guahao")
public String guahao(Model model) {
List<Departments> departments = departmentService.listAllDepartments();
model.addAttribute("departments", departments);
return "front/chooseDept";
}
// 跳到对应的科室挂号
@RequestMapping("guaHaoIng")
public String guaHaoIng(@RequestParam(defaultValue = "0") int id, Model model) {
Departments department = departmentService.findDepartmentById(id);
List<Doctors> doctors = doctorService.findDoctorByDptId(id);
model.addAttribute("department", department);
model.addAttribute("doctors", doctors);
return "front/guahao";
}
// 提交挂号
// 跳到挂号查询
@RequestMapping("/searchgh")
public String searchgh() {
return "front/patientFind";
}
}