midway-fatcms 0.0.16 → 0.0.18

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 (146) hide show
  1. package/dist/config/config.default.js +5 -3
  2. package/dist/configuration.d.ts +0 -3
  3. package/dist/configuration.js +0 -19
  4. package/dist/controller/gateway/ProxyApiGatewayController.d.ts +0 -2
  5. package/dist/controller/gateway/ProxyApiGatewayController.js +0 -18
  6. package/dist/controller/helpers.controller.d.ts +4 -5
  7. package/dist/controller/helpers.controller.js +56 -14
  8. package/dist/controller/manage/AccountRoleManageApi.js +3 -5
  9. package/dist/controller/manage/AnyApiMangeApi.js +4 -3
  10. package/dist/controller/manage/AppMangeApi.js +3 -4
  11. package/dist/controller/manage/AppPageMangeApi.js +4 -3
  12. package/dist/controller/manage/CrudMethodsMangeApi.js +3 -4
  13. package/dist/controller/manage/DataDictManageApi.js +6 -7
  14. package/dist/controller/manage/DeployManageApi.js +4 -5
  15. package/dist/controller/manage/FlowConfigManageApi.js +3 -5
  16. package/dist/controller/manage/MenuManageApi.js +3 -4
  17. package/dist/controller/manage/ProxyApiMangeApi.js +3 -4
  18. package/dist/controller/manage/SysConfigMangeApi.js +3 -3
  19. package/dist/controller/manage/SystemInfoManageApi.js +3 -1
  20. package/dist/controller/manage/WorkbenchMangeApi.js +3 -4
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +3 -0
  23. package/dist/libs/crud-pro/models/TransactionSqlServer.js +27 -4
  24. package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +5 -8
  25. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +25 -42
  26. package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.d.ts +2 -37
  27. package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.js +137 -213
  28. package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +0 -9
  29. package/dist/libs/crud-pro/utils/CrudMonitor.js +0 -21
  30. package/dist/libs/crud-pro/utils/MixinUtils.d.ts +2 -17
  31. package/dist/libs/crud-pro/utils/MixinUtils.js +4 -84
  32. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeId.d.ts +12 -0
  33. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeId.js +61 -0
  34. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.d.ts +19 -0
  35. package/dist/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.js +89 -0
  36. package/dist/libs/crud-pro/utils/idgene/index.d.ts +3 -0
  37. package/dist/libs/crud-pro/utils/idgene/index.js +10 -0
  38. package/dist/libs/crud-pro/utils/idgene/uuid.d.ts +7 -0
  39. package/dist/libs/crud-pro/utils/idgene/uuid.js +28 -0
  40. package/dist/libs/crud-pro/utils/pool/SqlServerUtils.js +26 -0
  41. package/dist/libs/crud-pro-quick/fixSoftDelete.d.ts +0 -17
  42. package/dist/libs/crud-pro-quick/fixSoftDelete.js +55 -5
  43. package/dist/libs/crud-pro-quick/models.d.ts +11 -1
  44. package/dist/middleware/cacherefresh.middleware.d.ts +3 -46
  45. package/dist/middleware/cacherefresh.middleware.js +9 -67
  46. package/dist/models/CacheRefreshCategory.d.ts +1 -18
  47. package/dist/models/CacheRefreshCategory.js +0 -17
  48. package/dist/models/SystemEntities.d.ts +2 -0
  49. package/dist/models/bizmodels.d.ts +0 -8
  50. package/dist/models/bizmodels.js +0 -8
  51. package/dist/schedule/scheduleNames.d.ts +2 -0
  52. package/dist/schedule/scheduleNames.js +3 -1
  53. package/dist/service/SysAppService.d.ts +0 -6
  54. package/dist/service/SysAppService.js +10 -79
  55. package/dist/service/SysConfigService.d.ts +0 -6
  56. package/dist/service/SysConfigService.js +6 -51
  57. package/dist/service/SysDictDataService.d.ts +0 -5
  58. package/dist/service/SysDictDataService.js +7 -65
  59. package/dist/service/SysMenuService.d.ts +0 -4
  60. package/dist/service/SysMenuService.js +5 -44
  61. package/dist/service/WorkbenchService.d.ts +1 -6
  62. package/dist/service/WorkbenchService.js +9 -63
  63. package/dist/service/anyapi/AnyApiService.d.ts +1 -1
  64. package/dist/service/anyapi/AnyApiService.js +6 -16
  65. package/dist/service/base/bizmemcache/BizMemCacheService.d.ts +16 -0
  66. package/dist/service/base/bizmemcache/BizMemCacheService.js +241 -0
  67. package/dist/service/base/bizmemcache/BizMemCacheStore.d.ts +34 -0
  68. package/dist/service/base/bizmemcache/BizMemCacheStore.js +119 -0
  69. package/dist/service/base/bizmemcache/BizMemCacheTypes.d.ts +60 -0
  70. package/dist/service/base/bizmemcache/BizMemCacheTypes.js +18 -0
  71. package/dist/service/base/cache-refresh/CacheRefreshHub.d.ts +0 -22
  72. package/dist/service/base/cache-refresh/CacheRefreshHub.js +0 -22
  73. package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.d.ts +0 -6
  74. package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.js +0 -6
  75. package/dist/service/crudstd/CrudStdService.js +1 -1
  76. package/dist/service/curd/CurdMixByDictService.d.ts +0 -4
  77. package/dist/service/curd/CurdMixByDictService.js +9 -55
  78. package/dist/service/curd/CurdMixBySysConfigService.d.ts +0 -5
  79. package/dist/service/curd/CurdMixBySysConfigService.js +9 -54
  80. package/dist/service/curd/CurdMixByWorkbenchService.d.ts +0 -1
  81. package/dist/service/curd/CurdMixByWorkbenchService.js +9 -36
  82. package/dist/service/curd/CurdProService.d.ts +0 -1
  83. package/dist/service/curd/CurdProService.js +0 -4
  84. package/dist/service/curd/fixCfgModel.js +21 -1
  85. package/dist/service/proxyapi/ProxyApiLoadService.d.ts +3 -8
  86. package/dist/service/proxyapi/ProxyApiLoadService.js +40 -68
  87. package/dist/service/proxyapi/ProxyApiService.d.ts +2 -0
  88. package/dist/service/proxyapi/ProxyApiService.js +32 -9
  89. package/dist/service/proxyapi/RouteTrie.d.ts +1 -7
  90. package/dist/service/proxyapi/RouteTrie.js +1 -17
  91. package/package.json +1 -1
  92. package/src/config/config.default.ts +4 -2
  93. package/src/configuration.ts +0 -23
  94. package/src/controller/gateway/ProxyApiGatewayController.ts +1 -9
  95. package/src/controller/helpers.controller.ts +66 -15
  96. package/src/controller/manage/AccountRoleManageApi.ts +3 -5
  97. package/src/controller/manage/AnyApiMangeApi.ts +4 -3
  98. package/src/controller/manage/AppMangeApi.ts +4 -5
  99. package/src/controller/manage/AppPageMangeApi.ts +4 -3
  100. package/src/controller/manage/CrudMethodsMangeApi.ts +4 -5
  101. package/src/controller/manage/DataDictManageApi.ts +7 -8
  102. package/src/controller/manage/DeployManageApi.ts +2 -3
  103. package/src/controller/manage/FlowConfigManageApi.ts +3 -5
  104. package/src/controller/manage/MenuManageApi.ts +4 -5
  105. package/src/controller/manage/ProxyApiMangeApi.ts +4 -5
  106. package/src/controller/manage/SysConfigMangeApi.ts +5 -5
  107. package/src/controller/manage/SystemInfoManageApi.ts +3 -1
  108. package/src/controller/manage/WorkbenchMangeApi.ts +4 -5
  109. package/src/index.ts +3 -0
  110. package/src/libs/crud-pro/models/TransactionSqlServer.ts +26 -4
  111. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +25 -43
  112. package/src/libs/crud-pro/services/CrudProDataTypeConvertService.ts +149 -219
  113. package/src/libs/crud-pro/utils/CrudMonitor.ts +0 -23
  114. package/src/libs/crud-pro/utils/MixinUtils.ts +309 -400
  115. package/src/libs/crud-pro/utils/idgene/generateSnowflakeId.ts +65 -0
  116. package/src/libs/crud-pro/utils/idgene/generateSnowflakeIdExt.ts +99 -0
  117. package/src/libs/crud-pro/utils/idgene/index.ts +3 -0
  118. package/src/libs/crud-pro/utils/idgene/uuid.ts +26 -0
  119. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +31 -0
  120. package/src/libs/crud-pro-quick/fixSoftDelete.ts +84 -18
  121. package/src/libs/crud-pro-quick/models.ts +15 -3
  122. package/src/middleware/cacherefresh.middleware.ts +10 -71
  123. package/src/models/CacheRefreshCategory.ts +0 -17
  124. package/src/models/SystemEntities.ts +2 -0
  125. package/src/models/bizmodels.ts +0 -8
  126. package/src/schedule/scheduleNames.ts +5 -3
  127. package/src/service/SysAppService.ts +7 -78
  128. package/src/service/SysConfigService.ts +4 -45
  129. package/src/service/SysDictDataService.ts +5 -64
  130. package/src/service/SysMenuService.ts +3 -40
  131. package/src/service/WorkbenchService.ts +9 -72
  132. package/src/service/anyapi/AnyApiService.ts +5 -17
  133. package/src/service/base/bizmemcache/BizMemCacheService.ts +290 -0
  134. package/src/service/base/bizmemcache/BizMemCacheStore.ts +159 -0
  135. package/src/service/base/bizmemcache/BizMemCacheTypes.ts +76 -0
  136. package/src/service/base/cache-refresh/CacheRefreshHub.ts +0 -22
  137. package/src/service/base/cache-refresh/CacheRefreshHubScheduleService.ts +0 -6
  138. package/src/service/crudstd/CrudStdService.ts +3 -2
  139. package/src/service/curd/CurdMixByDictService.ts +10 -61
  140. package/src/service/curd/CurdMixBySysConfigService.ts +9 -62
  141. package/src/service/curd/CurdMixByWorkbenchService.ts +7 -32
  142. package/src/service/curd/CurdProService.ts +0 -6
  143. package/src/service/curd/fixCfgModel.ts +145 -125
  144. package/src/service/proxyapi/ProxyApiLoadService.ts +39 -77
  145. package/src/service/proxyapi/ProxyApiService.ts +45 -9
  146. package/src/service/proxyapi/RouteTrie.ts +1 -18
