midway-fatcms 0.0.1-beta.75 → 0.0.1-beta.77
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/dist/controller/base/BaseApiController.js +6 -2
- package/dist/controller/manage/SystemInfoManageApi.js +2 -0
- package/dist/libs/crud-pro/CrudPro.js +3 -0
- package/dist/libs/crud-pro/interfaces.d.ts +10 -1
- package/dist/libs/crud-pro/models/Transaction.d.ts +21 -2
- package/dist/libs/crud-pro/models/Transaction.js +118 -15
- package/dist/libs/crud-pro/models/TransactionMySQL.d.ts +11 -20
- package/dist/libs/crud-pro/models/TransactionMySQL.js +33 -61
- package/dist/libs/crud-pro/models/TransactionPostgres.d.ts +11 -20
- package/dist/libs/crud-pro/models/TransactionPostgres.js +39 -60
- package/dist/libs/crud-pro/models/TransactionSqlServer.d.ts +1 -26
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +42 -73
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +3 -3
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -19
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +3 -3
- package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +9 -0
- package/dist/libs/crud-pro/utils/CrudMonitor.js +12 -0
- package/dist/libs/crud-pro/utils/MixinUtils.d.ts +1 -0
- package/dist/libs/crud-pro/utils/MixinUtils.js +3 -0
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +0 -3
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +24 -22
- package/dist/models/userSession.d.ts +1 -0
- package/dist/models/userSession.js +1 -0
- package/dist/schedule/anonymousContext.js +2 -1
- package/dist/service/AuthService.js +6 -1
- package/package.json +1 -1
- package/src/controller/base/BaseApiController.ts +7 -2
- package/src/controller/manage/SuperAdminManageApi.ts +6 -6
- package/src/controller/manage/SystemInfoManageApi.ts +2 -0
- package/src/libs/crud-pro/CrudPro.ts +5 -0
- package/src/libs/crud-pro/interfaces.ts +10 -1
- package/src/libs/crud-pro/models/Transaction.ts +141 -19
- package/src/libs/crud-pro/models/TransactionMySQL.ts +39 -60
- package/src/libs/crud-pro/models/TransactionPostgres.ts +49 -61
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +52 -77
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +3 -3
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +13 -22
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +3 -3
- package/src/libs/crud-pro/utils/CrudMonitor.ts +13 -0
- package/src/libs/crud-pro/utils/MixinUtils.ts +3 -0
- package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +24 -24
- package/src/models/userSession.ts +2 -0
- package/src/schedule/anonymousContext.ts +2 -1
- package/src/service/AuthService.ts +7 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.d.ts +0 -2
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.js +0 -128
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -127
|
@@ -2,91 +2,60 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionSqlServer = void 0;
|
|
4
4
|
const mssql_1 = require("mssql");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
connection = await this.connectAndCreateConnection(pool);
|
|
19
|
-
this.connectionMap[pool.poolName] = connection;
|
|
20
|
-
// 开启了事务
|
|
21
|
-
if (this.isBeginTransaction) {
|
|
22
|
-
await this.beginTransaction(pool.poolName);
|
|
5
|
+
const CrudMonitor_1 = require("../../../libs/crud-pro/utils/CrudMonitor");
|
|
6
|
+
const _ = require("lodash");
|
|
7
|
+
class SqlServerConnectionClient {
|
|
8
|
+
constructor(originConnection) {
|
|
9
|
+
this.originConnection = originConnection;
|
|
10
|
+
}
|
|
11
|
+
async query(sql, values) {
|
|
12
|
+
const request = new mssql_1.Request(this.originConnection);
|
|
13
|
+
if (Array.isArray(values)) {
|
|
14
|
+
for (let i = 0; i < values.length; i++) {
|
|
15
|
+
const index = i + 1;
|
|
16
|
+
const value = values[i];
|
|
17
|
+
request.input(`fatcms_ms${index}`, value);
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
async connectAndCreateConnection(pool) {
|
|
28
|
-
const poolInstance = pool.poolInstance;
|
|
29
|
-
const originConnection = await poolInstance.connect();
|
|
20
|
+
const res = await request.query(sql);
|
|
21
|
+
const rows = _.get(res, 'recordsets[0]') || [];
|
|
30
22
|
return {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const request = new mssql_1.Request(originConnection);
|
|
34
|
-
if (Array.isArray(values)) {
|
|
35
|
-
for (let i = 0; i < values.length; i++) {
|
|
36
|
-
const index = i + 1;
|
|
37
|
-
const value = values[i];
|
|
38
|
-
request.input(`fatcms_ms${index}`, value);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return request.query(sql);
|
|
42
|
-
},
|
|
23
|
+
rows,
|
|
24
|
+
originRes: res
|
|
43
25
|
};
|
|
44
26
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
async beginTransaction() {
|
|
28
|
+
const originConnection = this.originConnection;
|
|
29
|
+
const tmpTx = new mssql_1.Transaction(originConnection);
|
|
30
|
+
this.sqlServerTransaction = tmpTx;
|
|
31
|
+
return await tmpTx.begin();
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async commitTx() {
|
|
55
|
-
if (!this.isBeginTransaction) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const transactions = Object.values(this.transactionMap);
|
|
59
|
-
for (let i = 0; i < transactions.length; i++) {
|
|
60
|
-
const tmpTx = transactions[i];
|
|
61
|
-
await tmpTx.commit();
|
|
62
|
-
}
|
|
33
|
+
async commit() {
|
|
34
|
+
const tmpTx = this.sqlServerTransaction;
|
|
35
|
+
await tmpTx.commit();
|
|
63
36
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
async rollback() {
|
|
38
|
+
const tmpTx = this.sqlServerTransaction;
|
|
39
|
+
await tmpTx.rollback();
|
|
40
|
+
}
|
|
41
|
+
async release() {
|
|
42
|
+
try {
|
|
43
|
+
CrudMonitor_1.CrudMonitor.postgresReleaseConnectionCount++;
|
|
70
44
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const tmpTx = transactions[i];
|
|
74
|
-
await tmpTx.rollback();
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.log('[crud-pro] SqlServerConnectionClient release ', e);
|
|
75
47
|
}
|
|
76
48
|
}
|
|
49
|
+
}
|
|
50
|
+
class TransactionSqlServer {
|
|
77
51
|
/**
|
|
78
|
-
*
|
|
52
|
+
* 获取链接对象
|
|
53
|
+
* @param pool
|
|
79
54
|
*/
|
|
80
|
-
async
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
async beginTransaction(poolName) {
|
|
85
|
-
const connection = this.connectionMap[poolName];
|
|
86
|
-
const originConnection = connection.originConnection;
|
|
87
|
-
const tmpTx = new mssql_1.Transaction(originConnection);
|
|
88
|
-
this.transactionMap[poolName] = tmpTx;
|
|
89
|
-
return await tmpTx.begin();
|
|
55
|
+
async getTxConnection(pool) {
|
|
56
|
+
const poolInstance = pool.poolInstance;
|
|
57
|
+
const originConnection = await poolInstance.connect();
|
|
58
|
+
return new SqlServerConnectionClient(originConnection);
|
|
90
59
|
}
|
|
91
60
|
}
|
|
92
61
|
exports.TransactionSqlServer = TransactionSqlServer;
|
|
@@ -4,7 +4,7 @@ exports.CrudProCachedCfgService = void 0;
|
|
|
4
4
|
const humps_1 = require("humps");
|
|
5
5
|
const CrudProServiceBase_1 = require("./CrudProServiceBase");
|
|
6
6
|
const MixinUtils_1 = require("../utils/MixinUtils");
|
|
7
|
-
|
|
7
|
+
// import { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
|
|
8
8
|
const MemoryRefreshCache_1 = require("../utils/MemoryRefreshCache");
|
|
9
9
|
const methodCache = new MemoryRefreshCache_1.default();
|
|
10
10
|
function parseMethodInfo(methodInfo) {
|
|
@@ -49,7 +49,7 @@ class CrudProCachedCfgService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
49
49
|
sqlDbType: sysDatabaseDbType,
|
|
50
50
|
};
|
|
51
51
|
const queryRes = await this.executeUnsafeQuery(baseInfo, sql, [method]);
|
|
52
|
-
const rows2 =
|
|
52
|
+
const rows2 = queryRes.rows || [];
|
|
53
53
|
if (rows2.length > 0) {
|
|
54
54
|
return parseMethodInfo(rows2[0]);
|
|
55
55
|
}
|
|
@@ -64,7 +64,7 @@ class CrudProCachedCfgService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
64
64
|
sqlDbType: sysDatabaseDbType,
|
|
65
65
|
};
|
|
66
66
|
const queryRes = await this.executeUnsafeQuery(baseInfo, sql);
|
|
67
|
-
const rows2 =
|
|
67
|
+
const rows2 = queryRes.rows || [];
|
|
68
68
|
return rows2.map(row => {
|
|
69
69
|
return parseMethodInfo(row);
|
|
70
70
|
});
|
|
@@ -5,7 +5,6 @@ const _ = require("lodash");
|
|
|
5
5
|
const CrudProServiceBase_1 = require("./CrudProServiceBase");
|
|
6
6
|
const keys_1 = require("../models/keys");
|
|
7
7
|
const exceptions_1 = require("../exceptions");
|
|
8
|
-
const convertMix_1 = require("../utils/sqlConvert/convertMix");
|
|
9
8
|
const convertPgSql_1 = require("../utils/sqlConvert/convertPgSql");
|
|
10
9
|
const convertMsSql_1 = require("../utils/sqlConvert/convertMsSql");
|
|
11
10
|
const ModelUtils_1 = require("../utils/ModelUtils");
|
|
@@ -32,13 +31,8 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
32
31
|
const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || []);
|
|
33
32
|
let queryRes;
|
|
34
33
|
if (sqlCfgModel.sqlDbType === keys_1.SqlDbType.postgres) {
|
|
35
|
-
// import { PoolClient } from 'pg';
|
|
36
|
-
const pgClient = connection;
|
|
37
34
|
const pgSql = (0, convertPgSql_1.replaceQuestionMarks)(sqlCfgModel.executeSql, sqlCfgModel.isNativeSQL);
|
|
38
|
-
queryRes = await
|
|
39
|
-
text: pgSql,
|
|
40
|
-
values: executeSqlArgs || [],
|
|
41
|
-
});
|
|
35
|
+
queryRes = await connection.query(pgSql, executeSqlArgs);
|
|
42
36
|
this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
43
37
|
}
|
|
44
38
|
else if (sqlCfgModel.sqlDbType === keys_1.SqlDbType.sqlserver) {
|
|
@@ -52,8 +46,7 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
52
46
|
queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
|
|
53
47
|
this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
|
|
54
48
|
}
|
|
55
|
-
const
|
|
56
|
-
const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
|
|
49
|
+
const resObject = this.toQueryResByResPicker(queryRes.rows, queryRes.originRes, sqlCfgModel);
|
|
57
50
|
exeCtx.setResModelItem(sqlCfgModel.resName, resObject);
|
|
58
51
|
}
|
|
59
52
|
handleExecuteSqlArgsByResModel(exeCtx, executeSqlArgs) {
|
|
@@ -175,11 +168,10 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
175
168
|
}
|
|
176
169
|
return result === true;
|
|
177
170
|
}
|
|
178
|
-
toQueryResByResPicker(
|
|
171
|
+
toQueryResByResPicker(rows, originRes, sqlCfgModel) {
|
|
179
172
|
const resPicker = sqlCfgModel.resPicker;
|
|
180
173
|
// 返回第一行
|
|
181
174
|
if (keys_1.KeysOfSqlResPicker.RESULT_FIRST_ROW === resPicker) {
|
|
182
|
-
const rows = sqlRes;
|
|
183
175
|
if (rows && rows.length > 0) {
|
|
184
176
|
return rows[0];
|
|
185
177
|
}
|
|
@@ -187,7 +179,6 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
187
179
|
}
|
|
188
180
|
// $ResultSet[0].total_count , 只取第一行的的total_count
|
|
189
181
|
if (keys_1.KeysOfSqlResPicker.RESULT_TOTAL_COUNT === resPicker) {
|
|
190
|
-
const rows = sqlRes;
|
|
191
182
|
if (isEmpty(rows)) {
|
|
192
183
|
return 0;
|
|
193
184
|
}
|
|
@@ -198,28 +189,28 @@ class CrudProExecuteSqlService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
198
189
|
if (keys_1.KeysOfSqlResPicker.UPDATE_RESULT === resPicker) {
|
|
199
190
|
if (sqlCfgModel.sqlDbType === keys_1.SqlDbType.postgres) {
|
|
200
191
|
return {
|
|
201
|
-
insertId: _.get(
|
|
202
|
-
affectedRows: _.get(
|
|
192
|
+
insertId: _.get(originRes, 'rows[0].id'),
|
|
193
|
+
affectedRows: _.get(originRes, 'rowCount'),
|
|
203
194
|
};
|
|
204
195
|
}
|
|
205
196
|
if (sqlCfgModel.sqlDbType === keys_1.SqlDbType.sqlserver) {
|
|
206
197
|
return {
|
|
207
|
-
insertId: _.get(
|
|
208
|
-
affectedRows: _.get(
|
|
198
|
+
insertId: _.get(originRes, 'recordset[0].id'),
|
|
199
|
+
affectedRows: _.get(originRes, 'rowsAffected[0]'),
|
|
209
200
|
};
|
|
210
201
|
}
|
|
211
|
-
return
|
|
202
|
+
return rows;
|
|
212
203
|
}
|
|
213
204
|
//其他配置:形如: sqlRes[0].total_count
|
|
214
205
|
if (typeof resPicker === 'string') {
|
|
215
206
|
if (resPicker.startsWith('sqlRes')) {
|
|
216
|
-
return _.get({ sqlRes }, resPicker);
|
|
207
|
+
return _.get({ sqlRes: rows }, resPicker);
|
|
217
208
|
}
|
|
218
209
|
else {
|
|
219
210
|
throw new exceptions_1.CommonException(exceptions_1.Exceptions.RUN_EXECUTE_VALIDATE, 'resPicker必须是以sqlRes开头');
|
|
220
211
|
}
|
|
221
212
|
}
|
|
222
|
-
return
|
|
213
|
+
return rows;
|
|
223
214
|
}
|
|
224
215
|
}
|
|
225
216
|
exports.CrudProExecuteSqlService = CrudProExecuteSqlService;
|
|
@@ -17,7 +17,7 @@ declare class CrudProServiceBase {
|
|
|
17
17
|
* @param values
|
|
18
18
|
* @protected
|
|
19
19
|
*/
|
|
20
|
-
protected executeUnsafeQuery(obj: IExecuteUnsafeQueryCtx, sql: string, values?: any): Promise<
|
|
20
|
+
protected executeUnsafeQuery(obj: IExecuteUnsafeQueryCtx, sql: string, values?: any): Promise<import("../interfaces").IPoolConnectionQueryResult>;
|
|
21
21
|
protected getContextCfg(): ICrudProCfg;
|
|
22
22
|
protected getExecuteFunction(funcName: string): any;
|
|
23
23
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CrudProTableMetaService = void 0;
|
|
4
4
|
const CrudProServiceBase_1 = require("./CrudProServiceBase");
|
|
5
5
|
const keys_1 = require("../models/keys");
|
|
6
|
-
|
|
6
|
+
// import { pickAndConvertRowsByMix } from '../utils/sqlConvert/convertMix';
|
|
7
7
|
class CrudProTableMetaCache {
|
|
8
8
|
constructor() {
|
|
9
9
|
this.cacheMap = {};
|
|
@@ -51,7 +51,7 @@ class CrudProTableMetaService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
51
51
|
async loadTableColumnInfo(baseInfo) {
|
|
52
52
|
if (baseInfo.sqlDbType === keys_1.SqlDbType.mysql) {
|
|
53
53
|
const queryRes = await this.executeUnsafeQuery(baseInfo, 'describe ' + baseInfo.sqlTable);
|
|
54
|
-
const tableDescribe =
|
|
54
|
+
const tableDescribe = queryRes.rows || []; //pickAndConvertRowsByMix(queryRes, baseInfo.sqlDbType);
|
|
55
55
|
const tableDescribe2 = JSON.parse(JSON.stringify(tableDescribe));
|
|
56
56
|
return tableDescribe2.map(fieldObj => {
|
|
57
57
|
return fieldObj['Field'];
|
|
@@ -67,7 +67,7 @@ class CrudProTableMetaService extends CrudProServiceBase_1.CrudProServiceBase {
|
|
|
67
67
|
ORDER BY ordinal_position;
|
|
68
68
|
`.trim();
|
|
69
69
|
const queryRes = await this.executeUnsafeQuery(baseInfo, columnArraySql);
|
|
70
|
-
const tableDescribe =
|
|
70
|
+
const tableDescribe = queryRes.rows || [];
|
|
71
71
|
return tableDescribe.map(fieldObj => {
|
|
72
72
|
return fieldObj['column_name'];
|
|
73
73
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const CrudMonitor: {
|
|
2
|
+
mysqlGetConnectionCount: number;
|
|
3
|
+
mysqlReleaseConnectionCount: number;
|
|
4
|
+
postgresGetConnectionCount: number;
|
|
5
|
+
postgresReleaseConnectionCount: number;
|
|
6
|
+
mssqlGetConnectionCount: number;
|
|
7
|
+
mssqlReleaseConnectionCount: number;
|
|
8
|
+
};
|
|
9
|
+
export { CrudMonitor, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrudMonitor = void 0;
|
|
4
|
+
const CrudMonitor = {
|
|
5
|
+
mysqlGetConnectionCount: 0,
|
|
6
|
+
mysqlReleaseConnectionCount: 0,
|
|
7
|
+
postgresGetConnectionCount: 0,
|
|
8
|
+
postgresReleaseConnectionCount: 0,
|
|
9
|
+
mssqlGetConnectionCount: 0,
|
|
10
|
+
mssqlReleaseConnectionCount: 0,
|
|
11
|
+
};
|
|
12
|
+
exports.CrudMonitor = CrudMonitor;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
// import { SqlDbType } from '../../models/keys';
|
|
2
|
+
// import { pickAndConvertPgRows } from './convertPgType';
|
|
3
|
+
// import * as _ from 'lodash';
|
|
4
|
+
//
|
|
5
|
+
// function pickAndConvertRowsByMix(connectionQueryRes: any, sqlDbType: SqlDbType): any[] | any {
|
|
6
|
+
// if (!connectionQueryRes) {
|
|
7
|
+
// throw new Error('[pickAndConvertRowsByMix] error, connectionQueryRes is null ');
|
|
8
|
+
// }
|
|
9
|
+
//
|
|
10
|
+
// if (sqlDbType === SqlDbType.postgres) {
|
|
11
|
+
// return pickAndConvertPgRows(connectionQueryRes);
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// if (sqlDbType === SqlDbType.mysql) {
|
|
15
|
+
// return connectionQueryRes[0];
|
|
16
|
+
// }
|
|
17
|
+
//
|
|
18
|
+
// if (sqlDbType === SqlDbType.sqlserver) {
|
|
19
|
+
// return _.get(connectionQueryRes, 'recordsets[0]') || [];
|
|
20
|
+
// }
|
|
21
|
+
// throw new Error('[pickAndConvertRowsByMix] error sqlDbType, sqlDbType = ' + sqlDbType);
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// export { pickAndConvertRowsByMix };
|
|
@@ -95,6 +95,7 @@ let AuthService = class AuthService {
|
|
|
95
95
|
publicKey,
|
|
96
96
|
privateKey,
|
|
97
97
|
sessionIdCreatedAt: Date.now(),
|
|
98
|
+
sessionSavedAt: Date.now()
|
|
98
99
|
};
|
|
99
100
|
await this.userSessionService.saveUserSession(sessionInfo);
|
|
100
101
|
return sessionInfo;
|
|
@@ -129,6 +130,7 @@ let AuthService = class AuthService {
|
|
|
129
130
|
publicKey,
|
|
130
131
|
privateKey,
|
|
131
132
|
sessionIdCreatedAt: Date.now(),
|
|
133
|
+
sessionSavedAt: Date.now(),
|
|
132
134
|
};
|
|
133
135
|
if (bizExt && typeof bizExt === 'object') {
|
|
134
136
|
sessionInfo.bizExt = bizExt;
|
|
@@ -223,9 +225,12 @@ let AuthService = class AuthService {
|
|
|
223
225
|
return this.userSessionService.removeUserSession(sessionId);
|
|
224
226
|
}
|
|
225
227
|
async refreshSession(sessionInfo) {
|
|
228
|
+
if (sessionInfo.sessionSavedAt && Date.now() - sessionInfo.sessionSavedAt < 1000 * 60 * 5) {
|
|
229
|
+
return sessionInfo;
|
|
230
|
+
}
|
|
226
231
|
const roleCodes = await this.queryUserRoleCodeList(sessionInfo.accountId);
|
|
227
232
|
const functionCodes = await this.queryFunctionCodeList(roleCodes);
|
|
228
|
-
const newSessionInfo = { ...sessionInfo, roleCodes, functionCodes };
|
|
233
|
+
const newSessionInfo = { ...sessionInfo, roleCodes, functionCodes, sessionSavedAt: Date.now() };
|
|
229
234
|
await this.userSessionService.saveUserSession(newSessionInfo);
|
|
230
235
|
return newSessionInfo;
|
|
231
236
|
}
|
package/package.json
CHANGED
|
@@ -186,7 +186,7 @@ export class BaseApiController extends BaseService {
|
|
|
186
186
|
|
|
187
187
|
protected async decodeBodyBySession<T>(body: any): Promise<any> {
|
|
188
188
|
if (!this.ctx.userSession?.isLogin()) {
|
|
189
|
-
throw new Error('
|
|
189
|
+
throw new Error('身份安全校验不通过, 用户必须先登录');
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
const sessionInfo = this.getUserSessionInfo();
|
|
@@ -196,12 +196,17 @@ export class BaseApiController extends BaseService {
|
|
|
196
196
|
return body;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
const { privateKey, publicKey, accountId } = sessionInfo;
|
|
200
|
+
const serverPayload1 = md5(publicKey + accountId);
|
|
201
|
+
if (serverPayload1 !== secretBody0.payload1) {
|
|
202
|
+
throw new Error('身份安全校验不通过,请重新登录')
|
|
203
|
+
}
|
|
204
|
+
|
|
199
205
|
const secretBody = {
|
|
200
206
|
secretPayload: secretBody0.payload2,
|
|
201
207
|
secretKey: secretBody0.payload4,
|
|
202
208
|
};
|
|
203
209
|
|
|
204
|
-
const { privateKey, publicKey } = sessionInfo;
|
|
205
210
|
const secretPayload: string = secretBody.secretPayload;
|
|
206
211
|
const secretKey: string = secretBody.secretKey; // 使用RSA加密的AES密钥
|
|
207
212
|
const aesKey = await AsymmetricCrypto.decrypt(privateKey, secretKey); // 解密AES密钥
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Controller, Inject, Post, Get } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { VisitStatService } from '
|
|
4
|
-
import { KeysOfSimpleSQL } from '
|
|
3
|
+
import { VisitStatService } from '@/service/VisitStatService';
|
|
4
|
+
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
5
5
|
import { BaseApiController } from '../base/BaseApiController';
|
|
6
|
-
import { checkRole } from '
|
|
7
|
-
import { SystemFuncCodeNameMap, SystemRoleCode, SystemRoleCodeNameMap } from '
|
|
8
|
-
import { SystemTables } from '
|
|
9
|
-
import { CommonResult } from '
|
|
6
|
+
import { checkRole } from '@/middleware/permission.middleware';
|
|
7
|
+
import { SystemFuncCodeNameMap, SystemRoleCode, SystemRoleCodeNameMap } from '@/models/SystemPerm';
|
|
8
|
+
import { SystemTables } from '@/models/SystemTables';
|
|
9
|
+
import { CommonResult } from '@/libs/utils/common-dto';
|
|
10
10
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
11
11
|
|
|
12
12
|
@Controller('/ns/api/manage/superAdmin', { middleware: [checkRole(SystemRoleCode.SuperAdmin)] })
|
|
@@ -5,6 +5,7 @@ import { BaseApiController } from '../base/BaseApiController';
|
|
|
5
5
|
import { checkPermission } from '../../middleware/permission.middleware';
|
|
6
6
|
import { SystemFuncCode } from '../../models/SystemPerm';
|
|
7
7
|
import { CommonResult } from '../../libs/utils/common-dto';
|
|
8
|
+
import {CrudMonitor} from "@/libs/crud-pro/utils/CrudMonitor";
|
|
8
9
|
|
|
9
10
|
@Controller('/ns/api/manage/systemInfo', { middleware: [checkPermission(SystemFuncCode.SystemInfoManageApiRead)] })
|
|
10
11
|
export class SystemInfoManageApi extends BaseApiController {
|
|
@@ -48,6 +49,7 @@ export class SystemInfoManageApi extends BaseApiController {
|
|
|
48
49
|
timeInfo,
|
|
49
50
|
envInfo,
|
|
50
51
|
networkInfo,
|
|
52
|
+
crudMonitorInfo: CrudMonitor
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -124,6 +124,11 @@ class CrudPro {
|
|
|
124
124
|
// 执行SQL执行之后的的处理
|
|
125
125
|
await this.afterExecuteSQLList();
|
|
126
126
|
|
|
127
|
+
|
|
128
|
+
// 再次尝试释放一下资源。避免因为不正确的使用方式导致,连接未释放。
|
|
129
|
+
const txObj = this.executeContext.getTransaction();
|
|
130
|
+
await txObj.releaseTxOnlyReleased();
|
|
131
|
+
|
|
127
132
|
return exeCtx;
|
|
128
133
|
}
|
|
129
134
|
|
|
@@ -23,8 +23,17 @@ export interface IConnectionPool {
|
|
|
23
23
|
poolInstance: any; //MysqlPool | PostgresPool;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export interface IPoolConnectionQueryResult {
|
|
27
|
+
rows: any[];
|
|
28
|
+
originRes: any;
|
|
29
|
+
}
|
|
26
30
|
export interface IPoolConnectionClient {
|
|
27
|
-
query: (sql: string, values: any[]) => Promise<
|
|
31
|
+
query: (sql: string, values: any[]) => Promise<IPoolConnectionQueryResult>;
|
|
32
|
+
release: () => Promise<any>;
|
|
33
|
+
commit: () => Promise<any>;
|
|
34
|
+
rollback: () => Promise<any>;
|
|
35
|
+
beginTransaction: () => Promise<any>;
|
|
36
|
+
originConnection: any;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|