chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

+222
View File
@@ -0,0 +1,222 @@
/**
* 培训模块预览 harness 的接口 mock 数据与路由(仅 training-preview 本地验证用)。
* vite.training-preview.config.ts 以中间件形式拦截 /api/v1/training/*,
* 返回与后端一致的封包 { success: true, data },让培训面板无后端渲染演示数据。
*/
const NOW = new Date()
const month = (offset: number, day: number) => {
const d = new Date(NOW.getFullYear(), NOW.getMonth() + offset, day, 9, 0, 0)
return d.toISOString()
}
export const TRAINING_MOCK = {
depts: [
{ id: 'dept-a', tenant_id: 1, parent_id: '', name: '冲压车间', code: 'CY', sort: 1 },
{ id: 'dept-b', tenant_id: 1, parent_id: '', name: '技术部', code: 'JS', sort: 2 },
],
courses: [
{
id: 'c1', code: 'TR-001', name: '冲压B车间安全生产教育培训', mode: 'online', type: 'required',
lecturer_id: 'm1', hours: 0.75, credits: 1, exam_enabled: true, dept_ids: ['dept-a'],
post_scope: '全员必修', description: '', material_ids: ['mt1'], tags: ['安全'], status: 'published',
creator_id: '', created_at: month(0, 2), updated_at: month(0, 2),
},
{
id: 'c2', code: 'TR-002', name: '六轴机械手调试培训', mode: 'offline', type: 'required',
lecturer_id: 'm2', hours: 4, credits: 2, exam_enabled: false, dept_ids: ['dept-b'],
post_scope: '技术级以上', description: '', material_ids: [], tags: ['技能'], status: 'published',
creator_id: '', created_at: month(-1, 20), updated_at: month(-1, 20),
},
{
id: 'c3', code: 'TR-003', name: 'TOPGP系统培训', mode: 'online', type: 'elective',
lecturer_id: 'm1', hours: 0.5, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '', description: '', material_ids: [], tags: ['系统'], status: 'published',
creator_id: '', created_at: month(-2, 11), updated_at: month(-2, 11),
},
{
id: 'c4', code: 'TR-004', name: '产品品质培训(冲压)', mode: 'online', type: 'required',
lecturer_id: 'm1', hours: 0.67, credits: 1, exam_enabled: true, dept_ids: ['dept-a'],
post_scope: '品质岗', description: '', material_ids: ['mt2', 'mt3'], tags: ['品质'], status: 'published',
creator_id: '', created_at: month(0, 28), updated_at: month(0, 28),
},
{
id: 'c5', code: 'TR-005', name: '组装安全生产教育训练', mode: 'offline', type: 'required',
lecturer_id: 'm3', hours: 2, credits: 1, exam_enabled: false, dept_ids: ['dept-a'],
post_scope: '全员必修', description: '', material_ids: [], tags: ['安全'], status: 'published',
creator_id: '', created_at: month(0, 5), updated_at: month(0, 5),
},
{
id: 'c6', code: 'TR-006', name: '新员工入职引导', mode: 'online', type: 'required',
lecturer_id: 'm3', hours: 1, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '全员必修', description: '', material_ids: ['mt4'], tags: ['入职'], status: 'published',
creator_id: '', created_at: month(0, 30), updated_at: month(0, 30),
},
// 草稿课程:目录页仅展示已发布课程,此条应被前端过滤
{
id: 'c7', code: 'TR-007', name: '模具保养必修课(草稿)', mode: 'offline', type: 'required',
lecturer_id: 'm2', hours: 2, credits: 1, exam_enabled: false, dept_ids: [],
post_scope: '', description: '', material_ids: [], tags: [], status: 'draft',
creator_id: '', created_at: month(0, 1), updated_at: month(0, 1),
},
],
myTasks: [
{ id: 't1', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'me', deadline: month(0, 20), status: 'doing' },
{ id: 't2', course_id: 'c4', course_name: '产品品质培训(冲压)', member_id: 'me', deadline: month(0, 25), status: 'done' },
{ id: 't3', course_id: 'c6', course_name: '新员工入职引导', member_id: 'me', deadline: month(1, 10), status: 'pending' },
],
// 课程学习情况(管理端):课程+学员唯一任务行
courseLearning: [
{ id: 'cl1', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm1', employee_no: '91001', post: '培训运营工程师', dept_name: '设备部', deadline: month(0, 11), status: 'done' },
{ id: 'cl2', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm2', employee_no: '23107', post: '冲压技师', dept_name: '生产一部', deadline: month(0, 11), status: 'pending' },
{ id: 'cl3', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm3', employee_no: '24130', post: '质检员', dept_name: '品质部', deadline: month(0, 11), status: 'doing' },
{ id: 'cl4', course_id: 'c1', course_name: '冲压B车间安全生产教育培训', member_id: 'm4', employee_no: '24512', post: '装配技工', dept_name: '生产二部', deadline: month(-1, 20), status: 'overdue' },
],
members: [
{ id: 'm1', tenant_id: 1, user_id: 'u-m1', employee_no: '91001', dept_id: 'dept-a', post: '培训运营工程师', roles: ['hr'], lecturer_rate: 0, status: 'active' },
{ id: 'm2', tenant_id: 1, user_id: 'u-m2', employee_no: '23107', dept_id: 'dept-a', post: '冲压技师', roles: ['trainee'], lecturer_rate: 0, status: 'active' },
{ id: 'm3', tenant_id: 1, user_id: 'u-m3', employee_no: '24130', dept_id: 'dept-b', post: '质检员', roles: ['trainee'], lecturer_rate: 0, status: 'active' },
],
papers: [
{ id: 'p1', session_id: 's1', bank_id: 'b1', name: 'TPM_Bank(A卷)', total_score: 50, pass_score: 30, version: 'A', question_ids: [] },
],
examRecords: [
{ id: 'er1', paper_id: 'p1', session_id: 's1', member_id: 'm1', score: 45, submitted_at: month(0, 4), paper_name: 'TPM_Bank(A卷)', course_name: '冲压B车间安全生产教育培训', total_score: 50, pass_score: 30 },
{ id: 'er2', paper_id: 'p1', session_id: 's1', member_id: 'm2', score: 10, submitted_at: month(0, 4), paper_name: 'TPM_Bank(A卷)', course_name: '冲压B车间安全生产教育培训', total_score: 50, pass_score: 30 },
],
enrollments: [
{ id: 'e1', session_id: 's1', member_id: 'm1', status: 'completed', reason: '' },
{ id: 'e2', session_id: 's1', member_id: 'm2', status: 'enrolled', reason: '' },
{ id: 'e3', session_id: 's1', member_id: 'm3', status: 'enrolled', reason: '' },
],
signRecords: [
{ id: 'sr1', session_id: 's1', member_id: 'm1', signed_at: month(0, 4), channel: 'wecom_scan', distance_m: 12, status: 'normal', abnormal_flags: [], reviewed_by: '' },
{ id: 'sr2', session_id: 's1', member_id: 'm2', signed_at: month(0, 4), channel: 'wecom_scan', distance_m: 30, status: 'late', abnormal_flags: [], reviewed_by: '' },
],
wrongBook: [
{ id: 'w1', question_id: 'q1', stem: '冲压机双手启动按钮的作用是什么?', question_type: 'single', knowledge_point: '安全操作规范', wrong_count: 3, mastered: false },
{ id: 'w2', question_id: 'q2', stem: '模具安装前需确认哪些事项?', question_type: 'multiple', knowledge_point: '模具保养', wrong_count: 1, mastered: false },
],
profile: {
member_id: 'me', name: '林知夏', dept_name: '技术部', points: 3,
avg_score: 45, study_hours: 1.2, course_count: 3,
dimensions: [], competency: 10, pass_line: 75,
},
aiAnalysis: {
scope: 'course',
course_id: 'c1',
course_name: '冲压B车间安全生产教育培训',
stats: {
learning: { total: 4, done: 1, doing: 1, pending: 1, overdue: 1, completion_rate: 25 },
exam: { expected: 4, taken: 2, passed: 1, failed: 1, avg_score: 27.5, pass_rate: 50 },
sign: { expected: 3, signed: 2, late: 1, absent: 1, abnormal: 0 },
wrong_questions: [
{ knowledge_point: '安全操作规范', wrong_count: 3, error_rate: 0.5 },
{ knowledge_point: '模具保养', wrong_count: 1, error_rate: 0.33 },
],
},
analysis: [
'## 总体评价',
'',
'当前课程整体完成率 25%,明显偏低;考试及格率 50%,平均分 27.5 分,掌握情况不理想。',
'',
'## 学习情况',
'',
'- 共 4 项学习任务:已完成 1、学习中 1、待学习 1、**已逾期 1**,需优先催办逾期任务。',
'',
'## 考试情况',
'',
'- 应考 4 人,已考 2 人,及格 1 人;「安全操作规范」知识点错误率达 50%,建议集中补训。',
'',
'## 改进建议',
'',
'1. 对逾期学员逐人催办,并同步课长督办;',
'2. 组织未考学员安排补考,确保应考尽考;',
'3. 针对「安全操作规范」安排一次 30 分钟集中补训并二次考试。',
].join('\n'),
model_name: 'glm-4-plus',
generated_at: '',
},
sessions: [
{ id: 's1', course_id: 'c2', month_plan_id: '', year: NOW.getFullYear(), month: NOW.getMonth() + 1, start_at: month(1, 12), end_at: month(1, 12), location: '3号厂房 · 二楼培训室', online_url: '', capacity: 0, lecturer_id: 'm2', status: 'scheduled' },
{ id: 's2', course_id: 'c2', month_plan_id: '', year: NOW.getFullYear() - 1, month: 12, start_at: month(-2, 8), end_at: month(-2, 8), location: '技术部实训区', online_url: '', capacity: 0, lecturer_id: 'm2', status: 'finished' },
{ id: 's3', course_id: 'c5', month_plan_id: '', year: NOW.getFullYear() - 1, month: 10, start_at: month(-1, 15), end_at: month(-1, 15), location: '一楼展厅', online_url: '', capacity: 0, lecturer_id: 'm3', status: 'finished' },
],
hrDashboard: {
demand_progress: [
{ dept_id: 'dept-a', dept_name: '冲压车间', total: 8, done: 5, percent: 62 },
{ dept_id: 'dept-b', dept_name: '技术部', total: 6, done: 4, percent: 66 },
],
pending_demands: [
{ id: 'd1', course_name: '叉车年度复训', check_status: 'pending' },
{ id: 'd2', course_name: '品质工具(APQP)专题', check_status: 'passed' },
],
course_total: 12,
course_online: 8,
course_offline: 4,
month_completion: { percent: 46, completed: 12, total: 26 },
month_sessions: [{ id: 's1' }, { id: 's9' }],
},
}
// 配置中心 · 导入模板元数据(harness 固定展示内置默认;上传/删除不落库,刷新即还原)
const TEMPLATE_METAS = [
{
template_key: 'demand_collection',
file_name: '教育训练需求表模板.xlsx',
file_size: 7369,
updated_at: '',
updated_by: '',
source: 'default',
},
{
template_key: 'question_bank',
file_name: '部门培训课程试题(题库导入版)模板.xlsx',
file_size: 29405,
updated_at: '',
updated_by: '',
source: 'default',
},
]
// 返回 { matched, body };未匹配返回 null 由 vite 放行
export function resolveTrainingMock(method: string, url: string): { status: number; body: unknown } | null {
const ok = (data: unknown) => ({ status: 200, body: { success: true, data } })
if (!url.startsWith('/api/v1/training/')) return null
// 模板二进制下载由 vite 配置里的中间件直接回文件,不经过本函数
if (url === '/api/v1/training/templates' || url.endsWith('/templates')) {
if (method === 'GET') return ok(TEMPLATE_METAS)
return ok(TEMPLATE_METAS[0])
}
if (method === 'GET') {
if (url.includes('/depts')) return ok(TRAINING_MOCK.depts)
// 学习任务:/learning-tasks/all 为管理端课程学习情况,须先于 /learning-tasks 匹配
if (url.includes('/learning-tasks/all')) return ok(TRAINING_MOCK.courseLearning)
if (url.includes('/learning-tasks')) return ok(TRAINING_MOCK.myTasks)
if (url.includes('/ai-analysis')) {
return ok({ ...TRAINING_MOCK.aiAnalysis, generated_at: new Date().toISOString() })
}
// 考试:/exam-records/my-list、/exam-records/my 须先于 /exam-records 匹配
if (url.includes('/exam-records/my-list')) return ok(TRAINING_MOCK.examRecords)
if (url.includes('/exam-records/my')) return ok({ record: TRAINING_MOCK.examRecords[0], passed: true })
if (url.includes('/exam-records')) return ok(TRAINING_MOCK.examRecords)
if (url.includes('/wrong-book')) return ok(TRAINING_MOCK.wrongBook)
if (url.includes('/profile/me')) return ok(TRAINING_MOCK.profile)
if (url.includes('/enrollments')) return ok(TRAINING_MOCK.enrollments)
if (url.includes('/sign-records')) return ok(TRAINING_MOCK.signRecords)
if (url.includes('/papers')) return ok(TRAINING_MOCK.papers)
if (url.includes('/question-banks')) return ok({ items: [], total: 0 })
// 我的档案(/members/me)须先于成员列表(/members)匹配
if (url.includes('/members/me')) {
return ok({ id: 'me', tenant_id: 1, user_id: 'u1', employee_no: 'A1024', dept_id: 'dept-b', post: '高级产品经理', roles: ['trainee'], lecturer_rate: 0, status: 'active' })
}
if (url.includes('/members')) return ok({ items: TRAINING_MOCK.members, total: TRAINING_MOCK.members.length })
if (url.includes('/dashboards/hr')) return ok(TRAINING_MOCK.hrDashboard)
if (url.includes('/dashboards')) return ok({})
if (url.includes('/courses')) return ok({ items: TRAINING_MOCK.courses, total: TRAINING_MOCK.courses.length })
if (url.includes('/sessions')) return ok(TRAINING_MOCK.sessions)
return ok(null)
}
// POST(快速建课/发布/课件登记)统一回成功
return ok({ id: `c-new-${Date.now()}` })
}