@@ -1,57 +1,16 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { SystemTables } from '@/models/SystemTables';
1
+ import { Provide } from '@midwayjs/core';
4
2
  import { BaseService } from './base/BaseService';
5
- import { CurdProService } from './curd/CurdProService';
6
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
7
- import { CacheNameEnum } from "@/models/bizmodels";
8
- import { CacheServiceFactory } from "@/service/base/cache/CacheServiceFactory";
3
+ import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore';
9
4
 
10
5
  @Provide()
11
6
  export class SysConfigService extends BaseService {
12
- @Inject()
13
- ctx: Context;
14
-
15
- @Inject()
16
- private curdProService: CurdProService;
17
-
18
- @Inject()
19
- private cacheServiceFactory: CacheServiceFactory;
20
-
21
- private get sysConfigsDao(){
22
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
23
- return this.curdProService.getQuickCrud({
24
- sqlDatabase: SystemDbName,
25
- sqlDbType: SystemDbType,
26
- sqlTable: SystemTables.sys_configs,
27
- })
28
- }
29
7
 
30
8
  async getSysConfigOne(config_code: string): Promise<Record<string, any>> {
31
9
  if (!config_code || typeof config_code !== 'string') {
32
10
  throw new Error('[getSysAppOne] config_code required');
33
11
  }
34
- return await this.cacheServiceFactory.getJsonObjectCache({
35
- cacheKey: config_code,
36
- cacheName: CacheNameEnum.GetSysConfigOne,
37
- getter: async (ctx) => {
38
- const service: SysConfigService = await ctx.requestContext.getAsync(SysConfigService);
39
- const res = await service.sysConfigsDao.findOne({
40
- condition: {config_code, deleted_at: 0}
41
- });
42
- return res.row;
43
- },
44
- });
12
+ const sysConfigCodeMap = bizMemCacheStore.getSysConfig()?.sysConfigCodeMap || {};
13
+ return sysConfigCodeMap[config_code];
45
14
  }
46
15
 
47
- async removeSysConfigOneCache(config_code: string) {
48
- if (!config_code || typeof config_code !== 'string') {
49
- throw new Error('[removeSysConfigOneCache] config_code required');
50
- }
51
-
52
- return await this.cacheServiceFactory.removeItemCache({
53
- cacheKey: config_code,
54
- cacheName: CacheNameEnum.GetSysConfigOne,
55
- });
56
- }
57
16
  }
