Files
competition-website/app/model/examSubmission.js
WorkBuddy a303cf2d53 chore: 后端首次基线提交
运行必须源码:app/(controller/model/service/middleware/lib/utils/validate/router)、config/、database/(migrations/seeders/sql)、启动脚本、app/public/templates 模板。
已忽略运行非必须:node_modules/、logs/、run/、app/public 运行时上传数据、.env*、构建/缓存产物。
2026-08-17 12:25:42 +08:00

110 lines
3.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
/**
* 答题记录模型 - ExamSubmission
*
* 存储选手的试卷答题记录,包括答题内容、提交时间和得分。
* 每个选手在其组别的比赛中只允许提交一次。
* 表名:exam_submissions
*/
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT, JSON: JSON_TYPE } = app.Sequelize;
const ExamSubmission = app.model.define('exam_submission', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '答题记录唯一标识',
},
// 选手 ID,外键关联 contestants 表
contestant_id: {
type: INTEGER,
allowNull: false,
comment: '选手 ID',
references: {
model: 'contestants',
key: 'id',
},
},
// 答题内容(JSON 格式存储,如 [{question_id: 1, answer: "..."}, ...])
answers: {
type: JSON_TYPE,
allowNull: false,
comment: '答题内容(JSON)',
},
// 该考生固化后的题目顺序(question_uid 数组 JSON 字符串):首次进入随机生成并持久化,
// 之后重进复用,避免每次进入都 RAND() 重新打乱顺序(重进题目顺序变乱 Bug 修复)。
question_order: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '该考生固化题目顺序(question_uid JSON 数组),重进复用',
},
// Word 答案文件路径
word_file_path: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: 'Word答案文件路径',
},
// Word 答案文件名
word_file_name: {
type: STRING(255),
allowNull: true,
defaultValue: null,
comment: 'Word答案文件名',
},
// 提交时间
submit_time: {
type: DATE,
allowNull: true,
comment: '提交时间(占位/未提交为 NULL,正式提交后为具体时间)',
},
// 得分(管理员评分后更新,NULL 表示尚未评分)
score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '试卷得分',
},
// 创建时间
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
// 更新时间
updated_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}, {
tableName: 'exam_submissions',
timestamps: false,
underscored: true,
indexes: [
{
// 唯一约束:每选手仅一条答题提交记录,并发创建时折叠为一条(B12)。
unique: true,
name: 'uk_exam_submission_contestant',
fields: ['contestant_id'],
},
],
});
// 关联关系:一条答题记录属于一名选手
ExamSubmission.associate = () => {
app.model.ExamSubmission.belongsTo(app.model.Contestant, {
foreignKey: 'contestant_id',
as: 'contestant',
});
};
return ExamSubmission;
};