区域配置入口改为区域统计,五列表按当前通讯录整支人员去重;调岗依当前归属、零分母未知、最近真实提问时间和父行收起不重算。仅读治理正式总表,后台单并发/请求合并/60秒缓存,目录与配置版本隔离,客户端失败不伪零。 保留区域自定义目录与预览/双版本锁保存,父部门勾选联选全后代,取消子支清除祖先整支选择,避免隐式覆盖未选子级;允许删除无引用区域,已有引用不静默孤立。统计页与设置共享选择,统计支持累计与北京时间自然月;不新增迁移,不改DobotAI生产、代理、原问答、历史趋势或已有AI任务。 验证已执行:完整make verify退出0,705 Go/340前端通过、120项声明的可选集成跳过且必需0跳过;镜像全量隔离PG race退出0;新增去重/调岗/空分母、后台缓存/并发、HTTP授权/严格请求、真PG目录与配置失效、树选择/收起、五列与删除保护均先红后绿。旧导航测试按新名称更新后全量通过。上线前治理库备份与真实恢复72表/29张QA内容哈希一致,匹配独立主密钥受限备份。 当前尚待精确SHA CI、同镜像真实数据浏览器与正式读回,不把源码验证称为已上线。公司真实区域映射不在本轮擅改;只在隔离库验证保存。
This commit is contained in:
@@ -1,4 +1,92 @@
|
||||
import type { DepartmentRegion, RegionRule } from './qaOrg'
|
||||
export type DepartmentNode = { id: string; parent_id: string; name: string }
|
||||
export function subtreeIDs(nodes: DepartmentNode[], ids: string[]): string[] {
|
||||
const children = new Map<string, string[]>(),
|
||||
known = new Set(nodes.map((n) => n.id))
|
||||
for (const node of nodes) {
|
||||
const list = children.get(node.parent_id) ?? []
|
||||
list.push(node.id)
|
||||
children.set(node.parent_id, list)
|
||||
}
|
||||
const seen = new Set<string>(),
|
||||
queue = [...ids]
|
||||
while (queue.length) {
|
||||
const id = queue.pop()!
|
||||
if (!known.has(id)) throw Error('部门不在当前通讯录')
|
||||
if (seen.has(id)) continue
|
||||
seen.add(id)
|
||||
queue.push(...(children.get(id) ?? []))
|
||||
}
|
||||
return [...seen]
|
||||
}
|
||||
export function selectDepartmentBranch(
|
||||
nodes: DepartmentNode[],
|
||||
selected: string[],
|
||||
id: string,
|
||||
checked: boolean
|
||||
): string[] {
|
||||
const ids = subtreeIDs(nodes, [id]),
|
||||
next = new Set(selected)
|
||||
if (checked) ids.forEach((x) => next.add(x))
|
||||
else {
|
||||
ids.forEach((x) => next.delete(x))
|
||||
const parents = new Map(nodes.map((n) => [n.id, n.parent_id]))
|
||||
const seen = new Set<string>()
|
||||
let parent = parents.get(id)
|
||||
while (parent && !seen.has(parent)) {
|
||||
seen.add(parent)
|
||||
next.delete(parent)
|
||||
parent = parents.get(parent)
|
||||
}
|
||||
}
|
||||
return [...next]
|
||||
}
|
||||
export function departmentTree<T extends DepartmentNode>(
|
||||
nodes: T[],
|
||||
collapsed: ReadonlySet<string>,
|
||||
search = '',
|
||||
region = ''
|
||||
): Array<{ department: T; depth: number; hasChildren: boolean }> {
|
||||
const known = new Map(nodes.map((n) => [n.id, n])),
|
||||
children = new Map<string, T[]>()
|
||||
if (known.size !== nodes.length) throw Error('通讯录部门重复')
|
||||
for (const node of nodes) {
|
||||
if (node.parent_id && !known.has(node.parent_id)) throw Error('通讯录缺少父部门')
|
||||
const list = children.get(node.parent_id) ?? []
|
||||
list.push(node)
|
||||
children.set(node.parent_id, list)
|
||||
}
|
||||
for (const list of children.values())
|
||||
list.sort((a, b) => a.name.localeCompare(b.name, 'zh-CN') || a.id.localeCompare(b.id))
|
||||
const all: Array<{ department: T; depth: number; hasChildren: boolean; parents: string[]; path: string }> = [],
|
||||
seen = new Set<string>()
|
||||
const walk = (parent: string, parents: string[], names: string[]) => {
|
||||
for (const node of children.get(parent) ?? []) {
|
||||
if (seen.has(node.id) || parents.length > 100) throw Error('通讯录部门层级无效')
|
||||
seen.add(node.id)
|
||||
all.push({
|
||||
department: node,
|
||||
depth: parents.length,
|
||||
hasChildren: !!children.get(node.id)?.length,
|
||||
parents,
|
||||
path: [...names, node.name].join('/'),
|
||||
})
|
||||
walk(node.id, [...parents, node.id], [...names, node.name])
|
||||
}
|
||||
}
|
||||
walk('', [], [])
|
||||
if (all.length !== nodes.length) throw Error('通讯录部门存在循环')
|
||||
if (search || region) {
|
||||
const matches = all.filter(
|
||||
(r) =>
|
||||
(!search || r.path.toLowerCase().includes(search.toLowerCase())) &&
|
||||
(!region || (r.department as DepartmentNode & { region?: string }).region === region)
|
||||
)
|
||||
const visible = new Set(matches.flatMap((r) => [r.department.id, ...r.parents]))
|
||||
return all.filter((r) => visible.has(r.department.id))
|
||||
}
|
||||
return all.filter((r) => !r.parents.some((id) => collapsed.has(id)))
|
||||
}
|
||||
export function applyBulkRegionRules(rules: RegionRule[], ids: string[], region: string): RegionRule[] {
|
||||
const selected = new Set(ids)
|
||||
if (!selected.size) return [...rules]
|
||||
|
||||
Reference in New Issue
Block a user