@@ -1,74 +1,15 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { SystemTables } from '@/models/SystemTables';
1
+ import { Provide } from '@midwayjs/core';
3
2
  import { BaseService } from './base/BaseService';
4
- import { CurdProService } from './curd/CurdProService';
5
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
6
- import { CacheServiceFactory } from "@/service/base/cache/CacheServiceFactory";
7
- import { CacheNameEnum } from "@/models/bizmodels";
3
+ import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore';
8
4
 
9
5
  @Provide()
10
6
  export class SysDictDataService extends BaseService {
11
7
 
12
- @Inject()
13
- private curdProService: CurdProService;
14
-
15
- @Inject()
16
- private cacheServiceFactory: CacheServiceFactory;
17
-
18
- private get sys_data_dict_item() {
19
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
20
- return this.curdProService.getQuickCrud({
21
- sqlDatabase: SystemDbName,
22
- sqlDbType: SystemDbType,
23
- sqlTable: SystemTables.sys_data_dict_item,
24
- })
25
- }
26
-
27
- // private get sys_data_dict(){
28
- // const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
29
- // return this.curdProService.getQuickCrud({
30
- // sqlDatabase: SystemDbName,
31
- // sqlDbType: SystemDbType,
32
- // sqlTable: SystemTables.sys_data_dict,
33
- // })
34
- // }
35
-
36
-
37
8
  public async getDataDictItemsByDictCode(dict_code: string): Promise<any[]> {
38
9
  if (!dict_code || typeof dict_code !== 'string') {
39
- throw new Error('[getDataDictItemsByDictCode] page_path required');
40
- }
41
- return await this.cacheServiceFactory.getJsonObjectCache({
42
- cacheKey: dict_code,
43
- cacheName: CacheNameEnum.GetDataDictItemsByDictCode,
44
- getter: async (ctx) => {
45
- const service: SysDictDataService = await ctx.requestContext.getAsync(SysDictDataService);
46
- const res = await service.sys_data_dict_item.findList({
47
- condition: { dict_code, status: 1, deleted_at: 0 }
48
- });
49
- return res.rows;
50
- },
51
- });
52
- }
53
-
54
- public async removeCacheByDictItemId(dict_item_id: string) {
55
- const res = await this.sys_data_dict_item.findOne({ condition: { id: dict_item_id } });
56
- const dictItemObj = res.row;
57
- return this.removeCacheByDictCode(dictItemObj['dict_code']);
58
- }
59
-
60
- // public async removeCacheByDictId(dict_id: string) {
61
- // const dictObj = await this.sys_data_dict.getUniqueOne({condition: {id: dict_id}});
62
- // return this.removeCacheByDictCode(dictObj['dict_code']);
63
- // }
64
-
65
- public async removeCacheByDictCode(dict_code: string) {
66
- if (!dict_code || typeof dict_code !== 'string') {
67
- throw new Error('[removeSysAppOneCache] app_code required');
10
+ throw new Error('[getDataDictItemsByDictCode] dict_code required');
68
11
  }
69
- return await this.cacheServiceFactory.removeItemCache({
70
- cacheKey: dict_code,
71
- cacheName: CacheNameEnum.GetDataDictItemsByDictCode
72
- });
12
+ const dictCodeMap = bizMemCacheStore.getDataDictItem()?.dictCodeMap || {};
13
+ return dictCodeMap[dict_code] || [];
73
14
  }
74
15
  }
