midway-fatcms 0.0.1-beta.67 → 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/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 +19 -1
- 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 +24 -13
- package/dist/service/base/cache/CtxCache.d.ts +2 -3
- package/dist/service/base/cache/CtxCache.js +1 -2
- package/dist/service/base/cache/DiskCache.d.ts +6 -11
- package/dist/service/base/cache/DiskCache.js +10 -17
- package/dist/service/base/cache/MemoryCache.d.ts +3 -9
- package/dist/service/base/cache/MemoryCache.js +6 -14
- package/dist/service/base/cache/RedisCache.d.ts +3 -9
- package/dist/service/base/cache/RedisCache.js +6 -14
- 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/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 +25 -3
- package/src/service/EnumInfoService.ts +12 -18
- package/src/service/UserSessionService.ts +13 -18
- package/src/service/base/cache/CacheServiceFactory.ts +47 -38
- package/src/service/base/cache/CtxCache.ts +2 -4
- package/src/service/base/cache/DiskCache.ts +15 -20
- package/src/service/base/cache/MemoryCache.ts +8 -14
- package/src/service/base/cache/RedisCache.ts +8 -15
- 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
|
@@ -1,66 +1,75 @@
|
|
|
1
1
|
import { Inject, Provide, Config } from '@midwayjs/core';
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { ICacheService, IfatcmsCacheConfig } from '@/models/bizmodels';
|
|
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
6
|
import { CtxCache } from './CtxCache';
|
|
7
7
|
import { RedisCache } from './RedisCache';
|
|
8
|
-
import {
|
|
8
|
+
import { DiskCache } from './DiskCache';
|
|
9
9
|
import { MemoryCache } from './MemoryCache';
|
|
10
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,5 +1,5 @@
|
|
|
1
1
|
import { ICacheService } from '@/models/bizmodels';
|
|
2
|
-
import { CacheNameEnum
|
|
2
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
3
3
|
import { Context } from '@midwayjs/koa';
|
|
4
4
|
|
|
5
5
|
|
|
@@ -7,7 +7,6 @@ import { Context } from '@midwayjs/koa';
|
|
|
7
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 CtxCache implements ICacheService {
|
|
|
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
|
}
|
|
@@ -7,23 +7,25 @@ import { parseJsonObject } from '@/libs/utils/functions';
|
|
|
7
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);
|
|
@@ -50,21 +52,14 @@ export class FatcmsBaseDiskCache implements ICacheService {
|
|
|
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 {
|
|
@@ -10,16 +10,18 @@ const LRU_CACHE_MAP = new Map<string, LRUCache<string, any>>();
|
|
|
10
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 MemoryCache implements ICacheService {
|
|
|
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;
|
|
@@ -3,16 +3,17 @@ import { RedisService } from '@midwayjs/redis';
|
|
|
3
3
|
import { parseJsonObject } from '@/libs/utils/functions';
|
|
4
4
|
import { ICacheService } from '@/models/bizmodels';
|
|
5
5
|
|
|
6
|
-
|
|
7
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 RedisCache implements ICacheService {
|
|
|
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> {
|
|
@@ -11,7 +11,7 @@ import { Exceptions } from '@/libs/crud-pro/exceptions';
|
|
|
11
11
|
import { parseDatabaseName } from '@/libs/crud-pro/utils/DatabaseName';
|
|
12
12
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
13
13
|
import { IRequestCfgModel2 } from '@/models/bizmodels';
|
|
14
|
-
import {
|
|
14
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
15
15
|
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
16
16
|
import * as md5 from 'md5';
|
|
17
17
|
|
|
@@ -19,10 +19,6 @@ const linkToCustomMixUtils = new CrudMixUtils(RelatedType.linkToCustom);
|
|
|
19
19
|
const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
|
|
23
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
24
|
-
|
|
25
|
-
|
|
26
22
|
function toMapObject(rows: any[], fieldsArr: string[]): Map<string, any> {
|
|
27
23
|
const valueKey = fieldsArr[0];
|
|
28
24
|
const labelKey = fieldsArr[1];
|
|
@@ -98,11 +94,8 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
public async queryInfoByLinkToCustom(code: string): Promise<Map<string, any>> {
|
|
101
|
-
const { curdMixByCommonCacheLevel, curdMixByCommonCacheSecond } = this.ctx.workbenchInfoTools.getWorkbenchConfig();
|
|
102
97
|
return this.cacheServiceFactory.getJsonObjectCache({
|
|
103
|
-
cacheLevel: curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL,
|
|
104
98
|
cacheKey: md5(code),
|
|
105
|
-
cacheSecond: curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND,
|
|
106
99
|
cacheName: CacheNameEnum.CurdMixByLinkToCustom,
|
|
107
100
|
getter: async () => {
|
|
108
101
|
return await this.queryInfoByLinkToCustomImpl(code);
|
|
@@ -11,17 +11,12 @@ import { ColumnRelation } from '@/libs/crud-pro/interfaces';
|
|
|
11
11
|
import { parseConfigContentToEnumInfo } from '@/libs/utils/parseConfig';
|
|
12
12
|
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
13
13
|
import { CacheServiceFactory } from '../base/cache/CacheServiceFactory';
|
|
14
|
-
import {
|
|
14
|
+
import { CacheNameEnum} from "@/models/bizmodels";
|
|
15
15
|
|
|
16
16
|
const dictMixUtils = new CrudMixUtils(RelatedType.sysCfgEnum);
|
|
17
17
|
|
|
18
18
|
const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
|
|
19
19
|
|
|
20
|
-
const DEFAULT_CACHE_LEVEL = CacheLevelEnum.MEMORY;
|
|
21
|
-
const DEFAULT_CACHE_SECOND = 60 * 5;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
20
|
|
|
26
21
|
@Provide()
|
|
27
22
|
export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
@@ -35,15 +30,13 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
35
30
|
|
|
36
31
|
|
|
37
32
|
private async getFromCache(code: string): Promise<any> {
|
|
38
|
-
const
|
|
39
|
-
const cacheService = this.cacheServiceFactory.getCacheService(curdMixByCommonCacheLevel || DEFAULT_CACHE_LEVEL, CacheNameEnum.CurdMixBySysConfig);
|
|
33
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixBySysConfig);
|
|
40
34
|
return cacheService.getJsonObject(code);
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
private async setToCache(code: string, value: any): Promise<any> {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return cacheService.setJsonObject(code, value, curdMixByCommonCacheSecond || DEFAULT_CACHE_SECOND);
|
|
38
|
+
const cacheService = this.cacheServiceFactory.getCacheServiceByName(CacheNameEnum.CurdMixBySysConfig);
|
|
39
|
+
return cacheService.setJsonObject(code, value);
|
|
47
40
|
}
|
|
48
41
|
|
|
49
42
|
|
|
@@ -63,10 +56,10 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
63
56
|
return Object.values(resultRowMap);
|
|
64
57
|
}
|
|
65
58
|
|
|
66
|
-
const {
|
|
59
|
+
const {SystemDbName, SystemDbType} = GLOBAL_STATIC_CONFIG.getConfig();
|
|
67
60
|
const res1 = await this.curdProService.executeCrudByCfg(
|
|
68
61
|
{
|
|
69
|
-
condition: {
|
|
62
|
+
condition: {config_code: {$in: notCachedCodes}},
|
|
70
63
|
},
|
|
71
64
|
{
|
|
72
65
|
sqlTable: SystemTables.sys_configs,
|
|
@@ -79,12 +72,12 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
79
72
|
if (Array.isArray(rows) && rows.length > 0) {
|
|
80
73
|
for (let i = 0; i < rows.length; i++) {
|
|
81
74
|
const row = rows[i];
|
|
82
|
-
const {
|
|
75
|
+
const {config_code} = row;
|
|
83
76
|
await this.setToCache(config_code, row);
|
|
84
77
|
resultRowMap[config_code] = row;
|
|
85
78
|
}
|
|
86
79
|
}
|
|
87
|
-
return Object.values(resultRowMap)
|
|
80
|
+
return Object.values(resultRowMap)
|
|
88
81
|
}
|
|
89
82
|
|
|
90
83
|
async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
|