feat(hr-sync): 人员信息同步纳入快递公司组织树(覆盖全部钉钉部门)

This commit is contained in:
居居 2026-11-05 17:35:32 +08:00
parent c875549d2f
commit b273c62a4e
5 changed files with 20 additions and 17 deletions

View File

@ -14,12 +14,12 @@ const departments = [
]
describe('钉钉离职判定(方案 B)', () => {
it('供应商子树纳入抓取范围,快递公司子树排除', () => {
it('供应商与快递公司子树均纳入抓取范围', () => {
const scanned = collectScannedDepartmentExternalIds(departments)
expect(scanned.has('1')).toBe(true)
expect(scanned.has('3')).toBe(true)
expect(scanned.has('4')).toBe(false)
expect(scanned.has('5')).toBe(false)
expect(scanned.has('4')).toBe(true)
expect(scanned.has('5')).toBe(true)
expect(scanned.has('6')).toBe(true)
expect(scanned.has('7')).toBe(true)
})
@ -43,9 +43,10 @@ describe('钉钉离职判定(方案 B)', () => {
})
expect(result.skipped).toBe(false)
expect(result.candidates.map((candidate) => candidate.name)).toEqual(['乙', '己(供应商成员)'])
expect(result.candidates.map((candidate) => candidate.name)).toEqual(['乙', '丙(已转出到快递公司)', '己(供应商成员)'])
expect(result.candidates[0]).toMatchObject({ dingtalkUserId: 'user-b', name: '乙' })
expect(result.candidates[1]).toMatchObject({ dingtalkUserId: 'user-f', name: '己(供应商成员)' })
expect(result.candidates[1]).toMatchObject({ dingtalkUserId: 'user-c', name: '丙(已转出到快递公司)' })
expect(result.candidates[2]).toMatchObject({ dingtalkUserId: 'user-f', name: '己(供应商成员)' })
})
it('抓取人数明显缩水时整体跳过判定,避免限流/权限问题误标', () => {

View File

@ -10,16 +10,16 @@ describe('人员信息钉钉同步范围', () => {
{ id: '6', name: '运营中心A', parentId: '1' },
]
it('供应商子树纳入同步,快递公司子树排除', () => {
it('供应商与快递公司子树均纳入同步', () => {
const excluded = collectExcludedOwnerDirectoryDepartmentIds(departments, '1')
expect(excluded.has('2')).toBe(false)
expect(excluded.has('3')).toBe(false)
expect(excluded.has('4')).toBe(true)
expect(excluded.has('5')).toBe(true)
expect(excluded.has('4')).toBe(false)
expect(excluded.has('5')).toBe(false)
expect(excluded.has('6')).toBe(false)
})
it('只排除根级同名部门,嵌套同名部门不误伤', () => {
it('当前无排除部门,嵌套同名部门也不影响', () => {
const nested = [
{ id: '1', name: '江苏简尚', parentId: null },
{ id: '6', name: '运营中心A', parentId: '1' },

View File

@ -1,5 +1,6 @@
// 2026-11-05 口径:供应商子树也纳入人员信息同步(含其区域/供应商子部门),仅排除快递公司子树。
const EXCLUDED_OWNER_DIRECTORY_ROOTS = new Set(['快递公司'])
// 2026-11-05 口径:供应商与快递公司子树均纳入人员信息同步(覆盖全部钉钉部门)。
// 保留排除机制,后续如需再次排除某个根级部门,把名称加回该集合即可。
const EXCLUDED_OWNER_DIRECTORY_ROOTS = new Set<string>()
export type OwnerDirectoryDepartmentNode = {
id: string

View File

@ -170,7 +170,7 @@ describe('DingtalkDirectoryClient', () => {
}))
})
it('负责人通讯录抓取供应商组织树,仅排除快递公司组织树', async () => {
it('负责人通讯录抓取全部部门(含供应商与快递公司组织树)', async () => {
const requestedEmployeeDepartmentIds: number[] = []
global.fetch = jest.fn(async (input, init) => {
const url = String(input)
@ -202,6 +202,7 @@ describe('DingtalkDirectoryClient', () => {
const lists: Record<number, Array<{ userid: string; name: string; dept_id_list: number[] }>> = {
3: [{ userid: 'supplier-1', name: '供应商联系人', dept_id_list: [3] }],
4: [{ userid: 'employee-1', name: '运营甲', dept_id_list: [4] }],
6: [{ userid: 'courier-1', name: '快递联系人', dept_id_list: [6] }],
}
return response({ errcode: 0, result: {
list: lists[body.dept_id] ?? [],
@ -209,7 +210,7 @@ describe('DingtalkDirectoryClient', () => {
} })
}
if (url.includes('/user/get')) {
const names: Record<string, string> = { 'employee-1': '运营甲', 'supplier-1': '供应商联系人' }
const names: Record<string, string> = { 'employee-1': '运营甲', 'supplier-1': '供应商联系人', 'courier-1': '快递联系人' }
return response({ errcode: 0, result: { userid: body.userid, name: names[body.userid], dept_id_list: [] } })
}
const roleResponse = emptyRoleListResponse(url)
@ -219,11 +220,11 @@ describe('DingtalkDirectoryClient', () => {
const result = await dingtalkDirectoryClient.fetchSnapshot()
expect(requestedEmployeeDepartmentIds).toEqual(expect.arrayContaining([1, 2, 3, 4]))
expect(requestedEmployeeDepartmentIds).not.toEqual(expect.arrayContaining([5, 6]))
expect(requestedEmployeeDepartmentIds).toEqual(expect.arrayContaining([1, 2, 3, 4, 5, 6]))
expect(result.employees).toEqual(expect.arrayContaining([
expect.objectContaining({ dingtalkUserId: 'employee-1' }),
expect.objectContaining({ dingtalkUserId: 'supplier-1' }),
expect.objectContaining({ dingtalkUserId: 'courier-1' }),
]))
})
})

View File

@ -608,7 +608,7 @@ describe('负责人配置', () => {
})
})
it('负责人选项包含供应商组织树,仅排除快递公司组织树', async () => {
it('负责人选项包含供应商与快递公司组织树', async () => {
const { repository, service } = setup()
repository.listDirectoryContext.mockResolvedValue({
employees: [
@ -627,7 +627,7 @@ describe('负责人配置', () => {
const result = await service.listDirectoryOptions()
expect(result.items.map((item) => item.name)).toEqual(['运营甲', '供应商乙'])
expect(result.items.map((item) => item.name)).toEqual(['运营甲', '供应商乙', '快递丙'])
})
it('负责人选项排除已人工删除的通讯录人员', async () => {