feat(training): 新增精益培训视频与周任务管理
This commit is contained in:
1 parent
e5ede471fd
commit
a69814c409
32 files changed
+1619
-55
No files matched your search
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/api/training.api.ts
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计和导出。
|
||||
* 用途:培训工作区专用 HTTP API,负责员工进度读取/保存、HR 记录查询、统计导出和精益任务提醒。
|
||||
* 依赖:shared/api/client、auth headers、training.types。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构。
|
||||
* 逻辑:把后端 training 领域的 snake_case 返回值统一映射成前端工作区需要的 camelCase 结构,并提交精益未完成人员提醒请求。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
@@ -15,10 +15,37 @@ import type {
|
||||
TrainingRecord,
|
||||
TrainingStage,
|
||||
TrainingStats,
|
||||
LeanTrainingDashboard,
|
||||
LeanTrainingDashboardRow,
|
||||
LeanTrainingWeeklyTask,
|
||||
TrainingType,
|
||||
TrainingTypeOption,
|
||||
} from '../training/training.types';
|
||||
|
||||
type LeanTrainingTaskApi = {
|
||||
id: number; week_key: string; due_at: string; video_resource_ids: number[];
|
||||
target_roles: string[]; target_user_ids: number[];
|
||||
videos: Array<{ id: number; name: string }>; status: string; min_summary_length: number;
|
||||
};
|
||||
|
||||
type LeanTrainingDashboardRowApi = {
|
||||
id?: number; user_id: number; employee_id?: string | null; name: string; department?: string | null;
|
||||
videos: Array<{ name: string; watched_at?: string | null }>;
|
||||
summary_text?: string | null; status: 'completed' | 'incomplete'; completed_at?: string | null;
|
||||
};
|
||||
|
||||
const mapLeanTask = (data: LeanTrainingTaskApi): LeanTrainingWeeklyTask => ({
|
||||
id: data.id, weekKey: data.week_key, dueAt: data.due_at, videoResourceIds: data.video_resource_ids || [],
|
||||
targetRoles: data.target_roles || [], targetUserIds: data.target_user_ids || [],
|
||||
videos: data.videos || [], status: data.status, minSummaryLength: data.min_summary_length,
|
||||
});
|
||||
|
||||
const mapLeanDashboardRow = (data: LeanTrainingDashboardRowApi): LeanTrainingDashboardRow => ({
|
||||
id: data.id, userId: data.user_id, employeeId: data.employee_id, name: data.name, department: data.department,
|
||||
videos: (data.videos || []).map((item) => ({ name: item.name, watchedAt: item.watched_at })),
|
||||
summaryText: data.summary_text, status: data.status, completedAt: data.completed_at,
|
||||
});
|
||||
|
||||
type TrainingRecordApi = {
|
||||
id: number;
|
||||
user_id?: number;
|
||||
@@ -229,6 +256,31 @@ export async function getMyTrainingTypes(): Promise<TrainingTypeOption[]> {
|
||||
return requestJson<TrainingTypeOption[]>('/api/user/training-types', authHeaders());
|
||||
}
|
||||
|
||||
export async function getCurrentLeanTrainingTask(): Promise<LeanTrainingWeeklyTask | null> {
|
||||
const response = await requestJson<LeanTrainingTaskApi | null>('/api/user/lean-training/current-task', authHeaders());
|
||||
return response ? mapLeanTask(response) : null;
|
||||
}
|
||||
|
||||
export async function saveMyLeanTrainingCompletion(payload: { weeklyTaskId: number; watchedAt: Record<string, string>; summaryText: string }): Promise<LeanTrainingDashboardRow> {
|
||||
const response = await requestJson<LeanTrainingDashboardRowApi>('/api/user/lean-training/completions', {
|
||||
method: 'PUT', ...jsonAuthHeaders(), body: JSON.stringify({ weekly_task_id: payload.weeklyTaskId, watched_at: payload.watchedAt, summary_text: payload.summaryText }),
|
||||
});
|
||||
return mapLeanDashboardRow(response);
|
||||
}
|
||||
|
||||
export async function getLeanTrainingDashboard(): Promise<LeanTrainingDashboard> {
|
||||
const response = await requestJson<{ task: LeanTrainingTaskApi | null; completed: LeanTrainingDashboardRowApi[]; incomplete: LeanTrainingDashboardRowApi[] }>('/api/admin/lean-training/dashboard', authHeaders());
|
||||
return { task: response.task ? mapLeanTask(response.task) : null, completed: (response.completed || []).map(mapLeanDashboardRow), incomplete: (response.incomplete || []).map(mapLeanDashboardRow) };
|
||||
}
|
||||
|
||||
export async function sendLeanTrainingReminders(weeklyTaskId: number, userIds: number[]): Promise<{ created: number; skipped: number; failed: number }> {
|
||||
return requestJson<{ created: number; skipped: number; failed: number }>(`/api/admin/lean-training/weekly-tasks/${weeklyTaskId}/reminders`, {
|
||||
method: 'POST',
|
||||
...jsonAuthHeaders(),
|
||||
body: JSON.stringify({ user_ids: userIds }),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getMyTrainingProgress(type: string = 'onboarding'): Promise<TrainingProgressRecord | null> {
|
||||
const data = await requestJson<TrainingRecordApi | null>(`/api/user/training-record?type=${encodeURIComponent(type)}`, authHeaders());
|
||||
return data ? mapTrainingProgressRecord(data) : null;
|
||||
|
||||
Reference in new issue
Block a user