midway-fatcms 0.0.1-beta.2 → 0.0.1-beta.20
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 +9 -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/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/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/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +38 -34
- package/dist/controller/manage/MenuManageApi.js +1 -1
- 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 +6 -4
- 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 +5 -0
- package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
- 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 +22 -11
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -9
- 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 +31 -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/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 +226 -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 +1 -0
- package/dist/service/crudstd/CrudStdService.js +34 -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 +19 -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 +9 -9
- package/src/controller/manage/AppLogMangeApi.ts +3 -3
- package/src/controller/manage/AppMangeApi.ts +5 -5
- package/src/controller/manage/AppPageMangeApi.ts +3 -3
- package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
- package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
- package/src/controller/manage/CrudStandardDesignApi.ts +106 -113
- package/src/controller/manage/DataDictManageApi.ts +4 -4
- package/src/controller/manage/DeployManageApi.ts +85 -89
- package/src/controller/manage/DocLibManageApi.ts +3 -3
- package/src/controller/manage/DocManageApi.ts +8 -8
- package/src/controller/manage/MenuManageApi.ts +9 -14
- package/src/controller/manage/SuperAdminManageApi.ts +14 -13
- package/src/controller/manage/SysConfigMangeApi.ts +9 -9
- package/src/controller/manage/SystemInfoManageApi.ts +11 -6
- package/src/controller/manage/UserAccountManageApi.ts +8 -2
- package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
- 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 +26 -19
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +38 -50
- 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 +35 -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/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 +249 -0
- package/src/service/asyncTask/AsyncTaskService.ts +21 -0
- package/src/service/base/BaseService.ts +2 -2
- package/src/service/crudstd/CrudStdService.ts +43 -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,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) {
|
|
@@ -55,14 +63,13 @@ class CrudProCachedCfgService extends CrudProServiceBase {
|
|
|
55
63
|
return null;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
66
|
private async loadMethodInfoList(): Promise<any[]> {
|
|
61
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
67
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
62
68
|
const sql = `select * from ${methodsTableName}`; // 全部加载到内存
|
|
63
69
|
const baseInfo = {
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
sqlTable: methodsTableName,
|
|
71
|
+
sqlDatabase: sysDatabaseName,
|
|
72
|
+
sqlDbType: sysDatabaseDbType,
|
|
66
73
|
};
|
|
67
74
|
const [rows] = await this.executeUnsafeQuery(baseInfo, sql);
|
|
68
75
|
const rows2: any[] = rows as object[];
|
|
@@ -1,16 +1,16 @@
|
|
|
1
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
|
|
9
|
-
import {replaceQuestionMarksForMssql} from
|
|
10
|
-
import {ModelUtils} from '../utils/ModelUtils';
|
|
11
|
-
import {MixinUtils} from '../utils/MixinUtils';
|
|
12
|
-
import {FuncContext} from '../models/FuncContext';
|
|
13
|
-
import {ExecuteContext} from
|
|
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
14
|
|
|
15
15
|
const { checkFuncCfgValid } = ModelUtils;
|
|
16
16
|
const { isEmpty } = MixinUtils;
|
|
@@ -33,73 +33,62 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
|
33
33
|
|
|
34
34
|
const exeCtx = this.getExecuteContext();
|
|
35
35
|
const connection = await this.getTxConnectionBySqlCfg(sqlCfgModel);
|
|
36
|
-
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || [])
|
|
37
|
-
|
|
36
|
+
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || []);
|
|
38
37
|
|
|
39
38
|
let sqlRes: any;
|
|
40
|
-
let queryRes
|
|
39
|
+
let queryRes: any;
|
|
41
40
|
|
|
42
|
-
if (sqlCfgModel.
|
|
41
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.postgres) {
|
|
42
|
+
// import { PoolClient } from 'pg';
|
|
43
43
|
|
|
44
44
|
const pgClient: PoolClient = connection as any;
|
|
45
45
|
const pgSql = replaceQuestionMarks(sqlCfgModel.executeSql);
|
|
46
46
|
|
|
47
47
|
this.logger.info('executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
queryRes = await pgClient.query({
|
|
51
50
|
text: pgSql,
|
|
52
|
-
values: executeSqlArgs || []
|
|
51
|
+
values: executeSqlArgs || [],
|
|
53
52
|
});
|
|
54
|
-
sqlRes = pickAndConvertPgRows(queryRes)
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
else if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
|
|
59
|
-
|
|
53
|
+
sqlRes = pickAndConvertPgRows(queryRes);
|
|
54
|
+
} else if (sqlCfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
60
55
|
const mssql = replaceQuestionMarksForMssql(sqlCfgModel.executeSql);
|
|
61
56
|
|
|
62
57
|
this.logger.info('executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
63
58
|
// SQLServer
|
|
64
59
|
queryRes = await connection.query(mssql, executeSqlArgs);
|
|
65
|
-
sqlRes = _.get(queryRes,'recordsets[0]') || []
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
else {
|
|
69
|
-
|
|
60
|
+
sqlRes = _.get(queryRes, 'recordsets[0]') || [];
|
|
61
|
+
} else {
|
|
70
62
|
this.logger.info('executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
71
63
|
|
|
72
|
-
|
|
73
64
|
// MYSQL
|
|
74
65
|
queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
|
|
75
|
-
sqlRes = queryRes[0]
|
|
66
|
+
sqlRes = queryRes[0];
|
|
76
67
|
}
|
|
77
68
|
|
|
78
69
|
const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
|
|
79
70
|
exeCtx.setResModelItem(sqlCfgModel.resName, resObject);
|
|
80
71
|
}
|
|
81
72
|
|
|
82
|
-
|
|
83
73
|
private handleExecuteSqlArgsByResModel(exeCtx: ExecuteContext, executeSqlArgs: any[]): any[] {
|
|
84
|
-
return executeSqlArgs.map(
|
|
85
|
-
if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string'
|
|
74
|
+
return executeSqlArgs.map(arg => {
|
|
75
|
+
if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string') {
|
|
86
76
|
const word: string = arg.___GENERATE_GET_RES_ATTR___;
|
|
87
77
|
if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)) {
|
|
88
|
-
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)
|
|
78
|
+
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER);
|
|
89
79
|
this.logger.info('handleExecuteSqlArgsByResModel resName', resName);
|
|
90
80
|
this.logger.info('handleExecuteSqlArgsByResModel getResModel', exeCtx.getResModel());
|
|
91
81
|
return Number(exeCtx.getResModelItemLodash(resName) || 0);
|
|
92
82
|
}
|
|
93
83
|
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) ||
|
|
84
|
+
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_STRING);
|
|
85
|
+
return String(exeCtx.getResModelItemLodash(resName) || '');
|
|
96
86
|
}
|
|
97
87
|
}
|
|
98
88
|
return arg;
|
|
99
|
-
})
|
|
89
|
+
});
|
|
100
90
|
}
|
|
101
91
|
|
|
102
|
-
|
|
103
92
|
private executeSqlCfgModelPreCheck(sqlCfgModel: SqlCfgModel): boolean {
|
|
104
93
|
const crudType = sqlCfgModel.getCrudType();
|
|
105
94
|
|
|
@@ -245,18 +234,18 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
|
245
234
|
|
|
246
235
|
// 增删改res的内容是修改结果:包括: insert\delete\update
|
|
247
236
|
if (KeysOfSqlResPicker.UPDATE_RESULT === resPicker) {
|
|
248
|
-
if (sqlCfgModel.
|
|
237
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.postgres) {
|
|
249
238
|
return {
|
|
250
|
-
insertId: _.get(queryRes,'rows[0].id'),
|
|
251
|
-
affectedRows: _.get(queryRes,'rowCount')
|
|
252
|
-
}
|
|
239
|
+
insertId: _.get(queryRes, 'rows[0].id'),
|
|
240
|
+
affectedRows: _.get(queryRes, 'rowCount'),
|
|
241
|
+
};
|
|
253
242
|
}
|
|
254
243
|
|
|
255
|
-
if (sqlCfgModel.
|
|
244
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
256
245
|
return {
|
|
257
|
-
insertId: _.get(queryRes,'recordset[0].id'),
|
|
258
|
-
affectedRows: _.get(queryRes,'rowsAffected[0]')
|
|
259
|
-
}
|
|
246
|
+
insertId: _.get(queryRes, 'recordset[0].id'),
|
|
247
|
+
affectedRows: _.get(queryRes, 'rowsAffected[0]'),
|
|
248
|
+
};
|
|
260
249
|
}
|
|
261
250
|
|
|
262
251
|
return sqlRes;
|
|
@@ -264,16 +253,15 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
|
264
253
|
|
|
265
254
|
//其他配置:形如: sqlRes[0].total_count
|
|
266
255
|
if (typeof resPicker === 'string') {
|
|
267
|
-
if (resPicker.startsWith('sqlRes')){
|
|
256
|
+
if (resPicker.startsWith('sqlRes')) {
|
|
268
257
|
return _.get({ sqlRes }, resPicker);
|
|
269
258
|
} else {
|
|
270
|
-
throw
|
|
259
|
+
throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, 'resPicker必须是以sqlRes开头');
|
|
271
260
|
}
|
|
272
261
|
}
|
|
273
262
|
|
|
274
263
|
return sqlRes;
|
|
275
264
|
}
|
|
276
|
-
|
|
277
265
|
}
|
|
278
266
|
|
|
279
267
|
export { CrudProExecuteSqlService };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {SqlSegArg} from '../models/SqlSegArg';
|
|
2
|
-
import {MixinUtils} from '../utils/MixinUtils';
|
|
3
|
-
import {KeysOfConditions, SqlDbType} from '../models/keys';
|
|
4
|
-
import {CommonException, Exceptions} from '../exceptions';
|
|
5
|
-
import {ICompareCondition, IRequestCondition} from '../interfaces';
|
|
6
|
-
import {TypeUtils} from '../utils/TypeUtils';
|
|
7
|
-
import {SqlCfgModel} from
|
|
8
|
-
import {toSqlColumnName} from '../utils/sqlConvert/convertColumnName';
|
|
1
|
+
import { SqlSegArg } from '../models/SqlSegArg';
|
|
2
|
+
import { MixinUtils } from '../utils/MixinUtils';
|
|
3
|
+
import { KeysOfConditions, SqlDbType } from '../models/keys';
|
|
4
|
+
import { CommonException, Exceptions } from '../exceptions';
|
|
5
|
+
import { ICompareCondition, IRequestCondition } from '../interfaces';
|
|
6
|
+
import { TypeUtils } from '../utils/TypeUtils';
|
|
7
|
+
import { SqlCfgModel } from '../models/SqlCfgModel';
|
|
8
|
+
import { toSqlColumnName } from '../utils/sqlConvert/convertColumnName';
|
|
9
9
|
|
|
10
10
|
const { equalsIgnoreCase, isEmpty, isNotEmpty } = MixinUtils;
|
|
11
11
|
const { isBasicType, isNumber } = TypeUtils;
|
|
@@ -13,16 +13,14 @@ const { isBasicType, isNumber } = TypeUtils;
|
|
|
13
13
|
const createFunc = (sqlCfg: SqlCfgModel) => {
|
|
14
14
|
return {
|
|
15
15
|
toSqlColumnName: (columnName: string): string => {
|
|
16
|
-
return toSqlColumnName(columnName, sqlCfg)
|
|
16
|
+
return toSqlColumnName(columnName, sqlCfg);
|
|
17
17
|
},
|
|
18
18
|
toMatchSqlColumnName: (columnName: string): string => {
|
|
19
19
|
const arr = columnName.split(',');
|
|
20
|
-
return arr
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
20
|
+
return arr.map(s => toSqlColumnName(s.trim(), sqlCfg)).join(',');
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
26
24
|
|
|
27
25
|
class ValueChecker {
|
|
28
26
|
checkBasicArrayAndNotEmpty(value0: any, message: string) {
|
|
@@ -212,42 +210,31 @@ class CrudProGenSqlCondition {
|
|
|
212
210
|
tmpArgList.push(value0);
|
|
213
211
|
tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI like concat(?, '%')`; // like前缀匹配
|
|
214
212
|
|
|
215
|
-
if (this.sqlCfg.
|
|
216
|
-
tmpSql = `${toSqlColumnName(key)} like concat(
|
|
213
|
+
if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
|
|
214
|
+
tmpSql = `${toSqlColumnName(key)} like concat(?::text, '%')`; // like前缀匹配
|
|
217
215
|
}
|
|
218
|
-
|
|
219
216
|
} else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE, compare)) {
|
|
220
217
|
tmpArgList.push(value0);
|
|
221
218
|
tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI not like concat(?, '%')`;
|
|
222
219
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
tmpSql = `${toSqlColumnName(key)} not like concat(?, '%')`;
|
|
220
|
+
if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
|
|
221
|
+
tmpSql = `${toSqlColumnName(key)} not like concat(?::text, '%')`;
|
|
226
222
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
|
|
223
|
+
} else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
|
|
232
224
|
tmpArgList.push(value0);
|
|
233
225
|
tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI like concat('%', ?, '%')`; // like包含
|
|
234
226
|
|
|
235
|
-
if (this.sqlCfg.
|
|
236
|
-
tmpSql = `${toSqlColumnName(key)} like concat('%',
|
|
227
|
+
if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
|
|
228
|
+
tmpSql = `${toSqlColumnName(key)} like concat('%', ?::text, '%')`; // like包含
|
|
237
229
|
}
|
|
238
|
-
|
|
239
230
|
} else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE_INCLUDE, compare)) {
|
|
240
231
|
tmpArgList.push(value0);
|
|
241
|
-
tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI not like concat('%',?, '%')`;
|
|
232
|
+
tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI not like concat('%',?, '%')`; // like不包含
|
|
242
233
|
|
|
243
|
-
if (this.sqlCfg.
|
|
244
|
-
tmpSql = `${toSqlColumnName(key)} not like concat('%'
|
|
234
|
+
if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
|
|
235
|
+
tmpSql = `${toSqlColumnName(key)} not like concat('%',?::text, '%')`; // like不包含
|
|
245
236
|
}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
|
|
237
|
+
} else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
|
|
251
238
|
tmpArgList.push(value0);
|
|
252
239
|
tmpSql = `match(${toMatchSqlColumnName(key)}) against(?)`;
|
|
253
240
|
} else if (equalsIgnoreCase(KeysOfConditions.$MATCH_BOOL, compare)) {
|
|
@@ -328,10 +315,7 @@ class CrudProGenSqlCondition {
|
|
|
328
315
|
if (!isBasicType(value0)) {
|
|
329
316
|
throwCommonException(KeysOfConditions.$NOT_LIKE, '字符串');
|
|
330
317
|
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
|
|
318
|
+
} else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
|
|
335
319
|
if (!isBasicType(value0)) {
|
|
336
320
|
throwCommonException(KeysOfConditions.$LIKE_INCLUDE, '字符串');
|
|
337
321
|
}
|
|
@@ -339,10 +323,7 @@ class CrudProGenSqlCondition {
|
|
|
339
323
|
if (!isBasicType(value0)) {
|
|
340
324
|
throwCommonException(KeysOfConditions.$NOT_LIKE_INCLUDE, '字符串');
|
|
341
325
|
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
|
|
326
|
+
} else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
|
|
346
327
|
if (!isBasicType(value0)) {
|
|
347
328
|
throwCommonException(KeysOfConditions.$MATCH, '字符串');
|
|
348
329
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CrudProServiceBase } from './CrudProServiceBase';
|
|
2
2
|
import { CommonException, Exceptions } from '../exceptions';
|
|
3
3
|
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
|
-
import {KeysOfSimpleSQL, KeysOfSqlResPicker, SqlDbType} from '../models/keys';
|
|
5
|
-
import {RequestCfgModel} from
|
|
4
|
+
import { KeysOfSimpleSQL, KeysOfSqlResPicker, SqlDbType } from '../models/keys';
|
|
5
|
+
import { RequestCfgModel } from '../models/RequestCfgModel';
|
|
6
6
|
|
|
7
7
|
const { equalsIgnoreCase, isEmpty, isNotEmpty } = MixinUtils;
|
|
8
8
|
|
|
@@ -96,11 +96,11 @@ class CrudProGenSqlService extends CrudProServiceBase {
|
|
|
96
96
|
* @param cfgModel
|
|
97
97
|
* @private
|
|
98
98
|
*/
|
|
99
|
-
private generateOriginSqlForDelete(cfgModel: RequestCfgModel)
|
|
100
|
-
if (cfgModel.
|
|
99
|
+
private generateOriginSqlForDelete(cfgModel: RequestCfgModel): string {
|
|
100
|
+
if (cfgModel.sqlDbType === SqlDbType.postgres) {
|
|
101
101
|
return 'delete from @@table where @@asWhere:condition ';
|
|
102
102
|
}
|
|
103
|
-
if (cfgModel.
|
|
103
|
+
if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
104
104
|
return 'delete from @@table where @@asWhere:condition ';
|
|
105
105
|
}
|
|
106
106
|
return 'delete from @@table where @@asWhere:condition limit 100 '; // 删除操作,不能一次性删除太多
|
|
@@ -111,78 +111,63 @@ class CrudProGenSqlService extends CrudProServiceBase {
|
|
|
111
111
|
* @param cfgModel
|
|
112
112
|
* @private
|
|
113
113
|
*/
|
|
114
|
-
private generateOriginSqlForDuplicateInsert(cfgModel: RequestCfgModel)
|
|
115
|
-
if (cfgModel.
|
|
116
|
-
const uniqueColumn = cfgModel.uniqueColumn
|
|
114
|
+
private generateOriginSqlForDuplicateInsert(cfgModel: RequestCfgModel): string {
|
|
115
|
+
if (cfgModel.sqlDbType === SqlDbType.postgres) {
|
|
116
|
+
const uniqueColumn = cfgModel.uniqueColumn; // id
|
|
117
117
|
if (!Array.isArray(uniqueColumn) || uniqueColumn.length === 0) {
|
|
118
|
-
throw new CommonException(Exceptions.CFG_ERROR_POSTGRES_UNIQUE_COLUMNS_NULL)
|
|
118
|
+
throw new CommonException(Exceptions.CFG_ERROR_POSTGRES_UNIQUE_COLUMNS_NULL);
|
|
119
119
|
}
|
|
120
|
-
const unique_column = uniqueColumn
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
const unique_column = uniqueColumn
|
|
121
|
+
.map(s => {
|
|
122
|
+
return `"${s}"`;
|
|
123
|
+
})
|
|
124
|
+
.join(',');
|
|
123
125
|
return `insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) ON CONFLICT (${unique_column}) DO UPDATE set @@asUpdate:data `; // 关键字的前后,必须有空格
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const uniqueColumn = cfgModel.uniqueColumn ; // id
|
|
128
|
+
if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
129
|
+
const uniqueColumn = cfgModel.uniqueColumn; // id
|
|
129
130
|
if (uniqueColumn.length !== 1) {
|
|
130
131
|
throw new CommonException(Exceptions.CFG_UNIQUE_COLUMN_COUNT_MUST_ONE);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
const uniqueColumnStr = uniqueColumn[0];
|
|
134
|
-
const uniqueColumnVal =
|
|
135
|
-
|
|
136
|
-
const sql =
|
|
137
|
-
`IF EXISTS (SELECT 1 FROM @@table WHERE [${uniqueColumnStr}] = ${uniqueColumnVal})` +
|
|
138
|
-
"BEGIN\n" +
|
|
139
|
-
" UPDATE @@table\n" +
|
|
140
|
-
" SET @@asUpdate:data\n" +
|
|
141
|
-
` WHERE [${uniqueColumnStr}] = ${uniqueColumnVal} ;\n` +
|
|
142
|
-
"END\n" +
|
|
143
|
-
"ELSE\n" +
|
|
144
|
-
"BEGIN\n" +
|
|
145
|
-
" INSERT INTO @@table ( @@asInsertKeys:data )\n" +
|
|
146
|
-
" VALUES ( @@asInsertValues:data );\n" +
|
|
147
|
-
"END";
|
|
135
|
+
const uniqueColumnVal = '@@data.' + uniqueColumnStr;
|
|
136
|
+
|
|
137
|
+
const sql = '' + `IF EXISTS (SELECT 1 FROM @@table WHERE [${uniqueColumnStr}] = ${uniqueColumnVal})` + 'BEGIN\n' + ' UPDATE @@table\n' + ' SET @@asUpdate:data\n' + ` WHERE [${uniqueColumnStr}] = ${uniqueColumnVal} ;\n` + 'END\n' + 'ELSE\n' + 'BEGIN\n' + ' INSERT INTO @@table ( @@asInsertKeys:data )\n' + ' VALUES ( @@asInsertValues:data );\n' + 'END';
|
|
148
138
|
|
|
149
139
|
return sql;
|
|
150
140
|
}
|
|
151
141
|
|
|
152
|
-
|
|
153
142
|
return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) on duplicate key update @@asUpdate:data '; // 关键字的前后,必须有空格
|
|
154
143
|
}
|
|
155
144
|
|
|
156
|
-
|
|
157
145
|
/**
|
|
158
146
|
* 创建插入语句
|
|
159
147
|
* @param cfgModel
|
|
160
148
|
* @private
|
|
161
149
|
*/
|
|
162
150
|
private generateOriginSqlForInsert(cfgModel: RequestCfgModel): string {
|
|
163
|
-
if (cfgModel.
|
|
151
|
+
if (cfgModel.sqlDbType === SqlDbType.postgres) {
|
|
164
152
|
return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) RETURNING * ';
|
|
165
153
|
}
|
|
166
|
-
if (cfgModel.
|
|
154
|
+
if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
167
155
|
return 'insert into @@table ( @@asInsertKeys:data ) OUTPUT INSERTED.* values( @@asInsertValues:data ) ';
|
|
168
156
|
}
|
|
169
157
|
return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data )'; // 关键字的前后,必须有空格
|
|
170
158
|
}
|
|
171
159
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
160
|
private async generateExecuteSql() {
|
|
176
161
|
const exeCtx = this.getExecuteContext();
|
|
177
162
|
|
|
178
163
|
const reqCfgModel = exeCtx.getCfgModel();
|
|
179
164
|
const sqlCfgList = reqCfgModel.sqlCfgList || [];
|
|
180
|
-
const { sqlTable, sqlSchema, sqlDatabase,
|
|
165
|
+
const { sqlTable, sqlSchema, sqlDatabase, sqlDbType, maxLimit, columns, columnsRelation } = reqCfgModel;
|
|
181
166
|
|
|
182
167
|
for (let i = 0; i < sqlCfgList.length; i++) {
|
|
183
168
|
const sqlCfgModel = sqlCfgList[i];
|
|
184
169
|
|
|
185
|
-
sqlCfgModel.
|
|
170
|
+
sqlCfgModel.sqlDbType = MixinUtils.selectNotEmpty(sqlCfgModel.sqlDbType, sqlDbType);
|
|
186
171
|
sqlCfgModel.sqlDatabase = MixinUtils.selectNotEmpty(sqlCfgModel.sqlDatabase, sqlDatabase);
|
|
187
172
|
sqlCfgModel.sqlSchema = MixinUtils.selectNotEmpty(sqlCfgModel.sqlSchema, sqlSchema);
|
|
188
173
|
sqlCfgModel.sqlTable = MixinUtils.selectNotEmpty(sqlCfgModel.sqlTable, sqlTable);
|
|
@@ -195,8 +180,6 @@ class CrudProGenSqlService extends CrudProServiceBase {
|
|
|
195
180
|
exeCtx.getSqlCfgModels().push(sqlCfgModel);
|
|
196
181
|
}
|
|
197
182
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
183
|
}
|
|
201
184
|
|
|
202
185
|
export { CrudProGenSqlService };
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {CrudProServiceBase} from './CrudProServiceBase';
|
|
2
|
-
import {SqlCfgModel} from '../models/SqlCfgModel';
|
|
3
|
-
import {MixinUtils} from '../utils/MixinUtils';
|
|
4
|
-
import {SqlSegArg} from '../models/SqlSegArg';
|
|
5
|
-
import {KeysOfCustomSQL, SqlDbType} from '../models/keys';
|
|
6
|
-
import {RequestModel} from '../models/RequestModel';
|
|
7
|
-
import {CommonException, Exceptions} from '../exceptions';
|
|
8
|
-
import {RequestCfgModel} from '../models/RequestCfgModel';
|
|
9
|
-
import {ModelUtils} from '../utils/ModelUtils';
|
|
10
|
-
import {FuncContext} from '../models/FuncContext';
|
|
11
|
-
import {TypeUtils} from '../utils/TypeUtils';
|
|
12
|
-
import {sqlFuncUtils} from '../utils/SqlFuncUtils';
|
|
13
|
-
import {toSqlColumnName, toSqlColumnNamesJoin} from '../utils/sqlConvert/convertColumnName';
|
|
14
|
-
import {CrudProGenSqlCondition} from
|
|
1
|
+
import { CrudProServiceBase } from './CrudProServiceBase';
|
|
2
|
+
import { SqlCfgModel } from '../models/SqlCfgModel';
|
|
3
|
+
import { MixinUtils } from '../utils/MixinUtils';
|
|
4
|
+
import { SqlSegArg } from '../models/SqlSegArg';
|
|
5
|
+
import { KeysOfCustomSQL, SqlDbType } from '../models/keys';
|
|
6
|
+
import { RequestModel } from '../models/RequestModel';
|
|
7
|
+
import { CommonException, Exceptions } from '../exceptions';
|
|
8
|
+
import { RequestCfgModel } from '../models/RequestCfgModel';
|
|
9
|
+
import { ModelUtils } from '../utils/ModelUtils';
|
|
10
|
+
import { FuncContext } from '../models/FuncContext';
|
|
11
|
+
import { TypeUtils } from '../utils/TypeUtils';
|
|
12
|
+
import { sqlFuncUtils } from '../utils/SqlFuncUtils';
|
|
13
|
+
import { toSqlColumnName, toSqlColumnNamesJoin } from '../utils/sqlConvert/convertColumnName';
|
|
14
|
+
import { CrudProGenSqlCondition } from './CrudProGenSqlCondition';
|
|
15
15
|
|
|
16
16
|
const KEYS_CUSTOM_PATTERN = /@@[0-9a-zA-Z:._]+/gm;
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* 存在任何需要排除的
|
|
21
20
|
* @param columns
|
|
@@ -52,10 +51,9 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
52
51
|
const argList = [];
|
|
53
52
|
let executeSql = originSql;
|
|
54
53
|
|
|
55
|
-
|
|
56
54
|
// 发现有需要被替换的变量。
|
|
57
55
|
if (sqlArgModelMap) {
|
|
58
|
-
|
|
56
|
+
executeSql = originSql.replace(KEYS_CUSTOM_PATTERN, word => {
|
|
59
57
|
if (!word) {
|
|
60
58
|
return '';
|
|
61
59
|
}
|
|
@@ -73,7 +71,6 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
|
|
77
74
|
sqlCfgModel.executeSqlArgs = argList;
|
|
78
75
|
sqlCfgModel.executeSql = executeSql;
|
|
79
76
|
}
|
|
@@ -115,12 +112,10 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
115
112
|
return this.generateOffsetLimit(reqCfg, sqlCfg, reqModel);
|
|
116
113
|
} else if (word === KeysOfCustomSQL.SQL_ORDER_BYS) {
|
|
117
114
|
return this.generateOrderBys(reqModel, sqlCfg);
|
|
118
|
-
} else if ((
|
|
119
|
-
word.startsWith(KeysOfCustomSQL.SQL_GET_DATA_ATTR_START) ||
|
|
120
|
-
word.startsWith(KeysOfCustomSQL.SQL_GET_CONDITION_ATTR_START)) && word.indexOf('.') > 0) {
|
|
115
|
+
} else if ((word.startsWith(KeysOfCustomSQL.SQL_GET_DATA_ATTR_START) || word.startsWith(KeysOfCustomSQL.SQL_GET_CONDITION_ATTR_START)) && word.indexOf('.') > 0) {
|
|
121
116
|
return this.generateGetAttr(reqModel, word); //// data.xxx, condition.xxx
|
|
122
117
|
} else if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER) || word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_STRING)) {
|
|
123
|
-
return this.generatePickResAs(reqModel,
|
|
118
|
+
return this.generatePickResAs(reqModel, word); // @@pickResAsNumber:replies_count
|
|
124
119
|
} else if (word.startsWith(KeysOfCustomSQL.SQL_AS_UPDATE)) {
|
|
125
120
|
return this.generateDataUpdate(reqModel, sqlCfg, MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_AS_UPDATE));
|
|
126
121
|
} else if (word.startsWith(KeysOfCustomSQL.SQL_AS_INSERT_KEYS)) {
|
|
@@ -200,7 +195,7 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
200
195
|
result.push(reqColumn);
|
|
201
196
|
}
|
|
202
197
|
}
|
|
203
|
-
return new SqlSegArg(toSqlColumnNamesJoin(result,sqlCfgModel));
|
|
198
|
+
return new SqlSegArg(toSqlColumnNamesJoin(result, sqlCfgModel));
|
|
204
199
|
}
|
|
205
200
|
|
|
206
201
|
/**
|
|
@@ -226,12 +221,12 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
226
221
|
const reqLimit = req.limit;
|
|
227
222
|
const limit = Math.min(maxLimit, reqLimit);
|
|
228
223
|
|
|
229
|
-
if (sqlCfg.
|
|
224
|
+
if (sqlCfg.sqlDbType === SqlDbType.postgres) {
|
|
230
225
|
return new SqlSegArg(' LIMIT ? OFFSET ? ', [limit, req.offset]);
|
|
231
226
|
}
|
|
232
227
|
|
|
233
|
-
if (sqlCfg.
|
|
234
|
-
return new SqlSegArg(' OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ', [
|
|
228
|
+
if (sqlCfg.sqlDbType === SqlDbType.sqlserver) {
|
|
229
|
+
return new SqlSegArg(' OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ', [req.offset, limit]);
|
|
235
230
|
}
|
|
236
231
|
|
|
237
232
|
return new SqlSegArg(' limit ?,? ', [req.offset, limit]);
|
|
@@ -250,11 +245,12 @@ class CrudProOriginToExecuteSql extends CrudProServiceBase {
|
|
|
250
245
|
return new SqlSegArg(sql);
|
|
251
246
|
}
|
|
252
247
|
|
|
253
|
-
|
|
254
248
|
private generatePickResAs(req: RequestModel, world: string): SqlSegArg {
|
|
255
|
-
return new SqlSegArg(' ? ', [
|
|
249
|
+
return new SqlSegArg(' ? ', [
|
|
250
|
+
{
|
|
256
251
|
___GENERATE_GET_RES_ATTR___: world,
|
|
257
|
-
|
|
252
|
+
},
|
|
253
|
+
]);
|
|
258
254
|
}
|
|
259
255
|
|
|
260
256
|
private generateGetAttr(req: RequestModel, word: string): SqlSegArg {
|
|
@@ -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,11 +19,6 @@ function createBuildInExecuteFuncMap() {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
interface ExecuteUnsafeQueryCtx {
|
|
23
|
-
tableName: string;
|
|
24
|
-
dbName: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
const buildInExecuteFuncMap = createBuildInExecuteFuncMap();
|
|
28
23
|
|
|
29
24
|
class CrudProServiceBase {
|
|
@@ -60,10 +55,11 @@ class CrudProServiceBase {
|
|
|
60
55
|
* @param values
|
|
61
56
|
* @protected
|
|
62
57
|
*/
|
|
63
|
-
protected async executeUnsafeQuery(obj:
|
|
58
|
+
protected async executeUnsafeQuery(obj: IExecuteUnsafeQueryCtx, sql: string, values?: any) {
|
|
64
59
|
const sqlCfgModel: any = {
|
|
65
|
-
sqlTable: obj.
|
|
66
|
-
sqlDatabase: obj.
|
|
60
|
+
sqlTable: obj.sqlTable,
|
|
61
|
+
sqlDatabase: obj.sqlDatabase,
|
|
62
|
+
sqlDbType: obj.sqlDbType,
|
|
67
63
|
columns: [],
|
|
68
64
|
columnsRelation: [],
|
|
69
65
|
maxLimit: DEFAULT_MAX_LIMIT,
|