midway-fatcms 0.0.1-beta.64 → 0.0.1-beta.66

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 (108) hide show
  1. package/dist/config/config.default.js +7 -0
  2. package/dist/controller/base/BaseApiController.d.ts +5 -0
  3. package/dist/controller/base/BaseApiController.js +25 -0
  4. package/dist/controller/gateway/CrudStdGatewayController.d.ts +1 -1
  5. package/dist/controller/gateway/CrudStdGatewayController.js +36 -10
  6. package/dist/controller/gateway/FileController.js +2 -1
  7. package/dist/controller/gateway/PublicApiController.d.ts +1 -0
  8. package/dist/controller/gateway/PublicApiController.js +64 -28
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/interface.d.ts +2 -0
  12. package/dist/libs/crud-pro/exceptions.d.ts +2 -0
  13. package/dist/libs/crud-pro/exceptions.js +2 -0
  14. package/dist/libs/crud-pro/models/keys.d.ts +1 -1
  15. package/dist/libs/crud-pro/models/keys.js +1 -1
  16. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +6 -1
  17. package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +14 -0
  18. package/dist/libs/utils/AsymmetricCrypto.d.ts +76 -0
  19. package/dist/libs/utils/AsymmetricCrypto.js +261 -0
  20. package/dist/libs/utils/format-url.d.ts +2 -0
  21. package/dist/libs/utils/format-url.js +13 -0
  22. package/dist/libs/utils/render-utils.d.ts +16 -7
  23. package/dist/libs/utils/render-utils.js +27 -6
  24. package/dist/middleware/global.middleware.js +7 -0
  25. package/dist/models/SystemEntities.d.ts +34 -0
  26. package/dist/models/SystemEntities.js +22 -1
  27. package/dist/models/WorkbenchInfoTools.d.ts +7 -0
  28. package/dist/models/WorkbenchInfoTools.js +20 -0
  29. package/dist/models/bizmodels.d.ts +9 -0
  30. package/dist/models/contextLogger.d.ts +2 -0
  31. package/dist/models/contextLogger.js +8 -1
  32. package/dist/models/userSession.d.ts +2 -0
  33. package/dist/models/userSession.js +2 -0
  34. package/dist/schedule/anonymousContext.js +2 -0
  35. package/dist/service/AuthService.js +7 -0
  36. package/dist/service/EnumInfoService.d.ts +1 -1
  37. package/dist/service/EnumInfoService.js +32 -26
  38. package/dist/service/UserSessionService.d.ts +6 -1
  39. package/dist/service/UserSessionService.js +26 -17
  40. package/dist/service/WorkbenchService.d.ts +1 -0
  41. package/dist/service/WorkbenchService.js +27 -1
  42. package/dist/service/base/cache/CacheServiceFactory.d.ts +20 -0
  43. package/dist/service/base/cache/CacheServiceFactory.js +67 -0
  44. package/dist/service/base/cache/FatcmsBaseCtxCache.d.ts +19 -0
  45. package/dist/service/base/cache/FatcmsBaseCtxCache.js +38 -0
  46. package/dist/service/base/cache/FatcmsBaseDiskCache.d.ts +24 -0
  47. package/dist/service/base/cache/FatcmsBaseDiskCache.js +81 -0
  48. package/dist/service/base/cache/FatcmsBaseMemoryCache.d.ts +18 -0
  49. package/dist/service/base/cache/FatcmsBaseMemoryCache.js +66 -0
  50. package/dist/service/base/cache/FatcmsBaseNoneCache.d.ts +10 -0
  51. package/dist/service/base/cache/FatcmsBaseNoneCache.js +19 -0
  52. package/dist/service/base/{RedisCacheService.d.ts → cache/FatcmsBaseRedisCache.d.ts} +6 -6
  53. package/dist/service/base/cache/FatcmsBaseRedisCache.js +39 -0
  54. package/dist/service/crudstd/CrudStdService.d.ts +6 -4
  55. package/dist/service/crudstd/CrudStdService.js +24 -10
  56. package/dist/service/curd/CurdMixByDictService.d.ts +1 -2
  57. package/dist/service/curd/CurdMixByDictService.js +12 -8
  58. package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +1 -2
  59. package/dist/service/curd/CurdMixByLinkToCustomService.js +17 -13
  60. package/dist/service/curd/CurdMixBySysConfigService.d.ts +4 -0
  61. package/dist/service/curd/CurdMixBySysConfigService.js +50 -10
  62. package/dist/service/curd/CurdMixByWorkbenchService.d.ts +2 -1
  63. package/dist/service/curd/CurdMixByWorkbenchService.js +30 -22
  64. package/package.json +1 -1
  65. package/src/config/config.default.ts +8 -0
  66. package/src/controller/base/BaseApiController.ts +39 -0
  67. package/src/controller/gateway/CrudStdGatewayController.ts +42 -10
  68. package/src/controller/gateway/FileController.ts +2 -2
  69. package/src/controller/gateway/PublicApiController.ts +72 -28
  70. package/src/controller/manage/DocLibManageApi.ts +5 -5
  71. package/src/controller/manage/FileManageApi.ts +5 -5
  72. package/src/controller/manage/MenuManageApi.ts +4 -4
  73. package/src/index.ts +1 -1
  74. package/src/interface.ts +2 -0
  75. package/src/libs/crud-pro/exceptions.ts +2 -0
  76. package/src/libs/crud-pro/models/keys.ts +6 -6
  77. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +7 -1
  78. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +18 -0
  79. package/src/libs/utils/AsymmetricCrypto.ts +310 -0
  80. package/src/libs/utils/format-url.ts +16 -0
  81. package/src/libs/utils/render-utils.ts +56 -15
  82. package/src/middleware/global.middleware.ts +8 -0
  83. package/src/models/SystemEntities.ts +43 -0
  84. package/src/models/WorkbenchInfoTools.ts +18 -0
  85. package/src/models/bizmodels.ts +12 -0
  86. package/src/models/contextLogger.ts +10 -1
  87. package/src/models/userSession.ts +4 -0
  88. package/src/schedule/anonymousContext.ts +2 -0
  89. package/src/service/AuthService.ts +11 -0
  90. package/src/service/EnumInfoService.ts +35 -22
  91. package/src/service/UserSessionService.ts +29 -18
  92. package/src/service/WorkbenchService.ts +42 -2
  93. package/src/service/base/cache/CacheServiceFactory.ts +66 -0
  94. package/src/service/base/cache/FatcmsBaseCtxCache.ts +47 -0
  95. package/src/service/base/cache/FatcmsBaseDiskCache.ts +87 -0
  96. package/src/service/base/cache/FatcmsBaseMemoryCache.ts +74 -0
  97. package/src/service/base/cache/FatcmsBaseNoneCache.ts +24 -0
  98. package/src/service/base/cache/FatcmsBaseRedisCache.ts +48 -0
  99. package/src/service/crudstd/CrudStdService.ts +28 -12
  100. package/src/service/curd/CurdMixByAccountService.ts +1 -0
  101. package/src/service/curd/CurdMixByDictService.ts +14 -8
  102. package/src/service/curd/CurdMixByLinkToCustomService.ts +21 -12
  103. package/src/service/curd/CurdMixBySysConfigService.ts +60 -11
  104. package/src/service/curd/CurdMixByWorkbenchService.ts +31 -24
  105. package/src/service/proxyapi/WeightedRandom.ts +1 -1
  106. package/src/service/proxyapi/WeightedRoundRobin.ts +1 -1
  107. package/dist/service/base/RedisCacheService.js +0 -57
  108. package/src/service/base/RedisCacheService.ts +0 -42
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FatcmsBaseRedisCache = void 0;
4
+ const functions_1 = require("../../../libs/utils/functions");
5
+ class FatcmsBaseRedisCache {
6
+ constructor(ctx, cacheName, redisService) {
7
+ this.ctx = ctx;
8
+ this.cacheName = cacheName;
9
+ this.redisService = redisService;
10
+ }
11
+ getCacheKey(key) {
12
+ return `${this.cacheName}${key}`;
13
+ }
14
+ async getJsonObject(key) {
15
+ const cacheKey = this.getCacheKey(key);
16
+ const str = await this.redisService.get(cacheKey);
17
+ return (0, functions_1.parseJsonObject)(str);
18
+ }
19
+ /**
20
+ * 设置缓存对象
21
+ * @param key
22
+ * @param obj
23
+ * @param expireSecond 过期时间,单位秒
24
+ * @returns
25
+ */
26
+ async setJsonObject(key, obj, expireSecond) {
27
+ const cacheKey = this.getCacheKey(key);
28
+ if (!expireSecond) {
29
+ expireSecond = 60;
30
+ }
31
+ const str = JSON.stringify(obj);
32
+ return this.redisService.set(cacheKey, str, 'EX', expireSecond);
33
+ }
34
+ async removeItem(key) {
35
+ const cacheKey = this.getCacheKey(key);
36
+ return await this.redisService.del(cacheKey);
37
+ }
38
+ }
39
+ exports.FatcmsBaseRedisCache = FatcmsBaseRedisCache;
@@ -7,6 +7,7 @@ import { ExecuteContext } from '../../libs/crud-pro/models/ExecuteContext';
7
7
  import { CrudStdActionService } from './CrudStdActionService';
