This commit is contained in:
superlishunqin 2025-06-12 00:38:27 +08:00
parent fe2d7fb3a2
commit 3e6c8d353c
22 changed files with 55 additions and 35 deletions

View File

@ -458,6 +458,7 @@ def statistics():
"""统计报表""" """统计报表"""
from sqlalchemy import desc, func, case, or_, and_ from sqlalchemy import desc, func, case, or_, and_
from datetime import datetime, timedelta from datetime import datetime, timedelta
from collections import OrderedDict
# 获取筛选参数 # 获取筛选参数
search = request.args.get('search', '').strip() search = request.args.get('search', '').strip()
@ -537,26 +538,33 @@ def statistics():
# 获取学生统计数据 # 获取学生统计数据
students_stats = base_query.all() students_stats = base_query.all()
# 年级映射函数 # 年级映射函数和排序权重
def get_grade_label(grade, degree_type): def get_grade_info(grade, degree_type):
"""返回年级标签和排序权重"""
if degree_type in ['学博', '专博']: if degree_type in ['学博', '专博']:
return f'博士{grade}年级' # 博士权重为0-99年级越高权重越小优先显示
label = f'博士{grade}年级'
sort_weight = 10 - grade # 博士4年级权重6博士3年级权重7以此类推
else: else:
# 硕士权重为100-199年级越高权重越小
if grade == 1: if grade == 1:
return '研一' label = '研一'
elif grade == 2: elif grade == 2:
return '研二' label = '研二'
elif grade == 3: elif grade == 3:
return '研三' label = '研三'
else: else:
return f'{grade}' label = f'{grade}'
sort_weight = 110 - grade # 研三权重107研二权重108研一权重109
# 处理学生数据并按年级分组 return label, sort_weight
grade_groups = {}
# 处理学生数据并收集到临时字典
temp_grade_groups = {}
all_students_data = [] all_students_data = []
for stat in students_stats: for stat in students_stats:
grade_label = get_grade_label(stat.grade, stat.degree_type) grade_label, sort_weight = get_grade_info(stat.grade, stat.degree_type)
student_data = { student_data = {
'student_number': stat.student_number, 'student_number': stat.student_number,
@ -579,13 +587,24 @@ def statistics():
all_students_data.append(student_data) all_students_data.append(student_data)
if grade_label not in grade_groups: if grade_label not in temp_grade_groups:
grade_groups[grade_label] = [] temp_grade_groups[grade_label] = {
grade_groups[grade_label].append(student_data) 'students': [],
'sort_weight': sort_weight
}
temp_grade_groups[grade_label]['students'].append(student_data)
# 按出勤时长排序每个年级的学生 # 按出勤时长排序每个年级的学生
for grade in grade_groups: for grade in temp_grade_groups:
grade_groups[grade].sort(key=lambda x: x['total_work_hours'], reverse=True) temp_grade_groups[grade]['students'].sort(key=lambda x: x['total_work_hours'], reverse=True)
# 🔥 按排序权重重新排序年级组,生成有序字典
sorted_grade_items = sorted(temp_grade_groups.items(), key=lambda x: x[1]['sort_weight'])
# 创建最终的有序年级组字典
grade_groups = OrderedDict()
for grade_label, grade_data in sorted_grade_items:
grade_groups[grade_label] = grade_data['students']
# 总体统计 # 总体统计
overall_stats = { overall_stats = {
@ -690,6 +709,7 @@ def statistics():
print("=== 调试信息 ===") print("=== 调试信息 ===")
print(f"月度统计数据: {monthly_stats}") print(f"月度统计数据: {monthly_stats}")
print(f"学院统计数据: {college_stats}") print(f"学院统计数据: {college_stats}")
print(f"年级组排序: {list(grade_groups.keys())}")
print("===============") print("===============")
return render_template('admin/statistics.html', return render_template('admin/statistics.html',

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}添加学生 - CHM考勤管理系统{% endblock %} {% block title %}添加学生 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}考勤详情 - CHM考勤管理系统{% endblock %} {% block title %}考勤详情 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}考勤管理 - CHM考勤管理系统{% endblock %} {% block title %}考勤管理 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}管理员控制台 - CHM考勤管理系统{% endblock %} {% block title %}管理员控制台 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}编辑学生 - {{ student.name }} - CHM考勤管理系统{% endblock %} {% block title %}编辑学生 - {{ student.name }} - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}统计报表 - CHM考勤管理系统{% endblock %} {% block title %}统计报表 - SmartDSP考勤管理系统{% endblock %}
{% block extra_css %} {% block extra_css %}
<style> <style>

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}学生详情 - {{ student.name }} - CHM考勤管理系统{% endblock %} {% block title %}学生详情 - {{ student.name }} - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}学生管理 - CHM考勤管理系统{% endblock %} {% block title %}学生管理 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}上传考勤数据 - CHM考勤管理系统{% endblock %} {% block title %}上传考勤数据 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container mt-4"> <div class="container mt-4">

