From e3cb07f15d8745c5bea5ac7697b35af0e5e36239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=9E=97=E9=93=96?= Date: Wed, 2 Sep 2026 13:19:19 +0800 Subject: [PATCH] feat: align team capacity department order --- DESIGN.md | 2 +- PRODUCT.md | 2 +- .../TeamCapacityDashboard.test.tsx | 24 ++++++++----- .../TeamCapacityDashboard.tsx | 21 ++++++++---- .../department-dashboard/team-capacity.ts | 1 + lib/ding-workflow-team-capacity.test.ts | 18 +++++++--- lib/ding-workflow-team-capacity.ts | 34 ++++++++++++++----- 7 files changed, 73 insertions(+), 29 deletions(-) diff --git a/DESIGN.md b/DESIGN.md index c2e13681..46507d79 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -135,7 +135,7 @@ components: - 进行中项目明细采用可键盘聚焦的横向滚动数据表:桌面固定“审批单标题”首列并保留 14 项业务字段,移动端转换为同字段的语义化定义列表;节点时间在数值下方标注对应流程节点名称。 - 按时交付明细使用紧凑的三项流程筛选条;当前项用浅蓝底和蓝字表达,未选项悬停为灰底,切换时同步更新公式、数量和横向明细表。 - 团队负荷明细按部门展开人员和流程,商品企划部从人员、流程归属和平均负荷统计中排除;页面明确标注排除部门与指定人员。 -- 团队产能页面使用部门二级导航,右侧以近 8 个自然周的收到/完结双柱和可展开周明细承载部门产出;人员数以当前在职花名册为基数,流程按历史任务负责人归属。 +- 团队产能页面使用固定五项部门二级导航(品牌创意A部、品牌创意B部、综合支持部、品牌设计部、空间视觉部),按该顺序排列;右侧以近 8 个自然周的收到/完结双柱和可展开周明细承载部门产出,人员数以当前在职花名册为基数,流程按历史任务负责人归属。 ## Colors diff --git a/PRODUCT.md b/PRODUCT.md index de3a19a1..1727e011 100644 --- a/PRODUCT.md +++ b/PRODUCT.md @@ -35,7 +35,7 @@ web - “按时交付”只统计对应主管/规则审核节点在本月完成、审批状态为已完结且审批结论未拒绝的美术设计与内容视频流程;待计算流程不进入分母。详情页可在全部流程、美术设计流程和内容视频流程之间筛选,公式、数量与明细必须共用当前筛选口径。 - “首轮通过”读取作品过稿数据,分子为 V1 版本审核通过的作品数,分母为当前已通过的作品数;详情页列出部门范围内所有含 V1 的作品,搜索只过滤明细,不改变顶部完整口径。 - “团队负荷”统计品牌中心在职人员当前进行中的流程负荷,排除指定管理人员和商品企划部;该部门及其人员不进入流程归属、部门明细、人员分母或平均负荷。 -- “团队产能”按品牌中心二级部门展示近 8 个上海自然周的在职人数、收到流程数和完结流程数;流程按历史任务负责人映射到部门,点击周次查看进行中与已完结明细。 +- “团队产能”仅展示品牌创意A部、品牌创意B部、综合支持部、品牌设计部、空间视觉部五个二级部门,并按该顺序展示近 8 个上海自然周的在职人数、收到流程数和完结流程数;流程按历史任务负责人映射到部门,点击周次查看进行中与已完结明细。 - 除素材资产库、自动化工作流、人员架构、数据口径和已接入的中心指标外,其余板块现阶段只展示可理解、可扩展的模块框架,不虚构业务数据。 - 沿用项目现有 Next.js、NextAuth、Tailwind CSS 和权限体系。 diff --git a/components/department-dashboard/TeamCapacityDashboard.test.tsx b/components/department-dashboard/TeamCapacityDashboard.test.tsx index 7af83394..6c8ba4f0 100644 --- a/components/department-dashboard/TeamCapacityDashboard.test.tsx +++ b/components/department-dashboard/TeamCapacityDashboard.test.tsx @@ -19,8 +19,12 @@ const data = { lastSyncedAt: '2026-09-01T01:00:00.000Z', syncStatus: 'ready', }, departments: [ - { name: '美术设计部', personnelCount: 5, people: [], weeks: makeWeeks('art', true) }, - { name: '内容部', personnelCount: 3, people: [], weeks: makeWeeks('content') }, + { name: '商品企划部', personnelCount: 7, people: [], weeks: makeWeeks('excluded') }, + { name: '品牌创意A部', personnelCount: 5, people: [], weeks: makeWeeks('art', true) }, + { name: '空间视觉部', personnelCount: 12, people: [], weeks: makeWeeks('space') }, + { name: '品牌设计部', personnelCount: 1, people: [], weeks: makeWeeks('design') }, + { name: '品牌创意B部', personnelCount: 8, people: [], weeks: makeWeeks('content') }, + { name: '综合支持部', personnelCount: 12, people: [], weeks: makeWeeks('support') }, ], } @@ -32,21 +36,25 @@ describe('TeamCapacityDashboard', () => { it('renders department navigation, summary, and eight weeks', async () => { render() expect(await screen.findByRole('heading', { level: 1, name: '团队产能' })).toBeInTheDocument() - await screen.findByRole('button', { name: '美术设计部' }) + await screen.findByRole('button', { name: '品牌创意A部' }) expect(screen.getByRole('complementary', { name: '团队产能二级部门导航' })).toBeInTheDocument() - expect(screen.getByRole('button', { name: '美术设计部' })).toBeInTheDocument() - expect(screen.getByRole('button', { name: '内容部' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '品牌创意A部' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '品牌创意B部' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '综合支持部' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '品牌设计部' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: '空间视觉部' })).toBeInTheDocument() + expect(screen.queryByRole('button', { name: '商品企划部' })).not.toBeInTheDocument() expect(screen.getAllByRole('button', { name: /收到.*完结/ })).toHaveLength(8) expect(screen.getByText('在职人数')).toBeInTheDocument() }) it('switches department and selected week detail', async () => { render() - await screen.findByRole('button', { name: '美术设计部' }) + await screen.findByRole('button', { name: '品牌创意A部' }) fireEvent.click(screen.getAllByRole('button', { name: /收到2个,完结1个/ })[0]) expect(screen.getAllByText('美术流程一').length).toBeGreaterThan(0) - fireEvent.click(screen.getByRole('button', { name: '内容部' })) - expect(await screen.findByRole('heading', { name: '内容部' })).toBeInTheDocument() + fireEvent.click(screen.getByRole('button', { name: '品牌创意B部' })) + expect(await screen.findByRole('heading', { name: '品牌创意B部' })).toBeInTheDocument() expect(screen.getByText('本周暂无流程明细')).toBeInTheDocument() }) diff --git a/components/department-dashboard/TeamCapacityDashboard.tsx b/components/department-dashboard/TeamCapacityDashboard.tsx index f6b0a0b3..2c915493 100644 --- a/components/department-dashboard/TeamCapacityDashboard.tsx +++ b/components/department-dashboard/TeamCapacityDashboard.tsx @@ -12,6 +12,7 @@ import { UsersRound, } from 'lucide-react' import DepartmentShell from './DepartmentShell' +import { TEAM_CAPACITY_DEPARTMENT_ORDER } from './team-capacity' import type { TeamCapacityDepartment, TeamCapacityInsights, @@ -145,21 +146,27 @@ export default function TeamCapacityDashboard() { useEffect(() => { void load() }, [load]) - const departments = state.status === 'success' ? state.data.departments : [] + const capacityData = state.status === 'success' ? state.data : null + const departments = useMemo(() => { + if (!capacityData) return [] + return TEAM_CAPACITY_DEPARTMENT_ORDER.flatMap((name) => { + const department = capacityData.departments.find((candidate) => candidate.name === name) + return department ? [department] : [] + }) + }, [capacityData]) const selectedDepartment = useMemo(() => { - if (state.status !== 'success') return undefined - return state.data.departments.find((department) => department.name === selectedDepartmentKey) || state.data.departments[0] - }, [selectedDepartmentKey, state]) + return departments.find((department) => department.name === selectedDepartmentKey) || departments[0] + }, [departments, selectedDepartmentKey]) const weeks = selectedDepartment?.weeks || [] const selectedWeek = weeks.find((week) => week.key === selectedWeekKey) || weeks.at(-1) const weekMaxValue = Math.max(1, ...weeks.flatMap((week) => [week.receivedCount, week.completedCount])) useEffect(() => { if (state.status === 'success') { - if (!selectedDepartmentKey && state.data.departments[0]) setSelectedDepartmentKey(state.data.departments[0].name) - if (!selectedWeekKey && state.data.departments[0]?.weeks.at(-1)) setSelectedWeekKey(state.data.departments[0].weeks.at(-1)!.key) + if (!selectedDepartmentKey && departments[0]) setSelectedDepartmentKey(departments[0].name) + if (!selectedWeekKey && departments[0]?.weeks.at(-1)) setSelectedWeekKey(departments[0].weeks.at(-1)!.key) } - }, [selectedDepartmentKey, selectedWeekKey, state]) + }, [departments, selectedDepartmentKey, selectedWeekKey, state.status]) return ( diff --git a/components/department-dashboard/team-capacity.ts b/components/department-dashboard/team-capacity.ts index 1588732d..34c234d3 100644 --- a/components/department-dashboard/team-capacity.ts +++ b/components/department-dashboard/team-capacity.ts @@ -7,3 +7,4 @@ export type { TeamCapacityWorkflowItem, TeamCapacityWorkflowRow, } from '@/lib/ding-workflow-team-capacity' +export { TEAM_CAPACITY_DEPARTMENT_ORDER } from '@/lib/ding-workflow-team-capacity' diff --git a/lib/ding-workflow-team-capacity.test.ts b/lib/ding-workflow-team-capacity.test.ts index 0b202071..7e2eab34 100644 --- a/lib/ding-workflow-team-capacity.test.ts +++ b/lib/ding-workflow-team-capacity.test.ts @@ -45,8 +45,8 @@ describe('aggregateTeamCapacity', () => { it('按部门归属统计八周收到/完结及明细,并保留在职人数基数', () => { const result = aggregateTeamCapacity( [ - { id: 'user-1', dingtalkUserId: 'user-1', name: '员工一', departmentName: '设计部' }, - { id: 'user-2', dingtalkUserId: 'user-2', name: '员工二', departmentName: '设计部' }, + { id: 'user-1', dingtalkUserId: 'user-1', name: '员工一', departmentName: '品牌创意A部' }, + { id: 'user-2', dingtalkUserId: 'user-2', name: '员工二', departmentName: '品牌创意A部' }, ], [ workflow(), @@ -59,7 +59,7 @@ describe('aggregateTeamCapacity', () => { { lastSyncedAt: null, syncStatus: 'ready' }, new Date('2026-09-01T02:00:00.000Z'), ) - expect(result.departments).toHaveLength(1) + expect(result.departments).toHaveLength(5) const department = result.departments[0] expect(department.personnelCount).toBe(2) expect(department.weeks).toHaveLength(8) @@ -76,11 +76,21 @@ describe('aggregateTeamCapacity', () => { it('同一流程同一部门在同一周只计一次,且忽略无法映射的处理人', () => { const result = aggregateTeamCapacity( - [{ id: 'user-1', dingtalkUserId: 'user-1', name: '员工一', departmentName: '设计部' }], + [ + { id: 'user-1', dingtalkUserId: 'user-1', name: '员工一', departmentName: '品牌创意A部' }, + { id: 'user-2', dingtalkUserId: 'user-2', name: '员工二', departmentName: '品牌创意B部' }, + { id: 'user-3', dingtalkUserId: 'user-3', name: '员工三', departmentName: '综合支持部' }, + { id: 'user-4', dingtalkUserId: 'user-4', name: '员工四', departmentName: '品牌设计部' }, + { id: 'user-5', dingtalkUserId: 'user-5', name: '员工五', departmentName: '空间视觉部' }, + { id: 'ignored', dingtalkUserId: 'ignored', name: '不展示人员', departmentName: '商品企划部' }, + ], [workflow({ activeTasks: [task(), task({ taskId: 'task-2', createdAt: '2026-08-31T02:00:00.000Z' }), task({ taskId: 'task-3', assigneeUserId: 'unknown' })] })], { lastSyncedAt: null, syncStatus: 'pending' }, new Date('2026-09-01T02:00:00.000Z'), ) + expect(result.departments.map((department) => department.name)).toEqual([ + '品牌创意A部', '品牌创意B部', '综合支持部', '品牌设计部', '空间视觉部', + ]) const currentWeek = result.departments[0].weeks.at(-1)! expect(currentWeek.receivedCount).toBe(1) expect(currentWeek.involvedPersonnelCount).toBe(1) diff --git a/lib/ding-workflow-team-capacity.ts b/lib/ding-workflow-team-capacity.ts index 2a578008..acfa2e02 100644 --- a/lib/ding-workflow-team-capacity.ts +++ b/lib/ding-workflow-team-capacity.ts @@ -84,6 +84,19 @@ export type TeamCapacityInsights = { } } +/** + * 团队产能侧栏只展示品牌中心当前看板约定的五个二级部门,顺序与业务侧栏一致。 + */ +export const TEAM_CAPACITY_DEPARTMENT_ORDER = [ + '品牌创意A部', + '品牌创意B部', + '综合支持部', + '品牌设计部', + '空间视觉部', +] as const + +const TEAM_CAPACITY_DEPARTMENT_SET = new Set(TEAM_CAPACITY_DEPARTMENT_ORDER) + const TERMINAL_STATUSES = new Set(['COMPLETED', 'TERMINATED', 'CANCELED']) function inRange(value: string | null, start: string, end: string) { @@ -140,23 +153,25 @@ export function aggregateTeamCapacity( const personByDingtalkUserId = new Map() rosterRows.forEach((row) => { + const departmentName = row.departmentName.trim() + if (!TEAM_CAPACITY_DEPARTMENT_SET.has(departmentName)) return const person: TeamCapacityPerson = { id: row.id, dingtalkUserId: row.dingtalkUserId, name: row.name, } - const people = departmentPeople.get(row.departmentName) || [] + const people = departmentPeople.get(departmentName) || [] people.push(person) - departmentPeople.set(row.departmentName, people) + departmentPeople.set(departmentName, people) if (row.dingtalkUserId) { - personByDingtalkUserId.set(row.dingtalkUserId, { person, departmentName: row.departmentName }) + personByDingtalkUserId.set(row.dingtalkUserId, { person, departmentName }) } }) const involvedPersonnelByWeek = new Map>() - const departments = Array.from(departmentPeople.entries()) - .sort(([a], [b]) => a.localeCompare(b, 'zh-CN')) - .map(([name, people]) => ({ + const departments = TEAM_CAPACITY_DEPARTMENT_ORDER.map((name) => { + const people = departmentPeople.get(name) || [] + return { name, personnelCount: people.length, people: [...people].sort((a, b) => a.name.localeCompare(b.name, 'zh-CN') || a.id.localeCompare(b.id)), @@ -171,8 +186,11 @@ export function aggregateTeamCapacity( completedCount: 0, items: [], })), - })) - const departmentByName = new Map(departments.map((department) => [department.name, department])) + } + }) + const departmentByName = new Map( + departments.map((department) => [department.name, department]), + ) workflowRows.forEach((row) => { const tasksByDepartment = new Map()