@@ -1,10 +1,6 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { SystemTables } from '@/models/SystemTables';
1
+ import { Provide } from '@midwayjs/core';
3
2
  import { BaseService } from './base/BaseService';
4
- import { CurdProService } from './curd/CurdProService';
5
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
6
- import { CacheServiceFactory } from "@/service/base/cache/CacheServiceFactory";
7
- import { CacheNameEnum } from "@/models/bizmodels";
3
+ import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore';
8
4
 
9
5
  /**
10
6
  * 菜单表接口定义
@@ -49,45 +45,12 @@ interface SysMenus {
49
45
  @Provide()
50
46
  export class SysMenuService extends BaseService {
51
47
 
52
- @Inject()
53
- private curdProService: CurdProService;
54
-
55
- @Inject()
56
- private cacheServiceFactory: CacheServiceFactory;
57
-
58
- private get sys_menus_table() {
59
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
60
- return this.curdProService.getQuickCrud({
61
- sqlDatabase: SystemDbName,
62
- sqlDbType: SystemDbType,
63
- sqlTable: SystemTables.sys_menus,
64
- })
65
- }
66
-
67
-
68
48
  /**
69
49
  * 获取所有菜单列表
70
50
  * @returns
71
51
  */
72
52
  async getCachedMenusList(): Promise<SysMenus[]> {
73
- return await this.cacheServiceFactory.getJsonObjectCache({
74
- cacheKey: CacheNameEnum.GetSysMenusList,
75
- cacheName: CacheNameEnum.GetSysMenusList,
76
- getter: async (ctx) => {
77
- const service: SysMenuService = await ctx.requestContext.getAsync(SysMenuService);
78
- const res = await service.sys_menus_table.findList({
79
- condition: { deleted_at: 0 }
80
- });
81
- return res.rows;
82
- },
83
- });
53
+ return bizMemCacheStore.getSysMenu()?.sysMenuList || [];
84
54
  }
85
55
 
86
-
87
- async removeSysMenuCache() {
88
- return await this.cacheServiceFactory.removeItemCache({
89
- cacheKey: CacheNameEnum.GetSysMenusList,
90
- cacheName: CacheNameEnum.GetSysMenusList,
91
- });
92
- }
93
56
  }
@@ -1,89 +1,26 @@
1
1
  import { Config, Inject, Provide } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
- import { SystemTables } from '@/models/SystemTables';
5
3
  import { BaseService } from './base/BaseService';
6
- import { CurdProService } from './curd/CurdProService';
7
4
  import { CommonException } from '@/libs/crud-pro/exceptions';
8
5
  import { parseJsonObject } from '@/libs/utils/functions';
9
6
  import { IWorkbenchConfig, IWorkbenchEntity } from '@/models/SystemEntities';
