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

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 (54) hide show
  1. package/dist/config/config.default.js +4 -1
  2. package/dist/controller/gateway/PublicApiController.js +3 -11
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +4 -4
  6. package/dist/models/SystemEntities.d.ts +0 -22
  7. package/dist/models/SystemEntities.js +1 -14
  8. package/dist/models/bizmodels.d.ts +20 -2
  9. package/dist/models/bizmodels.js +15 -1
  10. package/dist/service/EnumInfoService.js +3 -9
  11. package/dist/service/UserSessionService.js +4 -7
  12. package/dist/service/base/cache/CacheServiceFactory.d.ts +3 -5
  13. package/dist/service/base/cache/CacheServiceFactory.js +31 -20
  14. package/dist/service/base/cache/{FatcmsBaseCtxCache.d.ts → CtxCache.d.ts} +4 -5
  15. package/dist/service/base/cache/{FatcmsBaseCtxCache.js → CtxCache.js} +4 -5
  16. package/dist/service/base/cache/DiskCache.d.ts +19 -0
  17. package/dist/service/base/cache/{FatcmsBaseDiskCache.js → DiskCache.js} +10 -17
  18. package/dist/service/base/cache/MemoryCache.d.ts +12 -0
  19. package/dist/service/base/cache/{FatcmsBaseMemoryCache.js → MemoryCache.js} +9 -17
  20. package/dist/service/base/cache/{FatcmsBaseNoneCache.d.ts → NoneCache.d.ts} +2 -2
  21. package/dist/service/base/cache/{FatcmsBaseNoneCache.js → NoneCache.js} +3 -3
  22. package/dist/service/base/cache/{FatcmsBaseRedisCache.d.ts → RedisCache.d.ts} +5 -11
  23. package/dist/service/base/cache/{FatcmsBaseRedisCache.js → RedisCache.js} +9 -17
  24. package/dist/service/crudstd/CrudStdService.js +3 -11
  25. package/dist/service/curd/CurdMixByAccountService.d.ts +4 -0
  26. package/dist/service/curd/CurdMixByAccountService.js +50 -12
  27. package/dist/service/curd/CurdMixByDictService.js +4 -8
  28. package/dist/service/curd/CurdMixByLinkToCustomService.js +2 -7
  29. package/dist/service/curd/CurdMixBySysConfigService.js +4 -8
  30. package/dist/service/curd/CurdMixByWorkbenchService.js +3 -9
  31. package/package.json +1 -1
  32. package/src/config/config.default.ts +4 -1
  33. package/src/controller/gateway/PublicApiController.ts +2 -14
  34. package/src/index.ts +1 -1
  35. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +7 -5
  36. package/src/models/SystemEntities.ts +1 -30
  37. package/src/models/WorkbenchInfoTools.ts +3 -2
  38. package/src/models/bizmodels.ts +26 -4
  39. package/src/service/EnumInfoService.ts +12 -18
  40. package/src/service/UserSessionService.ts +14 -19
  41. package/src/service/base/cache/CacheServiceFactory.ts +51 -42
  42. package/src/service/base/cache/{FatcmsBaseCtxCache.ts → CtxCache.ts} +4 -6
  43. package/src/service/base/cache/{FatcmsBaseDiskCache.ts → DiskCache.ts} +18 -23
  44. package/src/service/base/cache/{FatcmsBaseMemoryCache.ts → MemoryCache.ts} +10 -16
  45. package/src/service/base/cache/{FatcmsBaseNoneCache.ts → NoneCache.ts} +3 -3
  46. package/src/service/base/cache/{FatcmsBaseRedisCache.ts → RedisCache.ts} +11 -18
  47. package/src/service/crudstd/CrudStdService.ts +19 -31
  48. package/src/service/curd/CurdMixByAccountService.ts +62 -14
  49. package/src/service/curd/CurdMixByDictService.ts +6 -11
  50. package/src/service/curd/CurdMixByLinkToCustomService.ts +1 -8
  51. package/src/service/curd/CurdMixBySysConfigService.ts +8 -15
  52. package/src/service/curd/CurdMixByWorkbenchService.ts +3 -10
  53. package/dist/service/base/cache/FatcmsBaseDiskCache.d.ts +0 -24
  54. package/dist/service/base/cache/FatcmsBaseMemoryCache.d.ts +0 -18
