feat: 开发任务时间字段重构 + 双口径耗时 + 搜索 + 性能优化
核心变更: - DevTask 字段重构:startDate/dueDate/estimateHours/actualHours 替换为 expectedStartAt/expectedEndAt/actualStartAt/actualEndAt(含时分),预计/实际工时按工作时段(9:00-12:00 + 13:00-18:00)派生计算 - 状态机自动化:到点自动切开发中、未到可手动开干、超期需填延后原因 - 新建 lib/work-hours.ts:calcWorkHours(工作时段过滤)、formatWorkHours(X h(Y 天))、calcTwoMetrics(日历/人力双口径) - 新建 lib/dev-task-transitions.ts:状态切换守卫 - 三个 Tab 顶部统计:开发任务(预/日历/人力)、测试用例 / Bug(日历 / 人力);版本概览总人天投入改双行(日历总耗时 / 人力总投入) - 三个 Tab 加搜索框:300ms debounce + 标题/编号模糊匹配 - 性能优化:requirementIds/categories/requirements/testCases 转 Map/Set 索引、Row 组件 React.memo - 全局耗时显示统一带天数换算:8h(1天)、11h(1.4天) 新增文件: SearchInput.tsx, useDebouncedValue.ts, work-hours.ts, dev-task-transitions.ts, 设计文档 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Priority } from './derive';
|
||||
import { calcWorkHours, formatWorkHours, type TimeInterval } from './work-hours';
|
||||
|
||||
export type DevTaskStatus = 'todo' | 'in_progress' | 'testing' | 'submitted';
|
||||
|
||||
@@ -12,18 +13,20 @@ export interface DevTask {
|
||||
assigneeId: string;
|
||||
reviewerId?: string;
|
||||
priority: Priority;
|
||||
estimateHours: number;
|
||||
actualHours: number;
|
||||
startDate?: string;
|
||||
dueDate?: string;
|
||||
completedAt?: string;
|
||||
|
||||
expectedStartAt: string;
|
||||
expectedEndAt: string;
|
||||
actualStartAt?: string;
|
||||
actualEndAt?: string;
|
||||
|
||||
status: DevTaskStatus;
|
||||
isBlocked: boolean;
|
||||
blockReason?: string;
|
||||
blockedById?: string;
|
||||
predecessorIds?: string[];
|
||||
riskLevel?: 'low' | 'medium' | 'high';
|
||||
overdueReason?: string;
|
||||
delayReason?: string;
|
||||
overdueVersionReason?: string;
|
||||
createdBy: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
@@ -67,28 +70,82 @@ export function calcTaskProgress(task: DevTask): number {
|
||||
|
||||
export function calcGroupProgress(tasks: DevTask[]): number {
|
||||
if (tasks.length === 0) return 0;
|
||||
const totalEstimate = tasks.reduce((sum, t) => sum + t.estimateHours, 0);
|
||||
if (totalEstimate === 0) return 0;
|
||||
const weighted = tasks.reduce((sum, t) => sum + t.estimateHours * STATUS_PROGRESS[t.status], 0);
|
||||
const totalEstimate = tasks.reduce((sum, t) => sum + getEstimateHours(t), 0);
|
||||
if (totalEstimate === 0) {
|
||||
const sum = tasks.reduce((s, t) => s + STATUS_PROGRESS[t.status], 0);
|
||||
return Math.round(sum / tasks.length);
|
||||
}
|
||||
const weighted = tasks.reduce((sum, t) => sum + getEstimateHours(t) * STATUS_PROGRESS[t.status], 0);
|
||||
return Math.round(weighted / totalEstimate);
|
||||
}
|
||||
|
||||
export function formatHours(hours: number): string {
|
||||
if (hours < 8) return `${hours}h`;
|
||||
const days = Math.floor(hours / 8);
|
||||
const remainder = hours % 8;
|
||||
if (remainder === 0) return `${hours}h(${days}人天)`;
|
||||
return `${hours}h(≈${days}人天)`;
|
||||
return formatWorkHours(hours);
|
||||
}
|
||||
|
||||
export function calcActualHoursByDates(startDate?: string, completedAt?: string): number {
|
||||
if (!startDate) return 0;
|
||||
const end = completedAt || new Date().toISOString();
|
||||
const startMs = new Date(startDate).getTime();
|
||||
const endMs = new Date(end).getTime();
|
||||
if (isNaN(startMs) || isNaN(endMs) || endMs < startMs) return 0;
|
||||
const diffHours = (endMs - startMs) / (1000 * 60 * 60);
|
||||
return Math.round(diffHours * 2) / 2; // 精确到0.5h
|
||||
export function getEstimateHours(task: DevTask): number {
|
||||
if (!task.expectedStartAt || !task.expectedEndAt) return 0;
|
||||
return calcWorkHours(task.expectedStartAt, task.expectedEndAt);
|
||||
}
|
||||
|
||||
export function getActualHours(task: DevTask, now: Date = new Date()): number {
|
||||
if (!task.actualStartAt) return 0;
|
||||
const end = task.actualEndAt ?? now.toISOString();
|
||||
return calcWorkHours(task.actualStartAt, end);
|
||||
}
|
||||
|
||||
export interface AggregatedHours {
|
||||
estimate: number;
|
||||
actual: number;
|
||||
}
|
||||
|
||||
export function aggregateDevTaskHours(tasks: DevTask[], now: Date = new Date()): AggregatedHours {
|
||||
let estimate = 0;
|
||||
let actual = 0;
|
||||
for (const t of tasks) {
|
||||
estimate += getEstimateHours(t);
|
||||
actual += getActualHours(t, now);
|
||||
}
|
||||
return {
|
||||
estimate: Math.round(estimate * 2) / 2,
|
||||
actual: Math.round(actual * 2) / 2,
|
||||
};
|
||||
}
|
||||
|
||||
export function aggregateActualHoursByAssignee(
|
||||
tasks: DevTask[],
|
||||
now: Date = new Date(),
|
||||
): Array<{ assigneeId: string; actualHours: number; taskCount: number }> {
|
||||
const map = new Map<string, { actualHours: number; taskCount: number }>();
|
||||
for (const t of tasks) {
|
||||
const h = getActualHours(t, now);
|
||||
if (h <= 0 && t.status !== 'submitted') continue;
|
||||
const cur = map.get(t.assigneeId) || { actualHours: 0, taskCount: 0 };
|
||||
cur.actualHours += h;
|
||||
cur.taskCount += 1;
|
||||
map.set(t.assigneeId, cur);
|
||||
}
|
||||
return Array.from(map.entries())
|
||||
.map(([assigneeId, v]) => ({
|
||||
assigneeId,
|
||||
actualHours: Math.round(v.actualHours * 2) / 2,
|
||||
taskCount: v.taskCount,
|
||||
}))
|
||||
.sort((a, b) => b.actualHours - a.actualHours);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽取每条已开干任务的 [actualStartAt, actualEndAt ?? now] 时间区间
|
||||
* 用于双口径耗时统计(calcTwoMetrics)
|
||||
*/
|
||||
export function devTaskIntervals(tasks: DevTask[], now: Date = new Date()): TimeInterval[] {
|
||||
const out: TimeInterval[] = [];
|
||||
const nowIso = now.toISOString();
|
||||
for (const t of tasks) {
|
||||
if (!t.actualStartAt) continue;
|
||||
out.push({ start: t.actualStartAt, end: t.actualEndAt ?? nowIso });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function generateTaskNo(existingTasks: DevTask[]): string {
|
||||
@@ -98,3 +155,29 @@ export function generateTaskNo(existingTasks: DevTask[]): string {
|
||||
}, 0);
|
||||
return `DEV-${String(maxNum + 1).padStart(3, '0')}`;
|
||||
}
|
||||
|
||||
export function isLegacyTask(t: any): boolean {
|
||||
if (!t || typeof t !== 'object') return false;
|
||||
return (
|
||||
'startDate' in t ||
|
||||
'dueDate' in t ||
|
||||
'completedAt' in t ||
|
||||
'estimateHours' in t ||
|
||||
'actualHours' in t ||
|
||||
'overdueReason' in t
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容函数:按纯小时差计算耗时(保留给 PlanTab/TestCase 体系使用)
|
||||
* DevTask 体系应改用 getActualHours/getEstimateHours 走 calcWorkHours
|
||||
*/
|
||||
export function calcActualHoursByDates(startDate?: string, completedAt?: string): number {
|
||||
if (!startDate) return 0;
|
||||
const end = completedAt || new Date().toISOString();
|
||||
const startMs = new Date(startDate).getTime();
|
||||
const endMs = new Date(end).getTime();
|
||||
if (isNaN(startMs) || isNaN(endMs) || endMs < startMs) return 0;
|
||||
const diffHours = (endMs - startMs) / (1000 * 60 * 60);
|
||||
return Math.round(diffHours * 2) / 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user