View File

@ -1,6 +1,6 @@
{% extends "layout/base.html" %} {% extends "layout/base.html" %}
{% block title %}个人信息 - CHM考勤管理系统{% endblock %} {% block title %}个人信息 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid py-4"> <div class="container-fluid py-4">

View File

@ -1,6 +1,6 @@
{% extends "layout/base.html" %} {% extends "layout/base.html" %}
{% block title %}修改密码 - CHM考勤管理系统{% endblock %} {% block title %}修改密码 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid py-4"> <div class="container-fluid py-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}登录 - CHM考勤管理系统{% endblock %} {% block title %}登录 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="min-vh-100 d-flex align-items-center bg-light"> <div class="min-vh-100 d-flex align-items-center bg-light">
@ -14,7 +14,7 @@
<div class="mb-3"> <div class="mb-3">
<i class="fas fa-clock fa-4x text-primary"></i> <i class="fas fa-clock fa-4x text-primary"></i>
</div> </div>
<h2 class="fw-bold mb-2">CHM考勤系统</h2> <h2 class="fw-bold mb-2">SmartDSP考勤系统</h2>
<p class="text-muted">请使用学号和密码登录</p> <p class="text-muted">请使用学号和密码登录</p>
</div> </div>

View File

@ -1,6 +1,6 @@
{% extends "layout/base.html" %} {% extends "layout/base.html" %}
{% block title %}个人信息 - CHM考勤管理系统{% endblock %} {% block title %}个人信息 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid py-4"> <div class="container-fluid py-4">

View File

@ -45,7 +45,7 @@
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<footer class="bg-light text-center py-3 mt-auto"> <footer class="bg-light text-center py-3 mt-auto">
<div class="container"> <div class="container">
<span class="text-muted">&copy; 2025 CHM考勤管理系统. All rights reserved.</span> <span class="text-muted">&copy; 2025 SmartDSP考勤管理系统. All rights reserved.</span>
</div> </div>
</footer> </footer>
{% endif %} {% endif %}

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}我的考勤 - CHM考勤管理系统{% endblock %} {% block title %}我的考勤 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}考勤详情 - CHM考勤管理系统{% endblock %} {% block title %}考勤详情 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}学生主页 - CHM考勤管理系统{% endblock %} {% block title %}学生主页 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

View File

@ -1,6 +1,6 @@
{% extends 'layout/base.html' %} {% extends 'layout/base.html' %}
{% block title %}个人统计 - CHM考勤管理系统{% endblock %} {% block title %}个人统计 - SmartDSP考勤管理系统{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid mt-4"> <div class="container-fluid mt-4">

2
run.py
View File

@ -3,4 +3,4 @@ import os
app = create_app() app = create_app()
if __name__ == '__main__': if __name__ == '__main__':
port = int(os.environ.get('PORT', 23944)) port = int(os.environ.get('PORT', 23944))
app.run(host='0.0.0.0', port=port, debug=True) app.run(host='0.0.0.0', port=port)