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.
Files changed (48) hide show
  1. package/dist/controller/base/BaseApiController.js +6 -2
  2. package/dist/controller/manage/SystemInfoManageApi.js +2 -0
  3. package/dist/libs/crud-pro/CrudPro.js +3 -0
  4. package/dist/libs/crud-pro/interfaces.d.ts +10 -1
  5. package/dist/libs/crud-pro/models/Transaction.d.ts +21 -2
  6. package/dist/libs/crud-pro/models/Transaction.js +118 -15
  7. package/dist/libs/crud-pro/models/TransactionMySQL.d.ts +11 -20
  8. package/dist/libs/crud-pro/models/TransactionMySQL.js +33 -61
  9. package/dist/libs/crud-pro/models/TransactionPostgres.d.ts +11 -20
  10. package/dist/libs/crud-pro/models/TransactionPostgres.js +39 -60
  11. package/dist/libs/crud-pro/models/TransactionSqlServer.d.ts +1 -26
  12. package/dist/libs/crud-pro/models/TransactionSqlServer.js +42 -73
  13. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +3 -3
  14. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -19
  15. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +1 -1
  16. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +3 -3
  17. package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +9 -0
  18. package/dist/libs/crud-pro/utils/CrudMonitor.js +12 -0
  19. package/dist/libs/crud-pro/utils/MixinUtils.d.ts +1 -0
  20. package/dist/libs/crud-pro/utils/MixinUtils.js +3 -0
  21. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +0 -3
  22. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +24 -22
  23. package/dist/models/userSession.d.ts +1 -0
  24. package/dist/models/userSession.js +1 -0
  25. package/dist/schedule/anonymousContext.js +2 -1
  26. package/dist/service/AuthService.js +6 -1
  27. package/package.json +1 -1
  28. package/src/controller/base/BaseApiController.ts +7 -2
  29. package/src/controller/manage/SuperAdminManageApi.ts +6 -6
  30. package/src/controller/manage/SystemInfoManageApi.ts +2 -0
  31. package/src/libs/crud-pro/CrudPro.ts +5 -0
  32. package/src/libs/crud-pro/interfaces.ts +10 -1
  33. package/src/libs/crud-pro/models/Transaction.ts +141 -19
  34. package/src/libs/crud-pro/models/TransactionMySQL.ts +39 -60
  35. package/src/libs/crud-pro/models/TransactionPostgres.ts +49 -61
  36. package/src/libs/crud-pro/models/TransactionSqlServer.ts +52 -77
  37. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +3 -3
  38. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +13 -22
  39. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +3 -3
  40. package/src/libs/crud-pro/utils/CrudMonitor.ts +13 -0
  41. package/src/libs/crud-pro/utils/MixinUtils.ts +3 -0
  42. package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +24 -24
  43. package/src/models/userSession.ts +2 -0
  44. package/src/schedule/anonymousContext.ts +2 -1
  45. package/src/service/AuthService.ts +7 -1
  46. package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.d.ts +0 -2
  47. package/dist/libs/crud-pro/utils/sqlConvert/convertPgType.js +0 -128
  48. 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
