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,33 +1,11 @@
1
1
  import { CacheRefreshCategory } from '../../../models/CacheRefreshCategory';
2
2
  import * as koa from '@midwayjs/koa';
3
3
  declare type CacheRefresher = (ctx: koa.IMidwayKoaContext) => Promise<any>;
4
- /**
5
- * 统一缓存刷新中心
6
- *
7
- * 负责 非 HTTP 中间件场景 的缓存刷新,包括:
8
- * 1. 定时刷新:CacheRefreshHubScheduleService 实现 IScheduleService,10分钟自动调度
9
- * 2. Redis Pub/Sub 集群广播:CacheRefreshRedisSubscriber 收到广播后调用
10
- * 3. API 主动刷新:helpers.controller /refreshCache 接口调用
11
- *
12
- * 注意:manage 增删改触发的缓存刷新由 refreshCache() 中间件直接调用 CacheServiceFactory 完成,
13
- * 不经过 CacheRefreshHub。
14
- */
15
4
  declare class CacheRefreshHubInner {
16
5
  private readonly refreshers;
17
- /**
18
- * 注册缓存刷新器
19
- */
20
6
  register(category: CacheRefreshCategory, refresher: CacheRefresher): void;
21
- /**
22
- * 刷新指定类型的缓存(主动重加载)
23
- * @param category 缓存类型,'*' 刷新全部
24
- */
25
7
  refresh(category: CacheRefreshCategory | '*', ctx: koa.IMidwayKoaContext): Promise<void>;
26
- /**
27
- * 定时任务入口,刷新全部缓存
28
- */
29
8
  runBySchedule(ctx: koa.IMidwayKoaContext): Promise<void>;
30
9
  }
31
- /** 全局唯一实例 */
32
10
  export declare const CacheRefreshHub: CacheRefreshHubInner;
33
11
  export {};
@@ -3,31 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CacheRefreshHub = void 0;
4
4
  const CacheRefreshCategory_1 = require("../../../models/CacheRefreshCategory");
5
5
  const CrudMonitor_1 = require("../../../libs/crud-pro/utils/CrudMonitor");
6
- /**
7
- * 统一缓存刷新中心
8
- *
9
- * 负责 非 HTTP 中间件场景 的缓存刷新,包括:
10
- * 1. 定时刷新:CacheRefreshHubScheduleService 实现 IScheduleService,10分钟自动调度
11
- * 2. Redis Pub/Sub 集群广播:CacheRefreshRedisSubscriber 收到广播后调用
12
- * 3. API 主动刷新:helpers.controller /refreshCache 接口调用
13
- *
14
- * 注意:manage 增删改触发的缓存刷新由 refreshCache() 中间件直接调用 CacheServiceFactory 完成,
15
- * 不经过 CacheRefreshHub。
16
- */
17
6
  class CacheRefreshHubInner {
18
7
  constructor() {
19
8
  this.refreshers = new Map();
20
9
  }
21
- /**
22
- * 注册缓存刷新器
23
- */
24
10
  register(category, refresher) {
25
11
  this.refreshers.set(category, refresher);
26
12
  }
27
- /**
28
- * 刷新指定类型的缓存(主动重加载)
29
- * @param category 缓存类型,'*' 刷新全部
30
- */
31
13
  async refresh(category, ctx) {
32
14
  const categories = category === '*' ? CacheRefreshCategory_1.ALL_CACHE_REFRESH_CATEGORIES : [category];
33
15
  for (const cat of categories) {
@@ -43,12 +25,8 @@ class CacheRefreshHubInner {
43
25
  }
44
26
  }
45
27
  }
46
- /**
47
- * 定时任务入口,刷新全部缓存
48
- */
49
28
  async runBySchedule(ctx) {
50
29
  await this.refresh('*', ctx);
51
30
  }
52
31
  }
53
- /** 全局唯一实例 */
54
32
  exports.CacheRefreshHub = new CacheRefreshHubInner();
@@ -1,11 +1,5 @@
1
1
  import * as koa from '@midwayjs/koa';
2
2
  import { IScheduleService } from '../../../interface';
