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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixCfgModel = void 0;
|
|
4
|
+
const bizmodels_1 = require("../../models/bizmodels");
|
|
5
|
+
const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
6
|
+
function isSimpleQuery(sqlSimpleName) {
|
|
7
|
+
return sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY ||
|
|
8
|
+
sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_COUNT ||
|
|
9
|
+
sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE ||
|
|
10
|
+
sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE;
|
|
11
|
+
}
|
|
12
|
+
function fixCfgModel(cfgModel) {
|
|
13
|
+
if (!cfgModel.method) {
|
|
14
|
+
cfgModel.method = 'anonymous';
|
|
15
|
+
}
|
|
16
|
+
if (!cfgModel.updateCfg) {
|
|
17
|
+
cfgModel.updateCfg = {};
|
|
18
|
+
}
|
|
19
|
+
const sqlSimpleName = cfgModel.sqlSimpleName;
|
|
20
|
+
const enableStandardUpdateCfg = cfgModel.enableStandardUpdateCfg; // 用于设置data字段
|
|
21
|
+
const enableStandardUpdateCfgCondition = cfgModel.enableStandardUpdateCfgCondition; // 用于设置condition字段
|
|
22
|
+
// 彻底关闭
|
|
23
|
+
if (enableStandardUpdateCfg === false) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const getDataCfgArray = () => {
|
|
27
|
+
// 明确有配置
|
|
28
|
+
if (Array.isArray(enableStandardUpdateCfg)) {
|
|
29
|
+
if (enableStandardUpdateCfg.includes('null')) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
return enableStandardUpdateCfg;
|
|
33
|
+
}
|
|
34
|
+
// update 、insert 添加 by
|
|
35
|
+
return ['by']; // 创建/修改语句默认添加by
|
|
36
|
+
};
|
|
37
|
+
const getConditionCfgArray = () => {
|
|
38
|
+
// 明确有配置
|
|
39
|
+
if (Array.isArray(enableStandardUpdateCfgCondition)) {
|
|
40
|
+
if (enableStandardUpdateCfgCondition.includes('null')) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return enableStandardUpdateCfgCondition;
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
};
|
|
47
|
+
const dataCfgArray = getDataCfgArray();
|
|
48
|
+
const conditionCfgArray = getConditionCfgArray();
|
|
49
|
+
const mapping = {
|
|
50
|
+
'condition.created_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
|
|
51
|
+
'condition.created_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
|
|
52
|
+
'data.created_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
|
|
53
|
+
'data.created_avatar': { contextAsString: bizmodels_1.CTX_VISITOR_AVATAR },
|
|
54
|
+
'data.created_nickname': { contextAsString: bizmodels_1.CTX_VISITOR_NICKNAME },
|
|
55
|
+
'data.created_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
|
|
56
|
+
'data.modified_by': { contextAsString: bizmodels_1.CTX_VISITOR_ID },
|
|
57
|
+
'data.modified_avatar': { contextAsString: bizmodels_1.CTX_VISITOR_AVATAR },
|
|
58
|
+
'data.modified_nickname': { contextAsString: bizmodels_1.CTX_VISITOR_NICKNAME },
|
|
59
|
+
'data.modified_account_type': { contextAsString: bizmodels_1.CTX_VISITOR_ACCOUNT_TYPE },
|
|
60
|
+
};
|
|
61
|
+
const buildUpdateCfgBy = (cfgArray, prefix) => {
|
|
62
|
+
const obj = {};
|
|
63
|
+
if (Array.isArray(cfgArray)) {
|
|
64
|
+
for (let i = 0; i < cfgArray.length; i++) {
|
|
65
|
+
const suffix = cfgArray[i];
|
|
66
|
+
if (suffix) {
|
|
67
|
+
const key = `${prefix}_${suffix}`;
|
|
68
|
+
obj[key] = mapping[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return obj;
|
|
73
|
+
};
|
|
74
|
+
// 查询语句
|
|
75
|
+
if (isSimpleQuery(sqlSimpleName)) {
|
|
76
|
+
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 查询用户本人创建的
|
|
77
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
78
|
+
}
|
|
79
|
+
// 删除语句
|
|
80
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_DELETE) {
|
|
81
|
+
const updateCfgObj = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 删除用户本人创建的
|
|
82
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj);
|
|
83
|
+
}
|
|
84
|
+
// 插入语句
|
|
85
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT) {
|
|
86
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
|
|
87
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
88
|
+
}
|
|
89
|
+
// 更新语句
|
|
90
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
91
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
|
|
92
|
+
const updateCfgObj2 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
93
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
94
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
95
|
+
}
|
|
96
|
+
// 插入或更新
|
|
97
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE ||
|
|
98
|
+
sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE) {
|
|
99
|
+
const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
|
|
100
|
+
const updateCfgObj2 = buildUpdateCfgBy(dataCfgArray, 'data.modified');
|
|
101
|
+
const updateCfgObj3 = buildUpdateCfgBy(conditionCfgArray, 'condition.created'); // 更新用户本人创建的
|
|
102
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj1);
|
|
103
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj2);
|
|
104
|
+
Object.assign(cfgModel.updateCfg, updateCfgObj3);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.fixCfgModel = fixCfgModel;
|
package/package.json
CHANGED
package/src/configuration.ts
CHANGED
|
@@ -13,8 +13,9 @@ import { join } from 'path';
|
|
|
13
13
|
// import { NotFoundFilter } from './filter/notfound.filter';
|
|
14
14
|
import { GlobalMiddleware } from './middleware/global.middleware';
|
|
15
15
|
import { ForbiddenMiddleware } from './middleware/forbidden.middleware';
|
|
16
|
-
import {
|
|
16
|
+
import { startScheduleLoop } from './schedule';
|
|
17
17
|
import { privateAES } from './libs/utils/crypto-utils';
|
|
18
|
+
import { ALL_SCHEDULE_NAMES } from "@/schedule/scheduleNames";
|
|
18
19
|
|
|
19
20
|
@Configuration({
|
|
20
21
|
// namespace: 'fatcms',
|
|
@@ -63,16 +64,11 @@ export class ContainerLifeCycle {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
async onReady() {
|
|
66
|
-
const logger = this.app.getLogger();
|
|
67
|
-
const config = this.app.getConfig();
|
|
68
|
-
|
|
69
|
-
if (config.fatcmsScheduleService) {
|
|
70
|
-
// 启动定时任务
|
|
71
|
-
const scheduleServiceList = ['proxyApiLoadService', 'workbenchService', 'visitStatService', 'asyncTaskRunnerService'];
|
|
72
|
-
await startSchedule(this.app, scheduleServiceList);
|
|
73
|
-
logger.info('ContainerLifeCycle ==> onReady 启动定时任务 ' );
|
|
74
|
-
}
|
|
75
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 启动定时任务
|
|
70
|
+
*/
|
|
71
|
+
await this.startScheduleOnReady();
|
|
76
72
|
|
|
77
73
|
// add middleware
|
|
78
74
|
this.app.useMiddleware(ForbiddenMiddleware);
|
|
@@ -81,4 +77,28 @@ export class ContainerLifeCycle {
|
|
|
81
77
|
// add filter
|
|
82
78
|
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
|
|
83
79
|
}
|
|
80
|
+
|
|
81
|
+
private async startScheduleOnReady(){
|
|
82
|
+
const logger = this.app.getLogger();
|
|
83
|
+
const config = this.app.getConfig();
|
|
84
|
+
const fatcmsScheduleService: boolean | string[] = config.fatcmsScheduleService;
|
|
85
|
+
|
|
86
|
+
// 关闭定时任务
|
|
87
|
+
if (fatcmsScheduleService === false || fatcmsScheduleService === null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
let scheduleServiceList = ALL_SCHEDULE_NAMES
|
|
93
|
+
|
|
94
|
+
// 启动部分定时任务
|
|
95
|
+
if (Array.isArray(fatcmsScheduleService)){
|
|
96
|
+
scheduleServiceList = fatcmsScheduleService;
|
|
97
|
+
}
|
|
98
|
+
await startScheduleLoop(scheduleServiceList);
|
|
99
|
+
logger.info('ContainerLifeCycle ==> onReady 启动定时任务 : ' + JSON.stringify(scheduleServiceList) );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
84
104
|
}
|
|
@@ -2,7 +2,7 @@ import { All, Controller, Inject, Param } from '@midwayjs/core';
|
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
3
|
import { BaseApiController } from '../base/BaseApiController';
|
|
4
4
|
import * as _ from 'lodash';
|
|
5
|
-
import { AnyApiService } from '
|
|
5
|
+
import { AnyApiService } from '@/service/anyapi/AnyApiService';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* FaaS方式配置的接口
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { Controller, Inject,
|
|
1
|
+
import { Controller, Inject, Post, Query } from '@midwayjs/core';
|
|
2
2
|
|
|
3
3
|
import { Context } from '@midwayjs/koa';
|
|
4
4
|
import { BaseApiController } from '../base/BaseApiController';
|
|
5
5
|
import {AsyncTaskService} from "@/service/asyncTask/AsyncTaskService";
|
|
6
|
-
import {SysAsyncTaskEntity,
|
|
6
|
+
import {SysAsyncTaskEntity, SysAsyncTaskStatus} from "@/models/AsyncTaskModel";
|
|
7
7
|
import {KeysOfSimpleSQL} from "@/libs/crud-pro/models/keys";
|
|
8
8
|
import {SystemTables} from "@/models/SystemTables";
|
|
9
9
|
import {CommonException} from "@/libs/crud-pro/exceptions";
|
|
10
|
+
import {checkLogin} from "@/middleware/permission.middleware";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
function fixMyTasksCondition(body:any,ctx: Context){
|
|
14
|
+
if(!body.condition) {
|
|
15
|
+
throw new CommonException("参数不正确");
|
|
16
|
+
}
|
|
17
|
+
body.condition.created_by = ctx.userSession.getSessionInfo().accountId;
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
|
|
12
21
|
function fixCancelBodyData(body:any, id: number) {
|
|
@@ -21,26 +30,29 @@ function fixCancelBodyData(body:any, id: number) {
|
|
|
21
30
|
|
|
22
31
|
// fix data
|
|
23
32
|
const dataObj: SysAsyncTaskEntity = (body.data || {}) as any;
|
|
24
|
-
dataObj.task_status =
|
|
33
|
+
dataObj.task_status = SysAsyncTaskStatus.CANCELLED;
|
|
25
34
|
body.data = dataObj;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
|
|
29
|
-
function fixCreateBodyData(body:any) {
|
|
38
|
+
function fixCreateBodyData(body:any, ctx: Context) {
|
|
30
39
|
if(!body.data) {
|
|
31
40
|
throw new CommonException("参数不正确");
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
const sessionInfo = ctx.userSession.getSessionInfo();
|
|
34
44
|
// fix data
|
|
35
45
|
const dataObj: SysAsyncTaskEntity = (body.data || {}) as any;
|
|
36
|
-
dataObj.task_status =
|
|
46
|
+
dataObj.task_status = SysAsyncTaskStatus.PENDING;
|
|
47
|
+
dataObj.created_by = sessionInfo.accountId;
|
|
48
|
+
dataObj.created_user_session = JSON.stringify(sessionInfo); // 创建人的session信息。用于执行时的鉴权。
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
|
|
40
52
|
/**
|
|
41
53
|
* 异步任务框架
|
|
42
54
|
*/
|
|
43
|
-
@Controller('/ns/gw/AsyncTask')
|
|
55
|
+
@Controller('/ns/gw/AsyncTask', { middleware: [checkLogin()] })
|
|
44
56
|
export class AsyncTaskController extends BaseApiController {
|
|
45
57
|
@Inject()
|
|
46
58
|
protected ctx: Context;
|
|
@@ -49,15 +61,16 @@ export class AsyncTaskController extends BaseApiController {
|
|
|
49
61
|
private asyncTaskService: AsyncTaskService;
|
|
50
62
|
|
|
51
63
|
// 获取任务列表
|
|
52
|
-
@
|
|
64
|
+
@Post('/getMyTasks')
|
|
53
65
|
async getMyTasks() {
|
|
66
|
+
fixMyTasksCondition(this.ctx.request.body, this.ctx);
|
|
54
67
|
return this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
55
68
|
}
|
|
56
69
|
|
|
57
70
|
// 创建任务
|
|
58
71
|
@Post('/createTask')
|
|
59
72
|
async createTask() {
|
|
60
|
-
fixCreateBodyData(this.ctx.request.body);
|
|
73
|
+
fixCreateBodyData(this.ctx.request.body, this.ctx);
|
|
61
74
|
const res = await this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
62
75
|
await this.asyncTaskService.startTask();
|
|
63
76
|
return res;
|
|
@@ -21,11 +21,11 @@ function pickAsQuery(query_as_pick: string, query: any): any {
|
|
|
21
21
|
return query;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
// /ns/gw/
|
|
24
|
+
// /ns/gw/crudApi/getUser?__query_as_condition__=id&_query_as_data__=name&&id=1&name=22
|
|
25
25
|
/**
|
|
26
|
-
* query形式1:GET: /ns/gw/
|
|
27
|
-
* query形式2:GET: /ns/gw/
|
|
28
|
-
* query形式3:GET: /ns/gw/
|
|
26
|
+
* query形式1:GET: /ns/gw/crudApi/getUser?__query_json__=%7B%22condition%22%3A%7B%22id%22%3A2%7D%7D
|
|
27
|
+
* query形式2:GET: /ns/gw/crudApi/getUser?__query_as__=condition&id=1&name=22
|
|
28
|
+
* query形式3:GET: /ns/gw/crudApi/createUser?__query_as__=data&__query_pick__=id,name&id=1&name=22
|
|
29
29
|
*
|
|
30
30
|
* 执行单个配置的接口
|
|
31
31
|
*/
|
|
@@ -57,7 +57,7 @@ export class CrudMtdGatewayController extends ApiBaseService {
|
|
|
57
57
|
return CommonResult.errorRes('接口不存在或已下线: ' + methodCode);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
this.logInfo(
|
|
60
|
+
this.logInfo('methodInfo=== ', methodInfo);
|
|
61
61
|
|
|
62
62
|
const workbench_code_array = methodInfo.workbench_code_array || methodInfo.workbenchCodeArray;
|
|
63
63
|
const isSupport = await this.workbenchService.isSupportCurrentWorkbench(workbench_code_array);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Controller, Inject, Post } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { KeysOfSimpleSQL, KeysOfValidators } from '
|
|
3
|
+
import { KeysOfSimpleSQL, KeysOfValidators } from '@/libs/crud-pro/models/keys';
|
|
4
4
|
import { BaseApiController } from '../base/BaseApiController';
|
|
5
|
-
import { checkPermission } from '
|
|
6
|
-
import { SystemFuncCode } from '
|
|
7
|
-
import { SystemTables } from '
|
|
8
|
-
import { CTX_VISITOR_ID, CTX_WORKBENCH_CODE } from '
|
|
5
|
+
import { checkPermission } from '@/middleware/permission.middleware';
|
|
6
|
+
import { SystemFuncCode } from '@/models/SystemPerm';
|
|
7
|
+
import { SystemTables } from '@/models/SystemTables';
|
|
8
|
+
import { CTX_VISITOR_ID, CTX_WORKBENCH_CODE } from '@/models/bizmodels';
|
|
9
9
|
|
|
10
10
|
const publishUpdateCfg = {
|
|
11
11
|
'data.last_publish_by': { contextAsString: CTX_VISITOR_ID },
|
package/src/index.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
|
|
|
76
82
|
|
|
77
83
|
export * from './libs/utils/common-dto';
|
|
@@ -95,5 +101,6 @@ export * from './libs/crud-pro/models/keys';
|
|
|
95
101
|
export * from './libs/crud-pro/models/ExecuteContextFunc';
|
|
96
102
|
export * from './libs/crud-pro/models/RequestCfgModel';
|
|
97
103
|
export * from './libs/crud-pro/models/SqlSegArg';
|
|
104
|
+
export * from './libs/crud-pro/models/ResModel';
|
|
98
105
|
|
|
99
106
|
export * from './libs/global-config/global-config';
|
|
@@ -89,6 +89,9 @@ class CrudPro {
|
|
|
89
89
|
const logger = this.executeContext.getLogger();
|
|
90
90
|
logger.info('CurdPro executeCrudByCfg', cfgJson);
|
|
91
91
|
|
|
92
|
+
// 在执行之前可以根据业务需要修改需要执行的内容。
|
|
93
|
+
await this.beforeExecuteSQLList(reqJson, cfgJson);
|
|
94
|
+
|
|
92
95
|
const exeCtx = this.executeContext;
|
|
93
96
|
|
|
94
97
|
if (!cfgJson.method) {
|
|
@@ -153,6 +156,11 @@ class CrudPro {
|
|
|
153
156
|
private async afterExecuteSQLList() {
|
|
154
157
|
return this.executeContext.contextFunc.afterExecuteSQLList();
|
|
155
158
|
}
|
|
159
|
+
|
|
160
|
+
private async beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel) {
|
|
161
|
+
return this.executeContext.contextFunc.beforeExecuteSQLList(reqJson, cfgJson);
|
|
162
|
+
}
|
|
163
|
+
|
|
156
164
|
}
|
|
157
165
|
|
|
158
166
|
export { CrudPro };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ICrudProCfg } from './interfaces';
|
|
2
|
+
import { SqlDbType } from './models/keys';
|
|
2
3
|
|
|
3
4
|
export const defaultCrudProCfg: ICrudProCfg = {
|
|
4
5
|
sysDatabaseName: 'fatcms',
|
|
6
|
+
sysDatabaseDbType: SqlDbType.mysql, // 默认系统数据库名称,默认 mysql
|
|
5
7
|
sysConfigTableName: 'sys_configs', // 数据表:通用配置
|
|
6
8
|
dictItemTableName: 'sys_data_dict_item', // 数据表:数据字典,字典项。
|
|
7
9
|
methodsTableName: 'sys_crud_methods',
|
|
@@ -4,6 +4,7 @@ import {KeysOfAuthType, KeysOfSimpleSQL, KeysOfValidators, SqlDbType} from './mo
|
|
|
4
4
|
|
|
5
5
|
export interface ICrudProCfg {
|
|
6
6
|
sysDatabaseName?: string; // 默认系统数据库名称,默认 fatcms
|
|
7
|
+
sysDatabaseDbType?: SqlDbType; // 默认系统数据库名称,默认 mysql
|
|
7
8
|
methodsTableName?: string; // 方法配置的表名,默认 sys_crud_methods
|
|
8
9
|
methodsCacheTime?: number; //内存缓存时间默认 1分钟
|
|
9
10
|
dictItemTableName?: string; // 字典项表名称,默认:sys_data_dict_item
|
|
@@ -133,7 +134,7 @@ export interface ISqlCfgModel extends IBaseCfgModel {
|
|
|
133
134
|
originSql?: string; // 有特殊占位符的SQL, 原始的SQL
|
|
134
135
|
validate?: IFuncCfgModel; //执行前,进行校验,校验不通过就抛出异常. 校验函数可以返回 boolean或直接抛出异常
|
|
135
136
|
executeWhen?: IFuncCfgModel; //满足表达式的结果,才能执行。 默认:true 校验函数必须返回 boolean
|
|
136
|
-
executeSql?: string; // 可以运行的SQL
|
|
137
|
+
executeSql?: string; // 可以运行的SQL。在postgres/sqlserver环境下也可以使用问号。
|
|
137
138
|
executeSqlArgs?: any[]; //可以运行的SQL的参数
|
|
138
139
|
crudType?: string;
|
|
139
140
|
}
|
|
@@ -181,3 +182,11 @@ export interface ILogger {
|
|
|
181
182
|
error(msg: any, ...args: any[]): void;
|
|
182
183
|
warn(msg: any, ...args: any[]): void;
|
|
183
184
|
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
export interface IExecuteUnsafeQueryCtx {
|
|
189
|
+
sqlTable: string;
|
|
190
|
+
sqlDatabase: string;
|
|
191
|
+
sqlDbType: SqlDbType;
|
|
192
|
+
}
|
|
@@ -7,6 +7,7 @@ import { Transaction } from './Transaction';
|
|
|
7
7
|
import { ICrudProCfg, ILogger, IVisitor } from '../interfaces';
|
|
8
8
|
import { IExecuteContextFunc } from './ExecuteContextFunc';
|
|
9
9
|
import { defaultCrudProCfg } from '../defaultConfigs';
|
|
10
|
+
import { ResModelFlexible } from "./ResModel";
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class ExecuteContext {
|
|
@@ -20,7 +21,7 @@ class ExecuteContext {
|
|
|
20
21
|
// 运行时设置的。
|
|
21
22
|
private sqlCfgModels: SqlCfgModel[] = [];
|
|
22
23
|
private reqModel: RequestModel = null;
|
|
23
|
-
private resModel:
|
|
24
|
+
private resModel: ResModelFlexible = {};
|
|
24
25
|
private cfgModel: RequestCfgModel = null;
|
|
25
26
|
|
|
26
27
|
setTransaction(transaction: Transaction) {
|
|
@@ -62,7 +63,7 @@ class ExecuteContext {
|
|
|
62
63
|
this.reqModel = reqModel;
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
getResModel():
|
|
66
|
+
getResModel(): ResModelFlexible {
|
|
66
67
|
return this.resModel;
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -108,4 +109,6 @@ interface IExecuteContextHandler {
|
|
|
108
109
|
handleExecuteContext(executeContext: ExecuteContext): Promise<void>;
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
|
|
113
|
+
|
|
111
114
|
export { ExecuteContext, IExecuteContextHandler };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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';
|
|
@@ -14,6 +14,7 @@ export interface IExecuteContextFunc {
|
|
|
14
14
|
getFunctionMap(): any;
|
|
15
15
|
validateByAuthCfg(cfgModel: RequestCfgModel, reqModel: RequestModel): Promise<any>;
|
|
16
16
|
afterExecuteSQLList(): Promise<any>;
|
|
17
|
+
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any>;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
@@ -76,6 +77,16 @@ export class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
|
76
77
|
return null;
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
83
|
+
* @param reqJson
|
|
84
|
+
* @param cfgJson
|
|
85
|
+
*/
|
|
86
|
+
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any> {
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
getExecuteContext(): ExecuteContext {
|
|
80
91
|
return this.executeContext;
|
|
81
92
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
interface ResModelAffected {
|
|
3
|
+
insertId?: string | number;
|
|
4
|
+
affectedRows: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface ResModelStandard {
|
|
8
|
+
row?: any,
|
|
9
|
+
rows?: any[],
|
|
10
|
+
total_count?: number,
|
|
11
|
+
affected?: ResModelAffected,
|
|
12
|
+
insert_affected?: ResModelAffected,
|
|
13
|
+
update_affected?: ResModelAffected,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type ResModelFlexible = ResModelStandard & {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
ResModelAffected,
|
|
22
|
+
ResModelStandard,
|
|
23
|
+
ResModelFlexible
|
|
24
|
+
}
|
|
@@ -7,46 +7,54 @@ import MemoryRefreshCache from '../utils/MemoryRefreshCache';
|
|
|
7
7
|
|
|
8
8
|
const methodCache = new MemoryRefreshCache();
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
function parseMethodInfo(methodInfo: any): any {
|
|
12
11
|
const row: any = camelizeKeys(methodInfo as object); //转换成驼峰
|
|
13
12
|
const configObject = MixinUtils.parseJsonObject(row.moreConfig) || {};
|
|
14
13
|
const sqlCfgList = MixinUtils.parseJsonObject(row.sqlCfgList) || [];
|
|
15
|
-
return {...configObject, ...row, sqlCfgList};
|
|
14
|
+
return { ...configObject, ...row, sqlCfgList };
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
17
|
class CrudProCachedCfgService extends CrudProServiceBase {
|
|
21
18
|
constructor(serviceHub: ICurdProServiceHub) {
|
|
22
19
|
super(serviceHub);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
public async getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null> {
|
|
23
|
+
const methodInfo = await this.getCachedCfgByMethodInner(method, isEnableCache);
|
|
24
|
+
if (!methodInfo) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return { ...methodInfo };
|
|
28
|
+
}
|
|
26
29
|
|
|
30
|
+
private async getCachedCfgByMethodInner(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null> {
|
|
27
31
|
// 不使用缓存
|
|
28
32
|
if (!isEnableCache) {
|
|
29
|
-
return await this.loadMethodInfo(method)
|
|
33
|
+
return await this.loadMethodInfo(method);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
methodCache.setProps({
|
|
33
|
-
keepTime:
|
|
37
|
+
keepTime: 1000 * 60 * 2, // 2分钟
|
|
34
38
|
requestFn: () => this.loadMethodInfoList(),
|
|
35
39
|
getKeyFn: item => item.method,
|
|
36
40
|
});
|
|
37
|
-
|
|
41
|
+
const methodInfo = await methodCache.getItem(method);
|
|
42
|
+
if (methodInfo) {
|
|
43
|
+
return methodInfo;
|
|
44
|
+
}
|
|
45
|
+
return await this.loadMethodInfo(method);
|
|
38
46
|
}
|
|
39
47
|
|
|
40
|
-
|
|
41
48
|
private async loadMethodInfo(method: string): Promise<any> {
|
|
42
|
-
const {methodsTableName, sysDatabaseName} = this.getContextCfg();
|
|
43
|
-
const sql = `select *
|
|
44
|
-
|
|
45
|
-
where method = ? `; // 全部加载到内存
|
|
49
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
50
|
+
const sql = `select * from ${methodsTableName} where method = ? `; // 全部加载到内存
|
|
51
|
+
|
|
46
52
|
const baseInfo = {
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
sqlTable: methodsTableName,
|
|
54
|
+
sqlDatabase: sysDatabaseName,
|
|
55
|
+
sqlDbType: sysDatabaseDbType,
|
|
49
56
|
};
|
|
57
|
+
|
|
50
58
|
const [rows] = await this.executeUnsafeQuery(baseInfo, sql, [method]);
|
|
51
59
|
const rows2: any[] = rows as object[];
|
|
52
60
|
if (rows2.length > 0) {
|
|
@@ -58,11 +66,12 @@ class CrudProCachedCfgService extends CrudProServiceBase {
|
|
|
58
66
|
|
|
59
67
|
|
|
60
68
|
private async loadMethodInfoList(): Promise<any[]> {
|
|
61
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
69
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
62
70
|
const sql = `select * from ${methodsTableName}`; // 全部加载到内存
|
|
63
71
|
const baseInfo = {
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
sqlTable: methodsTableName,
|
|
73
|
+
sqlDatabase: sysDatabaseName,
|
|
74
|
+
sqlDbType: sysDatabaseDbType
|
|
66
75
|
};
|
|
67
76
|
const [rows] = await this.executeUnsafeQuery(baseInfo, sql);
|
|
68
77
|
const rows2: any[] = rows as object[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _ from 'lodash';
|
|
2
2
|
import { ICurdProServiceHub } from '../models/ServiceHub';
|
|
3
|
-
import {ICrudProCfg, ILogger, IPoolConnectionClient} from '../interfaces';
|
|
3
|
+
import {ICrudProCfg, IExecuteUnsafeQueryCtx, ILogger, IPoolConnectionClient} from '../interfaces';
|
|
4
4
|
import { SqlCfgModel } from '../models/SqlCfgModel';
|
|
5
5
|
import { ExecuteContext } from '../models/ExecuteContext';
|
|
6
6
|
import { MixinUtils } from '../utils/MixinUtils';
|
|
@@ -19,10 +19,6 @@ function createBuildInExecuteFuncMap() {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
interface ExecuteUnsafeQueryCtx {
|
|
23
|
-
tableName: string;
|
|
24
|
-
dbName: string;
|
|
25
|
-
}
|
|
26
22
|
|
|
27
23
|
const buildInExecuteFuncMap = createBuildInExecuteFuncMap();
|
|
28
24
|
|
|
@@ -60,10 +56,11 @@ class CrudProServiceBase {
|
|
|
60
56
|
* @param values
|
|
61
57
|
* @protected
|
|
62
58
|
*/
|
|
63
|
-
protected async executeUnsafeQuery(obj:
|
|
59
|
+
protected async executeUnsafeQuery(obj: IExecuteUnsafeQueryCtx, sql: string, values?: any) {
|
|
64
60
|
const sqlCfgModel: any = {
|
|
65
|
-
sqlTable: obj.
|
|
66
|
-
sqlDatabase: obj.
|
|
61
|
+
sqlTable: obj.sqlTable,
|
|
62
|
+
sqlDatabase: obj.sqlDatabase,
|
|
63
|
+
sqlDbType: obj.sqlDbType,
|
|
67
64
|
columns: [],
|
|
68
65
|
columnsRelation: [],
|
|
69
66
|
maxLimit: DEFAULT_MAX_LIMIT,
|