8
8
  import { CrudStdRelationService } from './CrudStdRelationService';
9
9
  import { ApiBaseService } from '../base/ApiBaseService';
10
+ import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
10
11
  export declare const SPECIAL_SETTING_KEY: {
11
12
  QUERY_LIST: string;
12
13
  QUERY_ONE: string;
@@ -25,6 +26,7 @@ export declare class CrudStdService extends ApiBaseService {
25
26
  protected curdMixService: CurdMixService;
26
27
  protected crudStdActionService: CrudStdActionService;
27
28
  protected crudStdRelationService: CrudStdRelationService;
29
+ protected cacheServiceFactory: CacheServiceFactory;
28
30
  /**
29
31
  * 执行普通CRUD
30
32
  */
@@ -51,10 +53,10 @@ export declare class CrudStdService extends ApiBaseService {
51
53
  */
52
54
  private getCrudStdAppInfo;
53
55
  /**
54
- * 查询APP信息
55
- * @param appCode
56
- * @private
57
- */
56
+ * 查询APP信息
57
+ * @param appCode
58
+ * @private
59
+ */
58
60
  getParsedCrudStdAppInfo(appCode: string): Promise<ICrudStdAppInfo>;
59
61
  /**
60
62
  * 查询APP信息
@@ -25,11 +25,15 @@ const ApiBaseService_1 = require("../base/ApiBaseService");
25
25
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
26
26
  const global_config_1 = require("../../libs/global-config/global-config");
27
27
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
28
+ const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
29
+ const SystemEntities_1 = require("../../models/SystemEntities");
28
30
  exports.SPECIAL_SETTING_KEY = {
29
31
  QUERY_LIST: 'QUERY_LIST',
30
32
  QUERY_ONE: 'QUERY_ONE',
31
33
  KANBAN_VIEW_STATUS_UPDATE: 'KANBAN_VIEW_STATUS_UPDATE', // 看板视图中更新状态
32
34
  };
35
+ const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
36
+ const DEFAULT_CACHE_SECOND = 60 * 5;
33
37
  function isNotEmptyStr(str) {
34
38
  return typeof str === 'string' && str.trim().length > 0;
35
39
  }
@@ -228,17 +232,23 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
228
232
  return await this.curdMixService.executeCrudByCfg({ condition: { app_code: appCode } }, ss);
229
233
  }
230
234
  /**
231
- * 查询APP信息
232
- * @param appCode
233
- * @private
234
- */
235
+ * 查询APP信息
236
+ * @param appCode
237
+ * @private
238
+ */
235
239
  async getParsedCrudStdAppInfo(appCode) {
236
- const cacheKey = 'getParsedCrudStdAppInfo:' + appCode;
237
- let appInfo = this.getFromCtxCache(cacheKey);
238
- if (!appInfo) {
239
- appInfo = await this.getParsedCrudStdAppInfoPrivate(appCode);
240
- this.setToCtxCache(cacheKey, appInfo);
241
- }
240
+ const { crudStdAppInfoCacheLevel, crudStdAppInfoCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
241
+ const cacheSecond = crudStdAppInfoCacheSecond || DEFAULT_CACHE_SECOND;
242
+ const cacheLevel = crudStdAppInfoCacheLevel || DEFAULT_CACHE_LEVEL;
243
+ let appInfo = await this.cacheServiceFactory.getJsonObjectCache({
244
+ cacheLevel,
245
+ cacheKey: appCode,
246
+ cacheSecond,
247
+ cacheName: SystemEntities_1.CacheNameEnum.GetParsedCrudStdAppInfo,
248
+ getter: async () => {
249
+ return await this.getParsedCrudStdAppInfoPrivate(appCode);
250
+ },
251
+ });
242
252
  return appInfo;
243
253
  }
244
254
  /**
@@ -397,6 +407,10 @@ __decorate([
397
407
  (0, core_1.Inject)(),
398
408
  __metadata("design:type", CrudStdRelationService_1.CrudStdRelationService)
399
409
  ], CrudStdService.prototype, "crudStdRelationService", void 0);
410
+ __decorate([
411
+ (0, core_1.Inject)(),
412
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
413
+ ], CrudStdService.prototype, "cacheServiceFactory", void 0);
400
414
  CrudStdService = __decorate([
401
415
  (0, core_1.Provide)()
402
416
  ], CrudStdService);
@@ -1,10 +1,9 @@
1
1
  import { Context } from '@midwayjs/koa';
2
2
  import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
3
- import { RedisCacheService } from '../base/RedisCacheService';
4
3
  export declare class CurdMixByDictService implements IExecuteContextHandler {
5
4
  ctx: Context;
6
5
  private curdProService;
7
- protected redisCacheService: RedisCacheService;
6
+ private cacheServiceFactory;
8
7
  private getFromCache;
9
8
  private setToCache;
10
9
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
@@ -17,19 +17,23 @@ const CurdMixUtils_1 = require("./CurdMixUtils");
17
17
  const SystemTables_1 = require("../../models/SystemTables");
18
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
- const RedisCacheService_1 = require("../base/RedisCacheService");
21
20
  const global_config_1 = require("../../libs/global-config/global-config");
22
- const RedisKeys_1 = require("../../models/RedisKeys");
21
+ const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
22
+ const SystemEntities_1 = require("../../models/SystemEntities");
23
23
  const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
24
24
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.dict);
25
+ const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
26
+ const DEFAULT_CACHE_SECOND = 60 * 5;
25
27
  let CurdMixByDictService = class CurdMixByDictService {
26
28
  async getFromCache(code) {
27
- const cacheKey = `${RedisKeys_1.RedisKeys.CURD_MIX_BY_DICT_PREFIX}${code}`;
28
- return this.redisCacheService.getJsonObject(cacheKey);
29
+ const { curdMixByCommonCacheLevel } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
30
+ const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixByDict);
31
+ return cacheService.getJsonObject(code);
29
32
  }
30
33
  async setToCache(code, value) {
31
- const cacheKey = `${RedisKeys_1.RedisKeys.CURD_MIX_BY_DICT_PREFIX}${code}`;
32
- return this.redisCacheService.setJsonObject(cacheKey, value, 60 * 60);
34
+ const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
35
+ const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixByDict);
36
+ return cacheService.setJsonObject(code, value, curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND);
33
37
  }
34
38
  async handleExecuteContextPrepare(executeContext) {
35
39
  const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
@@ -106,8 +110,8 @@ __decorate([
106
110
  ], CurdMixByDictService.prototype, "curdProService", void 0);
107
111
  __decorate([
108
112
  (0, core_1.Inject)(),
109
- __metadata("design:type", RedisCacheService_1.RedisCacheService)
110
- ], CurdMixByDictService.prototype, "redisCacheService", void 0);
113
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
114
+ ], CurdMixByDictService.prototype, "cacheServiceFactory", void 0);
111
115
  CurdMixByDictService = __decorate([
112
116
  (0, core_1.Provide)()
113
117
  ], CurdMixByDictService);
@@ -1,11 +1,10 @@
1
1
  import { Context } from '@midwayjs/koa';
2
2
  import { CurdProService } from './CurdProService';
3
3
  import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
4
- import { RedisCacheService } from '../base/RedisCacheService';
5
4
  export declare class CurdMixByLinkToCustomService implements IExecuteContextHandler {
6
5
  protected ctx: Context;
7
6
  protected curdProService: CurdProService;
8
- protected redisCacheService: RedisCacheService;
7
+ private cacheServiceFactory;
9
8
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
10
9
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
11
10
  queryInfoByLinkToCustom(code: string): Promise<Map<string, any>>;
@@ -17,12 +17,15 @@ const CurdMixUtils_1 = require("./CurdMixUtils");
17
17
  const keys_1 = require("../../libs/crud-pro/models/keys");
18
18
  const devops_1 = require("../../models/devops");
19
19
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
20
- const RedisCacheService_1 = require("../base/RedisCacheService");
21
20
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
22
21
  const global_config_1 = require("../../libs/global-config/global-config");
23
- const RedisKeys_1 = require("../../models/RedisKeys");
22
+ const SystemEntities_1 = require("../../models/SystemEntities");
23
+ const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
24
+ const md5 = require("md5");
24
25
  const linkToCustomMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.linkToCustom);
25
26
  const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
27
+ const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
28
+ const DEFAULT_CACHE_SECOND = 60 * 5;
26
29
  function toMapObject(rows, fieldsArr) {
27
30
  const valueKey = fieldsArr[0];
28
31
  const labelKey = fieldsArr[1];
@@ -79,15 +82,16 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
79
82
  });
80
83
  }
81
84
  async queryInfoByLinkToCustom(code) {
82
- const cacheKey = RedisKeys_1.RedisKeys.LINK_TO_CUSTOM_PREFIX + code;
83
- let values;
84
- const expireSecond = 2 * 60; // 2分钟
85
- const enumMap = await this.redisCacheService.getJsonObject(cacheKey);
86
- if (!enumMap || Object.keys(enumMap).length === 0) {
87
- values = await this.queryInfoByLinkToCustomImpl(code);
88
- await this.redisCacheService.setJsonObject(cacheKey, values, expireSecond);
89
- }
90
- return values;
85
+ const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
86
+ return this.cacheServiceFactory.getJsonObjectCache({
87
+ cacheLevel: curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL,
88
+ cacheKey: md5(code),
89
+ cacheSecond: curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND,
90
+ cacheName: SystemEntities_1.CacheNameEnum.CurdMixByLinkToCustom,
91
+ getter: async () => {
92
+ return await this.queryInfoByLinkToCustomImpl(code);
93
+ },
94
+ });
91
95
  }
92
96
  /**
93
97
  * code形如:mysql_________fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
@@ -195,8 +199,8 @@ __decorate([
195
199
  ], CurdMixByLinkToCustomService.prototype, "curdProService", void 0);
196
200
  __decorate([
197
201
  (0, core_1.Inject)(),
198
- __metadata("design:type", RedisCacheService_1.RedisCacheService)
199
- ], CurdMixByLinkToCustomService.prototype, "redisCacheService", void 0);
202
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
203
+ ], CurdMixByLinkToCustomService.prototype, "cacheServiceFactory", void 0);
200
204
  CurdMixByLinkToCustomService = __decorate([
201
205
  (0, core_1.Provide)()
202
206
  ], CurdMixByLinkToCustomService);
@@ -4,6 +4,10 @@ import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/cru
4
4
  export declare class CurdMixBySysConfigService implements IExecuteContextHandler {
5
5
  ctx: Context;
6
6
  protected curdProService: CurdProService;
7
+ private cacheServiceFactory;
8
+ private getFromCache;
9
+ private setToCache;
10
+ private queryConfigRowsUseCache;
7
11
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
8
12
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
9
13
  }
@@ -19,17 +19,39 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
20
  const parseConfig_1 = require("../../libs/utils/parseConfig");
21
21
  const global_config_1 = require("../../libs/global-config/global-config");
22
+ const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
23
+ const SystemEntities_1 = require("../../models/SystemEntities");
22
24
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.sysCfgEnum);
23
25
  const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
26
+ const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
27
+ const DEFAULT_CACHE_SECOND = 60 * 5;
24
28
  let CurdMixBySysConfigService = class CurdMixBySysConfigService {
25
- async handleExecuteContextPrepare(executeContext) {
26
- const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
27
- const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
28
- if (!codes || codes.length === 0) {
29
- return;
29
+ async getFromCache(code) {
30
+ const { curdMixByCommonCacheLevel } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
31
+ const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixBySysConfig);
32
+ return cacheService.getJsonObject(code);
33
+ }
34
+ async setToCache(code, value) {
35
+ const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
36
+ const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixBySysConfig);
37
+ return cacheService.setJsonObject(code, value, curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND);
38
+ }
39
+ async queryConfigRowsUseCache(codes) {
40
+ const resultRowMap = {};
41
+ for (let i = 0; i < codes.length; i++) {
42
+ const code = codes[i];
43
+ const row = await this.getFromCache(code);
44
+ if (row) {
45
+ resultRowMap[code] = row;
46
+ }
47
+ }
48
+ const notCachedCodes = codes.filter((code) => !resultRowMap[code]);
49
+ if (notCachedCodes.length === 0) {
50
+ return Object.values(resultRowMap);
30
51
  }
52
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
31
53
  const res1 = await this.curdProService.executeCrudByCfg({
32
- condition: { config_code: { $in: codes } },
54
+ condition: { config_code: { $in: notCachedCodes } },
33
55
  }, {
34
56
  sqlTable: SystemTables_1.SystemTables.sys_configs,
35
57
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
@@ -37,15 +59,29 @@ let CurdMixBySysConfigService = class CurdMixBySysConfigService {
37
59
  sqlDbType: SystemDbType,
38
60
  });
39
61
  const rows = res1.getResRows();
40
- const multiKeyMap = new MultiKeyMap_1.MultiKeyMap();
41
- if (Array.isArray(rows)) {
62
+ if (Array.isArray(rows) && rows.length > 0) {
42
63
  for (let i = 0; i < rows.length; i++) {
43
64
  const row = rows[i];
44
65
  const { config_code } = row;
45
- const config_content_rows = (0, parseConfig_1.parseConfigContentToEnumInfo)(row); // 数组元素必须有value字段
46
- multiKeyMap.addRowsValue1(config_content_rows, config_code, 'value');
66
+ await this.setToCache(config_code, row);
67
+ resultRowMap[config_code] = row;
47
68
  }
48
69
  }
70
+ return Object.values(resultRowMap);
71
+ }
72
+ async handleExecuteContextPrepare(executeContext) {
73
+ const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
74
+ if (!codes || codes.length === 0) {
75
+ return;
76
+ }
77
+ const multiKeyMap = new MultiKeyMap_1.MultiKeyMap();
78
+ const rows = await this.queryConfigRowsUseCache(codes);
79
+ for (let i = 0; i < rows.length; i++) {
80
+ const row = rows[i];
81
+ const { config_code } = row;
82
+ const config_content_rows = (0, parseConfig_1.parseConfigContentToEnumInfo)(row); // 数组元素必须有value字段
83
+ multiKeyMap.addRowsValue1(config_content_rows, config_code, 'value');
84
+ }
49
85
  executeContext[TMP_CTX_KEY] = multiKeyMap;
50
86
  }
51
87
  async handleExecuteContext(executeContext) {
@@ -74,6 +110,10 @@ __decorate([
74
110
  (0, core_1.Inject)(),
75
111
  __metadata("design:type", CurdProService_1.CurdProService)
76
112
  ], CurdMixBySysConfigService.prototype, "curdProService", void 0);
113
+ __decorate([
114
+ (0, core_1.Inject)(),
115
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
116
+ ], CurdMixBySysConfigService.prototype, "cacheServiceFactory", void 0);
77
117
  CurdMixBySysConfigService = __decorate([
78
118
  (0, core_1.Provide)()
79
119
  ], CurdMixBySysConfigService);
@@ -2,8 +2,9 @@ import { Context } from '@midwayjs/koa';
2
2
  import { CurdProService } from './CurdProService';
3
3
  import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
4
4
  export declare class CurdMixByWorkbenchService implements IExecuteContextHandler {
5
- ctx: Context;
5
+ protected ctx: Context;
6
6
  protected curdProService: CurdProService;
7
+ private cacheServiceFactory;
7
8
  private loadWorkbenchListMap;
8
9
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
9
10
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
@@ -12,39 +12,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CurdMixByWorkbenchService = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const _ = require("lodash");
15
- const lru_cache_1 = require("lru-cache");
16
15
  const CurdProService_1 = require("./CurdProService");
17
16
  const CurdMixUtils_1 = require("./CurdMixUtils");
18
17
  const SystemTables_1 = require("../../models/SystemTables");
19
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
20
19
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
21
20
  const global_config_1 = require("../../libs/global-config/global-config");
22
- const lruCache = new lru_cache_1.LRUCache({
23
- max: 500,
24
- ttl: 1000 * 60 * 5,
25
- ttlAutopurge: true,
26
- });
21
+ const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
22
+ const SystemEntities_1 = require("../../models/SystemEntities");
27
23
  const workbenchMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.workbenchBasic);
28
24
  const TMP_CTX_KEY = _.uniqueId('CurdMixByWorkbenchService');
25
+ const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
26
+ const DEFAULT_CACHE_SECOND = 60 * 5;
29
27
  let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
30
28
  async loadWorkbenchListMap() {
31
29
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
32
- let workbenchListMap = lruCache.get('workbenchListMap');
33
- if (!workbenchListMap) {
34
- const reqJson = {
35
- columns: 'workbench_code,workbench_name,workbench_domain',
36
- condition: {},
37
- };
38
- const res = await this.curdProService.executeCrudByCfg(reqJson, {
39
- sqlTable: SystemTables_1.SystemTables.sys_workbench,
40
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
41
- sqlDatabase: SystemDbName,
42
- sqlDbType: SystemDbType,
43
- });
44
- const workbenchList = res.getResRows();
45
- workbenchListMap = MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
46
- lruCache.set('workbenchListMap', workbenchListMap);
47
- }
30
+ const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig() || {};
31
+ const workbenchListMap = await this.cacheServiceFactory.getJsonObjectCache({
32
+ cacheLevel: curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL,
33
+ cacheSecond: curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND,
34
+ cacheKey: 'loadWorkbenchListMap',
35
+ refreshCache: false,
36
+ cacheName: SystemEntities_1.CacheNameEnum.CurdMixByWorkbench,
37
+ getter: async () => {
38
+ const reqJson = {
39
+ columns: 'workbench_code,workbench_name,workbench_domain',
40
+ condition: {},
41
+ };
42
+ const res = await this.curdProService.executeCrudByCfg(reqJson, {
43
+ sqlTable: SystemTables_1.SystemTables.sys_workbench,
44
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
45
+ sqlDatabase: SystemDbName,
46
+ sqlDbType: SystemDbType,
47
+ });
48
+ const workbenchList = res.getResRows();
49
+ return MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
50
+ },
51
+ });
48
52
  return workbenchListMap;
49
53
  }
50
54
  async handleExecuteContextPrepare(executeContext) {
@@ -72,6 +76,10 @@ __decorate([
72
76
  (0, core_1.Inject)(),
73
77
  __metadata("design:type", CurdProService_1.CurdProService)
74
78
  ], CurdMixByWorkbenchService.prototype, "curdProService", void 0);
79
+ __decorate([
80
+ (0, core_1.Inject)(),
81
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
82
+ ], CurdMixByWorkbenchService.prototype, "cacheServiceFactory", void 0);
75
83
  CurdMixByWorkbenchService = __decorate([
76
84
  (0, core_1.Provide)()
77
85
  ], CurdMixByWorkbenchService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.64",
3
+ "version": "0.0.1-beta.66",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -164,6 +164,14 @@ export default (appInfo: any) => {
164
164
  headerSecret: '222',
165
165
  },
166
166
 
167
+ /**
168
+ * 磁盘缓存配置
169
+ */
170
+ fatcmsCache: {
171
+ diskCacheDir: join(tmpdir(), 'fatcms-disk-cache'),
172
+ keyPrefix: 'fv1:',
173
+ },
174
+
167
175
  // 用户会话保持时间,单位秒
168
176
  fatcmsUserSessionKeepTimeSecond: 3600 * 24 * 30,
169
177
 
@@ -10,6 +10,9 @@ import { BaseService } from '@/service/base/BaseService';
10
10
  import * as moment from 'moment';
11
11
  import { CommonException } from '@/libs/crud-pro/exceptions';
12
12
  import { RedisKeys } from '@/models/RedisKeys';
13
+ import { Aes128CBC } from 'aes-128-cbc';
14
+ import * as md5 from 'md5';
15
+ import { AsymmetricCrypto } from '@/libs/utils/AsymmetricCrypto';
13
16
 
14
17
  export interface IExecuteSimpleSqlParams {
15
18
  updateCfg?: Record<string, IFuncCfgModel>;
@@ -19,6 +22,11 @@ export interface IExecuteSimpleSqlParams {
19
22
  columns?: string | string[]; // ..."columns": "id,name,age,sex,addr",
20
23
  }
21
24
 
25
+ export interface ISecretBody {
26
+ secretPayload: string;
27
+ secretKey: string; // 使用RSA公钥加密的AES密钥
28
+ }
29
+
22
30
  @Controller('/api/BaseApiController')
23
31
  export class BaseApiController extends BaseService {
24
32
  @Inject()
@@ -167,4 +175,35 @@ export class BaseApiController extends BaseService {
167
175
  columnsRelation.push(createdByRelation2);
168
176
  }
169
177
  }
178
+
179
+
180
+ protected async decodeBodyBySession<T>(body: any): Promise<any> {
181
+ const sessionInfo = this.getUserSessionInfo();
182
+ const sessionId = sessionInfo?.sessionId;
183
+ if (!sessionId) {
184
+ throw new Error('[decodeBodyBySessionId] sessionId is null');
185
+ }
186
+
187
+ const secretBody = body as ISecretBody;
188
+
189
+ if (!secretBody.secretPayload || !secretBody.secretKey) {
190
+ return body;
191
+ }
192
+
193
+ const { privateKey } = sessionInfo;
194
+
195
+ const secretPayload: string = secretBody.secretPayload;
196
+ const secretKey: string = secretBody.secretKey; // 使用RSA加密的AES密钥
197
+ const aesKey = await AsymmetricCrypto.decrypt(privateKey, secretKey); // 解密AES密钥
198
+
199
+ const createAes128 = () => {
200
+ const iv = md5(aesKey + sessionId);
201
+ return new Aes128CBC(aesKey, iv);
202
+ }
203
+ const aes128 = createAes128();
204
+ const decryptedPayload = await aes128.time_decrypt_base64_utf8(secretPayload);
205
+ return JSON.parse(decryptedPayload);
206
+ }
207
+
208
+
170
209
  }
@@ -4,13 +4,16 @@ import { BaseApiController } from '../base/BaseApiController';
4
4
  import { CrudStdService, SPECIAL_SETTING_KEY, ICrudStdActionParams, IRequestModelCrudProExt } from '@/service/crudstd/CrudStdService';
5
5
  import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
6
6
  import { CommonResult } from '@/libs/utils/common-dto';
7
+ import { checkLogin } from '@/middleware/permission.middleware';
7
8
 
8
9
  type ICrudStdParams = { stdAction: ICrudStdActionParams } & IRequestModelCrudProExt;
9
10
 
11
+
12
+
10
13
  /**
11
- * 零代码配置的界面,相关的接口的执行
14
+ * 零代码配置的界面,相关的接口的执行。这里的接口都需要登录。
12
15
  */
13
- @Controller('/ns/gw/api/crudStd')
16
+ @Controller('/ns/gw/api/crudStd', { middleware: [checkLogin()] })
14
17
  export class CrudStdGatewayController extends BaseApiController {
15
18
  @Inject()
16
19
  protected ctx: Context;
@@ -23,18 +26,36 @@ export class CrudStdGatewayController extends BaseApiController {
23
26
  */
24
27
  @Post('/getParsedCrudStdAppInfo')
25
28
  async getParsedCrudStdAppInfo(): Promise<CommonResult> {
26
- const body = this.ctx.request.body as ICrudStdParams;
29
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
30
+ const body = decodeBody as ICrudStdParams;
27
31
  const appCode = body.stdAction.appCode;
28
32
  const parsedAppInfo = await this.crudStdService.getParsedCrudStdAppInfo(appCode);
29
- return CommonResult.successNotNull(parsedAppInfo);
33
+ if (parsedAppInfo) {
34
+ const parsedAppInfo2: any = { ...parsedAppInfo };
35
+ delete parsedAppInfo2.created_at;
36
+ delete parsedAppInfo2.created_by;
37
+ delete parsedAppInfo2.workbench_code_array;
38
+ delete parsedAppInfo2.modified_at;
39
+ delete parsedAppInfo2.modified_by;
40
+ delete parsedAppInfo2.modified_desc;
41
+ delete parsedAppInfo2.std_crud_db;
42
+ delete parsedAppInfo2.std_crud_tbl;
43
+ return CommonResult.successNotNull(parsedAppInfo2);
44
+ }
45
+ return CommonResult.successNotNull(null);
30
46
  }
31
47
 
48
+
32
49
  /**
33
50
  * 列表查询: 分页查询
34
51
  */
35
52
  @Post('/getObjectList')
36
53
  async getObjectList() {
37
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
54
+
55
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
56
+ const body = decodeBody as ICrudStdParams;
57
+
58
+ const { stdAction, ...otherParams } = body;
38
59
  stdAction.settingKey = SPECIAL_SETTING_KEY.QUERY_LIST;
39
60
  return this.crudStdService.executeStdQuery(stdAction, otherParams, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
40
61
  }
@@ -44,7 +65,10 @@ export class CrudStdGatewayController extends BaseApiController {
44
65
  */
45
66
  @Post('/getObjectOne')
46
67
  async getObjectOne() {
47
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
68
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
69
+ const body = decodeBody as ICrudStdParams;
70
+
71
+ const { stdAction, ...otherParams } = body;
48
72
  stdAction.settingKey = SPECIAL_SETTING_KEY.QUERY_ONE;
49
73
  return this.crudStdService.executeStdQuery(stdAction, otherParams, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
50
74
  }
@@ -54,7 +78,9 @@ export class CrudStdGatewayController extends BaseApiController {
54
78
  */
55
79
  @Post('/deleteObject')
56
80
  async deleteObject() {
57
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
81
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
82
+ const body = decodeBody as ICrudStdParams;
83
+ const { stdAction, ...otherParams } = body;
58
84
  return this.crudStdService.executeStdQuery(stdAction, otherParams, KeysOfSimpleSQL.SIMPLE_DELETE);
59
85
  }
60
86
 
@@ -63,7 +89,9 @@ export class CrudStdGatewayController extends BaseApiController {
63
89
  */
64
90
  @Post('/createObject')
65
91
  async createObject() {
66
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
92
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
93
+ const body = decodeBody as ICrudStdParams;
94
+ const { stdAction, ...otherParams } = body;
67
95
  return this.crudStdService.executeStdQuery(stdAction, otherParams, KeysOfSimpleSQL.SIMPLE_INSERT);
68
96
  }
69
97
 
@@ -72,7 +100,9 @@ export class CrudStdGatewayController extends BaseApiController {
72
100
  */
73
101
  @Post('/updateObject')
74
102
  async updateObject() {
75
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
103
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
104
+ const body = decodeBody as ICrudStdParams;
105
+ const { stdAction, ...otherParams } = body;
76
106
  return this.crudStdService.executeStdQuery(stdAction, otherParams, KeysOfSimpleSQL.SIMPLE_UPDATE);
77
107
  }
78
108
 
@@ -81,7 +111,9 @@ export class CrudStdGatewayController extends BaseApiController {
81
111
  */
82
112
  @Post('/executeStdAction')
83
113
  async executeStdAction() {
84
- const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
114
+ const decodeBody = await this.decodeBodyBySession(this.ctx.request.body);
115
+ const body = decodeBody as ICrudStdParams;
116
+ const { stdAction, ...otherParams } = body;
85
117
  return await this.crudStdService.executeStdActionByReq(stdAction, otherParams);
86
118
  }
87
119
  }