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*、构建/缓存产物。
This commit is contained in:
WorkBuddy
2026-08-17 12:25:42 +08:00
commit a303cf2d53
109 changed files with 25904 additions and 0 deletions

167
app/model/account.js Normal file
View File

@@ -0,0 +1,167 @@
'use strict';
/**
* 账号模型 - Account
*
* 存储参赛者账号的全部信息,包括个人资料、联系方式和密码等。
* 表名:accounts
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize;
const Account = app.model.define('account', {
// 主键,自增
uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '账号唯一标识',
},
// 角色:contestant / admin
role: {
type: STRING(20),
allowNull: false,
defaultValue: 'contestant',
comment: '账号角色',
},
// 中文姓名
name_cn: {
type: STRING(50),
allowNull: false,
comment: '中文姓名',
},
// 英文姓名
name_en: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '英文姓名',
},
// 性别:male / female
gender: {
type: STRING(10),
allowNull: true,
defaultValue: null,
comment: '性别',
},
// 手机号码
phone: {
type: STRING(20),
allowNull: true,
defaultValue: null,
comment: '手机号码',
},
// 电子邮箱
email: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '电子邮箱',
},
// 身份证号,唯一
id_number: {
type: STRING(18),
allowNull: false,
unique: true,
comment: '身份证号',
},
// 登录密码(SHA256 哈希存储)
password: {
type: STRING(100),
allowNull: false,
comment: '登录密码',
},
// 密码盐值
salt: {
type: STRING(32),
allowNull: false,
comment: '密码盐值',
},
// 职位
position: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '职位',
},
// 专业
major: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '专业',
},
// 国家
country: {
type: STRING(50),
allowNull: true,
defaultValue: null,
comment: '国家',
},
// 地区
region: {
type: STRING(50),
allowNull: true,
defaultValue: null,
comment: '地区',
},
// 机构/单位(中文)
organization_cn: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: '机构/单位(中文)',
},
// 机构/单位(英文)
organization_en: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: '机构/单位(英文)',
},
// 账号是否已激活
activated: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '账号激活状态',
},
// 总分
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: 'accounts',
timestamps: false,
underscored: true,
indexes: [
{
unique: true,
fields: ['id_number'],
},
{
fields: ['role'],
},
],
});
return Account;
};

57
app/model/admin.js Normal file
View File

@@ -0,0 +1,57 @@
'use strict';
/**
* 管理员模型 - Admin
*
* 存储后台管理员账号信息,管理员通过用户名和密码进行登录。
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Admin = app.model.define('admin', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '管理员唯一标识',
},
// 管理员用户名,唯一
username: {
type: STRING(50),
allowNull: false,
unique: true,
comment: '管理员用户名',
},
// 管理员密码(明文存储,生产环境应使用 bcrypt 加密)
password: {
type: STRING(100),
allowNull: false,
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: 'admins',
// 时间戳字段
timestamps: false,
// 下划线命名
underscored: true,
});
return Admin;
};

135
app/model/aggregation.js Normal file
View File

@@ -0,0 +1,135 @@
'use strict';
/**
* 聚合报名模型 - Aggregation
*
* 存储参赛报名聚合信息,关联竞赛、团队和账号。
* 表名:aggregation
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, ENUM, DATE } = app.Sequelize;
const Aggregation = app.model.define('aggregation', {
// 主键,自增
aggregation_uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '聚合唯一标识',
},
// 外键:竞赛 ID
competition_uid: {
type: INTEGER,
allowNull: false,
comment: '关联竞赛 ID',
},
// 外键:团队 ID(允许为空:单人参赛/未分组的选手仍可建立聚合报名,
// 以便 benke/jiaoshi 作品上传等依赖 aggregation 的流程正常工作)
team_uid: {
type: INTEGER,
allowNull: true,
comment: '关联团队 ID',
},
// 外键:账号 ID
account_uid: {
type: INTEGER,
allowNull: false,
comment: '关联账号 ID',
},
// 身份:队长/队员/指导教师
identity: {
type: STRING(20),
allowNull: false,
comment: '身份',
},
// 是否为报名负责人
is_registrant: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否为报名负责人',
},
// 报名表文件路径
registration_form: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '报名表文件路径',
},
// 盖章报名表文件路径
stamped_form: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '盖章报名表文件路径',
},
// 审核状态:pending/approved/rejected
audit_status: {
type: STRING(20),
allowNull: false,
defaultValue: 'pending',
comment: '审核状态',
},
// 驳回原因
reject_reason: {
type: STRING(500),
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: 'aggregation',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['competition_uid'],
},
{
fields: ['team_uid'],
},
{
fields: ['account_uid'],
},
{
fields: ['audit_status'],
},
],
});
// 关联定义
Aggregation.associate = function() {
app.model.Aggregation.belongsTo(app.model.CompetitionInfo, {
foreignKey: 'competition_uid',
targetKey: 'competition_uid',
as: 'competition',
});
app.model.Aggregation.belongsTo(app.model.Team, {
foreignKey: 'team_uid',
targetKey: 'team_uid',
as: 'team',
});
app.model.Aggregation.belongsTo(app.model.Account, {
foreignKey: 'account_uid',
targetKey: 'uid',
as: 'account',
});
};
return Aggregation;
};

View File

@@ -0,0 +1,115 @@
'use strict';
/**
* 本科组作品提交模型 - BenkeSubmission
*
* 存储本科组参赛选手的作品提交记录,包括文件信息和评分。
* 表名:benke_submissions
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const BenkeSubmission = app.model.define('benke_submission', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '提交记录唯一标识',
},
// 外键:关联聚合报名 ID
aggregation_uid: {
type: INTEGER,
allowNull: false,
comment: '关联聚合报名 ID',
},
// 文件类型:word(文档)/ ppt(演示文稿)
file_type: {
type: STRING(20),
allowNull: true,
defaultValue: null,
comment: '文件类型 word/ppt',
},
// 作品名称
work_name: {
type: STRING(200),
allowNull: false,
comment: '作品名称',
},
// 文件存储路径
file_path: {
type: STRING(500),
allowNull: false,
comment: '文件存储路径',
},
// 文件原始名称
file_name: {
type: STRING(200),
allowNull: false,
comment: '文件原始名称',
},
// 文件大小(字节)
file_size: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '文件大小(字节)',
},
// 文件 MD5
file_md5: {
type: STRING(32),
allowNull: true,
defaultValue: null,
comment: '文件 MD5',
},
// 上传时间
upload_time: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '上传时间',
},
// 评分
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: 'benke_submissions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['aggregation_uid'],
},
],
});
// 关联定义
BenkeSubmission.associate = function() {
app.model.BenkeSubmission.belongsTo(app.model.Aggregation, {
foreignKey: 'aggregation_uid',
targetKey: 'aggregation_uid',
as: 'aggregation',
});
};
return BenkeSubmission;
};

105
app/model/carousel.js Normal file
View File

@@ -0,0 +1,105 @@
'use strict';
/**
* 轮播图模型 - Carousel
*
* 存储首页轮播图信息,支持标题、排序和启用/禁用控制。
* 表名:carousel
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE, TEXT } = app.Sequelize;
const Carousel = app.model.define('carousel', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '轮播图唯一标识',
},
// 图片 URL 地址(可为空时前端回退渐变背景)
image_url: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '图片 URL 地址(可为空回退渐变)',
},
// 轮播图标题
title: {
type: STRING(200),
allowNull: true,
comment: '轮播图标题',
},
// 富文本正文(HTML,由 wangEditor 生成,前端 v-html 渲染)
content: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '富文本正文(HTML)',
},
// 按钮文字(为空则不显示按钮)
button_text: {
type: STRING(100),
allowNull: true,
defaultValue: null,
comment: '按钮文字(为空则不显示按钮)',
},
// 按钮链接(内部路由如 /activate,或外部 http(s):// 链接)
button_link: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '按钮链接(内部路由/外部URL)',
},
// 排序序号(越小越靠前)
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序序号',
},
// 点击跳转链接
link_url: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '点击跳转链接',
},
// 是否启用
enabled: {
type: BOOLEAN,
allowNull: false,
defaultValue: true,
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: 'carousel',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['sort_order'],
},
{
fields: ['enabled'],
},
],
});
return Carousel;
};

View File

@@ -0,0 +1,67 @@
'use strict';
/**
* 选择题模型 - ChoiceQuestion
*
* 对应 choice_questions 表,存储所有组别的选择题(单选 + 多选)。
* 通过 group 字段区分中职组(zhongzhi)和高职组(gaozhi)。
*/
module.exports = app => {
const { STRING, INTEGER, DATE, JSON: JSON_TYPE, TEXT } = app.Sequelize;
return app.model.define('ChoiceQuestion', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
group: {
type: STRING(20),
allowNull: false,
comment: '组别:zhongzhi/gaozhi',
},
question: {
type: TEXT,
allowNull: false,
comment: '题目内容',
},
options: {
type: JSON_TYPE,
allowNull: false,
comment: '选项列表 [{ key: "A", text: "..." }, ...]',
},
answer: {
type: STRING(10),
allowNull: false,
comment: '正确答案(如 A / AB / ABCD)',
},
score: {
type: INTEGER,
allowNull: false,
defaultValue: 5,
comment: '分值',
},
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序',
},
created_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '创建时间',
},
updated_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '更新时间',
},
}, {
tableName: 'choice_questions',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
});
};

