From f96d980254865b87486d13c0d88f4d86f0e6c21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=B9=8F?= Date: Fri, 15 Jul 2022 18:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=94=AF=E6=8C=81=E5=A4=9A?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dict/controller/admin/info.ts | 1 + src/modules/dict/service/info.ts | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/modules/dict/controller/admin/info.ts b/src/modules/dict/controller/admin/info.ts index d1770d0..ebe684a 100644 --- a/src/modules/dict/controller/admin/info.ts +++ b/src/modules/dict/controller/admin/info.ts @@ -10,6 +10,7 @@ import { DictInfoService } from '../../service/info'; @CoolController({ api: ['add', 'delete', 'update', 'info', 'list', 'page'], entity: DictInfoEntity, + service: DictInfoService, listQueryOp: { fieldEq: ['typeId'], keyWordLikeFields: ['name'], diff --git a/src/modules/dict/service/info.ts b/src/modules/dict/service/info.ts index 29d72f1..0c396a7 100644 --- a/src/modules/dict/service/info.ts +++ b/src/modules/dict/service/info.ts @@ -69,4 +69,35 @@ export class DictInfoService extends BaseService { return e.name; }); } + + /** + * 修改之后 + * @param data + * @param type + */ + async modifyAfter(data: any, type: 'delete' | 'update' | 'add') { + if (type === 'delete') { + for (const id of data) { + await this.delChildDict(id); + } + } + } + + /** + * 删除子字典 + * @param id + */ + private async delChildDict(id) { + const delDict = await this.dictInfoEntity.find({ parentId: id }); + if (_.isEmpty(delDict)) { + return; + } + const delDictIds = delDict.map(e => { + return e.id; + }); + await this.dictInfoEntity.delete(delDictIds); + for (const dictId of delDictIds) { + await this.delChildDict(dictId); + } + } }