Java毕业设计实战之财务预算管理系统的实现
程序员文章站
2022-06-17 13:30:23
一、项目简述功能包括:实现公司对项目的管理。二、项目运行环境配置:jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclisp...
一、项目简述
功能包括:实现公司对项目的管理。
二、项目运行
环境配置:
jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclispe,sts都支持)
项目技术:
jsp +spring + springmvc + mybatis + html+ css + javascript + jquery + ajax + layui+ maven等等
用户信息控制层:
/** * 用户信息控制层 */ @controller public class userinfocontroller { @resource private userinfoservice userinfoservice; @resource private privilegeservice privilegeservice; @requestmapping(value = {"/", "login.html"}) public string tologin(httpservletrequest request, httpservletresponse response){ httpsession session = request.getsession(); if(session.getattribute(config.current_username)==null){ return "login"; }else { try { response.sendredirect("/pages/index"); } catch (ioexception e) { e.printstacktrace(); return "login"; } return null; } } // @requestmapping(value = "/login.do",method = requestmethod.post) @requestmapping(value = "/login.do") @responsebody public result getuserinfo(userinfo userinfo, httpservletrequest request, httpservletresponse response){ boolean userisexisted = userinfoservice.userisexisted(userinfo); system.out.println(userisexisted + " - " + request.getheader("token")); userinfo = getuserinfo(userinfo); if("client".equals(request.getheader("token")) && !userisexisted){ //用户不存在 return resultutil.success(-1); } if (userisexisted && userinfo == null){ return resultutil.unsuccess("用户名或密码错误!"); }else { //将用户信息存入session userinfo = setsessionuserinfo(userinfo,request.getsession()); //将当前用户信息存入cookie setcookieuser(request,response); return resultutil.success("登录成功", userinfo); } } @requestmapping("/users/getusersbywhere/{pageno}/{pagesize}") public @responsebody result getusersbywhere(userinfo userinfo, @pathvariable int pageno, @pathvariable int pagesize, httpsession session){ if ("".equals(userinfo.gethouseid())){ userinfo.sethouseid(null); } if (userinfo.getroleid() == -1){ userinfo.setroleid(config.getsessionuser(session).getroleid()); } utils.log(userinfo.tostring()); pagemodel model = new pagemodel<>(pageno,userinfo); model.setpagesize(pagesize); return userinfoservice.getusersbywhere(model); } @requestmapping("/user/add") public @responsebody result adduser(userinfo userinfo){ system.out.println(userinfo); try { int num = userinfoservice.add(userinfo); if(num>0){ return resultutil.success(); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/user/update") public @responsebody result updateuser(userinfo userinfo){ try { int num = userinfoservice.update(userinfo); if(num>0){ return resultutil.success(); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/user/del/{id}") public @responsebody result deleteuser(@pathvariable string id){ try { int num = userinfoservice.delete(id); if(num>0){ return resultutil.success(); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/getsessionuser") @responsebody public userinfo getsessionuser(httpsession session){ userinfo sessionuser = (userinfo) session.getattribute(config.current_username); sessionuser.setpassword(null); return sessionuser; } @requestmapping("/logout") public string logout(httpservletrequest request, httpservletresponse response){ delcookieuser(request, response); request.getsession().removeattribute(config.current_username); return "login"; } @requestmapping("/getallroles") public @responsebody result<role> getallroles(){ try { list<role> roles = userinfoservice.getallroles(); if (roles.size()>0){ return resultutil.success(roles); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/role/add") public @responsebody result addrole(role role){ try { int num = userinfoservice.addrole(role); if(num>0){ privilegeservice.adddefaultprivilegeswhenaddrole(role.getroleid().tostring()); return resultutil.success(); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/role/update") public @responsebody result updaterole(role role){ try { int num = userinfoservice.updaterole(role); if(num>0){ return resultutil.success(); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/role/del/{roleid}") public @responsebody result deleterole(@pathvariable string roleid){ try { privilegeservice.delprivilegeswendelrole(roleid); int num = userinfoservice.deleterole(roleid); if(num>0){ return resultutil.success(); }else { privilegeservice.adddefaultprivilegeswhenaddrole(roleid); return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/getrole/{id}") public @responsebody result getrolebyid(@pathvariable string id){ try { role role = userinfoservice.getrolebyid(id); if(role != null){ return resultutil.success(role); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } /** * 登录时将用户信息加入cookie中 * @param response */ private void setcookieuser(httpservletrequest request, httpservletresponse response){ userinfo user = getsessionuser(request.getsession()); cookie cookie = new cookie(config.current_username,user.getusername()+"_"+user.getid()); //cookie 保存7天 cookie.setmaxage(60*60*24*7); response.addcookie(cookie); } /** * 注销时删除cookie信息 * @param request * @param response */ private void delcookieuser(httpservletrequest request, httpservletresponse response){ userinfo user = getsessionuser(request.getsession()); cookie cookie = new cookie(config.current_username,user.getusername()+"_"+user.getid()); cookie.setmaxage(-1); response.addcookie(cookie); } /** * 通过用户信息获取用户权限信息,并存入session中 * @param userinfo * @param session * @return */ public userinfo setsessionuserinfo(userinfo userinfo, httpsession session){ list<privilege> privileges = privilegeservice.getprivilegebyroleid(userinfo.getroleid()); userinfo.setprivileges(privileges); session.setattribute(config.current_username,userinfo); return userinfo; } public userinfo getuserinfo(userinfo userinfo){ return userinfoservice.getuserinfo(userinfo); } }
数据图形展示:
@restcontroller @requestmapping("/bills") public class billcontroller { @resource private billservice billservice; /** * 适用于统计图 * @param bill * @return */ @requestmapping("/getbillstochart") public result<bill> findbywherenopage(bill bill, httpsession session){ bill = gethousebill(bill,session); return billservice.findbywherenopage(bill); } @requestmapping("/getbillsbywhere/{type}/{pageno}/{pagesize}") public result<bill> getbillsbywhere(bill bill,@pathvariable string type, @pathvariable int pageno, @pathvariable int pagesize, httpsession session){ if("-1".equals(bill.getpayway())){ bill.setpayway(null); } bill.settype(type); bill = gethousebill(bill,session); system.out.println(bill); pagemodel model = new pagemodel<>(pageno,bill); model.setpagesize(pagesize); return billservice.findbywhere(model); } @requestmapping("/getbillsbyuserid/{userid}/{pageno}/{pagesize}/{year}/{month}") public result getbillsbyuserid(@pathvariable integer userid, @pathvariable int pageno, @pathvariable int pagesize, @pathvariable int year, @pathvariable int month){ bill bill = new bill(); bill.setuserid(userid); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); bill.setstarttime(year+"-0"+month+"-01"); try { date date = sdf.parse(year+"-0"+(month+1)+"-01"); date.setdate(date.getdate()-1); bill.setendtime(sdf.format(date)); } catch (parseexception e) { e.printstacktrace(); } pagemodel model = new pagemodel<>(pageno,bill); model.setpagesize(pagesize); result result = billservice.findbywhere(model); list<map<string,string>> r = billservice.getmonthlyinfo(model); map<string,string> map = new hashmap<>(); for (map<string,string> m: r) { map.put(m.get("typeid"),string.format("%.2f",m.get("sum(money)"))); } result.setdata(map); return result; } private bill gethousebill(bill bill, httpsession session) { userinfo currentuser = config.getsessionuser(session); //当登录用户为家主时,查询默认查询全家账单情况 //当登录用户为普通用户时,仅查询当前用户的账单 if (currentuser.getroleid() == 2){ bill.sethouseid(currentuser.gethouseid()); }else if (currentuser.getroleid() == 3){ bill.setuserid(currentuser.getid()); } return bill; } @requestmapping(value = "/addbill",method = requestmethod.post) public result add(bill bill, httpsession session){ if (config.getsessionuser(session)!=null){ bill.setuserid(config.getsessionuser(session).getid()); } utils.log(bill.tostring()); try { int num = billservice.add(bill); if(num>0){ int billid = bill.getid(); bill = new bill(); bill.setid(billid); return resultutil.success("记账成功!",billservice.findbywherenopage(bill)); // return resultutil.success("记账成功!",bill); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/updatebill") public result update(bill bill, httpsession session){ if (config.getsessionuser(session)!=null){ bill.setuserid(config.getsessionuser(session).getid()); } utils.log(bill.tostring()); try { int num = billservice.update(bill); if(num>0){ return resultutil.success("修改成功!",null); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/delbill") public result del(int id){ try { int num = billservice.del(id); if(num>0){ return resultutil.success("删除成功!",null); }else { return resultutil.unsuccess(); } }catch (exception e){ return resultutil.error(e); } } @requestmapping("/getpayways") public result<payway> getallpayways(){ try { list<payway> payways = billservice.getallpayways(); if (payways!=null && payways.size()>0){ return resultutil.success(payways); }else { return resultutil.unsuccess(); } } catch (exception e) { return resultutil.error(e); } } }
用户信息mapper类:
@repository public interface userinfomapper { /** * 获取单个用户信息,可用于: * 1.登录 * 2.通过用户某一部分信息获取用户完整信息 * @param userinfo * @return */ userinfo getuserinfo(userinfo userinfo); /** * 注册 * @param userinfo * @return */ int adduser(userinfo userinfo); /** * 通过username判断该用户是否存在 * @param userinfo * @return */ int userisexisted(userinfo userinfo); /** * 通过条件获取符合条件的优化信息 -- 分页 * @param model * @return */ list<userinfo> getusersbywhere(pagemodel<userinfo> model); int gettoatlbywhere(pagemodel<userinfo> model); int add(userinfo userinfo); int update(userinfo userinfo); int delete(string id); list<role> getallroles(); int addrole(role role); int updaterole(role role); int deleterole(string id); role getrolebyid(string id); int addhouseid(house house); }
到此这篇关于java毕业设计实战之财务预算管理系统的实现的文章就介绍到这了,更多相关java 财务预算管理内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 批处理实现批量修改文件名