View File

@@ -0,0 +1,61 @@
'use strict';
/**
* 竞赛信息模型 - CompetitionInfo
*
* 存储竞赛的基本信息,包括竞赛名称和代码。
* 表名:competition_info
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CompetitionInfo = app.model.define('competition_info', {
// 主键,自增
competition_uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '竞赛唯一标识',
},
// 竞赛名称
competition_name: {
type: STRING(200),
allowNull: false,
comment: '竞赛名称',
},
// 竞赛代码(唯一标识码)
competition_code: {
type: STRING(50),
allowNull: false,
unique: true,
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: 'competition_info',
timestamps: false,
underscored: true,
indexes: [
{
unique: true,
fields: ['competition_code'],
},
],
});
return CompetitionInfo;
};

View File

@@ -0,0 +1,93 @@
'use strict';
/**
* 比赛时间配置模型 - CompetitionTime
*
* 存储各参赛组别的比赛时间配置,包括开始时间、结束时间、提交截止时间和Word模板路径。
* 每个组别只有一条配置记录。
* 表名:competition_times
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CompetitionTime = app.model.define('competition_time', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '时间配置唯一标识',
},
// 组别:zhongzhi/gaozhi/benke/jiaoshi,唯一约束
group: {
type: STRING(20),
allowNull: false,
unique: true,
comment: '组别',
},
// 比赛开始时间
start_time: {
type: DATE,
allowNull: true,
defaultValue: null,
comment: '比赛开始时间',
},
// 比赛结束时间
end_time: {
type: DATE,
allowNull: true,
defaultValue: null,
comment: '比赛结束时间',
},
// 作品提交截止时间
deadline: {
type: DATE,
allowNull: true,
defaultValue: null,
comment: '作品提交截止时间',
},
// Word 操作题模板文件路径(相对于 app/public/ 的相对路径)
word_template: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: 'Word 操作题模板文件路径',
},
// 客观题(选择题)抽取数量:考试时从该组别题库随机抽取的数量上限;
// 若题库实际数量不足,则自动按实际数量封顶(题目序号自适应题目数量)。
choice_count: {
type: INTEGER,
allowNull: false,
defaultValue: 50,
comment: '选择题抽取数量',
},
// 客观题(判断题)抽取数量,语义同 choice_count
judge_count: {
type: INTEGER,
allowNull: false,
defaultValue: 20,
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: 'competition_times',
timestamps: false,
underscored: true,
});
return CompetitionTime;
};

161
app/model/contestant.js Normal file
View File

@@ -0,0 +1,161 @@
'use strict';
/**
* 选手模型 - Contestant
*
* 存储参赛选手的基本信息,包括身份认证、组别、成绩等。
* 选手通过身份证号和密码进行登录认证。
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize;
const Contestant = app.model.define('contestant', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '选手唯一标识',
},
// 身份证号,唯一,长度 18,用于选手登录
id_number: {
type: STRING(18),
allowNull: false,
unique: true,
comment: '身份证号(登录账号)',
validate: {
len: [18, 18], // 严格校验 18 位身份证号
},
},
// 选手姓名
name: {
type: STRING(50),
allowNull: false,
comment: '选手姓名',
},
// 手机号码
phone: {
type: STRING(20),
allowNull: false,
comment: '手机号码',
},
// 参赛组别:zhongzhi(中职) / gaozhi(高职) / benke(本科) / jiaoshi(教师)
group: {
type: STRING(20),
allowNull: false,
comment: '参赛组别',
validate: {
isIn: [['zhongzhi', 'gaozhi', 'benke', 'jiaoshi']],
},
},
// 登录密码(存储明文,生产环境应使用 bcrypt 加密存储)
password: {
type: STRING(100),
allowNull: false,
defaultValue: '',
comment: '登录密码',
},
// 账号是否已激活(激活后才可以登录)
activated: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '账号激活状态',
},
// 总分(管理员打分后更新,NULL 表示尚未评分)
score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '选手总分(exam_score + word_score)',
},
// 卷面分(选择题+判断题自动计算)
exam_score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '卷面考试成绩',
},
// Word题分数(管理员手动打分)
word_score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: 'Word题得分',
},
// PPT分数(本科/教师组管理员手动打分)
ppt_score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: 'PPT得分(本科/教师组)',
},
// 所属团队 ID(外键关联 teams 表)
team_id: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '所属团队ID',
},
// 测试数据标记:0=生产数据,1=测试数据(重置时仅重置测试数据)
test_flag: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '测试数据标记:0=生产数据,1=测试数据',
},
// 记录创建时间
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: '更新时间',
},
}, {
// 表名保持为 contestants(原样,不做复数变换)
tableName: 'contestants',
// 不自动生成 createdAt / updatedAt(我们手动定义 created_at / updated_at)
timestamps: false,
// 下划线命名
underscored: true,
// 索引
indexes: [
{
unique: true,
fields: ['id_number'],
},
{
fields: ['group'],
},
{
fields: ['team_id'],
},
],
});
Contestant.associate = () => {
app.model.Contestant.belongsTo(app.model.Team, {
foreignKey: 'team_id',
targetKey: 'team_uid',
as: 'team',
});
app.model.Contestant.hasMany(app.model.ExamSubmission, {
foreignKey: 'contestant_id',
as: 'examSubmissions',
});
app.model.Contestant.hasMany(app.model.WorkSubmission, {
foreignKey: 'contestant_id',
as: 'workSubmissions',
});
};
return Contestant;
};

84
app/model/examQuestion.js Normal file
View File

@@ -0,0 +1,84 @@
'use strict';
/**
* 试卷题目模型 - ExamQuestion
*
* 存储各参赛组别的试卷题目,按组别区分,支持排序。
* 表名:exam_questions
*/
module.exports = app => {
const { STRING, TEXT, INTEGER, DATE } = app.Sequelize;
const ExamQuestion = app.model.define('exam_question', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '题目唯一标识',
},
// 所属组别:zhongzhi/gaozhi/benke/jiaoshi
group: {
type: STRING(20),
allowNull: false,
comment: '题目所属组别',
validate: {
isIn: [['zhongzhi', 'gaozhi', 'benke', 'jiaoshi']],
},
},
// 题目标题
title: {
type: STRING(200),
allowNull: false,
comment: '题目标题',
},
// 题目详细内容/描述
content: {
type: TEXT,
allowNull: false,
comment: '题目内容描述',
},
// 题目分值
score: {
type: INTEGER,
allowNull: false,
comment: '题目分值',
},
// 排序序号(决定题目在试卷中的展示顺序)
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
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_questions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['group'],
},
{
fields: ['group', 'sort_order'],
},
],
});
return ExamQuestion;
};

