feat(demo): 25 footprints w/ 10 competition awards + real drawn certificate attachments, grade data aligned to gpa formula, seed.mjs reuses demo_seed command layer
This commit is contained in:
+8
-50
@@ -1,54 +1,12 @@
|
||||
// 演示数据:仅当足迹表为空时写入,用于界面验收
|
||||
import { getDb, buildSearchText, migrateSync, uuidv7, hlcNext, DEMO_ROWS, DEMO_SEMESTERS } from './db.mjs';
|
||||
// 演示数据播种(本地开发兼容入口)
|
||||
// 与云端 demo 账号共用同一份 demo_seed 命令层逻辑(app/server/db.mjs),
|
||||
// 演示内容统一维护于 DEMO_ROWS / DEMO_SEMESTERS,竞赛/荣誉记录附带证书演示附件。
|
||||
import { handleCommand, getDb, migrateSync } from './db.mjs';
|
||||
|
||||
const db = getDb();
|
||||
const count = db.prepare('SELECT COUNT(*) AS c FROM footprint').get().c;
|
||||
if (count > 0) {
|
||||
console.log('已存在 ' + count + ' 条记录,跳过演示数据(如需重建请删除 app/.data 目录)');
|
||||
const r = handleCommand('demo_seed', {});
|
||||
if (!r.seeded) {
|
||||
console.log('已存在 ' + r.footprints + ' 条记录 / ' + r.semesters + ' 个学期,跳过演示数据(如需重建请删除 app/.data 目录)');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const types = Object.fromEntries(
|
||||
db.prepare('SELECT id, name FROM footprint_type').all().map(r => [r.name, r.id])
|
||||
);
|
||||
const dims = Object.fromEntries(
|
||||
db.prepare('SELECT id, name FROM dimension').all().map(r => [r.name, r.id])
|
||||
);
|
||||
|
||||
// [type, title, role, level, grade, organizer, start, end, status, desc, result, tags, dims, extras, metrics]
|
||||
// 数据统一维护在 ./db.mjs(DEMO_ROWS / DEMO_SEMESTERS)
|
||||
|
||||
const ins = db.prepare(`INSERT INTO footprint (type_id, title, role, level, award_grade, organizer,
|
||||
start_date, end_date, status, description, result, tags, search_text, extras, metrics)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`);
|
||||
const setDim = db.prepare('INSERT OR IGNORE INTO footprint_dimension (footprint_id, dimension_id) VALUES (?,?)');
|
||||
|
||||
for (const [t, title, role, level, grade, organizer, start, end, status, desc, result, tags, dimNames, extras, metrics] of DEMO_ROWS) {
|
||||
const search = buildSearchText(title, desc, result, tags, extras);
|
||||
const r = ins.run(types[t], title, role, level, grade, organizer, start, end, status, desc, result,
|
||||
JSON.stringify(tags), search, JSON.stringify(extras), JSON.stringify(metrics));
|
||||
const id = Number(r.lastInsertRowid);
|
||||
for (const name of dimNames) {
|
||||
if (dims[name]) setDim.run(id, dims[name]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('已写入 ' + DEMO_ROWS.length + ' 条演示记录');
|
||||
|
||||
// ---------- 学年学科成绩演示 ----------
|
||||
const semIns = db.prepare('INSERT INTO semester (term, gpa, rank, total_students, uuid, hlc, origin) VALUES (?,?,?,?,?,?,?)');
|
||||
const couIns = db.prepare('INSERT INTO course_grade (semester_id, course_name, credit, score, grade_point, uuid, hlc, origin) VALUES (?,?,?,?,?,?,?,?)');
|
||||
|
||||
|
||||
|
||||
for (const s of DEMO_SEMESTERS) {
|
||||
const h1 = hlcNext(db);
|
||||
const sid = Number(semIns.run(s.term, s.gpa, s.rank, s.total, uuidv7(), h1, 'seed').lastInsertRowid);
|
||||
for (const [name, credit, score, gp] of s.courses) {
|
||||
couIns.run(sid, name, credit, score, gp, uuidv7(), hlcNext(db), 'seed');
|
||||
}
|
||||
}
|
||||
console.log('已写入 ' + DEMO_SEMESTERS.length + ' 个学期、' + DEMO_SEMESTERS.reduce((a, s) => a + s.courses.length, 0) + ' 门课程成绩');
|
||||
|
||||
migrateSync(getDb());
|
||||
console.log('同步元数据(uuid/hlc/origin)已回填');
|
||||
console.log('演示数据已写入:足迹 ' + r.footprints + ' 条、学期成绩 ' + r.semesters + ' 个(竞赛/荣誉记录附带证书演示附件)');
|
||||
|
||||
Reference in New Issue
Block a user