feat(workspace): 添加个人日报派生逻辑

This commit is contained in:
Script Generator
2026-06-26 14:40:37 +08:00
parent 914e6180c1
commit 6b965429ce
2 changed files with 186 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
import type { TaskWorklog } from './task-worklog';
import type { WorkItem } from './workspace-engine';
export interface WorkspaceDailyReportItem {
id: string;
taskId: string;
taskTitle: string;
workContent: string;
hours: number;
createdAt: string;
productName?: string;
projectName?: string;
versionName?: string;
}
export interface WorkspaceDailyReport {
date: string;
totalHours: number;
totalCount: number;
items: WorkspaceDailyReportItem[];
}
interface GetWorkspaceDailyReportInput {
worklogs: TaskWorklog[];
workItems: WorkItem[];
userId: string;
date: string;
}
export function getWorkspaceDailyReport({
worklogs,
workItems,
userId,
date,
}: GetWorkspaceDailyReportInput): WorkspaceDailyReport {
const workItemMap = new Map(workItems.map((item) => [item.id, item]));
const items = worklogs
.filter((log) => log.userId === userId && log.date === date)
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
.map((log) => {
const item = workItemMap.get(log.taskId);
return {
id: log.id,
taskId: log.taskId,
taskTitle: item?.title ?? '未知任务',
workContent: log.workContent,
hours: log.hours,
createdAt: log.createdAt,
productName: item?.productName,
projectName: item?.projectName,
versionName: item?.versionName,
};
});
return {
date,
totalHours: items.reduce((sum, item) => sum + item.hours, 0),
totalCount: items.length,
items,
};
}