110
app/model/examSubmission.js Normal file
View File

@@ -0,0 +1,110 @@
'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;
};

View File

@@ -0,0 +1,89 @@
'use strict';
/**
* 高职组题库模型 - GaozhiQuestion
*
* 存储高职组比赛题目,支持单选、多选、判断等多种题型。
* 表名:gaozhi_questions
*/
module.exports = app => {
const { STRING, INTEGER, JSON, DATE } = app.Sequelize;
const GaozhiQuestion = app.model.define('gaozhi_question', {
// 主键,自增
question_uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '题目唯一标识',
},
// 题目内容
question: {
type: STRING(1000),
allowNull: false,
comment: '题目内容',
},
// 正确答案
answer: {
type: STRING(500),
allowNull: false,
comment: '正确答案',
},
// 题目类型:single(单选) / multiple(多选) / judge(判断)
question_type: {
type: STRING(20),
allowNull: false,
comment: '题目类型',
},
// 选项(JSON 格式)
options: {
type: JSON,
allowNull: true,
defaultValue: null,
comment: '选项',
},
// 题目分值
score: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '题目分值',
},
// 排序序号
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
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: 'gaozhi_questions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['question_type'],
},
{
fields: ['sort_order'],
},
],
});
return GaozhiQuestion;
};

View File