- class TransactionSqlServer {
6
- constructor() {
7
- this.isBeginTransaction = false;
8
- this.connectionMap = {};
9
- this.transactionMap = {};
10
- }
11
- /**
12
- * 获取链接对象
13
- * @param pool
14
- */
15
- async getTxConnection(pool) {
16
- let connection = this.connectionMap[pool.poolName];
17
- if (!connection) {
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
- return connection;
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
- originConnection,
32
- query: (sql, values) => {
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
- beginTx() {
49
- this.isBeginTransaction = true;
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
- async rollbackTx() {
68
- if (!this.isBeginTransaction) {
69
- return;
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
- const transactions = Object.values(this.transactionMap);
72
- for (let i = 0; i < transactions.length; i++) {
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 releaseTx() {
81
- this.connectionMap = {};
82
- this.transactionMap = {};
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
- const convertMix_1 = require("../utils/sqlConvert/convertMix");
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 = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, sysDatabaseDbType);
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 = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, sysDatabaseDbType);
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 pgClient.query({
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 sqlRes = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, sqlCfgModel.sqlDbType);
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(sqlRes, queryRes, sqlCfgModel) {
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(queryRes, 'rows[0].id'),
202
- affectedRows: _.get(queryRes, 'rowCount'),
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(queryRes, 'recordset[0].id'),
208
- affectedRows: _.get(queryRes, 'rowsAffected[0]'),
198
+ insertId: _.get(originRes, 'recordset[0].id'),
199
+ affectedRows: _.get(originRes, 'rowsAffected[0]'),
209
200
  };
210
201
  }
211
- return sqlRes;
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 sqlRes;
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<any[]>;
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
- const convertMix_1 = require("../utils/sqlConvert/convertMix");
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 = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, baseInfo.sqlDbType);
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 = (0, convertMix_1.pickAndConvertRowsByMix)(queryRes, baseInfo.sqlDbType);
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;
@@ -35,5 +35,6 @@ declare const MixinUtils: {
35
35
  hasAny(a: string[], b: string[]): boolean;
36
36
  selectNotEmpty(a: any, b: any): any;
37
37
  parseValueByType(value: any, targetType: string): any;
38
+ sleepMs(ms: number): Promise<any>;
38
39
  };
39
40
  export { MixinUtils };
@@ -251,5 +251,8 @@ const MixinUtils = {
251
251
  }
252
252
  return value;
253
253
  },
254
+ sleepMs(ms) {
255
+ return new Promise(resolve => setTimeout(resolve, ms));
256
+ }
254
257
  };
255
258
  exports.MixinUtils = MixinUtils;
@@ -1,3 +0,0 @@
1
- import { SqlDbType } from '../../models/keys';
2
- declare function pickAndConvertRowsByMix(connectionQueryRes: any, sqlDbType: SqlDbType): any[] | any;
3
- export { pickAndConvertRowsByMix };
@@ -1,22 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pickAndConvertRowsByMix = void 0;
4
- const keys_1 = require("../../models/keys");
5
- const convertPgType_1 = require("./convertPgType");
6
- const _ = require("lodash");
7
- function pickAndConvertRowsByMix(connectionQueryRes, sqlDbType) {
8
- if (!connectionQueryRes) {
9
- throw new Error('[pickAndConvertRowsByMix] error, connectionQueryRes is null ');
10
- }
11
- if (sqlDbType === keys_1.SqlDbType.postgres) {
12
- return (0, convertPgType_1.pickAndConvertPgRows)(connectionQueryRes);
13
- }
14
- if (sqlDbType === keys_1.SqlDbType.mysql) {
15
- return connectionQueryRes[0];
16
- }
17
- if (sqlDbType === keys_1.SqlDbType.sqlserver) {
18
- return _.get(connectionQueryRes, 'recordsets[0]') || [];
19
- }
20
- throw new Error('[pickAndConvertRowsByMix] error sqlDbType, sqlDbType = ' + sqlDbType);
21
- }
22
- exports.pickAndConvertRowsByMix = pickAndConvertRowsByMix;
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 };
@@ -21,6 +21,7 @@ interface ISessionInfo {
21
21
  privateKey: string;
22
22
  bizExt?: any;
23
23
  sessionIdCreatedAt: number;
24
+ sessionSavedAt: number;
24
25
  }
25
26
  interface IConsumerUserInfo {
26
27
  workbenchCode: string;
@@ -31,6 +31,7 @@ function createEmptySessionInfo(superAdmin) {
31
31
  publicKey: '',
32
32
  privateKey: '',
33
33
  sessionIdCreatedAt: 0,
34
+ sessionSavedAt: 0
34
35
  };
35
36
  }
36
37
  class UserSessionInfo {
@@ -17,7 +17,8 @@ const anonymousUserInfo = {
17
17
  accountType: userSession_1.SYS_ACCOUNT_TYPE,
18
18
  publicKey: '',
19
19
  privateKey: '',
20
- sessionIdCreatedAt: 0
20
+ sessionIdCreatedAt: 0,
21
+ sessionSavedAt: 0
21
22
  };
22
23
  const anonymousWorkbenchInfo = {
23
24
  id: 0,
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.75",
3
+ "version": "0.0.1-beta.77",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -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('[decodeBodyBySessionId] 用户必须登录');
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 '../../service/VisitStatService';
4
- import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
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 '../../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';
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<any[]>;
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
  /**