package com.gxw.controller;
import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
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.Hospital;
import com.gxw.service.HospitalService;
import com.gxw.util.StringUtil;
import net.sf.json.JSONArray;
/**
* 医院管理控制器
*
*@author GXWadmin
*
*/
@RequestMapping("/hospital")
@Controller
public class HospitalController {
@Autowired
private HospitalService hospitalService;
/**
* 医院列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("hospital/hospital_list");
return model;
}
/**
* 获取医院列表页面
* @param page
* @param hName
* @param hTelephone
* @param hAddress
* @return
*/
@RequestMapping(value="/get_list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(
@RequestParam(value="hName",required=false,defaultValue="") String hName,
Page page
){
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("hName", "%"+hName+"%");
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
map.put("rows", hospitalService.findList(queryMap));
map.put("total", hospitalService.getTotal(queryMap));
return map;
}
/**
* 编辑医院信息
* @param hospital
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Hospital hospital){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(hospital.gethName())){
ret.put("type", "error");
ret.put("msg", "名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(hospital.gethTelephone())){
ret.put("type", "error");
ret.put("msg", "电话不能为空!");
return ret;
}
if(StringUtils.isEmpty(hospital.gethAddress())){
ret.put("type", "error");
ret.put("msg", "地址不能为空!");
return ret;
}
if(hospitalService.edit(hospital) <= 0){
ret.put("type", "error");
ret.put("msg", "医院信息添加失败!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "医院信息修改成功!");
return ret;
}
/**
* 添加医院信息
* @param hospital
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Hospital hospital){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(hospital.gethName())){
ret.put("type", "error");
ret.put("msg", "名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(hospital.gethTelephone())){
ret.put("type", "error");
ret.put("msg", "电话不能为空!");
return ret;
}
if(StringUtils.isEmpty(hospital.gethAddress())){
ret.put("type", "error");
ret.put("msg", "地址不能为空!");
return ret;
}
if(hospitalService.add(hospital)<= 0){
ret.put("type", "error");
ret.put("msg", "医院信息添加失败");
return ret;
}
ret.put("type", "success");
ret.put("msg", "医院信息修改成功!");
return ret;
}
/**
* 删除医院信息
* @param hids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(
@RequestParam(value="hids[]",required=true) Long[] hids
){
Map<String, String> ret = new HashMap<String, String>();
//id为空或长度为0
if(hids == null || hids.length == 0){
ret.put("type", "error");
ret.put("msg", "请选择要删除的数据!");
return ret;
}
try {
if(hospitalService.delete(StringUtil.joinString(Arrays.asList(hids), ",")) <= 0){
ret.put("type", "error");
ret.put("msg", "删除失败!");
return ret;
}
} catch (Exception e) {
// TODO: handle exception
ret.put("type", "error");
ret.put("msg", "该医院信息已经存在!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "信息删除成功!");
return ret;
}
/**
* 上传图片
* @param hPhoto
* @param request
* @return
*/
@RequestMapping(value="/upload_hPhoto",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> uploadhPhoto(MultipartFile hPhoto,HttpServletRequest request){
Map<String, String> ret = new HashMap<String, String>();
if(hPhoto == null){
ret.put("type", "error");
ret.put("msg", "选择要上传的文件!");
return ret;
}
if(hPhoto.getSize() > 1024*1024*1024){
ret.put("type", "error");
ret.put("msg", "文件大小不能超过10M!");
return ret;
}
//获取文件后缀
String suffix = hPhoto.getOriginalFilename().substring(hPhoto.getOriginalFilename().lastIndexOf(".")+1,hPhoto.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 {
//将文件保存至指定目录
hPhoto.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;
}
}
最近下载更多
guozhihua12 LV3
2024年5月6日
tangguo666666 LV4
2023年6月5日
zxc131313 LV12
2022年10月23日
AlanLi LV19
2022年6月17日
109683670 LV9
2022年4月18日
java代写 LV7
2022年3月15日
wanglinddad LV55
2022年2月15日
lilong007 LV23
2021年12月20日
893213895 LV18
2021年12月16日
deck222 LV9
2021年12月12日
最近浏览更多
奋斗的小蚂蚁 LV15
10月17日
dddding yang LV6
9月15日
qixisb250dasb
5月6日
暂无贡献等级
1516299986 LV9
4月26日
wwb521 LV7
3月27日
AnthemLights LV1
1月1日
xianyu091012 LV5
2024年12月26日
yimaoermao LV1
2024年11月28日
杨秀益 LV1
2024年11月7日
JlikeL LV6
2024年9月24日