@@ -0,0 +1,133 @@
'use strict';
/**
* 高职组答题记录模型 - GaozhiSubmission
*
* 存储高职组参赛选手的答题记录,包括答题数据、判分和Word文件上传。
* 表名:gaozhi_submissions
*/
module.exports = app => {
const { STRING, INTEGER, TEXT, BOOLEAN, DATE } = app.Sequelize;
const GaozhiSubmission = app.model.define('gaozhi_submission', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '提交记录唯一标识',
},
// 外键:关联聚合报名 ID
aggregation_uid: {
type: INTEGER,
allowNull: false,
comment: '关联聚合报名 ID',
},
// 外键:关联题目 ID
question_uid: {
type: INTEGER,
allowNull: false,
comment: '关联题目 ID',
},
// 题型(choice / judge):与 question_uid 联合唯一标识一道题。
// 选择题与判断题的 id 在不同表中可能数值重叠(如 choice#5 与 judge#5),
// 仅凭 question_uid 无法区分,必须结合 question_type 存储,否则会折叠丢失答案(见 B11)。
question_type: {
type: STRING(16),
allowNull: false,
defaultValue: '',
comment: '题型:choice/judge,与 question_uid 联合区分题目',
},
// 答题数据(选手提交的答案)
answer_data: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '答题数据',
},
// 是否判为正确
is_correct: {
type: BOOLEAN,
allowNull: true,
defaultValue: null,
comment: '是否判为正确',
},
// 得分
score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '得分',
},
// Word 文件存储路径
word_file_path: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: 'Word 文件存储路径',
},
// Word 文件原始名称
word_file_name: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: 'Word 文件原始名称',
},
// Word 文件 MD5
word_file_md5: {
type: STRING(32),
allowNull: true,
defaultValue: null,
comment: 'Word 文件 MD5',
},
// 记录创建时间
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: 'gaozhi_submissions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['aggregation_uid'],
},
{
fields: ['question_uid'],
},
{
// 唯一约束:同一选手同一题(题型+题号)只保留一行,杜绝并发作答重复落库(B12)。
unique: true,
name: 'uk_gaozhi_submission',
fields: ['aggregation_uid', 'question_uid', 'question_type'],
},
],
});
// 关联定义
GaozhiSubmission.associate = function() {
app.model.GaozhiSubmission.belongsTo(app.model.Aggregation, {
foreignKey: 'aggregation_uid',
targetKey: 'aggregation_uid',
as: 'aggregation',
});
app.model.GaozhiSubmission.belongsTo(app.model.GaozhiQuestion, {
foreignKey: 'question_uid',
targetKey: 'question_uid',
as: 'gaozhiQuestion',
});
};
return GaozhiSubmission;
};

