From c68ddc2818388d9b97258c3b5d4766eeb010fba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=97=E9=98=B3?= <1627320840@qq.com> Date: Thu, 30 Oct 2025 17:10:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E9=80=9A?= =?UTF-8?q?=E7=94=A8=E6=8E=A5=E6=94=B6=E5=A4=84=E7=90=86=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BB=A5=E7=AE=80=E5=8C=96=E6=8E=A5=E6=94=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ts/core/thing/standard/application.ts | 191 ++++++---------------- 1 file changed, 49 insertions(+), 142 deletions(-) diff --git a/src/ts/core/thing/standard/application.ts b/src/ts/core/thing/standard/application.ts index 6e89e3c71..ae74056b8 100644 --- a/src/ts/core/thing/standard/application.ts +++ b/src/ts/core/thing/standard/application.ts @@ -960,6 +960,39 @@ export class Application extends Container implements IAppl } return false; } + // --- receive helpers - START --- + /** 通用接收处理函数(保持与原逻辑完全一致,仅做结构抽象) */ + private handleReceive( + operate: string, + data: TSchema, + list: TInstance[], + coll: any, + create: (data: TSchema) => TInstance, + ) { + switch (operate) { + case 'insert': + coll.cache.push(data); + list.push(create(data)); + break; + case 'remove': + coll.removeCache((i: any) => i.id !== (data as any).id); + list = list.filter((a: any) => a.id !== (data as any).id); + break; + case 'delete': + case 'replace': + const item = list.find((a: any) => a.id === (data as any).id); + if (data && item) { + if (operate === 'delete') { + data = { ...(data as any), isDeleted: true } as TSchema; + } + (item as any).setMetadata(data); + } + break; + default: + break; + } + } + workReceive(operate: string, data: any): boolean { switch (operate) { case 'insert': @@ -981,169 +1014,43 @@ export class Application extends Container implements IAppl .find((i) => i.metadata.primaryId === data.primaryId) ?.receive(operate, data); break; + default: + break; } return true; } + formReceive(operate: string, data: schema.XForm): boolean { - switch (operate) { - case 'insert': - { - this.resource.formColl.cache.push(data); - this.forms.push(new Form(data, this.directory, this)); - } - break; - case 'remove': - this.resource.formColl.removeCache((i) => i.id !== data.id); - this.forms = this.forms.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var form = this.forms.find((a) => a.id === data.id); - if (data && form) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XForm; - } - form.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.forms, this.resource.formColl, (d) => new Form(d, this.directory, this)); return true; } + viewReceive(operate: string, data: schema.XView): boolean { - switch (operate) { - case 'insert': - { - this.resource.viewColl.cache.push(data); - this.views.push(ViewFactory.createView(data, this.directory)); - } - break; - case 'remove': - this.resource.viewColl.removeCache((i) => i.id !== data.id); - this.views = this.views.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var view = this.views.find((a) => a.id === data.id); - if (data && view) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XView; - } - view.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.views, this.resource.viewColl, (d) => ViewFactory.createView(d, this.directory)); return true; } + reportReceive(operate: string, data: schema.XReport): boolean { - switch (operate) { - case 'insert': - { - this.resource.reportColl.cache.push(data); - this.reports.push(new Report(data, this.directory, this)); - } - break; - case 'remove': - this.resource.reportColl.removeCache((i) => i.id !== data.id); - this.reports = this.reports.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var form = this.reports.find((a) => a.id === data.id); - if (data && form) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XReport; - } - form.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.reports, this.resource.reportColl, (d) => new Report(d, this.directory, this)); return true; } + printReceive(operate: string, data: schema.XPrint): boolean { - switch (operate) { - case 'insert': - { - this.resource.printColl.cache.push(data); - this.prints.push(new Print(data, this.directory)); - } - break; - case 'remove': - this.resource.printColl.removeCache((i) => i.id !== data.id); - this.prints = this.prints.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var print = this.prints.find((a) => a.id === data.id); - if (data && print) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XPrint; - } - print.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.prints, this.resource.printColl, (d) => new Print(d, this.directory)); return true; } + documentReceive(operate: string, data: schema.XDocumentTemplate): boolean { - switch (operate) { - case 'insert': - { - this.resource.documentColl.cache.push(data); - this.documents.push(new DocumentTemplate(data, this.directory)); - } - break; - case 'remove': - this.resource.documentColl.removeCache((i) => i.id !== data.id); - this.documents = this.documents.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var document = this.documents.find((a) => a.id === data.id); - if (data && document) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XDocumentTemplate; - } - document.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.documents, this.resource.documentColl, (d) => new DocumentTemplate(d, this.directory)); return true; } + sequenceReceive(operate: string, data: schema.XSequence): boolean { - switch (operate) { - case 'insert': - { - this.sequences.push(new Sequence(data, this.directory)); - } - break; - case 'remove': - this.sequences = this.sequences.filter((a) => a.id !== data.id); - break; - case 'delete': - case 'replace': - var sequence = this.sequences.find((a) => a.id === data.id); - if (data && sequence) { - if (operate === 'delete') { - data = { ...data, isDeleted: true } as unknown as schema.XSequence; - } - sequence.setMetadata(data); - } - break; - default: - break; - } + this.handleReceive(operate, data, this.sequences, this.resource.sequenceColl, (d) => new Sequence(d, this.directory)); return true; } + // --- receive helpers - END --- + /** 业务办事分类 */ async toSpecies(dest: IDirectory): Promise { -- Gitee From 9d45a8c4f07c9d70c671f856aa7b1680f07fc204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=97=E9=98=B3?= <1627320840@qq.com> Date: Fri, 31 Oct 2025 15:59:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E5=88=86?= =?UTF-8?q?=E5=8F=91=E5=BA=94=E7=94=A8=E5=8A=9F=E8=83=BD=E5=8F=8A=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ts/core/thing/standard/application.ts | 77 +---------------------- 1 file changed, 3 insertions(+), 74 deletions(-) diff --git a/src/ts/core/thing/standard/application.ts b/src/ts/core/thing/standard/application.ts index ae74056b8..98919f34a 100644 --- a/src/ts/core/thing/standard/application.ts +++ b/src/ts/core/thing/standard/application.ts @@ -48,8 +48,6 @@ export interface IApplication extends IContainer { loadWorks(reload?: boolean): Promise; /** 加载所有办事 */ loadAllWorks(reload?: boolean): Promise; - /** 分发应用 */ - distribute(destination: IDirectory): Promise; /** 新建办事 */ createWork(data: model.WorkDefineModel): Promise; /** 加载表单 */ @@ -260,7 +258,6 @@ export class Application extends Container implements IAppl children: await this.recursionOperates( this, new Application(application, destination), - 'copy', _isSpanBelong, ), }, @@ -284,66 +281,6 @@ export class Application extends Container implements IAppl children: await this.recursionOperates( this, new Application(appEntity, destApplication.directory, destApplication), - 'copy', - _isSpanBelong, - ), - }, - }); - } - return true; - } - } - } - return false; - } - async distribute(destination: IDirectory): Promise { - if (this.allowDistribute(destination)) { - var _isSpanBelong = this.isSpanBelong(destination); - const appData = { - ...this.metadata, - shareId: destination.target.id, - id: _isSpanBelong ? this.metadata.id : 'snowId()', - }; - switch (destination.typeName) { - case '目录': { - appData.typeName = '应用'; - appData.parentId = ''; - appData.directoryId = destination.id; - const coll = destination.resource.applicationColl; - const application = await coll.replace(appData); - if (application) { - await coll.notify({ - operate: 'insert', - data: { - ...application, - children: await this.recursionOperates( - this, - new Application(application, destination), - 'distribute', - _isSpanBelong, - ), - }, - }); - } - return true; - } - case '应用': { - var destApplication = destination as unknown as IApplication; - appData.typeName = '模块'; - appData.parentId = destApplication.id; - appData.directoryId = destApplication.directory.id; - const directory = destApplication.directory; - const coll = directory.resource.applicationColl; - const appEntity = await coll.replace(appData); - if (appEntity) { - await coll.notify({ - operate: 'insert', - data: { - ...appEntity, - children: await this.recursionOperates( - this, - new Application(appEntity, destApplication.directory, destApplication), - 'distribute', _isSpanBelong, ), }, @@ -460,7 +397,6 @@ export class Application extends Container implements IAppl private async recursionOperates( app: IApplication, dest: IApplication, - cmd: 'copy' | 'distribute', spanBelong: boolean = false, ): Promise { const modules: schema.XApplication[] = []; @@ -479,7 +415,6 @@ export class Application extends Container implements IAppl ...(await this.recursionOperates( child, new Application(appEntity, dest.directory, dest), - cmd, spanBelong, )), ); @@ -522,15 +457,9 @@ export class Application extends Container implements IAppl existSequences.every((s) => s.metadata.sourceId != a.metadata.sourceId), ); } - for (const work of works) { - switch (cmd) { - case 'copy': - await work.copy(dest as unknown as IDirectory); - break; - case 'distribute': - await work.distribute(dest as unknown as IDirectory); - break; - } + + for (const work of works.filter((a) => a.metadata.isDeleted !== true)) { + await work.copy(dest as unknown as IDirectory); } for (const form of forms.filter((a) => a.metadata.isDeleted !== true)) { await form.copy(dest as unknown as IDirectory); -- Gitee