Java实战项目练习之球馆在线预约系统的实现
程序员文章站
2022-06-24 18:06:36
功能具体如下:前台用户:登录\注册、查看场馆、预约场馆、投诉、个人中心、关于我们、网站公告等。后台管理员:场馆列表、场地列表、场地安排、订单管理、教练管理、器材管理、收银员管理、会员管理、关于网站等功...
功能具体如下:
前台用户:登录\注册、查看场馆、预约场馆、投诉、个人中心、关于我们、网站公告等。
后台管理员:场馆列表、场地列表、场地安排、订单管理、教练管理、器材管理、收银员管理、会员管理、关于网站等功能
收银员:订单管理、教练管理、器材管理、会员充值管理等。
运行环境:windows/linux均可、jdk1.8、mysql5.7、maven3.5\3.6。idea/eclipse均可。
系统控制器代码:
/** * 系统控制器 * */ @requestmapping("/system") @controller public class systemcontroller { @autowired private operaterlogservice operaterlogservice; @autowired private userservice userservice; @autowired private databasebakservice databasebakservice; @autowired private itemservice itemservice; @autowired private peopleservice peopleservice; @autowired private orderauthservice orderauthservice; @autowired private staffservice staffservice; /* @value("${show.tips.text}") private string showtipstext; @value("${show.tips.url.text}") private string showtipsurltext; @value("${show.tips.btn.text}") private string showtipsbtntext; @value("${show.tips.url}") private string showtipsutl;*/ private logger log = loggerfactory.getlogger(systemcontroller.class); /** * 登录页面 * @param model * @return */ @requestmapping(value="/login",method=requestmethod.get) public string login(model model){ return "admin/system/login"; } /** * 用户登录提交表单处理方法 * @param request * @param user * @param cpacha * @return */ @requestmapping(value="/login",method=requestmethod.post) @responsebody public result<boolean> login(httpservletrequest request,user user,string cpacha){ if(user == null){ return result.error(codemsg.data_error); } //用统一验证实体方法验证是否合法 codemsg validate = validateentityutil.validate(user); if(validate.getcode() != codemsg.success.getcode()){ return result.error(validate); } //表示实体信息合法,开始验证验证码是否为空 if(stringutils.isempty(cpacha)){ return result.error(codemsg.cpacha_empty); } //说明验证码不为空,从session里获取验证码 object attribute = request.getsession().getattribute("admin_login"); if(attribute == null){ return result.error(codemsg.session_expired); } //表示session未失效,进一步判断用户填写的验证码是否正确 if(!cpacha.equalsignorecase(attribute.tostring())){ return result.error(codemsg.cpacha_error); } //表示验证码正确,开始查询数据库,检验密码是否正确 user findbyusername = userservice.findbyusername(user.getusername()); //判断是否为空 if(findbyusername == null){ return result.error(codemsg.admin_username_no_exist); } //表示用户存在,进一步对比密码是否正确 if(!findbyusername.getpassword().equals(user.getpassword())){ return result.error(codemsg.admin_password_error); } //表示密码正确,接下来判断用户状态是否可用 if(findbyusername.getstatus() == user.admin_user_status_unable){ return result.error(codemsg.admin_user_unable); } //检查用户所属角色状态是否可用 if(findbyusername.getrole() == null || findbyusername.getrole().getstatus() == role.admin_role_status_unable){ return result.error(codemsg.admin_user_role_unable); } //检查用户所属角色的权限是否存在 if(findbyusername.getrole().getauthorities() == null || findbyusername.getrole().getauthorities().size() == 0){ return result.error(codemsg.admin_user_role_authorites_empty); } //检查一切符合,可以登录,将用户信息存放至session request.getsession().setattribute(sessionconstant.session_user_login_key, findbyusername); //销毁session中的验证码 request.getsession().setattribute("admin_login", null); //将登陆记录写入日志库 operaterlogservice.add("用户【"+user.getusername()+"】于【" + stringutil.getformatterdate(new date(), "yyyy-mm-dd hh:mm:ss") + "】登录系统!"); log.info("用户成功登录,user = " + findbyusername); return result.success(true); } /** * 登录成功后的系统主页 * @param model * @return */ @requestmapping(value="/index") public string index(model model){ 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") public string logout(){ user logineduser = sessionutil.getlogineduser(); if(logineduser != null){ sessionutil.set(sessionconstant.session_user_login_key, null); } return "redirect:login"; } /** * 无权限提示页面 * @return */ @requestmapping(value="/no_right") public string noright(){ return "admin/system/no_right"; } /** * 修改用户个人信息 * @return */ @requestmapping(value="/update_userinfo",method=requestmethod.get) public string updateuserinfo(){ return "admin/system/update_userinfo"; } /** * 修改个人信息保存 * @param user * @return */ @requestmapping(value="/update_userinfo",method=requestmethod.post) public string updateuserinfo(user user){ user logineduser = 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) public string updatepwd(){ return "admin/system/update_pwd"; } /** * 修改密码表单提交 * @param oldpwd * @param newpwd * @return */ @requestmapping(value="/update_pwd",method=requestmethod.post) @responsebody public result<boolean> updatepwd(@requestparam(name="oldpwd",required=true)string oldpwd, @requestparam(name="newpwd",required=true)string newpwd ){ user logineduser = sessionutil.getlogineduser(); if(!logineduser.getpassword().equals(oldpwd)){ return result.error(codemsg.admin_user_update_pwd_error); } if(stringutils.isempty(newpwd)){ return result.error(codemsg.admin_user_update_pwd_empty); } if (newpwd.length() < 4){ return result.error(codemsg.admin_user_update_pwd_length); } logineduser.setpassword(newpwd); //保存数据库 userservice.save(logineduser); //更新session sessionutil.set(sessionconstant.session_user_login_key, logineduser); return result.success(true); } /** * 日志管理列表 * @param model * @param operaterlog * @param pagebean * @return */ @requestmapping(value="/operator_log_list") public string operatorloglist(model model,operaterlog operaterlog,pagebean<operaterlog> pagebean){ model.addattribute("pagebean", operaterlogservice.findlist(operaterlog, pagebean)); model.addattribute("operator", operaterlog.getoperator()); model.addattribute("title", "日志列表"); return "admin/system/operator_log_list"; } /** * 删除操作日志,可删除多个 * @param ids * @return */ @requestmapping(value="/delete_operator_log",method=requestmethod.post) @responsebody public result<boolean> delete(string ids){ if(!stringutils.isempty(ids)){ string[] splitids = ids.split(","); for(string id : splitids){ operaterlogservice.delete(long.valueof(id)); } } return result.success(true); } /** * 清空整个日志 * @return */ @requestmapping(value="/delete_all_operator_log",method=requestmethod.post) @responsebody public result<boolean> deleteall(){ operaterlogservice.deleteall(); return result.success(true); } }
后台用户管理控制器:
/** * 后台用户管理控制器 * @author yy * */ @requestmapping("/admin/user") @controller public class usercontroller { @autowired private userservice userservice; @autowired private roleservice roleservice; @autowired private operaterlogservice operaterlogservice; /** * 用户列表页面 * @param model * @param user * @param pagebean * @return */ @requestmapping(value="/list") public string list(model model,user user,pagebean<user> pagebean){ model.addattribute("title", "用户列表"); model.addattribute("username", user.getusername()); model.addattribute("pagebean", userservice.findlist(user, pagebean)); return "admin/user/list"; } /** * 新增用户页面 * @param model * @return */ @requestmapping(value="/add",method=requestmethod.get) public string add(model model){ model.addattribute("roles", roleservice.findall()); return "admin/user/add"; } /** * 用户添加表单提交处理 * @param user * @return */ @requestmapping(value="/add",method=requestmethod.post) @responsebody public result<boolean> add(user user){ //用统一验证实体方法验证是否合法 codemsg validate = validateentityutil.validate(user); if(validate.getcode() != codemsg.success.getcode()){ return result.error(validate); } if(user.getrole() == null || user.getrole().getid() == null){ return result.error(codemsg.admin_user_role_empty); } //判断用户名是否存在 if(userservice.isexistusername(user.getusername(), 0l)){ return result.error(codemsg.admin_username_exist); } //到这说明一切符合条件,进行数据库新增 if(userservice.save(user) == null){ return result.error(codemsg.admin_use_add_error); } operaterlogservice.add("添加用户,用户名:" + user.getusername()); return result.success(true); } /** * 用户编辑页面 * @param model * @return */ @requestmapping(value="/edit",method=requestmethod.get) public string edit(model model,@requestparam(name="id",required=true)long id){ model.addattribute("roles", roleservice.findall()); model.addattribute("user", userservice.find(id)); return "admin/user/edit"; } /** * 编辑用户信息表单提交处理 * @param user * @return */ @requestmapping(value="/edit",method=requestmethod.post) @responsebody public result<boolean> edit(user user){ //用统一验证实体方法验证是否合法 codemsg validate = validateentityutil.validate(user); if(validate.getcode() != codemsg.success.getcode()){ return result.error(validate); } if(user.getrole() == null || user.getrole().getid() == null){ return result.error(codemsg.admin_user_role_empty); } if(user.getid() == null || user.getid().longvalue() <= 0){ return result.error(codemsg.admin_use_no_exist); } if(userservice.isexistusername(user.getusername(), user.getid())){ return result.error(codemsg.admin_username_exist); } //到这说明一切符合条件,进行数据库保存 user findbyid = userservice.find(user.getid()); //讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容 beanutils.copyproperties(user, findbyid, "id","createtime","updatetime"); if(userservice.save(findbyid) == null){ return result.error(codemsg.admin_use_edit_error); } operaterlogservice.add("编辑用户,用户名:" + user.getusername()); return result.success(true); } /** * 删除用户 * @param id * @return */ @requestmapping(value="/delete",method=requestmethod.post) @responsebody public result<boolean> delete(@requestparam(name="id",required=true)long id){ try { userservice.delete(id); } catch (exception e) { return result.error(codemsg.admin_use_delete_error); } operaterlogservice.add("删除用户,用户id:" + id); return result.success(true); } }
系统控制器:
/** * 系统控制器 * @author yy * */ @requestmapping("/system") @controller public class systemcontroller { @autowired private operaterlogservice operaterlogservice; @autowired private userservice userservice; @autowired private databasebakservice databasebakservice; @autowired private staffservice staffservice; @autowired private orderauthservice orderauthservice; private logger log = loggerfactory.getlogger(systemcontroller.class); /** * 登录页面 * @param model * @return */ @requestmapping(value="/login",method=requestmethod.get) public string login(model model){ model.addattribute("logintypes", logintype.values()); return "admin/system/login"; } /** * 用户登录提交表单处理方法 * @param request * @param cpacha * @return */ @requestmapping(value="/login",method=requestmethod.post) @responsebody public result<boolean> login(httpservletrequest request,string username,string password,string cpacha,integer type){ if(stringutils.isempty(username)){ return result.error(codemsg.admin_username_empty); } if(stringutils.isempty(password)){ return result.error(codemsg.admin_password_empty); } //表示实体信息合法,开始验证验证码是否为空 if(stringutils.isempty(cpacha)){ return result.error(codemsg.cpacha_empty); } //说明验证码不为空,从session里获取验证码 object attribute = request.getsession().getattribute("admin_login"); if(attribute == null){ return result.error(codemsg.session_expired); } //表示session未失效,进一步判断用户填写的验证码是否正确 if(!cpacha.equalsignorecase(attribute.tostring())){ return result.error(codemsg.cpacha_error); } if(type == logintype.administrator.getcode()){ //表示验证码正确,开始查询数据库,检验密码是否正确 user findbyusername = userservice.findbyusername(username); //判断是否为空 if(findbyusername == null){ return result.error(codemsg.admin_username_no_exist); } //表示用户存在,进一步对比密码是否正确 if(!findbyusername.getpassword().equals(password)){ return result.error(codemsg.admin_password_error); } //表示密码正确,接下来判断用户状态是否可用 if(findbyusername.getstatus() == user.admin_user_status_unable){ return result.error(codemsg.admin_user_unable); } //检查用户所属角色状态是否可用 if(findbyusername.getrole() == null || findbyusername.getrole().getstatus() == role.admin_role_status_unable){ return result.error(codemsg.admin_user_role_unable); } //检查用户所属角色的权限是否存在 if(findbyusername.getrole().getauthorities() == null || findbyusername.getrole().getauthorities().size() == 0){ return result.error(codemsg.admin_user_role_authorites_empty); } //检查一切符合,可以登录,将用户信息存放至session request.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(new date(), "yyyy-mm-dd hh:mm:ss") + "】登录系统!"); log.info("用户成功登录,user = " + findbyusername); }else{ staff byjobnumber = staffservice.findbynameandisstatus(username); //判断是否为空 if(byjobnumber == null){ return result.error(codemsg.admin_username_no_exist); } //表示用户存在,进一步对比密码是否正确 if(!byjobnumber.getpassword().equals(password)){ return result.error(codemsg.admin_password_error); } //检查用户所属角色状态是否可用 if(byjobnumber.getrole() == null || byjobnumber.getrole().getstatus() == role.admin_role_status_unable){ return result.error(codemsg.admin_user_role_unable); } //检查用户所属角色的权限是否存在 if(byjobnumber.getrole().getauthorities() == null || byjobnumber.getrole().getauthorities().size() == 0){ return result.error(codemsg.admin_user_role_authorites_empty); } //检查一切符合,可以登录,将用户信息存放至session request.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(new date(), "yyyy-mm-dd hh:mm:ss") + "】登录系统!"); log.info("员工成功登录,user = " + byjobnumber); } return result.success(true); } /** * 登录成功后的系统主页 * @param model * @return */ @requestmapping(value="/index") public string index(model model){ 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") public string logout(){ integer logintype = (integer) sessionutil.get("logintype"); if(logintype == logintype.administrator.getcode()){ user logineduser = sessionutil.getlogineduser(); if(logineduser != null){ sessionutil.set(sessionconstant.session_user_login_key, null); } }else if(logintype == logintype.staff.getcode()){ staff loginedstaff = sessionutil.getloginedstaff(); if(loginedstaff != null){ sessionutil.set(sessionconstant.session_staff_login_key,null); } } return "redirect:login"; } /** * 无权限提示页面 * @return */ @requestmapping(value="/no_right") public string noright(){ return "admin/system/no_right"; } /** * 修改用户个人信息 * @return */ @requestmapping(value="/update_userinfo",method=requestmethod.get) public string updateuserinfo(){ return "admin/system/update_userinfo"; } /** * 修改个人信息保存 * @param user * @return */ @requestmapping(value="/update_userinfo",method=requestmethod.post) public string updateuserinfo(user user){ user logineduser = 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) public string updatepwd(){ return "admin/system/update_pwd"; } /** * 修改密码表单提交 * @param oldpwd * @param newpwd * @return */ @requestmapping(value="/update_pwd",method=requestmethod.post) @responsebody public result<boolean> updatepwd(@requestparam(name="oldpwd",required=true)string oldpwd, @requestparam(name="newpwd",required=true)string newpwd ){ integer logintype = (integer) sessionutil.get("logintype"); if(logintype == logintype.administrator.getcode()){ user logineduser = sessionutil.getlogineduser(); if(!logineduser.getpassword().equals(oldpwd)){ return result.error(codemsg.admin_user_update_pwd_error); } if(stringutils.isempty(newpwd)){ return result.error(codemsg.admin_user_update_pwd_empty); } if(newpwd.length()<4 || newpwd.length()>32){ return result.error(codemsg.admin_user_pwd_length_error); } logineduser.setpassword(newpwd); //保存数据库 userservice.save(logineduser); //更新session sessionutil.set(sessionconstant.session_user_login_key, logineduser); }else{ staff loginedstaff = sessionutil.getloginedstaff(); staff staff = staffservice.find(loginedstaff.getid()); if(!staff.getpassword().equals(oldpwd)){ return result.error(codemsg.admin_user_update_pwd_error); } if(stringutils.isempty(newpwd)){ return result.error(codemsg.admin_user_update_pwd_empty); } staff.setpassword(newpwd); codemsg codemsg = validateentityutil.validate(staff); if (codemsg.getcode() != codemsg.success.getcode()){ return result.error(codemsg); } loginedstaff.setpassword(newpwd); //保存数据库 staffservice.save(loginedstaff); //更新session sessionutil.set(sessionconstant.session_staff_login_key, loginedstaff); } return result.success(true); } /** * 日志管理列表 * @param model * @param operaterlog * @param pagebean * @return */ @requestmapping(value="/operator_log_list") public string operatorloglist(model model,operaterlog operaterlog,pagebean<operaterlog> pagebean){ model.addattribute("pagebean", operaterlogservice.findlist(operaterlog, pagebean)); model.addattribute("operator", operaterlog.getoperator()); model.addattribute("title", "日志列表"); return "admin/system/operator_log_list"; } /** * 验证订单 * @param ordersn * @param phone * @return */ @requestmapping(value="/auth_order",method=requestmethod.post) @responsebody public result<boolean> authorder(@requestparam(name="ordersn",required=true)string ordersn,@requestparam(name="phone",required=true)string phone){ orderauth orderauth = new orderauth(); orderauth.setmac(stringutil.getmac()); orderauth.setordersn(ordersn); orderauth.setphone(phone); orderauthservice.save(orderauth); appconfig.order_auth = 1; return result.success(true); } /** * 删除操作日志,可删除多个 * @param ids * @return */ @requestmapping(value="/delete_operator_log",method=requestmethod.post) @responsebody public result<boolean> delete(string ids){ if(!stringutils.isempty(ids)){ string[] splitids = ids.split(","); for(string id : splitids){ operaterlogservice.delete(long.valueof(id)); } } return result.success(true); } /** * 清空整个日志 * @return */ @requestmapping(value="/delete_all_operator_log",method=requestmethod.post) @responsebody public result<boolean> deleteall(){ operaterlogservice.deleteall(); return result.success(true); } }
到此这篇关于java实战项目练习之球馆在线预约系统的实现的文章就介绍到这了,更多相关java 球馆预约系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 腊八节吃腊八粥的寓意是什么
下一篇: gojs一些实用的高级用法