Java如何实现球馆在线预约系统

Java如何实现球馆在线预约系统

这篇文章给大家分享的是有关Java如何实现球馆在线预约系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

功能具体如下:
前台用户:登录\注册、查看场馆、预约场馆、投诉、个人中心、关于我们、网站公告等。
后台管理员:场馆列表、场地列表、场地安排、订单管理、教练管理、器材管理、收银员管理、会员管理、关于网站等功能
收银员:订单管理、教练管理、器材管理、会员充值管理等。
运行环境:windows/Linux均可、jdk1.8、mysql5.7、maven3.5\3.6。idea/eclipse均可。

系统控制器代码:

/***系统控制器**/@RequestMapping("/system")@ControllerpublicclassSystemController{@AutowiredprivateOperaterLogServiceoperaterLogService;@AutowiredprivateUserServiceuserService;@AutowiredprivateDatabaseBakServicedatabaseBakService;@AutowiredprivateItemServiceitemService;@AutowiredprivatePeopleServicepeopleService;@AutowiredprivateOrderAuthServiceorderAuthService;@AutowiredprivateStaffServicestaffService;/*@Value("${show.tips.text}")privateStringshowTipsText;@Value("${show.tips.url.text}")privateStringshowTipsUrlText;@Value("${show.tips.btn.text}")privateStringshowTipsBtnText;@Value("${show.tips.url}")privateStringshowTipsUtl;*/privateLoggerlog=LoggerFactory.getLogger(SystemController.class);/***登录页面*@parammodel*@return*/@RequestMapping(value="/login",method=RequestMethod.GET)publicStringlogin(Modelmodel){return"admin/system/login";}/***用户登录提交表单处理方法*@paramrequest*@paramuser*@paramcpacha*@return*/@RequestMapping(value="/login",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>login(HttpServletRequestrequest,Useruser,Stringcpacha){if(user==null){returnResult.error(CodeMsg.DATA_ERROR);}//用统一验证实体方法验证是否合法CodeMsgvalidate=ValidateEntityUtil.validate(user);if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){returnResult.error(validate);}//表示实体信息合法,开始验证验证码是否为空if(StringUtils.isEmpty(cpacha)){returnResult.error(CodeMsg.CPACHA_EMPTY);}//说明验证码不为空,从session里获取验证码Objectattribute=request.getSession().getAttribute("admin_login");if(attribute==null){returnResult.error(CodeMsg.SESSION_EXPIRED);}//表示session未失效,进一步判断用户填写的验证码是否正确if(!cpacha.equalsIgnoreCase(attribute.toString())){returnResult.error(CodeMsg.CPACHA_ERROR);}//表示验证码正确,开始查询数据库,检验密码是否正确UserfindByUsername=userService.findByUsername(user.getUsername());//判断是否为空if(findByUsername==null){returnResult.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);}//表示用户存在,进一步对比密码是否正确if(!findByUsername.getPassword().equals(user.getPassword())){returnResult.error(CodeMsg.ADMIN_PASSWORD_ERROR);}//表示密码正确,接下来判断用户状态是否可用if(findByUsername.getStatus()==User.ADMIN_USER_STATUS_UNABLE){returnResult.error(CodeMsg.ADMIN_USER_UNABLE);}//检查用户所属角色状态是否可用if(findByUsername.getRole()==null||findByUsername.getRole().getStatus()==Role.ADMIN_ROLE_STATUS_UNABLE){returnResult.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);}//检查用户所属角色的权限是否存在if(findByUsername.getRole().getAuthorities()==null||findByUsername.getRole().getAuthorities().size()==0){returnResult.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);}//检查一切符合,可以登录,将用户信息存放至sessionrequest.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY,findByUsername);//销毁session中的验证码request.getSession().setAttribute("admin_login",null);//将登陆记录写入日志库operaterLogService.add("用户【"+user.getUsername()+"】于【"+StringUtil.getFormatterDate(newDate(),"yyyy-MM-ddHH:mm:ss")+"】登录系统!");log.info("用户成功登录,user="+findByUsername);returnResult.success(true);}/***登录成功后的系统主页*@parammodel*@return*/@RequestMapping(value="/index")publicStringindex(Modelmodel){model.addAttribute("operatorLogs",operaterLogService.findLastestLog(10));model.addAttribute("userTotal",userService.total());model.addAttribute("operatorLogTotal",operaterLogService.total());model.addAttribute("databaseBackupTotal",databaseBakService.total());model.addAttribute("itemCount",itemService.count());model.addAttribute("peopleCount",peopleService.count());model.addAttribute("workerCount",staffService.countByType(Staff.WORKER));model.addAttribute("coachCount",staffService.countByType(Staff.COACH));model.addAttribute("onlineUserTotal",SessionListener.onlineUserCount);return"admin/system/index";}/***注销登录*@return*/@RequestMapping(value="/logout")publicStringlogout(){UserloginedUser=SessionUtil.getLoginedUser();if(loginedUser!=null){SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,null);}return"redirect:login";}/***无权限提示页面*@return*/@RequestMapping(value="/no_right")publicStringnoRight(){return"admin/system/no_right";}/***修改用户个人信息*@return*/@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)publicStringupdateUserInfo(){return"admin/system/update_userinfo";}/***修改个人信息保存*@paramuser*@return*/@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)publicStringupdateUserInfo(Useruser){UserloginedUser=SessionUtil.getLoginedUser();loginedUser.setEmail(user.getEmail());loginedUser.setMobile(user.getMobile());loginedUser.setHeadPic(user.getHeadPic());//首先保存到数据库userService.save(loginedUser);//更新session里的值SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);return"redirect:update_userinfo";}/***修改密码页面*@return*/@RequestMapping(value="/update_pwd",method=RequestMethod.GET)publicStringupdatePwd(){return"admin/system/update_pwd";}/***修改密码表单提交*@paramoldPwd*@paramnewPwd*@return*/@RequestMapping(value="/update_pwd",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>updatePwd(@RequestParam(name="oldPwd",required=true)StringoldPwd,@RequestParam(name="newPwd",required=true)StringnewPwd){UserloginedUser=SessionUtil.getLoginedUser();if(!loginedUser.getPassword().equals(oldPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);}if(StringUtils.isEmpty(newPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);}if(newPwd.length()<4){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_LENGTH);}loginedUser.setPassword(newPwd);//保存数据库userService.save(loginedUser);//更新sessionSessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);returnResult.success(true);}/***日志管理列表*@parammodel*@paramoperaterLog*@parampageBean*@return*/@RequestMapping(value="/operator_log_list")publicStringoperatorLogList(Modelmodel,OperaterLogoperaterLog,PageBean<OperaterLog>pageBean){model.addAttribute("pageBean",operaterLogService.findList(operaterLog,pageBean));model.addAttribute("operator",operaterLog.getOperator());model.addAttribute("title","日志列表");return"admin/system/operator_log_list";}/***删除操作日志,可删除多个*@paramids*@return*/@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>delete(Stringids){if(!StringUtils.isEmpty(ids)){String[]splitIds=ids.split(",");for(Stringid:splitIds){operaterLogService.delete(Long.valueOf(id));}}returnResult.success(true);}/***清空整个日志*@return*/@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>deleteAll(){operaterLogService.deleteAll();returnResult.success(true);}}

后台用户管理控制器:

/***后台用户管理控制器*@authoryy**/@RequestMapping("/admin/user")@ControllerpublicclassUserController{@AutowiredprivateUserServiceuserService;@AutowiredprivateRoleServiceroleService;@AutowiredprivateOperaterLogServiceoperaterLogService;/***用户列表页面*@parammodel*@paramuser*@parampageBean*@return*/@RequestMapping(value="/list")publicStringlist(Modelmodel,Useruser,PageBean<User>pageBean){model.addAttribute("title","用户列表");model.addAttribute("username",user.getUsername());model.addAttribute("pageBean",userService.findList(user,pageBean));return"admin/user/list";}/***新增用户页面*@parammodel*@return*/@RequestMapping(value="/add",method=RequestMethod.GET)publicStringadd(Modelmodel){model.addAttribute("roles",roleService.findAll());return"admin/user/add";}/***用户添加表单提交处理*@paramuser*@return*/@RequestMapping(value="/add",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>add(Useruser){//用统一验证实体方法验证是否合法CodeMsgvalidate=ValidateEntityUtil.validate(user);if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){returnResult.error(validate);}if(user.getRole()==null||user.getRole().getId()==null){returnResult.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);}//判断用户名是否存在if(userService.isExistUsername(user.getUsername(),0l)){returnResult.error(CodeMsg.ADMIN_USERNAME_EXIST);}//到这说明一切符合条件,进行数据库新增if(userService.save(user)==null){returnResult.error(CodeMsg.ADMIN_USE_ADD_ERROR);}operaterLogService.add("添加用户,用户名:"+user.getUsername());returnResult.success(true);}/***用户编辑页面*@parammodel*@return*/@RequestMapping(value="/edit",method=RequestMethod.GET)publicStringedit(Modelmodel,@RequestParam(name="id",required=true)Longid){model.addAttribute("roles",roleService.findAll());model.addAttribute("user",userService.find(id));return"admin/user/edit";}/***编辑用户信息表单提交处理*@paramuser*@return*/@RequestMapping(value="/edit",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>edit(Useruser){//用统一验证实体方法验证是否合法CodeMsgvalidate=ValidateEntityUtil.validate(user);if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){returnResult.error(validate);}if(user.getRole()==null||user.getRole().getId()==null){returnResult.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);}if(user.getId()==null||user.getId().longValue()<=0){returnResult.error(CodeMsg.ADMIN_USE_NO_EXIST);}if(userService.isExistUsername(user.getUsername(),user.getId())){returnResult.error(CodeMsg.ADMIN_USERNAME_EXIST);}//到这说明一切符合条件,进行数据库保存UserfindById=userService.find(user.getId());//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容BeanUtils.copyProperties(user,findById,"id","createTime","updateTime");if(userService.save(findById)==null){returnResult.error(CodeMsg.ADMIN_USE_EDIT_ERROR);}operaterLogService.add("编辑用户,用户名:"+user.getUsername());returnResult.success(true);}/***删除用户*@paramid*@return*/@RequestMapping(value="/delete",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>delete(@RequestParam(name="id",required=true)Longid){try{userService.delete(id);}catch(Exceptione){returnResult.error(CodeMsg.ADMIN_USE_DELETE_ERROR);}operaterLogService.add("删除用户,用户ID:"+id);returnResult.success(true);}}

系统控制器:

/***系统控制器*@authoryy**/@RequestMapping("/system")@ControllerpublicclassSystemController{@AutowiredprivateOperaterLogServiceoperaterLogService;@AutowiredprivateUserServiceuserService;@AutowiredprivateDatabaseBakServicedatabaseBakService;@AutowiredprivateStaffServicestaffService;@AutowiredprivateOrderAuthServiceorderAuthService;privateLoggerlog=LoggerFactory.getLogger(SystemController.class);/***登录页面*@parammodel*@return*/@RequestMapping(value="/login",method=RequestMethod.GET)publicStringlogin(Modelmodel){model.addAttribute("loginTypes",LoginType.values());return"admin/system/login";}/***用户登录提交表单处理方法*@paramrequest*@paramcpacha*@return*/@RequestMapping(value="/login",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>login(HttpServletRequestrequest,Stringusername,Stringpassword,Stringcpacha,Integertype){if(StringUtils.isEmpty(username)){returnResult.error(CodeMsg.ADMIN_USERNAME_EMPTY);}if(StringUtils.isEmpty(password)){returnResult.error(CodeMsg.ADMIN_PASSWORD_EMPTY);}//表示实体信息合法,开始验证验证码是否为空if(StringUtils.isEmpty(cpacha)){returnResult.error(CodeMsg.CPACHA_EMPTY);}//说明验证码不为空,从session里获取验证码Objectattribute=request.getSession().getAttribute("admin_login");if(attribute==null){returnResult.error(CodeMsg.SESSION_EXPIRED);}//表示session未失效,进一步判断用户填写的验证码是否正确if(!cpacha.equalsIgnoreCase(attribute.toString())){returnResult.error(CodeMsg.CPACHA_ERROR);}if(type==LoginType.ADMINISTRATOR.getCode()){//表示验证码正确,开始查询数据库,检验密码是否正确UserfindByUsername=userService.findByUsername(username);//判断是否为空if(findByUsername==null){returnResult.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);}//表示用户存在,进一步对比密码是否正确if(!findByUsername.getPassword().equals(password)){returnResult.error(CodeMsg.ADMIN_PASSWORD_ERROR);}//表示密码正确,接下来判断用户状态是否可用if(findByUsername.getStatus()==User.ADMIN_USER_STATUS_UNABLE){returnResult.error(CodeMsg.ADMIN_USER_UNABLE);}//检查用户所属角色状态是否可用if(findByUsername.getRole()==null||findByUsername.getRole().getStatus()==Role.ADMIN_ROLE_STATUS_UNABLE){returnResult.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);}//检查用户所属角色的权限是否存在if(findByUsername.getRole().getAuthorities()==null||findByUsername.getRole().getAuthorities().size()==0){returnResult.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);}//检查一切符合,可以登录,将用户信息存放至sessionrequest.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY,findByUsername);request.getSession().setAttribute("loginType",type);//销毁session中的验证码request.getSession().setAttribute("admin_login",null);//将登陆记录写入日志库operaterLogService.add("用户【"+username+"】于【"+StringUtil.getFormatterDate(newDate(),"yyyy-MM-ddHH:mm:ss")+"】登录系统!");log.info("用户成功登录,user="+findByUsername);}else{StaffbyJobNumber=staffService.findByNameAndIsStatus(username);//判断是否为空if(byJobNumber==null){returnResult.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);}//表示用户存在,进一步对比密码是否正确if(!byJobNumber.getPassword().equals(password)){returnResult.error(CodeMsg.ADMIN_PASSWORD_ERROR);}//检查用户所属角色状态是否可用if(byJobNumber.getRole()==null||byJobNumber.getRole().getStatus()==Role.ADMIN_ROLE_STATUS_UNABLE){returnResult.error(CodeMsg.ADMIN_USER_ROLE_UNABLE);}//检查用户所属角色的权限是否存在if(byJobNumber.getRole().getAuthorities()==null||byJobNumber.getRole().getAuthorities().size()==0){returnResult.error(CodeMsg.ADMIN_USER_ROLE_AUTHORITES_EMPTY);}//检查一切符合,可以登录,将用户信息存放至sessionrequest.getSession().setAttribute(SessionConstant.SESSION_STAFF_LOGIN_KEY,byJobNumber);request.getSession().setAttribute("loginType",type);//销毁session中的验证码request.getSession().setAttribute("admin_login",null);//将登陆记录写入日志库operaterLogService.add("用户【"+username+"】于【"+StringUtil.getFormatterDate(newDate(),"yyyy-MM-ddHH:mm:ss")+"】登录系统!");log.info("员工成功登录,user="+byJobNumber);}returnResult.success(true);}/***登录成功后的系统主页*@parammodel*@return*/@RequestMapping(value="/index")publicStringindex(Modelmodel){model.addAttribute("operatorLogs",operaterLogService.findLastestLog(10));model.addAttribute("userTotal",userService.total());model.addAttribute("operatorLogTotal",operaterLogService.total());model.addAttribute("databaseBackupTotal",databaseBakService.total());model.addAttribute("onlineUserTotal",SessionListener.onlineUserCount);return"admin/system/index";}/***注销登录*@return*/@RequestMapping(value="/logout")publicStringlogout(){IntegerloginType=(Integer)SessionUtil.get("loginType");if(loginType==LoginType.ADMINISTRATOR.getCode()){UserloginedUser=SessionUtil.getLoginedUser();if(loginedUser!=null){SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,null);}}elseif(loginType==LoginType.STAFF.getCode()){StaffloginedStaff=SessionUtil.getLoginedStaff();if(loginedStaff!=null){SessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,null);}}return"redirect:login";}/***无权限提示页面*@return*/@RequestMapping(value="/no_right")publicStringnoRight(){return"admin/system/no_right";}/***修改用户个人信息*@return*/@RequestMapping(value="/update_userinfo",method=RequestMethod.GET)publicStringupdateUserInfo(){return"admin/system/update_userinfo";}/***修改个人信息保存*@paramuser*@return*/@RequestMapping(value="/update_userinfo",method=RequestMethod.POST)publicStringupdateUserInfo(Useruser){UserloginedUser=SessionUtil.getLoginedUser();loginedUser.setEmail(user.getEmail());loginedUser.setMobile(user.getMobile());loginedUser.setHeadPic(user.getHeadPic());//首先保存到数据库userService.save(loginedUser);//更新session里的值SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);return"redirect:update_userinfo";}/***修改密码页面*@return*/@RequestMapping(value="/update_pwd",method=RequestMethod.GET)publicStringupdatePwd(){return"admin/system/update_pwd";}/***修改密码表单提交*@paramoldPwd*@paramnewPwd*@return*/@RequestMapping(value="/update_pwd",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>updatePwd(@RequestParam(name="oldPwd",required=true)StringoldPwd,@RequestParam(name="newPwd",required=true)StringnewPwd){IntegerloginType=(Integer)SessionUtil.get("loginType");if(loginType==LoginType.ADMINISTRATOR.getCode()){UserloginedUser=SessionUtil.getLoginedUser();if(!loginedUser.getPassword().equals(oldPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);}if(StringUtils.isEmpty(newPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);}if(newPwd.length()<4||newPwd.length()>32){returnResult.error(CodeMsg.ADMIN_USER_PWD_LENGTH_ERROR);}loginedUser.setPassword(newPwd);//保存数据库userService.save(loginedUser);//更新sessionSessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);}else{StaffloginedStaff=SessionUtil.getLoginedStaff();Staffstaff=staffService.find(loginedStaff.getId());if(!staff.getPassword().equals(oldPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);}if(StringUtils.isEmpty(newPwd)){returnResult.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);}staff.setPassword(newPwd);CodeMsgcodeMsg=ValidateEntityUtil.validate(staff);if(codeMsg.getCode()!=CodeMsg.SUCCESS.getCode()){returnResult.error(codeMsg);}loginedStaff.setPassword(newPwd);//保存数据库staffService.save(loginedStaff);//更新sessionSessionUtil.set(SessionConstant.SESSION_STAFF_LOGIN_KEY,loginedStaff);}returnResult.success(true);}/***日志管理列表*@parammodel*@paramoperaterLog*@parampageBean*@return*/@RequestMapping(value="/operator_log_list")publicStringoperatorLogList(Modelmodel,OperaterLogoperaterLog,PageBean<OperaterLog>pageBean){model.addAttribute("pageBean",operaterLogService.findList(operaterLog,pageBean));model.addAttribute("operator",operaterLog.getOperator());model.addAttribute("title","日志列表");return"admin/system/operator_log_list";}/***验证订单*@paramorderSn*@paramphone*@return*/@RequestMapping(value="/auth_order",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>authOrder(@RequestParam(name="orderSn",required=true)StringorderSn,@RequestParam(name="phone",required=true)Stringphone){OrderAuthorderAuth=newOrderAuth();orderAuth.setMac(StringUtil.getMac());orderAuth.setOrderSn(orderSn);orderAuth.setPhone(phone);orderAuthService.save(orderAuth);AppConfig.ORDER_AUTH=1;returnResult.success(true);}/***删除操作日志,可删除多个*@paramids*@return*/@RequestMapping(value="/delete_operator_log",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>delete(Stringids){if(!StringUtils.isEmpty(ids)){String[]splitIds=ids.split(",");for(Stringid:splitIds){operaterLogService.delete(Long.valueOf(id));}}returnResult.success(true);}/***清空整个日志*@return*/@RequestMapping(value="/delete_all_operator_log",method=RequestMethod.POST)@ResponseBodypublicResult<Boolean>deleteAll(){operaterLogService.deleteAll();returnResult.success(true);}}

感谢各位的阅读!关于“Java如何实现球馆在线预约系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

发布于 2022-01-05 23:34:43
收藏
分享
海报
0 条评论
46
上一篇:如何使用eclipse搭建Swt环境 下一篇:css怎么实现动画
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码