feat(qaops): 增加区域与全员提问排行及五十人分页
build / build (push) Successful in 1m6s

保留部门树并复用同一统计快照;区域内去重,跨区域和未归属单列,不改配置或主归属。按提问次数降序,保留零提问人员,每页50人。

验证:401项前端测试与类型检查通过,排序、区域去重、跨区域、零使用和123人三页边界红绿验证通过。
同镜像、正式网页和部署尚未验收。
This commit is contained in:
姚章浩
2026-10-21 18:06:30 +08:00
parent 99d6109bef
commit 4e655fb977
8 changed files with 563 additions and 59 deletions
+78
View File
@@ -0,0 +1,78 @@
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; 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, 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 }
}