计算机毕业设计-基于Python+Django的高考志愿辅助填报系统项目开发实战(附源码+论文)
摘要: 本文介绍了一个基于Python+Django的高考志愿辅助填报系统,采用MySQL数据库,分为学生端和管理员端。学生端提供注册登录、院校/专业查询、收藏、智能AI志愿推荐等功能;管理员端支持用户管理、数据维护及算法优化。系统通过E-R图设计数据库结构,并展示了核心功能界面截图,如学生注册、志愿填报及后台管理模块。附部分核心代码,包括用户注册、登录逻辑的实现,体现系统的完整性与实用性。 (字
大家好!我是职场程序猿,感谢您阅读本文,欢迎一键三连哦。
精彩专栏推荐👇🏻👇🏻👇🏻
开发环境
开发语言:Python
框架:django
Python版本:python3.8.7
数据库:mysql 5.7
数据库工具:Navicat11
开发软件:PyCharm
浏览器:谷歌浏览器
论文目录
【如需全文请按文末获取联系】
一、项目简介
本毕业设计构建的基于 Python 的高考志愿辅助填报系统,依托 Django 框架强大的 Web 开发能力与 MySQL 数据库高效的数据管理性能,为高考志愿填报流程提供了创新解决方案。系统精心设计了学生端与管理员端双模块架构:学生端功能完备,除基础的注册登录、密码修改、个人信息管理功能外,专业与院校信息模块整合海量权威数据,支持多维度检索;收藏功能方便考生标记意向信息;智能 AI 推荐模块通过深度挖掘考生的成绩数据、兴趣测评结果、职业倾向等信息,运用先进的机器学习算法,生成科学合理的个性化志愿填报方案,有效降低考生 “滑档” 风险。管理员端则具备全流程管理能力,可对学生信息、公告发布、院校与专业数据、志愿填报情况、录取信息等进行精细化管理,同时通过智能 AI 管理模块优化算法参数,确保系统推荐的准确性与稳定性。
二、系统设计
2.1软件功能模块设计
系统分为两大核心部分,学生操作部分,学生功能包括注册登录,修改密码,专业信息,院校信息,收藏信息,志愿填报,智能AI,个人信息等功能。管理员后台操作部分,管理员功能包括个人中心,学生管理,公告信息管理,院校信息管理,志愿填报管理,专业信息管理,录取信息管理,通知公告管理,智能AI管理,个人信息管理,修改密码等功能。系统结构功能图如图4-2所示。
2.2数据库设计
全局E-R图如下图4-5所示。
管理员实体如图4-6所示。
学生实体如图4-7所示。
三、系统项目部分截图
3.1学生功能实现
学生登陆注册
登录模块向学生提供了身份验证及系统访问控制的功能。在此模块中,学生首先需要输入自己的账号与密码,如果输入正确,学生将被允许登录系统;如果验证失败,系统则会向学生展示错误信息提示。
学生登录功能界面如下图5-1所示。
如果学生没有系统账号,需要先进行注册。点击注册学生按钮,根据提示输入注册信息,点击注册按钮,进行系统账号的注册。
学生注册功能界面如下图5-2所示。
院校信息查看
学生查看当前系统中的院校信息。学生可以根通过上方的搜索框快速搜索院校信息。
院校信息功能界面如下图5-4所示。
志愿填报查看
志愿填报模块允许学生查看志愿填报列表。学生可以在页面上查看志愿填报,也可以根通过上方的搜索框快速搜索对应志愿填报。
志愿填报功能界面如下图5-6所示。
3.2管理员功能实现
学生管理
学生管理模块让管理员查看和删除、修改系统的学生。管理员通过后台进入学生模块。查看当前所有学生的列表,可进行查看、编辑或删除操作。点击“移除”按钮,将学生删除。
学生管理功能界面如下图5-9所示。
志愿填报管理
志愿填报管理模块让管理员查看和删除、修改系统的志愿填报。管理员通过后台进入志愿填报管理模块。查看当前所有志愿填报的列表,可进行查看、编辑或删除操作。点击“移除”按钮,将志愿填报删除。
志愿填报功能界面如下图5-11所示。
四、部分核心代码
#coding:utf-8
import base64, copy, logging, os, sys, time, xlrd, json, datetime, configparser
from django.http import JsonResponse
from django.apps import apps
import numbers
from django.db.models.aggregates import Count,Sum
from django.db.models import Case, When, IntegerField, F
from django.forms import model_to_dict
import requests
from util.CustomJSONEncoder import CustomJsonEncoder
from .models import zhiyuantianbao
from util.codes import *
from util.auth import Auth
from util.common import Common
import util.message as mes
from django.db import connection
import random
from django.core.mail import send_mail
from django.conf import settings
from django.shortcuts import redirect
from django.db.models import Q
from util.baidubce_api import BaiDuBce
from .config_model import config
def zhiyuantianbao_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = zhiyuantianbao.createbyreq(zhiyuantianbao, zhiyuantianbao, req_dict)
if error is Exception or (type(error) is str and "Exception" in error):
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
else:
msg['data'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = zhiyuantianbao.getbyparams(zhiyuantianbao, zhiyuantianbao, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg, encoder=CustomJsonEncoder)
try:
__sfsh__= zhiyuantianbao.__sfsh__
except:
__sfsh__=None
if __sfsh__=='是':
if datas[0].get('sfsh')!='是':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg, encoder=CustomJsonEncoder)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, zhiyuantianbao, req_dict)
def zhiyuantianbao_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
columns= zhiyuantianbao.getallcolumn( zhiyuantianbao, zhiyuantianbao)
try:
__loginUserColumn__= zhiyuantianbao.__loginUserColumn__
except:
__loginUserColumn__=None
username=req_dict.get(list(req_dict.keys())[0])
if __loginUserColumn__:
username_str=__loginUserColumn__
else:
username_str=username
if 'mima' in columns:
password_str='mima'
else:
password_str='password'
init_pwd = '123456'
recordsParam = {}
recordsParam[username_str] = req_dict.get("username")
records=zhiyuantianbao.getbyparams(zhiyuantianbao, zhiyuantianbao, recordsParam)
if len(records)<1:
msg['code'] = 400
msg['msg'] = '用户不存在'
return JsonResponse(msg, encoder=CustomJsonEncoder)
eval('''zhiyuantianbao.objects.filter({}='{}').update({}='{}')'''.format(username_str,username,password_str,init_pwd))
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = zhiyuantianbao.getbyparams(zhiyuantianbao, zhiyuantianbao, req_dict)[0]
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":"是"})
data=zhiyuantianbao.getbyparams(zhiyuantianbao, zhiyuantianbao, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
global zhiyuantianbao
#当前登录用户信息
tablename = request.session.get("tablename")
from .models import xuesheng
if tablename == 'xuesheng':
req_dict['xuehao'] = request.session.get("params").get(xuesheng.__loginUserColumn__)
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =zhiyuantianbao.page(zhiyuantianbao, zhiyuantianbao, req_dict, request)
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_autoSort(request):
'''
.智能推荐功能(表属性:[intelRecom(是/否)],新增clicktime[前端不显示该字段]字段(调用info/detail接口的时候更新),按clicktime排序查询)
主要信息列表(如商品列表,新闻列表)中使用,显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao):
req_dict['sort']='clicknum'
elif "browseduration" in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao):
req_dict['sort']='browseduration'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = zhiyuantianbao.page(zhiyuantianbao,zhiyuantianbao, req_dict)
return JsonResponse(msg, encoder=CustomJsonEncoder)
#分类列表
def zhiyuantianbao_lists(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":[]}
msg['data'],_,_,_,_ = zhiyuantianbao.page(zhiyuantianbao, zhiyuantianbao, {})
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_query(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
try:
query_result = zhiyuantianbao.objects.filter(**request.session.get("req_dict")).values()
msg['data'] = query_result[0]
except Exception as e:
msg['code'] = crud_error_code
msg['msg'] = f"发生错误:{e}"
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= zhiyuantianbao.getallcolumn( zhiyuantianbao, zhiyuantianbao)
if "vipread" in req_dict and "vipread" not in columns:
del req_dict["vipread"]
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=zhiyuantianbao.__foreEndList__
except:
__foreEndList__=None
try:
__foreEndListAuth__=zhiyuantianbao.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=zhiyuantianbao.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="是" and __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and request.session.get("params") is not None:
req_dict['userid']=request.session.get("params").get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "是":
if req_dict.get("userid"):
# del req_dict["userid"]
pass
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
pass
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致],则对应的表有个隐藏属性authTable为”是”,那么该用户查看该表信息时,只能查看自己的
try:
__authTables__=zhiyuantianbao.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="是":
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
try:
del req_dict['userid']
except:
pass
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
username=params.get(authColumn)
break
if zhiyuantianbao.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
q = Q()
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = zhiyuantianbao.page(zhiyuantianbao, zhiyuantianbao, req_dict, request, q)
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if 'clicktime' in req_dict.keys():
del req_dict['clicktime']
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= zhiyuantianbao.getallcolumn( zhiyuantianbao, zhiyuantianbao)
if tablename!='users' and req_dict.get("userid")==None and 'userid' in columns and __isAdmin__!='是':
params=request.session.get("params")
req_dict['userid']=params.get('id')
if 'addtime' in req_dict.keys():
del req_dict['addtime']
idOrErr= zhiyuantianbao.createbyreq(zhiyuantianbao,zhiyuantianbao, req_dict)
if idOrErr is Exception:
msg['code'] = crud_error_code
msg['msg'] = idOrErr
else:
msg['data'] = idOrErr
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
#获取全部列名
columns= zhiyuantianbao.getallcolumn( zhiyuantianbao, zhiyuantianbao)
try:
__authSeparate__=zhiyuantianbao.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=zhiyuantianbao.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
if 'addtime' in req_dict.keys():
del req_dict['addtime']
error= zhiyuantianbao.createbyreq(zhiyuantianbao,zhiyuantianbao, req_dict)
if error is Exception:
msg['code'] = crud_error_code
msg['msg'] = error
else:
msg['data'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_thumbsup(request,id_):
'''
点赞:表属性thumbsUp[是/否],刷表新增thumbsupnum赞和crazilynum踩字段,
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=zhiyuantianbao.getbyid(zhiyuantianbao,zhiyuantianbao,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = zhiyuantianbao.updatebyparams(zhiyuantianbao,zhiyuantianbao, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = zhiyuantianbao.getbyid(zhiyuantianbao,zhiyuantianbao, int(id_))
if len(data)>0:
msg['data']=data[0]
if msg['data'].__contains__("reversetime"):
if isinstance(msg['data']['reversetime'], datetime.datetime):
msg['data']['reversetime'] = msg['data']['reversetime'].strftime("%Y-%m-%d %H:%M:%S")
else:
if msg['data']['reversetime'] != None:
reversetime = datetime.datetime.strptime(msg['data']['reversetime'], '%Y-%m-%d %H:%M:%S')
msg['data']['reversetime'] = reversetime.strftime("%Y-%m-%d %H:%M:%S")
#浏览点击次数
try:
__browseClick__= zhiyuantianbao.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum,"clicktime":datetime.datetime.now()}
ret=zhiyuantianbao.updatebyparams(zhiyuantianbao,zhiyuantianbao,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =zhiyuantianbao.getbyid(zhiyuantianbao,zhiyuantianbao, int(id_))
if len(data)>0:
msg['data']=data[0]
if msg['data'].__contains__("reversetime"):
if isinstance(msg['data']['reversetime'], datetime.datetime):
msg['data']['reversetime'] = msg['data']['reversetime'].strftime("%Y-%m-%d %H:%M:%S")
else:
if msg['data']['reversetime'] != None:
reversetime = datetime.datetime.strptime(msg['data']['reversetime'], '%Y-%m-%d %H:%M:%S')
msg['data']['reversetime'] = reversetime.strftime("%Y-%m-%d %H:%M:%S")
#浏览点击次数
try:
__browseClick__= zhiyuantianbao.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum,"clicktime":datetime.datetime.now()}
ret=zhiyuantianbao.updatebyparams(zhiyuantianbao,zhiyuantianbao,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if 'clicktime' in req_dict.keys() and req_dict['clicktime']=="None":
del req_dict['clicktime']
if req_dict.get("mima") and "mima" not in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao) :
del req_dict["mima"]
if req_dict.get("password") and "password" not in zhiyuantianbao.getallcolumn(zhiyuantianbao,zhiyuantianbao) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = zhiyuantianbao.updatebyparams(zhiyuantianbao, zhiyuantianbao, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhiyuantianbao_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=zhiyuantianbao.deletes(zhiyuantianbao,
zhiyuantianbao,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhiyuantianbao_vote(request,id_):
'''
浏览点击次数(表属性[browseClick:是/否],点击字段(clicknum),调用info/detail接口的时候后端自动+1)、投票功能(表属性[vote:是/否],投票字段(votenum),调用vote接口后端votenum+1)
统计商品或新闻的点击次数;提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= zhiyuantianbao.getbyid(zhiyuantianbao, zhiyuantianbao, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=zhiyuantianbao.updatebyparams(zhiyuantianbao,zhiyuantianbao,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def zhiyuantianbao_importExcel(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
excel_file = request.FILES.get("file", "")
if excel_file.size > 100 * 1024 * 1024: # 限制为 100MB
msg['code'] = 400
msg["msg"] = '文件大小不能超过100MB'
return JsonResponse(msg)
file_type = excel_file.name.split('.')[1]
if file_type in ['xlsx', 'xls']:
data = xlrd.open_workbook(filename=None, file_contents=excel_file.read())
table = data.sheets()[0]
rows = table.nrows
try:
for row in range(1, rows):
row_values = table.row_values(row)
req_dict = {}
zhiyuantianbao.createbyreq(zhiyuantianbao, zhiyuantianbao, req_dict)
except:
pass
else:
msg = {
"msg": "文件类型错误",
"code": 500
}
return JsonResponse(msg)
def zhiyuantianbao_autoSort2(request):
return JsonResponse({"code": 0, "msg": '', "data":{}})
def zhiyuantianbao_count(request):
'''
总数接口
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
req_dict = request.session.get("req_dict")
where = ' where 1 = 1 '
for key in req_dict:
if req_dict[key] != None:
where = where + " and key like '{0}'".format(req_dict[key])
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
sql = "SELECT count(*) AS count FROM zhiyuantianbao {0}".format(where)
count = 0
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
count = online_dict['count']
msg['data'] = count
return JsonResponse(msg, encoder=CustomJsonEncoder)
# (按值统计)时间统计类型
def zhiyuantianbao_value(request, xColumnName, yColumnName, timeStatType):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
where = " where sfsh IN ('是') "
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
sql = ''
if timeStatType == '日':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d')".format(xColumnName, yColumnName, where, '%Y-%m-%d')
if timeStatType == '月':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y-%m')".format(xColumnName, yColumnName, where, '%Y-%m')
if timeStatType == '季':
sql = "SELECT CONCAT(YEAR(MIN({0})), '-Q', QUARTER(MIN({0}))) AS {0}, SUM({1}) AS total FROM orders {2} GROUP BY YEAR({0}), QUARTER({0})".format(xColumnName, yColumnName, where)
if timeStatType == '年':
sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y')".format(xColumnName, yColumnName, where, '%Y')
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'] = L
req_dict = request.session.get("req_dict")
if "order" in req_dict:
order = req_dict["order"]
if order == "desc":
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'],reverse=True)
else:
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'])
if "limit" in req_dict and int(req_dict["limit"]) < len(L):
msg['data'] = msg['data'][:int(req_dict["limit"])]
return JsonResponse(msg, encoder=CustomJsonEncoder)
# 按值统计
def zhiyuantianbao_o_value(request, xColumnName, yColumnName):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
where = " where sfsh IN ('是') "
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
sql = "SELECT {0}, ROUND(sum({1}),2) AS total FROM zhiyuantianbao {2} GROUP BY {0}".format(xColumnName, yColumnName, where)
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'] = L
req_dict = request.session.get("req_dict")
if "order" in req_dict:
order = req_dict["order"]
if order == "desc":
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'],reverse=True)
else:
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'])
if "limit" in req_dict and int(req_dict["limit"]) < len(L):
msg['data'] = msg['data'][:int(req_dict["limit"])]
return JsonResponse(msg, encoder=CustomJsonEncoder)
# (按值统计)时间统计类型(多)
def zhiyuantianbao_valueMul(request, xColumnName, timeStatType):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": []}
req_dict = request.session.get("req_dict")
where = ' where 1 = 1 '
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
for item in req_dict['yColumnNameMul'].split(','):
sql = ''
if timeStatType == '日':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m-%d') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y-%m-%d')".format(xColumnName, item, where, '%Y-%m-%d')
if timeStatType == '月':
sql = "SELECT DATE_FORMAT({0}, '%Y-%m') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y-%m')".format(xColumnName, item, where, '%Y-%m')
if timeStatType == '季':
sql = "SELECT CONCAT(YEAR(MIN({0})), '-Q', QUARTER(MIN({0}))) {0}, sum({1}) total FROM zhiyuantianbao {2} GROUP BY YEAR({0}), QUARTER({0})".format(xColumnName, item, where)
if timeStatType == '年':
sql = "SELECT DATE_FORMAT({0}, '%Y') {0}, ROUND(sum({1}),2) total FROM zhiyuantianbao {2} GROUP BY DATE_FORMAT({0}, '%Y')".format(xColumnName, item, where, '%Y')
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'].append(L)
return JsonResponse(msg, encoder=CustomJsonEncoder)
# (按值统计(多))
def zhiyuantianbao_o_valueMul(request, xColumnName):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": []}
req_dict = request.session.get("req_dict")
where = ' where 1 = 1 '
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
for item in req_dict['yColumnNameMul'].split(','):
sql = "SELECT {0}, ROUND(sum({1}),2) AS total FROM zhiyuantianbao {2} GROUP BY {0}".format(xColumnName, item, where)
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime(
"%Y-%m-%d %H:%M:%S")
else:
pass
L.append(online_dict)
msg['data'].append(L)
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_group(request, columnName):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
where = ' where 1 = 1 '
token = request.META.get('HTTP_TOKEN')
decode_str = eval(base64.b64decode(token).decode("utf8"))
if decode_str['tablename'] == 'xuesheng':
where = where + " and xuehao ='{0}' ".format(decode_str['params']['xuehao'])
sql = "SELECT COUNT(*) AS total, " + columnName + " FROM zhiyuantianbao " + where + " GROUP BY " + columnName
L = []
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
for key in online_dict:
if 'datetime.datetime' in str(type(online_dict[key])):
online_dict[key] = online_dict[key].strftime("%Y-%m-%d")
else:
pass
L.append(online_dict)
msg['data'] = L
req_dict = request.session.get("req_dict")
if "order" in req_dict:
order = req_dict["order"]
if order == "desc":
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'],reverse=True)
else:
msg['data'] = sorted((x for x in msg['data'] if x['total'] is not None),key=lambda x: x['total'])
if "limit" in req_dict and int(req_dict["limit"]) < len(L):
msg['data'] = msg['data'][:int(req_dict["limit"])]
return JsonResponse(msg, encoder=CustomJsonEncoder)
def zhiyuantianbao_shBatch(request):
'''
批量审核
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
for id in req_dict.get("ids"):
data =zhiyuantianbao.getbyid(zhiyuantianbao,zhiyuantianbao, int(id))
if len(data)>0:
data=data[0]
data['sfsh'] = req_dict.get("sfsh")
data['shhf'] = req_dict.get("shhf")
zhiyuantianbao.updatebyparams(zhiyuantianbao, zhiyuantianbao, data)
return JsonResponse(msg)
获取源码或论文
如需对应的论文或源码,以及其他定制需求,也可以下方微信联系我。
更多推荐
所有评论(0)