Java实战宠物店在线交易平台的实现流程
程序员文章站
2022-06-24 17:58:20
该系统分为前台和后台,前台可以自主注册,后台管理员角色,除基础脚手架外,实现的功能有:后台管理员功能有:商品分类管理、商品管理、套餐管理、新闻分类管理、新闻管理、常见问题、关于我们、团队管理、订单查看...
该系统分为前台和后台,前台可以自主注册,后台管理员角色,除基础脚手架外,实现的功能有:
后台管理员功能有:
商品分类管理、商品管理、套餐管理、新闻分类管理、新闻管理、常见问题、关于我们、团队管理、订单查看和前台用户查看等功能。
前台用户功能有:注册登录、查看商品、购物车、支付订单、评价、照片库、新闻列表、个人中心、购买套餐等功能。
运行环境:windows/linux均可、jdk1.8、mysql5.7、maven3.5\maven3.6、idea/eclipse均可。
系统控制器代码:
/** * 系统控制器 * @author admin * */ @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 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); } }
用户控制:
/** * 用户控制 */ @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"; } /** * 更新数据库 */ @responsebody @requestmapping("/updateuser") public string updateuser(user user) { return userservice.updateuser(user); } }
健康评估控制层:
/** * 健康评估 */ @controller("healthcontroller") @requestmapping("/health") public class healthcontroller { @autowired private diagnosisservice diagnosisservice; @autowired private appointmentservice appointmentservice; @autowired private petservice petservice; @autowired private petdailyservice petdailyservice; @autowired private userservice userservice; @autowired private standardservice standardservice; /** * 分析页面 */ @requestmapping("/assess") public string applylistdoctor(model model) { subject subject = securityutils.getsubject(); user user = (user) subject.getprincipal(); pet pet = new pet(); pet.setuserid(user.getid()); pet.setpage(1); pet.setlimit(100); mmgridpagevobean<pet> vobean = (mmgridpagevobean<pet>) petservice.getallbylimit(pet); list<pet> rows = vobean.getrows(); // 获取到该用户下所有的宠物 model.addattribute("pets", rows); list<long> applycount = new arraylist<>(); list<string> dscount = new arraylist<>(); list<string> tscount = new arraylist<>(); list<string> wscount = new arraylist<>(); list<string> hscount = new arraylist<>(); list<string> ascount = new arraylist<>(); list<double> pt = new arraylist<>(); list<double> pw = new arraylist<>(); list<double> ph = new arraylist<>(); list<double> pa = new arraylist<>(); list<double> mt = new arraylist<>(); list<double> mw = new arraylist<>(); list<double> mh = new arraylist<>(); list<double> ma = new arraylist<>(); for(pet p: rows){ // 获取预约次数 appointment appointment = new appointment(); appointment.setpetid(p.getid()); appointment.setpage(1); appointment.setlimit(1000); mmgridpagevobean<appointment> as = (mmgridpagevobean<appointment>) appointmentservice.getallbylimit(appointment); applycount.add(as==null? 0l : as.gettotal()); // 获取就诊记录 diagnosis diagnosis = new diagnosis(); diagnosis.setpetid(p.getid()); diagnosis.setpage(1); diagnosis.setlimit(10); mmgridpagevobean<diagnosis> ds = (mmgridpagevobean<diagnosis>) diagnosisservice.getallbylimit(diagnosis); list<diagnosis> dsrows = ds.getrows(); 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(); // 对应宠物类型 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); 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( " 体温偏高"); } if (w>=wsmin && w<=wsmax){ wscount.add( " 体重正常"); }else if (w<wsmin){ wscount.add(" 体重偏低"); }else if (w>wsmax){ wscount.add(" 体重偏高"); } if (h>=hsmin && h<=hsmax){ hscount.add(" 身高正常"); }else if (h<hsmin){ hscount.add( " 身高偏低"); }else if (h>hsmax){ hscount.add(" 身高偏高"); } if (a>=asmin && a<=asmax){ ascount.add( " 饭量正常"); }else if (a<asmin){ ascount.add(" 饭量偏低"); }else if (a>asmax){ ascount.add(" 饭量偏高"); } } model.addattribute("pets", rows); model.addattribute("tscount", tscount); model.addattribute("wscount", wscount); model.addattribute("hscount", hscount); model.addattribute("ascount", ascount); model.addattribute("dscount", dscount); system.out.println(pt); model.addattribute("pt", pt); model.addattribute("ph", ph); model.addattribute("pw", pw); model.addattribute("pa", pa); model.addattribute("mt", mt); model.addattribute("mh", mh); model.addattribute("mw", mw); model.addattribute("ma", ma); return "tj/assess"; } /** * 普通用户预约统计 */ @requestmapping("/tjapply") public string tjapply(model model) { subject subject = securityutils.getsubject(); user user = (user) subject.getprincipal(); appointment appointment = new appointment(); appointment.setuserid(user.getid()); 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/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) { subject subject = securityutils.getsubject(); user user = (user) subject.getprincipal(); pet pet = new pet(); pet.setuserid(user.getid()); pet.setpage(1); pet.setlimit(99999); mmgridpagevobean<pet> vobean = (mmgridpagevobean<pet>) petservice.getallbylimit(pet); list<pet> rows = vobean.getrows(); model.addattribute("pets", rows); if (rows.size()>0){ pet = rows.get(0); petdaily daily = new petdaily(); daily.setpetid(pet.getid()); daily.setpage(1); daily.setlimit(99999); mmgridpagevobean<petdaily> ppp = (mmgridpagevobean<petdaily>) petdailyservice.getallbylimit(daily); list<petdaily> list = ppp.getrows(); for (petdaily p : list){ p.setdatetime(myutils.getdate2string(p.getcreatetime(), "yyyy-mm-dd")); } model.addattribute("dailys", list); } return "tj/tjdaily"; } /** * 医生宠物日志统计 */ @requestmapping("/tjdailydoctor") public string tjdailydoctor(model model) { pet pet = new pet(); pet.setpage(1); pet.setlimit(99999); mmgridpagevobean<pet> vobean = (mmgridpagevobean<pet>) petservice.getallbylimit(pet); list<pet> rows = vobean.getrows(); model.addattribute("pets", rows); if (rows.size()>0){ pet = rows.get(0); petdaily daily = new petdaily(); daily.setpetid(pet.getid()); daily.setpage(1); daily.setlimit(99999); mmgridpagevobean<petdaily> ppp = (mmgridpagevobean<petdaily>) petdailyservice.getallbylimit(daily); list<petdaily> list = ppp.getrows(); for (petdaily p : list){ p.setdatetime(myutils.getdate2string(p.getcreatetime(), "yyyy-mm-dd")); } model.addattribute("dailys", list); } return "tj/tjdailydoctor"; } /** * 普通用户查询条件数据返回宠物日志 */ @requestmapping("/tjdailydata") @responsebody public object tjdailydata(long id){ petdaily daily = new petdaily(); daily.setpetid(id); daily.setpage(1); daily.setlimit(99999); mmgridpagevobean<petdaily> ppp = (mmgridpagevobean<petdaily>) petdailyservice.getallbylimit(daily); list<petdaily> list = ppp.getrows(); for (petdaily p : list){ p.setdatetime(myutils.getdate2string(p.getcreatetime(), "yyyy-mm-dd")); } return list; } /** * 医生查询条件数据返回宠物日志 */ @requestmapping("/tjdailydatadoctor") @responsebody public object tjdailydatadoctor(long id){ petdaily daily = new petdaily(); daily.setpetid(id); daily.setpage(1); daily.setlimit(99999); mmgridpagevobean<petdaily> ppp = (mmgridpagevobean<petdaily>) petdailyservice.getallbylimit(daily); list<petdaily> list = ppp.getrows(); for (petdaily p : list){ p.setdatetime(myutils.getdate2string(p.getcreatetime(), "yyyy-mm-dd")); } return list; } /** * 用户查看医生空闲时间 */ @requestmapping(value = "/freetime") public string freetime(model model) { list<user> doctors = userservice.listdoctor(); model.addattribute("doctors", doctors); long docid = doctors.get(0).getid(); model.addattribute("docname", doctors.get(0).getname()); string nowdateymd = myutils.getnowdateymd(); list<map<string, object>> map = appointmentservice.getfreetimebyid(docid, nowdateymd+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); } } model.addattribute("time", time); model.addattribute("value", value); return "tj/freetime"; } @requestmapping(value = "/getfreetime") @responsebody public object getfreetime(long id, string date) { user doctors = userservice.selectbyprimarykey(id); map<string, object> result = new hashmap<>(); result.put("n", doctors.getname()); 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; } }
到此这篇关于java实战宠物店在线交易平台的实现流程的文章就介绍到这了,更多相关java 宠物在线交易内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!