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
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ConnectionPool, Request, Transaction } from 'mssql';
|
|
2
2
|
import { IConnectionPool, IPoolConnectionClient } from '../interfaces';
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
interface ISqlServerConnection extends IPoolConnectionClient {
|
|
6
|
-
originConnection: ConnectionPool
|
|
5
|
+
originConnection: ConnectionPool;
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
8
|
class TransactionSqlServer {
|
|
12
9
|
private isBeginTransaction = false;
|
|
13
10
|
private connectionMap: Record<string, ISqlServerConnection> = {};
|
|
@@ -31,23 +28,23 @@ class TransactionSqlServer {
|
|
|
31
28
|
return connection;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
private async connectAndCreateConnection(pool: IConnectionPool)
|
|
31
|
+
private async connectAndCreateConnection(pool: IConnectionPool): Promise<ISqlServerConnection> {
|
|
35
32
|
const poolInstance: ConnectionPool = pool.poolInstance as any;
|
|
36
33
|
const originConnection = await poolInstance.connect();
|
|
37
34
|
return {
|
|
38
35
|
originConnection,
|
|
39
|
-
query: (sql:string, values: any)
|
|
36
|
+
query: (sql: string, values: any): Promise<any> => {
|
|
40
37
|
const request = new Request(originConnection);
|
|
41
38
|
if (Array.isArray(values)) {
|
|
42
39
|
for (let i = 0; i < values.length; i++) {
|
|
43
|
-
const index = i+1;
|
|
40
|
+
const index = i + 1;
|
|
44
41
|
const value = values[i];
|
|
45
42
|
request.input(`fatcms_ms${index}`, value);
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
return request.query(sql);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
/**
|
|
@@ -93,15 +90,13 @@ class TransactionSqlServer {
|
|
|
93
90
|
this.transactionMap = {};
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
|
|
97
93
|
private async beginTransaction(poolName: string) {
|
|
98
94
|
const connection = this.connectionMap[poolName];
|
|
99
95
|
const originConnection: ConnectionPool = connection.originConnection;
|
|
100
|
-
const tmpTx =
|
|
96
|
+
const tmpTx = new Transaction(originConnection);
|
|
101
97
|
this.transactionMap[poolName] = tmpTx;
|
|
102
|
-
return await tmpTx.begin()
|
|
98
|
+
return await tmpTx.begin();
|
|
103
99
|
}
|
|
104
|
-
|
|
105
100
|
}
|
|
106
101
|
|
|
107
102
|
export { TransactionSqlServer };
|
|
@@ -3,69 +3,78 @@ import { CrudProServiceBase } from './CrudProServiceBase';
|
|
|
3
3
|
import { IRequestCfgModel } from '../interfaces';
|
|
4
4
|
import { MixinUtils } from '../utils/MixinUtils';
|
|
5
5
|
import { ICurdProServiceHub } from '../models/ServiceHub';
|
|
6
|
+
import { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
|
|
6
7
|
import MemoryRefreshCache from '../utils/MemoryRefreshCache';
|
|
7
8
|
|
|
8
|
-
const methodCache = new MemoryRefreshCache();
|
|
9
9
|
|
|
10
|
+
const methodCache = new MemoryRefreshCache();
|
|
10
11
|
|
|
11
12
|
function parseMethodInfo(methodInfo: any): any {
|
|
12
13
|
const row: any = camelizeKeys(methodInfo as object); //转换成驼峰
|
|
13
14
|
const configObject = MixinUtils.parseJsonObject(row.moreConfig) || {};
|
|
14
15
|
const sqlCfgList = MixinUtils.parseJsonObject(row.sqlCfgList) || [];
|
|
15
|
-
return {...configObject, ...row, sqlCfgList};
|
|
16
|
+
return { ...configObject, ...row, sqlCfgList };
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
19
|
class CrudProCachedCfgService extends CrudProServiceBase {
|
|
21
20
|
constructor(serviceHub: ICurdProServiceHub) {
|
|
22
21
|
super(serviceHub);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
public async getCachedCfgByMethod(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null> {
|
|
25
|
+
const methodInfo = await this.getCachedCfgByMethodInner(method, isEnableCache);
|
|
26
|
+
if (!methodInfo) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return { ...methodInfo };
|
|
30
|
+
}
|
|
26
31
|
|
|
32
|
+
private async getCachedCfgByMethodInner(method: string, isEnableCache: boolean): Promise<IRequestCfgModel | null> {
|
|
27
33
|
// 不使用缓存
|
|
28
34
|
if (!isEnableCache) {
|
|
29
|
-
return await this.loadMethodInfo(method)
|
|
35
|
+
return await this.loadMethodInfo(method);
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
methodCache.setProps({
|
|
33
|
-
keepTime:
|
|
39
|
+
keepTime: 1000 * 60 * 2, // 2分钟
|
|
34
40
|
requestFn: () => this.loadMethodInfoList(),
|
|
35
41
|
getKeyFn: item => item.method,
|
|
36
42
|
});
|
|
37
|
-
|
|
43
|
+
const methodInfo = await methodCache.getItem(method);
|
|
44
|
+
if (methodInfo) {
|
|
45
|
+
return methodInfo;
|
|
46
|
+
}
|
|
47
|
+
return await this.loadMethodInfo(method);
|
|
38
48
|
}
|
|
39
49
|
|
|
40
|
-
|
|
41
50
|
private async loadMethodInfo(method: string): Promise<any> {
|
|
42
|
-
const {methodsTableName, sysDatabaseName} = this.getContextCfg();
|
|
43
|
-
const sql = `select *
|
|
44
|
-
|
|
45
|
-
where method = ? `; // 全部加载到内存
|
|
51
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
52
|
+
const sql = `select * from ${methodsTableName} where method = ? `; // 全部加载到内存
|
|
53
|
+
|
|
46
54
|
const baseInfo = {
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
sqlTable: methodsTableName,
|
|
56
|
+
sqlDatabase: sysDatabaseName,
|
|
57
|
+
sqlDbType: sysDatabaseDbType,
|
|
49
58
|
};
|
|
50
|
-
|
|
51
|
-
const
|
|
59
|
+
|
|
60
|
+
const queryRes = await this.executeUnsafeQuery(baseInfo, sql, [method]);
|
|
61
|
+
const rows2: any[] = pickAndConvertRowsByMix(queryRes, sysDatabaseDbType)
|
|
52
62
|
if (rows2.length > 0) {
|
|
53
63
|
return parseMethodInfo(rows2[0]);
|
|
54
64
|
}
|
|
55
65
|
return null;
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
68
|
private async loadMethodInfoList(): Promise<any[]> {
|
|
61
|
-
const { methodsTableName, sysDatabaseName } = this.getContextCfg();
|
|
69
|
+
const { methodsTableName, sysDatabaseName, sysDatabaseDbType } = this.getContextCfg();
|
|
62
70
|
const sql = `select * from ${methodsTableName}`; // 全部加载到内存
|
|
63
71
|
const baseInfo = {
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
sqlTable: methodsTableName,
|
|
73
|
+
sqlDatabase: sysDatabaseName,
|
|
74
|
+
sqlDbType: sysDatabaseDbType,
|
|
66
75
|
};
|
|
67
|
-
const
|
|
68
|
-
const rows2: any[] =
|
|
76
|
+
const queryRes = await this.executeUnsafeQuery(baseInfo, sql);
|
|
77
|
+
const rows2: any[] = pickAndConvertRowsByMix(queryRes, sysDatabaseDbType)
|
|
69
78
|
return rows2.map(row => {
|
|
70
79
|
return parseMethodInfo(row);
|
|
71
80
|
});
|
|
@@ -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 {
|
|
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 { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
|
|
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,58 @@ 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 || [])
|
|
36
|
+
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || []);
|
|
37
37
|
|
|
38
|
+
let queryRes: any;
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (sqlCfgModel.sqlDdType === SqlDbType.postgres) { // import { PoolClient } from 'pg';
|
|
40
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.postgres) {
|
|
41
|
+
// import { PoolClient } from 'pg';
|
|
43
42
|
|
|
44
43
|
const pgClient: PoolClient = connection as any;
|
|
45
44
|
const pgSql = replaceQuestionMarks(sqlCfgModel.executeSql);
|
|
46
|
-
|
|
47
45
|
this.logger.info('executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
48
|
-
|
|
49
|
-
|
|
50
46
|
queryRes = await pgClient.query({
|
|
51
47
|
text: pgSql,
|
|
52
|
-
values: executeSqlArgs || []
|
|
48
|
+
values: executeSqlArgs || [],
|
|
53
49
|
});
|
|
54
|
-
sqlRes = pickAndConvertPgRows(queryRes)
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
else if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
|
|
59
50
|
|
|
51
|
+
} else if (sqlCfgModel.sqlDbType === SqlDbType.sqlserver) { // SQLServer
|
|
52
|
+
|
|
60
53
|
const mssql = replaceQuestionMarksForMssql(sqlCfgModel.executeSql);
|
|
61
|
-
|
|
62
54
|
this.logger.info('executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
63
|
-
// SQLServer
|
|
64
55
|
queryRes = await connection.query(mssql, executeSqlArgs);
|
|
65
|
-
sqlRes = _.get(queryRes,'recordsets[0]') || []
|
|
66
|
-
}
|
|
67
56
|
|
|
68
|
-
else {
|
|
57
|
+
} else { // MYSQL
|
|
69
58
|
|
|
70
59
|
this.logger.info('executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// MYSQL
|
|
74
60
|
queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
|
|
75
|
-
|
|
61
|
+
|
|
76
62
|
}
|
|
77
63
|
|
|
64
|
+
const sqlRes = pickAndConvertRowsByMix(queryRes, sqlCfgModel.sqlDbType);
|
|
78
65
|
const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
|
|
79
66
|
exeCtx.setResModelItem(sqlCfgModel.resName, resObject);
|
|
80
67
|
}
|
|
81
68
|
|
|
82
|
-
|
|
83
69
|
private handleExecuteSqlArgsByResModel(exeCtx: ExecuteContext, executeSqlArgs: any[]): any[] {
|
|
84
|
-
return executeSqlArgs.map(
|
|
85
|
-
if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string'
|
|
70
|
+
return executeSqlArgs.map(arg => {
|
|
71
|
+
if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string') {
|
|
86
72
|
const word: string = arg.___GENERATE_GET_RES_ATTR___;
|
|
87
73
|
if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)) {
|
|
88
|
-
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)
|
|
74
|
+
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER);
|
|
89
75
|
this.logger.info('handleExecuteSqlArgsByResModel resName', resName);
|
|
90
76
|
this.logger.info('handleExecuteSqlArgsByResModel getResModel', exeCtx.getResModel());
|
|
91
77
|
return Number(exeCtx.getResModelItemLodash(resName) || 0);
|
|
92
78
|
}
|
|
93
79
|
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) ||
|
|
80
|
+
const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_STRING);
|
|
81
|
+
return String(exeCtx.getResModelItemLodash(resName) || '');
|
|
96
82
|
}
|
|
97
83
|
}
|
|
98
84
|
return arg;
|
|
99
|
-
})
|
|
85
|
+
});
|
|
100
86
|
}
|
|
101
87
|
|
|
102
|
-
|
|
103
88
|
private executeSqlCfgModelPreCheck(sqlCfgModel: SqlCfgModel): boolean {
|
|
104
89
|
const crudType = sqlCfgModel.getCrudType();
|
|
105
90
|
|
|
@@ -245,18 +230,18 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
|
245
230
|
|
|
246
231
|
// 增删改res的内容是修改结果:包括: insert\delete\update
|
|
247
232
|
if (KeysOfSqlResPicker.UPDATE_RESULT === resPicker) {
|
|
248
|
-
if (sqlCfgModel.
|
|
233
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.postgres) {
|
|
249
234
|
return {
|
|
250
|
-
insertId: _.get(queryRes,'rows[0].id'),
|
|
251
|
-
affectedRows: _.get(queryRes,'rowCount')
|
|
252
|
-
}
|
|
235
|
+
insertId: _.get(queryRes, 'rows[0].id'),
|
|
236
|
+
affectedRows: _.get(queryRes, 'rowCount'),
|
|
237
|
+
};
|
|
253
238
|
}
|
|
254
239
|
|
|
255
|
-
if (sqlCfgModel.
|
|
240
|
+
if (sqlCfgModel.sqlDbType === SqlDbType.sqlserver) {
|
|
256
241
|
return {
|
|
257
|
-
insertId: _.get(queryRes,'recordset[0].id'),
|
|
258
|
-
affectedRows: _.get(queryRes,'rowsAffected[0]')
|
|
259
|
-
}
|
|
242
|
+
insertId: _.get(queryRes, 'recordset[0].id'),
|
|
243
|
+
affectedRows: _.get(queryRes, 'rowsAffected[0]'),
|
|
244
|
+
};
|
|
260
245
|
}
|
|
261
246
|
|
|
262
247
|
return sqlRes;
|
|
@@ -264,16 +249,15 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
|
|
|
264
249
|
|
|
265
250
|
//其他配置:形如: sqlRes[0].total_count
|
|
266
251
|
if (typeof resPicker === 'string') {
|
|
267
|
-
if (resPicker.startsWith('sqlRes')){
|
|
252
|
+
if (resPicker.startsWith('sqlRes')) {
|
|
268
253
|
return _.get({ sqlRes }, resPicker);
|
|
269
254
|
} else {
|
|
270
|
-
throw
|
|
255
|
+
throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, 'resPicker必须是以sqlRes开头');
|
|
271
256
|
}
|
|
272
257
|
}
|
|
273
258
|
|
|
274
259
|
return sqlRes;
|
|
275
260
|
}
|
|
276
|
-
|
|
277
261
|
}
|
|
278
262
|
|
|
279
263
|
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 };
|