10
- import { IScheduleService } from '@/interface';
11
7
  import { getDebugWorkbenchCode } from '@/libs/utils/fatcms-request';
12
- import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
13
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
14
8
  import { HEADER_KEY_RUN_BY_ASYNC_TASK_WORKBENCH_CODE } from '@/models/AsyncTaskModel';
15
9
  import { formatHost } from '@/libs/utils/format-url';
16
- import { CacheServiceFactory } from "@/service/base/cache/CacheServiceFactory";
17
- import { CacheNameEnum } from "@/models/bizmodels";
10
+ import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore';
11
+ import { IWorkbenchCachedObj } from '@/service/base/bizmemcache/BizMemCacheTypes';
18
12
 
19
13
 
20
- interface IWorkbenchCachedObj {
21
- workbenchList: IWorkbenchEntity[];
22
- workbenchDomainMap: Record<string, IWorkbenchEntity>; // key是domain
23
- }
24
-
25
14
  @Provide()
26
- export class WorkbenchService extends BaseService implements IScheduleService {
15
+ export class WorkbenchService extends BaseService {
27
16
  @Inject()
28
17
  ctx: Context;
29
18
 
30
- @Inject()
31
- private curdProService: CurdProService;
32
-
33
- @Inject()
34
- private cacheServiceFactory: CacheServiceFactory;
35
-
36
19
  @Config('fatcmsTargetWorkbenchCode')
37
20
  private fatcmsTargetWorkbenchCode: string;
38
21
 
39
-
40
- public async clearCache() {
41
-
42
- await this.cacheServiceFactory.removeItemCache({
43
- cacheKey: CacheNameEnum.CurdMixByWorkbench,
44
- cacheName: CacheNameEnum.CurdMixByWorkbench,
45
- });
46
-
47
- await this.cacheServiceFactory.removeItemCache({
48
- cacheKey: CacheNameEnum.GetWorkbenchCachedObj,
49
- cacheName: CacheNameEnum.GetWorkbenchCachedObj,
50
- });
51
-
52
- await this.getWorkbenchCachedObj(true);
53
- }
54
-
55
- public async runBySchedule() {
56
- await this.getWorkbenchCachedObj(true);
57
- }
58
-
59
- private async getWorkbenchCachedObj(isForceRefresh?: boolean): Promise<IWorkbenchCachedObj> {
60
- return this.cacheServiceFactory.getJsonObjectCache({
61
- cacheKey: CacheNameEnum.GetWorkbenchCachedObj,
62
- cacheName: CacheNameEnum.GetWorkbenchCachedObj,
63
- refreshCache: isForceRefresh,
64
- getter: async (ctx) => {
65
- const service: WorkbenchService = await ctx.requestContext.getAsync(WorkbenchService);
66
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
67
- const reqJson = { condition: { deleted_at: 0 }, pageSize: 1000, limit: 1000 };
68
- const res = await service.curdProService.executeCrudByCfg(reqJson, {
69
- sqlTable: SystemTables.sys_workbench,
70
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
71
- sqlDatabase: SystemDbName,
72
- sqlDbType: SystemDbType,
73
- });
74
- const listData = res.getResRows() as IWorkbenchEntity[];
75
-
76
- const domainMap1 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain); // 主域名。其他两个域名。
77
- const domainMap2 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain2);
78
- const domainMap3 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain3);
79
- const domainMap = { ...domainMap1, ...domainMap2, ...domainMap3 };
80
- const cacheObj: IWorkbenchCachedObj = {
81
- workbenchList: listData,
82
- workbenchDomainMap: domainMap
83
- }
84
- return cacheObj;
85
- },
86
- });
22
+ private getWorkbenchCachedObj(): IWorkbenchCachedObj {
23
+ return bizMemCacheStore.getWorkbench();
87
24
  }
88
25
 
89
26
  /**
@@ -91,8 +28,8 @@ export class WorkbenchService extends BaseService implements IScheduleService {
91
28
  * @returns
92
29
  */
93
30
  public async getAllWorkbenchInfoList(): Promise<IWorkbenchEntity[]> {
94
- const cachedObj = await this.getWorkbenchCachedObj();
95
- return cachedObj.workbenchList;
31
+ const cachedObj = this.getWorkbenchCachedObj();
32
+ return cachedObj?.workbenchList || [];
96
33
  }
97
34
 
98
35
  /**
@@ -100,8 +37,8 @@ export class WorkbenchService extends BaseService implements IScheduleService {
100
37
  * @returns
101
38
  */
102
39
  public async getAllWorkbenchInfoMap(): Promise<Record<string, IWorkbenchEntity>> {
103
- const cachedObj = await this.getWorkbenchCachedObj();
104
- return cachedObj.workbenchDomainMap;
40
+ const cachedObj = this.getWorkbenchCachedObj();
41
+ return cachedObj?.workbenchDomainMap || {};
105
42
  }
