64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
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,
|
|
};
|
|
}
|