deploy-hxtesting / build-and-deploy (push) Successful in 1m13s
员工首登自动开通个人空间(create_personal 默认)后,归属空间(users.tenant_id)
与「最近活跃租户」偏好停在个人空间,登录后看到的是个人空间里那份空的组织
架构/培训数据,模板下载也没有部门下拉。空间 Owner 现可一键收编:
1. GET /org/employees/adoptable 收编预览:归属空间不在本空间的活跃成员
(COALESCE 兜底 NULL 归属,联查名册标记与归属空间名供确认);
2. POST /org/employees/adopt-home 批量收编:逐条校验不整批失败,非本空间
成员/停用/跨空间账号/已归属本空间逐条跳过并回传原因;归属指针与最近
活跃租户偏好一起改指本空间(登录路径优先读偏好,只改归属会被旧偏好
拉回),成员关系/角色/个人空间数据不动,可经空间切换器改回,非破坏性;
3. 收编成功者补跑自动入册(EnsureEmployeesForUsers 仅补空幂等),
同步部门自动匹配进名册;
4. 单条 rbac.member_home_adopted 审计(best-effort);路由 g.Owner() 限定,
与成员批量导入/Casdoor 同步同权限级别;
5. 收编依赖只引 repository 层(UserRepository/TenantMemberRepository),
避开 tenantMemberService→OrgCenterService→userService→memberService
的 DI 环;
6. 前端组织架构页新增「收编到本空间」入口(仅 hasRole('owner') 可见)+
预览确认弹窗(与 OA 同步弹窗同两段式交互);顺手补齐
OrgEmployee.wecom_userid 缺失的存量类型缺口(type-check 阻断项)。
测试:服务层新增收编落点+偏好/六类跳过/守卫 3 例;仓库层 sqlite 用例覆盖
NULL 归属兜底与停用/已归属排除;既有 org/member/casdoor/培训模板用例无回归。
197 lines
6.7 KiB
TypeScript
197 lines
6.7 KiB
TypeScript
import { get, post, put, del } from '@/utils/request'
|
||
import type { WecomSyncSummary } from '@/api/training'
|
||
|
||
// 组织中心(租户级共享组织架构)API 封装,对应后端 /api/v1/org/*(routes_org.go)。
|
||
// 部门/员工档案归租户所有;业务模块(企业培训/图纸标注/物料检核...)通过
|
||
// module_key 在 org_module_members 上绑定各自角色,组织数据只维护一份。
|
||
// 响应解包沿用 api/training 导出的 unwrap(调用方 import { unwrap } from '@/api/training')。
|
||
|
||
// 注意必须带 /api/v1 前缀(与其他 api 模块一致);axios baseURL 为 '/',
|
||
// 缺前缀时请求会落入前端 SPA 回退路由,返回 index.html 而非接口数据。
|
||
const base = '/api/v1/org'
|
||
|
||
export type OrgModuleKey = string
|
||
|
||
/** 企业培训模块的 module_key(组织中心首个接入模块)。 */
|
||
export const ORG_MODULE_TRAINING: OrgModuleKey = 'training'
|
||
|
||
export interface OrgDept {
|
||
id: string
|
||
tenant_id: number
|
||
parent_id: string
|
||
name: string
|
||
code: string
|
||
sort: number
|
||
}
|
||
|
||
/** 模块绑定行(org_module_members):某模块在某员工上的角色/扩展属性。 */
|
||
export interface OrgModuleMember {
|
||
id: string
|
||
tenant_id: number
|
||
module_key: OrgModuleKey
|
||
employee_id: string
|
||
roles: string[]
|
||
extra: Record<string, any>
|
||
}
|
||
|
||
export interface OrgEmployee {
|
||
id: string
|
||
tenant_id: number
|
||
user_id: string
|
||
employee_no: string
|
||
dept_id: string
|
||
post: string
|
||
lecturer_rate: number
|
||
status: string
|
||
/** 企微账号(OA 同步/绑定维护;列表 Select org_employees.* 随行返回)。 */
|
||
wecom_userid?: string
|
||
/** 联查展示字段:用户姓名/部门名称/指定 module_key 的绑定角色 */
|
||
user_name?: string
|
||
dept_name?: string
|
||
roles?: string[]
|
||
}
|
||
|
||
export interface OrgListQuery {
|
||
module_key?: string
|
||
dept_id?: string
|
||
keyword?: string
|
||
page?: number
|
||
page_size?: number
|
||
}
|
||
|
||
export interface OrgPagedData<T> {
|
||
items: T[]
|
||
total: number
|
||
}
|
||
|
||
// ---- 部门 ----
|
||
|
||
export const listDepts = () => get<{ success: boolean; data: OrgDept[] }>(`${base}/depts`)
|
||
|
||
/** 新增/修改部门:id 为空走新增,否则更新。 */
|
||
export const saveDept = (payload: Partial<OrgDept>) =>
|
||
post<{ success: boolean; data: OrgDept }>(`${base}/depts`, payload)
|
||
|
||
export const deleteDept = (id: string) => del<{ success: boolean }>(`${base}/depts/${enc(id)}`)
|
||
|
||
// ---- 员工档案 ----
|
||
|
||
export const listEmployees = (query?: OrgListQuery) =>
|
||
get<{ success: boolean; data: OrgPagedData<OrgEmployee> }>(`${base}/employees`, { params: query })
|
||
|
||
export interface OrgPlatformUser {
|
||
id: string
|
||
username: string
|
||
email: string
|
||
/** 姓名(OIDC displayName claim),可能为空 */
|
||
display_name?: string
|
||
/** Casdoor 同步的部门编号/名称(users.dept_code/dept_name,000156 同步态字段)。
|
||
* 从平台用户添加时按 dept_code 自动预选组织架构部门;两者可为空。 */
|
||
dept_code?: string
|
||
dept_name?: string
|
||
in_roster: boolean
|
||
}
|
||
|
||
export const listPlatformUsers = () =>
|
||
get<{ success: boolean; data: OrgPlatformUser[] }>(`${base}/platform-users`)
|
||
|
||
export interface OrgImportEmployee {
|
||
user_id: string
|
||
employee_no?: string
|
||
dept_id: string
|
||
post?: string
|
||
status?: string
|
||
}
|
||
|
||
/** 批量导入员工档案(部门必填,须为已维护部门)。 */
|
||
export const importEmployees = (employees: OrgImportEmployee[]) =>
|
||
post<{ success: boolean; data: { imported: number } }>(`${base}/employees/import`, { employees })
|
||
|
||
export interface OrgUpdateEmployee {
|
||
dept_id: string
|
||
post?: string
|
||
/** 留空表示不变更 */
|
||
status?: string
|
||
}
|
||
|
||
/** 修改员工档案(部门必填;姓名/工号随平台账号,不在可编辑范围)。 */
|
||
export const updateEmployee = (id: string, payload: OrgUpdateEmployee) =>
|
||
put<{ success: boolean; data: OrgEmployee }>(`${base}/employees/${enc(id)}`, payload)
|
||
|
||
// ---- 职称角色 / 企微账号(自培训域迁入组织架构页;/org 域别名路由复用培训
|
||
// handler,角色绑定仍写 module_key='training';权限细控 HR/经理在 handler 内) ----
|
||
|
||
/** 设置员工职称角色(学员为全员隐式角色,由后端保留,前端保存时一并带上)。 */
|
||
export const updateOrgEmployeeRoles = (id: string, roles: string[]) =>
|
||
put<{ success: boolean; data: OrgEmployee }>(`${base}/employees/${enc(id)}/roles`, { roles })
|
||
|
||
/** 维护员工企微账号(培训提醒推送目标;留空即解绑)。 */
|
||
export const updateOrgEmployeeWecomUserid = (id: string, wecomUserid: string) =>
|
||
put<{ success: boolean; data: OrgEmployee }>(`${base}/employees/${enc(id)}/wecom-userid`, {
|
||
wecom_userid: wecomUserid,
|
||
})
|
||
|
||
/** 从 OA 目录按工号批量拉取企微 userid(预览→写入两段式,预览只读)。 */
|
||
export const previewOrgWecomSync = () =>
|
||
post<{ success: boolean; data: WecomSyncSummary }>(`${base}/employees/wecom-userid-sync/preview`)
|
||
|
||
/** OA 同步写入(无冲突时才落库,返回写入统计)。 */
|
||
export const applyOrgWecomSync = () =>
|
||
post<{ success: boolean; data: WecomSyncSummary }>(`${base}/employees/wecom-userid-sync/apply`)
|
||
|
||
// ---- 归属空间收编(登录默认落点;后端 Owner 限定) ----
|
||
// 员工首登自动开通个人空间后,归属指针(users.tenant_id)停在个人空间,登录后
|
||
// 看到的组织架构/培训是个人空间那份空数据;收编把默认落点改回本空间,
|
||
// 成员关系与个人空间数据不变(可经空间切换器改回,非破坏性)。
|
||
|
||
/** 可收编成员:归属空间不在本空间的活跃成员。 */
|
||
export interface OrgAdoptableUser {
|
||
id: string
|
||
username: string
|
||
display_name: string
|
||
email: string
|
||
home_tenant_id: number
|
||
home_tenant_name: string
|
||
in_roster: boolean
|
||
}
|
||
|
||
/** 单条收编跳过记录(非本空间成员/停用/跨空间账号等,原因逐条回传)。 */
|
||
export interface OrgAdoptSkip {
|
||
user_id: string
|
||
username: string
|
||
display_name: string
|
||
reason: string
|
||
}
|
||
|
||
export interface OrgAdoptResult {
|
||
adopted: number
|
||
skipped: OrgAdoptSkip[]
|
||
}
|
||
|
||
/** 收编预览:归属空间不在本空间的活跃成员列表。 */
|
||
export const listAdoptableUsers = () =>
|
||
get<{ success: boolean; data: OrgAdoptableUser[] }>(`${base}/employees/adoptable`)
|
||
|
||
/** 批量收编:把成员的归属空间(登录默认落点)改为本空间。 */
|
||
export const adoptHomeTenant = (userIds: string[]) =>
|
||
post<{ success: boolean; data: OrgAdoptResult }>(`${base}/employees/adopt-home`, { user_ids: userIds })
|
||
|
||
// ---- 模块角色绑定 ----
|
||
|
||
export const listModuleMembers = (moduleKey: OrgModuleKey) =>
|
||
get<{ success: boolean; data: OrgModuleMember[] }>(
|
||
`${base}/modules/${enc(moduleKey)}/members`,
|
||
)
|
||
|
||
export const putModuleMember = (moduleKey: OrgModuleKey, employeeId: string, roles: string[]) =>
|
||
put<{ success: boolean; data: OrgModuleMember }>(
|
||
`${base}/modules/${enc(moduleKey)}/members/${enc(employeeId)}`,
|
||
{ roles },
|
||
)
|
||
|
||
// ---- 内部小工具 ----
|
||
|
||
function enc(value: string) {
|
||
return encodeURIComponent(value)
|
||
}
|