midway-fatcms 0.0.1-beta.2 → 0.0.1-beta.22
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/.eslintrc.json +12 -0
- package/.prettierrc.js +4 -0
- package/README.md +7 -0
- package/dist/config/config.default.js +52 -15
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +33 -8
- package/dist/controller/base/BaseApiController.d.ts +1 -1
- package/dist/controller/base/BaseApiController.js +14 -6
- package/dist/controller/gateway/AsyncTaskController.d.ts +14 -0
- package/dist/controller/gateway/AsyncTaskController.js +108 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
- package/dist/controller/gateway/CrudStdGatewayController.d.ts +5 -5
- package/dist/controller/gateway/DocGatewayController.js +14 -9
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.d.ts +2 -0
- package/dist/controller/gateway/StaticController.js +59 -40
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/home.controller.js +2 -2
- package/dist/controller/manage/AnyApiMangeApi.js +2 -2
- package/dist/controller/manage/AppLogMangeApi.js +2 -2
- package/dist/controller/manage/AppMangeApi.js +2 -2
- package/dist/controller/manage/AppPageMangeApi.js +2 -2
- package/dist/controller/manage/AppSchemaHistoryApi.js +2 -2
- package/dist/controller/manage/CrudMethodsMangeApi.js +2 -2
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +78 -75
- package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
- package/dist/controller/manage/DataDictManageApi.js +1 -1
- package/dist/controller/manage/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +38 -34
- package/dist/controller/manage/DocLibManageApi.js +2 -2
- package/dist/controller/manage/DocManageApi.js +2 -2
- package/dist/controller/manage/FileManageApi.js +1 -1
- package/dist/controller/manage/LowCodeTplManageApi.js +2 -2
- package/dist/controller/manage/MenuManageApi.js +2 -2
- package/dist/controller/manage/ProxyApiMangeApi.js +2 -2
- package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
- package/dist/controller/manage/SuperAdminManageApi.js +12 -8
- package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
- package/dist/controller/manage/SysConfigMangeApi.js +8 -6
- package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
- package/dist/controller/manage/SystemInfoManageApi.js +7 -1
- package/dist/controller/manage/UserAccountManageApi.d.ts +2 -2
- package/dist/controller/manage/UserAccountManageApi.js +7 -2
- package/dist/controller/manage/WorkbenchMangeApi.js +3 -3
- package/dist/controller/myinfo/AuthController.d.ts +0 -4
- package/dist/controller/myinfo/AuthController.js +1 -54
- package/dist/controller/render/AppRenderController.js +10 -4
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +5 -5
- package/dist/index.d.ts +34 -4
- package/dist/index.js +34 -4
- 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 +7 -1
- 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/RequestCfgModel.d.ts +1 -1
- 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/models/SqlCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +27 -15
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +13 -17
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
- 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 +32 -7
- package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
- package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
- package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +3 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +22 -0
- package/dist/libs/global-config/global-config.d.ts +45 -0
- package/dist/libs/global-config/global-config.js +33 -0
- package/dist/libs/utils/errorToString.d.ts +2 -0
- package/dist/libs/utils/errorToString.js +57 -0
- package/dist/libs/utils/fatcms-request.js +2 -2
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +8 -1
- package/dist/models/AsyncTaskModel.d.ts +69 -0
- package/dist/models/AsyncTaskModel.js +26 -0
- package/dist/models/RedisKeys.d.ts +8 -0
- package/dist/models/RedisKeys.js +11 -0
- package/dist/models/SystemTables.d.ts +1 -3
- package/dist/models/SystemTables.js +2 -4
- package/dist/schedule/anonymousContext.d.ts +13 -0
- package/dist/schedule/anonymousContext.js +59 -0
- package/dist/schedule/index.d.ts +4 -3
- package/dist/schedule/index.js +8 -67
- package/dist/schedule/runSchedule.d.ts +15 -0
- package/dist/schedule/runSchedule.js +68 -0
- package/dist/schedule/scheduleNames.d.ts +13 -0
- package/dist/schedule/scheduleNames.js +17 -0
- package/dist/service/AuthService.js +8 -5
- package/dist/service/EnumInfoService.js +7 -4
- package/dist/service/FileCenterService.js +13 -9
- package/dist/service/SysConfigService.js +4 -2
- package/dist/service/UserAccountService.js +10 -6
- package/dist/service/UserSessionService.js +2 -1
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +20 -27
- package/dist/service/WorkbenchService.js +4 -2
- package/dist/service/anyapi/AnyApiService.js +4 -2
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +37 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +232 -0
- package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
- package/dist/service/asyncTask/AsyncTaskService.js +34 -0
- package/dist/service/crudstd/CrudStdService.d.ts +2 -1
- package/dist/service/crudstd/CrudStdService.js +48 -3
- package/dist/service/curd/CrudProQuick.d.ts +24 -0
- package/dist/service/curd/CrudProQuick.js +105 -0
- package/dist/service/curd/CurdMixByAccountService.js +12 -6
- package/dist/service/curd/CurdMixByDictService.js +4 -2
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +10 -1
- package/dist/service/curd/CurdMixByLinkToCustomService.js +72 -24
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
- package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
- package/dist/service/curd/CurdMixService.d.ts +1 -1
- package/dist/service/curd/CurdMixService.js +2 -2
- package/dist/service/curd/CurdMixUtils.d.ts +7 -0
- package/dist/service/curd/CurdMixUtils.js +65 -28
- package/dist/service/curd/CurdProService.d.ts +2 -10
- package/dist/service/curd/CurdProService.js +31 -146
- package/dist/service/curd/fixCfgModel.d.ts +3 -0
- package/dist/service/curd/fixCfgModel.js +107 -0
- package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
- package/dist/views/404_app.html +31 -0
- package/dist/views/404_workbench.html +34 -0
- package/dist/views/static/favicon.ico +0 -0
- package/package.json +9 -2
- package/src/config/config.default.ts +58 -27
- package/src/configuration.ts +42 -9
- package/src/controller/base/BaseApiController.ts +26 -19
- package/src/controller/gateway/AnyApiGatewayController.ts +1 -1
- package/src/controller/gateway/AsyncTaskController.ts +83 -0
- package/src/controller/gateway/CrudMtdGatewayController.ts +17 -13
- package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
- package/src/controller/gateway/DocGatewayController.ts +25 -17
- package/src/controller/gateway/FileController.ts +8 -9
- package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
- package/src/controller/gateway/PublicApiController.ts +19 -22
- package/src/controller/gateway/StaticController.ts +234 -242
- package/src/controller/helpers.controller.ts +1 -1
- package/src/controller/home.controller.ts +8 -15
- package/src/controller/manage/AnyApiMangeApi.ts +11 -11
- package/src/controller/manage/AppLogMangeApi.ts +5 -5
- package/src/controller/manage/AppMangeApi.ts +7 -7
- package/src/controller/manage/AppPageMangeApi.ts +5 -5
- package/src/controller/manage/AppSchemaHistoryApi.ts +3 -3
- package/src/controller/manage/CrudMethodsMangeApi.ts +5 -5
- package/src/controller/manage/CrudStandardDesignApi.ts +106 -113
- package/src/controller/manage/DataDictManageApi.ts +5 -5
- package/src/controller/manage/DeployManageApi.ts +85 -89
- package/src/controller/manage/DocLibManageApi.ts +5 -5
- package/src/controller/manage/DocManageApi.ts +10 -10
- package/src/controller/manage/FileManageApi.ts +1 -1
- package/src/controller/manage/LowCodeTplManageApi.ts +2 -2
- package/src/controller/manage/MenuManageApi.ts +10 -15
- package/src/controller/manage/ProxyApiMangeApi.ts +2 -2
- package/src/controller/manage/SuperAdminManageApi.ts +14 -13
- package/src/controller/manage/SysConfigMangeApi.ts +11 -11
- package/src/controller/manage/SystemInfoManageApi.ts +11 -6
- package/src/controller/manage/UserAccountManageApi.ts +10 -4
- package/src/controller/manage/WorkbenchMangeApi.ts +8 -8
- package/src/controller/myinfo/AuthController.ts +6 -72
- package/src/controller/render/AppRenderController.ts +24 -21
- package/src/controller/test.controller.ts +18 -18
- package/src/index.ts +38 -4
- package/src/libs/crud-pro/CrudPro.ts +7 -0
- package/src/libs/crud-pro/defaultConfigs.ts +2 -0
- package/src/libs/crud-pro/interfaces.ts +10 -3
- package/src/libs/crud-pro/models/ExecuteContext.ts +3 -3
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +11 -1
- package/src/libs/crud-pro/models/RequestCfgModel.ts +1 -1
- package/src/libs/crud-pro/models/RequestModel.ts +1 -1
- package/src/libs/crud-pro/models/ResModel.ts +19 -0
- package/src/libs/crud-pro/models/SqlCfgModel.ts +2 -2
- package/src/libs/crud-pro/models/Transaction.ts +8 -9
- package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +32 -23
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +38 -54
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +26 -45
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +23 -40
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +25 -29
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +5 -9
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +36 -9
- package/src/libs/crud-pro/utils/DatabaseName.ts +35 -15
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
- package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
- package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +2 -2
- package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +26 -0
- package/src/libs/global-config/global-config.ts +78 -0
- package/src/libs/utils/crypto-utils.ts +2 -4
- package/src/libs/utils/errorToString.ts +61 -0
- package/src/libs/utils/fatcms-request.ts +9 -21
- package/src/libs/utils/ordernum-utils.ts +2 -6
- package/src/libs/utils/parseConfig.ts +7 -15
- package/src/middleware/forbidden.middleware.ts +6 -25
- package/src/middleware/global.middleware.ts +18 -16
- package/src/models/AsyncTaskModel.ts +79 -0
- package/src/models/RedisKeys.ts +13 -0
- package/src/models/SystemTables.ts +1 -4
- package/src/models/bizmodels.ts +1 -2
- package/src/schedule/anonymousContext.ts +79 -0
- package/src/schedule/index.ts +11 -72
- package/src/schedule/runSchedule.ts +83 -0
- package/src/schedule/scheduleNames.ts +21 -0
- package/src/service/AuthService.ts +13 -8
- package/src/service/EnumInfoService.ts +8 -3
- package/src/service/FileCenterService.ts +12 -6
- package/src/service/SysConfigService.ts +10 -6
- package/src/service/UserAccountService.ts +14 -4
- package/src/service/UserSessionService.ts +5 -4
- package/src/service/VisitStatService.ts +57 -70
- package/src/service/WorkbenchService.ts +7 -2
- package/src/service/anyapi/AnyApiService.ts +11 -8
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +255 -0
- package/src/service/asyncTask/AsyncTaskService.ts +21 -0
- package/src/service/base/BaseService.ts +2 -2
- package/src/service/crudstd/CrudStdService.ts +60 -5
- package/src/service/curd/CrudProQuick.ts +137 -0
- package/src/service/curd/CurdMixByAccountService.ts +14 -6
- package/src/service/curd/CurdMixByDictService.ts +8 -2
- package/src/service/curd/CurdMixByLinkToCustomService.ts +101 -50
- package/src/service/curd/CurdMixBySysConfigService.ts +7 -2
- package/src/service/curd/CurdMixByWorkbenchService.ts +6 -2
- package/src/service/curd/CurdMixService.ts +3 -3
- package/src/service/curd/CurdMixUtils.ts +82 -39
- package/src/service/curd/CurdProService.ts +45 -189
- package/src/service/curd/fixCfgModel.ts +139 -0
- package/src/service/proxyapi/ProxyApiLoadService.ts +12 -3
- package/src/views/404_app.html +31 -0
- package/src/views/404_workbench.html +34 -0
- package/src/views/static/favicon.ico +0 -0
- package/tsconfig.json +32 -0
- package/dist/controller/medstatistic/MedAdminController.d.ts +0 -35
- package/dist/controller/medstatistic/MedAdminController.js +0 -205
- package/dist/controller/medstatistic/MedClientController.d.ts +0 -28
- package/dist/controller/medstatistic/MedClientController.js +0 -188
- package/dist/controller/medstatistic/MedMessageService.d.ts +0 -19
- package/dist/controller/medstatistic/MedMessageService.js +0 -95
- package/dist/controller/medstatistic/MedScoreService.d.ts +0 -21
- package/dist/controller/medstatistic/MedScoreService.js +0 -107
- package/dist/controller/medstatistic/constants.d.ts +0 -32
- package/dist/controller/medstatistic/constants.js +0 -43
- package/src/controller/medstatistic/MedAdminController.ts +0 -221
- package/src/controller/medstatistic/MedClientController.ts +0 -188
- package/src/controller/medstatistic/MedMessageService.ts +0 -89
- package/src/controller/medstatistic/MedScoreService.ts +0 -108
- package/src/controller/medstatistic/constants.ts +0 -63
|
@@ -7,6 +7,7 @@ import { checkPermission } from '../../middleware/permission.middleware';
|
|
|
7
7
|
import { SystemFuncCode } from '../../models/SystemPerm';
|
|
8
8
|
import { CommonException, Exceptions } from '../../libs/crud-pro/exceptions';
|
|
9
9
|
import { SystemTables } from '../../models/SystemTables';
|
|
10
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
10
11
|
|
|
11
12
|
const accountNameBlacklist = new Set(['sa', 'root', 'admin', 'superadmin', 'administrator', 'sys', 'sysop', 'schedule_user']);
|
|
12
13
|
function checkAccountCreateBlacklist(value: string) {
|
|
@@ -18,12 +19,12 @@ function checkAccountCreateBlacklist(value: string) {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
const LOGIN_NAME_VALIDATE =
|
|
22
|
+
const LOGIN_NAME_VALIDATE = [KeysOfValidators.STRING, KeysOfValidators.NAME, 'length:6,50', checkAccountCreateBlacklist];
|
|
22
23
|
|
|
23
24
|
@Controller('/ns/api/manage/userAccount', { middleware: [checkPermission(SystemFuncCode.UserAccountMangeRead)] })
|
|
24
25
|
export class UserAccountManageApi extends BaseApiController {
|
|
25
26
|
@Inject()
|
|
26
|
-
ctx: Context;
|
|
27
|
+
protected ctx: Context;
|
|
27
28
|
|
|
28
29
|
@Post('/getUserAccountList')
|
|
29
30
|
async getUserAccountList() {
|
|
@@ -43,7 +44,7 @@ export class UserAccountManageApi extends BaseApiController {
|
|
|
43
44
|
async updateUserAccount() {
|
|
44
45
|
return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_UPDATE, {
|
|
45
46
|
validateCfg: {
|
|
46
|
-
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.
|
|
47
|
+
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
|
|
47
48
|
'data.login_name': LOGIN_NAME_VALIDATE,
|
|
48
49
|
'data.nick_name': [KeysOfValidators.STRING, 'length:3,20', checkAccountCreateBlacklist],
|
|
49
50
|
},
|
|
@@ -58,6 +59,11 @@ export class UserAccountManageApi extends BaseApiController {
|
|
|
58
59
|
const body = this.ctx.request.body as any;
|
|
59
60
|
body.data.account_id = createUniqueId();
|
|
60
61
|
|
|
62
|
+
const { generateUserAccountId } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
63
|
+
if (typeof generateUserAccountId === 'function') {
|
|
64
|
+
body.data.account_id = await generateUserAccountId(body.data);
|
|
65
|
+
}
|
|
66
|
+
|
|
61
67
|
return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_INSERT, {
|
|
62
68
|
validateCfg: {
|
|
63
69
|
'data.login_name': LOGIN_NAME_VALIDATE,
|
|
@@ -71,7 +77,7 @@ export class UserAccountManageApi extends BaseApiController {
|
|
|
71
77
|
async deleteUserAccount() {
|
|
72
78
|
return this.executeSysSimpleSQL(SystemTables.sys_user_account, KeysOfSimpleSQL.SIMPLE_DELETE, {
|
|
73
79
|
validateCfg: {
|
|
74
|
-
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.
|
|
80
|
+
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
|
|
75
81
|
},
|
|
76
82
|
});
|
|
77
83
|
}
|
|
@@ -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 { WorkbenchService } from '
|
|
5
|
+
import { checkPermission } from '@/middleware/permission.middleware';
|
|
6
|
+
import { SystemFuncCode } from '@/models/SystemPerm';
|
|
7
|
+
import { SystemTables } from '@/models/SystemTables';
|
|
8
|
+
import { WorkbenchService } from '@/service/WorkbenchService';
|
|
9
9
|
|
|
10
10
|
@Controller('/ns/api/manage/workbench', { middleware: [checkPermission(SystemFuncCode.WorkbenchMangeRead)] })
|
|
11
11
|
export class WorkbenchMangeApi extends BaseApiController {
|
|
@@ -33,7 +33,7 @@ export class WorkbenchMangeApi extends BaseApiController {
|
|
|
33
33
|
const body = this.ctx.request.body as any;
|
|
34
34
|
const dataObj: any = body.data || {};
|
|
35
35
|
|
|
36
|
-
dataObj.html_content = dataObj.html_content ||
|
|
36
|
+
dataObj.html_content = dataObj.html_content || '<html>hello</html>';
|
|
37
37
|
|
|
38
38
|
return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_INSERT, {
|
|
39
39
|
validateCfg: {
|
|
@@ -51,7 +51,7 @@ export class WorkbenchMangeApi extends BaseApiController {
|
|
|
51
51
|
|
|
52
52
|
return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_UPDATE, {
|
|
53
53
|
validateCfg: {
|
|
54
|
-
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.
|
|
54
|
+
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
|
|
55
55
|
'condition.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
|
|
56
56
|
},
|
|
57
57
|
});
|
|
@@ -64,7 +64,7 @@ export class WorkbenchMangeApi extends BaseApiController {
|
|
|
64
64
|
|
|
65
65
|
return this.executeSysSimpleSQL(SystemTables.sys_workbench, KeysOfSimpleSQL.SIMPLE_DELETE, {
|
|
66
66
|
validateCfg: {
|
|
67
|
-
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.
|
|
67
|
+
'condition.id': [KeysOfValidators.REQUIRED, KeysOfValidators.NUMERIC],
|
|
68
68
|
'condition.workbench_code': [KeysOfValidators.REQUIRED, KeysOfValidators.STRING],
|
|
69
69
|
},
|
|
70
70
|
});
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Controller, Inject, Post } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import axios from 'axios';
|
|
4
3
|
import { BaseApiController } from '../base/BaseApiController';
|
|
5
4
|
import { AuthService } from '../../service/AuthService';
|
|
6
|
-
import {
|
|
5
|
+
import { ISessionInfo, SESSION_ID_KEY, sessionCookieCfg } from '../../models/userSession';
|
|
7
6
|
import { CommonResult } from '../../libs/utils/common-dto';
|
|
8
7
|
import { checkLogin } from '../../middleware/permission.middleware';
|
|
9
|
-
import { assertCsrfToken } from
|
|
10
|
-
import {WorkbenchService} from
|
|
11
|
-
import {CommonException} from
|
|
8
|
+
import { assertCsrfToken } from '../../libs/utils/fatcms-request';
|
|
9
|
+
import { WorkbenchService } from '../../service/WorkbenchService';
|
|
10
|
+
import { CommonException } from '../../libs/crud-pro/exceptions';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* 支持使用明文密码和Hash后密码登录。
|
|
@@ -23,7 +22,6 @@ export class AuthController extends BaseApiController {
|
|
|
23
22
|
@Inject()
|
|
24
23
|
private authService: AuthService;
|
|
25
24
|
|
|
26
|
-
|
|
27
25
|
@Inject()
|
|
28
26
|
private workbenchService: WorkbenchService;
|
|
29
27
|
|
|
@@ -54,7 +52,6 @@ export class AuthController extends BaseApiController {
|
|
|
54
52
|
throw new CommonException('WORKBENCH_IS_NOT_FOUND', '站点未找到');
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
|
|
58
55
|
const userSessionInfo = await this.authService.createUserSession(loginName, workbench.workbench_code);
|
|
59
56
|
|
|
60
57
|
this.ctx.cookies.set(SESSION_ID_KEY, userSessionInfo.sessionId, sessionCookieCfg);
|
|
@@ -62,67 +59,6 @@ export class AuthController extends BaseApiController {
|
|
|
62
59
|
return CommonResult.successMsg('登录成功', userSessionInfo);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 使用https://medstatistic.com/账号登录
|
|
68
|
-
*/
|
|
69
|
-
@Post('/loginByMedStatistic')
|
|
70
|
-
async loginByMedStatistic(): Promise<CommonResult> {
|
|
71
|
-
|
|
72
|
-
const { medStatisticToken } = this.ctx.request.body as any;
|
|
73
|
-
if (!medStatisticToken) {
|
|
74
|
-
return CommonResult.errorRes("medStatisticToken is null")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const workbench = await this.workbenchService.getCurrentHostWorkbenchInfo();
|
|
78
|
-
if (!workbench) {
|
|
79
|
-
throw new CommonException('WORKBENCH_IS_NOT_FOUND', '站点未找到');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 先删除之前的cookie
|
|
83
|
-
const sessionId = this.ctx.cookies.get(SESSION_ID_KEY, sessionCookieCfg);
|
|
84
|
-
await this.authService.removeUserSession(sessionId);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
let userInfoRes: any = null;
|
|
88
|
-
try {
|
|
89
|
-
userInfoRes = await axios.get("https://console.medstatistic.com/api/user/index?lang=zh-cn", {
|
|
90
|
-
headers: {
|
|
91
|
-
host: "console.medstatistic.com",
|
|
92
|
-
origin: "https://console.medstatistic.com",
|
|
93
|
-
token: medStatisticToken
|
|
94
|
-
},
|
|
95
|
-
responseType: 'json'
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
} catch (e) {
|
|
99
|
-
return CommonResult.errorRes(e?.message || '');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const userInfo = userInfoRes?.data?.data;
|
|
103
|
-
|
|
104
|
-
if (!userInfo || !userInfo.id) {
|
|
105
|
-
return CommonResult.errorRes("USER_NOT_EXIST")
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const consumerUserInfo: IConsumerUserInfo = {
|
|
109
|
-
workbenchCode: workbench.workbench_code,
|
|
110
|
-
accountType: 'medstatistic',
|
|
111
|
-
accountId: userInfo.id,
|
|
112
|
-
nickName: userInfo.nickname,
|
|
113
|
-
loginName: `${userInfo.id}_${userInfo.username}`,
|
|
114
|
-
avatar: userInfo.avatar,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const userSessionInfo = await this.authService.createUserSessionForConsumer(consumerUserInfo);
|
|
118
|
-
|
|
119
|
-
this.ctx.cookies.set(SESSION_ID_KEY, userSessionInfo.sessionId, sessionCookieCfg);
|
|
120
|
-
|
|
121
|
-
return CommonResult.successMsg('登录成功', userSessionInfo);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
62
|
/**
|
|
127
63
|
* 退出
|
|
128
64
|
*/
|
|
@@ -134,19 +70,17 @@ export class AuthController extends BaseApiController {
|
|
|
134
70
|
return CommonResult.successMsg('退出成功');
|
|
135
71
|
}
|
|
136
72
|
|
|
137
|
-
|
|
138
73
|
/**
|
|
139
74
|
* 避免Session过期,前端需要定时调用此接口刷新
|
|
140
75
|
*/
|
|
141
76
|
@Post('/refreshSession', { middleware: [checkLogin()] })
|
|
142
77
|
async refreshSession(): Promise<CommonResult> {
|
|
143
|
-
const sessionInfo:ISessionInfo = this.ctx.userSession.getSessionInfo();
|
|
78
|
+
const sessionInfo: ISessionInfo = this.ctx.userSession.getSessionInfo();
|
|
144
79
|
const newSessionInfo: ISessionInfo = await this.authService.refreshSession(sessionInfo);
|
|
145
80
|
this.ctx.cookies.set(SESSION_ID_KEY, newSessionInfo.sessionId, sessionCookieCfg);
|
|
146
81
|
return CommonResult.successRes(newSessionInfo);
|
|
147
82
|
}
|
|
148
83
|
|
|
149
|
-
|
|
150
84
|
/**
|
|
151
85
|
* 修改我自己的密码
|
|
152
86
|
*/
|
|
@@ -156,7 +90,7 @@ export class AuthController extends BaseApiController {
|
|
|
156
90
|
const loginName = this.ctx.userSession.getSessionInfo().loginName;
|
|
157
91
|
|
|
158
92
|
if (loginName === 'devopsviewer') {
|
|
159
|
-
return CommonResult.errorRes(
|
|
93
|
+
return CommonResult.errorRes('开放体验账号不支持修改密码');
|
|
160
94
|
}
|
|
161
95
|
|
|
162
96
|
return this.userAccountService.chgUserPassword(loginName, unsaltedPwd);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {Inject, Controller, Get, Param} from '@midwayjs/core';
|
|
2
|
-
import {Context} from '@midwayjs/koa';
|
|
3
|
-
import {BaseApiController} from '../base/BaseApiController';
|
|
4
|
-
import {KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
|
|
5
|
-
import {
|
|
6
|
-
import {WorkbenchService} from '../../service/WorkbenchService';
|
|
7
|
-
import {createRenderUtils} from
|
|
8
|
-
import {privateAES} from
|
|
9
|
-
|
|
1
|
+
import { Inject, Controller, Get, Param } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import { BaseApiController } from '../base/BaseApiController';
|
|
4
|
+
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
5
|
+
import { SystemTables } from '../../models/SystemTables';
|
|
6
|
+
import { WorkbenchService } from '../../service/WorkbenchService';
|
|
7
|
+
import { createRenderUtils } from '../../libs/utils/render-utils';
|
|
8
|
+
import { privateAES } from '../../libs/utils/crypto-utils';
|
|
9
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 渲染独立外部应用
|
|
@@ -21,52 +21,55 @@ export class AppRenderController extends BaseApiController {
|
|
|
21
21
|
|
|
22
22
|
@Get('/:appPath+')
|
|
23
23
|
async home(@Param('appPath') appPath: string): Promise<string> {
|
|
24
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
25
|
+
|
|
24
26
|
const appPathArr = appPath.split('/');
|
|
25
27
|
const appCode = appPathArr[0];
|
|
26
28
|
|
|
27
29
|
const res = await this.curdMixService.executeCrudByCfg(
|
|
28
|
-
{condition: {app_code: appCode}},
|
|
30
|
+
{ condition: { app_code: appCode } },
|
|
29
31
|
{
|
|
30
32
|
sqlTable: SystemTables.sys_app,
|
|
31
33
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
32
34
|
sqlDatabase: SystemDbName,
|
|
33
|
-
|
|
35
|
+
sqlDbType: SystemDbType,
|
|
34
36
|
}
|
|
35
37
|
);
|
|
36
38
|
|
|
37
|
-
const {row: appInfo} = res.getResModel();
|
|
39
|
+
const { row: appInfo } = res.getResModel();
|
|
38
40
|
if (!appInfo) {
|
|
39
41
|
this.ctx.status = 404;
|
|
40
|
-
return this.ctx.render('404_app', {appCode, errorMsg: ' 应用不存在'});
|
|
42
|
+
return this.ctx.render('404_app', { appCode, errorMsg: ' 应用不存在' });
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
if (appInfo.status !== 1) {
|
|
44
46
|
this.ctx.status = 404;
|
|
45
|
-
return this.ctx.render('404_app', {appCode, errorMsg: ' 应用已下线'});
|
|
47
|
+
return this.ctx.render('404_app', { appCode, errorMsg: ' 应用已下线' });
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
const isSupportWorkbench = await this.isSupportCurrentWorkbench(appInfo);
|
|
49
51
|
if (!isSupportWorkbench) {
|
|
50
52
|
this.ctx.status = 404;
|
|
51
|
-
return this.ctx.render('404_app', {appCode, errorMsg: ' 应用没有绑定此站点'});
|
|
53
|
+
return this.ctx.render('404_app', { appCode, errorMsg: ' 应用没有绑定此站点' });
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const workbenchInfo = await this.workbenchService.getCurrentHostWorkbenchInfo();
|
|
55
57
|
|
|
56
58
|
const html_content = appInfo.html_content || '<b style="color: red">错误:未配置HTML模版,请检查!!</b>';
|
|
57
59
|
const userInfo = this.getUserSessionInfo();
|
|
58
|
-
const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64(
|
|
60
|
+
const fatcmscsrftoken = await privateAES.time_encrypt_utf8_base64('' + Date.now());
|
|
59
61
|
|
|
60
62
|
const utils = createRenderUtils({
|
|
61
63
|
ctx: this.ctx,
|
|
62
|
-
appInfo,
|
|
64
|
+
appInfo,
|
|
65
|
+
workbenchInfo,
|
|
66
|
+
userInfo,
|
|
67
|
+
package_assets: appInfo.package_assets,
|
|
68
|
+
fatcmscsrftoken,
|
|
63
69
|
});
|
|
64
|
-
return this.ctx.renderString(html_content, {appInfo, workbenchInfo, userInfo, utils}, {viewEngine: 'ejs'});
|
|
70
|
+
return this.ctx.renderString(html_content, { appInfo, workbenchInfo, userInfo, utils }, { viewEngine: 'ejs' });
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
73
|
private async isSupportCurrentWorkbench(appInfo: any): Promise<boolean> {
|
|
71
74
|
if (this.isLocalEnv()) {
|
|
72
75
|
return true;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {Controller, Get, Inject} from '@midwayjs/core';
|
|
2
|
-
import {Context} from '@midwayjs/koa';
|
|
3
|
-
import {CurdMixService} from '../service/curd/CurdMixService';
|
|
4
|
-
import {BaseApiController} from
|
|
5
|
-
import {IRequestCfgModel} from
|
|
6
|
-
import {KeysOfSimpleSQL, SqlDbType} from
|
|
7
|
-
|
|
1
|
+
import { Controller, Get, Inject } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import { CurdMixService } from '../service/curd/CurdMixService';
|
|
4
|
+
import { BaseApiController } from './base/BaseApiController';
|
|
5
|
+
import { IRequestCfgModel } from '../libs/crud-pro/interfaces';
|
|
6
|
+
import { KeysOfSimpleSQL, SqlDbType } from '../libs/crud-pro/models/keys';
|
|
8
7
|
|
|
9
8
|
// http://127.0.0.1:7002/ns/api/test/testPgQuery
|
|
10
9
|
|
|
11
10
|
@Controller('/ns/api/test')
|
|
12
|
-
export class TestApiController extends BaseApiController{
|
|
11
|
+
export class TestApiController extends BaseApiController {
|
|
13
12
|
@Inject()
|
|
14
13
|
protected ctx: Context;
|
|
15
14
|
|
|
@@ -19,19 +18,20 @@ export class TestApiController extends BaseApiController{
|
|
|
19
18
|
@Get('/testPgQuery')
|
|
20
19
|
async testPgQuery() {
|
|
21
20
|
const cfgModel: IRequestCfgModel = {
|
|
22
|
-
sqlTable:
|
|
21
|
+
sqlTable: 'test_table1',
|
|
23
22
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
24
|
-
sqlDatabase:
|
|
25
|
-
|
|
23
|
+
sqlDatabase: 'postgres_test1',
|
|
24
|
+
sqlDbType: SqlDbType.postgres,
|
|
26
25
|
updateCfg: {},
|
|
27
26
|
};
|
|
28
27
|
|
|
29
|
-
return this.curdMixService.executeCrudByCfg(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
return this.curdMixService.executeCrudByCfg(
|
|
29
|
+
{
|
|
30
|
+
condition: {
|
|
31
|
+
int4: '222',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
cfgModel
|
|
35
|
+
);
|
|
35
36
|
}
|
|
36
|
-
|
|
37
37
|
}
|
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';
|
|
@@ -30,10 +31,6 @@ export * from './controller/manage/SysConfigMangeApi';
|
|
|
30
31
|
export * from './controller/manage/SystemInfoManageApi';
|
|
31
32
|
export * from './controller/manage/UserAccountManageApi';
|
|
32
33
|
export * from './controller/manage/WorkbenchMangeApi';
|
|
33
|
-
export * from './controller/medstatistic/MedAdminController';
|
|
34
|
-
export * from './controller/medstatistic/MedClientController';
|
|
35
|
-
export * from './controller/medstatistic/MedMessageService';
|
|
36
|
-
export * from './controller/medstatistic/MedScoreService';
|
|
37
34
|
export * from './controller/myinfo/AuthController';
|
|
38
35
|
export * from './controller/myinfo/MyInfoController';
|
|
39
36
|
export * from './controller/render/AppRenderController';
|
|
@@ -67,5 +64,42 @@ export * from './service/curd/CurdMixBySysConfigService';
|
|
|
67
64
|
export * from './service/curd/CurdMixByWorkbenchService';
|
|
68
65
|
export * from './service/curd/CurdMixService';
|
|
69
66
|
export * from './service/curd/CurdProService';
|
|
67
|
+
export * from './service/curd/CrudProQuick';
|
|
70
68
|
export * from './service/proxyapi/ProxyApiLoadService';
|
|
71
69
|
export * from './service/proxyapi/ProxyApiService';
|
|
70
|
+
export * from './service/asyncTask/AsyncTaskService';
|
|
71
|
+
export * from './service/asyncTask/AsyncTaskRunnerService';
|
|
72
|
+
export * from './models/userSession';
|
|
73
|
+
export * from './models/bizmodels';
|
|
74
|
+
export * from './models/SystemEntities';
|
|
75
|
+
export * from './models/SystemPerm';
|
|
76
|
+
export * from './models/contextLogger';
|
|
77
|
+
export * from './models/devops';
|
|
78
|
+
export * from './models/SystemTables';
|
|
79
|
+
export * from './models/AsyncTaskModel';
|
|
80
|
+
export * from './schedule/index';
|
|
81
|
+
|
|
82
|
+
export * from './libs/utils/common-dto';
|
|
83
|
+
export * from './libs/utils/crypto-utils';
|
|
84
|
+
export * from './libs/utils/fatcms-request';
|
|
85
|
+
export * from './libs/utils/functions';
|
|
86
|
+
export * from './libs/utils/ordernum-utils';
|
|
87
|
+
export * from './libs/utils/parseConfig';
|
|
88
|
+
|
|
89
|
+
export * from './libs/crud-pro/CrudPro';
|
|
90
|
+
export * from './libs/crud-pro/defaultConfigs';
|
|
91
|
+
export * from './libs/crud-pro/exceptions';
|
|
92
|
+
export * from './libs/crud-pro/interfaces';
|
|
93
|
+
|
|
94
|
+
export * from './libs/crud-pro/models/ExecuteContext';
|
|
95
|
+
export * from './libs/crud-pro/models/FuncContext';
|
|
96
|
+
export * from './libs/crud-pro/models/RequestModel';
|
|
97
|
+
export * from './libs/crud-pro/models/SqlCfgModel';
|
|
98
|
+
export * from './libs/crud-pro/models/Transaction';
|
|
99
|
+
export * from './libs/crud-pro/models/keys';
|
|
100
|
+
export * from './libs/crud-pro/models/ExecuteContextFunc';
|
|
101
|
+
export * from './libs/crud-pro/models/RequestCfgModel';
|
|
102
|
+
export * from './libs/crud-pro/models/SqlSegArg';
|
|
103
|
+
export * from './libs/crud-pro/models/ResModel';
|
|
104
|
+
|
|
105
|
+
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,10 @@ 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
|
+
}
|
|
156
163
|
}
|
|
157
164
|
|
|
158
165
|
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',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// import { Pool as MysqlPool } from 'mysql2/promise';
|
|
2
2
|
// import { Pool as PostgresPool } from 'pg';
|
|
3
|
-
import {KeysOfAuthType, KeysOfSimpleSQL, KeysOfValidators, SqlDbType} from './models/keys';
|
|
3
|
+
import { KeysOfAuthType, KeysOfSimpleSQL, KeysOfValidators, SqlDbType } from './models/keys';
|
|
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
|
|
@@ -102,7 +103,7 @@ export interface IBaseCfgModel {
|
|
|
102
103
|
sqlTable?: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
103
104
|
sqlSchema?: string; // 可以为空
|
|
104
105
|
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
105
|
-
|
|
106
|
+
sqlDbType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
106
107
|
maxLimit?: number; // 最大一次性返回的数量
|
|
107
108
|
columns?: string | string[]; // "columns": "id,name,age,sex,addr",
|
|
108
109
|
columnsRelation?: ColumnRelation[];
|
|
@@ -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,9 @@ export interface ILogger {
|
|
|
181
182
|
error(msg: any, ...args: any[]): void;
|
|
182
183
|
warn(msg: any, ...args: any[]): void;
|
|
183
184
|
}
|
|
185
|
+
|
|
186
|
+
export interface IExecuteUnsafeQueryCtx {
|
|
187
|
+
sqlTable: string;
|
|
188
|
+
sqlDatabase: string;
|
|
189
|
+
sqlDbType: SqlDbType;
|
|
190
|
+
}
|
|
@@ -7,7 +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
|
-
|
|
10
|
+
import { ResModelFlexible } from './ResModel';
|
|
11
11
|
|
|
12
12
|
class ExecuteContext {
|
|
13
13
|
// 运行前设置的
|
|
@@ -20,7 +20,7 @@ class ExecuteContext {
|
|
|
20
20
|
// 运行时设置的。
|
|
21
21
|
private sqlCfgModels: SqlCfgModel[] = [];
|
|
22
22
|
private reqModel: RequestModel = null;
|
|
23
|
-
private resModel:
|
|
23
|
+
private resModel: ResModelFlexible = {};
|
|
24
24
|
private cfgModel: RequestCfgModel = null;
|
|
25
25
|
|
|
26
26
|
setTransaction(transaction: Transaction) {
|
|
@@ -62,7 +62,7 @@ class ExecuteContext {
|
|
|
62
62
|
this.reqModel = reqModel;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
getResModel():
|
|
65
|
+
getResModel(): ResModelFlexible {
|
|
66
66
|
return this.resModel;
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -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';
|
|
@@ -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,15 @@ export class BaseExecuteContextFunc implements IExecuteContextFunc {
|
|
|
76
77
|
return null;
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
/**
|
|
81
|
+
* 在执行之前可以根据业务需要修改需要执行的内容
|
|
82
|
+
* @param reqJson
|
|
83
|
+
* @param cfgJson
|
|
84
|
+
*/
|
|
85
|
+
beforeExecuteSQLList(reqJson: IRequestModel, cfgJson: IRequestCfgModel): Promise<any> {
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
getExecuteContext(): ExecuteContext {
|
|
80
90
|
return this.executeContext;
|
|
81
91
|
}
|
|
@@ -38,7 +38,7 @@ class RequestCfgModel {
|
|
|
38
38
|
sqlTable: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
39
39
|
sqlSchema?: string; // 可以为空
|
|
40
40
|
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
41
|
-
|
|
41
|
+
sqlDbType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
42
42
|
maxLimit = DEFAULT_MAX_LIMIT; // 最大一次性返回的数量
|
|
43
43
|
method: string; // 不能为空
|
|
44
44
|
transactionEnable: boolean; // 是否开启事务,默认不开启,每条语句都是autocommit
|
|
@@ -2,7 +2,7 @@ import * as _ from 'lodash';
|
|
|
2
2
|
import { ILimitOffset, IOrderByItem, IRequestModel, IVisitor } from '../interfaces';
|
|
3
3
|
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
4
|
import { CommonException, Exceptions } from '../exceptions';
|
|
5
|
-
import {DEFAULT_LIMIT} from
|
|
5
|
+
import { DEFAULT_LIMIT } from '../defaultConfigs';
|
|
6
6
|
|
|
7
7
|
class RequestModel {
|
|
8
8
|
visitor: IVisitor;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface ResModelAffected {
|
|
2
|
+
insertId?: string | number;
|
|
3
|
+
affectedRows: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface ResModelStandard {
|
|
7
|
+
row?: any;
|
|
8
|
+
rows?: any[];
|
|
9
|
+
total_count?: number;
|
|
10
|
+
affected?: ResModelAffected;
|
|
11
|
+
insert_affected?: ResModelAffected;
|
|
12
|
+
update_affected?: ResModelAffected;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ResModelFlexible = ResModelStandard & {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { ResModelAffected, ResModelStandard, ResModelFlexible };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnRelation, IFuncCfgModel, ISqlCfgModel } from '../interfaces';
|
|
2
2
|
import { MixinUtils } from '../utils/MixinUtils';
|
|
3
|
-
import { KeyOfCrudTypes, KeysOfSqlResPicker, SqlDbType} from './keys';
|
|
3
|
+
import { KeyOfCrudTypes, KeysOfSqlResPicker, SqlDbType } from './keys';
|
|
4
4
|
import { parseJsonObject } from '../../utils/functions';
|
|
5
5
|
|
|
6
6
|
const { isEmpty } = MixinUtils;
|
|
@@ -11,7 +11,7 @@ class SqlCfgModel {
|
|
|
11
11
|
sqlTable: string; // 可以为空. originSql中不包含@@table时可以为空
|
|
12
12
|
sqlSchema?: string; // 可以为空
|
|
13
13
|
sqlDatabase?: string; // 可以为空,用此字段进行connection的选择和切换。配合getBizConnectionPool使用
|
|
14
|
-
|
|
14
|
+
sqlDbType?: SqlDbType; // 数据库类型,mysql(默认) 、postgres
|
|
15
15
|
maxLimit: number; // 最大一次性返回的数量
|
|
16
16
|
resName: string;
|
|
17
17
|
resPicker: KeysOfSqlResPicker;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {IConnectionPool, IPoolConnectionClient} from '../interfaces';
|
|
2
|
-
import {SqlDbType} from
|
|
3
|
-
import {TransactionMySQL} from
|
|
4
|
-
import {TransactionPostgres} from
|
|
5
|
-
import {TransactionSqlServer} from
|
|
1
|
+
import { IConnectionPool, IPoolConnectionClient } from '../interfaces';
|
|
2
|
+
import { SqlDbType } from './keys';
|
|
3
|
+
import { TransactionMySQL } from './TransactionMySQL';
|
|
4
|
+
import { TransactionPostgres } from './TransactionPostgres';
|
|
5
|
+
import { TransactionSqlServer } from './TransactionSqlServer';
|
|
6
6
|
|
|
7
7
|
class Transaction {
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private transactionSqlServer : TransactionSqlServer = new TransactionSqlServer();
|
|
8
|
+
private transactionMySQL: TransactionMySQL = new TransactionMySQL();
|
|
9
|
+
private transactionPostgres: TransactionPostgres = new TransactionPostgres();
|
|
10
|
+
private transactionSqlServer: TransactionSqlServer = new TransactionSqlServer();
|
|
12
11
|
|
|
13
12
|
private getTxObj(pool: IConnectionPool): TransactionMySQL | TransactionPostgres | TransactionSqlServer {
|
|
14
13
|
if (pool.dbType === SqlDbType.postgres) {
|