midway-fatcms 0.0.9 → 0.0.10
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 +2 -4
- package/dist/configuration.d.ts +10 -4
- package/dist/configuration.js +57 -12
- package/dist/controller/base/BaseApiController.d.ts +20 -1
- package/dist/controller/base/BaseApiController.js +128 -2
- package/dist/controller/helpers.controller.d.ts +5 -4
- package/dist/controller/helpers.controller.js +33 -15
- package/dist/controller/home.controller.d.ts +3 -0
- package/dist/controller/home.controller.js +13 -1
- package/dist/controller/manage/AccountRoleManageApi.d.ts +10 -0
- package/dist/controller/manage/AccountRoleManageApi.js +103 -0
- package/dist/controller/manage/AnyApiMangeApi.js +9 -2
- package/dist/controller/manage/AppLogMangeApi.js +9 -2
- package/dist/controller/manage/AppMangeApi.d.ts +0 -2
- package/dist/controller/manage/AppMangeApi.js +14 -18
- package/dist/controller/manage/AppPageMangeApi.js +9 -2
- package/dist/controller/manage/ConfigChangelogManageApi.d.ts +9 -0
- package/dist/controller/manage/ConfigChangelogManageApi.js +80 -0
- package/dist/controller/manage/CrudMethodsMangeApi.js +14 -5
- package/dist/controller/manage/DataDictManageApi.d.ts +2 -3
- package/dist/controller/manage/DataDictManageApi.js +35 -31
- package/dist/controller/manage/DeployManageApi.d.ts +0 -3
- package/dist/controller/manage/DeployManageApi.js +6 -33
- package/dist/controller/manage/DocLibManageApi.js +5 -0
- package/dist/controller/manage/DocManageApi.js +5 -0
- package/dist/controller/manage/FlowConfigManageApi.d.ts +0 -2
- package/dist/controller/manage/FlowConfigManageApi.js +5 -16
- package/dist/controller/manage/FuncManageApi.d.ts +10 -0
- package/dist/controller/manage/FuncManageApi.js +87 -0
- package/dist/controller/manage/MenuManageApi.d.ts +0 -1
- package/dist/controller/manage/MenuManageApi.js +10 -14
- package/dist/controller/manage/ProxyApiMangeApi.js +5 -3
- package/dist/controller/manage/RoleFuncManageApi.d.ts +10 -0
- package/dist/controller/manage/RoleFuncManageApi.js +102 -0
- package/dist/controller/manage/RoleManageApi.d.ts +10 -0
- package/dist/controller/manage/RoleManageApi.js +87 -0
- package/dist/controller/manage/SysConfigMangeApi.d.ts +0 -1
- package/dist/controller/manage/SysConfigMangeApi.js +13 -13
- package/dist/controller/manage/UserAccountManageApi.d.ts +0 -1
- package/dist/controller/manage/UserAccountManageApi.js +7 -15
- package/dist/controller/manage/WorkbenchMangeApi.d.ts +0 -1
- package/dist/controller/manage/WorkbenchMangeApi.js +17 -22
- package/dist/controller/render/AppRenderController.d.ts +3 -0
- package/dist/controller/render/AppRenderController.js +13 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/interface.d.ts +2 -1
- package/dist/libs/crud-pro/CrudPro.d.ts +19 -0
- package/dist/libs/crud-pro/CrudPro.js +50 -1
- package/dist/libs/crud-pro/exceptions.d.ts +9 -1
- package/dist/libs/crud-pro/exceptions.js +9 -1
- package/dist/libs/crud-pro/interfaces.d.ts +84 -47
- package/dist/libs/crud-pro/interfaces.js +2 -2
- package/dist/libs/crud-pro/models/CrudResult.d.ts +14 -1
- package/dist/libs/crud-pro/models/CrudResult.js +9 -1
- package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -0
- package/dist/libs/crud-pro/models/RequestModel.d.ts +2 -2
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +7 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +13 -2
- package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.d.ts +28 -101
- package/dist/libs/crud-pro/services/CrudProDataTypeConvertService.js +258 -151
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +18 -8
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +2 -1
- package/dist/libs/crud-pro/utils/CrudMonitor.d.ts +20 -0
- package/dist/libs/crud-pro/utils/CrudMonitor.js +40 -0
- package/dist/libs/crud-pro/utils/MemoryRefreshCache.d.ts +4 -0
- package/dist/libs/crud-pro/utils/MemoryRefreshCache.js +10 -1
- package/dist/libs/crud-pro/utils/MixinUtils.js +27 -14
- package/dist/libs/crud-pro/utils/SqlFuncUtils.d.ts +187 -2
- package/dist/libs/crud-pro/utils/SqlFuncUtils.js +204 -12
- package/dist/libs/crud-pro/utils/pool/MySQLUtils.js +9 -1
- package/dist/libs/crud-pro-quick/CrudProQuick.d.ts +22 -13
- package/dist/libs/crud-pro-quick/CrudProQuick.js +54 -26
- package/dist/middleware/cacherefresh.middleware.d.ts +47 -0
- package/dist/middleware/cacherefresh.middleware.js +74 -0
- package/dist/models/CacheRefreshCategory.d.ts +23 -0
- package/dist/models/CacheRefreshCategory.js +27 -0
- package/dist/models/FlowModel.d.ts +4 -3
- package/dist/models/RedisKeys.d.ts +1 -4
- package/dist/models/RedisKeys.js +1 -4
- package/dist/models/SystemPerm.d.ts +8 -1
- package/dist/models/SystemPerm.js +7 -0
- package/dist/models/SystemTables.d.ts +1 -0
- package/dist/models/SystemTables.js +1 -0
- package/dist/schedule/runSchedule.js +1 -1
- package/dist/schedule/scheduleNames.d.ts +2 -6
- package/dist/schedule/scheduleNames.js +3 -7
- package/dist/service/AuthService.js +1 -1
- package/dist/service/ConfigChangelogService.d.ts +69 -0
- package/dist/service/ConfigChangelogService.js +196 -0
- package/dist/service/SysAppService.js +10 -7
- package/dist/service/SysConfigService.js +6 -4
- package/dist/service/SysDictDataService.js +6 -4
- package/dist/service/SysMenuService.js +7 -5
- package/dist/service/UserSessionService.js +6 -4
- package/dist/service/WorkbenchService.js +7 -5
- package/dist/service/anyapi/AnyApiService.js +1 -1
- package/dist/service/base/cache/CacheServiceFactory.d.ts +37 -6
- package/dist/service/base/cache/CacheServiceFactory.js +52 -30
- package/dist/service/base/cache-refresh/CacheRefreshHub.d.ts +33 -0
- package/dist/service/base/cache-refresh/CacheRefreshHub.js +54 -0
- package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.d.ts +11 -0
- package/dist/service/base/cache-refresh/CacheRefreshHubScheduleService.js +26 -0
- package/dist/service/base/cache-refresh/CacheRefreshRedisSubscriber.d.ts +30 -0
- package/dist/service/base/cache-refresh/CacheRefreshRedisSubscriber.js +108 -0
- package/dist/service/curd/CurdMixByDictService.js +1 -1
- package/dist/service/curd/CurdMixByLinkToCustomService.js +3 -8
- package/dist/service/curd/CurdMixBySysConfigService.js +1 -1
- package/dist/service/curd/CurdMixByWorkbenchService.js +7 -5
- package/dist/service/curd/CurdProService.d.ts +2 -0
- package/dist/service/curd/CurdProService.js +11 -0
- package/dist/service/flow/FlowConfigService.js +6 -4
- package/dist/service/proxyapi/ProxyApiLoadService.d.ts +3 -3
- package/dist/service/proxyapi/ProxyApiLoadService.js +7 -5
- package/dist/service/proxyapi/RouteTrie.d.ts +6 -1
- package/dist/service/proxyapi/RouteTrie.js +9 -1
- package/package.json +2 -2
- package/{.qoder/skills → skills}/midway-fatcms/02-crud-quick.md +99 -9
- package/{.qoder/skills → skills}/midway-fatcms/05-configuration.md +24 -16
- package/{.qoder/skills → skills}/midway-fatcms/07-examples.md +93 -0
- package/skills/midway-fatcms/08-sqlfunc-expressions.md +484 -0
- package/skills/midway-fatcms/09-native-sql.md +301 -0
- package/{.qoder/skills → skills}/midway-fatcms/SKILL.md +3 -0
- package/src/config/config.default.ts +2 -4
- package/src/configuration.ts +66 -13
- package/src/controller/base/BaseApiController.ts +159 -3
- package/src/controller/helpers.controller.ts +35 -13
- package/src/controller/home.controller.ts +15 -1
- package/src/controller/manage/AccountRoleManageApi.ts +68 -0
- package/src/controller/manage/AnyApiMangeApi.ts +9 -2
- package/src/controller/manage/AppLogMangeApi.ts +9 -2
- package/src/controller/manage/AppMangeApi.ts +14 -18
- package/src/controller/manage/AppPageMangeApi.ts +9 -2
- package/src/controller/manage/ConfigChangelogManageApi.ts +52 -0
- package/src/controller/manage/CrudMethodsMangeApi.ts +14 -5
- package/src/controller/manage/DataDictManageApi.ts +35 -42
- package/src/controller/manage/DeployManageApi.ts +6 -25
- package/src/controller/manage/DocLibManageApi.ts +5 -0
- package/src/controller/manage/DocManageApi.ts +5 -0
- package/src/controller/manage/FlowConfigManageApi.ts +5 -19
- package/src/controller/manage/FuncManageApi.ts +52 -0
- package/src/controller/manage/MenuManageApi.ts +10 -18
- package/src/controller/manage/ProxyApiMangeApi.ts +5 -3
- package/src/controller/manage/RoleFuncManageApi.ts +67 -0
- package/src/controller/manage/RoleManageApi.ts +52 -0
- package/src/controller/manage/SysConfigMangeApi.ts +13 -12
- package/src/controller/manage/UserAccountManageApi.ts +8 -16
- package/src/controller/manage/WorkbenchMangeApi.ts +17 -26
- package/src/controller/render/AppRenderController.ts +19 -3
- package/src/index.ts +7 -0
- package/src/interface.ts +2 -1
- package/src/libs/crud-pro/CrudPro.ts +52 -2
- package/src/libs/crud-pro/exceptions.ts +10 -1
- package/src/libs/crud-pro/interfaces.ts +183 -135
- package/src/libs/crud-pro/models/CrudResult.ts +21 -0
- package/src/libs/crud-pro/models/RequestCfgModel.ts +1 -0
- package/src/libs/crud-pro/models/RequestModel.ts +2 -2
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +12 -1
- package/src/libs/crud-pro/services/CrudProDataTypeConvertService.ts +266 -167
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +18 -8
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +3 -1
- package/src/libs/crud-pro/utils/CrudMonitor.ts +54 -1
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +11 -1
- package/src/libs/crud-pro/utils/MixinUtils.ts +28 -14
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +405 -15
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +9 -1
- package/src/libs/crud-pro-quick/CrudProQuick.ts +57 -27
- package/src/middleware/cacherefresh.middleware.ts +80 -0
- package/src/models/CacheRefreshCategory.ts +24 -0
- package/src/models/FlowModel.ts +8 -3
- package/src/models/RedisKeys.ts +1 -4
- package/src/models/SystemPerm.ts +9 -1
- package/src/models/SystemTables.ts +1 -0
- package/src/schedule/runSchedule.ts +1 -1
- package/src/schedule/scheduleNames.ts +3 -7
- package/src/service/AuthService.ts +1 -1
- package/src/service/ConfigChangelogService.ts +235 -0
- package/src/service/SysAppService.ts +7 -5
- package/src/service/SysConfigService.ts +3 -2
- package/src/service/SysDictDataService.ts +3 -2
- package/src/service/SysMenuService.ts +4 -3
- package/src/service/UserSessionService.ts +4 -3
- package/src/service/WorkbenchService.ts +4 -3
- package/src/service/anyapi/AnyApiService.ts +1 -1
- package/src/service/base/cache/CacheServiceFactory.ts +84 -46
- package/src/service/base/cache-refresh/CacheRefreshHub.ts +57 -0
- package/src/service/base/cache-refresh/CacheRefreshHubScheduleService.ts +17 -0
- package/src/service/base/cache-refresh/CacheRefreshRedisSubscriber.ts +115 -0
- package/src/service/curd/CurdMixByDictService.ts +1 -1
- package/src/service/curd/CurdMixByLinkToCustomService.ts +3 -8
- package/src/service/curd/CurdMixBySysConfigService.ts +1 -1
- package/src/service/curd/CurdMixByWorkbenchService.ts +4 -3
- package/src/service/curd/CurdProService.ts +17 -0
- package/src/service/flow/FlowConfigService.ts +3 -2
- package/src/service/proxyapi/ProxyApiLoadService.ts +9 -8
- package/src/service/proxyapi/RouteTrie.ts +10 -1
- package/dist/service/TableMetaCacheRedisSubscriber.d.ts +0 -31
- package/dist/service/TableMetaCacheRedisSubscriber.js +0 -98
- package/src/service/TableMetaCacheRedisSubscriber.ts +0 -105
- /package/{.qoder/skills → skills}/midway-fatcms/01-quick-start.md +0 -0
- /package/{.qoder/skills → skills}/midway-fatcms/03-crud-sharding.md +0 -0
- /package/{.qoder/skills → skills}/midway-fatcms/04-condition-operators.md +0 -0
- /package/{.qoder/skills → skills}/midway-fatcms/06-builtin-functions.md +0 -0
|
@@ -163,11 +163,9 @@ exports.default = (appInfo) => {
|
|
|
163
163
|
fatcmsUserSessionKeepTimeSecond: 3600 * 24 * 30,
|
|
164
164
|
// 是否启用内置的定时任务
|
|
165
165
|
fatcmsScheduleService: {
|
|
166
|
-
|
|
167
|
-
workbenchService: 60 * 1000,
|
|
166
|
+
cacheRefreshHubScheduleService: 10 * 60 * 1000,
|
|
168
167
|
visitStatService: 10 * 60 * 1000,
|
|
169
|
-
asyncTaskRunnerService: 1000,
|
|
170
|
-
cacheServiceFactory: 2 * 60 * 1000, // 2分钟重新加载一次,
|
|
168
|
+
asyncTaskRunnerService: 1000, // 1s可以执行
|
|
171
169
|
},
|
|
172
170
|
// Excel导出文件的临时目录
|
|
173
171
|
fatcmsExportExcelTmpFilePath: (0, path_1.join)((0, os_1.tmpdir)(), 'fatcms-export-excel'),
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import * as koa from '@midwayjs/koa';
|
|
2
|
+
import { RedisService } from '@midwayjs/redis';
|
|
2
3
|
export declare class ContainerLifeCycle {
|
|
3
4
|
app: koa.Application;
|
|
5
|
+
redisService: RedisService;
|
|
4
6
|
onConfigLoad(): Promise<any>;
|
|
5
7
|
onReady(): Promise<void>;
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* 初始化缓存刷新的 Redis Pub/Sub 广播
|
|
8
10
|
*
|
|
9
11
|
* - 发布客户端:复用已有的 RedisService 实例
|
|
10
12
|
* - 订阅客户端:通过 duplicate() 创建独立连接
|
|
11
13
|
*
|
|
12
|
-
* 集群部署时,任意节点调用
|
|
13
|
-
* 会通过 Redis
|
|
14
|
+
* 集群部署时,任意节点调用 refreshCacheWithBroadcast()
|
|
15
|
+
* 会通过 Redis 广播通知所有节点刷新缓存。
|
|
14
16
|
*/
|
|
15
|
-
private
|
|
17
|
+
private initCacheRefreshRedis;
|
|
18
|
+
/**
|
|
19
|
+
* 注册各类型缓存的刷新器到 CacheRefreshHub
|
|
20
|
+
*/
|
|
21
|
+
private registerCacheRefreshers;
|
|
16
22
|
private startScheduleOnReady;
|
|
17
23
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -27,8 +27,14 @@ const global_middleware_1 = require("./middleware/global.middleware");
|
|
|
27
27
|
const forbidden_middleware_1 = require("./middleware/forbidden.middleware");
|
|
28
28
|
const schedule_1 = require("./schedule");
|
|
29
29
|
const crypto_utils_1 = require("./libs/utils/crypto-utils");
|
|
30
|
-
const
|
|
30
|
+
const CacheRefreshRedisSubscriber_1 = require("./service/base/cache-refresh/CacheRefreshRedisSubscriber");
|
|
31
31
|
const redis_1 = require("@midwayjs/redis");
|
|
32
|
+
const CacheRefreshHub_1 = require("./service/base/cache-refresh/CacheRefreshHub");
|
|
33
|
+
const CacheRefreshCategory_1 = require("./models/CacheRefreshCategory");
|
|
34
|
+
const CacheServiceFactory_1 = require("./service/base/cache/CacheServiceFactory");
|
|
35
|
+
const bizmodels_1 = require("./models/bizmodels");
|
|
36
|
+
const ProxyApiLoadService_1 = require("./service/proxyapi/ProxyApiLoadService");
|
|
37
|
+
const CurdProService_1 = require("./service/curd/CurdProService");
|
|
32
38
|
let ContainerLifeCycle = class ContainerLifeCycle {
|
|
33
39
|
async onConfigLoad() {
|
|
34
40
|
const config = this.app.getConfig();
|
|
@@ -56,9 +62,13 @@ let ContainerLifeCycle = class ContainerLifeCycle {
|
|
|
56
62
|
*/
|
|
57
63
|
schedule_1.ANONYMOUS_CONTEXT.setApp(this.app);
|
|
58
64
|
/**
|
|
59
|
-
*
|
|
65
|
+
* 初始化缓存刷新 Redis 广播
|
|
60
66
|
*/
|
|
61
|
-
await this.
|
|
67
|
+
await this.initCacheRefreshRedis();
|
|
68
|
+
/**
|
|
69
|
+
* 注册缓存刷新器到 CacheRefreshHub
|
|
70
|
+
*/
|
|
71
|
+
this.registerCacheRefreshers();
|
|
62
72
|
/**
|
|
63
73
|
* 启动定时任务
|
|
64
74
|
*/
|
|
@@ -70,25 +80,56 @@ let ContainerLifeCycle = class ContainerLifeCycle {
|
|
|
70
80
|
// this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
|
-
*
|
|
83
|
+
* 初始化缓存刷新的 Redis Pub/Sub 广播
|
|
74
84
|
*
|
|
75
85
|
* - 发布客户端:复用已有的 RedisService 实例
|
|
76
86
|
* - 订阅客户端:通过 duplicate() 创建独立连接
|
|
77
87
|
*
|
|
78
|
-
* 集群部署时,任意节点调用
|
|
79
|
-
* 会通过 Redis
|
|
88
|
+
* 集群部署时,任意节点调用 refreshCacheWithBroadcast()
|
|
89
|
+
* 会通过 Redis 广播通知所有节点刷新缓存。
|
|
80
90
|
*/
|
|
81
|
-
async
|
|
91
|
+
async initCacheRefreshRedis() {
|
|
82
92
|
try {
|
|
83
|
-
|
|
84
|
-
(0,
|
|
85
|
-
(0, TableMetaCacheRedisSubscriber_1.initTableMetaCacheSubscriber)(redisService);
|
|
93
|
+
(0, CacheRefreshRedisSubscriber_1.initCacheRefreshPublishClient)(this.redisService);
|
|
94
|
+
(0, CacheRefreshRedisSubscriber_1.initCacheRefreshSubscriber)(this.redisService);
|
|
86
95
|
}
|
|
87
96
|
catch (e) {
|
|
88
|
-
// Redis
|
|
89
|
-
this.app.getLogger().warn('ContainerLifeCycle ==>
|
|
97
|
+
// Redis 未配置或不可用时,降级为单节点模式(仅刷新本节点缓存)
|
|
98
|
+
this.app.getLogger().warn('ContainerLifeCycle ==> initCacheRefreshRedis Redis不可用,降级为单节点模式:', e.message);
|
|
90
99
|
}
|
|
91
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 注册各类型缓存的刷新器到 CacheRefreshHub
|
|
103
|
+
*/
|
|
104
|
+
registerCacheRefreshers() {
|
|
105
|
+
// CrudMethodConfig: 清空 CRUD 方法配置缓存(清空后下次请求时懒加载)
|
|
106
|
+
CacheRefreshHub_1.CacheRefreshHub.register(CacheRefreshCategory_1.CacheRefreshCategory.CrudMethodConfig, async (ctx) => {
|
|
107
|
+
// clearMethodCache();
|
|
108
|
+
const cacheServiceFactory = await ctx.requestContext.getAsync(CurdProService_1.CurdProService);
|
|
109
|
+
await cacheServiceFactory.loadMethodCache(ctx);
|
|
110
|
+
});
|
|
111
|
+
// TableMeta: 清空表元数据缓存(清空后下次请求时懒加载)
|
|
112
|
+
CacheRefreshHub_1.CacheRefreshHub.register(CacheRefreshCategory_1.CacheRefreshCategory.TableMeta, async (ctx) => {
|
|
113
|
+
// clearTableMetaCache();
|
|
114
|
+
const cacheServiceFactory = await ctx.requestContext.getAsync(CurdProService_1.CurdProService);
|
|
115
|
+
await cacheServiceFactory.loadTableMetaCache(ctx);
|
|
116
|
+
});
|
|
117
|
+
// CacheService: 主动重加载所有 CacheServiceFactory 管理的业务缓存
|
|
118
|
+
CacheRefreshHub_1.CacheRefreshHub.register(CacheRefreshCategory_1.CacheRefreshCategory.CacheService, async (ctx) => {
|
|
119
|
+
const cacheServiceFactory = await ctx.requestContext.getAsync(CacheServiceFactory_1.CacheServiceFactory);
|
|
120
|
+
await cacheServiceFactory.refreshAllCache(ctx);
|
|
121
|
+
});
|
|
122
|
+
// LinkToCustom: 刷新 linkToCustom 关联枚举缓存
|
|
123
|
+
CacheRefreshHub_1.CacheRefreshHub.register(CacheRefreshCategory_1.CacheRefreshCategory.LinkToCustom, async (ctx) => {
|
|
124
|
+
const cacheServiceFactory = await ctx.requestContext.getAsync(CacheServiceFactory_1.CacheServiceFactory);
|
|
125
|
+
await cacheServiceFactory.refreshByCacheName(bizmodels_1.CacheNameEnum.CurdMixByLinkToCustom, ctx);
|
|
126
|
+
});
|
|
127
|
+
// ProxyApiRoute: 重建代理API路由树(复用 ProxyApiLoadService.runBySchedule 的逻辑)
|
|
128
|
+
CacheRefreshHub_1.CacheRefreshHub.register(CacheRefreshCategory_1.CacheRefreshCategory.ProxyApiRoute, async (ctx) => {
|
|
129
|
+
const proxyApiLoadService = await ctx.requestContext.getAsync(ProxyApiLoadService_1.ProxyApiLoadService);
|
|
130
|
+
await proxyApiLoadService.refreshRouteTrie();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
92
133
|
async startScheduleOnReady() {
|
|
93
134
|
const logger = this.app.getLogger();
|
|
94
135
|
const config = this.app.getConfig();
|
|
@@ -118,6 +159,10 @@ __decorate([
|
|
|
118
159
|
(0, core_1.App)(),
|
|
119
160
|
__metadata("design:type", Object)
|
|
120
161
|
], ContainerLifeCycle.prototype, "app", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
(0, core_1.Inject)(),
|
|
164
|
+
__metadata("design:type", redis_1.RedisService)
|
|
165
|
+
], ContainerLifeCycle.prototype, "redisService", void 0);
|
|
121
166
|
ContainerLifeCycle = __decorate([
|
|
122
167
|
(0, core_1.Configuration)({
|
|
123
168
|
// namespace: 'fatcms',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
2
|
import { CurdMixService } from '../../service/curd/CurdMixService';
|
|
3
|
-
import { IFuncCfgModel, IValidatorCfgItem } from '../../libs/crud-pro/interfaces';
|
|
3
|
+
import { ColumnRelation, IFuncCfgModel, IValidatorCfgItem } from '../../libs/crud-pro/interfaces';
|
|
4
4
|
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
5
5
|
import { UserAccountService } from '../../service/UserAccountService';
|
|
6
6
|
import { BaseService } from '../../service/base/BaseService';
|
|
7
|
+
import { ConfigChangelogService } from '../../service/ConfigChangelogService';
|
|
7
8
|
export interface IExecuteSimpleSqlParams {
|
|
8
9
|
updateCfg?: Record<string, IFuncCfgModel>;
|
|
9
10
|
allowCfg?: Record<string, string[]>;
|
|
@@ -11,6 +12,7 @@ export interface IExecuteSimpleSqlParams {
|
|
|
11
12
|
validateCfg?: Record<string, IValidatorCfgItem[]>;
|
|
12
13
|
enableSoftDelete?: boolean;
|
|
13
14
|
columns?: string | string[];
|
|
15
|
+
columnsRelation?: ColumnRelation[];
|
|
14
16
|
}
|
|
15
17
|
export interface ISecretBodyAnno {
|
|
16
18
|
payload1: string;
|
|
@@ -26,6 +28,7 @@ export declare class BaseApiController extends BaseService {
|
|
|
26
28
|
protected ctx: Context;
|
|
27
29
|
protected curdMixService: CurdMixService;
|
|
28
30
|
protected userAccountService: UserAccountService;
|
|
31
|
+
protected configChangelogService: ConfigChangelogService;
|
|
29
32
|
/**
|
|
30
33
|
* 检查用户是否在指定时间内重复执行了某个操作
|
|
31
34
|
* @param actionCode 操作编码
|
|
@@ -42,6 +45,22 @@ export declare class BaseApiController extends BaseService {
|
|
|
42
45
|
* @protected
|
|
43
46
|
*/
|
|
44
47
|
protected executeSysSimpleSQL(sqlTable: string, sqlSimpleName: KeysOfSimpleSQL, extParams?: IExecuteSimpleSqlParams): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
48
|
+
/**
|
|
49
|
+
* 判断是否为写操作
|
|
50
|
+
*/
|
|
51
|
+
private isShouldLogAction;
|
|
52
|
+
/**
|
|
53
|
+
* 查询当前记录用于日志快照
|
|
54
|
+
*/
|
|
55
|
+
private queryCurrentRecordForLog;
|
|
56
|
+
/**
|
|
57
|
+
* 异步记录变更日志(不阻塞主流程)
|
|
58
|
+
*/
|
|
59
|
+
private recordChangelogAsync;
|
|
60
|
+
/**
|
|
61
|
+
* 计算两个快照之间变更的字段名列表
|
|
62
|
+
*/
|
|
63
|
+
private computeChangedFields;
|
|
45
64
|
private addAccountBasicInfoCfgModel;
|
|
46
65
|
private addWorkbenchBasicInfoCfgModel;
|
|
47
66
|
protected decodeBodyBySession<T>(body: any): Promise<any>;
|
|
@@ -23,6 +23,7 @@ const RedisKeys_1 = require("../../models/RedisKeys");
|
|
|
23
23
|
const aes_128_cbc_1 = require("aes-128-cbc");
|
|
24
24
|
const md5 = require("md5");
|
|
25
25
|
const AsymmetricCrypto_1 = require("../../libs/utils/AsymmetricCrypto");
|
|
26
|
+
const ConfigChangelogService_1 = require("../../service/ConfigChangelogService");
|
|
26
27
|
let BaseApiController = class BaseApiController extends BaseService_1.BaseService {
|
|
27
28
|
/**
|
|
28
29
|
* 检查用户是否在指定时间内重复执行了某个操作
|
|
@@ -64,6 +65,7 @@ let BaseApiController = class BaseApiController extends BaseService_1.BaseServic
|
|
|
64
65
|
* @protected
|
|
65
66
|
*/
|
|
66
67
|
async executeSysSimpleSQL(sqlTable, sqlSimpleName, extParams) {
|
|
68
|
+
var _a, _b, _c, _d;
|
|
67
69
|
const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
|
|
68
70
|
const body = this.ctx.request.body;
|
|
69
71
|
const req = this.ctx.req;
|
|
@@ -83,11 +85,131 @@ let BaseApiController = class BaseApiController extends BaseService_1.BaseServic
|
|
|
83
85
|
this.addAccountBasicInfoCfgModel(cfgModel);
|
|
84
86
|
//自动关联工作台基本信息
|
|
85
87
|
this.addWorkbenchBasicInfoCfgModel(cfgModel);
|
|
86
|
-
//sys系统表都是标准的,都有modified_at字段。
|
|
88
|
+
//sys系统表都是标准的,都有modified_at、modified_by字段。
|
|
87
89
|
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE && body.data) {
|
|
88
90
|
body.data['modified_at'] = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
91
|
+
body.data['modified_by'] = ((_a = this.getUserSessionInfo()) === null || _a === void 0 ? void 0 : _a.accountId) || 'anonymous';
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
//sys系统表都是标准的,都有created_at、created_by字段。
|
|
94
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_INSERT && body.data) {
|
|
95
|
+
body.data['created_at'] = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
96
|
+
body.data['created_by'] = ((_b = this.getUserSessionInfo()) === null || _b === void 0 ? void 0 : _b.accountId) || 'anonymous';
|
|
97
|
+
}
|
|
98
|
+
// ========== 配置变更日志自动记录 ==========
|
|
99
|
+
let beforeData = null;
|
|
100
|
+
let recordId = '';
|
|
101
|
+
const shouldLog = (0, ConfigChangelogService_1.isChangelogTable)(sqlTable) && this.isShouldLogAction(sqlSimpleName);
|
|
102
|
+
if (shouldLog) {
|
|
103
|
+
// UPDATE/DELETE 需要condition.id来定位变更记录
|
|
104
|
+
if (!((_c = body === null || body === void 0 ? void 0 : body.condition) === null || _c === void 0 ? void 0 : _c.id)) {
|
|
105
|
+
throw new exceptions_1.CommonException(`配置变更日志要求condition.id必传,当前操作: ${sqlSimpleName},表: ${sqlTable}`);
|
|
106
|
+
}
|
|
107
|
+
// UPDATE/DELETE 前查询当前记录作为 before_data
|
|
108
|
+
try {
|
|
109
|
+
beforeData = await this.queryCurrentRecordForLog(sqlTable, body);
|
|
110
|
+
recordId = String((beforeData === null || beforeData === void 0 ? void 0 : beforeData.id) || ((_d = body === null || body === void 0 ? void 0 : body.condition) === null || _d === void 0 ? void 0 : _d.id) || '');
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
this.logWarn('executeSysSimpleSQL: 查询beforeData失败,跳过日志记录', e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// 执行原操作
|
|
117
|
+
const result = await this.curdMixService.executeCrudByCfg(body, cfgModel);
|
|
118
|
+
if (shouldLog) {
|
|
119
|
+
await this.recordChangelogAsync(sqlTable, sqlSimpleName, body, beforeData, recordId, req).catch(e => {
|
|
120
|
+
this.logError('executeSysSimpleSQL: 异步记录变更日志失败', e);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 判断是否为写操作
|
|
127
|
+
*/
|
|
128
|
+
isShouldLogAction(sqlSimpleName) {
|
|
129
|
+
return [
|
|
130
|
+
keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
|
|
131
|
+
keys_1.KeysOfSimpleSQL.SIMPLE_DELETE,
|
|
132
|
+
].includes(sqlSimpleName);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 查询当前记录用于日志快照
|
|
136
|
+
*/
|
|
137
|
+
async queryCurrentRecordForLog(sqlTable, body) {
|
|
138
|
+
const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
|
|
139
|
+
const condition = body.condition || {};
|
|
140
|
+
if (!condition.id) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const result = await this.curdMixService.executeCrudByCfg({ condition: { id: condition.id } }, {
|
|
144
|
+
sqlTable,
|
|
145
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
146
|
+
sqlDatabase: SystemDbName,
|
|
147
|
+
sqlDbType: SystemDbType,
|
|
148
|
+
});
|
|
149
|
+
return result.getOneObj() || null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 异步记录变更日志(不阻塞主流程)
|
|
153
|
+
*/
|
|
154
|
+
async recordChangelogAsync(sqlTable, sqlSimpleName, body, beforeData, recordId, req) {
|
|
155
|
+
const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
|
|
156
|
+
let afterData = null;
|
|
157
|
+
let changedFields;
|
|
158
|
+
if (sqlSimpleName === keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
159
|
+
// UPDATE: 查询更新后的记录
|
|
160
|
+
const condition = body.condition || {};
|
|
161
|
+
try {
|
|
162
|
+
const result = await this.curdMixService.executeCrudByCfg({ condition: { id: condition.id } }, {
|
|
163
|
+
sqlTable,
|
|
164
|
+
sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
165
|
+
sqlDatabase: SystemDbName,
|
|
166
|
+
sqlDbType: SystemDbType,
|
|
167
|
+
});
|
|
168
|
+
afterData = result.getOneObj() || null;
|
|
169
|
+
}
|
|
170
|
+
catch (_) {
|
|
171
|
+
// 查询失败时忽略
|
|
172
|
+
}
|
|
173
|
+
// 计算变更字段
|
|
174
|
+
if (beforeData && afterData) {
|
|
175
|
+
changedFields = this.computeChangedFields(beforeData, afterData);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// DELETE: afterData 为 null
|
|
179
|
+
const actionMap = {
|
|
180
|
+
[keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE]: 'UPDATE',
|
|
181
|
+
[keys_1.KeysOfSimpleSQL.SIMPLE_DELETE]: 'DELETE',
|
|
182
|
+
};
|
|
183
|
+
await this.configChangelogService.recordChange({
|
|
184
|
+
tableName: sqlTable,
|
|
185
|
+
action: actionMap[sqlSimpleName],
|
|
186
|
+
recordId,
|
|
187
|
+
beforeData,
|
|
188
|
+
afterData,
|
|
189
|
+
changedFields,
|
|
190
|
+
requestPath: `${req.method}:${req.url}`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* 计算两个快照之间变更的字段名列表
|
|
195
|
+
*/
|
|
196
|
+
computeChangedFields(before, after) {
|
|
197
|
+
const allKeys = new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
198
|
+
//modified_at\modified_by\created_at\created_by 字段不参与比较
|
|
199
|
+
allKeys.delete('modified_at');
|
|
200
|
+
allKeys.delete('modified_by');
|
|
201
|
+
allKeys.delete('created_at');
|
|
202
|
+
allKeys.delete('created_by');
|
|
203
|
+
const changed = [];
|
|
204
|
+
for (const key of allKeys) {
|
|
205
|
+
const beforeVal = before[key];
|
|
206
|
+
const afterVal = after[key];
|
|
207
|
+
// 简单比较优先,不等时再用JSON.stringify处理对象差异
|
|
208
|
+
if (beforeVal !== afterVal && JSON.stringify(beforeVal) !== JSON.stringify(afterVal)) {
|
|
209
|
+
changed.push(key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return changed;
|
|
91
213
|
}
|
|
92
214
|
addAccountBasicInfoCfgModel(cfgModel) {
|
|
93
215
|
let columnsRelation = cfgModel.columnsRelation;
|
|
@@ -188,6 +310,10 @@ __decorate([
|
|
|
188
310
|
(0, core_1.Inject)(),
|
|
189
311
|
__metadata("design:type", UserAccountService_1.UserAccountService)
|
|
190
312
|
], BaseApiController.prototype, "userAccountService", void 0);
|
|
313
|
+
__decorate([
|
|
314
|
+
(0, core_1.Inject)(),
|
|
315
|
+
__metadata("design:type", ConfigChangelogService_1.ConfigChangelogService)
|
|
316
|
+
], BaseApiController.prototype, "configChangelogService", void 0);
|
|
191
317
|
BaseApiController = __decorate([
|
|
192
318
|
(0, core_1.Controller)('/api/BaseApiController')
|
|
193
319
|
], BaseApiController);
|
|
@@ -33,10 +33,11 @@ export declare class HelpersApi {
|
|
|
33
33
|
*/
|
|
34
34
|
cryptoAes128CBC(queryData: any): Promise<CommonResult>;
|
|
35
35
|
/**
|
|
36
|
-
* 工具函数:
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* 工具函数: 刷新缓存(集群广播)
|
|
37
|
+
* 通过 CacheRefreshHub 在 ANONYMOUS_CONTEXT 中主动重加载缓存,并通过 Redis Pub/Sub 广播通知集群中其他节点。
|
|
38
|
+
* 可通过 category 参数指定刷新的缓存类型(CacheRefreshCategory),不传则刷新全部。
|
|
39
|
+
* 可通过 cacheName 参数指定刷新的业务缓存(CacheNameEnum)。
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
refreshCacheApi(queryData: any): Promise<CommonResult>;
|
|
41
42
|
private checkLocalPermissionEnv;
|
|
42
43
|
}
|
|
@@ -21,7 +21,9 @@ const functions_1 = require("../libs/utils/functions");
|
|
|
21
21
|
const crypto_utils_1 = require("../libs/utils/crypto-utils");
|
|
22
22
|
const common_dto_1 = require("../libs/utils/common-dto");
|
|
23
23
|
const SystemPerm_1 = require("../models/SystemPerm");
|
|
24
|
-
const
|
|
24
|
+
const permission_middleware_1 = require("../middleware/permission.middleware");
|
|
25
|
+
const CacheRefreshRedisSubscriber_1 = require("../service/base/cache-refresh/CacheRefreshRedisSubscriber");
|
|
26
|
+
const CacheServiceFactory_1 = require("../service/base/cache/CacheServiceFactory");
|
|
25
27
|
// http://127.0.0.1:7002/ns/api/helpers/getApiScript?prefix=/ns/api/manage
|
|
26
28
|
// http://127.0.0.1:7002/ns/api/helpers/getApiScript
|
|
27
29
|
// http://127.0.0.1:7002/ns/api/helpers/getApiEnv
|
|
@@ -126,27 +128,42 @@ let HelpersApi = class HelpersApi {
|
|
|
126
128
|
});
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
|
-
* 工具函数:
|
|
130
|
-
*
|
|
131
|
-
*
|
|
131
|
+
* 工具函数: 刷新缓存(集群广播)
|
|
132
|
+
* 通过 CacheRefreshHub 在 ANONYMOUS_CONTEXT 中主动重加载缓存,并通过 Redis Pub/Sub 广播通知集群中其他节点。
|
|
133
|
+
* 可通过 category 参数指定刷新的缓存类型(CacheRefreshCategory),不传则刷新全部。
|
|
134
|
+
* 可通过 cacheName 参数指定刷新的业务缓存(CacheNameEnum)。
|
|
132
135
|
*/
|
|
133
|
-
async
|
|
134
|
-
const
|
|
136
|
+
async refreshCacheApi(queryData) {
|
|
137
|
+
const categoryParam = queryData.category;
|
|
138
|
+
const cacheNameParam = queryData.cacheName;
|
|
139
|
+
if (cacheNameParam) {
|
|
140
|
+
// 按 CacheNameEnum 单独刷新业务缓存
|
|
141
|
+
const cacheName = cacheNameParam;
|
|
142
|
+
const cacheServiceFactory = await this.ctx.requestContext.getAsync(CacheServiceFactory_1.CacheServiceFactory);
|
|
143
|
+
await cacheServiceFactory.refreshByCacheName(cacheName, this.ctx);
|
|
144
|
+
return common_dto_1.CommonResult.successRes({
|
|
145
|
+
message: `业务缓存 ${cacheName} 已刷新`,
|
|
146
|
+
cacheName,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const category = categoryParam ? categoryParam : undefined;
|
|
150
|
+
await (0, CacheRefreshRedisSubscriber_1.refreshCacheWithBroadcast)(this.ctx, category);
|
|
135
151
|
return common_dto_1.CommonResult.successRes({
|
|
136
|
-
message: '
|
|
137
|
-
|
|
152
|
+
message: `缓存已刷新${category ? '(' + category + ')' : '(全部)'}(已广播集群)`,
|
|
153
|
+
category: category || 'ALL',
|
|
138
154
|
});
|
|
139
155
|
}
|
|
140
156
|
checkLocalPermissionEnv() {
|
|
141
157
|
//是否是开发者
|
|
142
158
|
const isDevelopUser = () => {
|
|
143
|
-
var _a, _b;
|
|
159
|
+
var _a, _b, _c;
|
|
144
160
|
const isDevOpsWriter = (_a = this.ctx.userSession) === null || _a === void 0 ? void 0 : _a.hasRole(SystemPerm_1.SystemRoleCode.DevOpsWriter);
|
|
145
161
|
const isSuperAdmin = (_b = this.ctx.userSession) === null || _b === void 0 ? void 0 : _b.hasRole(SystemPerm_1.SystemRoleCode.SuperAdmin);
|
|
146
|
-
|
|
162
|
+
const isHelpersTools = (_c = this.ctx.userSession) === null || _c === void 0 ? void 0 : _c.hasPermission(SystemPerm_1.SystemFuncCode.HelpersTools);
|
|
163
|
+
if (isSuperAdmin || isHelpersTools || isDevOpsWriter) {
|
|
147
164
|
return true;
|
|
148
165
|
}
|
|
149
|
-
return
|
|
166
|
+
return false;
|
|
150
167
|
};
|
|
151
168
|
// 运行在本地
|
|
152
169
|
const isLocalEnv = () => {
|
|
@@ -155,7 +172,7 @@ let HelpersApi = class HelpersApi {
|
|
|
155
172
|
return env === 'local' && (host.startsWith('127.0.0.1') || host.startsWith('localhost:') || host === 'localhost');
|
|
156
173
|
};
|
|
157
174
|
if (!isLocalEnv() && !isDevelopUser()) {
|
|
158
|
-
throw new exceptions_1.CommonException(exceptions_1.Exceptions.NO_AUTH, '
|
|
175
|
+
throw new exceptions_1.CommonException(exceptions_1.Exceptions.NO_AUTH, '此测试函数,仅限本地环境或开发者调用');
|
|
159
176
|
}
|
|
160
177
|
}
|
|
161
178
|
};
|
|
@@ -195,11 +212,12 @@ __decorate([
|
|
|
195
212
|
__metadata("design:returntype", Promise)
|
|
196
213
|
], HelpersApi.prototype, "cryptoAes128CBC", null);
|
|
197
214
|
__decorate([
|
|
198
|
-
(0, core_1.Get)('/
|
|
215
|
+
(0, core_1.Get)('/refreshCache', { middleware: [(0, permission_middleware_1.checkPermission)(SystemPerm_1.SystemFuncCode.HelpersCacheRefresh)] }),
|
|
216
|
+
__param(0, (0, core_1.Query)()),
|
|
199
217
|
__metadata("design:type", Function),
|
|
200
|
-
__metadata("design:paramtypes", []),
|
|
218
|
+
__metadata("design:paramtypes", [Object]),
|
|
201
219
|
__metadata("design:returntype", Promise)
|
|
202
|
-
], HelpersApi.prototype, "
|
|
220
|
+
], HelpersApi.prototype, "refreshCacheApi", null);
|
|
203
221
|
HelpersApi = __decorate([
|
|
204
222
|
(0, core_1.Controller)('/ns/api/helpers')
|
|
205
223
|
], HelpersApi);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Context } from '@midwayjs/koa';
|
|
2
2
|
import { BaseApiController } from './base/BaseApiController';
|
|
3
3
|
import { WorkbenchService } from '../service/WorkbenchService';
|
|
4
|
+
import { ISessionInfo } from '../models/userSession';
|
|
4
5
|
export declare class HomeController extends BaseApiController {
|
|
5
6
|
protected ctx: Context;
|
|
6
7
|
protected workbenchService: WorkbenchService;
|
|
8
|
+
private authService;
|
|
7
9
|
home(): Promise<string>;
|
|
10
|
+
protected getUserAndRefreshSessionInfo(): Promise<ISessionInfo>;
|
|
8
11
|
robots(): Promise<string>;
|
|
9
12
|
}
|
|
@@ -15,6 +15,7 @@ const BaseApiController_1 = require("./base/BaseApiController");
|
|
|
15
15
|
const WorkbenchService_1 = require("../service/WorkbenchService");
|
|
16
16
|
const render_utils_1 = require("../libs/utils/render-utils");
|
|
17
17
|
const crypto_utils_1 = require("../libs/utils/crypto-utils");
|
|
18
|
+
const AuthService_1 = require("../service/AuthService");
|
|
18
19
|
let HomeController = class HomeController extends BaseApiController_1.BaseApiController {
|
|
19
20
|
async home() {
|
|
20
21
|
const host = this.ctx.request.host;
|
|
@@ -30,7 +31,7 @@ let HomeController = class HomeController extends BaseApiController_1.BaseApiCon
|
|
|
30
31
|
return this.ctx.render('404_workbench', infos);
|
|
31
32
|
}
|
|
32
33
|
const html_content = workbenchInfo.html_content || '未配置HTML模版';
|
|
33
|
-
const userInfo = this.
|
|
34
|
+
const userInfo = await this.getUserAndRefreshSessionInfo();
|
|
34
35
|
// 形如(不带域名):/ns/app/abc-app-path?aa=2332
|
|
35
36
|
const urlcsrftoken = await crypto_utils_1.privateAES.time_encrypt_utf8_base64(JSON.stringify({
|
|
36
37
|
url: this.ctx.req.url,
|
|
@@ -48,6 +49,13 @@ let HomeController = class HomeController extends BaseApiController_1.BaseApiCon
|
|
|
48
49
|
const query = this.ctx.query || {};
|
|
49
50
|
return this.ctx.renderString(html_content, { workbenchInfo, userInfo, utils, query }, { viewEngine: 'ejs' });
|
|
50
51
|
}
|
|
52
|
+
async getUserAndRefreshSessionInfo() {
|
|
53
|
+
const userSessionInfo = await this.getUserSessionInfo();
|
|
54
|
+
if (!userSessionInfo) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return await this.authService.refreshSession(userSessionInfo);
|
|
58
|
+
}
|
|
51
59
|
async robots() {
|
|
52
60
|
return `User-agent: * \nDisallow: /ns/api/manage/`;
|
|
53
61
|
}
|
|
@@ -60,6 +68,10 @@ __decorate([
|
|
|
60
68
|
(0, core_1.Inject)(),
|
|
61
69
|
__metadata("design:type", WorkbenchService_1.WorkbenchService)
|
|
62
70
|
], HomeController.prototype, "workbenchService", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, core_1.Inject)(),
|
|
73
|
+
__metadata("design:type", AuthService_1.AuthService)
|
|
74
|
+
], HomeController.prototype, "authService", void 0);
|
|
63
75
|
__decorate([
|
|
64
76
|
(0, core_1.Get)('/*'),
|
|
65
77
|
__metadata("design:type", Function),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from '@midwayjs/koa';
|
|
2
|
+
import { BaseApiController } from '../base/BaseApiController';
|
|
3
|
+
export declare class AccountRoleManageApi extends BaseApiController {
|
|
4
|
+
protected ctx: Context;
|
|
5
|
+
getAccountRoleList(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
6
|
+
getAccountRoleOne(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
7
|
+
createAccountRole(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
8
|
+
updateAccountRole(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
9
|
+
deleteAccountRole(): Promise<import("../../libs/crud-pro/models/ExecuteContext").ExecuteContext>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccountRoleManageApi = void 0;
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
|
+
const keys_1 = require("../../libs/crud-pro/models/keys");
|
|
15
|
+
const BaseApiController_1 = require("../base/BaseApiController");
|
|
16
|
+
const permission_middleware_1 = require("../../middleware/permission.middleware");
|
|
17
|
+
const cacherefresh_middleware_1 = require("../../middleware/cacherefresh.middleware");
|
|
18
|
+
const bizmodels_1 = require("../../models/bizmodels");
|
|
19
|
+
const SystemPerm_1 = require("../../models/SystemPerm");
|
|
20
|
+
const CurdMixUtils_1 = require("../../service/curd/CurdMixUtils");
|
|
21
|
+
let AccountRoleManageApi = class AccountRoleManageApi extends BaseApiController_1.BaseApiController {
|
|
22
|
+
async getAccountRoleList() {
|
|
23
|
+
return this.executeSysSimpleSQL('sys_perm_user_role', keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE, {
|
|
24
|
+
columnsRelation: [
|
|
25
|
+
{
|
|
26
|
+
relatedType: CurdMixUtils_1.RelatedType.accountBasic,
|
|
27
|
+
sourceColumn: 'account_id',
|
|
28
|
+
targetColumns: [], // 默认: account_id_user.nick_name / .avatar / .account_id
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
relatedType: CurdMixUtils_1.RelatedType.linkToCustom,
|
|
32
|
+
relatedCode: 'fatcms~~~sys_perm_role~~~role_code,role_name,id',
|
|
33
|
+
sourceColumn: 'role_code',
|
|
34
|
+
targetColumns: [], // 默认: role_code_info = { role_code, role_name }
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async getAccountRoleOne() {
|
|
40
|
+
return this.executeSysSimpleSQL('sys_perm_user_role', keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
|
|
41
|
+
}
|
|
42
|
+
async createAccountRole() {
|
|
43
|
+
return this.executeSysSimpleSQL('sys_perm_user_role', keys_1.KeysOfSimpleSQL.SIMPLE_INSERT, {
|
|
44
|
+
validateCfg: {
|
|
45
|
+
'data.account_id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.STRING],
|
|
46
|
+
'data.role_code': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.STRING],
|
|
47
|
+
'data.status': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async updateAccountRole() {
|
|
52
|
+
return this.executeSysSimpleSQL('sys_perm_user_role', keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE, {
|
|
53
|
+
validateCfg: {
|
|
54
|
+
'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async deleteAccountRole() {
|
|
59
|
+
return this.executeSysSimpleSQL('sys_perm_user_role', keys_1.KeysOfSimpleSQL.SIMPLE_DELETE, {
|
|
60
|
+
validateCfg: {
|
|
61
|
+
'condition.id': [keys_1.KeysOfValidators.REQUIRED, keys_1.KeysOfValidators.NUMERIC],
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, core_1.Inject)(),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], AccountRoleManageApi.prototype, "ctx", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
(0, core_1.Post)('/getAccountRoleList'),
|
|
72
|
+
__metadata("design:type", Function),
|
|
73
|
+
__metadata("design:paramtypes", []),
|
|
74
|
+
__metadata("design:returntype", Promise)
|
|
75
|
+
], AccountRoleManageApi.prototype, "getAccountRoleList", null);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, core_1.Post)('/getAccountRoleOne'),
|
|
78
|
+
__metadata("design:type", Function),
|
|
79
|
+
__metadata("design:paramtypes", []),
|
|
80
|
+
__metadata("design:returntype", Promise)
|
|
81
|
+
], AccountRoleManageApi.prototype, "getAccountRoleOne", null);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, core_1.Post)('/createAccountRole', { middleware: [(0, permission_middleware_1.checkPermission)(SystemPerm_1.SystemFuncCode.AccountRoleManageWrite), (0, cacherefresh_middleware_1.refreshCache)(bizmodels_1.CacheNameEnum.CurdMixByAccount)] }),
|
|
84
|
+
__metadata("design:type", Function),
|
|
85
|
+
__metadata("design:paramtypes", []),
|
|
86
|
+
__metadata("design:returntype", Promise)
|
|
87
|
+
], AccountRoleManageApi.prototype, "createAccountRole", null);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, core_1.Post)('/updateAccountRole', { middleware: [(0, permission_middleware_1.checkPermission)(SystemPerm_1.SystemFuncCode.AccountRoleManageWrite), (0, cacherefresh_middleware_1.refreshCache)(bizmodels_1.CacheNameEnum.CurdMixByAccount)] }),
|
|
90
|
+
__metadata("design:type", Function),
|
|
91
|
+
__metadata("design:paramtypes", []),
|
|
92
|
+
__metadata("design:returntype", Promise)
|
|
93
|
+
], AccountRoleManageApi.prototype, "updateAccountRole", null);
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, core_1.Post)('/deleteAccountRole', { middleware: [(0, permission_middleware_1.checkPermission)(SystemPerm_1.SystemFuncCode.AccountRoleManageWrite), (0, cacherefresh_middleware_1.refreshCache)(bizmodels_1.CacheNameEnum.CurdMixByAccount)] }),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", []),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], AccountRoleManageApi.prototype, "deleteAccountRole", null);
|
|
100
|
+
AccountRoleManageApi = __decorate([
|
|
101
|
+
(0, core_1.Controller)('/ns/api/manage/accountRole', { middleware: [(0, permission_middleware_1.checkPermission)(SystemPerm_1.SystemFuncCode.AccountRoleManageRead)] })
|
|
102
|
+
], AccountRoleManageApi);
|
|
103
|
+
exports.AccountRoleManageApi = AccountRoleManageApi;
|