Files
knowledge-governance/web/src/qaPeopleAnalysis.ts
T
姚章浩 f38541db06
build / build (push) Successful in 1m5s
fix(qaops): 区域人员表直接展示部门并调整列宽
仅按区域显示真实部门名称与完整路径悬停,替代部门数量折叠摘要;适配人员与部门列宽,按人视图保持原样。归属、统计与分页不变。

验证:真实节点名称、区域直显且按人不变、区域列宽分别先红后绿,14项相关测试与类型检查通过。完整门禁、候选和上线验收待执行。
2026-10-24 14:14:21 +08:00

79 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { DepartmentPersonStatistic, DepartmentStatisticsSnapshot } from './qaDepartmentStatistics'
export const departmentTime = (value: string) =>
new Date(value).toLocaleString('zh-CN', {
timeZone: 'Asia/Shanghai',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false,
})
export const PEOPLE_PAGE_SIZE = 50
export type PersonRankingRow = DepartmentPersonStatistic & {
region_ids: string[]
region_state: 'matched' | 'cross_region' | 'unassigned'
group_key: string
region_label: string
department_paths: Array<{ id: string; name: string; path: string }>
}
export type PeopleAnalysisGroup = { key: string; name: string; people: PersonRankingRow[]; visits: number }
export function peopleAnalysis(data: DepartmentStatisticsSnapshot): {
people: PersonRankingRow[]
groups: PeopleAnalysisGroup[]
} {
const nodes = new Map(data.rows.map((d) => [d.id, d]))
const people: PersonRankingRow[] = data.people
.map((person) => ({
...person,
department_ids: [...person.department_ids],
region_ids: [],
region_state: 'unassigned' as const,
group_key: 'state:unassigned',
region_label: '未归属',
department_paths: person.department_ids.map((id) => {
const names: string[] = []
let current = id
while (current) {
const d = nodes.get(current)!
names.unshift(d.name)
current = d.parent_id
}
return { id, name: nodes.get(id)!.name, path: names.join('/') }
}),
}))
.sort((a, b) => b.visits - a.visits || a.name.localeCompare(b.name, 'zh-CN') || a.key.localeCompare(b.key))
const labels = new Map(data.regions.map((r) => [r.id, r.name]))
const groups: PeopleAnalysisGroup[] = [
...data.regions.map((r) => ({ key: 'region:' + r.id, name: r.name, people: [] as PersonRankingRow[], visits: 0 })),
{ key: 'state:cross_region', name: '跨区域待核对', people: [], visits: 0 },
{ key: 'state:unassigned', name: '未归属', people: [], visits: 0 },
]
const byKey = new Map(groups.map((g) => [g.key, g]))
for (const person of people) {
person.region_ids = [...new Set(person.department_ids.map((id) => nodes.get(id)!.region).filter(Boolean))].sort()
person.region_state =
person.region_ids.length === 1 ? 'matched' : person.region_ids.length > 1 ? 'cross_region' : 'unassigned'
person.group_key =
person.region_state === 'matched' ? 'region:' + person.region_ids[0] : 'state:' + person.region_state
person.region_label =
person.region_state === 'matched'
? labels.get(person.region_ids[0])!
: person.region_state === 'cross_region'
? '跨区域待核对(' + person.region_ids.map((id) => labels.get(id)).join('、') + ')'
: '未归属'
const group = byKey.get(person.group_key)!
group.people.push(person)
group.visits += person.visits
}
return { people, groups }
}
export function peoplePage(people: PersonRankingRow[], requested: number) {
const total = people.length,
pages = Math.max(1, Math.ceil(total / PEOPLE_PAGE_SIZE))
const page = Math.max(1, Math.min(pages, Number.isFinite(requested) ? Math.trunc(requested) : 1))
const start = (page - 1) * PEOPLE_PAGE_SIZE,
end = Math.min(total, start + PEOPLE_PAGE_SIZE)
return { items: people.slice(start, end), page, pages, total, start, end }
}