midway-fatcms 0.0.1-beta.13 → 0.0.1-beta.16
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/README.md +7 -0
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +21 -8
- package/dist/controller/base/BaseApiController.d.ts +1 -1
- package/dist/controller/gateway/AsyncTaskController.js +17 -6
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +5 -5
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
- package/dist/libs/crud-pro/CrudPro.js +5 -0
- package/dist/libs/crud-pro/defaultConfigs.js +2 -0
- package/dist/libs/crud-pro/interfaces.d.ts +6 -0
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +2 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
- package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
- package/dist/libs/crud-pro/models/ResModel.js +2 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +22 -11
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.js +3 -2
- package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +31 -7
- package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
- package/dist/libs/global-config/global-config.d.ts +6 -0
- package/dist/libs/global-config/global-config.js +1 -0
- package/dist/models/AsyncTaskModel.d.ts +13 -11
- package/dist/models/AsyncTaskModel.js +23 -23
- package/dist/schedule/anonymousContext.d.ts +13 -0
- package/dist/schedule/anonymousContext.js +59 -0
- package/dist/schedule/index.d.ts +4 -4
- package/dist/schedule/index.js +9 -68
- package/dist/schedule/runSchedule.d.ts +6 -0
- package/dist/schedule/runSchedule.js +34 -0
- package/dist/schedule/scheduleNames.d.ts +8 -0
- package/dist/schedule/scheduleNames.js +17 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +14 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +66 -16
- package/dist/service/asyncTask/AsyncTaskService.js +2 -1
- package/dist/service/crudstd/CrudStdService.d.ts +1 -0
- package/dist/service/crudstd/CrudStdService.js +27 -0
- package/dist/service/curd/CrudProQuick.d.ts +24 -0
- package/dist/service/curd/CrudProQuick.js +105 -0
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +10 -1
- package/dist/service/curd/CurdMixByLinkToCustomService.js +71 -23
- package/dist/service/curd/CurdMixService.d.ts +1 -1
- package/dist/service/curd/CurdMixService.js +2 -2
- package/dist/service/curd/CurdMixUtils.js +35 -28
- package/dist/service/curd/CurdProService.d.ts +2 -10
- package/dist/service/curd/CurdProService.js +28 -143
- package/dist/service/curd/fixCfgModel.d.ts +3 -0
- package/dist/service/curd/fixCfgModel.js +107 -0
- package/package.json +1 -1
- package/src/configuration.ts +30 -10
- package/src/controller/gateway/AnyApiGatewayController.ts +1 -1
- package/src/controller/gateway/AsyncTaskController.ts +21 -8
- package/src/controller/gateway/CrudMtdGatewayController.ts +5 -5
- package/src/controller/manage/DocManageApi.ts +5 -5
- package/src/index.ts +7 -0
- package/src/libs/crud-pro/CrudPro.ts +8 -0
- package/src/libs/crud-pro/defaultConfigs.ts +2 -0
- package/src/libs/crud-pro/interfaces.ts +10 -1
- package/src/libs/crud-pro/models/ExecuteContext.ts +5 -2
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +12 -1
- package/src/libs/crud-pro/models/ResModel.ts +24 -0
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +26 -17
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +5 -8
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +43 -9
- package/src/libs/crud-pro/utils/DatabaseName.ts +35 -15
- package/src/libs/global-config/global-config.ts +12 -1
- package/src/models/AsyncTaskModel.ts +14 -11
- package/src/schedule/anonymousContext.ts +79 -0
- package/src/schedule/index.ts +13 -72
- package/src/schedule/runSchedule.ts +35 -0
- package/src/schedule/scheduleNames.ts +20 -0
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +91 -24
- package/src/service/asyncTask/AsyncTaskService.ts +3 -2
- package/src/service/base/BaseService.ts +2 -2
- package/src/service/crudstd/CrudStdService.ts +34 -6
- package/src/service/curd/CrudProQuick.ts +137 -0
- package/src/service/curd/CurdMixByLinkToCustomService.ts +100 -49
- package/src/service/curd/CurdMixService.ts +3 -3
- package/src/service/curd/CurdMixUtils.ts +51 -38
- package/src/service/curd/CurdProService.ts +42 -186
- package/src/service/curd/fixCfgModel.ts +139 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ from 'lodash';
|
|
2
2
|
import {Config, Inject, Provide} from '@midwayjs/core';
|
|
3
|
-
import {CrudPro} from '
|
|
3
|
+
import {CrudPro} from '@/libs/crud-pro/CrudPro';
|
|
4
4
|
import {Context} from '@midwayjs/koa';
|
|
5
5
|
import {
|
|
6
6
|
IConnectionPool,
|
|
@@ -8,27 +8,26 @@ import {
|
|
|
8
8
|
IRequestCfgModel,
|
|
9
9
|
IRequestModel,
|
|
10
10
|
ISqlCfgModel
|
|
11
|
-
} from '
|
|
12
|
-
import {SqlCfgModel} from '
|
|
11
|
+
} from '@/libs/crud-pro/interfaces';
|
|
12
|
+
import {SqlCfgModel} from '@/libs/crud-pro/models/SqlCfgModel';
|
|
13
13
|
import {getConnectionPool as getMySQLConnectionPool} from '../../libs/crud-pro/utils/pool/MySQLUtils';
|
|
14
14
|
import {getConnectionPool as getPostgresConnectionPool} from '../../libs/crud-pro/utils/pool/PostgresUtils';
|
|
15
15
|
import {getConnectionPool as getSqlServerConnectionPool} from '../../libs/crud-pro/utils/pool/SqlServerUtils';
|
|
16
|
-
import {
|
|
17
|
-
import {CommonException, Exceptions} from '
|
|
18
|
-
import {UserSessionInfo} from '
|
|
19
|
-
import {BaseExecuteContextFunc} from '
|
|
20
|
-
import {ExecuteContext, IExecuteContextHandler} from '
|
|
16
|
+
import { SqlDbType} from '@/libs/crud-pro/models/keys';
|
|
17
|
+
import {CommonException, Exceptions} from '@/libs/crud-pro/exceptions';
|
|
18
|
+
import {UserSessionInfo} from '@/models/userSession';
|
|
19
|
+
import {BaseExecuteContextFunc} from '@/libs/crud-pro/models/ExecuteContextFunc';
|
|
20
|
+
import {ExecuteContext, IExecuteContextHandler} from '@/libs/crud-pro/models/ExecuteContext';
|
|
21
21
|
import {RelatedType} from './CurdMixUtils';
|
|
22
22
|
import {BaseService} from '../base/BaseService';
|
|
23
23
|
import {
|
|
24
|
-
CTX_VISITOR_ACCOUNT_TYPE,
|
|
25
|
-
CTX_VISITOR_AVATAR,
|
|
26
|
-
CTX_VISITOR_ID,
|
|
27
|
-
CTX_VISITOR_NICKNAME,
|
|
28
24
|
IRequestCfgModel2,
|
|
29
25
|
IVisitorExt,
|
|
30
|
-
} from '
|
|
31
|
-
import {IWorkbenchEntity} from '
|
|
26
|
+
} from '@/models/bizmodels';
|
|
27
|
+
import {IWorkbenchEntity} from '@/models/SystemEntities';
|
|
28
|
+
import {CrudProQuick} from "@/service/curd/CrudProQuick";
|
|
29
|
+
import {fixCfgModel} from "./fixCfgModel";
|
|
30
|
+
import {GLOBAL_STATIC_CONFIG} from "@/libs/global-config/global-config";
|
|
32
31
|
|
|
33
32
|
function toVisitor(ctx: Context): IVisitorExt {
|
|
34
33
|
const workbenchInfo: IWorkbenchEntity = ctx.workbenchInfo;
|
|
@@ -87,6 +86,7 @@ class MyContextFunc extends BaseExecuteContextFunc {
|
|
|
87
86
|
if (sqlDbType === SqlDbType.postgres) {
|
|
88
87
|
const dbConfig = _.get(this.postgres2Config, dataBaseName);
|
|
89
88
|
if (!dbConfig) {
|
|
89
|
+
console.error('postgres配置中不存在此数据库', JSON.stringify(sqlCfgModel));
|
|
90
90
|
throw new CommonException(Exceptions.DB_NOT_FOUND, 'postgres配置中不存在此数据库:' + dataBaseName);
|
|
91
91
|
}
|
|
92
92
|
return getPostgresConnectionPool(dataBaseName, dbConfig);
|
|
@@ -95,6 +95,7 @@ class MyContextFunc extends BaseExecuteContextFunc {
|
|
|
95
95
|
if (sqlDbType === SqlDbType.sqlserver) {
|
|
96
96
|
const dbConfig = _.get(this.sqlserver2Config, dataBaseName);
|
|
97
97
|
if (!dbConfig) {
|
|
98
|
+
console.error('sqlserver配置中不存在此数据库', JSON.stringify(sqlCfgModel));
|
|
98
99
|
throw new CommonException(Exceptions.DB_NOT_FOUND, 'sqlserver配置中不存在此数据库:' + dataBaseName);
|
|
99
100
|
}
|
|
100
101
|
return getSqlServerConnectionPool(dataBaseName, dbConfig);
|
|
@@ -102,6 +103,7 @@ class MyContextFunc extends BaseExecuteContextFunc {
|
|
|
102
103
|
|
|
103
104
|
const dbConfig = _.get(this.mysql2Config, dataBaseName);
|
|
104
105
|
if (!dbConfig) {
|
|
106
|
+
console.error('MySQL配置中不存在此数据库', JSON.stringify(sqlCfgModel));
|
|
105
107
|
throw new CommonException(Exceptions.DB_NOT_FOUND, 'MySQL配置中不存在此数据库:' + dataBaseName);
|
|
106
108
|
}
|
|
107
109
|
return getMySQLConnectionPool(dataBaseName, dbConfig);
|
|
@@ -118,50 +120,23 @@ class MyContextFunc extends BaseExecuteContextFunc {
|
|
|
118
120
|
}
|
|
119
121
|
return null;
|
|
120
122
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export class DBUtils {
|
|
124
|
-
private readonly sqlDatabase: string;
|
|
125
|
-
private readonly sqlDbType: SqlDbType;
|
|
126
|
-
private readonly curdProService: CurdProService;
|
|
127
123
|
|
|
128
|
-
constructor(sqlDatabase: string, sqlDbType: SqlDbType, curdProService: CurdProService) {
|
|
129
|
-
this.sqlDatabase = sqlDatabase;
|
|
130
|
-
this.sqlDbType = sqlDbType;
|
|
131
|
-
this.curdProService = curdProService;
|
|
132
|
-
}
|
|
133
124
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
125
|
+
/**
|
|
126
|
+
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
127
|
+
* @param reqJson
|
|
128
|
+
* @param cfgJson
|
|
129
|
+
*/
|
|
130
|
+
async beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any> {
|
|
131
|
+
const { bizUpdateCfgModelForCrudPro } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
132
|
+
if (typeof bizUpdateCfgModelForCrudPro === "function") {
|
|
133
|
+
await bizUpdateCfgModelForCrudPro(reqJson, cfgJson)
|
|
134
|
+
}
|
|
135
|
+
return Promise.resolve();
|
|
144
136
|
}
|
|
145
137
|
|
|
146
|
-
public async getList(reqJson: IRequestModel, sqlTable: string): Promise<any[]> {
|
|
147
|
-
const cfgModel: IRequestCfgModel = {
|
|
148
|
-
sqlTable,
|
|
149
|
-
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
150
|
-
sqlDatabase: this.sqlDatabase,
|
|
151
|
-
sqlDbType: this.sqlDbType,
|
|
152
|
-
updateCfg: {},
|
|
153
|
-
};
|
|
154
|
-
const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
|
|
155
|
-
return res.getResRows();
|
|
156
|
-
}
|
|
157
138
|
}
|
|
158
139
|
|
|
159
|
-
function isSimpleQuery(sqlSimpleName: KeysOfSimpleSQL): boolean {
|
|
160
|
-
return sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY ||
|
|
161
|
-
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_COUNT ||
|
|
162
|
-
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_PAGE ||
|
|
163
|
-
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_ONE
|
|
164
|
-
}
|
|
165
140
|
|
|
166
141
|
@Provide()
|
|
167
142
|
export class CurdProService extends BaseService {
|
|
@@ -196,9 +171,15 @@ export class CurdProService extends BaseService {
|
|
|
196
171
|
|
|
197
172
|
const crudPro = new CrudPro();
|
|
198
173
|
crudPro.transaction = this.ctx.transaction;
|
|
199
|
-
crudPro.logger = this.getContextLogger();
|
|
174
|
+
crudPro.logger = this.getContextLogger() as any;
|
|
200
175
|
crudPro.visitor = visitor;
|
|
201
|
-
|
|
176
|
+
|
|
177
|
+
const crudProCfg: ICrudProCfg = this.crudProCfg || {};
|
|
178
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
179
|
+
crudProCfg.sysDatabaseName = SystemDbName;
|
|
180
|
+
crudProCfg.sysDatabaseDbType = SystemDbType;
|
|
181
|
+
|
|
182
|
+
crudPro.contextCfg = crudProCfg;
|
|
202
183
|
|
|
203
184
|
crudPro.contextFunc = new MyContextFunc({
|
|
204
185
|
mysql2Config: this.mysql2Config,
|
|
@@ -213,7 +194,7 @@ export class CurdProService extends BaseService {
|
|
|
213
194
|
* 依赖缓存中与加载的配置
|
|
214
195
|
* @param reqJson
|
|
215
196
|
*/
|
|
216
|
-
async executeCrud(reqJson: IRequestModel) {
|
|
197
|
+
async executeCrud(reqJson: IRequestModel): Promise<ExecuteContext> {
|
|
217
198
|
if (!reqJson.method) {
|
|
218
199
|
throw new Error('Method not implemented');
|
|
219
200
|
}
|
|
@@ -234,141 +215,16 @@ export class CurdProService extends BaseService {
|
|
|
234
215
|
// 直接执行一个请求
|
|
235
216
|
async executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2): Promise<ExecuteContext> {
|
|
236
217
|
this.logInfo('executeCrudByCfg', cfgModel);
|
|
237
|
-
|
|
238
|
-
if (!cfgModel.method) {
|
|
239
|
-
const req = this.ctx.req;
|
|
240
|
-
if (req) {
|
|
241
|
-
cfgModel.method = `${req.method}:${req.url}`;
|
|
242
|
-
} else {
|
|
243
|
-
cfgModel.method = 'anonymous';
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!cfgModel.updateCfg) {
|
|
248
|
-
cfgModel.updateCfg = {};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// 应用标准的updateCfg
|
|
252
|
-
this.applyStandardUpdateCfg(cfgModel);
|
|
253
|
-
|
|
254
218
|
const curdPro = this.getCrudPro();
|
|
255
|
-
return await curdPro.executeCrudByCfg(reqJson, cfgModel);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
219
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
|
|
264
|
-
const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
|
|
265
|
-
|
|
266
|
-
// 彻底关闭
|
|
267
|
-
if (enableStandardUpdateCfg === false) {
|
|
268
|
-
return ;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const getDataCfgArray = ()=>{
|
|
272
|
-
// 明确有配置
|
|
273
|
-
if (Array.isArray(enableStandardUpdateCfg)) {
|
|
274
|
-
if (enableStandardUpdateCfg.includes('null')) {
|
|
275
|
-
return [];
|
|
276
|
-
}
|
|
277
|
-
return enableStandardUpdateCfg;
|
|
278
|
-
}
|
|
279
|
-
// update 、insert 添加 by
|
|
280
|
-
return ['by']; // 创建/修改语句默认添加by
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const getConditionCfgArray = ()=>{
|
|
284
|
-
// 明确有配置
|
|
285
|
-
if (Array.isArray(enableStandardUpdateCfgCondition)) {
|
|
286
|
-
if (enableStandardUpdateCfgCondition.includes('null')) {
|
|
287
|
-
return [];
|
|
288
|
-
}
|
|
289
|
-
return enableStandardUpdateCfgCondition;
|
|
290
|
-
}
|
|
291
|
-
return [];
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const dataCfgArray = getDataCfgArray();
|
|
296
|
-
const conditionCfgArray = getConditionCfgArray();
|
|
297
|
-
|
|
298
|
-
const mapping = {
|
|
299
|
-
|
|
300
|
-
'condition.created_by': {contextAsString: CTX_VISITOR_ID},
|
|
301
|
-
'condition.created_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
302
|
-
|
|
303
|
-
'data.created_by': {contextAsString: CTX_VISITOR_ID},
|
|
304
|
-
'data.created_avatar': {contextAsString: CTX_VISITOR_AVATAR},
|
|
305
|
-
'data.created_nickname': {contextAsString: CTX_VISITOR_NICKNAME},
|
|
306
|
-
'data.created_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
307
|
-
|
|
308
|
-
'data.modified_by': {contextAsString: CTX_VISITOR_ID},
|
|
309
|
-
'data.modified_avatar': {contextAsString: CTX_VISITOR_AVATAR},
|
|
310
|
-
'data.modified_nickname': {contextAsString: CTX_VISITOR_NICKNAME},
|
|
311
|
-
'data.modified_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const buildUpdateCfgBy = (cfgArray: string[], prefix: string): any => {
|
|
316
|
-
const obj: any = {};
|
|
317
|
-
if (Array.isArray(cfgArray)) {
|
|
318
|
-
for (let i = 0; i < cfgArray.length; i++) {
|
|
319
|
-
const suffix = cfgArray[i];
|
|
320
|
-
if (suffix) {
|
|
321
|
-
const key = `${prefix}_${suffix}`
|
|
322
|
-
obj[key] = mapping[key]
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return obj;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// 查询语句
|
|
330
|
-
if (isSimpleQuery(sqlSimpleName) ) {
|
|
331
|
-
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
|
|
332
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// 删除语句
|
|
336
|
-
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_DELETE) {
|
|
337
|
-
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
|
|
338
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// 插入语句
|
|
342
|
-
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT) {
|
|
343
|
-
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.created')
|
|
344
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// 更新语句
|
|
348
|
-
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
349
|
-
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.modified')
|
|
350
|
-
const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
351
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
352
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// 插入或更新
|
|
356
|
-
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE ||
|
|
357
|
-
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
|
|
358
|
-
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.created')
|
|
359
|
-
const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray,'data.modified')
|
|
360
|
-
const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
361
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
362
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
363
|
-
Object.assign(cfgModel.updateCfg, updateCfgObj3);
|
|
364
|
-
}
|
|
220
|
+
// 应用标准的updateCfg。
|
|
221
|
+
fixCfgModel(cfgModel);
|
|
222
|
+
return await curdPro.executeCrudByCfg(reqJson, cfgModel);
|
|
365
223
|
}
|
|
366
224
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
getBbUtil(database: string, sqlDbType: SqlDbType): DBUtils {
|
|
371
|
-
return new DBUtils(database, sqlDbType, this);
|
|
225
|
+
getBbUtil(sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string): CrudProQuick {
|
|
226
|
+
const curdPro = this.getCrudPro();
|
|
227
|
+
return new CrudProQuick(curdPro, sqlDatabase, sqlDbType, sqlTable);
|
|
372
228
|
}
|
|
373
229
|
|
|
374
230
|
public async getCachedCfgByMethod(method: string): Promise<IRequestCfgModel> {
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CTX_VISITOR_ACCOUNT_TYPE,
|
|
3
|
+
CTX_VISITOR_AVATAR,
|
|
4
|
+
CTX_VISITOR_ID,
|
|
5
|
+
CTX_VISITOR_NICKNAME,
|
|
6
|
+
IRequestCfgModel2
|
|
7
|
+
} from "@/models/bizmodels";
|
|
8
|
+
import {KeysOfSimpleSQL} from "@/libs/crud-pro/models/keys";
|
|
9
|
+
|
|
10
|
+
function isSimpleQuery(sqlSimpleName: KeysOfSimpleSQL): boolean {
|
|
11
|
+
return sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY ||
|
|
12
|
+
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_COUNT ||
|
|
13
|
+
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_PAGE ||
|
|
14
|
+
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_QUERY_ONE
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
function fixCfgModel(cfgModel: IRequestCfgModel2 ){
|
|
20
|
+
|
|
21
|
+
if (!cfgModel.method) {
|
|
22
|
+
cfgModel.method = 'anonymous';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!cfgModel.updateCfg) {
|
|
26
|
+
cfgModel.updateCfg = {};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const sqlSimpleName = cfgModel.sqlSimpleName;
|
|
30
|
+
|
|
31
|
+
const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
|
|
32
|
+
const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
|
|
33
|
+
|
|
34
|
+
// 彻底关闭
|
|
35
|
+
if (enableStandardUpdateCfg === false) {
|
|
36
|
+
return ;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getDataCfgArray = ()=>{
|
|
40
|
+
// 明确有配置
|
|
41
|
+
if (Array.isArray(enableStandardUpdateCfg)) {
|
|
42
|
+
if (enableStandardUpdateCfg.includes('null')) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return enableStandardUpdateCfg;
|
|
46
|
+
}
|
|
47
|
+
// update 、insert 添加 by
|
|
48
|
+
return ['by']; // 创建/修改语句默认添加by
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getConditionCfgArray = ()=>{
|
|
52
|
+
// 明确有配置
|
|
53
|
+
if (Array.isArray(enableStandardUpdateCfgCondition)) {
|
|
54
|
+
if (enableStandardUpdateCfgCondition.includes('null')) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return enableStandardUpdateCfgCondition;
|
|
58
|
+
}
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const dataCfgArray = getDataCfgArray();
|
|
64
|
+
const conditionCfgArray = getConditionCfgArray();
|
|
65
|
+
|
|
66
|
+
const mapping = {
|
|
67
|
+
|
|
68
|
+
'condition.created_by': {contextAsString: CTX_VISITOR_ID},
|
|
69
|
+
'condition.created_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
70
|
+
|
|
71
|
+
'data.created_by': {contextAsString: CTX_VISITOR_ID},
|
|
72
|
+
'data.created_avatar': {contextAsString: CTX_VISITOR_AVATAR},
|
|
73
|
+
'data.created_nickname': {contextAsString: CTX_VISITOR_NICKNAME},
|
|
74
|
+
'data.created_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
75
|
+
|
|
76
|
+
'data.modified_by': {contextAsString: CTX_VISITOR_ID},
|
|
77
|
+
'data.modified_avatar': {contextAsString: CTX_VISITOR_AVATAR},
|
|
78
|
+
'data.modified_nickname': {contextAsString: CTX_VISITOR_NICKNAME},
|
|
79
|
+
'data.modified_account_type': {contextAsString: CTX_VISITOR_ACCOUNT_TYPE},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const buildUpdateCfgBy = (cfgArray: string[], prefix: string): any => {
|
|
84
|
+
const obj: any = {};
|
|
85
|
+
if (Array.isArray(cfgArray)) {
|
|
86
|
+
for (let i = 0; i < cfgArray.length; i++) {
|
|
87
|
+
const suffix = cfgArray[i];
|
|
88
|
+
if (suffix) {
|
|
89
|
+
const key = `${prefix}_${suffix}`
|
|
90
|
+
obj[key] = mapping[key]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 查询语句
|
|
98
|
+
if (isSimpleQuery(sqlSimpleName) ) {
|
|
99
|
+
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
|
|
100
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 删除语句
|
|
104
|
+
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_DELETE) {
|
|
105
|
+
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
|
|
106
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 插入语句
|
|
110
|
+
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT) {
|
|
111
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.created')
|
|
112
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 更新语句
|
|
116
|
+
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
117
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.modified')
|
|
118
|
+
const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
119
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
120
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 插入或更新
|
|
124
|
+
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE ||
|
|
125
|
+
sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
|
|
126
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray,'data.created')
|
|
127
|
+
const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray,'data.modified')
|
|
128
|
+
const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
129
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
130
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
131
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj3);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
fixCfgModel
|
|
139
|
+
}
|