106
43
 
107
44
  /**
@@ -2,7 +2,6 @@ import { Inject, Provide } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
4
  import { SystemTables } from '@/models/SystemTables';
5
- import { LRUCache } from 'lru-cache';
6
5
  import { BizException } from '@/models/devops';
7
6
  import { CurdMixService } from '../curd/CurdMixService';
8
7
  import { ISysAnyApiEntity } from '@/models/SystemEntities';
@@ -14,12 +13,7 @@ import { WorkbenchService } from '../WorkbenchService';
14
13
  import { validateByCfgString } from '@/libs/crud-pro/utils/ValidateUtils';
15
14
  import { API_BASE_TYPE, ApiBaseService } from '../base/ApiBaseService';
16
15
  import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
17
-
18
- const lruCache = new LRUCache<string, any>({
19
- max: 500,
20
- ttl: 1000 * 60,
21
- ttlAutopurge: true,
22
- });
16
+ import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore';
23
17
 
24
18
  @Provide()
25
19
  export class AnyApiService extends ApiBaseService {
@@ -65,21 +59,15 @@ export class AnyApiService extends ApiBaseService {
65
59
  }
66
60
 
67
61
  private async getAnyApiMethod(methodCode: string): Promise<ISysAnyApiEntity> {
68
- // 开发环境,不使用缓存
69
62
  if (this.isEnableDebug()) {
70
- return this._getAnyApiMethod(methodCode);
63
+ return this.loadAnyApiMethodFromDb(methodCode);
71
64
  }
72
65
 
73
- // 线上环境可以使用缓存
74
- let anyApi = lruCache.get(methodCode);
75
- if (!anyApi) {
76
- anyApi = await this._getAnyApiMethod(methodCode);
77
- lruCache.set(methodCode, anyApi);
78
- }
79
- return anyApi;
66
+ const sysAnyApiMethodMap = bizMemCacheStore.getSysAnyApi()?.sysAnyApiMethodMap || {};
67
+ return sysAnyApiMethodMap[methodCode] || null;
80
68
  }
81
69
 
82
- private async _getAnyApiMethod(methodCode: string): Promise<ISysAnyApiEntity> {
70
+ private async loadAnyApiMethodFromDb(methodCode: string): Promise<ISysAnyApiEntity> {
83
71
  const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
84
72
 
85
73
  const res = await this.curdMixService.executeCrudByCfg(
@@ -0,0 +1,290 @@
1
+ import * as _ from 'lodash';
2
+ import { Inject, Provide } from '@midwayjs/core';
3
+ import { IScheduleService } from '@/interface';
4
+ import { SystemTables } from '@/models/SystemTables';
5
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
6
+ import { BaseService } from "@/service/base/BaseService";
7
+ import { CurdProService } from '../../curd/CurdProService';
8
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
9
+ import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
10
+ import { IWorkbenchEntity } from '@/models/SystemEntities';
11
+ import { bizMemCacheStore } from './BizMemCacheStore';
12
+ import { BizMemCacheKey, buildSysAppPageCacheKey, ICrudMethodCacheObj, IDataDictItemCacheObj, IWorkbenchCachedObj, ISysConfgCacheObj, ISysMenuCacheObj, ISysAppCacheObj, ISysAppPageCacheObj, ISysAnyApiCacheObj, ISysProxyApiCacheObj } from './BizMemCacheTypes';
13
+ import { parseJsonObject } from '@/libs/utils/functions';
14
+ import { parseCrudMethodInfo, setMethodCache } from '@/libs/crud-pro/services/CrudProCachedCfgService';
15
+
16
+
17
+
18
+
19
+ @Provide()
20
+ export class BizMemCacheService extends BaseService implements IScheduleService {
21
+
22
+ @Inject()
23
+ private curdProService: CurdProService;
24
+
25
+ public async runBySchedule(): Promise<void> {
26
+ await this.reloadIfRedisChanged('workbenchCachedObj', () => this.loadWorkbenchCachedObj());
27
+ await this.reloadIfRedisChanged('sysConfgCacheObj', () => this.loadSysConfigObj());
28
+ await this.reloadIfRedisChanged('dataDictItemCacheObj', () => this.loadDataDictItemCacheObj());
29
+ await this.reloadIfRedisChanged('sysMenuCacheObj', () => this.loadSysMenuCacheObj());
30
+ await this.reloadIfRedisChanged('sysAppCacheObj', () => this.loadSysAppCacheObj());
31
+ await this.reloadIfRedisChanged('sysAppPageCacheObj', () => this.loadSysAppPageCacheObj());
32
+ await this.reloadIfRedisChanged('sysAnyApiCacheObj', () => this.loadSysAnyApiCacheObj());
33
+ await this.reloadIfRedisChanged('sysProxyApiCacheObj', () => this.loadSysProxyApiCacheObj());
34
+ await this.reloadIfRedisChanged('crudMethodCacheObj', () => this.loadCrudMethodCacheObj());
35
+ }
36
+
37
+ private async reloadIfRedisChanged(key: BizMemCacheKey, loader: () => Promise<void>) {
38
+ const redisTimeStr = await this.redisService.get(bizMemCacheStore.getRedisKey(key));
39
+ const redisTime = Number(redisTimeStr) || 0;
40
+ const memTime = bizMemCacheStore.getLastTime(key);
41
+ if (redisTime !== memTime) {
42
+ await loader();
43
+ bizMemCacheStore.setLastTime(key, redisTime);
44
+ }
45
+ }
46
+
47
+ private async loadSysMenuCacheObj() {
48
+
49
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
50
+
51
+ const res1 = await this.curdProService.executeCrudByCfg(
52
+ {
53
+ condition: { deleted_at: 0, status: 1 },
54
+ },
55
+ {
56
+ sqlTable: SystemTables.sys_menus,
57
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
58
+ sqlDatabase: SystemDbName,
59
+ sqlDbType: SystemDbType,
60
+ maxLimit: 10 * 10000
61
+ }
62
+ );
63
+
64
+ const rows = res1.getResRows();
65
+ const cacheObj: ISysMenuCacheObj = {
66
+ sysMenuList: rows,
67
+ sysMenuCodeMap: _.keyBy(rows, 'menu_code')
68
+ }
69
+ bizMemCacheStore.setSysMenu(cacheObj);
70
+
71
+ }
72
+
73
+
74
+ private async loadDataDictItemCacheObj() {
75
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
76
+ const res1 = await this.curdProService.executeCrudByCfg(
77
+ {
78
+ columns: ['dict_code', 'label', 'value', 'style', 'code'],
79
+ condition: { deleted_at: 0, status: 1 },
80
+ },
81
+ {
82
+ sqlTable: SystemTables.sys_data_dict_item,
83
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
84
+ sqlDatabase: SystemDbName,
85
+ sqlDbType: SystemDbType,
86
+ maxLimit: 10 * 10000
87
+ }
88
+ );
89
+
90
+ const rows = res1.getResRows();
91
+
92
+ const dictCodeMap: Record<string, any[]> = _.groupBy(rows, 'dict_code');
93
+
94
+ const cacheObj: IDataDictItemCacheObj = {
95
+ dictCodeMap: dictCodeMap
96
+ }
97
+ bizMemCacheStore.setDataDictItem(cacheObj);
98
+
99
+ }
100
+
101
+
102
+
103
+
104
+
105
+ private async loadSysConfigObj() {
106
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
107
+ const res1 = await this.curdProService.executeCrudByCfg(
108
+ {
109
+ condition: { deleted_at: 0, status: 1 },
110
+ },
111
+ {
112
+ sqlTable: SystemTables.sys_configs,
113
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
114
+ sqlDatabase: SystemDbName,
115
+ sqlDbType: SystemDbType,
116
+ }
117
+ );
118
+ const sysConfigCodeMap = {};
119
+ const rows = res1.getResRows();
120
+ if (Array.isArray(rows) && rows.length > 0) {
121
+ for (let i = 0; i < rows.length; i++) {
122
+ const row = rows[i];
123
+ const { config_code } = row;
124
+ sysConfigCodeMap[config_code] = row;
125
+ }
126
+ }
127
+
128
+ const cacheObj: ISysConfgCacheObj = {
129
+ sysConfigList: rows,
130
+ sysConfigCodeMap: sysConfigCodeMap
131
+ }
132
+ bizMemCacheStore.setSysConfig(cacheObj);
133
+
134
+ }
135
+
136
+
137
+
138
+
139
+
140
+ private async loadWorkbenchCachedObj(): Promise<any> {
141
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
142
+ const reqJson = { condition: { deleted_at: 0 }, pageSize: 1000, limit: 1000 };
143
+ const res = await this.curdProService.executeCrudByCfg(reqJson, {
144
+ sqlTable: SystemTables.sys_workbench,
145
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
146
+ sqlDatabase: SystemDbName,
147
+ sqlDbType: SystemDbType,
148
+ });
149
+ const listData = res.getResRows() as IWorkbenchEntity[];
150
+
151
+ const domainMap1 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain); // 主域名。其他两个域名。
152
+ const domainMap2 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain2);
153
+ const domainMap3 = MixinUtils.toMap(listData, (e: any) => e.workbench_domain3);
154
+ const domainMap = { ...domainMap1, ...domainMap2, ...domainMap3 };
155
+ const cacheObj: IWorkbenchCachedObj = {
156
+ workbenchList: listData,
157
+ workbenchDomainMap: domainMap
158
+ }
159
+ bizMemCacheStore.setWorkbench(cacheObj);
160
+ }
161
+
162
+ private async loadSysAppCacheObj() {
163
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
164
+ const res = await this.curdProService.executeCrudByCfg(
165
+ {
166
+ condition: { deleted_at: 0 },
167
+ },
168
+ {
169
+ sqlTable: SystemTables.sys_app,
170
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
171
+ sqlDatabase: SystemDbName,
172
+ sqlDbType: SystemDbType,
173
+ maxLimit: 10 * 10000,
174
+ }
175
+ );
176
+ const rows = res.getResRows();
177
+ const cacheObj: ISysAppCacheObj = {
178
+ sysAppList: rows,
179
+ sysAppCodeMap: _.keyBy(rows, 'app_code'),
180
+ };
181
+ bizMemCacheStore.setSysApp(cacheObj);
182
+ }
183
+
184
+ private async loadSysAppPageCacheObj() {
185
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
186
+ const res = await this.curdProService.executeCrudByCfg(
187
+ {
188
+ condition: { deleted_at: 0 },
189
+ },
190
+ {
191
+ sqlTable: SystemTables.sys_app_page,
192
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
193
+ sqlDatabase: SystemDbName,
194
+ sqlDbType: SystemDbType,
195
+ maxLimit: 10 * 10000,
196
+ }
197
+ );
198
+ const rows = res.getResRows();
199
+ const sysAppPageMap: Record<string, any> = {};
200
+ for (let i = 0; i < rows.length; i++) {
201
+ const row = rows[i];
202
+ const cacheKey = buildSysAppPageCacheKey(row.workbench_code, row.page_path);
203
+ sysAppPageMap[cacheKey] = row;
204
+ }
205
+ const cacheObj: ISysAppPageCacheObj = {
206
+ sysAppPageList: rows,
207
+ sysAppPageMap,
208
+ };
209
+ bizMemCacheStore.setSysAppPage(cacheObj);
210
+ }
211
+
212
+ private async loadSysAnyApiCacheObj() {
213
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
214
+ const res = await this.curdProService.executeCrudByCfg(
215
+ {
216
+ condition: { deleted_at: 0 },
217
+ },
218
+ {
219
+ sqlTable: SystemTables.sys_anyapi,
220
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
221
+ sqlDatabase: SystemDbName,
222
+ sqlDbType: SystemDbType,
223
+ maxLimit: 10 * 10000,
224
+ }
225
+ );
226
+ const rows = res.getResRows();
227
+ const sysAnyApiMethodMap: Record<string, any> = {};
228
+ for (let i = 0; i < rows.length; i++) {
229
+ const row = rows[i];
230
+ const obj = { ...row };
231
+ obj.parsedOthers = parseJsonObject(obj.others);
232
+ sysAnyApiMethodMap[row.method] = obj;
233
+ }
234
+ const cacheObj: ISysAnyApiCacheObj = {
235
+ sysAnyApiList: rows,
236
+ sysAnyApiMethodMap,
237
+ };
238
+ bizMemCacheStore.setSysAnyApi(cacheObj);
239
+ }
240
+
241
+ private async loadSysProxyApiCacheObj() {
242
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
243
+ const res = await this.curdProService.executeCrudByCfg(
244
+ {
245
+ condition: { deleted_at: 0 },
246
+ },
247
+ {
248
+ sqlTable: SystemTables.sys_proxyapi,
249
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
250
+ sqlDatabase: SystemDbName,
251
+ sqlDbType: SystemDbType,
252
+ maxLimit: 10 * 10000,
253
+ }
254
+ );
255
+ const rows = res.getResRows();
256
+ const cacheObj: ISysProxyApiCacheObj = {
257
+ sysProxyApiList: rows,
258
+ routeTrieMap: null,
259
+ };
260
+ bizMemCacheStore.setSysProxyApi(cacheObj);
261
+ }
262
+
263
+ private async loadCrudMethodCacheObj() {
264
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
265
+ const res = await this.curdProService.executeCrudByCfg(
266
+ {
267
+ condition: { deleted_at: 0 },
268
+ },
269
+ {
270
+ sqlTable: SystemTables.sys_crud_methods,
271
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
272
+ sqlDatabase: SystemDbName,
273
+ sqlDbType: SystemDbType,
274
+ maxLimit: 10 * 10000,
275
+ }
276
+ );
277
+ const rows = res.getResRows();
278
+ const crudMethodList = rows.map(row => parseCrudMethodInfo(row));
279
+ const cacheObj: ICrudMethodCacheObj = {
280
+ crudMethodList,
281
+ crudMethodMap: _.keyBy(crudMethodList, 'method'),
282
+ };
283
+ bizMemCacheStore.setCrudMethod(cacheObj);
284
+ setMethodCache(crudMethodList);
285
+ }
286
+
287
+
288
+
289
+
290
+ }