Files
competition-website/app/model/account.js
qubiaobiao 079c1b31c9 R20:客观题分值口径 + 大题一位小数评分 + 页面刷新修复 + 大题导出 Word
A1/A2 客观题:
- 清理题库占位题(答案恒 A/true、分值恒 5),客观题分值硬约束为 1 分
- 新增 scripts/check_question_bank_health.py(带变异注入自检,已验证判别力)
- ci-gates.sh 由 9 步扩为 10 步,纳入题库健康门禁

B 大题评分一位小数:
- 新增 app/lib/decimal_score.js:DECIMAL(6,1) + getter 兜底,单点收口
  「DB 列 / model 声明 / dialectOptions.decimalNumbers」三处必须同时成立
- 10 个 model 的 score 字段改走该工厂
- database/migrations/025:17 列 INT → DECIMAL(6,1)(6 列题目分值保持 int)
- service/bigQuestion.js:setSubScores 用 Math.round(n*10)/10 收敛,不再抹成整数

C 页面状态刷新:
- 修复 onQuestionTypeChange 的 `bigQuestions.length === 0` 守卫(切组后旧数组仍非空
  ⇒ 永不重新拉取)
- 修复评分后只刷一半(saveBigScores / saveExamScore 各只刷一侧列表)
- 收敛为唯一刷新入口 refreshQuestionData();ensureBigData 改按「数据属于哪个组」
  判定;fetchBigQuestions/fetchBigAnswers 增加组别竞态守卫

D 大题导出 Word(单题 / 批量 / 全部):
- 新增 app/lib/docx.js:零新依赖手写 OOXML(复用已有 archiver@8),支持 p/strong/
  span/a/br/table/ul-ol 子集,具名捕获组词法解析,pPr 严格排在 runs 之前
- service.bigQuestion.exportQuestions + controller.exportBigQuestions +
  GET /api/admin/big-questions/:group/export
- 前端导出选中/全部两按钮 + 表格多选(reserve-selection)

计划外发现并修复(已在报告中披露):
- 管理端跨组写分越权:setSubScores 定位作答行时缺 group 约束,可用任意组的路径
  改写他组考生成绩(读写不对称:读取侧有 where:{group},写入侧没有)
  ⇒ 已补 group 约束,并区分「不属于本组」与「尚未抽题」两种文案
- 导出路由注册顺序:export 原注册在 :group/:id 之后(当时因后者仅 PUT/DELETE 而
  未暴露问题),已前移以消除「将来新增 GET /:group/:id 会吞掉 export」的隐患

验证(全部实测,非仅看退出码):
- ci-gates.sh 10/10 全绿;四连门禁 52/0 · 22/0 · 20/0 · 46/0
- 端到端探针 probe_d_03(导出+小数)ALL PASS;probe_e_01(切组刷新)22/22 ALL PASS
- 前端构建 VITE_EXIT=0

未 push:须先上线验证通过再单独授权。
2026-09-23 18:29:50 +08:00

166 lines
3.7 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';
/**
* 账号模型 - Account
*
* 存储参赛者账号的全部信息,包括个人资料、联系方式和密码等。
* 表名:accounts
*/
module.exports = app => {
const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize;
// 分数列统一走共享工厂(DECIMAL(6,1) + Number 兜底,见 app/lib/decimal_score.js)
const decimalScore = require('../lib/decimal_score')(app);
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: '身份证号',
},
// 登录密码(bcrypt 加盐哈希存储;兼容存量 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: decimalScore('score', '账号总分', { defaultValue: null }),
// 记录创建时间
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;
};