From 7ccb9032902a6b4ba83a5c4680f232bee782bacf Mon Sep 17 00:00:00 2001 From: cool Date: Mon, 11 Mar 2024 19:14:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=BA=E5=88=B6=E8=AE=BE=E7=BD=AE=E5=AE=9E?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/package.json | 2 +- core/src/package.json | 2 +- core/src/service/base.ts | 33 ++++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/core/package.json b/core/package.json index 3b39c2f..d19f68f 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "7.1.6", + "version": "7.1.7", "description": "", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/core/src/package.json b/core/src/package.json index 5d6bb2c..d7749ce 100644 --- a/core/src/package.json +++ b/core/src/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "7.1.6", + "version": "7.1.7", "description": "", "main": "index.js", "typings": "index.d.ts", diff --git a/core/src/service/base.ts b/core/src/service/base.ts index 15bfc68..b45d3c4 100644 --- a/core/src/service/base.ts +++ b/core/src/service/base.ts @@ -55,14 +55,14 @@ export abstract class BaseService { baseApp: Application; @Init() - async init(){ + async init() { const services = { mysql: this.baseMysqlService, postgres: this.basePgService, - sqlite: this.baseSqliteService + sqlite: this.baseSqliteService, }; this.service = services[this.ormType]; - if(!this.service) throw new CoolCoreException('暂不支持当前数据库类型'); + if (!this.service) throw new CoolCoreException("暂不支持当前数据库类型"); this.sqlParams = this.service.sqlParams; await this.service.init(); } @@ -79,7 +79,6 @@ export abstract class BaseService { this.service.setCtx(ctx); } - // 设置应用对象 setApp(app: Application) { this.baseApp = app; @@ -104,11 +103,11 @@ export abstract class BaseService { return this.service.getCountSql(sql); } - /** + /** * 参数安全性检查 * @param params */ - async paramSafetyCheck(params) { + async paramSafetyCheck(params) { return await this.service.paramSafetyCheck(params); } @@ -153,7 +152,12 @@ export abstract class BaseService { * @param connectionName 连接名称 */ async sqlRenderPage(sql, query, autoSort = true, connectionName?) { - return await this.service.sqlRenderPage(sql, query, autoSort, connectionName); + return await this.service.sqlRenderPage( + sql, + query, + autoSort, + connectionName + ); } /** @@ -162,6 +166,7 @@ export abstract class BaseService { * @param infoIgnoreProperty 忽略返回属性 */ async info(id: any, infoIgnoreProperty?: string[]) { + this.service.setEntity(this.entity); return await this.service.info(id, infoIgnoreProperty); } @@ -170,6 +175,7 @@ export abstract class BaseService { * @param ids 删除的ID集合 如:[1,2,3] 或者 1,2,3 */ async delete(ids: any) { + this.service.setEntity(this.entity); await this.modifyBefore(ids, "delete"); await this.service.delete(ids); await this.modifyAfter(ids, "delete"); @@ -181,6 +187,7 @@ export abstract class BaseService { * @param entity 实体 */ async softDelete(ids: number[], entity?: Repository) { + this.service.setEntity(this.entity); await this.service.softDelete(ids, entity); } @@ -189,10 +196,11 @@ export abstract class BaseService { * @param param 数据 */ async update(param: any) { + this.service.setEntity(this.entity); if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY); if (!param.id && !(param instanceof Array)) throw new CoolValidateException(ERRINFO.NOID); - await this.addOrUpdate(param,'update') + await this.addOrUpdate(param, "update"); } /** @@ -201,7 +209,7 @@ export abstract class BaseService { */ async add(param: any | any[]): Promise { if (!this.entity) throw new CoolValidateException(ERRINFO.NOENTITY); - await this.addOrUpdate(param, 'add'); + await this.addOrUpdate(param, "add"); return { id: param instanceof Array @@ -218,7 +226,8 @@ export abstract class BaseService { * 新增|修改 * @param param 数据 */ - async addOrUpdate(param: any | any[], type: 'add' | 'update' = 'add') { + async addOrUpdate(param: any | any[], type: "add" | "update" = "add") { + this.service.setEntity(this.entity); await this.modifyBefore(param, type); await this.service.addOrUpdate(param, type); await this.modifyAfter(param, type); @@ -231,6 +240,7 @@ export abstract class BaseService { * @param connectionName 连接名 */ async list(query, option, connectionName?): Promise { + this.service.setEntity(this.entity); return await this.service.list(query, option, connectionName); } @@ -241,6 +251,7 @@ export abstract class BaseService { * @param connectionName 连接名 */ async page(query, option, connectionName?) { + this.service.setEntity(this.entity); return await this.service.page(query, option, connectionName); } @@ -250,6 +261,7 @@ export abstract class BaseService { * @param option */ async getOptionFind(query, option: QueryOp) { + this.service.setEntity(this.entity); return await this.service.getOptionFind(query, option); } @@ -270,5 +282,4 @@ export abstract class BaseService { data: any, type: "delete" | "update" | "add" ): Promise {} - }