View File

@@ -0,0 +1,115 @@
'use strict';
/**
* 教师组作品提交模型 - JiaoshiSubmission
*
* 存储教师组参赛选手的作品提交记录,包括文件信息和评分。
* 表名:jiaoshi_submissions
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const JiaoshiSubmission = app.model.define('jiaoshi_submission', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '提交记录唯一标识',
},
// 外键:关联聚合报名 ID
aggregation_uid: {
type: INTEGER,
allowNull: false,
comment: '关联聚合报名 ID',
},
// 文件类型:word(文档)/ ppt(演示文稿)
file_type: {
type: STRING(20),
allowNull: true,
defaultValue: null,
comment: '文件类型 word/ppt',
},
// 作品名称
work_name: {
type: STRING(200),
allowNull: false,
comment: '作品名称',
},
// 文件存储路径
file_path: {
type: STRING(500),
allowNull: false,
comment: '文件存储路径',
},
// 文件原始名称
file_name: {
type: STRING(200),
allowNull: false,
comment: '文件原始名称',
},
// 文件大小(字节)
file_size: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '文件大小(字节)',
},
// 文件 MD5
file_md5: {
type: STRING(32),
allowNull: true,
defaultValue: null,
comment: '文件 MD5',
},
// 上传时间
upload_time: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '上传时间',
},
// 评分
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: 'jiaoshi_submissions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['aggregation_uid'],
},
],
});
// 关联定义
JiaoshiSubmission.associate = function() {
app.model.JiaoshiSubmission.belongsTo(app.model.Aggregation, {
foreignKey: 'aggregation_uid',
targetKey: 'aggregation_uid',
as: 'aggregation',
});
};
return JiaoshiSubmission;
};

View File

@@ -0,0 +1,62 @@
'use strict';
/**
* 判断题模型 - JudgeQuestion
*
* 对应 judge_questions 表,存储所有组别的判断题。
* 通过 group 字段区分中职组(zhongzhi)和高职组(gaozhi)。
*/
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;
return app.model.define('JudgeQuestion', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
group: {
type: STRING(20),
allowNull: false,
comment: '组别:zhongzhi/gaozhi',
},
question: {
type: TEXT,
allowNull: false,
comment: '题目内容',
},
answer: {
type: STRING(10),
allowNull: false,
comment: '正确答案:true 或 false',
},
score: {
type: INTEGER,
allowNull: false,
defaultValue: 5,
comment: '分值',
},
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序',
},
created_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '创建时间',
},
updated_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '更新时间',
},
}, {
tableName: 'judge_questions',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
});
};

