package controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import service.DoctorService;
import service.UserService;
import tools.Pager;
import entity.Doctor;
import entity.User;
import exception.ServiceException;

@Controller
public class DoctorController {

	@Autowired
	private DoctorService doctorService;
	@Autowired
	private UserService userService;

	@RequestMapping("/findDoctorByPage.do")
	public @ResponseBody
	HashMap<String, Object> toDoctorManage(Integer page,Integer limit, HttpServletRequest request) {
		Pager<Doctor> pager = null;
		try {
			pager = doctorService.findDoctorByPage(page, limit);
			request.setAttribute("page", page);
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", pager.getPageCount());
		map.put("data", pager.getContent());
		return map;
	}

	@RequestMapping("/removeDoctorById.do")
	public @ResponseBody String removeDoctorById(Integer did) {
		try {
			doctorService.removeDoctor(did);
		} catch (ServiceException e) {
			e.printStackTrace();
			return "{\"msg\":\"2\"}";
		}
		return "{\"msg\":\"1\"}";
	}

	@RequestMapping("/addOrModifyDoctor.do")
	public @ResponseBody String addDoctor(Integer did,Integer uid,String name, String username, String password, String titel, String subject,
			String sex, String education) throws Exception {
		try {
			User user = new User();
			user.setId(uid);
			user.setUsername(username);
			user.setPassword(password);
			user.setRole(1);
			
			Doctor doctor = new Doctor();
			doctor.setDid(did);
			doctor.setEducation(education);
			doctor.setName(name);
			doctor.setSex(sex);
			doctor.setSubject(subject);
			doctor.setTitel(titel);
			doctor.setUser(user);
			
			if(did==null){
				doctorService.registDoctor(doctor);
			}else{
				doctorService.modifyDoctor(doctor);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			throw e;
		}
		return "";
	}
	
	@RequestMapping("/showDoctorAdd.do")
	public String toUpdateDoctor(Integer did,HttpServletRequest request){
		try {
			if(did!=null){
				Doctor doctor = doctorService.findDoctorById(did);
				request.setAttribute("doctor", doctor);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
		}
		return "doctor/doctorAdd";
	}
	@RequestMapping("getDoctorBySubject")
	public @ResponseBody List<Doctor> getDoctorBySubject(String subject){
		System.out.println(subject);
		List<Doctor> doctors = null;
		try {
			doctors = doctorService.findDoctorBySubject(subject);
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doctors;
	}

	public DoctorService getDoctorService() {
		return doctorService;
	}

	public void setDoctorService(DoctorService doctorService) {
		this.doctorService = doctorService;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}
最近下载更多
Mr_VVcat  LV8 4月16日
FF加菲猫  LV4 2月15日
fengyezi1205  LV1 2023年11月8日
xxu0219  LV2 2023年3月22日
1355862436  LV9 2022年11月3日
wanghsm  LV4 2022年6月9日
yinxunyu12138  LV11 2022年5月6日
wangxin199804  LV9 2022年4月18日
591231555  LV20 2022年4月18日
马小雨  LV2 2022年4月13日
最近浏览更多
Mr_VVcat  LV8 4月16日
plecon  LV1 3月26日
jc121140  LV3 3月23日
谢谢谢谢谢谢你  LV6 2月28日
Hopu2024  LV2 2月23日
FF加菲猫  LV4 2月15日
Mirage无衣 1月16日
暂无贡献等级
iiiiiiixiiiiii  LV1 1月5日
小安同学  LV7 2023年12月30日
阡陌兮然 2023年12月14日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友