- R176 成绩公示表引擎(lib/publicitySheet.js + lib/assets/publicity-template.xlsx 官方模板基底) 与指导教师回填(lib/teacherBackfill.js);赛项名称/编号改为配置项 - R177 新闻「发布 ↔ 撤回」互斥:撤回只置 is_draft=1,不删除数据 - R178 C 层 RBAC:lib/adminPermissions.js(13 权限点 / 70 条路由规则,唯一 SoT) + middleware/auth.js 三段判定(默认拒绝 · is_super 单点 · token_version) + controller/service/adminUser.js + lib/auditLog.js + model/adminAuditLog.js - R178 B1 交卷冻结:service.exam.assertNotSubmitted(bizCode 4006 单一判据源) - R178 B④ 提交口径拆分:formalSubmitted / submitted / answeredCount 三字段 - R178 成绩总览补小组编号:resolveTeamLabels(与选手管理同源,含兜底与三态) - R181 生产迁移配套:admins +7 列、admin_audit_logs(scripts/migrate_r178_admin_rbac.py)
159 lines
4.4 KiB
JavaScript
159 lines
4.4 KiB
JavaScript
'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: '驳回原因',
|
||
},
|
||
// 所属单位 / 学校名称(报名表原始来源,R84 续六新增声明)
|
||
// ⚠️ 该列在运行库中**一直存在**(`SHOW COLUMNS FROM aggregation` 可见),
|
||
// 只是模型漏声明 ⇒ 任何 `attributes: ['organization_cn']` 查询都会
|
||
// 被 Sequelize 当作未知列。此处补齐仅为让模型与运行库一致,
|
||
// 声明为 allowNull:true,不改变既有写入路径的语义。
|
||
organization_cn: {
|
||
type: STRING(200),
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '所属单位/学校名称',
|
||
},
|
||
// 参赛组别(zhongzhi/gaozhi/benke/jiaoshi)—— 同为运行库既有列,模型漏声明。
|
||
// ⚠️ `group` 是 MySQL 保留字,Sequelize 会自动加反引号;手写 SQL 时须自行反引号。
|
||
group: {
|
||
type: STRING(20),
|
||
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() {
|
||
// ⚠️ R176:CompetitionInfo 的运行库结构是 key-value(主键 id),
|
||
// 不是原来的三列结构 ⇒ targetKey 必须是 `id`,否则 Sequelize 解析
|
||
// `competition_uid` 这个属性时会找不到定义。
|
||
// `aggregation.competition_uid` 存的是数字(实测恒为 1),对应 competition_info.id。
|
||
app.model.Aggregation.belongsTo(app.model.CompetitionInfo, {
|
||
foreignKey: 'competition_uid',
|
||
targetKey: 'id',
|
||
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;
|
||
};
|