midway-fatcms 0.0.1-beta.4 → 0.0.1-beta.41
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 +14 -0
- package/.prettierrc.js +4 -0
- package/README.md +7 -0
- package/dist/config/config.default.js +58 -15
- package/dist/config/seed/aeskey.txt +1 -1
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +33 -9
- package/dist/controller/base/BaseApiController.d.ts +7 -1
- package/dist/controller/base/BaseApiController.js +32 -6
- package/dist/controller/gateway/AsyncTaskController.d.ts +20 -0
- package/dist/controller/gateway/AsyncTaskController.js +181 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
- package/dist/controller/gateway/DocGatewayController.js +14 -9
- package/dist/controller/gateway/FileController.d.ts +3 -2
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.d.ts +0 -1
- package/dist/controller/gateway/StaticController.js +40 -39
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/home.controller.js +4 -3
- 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 +86 -83
- 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 +12 -5
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +5 -5
- package/dist/index.d.ts +35 -4
- package/dist/index.js +35 -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 +12 -5
- 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/Transaction.d.ts +1 -0
- package/dist/libs/crud-pro/models/Transaction.js +7 -0
- 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 +17 -19
- 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 +15 -3
- 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/sql.txt +120 -120
- 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/base64.d.ts +9 -0
- package/dist/libs/utils/base64.js +42 -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/libs/utils/functions.d.ts +2 -1
- package/dist/libs/utils/functions.js +6 -1
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +30 -10
- package/dist/middleware/permission.middleware.js +1 -1
- package/dist/models/AsyncTaskModel.d.ts +74 -0
- package/dist/models/AsyncTaskModel.js +31 -0
- package/dist/models/RedisKeys.d.ts +14 -0
- package/dist/models/RedisKeys.js +17 -0
- package/dist/models/SystemEntities.d.ts +8 -1
- package/dist/models/SystemEntities.js +7 -0
- package/dist/models/SystemTables.d.ts +1 -3
- package/dist/models/SystemTables.js +2 -4
- package/dist/models/bizmodels.d.ts +28 -0
- package/dist/models/bizmodels.js +6 -1
- package/dist/schedule/anonymousContext.d.ts +14 -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 +12 -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 +9 -5
- package/dist/service/FileCenterService.js +13 -9
- package/dist/service/SysConfigService.d.ts +1 -1
- package/dist/service/SysConfigService.js +4 -2
- package/dist/service/UserAccountService.js +10 -6
- package/dist/service/UserSessionService.d.ts +21 -0
- package/dist/service/UserSessionService.js +73 -2
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +20 -27
- package/dist/service/WorkbenchService.d.ts +33 -0
- package/dist/service/WorkbenchService.js +70 -12
- package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
- package/dist/service/anyapi/AnyApiService.js +4 -2
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +50 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +287 -0
- package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
- package/dist/service/asyncTask/AsyncTaskService.js +34 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.d.ts +10 -0
- package/dist/service/asyncTask/handler/ExcelInfoModel.js +2 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.d.ts +7 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +216 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.d.ts +36 -0
- package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +139 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.d.ts +46 -0
- package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +121 -0
- package/dist/service/base/BaseService.d.ts +12 -0
- package/dist/service/base/BaseService.js +22 -0
- package/dist/service/base/RedisCacheService.d.ts +7 -0
- package/dist/service/base/RedisCacheService.js +7 -0
- package/dist/service/crudstd/CrudStdService.d.ts +8 -1
- package/dist/service/crudstd/CrudStdService.js +63 -6
- package/dist/service/curd/CrudProQuick.d.ts +44 -0
- package/dist/service/curd/CrudProQuick.js +147 -0
- package/dist/service/curd/CurdMixByAccountService.d.ts +4 -4
- package/dist/service/curd/CurdMixByAccountService.js +12 -6
- package/dist/service/curd/CurdMixByDictService.d.ts +4 -4
- package/dist/service/curd/CurdMixByDictService.js +10 -7
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +13 -4
- package/dist/service/curd/CurdMixByLinkToCustomService.js +73 -24
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +3 -3
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +3 -3
- package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
- package/dist/service/curd/CurdMixService.d.ts +13 -3
- package/dist/service/curd/CurdMixService.js +26 -2
- package/dist/service/curd/CurdMixUtils.d.ts +27 -4
- package/dist/service/curd/CurdMixUtils.js +115 -41
- package/dist/service/curd/CurdProService.d.ts +3 -10
- package/dist/service/curd/CurdProService.js +36 -148
- 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/service/proxyapi/ProxyApiService.d.ts +1 -0
- package/dist/service/proxyapi/ProxyApiService.js +43 -9
- package/dist/views/404_app.html +31 -31
- package/dist/views/404_workbench.html +34 -34
- package/package.json +28 -24
- 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/config/config.default.ts +0 -172
- package/src/config/seed/aeskey.txt +0 -1
- package/src/config/utils.ts +0 -23
- package/src/configuration.ts +0 -83
- package/src/controller/base/BaseApiController.ts +0 -145
- package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
- package/src/controller/gateway/CrudMtdGatewayController.ts +0 -107
- package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
- package/src/controller/gateway/DocGatewayController.ts +0 -165
- package/src/controller/gateway/FileController.ts +0 -110
- package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
- package/src/controller/gateway/PublicApiController.ts +0 -145
- package/src/controller/gateway/StaticController.ts +0 -328
- package/src/controller/helpers.controller.ts +0 -161
- package/src/controller/home.controller.ts +0 -71
- package/src/controller/manage/AnyApiMangeApi.ts +0 -66
- package/src/controller/manage/AppLogMangeApi.ts +0 -53
- package/src/controller/manage/AppMangeApi.ts +0 -53
- package/src/controller/manage/AppPageMangeApi.ts +0 -52
- package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
- package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
- package/src/controller/manage/CrudStandardDesignApi.ts +0 -353
- package/src/controller/manage/DataDictManageApi.ts +0 -78
- package/src/controller/manage/DeployManageApi.ts +0 -179
- package/src/controller/manage/DocLibManageApi.ts +0 -69
- package/src/controller/manage/DocManageApi.ts +0 -99
- package/src/controller/manage/FileManageApi.ts +0 -45
- package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
- package/src/controller/manage/MenuManageApi.ts +0 -63
- package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
- package/src/controller/manage/SuperAdminManageApi.ts +0 -138
- package/src/controller/manage/SysConfigMangeApi.ts +0 -95
- package/src/controller/manage/SystemInfoManageApi.ts +0 -48
- package/src/controller/manage/UserAccountManageApi.ts +0 -88
- package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
- 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
- package/src/controller/myinfo/AuthController.ts +0 -174
- package/src/controller/myinfo/MyInfoController.ts +0 -32
- package/src/controller/render/AppRenderController.ts +0 -76
- package/src/controller/test.controller.ts +0 -37
- package/src/filter/default.filter.ts +0 -13
- package/src/filter/notfound.filter.ts +0 -10
- package/src/index.ts +0 -71
- package/src/interface.ts +0 -31
- package/src/libs/crud-pro/CrudPro.ts +0 -158
- package/src/libs/crud-pro/defaultConfigs.ts +0 -13
- package/src/libs/crud-pro/exceptions.ts +0 -124
- package/src/libs/crud-pro/interfaces.ts +0 -183
- package/src/libs/crud-pro/models/ExecuteContext.ts +0 -111
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -86
- package/src/libs/crud-pro/models/FuncContext.ts +0 -21
- package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
- package/src/libs/crud-pro/models/RequestModel.ts +0 -141
- package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
- package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
- package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
- package/src/libs/crud-pro/models/Transaction.ts +0 -74
- package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
- package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -107
- package/src/libs/crud-pro/models/keys.ts +0 -159
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -75
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -279
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -373
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -202
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -397
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -98
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -59
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
- package/src/libs/crud-pro/sql.txt +0 -120
- package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
- package/src/libs/crud-pro/utils/DatabaseName.ts +0 -40
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
- package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
- package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
- package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
- package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -167
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
- package/src/libs/utils/common-dto.ts +0 -52
- package/src/libs/utils/crypto-utils.ts +0 -52
- package/src/libs/utils/fatcms-request.ts +0 -115
- package/src/libs/utils/functions.ts +0 -67
- package/src/libs/utils/ordernum-utils.ts +0 -18
- package/src/libs/utils/parseConfig.ts +0 -62
- package/src/libs/utils/parseCreateSql.ts +0 -91
- package/src/libs/utils/render-utils.ts +0 -184
- package/src/middleware/forbidden.middleware.ts +0 -71
- package/src/middleware/global.middleware.ts +0 -278
- package/src/middleware/permission.middleware.ts +0 -81
- package/src/middleware/tx.middleware.ts +0 -30
- package/src/models/SystemEntities.ts +0 -115
- package/src/models/SystemPerm.ts +0 -105
- package/src/models/SystemTables.ts +0 -30
- package/src/models/bizmodels.ts +0 -89
- package/src/models/contextLogger.ts +0 -132
- package/src/models/devops.ts +0 -17
- package/src/models/userSession.ts +0 -216
- package/src/schedule/index.ts +0 -73
- package/src/service/AuthService.ts +0 -270
- package/src/service/EnumInfoService.ts +0 -129
- package/src/service/FileCenterService.ts +0 -394
- package/src/service/SysConfigService.ts +0 -34
- package/src/service/UserAccountService.ts +0 -100
- package/src/service/UserSessionService.ts +0 -81
- package/src/service/VisitStatService.ts +0 -179
- package/src/service/WorkbenchService.ts +0 -160
- package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
- package/src/service/anyapi/AnyApiService.ts +0 -184
- package/src/service/base/ApiBaseService.ts +0 -42
- package/src/service/base/ApiRateLimiter.ts +0 -59
- package/src/service/base/BaseService.ts +0 -74
- package/src/service/base/RedisCacheService.ts +0 -38
- package/src/service/crudstd/CrudStdActionService.ts +0 -27
- package/src/service/crudstd/CrudStdConstant.ts +0 -62
- package/src/service/crudstd/CrudStdRelationService.ts +0 -78
- package/src/service/crudstd/CrudStdService.ts +0 -188
- package/src/service/curd/CurdMixByAccountService.ts +0 -83
- package/src/service/curd/CurdMixByDictService.ts +0 -113
- package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -167
- package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
- package/src/service/curd/CurdMixByWorkbenchService.ts +0 -68
- package/src/service/curd/CurdMixService.ts +0 -65
- package/src/service/curd/CurdMixUtils.ts +0 -248
- package/src/service/curd/CurdProService.ts +0 -379
- package/src/service/proxyapi/ProxyApiLoadService.ts +0 -165
- package/src/service/proxyapi/ProxyApiService.ts +0 -262
- package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
- package/src/service/proxyapi/RouteHandler.ts +0 -8
- package/src/service/proxyapi/RouteTrie.ts +0 -74
- package/src/service/proxyapi/WeightedRandom.ts +0 -37
- package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
- package/src/views/404_app.html +0 -31
- package/src/views/404_workbench.html +0 -34
- package/src/views/static/favicon.ico +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
export enum SqlDbType {
|
|
2
|
-
mysql = 'mysql',
|
|
3
|
-
postgres = 'postgres',
|
|
4
|
-
sqlserver = 'sqlserver', //微软 SQL Server
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export enum KeysOfFunCtx {
|
|
8
|
-
FUNC_CTX = '$',
|
|
9
|
-
CURRENT_VALUE = '$current',
|
|
10
|
-
VISITOR = 'visitor',
|
|
11
|
-
VISITOR_ATTR = 'visitor.',
|
|
12
|
-
REQUEST = 'req.',
|
|
13
|
-
RESULT = 'res.',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//鉴权类型;free无需鉴权,login仅登录即可,byRoleCode校验角色,byFuncCode校验功能点
|
|
17
|
-
export enum KeysOfAuthType {
|
|
18
|
-
free = 'free', // 无需任何校验
|
|
19
|
-
login = 'login', // 仅仅登录即可
|
|
20
|
-
byRoleCode = 'byRoleCode', // 根据角色校验
|
|
21
|
-
byFuncCode = 'byFuncCode', // 根据功能点校验
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export enum KeysOfValidators {
|
|
25
|
-
REQUIRED = 'required',
|
|
26
|
-
BOOLEAN = 'boolean', // 布尔值类型
|
|
27
|
-
OBJECT = 'object', // 普通对象类型类型
|
|
28
|
-
ARRAY = 'array', // 数组
|
|
29
|
-
ARRAY_STRING = 'array:string', // 数组
|
|
30
|
-
ARRAY_NUMBER = 'array:number', // 数组
|
|
31
|
-
STRING = 'string', // 字符串类型
|
|
32
|
-
EMAIL = 'email',
|
|
33
|
-
NAME = 'name', //必须以字母开头,只能包含:字母/数字/下划线
|
|
34
|
-
PHONE_CN = 'phone:cn', // 中国手机号:11位
|
|
35
|
-
INTEGER = 'integer', // long,int,short,bigInteger
|
|
36
|
-
NUMBER = 'number', // long,int,short,float,double
|
|
37
|
-
NUMERIC = 'numeric', //long,int,short,float,double或只包含数字的字符串
|
|
38
|
-
MOMENT = 'moment:', // moment:YYYY-MM-DD HH:mm:ss 时间日期格式校验
|
|
39
|
-
SCALE = 'scale:', // 判断参数是否位于这个区间:scale:[1,3] ; scale:(1,3) ; scale:(1,3] ;
|
|
40
|
-
LENGTH = 'length:', // length:1,5 ; length >=1 and length <=5
|
|
41
|
-
REG_EXP = 'regexp:', // regexp:[a-zA-Z-_.]
|
|
42
|
-
ENUM = 'enum:', // enum : 1,2,3,4,5,6,aa,bb,cc :比较时用字符串比较
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export enum KeyOfCrudTypes {
|
|
46
|
-
SELECT = 'SELECT',
|
|
47
|
-
UPDATE = 'UPDATE',
|
|
48
|
-
INSERT = 'INSERT',
|
|
49
|
-
DELETE = 'DELETE',
|
|
50
|
-
NOT_CRUD = 'NOT_CRUD',
|
|
51
|
-
EMPTY_SQL = 'EMPTY_SQL',
|
|
52
|
-
SYS_QUERY = 'SYS_QUERY',
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export enum KeysOfSimpleSQL {
|
|
56
|
-
SIMPLE_QUERY = 'SIMPLE_QUERY', // select * from xx where @condition limit 100,
|
|
57
|
-
SIMPLE_QUERY_ONE = 'SIMPLE_QUERY_ONE', //只查询一条 select * from xx where @condition limit 1,
|
|
58
|
-
SIMPLE_QUERY_PAGE = 'SIMPLE_QUERY_PAGE', //分页查询 select * from xx where @condition limit 100 offset 100,
|
|
59
|
-
SIMPLE_QUERY_COUNT = 'SIMPLE_QUERY_COUNT', //查询数量 select count(0) as totalCount from xx where @condition,
|
|
60
|
-
SIMPLE_UPDATE = 'SIMPLE_UPDATE', // update xx set @data where @condition limit 1
|
|
61
|
-
SIMPLE_INSERT = 'SIMPLE_INSERT', // insert into xx values @datas
|
|
62
|
-
SIMPLE_DELETE = 'SIMPLE_DELETE', // delete from xx values where @condition limit 1
|
|
63
|
-
SIMPLE_INSERT_ON_DUPLICATE_UPDATE = 'SIMPLE_INSERT_ON_DUPLICATE_UPDATE',
|
|
64
|
-
SIMPLE_INSERT_OR_UPDATE = 'SIMPLE_INSERT_OR_UPDATE',
|
|
65
|
-
CUSTOM = 'CUSTOM',
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export enum KeysOfSqlResPicker {
|
|
69
|
-
UPDATE_RESULT = 'UPDATE_RESULT', // update/insert/delete 产生影响的结果
|
|
70
|
-
RESULT_FIRST_ROW = 'RESULT_FIRST_ROW', // $ResultSet[0], 只取第一行的数据返回。返回JSONObject
|
|
71
|
-
RESULT_TOTAL_COUNT = 'RESULT_TOTAL_COUNT', // $ResultSet[0].total_count , 只取第一行的的total_count。返回long
|
|
72
|
-
RESULT_ONE_VALUE = 'RESULT_ONE_VALUE', // $ResultSet[0].total_count , 只取第一行的的total_count。返回long
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const KeysOfCustomSQL = {
|
|
76
|
-
SQL_COLUMNS: '@@columns',
|
|
77
|
-
SQL_TABLE: '@@table', // 只有简单查询才能用得到
|
|
78
|
-
SQL_OFFSET_LIMIT: '@@offsetLimit',
|
|
79
|
-
SQL_ORDER_BYS: '@@orderBys',
|
|
80
|
-
|
|
81
|
-
SQL_AS_WHERE: '@@asWhere:', // @@asWhere:condition , @@asWhere:condition_zhangsan
|
|
82
|
-
SQL_AS_UPDATE: '@@asUpdate:', // @@asUpdate:data, @@asWhere:data_zhangsan
|
|
83
|
-
SQL_AS_INSERT_KEYS: '@@asInsertKeys:', // @@asInsertKeys:data, @@asInsertKeys:data_zhangsan
|
|
84
|
-
SQL_AS_INSERT_VALUES: '@@asInsertValues:', // @@asInsertValues:data, @@asInsertValues:data_zhangsan
|
|
85
|
-
|
|
86
|
-
// 从Req中取值:单独取Data中的某个字段:获取单个值。
|
|
87
|
-
SQL_GET_DATA_ATTR_START: '@@data', // // select * from fa_lang_faq where id = @@data.id
|
|
88
|
-
SQL_GET_CONDITION_ATTR_START: '@@condition', // select * from fa_lang_faq where id = @@condition.id
|
|
89
|
-
|
|
90
|
-
// 从Res中取值
|
|
91
|
-
SQL_PICK_RES_AS_NUMBER: '@@pickResAsNumber:', // select * from fa_lang_faq where id = @@pickResAsNumber:rows[0].id
|
|
92
|
-
SQL_PICK_RES_AS_STRING: '@@pickResAsString:', // select * from fa_lang_faq where lang_code = @@pickResAsString:row.lang_code
|
|
93
|
-
|
|
94
|
-
// 使用java函数:获取单个值
|
|
95
|
-
SQL_FUNCTION: '@@function:', // @@function:aaa
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 查询条件中允许出现的关键词
|
|
100
|
-
* 与MongoDB的语法完全一致
|
|
101
|
-
*/
|
|
102
|
-
export const KeysOfConditions = {
|
|
103
|
-
$OR: '$or', //或
|
|
104
|
-
|
|
105
|
-
$NE: '$ne', //不等于
|
|
106
|
-
$LT: '$lt', //小于
|
|
107
|
-
$LTE: '$lte', //小于或等于
|
|
108
|
-
$GT: '$gt', //大于
|
|
109
|
-
$GTE: '$gte', //大于或等于
|
|
110
|
-
$IN: '$in', //in
|
|
111
|
-
$NIN: '$nin', // not in
|
|
112
|
-
$NOT_NULL: '$notNull', // is not null
|
|
113
|
-
$NULL: '$null', // is null
|
|
114
|
-
$RANGE: '$range', // between 1 and 2
|
|
115
|
-
$LIKE: '$like', // A% 以A开头 {age:1, name:{"$like":"张"} }
|
|
116
|
-
$NOT_LIKE: '$notLike', // A% 以A开头 {age:1, name:{"$notLike":"张"} }
|
|
117
|
-
|
|
118
|
-
$LIKE_INCLUDE: '$likeInclude', // %A% 包含A {age:1, name:{"$like":"张"} }
|
|
119
|
-
$NOT_LIKE_INCLUDE: '$notLikeInclude', // %A% 包含A {age:1, name:{"$notLike":"张"} }
|
|
120
|
-
|
|
121
|
-
$MATCH: '$match', // 全文索引 {age:1, name:{"$match":"张"} }
|
|
122
|
-
$MATCH_BOOL: '$matchBool', // 全文索引 {age:1, name:{"$matchBool":"张"} }
|
|
123
|
-
|
|
124
|
-
COMPARE_KEYS: new Set<string>([]),
|
|
125
|
-
ALL_KEYS: new Set<string>([]),
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
function initKeysOfConditions() {
|
|
129
|
-
const addIgnoreCase = (keys: Set<string>, key: string) => {
|
|
130
|
-
keys.add(key);
|
|
131
|
-
keys.add(key.toUpperCase());
|
|
132
|
-
keys.add(key.toLowerCase());
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// 比较操作符, 支持忽略大小写
|
|
136
|
-
KeysOfConditions.COMPARE_KEYS = new Set([]);
|
|
137
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NE);
|
|
138
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$LT);
|
|
139
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$LTE);
|
|
140
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$GT);
|
|
141
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$GTE);
|
|
142
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$IN);
|
|
143
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NIN);
|
|
144
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$LIKE);
|
|
145
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$LIKE_INCLUDE);
|
|
146
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NOT_LIKE);
|
|
147
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NOT_LIKE_INCLUDE);
|
|
148
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$MATCH);
|
|
149
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$MATCH_BOOL);
|
|
150
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$RANGE);
|
|
151
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NULL);
|
|
152
|
-
addIgnoreCase(KeysOfConditions.COMPARE_KEYS, KeysOfConditions.$NOT_NULL);
|
|
153
|
-
|
|
154
|
-
// 所有操作符
|
|
155
|
-
KeysOfConditions.ALL_KEYS = new Set([...KeysOfConditions.COMPARE_KEYS]);
|
|
156
|
-
addIgnoreCase(KeysOfConditions.ALL_KEYS, KeysOfConditions.$OR);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
initKeysOfConditions();
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { camelizeKeys } from 'humps';
|
|
2
|
-
import { CrudProServiceBase } from './CrudProServiceBase';
|
|
3
|
-
import { IRequestCfgModel } from '../interfaces';
|
|
4
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
5
|
-
import { ICurdProServiceHub } from '../models/ServiceHub';
|
|
6
|
-
import MemoryRefreshCache from '../utils/MemoryRefreshCache';
|
|
7
|
-
|
|
8
|
-
const methodCache = new MemoryRefreshCache();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function parseMethodInfo(methodInfo: any): any {
|
|
12
|
-
const row: any = camelizeKeys(methodInfo as object); //转换成驼峰
|
|
13
|
-
const configObject = MixinUtils.parseJsonObject(row.moreConfig) || {};
|
|
14
|
-
const sqlCfgList = MixinUtils.parseJsonObject(row.sqlCfgList) || [];
|
|
15
|
-
return {...configObject, ...row, sqlCfgList};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class CrudProCachedCfgService extends CrudProServiceBase {
|
|
21
|
-
constructor(serviceHub: ICurdProServiceHub) {
|
|
22
|
-
super(serviceHub);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public async getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null> {
|
|
26
|
-
|
|
27
|
-
// 不使用缓存
|
|
28
|
-
if (!isEnableCache) {
|
|
29
|
-
return await this.loadMethodInfo(method)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
methodCache.setProps({
|
|
33
|
-
keepTime: 2000,
|
|
34
|
-
requestFn: () => this.loadMethodInfoList(),
|
|
35
|
-
getKeyFn: item => item.method,
|
|
36
|
-
});
|
|
37
|
-
return await methodCache.getItem(method);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
private async loadMethodInfo(method: string): Promise<any> {
|
|
42
|
-
const {methodsTableName, sysDatabaseName} = this.getContextCfg();
|
|
43
|
-
const sql = `select *
|
|
44
|
-
from ${methodsTableName}
|
|
45
|
-
where method = ? `; // 全部加载到内存
|
|
46
|
-
const baseInfo = {
|
|
47
|
-
tableName: methodsTableName, // // 方法配置的表名,默认 sys_crud_pro_methods
|
|
48
|
-
dbName: sysDatabaseName,
|
|
49
|
-
};
|
|
50
|
-
const [rows] = await this.executeUnsafeQuery(baseInfo, sql, [method]);
|
|
51
|
-
const rows2: any[] = rows as object[];
|
|
52
|
-
if (rows2.length > 0) {
|
|
53
|
-
return parseMethodInfo(rows2[0]);
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
private async loadMethodInfoList(): Promise<any[]> {
|
|
61
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
62
|
-
const sql = `select * from ${methodsTableName}`; // 全部加载到内存
|
|
63
|
-
const baseInfo = {
|
|
64
|
-
tableName: methodsTableName, // // 方法配置的表名,默认 sys_crud_pro_methods
|
|
65
|
-
dbName: sysDatabaseName,
|
|
66
|
-
};
|
|
67
|
-
const [rows] = await this.executeUnsafeQuery(baseInfo, sql);
|
|
68
|
-
const rows2: any[] = rows as object[];
|
|
69
|
-
return rows2.map(row => {
|
|
70
|
-
return parseMethodInfo(row);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { CrudProCachedCfgService };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { CrudProServiceBase } from './CrudProServiceBase';
|
|
2
|
-
import { IFuncCfgModel, IFunctionParam } from '../interfaces';
|
|
3
|
-
import { FuncContext } from '../models/FuncContext';
|
|
4
|
-
import { TypeUtils } from '../utils/TypeUtils';
|
|
5
|
-
import { MixinUtils } from '../utils/MixinUtils';
|
|
6
|
-
import * as _ from 'lodash';
|
|
7
|
-
import { CommonException, Exceptions } from '../exceptions';
|
|
8
|
-
import { KeysOfFunCtx } from '../models/keys';
|
|
9
|
-
|
|
10
|
-
const { isNil, isNumeric } = TypeUtils;
|
|
11
|
-
const { isEmpty } = MixinUtils;
|
|
12
|
-
|
|
13
|
-
function isNotNil(obj: any): boolean {
|
|
14
|
-
return !isNil(obj);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class CrudProExecuteFuncService extends CrudProServiceBase {
|
|
18
|
-
executeFuncCfg(funCfg: IFuncCfgModel, funcContext: FuncContext) {
|
|
19
|
-
if (isNil(funCfg)) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (funCfg.___PLAIN_OBJECT___ === true) {
|
|
24
|
-
return funCfg;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (isNotNil(funCfg.const)) {
|
|
28
|
-
return funCfg.const;
|
|
29
|
-
}
|
|
30
|
-
if (isNotNil(funCfg.constString)) {
|
|
31
|
-
return '' + funCfg.constString;
|
|
32
|
-
}
|
|
33
|
-
if (isNotNil(funCfg.constNumber) && isNumeric(funCfg.constNumber)) {
|
|
34
|
-
return Number(funCfg.constNumber);
|
|
35
|
-
}
|
|
36
|
-
if (isNotNil(funCfg.constBool)) {
|
|
37
|
-
return Boolean(funCfg.constBool);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (isNotNil(funCfg.context)) {
|
|
41
|
-
return this.pickContextValue(funCfg.context, funcContext);
|
|
42
|
-
}
|
|
43
|
-
if (isNotNil(funCfg.contextAsString)) {
|
|
44
|
-
return '' + this.pickContextValue(funCfg.contextAsString, funcContext);
|
|
45
|
-
}
|
|
46
|
-
if (isNotNil(funCfg.contextAsNumber)) {
|
|
47
|
-
return Number(this.pickContextValue(funCfg.contextAsNumber, funcContext));
|
|
48
|
-
}
|
|
49
|
-
if (isNotNil(funCfg.contextAsBool)) {
|
|
50
|
-
return Boolean(this.pickContextValue(funCfg.contextAsBool, funcContext));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (isNotNil(funCfg.functionName)) {
|
|
54
|
-
const func = this.getExecuteFunction(funCfg.functionName);
|
|
55
|
-
if (!func) {
|
|
56
|
-
throw new CommonException(Exceptions.RUN_FUNCTION_NOT_FOUND, funCfg.functionName);
|
|
57
|
-
}
|
|
58
|
-
const functionParamValues = this.getFunctionParamValues(funCfg.functionParams, funcContext);
|
|
59
|
-
return func.apply(funcContext, functionParamValues);
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private pickContextValue(pickString: string, funcCtx: FuncContext) {
|
|
65
|
-
if (!pickString) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (pickString === KeysOfFunCtx.FUNC_CTX) {
|
|
70
|
-
return funcCtx;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (pickString === KeysOfFunCtx.CURRENT_VALUE) {
|
|
74
|
-
return funcCtx.currentValue;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 例如:accountId, 访问此变量,用户必须登录。
|
|
78
|
-
if (pickString.startsWith(KeysOfFunCtx.VISITOR_ATTR)) {
|
|
79
|
-
const reqModel = funcCtx?.reqModel;
|
|
80
|
-
const attrValue = _.get(reqModel, pickString); // visitor.nickName
|
|
81
|
-
if (isNil(attrValue)) {
|
|
82
|
-
throw new CommonException(Exceptions.RUN_PICK_ERR_VISITOR_NULL, '获取用户ID失败, 可能用户没有登陆');
|
|
83
|
-
}
|
|
84
|
-
return attrValue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 例如:accountId, 访问此变量,用户必须登录。
|
|
88
|
-
if (pickString === KeysOfFunCtx.VISITOR) {
|
|
89
|
-
const visitor = funcCtx?.reqModel?.visitor;
|
|
90
|
-
if (isNil(visitor)) {
|
|
91
|
-
throw new CommonException(Exceptions.RUN_PICK_ERR_VISITOR_NULL, '获取用户对象失败, 可能用户没有登陆');
|
|
92
|
-
}
|
|
93
|
-
return visitor;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 例如: req.data.name
|
|
97
|
-
if (pickString.startsWith(KeysOfFunCtx.REQUEST)) {
|
|
98
|
-
const reqExpress = pickString.substring(KeysOfFunCtx.REQUEST.length);
|
|
99
|
-
return _.get(funcCtx.reqModel, reqExpress);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 例如: res.total_count
|
|
103
|
-
if (pickString.startsWith(KeysOfFunCtx.RESULT)) {
|
|
104
|
-
const reqExpress = pickString.substring(KeysOfFunCtx.RESULT.length);
|
|
105
|
-
return _.get(funcCtx.resModel, reqExpress);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private getFunctionParamValues(functionParams: IFunctionParam[], funcContext: FuncContext): any[] {
|
|
112
|
-
if (isNil(functionParams) || isEmpty(functionParams)) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
return functionParams.map(p => {
|
|
116
|
-
if (typeof p === 'undefined' || p === null) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (typeof p === 'string' || typeof p === 'number' || typeof p === 'boolean') {
|
|
121
|
-
return p;
|
|
122
|
-
}
|
|
123
|
-
return this.executeFuncCfg(p, funcContext);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export { CrudProExecuteFuncService };
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import * as _ from 'lodash';
|
|
2
|
-
import {PoolClient} from 'pg'
|
|
3
|
-
import {CrudProServiceBase} from './CrudProServiceBase';
|
|
4
|
-
import {SqlCfgModel} from '../models/SqlCfgModel';
|
|
5
|
-
import {KeyOfCrudTypes, KeysOfCustomSQL, KeysOfSqlResPicker, SqlDbType} from '../models/keys';
|
|
6
|
-
import {CommonException, Exceptions} from '../exceptions';
|
|
7
|
-
import {pickAndConvertPgRows} from '../utils/sqlConvert/convertPgType';
|
|
8
|
-
import {replaceQuestionMarks} from "../utils/sqlConvert/convertPgSql";
|
|
9
|
-
import {replaceQuestionMarksForMssql} from "../utils/sqlConvert/convertMsSql";
|
|
10
|
-
import {ModelUtils} from '../utils/ModelUtils';
|
|
11
|
-
import {MixinUtils} from '../utils/MixinUtils';
|
|
12
|
-
import {FuncContext} from '../models/FuncContext';
|
|
13
|
-
import {ExecuteContext} from "../models/ExecuteContext";
|
|
14
|
-
|
|
15
|
-
const { checkFuncCfgValid } = ModelUtils;
|
|
16
|
-
const { isEmpty } = MixinUtils;
|
|
17
|
-
|
|
18
|
-
class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
19
|
-
async executeSqlCfgModels(): Promise<void> {
|
|
20
|
-
const exeCtx = this.getExecuteContext();
|
|
21
|
-
const sqlCfgModels = exeCtx.getSqlCfgModels();
|
|
22
|
-
for (let i = 0; i < sqlCfgModels.length; i++) {
|
|
23
|
-
const sqlCfgModel = sqlCfgModels[i];
|
|
24
|
-
const checkResult = this.executeSqlCfgModelPreCheck(sqlCfgModel);
|
|
25
|
-
if (checkResult) {
|
|
26
|
-
await this.executeSqlCfgModel(sqlCfgModel);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private async executeSqlCfgModel(sqlCfgModel: SqlCfgModel) {
|
|
32
|
-
this.logger.info('executeSqlCfgModel1', sqlCfgModel.executeSql, sqlCfgModel.executeSqlArgs);
|
|
33
|
-
|
|
34
|
-
const exeCtx = this.getExecuteContext();
|
|
35
|
-
const connection = await this.getTxConnectionBySqlCfg(sqlCfgModel);
|
|
36
|
-
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || [])
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let sqlRes: any;
|
|
40
|
-
let queryRes : any;
|
|
41
|
-
|
|
42
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.postgres) { // import { PoolClient } from 'pg';
|
|
43
|
-
|
|
44
|
-
const pgClient: PoolClient = connection as any;
|
|
45
|
-
const pgSql = replaceQuestionMarks(sqlCfgModel.executeSql);
|
|
46
|
-
|
|
47
|
-
this.logger.info('executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
queryRes = await pgClient.query({
|
|
51
|
-
text: pgSql,
|
|
52
|
-
values: executeSqlArgs || []
|
|
53
|
-
});
|
|
54
|
-
sqlRes = pickAndConvertPgRows(queryRes)
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
else if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
|
|
59
|
-
|
|
60
|
-
const mssql = replaceQuestionMarksForMssql(sqlCfgModel.executeSql);
|
|
61
|
-
|
|
62
|
-
this.logger.info('executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
63
|
-
// SQLServer
|
|
64
|
-
queryRes = await connection.query(mssql, executeSqlArgs);
|
|
65
|
-
sqlRes = _.get(queryRes,'recordsets[0]') || []
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
else {
|
|
69
|
-
|
|
70
|
-
this.logger.info('executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// MYSQL
|
|
74
|
-
queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
|
|
75
|
-
sqlRes = queryRes[0]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
|
|
79
|
-
exeCtx.setResModelItem(sqlCfgModel.resName, resObject);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
private handleExecuteSqlArgsByResModel(exeCtx: ExecuteContext, executeSqlArgs: any[]): any[] {
|
|
84
|
-
return executeSqlArgs.map((arg)=> {
|
|
85
|
-
if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string' ) {
|
|
86
|
-
const word: string = arg.___GENERATE_GET_RES_ATTR___;
|
|
87
|
-
if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)) {
|
|
88
|
-
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)
|
|
89
|
-
this.logger.info('handleExecuteSqlArgsByResModel resName', resName);
|
|
90
|
-
this.logger.info('handleExecuteSqlArgsByResModel getResModel', exeCtx.getResModel());
|
|
91
|
-
return Number(exeCtx.getResModelItemLodash(resName) || 0);
|
|
92
|
-
}
|
|
93
|
-
if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_STRING)) {
|
|
94
|
-
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_STRING)
|
|
95
|
-
return String(exeCtx.getResModelItemLodash(resName) || "");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return arg;
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
private executeSqlCfgModelPreCheck(sqlCfgModel: SqlCfgModel): boolean {
|
|
104
|
-
const crudType = sqlCfgModel.getCrudType();
|
|
105
|
-
|
|
106
|
-
if (KeyOfCrudTypes.EMPTY_SQL === crudType) {
|
|
107
|
-
// 允许空SQL,没有需要执行的正常。
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (KeyOfCrudTypes.NOT_CRUD === crudType) {
|
|
112
|
-
// 只支持增删改查,其他语句不支持。
|
|
113
|
-
throw new CommonException(Exceptions.CFG_NOT_SUPPORT_THE_SQL, sqlCfgModel.executeSql);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// 此SQL不需要执行
|
|
117
|
-
if (!this.isNeedExecute(sqlCfgModel)) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 执行之前,根据配置校验一下此SQL是否可以执行
|
|
122
|
-
this.assertByValidate(sqlCfgModel);
|
|
123
|
-
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private assertByValidate(sqlCfgModel: SqlCfgModel) {
|
|
128
|
-
const exeCtx = this.getExecuteContext();
|
|
129
|
-
const funcCfg = sqlCfgModel.validate;
|
|
130
|
-
if (!funcCfg) {
|
|
131
|
-
return; // 没有配置。
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (!checkFuncCfgValid(funcCfg)) {
|
|
135
|
-
throw new CommonException(Exceptions.CFG_SQL_CFG_EXECUTE_VALIDATE_EMPTY, {
|
|
136
|
-
funcCfg: funcCfg,
|
|
137
|
-
originSql: sqlCfgModel.originSql,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const errMsg = funcCfg.message || '执行前校验失败';
|
|
142
|
-
|
|
143
|
-
let result;
|
|
144
|
-
try {
|
|
145
|
-
const exeFunCtx = new FuncContext();
|
|
146
|
-
|
|
147
|
-
exeFunCtx.currentValue = null;
|
|
148
|
-
exeFunCtx.reqModel = exeCtx.getReqModel();
|
|
149
|
-
exeFunCtx.resModel = exeCtx.getResModel();
|
|
150
|
-
|
|
151
|
-
result = this.serviceHub.executeFuncCfg(funcCfg, exeFunCtx); // 可以抛出异常
|
|
152
|
-
} catch (e) {
|
|
153
|
-
this.logger.debug('assertByValidate', e);
|
|
154
|
-
throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, {
|
|
155
|
-
funcCfg: funcCfg,
|
|
156
|
-
originSql: sqlCfgModel.originSql,
|
|
157
|
-
error: '' + e,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!(typeof result === 'boolean')) {
|
|
162
|
-
// 自定义的校验函数,必须返回boolean类型的树枝
|
|
163
|
-
throw new CommonException(Exceptions.CFG_IS_NEED_EXECUTE_FUNC_MUST_RETURN_BOOL, {
|
|
164
|
-
funcCfg: funcCfg,
|
|
165
|
-
originSql: sqlCfgModel.originSql,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (result === false) {
|
|
170
|
-
throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, errMsg);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 判断此SQL是否需要执行
|
|
176
|
-
* @param sqlCfgModel
|
|
177
|
-
* @param exeCtx
|
|
178
|
-
* @private
|
|
179
|
-
*/
|
|
180
|
-
private isNeedExecute(sqlCfgModel: SqlCfgModel) {
|
|
181
|
-
const exeCtx = this.getExecuteContext();
|
|
182
|
-
const funcCfg = sqlCfgModel.executeWhen;
|
|
183
|
-
if (!funcCfg || Object.keys(funcCfg).length === 0) {
|
|
184
|
-
return true; // 没有配置。默认,需要执行。
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!checkFuncCfgValid(funcCfg)) {
|
|
188
|
-
throw new CommonException(Exceptions.CFG_CHECK_EXECUTE_WHEN_EMPTY, {
|
|
189
|
-
funcCfg: funcCfg,
|
|
190
|
-
originSql: sqlCfgModel.originSql,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
let result;
|
|
195
|
-
|
|
196
|
-
try {
|
|
197
|
-
const exeFunCtx = new FuncContext();
|
|
198
|
-
|
|
199
|
-
exeFunCtx.currentValue = null;
|
|
200
|
-
exeFunCtx.reqModel = exeCtx.getReqModel();
|
|
201
|
-
exeFunCtx.resModel = exeCtx.getResModel();
|
|
202
|
-
|
|
203
|
-
result = this.serviceHub.executeFuncCfg(funcCfg, exeFunCtx);
|
|
204
|
-
} catch (e) {
|
|
205
|
-
this.logger.debug('isNeedExecute', e);
|
|
206
|
-
throw new CommonException(Exceptions.RUN_IS_NEED_EXECUTE_ERR, {
|
|
207
|
-
funcCfg: funcCfg,
|
|
208
|
-
originSql: sqlCfgModel.originSql,
|
|
209
|
-
error: '' + e,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (!(typeof result === 'boolean')) {
|
|
214
|
-
// 自定义的校验函数,必须返回boolean类型的树枝
|
|
215
|
-
throw new CommonException(Exceptions.CFG_IS_NEED_EXECUTE_FUNC_MUST_RETURN_BOOL, {
|
|
216
|
-
funcCfg: funcCfg,
|
|
217
|
-
originSql: sqlCfgModel.originSql,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return result === true;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private toQueryResByResPicker(sqlRes: any, queryRes: any, sqlCfgModel: SqlCfgModel) {
|
|
225
|
-
const resPicker = sqlCfgModel.resPicker;
|
|
226
|
-
|
|
227
|
-
// 返回第一行
|
|
228
|
-
if (KeysOfSqlResPicker.RESULT_FIRST_ROW === resPicker) {
|
|
229
|
-
const rows = sqlRes as any[];
|
|
230
|
-
if (rows && rows.length > 0) {
|
|
231
|
-
return rows[0];
|
|
232
|
-
}
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// $ResultSet[0].total_count , 只取第一行的的total_count
|
|
237
|
-
if (KeysOfSqlResPicker.RESULT_TOTAL_COUNT === resPicker) {
|
|
238
|
-
const rows = sqlRes as any[];
|
|
239
|
-
if (isEmpty(rows)) {
|
|
240
|
-
return 0;
|
|
241
|
-
}
|
|
242
|
-
const map0 = rows[0];
|
|
243
|
-
return Number(map0['total_count'] || 0);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// 增删改res的内容是修改结果:包括: insert\delete\update
|
|
247
|
-
if (KeysOfSqlResPicker.UPDATE_RESULT === resPicker) {
|
|
248
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.postgres) {
|
|
249
|
-
return {
|
|
250
|
-
insertId: _.get(queryRes,'rows[0].id'),
|
|
251
|
-
affectedRows: _.get(queryRes,'rowCount')
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
|
|
256
|
-
return {
|
|
257
|
-
insertId: _.get(queryRes,'recordset[0].id'),
|
|
258
|
-
affectedRows: _.get(queryRes,'rowsAffected[0]')
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return sqlRes;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
//其他配置:形如: sqlRes[0].total_count
|
|
266
|
-
if (typeof resPicker === 'string') {
|
|
267
|
-
if (resPicker.startsWith('sqlRes')){
|
|
268
|
-
return _.get({ sqlRes }, resPicker);
|
|
269
|
-
} else {
|
|
270
|
-
throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, 'resPicker必须是以sqlRes开头')
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return sqlRes;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export { CrudProExecuteSqlService };
|