fix: 组织架构根部门自动创建为公司名

1. 注册时自动创建根部门(公司名,level=0),作为组织架构顶层节点
2. 部门列表查询时兼容历史组织:若无任何部门,自动补建根部门
3. 创建部门时若未指定父部门,默认挂到根部门下
4. 前端 OrgChart:
   - 根部门显示"公司"标签,不可编辑/删除
   - 新增部门时默认父部门为根部门
   - 上级部门下拉移除"无(根部门)"选项,改为列出所有可选部门

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
selfrelease
2026-08-16 09:16:31 +08:00
parent c2c99126be
commit 9a826c16b0
3 changed files with 72 additions and 24 deletions
+13
View File
@@ -27,6 +27,19 @@ export async function register(orgName: string, phone: string, password: string)
},
})
// 自动创建根部门(公司名),作为组织架构的顶层节点
await prisma.department.create({
data: {
orgId: org.id,
name: orgName,
parentId: null,
level: 0,
sortOrder: 0,
description: '组织根节点',
createdBy: user.id,
},
})
await prisma.user.update({
where: { id: user.id },
data: { lastLoginAt: new Date() },