3
- /**
4
- * CacheRefreshHub 的定时调度适配器
5
- *
6
- * 实现 IScheduleService 接口,使 CacheRefreshHub 能被 runSchedule.ts 调度。
7
- * 注册到 scheduleNames.ts 中的 cacheRefreshHub 定时任务。
8
- */
9
3
  export declare class CacheRefreshHubScheduleService implements IScheduleService {
10
4
  runBySchedule(ctx: koa.IMidwayKoaContext): Promise<void>;
11
5
  }
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.CacheRefreshHubScheduleService = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
11
  const CacheRefreshHub_1 = require("../../../service/base/cache-refresh/CacheRefreshHub");
12
- /**
13
- * CacheRefreshHub 的定时调度适配器
14
- *
15
- * 实现 IScheduleService 接口,使 CacheRefreshHub 能被 runSchedule.ts 调度。
16
- * 注册到 scheduleNames.ts 中的 cacheRefreshHub 定时任务。
17
- */
18
12
  let CacheRefreshHubScheduleService = class CacheRefreshHubScheduleService {
19
13
  async runBySchedule(ctx) {
20
14
  await CacheRefreshHub_1.CacheRefreshHub.refresh('*', ctx);
@@ -79,7 +79,7 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
79
79
  sqlTable: getExecuteTableNameBySettingKey(appInfo, stdAction, sqlSimpleName),
80
80
  sqlSimpleName,
81
81
  updateCfg: {},
82
- enableSoftDelete: deleteStrategy === 'soft',
82
+ enableSoftDelete: deleteStrategy,
83
83
  enableStandardUpdateCfg: Array.isArray(enableStandardUpdateCfg) && enableStandardUpdateCfg.length > 0 ? enableStandardUpdateCfg : ['by', 'at'],
84
84
  enableStandardUpdateCfgCondition: Array.isArray(enableStandardUpdateCfgCondition) && enableStandardUpdateCfgCondition.length > 0 ? enableStandardUpdateCfgCondition : false, // 默认为false
85
85
  };
@@ -2,10 +2,6 @@ import { Context } from '@midwayjs/koa';
2
2
  import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
3
3
  export declare class CurdMixByDictService implements IExecuteContextHandler {
4
4
  ctx: Context;
5
- private curdProService;
6
- private cacheServiceFactory;
7
- private getFromCache;
8
- private setToCache;
9
5
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
10
6
  private getDictItemRows;
11
7
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
@@ -12,25 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CurdMixByDictService = void 0;
13
13
  const _ = require("lodash");
14
14
  const core_1 = require("@midwayjs/core");
15
- const CurdProService_1 = require("./CurdProService");
16
15
  const CurdMixUtils_1 = require("./CurdMixUtils");
17
- const SystemTables_1 = require("../../models/SystemTables");
18
- const keys_1 = require("../../libs/crud-pro/models/keys");
19
16
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
- const global_config_1 = require("../../libs/global-config/global-config");
21
- const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
22
- const bizmodels_1 = require("../../models/bizmodels");
17
+ const BizMemCacheStore_1 = require("../../service/base/bizmemcache/BizMemCacheStore");
23
18
  const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
24
19
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.dict);
25
20
  let CurdMixByDictService = class CurdMixByDictService {
26
- async getFromCache(code) {
27
- const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByDict);
28
- return cacheService.getJsonObject(code);
29
- }
30
- async setToCache(code, value) {
31
- const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.CurdMixByDict);
32
- return cacheService.setJsonObject(code, value);
33
- }
34
21
  async handleExecuteContextPrepare(executeContext) {
35
22
  const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
36
23
  if (!codes || codes.length === 0) {
@@ -40,42 +27,17 @@ let CurdMixByDictService = class CurdMixByDictService {
40
27
  executeContext[TMP_CTX_KEY] = new MultiKeyMap_1.MultiKeyMap(rows, 'dict_code', 'value');
41
28
  }
42
29
  async getDictItemRows(codes) {
43
- const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
44
- const noCacheCodes = [];
45
- // 从缓存里面取
46
- let cachedRows = [];
47
- for (let i = 0; i < codes.length; i++) {
48
- const code = codes[i];
49
- const rows1 = await this.getFromCache(code);
50
- // const rows1 = [];
51
- if (rows1 && rows1.length > 0) {
52
- cachedRows = cachedRows.concat(rows1);
53
- }
54
- else {
55
- noCacheCodes.push(code);
56
- }
57
- }
58
- // 从数据库里面取
30
+ var _a;
31
+ const dictCodeMap = ((_a = BizMemCacheStore_1.bizMemCacheStore.getDataDictItem()) === null || _a === void 0 ? void 0 : _a.dictCodeMap) || {};
59
32
  let selectedRows = [];
60
- if (noCacheCodes.length > 0) {
61
- const res1 = await this.curdProService.executeCrudByCfg({
62
- columns: ['dict_code', 'label', 'value', 'style', 'code'],
63
- condition: { dict_code: { $in: noCacheCodes }, deleted_at: 0, status: 1 },
64
- }, {
65
- sqlTable: SystemTables_1.SystemTables.sys_data_dict_item,
66
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
67
- sqlDatabase: SystemDbName,
68
- sqlDbType: SystemDbType,
69
- });
70
- selectedRows = res1.getResRows();
71
- //放到缓存里
72
- for (let i = 0; i < noCacheCodes.length; i++) {
73
- const noCacheCode = noCacheCodes[i];
74
- const rows1 = selectedRows.filter(e => e.dict_code === noCacheCode);
75
- await this.setToCache(noCacheCode, rows1);
33
+ for (let index = 0; index < codes.length; index++) {
34
+ const dict_code = codes[index];
35
+ const itemRows = dictCodeMap[dict_code];
36
+ if (Array.isArray(itemRows)) {
37
+ selectedRows = selectedRows.concat(itemRows);
76
38
  }
77
39
  }
78
- return cachedRows.concat(selectedRows);
40
+ return selectedRows;
79
41
  }
80
42
  async handleExecuteContext(executeContext) {
81
43
  const multiKeyMap = executeContext[TMP_CTX_KEY];
@@ -101,14 +63,6 @@ __decorate([
101
63
  (0, core_1.Inject)(),
102
64
  __metadata("design:type", Object)
103
65
  ], CurdMixByDictService.prototype, "ctx", void 0);
104
- __decorate([
105
- (0, core_1.Inject)(),
106
- __metadata("design:type", CurdProService_1.CurdProService)
107
- ], CurdMixByDictService.prototype, "curdProService", void 0);
108
- __decorate([
109
- (0, core_1.Inject)(),
110
- __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
111
- ], CurdMixByDictService.prototype, "cacheServiceFactory", void 0);
112
66
  CurdMixByDictService = __decorate([
113
67
  (0, core_1.Provide)()
114
68
  ], CurdMixByDictService);
@@ -1,12 +1,7 @@
1
1
  import { Context } from '@midwayjs/koa';
2
- import { CurdProService } from './CurdProService';
3
2
  import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
4
3
  export declare class CurdMixBySysConfigService implements IExecuteContextHandler {
5
4
  ctx: Context;
6
- protected curdProService: CurdProService;
7
- private cacheServiceFactory;
8
- private getFromCache;
9
- private setToCache;
10
5
  private queryConfigRowsUseCache;
11
6
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
12
7
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
@@ -11,59 +11,22 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CurdMixBySysConfigService = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
- const CurdProService_1 = require("./CurdProService");
15
14
  const CurdMixUtils_1 = require("./CurdMixUtils");
16
15
  const _ = require("lodash");
17
- const SystemTables_1 = require("../../models/SystemTables");
18
- const keys_1 = require("../../libs/crud-pro/models/keys");
19
16
  const MultiKeyMap_1 = require("../../libs/crud-pro/utils/MultiKeyMap");
20
17
  const parseConfig_1 = require("../../libs/utils/parseConfig");
21
- const global_config_1 = require("../../libs/global-config/global-config");
22
- const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
23
- const bizmodels_1 = require("../../models/bizmodels");
18
+ const BizMemCacheStore_1 = require("../../service/base/bizmemcache/BizMemCacheStore");
24
19
  const dictMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.sysCfgEnum);
25
20
  const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
26
21
  let CurdMixBySysConfigService = class CurdMixBySysConfigService {
27
- async getFromCache(code) {
28
- const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.GetSysConfigOne);
29
- return cacheService.getJsonObject(code);
30
- }
31
- async setToCache(code, value) {
32
- const cacheService = this.cacheServiceFactory.getCacheServiceByName(bizmodels_1.CacheNameEnum.GetSysConfigOne);
33
- return cacheService.setJsonObject(code, value);
34
- }
35
- async queryConfigRowsUseCache(codes) {
36
- const resultRowMap = {};
37
- for (let i = 0; i < codes.length; i++) {
38
- const code = codes[i];
39
- const row = await this.getFromCache(code);
40
- if (row) {
41
- resultRowMap[code] = row;
42
- }
43
- }
44
- const notCachedCodes = codes.filter((code) => !resultRowMap[code]);
45
- if (notCachedCodes.length === 0) {
46
- return Object.values(resultRowMap);
47
- }
48
- const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
49
- const res1 = await this.curdProService.executeCrudByCfg({
50
- condition: { config_code: { $in: notCachedCodes }, deleted_at: 0, status: 1 },
51
- }, {
52
- sqlTable: SystemTables_1.SystemTables.sys_configs,
53
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
54
- sqlDatabase: SystemDbName,
55
- sqlDbType: SystemDbType,
22
+ queryConfigRowsUseCache(codes) {
23
+ var _a;
24
+ const codeSet = new Set(codes);
25
+ const sysConfigList = ((_a = BizMemCacheStore_1.bizMemCacheStore.getSysConfig()) === null || _a === void 0 ? void 0 : _a.sysConfigList) || [];
26
+ return sysConfigList.filter((row) => {
27
+ const { config_code } = row;
28
+ return codeSet.has(config_code);
56
29
  });
57
- const rows = res1.getResRows();
58
- if (Array.isArray(rows) && rows.length > 0) {
59
- for (let i = 0; i < rows.length; i++) {
60
- const row = rows[i];
61
- const { config_code } = row;
62
- await this.setToCache(config_code, row);
63
- resultRowMap[config_code] = row;
64
- }
65
- }
66
- return Object.values(resultRowMap);
67
30
  }
68
31
  async handleExecuteContextPrepare(executeContext) {
69
32
  const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
@@ -71,7 +34,7 @@ let CurdMixBySysConfigService = class CurdMixBySysConfigService {
71
34
  return;
72
35
  }
73
36
  const multiKeyMap = new MultiKeyMap_1.MultiKeyMap();
74
- const rows = await this.queryConfigRowsUseCache(codes);
37
+ const rows = this.queryConfigRowsUseCache(codes);
75
38
  for (let i = 0; i < rows.length; i++) {
76
39
  const row = rows[i];
77
40
  const { config_code } = row;
@@ -104,14 +67,6 @@ __decorate([
104
67
  (0, core_1.Inject)(),
105
68
  __metadata("design:type", Object)
106
69
  ], CurdMixBySysConfigService.prototype, "ctx", void 0);
107
- __decorate([
108
- (0, core_1.Inject)(),
109
- __metadata("design:type", CurdProService_1.CurdProService)
110
- ], CurdMixBySysConfigService.prototype, "curdProService", void 0);
111
- __decorate([
112
- (0, core_1.Inject)(),
113
- __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
114
- ], CurdMixBySysConfigService.prototype, "cacheServiceFactory", void 0);
115
70
  CurdMixBySysConfigService = __decorate([
116
71
  (0, core_1.Provide)()
117
72
  ], CurdMixBySysConfigService);
@@ -4,7 +4,6 @@ import { HandleExecuteContextType, IExecuteContextHandler } from '../../libs/cru
4
4
  export declare class CurdMixByWorkbenchService implements IExecuteContextHandler {
5
5
  protected ctx: Context;
6
6
  protected curdProService: CurdProService;
7
- private cacheServiceFactory;
8
7
  private loadWorkbenchListMap;
9
8
  handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void>;
10
9
  handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void>;
@@ -8,44 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
- var CurdMixByWorkbenchService_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CurdMixByWorkbenchService = void 0;
14
13
  const core_1 = require("@midwayjs/core");
15
14
  const _ = require("lodash");
16
15
  const CurdProService_1 = require("./CurdProService");
17
16
  const CurdMixUtils_1 = require("./CurdMixUtils");
18
- const SystemTables_1 = require("../../models/SystemTables");
19
- const keys_1 = require("../../libs/crud-pro/models/keys");
20
17
  const MixinUtils_1 = require("../../libs/crud-pro/utils/MixinUtils");
21
- const global_config_1 = require("../../libs/global-config/global-config");
22
- const CacheServiceFactory_1 = require("../base/cache/CacheServiceFactory");
23
- const bizmodels_1 = require("../../models/bizmodels");
18
+ const BizMemCacheStore_1 = require("../../service/base/bizmemcache/BizMemCacheStore");
24
19
  const workbenchMixUtils = new CurdMixUtils_1.CrudMixUtils(CurdMixUtils_1.RelatedType.workbenchBasic);
25
20
  const TMP_CTX_KEY = _.uniqueId('CurdMixByWorkbenchService');
26
- let CurdMixByWorkbenchService = CurdMixByWorkbenchService_1 = class CurdMixByWorkbenchService {
21
+ let CurdMixByWorkbenchService = class CurdMixByWorkbenchService {
27
22
  async loadWorkbenchListMap() {
28
- const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
29
- return await this.cacheServiceFactory.getJsonObjectCache({
30
- cacheKey: bizmodels_1.CacheNameEnum.CurdMixByWorkbench,
31
- cacheName: bizmodels_1.CacheNameEnum.CurdMixByWorkbench,
32
- refreshCache: false,
33
- getter: async (ctx) => {
34
- const service = await ctx.requestContext.getAsync(CurdMixByWorkbenchService_1);
35
- const reqJson = {
36
- columns: 'workbench_code,workbench_name,workbench_domain',
37
- condition: { deleted_at: 0, status: 1 },
38
- };
39
- const res = await service.curdProService.executeCrudByCfg(reqJson, {
40
- sqlTable: SystemTables_1.SystemTables.sys_workbench,
41
- sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY,
42
- sqlDatabase: SystemDbName,
43
- sqlDbType: SystemDbType,
44
- });
45
- const workbenchList = res.getResRows();
46
- return MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
47
- },
48
- });
23
+ var _a;
24
+ const workbenchList = ((_a = BizMemCacheStore_1.bizMemCacheStore.getWorkbench()) === null || _a === void 0 ? void 0 : _a.workbenchList) || [];
25
+ return MixinUtils_1.MixinUtils.toNewMap(workbenchList, (obj) => obj.workbench_code);
49
26
  }
50
27
  async handleExecuteContextPrepare(executeContext) {
51
28
  const relations = workbenchMixUtils.pickColumnRelations(executeContext);
@@ -55,12 +32,12 @@ let CurdMixByWorkbenchService = CurdMixByWorkbenchService_1 = class CurdMixByWor
55
32
  executeContext[TMP_CTX_KEY] = await this.loadWorkbenchListMap();
56
33
  }
57
34
  async handleExecuteContext(executeContext) {
58
- const userInfoMap = executeContext[TMP_CTX_KEY];
59
- if (!userInfoMap || userInfoMap.size === 0) {
35
+ const workbenchInfoMap = executeContext[TMP_CTX_KEY];
36
+ if (!workbenchInfoMap || workbenchInfoMap.size === 0) {
60
37
  return;
61
38
  }
62
39
  workbenchMixUtils.forEachRowAndColumnsRelation(executeContext, (row, columnRelation) => {
63
- workbenchMixUtils.copyColumnRelationToRowNoRelatedCode(row, userInfoMap, columnRelation);
40
+ workbenchMixUtils.copyColumnRelationToRowNoRelatedCode(row, workbenchInfoMap, columnRelation);
64
41
  });
65
42
  }
66
43
  };
@@ -72,11 +49,7 @@ __decorate([
72
49
  (0, core_1.Inject)(),
73
50
  __metadata("design:type", CurdProService_1.CurdProService)
74
51
  ], CurdMixByWorkbenchService.prototype, "curdProService", void 0);
75
- __decorate([
76
- (0, core_1.Inject)(),
77
- __metadata("design:type", CacheServiceFactory_1.CacheServiceFactory)
78
- ], CurdMixByWorkbenchService.prototype, "cacheServiceFactory", void 0);
79
- CurdMixByWorkbenchService = CurdMixByWorkbenchService_1 = __decorate([
52
+ CurdMixByWorkbenchService = __decorate([
80
53
  (0, core_1.Provide)()
81
54
  ], CurdMixByWorkbenchService);
82
55
  exports.CurdMixByWorkbenchService = CurdMixByWorkbenchService;
@@ -191,6 +191,5 @@ export declare class CurdProService extends BaseService {
191
191
  * );
192
192
  */
193
193
  getAllTableInfos(query: ITableNamesQuery, options?: ITableNamesOptions): Promise<ITableListResult>;
194
- loadMethodCache(ctx?: any): Promise<void>;
195
194
  loadTableMetaCache(ctx?: any): Promise<void>;
196
195
  }
@@ -25,7 +25,6 @@ const crud_sharding_1 = require("../../libs/crud-sharding");
25
25
  const fixCfgModel_1 = require("./fixCfgModel");
26
26
  const global_config_1 = require("../../libs/global-config/global-config");
27
27
  const fixSoftDelete_1 = require("../../libs/crud-pro-quick/fixSoftDelete");
28
- const CrudProCachedCfgService_1 = require("../../libs/crud-pro/services/CrudProCachedCfgService");
29
28
  function toVisitor(ctx) {
30
29
  const workbenchInfo = ctx.workbenchInfo;
31
30
  const userSession = ctx.userSession;
@@ -360,9 +359,6 @@ let CurdProService = class CurdProService extends BaseService_1.BaseService {
360
359
  const curdPro = this.getCrudPro();
361
360
  return curdPro.getAllTableInfos(query, options);
362
361
  }
363
- async loadMethodCache(ctx) {
364
- (0, CrudProCachedCfgService_1.clearMethodCache)();
365
- }
366
362
  async loadTableMetaCache(ctx) {
367
363
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
368
364
  await this.getAllTableInfos({
@@ -65,7 +65,9 @@ function fixCfgModel(cfgModel) {
65
65
  const suffix = cfgArray[i];
66
66
  if (suffix) {
67
67
  const key = `${prefix}_${suffix}`;
68
- obj[key] = mapping[key];
68
+ if (mapping[key]) {
69
+ obj[key] = mapping[key];
70
+ }
69
71
  }
70
72
  }
71
73
  }
@@ -85,6 +87,24 @@ function fixCfgModel(cfgModel) {
85
87
  if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT) {
86
88
  const updateCfgObj1 = buildUpdateCfgBy(dataCfgArray, 'data.created');
87
89
  _.merge(cfgModel.updateCfg, updateCfgObj1);
90
+ // 启用: 雪花ID
91
+ if (dataCfgArray.includes('idBySnowflakeId')) {
92
+ _.merge(cfgModel.updateCfg, {
93
+ 'data.id': { functionName: 'generateSnowflakeId' },
94
+ });
95
+ }
96
+ // 启用: 扩展的雪花ID: -128bit,base58(建议数据库varchar(24))
97
+ if (dataCfgArray.includes('idBySnowflakeIdExt')) {
98
+ _.merge(cfgModel.updateCfg, {
99
+ 'data.id': { functionName: 'generateSnowflakeIdExt' },
100
+ });
101
+ }
102
+ // 启用: UUID
103
+ if (dataCfgArray.includes('idByUUID')) {
104
+ _.merge(cfgModel.updateCfg, {
105
+ 'data.id': { functionName: 'uuid' },
106
+ });
107
+ }
88
108
  }
89
109
  // 更新语句
90
110
  if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
@@ -1,21 +1,16 @@
1
- import { Context } from '@midwayjs/koa';
2
1
  import { BaseService } from '../base/BaseService';
3
2
  import { RouteTrie } from './RouteTrie';
4
3
  /**
5
4
  * 接口代理。 数据加载
6
5
  */
7
6
  export declare class ProxyApiLoadService extends BaseService {
8
- protected ctx: Context;
9
- private curdProService;
10
7
  private workbenchService;
11
8
  /**
12
- * 创建路由树。刷新路由缓存
13
- * 先构建全新的 RouteTrie,完成后原子替换,避免重建期间路由不可用
14
- * @param workbench_code
9
+ * 获取站点路由树;routeTrieMap 为空或缺失时懒重建
15
10
  */
16
- buildRouteTrie(workbench_code: string): Promise<RouteTrie>;
11
+ getRouteTrie(workbench_code: string): RouteTrie;
12
+ private buildRouteTrie;
17
13
  private buildUpstreamMap;
18
14
  private loadProxyApiEntity;
19
15
  private addUpstreamInfo;
20
- refreshRouteTrie(): Promise<any>;
21
16
  }