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
package/README.md
CHANGED
package/dist/configuration.d.ts
CHANGED
package/dist/configuration.js
CHANGED
|
@@ -27,6 +27,7 @@ const global_middleware_1 = require("./middleware/global.middleware");
|
|
|
27
27
|
const forbidden_middleware_1 = require("./middleware/forbidden.middleware");
|
|
28
28
|
const schedule_1 = require("./schedule");
|
|
29
29
|
const crypto_utils_1 = require("./libs/utils/crypto-utils");
|
|
30
|
+
const scheduleNames_1 = require("./schedule/scheduleNames");
|
|
30
31
|
let ContainerLifeCycle = class ContainerLifeCycle {
|
|
31
32
|
async onConfigLoad() {
|
|
32
33
|
const config = this.app.getConfig();
|
|
@@ -50,20 +51,32 @@ let ContainerLifeCycle = class ContainerLifeCycle {
|
|
|
50
51
|
return newConfig;
|
|
51
52
|
}
|
|
52
53
|
async onReady() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const scheduleServiceList = ['proxyApiLoadService', 'workbenchService', 'visitStatService', 'asyncTaskRunnerService'];
|
|
58
|
-
await (0, schedule_1.startSchedule)(this.app, scheduleServiceList);
|
|
59
|
-
logger.info('ContainerLifeCycle ==> onReady 启动定时任务 ');
|
|
60
|
-
}
|
|
54
|
+
/**
|
|
55
|
+
* 启动定时任务
|
|
56
|
+
*/
|
|
57
|
+
await this.startScheduleOnReady();
|
|
61
58
|
// add middleware
|
|
62
59
|
this.app.useMiddleware(forbidden_middleware_1.ForbiddenMiddleware);
|
|
63
60
|
this.app.useMiddleware(global_middleware_1.GlobalMiddleware);
|
|
64
61
|
// add filter
|
|
65
62
|
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
|
|
66
63
|
}
|
|
64
|
+
async startScheduleOnReady() {
|
|
65
|
+
const logger = this.app.getLogger();
|
|
66
|
+
const config = this.app.getConfig();
|
|
67
|
+
const fatcmsScheduleService = config.fatcmsScheduleService;
|
|
68
|
+
// 关闭定时任务
|
|
69
|
+
if (fatcmsScheduleService === false || fatcmsScheduleService === null) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
let scheduleServiceList = scheduleNames_1.ALL_SCHEDULE_NAMES;
|
|
73
|
+
// 启动部分定时任务
|
|
74
|
+
if (Array.isArray(fatcmsScheduleService)) {
|
|
75
|
+
scheduleServiceList = fatcmsScheduleService;
|
|
76
|
+
}
|
|
77
|
+
await (0, schedule_1.startScheduleLoop)(scheduleServiceList);
|
|
78
|
+
logger.info('ContainerLifeCycle ==> onReady 启动定时任务 : ' + JSON.stringify(scheduleServiceList));
|
|
79
|
+
}
|
|
67
80
|
};
|
|
68
81
|
__decorate([
|
|
69
82
|
(0, core_1.App)(),
|
|
@@ -25,7 +25,7 @@ export declare class BaseApiController extends BaseService {
|
|
|
25
25
|
* @protected
|
|
26
26
|
*/
|
|
27
27
|
protected executeSysSimpleSQL(sqlTable: string, sqlSimpleName: KeysOfSimpleSQL, params?: IExecuteSimpleSqlParams): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
28
|
-
protected get sysDBUtil(): import("../..").
|
|
28
|
+
protected get sysDBUtil(): import("../..").CrudProQuick;
|
|
29
29
|
private addAccountBasicInfoCfgModel;
|
|
30
30
|
private addWorkbenchBasicInfoCfgModel;
|
|
31
31
|
}
|
|
@@ -20,6 +20,13 @@ const AsyncTaskModel_1 = require("../../models/AsyncTaskModel");
|
|
|
20
20
|
const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
21
21
|
const SystemTables_1 = require("../../models/SystemTables");
|
|
22
22
|
const exceptions_1 = require("../../libs/crud-pro/exceptions");
|
|
23
|
+
const permission_middleware_1 = require("../../middleware/permission.middleware");
|
|
24
|
+
function fixMyTasksCondition(body, ctx) {
|
|
25
|
+
if (!body.condition) {
|
|
26
|
+
throw new exceptions_1.CommonException("参数不正确");
|
|
27
|
+
}
|
|
28
|
+
body.condition.created_by = ctx.userSession.getSessionInfo().accountId;
|
|
29
|
+
}
|
|
23
30
|
function fixCancelBodyData(body, id) {
|
|
24
31
|
if (!body.data || !body.condition) {
|
|
25
32
|
throw new exceptions_1.CommonException("参数不正确");
|
|
@@ -30,16 +37,19 @@ function fixCancelBodyData(body, id) {
|
|
|
30
37
|
body.condition = conditionObj;
|
|
31
38
|
// fix data
|
|
32
39
|
const dataObj = (body.data || {});
|
|
33
|
-
dataObj.task_status = AsyncTaskModel_1.
|
|
40
|
+
dataObj.task_status = AsyncTaskModel_1.SysAsyncTaskStatus.CANCELLED;
|
|
34
41
|
body.data = dataObj;
|
|
35
42
|
}
|
|
36
|
-
function fixCreateBodyData(body) {
|
|
43
|
+
function fixCreateBodyData(body, ctx) {
|
|
37
44
|
if (!body.data) {
|
|
38
45
|
throw new exceptions_1.CommonException("参数不正确");
|
|
39
46
|
}
|
|
47
|
+
const sessionInfo = ctx.userSession.getSessionInfo();
|
|
40
48
|
// fix data
|
|
41
49
|
const dataObj = (body.data || {});
|
|
42
|
-
dataObj.task_status = AsyncTaskModel_1.
|
|
50
|
+
dataObj.task_status = AsyncTaskModel_1.SysAsyncTaskStatus.PENDING;
|
|
51
|
+
dataObj.created_by = sessionInfo.accountId;
|
|
52
|
+
dataObj.created_user_session = JSON.stringify(sessionInfo); // 创建人的session信息。用于执行时的鉴权。
|
|
43
53
|
}
|
|
44
54
|
/**
|
|
45
55
|
* 异步任务框架
|
|
@@ -47,11 +57,12 @@ function fixCreateBodyData(body) {
|
|
|
47
57
|
let AsyncTaskController = class AsyncTaskController extends BaseApiController_1.BaseApiController {
|
|
48
58
|
// 获取任务列表
|
|
49
59
|
async getMyTasks() {
|
|
60
|
+
fixMyTasksCondition(this.ctx.request.body, this.ctx);
|
|
50
61
|
return this.executeSysSimpleSQL(SystemTables_1.SystemTables.sys_async_tasks, keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
51
62
|
}
|
|
52
63
|
// 创建任务
|
|
53
64
|
async createTask() {
|
|
54
|
-
fixCreateBodyData(this.ctx.request.body);
|
|
65
|
+
fixCreateBodyData(this.ctx.request.body, this.ctx);
|
|
55
66
|
const res = await this.executeSysSimpleSQL(SystemTables_1.SystemTables.sys_async_tasks, keys_1.KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
56
67
|
await this.asyncTaskService.startTask();
|
|
57
68
|
return res;
|
|
@@ -73,7 +84,7 @@ __decorate([
|
|
|
73
84
|
__metadata("design:type", AsyncTaskService_1.AsyncTaskService)
|
|
74
85
|
], AsyncTaskController.prototype, "asyncTaskService", void 0);
|
|
75
86
|
__decorate([
|
|
76
|
-
(0, core_1.
|
|
87
|
+
(0, core_1.Post)('/getMyTasks'),
|
|
77
88
|
__metadata("design:type", Function),
|
|
78
89
|
__metadata("design:paramtypes", []),
|
|
79
90
|
__metadata("design:returntype", Promise)
|
|
@@ -92,6 +103,6 @@ __decorate([
|
|
|
92
103
|
__metadata("design:returntype", Promise)
|
|
93
104
|
], AsyncTaskController.prototype, "cancelTask", null);
|
|
94
105
|
AsyncTaskController = __decorate([
|
|
95
|
-
(0, core_1.Controller)('/ns/gw/AsyncTask')
|
|
106
|
+
(0, core_1.Controller)('/ns/gw/AsyncTask', { middleware: [(0, permission_middleware_1.checkLogin)()] })
|
|
96
107
|
], AsyncTaskController);
|
|
97
108
|
exports.AsyncTaskController = AsyncTaskController;
|
|
@@ -3,9 +3,9 @@ import { CommonResult } from '../../libs/utils/common-dto';
|
|
|
3
3
|
import { WorkbenchService } from '../../service/WorkbenchService';
|
|
4
4
|
import { ApiBaseService } from '../../service/base/ApiBaseService';
|
|
5
5
|
/**
|
|
6
|
-
* query形式1:GET: /ns/gw/
|
|
7
|
-
* query形式2:GET: /ns/gw/
|
|
8
|
-
* query形式3:GET: /ns/gw/
|
|
6
|
+
* query形式1:GET: /ns/gw/crudApi/getUser?__query_json__=%7B%22condition%22%3A%7B%22id%22%3A2%7D%7D
|
|
7
|
+
* query形式2:GET: /ns/gw/crudApi/getUser?__query_as__=condition&id=1&name=22
|
|
8
|
+
* query形式3:GET: /ns/gw/crudApi/createUser?__query_as__=data&__query_pick__=id,name&id=1&name=22
|
|
9
9
|
*
|
|
10
10
|
* 执行单个配置的接口
|
|
11
11
|
*/
|
|
@@ -31,11 +31,11 @@ function pickAsQuery(query_as_pick, query) {
|
|
|
31
31
|
}
|
|
32
32
|
return query;
|
|
33
33
|
}
|
|
34
|
-
// /ns/gw/
|
|
34
|
+
// /ns/gw/crudApi/getUser?__query_as_condition__=id&_query_as_data__=name&&id=1&name=22
|
|
35
35
|
/**
|
|
36
|
-
* query形式1:GET: /ns/gw/
|
|
37
|
-
* query形式2:GET: /ns/gw/
|
|
38
|
-
* query形式3:GET: /ns/gw/
|
|
36
|
+
* query形式1:GET: /ns/gw/crudApi/getUser?__query_json__=%7B%22condition%22%3A%7B%22id%22%3A2%7D%7D
|
|
37
|
+
* query形式2:GET: /ns/gw/crudApi/getUser?__query_as__=condition&id=1&name=22
|
|
38
|
+
* query形式3:GET: /ns/gw/crudApi/createUser?__query_as__=data&__query_pick__=id,name&id=1&name=22
|
|
39
39
|
*
|
|
40
40
|
* 执行单个配置的接口
|
|
41
41
|
*/
|
|
@@ -51,7 +51,7 @@ let CrudMtdGatewayController = class CrudMtdGatewayController extends ApiBaseSer
|
|
|
51
51
|
if (!methodInfo || methodInfo.status !== 1) {
|
|
52
52
|
return common_dto_1.CommonResult.errorRes('接口不存在或已下线: ' + methodCode);
|
|
53
53
|
}
|
|
54
|
-
this.logInfo(
|
|
54
|
+
this.logInfo('methodInfo=== ', methodInfo);
|
|
55
55
|
const workbench_code_array = methodInfo.workbench_code_array || methodInfo.workbenchCodeArray;
|
|
56
56
|
const isSupport = await this.workbenchService.isSupportCurrentWorkbench(workbench_code_array);
|
|
57
57
|
if (!isSupport) {
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './controller/gateway/FileController';
|
|
|
8
8
|
export * from './controller/gateway/ProxyApiGatewayController';
|
|
9
9
|
export * from './controller/gateway/PublicApiController';
|
|
10
10
|
export * from './controller/gateway/StaticController';
|
|
11
|
+
export * from './controller/gateway/AsyncTaskController';
|
|
11
12
|
export * from './controller/helpers.controller';
|
|
12
13
|
export * from './controller/home.controller';
|
|
13
14
|
export * from './controller/manage/AnyApiMangeApi';
|
|
@@ -63,8 +64,11 @@ export * from './service/curd/CurdMixBySysConfigService';
|
|
|
63
64
|
export * from './service/curd/CurdMixByWorkbenchService';
|
|
64
65
|
export * from './service/curd/CurdMixService';
|
|
65
66
|
export * from './service/curd/CurdProService';
|
|
67
|
+
export * from './service/curd/CrudProQuick';
|
|
66
68
|
export * from './service/proxyapi/ProxyApiLoadService';
|
|
67
69
|
export * from './service/proxyapi/ProxyApiService';
|
|
70
|
+
export * from './service/asyncTask/AsyncTaskService';
|
|
71
|
+
export * from './service/asyncTask/AsyncTaskRunnerService';
|
|
68
72
|
export * from './models/userSession';
|
|
69
73
|
export * from './models/bizmodels';
|
|
70
74
|
export * from './models/SystemEntities';
|
|
@@ -72,6 +76,8 @@ export * from './models/SystemPerm';
|
|
|
72
76
|
export * from './models/contextLogger';
|
|
73
77
|
export * from './models/devops';
|
|
74
78
|
export * from './models/SystemTables';
|
|
79
|
+
export * from './models/AsyncTaskModel';
|
|
80
|
+
export * from './schedule/index';
|
|
75
81
|
export * from './libs/utils/common-dto';
|
|
76
82
|
export * from './libs/utils/crypto-utils';
|
|
77
83
|
export * from './libs/utils/fatcms-request';
|
|
@@ -91,4 +97,5 @@ export * from './libs/crud-pro/models/keys';
|
|
|
91
97
|
export * from './libs/crud-pro/models/ExecuteContextFunc';
|
|
92
98
|
export * from './libs/crud-pro/models/RequestCfgModel';
|
|
93
99
|
export * from './libs/crud-pro/models/SqlSegArg';
|
|
100
|
+
export * from './libs/crud-pro/models/ResModel';
|
|
94
101
|
export * from './libs/global-config/global-config';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./controller/gateway/FileController"), exports);
|
|
|
26
26
|
__exportStar(require("./controller/gateway/ProxyApiGatewayController"), exports);
|
|
27
27
|
__exportStar(require("./controller/gateway/PublicApiController"), exports);
|
|
28
28
|
__exportStar(require("./controller/gateway/StaticController"), exports);
|
|
29
|
+
__exportStar(require("./controller/gateway/AsyncTaskController"), exports);
|
|
29
30
|
__exportStar(require("./controller/helpers.controller"), exports);
|
|
30
31
|
__exportStar(require("./controller/home.controller"), exports);
|
|
31
32
|
__exportStar(require("./controller/manage/AnyApiMangeApi"), exports);
|
|
@@ -81,8 +82,11 @@ __exportStar(require("./service/curd/CurdMixBySysConfigService"), exports);
|
|
|
81
82
|
__exportStar(require("./service/curd/CurdMixByWorkbenchService"), exports);
|
|
82
83
|
__exportStar(require("./service/curd/CurdMixService"), exports);
|
|
83
84
|
__exportStar(require("./service/curd/CurdProService"), exports);
|
|
85
|
+
__exportStar(require("./service/curd/CrudProQuick"), exports);
|
|
84
86
|
__exportStar(require("./service/proxyapi/ProxyApiLoadService"), exports);
|
|
85
87
|
__exportStar(require("./service/proxyapi/ProxyApiService"), exports);
|
|
88
|
+
__exportStar(require("./service/asyncTask/AsyncTaskService"), exports);
|
|
89
|
+
__exportStar(require("./service/asyncTask/AsyncTaskRunnerService"), exports);
|
|
86
90
|
__exportStar(require("./models/userSession"), exports);
|
|
87
91
|
__exportStar(require("./models/bizmodels"), exports);
|
|
88
92
|
__exportStar(require("./models/SystemEntities"), exports);
|
|
@@ -90,6 +94,8 @@ __exportStar(require("./models/SystemPerm"), exports);
|
|
|
90
94
|
__exportStar(require("./models/contextLogger"), exports);
|
|
91
95
|
__exportStar(require("./models/devops"), exports);
|
|
92
96
|
__exportStar(require("./models/SystemTables"), exports);
|
|
97
|
+
__exportStar(require("./models/AsyncTaskModel"), exports);
|
|
98
|
+
__exportStar(require("./schedule/index"), exports);
|
|
93
99
|
__exportStar(require("./libs/utils/common-dto"), exports);
|
|
94
100
|
__exportStar(require("./libs/utils/crypto-utils"), exports);
|
|
95
101
|
__exportStar(require("./libs/utils/fatcms-request"), exports);
|
|
@@ -109,4 +115,5 @@ __exportStar(require("./libs/crud-pro/models/keys"), exports);
|
|
|
109
115
|
__exportStar(require("./libs/crud-pro/models/ExecuteContextFunc"), exports);
|
|
110
116
|
__exportStar(require("./libs/crud-pro/models/RequestCfgModel"), exports);
|
|
111
117
|
__exportStar(require("./libs/crud-pro/models/SqlSegArg"), exports);
|
|
118
|
+
__exportStar(require("./libs/crud-pro/models/ResModel"), exports);
|
|
112
119
|
__exportStar(require("./libs/global-config/global-config"), exports);
|
|
@@ -75,6 +75,8 @@ class CrudPro {
|
|
|
75
75
|
async executeCrudByCfg(reqJson, cfgJson) {
|
|
76
76
|
const logger = this.executeContext.getLogger();
|
|
77
77
|
logger.info('CurdPro executeCrudByCfg', cfgJson);
|
|
78
|
+
// 在执行之前可以根据业务需要修改需要执行的内容。
|
|
79
|
+
await this.beforeExecuteSQLList(reqJson, cfgJson);
|
|
78
80
|
const exeCtx = this.executeContext;
|
|
79
81
|
if (!cfgJson.method) {
|
|
80
82
|
throw new exceptions_1.CommonException(exceptions_1.Exceptions.CFG_METHOD_EMPTY, JSON.stringify(cfgJson));
|
|
@@ -127,5 +129,8 @@ class CrudPro {
|
|
|
127
129
|
async afterExecuteSQLList() {
|
|
128
130
|
return this.executeContext.contextFunc.afterExecuteSQLList();
|
|
129
131
|
}
|
|
132
|
+
async beforeExecuteSQLList(reqJson, cfgJson) {
|
|
133
|
+
return this.executeContext.contextFunc.beforeExecuteSQLList(reqJson, cfgJson);
|
|
134
|
+
}
|
|
130
135
|
}
|
|
131
136
|
exports.CrudPro = CrudPro;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_LIMIT = exports.DEFAULT_MAX_LIMIT = exports.defaultCrudProCfg = void 0;
|
|
4
|
+
const keys_1 = require("./models/keys");
|
|
4
5
|
exports.defaultCrudProCfg = {
|
|
5
6
|
sysDatabaseName: 'fatcms',
|
|
7
|
+
sysDatabaseDbType: keys_1.SqlDbType.mysql,
|
|
6
8
|
sysConfigTableName: 'sys_configs',
|
|
7
9
|
dictItemTableName: 'sys_data_dict_item',
|
|
8
10
|
methodsTableName: 'sys_crud_methods',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeysOfAuthType, KeysOfSimpleSQL, KeysOfValidators, SqlDbType } from './models/keys';
|
|
2
2
|
export interface ICrudProCfg {
|
|
3
3
|
sysDatabaseName?: string;
|
|
4
|
+
sysDatabaseDbType?: SqlDbType;
|
|
4
5
|
methodsTableName?: string;
|
|
5
6
|
methodsCacheTime?: number;
|
|
6
7
|
dictItemTableName?: string;
|
|
@@ -154,4 +155,9 @@ export interface ILogger {
|
|
|
154
155
|
error(msg: any, ...args: any[]): void;
|
|
155
156
|
warn(msg: any, ...args: any[]): void;
|
|
156
157
|
}
|
|
158
|
+
export interface IExecuteUnsafeQueryCtx {
|
|
159
|
+
sqlTable: string;
|
|
160
|
+
sqlDatabase: string;
|
|
161
|
+
sqlDbType: SqlDbType;
|
|
162
|
+
}
|
|
157
163
|
export {};
|
|
@@ -4,6 +4,7 @@ import { SqlCfgModel } from './SqlCfgModel';
|
|
|
4
4
|
import { Transaction } from './Transaction';
|
|
5
5
|
import { ICrudProCfg, ILogger, IVisitor } from '../interfaces';
|
|
6
6
|
import { IExecuteContextFunc } from './ExecuteContextFunc';
|
|
7
|
+
import { ResModelFlexible } from "./ResModel";
|
|
7
8
|
declare class ExecuteContext {
|
|
8
9
|
private transaction;
|
|
9
10
|
private logger;
|
|
@@ -24,7 +25,7 @@ declare class ExecuteContext {
|
|
|
24
25
|
getVisitor(): IVisitor;
|
|
25
26
|
getReqModel(): RequestModel;
|
|
26
27
|
setReqModel(reqModel: RequestModel): void;
|
|
27
|
-
getResModel():
|
|
28
|
+
getResModel(): ResModelFlexible;
|
|
28
29
|
getOneObj(): any;
|
|
29
30
|
getResRows(): any[];
|
|
30
31
|
setResModelItem(resName: string, data: any): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IConnectionPool } from '../interfaces';
|
|
1
|
+
import { IConnectionPool, IRequestCfgModel, IRequestModel } from '../interfaces';
|
|
2
2
|
import { ExecuteContext } from './ExecuteContext';
|
|
3
3
|
import { SqlCfgModel } from './SqlCfgModel';
|
|
4
4
|
import { RequestCfgModel } from './RequestCfgModel';
|
|
@@ -10,6 +10,7 @@ export interface IExecuteContextFunc {
|
|
|
10
10
|
getFunctionMap(): any;
|
|
11
11
|
validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): Promise<any>;
|
|
12
12
|
afterExecuteSQLList(): Promise<any>;
|
|
13
|
+
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any>;
|
|
13
14
|
}
|
|
14
15
|
export declare class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
15
16
|
private executeContext;
|
|
@@ -26,6 +27,12 @@ export declare class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
|
26
27
|
* @param exeCtx
|
|
27
28
|
*/
|
|
28
29
|
afterExecuteSQLList(): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
32
|
+
* @param reqJson
|
|
33
|
+
* @param cfgJson
|
|
34
|
+
*/
|
|
35
|
+
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any>;
|
|
29
36
|
getExecuteContext(): ExecuteContext;
|
|
30
37
|
setExecuteContext(executeContext: ExecuteContext): void;
|
|
31
38
|
}
|
|
@@ -54,6 +54,14 @@ class BaseExecuteContextFunc {
|
|
|
54
54
|
afterExecuteSQLList() {
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
59
|
+
* @param reqJson
|
|
60
|
+
* @param cfgJson
|
|
61
|
+
*/
|
|
62
|
+
beforeExecuteSQLList(reqJson, cfgJson) {
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
}
|
|
57
65
|
getExecuteContext() {
|
|
58
66
|
return this.executeContext;
|
|
59
67
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface ResModelAffected {
|
|
2
|
+
insertId?: string | number;
|
|
3
|
+
affectedRows: number;
|
|
4
|
+
}
|
|
5
|
+
interface ResModelStandard {
|
|
6
|
+
row?: any;
|
|
7
|
+
rows?: any[];
|
|
8
|
+
total_count?: number;
|
|
9
|
+
affected?: ResModelAffected;
|
|
10
|
+
insert_affected?: ResModelAffected;
|
|
11
|
+
update_affected?: ResModelAffected;
|
|
12
|
+
}
|
|
13
|
+
declare type ResModelFlexible = ResModelStandard & {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
export { ResModelAffected, ResModelStandard, ResModelFlexible };
|
|
@@ -4,6 +4,7 @@ import { ICurdProServiceHub } from '../models/ServiceHub';
|
|
|
4
4
|
declare class CrudProCachedCfgService extends CrudProServiceBase {
|
|
5
5
|
constructor(serviceHub: ICurdProServiceHub);
|
|
6
6
|
getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null>;
|
|
7
|
+
private getCachedCfgByMethodInner;
|
|
7
8
|
private loadMethodInfo;
|
|
8
9
|
private loadMethodInfoList;
|
|
9
10
|
}
|
|
@@ -17,25 +17,35 @@ class CrudProCachedCfgService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
17
17
|
super(serviceHub);
|
|
18
18
|
}
|
|
19
19
|
async getCachedCfgByMethod(method, isEnableCache) {
|
|
20
|
+
const methodInfo = await this.getCachedCfgByMethodInner(method, isEnableCache);
|
|
21
|
+
if (!methodInfo) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return { ...methodInfo };
|
|
25
|
+
}
|
|
26
|
+
async getCachedCfgByMethodInner(method, isEnableCache) {
|
|
20
27
|
// 不使用缓存
|
|
21
28
|
if (!isEnableCache) {
|
|
22
29
|
return await this.loadMethodInfo(method);
|
|
23
30
|
}
|
|
24
31
|
methodCache.setProps({
|
|
25
|
-
keepTime:
|
|
32
|
+
keepTime: 1000 * 60 * 2,
|
|
26
33
|
requestFn: () => this.loadMethodInfoList(),
|
|
27
34
|
getKeyFn: item => item.method,
|
|
28
35
|
});
|
|
29
|
-
|
|
36
|
+
const methodInfo = await methodCache.getItem(method);
|
|
37
|
+
if (methodInfo) {
|
|
38
|
+
return methodInfo;
|
|
39
|
+
}
|
|
40
|
+
return await this.loadMethodInfo(method);
|
|
30
41
|
}
|
|
31
42
|
async loadMethodInfo(method) {
|
|
32
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
33
|
-
const sql = `select *
|
|
34
|
-
from ${methodsTableName}
|
|
35
|
-
where method = ? `; // 全部加载到内存
|
|
43
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
44
|
+
const sql = `select * from ${methodsTableName} where method = ? `; // 全部加载到内存
|
|
36
45
|
const baseInfo = {
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
sqlTable: methodsTableName,
|
|
47
|
+
sqlDatabase: sysDatabaseName,
|
|
48
|
+
sqlDbType: sysDatabaseDbType,
|
|
39
49
|
};
|
|
40
50
|
const [rows] = await this.executeUnsafeQuery(baseInfo, sql, [method]);
|
|
41
51
|
const rows2 = rows;
|
|
@@ -45,11 +55,12 @@ class CrudProCachedCfgService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
45
55
|
return null;
|
|
46
56
|
}
|
|
47
57
|
async loadMethodInfoList() {
|
|
48
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
58
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
49
59
|
const sql = `select * from ${methodsTableName}`; // 全部加载到内存
|
|
50
60
|
const baseInfo = {
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
sqlTable: methodsTableName,
|
|
62
|
+
sqlDatabase: sysDatabaseName,
|
|
63
|
+
sqlDbType: sysDatabaseDbType
|
|
53
64
|
};
|
|
54
65
|
const [rows] = await this.executeUnsafeQuery(baseInfo, sql);
|
|
55
66
|
const rows2 = rows;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { ICurdProServiceHub } from '../models/ServiceHub';
|
|
2
|
-
import { ICrudProCfg, ILogger, IPoolConnectionClient } from '../interfaces';
|
|
2
|
+
import { ICrudProCfg, IExecuteUnsafeQueryCtx, ILogger, IPoolConnectionClient } from '../interfaces';
|
|
3
3
|
import { SqlCfgModel } from '../models/SqlCfgModel';
|
|
4
4
|
import { ExecuteContext } from '../models/ExecuteContext';
|
|
5
5
|
import { IExecuteContextFunc } from '../models/ExecuteContextFunc';
|
|
6
|
-
interface ExecuteUnsafeQueryCtx {
|
|
7
|
-
tableName: string;
|
|
8
|
-
dbName: string;
|
|
9
|
-
}
|
|
10
6
|
declare class CrudProServiceBase {
|
|
11
7
|
protected serviceHub: ICurdProServiceHub;
|
|
12
8
|
constructor(serviceHub: ICurdProServiceHub);
|
|
@@ -21,7 +17,7 @@ declare class CrudProServiceBase {
|
|
|
21
17
|
* @param values
|
|
22
18
|
* @protected
|
|
23
19
|
*/
|
|
24
|
-
protected executeUnsafeQuery(obj:
|
|
20
|
+
protected executeUnsafeQuery(obj: IExecuteUnsafeQueryCtx, sql: string, values?: any): Promise<any[]>;
|
|
25
21
|
protected getContextCfg(): ICrudProCfg;
|
|
26
22
|
protected getExecuteFunction(funcName: string): any;
|
|
27
23
|
}
|
|
@@ -45,8 +45,9 @@ class CrudProServiceBase {
|
|
|
45
45
|
*/
|
|
46
46
|
async executeUnsafeQuery(obj, sql, values) {
|
|
47
47
|
const sqlCfgModel = {
|
|
48
|
-
sqlTable: obj.
|
|
49
|
-
sqlDatabase: obj.
|
|
48
|
+
sqlTable: obj.sqlTable,
|
|
49
|
+
sqlDatabase: obj.sqlDatabase,
|
|
50
|
+
sqlDbType: obj.sqlDbType,
|
|
50
51
|
columns: [],
|
|
51
52
|
columnsRelation: [],
|
|
52
53
|
maxLimit: defaultConfigs_1.DEFAULT_MAX_LIMIT,
|
|
@@ -4,5 +4,6 @@ import { ITableMeta } from '../interfaces';
|
|
|
4
4
|
declare class CrudProTableMetaService extends CrudProServiceBase {
|
|
5
5
|
getTableMeta(sqlCfgModel: SqlCfgModel): Promise<ITableMeta>;
|
|
6
6
|
private loadTableMeta;
|
|
7
|
+
private loadTableColumnInfo;
|
|
7
8
|
}
|
|
8
9
|
export { CrudProTableMetaService };
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CrudProTableMetaService = void 0;
|
|
4
4
|
const CrudProServiceBase_1 = require("./CrudProServiceBase");
|
|
5
|
+
const keys_1 = require("../models/keys");
|
|
6
|
+
const convertPgType_1 = require("../utils/sqlConvert/convertPgType");
|
|
5
7
|
class CrudProTableMetaCache {
|
|
6
8
|
constructor() {
|
|
7
9
|
this.cacheMap = {};
|
|
@@ -39,15 +41,37 @@ class CrudProTableMetaService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
39
41
|
tableColumns: [],
|
|
40
42
|
};
|
|
41
43
|
const baseInfo = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
sqlTable: sqlCfgModel.sqlTable,
|
|
45
|
+
sqlDatabase: sqlCfgModel.sqlDatabase,
|
|
46
|
+
sqlDbType: sqlCfgModel.sqlDbType
|
|
44
47
|
};
|
|
45
|
-
|
|
46
|
-
const tableDescribe2 = JSON.parse(JSON.stringify(tableDescribe));
|
|
47
|
-
obj.tableColumns = tableDescribe2.map(fieldObj => {
|
|
48
|
-
return fieldObj['Field'];
|
|
49
|
-
});
|
|
48
|
+
obj.tableColumns = await this.loadTableColumnInfo(baseInfo);
|
|
50
49
|
return obj;
|
|
51
50
|
}
|
|
51
|
+
async loadTableColumnInfo(baseInfo) {
|
|
52
|
+
if (baseInfo.sqlDbType === keys_1.SqlDbType.mysql) {
|
|
53
|
+
const [tableDescribe] = await this.executeUnsafeQuery(baseInfo, 'describe ' + baseInfo.sqlTable);
|
|
54
|
+
const tableDescribe2 = JSON.parse(JSON.stringify(tableDescribe));
|
|
55
|
+
return tableDescribe2.map(fieldObj => {
|
|
56
|
+
return fieldObj['Field'];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (baseInfo.sqlDbType === keys_1.SqlDbType.postgres) {
|
|
60
|
+
const schemaname = 'public';
|
|
61
|
+
const columnArraySql = `
|
|
62
|
+
SELECT
|
|
63
|
+
*
|
|
64
|
+
FROM information_schema.columns
|
|
65
|
+
WHERE table_schema = '${schemaname}' and table_name = '${baseInfo.sqlTable}'
|
|
66
|
+
ORDER BY ordinal_position;
|
|
67
|
+
`.trim();
|
|
68
|
+
const queryRes = await this.executeUnsafeQuery(baseInfo, columnArraySql);
|
|
69
|
+
const rows = (0, convertPgType_1.pickAndConvertPgRows)(queryRes);
|
|
70
|
+
return rows.map(fieldObj => {
|
|
71
|
+
return fieldObj['column_name'];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
throw new Error("暂不支持的数据库类型:" + baseInfo.sqlDbType);
|
|
75
|
+
}
|
|
52
76
|
}
|
|
53
77
|
exports.CrudProTableMetaService = CrudProTableMetaService;
|
|
@@ -2,14 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toDatabaseNameStr = exports.parseDatabaseName = exports.SPLIT_CONST = void 0;
|
|
4
4
|
const keys_1 = require("../models/keys");
|
|
5
|
-
const SPLIT_CONST =
|
|
5
|
+
const SPLIT_CONST = '_________';
|
|
6
6
|
exports.SPLIT_CONST = SPLIT_CONST;
|
|
7
|
+
const PREFIX_MYSQL = `${keys_1.SqlDbType.mysql}${SPLIT_CONST}`;
|
|
8
|
+
const PREFIX_POSTGRES = `${keys_1.SqlDbType.postgres}${SPLIT_CONST}`;
|
|
9
|
+
const PREFIX_SQLSERVER = `${keys_1.SqlDbType.sqlserver}${SPLIT_CONST}`;
|
|
7
10
|
function parseDatabaseName(databaseName) {
|
|
8
11
|
const dbNameArr = databaseName.split(SPLIT_CONST);
|
|
12
|
+
if (databaseName.startsWith(PREFIX_MYSQL)) {
|
|
13
|
+
return {
|
|
14
|
+
dbType: keys_1.SqlDbType.mysql,
|
|
15
|
+
dbName: dbNameArr[1],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (databaseName.startsWith(PREFIX_POSTGRES)) {
|
|
19
|
+
return {
|
|
20
|
+
dbType: keys_1.SqlDbType.postgres,
|
|
21
|
+
dbName: dbNameArr[1],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (databaseName.startsWith(PREFIX_SQLSERVER)) {
|
|
25
|
+
return {
|
|
26
|
+
dbType: keys_1.SqlDbType.sqlserver,
|
|
27
|
+
dbName: dbNameArr[1],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
9
30
|
if (dbNameArr.length === 1) {
|
|
10
31
|
return {
|
|
11
32
|
dbType: keys_1.SqlDbType.mysql,
|
|
12
|
-
dbName: dbNameArr[0]
|
|
33
|
+
dbName: dbNameArr[0],
|
|
13
34
|
};
|
|
14
35
|
}
|
|
15
36
|
if (dbNameArr.length > 1) {
|
|
@@ -17,7 +38,7 @@ function parseDatabaseName(databaseName) {
|
|
|
17
38
|
const dbType = dbType0;
|
|
18
39
|
return {
|
|
19
40
|
dbType,
|
|
20
|
-
dbName
|
|
41
|
+
dbName,
|
|
21
42
|
};
|
|
22
43
|
}
|
|
23
44
|
return null;
|
|
@@ -16,6 +16,12 @@ interface IGlobalStaticConfig {
|
|
|
16
16
|
* @param ctx
|
|
17
17
|
*/
|
|
18
18
|
bizUpdateCfgModelForCrudMtd(reqJson: any, cfgModel: any, methodInfo: any, ctx: any): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* CrudPro: 业务系统自定义的修改cfgModel。这是最底层的!!全局的!!全局的!!全局的!!!
|
|
21
|
+
* @param reqJson
|
|
22
|
+
* @param cfgModel
|
|
23
|
+
*/
|
|
24
|
+
bizUpdateCfgModelForCrudPro(reqJson: any, cfgModel: any): Promise<any>;
|
|
19
25
|
/**
|
|
20
26
|
* 生成用户的账号ID,业务系统可以生成类似工号的ID
|
|
21
27
|
* @param userSubmitData
|
|
@@ -10,6 +10,7 @@ class GlobalStaticConfig {
|
|
|
10
10
|
this.configObject = {
|
|
11
11
|
bizUpdateCfgModelForCrudStd: noop,
|
|
12
12
|
bizUpdateCfgModelForCrudMtd: noop,
|
|
13
|
+
bizUpdateCfgModelForCrudPro: noop,
|
|
13
14
|
generateUserAccountId: null,
|
|
14
15
|
toFatcmsUserAccountId: (bizTableUserId) => {
|
|
15
16
|
return bizTableUserId;
|