117
app/model/news.js Normal file
View File

@@ -0,0 +1,117 @@
'use strict';
/**
* 新闻模型 - News
*
* 存储新闻通知信息,支持置顶、微信公众号链接和按组别过滤显示。
* 表名:news
*/
module.exports = app => {
const { STRING, TEXT, BOOLEAN, DATE, INTEGER } = app.Sequelize;
const News = app.model.define('news', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '新闻唯一标识',
},
// 新闻标题
title: {
type: STRING(200),
allowNull: false,
comment: '新闻标题',
},
// 新闻正文内容(支持 HTML)
content: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '新闻正文(微信链接型新闻可为空)',
},
// 微信公众号文章链接
wx_link: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: '微信公众号文章链接',
},
// 新闻类型:content(内容型)/ wx_link(微信链接型)
news_type: {
type: STRING(20),
allowNull: false,
defaultValue: 'content',
comment: '新闻类型:content=内容型, wx_link=微信链接型',
},
// 发布时间
publish_time: {
type: DATE,
allowNull: false,
comment: '发布时间',
},
// 是否置顶
pinned: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否置顶',
},
// 排序序号
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序序号,越小越靠前',
},
// 目标可见组别
group: {
type: STRING(20),
allowNull: false,
defaultValue: 'all',
comment: '目标可见组别',
},
// 标签(逗号分隔)
tags: {
type: STRING(500),
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: 'news',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['publish_time'],
},
{
fields: ['pinned', 'publish_time'],
},
{
fields: ['group'],
},
{
fields: ['sort_order'],
},
],
});
return News;
};

55
app/model/systemConfig.js Normal file
View File

@@ -0,0 +1,55 @@
'use strict';
/**
* 系统配置模型 - SystemConfig
*
* 存储系统级别的配置项,以键值对形式存储。
* 表名:system_configs
*/
module.exports = app => {
const { STRING, TEXT, INTEGER, DATE } = app.Sequelize;
const SystemConfig = app.model.define('system_config', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '配置唯一标识',
},
// 配置键名,唯一
config_key: {
type: STRING(100),
allowNull: false,
unique: true,
comment: '配置键名',
},
// 配置值(文本存储,可存储 JSON 字符串)
config_value: {
type: TEXT,
allowNull: false,
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: 'system_configs',
timestamps: false,
underscored: true,
});
return SystemConfig;
};

78
app/model/team.js Normal file
View File

