@yongdall/organization 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.mts +1 -1
- package/index.mjs +1 -1
- package/{organization-bygDRLDu.mjs → organization-CEkzOuGJ.mjs} +5 -2
- package/organization-CEkzOuGJ.mjs.map +1 -0
- package/package.json +7 -6
- package/yongdall/migration.mjs +10 -0
- package/yongdall/migration.mjs.map +1 -0
- package/yongdall/model.mjs +13 -0
- package/yongdall/model.mjs.map +1 -0
- package/yongdall.plugin.yml +1 -0
- package/hooks.yongdall.mjs +0 -15
- package/hooks.yongdall.mjs.map +0 -1
- package/organization-bygDRLDu.mjs.map +0 -1
package/index.d.mts
CHANGED
|
@@ -15,7 +15,7 @@ declare const Organization: _yongdall_model0.ModelTable<{
|
|
|
15
15
|
id: imodel10.FieldDefine<"uuid", false, false>;
|
|
16
16
|
label: imodel10.FieldDefine<"string", false, false>;
|
|
17
17
|
parentId: imodel10.FieldDefine<"uuid", false, true>;
|
|
18
|
-
typeId: imodel10.FieldDefine<"string",
|
|
18
|
+
typeId: imodel10.FieldDefine<"string", true, false>;
|
|
19
19
|
internal: imodel10.FieldDefine<"bool", false, false>;
|
|
20
20
|
mainId: imodel10.FieldDefine<"uuid", false, true>;
|
|
21
21
|
description: imodel10.FieldDefine<"text", false, true>;
|
package/index.mjs
CHANGED
|
@@ -82,10 +82,13 @@ const Organization = createModel("organization", {
|
|
|
82
82
|
}),
|
|
83
83
|
typeId: createField("string", {
|
|
84
84
|
size: 255,
|
|
85
|
+
array: true,
|
|
85
86
|
nullable: false,
|
|
86
87
|
label: "类型",
|
|
87
88
|
model: "organizationType",
|
|
88
|
-
|
|
89
|
+
source: { value: "id" },
|
|
90
|
+
renderer: "select",
|
|
91
|
+
default: [],
|
|
89
92
|
layout: { colSpan: 6 }
|
|
90
93
|
}),
|
|
91
94
|
internal: createField("bool", {
|
|
@@ -317,4 +320,4 @@ const Organization = createModel("organization", {
|
|
|
317
320
|
|
|
318
321
|
//#endregion
|
|
319
322
|
export { OrganizationType as n, Organization as t };
|
|
320
|
-
//# sourceMappingURL=organization-
|
|
323
|
+
//# sourceMappingURL=organization-CEkzOuGJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization-CEkzOuGJ.mjs","names":[],"sources":["../../plugins/organization/models/OrganizationType.mjs","../../plugins/organization/models/Organization.mjs"],"sourcesContent":["import { createField, createModel, uuid, now } from '@yongdall/model';\n\nexport const OrganizationType = createModel('organizationType', {\n\tid: createField('string', { nullable: false, label: '标识', primary: 1 }),\n\tlabel: createField('string', { nullable: false, default: '', label: '名称' }),\n\tdescription: createField('string', { nullable: true, default: '', label: '描述' }),\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期' }),\n}, {\n\tlabel: '组织类型',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{permission: 'system:organization', fields: '*', authorizations: ['query', 'options', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{permission: 'organization', fields: '*', authorizations: ['query', 'options', 'read'] },\n\t],\n});\n","import { createField, createModel, uuid, now, Query, mergeHooks, Where } from '@yongdall/model';\nimport { useConnection } from '@yongdall/connection';\nimport { nestedSetTree, ServerError } from '@yongdall/core';\n\n// 定义模型\nexport const Organization = createModel('organization', {\n\tid: createField('uuid', { nullable: false, default: uuid, primary: 1, uncreatable: true, layout: { hidden: true } }),\n\tlabel: createField('string', { size: 255, nullable: false, default: '', label: '名称', layout: { colSpan: 6 } }),\n\tparentId: createField('uuid', { nullable: true, label: '上级组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\ttypeId: createField('string', { size: 255, array: true, nullable: false, label: '类型', model: 'organizationType',source: {value: 'id'}, renderer: 'select', default: [], layout: { colSpan: 6 } }),\n\tinternal: createField('bool', { nullable: false, default: false, label: '是否为子组织', layout: { colSpan: 6 } }),\n\tmainId: createField('uuid', { nullable: true, label: '所属主体组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\tdescription: createField('text', { nullable: true, label: '描述' }),\n\n\t// Nested Set 树结构字段,通常由 hook 自动维护,但需定义以便存储\n\tlft: createField('i32', { nullable: false, default: 0, label: 'LFT', layout: { hidden: true } }),\n\trgt: createField('i32', { nullable: false, default: 0, label: 'RGT', layout: { hidden: true } }),\n\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期', layout: { hidden: true } }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期', layout: { hidden: true } }),\n}, {\n\tlabel: '组织',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{ permission: 'system:organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: 'system:organization', fields: ['mainId', 'lft'], authorizations: ['options', 'query', 'read'] },\n\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'mainId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'mainId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'parentId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'parentId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'id', authorizations: ['options', 'query', 'read', 'create', 'update', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'id', authorizations: ['options', 'query', 'read'] },\n\t],\n\thooks: mergeHooks(nestedSetTree('parentId'), {\n\n\t\tasync beforeCreate(conn, Model, document) {\n\t\t\tdelete document.mainId;\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parentId = document.parentId;\n\t\t\t\tif (!parentId) { return; }\n\t\t\t\tconst parent = await conn.first(new Query(Model).where('id', parentId));\n\t\t\t\tif (!parent) {\n\t\t\t\t\tdelete document.parentId;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (parent.internal) {\n\t\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst parentId = document.parentId;\n\t\t\tconst parent = parentId\n\t\t\t\t? await conn.first(new Query(Model).where('id', parentId))\n\t\t\t\t: null;\n\n\t\t\tif (!parent) {\n\t\t\t\tthrow new ServerError('请选择上级组织');\n\t\t\t}\n\n\t\t\tdocument.internal = true;\n\t\t\tdocument.mainId = (parent.internal && parent.mainId) || parent.id;\n\t\t},\n\t\tasync afterCreate(conn, Model, document) {\n\t\t\tif (document.mainId) { return; }\n\t\t\tconst id = document.id;\n\t\t\tif (!await conn.update(Model, { mainId: id }, Where.and('id', id), true)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdocument.mainId = id;\n\t\t},\n\n\t\tasync beforeUpdate(conn, Model, document, set) {\n\t\t\tdelete set.mainId;\n\n\t\t\tconst parentId = set.parentId;\n\t\t\t// 检查 parentId 是否真的改变\n\t\t\tif ((typeof parentId !== 'number' && typeof parentId !== 'string') || parentId === document.parentId) {\n\t\t\t\tdelete set.parentId;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!parentId) {\n\t\t\t\tif (document.internal) {\n\t\t\t\t\tdelete set.parentId;\n\t\t\t\t} else {\n\t\t\t\t\tset.parentId = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parent = await conn.count(\n\t\t\t\t\tnew Query(Model)\n\t\t\t\t\t\t.where('id', parentId)\n\t\t\t\t\t\t.where('internal', false)\n\t\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t}\n\n\t\t\tconst parent = await conn.count(\n\t\t\t\tnew Query(Model)\n\t\t\t\t.where('id', parentId)\n\t\t\t\t.where('mainId', document.mainId)\n\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\tthrow new ServerError('非主体组织,只能调整到同一主体组织下');\n\n\n\t\t}\n\t}),\n});\n\n// 静态方法转换为独立导出函数\n// 使用时需传入 connection 或直接使用模型引用\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getAncestors(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(\n\t\tnew Query(Organization).select('lft', 'rgt').where('id', id)\n\t);\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '<=', lft).where('rgt', '>=', rgt)\n\t);\n\treturn list.map(v => v.id);\n}\n\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getPosterity(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(new Query(Organization).select('lft', 'rgt').where('id', id));\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '>=', lft).where('rgt', '<=', rgt)\n\t);\n\treturn list.map(v => v.id);\n}\n\nexport default Organization;\n"],"mappings":";;;;;AAEA,MAAa,mBAAmB,YAAY,oBAAoB;CAC/D,IAAI,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CACvE,OAAO,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,OAAO;EAAM,CAAC;CAC3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AAE,KAAK,CACvE;AAED,YAAS,SAAS;;EAGnB,MAAM,aAAa,MAAM,OAAO,UAAU,KAAK;AAC9C,UAAO,IAAI;GAEX,MAAM,WAAW,IAAI;AAErB,OAAK,OAAO,aAAa,YAAY,OAAO,aAAa,YAAa,aAAa,SAAS,UAAU;AACrG,WAAO,IAAI;AACX;;AAED,OAAI,CAAC,UAAU;AACd,QAAI,SAAS,SACZ,QAAO,IAAI;QAEX,KAAI,WAAW;AAEhB;;AAGD,OAAI,CAAC,SAAS,UAAU;AAMvB,QALe,MAAM,KAAK,MACzB,IAAI,MAAM,MAAM,CACd,MAAM,MAAM,SAAS,CACrB,MAAM,YAAY,MAAM,CAC1B,CACa;AACd,UAAM,IAAI,YAAY,uBAAuB;;AAQ7C,OALc,MAAM,KAAK,MACzB,IAAI,MAAM,MAAM,CACf,MAAM,MAAM,SAAS,CACrB,MAAM,UAAU,SAAS,OAAO,CACjC,CACc;AACf,SAAM,IAAI,YAAY,qBAAqB;;EAI5C,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/organization",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@yongdall/connection": "^0.
|
|
15
|
-
"@yongdall/context": "^0.
|
|
16
|
-
"@yongdall/model": "^0.
|
|
17
|
-
"@yongdall/core": "^0.
|
|
14
|
+
"@yongdall/connection": "^0.5.0",
|
|
15
|
+
"@yongdall/context": "^0.5.0",
|
|
16
|
+
"@yongdall/model": "^0.5.0",
|
|
17
|
+
"@yongdall/core": "^0.5.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@yongdall/
|
|
20
|
+
"@yongdall/migrate": "^0.5.0",
|
|
21
|
+
"@yongdall/types": "^0.5.0"
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { n as OrganizationType, t as Organization } from "../organization-CEkzOuGJ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/organization/yongdall/migration.mjs
|
|
4
|
+
/** @import { Profile } from '@yongdall/migrate' */
|
|
5
|
+
/** @type {Profile['models']} */
|
|
6
|
+
const models = [OrganizationType, Organization];
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { models };
|
|
10
|
+
//# sourceMappingURL=migration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.mjs","names":[],"sources":["../../../plugins/organization/yongdall/migration.mjs"],"sourcesContent":["/** @import { Profile } from '@yongdall/migrate' */\nimport { OrganizationType, Organization } from '../index.mjs';\n\n\n/** @type {Profile['models']} */\nexport const models = [\n\tOrganizationType,\n\tOrganization,\n]\n"],"mappings":";;;;;AAKA,MAAa,SAAS,CACrB,kBACA,aACA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { n as OrganizationType, t as Organization } from "../organization-CEkzOuGJ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/organization/yongdall/model.mjs
|
|
4
|
+
/** @import { ModelProfile } from '@yongdall/core' */
|
|
5
|
+
/** @type {ModelProfile['models']} */
|
|
6
|
+
const models = {
|
|
7
|
+
organizationType: OrganizationType,
|
|
8
|
+
organization: Organization
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { models };
|
|
13
|
+
//# sourceMappingURL=model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.mjs","names":[],"sources":["../../../plugins/organization/yongdall/model.mjs"],"sourcesContent":["/** @import { ModelProfile } from '@yongdall/core' */\nimport { OrganizationType, Organization } from '../index.mjs';\n\n/** @type {ModelProfile['models']} */\nexport const models = {\n\torganizationType: OrganizationType,\n\torganization: Organization,\n};\n"],"mappings":";;;;;AAIA,MAAa,SAAS;CACrB,kBAAkB;CAClB,cAAc;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
label: 组织架构
|
package/hooks.yongdall.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { n as OrganizationType, t as Organization } from "./organization-bygDRLDu.mjs";
|
|
2
|
-
|
|
3
|
-
//#region plugins/organization/hooks.yongdall.mjs
|
|
4
|
-
/** @import { Hooks } from '@yongdall/core' */
|
|
5
|
-
/** @type {Hooks.Define['models']} */
|
|
6
|
-
const models = {
|
|
7
|
-
organizationType: OrganizationType,
|
|
8
|
-
organization: Organization
|
|
9
|
-
};
|
|
10
|
-
/** @type {Hooks.Define['migrationModels']} */
|
|
11
|
-
const migrationModels = [OrganizationType, Organization];
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { migrationModels, models };
|
|
15
|
-
//# sourceMappingURL=hooks.yongdall.mjs.map
|
package/hooks.yongdall.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../plugins/organization/hooks.yongdall.mjs"],"sourcesContent":["/** @import { Hooks } from '@yongdall/core' */\nimport { OrganizationType, Organization } from './index.mjs';\n\n/** @type {Hooks.Define['models']} */\nexport const models = {\n\torganizationType: OrganizationType,\n\torganization: Organization,\n};\n\n/** @type {Hooks.Define['migrationModels']} */\nexport const migrationModels = [\n\tOrganizationType,\n\tOrganization,\n]\n"],"mappings":";;;;;AAIA,MAAa,SAAS;CACrB,kBAAkB;CAClB,cAAc;CACd;;AAGD,MAAa,kBAAkB,CAC9B,kBACA,aACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"organization-bygDRLDu.mjs","names":[],"sources":["../../plugins/organization/models/OrganizationType.mjs","../../plugins/organization/models/Organization.mjs"],"sourcesContent":["import { createField, createModel, uuid, now } from '@yongdall/model';\n\nexport const OrganizationType = createModel('organizationType', {\n\tid: createField('string', { nullable: false, label: '标识', primary: 1 }),\n\tlabel: createField('string', { nullable: false, default: '', label: '名称' }),\n\tdescription: createField('string', { nullable: true, default: '', label: '描述' }),\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期' }),\n}, {\n\tlabel: '组织类型',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{permission: 'system:organization', fields: '*', authorizations: ['query', 'options', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{permission: 'organization', fields: '*', authorizations: ['query', 'options', 'read'] },\n\t],\n});\n","import { createField, createModel, uuid, now, Query, mergeHooks, Where } from '@yongdall/model';\nimport { useConnection } from '@yongdall/connection';\nimport { nestedSetTree, ServerError } from '@yongdall/core';\n\n// 定义模型\nexport const Organization = createModel('organization', {\n\tid: createField('uuid', { nullable: false, default: uuid, primary: 1, uncreatable: true, layout: { hidden: true } }),\n\tlabel: createField('string', { size: 255, nullable: false, default: '', label: '名称', layout: { colSpan: 6 } }),\n\tparentId: createField('uuid', { nullable: true, label: '上级组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\ttypeId: createField('string', { size: 255, nullable: false, label: '类型', model: 'organizationType', renderer: 'document', layout: { colSpan: 6 } }),\n\tinternal: createField('bool', { nullable: false, default: false, label: '是否为子组织', layout: { colSpan: 6 } }),\n\tmainId: createField('uuid', { nullable: true, label: '所属主体组织', model: 'organization', renderer: 'document', layout: { colSpan: 6 } }),\n\tdescription: createField('text', { nullable: true, label: '描述' }),\n\n\t// Nested Set 树结构字段,通常由 hook 自动维护,但需定义以便存储\n\tlft: createField('i32', { nullable: false, default: 0, label: 'LFT', layout: { hidden: true } }),\n\trgt: createField('i32', { nullable: false, default: 0, label: 'RGT', layout: { hidden: true } }),\n\n\tcreatedAt: createField('timestamp', { nullable: false, creating: now, label: '创建日期', layout: { hidden: true } }),\n\tupdatedAt: createField('timestamp', { nullable: false, updating: now, label: '最后更新日期', layout: { hidden: true } }),\n}, {\n\tlabel: '组织',\n\tlabelField: 'label',\n\tpermissions: [\n\t\t{ permission: 'system:organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: 'system:organization', fields: ['mainId', 'lft'], authorizations: ['options', 'query', 'read'] },\n\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'mainId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'mainId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'parentId', authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'parentId', authorizations: ['options', 'query', 'read'] },\n\t\t{ permission: 'organization', fields: ['id', 'label', 'parentId', 'typeId', 'internal', 'description', 'createdAt', 'updatedAt'], organizationField: 'id', authorizations: ['options', 'query', 'read', 'create', 'update', 'add', 'remove'] },\n\t\t{ permission: '', fields: ['mainId', 'lft'], organizationField: 'id', authorizations: ['options', 'query', 'read'] },\n\t],\n\thooks: mergeHooks(nestedSetTree('parentId'), {\n\n\t\tasync beforeCreate(conn, Model, document) {\n\t\t\tdelete document.mainId;\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parentId = document.parentId;\n\t\t\t\tif (!parentId) { return; }\n\t\t\t\tconst parent = await conn.first(new Query(Model).where('id', parentId));\n\t\t\t\tif (!parent) {\n\t\t\t\t\tdelete document.parentId;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (parent.internal) {\n\t\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst parentId = document.parentId;\n\t\t\tconst parent = parentId\n\t\t\t\t? await conn.first(new Query(Model).where('id', parentId))\n\t\t\t\t: null;\n\n\t\t\tif (!parent) {\n\t\t\t\tthrow new ServerError('请选择上级组织');\n\t\t\t}\n\n\t\t\tdocument.internal = true;\n\t\t\tdocument.mainId = (parent.internal && parent.mainId) || parent.id;\n\t\t},\n\t\tasync afterCreate(conn, Model, document) {\n\t\t\tif (document.mainId) { return; }\n\t\t\tconst id = document.id;\n\t\t\tif (!await conn.update(Model, { mainId: id }, Where.and('id', id), true)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdocument.mainId = id;\n\t\t},\n\n\t\tasync beforeUpdate(conn, Model, document, set) {\n\t\t\tdelete set.mainId;\n\n\t\t\tconst parentId = set.parentId;\n\t\t\t// 检查 parentId 是否真的改变\n\t\t\tif ((typeof parentId !== 'number' && typeof parentId !== 'string') || parentId === document.parentId) {\n\t\t\t\tdelete set.parentId;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!parentId) {\n\t\t\t\tif (document.internal) {\n\t\t\t\t\tdelete set.parentId;\n\t\t\t\t} else {\n\t\t\t\t\tset.parentId = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!document.internal) {\n\t\t\t\tconst parent = await conn.count(\n\t\t\t\t\tnew Query(Model)\n\t\t\t\t\t\t.where('id', parentId)\n\t\t\t\t\t\t.where('internal', false)\n\t\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\t\tthrow new ServerError('主体组织,只能作为其他主体组织的下级组织');\n\t\t\t}\n\n\t\t\tconst parent = await conn.count(\n\t\t\t\tnew Query(Model)\n\t\t\t\t.where('id', parentId)\n\t\t\t\t.where('mainId', document.mainId)\n\t\t\t);\n\t\t\t\tif (parent) { return; }\n\t\t\tthrow new ServerError('非主体组织,只能调整到同一主体组织下');\n\n\n\t\t}\n\t}),\n});\n\n// 静态方法转换为独立导出函数\n// 使用时需传入 connection 或直接使用模型引用\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getAncestors(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(\n\t\tnew Query(Organization).select('lft', 'rgt').where('id', id)\n\t);\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '<=', lft).where('rgt', '>=', rgt)\n\t);\n\treturn list.map(v => v.id);\n}\n\n/**\n * \n * @param {string?} id \n * @returns \n */\nexport async function getPosterity(id) {\n\tif (!id) return [];\n\tconst conn = useConnection('rdb');\n\tconst o = await conn.first(new Query(Organization).select('lft', 'rgt').where('id', id));\n\tif (!o) { return []; }\n\n\tconst { lft, rgt } = o;\n\tconst list = await conn.select(\n\t\tnew Query(Organization).select('id').where('lft', '>=', lft).where('rgt', '<=', rgt)\n\t);\n\treturn list.map(v => v.id);\n}\n\nexport default Organization;\n"],"mappings":";;;;;AAEA,MAAa,mBAAmB,YAAY,oBAAoB;CAC/D,IAAI,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,CAAC;CACvE,OAAO,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,OAAO;EAAM,CAAC;CAC3E,aAAa,YAAY,UAAU;EAAE,UAAU;EAAM,SAAS;EAAI,OAAO;EAAM,CAAC;CAChF,WAAW,YAAY,aAAa;EAAE,UAAU;EAAO,UAAU;EAAK,OAAO;EAAQ,CAAC;CACtF,WAAW,YAAY,aAAa;EAAE,UAAU;EAAO,UAAU;EAAK,OAAO;EAAU,CAAC;CACxF,EAAE;CACF,OAAO;CACP,YAAY;CACZ,aAAa,CACZ;EAAC,YAAY;EAAuB,QAAQ;EAA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