|
作者简介:Java领域优质创作者、CSDN博客专家、CSDN内容合伙人、掘金特邀作者、阿里云博客专家、51CTO特邀作者、多年架构师设计经验、多年校企合作经验,被多个学校常年聘为校外企业导师,指导学生毕业设计并参与学生毕业答辩指导,有较为丰富的相关经验。期待与各位高校教师、企业讲师以及同行交流合作主要内容:Java项目、Python项目、前端项目、PHP、ASP.NET、人工智能与大数据、单片机开发、物联网设计与开发设计、简历模板、学习资料、面试题库、技术互助、就业指导等业务范围:免费功能设计、开题报告、任务书、中期检查PPT、系统功能实现、代码编写、论文编写和辅导、论文降重、长期答辩答疑辅导、腾讯会议一对一专业讲解辅导答辩、模拟答辩演练、和理解代码逻辑思路等。收藏点赞不迷路 关注作者有好处文末获取源码 项目编号:BS-Python-048一,环境介绍语言环境:Python3.8数据库:Mysql:mysql5.7WEB框架:Django开发工具:IDEA或PyCharm二,项目简介基于Python和Flask实现的宿舍管理系统是一个旨在提升宿舍管理效率和便捷性的Web应用。该系统利用Flask框架快速构建后端服务,提供RESTfulAPI接口,支持用户登录、宿舍信息管理、学生入住与退宿记录、物品报修及维修跟踪、安全巡查记录等功能。前端可以采用Vue+HTML/CSS/JavaScript进行界面设计,与后端通过AJAX等技术实现数据交互,提供友好的用户操作界面。系统核心在于数据库设计,需合理构建宿舍、学生、管理员、报修记录等数据表,并通过SQLAlchemy等ORM工具简化数据库操作。安全性方面,通过用户认证与授权机制保护数据安全,如使用JWT进行用户身份验证。此外,系统还应具备可扩展性和可维护性,便于未来功能升级和故障排查。整体而言,该宿舍管理系统通过自动化管理流程,减轻了宿管人员的工作负担,提高了宿舍管理的透明度和效率,为学生提供了更加便捷和舒适的生活环境。三,系统展示学生角色功能四,核心代码展示#coding:utf-8__author__="ila"importlogging,os,xlrdfromflaskimportrequest,jsonify,sessionfromsqlalchemy.sqlimportfunc,and_,or_fromapi.models.brush_modelimport*from.importmain_bpfromutils.codesimport*fromutils.jwt_authimportAuthfromconfigsimportconfigsfromutils.helperimport*importrandomimportsmtplibfromemail.mime.textimportMIMETextfromemail.headerimportHeader#注册接口@main_bp.route("/python90kns/fangkedengji/register",methods=['POST'])defpython90kns_fangkedengji_register():ifrequest.method=='POST':msg={'code':normal_code,'message':'success','data':[{}]}req_dict=session.get("req_dict")error=fangkedengji.createbyreq(fangkedengji,fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']="注册用户已存在"returnjsonify(msg)#登录接口@main_bp.route("/python90kns/fangkedengji/login",methods=['GET','POST'])defpython90kns_fangkedengji_login():ifrequest.method=='GET'orrequest.method=='POST':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")req_model=session.get("req_dict")try:delreq_model['role']except:passdatas=fangkedengji.getbyparams(fangkedengji,fangkedengji,req_model)ifnotdatas:msg['code']=password_error_codemsg['msg']='密码错误或用户不存在'returnjsonify(msg)req_dict['id']=datas[0].get('id')returnAuth.authenticate(Auth,fangkedengji,req_dict)#登出接口@main_bp.route("/python90kns/fangkedengji/logout",methods=['POST'])defpython90kns_fangkedengji_logout():ifrequest.method=='POST':msg={"msg":"退出成功","code":0}req_dict=session.get("req_dict")returnjsonify(msg)#重置密码接口@main_bp.route("/python90kns/fangkedengji/resetPass",methods=['POST'])defpython90kns_fangkedengji_resetpass():''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success"}req_dict=session.get("req_dict")ifreq_dict.get('mima')!=None:req_dict['mima']='123456'error=fangkedengji.updatebyparams(fangkedengji,fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorelse:msg['msg']='密码已重置为:123456'returnjsonify(msg)#获取会话信息接口@main_bp.route("/python90kns/fangkedengji/session",methods=['GET'])defpython90kns_fangkedengji_session():''''''ifrequest.method=='GET':msg={"code":normal_code,"data":{}}req_dict={"id":session.get('params').get("id")}msg['data']=fangkedengji.getbyparams(fangkedengji,fangkedengji,req_dict)[0]returnjsonify(msg)#分类接口(后端)@main_bp.route("/python90kns/fangkedengji/page",methods=['GET'])defpython90kns_fangkedengji_page():''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict=session.get("req_dict")userinfo=session.get("params")try:__hasMessage__=fangkedengji.__hasMessage__except:__hasMessage__=Noneif__hasMessage__and__hasMessage__!="否":tablename=session.get("tablename")iftablename!="users"andsession.get("params")!=Noneandfangkedengji!='chat':req_dict["userid"]=session.get("params").get("id")tablename=session.get("tablename")iftablename=="users":try:passexcept:passelse:mapping_str_to_object={}formodelinBase_model._decl_class_registry.values():ifhasattr(model,'__tablename__'):mapping_str_to_object[model.__tablename__]=modeltry:__isAdmin__=mapping_str_to_object[tablename].__isAdmin__except:__isAdmin__=Noneif__isAdmin__!="是"andsession.get("params")!=None:req_dict["userid"]=session.get("params").get("id")else:try:delreq_dict["userid"]except:passtablename=session.get("tablename")iftablename=='xuesheng':req_dict['xueshengxuehao']=userinfo['xueshengxuehao']if'userid'inreq_dict.keys():delreq_dict["userid"]clause_args=[]or_clauses=or_(*clause_args)msg['data']['list'],msg['data']['currPage'],msg['data']['totalPage'],msg['data']['total'],\msg['data']['pageSize']=fangkedengji.page(fangkedengji,fangkedengji,req_dict,or_clauses)returnjsonify(msg)#排序接口@main_bp.route("/python90kns/fangkedengji/autoSort",methods=['GET'])defpython90kns_fangkedengji_autosort():''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict=session.get("req_dict")req_dict['sort']='clicktime'req_dict['order']='desc'try:__browseClick__=fangkedengji.__browseClick__except:__browseClick__=Noneif__browseClick__=='是':req_dict['sort']='clicknum'elif__browseClick__=='时长':req_dict['sort']='browseduration'else:req_dict['sort']='clicktime'msg['data']['list'],msg['data']['currPage'],msg['data']['totalPage'],msg['data']['total'],\msg['data']['pageSize']=fangkedengji.page(fangkedengji,fangkedengji,req_dict)returnjsonify(msg)#分页接口(前端)@main_bp.route("/python90kns/fangkedengji/list",methods=['GET'])defpython90kns_fangkedengji_list():''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}req_dict=session.get("req_dict")ifreq_dict.__contains__('vipread'):delreq_dict['vipread']userinfo=session.get("params")try:__foreEndList__=fangkedengji.__foreEndList__except:__foreEndList__=Noneif__foreEndList__and__foreEndList__!="否":tablename=session.get("tablename")iftablename!="users"andsession.get("params")!=None:req_dict['userid']=session.get("params").get("id")try:__foreEndListAuth__=fangkedengji.__foreEndListAuth__except:__foreEndListAuth__=Noneif__foreEndListAuth__and__foreEndListAuth__!="否":tablename=session.get("tablename")iftablename!="users"andsession.get("params")!=None:req_dict['userid']=session.get("params").get("id")tablename=session.get("tablename")iftablename=="users":try:delreq_dict["userid"]except:passelse:mapping_str_to_object={}formodelinBase_model._decl_class_registry.values():ifhasattr(model,'__tablename__'):mapping_str_to_object[model.__tablename__]=modeltry:__isAdmin__=mapping_str_to_object[tablename].__isAdmin__except:__isAdmin__=Noneif__isAdmin__!="是"andsession.get("params")!=None:req_dict["userid"]=session.get("params").get("id")else:try:delreq_dict["userid"]except:passif'luntan'in'fangkedengji':if'userid'inreq_dict.keys():delreq_dict["userid"]msg['data']['list'],msg['data']['currPage'],msg['data']['totalPage'],msg['data']['total'],\msg['data']['pageSize']=fangkedengji.page(fangkedengji,fangkedengji,req_dict)returnjsonify(msg)#保存接口(后端)@main_bp.route("/python90kns/fangkedengji/save",methods=['POST'])defpython90kns_fangkedengji_save():''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")forkeyinreq_dict:ifreq_dict[key]=='':req_dict[key]=Noneerror=fangkedengji.createbyreq(fangkedengji,fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#添加接口(前端)@main_bp.route("/python90kns/fangkedengji/add",methods=['POST'])defpython90kns_fangkedengji_add():''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")try:__foreEndListAuth__=fangkedengji.__foreEndListAuth__except:__foreEndListAuth__=Noneif__foreEndListAuth__and__foreEndListAuth__!="否":tablename=session.get("tablename")iftablename!="users":req_dict['userid']=session.get("params").get("id")error=fangkedengji.createbyreq(fangkedengji,fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#踩、赞接口@main_bp.route("/python90kns/fangkedengji/thumbsup/",methods=['GET'])defpython90kns_fangkedengji_thumbsup(id_):''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")id_=int(id_)type_=int(req_dict.get("type",0))rets=fangkedengji.getbyid(fangkedengji,fangkedengji,id_)update_dict={"id":id_,}iftype_==1:#赞update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1eliftype_==2:#踩update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1error=fangkedengji.updatebyparams(fangkedengji,fangkedengji,update_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#获取详情信息(后端)@main_bp.route("/python90kns/fangkedengji/info/",methods=['GET'])defpython90kns_fangkedengji_info(id_):''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}data=fangkedengji.getbyid(fangkedengji,fangkedengji,int(id_))iflen(data)>0:msg['data']=data[0]#浏览点击次数try:__browseClick__=fangkedengji.__browseClick__except:__browseClick__=Noneif__browseClick__and"clicknum"infangkedengji.__table__.columns:click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum")or0)+1)}ret=fangkedengji.updatebyparams(fangkedengji,fangkedengji,click_dict)ifret!=None:msg['code']=crud_error_codemsg['msg']=retreturnjsonify(msg)#获取详情信息(前端)@main_bp.route("/python90kns/fangkedengji/detail/",methods=['GET'])defpython90kns_fangkedengji_detail(id_):''''''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}data=fangkedengji.getbyid(fangkedengji,fangkedengji,int(id_))iflen(data)>0:msg['data']=data[0]#浏览点击次数try:__browseClick__=fangkedengji.__browseClick__except:__browseClick__=Noneif__browseClick__and"clicknum"infangkedengji.__table__.columns:click_dict={"id":int(id_),"clicknum":str(int(data[0].get("clicknum")or0)+1)}ret=fangkedengji.updatebyparams(fangkedengji,fangkedengji,click_dict)ifret!=None:msg['code']=crud_error_codemsg['msg']=retreturnjsonify(msg)#更新接口@main_bp.route("/python90kns/fangkedengji/update",methods=['POST'])defpython90kns_fangkedengji_update():''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")ifreq_dict.get("mima")and"mima"notinfangkedengji.__table__.columns:delreq_dict["mima"]ifreq_dict.get("password")and"password"notinfangkedengji.__table__.columns:delreq_dict["password"]try:delreq_dict["clicknum"]except:passerror=fangkedengji.updatebyparams(fangkedengji,fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#删除接口@main_bp.route("/python90kns/fangkedengji/delete",methods=['POST'])defpython90kns_fangkedengji_delete():''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success","data":{}}req_dict=session.get("req_dict")error=fangkedengji.delete(fangkedengji,req_dict)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#投票接口@main_bp.route("/python90kns/fangkedengji/vote/",methods=['POST'])defpython90kns_fangkedengji_vote(id_):''''''ifrequest.method=='POST':msg={"code":normal_code,"msg":"success"}data=fangkedengji.getbyid(fangkedengji,fangkedengji,int(id_))foriindata:votenum=i.get('votenum')ifvotenum!=None:params={"id":int(id_),"votenum":votenum+1}error=fangkedengji.updatebyparams(fangkedengji,fangkedengji,params)iferror!=None:msg['code']=crud_error_codemsg['msg']=errorreturnjsonify(msg)#分组统计接口@main_bp.route("/python90kns/fangkedengji/group/",methods=['GET'])defpython90kns_fangkedengji_group(columnName):'''分组统计接口'''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}msg['data']=fangkedengji.groupbycolumnname(fangkedengji,fangkedengji,columnName)returnjsonify(msg)#按值统计接口@main_bp.route("/python90kns/fangkedengji/value//",methods=['GET'])defpython90kns_fangkedengji_value(xColumnName,yColumnName):'''按值统计接口,{"code":0,"data":[{"total":10.0,"shangpinleibie":"aa"},{"total":20.0,"shangpinleibie":"bb"},{"total":15.0,"shangpinleibie":"cc"}]}'''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}msg['data']=fangkedengji.getvaluebyxycolumnname(fangkedengji,fangkedengji,xColumnName,yColumnName)returnjsonify(msg)#按日期统计接口@main_bp.route("/python90kns/fangkedengji/value///",methods=['GET'])defpython90kns_fangkedengji_value_riqi(xColumnName,yColumnName,timeStatType):'''按日期统计接口'''ifrequest.method=='GET':msg={"code":normal_code,"msg":"success","data":{}}where='where1=1'sql=''iftimeStatType=='日':sql="SELECTDATE_FORMAT({0},'%Y-%m-%d'){0},sum({1})totalFROMfangkedengji{2}GROUPBYDATE_FORMAT({0},'%Y-%m-%d')".format(xColumnName,yColumnName,where,'%Y-%m-%d')iftimeStatType=='月':sql="SELECTDATE_FORMAT({0},'%Y-%m'){0},sum({1})totalFROMfangkedengji{2}GROUPBYDATE_FORMAT({0},'%Y-%m')".format(xColumnName,yColumnName,where,'%Y-%m')iftimeStatType=='年':sql="SELECTDATE_FORMAT({0},'%Y'){0},sum({1})totalFROMfangkedengji{2}GROUPBYDATE_FORMAT({0},'%Y')".format(xColumnName,yColumnName,where,'%Y')data=db.session.execute(sql)data=data.fetchall()results=[]foriinrange(len(data)):result={xColumnName:decimalEncoder(data[i][0]),'total':decimalEncoder(data[i][1])}results.append(result)msg['data']=resultsreturnjsonify(msg)#推荐算法接口@main_bp.route("/python90kns/fangkedengji/autoSort2",methods=['GET'])defpython90kns_fangkedengji_autoSort2():ifrequest.method=='GET':leixing=set()req_dict=session.get("req_dict")userinfo=session.get("params")sql="selectinteltypefromstoreupwhereuserid="+userinfo.get("id")+"andtablename='fangkedengji'orderbyaddtimedesc"try:data=db.session.execute(sql)rows=data.fetchall()forrowinrows:foriteminrow:ifitem!=None:leixing.add(item)except:leixing=set()L=[]sql="select*fromfangkedengjiwhere$intelRecomColumnin('%s"%("','").join(leixing)+"')unionallselect*fromfangkedengjiwhere$intelRecomColumnnotin('%s"%("','").join(leixing)+"')"data=db.session.execute(sql)data_dict=[dict(zip(result.keys(),result))forresultindata.fetchall()]foronline_dictindata_dict:forkeyinonline_dict:if'datetime.datetime'instr(type(online_dict[key]))nline_dict[key]=online_dict[key].strftime("%Y-%m-%d%H:%M:%S")else:passL.append(online_dict)returnjsonify({"code":0,"msg":'',"data":{"currPage":1,"totalPage":1,"total":1,"pageSize":5,"list"[0:6]}})五,相关作品展示基于Java开发、Python开发、PHP开发、C#开发等相关语言开发的实战项目基于Nodejs、Vue等前端技术开发的前端实战项目基于微信小程序和安卓APP应用开发的相关作品基于51单片机等嵌入式物联网开发应用基于各类算法实现的AI智能应用基于大数据实现的各类数据管理和推荐系统
|
|