midway-fatcms 0.0.16 → 0.0.17
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.
- package/dist/config/config.default.js +5 -3
- package/dist/configuration.d.ts +0 -3
- package/dist/configuration.js +0 -19
- package/dist/controller/gateway/ProxyApiGatewayController.d.ts +0 -2
- package/dist/controller/gateway/ProxyApiGatewayController.js +0 -18
- package/dist/controller/helpers.controller.d.ts +4 -5
- package/dist/controller/helpers.controller.js +56 -14
- package/dist/controller/manage/AccountRoleManageApi.js +3 -5
- package/dist/controller/manage/AnyApiMangeApi.js +4 -3
- package/dist/controller/manage/AppMangeApi.js +3 -4
- package/dist/controller/manage/AppPageMangeApi.js +4 -3
- package/dist/controller/manage/CrudMethodsMangeApi.js +3 -4
- package/dist/controller/manage/DataDictManageApi.js +6 -7
- package/dist/controller/manage/DeployManageApi.js +4 -5
- package/dist/controller/manage/FlowConfigManageApi.js +3 -5
- package/dist/controller/manage/MenuManageApi.js +3 -4
- package/dist/controller/manage/ProxyApiMangeApi.js +3 -4
- package/dist/controller/manage/SysConfigMangeApi.js +3 -3
- package/dist/controller/manage/SystemInfoManageApi.js +3 -1
- package/dist/controller/manage/WorkbenchMangeApi.js +3 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +27 -4
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +5 -8
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +25 -42
- package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +0 -9
- package/dist/libs/crud-pro/utils/CrudMonitor.js +0 -21
- package/dist/libs/crud-pro/utils/pool/SqlServerUtils.js +26 -0
- package/dist/middleware/cacherefresh.middleware.d.ts +3 -46
- package/dist/middleware/cacherefresh.middleware.js +9 -67
- package/dist/models/CacheRefreshCategory.d.ts +1 -18
- package/dist/models/CacheRefreshCategory.js +0 -17
- package/dist/models/SystemEntities.d.ts +2 -0
- package/dist/models/bizmodels.d.ts +0 -8
- package/dist/models/bizmodels.js +0 -8
- package/dist/schedule/scheduleNames.d.ts +2 -0
- package/dist/schedule/scheduleNames.js +3 -1
- package/dist/service/SysAppService.d.ts +2 -5
- package/dist/service/SysAppService.js +15 -69
- package/dist/service/SysConfigService.d.ts +1 -6
- package/dist/service/SysConfigService.js +7 -46
- package/dist/service/SysDictDataService.d.ts +2 -5
- package/dist/service/SysDictDataService.js +13 -59
- package/dist/service/SysMenuService.d.ts +1 -4
- package/dist/service/SysMenuService.js +6 -42
- package/dist/service/WorkbenchService.d.ts +1 -5
- package/dist/service/WorkbenchService.js +10 -61
- package/dist/service/anyapi/AnyApiService.d.ts +1 -1
- package/dist/service/anyapi/AnyApiService.js +6 -16
- package/dist/service/base/bizmemcache/BizMemCacheService.d.ts +16 -0
- package/dist/service/base/bizmemcache/BizMemCacheService.js +239 -0
- package/dist/service/base/bizmemcache/BizMemCacheStore.d.ts +34 -0
- package/dist/service/base/bizmemcache/BizMemCacheStore.js +118 -0
- package/dist/service/base/bizmemcache/BizMemCacheTypes.d.ts +60 -0
- package/dist/service/base/bizmemcache/BizMemCacheTypes.js +18 -0
- package/dist/service/base/cache-refresh/CacheRefreshHub.d.ts +0 -22
- package/dist/service/base/cache-refresh/CacheRefreshHub.js +0 -22
- package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.d.ts +0 -6
- package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.js +0 -6
- package/dist/service/curd/CurdMixByDictService.d.ts +0 -4
- package/dist/service/curd/CurdMixByDictService.js +9 -55
- package/dist/service/curd/CurdMixBySysConfigService.d.ts +0 -5
- package/dist/service/curd/CurdMixBySysConfigService.js +9 -54
- package/dist/service/curd/CurdMixByWorkbenchService.d.ts +0 -1
- package/dist/service/curd/CurdMixByWorkbenchService.js +9 -36
- package/dist/service/curd/CurdProService.d.ts +0 -1
- package/dist/service/curd/CurdProService.js +0 -4
- package/dist/service/proxyapi/ProxyApiLoadService.d.ts +3 -8
- package/dist/service/proxyapi/ProxyApiLoadService.js +40 -68
- package/dist/service/proxyapi/ProxyApiService.d.ts +2 -0
- package/dist/service/proxyapi/ProxyApiService.js +32 -9
- package/dist/service/proxyapi/RouteTrie.d.ts +1 -7
- package/dist/service/proxyapi/RouteTrie.js +1 -17
- package/package.json +1 -1
- package/src/config/config.default.ts +4 -2
- package/src/configuration.ts +0 -23
- package/src/controller/gateway/ProxyApiGatewayController.ts +1 -9
- package/src/controller/helpers.controller.ts +66 -15
- package/src/controller/manage/AccountRoleManageApi.ts +3 -5
- package/src/controller/manage/AnyApiMangeApi.ts +4 -3
- package/src/controller/manage/AppMangeApi.ts +4 -5
- package/src/controller/manage/AppPageMangeApi.ts +4 -3
- package/src/controller/manage/CrudMethodsMangeApi.ts +4 -5
- package/src/controller/manage/DataDictManageApi.ts +7 -8
- package/src/controller/manage/DeployManageApi.ts +2 -3
- package/src/controller/manage/FlowConfigManageApi.ts +3 -5
- package/src/controller/manage/MenuManageApi.ts +4 -5
- package/src/controller/manage/ProxyApiMangeApi.ts +4 -5
- package/src/controller/manage/SysConfigMangeApi.ts +5 -5
- package/src/controller/manage/SystemInfoManageApi.ts +3 -1
- package/src/controller/manage/WorkbenchMangeApi.ts +4 -5
- package/src/index.ts +3 -0
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +26 -4
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +25 -43
- package/src/libs/crud-pro/utils/CrudMonitor.ts +0 -23
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +31 -0
- package/src/middleware/cacherefresh.middleware.ts +10 -71
- package/src/models/CacheRefreshCategory.ts +0 -17
- package/src/models/SystemEntities.ts +2 -0
- package/src/models/bizmodels.ts +0 -8
- package/src/schedule/scheduleNames.ts +5 -3
- package/src/service/SysAppService.ts +13 -66
- package/src/service/SysConfigService.ts +6 -39
- package/src/service/SysDictDataService.ts +11 -56
- package/src/service/SysMenuService.ts +4 -37
- package/src/service/WorkbenchService.ts +10 -68
- package/src/service/anyapi/AnyApiService.ts +5 -17
- package/src/service/base/bizmemcache/BizMemCacheService.ts +288 -0
- package/src/service/base/bizmemcache/BizMemCacheStore.ts +158 -0
- package/src/service/base/bizmemcache/BizMemCacheTypes.ts +76 -0
- package/src/service/base/cache-refresh/CacheRefreshHub.ts +0 -22
- package/src/service/base/cache-refresh/CacheRefreshHubScheduleService.ts +0 -6
- package/src/service/curd/CurdMixByDictService.ts +10 -61
- package/src/service/curd/CurdMixBySysConfigService.ts +9 -62
- package/src/service/curd/CurdMixByWorkbenchService.ts +7 -32
- package/src/service/curd/CurdProService.ts +0 -6
- package/src/service/proxyapi/ProxyApiLoadService.ts +39 -77
- package/src/service/proxyapi/ProxyApiService.ts +45 -9
- package/src/service/proxyapi/RouteTrie.ts +1 -18
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
import { RedisService } from '@midwayjs/redis';
|
|
3
|
+
import {
|
|
4
|
+
BizMemCacheKey,
|
|
5
|
+
BIZ_MEM_CACHE_REDIS_KEYS,
|
|
6
|
+
IBizMemCacheData,
|
|
7
|
+
ICrudMethodCacheObj,
|
|
8
|
+
IDataDictItemCacheObj,
|
|
9
|
+
ISysAnyApiCacheObj,
|
|
10
|
+
ISysAppCacheObj,
|
|
11
|
+
ISysAppPageCacheObj,
|
|
12
|
+
ISysConfgCacheObj,
|
|
13
|
+
ISysMenuCacheObj,
|
|
14
|
+
ISysProxyApiCacheObj,
|
|
15
|
+
IWorkbenchCachedObj,
|
|
16
|
+
} from './BizMemCacheTypes';
|
|
17
|
+
|
|
18
|
+
function createEmptyData(): IBizMemCacheData {
|
|
19
|
+
return {
|
|
20
|
+
workbenchCachedObj: null,
|
|
21
|
+
sysConfgCacheObj: null,
|
|
22
|
+
sysMenuCacheObj: null,
|
|
23
|
+
dataDictItemCacheObj: null,
|
|
24
|
+
sysAppCacheObj: null,
|
|
25
|
+
sysAppPageCacheObj: null,
|
|
26
|
+
sysAnyApiCacheObj: null,
|
|
27
|
+
sysProxyApiCacheObj: null,
|
|
28
|
+
crudMethodCacheObj: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createEmptyLastTime(): Record<BizMemCacheKey, number> {
|
|
33
|
+
return {
|
|
34
|
+
workbenchCachedObj: 0,
|
|
35
|
+
sysConfgCacheObj: 0,
|
|
36
|
+
sysMenuCacheObj: 0,
|
|
37
|
+
dataDictItemCacheObj: 0,
|
|
38
|
+
sysAppCacheObj: 0,
|
|
39
|
+
sysAppPageCacheObj: 0,
|
|
40
|
+
sysAnyApiCacheObj: 0,
|
|
41
|
+
sysProxyApiCacheObj: 0,
|
|
42
|
+
crudMethodCacheObj: 0,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class BizMemCacheStoreInner {
|
|
47
|
+
private data: IBizMemCacheData = createEmptyData();
|
|
48
|
+
private lastTime: Record<BizMemCacheKey, number> = createEmptyLastTime();
|
|
49
|
+
|
|
50
|
+
getWorkbench(): IWorkbenchCachedObj | null {
|
|
51
|
+
return this.data.workbenchCachedObj;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
setWorkbench(obj: IWorkbenchCachedObj): void {
|
|
55
|
+
this.data.workbenchCachedObj = obj;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getSysConfig(): ISysConfgCacheObj | null {
|
|
59
|
+
return this.data.sysConfgCacheObj;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setSysConfig(obj: ISysConfgCacheObj): void {
|
|
63
|
+
this.data.sysConfgCacheObj = obj;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getSysMenu(): ISysMenuCacheObj | null {
|
|
67
|
+
return this.data.sysMenuCacheObj;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setSysMenu(obj: ISysMenuCacheObj): void {
|
|
71
|
+
this.data.sysMenuCacheObj = obj;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getDataDictItem(): IDataDictItemCacheObj | null {
|
|
75
|
+
return this.data.dataDictItemCacheObj;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setDataDictItem(obj: IDataDictItemCacheObj): void {
|
|
79
|
+
this.data.dataDictItemCacheObj = obj;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getSysApp(): ISysAppCacheObj | null {
|
|
83
|
+
return this.data.sysAppCacheObj;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setSysApp(obj: ISysAppCacheObj): void {
|
|
87
|
+
this.data.sysAppCacheObj = obj;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getSysAppPage(): ISysAppPageCacheObj | null {
|
|
91
|
+
return this.data.sysAppPageCacheObj;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setSysAppPage(obj: ISysAppPageCacheObj): void {
|
|
95
|
+
this.data.sysAppPageCacheObj = obj;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getSysAnyApi(): ISysAnyApiCacheObj | null {
|
|
99
|
+
return this.data.sysAnyApiCacheObj;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setSysAnyApi(obj: ISysAnyApiCacheObj): void {
|
|
103
|
+
this.data.sysAnyApiCacheObj = obj;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getSysProxyApi(): ISysProxyApiCacheObj | null {
|
|
107
|
+
return this.data.sysProxyApiCacheObj;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setSysProxyApi(obj: ISysProxyApiCacheObj): void {
|
|
111
|
+
this.data.sysProxyApiCacheObj = obj;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getCrudMethod(): ICrudMethodCacheObj | null {
|
|
115
|
+
return this.data.crudMethodCacheObj;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setCrudMethod(obj: ICrudMethodCacheObj): void {
|
|
119
|
+
this.data.crudMethodCacheObj = obj;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getRedisKey(key: BizMemCacheKey): string {
|
|
123
|
+
return BIZ_MEM_CACHE_REDIS_KEYS[key];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
getAllKeys(): BizMemCacheKey[] {
|
|
127
|
+
return Object.keys(BIZ_MEM_CACHE_REDIS_KEYS) as BizMemCacheKey[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
isKeyValid(key: string): key is BizMemCacheKey {
|
|
131
|
+
return Object.prototype.hasOwnProperty.call(BIZ_MEM_CACHE_REDIS_KEYS, key);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getLastTime(key: BizMemCacheKey): number {
|
|
135
|
+
return this.lastTime[key];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
setLastTime(key: BizMemCacheKey, time: number): void {
|
|
139
|
+
this.lastTime[key] = time;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getLastTimeSnapshot(): Readonly<Record<BizMemCacheKey, number>> {
|
|
143
|
+
return { ...this.lastTime };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async markDirty(key: BizMemCacheKey, redis: RedisService): Promise<void> {
|
|
147
|
+
await redis.set(this.getRedisKey(key), Date.now());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async markAllDirty(redis: RedisService): Promise<void> {
|
|
151
|
+
const now = Date.now();
|
|
152
|
+
for (const key of this.getAllKeys()) {
|
|
153
|
+
await redis.set(this.getRedisKey(key), now);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const bizMemCacheStore = new BizMemCacheStoreInner();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
import { IWorkbenchEntity } from '@/models/SystemEntities';
|
|
3
|
+
|
|
4
|
+
export interface IWorkbenchCachedObj {
|
|
5
|
+
workbenchList: IWorkbenchEntity[];
|
|
6
|
+
workbenchDomainMap: Record<string, IWorkbenchEntity>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ISysMenuCacheObj {
|
|
10
|
+
sysMenuList: any[];
|
|
11
|
+
sysMenuCodeMap: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ISysConfgCacheObj {
|
|
15
|
+
sysConfigList: any[];
|
|
16
|
+
sysConfigCodeMap: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IDataDictItemCacheObj {
|
|
20
|
+
dictCodeMap: Record<string, any[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ISysAppCacheObj {
|
|
24
|
+
sysAppList: any[];
|
|
25
|
+
sysAppCodeMap: Record<string, any>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ISysAppPageCacheObj {
|
|
29
|
+
sysAppPageList: any[];
|
|
30
|
+
sysAppPageMap: Record<string, any>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function buildSysAppPageCacheKey(workbench_code: string, page_path: string): string {
|
|
34
|
+
return `${workbench_code}#${page_path}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ISysAnyApiCacheObj {
|
|
38
|
+
sysAnyApiList: any[];
|
|
39
|
+
sysAnyApiMethodMap: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ISysProxyApiCacheObj {
|
|
43
|
+
sysProxyApiList: any[];
|
|
44
|
+
routeTrieMap: Record<string, any> | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ICrudMethodCacheObj {
|
|
48
|
+
crudMethodList: any[];
|
|
49
|
+
crudMethodMap: Record<string, any>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IBizMemCacheData {
|
|
53
|
+
workbenchCachedObj: IWorkbenchCachedObj;
|
|
54
|
+
sysConfgCacheObj: ISysConfgCacheObj;
|
|
55
|
+
sysMenuCacheObj: ISysMenuCacheObj;
|
|
56
|
+
dataDictItemCacheObj: IDataDictItemCacheObj;
|
|
57
|
+
sysAppCacheObj: ISysAppCacheObj;
|
|
58
|
+
sysAppPageCacheObj: ISysAppPageCacheObj;
|
|
59
|
+
sysAnyApiCacheObj: ISysAnyApiCacheObj;
|
|
60
|
+
sysProxyApiCacheObj: ISysProxyApiCacheObj;
|
|
61
|
+
crudMethodCacheObj: ICrudMethodCacheObj;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const BIZ_MEM_CACHE_REDIS_KEYS = {
|
|
65
|
+
workbenchCachedObj: 'BIZ_MEM_CACHE_KEY:workbenchCachedObj',
|
|
66
|
+
sysConfgCacheObj: 'BIZ_MEM_CACHE_KEY:sysConfgCacheObj',
|
|
67
|
+
sysMenuCacheObj: 'BIZ_MEM_CACHE_KEY:sysMenuCacheObj',
|
|
68
|
+
dataDictItemCacheObj: 'BIZ_MEM_CACHE_KEY:dataDictItemCacheObj',
|
|
69
|
+
sysAppCacheObj: 'BIZ_MEM_CACHE_KEY:sysAppCacheObj',
|
|
70
|
+
sysAppPageCacheObj: 'BIZ_MEM_CACHE_KEY:sysAppPageCacheObj',
|
|
71
|
+
sysAnyApiCacheObj: 'BIZ_MEM_CACHE_KEY:sysAnyApiCacheObj',
|
|
72
|
+
sysProxyApiCacheObj: 'BIZ_MEM_CACHE_KEY:sysProxyApiCacheObj',
|
|
73
|
+
crudMethodCacheObj: 'BIZ_MEM_CACHE_KEY:crudMethodCacheObj',
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
export type BizMemCacheKey = keyof typeof BIZ_MEM_CACHE_REDIS_KEYS;
|
|
@@ -4,32 +4,14 @@ import { CrudMonitor } from '@/libs/crud-pro/utils/CrudMonitor';
|
|
|
4
4
|
|
|
5
5
|
type CacheRefresher = (ctx: koa.IMidwayKoaContext) => Promise<any>;
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* 统一缓存刷新中心
|
|
9
|
-
*
|
|
10
|
-
* 负责 非 HTTP 中间件场景 的缓存刷新,包括:
|
|
11
|
-
* 1. 定时刷新:CacheRefreshHubScheduleService 实现 IScheduleService,10分钟自动调度
|
|
12
|
-
* 2. Redis Pub/Sub 集群广播:CacheRefreshRedisSubscriber 收到广播后调用
|
|
13
|
-
* 3. API 主动刷新:helpers.controller /refreshCache 接口调用
|
|
14
|
-
*
|
|
15
|
-
* 注意:manage 增删改触发的缓存刷新由 refreshCache() 中间件直接调用 CacheServiceFactory 完成,
|
|
16
|
-
* 不经过 CacheRefreshHub。
|
|
17
|
-
*/
|
|
18
7
|
class CacheRefreshHubInner {
|
|
19
8
|
|
|
20
9
|
private readonly refreshers = new Map<CacheRefreshCategory, CacheRefresher>();
|
|
21
10
|
|
|
22
|
-
/**
|
|
23
|
-
* 注册缓存刷新器
|
|
24
|
-
*/
|
|
25
11
|
register(category: CacheRefreshCategory, refresher: CacheRefresher): void {
|
|
26
12
|
this.refreshers.set(category, refresher);
|
|
27
13
|
}
|
|
28
14
|
|
|
29
|
-
/**
|
|
30
|
-
* 刷新指定类型的缓存(主动重加载)
|
|
31
|
-
* @param category 缓存类型,'*' 刷新全部
|
|
32
|
-
*/
|
|
33
15
|
async refresh(category: CacheRefreshCategory | '*', ctx: koa.IMidwayKoaContext): Promise<void> {
|
|
34
16
|
const categories = category === '*' ? ALL_CACHE_REFRESH_CATEGORIES : [category];
|
|
35
17
|
for (const cat of categories) {
|
|
@@ -45,13 +27,9 @@ class CacheRefreshHubInner {
|
|
|
45
27
|
}
|
|
46
28
|
}
|
|
47
29
|
|
|
48
|
-
/**
|
|
49
|
-
* 定时任务入口,刷新全部缓存
|
|
50
|
-
*/
|
|
51
30
|
async runBySchedule(ctx: koa.IMidwayKoaContext): Promise<void> {
|
|
52
31
|
await this.refresh('*', ctx);
|
|
53
32
|
}
|
|
54
33
|
}
|
|
55
34
|
|
|
56
|
-
/** 全局唯一实例 */
|
|
57
35
|
export const CacheRefreshHub = new CacheRefreshHubInner();
|
|
@@ -3,12 +3,6 @@ import * as koa from '@midwayjs/koa';
|
|
|
3
3
|
import { IScheduleService } from '@/interface';
|
|
4
4
|
import { CacheRefreshHub } from '@/service/base/cache-refresh/CacheRefreshHub';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* CacheRefreshHub 的定时调度适配器
|
|
8
|
-
*
|
|
9
|
-
* 实现 IScheduleService 接口,使 CacheRefreshHub 能被 runSchedule.ts 调度。
|
|
10
|
-
* 注册到 scheduleNames.ts 中的 cacheRefreshHub 定时任务。
|
|
11
|
-
*/
|
|
12
6
|
@Provide()
|
|
13
7
|
export class CacheRefreshHubScheduleService implements IScheduleService {
|
|
14
8
|
async runBySchedule(ctx: koa.IMidwayKoaContext): Promise<void> {
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import * as _ from 'lodash';
|
|
2
2
|
import { Inject, Provide } from '@midwayjs/core';
|
|
3
3
|
import { Context } from '@midwayjs/koa';
|
|
4
|
-
import { CurdProService } from './CurdProService';
|
|
5
4
|
import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
|
|
6
5
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
7
|
-
import { SystemTables } from '@/models/SystemTables';
|
|
8
|
-
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
9
6
|
import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
|
|
10
7
|
import { ColumnRelation } from '@/libs/crud-pro/interfaces';
|
|
11
|
-
import {
|
|
12
|
-
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
13
|
-
import { CacheNameEnum } from "@/models/bizmodels";
|
|
8
|
+
import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore'
|
|
14
9
|
|
|
15
10
|
const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
|
|
16
11
|
const dictMixUtils = new CrudMixUtils(RelatedType.dict);
|
|
@@ -21,22 +16,6 @@ export class CurdMixByDictService implements IExecuteContextHandler {
|
|
|
21
16
|
@Inject()
|
|
22
17
|
ctx: Context;
|
|
23
18
|
|
|
24
|
-
@Inject()
|
|
25
|
-
private curdProService: CurdProService;
|
|
26
|
-
|
|
27
|
-
@Inject()
|
|
28
|
-
private cacheServiceFactory: CacheServiceFactory;
|
|
29
|
-
|
|
30
|
-
private async getFromCache(code: string): Promise<any[]> {
|
|
31
|
-
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByDict);
|
|
32
|
-
return cacheService.getJsonObject(code);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private async setToCache(code: string, value: any[]): Promise<any> {
|
|
36
|
-
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByDict);
|
|
37
|
-
return cacheService.setJsonObject(code, value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
19
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void> {
|
|
41
20
|
const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
|
|
42
21
|
if (!codes || codes.length === 0) {
|
|
@@ -46,51 +25,21 @@ export class CurdMixByDictService implements IExecuteContextHandler {
|
|
|
46
25
|
executeContext[TMP_CTX_KEY] = new MultiKeyMap(rows, 'dict_code', 'value');
|
|
47
26
|
}
|
|
48
27
|
|
|
49
|
-
private async getDictItemRows(codes: string[]) {
|
|
50
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
51
|
-
const noCacheCodes: string[] = [];
|
|
52
|
-
|
|
53
|
-
// 从缓存里面取
|
|
54
|
-
let cachedRows = [];
|
|
55
|
-
for (let i = 0; i < codes.length; i++) {
|
|
56
|
-
const code = codes[i];
|
|
57
|
-
const rows1: any[] = await this.getFromCache(code);
|
|
58
|
-
// const rows1 = [];
|
|
59
|
-
if (rows1 && rows1.length > 0) {
|
|
60
|
-
cachedRows = cachedRows.concat(rows1);
|
|
61
|
-
} else {
|
|
62
|
-
noCacheCodes.push(code);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
28
|
|
|
66
|
-
|
|
29
|
+
private async getDictItemRows(codes: string[]) {
|
|
30
|
+
const dictCodeMap = bizMemCacheStore.getDataDictItem()?.dictCodeMap || {};
|
|
67
31
|
let selectedRows = [];
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
sqlTable: SystemTables.sys_data_dict_item,
|
|
76
|
-
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
77
|
-
sqlDatabase: SystemDbName,
|
|
78
|
-
sqlDbType: SystemDbType,
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
selectedRows = res1.getResRows();
|
|
82
|
-
|
|
83
|
-
//放到缓存里
|
|
84
|
-
for (let i = 0; i < noCacheCodes.length; i++) {
|
|
85
|
-
const noCacheCode = noCacheCodes[i];
|
|
86
|
-
const rows1 = selectedRows.filter(e => e.dict_code === noCacheCode);
|
|
87
|
-
await this.setToCache(noCacheCode, rows1);
|
|
32
|
+
for (let index = 0; index < codes.length; index++) {
|
|
33
|
+
const dict_code = codes[index];
|
|
34
|
+
const itemRows = dictCodeMap[dict_code];
|
|
35
|
+
if(Array.isArray(itemRows)) {
|
|
36
|
+
selectedRows = selectedRows.concat(itemRows);
|
|
88
37
|
}
|
|
89
38
|
}
|
|
90
|
-
|
|
91
|
-
return cachedRows.concat(selectedRows);
|
|
39
|
+
return selectedRows;
|
|
92
40
|
}
|
|
93
41
|
|
|
42
|
+
|
|
94
43
|
async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
|
|
95
44
|
const multiKeyMap = executeContext[TMP_CTX_KEY] as MultiKeyMap;
|
|
96
45
|
if (!multiKeyMap || multiKeyMap.isEmpty()) {
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Inject, Provide } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { CurdProService } from './CurdProService';
|
|
4
3
|
import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
|
|
5
4
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
6
5
|
import * as _ from 'lodash';
|
|
7
|
-
import { SystemTables } from '@/models/SystemTables';
|
|
8
|
-
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
9
6
|
import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
|
|
10
7
|
import { ColumnRelation } from '@/libs/crud-pro/interfaces';
|
|
11
8
|
import { parseConfigContentToEnumInfo } from '@/libs/utils/parseConfig';
|
|
12
|
-
import {
|
|
13
|
-
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
14
|
-
import { CacheNameEnum } from "@/models/bizmodels";
|
|
9
|
+
import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore'
|
|
15
10
|
|
|
16
11
|
const dictMixUtils = new CrudMixUtils(RelatedType.sysCfgEnum);
|
|
17
12
|
|
|
@@ -23,62 +18,14 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
23
18
|
@Inject()
|
|
24
19
|
ctx: Context;
|
|
25
20
|
|
|
26
|
-
@Inject()
|
|
27
|
-
protected curdProService: CurdProService;
|
|
28
|
-
|
|
29
|
-
@Inject()
|
|
30
|
-
private cacheServiceFactory: CacheServiceFactory;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
private async getFromCache(code: string): Promise<any> {
|
|
34
|
-
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.GetSysConfigOne);
|
|
35
|
-
return cacheService.getJsonObject(code);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private async setToCache(code: string, value: any): Promise<any> {
|
|
39
|
-
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.GetSysConfigOne);
|
|
40
|
-
return cacheService.setJsonObject(code, value);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
private async queryConfigRowsUseCache(codes: string[]): Promise<any[]> {
|
|
45
21
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const notCachedCodes = codes.filter((code) => !resultRowMap[code]);
|
|
56
|
-
if (notCachedCodes.length === 0) {
|
|
57
|
-
return Object.values(resultRowMap);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
61
|
-
const res1 = await this.curdProService.executeCrudByCfg(
|
|
62
|
-
{
|
|
63
|
-
condition: { config_code: { $in: notCachedCodes }, deleted_at: 0, status: 1 },
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
sqlTable: SystemTables.sys_configs,
|
|
67
|
-
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
68
|
-
sqlDatabase: SystemDbName,
|
|
69
|
-
sqlDbType: SystemDbType,
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
const rows = res1.getResRows();
|
|
73
|
-
if (Array.isArray(rows) && rows.length > 0) {
|
|
74
|
-
for (let i = 0; i < rows.length; i++) {
|
|
75
|
-
const row = rows[i];
|
|
76
|
-
const { config_code } = row;
|
|
77
|
-
await this.setToCache(config_code, row);
|
|
78
|
-
resultRowMap[config_code] = row;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return Object.values(resultRowMap)
|
|
22
|
+
private queryConfigRowsUseCache(codes: string[]): any[] {
|
|
23
|
+
const codeSet = new Set(codes);
|
|
24
|
+
const sysConfigList = bizMemCacheStore.getSysConfig()?.sysConfigList || [];
|
|
25
|
+
return sysConfigList.filter((row) => {
|
|
26
|
+
const { config_code } = row;
|
|
27
|
+
return codeSet.has(config_code);
|
|
28
|
+
});
|
|
82
29
|
}
|
|
83
30
|
|
|
84
31
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
|
|
@@ -88,7 +35,7 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
88
35
|
}
|
|
89
36
|
|
|
90
37
|
const multiKeyMap = new MultiKeyMap();
|
|
91
|
-
const rows =
|
|
38
|
+
const rows = this.queryConfigRowsUseCache(codes);
|
|
92
39
|
|
|
93
40
|
for (let i = 0; i < rows.length; i++) {
|
|
94
41
|
const row = rows[i];
|
|
@@ -4,13 +4,9 @@ import * as _ from 'lodash';
|
|
|
4
4
|
import { CurdProService } from './CurdProService';
|
|
5
5
|
import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
|
|
6
6
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
7
|
-
import { SystemTables } from '@/models/SystemTables';
|
|
8
|
-
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
9
7
|
import { ColumnRelation } from '@/libs/crud-pro/interfaces';
|
|
10
8
|
import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
|
|
11
|
-
import {
|
|
12
|
-
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
13
|
-
import { CacheNameEnum } from "@/models/bizmodels";
|
|
9
|
+
import { bizMemCacheStore } from '@/service/base/bizmemcache/BizMemCacheStore'
|
|
14
10
|
|
|
15
11
|
const workbenchMixUtils = new CrudMixUtils(RelatedType.workbenchBasic);
|
|
16
12
|
|
|
@@ -25,33 +21,12 @@ export class CurdMixByWorkbenchService implements IExecuteContextHandler {
|
|
|
25
21
|
@Inject()
|
|
26
22
|
protected curdProService: CurdProService;
|
|
27
23
|
|
|
28
|
-
@Inject()
|
|
29
|
-
private cacheServiceFactory: CacheServiceFactory;
|
|
30
|
-
|
|
31
24
|
private async loadWorkbenchListMap(): Promise<Map<string, any>> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cacheKey: CacheNameEnum.CurdMixByWorkbench,
|
|
35
|
-
cacheName: CacheNameEnum.CurdMixByWorkbench,
|
|
36
|
-
refreshCache: false,
|
|
37
|
-
getter: async (ctx) => {
|
|
38
|
-
const service: CurdMixByWorkbenchService = await ctx.requestContext.getAsync(CurdMixByWorkbenchService);
|
|
39
|
-
const reqJson = {
|
|
40
|
-
columns: 'workbench_code,workbench_name,workbench_domain',
|
|
41
|
-
condition: { deleted_at: 0, status: 1 },
|
|
42
|
-
};
|
|
43
|
-
const res = await service.curdProService.executeCrudByCfg(reqJson, {
|
|
44
|
-
sqlTable: SystemTables.sys_workbench,
|
|
45
|
-
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
46
|
-
sqlDatabase: SystemDbName,
|
|
47
|
-
sqlDbType: SystemDbType,
|
|
48
|
-
});
|
|
49
|
-
const workbenchList = res.getResRows();
|
|
50
|
-
return MixinUtils.toNewMap(workbenchList, (obj: any) => obj.workbench_code);
|
|
51
|
-
},
|
|
52
|
-
});
|
|
25
|
+
const workbenchList = bizMemCacheStore.getWorkbench()?.workbenchList || [];
|
|
26
|
+
return MixinUtils.toNewMap(workbenchList, (obj: any) => obj.workbench_code);
|
|
53
27
|
}
|
|
54
28
|
|
|
29
|
+
|
|
55
30
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
|
|
56
31
|
const relations = workbenchMixUtils.pickColumnRelations(executeContext);
|
|
57
32
|
if (!relations || relations.length === 0) {
|
|
@@ -61,12 +36,12 @@ export class CurdMixByWorkbenchService implements IExecuteContextHandler {
|
|
|
61
36
|
}
|
|
62
37
|
|
|
63
38
|
async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
39
|
+
const workbenchInfoMap = executeContext[TMP_CTX_KEY] as Map<string, any>;
|
|
40
|
+
if (!workbenchInfoMap || workbenchInfoMap.size === 0) {
|
|
66
41
|
return;
|
|
67
42
|
}
|
|
68
43
|
workbenchMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
|
|
69
|
-
workbenchMixUtils.copyColumnRelationToRowNoRelatedCode(row,
|
|
44
|
+
workbenchMixUtils.copyColumnRelationToRowNoRelatedCode(row, workbenchInfoMap, columnRelation);
|
|
70
45
|
});
|
|
71
46
|
}
|
|
72
47
|
}
|
|
@@ -21,7 +21,6 @@ import { ShardingBase, ShardingByTimeCrud, ShardingByHashCrud, ShardingByKeyCrud
|
|
|
21
21
|
import { fixCfgModel } from './fixCfgModel';
|
|
22
22
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
23
23
|
import { fixSoftDelete } from "@/libs/crud-pro-quick/fixSoftDelete";
|
|
24
|
-
import { clearMethodCache } from '@/libs/crud-pro/services/CrudProCachedCfgService';
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* getQuickCrud 参数接口
|
|
@@ -433,11 +432,6 @@ export class CurdProService extends BaseService {
|
|
|
433
432
|
}
|
|
434
433
|
|
|
435
434
|
|
|
436
|
-
public async loadMethodCache(ctx?: any): Promise<void> {
|
|
437
|
-
clearMethodCache();
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
435
|
public async loadTableMetaCache(ctx?: any): Promise<void> {
|
|
442
436
|
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
443
437
|
await this.getAllTableInfos({
|