package com.cyh.contorller;
import com.cyh.bean.Appointment;
import com.cyh.bean.Vaccunit;
import com.cyh.service.AppointmentService;
import com.cyh.service.VaccunitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.List;
/**
* @author: Administrator
* @create: 2023-05-08 16:57
**/
@Controller
public class AppointmentContorller {
ModelAndView mv = null;
@Autowired
AppointmentService appointmentService;
@Autowired
VaccunitService vaccunitService;
@RequestMapping("/login")
public ModelAndView login() {
mv = new ModelAndView();
List<Appointment> logins = appointmentService.logins();
mv.addObject("user", logins);
mv.setViewName("zhuye");
return mv;
}
@RequestMapping("/selectAll")
@ResponseBody
public List<Appointment> selectAll() {
List<Appointment> selectAll = appointmentService.logins();
return selectAll;
}
@RequestMapping("/add")
public ModelAndView add(Appointment appointment) {
mv = new ModelAndView();
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
appointment.setBirthday(nowTime);
boolean add = appointmentService.add(appointment);
mv.addObject("user", add);
mv.setViewName("redirect:selectAll");
return mv;
}
@RequestMapping("/dell")
public ModelAndView dell(int aid) {
System.out.println(aid);
mv = new ModelAndView();
appointmentService.dell(aid);
mv.setViewName("redirect:selectAll");
return mv;
}
@RequestMapping("/findByVid")
public ModelAndView findByVid(int vid) {
System.out.println(1);
mv = new ModelAndView();
int count = appointmentService.count(vid);
Vaccunit byVid = vaccunitService.login(vid);
mv.addObject("byVid", byVid);
mv.addObject("count", count);
mv.setViewName("statistics");
return mv;
}
@RequestMapping("/show")
public ModelAndView show(int aid) {
mv = new ModelAndView();
Appointment show = appointmentService.show(aid);
mv.addObject("show", show);
mv.setViewName("show");
return mv;
}
@RequestMapping("showGai")
public ModelAndView showGai(Appointment appointment) {
mv = new ModelAndView();
Timestamp nowTime = new Timestamp(System.currentTimeMillis());
appointment.setBirthday(nowTime);
System.out.println(appointment);
appointmentService.showGai(appointment);
mv.setViewName("index");
return mv;
}
@RequestMapping("/obscure")
public ModelAndView obscure(Appointment appointment,String person) {
mv = new ModelAndView();
// List<Appointment> obscure = appointmentService.obscure(appointment);
List<Appointment> obscure = appointmentService.obscure(person);
if (obscure.isEmpty()||person==null) {
mv.setViewName("redirect:login");
} else {
mv.addObject("user", obscure);
mv.setViewName("zhuye");
}
return mv;
}
}