@@ -0,0 +1,78 @@
'use strict';
/**
* 参赛团队模型 - Team
*
* 存储参赛团队的基本信息,包括组别和团队编号等。
* 表名:teams
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Team = app.model.define('team', {
// 主键(业务唯一标识),由应用层显式赋值,不依赖数据库自增。
// 说明:运行库中 teams 表真实自增主键为 id,team_uid 仅是普通 INT 列(非自增)。
// 此处声明 autoIncrement:false,使模型与运行库一致——create 时必须显式传入 team_uid,
// 避免 Sequelize 误以为 DB 会生成 team_uid 而省去该列(旧 bug:写入 NULL 导致 G1 团队锁失效)。
team_uid: {
type: INTEGER,
primaryKey: true,
comment: '团队唯一标识(由应用层显式生成,非 DB 自增)',
},
// 组别名称:zhongzhi/gaozhi/benke/jiaoshi
group_name: {
type: STRING(20),
allowNull: false,
comment: '参赛组别',
},
// 团队 ID(外部编号)
team_id: {
type: STRING(50),
allowNull: false,
comment: '团队编号',
},
// 团队序号(人类可读队伍编号,如 BRICS2026-ST-027-91001,含字母与连字符,必须为字符串)
team_number: {
type: STRING(50),
allowNull: true,
defaultValue: null,
comment: '团队序号(人类可读队伍编号,如 BRICS2026-ST-027-91001)',
},
// 团队地址/地区
address: {
type: STRING(200),
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: 'teams',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['group_name'],
},
{
fields: ['team_id'],
},
],
});
return Team;
};

67
app/model/wordQuestion.js Normal file
View File

@@ -0,0 +1,67 @@
'use strict';
/**
* Word操作题模型 - WordQuestion
*
* 对应 word_questions 表,存储所有组别的 Word 操作题。
* 通过 group 字段区分中职组(zhongzhi)和高职组(gaozhi)。
*/
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;
return app.model.define('WordQuestion', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
group: {
type: STRING(20),
allowNull: false,
comment: '组别:zhongzhi/gaozhi',
},
title: {
type: STRING(200),
allowNull: false,
comment: '题目标题',
},
description: {
type: TEXT,
allowNull: true,
comment: '题目描述/操作要求',
},
score: {
type: INTEGER,
allowNull: false,
defaultValue: 30,
comment: '分值',
},
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '排序',
},
template_path: {
type: STRING(500),
allowNull: true,
comment: 'Word 模板文件路径',
},
created_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '创建时间',
},
updated_at: {
type: DATE,
defaultValue: app.Sequelize.NOW,
comment: '更新时间',
},
}, {
tableName: 'word_questions',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
});
};

109
app/model/workSubmission.js Normal file
View File

@@ -0,0 +1,109 @@
'use strict';
/**
* 作品提交模型 - WorkSubmission
*
* 存储选手上传的作品文件信息,包括文件类型、名称、路径等。
* 支持 plan(计划书)和 ppt(演示文稿)两种文件类型。
* 表名:work_submissions
*/
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const WorkSubmission = app.model.define('work_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',
},
},
// 文件类型:plan(计划书)/ ppt(演示文稿)
file_type: {
type: STRING(20),
allowNull: false,
comment: '文件类型',
validate: {
isIn: [['plan', 'ppt']],
},
},
// 文件名(原始文件名)
file_name: {
type: STRING(200),
allowNull: false,
comment: '原始文件名',
},
// 文件存储路径(服务器上的相对路径)
file_path: {
type: STRING(500),
allowNull: false,
comment: '文件存储路径',
},
// 文件大小(字节)
file_size: {
type: INTEGER,
allowNull: false,
comment: '文件大小(字节)',
},
// 提交时间
submit_time: {
type: DATE,
allowNull: false,
comment: '提交时间',
},
// 得分(管理员评分后更新,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: 'work_submissions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['contestant_id'],
},
{
fields: ['file_type'],
},
],
});
// 关联关系:一条作品提交记录属于一名选手
WorkSubmission.associate = () => {
app.model.WorkSubmission.belongsTo(app.model.Contestant, {
foreignKey: 'contestant_id',
as: 'contestant',
});
};
return WorkSubmission;
};

View File

