基于javaweb+mysql的springboot+mybatis宠物医院预约管理系统(管理员、医生、用户)(java+springboot+ssm+thymeleaf+html+layui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
用户管理(管理员、医生、用户)、宠物管理、预约就诊、预约审核、日常健康管理、医院管理、统计分析等……
技术框架
SpringBoot SpringMVC MyBatis Shiro Thymeleaf HTML JavaScript Layui……
基于javaweb+mysql的SpringBoot+MyBatis宠物医院预约管理系统(管理员、医生、用户)(java+springboot+ssm+thymeleaf+html+layui)
/**
* 用户控制
*/
@Controller("User")
@RequestMapping("/user")
public class UserController {
private final Logger logger = LoggerFactory.getLogger(UserController.class);
private final ResultMap resultMap;
@Autowired
private UserService userService;
@Autowired
private UserRoleService userRoleService;
@Autowired
public UserController(ResultMap resultMap) {
this.resultMap = resultMap;
}
/**
* 返回有权限信息
*/
@RequestMapping(value = "/getMessage", method = RequestMethod.GET)
public ResultMap getMessage() {
return resultMap.success().message("您拥有用户权限,可以获得该接口的信息!");
}
/**
* 修改用户信息页面user/userEdit.html
*/
@RequestMapping(value = "/editUserPage")
public String editUserPage(Long userId, Model model) {
model.addAttribute("manageUser", userId);
if (null != userId) {
User user = userService.selectByPrimaryKey(userId);
model.addAttribute("manageUser", user);
}
return "user/userEdit";
}
*
* @param id
* @return String<BR>
*/
@RequestMapping("/delRole")
@ResponseBody
public String delRole(int id) {
// 删除角色
boolean flag1 = roleService.delRoleById(id);
// 删除角色_权限表
boolean flag2 = pageRoleService.delPageRoleByRoleId(id);
// 删除某个角色的所有用户
boolean flag3 = userRoleService.delUserRoleByRoleId(id);
if (flag1 && flag2 && flag3) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: updateRole <BR>
* Description: 根据权限id修改权限信息 <BR>
*
* @param id
* @param name
* @return String<BR>
*/
@RequestMapping("/updateRole")
@ResponseBody
public String updateRole(Integer id, String name) {
int n = roleService.updateRoleById(id, name);
if (n != 0) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: addPageRoleByRoleId <BR>
* Description: 增加某个角色的权限页面 <BR>
*
// 状态:1申请中,2申请通过,3不通过,4已完成
appointment.setStatus(1);
appointmentService.add(appointment);
return "SUCCESS";
} catch (Exception e) {
logger.error("添加异常", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "ERROR";
}
}
/**
* 改变预约状态
*/
@RequestMapping(value = "/chStatus")
@ResponseBody
@Transactional
public String chStatus(Appointment appointment) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
try {
appointment.setDoctorId(user.getId());
appointmentService.update(appointment);
// 就诊
if (appointment.getStatus() == 4){
return "jz";
}
return "SUCCESS";
} catch (Exception e) {
logger.error("添加异常", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "ERROR";
}
}
}
standard.setAgeMax(petAge);
standard.setPage(1);
standard.setLimit(100);
MMGridPageVoBean<Standard> ss = (MMGridPageVoBean<Standard>) standardService.getAllByLimit(standard);
List<Standard> ssRows = ss.getRows();
double tsMin = 0;
double tsMax = 0;
double wsMin = 0;
double wsMax = 0;
double hsMin = 0;
double hsMax = 0;
double asMin = 0;
double asMax = 0;
for (Standard s : ssRows){
tsMin+=s.getTempMin();
tsMax+=s.getTempMax();
wsMin+=s.getWeightMin();
wsMax+=s.getWeightMax();
hsMin+=s.getHeightMin();
hsMax+=s.getHeightMax();
asMin+=s.getAppetiteMin();
asMax+=s.getAppetiteMax();
}
tsMin = tsMin / ssRows.size();
tsMax = tsMax / ssRows.size();
wsMin = wsMin / ssRows.size();
wsMax = wsMax / ssRows.size();
hsMin = hsMin / ssRows.size();
hsMax = hsMax / ssRows.size();
asMin = asMin / ssRows.size();
asMax = asMax / ssRows.size();
mt.add(tsMax);
mw.add(wsMax);
mh.add(hsMax);
ma.add(asMax);
if (t>=tsMin && t<=tsMax){
tsCount.add(" 体温正常");
}else if (t<tsMin){
tsCount.add( " 体温偏低");
}else if (t>tsMax){
tsCount.add( " 体温偏高");
}
List<Map<String, Object>> map = appointmentService.getFreeTimeById(id, date+MyUtils.START_HOUR);
List<String> time = new ArrayList<>();
List<Long> value = new ArrayList<>();
for (Map<String, Object> m : map){
String df = (String) m.get("df");
time.add(df+"点");
Long v = (Long) m.get("c");
if (v == null) {
value.add(0L);
}else {
value.add(v);
}
}
result.put("t", time);
result.put("v", value);
return result;
}
}
public ResultMap doRegist(User user) {
System.out.println(user);
User u = userService.getUserByPhoneAndName(user.getPhone(), null);
if (u != null){
return resultMap.success().message("该手机号已注册!");
}
try {
user.setPassword(MD5.md5(user.getPassword()));
user.setCreateTime(new Date());
userService.save(user);
String[] ids = new String[1];
ids[0] = user.getId()+"";
// 普通用户
userRoleService.addUserRole(2, ids);
return resultMap.success().message("注册成功");
}catch (Exception e){
e.printStackTrace();
return resultMap.fail().message("注册失败");
}
}
/**
* Method name: index <BR>
* Description: 登录页面 <BR>
*
* @return String login.html<BR>
*/
@RequestMapping(value = "/")
public String index(Model model) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
model.addAttribute("user", user);
List<Page> pageList = pageService.getAllRolePageByUserId(user.getId()+"");
model.addAttribute("pageList", pageList);
return "index";
} else {
return "login";
}
}
public ResultMap delUserRoleByUserIdAndRoleId(String userId, Integer roleId) {
return userRoleService.delUserRoleByUserIdAndRoleId(userId, roleId);
}
/**
* Method name: selectUserRole <BR>
* Description: 跳转到选择用户角色页面 <BR>
*
* @return String<BR>
*/
@RequestMapping("/selectUserRole")
public String selectUserRole() {
return "sa/selectUserRole";
}
/**
* Method name: addUserRole <BR>
* Description: 增加用户的角色 <BR>
*
* @param roleId
* @param userIds
* @return String<BR>
*/
@RequestMapping("/addUserRole")
@ResponseBody
public String addUserRole(Integer roleId, String[] userIds) {
return userRoleService.addUserRole(roleId, userIds);
}
/**
* Method name: userAddPage <BR>
* Description: 用户添加页面 <BR>
*
* @return String<BR>
*/
@RequestMapping(value = "/userAddPage")
public String userAddPage() {
return "sa/userAdd";
}
/**
* Method name: userPage <BR>
* Description: 用户管理页面 <BR>
*
* @return String<BR>
*/
@RequestMapping(value = "/userPage")
public String userPage() {
return "sa/userList";
}
/**
* @return String<BR>
*/
@RequestMapping("/addPageRoleByRoleId")
@ResponseBody
public String addPageRoleByRoleId(Integer roleId, Integer[] pageIds) {
if (null == roleId) {
return "ERROR";
}
// 先删除老的权限
boolean flag1 = pageRoleService.delPageRoleByRoleId(roleId);
boolean flag2 = pageRoleService.addPageRoles(roleId, pageIds);
if (flag1 && flag2) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: getAllUserByMap <BR>
* Description: 根据角色查询下面所有的人员/非角色下所有人员 <BR>
*/
@RequestMapping("/getAllUserByRoleId")
@ResponseBody
public Object getAllUserByRoleId(Integer roleId, String roleNot, Integer page, Integer limit) {
if (null == roleNot) {
return userService.getAllUserByRoleId(roleId, page, limit);
}
return userService.getAllUserByNotRoleId(roleId, page, limit);
}
/**
* Method name: delUserRoleByUserIdAndRoleId <BR>
* Description: 根据用户id权限id删除用户权限表 <BR>
*
* @param userId
* @param roleId
* @return ResultMap<BR>
*/
@RequestMapping("/delUserRoleByUserIdAndRoleId")
@ResponseBody
case 1:dsCount.add(p.getName() + " 宠物健康,请继续保持");break;
case 2:dsCount.add(p.getName() + " 宠物异常请及时就诊!");break;
case 3:dsCount.add(p.getName() + " 宠物病情比较严重,请及时就医!");break;
case 4:dsCount.add(p.getName() + " 很抱歉宠物已无法治疗!");break;
default:dsCount.add(p.getName() + " 宠物基本健康,请继续保持");break;
}
// 获取宠物日志
PetDaily petDaily = new PetDaily();
petDaily.setPetId(p.getId());
petDaily.setPage(1);
petDaily.setLimit(10);
MMGridPageVoBean<PetDaily> ps = (MMGridPageVoBean<PetDaily>) petDailyService.getAllByLimit(petDaily);
List<PetDaily> psRows = ps.getRows();
double t = 0;
double w = 0;
double h = 0;
double a = 0;
for (PetDaily petDaily1 : psRows){
t+=petDaily1.getTemperature();
w+=petDaily1.getWeight();
h+=petDaily1.getHeight();
a+=petDaily1.getAppetite();
}
t = t/psRows.size();
w = w/psRows.size();
h = h/psRows.size();
a = a/psRows.size();
pt.add(t);
pw.add(w);
ph.add(h);
pa.add(a);
// 获取标准
Standard standard = new Standard();
// 对应宠物类型
standard.setType(p.getType());
// 健康标准
standard.setStatus(1);
int petAge = MyUtils.get2DateDay(MyUtils.getDate2String(p.getBirthday(), "yyyy-MM-dd"), MyUtils.getDate2String(new Date(), "yyyy-MM-dd"));
petAge = (petAge<0? -petAge : petAge)/365;
// 年龄
standard.setAgeMax(petAge);
int diagnosisStatus = 0;
for (Diagnosis d: dsRows){
diagnosisStatus += d.getStatus();
}
int sw = diagnosisStatus / dsRows.size();
switch (sw){
case 1:dsCount.add(p.getName() + " 宠物健康,请继续保持");break;
case 2:dsCount.add(p.getName() + " 宠物异常请及时就诊!");break;
case 3:dsCount.add(p.getName() + " 宠物病情比较严重,请及时就医!");break;
case 4:dsCount.add(p.getName() + " 很抱歉宠物已无法治疗!");break;
default:dsCount.add(p.getName() + " 宠物基本健康,请继续保持");break;
}
// 获取宠物日志
PetDaily petDaily = new PetDaily();
petDaily.setPetId(p.getId());
petDaily.setPage(1);
petDaily.setLimit(10);
MMGridPageVoBean<PetDaily> ps = (MMGridPageVoBean<PetDaily>) petDailyService.getAllByLimit(petDaily);
List<PetDaily> psRows = ps.getRows();
double t = 0;
double w = 0;
double h = 0;
double a = 0;
for (PetDaily petDaily1 : psRows){
t+=petDaily1.getTemperature();
w+=petDaily1.getWeight();
h+=petDaily1.getHeight();
a+=petDaily1.getAppetite();
}
t = t/psRows.size();
w = w/psRows.size();
h = h/psRows.size();
a = a/psRows.size();
pt.add(t);
pw.add(w);
ph.add(h);
pa.add(a);
// 获取标准
Standard standard = new Standard();
* 医生宠物健康史页面user/diagnosisListDoctor.html
*/
@RequestMapping("/diagnosisListDoctor")
public String diagnosisListDoctor(Long petId, Model model) {
if (petId!=null){
model.addAttribute("petId", petId);
}else {
model.addAttribute("petId", "petId");
}
return "user/diagnosisListDoctor";
}
/**
* 普通用户宠物健康史页面user/diagnosisList.html
*/
@RequestMapping("/diagnosisList")
public String diagnosisList(Long petId, Model model) {
if (petId!=null){
model.addAttribute("petId", petId);
}else {
model.addAttribute("petId", "petId");
}
return "user/diagnosisList";
}
/**
* 普通用户返回查询数据
*/
@RequestMapping("/getAllByLimit")
@ResponseBody
public Object getAllByLimit(Diagnosis diagnosis) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
diagnosis.setUserId(user.getId());
return diagnosisService.getAllByLimit(diagnosis);
}
/**
* 医生返回查询数据
*/
@RequestMapping("/getAllByLimitDoctor")
@ResponseBody
public Object getAllByLimitBaoJie(Diagnosis diagnosis) {
return diagnosisService.getAllByLimit(diagnosis);
}
/**
* 删除记录
*/
@RequestMapping(value = "/del")
@ResponseBody
@Transactional
public String del(Long id) {
try {
diagnosisService.deleteById(id);
return "SUCCESS";
return "ERROR";
}
/**
* Method name: getAllUserByMap <BR>
* Description: 根据角色查询下面所有的人员/非角色下所有人员 <BR>
*/
@RequestMapping("/getAllUserByRoleId")
@ResponseBody
public Object getAllUserByRoleId(Integer roleId, String roleNot, Integer page, Integer limit) {
if (null == roleNot) {
return userService.getAllUserByRoleId(roleId, page, limit);
}
return userService.getAllUserByNotRoleId(roleId, page, limit);
}
/**
* Method name: delUserRoleByUserIdAndRoleId <BR>
* Description: 根据用户id权限id删除用户权限表 <BR>
*
* @param userId
* @param roleId
* @return ResultMap<BR>
*/
@RequestMapping("/delUserRoleByUserIdAndRoleId")
@ResponseBody
public ResultMap delUserRoleByUserIdAndRoleId(String userId, Integer roleId) {
return userRoleService.delUserRoleByUserIdAndRoleId(userId, roleId);
}
/**
* Method name: selectUserRole <BR>
* Description: 跳转到选择用户角色页面 <BR>
*
* @return String<BR>
*/
@RequestMapping("/selectUserRole")
public String selectUserRole() {
return "sa/selectUserRole";
}
/**
* Method name: addUserRole <BR>
* Description: 增加用户的角色 <BR>
*
* @return List<Role><BR>
*/
@RequestMapping("/getAllRole")
@ResponseBody
public List<Role> getAllRole() {
return roleService.getAllRole();
}
/**
* Method name: getAllPage <BR>
* Description: 获取所有页面 <BR>
*
* @return List<Page><BR>
*/
@RequestMapping("/getAllPage")
@ResponseBody
public List<Page> getAllPage() {
return pageService.getAllPage();
}
/**
* Method name: getPageByRole <BR>
* Description: 获取某个角色的权限页面 <BR>
*/
@RequestMapping("/getPageByRole")
@ResponseBody
public Object getPageByRole(Integer roleId) {
return pageService.getAllPageByRoleId(roleId);
}
/**
* Method name: updatePageById <BR>
* Description: 根据页面id更新页面 <BR>
*
* @param page
* @return ResultMap<BR>
*/
@RequestMapping("/updatePageById")
@ResponseBody
public ResultMap updatePageById(Page page) {
return pageService.updatePageById(page);
}
/**
* Method name: delPageById <BR>
* Description: 根据页面id删除页面 <BR>
*
* @param id
* @return ResultMap<BR>
*/
@RequestMapping("/delPageById")
@ResponseBody
public ResultMap delPageById(Integer id) {
if (null == id) {
return new ResultMap().fail().message("参数错误");
}
return pageService.delPageById(id);
}
/**
* Method name: addRole <BR>
* Description: 增加角色 <BR>
*
* @param name
* @return String<BR>
*/
@RequestMapping("/addRole")
@ResponseBody
public String addRole(String name) {
return roleService.addRole(name);
}
/**
* Method name: delManageRole <BR>
* Description: 根据角色id删除角色 <BR>
*
* @param id
* @return String<BR>
*/
@RequestMapping("/delRole")
@ResponseBody
public String demoTable() {
return "table";
}
@RequestMapping(value = "/demo/tu", method = RequestMethod.GET)
public String demoTu() {
return "tu";
}
@RequestMapping(value = "/demo/tu1", method = RequestMethod.GET)
public String tu1() {
return "tu1";
}
@RequestMapping(value = "/demo/tu2", method = RequestMethod.GET)
public String tu2() {
return "tu2";
}
@RequestMapping(value = "/demo/tu3", method = RequestMethod.GET)
public String tu3() {
return "tu3";
}
/**演示页面**/
/**
* Method name: logout <BR>
* Description: 退出登录 <BR>
* @return String<BR>
*/
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout() {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
logger.info("{}---退出登录!", user.getName());
}
subject.logout();
return "login";
}
/**
* Method name: login <BR>
* Description: 登录验证 <BR>
* Remark: <BR>
*
* @param username 用户名
* @param password 密码
* @return ResultMap<BR>
user.setCreateTime(new Date());
userService.save(user);
String[] ids = new String[1];
ids[0] = user.getId()+"";
// 普通用户
userRoleService.addUserRole(2, ids);
return resultMap.success().message("注册成功");
}catch (Exception e){
e.printStackTrace();
return resultMap.fail().message("注册失败");
}
}
/**
* Method name: index <BR>
* Description: 登录页面 <BR>
*
* @return String login.html<BR>
*/
@RequestMapping(value = "/")
public String index(Model model) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
model.addAttribute("user", user);
List<Page> pageList = pageService.getAllRolePageByUserId(user.getId()+"");
model.addAttribute("pageList", pageList);
return "index";
} else {
return "login";
}
}
/**
* Method name: main <BR>
* Description: 进入主页面 <BR>
* index.html
*/
@RequestMapping(value = "/main")
public String main(Model model) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
model.addAttribute("user", user);
} else {
/**
* 医生返回查询数据
*/
@RequestMapping("/getAllByLimitDoctor")
@ResponseBody
public Object getAllByLimitBaoJie(Standard pojo) {
return standardService.getAllByLimit(pojo);
}
/**
* 根据id删除
*/
@RequestMapping(value = "/del")
@ResponseBody
@Transactional
public String del(Long id) {
try {
standardService.deleteById(id);
return "SUCCESS";
} catch (Exception e) {
logger.error("删除异常", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "ERROR";
}
}
/**
* 添加页面 user/standardAdd.html
*/
@RequestMapping(value = "/add")
public String add() {
return "user/standardAdd";
}
/**
* 插入数据库
*/
@RequestMapping(value = "/doAdd")
@ResponseBody
@Transactional
public String doAdd(Standard pojo) {
try {
standardService.add(pojo);
return "SUCCESS";
} catch (Exception e) {
logger.error("添加异常", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "ERROR";
}
}
}
}
}
model.addAttribute("a1", a1);
model.addAttribute("a2", a2);
model.addAttribute("a3", a3);
model.addAttribute("a4", a4);
return "tj/tjApply";
}
/**
* 医生预约统计
*/
@RequestMapping("/tjApplyDoctor")
public String tjApplyDoctor(Model model) {
Appointment appointment = new Appointment();
appointment.setPage(1);
appointment.setLimit(99999);
MMGridPageVoBean<Appointment> voBean = (MMGridPageVoBean<Appointment>) appointmentService.getAllByLimit(appointment);
List<Appointment> rows = voBean.getRows();
Integer a1 = 0;
Integer a2 = 0;
Integer a3 = 0;
Integer a4 = 0;
for (Appointment a: rows){
switch (a.getStatus()){
case 1: a1++;break;
case 2: a2++;break;
case 3: a3++;break;
case 4: a4++;break;
}
}
model.addAttribute("a1", a1);
model.addAttribute("a2", a2);
model.addAttribute("a3", a3);
model.addAttribute("a4", a4);
return "tj/tjApplyDoctor";
}
/**
* 普通用户宠物日志统计
*/
@RequestMapping("/tjDaily")
public String tjDaily(Model model) {