package com.gxw.controller; import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; 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.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import com.gxw.page.Page; import com.gxw.pojo.Doctor; import com.gxw.service.DoctorService; /** * 医生信息管理 * * @author GXWdoctor * */ @RequestMapping("/doctor") @Controller public class DoctorController { @Autowired private DoctorService doctorService; /** * 医生信息列表 * * @param model * @return */ @RequestMapping(value = "/list", method = RequestMethod.GET) public ModelAndView tolist(ModelAndView model) { model.setViewName("doctor/doctor_list"); return model; } /** * 获取医生信息列表 * * @param aName * @param page * @return */ @RequestMapping(value = "/get_list", method = RequestMethod.POST) @ResponseBody public Map<String, Object> getList( @RequestParam(value = "dName", required = false, defaultValue = "") String dName, Page page) { Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> queryMap = new HashMap<String, Object>(); queryMap.put("dName", "%" + dName + "%"); queryMap.put("offset", page.getOffset()); queryMap.put("pageSize", page.getRows()); map.put("rows", doctorService.findList(queryMap)); map.put("total", doctorService.getTotal(queryMap)); return map; } /** * 添加医生操作 * * @param doctor * @return */ @RequestMapping(value = "/add", method = RequestMethod.POST) @ResponseBody public Map<String, String> toadd(Doctor doctor) { Map<String, String> ret = new HashMap<String, String>(); if (doctor == null) { ret.put("type", "error"); ret.put("msg", "数据绑定出错,请联系后台管理员!"); return ret; } if (StringUtils.isEmpty(doctor.getdName())) { ret.put("type", "error"); ret.put("msg", "姓名不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdSex())) { ret.put("type", "error"); ret.put("msg", "性别不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdYear())) { ret.put("type", "error"); ret.put("msg", "从医年限不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdPhone())) { ret.put("type", "error"); ret.put("msg", "手机号不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdRole())) { ret.put("type", "error"); ret.put("msg", "角色不能为空!"); return ret; } Doctor existDoctor = doctorService.findBydName(doctor.getdName()); if (existDoctor != null) { ret.put("type", "error"); ret.put("msg", "该医生姓名已经存在!"); return ret; } if (doctorService.add(doctor) <= 0) { ret.put("type", "error"); ret.put("msg", "添加失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "添加成功!"); return ret; } /** * 编辑管理员操作 * * @param doctor * @return */ @RequestMapping(value = "/edit", method = RequestMethod.POST) @ResponseBody public Map<String, String> edit(Doctor doctor) { Map<String, String> ret = new HashMap<String, String>(); if (doctor == null) { ret.put("type", "error"); ret.put("msg", "数据绑定出错,请联系后台管理员!"); return ret; } if (StringUtils.isEmpty(doctor.getdName())) { ret.put("type", "error"); ret.put("msg", "姓名不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdSex())) { ret.put("type", "error"); ret.put("msg", "性别不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdYear())) { ret.put("type", "error"); ret.put("msg", "从医年限不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdPhone())) { ret.put("type", "error"); ret.put("msg", "手机号不能为空!"); return ret; } if (StringUtils.isEmpty(doctor.getdRole())) { ret.put("type", "error"); ret.put("msg", "角色不能为空!"); return ret; } Doctor existDoctor = doctorService.findBydName(doctor.getdName()); if (existDoctor != null) { ret.put("type", "error"); ret.put("msg", "该医生姓名已经存在!"); return ret; } if (doctorService.edit(doctor) <= 0) { ret.put("type", "error"); ret.put("msg", "修改失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "修改成功!"); return ret; } /** * 删除管理员操作 * * @param doctor * @return */ @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody public Map<String, String> delete( @RequestParam(value = "dIds[]", required = true) int[] dIds) { Map<String, String> ret = new HashMap<String, String>(); if (dIds == null) { ret.put("type", "error"); ret.put("msg", "请选择要删除的数据!"); return ret; } String dIdsString = ""; for (int dId : dIds) { dIdsString += dId + ","; } dIdsString = dIdsString.substring(0, dIdsString.length() - 1); if (doctorService.delete(dIdsString) <= 0) { ret.put("type", "error"); ret.put("msg", "删除失败!"); return ret; } ret.put("type", "success"); ret.put("msg", "删除成功!"); return ret; } /** * 上传图片 * @param dPhoto * @param request * @return */ @RequestMapping(value="/upload_dPhoto",method=RequestMethod.POST) @ResponseBody public Map<String, String> uploaddPhoto(MultipartFile dPhoto,HttpServletRequest request){ Map<String, String> ret = new HashMap<String, String>(); if(dPhoto == null){ ret.put("type", "error"); ret.put("msg", "选择要上传的文件!"); return ret; } if(dPhoto.getSize() > 1024*1024*1024){ ret.put("type", "error"); ret.put("msg", "文件大小不能超过10M!"); return ret; } //获取文件后缀 String suffix = dPhoto.getOriginalFilename().substring(dPhoto.getOriginalFilename().lastIndexOf(".")+1,dPhoto.getOriginalFilename().length()); if(!"jpg,jpeg,gif,png".toUpperCase().contains(suffix.toUpperCase())){ ret.put("type", "error"); ret.put("msg", "请选择jpg,jpeg,gif,png格式的图片!"); return ret; } String savePath = request.getServletContext().getRealPath("/") + "/resources/upload/"; File savePathFile = new File(savePath); if(!savePathFile.exists()){ //若不存在改目录,则创建目录 savePathFile.mkdir(); } String filename = new Date().getTime()+"."+suffix; try { //将文件保存至指定目录 dPhoto.transferTo(new File(savePath+filename)); }catch (Exception e) { // TODO Auto-generated catch block ret.put("type", "error"); ret.put("msg", "保存文件异常!"); e.printStackTrace(); return ret; } ret.put("type", "success"); ret.put("msg", "医生信息删除成功!"); ret.put("filepath",request.getServletContext().getContextPath() + "/resources/upload/" + filename ); return ret; } }
最近下载更多
tangguo666666 LV4
2023年6月5日
zxc131313 LV12
2022年10月23日
AlanLi LV18
2022年6月17日
109683670 LV9
2022年4月18日
java代写 LV7
2022年3月15日
wanglinddad LV54
2022年2月15日
lilong007 LV20
2021年12月20日
893213895 LV18
2021年12月16日
deck222 LV9
2021年12月12日
KSY247 LV5
2021年11月10日
最近浏览更多
爱丽淇 LV5
3月19日
a318888331 LV13
3月10日
FF加菲猫 LV4
2月15日
iiiiiiixiiiiii LV1
2023年12月28日
ziv5466123 LV7
2023年12月15日
cyz521213 LV1
2023年12月9日
mukoooo LV2
2023年12月5日
内心向阳 LV4
2023年11月8日
lyq6666666 LV5
2023年10月25日
沉默66666
2023年10月5日
暂无贡献等级