@@ -0,0 +1,89 @@
'use strict';
/**
* 中职组题库模型 - ZhongzhiQuestion
*
* 存储中职组比赛题目,支持单选、多选、判断等多种题型。
* 表名:zhongzhi_questions
*/
module.exports = app => {
const { STRING, INTEGER, JSON, DATE } = app.Sequelize;
const ZhongzhiQuestion = app.model.define('zhongzhi_question', {
// 主键,自增
question_uid: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '题目唯一标识',
},
// 题目内容
question: {
type: STRING(1000),
allowNull: false,
comment: '题目内容',
},
// 正确答案
answer: {
type: STRING(500),
allowNull: false,
comment: '正确答案',
},
// 题目类型:single(单选) / multiple(多选) / judge(判断)
question_type: {
type: STRING(20),
allowNull: false,
comment: '题目类型',
},
// 选项(JSON 格式,如 ["A. xxx", "B. xxx", "C. xxx", "D. xxx"])
options: {
type: JSON,
allowNull: true,
defaultValue: null,
comment: '选项',
},
// 题目分值
score: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '题目分值',
},
// 排序序号
sort_order: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
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: 'zhongzhi_questions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['question_type'],
},
{
fields: ['sort_order'],
},
],
});
return ZhongzhiQuestion;
};

View File

@@ -0,0 +1,133 @@
'use strict';
/**
* 中职组答题记录模型 - ZhongzhiSubmission
*
* 存储中职组参赛选手的答题记录,包括答题数据、判分和Word文件上传。
* 表名:zhongzhi_submissions
*/
module.exports = app => {
const { STRING, INTEGER, TEXT, BOOLEAN, DATE } = app.Sequelize;
const ZhongzhiSubmission = app.model.define('zhongzhi_submission', {
// 主键 ID,自增
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '提交记录唯一标识',
},
// 外键:关联聚合报名 ID
aggregation_uid: {
type: INTEGER,
allowNull: false,
comment: '关联聚合报名 ID',
},
// 外键:关联题目 ID
question_uid: {
type: INTEGER,
allowNull: false,
comment: '关联题目 ID',
},
// 题型(choice / judge):与 question_uid 联合唯一标识一道题。
// 选择题与判断题的 id 在不同表中可能数值重叠(如 choice#5 与 judge#5),
// 仅凭 question_uid 无法区分,必须结合 question_type 存储,否则会折叠丢失答案(见 B11)。
question_type: {
type: STRING(16),
allowNull: false,
defaultValue: '',
comment: '题型:choice/judge,与 question_uid 联合区分题目',
},
// 答题数据(选手提交的答案)
answer_data: {
type: TEXT,
allowNull: true,
defaultValue: null,
comment: '答题数据',
},
// 是否判为正确
is_correct: {
type: BOOLEAN,
allowNull: true,
defaultValue: null,
comment: '是否判为正确',
},
// 得分
score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '得分',
},
// Word 文件存储路径
word_file_path: {
type: STRING(500),
allowNull: true,
defaultValue: null,
comment: 'Word 文件存储路径',
},
// Word 文件原始名称
word_file_name: {
type: STRING(200),
allowNull: true,
defaultValue: null,
comment: 'Word 文件原始名称',
},
// Word 文件 MD5
word_file_md5: {
type: STRING(32),
allowNull: true,
defaultValue: null,
comment: 'Word 文件 MD5',
},
// 记录创建时间
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: 'zhongzhi_submissions',
timestamps: false,
underscored: true,
indexes: [
{
fields: ['aggregation_uid'],
},
{
fields: ['question_uid'],
},
{
// 唯一约束:同一选手同一题(题型+题号)只保留一行,杜绝并发作答重复落库(B12)。
unique: true,
name: 'uk_zhongzhi_submission',
fields: ['aggregation_uid', 'question_uid', 'question_type'],
},
],
});
// 关联定义
ZhongzhiSubmission.associate = function() {
app.model.ZhongzhiSubmission.belongsTo(app.model.Aggregation, {
foreignKey: 'aggregation_uid',
targetKey: 'aggregation_uid',
as: 'aggregation',
});
app.model.ZhongzhiSubmission.belongsTo(app.model.ZhongzhiQuestion, {
foreignKey: 'question_uid',
targetKey: 'question_uid',
as: 'zhongzhiQuestion',
});
};
return ZhongzhiSubmission;
};