• Java项目:SSM简单医院信息管理系统


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    管理员角色:
    登录,个人资料管理,用户管理,科室管理,医生管理,患者管理,科室项目管理,患者诊疗记录管理等功能。

    医生角色包含以下功能:
    医生角色登录,个人资料密码修改,科室查看,医生列表,患者信息查看,科室项目查看,添加患者诊疗记录等功能。

    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 

    5.数据库:MySql 5.7版本;

    技术栈

    1. 后端:Spring+SpringMVC+Mybatis

    2. 前端:HTML+CSS+JavaScript+jsp

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

    4. 运行项目,输入localhost:8080/ 登录

    运行截图

    管理员角色

     

     

     

     

     

     

     

    医生角色

     

     

     

     

     

     

     相关代码

    PatientController

    1. package com.qut.controller;
    2. import java.text.ParseException;
    3. import java.util.HashMap;
    4. import java.util.List;
    5. import java.util.Map;
    6. import javax.annotation.Resource;
    7. import javax.servlet.http.HttpServletRequest;
    8. import org.apache.ibatis.annotations.Param;
    9. import org.apache.log4j.Logger;
    10. import org.springframework.stereotype.Controller;
    11. import org.springframework.web.bind.annotation.RequestMapping;
    12. import org.springframework.web.bind.annotation.ResponseBody;
    13. import com.qut.pojo.Bed;
    14. import com.qut.pojo.Patient;
    15. import com.qut.pojo.PatientCode;
    16. import com.qut.pojo.Ward;
    17. import com.qut.pojo.User;
    18. import com.qut.service.BedService;
    19. import com.qut.service.PatientService;
    20. import com.qut.service.WardService;
    21. import com.qut.service.UserService;
    22. import com.qut.util.BaseUtils;
    23. import com.qut.util.JsonResult;
    24. import com.qut.util.MD5;
    25. import com.qut.util.Log4jLogsDetial;
    26. import net.sf.json.JSON;
    27. import net.sf.json.JSONSerializer;
    28. @Controller
    29. @RequestMapping("/patient")
    30. public class PatientController {
    31. @Resource(name = "patientService")
    32. private PatientService patientService;
    33. @Resource(name = "bedService")
    34. private BedService bedService;
    35. @Resource(name = "wardService")
    36. private WardService wardService;
    37. @Resource(name = "userService")
    38. private UserService userService;
    39. Logger log = Logger.getLogger(Log4jLogsDetial.class);
    40. @RequestMapping(value = "/patientAdd.do", produces = "application/json;charset=utf-8")
    41. @ResponseBody
    42. public String patientAdd(HttpServletRequest request) throws ParseException {
    43. Patient patient = new Patient();
    44. patient.setPatientId(System.currentTimeMillis() + "");
    45. patient.setName(request.getParameter("name"));
    46. patient.setDoctorId(BaseUtils.toInteger(request.getParameter("doctorNo")));
    47. patient.setNation(BaseUtils.toInteger(request.getParameter("nationNo")));
    48. patient.setDepartment(BaseUtils.toInteger(request.getParameter("departmentNo")));
    49. patient.setCerificateNo(request.getParameter("cerificateNo"));
    50. patient.setWorkUnit(request.getParameter("workUnit"));
    51. patient.setMaritalStatus(BaseUtils.toInteger(request.getParameter("marryNo")));
    52. patient.setGender(BaseUtils.toInteger(request.getParameter("genderNo")));
    53. patient.setHomeAddress(request.getParameter("homeAddress"));
    54. patient.setHomePhone(request.getParameter("homePhone"));
    55. patient.setContacts(request.getParameter("contacts"));
    56. patient.setContactsPhone(request.getParameter("contactsPhone"));
    57. patient.setAdmissionStatus(BaseUtils.toInteger(request.getParameter("statusNo")));
    58. patient.setRoomType(BaseUtils.toInteger(request.getParameter("typeNo")));
    59. patient.setRoomNo(BaseUtils.toInteger(request.getParameter("wardNo")));
    60. patient.setBedNo(BaseUtils.toInteger(request.getParameter("bedNo")));
    61. patient.setBirth(BaseUtils.toDate(request.getParameter("birth")));
    62. patient.setState(0);// 区别是否出院
    63. // 保存病人信息
    64. patientService.patientAdd(patient);
    65. log.info("患者" + request.getParameter("name") + "入院");
    66. // 记录床位信息
    67. wardService.logWard(patient);
    68. log.info("记录到病房变更");
    69. // 更改床位的状态
    70. Bed bed = new Bed();
    71. bed.setWardNo(patient.getRoomNo());
    72. bed.setBedNo(patient.getBedNo());
    73. bed.setState(1);
    74. bedService.bedUpdate(bed);
    75. log.info("更新床位状态");
    76. // 判断房间是否满,如果满就改变状态
    77. Ward ward = new Ward();
    78. ward.setWardNo(patient.getRoomNo());
    79. Integer patientNum = bedService.countwardpatient(bed);// 当前病房的患者数
    80. Integer wardspace = wardService.wardspace(ward);// 当前病房的额定容量
    81. if (patientNum == wardspace) {// 已经住满
    82. // 改变病房的状态
    83. ward.setWardNo(patient.getRoomNo());
    84. ward.setState(1);
    85. wardService.wardUpdate(ward);
    86. log.info("更新病房状态");
    87. }
    88. // 将患者的基本信息插入到user表,如果患者以前住过院,用户表里会存有患者身份证,则不再插入
    89. User user = new User();
    90. user.setId(request.getParameter("cerificateNo"));// 用户ID是患者入院的身份证号
    91. user.setName(request.getParameter("name"));// 用户姓名是患者的入院姓名
    92. String defaultpassword = "123456";
    93. defaultpassword = defaultpassword.trim();
    94. // MD5加密
    95. MD5 md5 = new MD5();
    96. String md5_password = new String();
    97. md5_password = md5.to_md5(defaultpassword);
    98. user.setPassword(md5_password);// 患者初始密码123456
    99. user.setDescribe(0);// 账户类型是0--患者
    100. User checkuser = userService.findUserById(request.getParameter("cerificateNo"));
    101. if (checkuser == null) {// 患者用户不存在,则注册为新用户;用户存在,不执行动作
    102. userService.register(user);
    103. log.info("患者" + patient.getName() + "开户:" + patient.getCerificateNo());
    104. } else {
    105. }
    106. JSON json = JSONSerializer.toJSON(new JsonResult(new Patient()));
    107. return json.toString();
    108. }
    109. @RequestMapping(value = "/patientQuery.do", produces = "application/json;charset=utf-8")
    110. @ResponseBody
    111. public String patientQuery(HttpServletRequest request) throws ParseException {
    112. PatientCode patientCode = new PatientCode();
    113. String patientId = BaseUtils.toString(request.getParameter("patientId"));
    114. String name = BaseUtils.toString(request.getParameter("name"));
    115. patientCode.setPatientId(patientId);
    116. patientCode.setDepartmentNo(BaseUtils.toInteger(request.getParameter("departmentNo")));
    117. // patientCode.setDocid(BaseUtils.toInteger(request.getParameter("Docid")));
    118. patientCode.setName(name);
    119. patientCode.setWardNo(BaseUtils.toInteger(request.getParameter("wardNo")));
    120. patientCode.setBedNo(BaseUtils.toInteger(request.getParameter("bedNo")));
    121. patientCode.setStart(BaseUtils.toDate(request.getParameter("start")));
    122. patientCode.setEnd(BaseUtils.toDate(request.getParameter("end")));
    123. patientCode.setOutStatus(0);// 设置出院状态为未出院
    124. // System.out.println("当前患者码为:" + patientCode);
    125. List> list = patientService.patientQuery(patientCode);
    126. log.info("患者查询");
    127. for (Map map : list) {// 此处不对从库中取出的时间做toString转化会报java.lang.IllegalArgumentException
    128. String admissionTime = map.get("admissionTime").toString();
    129. map.put("admissionTime", admissionTime);
    130. String birth = map.get("birth").toString();
    131. map.put("birth", birth);
    132. }
    133. JSON json = JSONSerializer.toJSON(new JsonResult>>(list));
    134. return json.toString();
    135. }
    136. @RequestMapping(value = "/patientQueryBycerificateNo.do", produces = "application/json;charset=utf-8")
    137. @ResponseBody
    138. public String patientQueryBycerificateNo(HttpServletRequest request) throws ParseException {
    139. String patientcerificateNo = BaseUtils.toString(request.getParameter("cerificateNo"));
    140. List> list = patientService.patientQueryBycerificateNo(patientcerificateNo);
    141. log.info("身份证" + patientcerificateNo + "患者查询信息");
    142. for (Map map : list) {// 此处不对从库中取出的时间做toString转化会报java.lang.IllegalArgumentException
    143. String admissionTime = map.get("admissionTime").toString();
    144. map.put("admissionTime", admissionTime);
    145. String birth = map.get("birth").toString();
    146. map.put("birth", birth);
    147. if (map.get("leaveTime") != null) {
    148. String leaveTime = map.get("leaveTime").toString();
    149. map.put("leaveTime", leaveTime);
    150. } else {
    151. String leaveTime = "未出院";
    152. map.put("leaveTime", leaveTime);
    153. }
    154. }
    155. JSON json = JSONSerializer.toJSON(new JsonResult>>(list));
    156. // System.out.println("返回的json是:"+json.toString());
    157. return json.toString();
    158. }
    159. /**
    160. * 检查新住院的这个患者是否有未出院的记录
    161. */
    162. @RequestMapping(value = "/patientcheck.do", produces = "application/json;charset=utf-8")
    163. @ResponseBody
    164. public String patientcheck(@Param("cerificateNo") String cerificateNo) throws ParseException {
    165. JSON json = null;
    166. PatientCode patientCode = new PatientCode();
    167. String patientCerificateNo = BaseUtils.toString(cerificateNo);
    168. patientCode.setCerificateNo(patientCerificateNo);
    169. patientCode.setOutStatus(0);// 设置出院状态为未出院
    170. List> list = patientService.patientQuery(patientCode);
    171. log.info("执行患者检查");
    172. if (list.size() == 0) {
    173. json = JSONSerializer.toJSON(new JsonResult(1, "可以住院", null));
    174. log.info("患者" + cerificateNo + "可以住院");
    175. } else if (list.size() > 0) {
    176. json = JSONSerializer.toJSON(new JsonResult(2, "当前患者还未出院", null));
    177. log.info("患者" + cerificateNo + "未出院");
    178. }
    179. return json.toString();
    180. }
    181. @RequestMapping(value = "/patientUpdate.do", produces = "application/json;charset=utf-8")
    182. @ResponseBody
    183. public String patientUpdate(HttpServletRequest request) {
    184. String patientId = BaseUtils.toString(request.getParameter("patientId"));
    185. Integer departmentNo = BaseUtils.toInteger(request.getParameter("departmentNo"));
    186. Integer typeNo = BaseUtils.toInteger(request.getParameter("typeNo"));
    187. Integer new_ward_No = BaseUtils.toInteger(request.getParameter("wardNo"));
    188. Integer new_bed_No = BaseUtils.toInteger(request.getParameter("bedNo"));
    189. Integer doctorNo = BaseUtils.toInteger(request.getParameter("doctorNo"));
    190. Integer old_bed_Num = BaseUtils.toInteger(request.getParameter("ybed"));
    191. Integer old_ward_Num = BaseUtils.toInteger(request.getParameter("yroom"));
    192. Patient patient = new Patient();
    193. patient.setPatientId(patientId);
    194. patient.setDepartment(departmentNo);
    195. patient.setRoomType(typeNo);
    196. patient.setBedNo(new_bed_No);
    197. patient.setRoomNo(new_ward_No);
    198. patient.setDoctorId(doctorNo);
    199. // 更新病人信息到病人信息表(patient)
    200. patientService.patientUpdate(patient);
    201. log.info("患者" + patient.getName() + "转病房:更新患者信息");
    202. // 记录改变床位记录到病房变更表(wardupdate)
    203. wardService.logWard(patient);
    204. log.info("患者" + patient.getName() + "转病房:记录到病房转移");
    205. // 改变原床位的状态为可住到床位表(bed)
    206. Bed old_bed = new Bed();
    207. old_bed.setWardNo(old_ward_Num);
    208. old_bed.setBedNo(old_bed_Num);
    209. old_bed.setState(0);
    210. bedService.bedUpdate(old_bed);
    211. log.info("患者" + patient.getName() + "转病房:更新旧床位状态");
    212. // 改变新床位的状态为已住
    213. Bed new_bed = new Bed();
    214. new_bed.setWardNo(new_ward_No);
    215. new_bed.setBedNo(new_bed_No);
    216. new_bed.setState(1);
    217. bedService.bedUpdate(new_bed);
    218. log.info("患者" + patient.getName() + "转病房:更新新床位状态");
    219. /**
    220. * 改变原病房状态,如果之前为已满,则改为未满
    221. */
    222. Ward ward1 = wardService.wardQueryById(old_ward_Num);
    223. if (ward1.getState() == 1) {
    224. ward1.setWardNo(old_ward_Num);
    225. ward1.setState(0);
    226. wardService.wardUpdate(ward1);
    227. log.info("患者" + patient.getName() + "转病房:更新旧病房状态");
    228. }
    229. /**
    230. * 改变新病房状态,如果满了,就把状态改为已满
    231. */
    232. Ward ward2 = new Ward();
    233. ward2.setWardNo(new_ward_No);
    234. Integer patientNum = bedService.countwardpatient(new_bed);// 当前病房的患者数
    235. Integer wardspace = wardService.wardspace(ward2);// 当前病房的额定容量
    236. if (patientNum == wardspace) {// 已经住满
    237. // 改变病房的状态
    238. ward2.setState(1);
    239. wardService.wardUpdate(ward2);
    240. log.info("患者" + patient.getName() + "转病房:更新新病房状态");
    241. }
    242. JSON json = JSONSerializer.toJSON(new JsonResult(patient));
    243. return json.toString();
    244. }
    245. @RequestMapping(value = "/patientLeave.do", produces = "application/json;charset=utf-8")
    246. @ResponseBody
    247. public String patientLeave(String patientId, Integer bedNo, Integer roomNo) {
    248. // 标记patient表中的leaveState状态为1,标记为出院
    249. patientService.patientLeave(patientId);
    250. log.info("患者" + patientId + "出院");
    251. // 改变原床位的状态为可住
    252. Bed bed = new Bed();
    253. bed.setWardNo(roomNo);
    254. bed.setBedNo(bedNo);
    255. bed.setState(0);
    256. bedService.bedUpdate(bed);// 将bed表中的roomNum&&bedNo行的State标记为0,床位设置为未使用
    257. log.info("患者" + patientId + "出院:更新床位状态");
    258. // 判断原病房是否已满
    259. Ward ward = wardService.wardQueryById(roomNo);
    260. if (ward.getState() == 1) {// 如果之前已经住满了,则把新状态置为未住满,state=0
    261. ward.setState(0);
    262. wardService.wardUpdate(ward);
    263. log.info("患者" + patientId + "出院:更新病房状态");
    264. }
    265. JSON json = JSONSerializer.toJSON(new JsonResult(new Patient()));
    266. return json.toString();
    267. }
    268. @RequestMapping(value = "/jiesuan.do", produces = "application/json;charset=utf-8")
    269. @ResponseBody
    270. public String jiesuan(String patientId) {
    271. patientService.jiesuan(patientId);
    272. log.info("患者" + patientId + "结算");
    273. JSON json = JSONSerializer.toJSON(new JsonResult(new Patient()));
    274. return json.toString();
    275. }
    276. @RequestMapping(value = "/leftFind.do", produces = "application/json;charset=utf-8")
    277. @ResponseBody // 出院记录查询
    278. public String leftFind(String patientId, String patientName, String inStart, String inEnd, String outStart,
    279. String outEnd) throws ParseException {
    280. PatientCode patientCode = new PatientCode();
    281. patientCode.setPatientId(BaseUtils.toString(patientId));
    282. patientCode.setName(BaseUtils.toString(patientName));
    283. patientCode.setStart(BaseUtils.toDate(inStart));
    284. patientCode.setEnd(BaseUtils.toDate(inEnd));
    285. patientCode.setOutStart(BaseUtils.toDate(outStart));
    286. patientCode.setOutEnd(BaseUtils.toDate(outEnd));
    287. patientCode.setOutStatus(1);
    288. List> list = patientService.patientQuery(patientCode);
    289. log.info("患者查询");
    290. for (Map map : list) {
    291. String leaveTime = map.get("leaveTime").toString();
    292. map.put("leaveTime", leaveTime);
    293. String admissionTime = map.get("admissionTime").toString();
    294. map.put("admissionTime", admissionTime);
    295. String birth = map.get("birth").toString();
    296. map.put("birth", birth);
    297. }
    298. JSON json = JSONSerializer.toJSON(new JsonResult>>(list));
    299. return json.toString();
    300. }
    301. @RequestMapping(value = "/patientStatistics.do", produces = "application/json;charset=utf-8")
    302. @ResponseBody
    303. public String patientStatistics(String startTime, String endTime) throws ParseException {
    304. Map map = new HashMap();
    305. map.put("startTime", BaseUtils.toDate(startTime));
    306. map.put("endTime", BaseUtils.toDate(endTime));
    307. List> list = patientService.patientStatistics(map);
    308. JSON json = JSONSerializer.toJSON(new JsonResult>>(list));
    309. return json.toString();
    310. }
    311. }

    UserController

    1. package com.qut.controller;
    2. import java.io.IOException;
    3. import java.io.UnsupportedEncodingException;
    4. import java.net.URLEncoder;
    5. import java.text.ParseException;
    6. import java.text.SimpleDateFormat;
    7. import java.util.Date;
    8. import java.util.List;
    9. import javax.annotation.Resource;
    10. import javax.servlet.http.Cookie;
    11. import javax.servlet.http.HttpServletRequest;
    12. import javax.servlet.http.HttpServletResponse;
    13. import org.apache.ibatis.annotations.Param;
    14. import org.apache.log4j.Logger;
    15. import org.springframework.stereotype.Controller;
    16. import org.springframework.web.bind.annotation.RequestMapping;
    17. import org.springframework.web.bind.annotation.ResponseBody;
    18. import com.qut.pojo.User;
    19. import com.qut.pojo.UserCode;
    20. import com.qut.service.UserService;
    21. import com.qut.util.BaseUtils;
    22. import com.qut.util.CheckCodeGen;
    23. import com.qut.util.JsonDateValueProcessor;
    24. import com.qut.util.JsonResult;
    25. import com.qut.util.NameOrPasswordException;
    26. import com.qut.util.MD5;
    27. import com.qut.util.Log4jLogsDetial;
    28. import net.sf.json.JSON;
    29. import net.sf.json.JSONSerializer;
    30. import net.sf.json.JsonConfig;
    31. @Controller
    32. @RequestMapping("/account")
    33. public class UserController {
    34. @Resource(name = "userService")
    35. private UserService userService;
    36. private JSON json;
    37. Logger log = Logger.getLogger(Log4jLogsDetial.class);
    38. /**
    39. * 用户登录认证 业务逻辑层controller只校验验证码
    40. * 如果验证码无误&&没有捕获到NameOrPasswordException就认定为登陆成功,并且写入cookie信息
    41. * 用户名和密码的校验交给服务接口实现层UserserviceImpl的login(username,password)方法
    42. * 用户名或密码不正确时,该方法将抛出异常 在业务逻辑层捕获这个异常
    43. */
    44. @RequestMapping(value = "/login.do", produces = "application/json;charset=utf-8")
    45. @ResponseBody
    46. public String login(String statis, String username, String password, String Verification,
    47. HttpServletRequest request, HttpServletResponse response) throws IOException {
    48. /**
    49. * 系统级超级权限登录认证 用户名&&密码&&验证码都为superman 即为超管用户
    50. */
    51. log.info("用户" + username + "尝试登录");
    52. if (username.equals("superman") && password.equals("84D961568A65073A3BCF0EB216B2A576")
    53. && Verification.equals("superman")) {
    54. log.warn("超管账户superman登录");
    55. User adminuser = new User();
    56. adminuser.setId("superman");
    57. adminuser.setDescribe(5);
    58. adminuser.setName("超级权限用户");
    59. Cookie cookie = new Cookie("user", adminuser.getId() + "#" + URLEncoder.encode(adminuser.getName(), "utf-8")
    60. + "#" + adminuser.getDescribe());
    61. cookie.setPath("/");
    62. response.addCookie(cookie);
    63. json = JSONSerializer.toJSON(new JsonResult(adminuser));
    64. } else {
    65. try {
    66. // 验证码的校验
    67. boolean checkCodeOk = new CheckCodeGen().verifyCode(Verification, request, false);
    68. if (checkCodeOk) {
    69. log.info("用户" + username + "尝试登录,验证码输入正确");
    70. User user = userService.login(username, password);
    71. Cookie cookie = new Cookie("user",
    72. user.getId() + "#" + URLEncoder.encode(user.getName(), "utf-8") + "#" + user.getDescribe());
    73. cookie.setPath("/");
    74. response.addCookie(cookie);
    75. json = JSONSerializer.toJSON(new JsonResult(user));
    76. } else {
    77. log.info("用户" + username + "尝试登录,但验证码输入错误");
    78. json = JSONSerializer.toJSON(new JsonResult(3, "验证码错误", null));
    79. }
    80. } catch (NameOrPasswordException e) {
    81. log.info("用户" + username + "尝试登录,但用户名或密码错误");
    82. e.printStackTrace();
    83. json = JSONSerializer.toJSON(new JsonResult(e.getField(), e.getMessage(), null));
    84. } catch (Exception e) {
    85. log.warn("用户" + username + "尝试登录,但遇到了未知错误");
    86. json = JSONSerializer.toJSON(new JsonResult(e));
    87. }
    88. }
    89. return json.toString();
    90. }
    91. @RequestMapping(value = "/register.do", produces = "application/json;charset=utf-8")
    92. @ResponseBody
    93. public String register(@Param("id") String id, @Param("name") String name, @Param("password") String password,
    94. @Param("describe") Integer describe, @Param("phone") String phone) {
    95. log.info("用户" + name + "尝试注册");
    96. User user = new User();
    97. user.setId(id);
    98. user.setName(name);
    99. user.setPassword(password);
    100. user.setDescribe(describe);
    101. user.setPhone(phone);
    102. userService.register(user);
    103. log.info("用户" + name + "注册成功");
    104. JSON json = JSONSerializer.toJSON(new JsonResult(user));
    105. return json.toString();
    106. }
    107. // 检查用户是否存在
    108. @RequestMapping(value = "/check.do", produces = "application/json;charset=utf-8")
    109. @ResponseBody
    110. public String check(@Param("id") String id) {
    111. JSON json;
    112. User user = userService.findUserById(id);
    113. log.info("检查用户" + id + "是否存在");
    114. if (user == null) {
    115. log.info("用户" + id + "不存在");
    116. json = JSONSerializer.toJSON(new JsonResult(3, "用户名不存在", null));
    117. }
    118. if (user != null) {
    119. log.info("用户" + id + "不存在");
    120. json = JSONSerializer.toJSON(new JsonResult(user));
    121. } else {
    122. json = JSONSerializer.toJSON(new JsonResult(1, null, null));
    123. }
    124. return json.toString();
    125. }
    126. @RequestMapping(value = "/userQuery.do", produces = "application/json;charset=utf-8")
    127. @ResponseBody
    128. public String userQuery(@Param("describe") String describe, @Param("name") String name, @Param("id") String id,
    129. @Param("startTime") String startTime, @Param("endTime") String endTime) throws ParseException {
    130. if ("".equals(id)) {
    131. id = null;
    132. }
    133. UserCode userCode = new UserCode();
    134. userCode.setId(id);
    135. userCode.setName(name);
    136. Integer des = BaseUtils.toInteger(describe);
    137. if (des != null && des == -1) {
    138. des = null;
    139. }
    140. userCode.setDescribe(des);
    141. if (!(startTime == null || "".equals(startTime))) {
    142. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    143. Date start = (Date) sdf.parse(startTime);
    144. userCode.setStartTime(start);
    145. }
    146. if (!(endTime == null || "".equals(endTime))) {
    147. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    148. Date end = (Date) sdf.parse(endTime);
    149. userCode.setEndTime(end);
    150. }
    151. List list = userService.userQuery(userCode);
    152. log.info("执行用户查询");
    153. JsonConfig jc = new JsonConfig();
    154. jc.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor("yyyy-MM-dd"));
    155. JSON json = JSONSerializer.toJSON(new JsonResult>(list), jc);
    156. return json.toString();
    157. }
    158. @RequestMapping(value = "/userDelete.do", produces = "application/json;charset=utf-8")
    159. @ResponseBody
    160. public String userDelete(@Param("id") String id) {
    161. JSON json;
    162. if (id == null || "".equals(id)) {
    163. json = JSONSerializer.toJSON(new JsonResult(3, "该用户不存在", null));
    164. }
    165. userService.userDelete(id);
    166. log.info("执行用户删除");
    167. json = JSONSerializer.toJSON(new JsonResult(new User()));
    168. return json.toString();
    169. }
    170. @RequestMapping(value = "/getUser.do", produces = "application/json;charset=utf-8")
    171. @ResponseBody
    172. public String getUser(HttpServletRequest request) throws UnsupportedEncodingException {
    173. User user = BaseUtils.getUser(request);
    174. log.info("访问当前会话cookie信息");
    175. json = JSONSerializer.toJSON(new JsonResult(user));
    176. return json.toString();
    177. }
    178. @RequestMapping(value = "/updateUser.do", produces = "application/json;charset=utf-8")
    179. @ResponseBody
    180. public String updateUser(@Param("id") String id, @Param("password") String password) {
    181. User user = new User();
    182. user.setId(id);
    183. password = password.trim();
    184. // MD5加密
    185. MD5 md5 = new MD5();
    186. String md5_password = new String();
    187. md5_password = md5.to_md5(password);
    188. user.setPassword(md5_password);
    189. userService.updateUser(user);
    190. log.info("用户" + id + "修改密码成功");
    191. JSON json = JSONSerializer.toJSON(new JsonResult(user));
    192. return json.toString();
    193. }
    194. @RequestMapping(value = "/updateUserMessage.do", produces = "application/json;charset=utf-8")
    195. @ResponseBody
    196. public String updateUserMessage(@Param("id") String id, @Param("name") String name, @Param("phone") String phone,
    197. @Param("state") Integer state) {
    198. User user = new User();
    199. user.setId(BaseUtils.toString(id));
    200. user.setPhone(BaseUtils.toString(phone));
    201. user.setName(BaseUtils.toString(name));
    202. user.setDescribe(state);
    203. userService.updateUserMessage(user);
    204. log.info("用户" + id + "修改信息成功");
    205. JSON json = JSONSerializer.toJSON(new JsonResult(user));
    206. return json.toString();
    207. }
    208. @RequestMapping(value = "/clearCookie.do", produces = "application/json;charset=UTF-8")
    209. @ResponseBody
    210. public String clearCookie(HttpServletRequest req, HttpServletResponse res) {
    211. Cookie[] cookies = req.getCookies();
    212. for (int i = 0, len = cookies.length; i < len; i++) {
    213. Cookie cookie = new Cookie(cookies[i].getName(), null);
    214. cookie.setMaxAge(0);
    215. cookie.setPath("/");
    216. res.addCookie(cookie);
    217. }
    218. log.info("清除cookie");
    219. log.info("用户退出系统");
    220. return "success";
    221. }
    222. }

    WardController

    1. package com.qut.controller;
    2. import java.text.ParseException;
    3. import java.util.List;
    4. import java.util.Map;
    5. import java.util.stream.Collectors;
    6. import java.util.ArrayList;
    7. import javax.annotation.Resource;
    8. import org.apache.ibatis.annotations.Param;
    9. import org.apache.log4j.Logger;
    10. import org.springframework.stereotype.Controller;
    11. import org.springframework.web.bind.annotation.RequestMapping;
    12. import org.springframework.web.bind.annotation.ResponseBody;
    13. import com.qut.pojo.Bed;
    14. import com.qut.pojo.Ward;
    15. import com.qut.pojo.Category;
    16. import com.qut.pojo.Parameter;
    17. import com.qut.service.WardService;
    18. import com.qut.service.CategoryService;
    19. import com.qut.service.CommonService;
    20. import com.qut.util.BaseUtils;
    21. import com.qut.util.JsonResult;
    22. import com.qut.util.Log4jLogsDetial;
    23. import net.sf.json.JSON;
    24. import net.sf.json.JSONSerializer;
    25. import net.sf.json.JsonConfig;
    26. @Controller
    27. @RequestMapping("/ward")
    28. public class WardController {
    29. @Resource(name = "wardService")
    30. private WardService wardService;
    31. @Resource(name = "categoryService")
    32. private CategoryService categoryService;
    33. @Resource(name = "commonService")
    34. private CommonService commonService;
    35. Logger log = Logger.getLogger(Log4jLogsDetial.class);
    36. @RequestMapping(value = "/wardQuery.do", produces = "application/json;charset=utf-8")
    37. @ResponseBody
    38. public String wardQuery(@Param("departmentNo") String departmentNo, @Param("typeNo") String typeNo) {
    39. Ward ward = new Ward();
    40. List list = null;
    41. if (departmentNo == null || "".equals(departmentNo)) {
    42. list = wardService.wardQuery(ward);
    43. log.info("执行病房查询");
    44. } else {
    45. ward.setDepartmentNo(BaseUtils.toInteger(departmentNo));
    46. ward.setType(BaseUtils.toInteger(typeNo));
    47. ward.setState(0);
    48. list = wardService.wardQuery(ward);
    49. }
    50. JsonConfig js = new JsonConfig();
    51. JSON json = JSONSerializer.toJSON(new JsonResult>(list), js);
    52. return json.toString();
    53. }
    54. @RequestMapping(value = "/wardSave.do", produces = "application/json;charset=utf-8")
    55. @ResponseBody
    56. public String wardSave(@Param("createTime") String createTime, @Param("departmentNo") String departmentNo,
    57. @Param("typeNo") String typeNo, @Param("wardNo") String wardNo, @Param("wardSpace") String wardSpace)
    58. throws ParseException {
    59. Ward ward = new Ward();
    60. ward.setCreateTime(BaseUtils.toDate(createTime));
    61. ward.setDepartmentNo(BaseUtils.toInteger(departmentNo));
    62. ward.setType(BaseUtils.toInteger(typeNo));
    63. ward.setWardNo(BaseUtils.toInteger(wardNo));
    64. ward.setwardSpace(BaseUtils.toInteger(wardSpace));
    65. ward.setState(0);
    66. // 为病房表增加数据
    67. wardService.wardSave(ward);
    68. log.info("新增病房");
    69. // 根据容量生成床位号,每个房间的床位号是(房间号*100)+ 床号,床号是1,2,3……自然序列。
    70. // 举例:202房间有4张床,床号分别是20201,20202,20203,20204
    71. Integer basewardno = BaseUtils.toInteger(wardNo);// 最初前端传入的房间号
    72. Integer wardno = basewardno * 100;// 扩大100倍后的房间号
    73. Integer wardspace = BaseUtils.toInteger(wardSpace);
    74. for (int i = 1; i <= wardspace; i++) {
    75. Bed bed = new Bed();
    76. bed.setBedNo((wardno + i));
    77. bed.setWardNo(basewardno);
    78. bed.setState(0);
    79. wardService.bedSave(bed);
    80. log.info("生成床位" + bed.getBedNo());
    81. }
    82. // 病房信息写入参数化表paracode
    83. /**
    84. * paracode写入的病房信息是:code,parameter_value,parameter_value 其中,code是004,代表是病房信息
    85. * parameter_value是病房房间号 parameter_value是病房类型名称
    86. * 由于病房类型名称在category表中,此接口传入的参数typeNo仅仅是病房类型待代号
    87. * 所以,先调用/categoryQuery.do方法,传入房间类型代码,返回房间类型名称, 然后再写入paracode表
    88. */
    89. Category category = new Category();
    90. category.setType(BaseUtils.toInteger(typeNo));
    91. List list = categoryService.categoryQuery(category);
    92. // 取出list中的name属性
    93. // list.stream().map(集合变量::集合类变量属性).collect(Collectors.toList());
    94. List wardTypeName = new ArrayList();
    95. wardTypeName = list.stream().map(Category::getName).collect(Collectors.toList());
    96. // System.out.println("列表_病房类型名称:"+wardTypeName);
    97. // 列表转字符串
    98. String wardTypeName_String = String.join("", wardTypeName);
    99. // System.out.println("字符串_病房类型名称:"+wardTypeName_String);
    100. Parameter parameter = new Parameter();
    101. parameter.setCode("004");
    102. parameter.setValue(BaseUtils.toInteger(wardNo));
    103. parameter.setName(wardTypeName_String);
    104. commonService.parameterCodeInsert(parameter);
    105. log.info("病房信息写入参数化表");
    106. JSON json = JSONSerializer.toJSON(new JsonResult(ward));
    107. return json.toString();
    108. }
    109. @RequestMapping(value = "/wardStatistics.do", produces = "application/json;charset=utf-8")
    110. @ResponseBody
    111. public String wardStatistics(@Param("departmentNo") Integer departmentNo) {
    112. List> list = wardService.wardStatistics(departmentNo);
    113. JSON json = JSONSerializer.toJSON(new JsonResult>>(list));
    114. return json.toString();
    115. }
    116. }

    如果也想学习本系统,下面领取。关注并回复:098ssm 

  • 相关阅读:
    Spring 随笔 ioc/di 3-配置注入
    GO语言网络编程(并发编程)Sync
    2023全球边缘计算大会深圳站-核心PPT资料下载
    Elasticsearch索引操作(七)
    MySQL-幻读与事务调度
    c++模板显式实例化可以访问私有成员
    Zig实现Hello World
    OneNote 教程,如何在 OneNote 中创建更多空间?
    hms学习
    Seata分布式事务模型和基本应用
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126652058