diff --git a/components/department-dashboard/business-trends.test.ts b/components/department-dashboard/business-trends.test.ts index 8921997..195b60c 100644 --- a/components/department-dashboard/business-trends.test.ts +++ b/components/department-dashboard/business-trends.test.ts @@ -41,4 +41,14 @@ describe('business trends aggregation', () => { expect(result.brands.map((brand) => brand.brand)).toEqual([...BUSINESS_TREND_BRANDS]) expect(result.brands.every((brand) => brand.processes.every((process) => process.weeks.every((week) => week.items.length === 0)))).toBe(true) }) + + it('does not count terminated workflows as completed', () => { + const result = aggregateBusinessTrends([{ + id: 'terminated', businessId: null, title: '终止流程', status: 'TERMINATED', processCode: 'ART', projectType: '美术设计流程', brand: '亿家达', + requesterName: '甲', requesterDepartment: '品牌中心', initiatorName: '甲', initiatorDepartment: '品牌中心', + sourceCreatedAt: '2026-08-31T01:00:00.000Z', sourceUpdatedAt: null, sourceFinishedAt: '2026-09-01T01:00:00.000Z', activeTasks: [], + }], { lastSyncedAt: null, syncStatus: 'ready' }, new Date('2026-09-01T02:00:00.000Z')) + const art = result.brands[0].processes.find((process) => process.key === 'art')! + expect(art.weeks.at(-1)).toMatchObject({ startedCount: 1, completedCount: 0 }) + }) }) diff --git a/components/department-dashboard/business-trends.ts b/components/department-dashboard/business-trends.ts index 245ccd8..e0fe2d6 100644 --- a/components/department-dashboard/business-trends.ts +++ b/components/department-dashboard/business-trends.ts @@ -103,6 +103,10 @@ function inRange(value: string | null, start: string, end: string) { return Number.isFinite(time) && time >= Date.parse(start) && time < Date.parse(end) } +function isCompletedStatus(value: string) { + return value.trim().toUpperCase() === 'COMPLETED' +} + function processKeyFor(row: BusinessTrendWorkflowRow): BusinessTrendProcessKey | null { if (row.projectType === '美术设计流程') return 'art' if (row.projectType === '内容视频和图片拍摄' || row.projectType === '内容视频流程') return 'content' @@ -133,7 +137,7 @@ export function aggregateBusinessTrends( if (!process) return process.weeks.forEach((week) => { const startedInWeek = inRange(row.sourceCreatedAt, week.start, week.end) - const completedInWeek = inRange(row.sourceFinishedAt, week.start, week.end) + const completedInWeek = isCompletedStatus(row.status) && inRange(row.sourceFinishedAt, week.start, week.end) if (!startedInWeek && !completedInWeek) return if (startedInWeek) week.startedCount += 1 if (completedInWeek) week.completedCount += 1