1. 奖章条件优化 - 修复统计查询 SQL 语法 - 添加按类别检查奖章方法 2. 移动端适配 - 登录页、课程中心、课程详情 - 考试页面、成长路径、排行榜 3. 证书系统 - 数据库模型和迁移脚本 - 证书颁发/列表/下载/验证 API - 前端证书列表页面 4. 数据大屏 - 企业级/团队级数据 API - ECharts 可视化大屏页面
This commit is contained in:
@@ -27,6 +27,11 @@ from app.models.level import (
|
||||
BadgeCategory,
|
||||
ConditionType,
|
||||
)
|
||||
from app.models.certificate import (
|
||||
CertificateTemplate,
|
||||
UserCertificate,
|
||||
CertificateType,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
@@ -64,4 +69,7 @@ __all__ = [
|
||||
"ExpType",
|
||||
"BadgeCategory",
|
||||
"ConditionType",
|
||||
"CertificateTemplate",
|
||||
"UserCertificate",
|
||||
"CertificateType",
|
||||
]
|
||||
|
||||
76
backend/app/models/certificate.py
Normal file
76
backend/app/models/certificate.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
证书系统数据模型
|
||||
|
||||
定义证书模板和用户证书的数据结构
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey, Enum as SQLEnum, DECIMAL, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class CertificateType(str, Enum):
|
||||
"""证书类型枚举"""
|
||||
COURSE = "course" # 课程结业证书
|
||||
EXAM = "exam" # 考试合格证书
|
||||
ACHIEVEMENT = "achievement" # 成就证书
|
||||
|
||||
|
||||
class CertificateTemplate(Base):
|
||||
"""证书模板表"""
|
||||
__tablename__ = "certificate_templates"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
name = Column(String(100), nullable=False, comment="模板名称")
|
||||
type = Column(SQLEnum(CertificateType), nullable=False, comment="证书类型")
|
||||
background_url = Column(String(500), comment="证书背景图URL")
|
||||
template_html = Column(Text, comment="HTML模板内容")
|
||||
template_style = Column(Text, comment="CSS样式")
|
||||
is_active = Column(Boolean, default=True, comment="是否启用")
|
||||
sort_order = Column(Integer, default=0, comment="排序顺序")
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.now)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
|
||||
|
||||
# 关联
|
||||
certificates = relationship("UserCertificate", back_populates="template")
|
||||
|
||||
|
||||
class UserCertificate(Base):
|
||||
"""用户证书表"""
|
||||
__tablename__ = "user_certificates"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, comment="用户ID")
|
||||
template_id = Column(Integer, ForeignKey("certificate_templates.id"), nullable=False, comment="模板ID")
|
||||
certificate_no = Column(String(50), unique=True, nullable=False, comment="证书编号")
|
||||
title = Column(String(200), nullable=False, comment="证书标题")
|
||||
description = Column(Text, comment="证书描述")
|
||||
issued_at = Column(DateTime, default=datetime.now, comment="颁发时间")
|
||||
valid_until = Column(DateTime, comment="有效期至")
|
||||
|
||||
# 关联信息
|
||||
course_id = Column(Integer, comment="关联课程ID")
|
||||
exam_id = Column(Integer, comment="关联考试ID")
|
||||
badge_id = Column(Integer, comment="关联奖章ID")
|
||||
|
||||
# 成绩信息
|
||||
score = Column(DECIMAL(5, 2), comment="考试分数")
|
||||
completion_rate = Column(DECIMAL(5, 2), comment="完成率")
|
||||
|
||||
# 生成的文件
|
||||
pdf_url = Column(String(500), comment="PDF文件URL")
|
||||
image_url = Column(String(500), comment="分享图片URL")
|
||||
|
||||
# 元数据
|
||||
meta_data = Column(JSON, comment="扩展元数据")
|
||||
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.now)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now)
|
||||
|
||||
# 关联
|
||||
template = relationship("CertificateTemplate", back_populates="certificates")
|
||||
user = relationship("User", backref="certificates")
|
||||
Reference in New Issue
Block a user