midway-fatcms 0.0.1-beta.66 → 0.0.1-beta.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.default.js +4 -1
- package/dist/controller/gateway/PublicApiController.js +3 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +4 -4
- package/dist/models/SystemEntities.d.ts +0 -22
- package/dist/models/SystemEntities.js +1 -14
- package/dist/models/bizmodels.d.ts +20 -2
- package/dist/models/bizmodels.js +15 -1
- package/dist/service/EnumInfoService.js +3 -9
- package/dist/service/UserSessionService.js +4 -7
- package/dist/service/base/cache/CacheServiceFactory.d.ts +3 -5
- package/dist/service/base/cache/CacheServiceFactory.js +31 -20
- package/dist/service/base/cache/{FatcmsBaseCtxCache.d.ts → CtxCache.d.ts} +4 -5
- package/dist/service/base/cache/{FatcmsBaseCtxCache.js → CtxCache.js} +4 -5
- package/dist/service/base/cache/DiskCache.d.ts +19 -0
- package/dist/service/base/cache/{FatcmsBaseDiskCache.js → DiskCache.js} +10 -17
- package/dist/service/base/cache/MemoryCache.d.ts +12 -0
- package/dist/service/base/cache/{FatcmsBaseMemoryCache.js → MemoryCache.js} +9 -17
- package/dist/service/base/cache/{FatcmsBaseNoneCache.d.ts → NoneCache.d.ts} +2 -2
- package/dist/service/base/cache/{FatcmsBaseNoneCache.js → NoneCache.js} +3 -3
- package/dist/service/base/cache/{FatcmsBaseRedisCache.d.ts → RedisCache.d.ts} +5 -11
- package/dist/service/base/cache/{FatcmsBaseRedisCache.js → RedisCache.js} +9 -17
- package/dist/service/crudstd/CrudStdService.js +3 -11
- package/dist/service/curd/CurdMixByAccountService.d.ts +4 -0
- package/dist/service/curd/CurdMixByAccountService.js +50 -12
- package/dist/service/curd/CurdMixByDictService.js +4 -8
- package/dist/service/curd/CurdMixByLinkToCustomService.js +2 -7
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -8
- package/dist/service/curd/CurdMixByWorkbenchService.js +3 -9
- package/package.json +1 -1
- package/src/config/config.default.ts +4 -1
- package/src/controller/gateway/PublicApiController.ts +2 -14
- package/src/index.ts +1 -1
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +7 -5
- package/src/models/SystemEntities.ts +1 -30
- package/src/models/WorkbenchInfoTools.ts +3 -2
- package/src/models/bizmodels.ts +26 -4
- package/src/service/EnumInfoService.ts +12 -18
- package/src/service/UserSessionService.ts +14 -19
- package/src/service/base/cache/CacheServiceFactory.ts +51 -42
- package/src/service/base/cache/{FatcmsBaseCtxCache.ts → CtxCache.ts} +4 -6
- package/src/service/base/cache/{FatcmsBaseDiskCache.ts → DiskCache.ts} +18 -23
- package/src/service/base/cache/{FatcmsBaseMemoryCache.ts → MemoryCache.ts} +10 -16
- package/src/service/base/cache/{FatcmsBaseNoneCache.ts → NoneCache.ts} +3 -3
- package/src/service/base/cache/{FatcmsBaseRedisCache.ts → RedisCache.ts} +11 -18
- package/src/service/crudstd/CrudStdService.ts +19 -31
- package/src/service/curd/CurdMixByAccountService.ts +62 -14
- package/src/service/curd/CurdMixByDictService.ts +6 -11
- package/src/service/curd/CurdMixByLinkToCustomService.ts +1 -8
- package/src/service/curd/CurdMixBySysConfigService.ts +8 -15
- package/src/service/curd/CurdMixByWorkbenchService.ts +3 -10
- package/dist/service/base/cache/FatcmsBaseDiskCache.d.ts +0 -24
- package/dist/service/base/cache/FatcmsBaseMemoryCache.d.ts +0 -18
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { ICacheServiceBase } from '@/models/bizmodels';
|
|
1
|
+
import {Config, Inject, Provide} from '@midwayjs/core';
|
|
2
|
+
import {Context} from '@midwayjs/koa';
|
|
3
|
+
import {parseJsonObject} from '@/libs/utils/functions';
|
|
4
|
+
import {ISessionInfo, SESSION_ID_KEY, sessionCookieCfg} from '@/models/userSession';
|
|
5
|
+
import {HEADER_KEY_RUN_BY_ASYNC_TASK_ID} from '@/models/AsyncTaskModel';
|
|
6
|
+
import {CurdProService} from './curd/CurdProService';
|
|
7
|
+
import {KeysOfSimpleSQL} from '@/libs/crud-pro/models/keys';
|
|
8
|
+
import {SystemTables} from '@/models/SystemTables';
|
|
9
|
+
import {GLOBAL_STATIC_CONFIG} from '@/libs/global-config/global-config';
|
|
10
|
+
import {CacheServiceFactory} from './base/cache/CacheServiceFactory';
|
|
11
|
+
import {ICacheService , CacheNameEnum} from '@/models/bizmodels';
|
|
13
12
|
|
|
14
13
|
function pickUserAvatar(avatar: any): string {
|
|
15
14
|
if (!avatar) {
|
|
@@ -70,8 +69,8 @@ export class UserSessionService {
|
|
|
70
69
|
* 获取用户会话缓存服务
|
|
71
70
|
* @returns
|
|
72
71
|
*/
|
|
73
|
-
private getUserSessionCacheService():
|
|
74
|
-
return this.cacheServiceFactory.
|
|
72
|
+
private getUserSessionCacheService(): ICacheService {
|
|
73
|
+
return this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.UserSessionBySessionId);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
/**
|
|
@@ -140,15 +139,11 @@ export class UserSessionService {
|
|
|
140
139
|
return parseJsonObject(asyncTaskObj.created_user_session);
|
|
141
140
|
};
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
cacheLevel: CacheLevelEnum.REDIS,
|
|
142
|
+
return await this.cacheServiceFactory.getJsonObjectCache({
|
|
145
143
|
cacheName: CacheNameEnum.UserSessionByAsyncTaskId,
|
|
146
144
|
cacheKey: taskSessionCacheKey,
|
|
147
|
-
cacheSecond: 3600,
|
|
148
145
|
getter: loadSessionInfo,
|
|
149
146
|
});
|
|
150
|
-
|
|
151
|
-
return sessionInfo1;
|
|
152
147
|
}
|
|
153
148
|
|
|
154
149
|
/**
|
|
@@ -1,66 +1,75 @@
|
|
|
1
1
|
import { Inject, Provide, Config } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import {
|
|
4
|
-
import { CacheLevelEnum,
|
|
3
|
+
import {CacheNameEnum, ICacheService, IfatcmsCacheConfig, IWorkbenchConfigCacheLevel} from '@/models/bizmodels';
|
|
4
|
+
import { CacheLevelEnum, } from '@/models/SystemEntities';
|
|
5
5
|
import { RedisService } from '@midwayjs/redis';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { CtxCache } from './CtxCache';
|
|
7
|
+
import { RedisCache } from './RedisCache';
|
|
8
|
+
import { DiskCache } from './DiskCache';
|
|
9
|
+
import { MemoryCache } from './MemoryCache';
|
|
10
|
+
import { NoneCache } from './NoneCache';
|
|
11
11
|
|
|
12
12
|
interface IGetJsonObjectCacheParam {
|
|
13
|
-
cacheLevel: CacheLevelEnum;
|
|
14
13
|
cacheName: CacheNameEnum;
|
|
15
14
|
cacheKey: string;
|
|
16
|
-
cacheSecond: number;
|
|
17
15
|
refreshCache?: boolean;
|
|
18
16
|
getter: () => Promise<any>;
|
|
19
17
|
}
|
|
20
18
|
|
|
19
|
+
const defaultCacheConfig: IWorkbenchConfigCacheLevel = {
|
|
20
|
+
cacheLevel: CacheLevelEnum.MEMORY,
|
|
21
|
+
cacheSecond: 60 * 5
|
|
22
|
+
}
|
|
23
|
+
|
|
21
24
|
@Provide()
|
|
22
25
|
export class CacheServiceFactory {
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
@Inject()
|
|
27
|
+
protected ctx: Context;
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
@Config('fatcmsCache')
|
|
30
|
+
private fatcmsCache: IfatcmsCacheConfig;
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
@Inject()
|
|
33
|
+
protected redisService: RedisService;
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
private getCacheService(cacheLevelEnum: CacheLevelEnum, cacheName: CacheNameEnum, cacheSecond: number): ICacheService {
|
|
36
|
+
switch (cacheLevelEnum) {
|
|
37
|
+
case CacheLevelEnum.CONTEXT:
|
|
38
|
+
return new CtxCache(this.ctx, cacheName);
|
|
39
|
+
case CacheLevelEnum.REDIS:
|
|
40
|
+
return new RedisCache(this.ctx, cacheName, this.redisService, cacheSecond);
|
|
41
|
+
case CacheLevelEnum.DISK:
|
|
42
|
+
return new DiskCache(this.ctx, cacheName, this.fatcmsCache, cacheSecond);
|
|
43
|
+
case CacheLevelEnum.MEMORY:
|
|
44
|
+
return new MemoryCache(this.ctx, cacheName, cacheSecond);
|
|
45
|
+
case CacheLevelEnum.NONE:
|
|
46
|
+
return new NoneCache(this.ctx, cacheName);
|
|
47
|
+
default:
|
|
48
|
+
return new NoneCache(this.ctx, cacheName);
|
|
45
49
|
}
|
|
50
|
+
}
|
|
46
51
|
|
|
47
|
-
public async getJsonObjectCache(param: IGetJsonObjectCacheParam): Promise<any> {
|
|
48
|
-
let { cacheLevel, cacheName, cacheKey, cacheSecond, refreshCache, getter } = param;
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
public getCacheServiceByName(cacheName: CacheNameEnum): ICacheService {
|
|
54
|
+
const cacheConfig: Record<CacheNameEnum, IWorkbenchConfigCacheLevel> = (this.fatcmsCache?.cacheConfig || {}) as any;
|
|
55
|
+
if (cacheConfig[cacheName]) {
|
|
56
|
+
const { cacheLevel, cacheSecond } = Object.assign({}, defaultCacheConfig, cacheConfig[cacheName]) ;
|
|
57
|
+
return this.getCacheService(cacheLevel, cacheName, cacheSecond);
|
|
58
|
+
}
|
|
59
|
+
const { cacheLevel, cacheSecond } = defaultCacheConfig;
|
|
60
|
+
return this.getCacheService(cacheLevel, cacheName, cacheSecond);
|
|
61
|
+
}
|
|
54
62
|
|
|
55
|
-
const realCacheKey = this.fatcmsCache.keyPrefix + cacheKey;
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
public async getJsonObjectCache(param: IGetJsonObjectCacheParam): Promise<any> {
|
|
65
|
+
const {cacheName, cacheKey, refreshCache, getter} = param;
|
|
66
|
+
const cacheService = this.getCacheServiceByName(cacheName);
|
|
67
|
+
let obj = await cacheService.getJsonObject(cacheKey);
|
|
68
|
+
if (!obj || refreshCache === true) {
|
|
69
|
+
obj = await getter();
|
|
70
|
+
await cacheService.setJsonObject(cacheKey, obj);
|
|
64
71
|
}
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
65
74
|
|
|
66
75
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CacheNameEnum
|
|
1
|
+
import { ICacheService } from '@/models/bizmodels';
|
|
2
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
3
3
|
import { Context } from '@midwayjs/koa';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export class
|
|
7
|
+
export class CtxCache implements ICacheService {
|
|
8
8
|
private ctx: Context;
|
|
9
9
|
private cacheName: CacheNameEnum;
|
|
10
|
-
|
|
11
10
|
constructor(ctx: Context, cacheName: CacheNameEnum) {
|
|
12
11
|
this.ctx = ctx;
|
|
13
12
|
this.cacheName = cacheName;
|
|
@@ -32,10 +31,9 @@ export class FatcmsBaseCtxCache implements ICacheServiceBase {
|
|
|
32
31
|
* 设置缓存对象
|
|
33
32
|
* @param key
|
|
34
33
|
* @param obj
|
|
35
|
-
* @param expireSecond 过期时间,单位秒
|
|
36
34
|
* @returns
|
|
37
35
|
*/
|
|
38
|
-
async setJsonObject(key: string, obj: any
|
|
36
|
+
async setJsonObject(key: string, obj: any): Promise<any> {
|
|
39
37
|
const cacheMap = this.getCacheMap();
|
|
40
38
|
cacheMap.set(key, obj);
|
|
41
39
|
}
|
|
@@ -3,34 +3,36 @@ import * as md5 from 'md5';
|
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
4
|
import * as fs2 from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
|
-
import { parseJsonObject } from '
|
|
7
|
-
import {
|
|
6
|
+
import { parseJsonObject } from '@/libs/utils/functions';
|
|
7
|
+
import { ICacheService, IfatcmsCacheConfig } from '@/models/bizmodels';
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
export class
|
|
10
|
+
export class DiskCache implements ICacheService {
|
|
11
11
|
protected ctx: Context;
|
|
12
12
|
protected cacheName: string;
|
|
13
13
|
private fatcmsCache: IfatcmsCacheConfig;
|
|
14
|
-
|
|
15
|
-
constructor(ctx: Context, cacheName: string, fatcmsCache: IfatcmsCacheConfig) {
|
|
14
|
+
private cacheSecond: number;
|
|
15
|
+
constructor(ctx: Context, cacheName: string, fatcmsCache: IfatcmsCacheConfig,cacheSecond: number) {
|
|
16
16
|
this.ctx = ctx;
|
|
17
17
|
this.cacheName = cacheName;
|
|
18
18
|
this.fatcmsCache = fatcmsCache;
|
|
19
|
+
this.cacheSecond = cacheSecond;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
/**
|
|
24
|
+
* 获取缓存文件路径
|
|
25
|
+
* @param key
|
|
26
|
+
* @param checkDirExist
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
27
29
|
private async getCacheFilePath(key: string, checkDirExist: boolean = true): Promise<string> {
|
|
28
30
|
const cacheDir0 = this.fatcmsCache.diskCacheDir;
|
|
29
31
|
const cacheDir = path.join(cacheDir0, this.cacheName);
|
|
30
32
|
if (checkDirExist) {
|
|
31
33
|
const isDirExist = await fs2.promises.access(cacheDir).then(() => true, () => false);
|
|
32
34
|
if (!isDirExist) {
|
|
33
|
-
await fs2.promises.mkdir(cacheDir, { recursive: true });
|
|
35
|
+
await fs2.promises.mkdir(cacheDir, { recursive: true });
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
return path.join(cacheDir, `${md5(key)}.json`);
|
|
@@ -50,21 +52,14 @@ export class FatcmsBaseDiskCache implements ICacheServiceBase {
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @param expireSecond 过期时间,单位秒
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
async setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any> {
|
|
61
|
-
if (!expireSecond) {
|
|
62
|
-
expireSecond = 60;
|
|
63
|
-
}
|
|
55
|
+
|
|
56
|
+
async setJsonObject(key: string, obj: any, cacheSecond0?: number): Promise<any> {
|
|
57
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
58
|
+
|
|
64
59
|
const str = JSON.stringify({
|
|
65
60
|
data: obj,
|
|
66
61
|
key,
|
|
67
|
-
expireAt: Date.now() +
|
|
62
|
+
expireAt: Date.now() + cacheSecond * 1000,
|
|
68
63
|
});
|
|
69
64
|
const cacheFilePath = await this.getCacheFilePath(key);
|
|
70
65
|
try {
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
2
|
import { LRUCache } from 'lru-cache';
|
|
3
|
-
import {
|
|
3
|
+
import { ICacheService } from '@/models/bizmodels';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const LRU_CACHE_MAP = new Map<string, LRUCache<string, any>>();
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
export class
|
|
10
|
+
export class MemoryCache implements ICacheService {
|
|
11
11
|
protected ctx: Context;
|
|
12
12
|
protected cacheName: string;
|
|
13
|
+
protected cacheSecond: number;
|
|
13
14
|
|
|
14
|
-
constructor(ctx: Context, cacheName: string) {
|
|
15
|
+
constructor(ctx: Context, cacheName: string, cacheSecond:number) {
|
|
15
16
|
this.ctx = ctx;
|
|
16
17
|
this.cacheName = cacheName;
|
|
18
|
+
this.cacheSecond = cacheSecond;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
private getLruCache(): LRUCache<string, any> {
|
|
20
22
|
if (!LRU_CACHE_MAP.has(this.cacheName)) {
|
|
21
23
|
const lruCache = new LRUCache<string, any>({
|
|
22
|
-
max:
|
|
24
|
+
max: 2000,
|
|
23
25
|
ttl: 1000 * 60 * 60 * 24,
|
|
24
26
|
ttlAutopurge: true,
|
|
25
27
|
});
|
|
@@ -41,22 +43,14 @@ export class FatcmsBaseMemoryCache implements ICacheServiceBase {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @param obj
|
|
48
|
-
* @param expireSecond 过期时间,单位秒
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
async setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any> {
|
|
46
|
+
|
|
47
|
+
async setJsonObject(key: string, obj: any, cacheSecond0: number): Promise<any> {
|
|
48
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
52
49
|
const lruCache = this.getLruCache();
|
|
53
|
-
if (!expireSecond) {
|
|
54
|
-
expireSecond = 60;
|
|
55
|
-
}
|
|
56
50
|
const saveObj = {
|
|
57
51
|
data: obj,
|
|
58
52
|
key,
|
|
59
|
-
expireAt: Date.now() +
|
|
53
|
+
expireAt: Date.now() + cacheSecond * 1000,
|
|
60
54
|
};
|
|
61
55
|
lruCache.set(key, saveObj);
|
|
62
56
|
return true;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ICacheService } from '@/models/bizmodels';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
3
|
|
|
4
|
-
export class
|
|
4
|
+
export class NoneCache implements ICacheService {
|
|
5
5
|
protected ctx: Context;
|
|
6
6
|
protected cacheName: string;
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
constructor(ctx: Context, cacheName: string) {
|
|
9
9
|
this.ctx = ctx;
|
|
10
10
|
this.cacheName = cacheName;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
2
|
import { RedisService } from '@midwayjs/redis';
|
|
3
|
-
import { parseJsonObject } from '
|
|
4
|
-
import {
|
|
3
|
+
import { parseJsonObject } from '@/libs/utils/functions';
|
|
4
|
+
import { ICacheService } from '@/models/bizmodels';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
export class FatcmsBaseRedisCache implements ICacheServiceBase {
|
|
6
|
+
export class RedisCache implements ICacheService {
|
|
8
7
|
protected ctx: Context;
|
|
9
8
|
protected cacheName: string;
|
|
10
9
|
protected redisService: RedisService;
|
|
10
|
+
protected cacheSecond: number;
|
|
11
11
|
|
|
12
|
-
constructor(ctx: Context, cacheName: string, redisService: RedisService) {
|
|
12
|
+
constructor(ctx: Context, cacheName: string, redisService: RedisService, cacheSecond: number) {
|
|
13
13
|
this.ctx = ctx;
|
|
14
14
|
this.cacheName = cacheName;
|
|
15
15
|
this.redisService = redisService;
|
|
16
|
+
this.cacheSecond = cacheSecond;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
private getCacheKey(key: string): string {
|
|
@@ -25,24 +26,16 @@ export class FatcmsBaseRedisCache implements ICacheServiceBase {
|
|
|
25
26
|
return parseJsonObject(str);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @param obj
|
|
32
|
-
* @param expireSecond 过期时间,单位秒
|
|
33
|
-
* @returns
|
|
34
|
-
*/
|
|
35
|
-
async setJsonObject(key: string, obj: any, expireSecond?: number): Promise<any> {
|
|
29
|
+
|
|
30
|
+
async setJsonObject(key: string, obj: any, cacheSecond0?: number): Promise<any> {
|
|
31
|
+
const cacheSecond = cacheSecond0 || this.cacheSecond || 60;
|
|
36
32
|
const cacheKey = this.getCacheKey(key);
|
|
37
|
-
if (!expireSecond) {
|
|
38
|
-
expireSecond = 60;
|
|
39
|
-
}
|
|
40
33
|
const str = JSON.stringify(obj);
|
|
41
|
-
return this.redisService.set(cacheKey, str, 'EX',
|
|
34
|
+
return this.redisService.set(cacheKey, str, 'EX', cacheSecond);
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
async removeItem(key: string): Promise<any> {
|
|
45
38
|
const cacheKey = this.getCacheKey(key);
|
|
46
|
-
return
|
|
39
|
+
return this.redisService.del(cacheKey);
|
|
47
40
|
}
|
|
48
41
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/* eslint-disable prettier/prettier */
|
|
2
2
|
import * as _ from 'lodash';
|
|
3
3
|
import * as ejs from 'ejs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
4
|
+
import {Inject, Provide} from '@midwayjs/core';
|
|
5
|
+
import {Context} from '@midwayjs/koa';
|
|
6
|
+
import {CurdMixService} from '../curd/CurdMixService';
|
|
7
|
+
import {IRequestCfgModel, IRequestModel} from '@/libs/crud-pro/interfaces';
|
|
8
|
+
import {KeysOfAuthType, KeysOfSimpleSQL, SqlDbType} from '@/libs/crud-pro/models/keys';
|
|
9
|
+
import {parseJsonObject} from '@/libs/utils/functions';
|
|
10
|
+
import {ICrudStdAppInfo, ICrudStdAppInfoForSettingKey} from '@/models/bizmodels';
|
|
11
|
+
import {BizException} from '@/models/devops';
|
|
12
|
+
import {ExecuteContext} from '@/libs/crud-pro/models/ExecuteContext';
|
|
13
|
+
import {SystemTables} from '@/models/SystemTables';
|
|
14
|
+
import {CrudStdActionService} from './CrudStdActionService';
|
|
15
|
+
import {CrudStdRelationService} from './CrudStdRelationService';
|
|
16
|
+
import {ApiBaseService} from '../base/ApiBaseService';
|
|
17
|
+
import {parseDatabaseName} from '@/libs/crud-pro/utils/DatabaseName';
|
|
18
|
+
import {GLOBAL_STATIC_CONFIG} from '@/libs/global-config/global-config';
|
|
19
|
+
import {MixinUtils} from '@/libs/crud-pro/utils/MixinUtils';
|
|
20
|
+
import {CacheServiceFactory} from '../base/cache/CacheServiceFactory';
|
|
21
|
+
import {CacheNameEnum} from "@/models/bizmodels";
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
export const SPECIAL_SETTING_KEY = {
|
|
@@ -38,11 +38,6 @@ export interface IRequestModelCrudProExt extends IRequestModel {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
|
|
43
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
44
|
-
|
|
45
|
-
|
|
46
41
|
function isNotEmptyStr(str: any): boolean {
|
|
47
42
|
return typeof str === 'string' && str.trim().length > 0;
|
|
48
43
|
}
|
|
@@ -315,20 +310,13 @@ export class CrudStdService extends ApiBaseService {
|
|
|
315
310
|
* @private
|
|
316
311
|
*/
|
|
317
312
|
public async getParsedCrudStdAppInfo(appCode: string): Promise<ICrudStdAppInfo> {
|
|
318
|
-
|
|
319
|
-
const cacheSecond = crudStdAppInfoCacheSecond || DEFAULT_CACHE_SECOND;
|
|
320
|
-
const cacheLevel = crudStdAppInfoCacheLevel || DEFAULT_CACHE_LEVEL;
|
|
321
|
-
|
|
322
|
-
let appInfo = await this.cacheServiceFactory.getJsonObjectCache({
|
|
323
|
-
cacheLevel,
|
|
313
|
+
return await this.cacheServiceFactory.getJsonObjectCache({
|
|
324
314
|
cacheKey: appCode,
|
|
325
|
-
cacheSecond,
|
|
326
315
|
cacheName: CacheNameEnum.GetParsedCrudStdAppInfo,
|
|
327
316
|
getter: async () => {
|
|
328
317
|
return await this.getParsedCrudStdAppInfoPrivate(appCode);
|
|
329
318
|
},
|
|
330
319
|
});
|
|
331
|
-
return appInfo;
|
|
332
320
|
}
|
|
333
321
|
|
|
334
322
|
|
|
@@ -9,6 +9,8 @@ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
|
9
9
|
import { ColumnRelation, IRequestCfgModel, IRequestModel } from '@/libs/crud-pro/interfaces';
|
|
10
10
|
import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
|
|
11
11
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
12
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
13
|
+
import { CacheServiceFactory } from "@/service/base/cache/CacheServiceFactory";
|
|
12
14
|
|
|
13
15
|
const dictMixUtils = new CrudMixUtils(RelatedType.accountBasic);
|
|
14
16
|
|
|
@@ -17,17 +19,21 @@ const TMP_CTX_KEY2 = _.uniqueId('CurdMixByAccountService2');
|
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
|
|
22
|
+
|
|
20
23
|
@Provide()
|
|
21
24
|
export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
22
|
-
|
|
25
|
+
|
|
23
26
|
@Inject()
|
|
24
27
|
protected ctx: Context;
|
|
25
28
|
|
|
26
29
|
@Inject()
|
|
27
30
|
protected curdProService: CurdProService;
|
|
28
31
|
|
|
32
|
+
@Inject()
|
|
33
|
+
private cacheServiceFactory: CacheServiceFactory;
|
|
34
|
+
|
|
35
|
+
|
|
29
36
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
|
|
30
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
31
37
|
|
|
32
38
|
const relations = dictMixUtils.pickColumnRelations(executeContext);
|
|
33
39
|
if (!relations || relations.length === 0) {
|
|
@@ -57,29 +63,71 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
57
63
|
return;
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
sqlDbType: SystemDbType,
|
|
66
|
-
};
|
|
66
|
+
const userInfos = await this.queryUserAccountIdList([...accountIds]);
|
|
67
|
+
executeContext[TMP_CTX_KEY] = MixinUtils.toNewMap(userInfos, (obj: any) => obj.account_id);
|
|
68
|
+
executeContext[TMP_CTX_KEY2] = isArrayModeMap;
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
|
|
72
|
+
private async getFromCache(code: string): Promise<any> {
|
|
73
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByAccount);
|
|
74
|
+
return cacheService.getJsonObject(code);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private async setToCache(code: string, value: any): Promise<any> {
|
|
78
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByAccount);
|
|
79
|
+
return cacheService.setJsonObject(code, value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async queryUserAccountIdList(accountIds: string[]): Promise<any[]> {
|
|
83
|
+
const resultRowMap = {} as Record<string, any>;
|
|
84
|
+
for (let i = 0; i < accountIds.length; i++) {
|
|
85
|
+
const accountId = accountIds[i];
|
|
86
|
+
const row = await this.getFromCache(accountId);
|
|
87
|
+
if (row) {
|
|
88
|
+
resultRowMap[accountId] = row;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const notCachedCodes = accountIds.filter((accountId) => !resultRowMap[accountId]);
|
|
93
|
+
if (notCachedCodes.length === 0) {
|
|
94
|
+
return Object.values(resultRowMap);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
68
98
|
const reqJson: IRequestModel = {
|
|
69
99
|
columns: ['nick_name', 'avatar', 'account_id'],
|
|
70
100
|
condition: {
|
|
71
101
|
account_id: {
|
|
72
|
-
$in: [...
|
|
102
|
+
$in: [...notCachedCodes],
|
|
73
103
|
},
|
|
74
104
|
},
|
|
75
105
|
};
|
|
76
106
|
|
|
107
|
+
const cfgModel: IRequestCfgModel = {
|
|
108
|
+
method: 'UserAccountService.queryAccountBasicInfoByIds',
|
|
109
|
+
sqlTable: SystemTables.sys_user_account,
|
|
110
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
111
|
+
sqlDatabase: SystemDbName,
|
|
112
|
+
sqlDbType: SystemDbType,
|
|
113
|
+
};
|
|
77
114
|
const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
115
|
+
const rows = res.getResRows();
|
|
116
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
117
|
+
for (let i = 0; i < rows.length; i++) {
|
|
118
|
+
const row = rows[i];
|
|
119
|
+
const { account_id } = row;
|
|
120
|
+
await this.setToCache(account_id, row);
|
|
121
|
+
resultRowMap[account_id] = row;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return Object.values(resultRowMap)
|
|
125
|
+
|
|
81
126
|
}
|
|
82
127
|
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
83
131
|
async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
|
|
84
132
|
const userInfoMap = executeContext[TMP_CTX_KEY] as Map<string, any>;
|
|
85
133
|
const isArrayModeMap = executeContext[TMP_CTX_KEY2] as Map<string, boolean>;
|
|
@@ -105,7 +153,7 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
105
153
|
{ from: 'avatar', to: `${sourceColumn}_user.avatar` },
|
|
106
154
|
{ from: 'account_id', to: `${sourceColumn}_user.account_id` },
|
|
107
155
|
];
|
|
108
|
-
}
|
|
156
|
+
}
|
|
109
157
|
}
|
|
110
158
|
dictMixUtils.copyUserInfoToRowNoRelatedCode(row, userInfoMap, columnRelation);
|
|
111
159
|
});
|
|
@@ -10,15 +10,12 @@ import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
|
|
|
10
10
|
import { ColumnRelation } from '@/libs/crud-pro/interfaces';
|
|
11
11
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
12
12
|
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
13
|
-
import {
|
|
13
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
14
14
|
|
|
15
15
|
const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
|
|
16
16
|
const dictMixUtils = new CrudMixUtils(RelatedType.dict);
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
|
|
20
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
21
|
-
|
|
22
19
|
@Provide()
|
|
23
20
|
export class CurdMixByDictService implements IExecuteContextHandler {
|
|
24
21
|
@Inject()
|
|
@@ -30,16 +27,14 @@ export class CurdMixByDictService implements IExecuteContextHandler {
|
|
|
30
27
|
@Inject()
|
|
31
28
|
private cacheServiceFactory: CacheServiceFactory;
|
|
32
29
|
|
|
33
|
-
private async getFromCache(code: string): Promise<any> {
|
|
34
|
-
const
|
|
35
|
-
const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, CacheNameEnum.CurdMixByDict);
|
|
30
|
+
private async getFromCache(code: string): Promise<any[]> {
|
|
31
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByDict);
|
|
36
32
|
return cacheService.getJsonObject(code);
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
private async setToCache(code: string, value: any): Promise<any> {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
return cacheService.setJsonObject(code, value, curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND);
|
|
35
|
+
private async setToCache(code: string, value: any[]): Promise<any> {
|
|
36
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixByDict);
|
|
37
|
+
return cacheService.setJsonObject(code, value);
|
|
43
38
|
}
|
|
44
39
|
|
|
45
40
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void> {
|