@@ -1,20 +1,14 @@
1
1
  import { Context } from '@midwayjs/koa';
2
2
  import { RedisService } from '@midwayjs/redis';
3
- import { ICacheServiceBase } from '../../../models/bizmodels';
4
- export declare class FatcmsBaseRedisCache implements ICacheServiceBase {
3
+ import { ICacheService } from '../../../models/bizmodels';
4
+ export declare class RedisCache implements ICacheService {
5
5
  protected ctx: Context;
6
6
  protected cacheName: string;
7
7
  protected redisService: RedisService;
8
- constructor(ctx: Context, cacheName: string, redisService: RedisService);
8
+ protected cacheSecond: number;
9
+ constructor(ctx: Context, cacheName: string, redisService: RedisService, cacheSecond: number);
9
10
  private getCacheKey;
10
11
  getJsonObject(key: string): Promise<any>;
11
- /**
12
- * 设置缓存对象
13
- * @param key
14
- * @param obj
15
- * @param expireSecond 过期时间,单位秒
16
- * @returns
17
- */
18
- setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any>;
12
+ setJsonObject(key: string, obj: any, cacheSecond0?: number): Promise<any>;
19
13
  removeItem(key: string): Promise<any>;
20
14
  }
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FatcmsBaseRedisCache = void 0;
3
+ exports.RedisCache = void 0;
4
4
  const functions_1 = require("../../../libs/utils/functions");
5
- class FatcmsBaseRedisCache {
6
- constructor(ctx, cacheName, redisService) {
5
+ class RedisCache {
6
+ constructor(ctx, cacheName, redisService, cacheSecond) {
7
7
  this.ctx = ctx;
8
8
  this.cacheName = cacheName;
9
9
  this.redisService = redisService;
10
+ this.cacheSecond = cacheSecond;
10
11
  }
11
12
  getCacheKey(key) {
12
13
  return `${this.cacheName}${key}`;
@@ -16,24 +17,15 @@ class FatcmsBaseRedisCache {
16
17
  const str = await this.redisService.get(cacheKey);
17
18
  return (0, functions_1.parseJsonObject)(str);
18
19
  }
19
- /**
20
- * 设置缓存对象
21
- * @param key
22
- * @param obj
23
- * @param expireSecond 过期时间,单位秒
24
- * @returns
25
- */
26
- async setJsonObject(key, obj, expireSecond) {
20
+ async setJsonObject(key, obj, cacheSecond0) {
21
+ const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
27
22
  const cacheKey = this.getCacheKey(key);
28
- if (!expireSecond) {
29
- expireSecond = 60;
30
- }
31
23
  const str = JSON.stringify(obj);
32
- return this.redisService.set(cacheKey, str, 'EX', expireSecond);
24
+ return this.redisService.set(cacheKey, str, 'EX', cacheSecond);
33
25
  }
34
26
  async removeItem(key) {
35
27
  const cacheKey = this.getCacheKey(key);
36
- return await this.redisService.del(cacheKey);
28
+ return this.redisService.del(cacheKey);
37
29
  }
38
30
  }
39
- exports.FatcmsBaseRedisCache = FatcmsBaseRedisCache;
31
+ exports.RedisCache = RedisCache;
@@ -26,14 +26,12 @@ 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
28
  const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
29
- const SystemEntities_1 = require("../../models/SystemEntities");
29
+ const bizmodels_1 = require("../../models/bizmodels");
30
30
  exports.SPECIAL_SETTING_KEY = {
31
31
  QUERY_LIST: 'QUERY_LIST',
32
32
  QUERY_ONE: 'QUERY_ONE',
33
33
  KANBAN_VIEW_STATUS_UPDATE: 'KANBAN_VIEW_STATUS_UPDATE', // 看板视图中更新状态
34
34
  };
35
- const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
36
- const DEFAULT_CACHE_SECOND = 60 * 5;
37
35
  function isNotEmptyStr(str) {
38
36
  return typeof str === 'string' && str.trim().length > 0;
39
37
  }
@@ -237,19 +235,13 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
237
235
  * @private
238
236
  */
239
237
  async getParsedCrudStdAppInfo(appCode) {
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,
238
+ return await this.cacheServiceFactory.getJsonObjectCache({
245
239
  cacheKey: appCode,
246
- cacheSecond,
247
- cacheName: SystemEntities_1.CacheNameEnum.GetParsedCrudStdAppInfo,
240
+ cacheName: bizmodels_1.CacheNameEnum.GetParsedCrudStdAppInfo,
248
241
  getter: async () => {
249
242
  return await this.getParsedCrudStdAppInfoPrivate(appCode);
250
243
  },
251
244
  });
252
- return appInfo;
253
245
  }
254
246
  /**
255
247
  * 查询APP信息
@@ -4,6 +4,10 @@ import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/cru
4
4
  export declare class CurdMixByAccountService implements IExecuteContextHandler {
5
5
  protected ctx: Context;
6
6
  protected curdProService: CurdProService;
7
+ private cacheServiceFactory;
7
8
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
9
+ private getFromCache;
10
+ private setToCache;
11
+ private queryUserAccountIdList;
8
12
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
9
13
  }
@@ -18,12 +18,13 @@ const SystemTables_1 = require("../../models/SystemTables");
18
18
  const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
20
20
  const global_config_1 = require("../../libs/global-config/global-config");
21
+ const bizmodels_1 = require("../../models/bizmodels");
22
+ const CacheServiceFactory_1 = require("../../service/base/cache/CacheServiceFactory");
21
23
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.accountBasic);
22
24
  const TMP_CTX_KEY = _.uniqueId('CurdMixByAccountService');
23
25
  const TMP_CTX_KEY2 = _.uniqueId('CurdMixByAccountService2');
24
26
  let CurdMixByAccountService = class CurdMixByAccountService {
25
27
  async handleExecuteContextPrepare(executeContext) {
26
- const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
27
28
  const relations = dictMixUtils.pickColumnRelations(executeContext);
28
29
  if (!relations || relations.length === 0) {
29
30
  return;
@@ -49,25 +50,58 @@ let CurdMixByAccountService = class CurdMixByAccountService {
49
50
  if (accountIds.size === 0) {
50
51
  return;
51
52
  }
52
- const cfgModel = {
53
- method: 'UserAccountService.queryAccountBasicInfoByIds',
54
- sqlTable: SystemTables_1.SystemTables.sys_user_account,
55
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
56
- sqlDatabase: SystemDbName,
57
- sqlDbType: SystemDbType,
58
- };
53
+ const userInfos = await this.queryUserAccountIdList([...accountIds]);
54
+ executeContext[TMP_CTX_KEY] = MixinUtils_1.MixinUtils.toNewMap(userInfos, (obj) => obj.account_id);
55
+ executeContext[TMP_CTX_KEY2] = isArrayModeMap;
56
+ }
57
+ async getFromCache(code) {
58
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByAccount);
59
+ return cacheService.getJsonObject(code);
60
+ }
61
+ async setToCache(code, value) {
62
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByAccount);
63
+ return cacheService.setJsonObject(code, value);
64
+ }
65
+ async queryUserAccountIdList(accountIds) {
66
+ const resultRowMap = {};
67
+ for (let i = 0; i < accountIds.length; i++) {
68
+ const accountId = accountIds[i];
69
+ const row = await this.getFromCache(accountId);
70
+ if (row) {
71
+ resultRowMap[accountId] = row;
72
+ }
73
+ }
74
+ const notCachedCodes = accountIds.filter((accountId) => !resultRowMap[accountId]);
75
+ if (notCachedCodes.length === 0) {
76
+ return Object.values(resultRowMap);
77
+ }
78
+ const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
59
79
  const reqJson = {
60
80
  columns: ['nick_name', 'avatar', 'account_id'],
61
81
  condition: {
62
82
  account_id: {
63
- $in: [...accountIds],
83
+ $in: [...notCachedCodes],
64
84
  },
65
85
  },
66
86
  };
87
+ const cfgModel = {
88
+ method: 'UserAccountService.queryAccountBasicInfoByIds',
89
+ sqlTable: SystemTables_1.SystemTables.sys_user_account,
90
+ sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
91
+ sqlDatabase: SystemDbName,
92
+ sqlDbType: SystemDbType,
93
+ };
67
94
  const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
68
- const userInfos = res.getResRows();
69
- executeContext[TMP_CTX_KEY] = MixinUtils_1.MixinUtils.toNewMap(userInfos, (obj) => obj.account_id);
70
- executeContext[TMP_CTX_KEY2] = isArrayModeMap;
95
+ const rows = res.getResRows();
96
+ if (Array.isArray(rows) && rows.length > 0) {
97
+ for (let i = 0; i < rows.length; i++) {
98
+ const row = rows[i];
99
+ const { account_id } = row;
100
+ await this.setToCache(account_id, row);
101
+ resultRowMap[account_id] = row;
102
+ }
103
+ }
104
+ return Object.values(resultRowMap);
71
105
  }
72
106
  async handleExecuteContext(executeContext) {
73
107
  const userInfoMap = executeContext[TMP_CTX_KEY];
@@ -107,6 +141,10 @@ __decorate([
107
141
  (0, core_1.Inject)(),
108
142
  __metadata("design:type", CurdProService_1.CurdProService)
109
143
  ], CurdMixByAccountService.prototype, "curdProService", void 0);
144
+ __decorate([
145
+ (0, core_1.Inject)(),
146
+ __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
147
+ ], CurdMixByAccountService.prototype, "cacheServiceFactory", void 0);
110
148
  CurdMixByAccountService = __decorate([
111
149
  (0, core_1.Provide)()
112
150
  ], CurdMixByAccountService);
@@ -19,21 +19,17 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
20
  const global_config_1 = require("../../libs/global-config/global-config");
21
21
  const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
22
- const SystemEntities_1 = require("../../models/SystemEntities");
22
+ const bizmodels_1 = require("../../models/bizmodels");
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;
27
25
  let CurdMixByDictService = class CurdMixByDictService {
28
26
  async getFromCache(code) {
29
- const { curdMixByCommonCacheLevel } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
30
- const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixByDict);
27
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByDict);
31
28
  return cacheService.getJsonObject(code);
32
29
  }
33
30
  async setToCache(code, value) {
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);
31
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByDict);
32
+ return cacheService.setJsonObject(code, value);
37
33
  }
38
34
  async handleExecuteContextPrepare(executeContext) {
39
35
  const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
@@ -19,13 +19,11 @@ const devops_1 = require("../../models/devops");
19
19
  const exceptions_1 = require("../../libs/crud-pro/exceptions");
20
20
  const DatabaseName_1 = require("../../libs/crud-pro/utils/DatabaseName");
21
21
  const global_config_1 = require("../../libs/global-config/global-config");
22
- const SystemEntities_1 = require("../../models/SystemEntities");
22
+ const bizmodels_1 = require("../../models/bizmodels");
23
23
  const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
24
24
  const md5 = require("md5");
25
25
  const linkToCustomMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.linkToCustom);
26
26
  const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
27
- const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
28
- const DEFAULT_CACHE_SECOND = 60 * 5;
29
27
  function toMapObject(rows, fieldsArr) {
30
28
  const valueKey = fieldsArr[0];
31
29
  const labelKey = fieldsArr[1];
@@ -82,12 +80,9 @@ let CurdMixByLinkToCustomService = class CurdMixByLinkToCustomService {
82
80
  });
83
81
  }
84
82
  async queryInfoByLinkToCustom(code) {
85
- const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
86
83
  return this.cacheServiceFactory.getJsonObjectCache({
87
- cacheLevel: curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL,
88
84
  cacheKey: md5(code),
89
- cacheSecond: curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND,
90
- cacheName: SystemEntities_1.CacheNameEnum.CurdMixByLinkToCustom,
85
+ cacheName: bizmodels_1.CacheNameEnum.CurdMixByLinkToCustom,
91
86
  getter: async () => {
92
87
  return await this.queryInfoByLinkToCustomImpl(code);
93
88
  },
@@ -20,21 +20,17 @@ 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
22
  const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
23
- const SystemEntities_1 = require("../../models/SystemEntities");
23
+ const bizmodels_1 = require("../../models/bizmodels");
24
24
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.sysCfgEnum);
25
25
  const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
26
- const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
27
- const DEFAULT_CACHE_SECOND = 60 * 5;
28
26
  let CurdMixBySysConfigService = class CurdMixBySysConfigService {
29
27
  async getFromCache(code) {
30
- const { curdMixByCommonCacheLevel } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
31
- const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, SystemEntities_1.CacheNameEnum.CurdMixBySysConfig);
28
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixBySysConfig);
32
29
  return cacheService.getJsonObject(code);
33
30
  }
34
31
  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);
32
+ const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixBySysConfig);
33
+ return cacheService.setJsonObject(code, value);
38
34
  }
39
35
  async queryConfigRowsUseCache(codes) {
40
36
  const resultRowMap = {};
@@ -19,21 +19,16 @@ const keys_1 = require("../../libs/crud-pro/models/keys");
19
19
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
20
20
  const global_config_1 = require("../../libs/global-config/global-config");
21
21
  const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
22
- const SystemEntities_1 = require("../../models/SystemEntities");
22
+ const bizmodels_1 = require("../../models/bizmodels");
23
23
  const workbenchMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.workbenchBasic);
24
24
  const TMP_CTX_KEY = _.uniqueId('CurdMixByWorkbenchService');
25
- const DEFAULT_CACHE_LEVEL = SystemEntities_1.CacheLevelEnum.MEMORY;
26
- const DEFAULT_CACHE_SECOND = 60 * 5;
27
25
  let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
28
26
  async loadWorkbenchListMap() {
29
27
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
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,
28
+ return await this.cacheServiceFactory.getJsonObjectCache({
34
29
  cacheKey: 'loadWorkbenchListMap',
35
30
  refreshCache: false,
36
- cacheName: SystemEntities_1.CacheNameEnum.CurdMixByWorkbench,
31
+ cacheName: bizmodels_1.CacheNameEnum.CurdMixByWorkbench,
37
32
  getter: async () => {
38
33
  const reqJson = {
39
34
  columns: 'workbench_code,workbench_name,workbench_domain',
@@ -49,7 +44,6 @@ let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
49
44
  return MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
50
45
  },
51
46
  });
52
- return workbenchListMap;
53
47
  }
54
48
  async handleExecuteContextPrepare(executeContext) {
55
49
  const relations = workbenchMixUtils.pickColumnRelations(executeContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.66",
3
+ "version": "0.0.1-beta.68",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -169,7 +169,10 @@ export default (appInfo: any) => {
169
169
  */
170
170
  fatcmsCache: {
171
171
  diskCacheDir: join(tmpdir(), 'fatcms-disk-cache'),
172
- keyPrefix: 'fv1:',
172
+ cacheConfig: {
173
+ UserSessionBySessionId: { cacheLevel: 'REDIS', cacheSecond: 3600 * 24 * 30 },
174
+ UserSessionByAsyncTaskId: { cacheLevel: 'REDIS', cacheSecond: 3600 },
175
+ }
173
176
  },
174
177
 
175
178
  // 用户会话保持时间,单位秒
@@ -11,12 +11,8 @@ import { WorkbenchService } from '@/service/WorkbenchService';
11
11
  import { SystemRoleCode } from '@/models/SystemPerm';
12
12
  import { KeysOfAuthType } from '@/libs/crud-pro/models/keys';
13
13
  import { CacheServiceFactory } from '@/service/base/cache/CacheServiceFactory';
14
- import md5 = require('md5');
15
- import { CacheLevelEnum, CacheNameEnum } from '@/models/SystemEntities';
16
-
17
-
18
- const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
19
- const DEFAULT_CACHE_SECOND = 60 * 5;
14
+ import * as md5 from 'md5';
15
+ import { CacheNameEnum} from "@/models/bizmodels";
20
16
 
21
17
 
22
18
  /**
@@ -64,12 +60,8 @@ export class PublicApiController extends BaseApiController {
64
60
  return CommonResult.errorRes('param workbenchMenuCode is null');
65
61
  }
66
62
 
67
- const { publicApiMenuCacheLevel, publicApiMenuCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
68
-
69
63
  const mapResult = await this.cacheServiceFactory.getJsonObjectCache({
70
- cacheLevel: publicApiMenuCacheLevel || DEFAULT_CACHE_LEVEL,
71
64
  cacheKey: "" + workbenchMenuCode,
72
- cacheSecond: publicApiMenuCacheSecond || DEFAULT_CACHE_SECOND,
73
65
  cacheName: CacheNameEnum.GetWorkbenchMenu,
74
66
  getter: async () => {
75
67
 
@@ -134,13 +126,9 @@ export class PublicApiController extends BaseApiController {
134
126
  };
135
127
 
136
128
 
137
- const { publicApiNavPageInfoCacheLevel, publicApiNavPageInfoCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
138
-
139
129
  const getOne = async (condition: any, tableName: string, key: string) => {
140
130
  const cacheKey = md5(tableName + ':' + JSON.stringify(condition) + ":" + key);
141
131
  const oneData = await this.cacheServiceFactory.getJsonObjectCache({
142
- cacheLevel: publicApiNavPageInfoCacheLevel || DEFAULT_CACHE_LEVEL,
143
- cacheSecond: publicApiNavPageInfoCacheSecond || DEFAULT_CACHE_SECOND,
144
132
  cacheKey,
145
133
  cacheName: CacheNameEnum.GetNavPageInfo,
146
134
  getter: async () => {
package/src/index.ts CHANGED
@@ -54,7 +54,7 @@ export * from './service/anyapi/AnyApiSandboxService';
54
54
  export * from './service/anyapi/AnyApiService';
55
55
  export * from './service/base/ApiBaseService';
56
56
  export * from './service/base/BaseService';
57
- export * from './service/base/cache/FatcmsBaseRedisCache';
57
+ export * from './service/base/cache/CacheServiceFactory';
58
58
  export * from './service/crudstd/CrudStdActionService';
59
59
  export * from './service/crudstd/CrudStdRelationService';
60
60
  export * from './service/crudstd/CrudStdService';
@@ -29,7 +29,7 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
29
29
  }
30
30
 
31
31
  private async executeSqlCfgModel(sqlCfgModel: SqlCfgModel) {
32
- this.logger.info('executeSqlCfgModel1', sqlCfgModel.executeSql, sqlCfgModel.executeSqlArgs);
32
+ this.logger.info('[CrudProExecuteSqlService] executeSqlCfgModel_before', sqlCfgModel.executeSql, sqlCfgModel.executeSqlArgs);
33
33
 
34
34
  const exeCtx = this.getExecuteContext();
35
35
  const connection = await this.getTxConnectionBySqlCfg(sqlCfgModel);
@@ -42,22 +42,24 @@ class CrudProExecuteSqlService extends CrudProServiceBase {
42
42
 
43
43
  const pgClient: PoolClient = connection as any;
44
44
  const pgSql = replaceQuestionMarks(sqlCfgModel.executeSql);
45
- this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
46
45
  queryRes = await pgClient.query({
47
46
  text: pgSql,
48
47
  values: executeSqlArgs || [],
49
48
  });
49
+
50
+ this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
51
+
50
52
  } else if (sqlCfgModel.sqlDbType === SqlDbType.sqlserver) {
51
53
  // SQLServer
52
54
 
53
55
  const mssql = replaceQuestionMarksForMssql(sqlCfgModel.executeSql);
54
- this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
55
56
  queryRes = await connection.query(mssql, executeSqlArgs);
57
+ this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
58
+
56
59
  } else {
57
60
  // MYSQL
58
-
59
- this.logger.debug('[CrudProExecuteSqlService]executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
60
61
  queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
62
+ this.logger.debug('[CrudProExecuteSqlService] executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
61
63
  }
62
64
 
63
65
  const sqlRes = pickAndConvertRowsByMix(queryRes, sqlCfgModel.sqlDbType);
@@ -130,37 +130,8 @@ export enum CacheLevelEnum {
130
130
  DISK = 'DISK', // 磁盘缓存
131
131
  }
132
132
 
133
- export enum CacheNameEnum {
134
- CurdMixByDict = 'CurdMixByDict',
135
- CurdMixByLinkToCustom = 'CurdMixByLinkToCustom',
136
- CurdMixBySysConfig = 'CurdMixBySysConfig',
137
- CurdMixByWorkbench = 'CurdMixByWorkbench',
138
- GetParsedCrudStdAppInfo = 'GetParsedCrudStdAppInfo',
139
- GetWorkbenchMenu = 'GetWorkbenchMenu',
140
- GetNavPageInfo = 'GetNavPageInfo',
141
- GetEnumInfoByCode = 'GetEnumInfoByCode',
142
- UserSessionBySessionId = 'UserSessionBySessionId',
143
- UserSessionByAsyncTaskId = 'UserSessionByAsyncTaskId',
144
- }
145
-
146
-
147
133
  export interface IWorkbenchConfig {
148
134
  nodeApiWhiteEnable?: boolean; // 接口白名单开关
149
135
  nodeApiWhiteList?: string[]; // 接口白名单,完整匹配
150
136
  nodeApiWhitePrefix?: string[]; // 接口白名单,根据前缀匹配
151
-
152
- crudStdAppInfoCacheLevel?: CacheLevelEnum; // 零代码CRUD接口白名单开关. 默认: MEMORY
153
- crudStdAppInfoCacheSecond?: number; // 零代码CRUD接口白名单缓存时间,单位:秒。 默认 5分钟
154
-
155
- publicApiNavPageInfoCacheLevel?: CacheLevelEnum; // 公开API导航页缓存级别. 默认: MEMORY
156
- publicApiNavPageInfoCacheSecond?: number; // 公开API导航页缓存时间,单位:秒。 默认 5分钟
157
-
158
- publicApiMenuCacheLevel?: CacheLevelEnum; // 公开API菜单缓存级别. 默认: MEMORY
159
- publicApiMenuCacheSecond?: number; // 公开API菜单缓存时间,单位:秒。 默认 5分钟
160
-
161
- queryEnumInfoCacheLevel?: CacheLevelEnum; // 查询枚举缓存级别. 默认: MEMORY
162
- queryEnumInfoCacheSecond?: number; // 查询枚举缓存时间,单位:秒。 默认 5分钟
163
-
164
- curdMixByCommonCacheLevel?: CacheLevelEnum; // CrudMixService 缓存级别. 默认: MEMORY
165
- curdMixByCommonCacheSecond?: number; // CrudMixService 缓存时间,单位:秒。 默认 5分钟
166
- }
137
+ }
@@ -1,5 +1,6 @@
1
1
  import { parseJsonObject } from "@/libs/utils/functions";
2
- import { IWorkbenchConfig, IWorkbenchEntity } from "./SystemEntities";
2
+ import { IWorkbenchConfig, IWorkbenchEntity} from "./SystemEntities";
3
+
3
4
 
4
5
 
5
6
  export class WorkbenchInfoTools {
@@ -13,6 +14,6 @@ export class WorkbenchInfoTools {
13
14
  }
14
15
  const configObj: IWorkbenchConfig = parseJsonObject(this.workbenchInfo?.config_content);
15
16
  this.parsedConfigContent = configObj || {};
16
- return this.parsedConfigContent;
17
+ return this.parsedConfigContent;
17
18
  }
18
19
  }
@@ -1,4 +1,5 @@
1
- import { IRequestCfgModel, IVisitor } from '../libs/crud-pro/interfaces';
1
+ import { IRequestCfgModel, IVisitor } from '@/libs/crud-pro/interfaces';
2
+ import {CacheLevelEnum} from "@/models/SystemEntities";
2
3
 
3
4
  /**
4
5
  * 实体表公共字段
@@ -126,14 +127,35 @@ export interface IStdCrudExportInputParams {
126
127
  pageSize: number; // 公共
127
128
  }
128
129
 
129
- export interface ICacheServiceBase {
130
+ export interface ICacheService {
130
131
  getJsonObject(key: string): Promise<any>;
131
132
  setJsonObject(key: string, obj: any, cacheSecond?: number): Promise<any>;
132
133
  removeItem(key: string): Promise<any>;
133
134
  }
134
135
 
135
136
 
137
+ export enum CacheNameEnum {
138
+ CurdMixByAccount = 'CurdMixByAccount',
139
+ CurdMixByDict = 'CurdMixByDict',
140
+ CurdMixByLinkToCustom = 'CurdMixByLinkToCustom',
141
+ CurdMixBySysConfig = 'CurdMixBySysConfig',
142
+ CurdMixByWorkbench = 'CurdMixByWorkbench',
143
+ GetParsedCrudStdAppInfo = 'GetParsedCrudStdAppInfo',
144
+ GetWorkbenchMenu = 'GetWorkbenchMenu',
145
+ GetNavPageInfo = 'GetNavPageInfo',
146
+ GetEnumInfoByCode = 'GetEnumInfoByCode',
147
+ UserSessionBySessionId = 'UserSessionBySessionId', // 只能是Redis
148
+ UserSessionByAsyncTaskId = 'UserSessionByAsyncTaskId', // 只能是Redis
149
+ }
150
+
151
+
152
+ export interface IWorkbenchConfigCacheLevel {
153
+ cacheLevel: CacheLevelEnum;
154
+ cacheSecond: number;
155
+ }
156
+
157
+
136
158
  export interface IfatcmsCacheConfig {
137
- diskCacheDir: string;
138
- keyPrefix: string;
159
+ diskCacheDir: string;
160
+ cacheConfig?: Record<CacheNameEnum, IWorkbenchConfigCacheLevel>
139
161
  }
@@ -1,14 +1,14 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
- import { CurdProService } from './curd/CurdProService';
5
- import { RelatedType } from './curd/CurdMixUtils';
6
- import { SystemTables } from '@/models/SystemTables';
7
- import { parseConfigContentToEnumInfo, IEnumInfo } from '@/libs/utils/parseConfig';
8
- import { CurdMixByLinkToCustomService } from './curd/CurdMixByLinkToCustomService';
9
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
10
- import { CacheServiceFactory } from './base/cache/CacheServiceFactory';
11
- import { CacheLevelEnum, CacheNameEnum } from '@/models/SystemEntities';
1
+ import {Inject, Provide} from '@midwayjs/core';
2
+ import {Context} from '@midwayjs/koa';
3
+ import {KeysOfSimpleSQL} from '@/libs/crud-pro/models/keys';
4
+ import {CurdProService} from './curd/CurdProService';
5
+ import {RelatedType} from './curd/CurdMixUtils';
6
+ import {SystemTables} from '@/models/SystemTables';
7
+ import {IEnumInfo, parseConfigContentToEnumInfo} from '@/libs/utils/parseConfig';
8
+ import {CurdMixByLinkToCustomService} from './curd/CurdMixByLinkToCustomService';
9
+ import {GLOBAL_STATIC_CONFIG} from '@/libs/global-config/global-config';
10
+ import {CacheServiceFactory} from './base/cache/CacheServiceFactory';
11
+ import { CacheNameEnum } from "@/models/bizmodels";
12
12
 
13
13
  interface IQueryEnumInfo {
14
14
  type: RelatedType;
@@ -24,8 +24,6 @@ function filterEmpty(e: IEnumInfo): boolean {
24
24
  return e.label && typeof e.value !== 'undefined';
25
25
  }
26
26
 
27
- const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
28
- const DEFAULT_CACHE_SECOND = 60 * 5;
29
27
 
30
28
 
31
29
  @Provide()
@@ -42,7 +40,6 @@ export class EnumInfoService {
42
40
  private cacheServiceFactory: CacheServiceFactory;
43
41
 
44
42
  async queryEnumInfo(codeList: IQueryEnumInfo[], refreshCache: boolean): Promise<IQueryEnumResult[]> {
45
- const { queryEnumInfoCacheLevel, queryEnumInfoCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig() || {};
46
43
 
47
44
  const getEnumInfoByCode = async (type: RelatedType, code: string) => {
48
45
  if (type === RelatedType.linkToCustom) {
@@ -50,9 +47,7 @@ export class EnumInfoService {
50
47
  }
51
48
 
52
49
  const cacheKey = `${type}@@${code}`;
53
- const emums = refreshCache ? null : await this.cacheServiceFactory.getJsonObjectCache({
54
- cacheLevel: queryEnumInfoCacheLevel || DEFAULT_CACHE_LEVEL,
55
- cacheSecond: queryEnumInfoCacheSecond || DEFAULT_CACHE_SECOND,
50
+ return await this.cacheServiceFactory.getJsonObjectCache({
56
51
  cacheKey,
57
52
  refreshCache,
58
53
  cacheName: CacheNameEnum.GetEnumInfoByCode,
@@ -65,7 +60,6 @@ export class EnumInfoService {
65
60
  return [];
66
61
  },
67
62
  });
68
- return emums;
69
63
  };
70
64
 
71
65
  const result = [];