midway-fatcms 0.0.1-beta.26 → 0.0.1-beta.28
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/controller/home.controller.js +2 -1
- package/dist/controller/render/AppRenderController.js +2 -1
- package/dist/models/bizmodels.d.ts +1 -0
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +1 -1
- package/dist/service/crudstd/CrudStdService.d.ts +0 -6
- package/dist/service/crudstd/CrudStdService.js +13 -33
- package/package.json +1 -5
- package/src/config/config.default.ts +0 -207
- package/src/config/seed/aeskey.txt +0 -1
- package/src/config/utils.ts +0 -22
- package/src/configuration.ts +0 -109
- package/src/controller/base/BaseApiController.ts +0 -170
- package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
- package/src/controller/gateway/AsyncTaskController.ts +0 -157
- package/src/controller/gateway/CrudMtdGatewayController.ts +0 -111
- package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
- package/src/controller/gateway/DocGatewayController.ts +0 -173
- package/src/controller/gateway/FileController.ts +0 -109
- package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
- package/src/controller/gateway/PublicApiController.ts +0 -142
- package/src/controller/gateway/StaticController.ts +0 -298
- package/src/controller/helpers.controller.ts +0 -161
- package/src/controller/home.controller.ts +0 -64
- package/src/controller/manage/AnyApiMangeApi.ts +0 -66
- package/src/controller/manage/AppLogMangeApi.ts +0 -53
- package/src/controller/manage/AppMangeApi.ts +0 -53
- package/src/controller/manage/AppPageMangeApi.ts +0 -52
- package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
- package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
- package/src/controller/manage/CrudStandardDesignApi.ts +0 -346
- package/src/controller/manage/DataDictManageApi.ts +0 -78
- package/src/controller/manage/DeployManageApi.ts +0 -175
- package/src/controller/manage/DocLibManageApi.ts +0 -69
- package/src/controller/manage/DocManageApi.ts +0 -99
- package/src/controller/manage/FileManageApi.ts +0 -45
- package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
- package/src/controller/manage/MenuManageApi.ts +0 -58
- package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
- package/src/controller/manage/SuperAdminManageApi.ts +0 -139
- package/src/controller/manage/SysConfigMangeApi.ts +0 -95
- package/src/controller/manage/SystemInfoManageApi.ts +0 -53
- package/src/controller/manage/UserAccountManageApi.ts +0 -94
- package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
- package/src/controller/myinfo/AuthController.ts +0 -108
- package/src/controller/myinfo/MyInfoController.ts +0 -32
- package/src/controller/render/AppRenderController.ts +0 -79
- package/src/controller/test.controller.ts +0 -37
- package/src/filter/default.filter.ts +0 -13
- package/src/filter/notfound.filter.ts +0 -10
- package/src/index.ts +0 -106
- package/src/interface.ts +0 -31
- package/src/libs/crud-pro/CrudPro.ts +0 -165
- package/src/libs/crud-pro/defaultConfigs.ts +0 -15
- package/src/libs/crud-pro/exceptions.ts +0 -124
- package/src/libs/crud-pro/interfaces.ts +0 -190
- package/src/libs/crud-pro/models/ExecuteContext.ts +0 -120
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -96
- package/src/libs/crud-pro/models/FuncContext.ts +0 -21
- package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
- package/src/libs/crud-pro/models/RequestModel.ts +0 -141
- package/src/libs/crud-pro/models/ResModel.ts +0 -19
- package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
- package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
- package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
- package/src/libs/crud-pro/models/Transaction.ts +0 -73
- package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
- package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -102
- package/src/libs/crud-pro/models/keys.ts +0 -159
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -83
- package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -262
- package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
- package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -354
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -185
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -393
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -94
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -86
- package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
- package/src/libs/crud-pro/sql.txt +0 -120
- package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
- package/src/libs/crud-pro/utils/DatabaseName.ts +0 -60
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
- package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
- package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
- package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
- package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
- package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
- package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
- package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
- package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -165
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +0 -26
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
- package/src/libs/global-config/global-config.ts +0 -78
- package/src/libs/utils/common-dto.ts +0 -52
- package/src/libs/utils/crypto-utils.ts +0 -50
- package/src/libs/utils/errorToString.ts +0 -61
- package/src/libs/utils/fatcms-request.ts +0 -103
- package/src/libs/utils/functions.ts +0 -73
- package/src/libs/utils/ordernum-utils.ts +0 -14
- package/src/libs/utils/parseConfig.ts +0 -54
- package/src/libs/utils/parseCreateSql.ts +0 -91
- package/src/libs/utils/render-utils.ts +0 -184
- package/src/middleware/forbidden.middleware.ts +0 -52
- package/src/middleware/global.middleware.ts +0 -280
- package/src/middleware/permission.middleware.ts +0 -80
- package/src/middleware/tx.middleware.ts +0 -30
- package/src/models/AsyncTaskModel.ts +0 -82
- package/src/models/RedisKeys.ts +0 -13
- package/src/models/SystemEntities.ts +0 -115
- package/src/models/SystemPerm.ts +0 -105
- package/src/models/SystemTables.ts +0 -27
- package/src/models/bizmodels.ts +0 -120
- package/src/models/contextLogger.ts +0 -132
- package/src/models/devops.ts +0 -17
- package/src/models/userSession.ts +0 -216
- package/src/schedule/anonymousContext.ts +0 -73
- package/src/schedule/index.ts +0 -12
- package/src/schedule/runSchedule.ts +0 -82
- package/src/schedule/scheduleNames.ts +0 -21
- package/src/service/AuthService.ts +0 -272
- package/src/service/EnumInfoService.ts +0 -130
- package/src/service/FileCenterService.ts +0 -395
- package/src/service/SysConfigService.ts +0 -37
- package/src/service/UserAccountService.ts +0 -107
- package/src/service/UserSessionService.ts +0 -78
- package/src/service/VisitStatService.ts +0 -166
- package/src/service/WorkbenchService.ts +0 -165
- package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
- package/src/service/anyapi/AnyApiService.ts +0 -186
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +0 -266
- package/src/service/asyncTask/AsyncTaskService.ts +0 -21
- package/src/service/asyncTask/handler/ExcelInfoModel.ts +0 -11
- package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +0 -245
- package/src/service/asyncTask/handler/ExportExcelByInnerHttpHandler.ts +0 -147
- package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -138
- package/src/service/base/ApiBaseService.ts +0 -42
- package/src/service/base/ApiRateLimiter.ts +0 -59
- package/src/service/base/BaseService.ts +0 -100
- package/src/service/base/RedisCacheService.ts +0 -38
- package/src/service/crudstd/CrudStdActionService.ts +0 -27
- package/src/service/crudstd/CrudStdConstant.ts +0 -62
- package/src/service/crudstd/CrudStdRelationService.ts +0 -78
- package/src/service/crudstd/CrudStdService.ts +0 -283
- package/src/service/curd/CrudProQuick.ts +0 -131
- package/src/service/curd/CurdMixByAccountService.ts +0 -90
- package/src/service/curd/CurdMixByDictService.ts +0 -114
- package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -219
- package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
- package/src/service/curd/CurdMixByWorkbenchService.ts +0 -71
- package/src/service/curd/CurdMixService.ts +0 -97
- package/src/service/curd/CurdMixUtils.ts +0 -311
- package/src/service/curd/CurdProService.ts +0 -229
- package/src/service/curd/fixCfgModel.ts +0 -139
- package/src/service/proxyapi/ProxyApiLoadService.ts +0 -174
- package/src/service/proxyapi/ProxyApiService.ts +0 -262
- package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
- package/src/service/proxyapi/RouteHandler.ts +0 -8
- package/src/service/proxyapi/RouteTrie.ts +0 -74
- package/src/service/proxyapi/WeightedRandom.ts +0 -37
- package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
- package/src/views/404_app.html +0 -31
- package/src/views/404_workbench.html +0 -34
- package/src/views/static/favicon.ico +0 -0
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { Controller, Inject } from '@midwayjs/core';
|
|
2
|
-
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { CurdMixService } from '@/service/curd/CurdMixService';
|
|
4
|
-
import { IFuncCfgModel, IRequestCfgModel, IValidatorCfgItem } from '@/libs/crud-pro/interfaces';
|
|
5
|
-
import { KeyOfCrudTypes, KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
6
|
-
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
7
|
-
import { UserAccountService } from '@/service/UserAccountService';
|
|
8
|
-
import { RelatedType } from '@/service/curd/CurdMixUtils';
|
|
9
|
-
import { BaseService } from '@/service/base/BaseService';
|
|
10
|
-
import * as moment from 'moment';
|
|
11
|
-
import { CommonException } from '@/libs/crud-pro/exceptions';
|
|
12
|
-
import { RedisKeys } from '@/models/RedisKeys';
|
|
13
|
-
|
|
14
|
-
export interface IExecuteSimpleSqlParams {
|
|
15
|
-
updateCfg?: Record<string, IFuncCfgModel>;
|
|
16
|
-
allowCfg?: Record<string, string[]>;
|
|
17
|
-
rejectCfg?: Record<string, string[]>;
|
|
18
|
-
validateCfg?: Record<string, IValidatorCfgItem[]>;
|
|
19
|
-
columns?: string | string[]; // ..."columns": "id,name,age,sex,addr",
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Controller('/api/BaseApiController')
|
|
23
|
-
export class BaseApiController extends BaseService {
|
|
24
|
-
@Inject()
|
|
25
|
-
protected ctx: Context;
|
|
26
|
-
|
|
27
|
-
@Inject()
|
|
28
|
-
protected curdMixService: CurdMixService;
|
|
29
|
-
|
|
30
|
-
@Inject()
|
|
31
|
-
protected userAccountService: UserAccountService;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 检查用户是否在指定时间内重复执行了某个操作
|
|
35
|
-
* @param actionCode 操作编码
|
|
36
|
-
* @param limitSecond 限制时间,单位:秒
|
|
37
|
-
*/
|
|
38
|
-
protected async checkUserActionTimeLimit(actionCode: string, limitSecond = 60) {
|
|
39
|
-
const userSessionInfo = this.getUserSessionInfo();
|
|
40
|
-
if (!userSessionInfo) {
|
|
41
|
-
throw new CommonException('USER_SESSION_INFO_IS_NOT_EXIST', '用户会话信息不存在');
|
|
42
|
-
}
|
|
43
|
-
const key = `${RedisKeys.USER_ACTION_TIME_LIMIT_PREFIX}${userSessionInfo.sessionId}_${actionCode}`;
|
|
44
|
-
const lock = await this.redisService.set(key, 1, 'EX', limitSecond, 'NX');
|
|
45
|
-
if (lock !== 'OK') {
|
|
46
|
-
throw new CommonException('TOO_MANY_REQUESTS_PLEASE_WAIT', `您操作太频繁了,请${limitSecond}秒后再试`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
protected getUserSessionInfo() {
|
|
51
|
-
if (!this.ctx.userSession) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return this.ctx.userSession.getSessionInfo();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async executeSysSQL(executeSql: string, executeSqlArgs: any[]) {
|
|
58
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
59
|
-
return await this.curdMixService.executeSQL({
|
|
60
|
-
executeSql: executeSql,
|
|
61
|
-
executeSqlArgs: executeSqlArgs,
|
|
62
|
-
sqlDatabase: SystemDbName,
|
|
63
|
-
sqlDbType: SystemDbType,
|
|
64
|
-
crudType: KeyOfCrudTypes.SYS_QUERY,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 查询sys表中的SQL语句。sys表的表结构都是标准的。
|
|
70
|
-
* @param sqlTable
|
|
71
|
-
* @param sqlSimpleName
|
|
72
|
-
* @param params
|
|
73
|
-
* @protected
|
|
74
|
-
*/
|
|
75
|
-
protected async executeSysSimpleSQL(sqlTable: string, sqlSimpleName: KeysOfSimpleSQL, params?: IExecuteSimpleSqlParams) {
|
|
76
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
77
|
-
const body = this.ctx.request.body as any;
|
|
78
|
-
const req = this.ctx.req;
|
|
79
|
-
const cfgModel: IRequestCfgModel = {
|
|
80
|
-
method: `${req.method}:${req.url}`,
|
|
81
|
-
sqlTable,
|
|
82
|
-
sqlSimpleName,
|
|
83
|
-
sqlDatabase: SystemDbName,
|
|
84
|
-
sqlDbType: SystemDbType,
|
|
85
|
-
updateCfg: {},
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (params && typeof params === 'object') {
|
|
89
|
-
Object.assign(cfgModel, params);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
//自动关联用户基本信息
|
|
93
|
-
this.addAccountBasicInfoCfgModel(cfgModel);
|
|
94
|
-
|
|
95
|
-
//自动关联工作台基本信息
|
|
96
|
-
this.addWorkbenchBasicInfoCfgModel(cfgModel);
|
|
97
|
-
|
|
98
|
-
//sys系统表都是标准的,都有modified_at字段。
|
|
99
|
-
if (sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE && body.data) {
|
|
100
|
-
body.data['modified_at'] = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss.SSS');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return await this.curdMixService.executeCrudByCfg(body, cfgModel);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
protected get sysDBUtil() {
|
|
107
|
-
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
108
|
-
return this.curdMixService.getBbUtil(SystemDbName, SystemDbType);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private addAccountBasicInfoCfgModel(cfgModel: IRequestCfgModel) {
|
|
112
|
-
let columnsRelation = cfgModel.columnsRelation;
|
|
113
|
-
if (!columnsRelation) {
|
|
114
|
-
columnsRelation = [];
|
|
115
|
-
cfgModel.columnsRelation = columnsRelation;
|
|
116
|
-
}
|
|
117
|
-
let createdByRelation = columnsRelation.find(s => s.relatedType === RelatedType.accountBasic && s.sourceColumn === 'created_by');
|
|
118
|
-
if (!createdByRelation) {
|
|
119
|
-
createdByRelation = {
|
|
120
|
-
relatedType: RelatedType.accountBasic,
|
|
121
|
-
sourceColumn: 'created_by',
|
|
122
|
-
targetColumns: [], // 使用默认
|
|
123
|
-
};
|
|
124
|
-
columnsRelation.push(createdByRelation);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let modifiedByRelation = columnsRelation.find(s => s.relatedType === RelatedType.accountBasic && s.sourceColumn === 'modified_by');
|
|
128
|
-
if (!modifiedByRelation) {
|
|
129
|
-
modifiedByRelation = {
|
|
130
|
-
relatedType: RelatedType.accountBasic,
|
|
131
|
-
sourceColumn: 'modified_by',
|
|
132
|
-
targetColumns: [], // 使用默认
|
|
133
|
-
};
|
|
134
|
-
columnsRelation.push(modifiedByRelation);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private addWorkbenchBasicInfoCfgModel(cfgModel: IRequestCfgModel) {
|
|
139
|
-
let columnsRelation = cfgModel.columnsRelation;
|
|
140
|
-
if (!columnsRelation) {
|
|
141
|
-
columnsRelation = [];
|
|
142
|
-
cfgModel.columnsRelation = columnsRelation;
|
|
143
|
-
}
|
|
144
|
-
let createdByRelation = columnsRelation.find(s => s.relatedType === RelatedType.workbenchBasic && s.sourceColumn === 'workbench_code');
|
|
145
|
-
if (!createdByRelation) {
|
|
146
|
-
createdByRelation = {
|
|
147
|
-
relatedType: RelatedType.workbenchBasic,
|
|
148
|
-
sourceColumn: 'workbench_code',
|
|
149
|
-
targetColumns: [
|
|
150
|
-
{ from: 'workbench_domain', to: 'workbench_info.workbench_domain' },
|
|
151
|
-
{ from: 'workbench_name', to: 'workbench_info.workbench_name' },
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
columnsRelation.push(createdByRelation);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
let createdByRelation2 = columnsRelation.find(s => s.relatedType === RelatedType.workbenchBasic && s.sourceColumn === 'workbench_code_array');
|
|
158
|
-
if (!createdByRelation2) {
|
|
159
|
-
createdByRelation2 = {
|
|
160
|
-
relatedType: RelatedType.workbenchBasic,
|
|
161
|
-
sourceColumn: 'workbench_code_array',
|
|
162
|
-
targetColumns: [
|
|
163
|
-
{ from: 'workbench_domain', to: 'workbench_info_array[$ARRAY_INDEX].workbench_domain' },
|
|
164
|
-
{ from: 'workbench_name', to: 'workbench_info_array[$ARRAY_INDEX].workbench_name' },
|
|
165
|
-
],
|
|
166
|
-
};
|
|
167
|
-
columnsRelation.push(createdByRelation2);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { All, Controller, Inject, Param } from '@midwayjs/core';
|
|
2
|
-
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { BaseApiController } from '../base/BaseApiController';
|
|
4
|
-
import * as _ from 'lodash';
|
|
5
|
-
import { AnyApiService } from '@/service/anyapi/AnyApiService';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* FaaS方式配置的接口
|
|
9
|
-
*/
|
|
10
|
-
@Controller('/ns/gw/anyApi')
|
|
11
|
-
export class AnyApiGatewayController extends BaseApiController {
|
|
12
|
-
@Inject()
|
|
13
|
-
protected ctx: Context;
|
|
14
|
-
|
|
15
|
-
@Inject()
|
|
16
|
-
private anyApiService: AnyApiService;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 执行配置出来的接口的接口。此接口本身不需要鉴权。鉴权信息在配置中由curdPro底层进行鉴权
|
|
20
|
-
*/
|
|
21
|
-
@All('/execute/:methodCode')
|
|
22
|
-
async executeAnyApiMethod(@Param('methodCode') methodCode: string) {
|
|
23
|
-
if (!methodCode) {
|
|
24
|
-
throw 'method参数不存在';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const headers = _.get(this.ctx, 'request.headers') || {};
|
|
28
|
-
const body = _.get(this.ctx, 'request.body') || {};
|
|
29
|
-
const query = this.ctx.query || {};
|
|
30
|
-
|
|
31
|
-
return await this.anyApiService.executeAnyApiMethod(methodCode, headers, body, query);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as fs2 from 'node:fs/promises';
|
|
3
|
-
import { Controller, Inject, Post, Query, Get } from '@midwayjs/core';
|
|
4
|
-
import { Context } from '@midwayjs/koa';
|
|
5
|
-
import { BaseApiController } from '../base/BaseApiController';
|
|
6
|
-
import { AsyncTaskService } from '@/service/asyncTask/AsyncTaskService';
|
|
7
|
-
import { SysAsyncTaskEntity, SysAsyncTaskStatus } from '@/models/AsyncTaskModel';
|
|
8
|
-
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
9
|
-
import { SystemTables } from '@/models/SystemTables';
|
|
10
|
-
import { CommonException } from '@/libs/crud-pro/exceptions';
|
|
11
|
-
import { checkLogin } from '@/middleware/permission.middleware';
|
|
12
|
-
import { parseJsonObject } from '@/libs/utils/functions';
|
|
13
|
-
|
|
14
|
-
function fixMyTasksCondition(body: any, ctx: Context) {
|
|
15
|
-
if (!body.condition) {
|
|
16
|
-
throw new CommonException('参数不正确');
|
|
17
|
-
}
|
|
18
|
-
body.condition.created_by = ctx.userSession.getSessionInfo().accountId;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function fixCancelBodyData(body: any, id: number) {
|
|
22
|
-
if (!body.data || !body.condition) {
|
|
23
|
-
throw new CommonException('参数不正确');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// fix condition
|
|
27
|
-
const conditionObj: SysAsyncTaskEntity = (body.condition || {}) as any;
|
|
28
|
-
conditionObj.id = id;
|
|
29
|
-
body.condition = conditionObj;
|
|
30
|
-
|
|
31
|
-
// fix data
|
|
32
|
-
const dataObj: SysAsyncTaskEntity = (body.data || {}) as any;
|
|
33
|
-
dataObj.task_status = SysAsyncTaskStatus.CANCELLED;
|
|
34
|
-
body.data = dataObj;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function fixCreateBodyData(body: any, ctx: Context) {
|
|
38
|
-
if (!body.data) {
|
|
39
|
-
throw new CommonException('参数不正确');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const sessionInfo = ctx.userSession.getSessionInfo();
|
|
43
|
-
// fix data
|
|
44
|
-
const dataObj: SysAsyncTaskEntity = (body.data || {}) as any;
|
|
45
|
-
const input_params = parseJsonObject(dataObj.input_params) || {};
|
|
46
|
-
const headers = ctx.headers || {};
|
|
47
|
-
input_params.headers = {
|
|
48
|
-
fatcmscsrftoken: headers.fatcmscsrftoken,
|
|
49
|
-
host: headers.host,
|
|
50
|
-
origin: headers.origin,
|
|
51
|
-
};
|
|
52
|
-
dataObj.task_status = SysAsyncTaskStatus.PENDING;
|
|
53
|
-
dataObj.created_by = sessionInfo.accountId;
|
|
54
|
-
dataObj.created_user_session = JSON.stringify(sessionInfo); // 创建人的session信息。用于执行时的鉴权。
|
|
55
|
-
dataObj.input_params = JSON.stringify(input_params);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 异步任务框架
|
|
60
|
-
*/
|
|
61
|
-
@Controller('/ns/gw/AsyncTask', { middleware: [checkLogin()] })
|
|
62
|
-
export class AsyncTaskController extends BaseApiController {
|
|
63
|
-
@Inject()
|
|
64
|
-
protected ctx: Context;
|
|
65
|
-
|
|
66
|
-
@Inject()
|
|
67
|
-
private asyncTaskService: AsyncTaskService;
|
|
68
|
-
|
|
69
|
-
// 获取任务列表
|
|
70
|
-
@Post('/getMyTasks')
|
|
71
|
-
async getMyTasks() {
|
|
72
|
-
fixMyTasksCondition(this.ctx.request.body, this.ctx);
|
|
73
|
-
return this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 创建任务
|
|
77
|
-
@Post('/createTask')
|
|
78
|
-
async createTask() {
|
|
79
|
-
//每个用户:5秒内只能创建1次任务
|
|
80
|
-
await this.checkUserActionTimeLimit('AsyncTaskController_createTask', 5);
|
|
81
|
-
|
|
82
|
-
fixCreateBodyData(this.ctx.request.body, this.ctx);
|
|
83
|
-
const res = await this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
84
|
-
await this.asyncTaskService.startTask();
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// 取消任务
|
|
89
|
-
@Post('/cancelTask')
|
|
90
|
-
async cancelTask(@Query('id') id: number) {
|
|
91
|
-
fixCancelBodyData(this.ctx.request.body, id);
|
|
92
|
-
await this.asyncTaskService.cancelTask(id);
|
|
93
|
-
await this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_UPDATE);
|
|
94
|
-
return { success: true };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 下载异步任务的导出文件
|
|
98
|
-
@Get('/downloadExportFile')
|
|
99
|
-
async downloadExportFile(@Query('task_uuid') task_uuid: string, @Query('id') id: string) {
|
|
100
|
-
if (!task_uuid) {
|
|
101
|
-
throw new CommonException('task_uuid is not exist');
|
|
102
|
-
}
|
|
103
|
-
if (!id) {
|
|
104
|
-
throw new CommonException('id is not exist');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.ctx.request.body = {
|
|
108
|
-
condition: {
|
|
109
|
-
task_uuid: task_uuid,
|
|
110
|
-
id: id,
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
const res = await this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
|
|
114
|
-
const taskObj: SysAsyncTaskEntity = res.getOneObj();
|
|
115
|
-
if (!taskObj) {
|
|
116
|
-
throw new CommonException('任务不存在');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const output_file_path = taskObj.output_file_path;
|
|
120
|
-
if (!output_file_path) {
|
|
121
|
-
throw new CommonException('导出文件不存在, 可能是任务没有执行完成');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
await fs2.access(output_file_path);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
throw new CommonException('导出文件不存在,可能是文件被删除了。');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
await this.responseLocalFileForAsyncTask(taskObj);
|
|
131
|
-
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 响应异步任务的导出文件
|
|
137
|
-
* @param taskObj
|
|
138
|
-
*/
|
|
139
|
-
private async responseLocalFileForAsyncTask(taskObj: SysAsyncTaskEntity): Promise<void> {
|
|
140
|
-
const output_file_path = taskObj.output_file_path;
|
|
141
|
-
const outputFileName = taskObj.task_name + '_' + taskObj.id + '.' + taskObj.output_file_format;
|
|
142
|
-
|
|
143
|
-
const stat = await fs2.stat(output_file_path);
|
|
144
|
-
const headers = {
|
|
145
|
-
'content-length': '' + stat.size,
|
|
146
|
-
'content-type': 'application/octet-stream',
|
|
147
|
-
'content-disposition': `attachment; filename*=UTF-8''${encodeURIComponent(outputFileName)}`,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const stream = fs.createReadStream(output_file_path);
|
|
151
|
-
stream.setMaxListeners(50);
|
|
152
|
-
this.logInfo(`[AsyncTaskController]返回本地文件: ${output_file_path}`);
|
|
153
|
-
this.ctx.status = 200;
|
|
154
|
-
this.ctx.set(headers);
|
|
155
|
-
this.ctx.body = stream;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as _ from 'lodash';
|
|
2
|
-
import { decamelizeKeys } from 'humps';
|
|
3
|
-
import { Controller, Inject, Param, All } from '@midwayjs/core';
|
|
4
|
-
import { Context } from '@midwayjs/koa';
|
|
5
|
-
import { CommonResult } from '@/libs/utils/common-dto';
|
|
6
|
-
import { WorkbenchService } from '@/service/WorkbenchService';
|
|
7
|
-
import { API_BASE_TYPE, ApiBaseService } from '@/service/base/ApiBaseService';
|
|
8
|
-
import { CurdProService } from '@/service/curd/CurdProService';
|
|
9
|
-
import { CurdMixService } from '@/service/curd/CurdMixService';
|
|
10
|
-
import { IRequestCfgModel2 } from '@/models/bizmodels';
|
|
11
|
-
import { parseDatabaseName } from '@/libs/crud-pro/utils/DatabaseName';
|
|
12
|
-
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
13
|
-
|
|
14
|
-
const QUERY_AS_LIST = ['condition', 'data'];
|
|
15
|
-
|
|
16
|
-
function pickAsQuery(query_as_pick: string, query: any): any {
|
|
17
|
-
if (query_as_pick && typeof query_as_pick === 'string') {
|
|
18
|
-
const pickArray = query_as_pick.split(',');
|
|
19
|
-
return _.pick(query, pickArray);
|
|
20
|
-
}
|
|
21
|
-
return query;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// /ns/gw/crudApi/getUser?__query_as_condition__=id&_query_as_data__=name&&id=1&name=22
|
|
25
|
-
/**
|
|
26
|
-
* query形式1:GET: /ns/gw/crudApi/getUser?__query_json__=%7B%22condition%22%3A%7B%22id%22%3A2%7D%7D
|
|
27
|
-
* query形式2:GET: /ns/gw/crudApi/getUser?__query_as__=condition&id=1&name=22
|
|
28
|
-
* query形式3:GET: /ns/gw/crudApi/createUser?__query_as__=data&__query_pick__=id,name&id=1&name=22
|
|
29
|
-
*
|
|
30
|
-
* 执行单个配置的接口
|
|
31
|
-
*/
|
|
32
|
-
@Controller('/ns/gw/crudApi')
|
|
33
|
-
export class CrudMtdGatewayController extends ApiBaseService {
|
|
34
|
-
@Inject()
|
|
35
|
-
protected ctx: Context;
|
|
36
|
-
|
|
37
|
-
@Inject()
|
|
38
|
-
protected workbenchService: WorkbenchService;
|
|
39
|
-
|
|
40
|
-
@Inject()
|
|
41
|
-
private curdProService: CurdProService;
|
|
42
|
-
|
|
43
|
-
@Inject()
|
|
44
|
-
private curdMixService: CurdMixService;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 执行配置出来的接口的接口。此接口本身不需要鉴权。鉴权信息在配置中由curdPro底层进行鉴权
|
|
48
|
-
*/
|
|
49
|
-
@All('/execute/:methodCode')
|
|
50
|
-
async executeCrudMethod(@Param('methodCode') methodCode: string) {
|
|
51
|
-
if (!methodCode) {
|
|
52
|
-
return CommonResult.errorRes('method参数不存在');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const methodInfo = (await this.curdProService.getCachedCfgByMethod(methodCode)) as any;
|
|
56
|
-
if (!methodInfo || methodInfo.status !== 1) {
|
|
57
|
-
return CommonResult.errorRes('接口不存在或已下线: ' + methodCode);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.logInfo('methodInfo=== ', methodInfo);
|
|
61
|
-
|
|
62
|
-
const workbench_code_array = methodInfo.workbench_code_array || methodInfo.workbenchCodeArray;
|
|
63
|
-
const isSupport = await this.workbenchService.isSupportCurrentWorkbench(workbench_code_array);
|
|
64
|
-
if (!isSupport) {
|
|
65
|
-
return CommonResult.errorRes('此接口不支持在当前站点打开');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 权限等校验\服务降级\限流令牌桶
|
|
69
|
-
const entity = decamelizeKeys(methodInfo) as any;
|
|
70
|
-
await super.beforeCheckApiAccessibility(API_BASE_TYPE.CRUD_METHOD, entity);
|
|
71
|
-
|
|
72
|
-
const reqJson: any = {};
|
|
73
|
-
|
|
74
|
-
const body = this.ctx.request.body as any;
|
|
75
|
-
if (body && typeof body === 'object') {
|
|
76
|
-
Object.assign(reqJson, body);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const query = this.ctx.query || {};
|
|
80
|
-
|
|
81
|
-
const query_json = query['__query_json__'];
|
|
82
|
-
const query_as = query['__query_as__'] as string;
|
|
83
|
-
const query_pick = query['__query_pick__'] as string; // 以逗号分割的字段列表。只部分字段作为参数。。
|
|
84
|
-
|
|
85
|
-
delete query['__query_json__'];
|
|
86
|
-
delete query['__query_as__'];
|
|
87
|
-
delete query['__query_pick__'];
|
|
88
|
-
|
|
89
|
-
if (query_json && typeof query_json === 'string') {
|
|
90
|
-
const queryJson = JSON.parse(query_json);
|
|
91
|
-
Object.assign(reqJson, queryJson);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (query_as && QUERY_AS_LIST.includes(query_as)) {
|
|
95
|
-
const pickedQuery = pickAsQuery(query_pick, query);
|
|
96
|
-
_.set(reqJson, query_as, pickedQuery);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
Object.assign(reqJson, { method: methodCode });
|
|
100
|
-
|
|
101
|
-
const cfgModel = methodInfo as IRequestCfgModel2;
|
|
102
|
-
const { dbType, dbName } = parseDatabaseName(cfgModel.sqlDatabase);
|
|
103
|
-
cfgModel.sqlDatabase = dbName;
|
|
104
|
-
cfgModel.sqlDbType = dbType;
|
|
105
|
-
|
|
106
|
-
// 业务系统自定义的修改cfgModel
|
|
107
|
-
await GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudMtd(reqJson, cfgModel, methodInfo, this.ctx);
|
|
108
|
-
|
|
109
|
-
return this.curdMixService.executeCrudByCfg(reqJson, cfgModel);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { Controller, Inject, Post } from '@midwayjs/core';
|
|
2
|
-
import { Context } from '@midwayjs/koa';
|
|
3
|
-
import { BaseApiController } from '../base/BaseApiController';
|
|
4
|
-
import { CrudStdService, SPECIAL_SETTING_KEY } from '@/service/crudstd/CrudStdService';
|
|
5
|
-
import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
|
|
6
|
-
import { IRequestModel } from '@/libs/crud-pro/interfaces';
|
|
7
|
-
import { CommonResult } from '@/libs/utils/common-dto';
|
|
8
|
-
|
|
9
|
-
interface ICrudStdActionParams {
|
|
10
|
-
appCode: string;
|
|
11
|
-
settingKey?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type ICrudStdParams = { stdAction: ICrudStdActionParams } & IRequestModel;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 零代码配置的界面,相关的接口的执行
|
|
18
|
-
*/
|
|
19
|
-
@Controller('/ns/gw/api/crudStd')
|
|
20
|
-
export class CrudStdGatewayController extends BaseApiController {
|
|
21
|
-
@Inject()
|
|
22
|
-
protected ctx: Context;
|
|
23
|
-
|
|
24
|
-
@Inject()
|
|
25
|
-
private crudStdService: CrudStdService;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 获取零代码应用基本信息
|
|
29
|
-
*/
|
|
30
|
-
@Post('/getParsedCrudStdAppInfo')
|
|
31
|
-
async getParsedCrudStdAppInfo(): Promise<CommonResult> {
|
|
32
|
-
const body = this.ctx.request.body as ICrudStdParams;
|
|
33
|
-
const appCode = body.stdAction.appCode;
|
|
34
|
-
const parsedAppInfo = await this.crudStdService.getParsedCrudStdAppInfo(appCode);
|
|
35
|
-
return CommonResult.successNotNull(parsedAppInfo);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 列表查询: 分页查询
|
|
40
|
-
*/
|
|
41
|
-
@Post('/getObjectList')
|
|
42
|
-
async getObjectList() {
|
|
43
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
44
|
-
const appCode = stdAction.appCode;
|
|
45
|
-
return this.crudStdService.executeStdQuery(appCode, SPECIAL_SETTING_KEY.QUERY_LIST, otherParams, KeysOfSimpleSQL.SIMPLE_QUERY_PAGE);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 单个查询
|
|
50
|
-
*/
|
|
51
|
-
@Post('/getObjectOne')
|
|
52
|
-
async getObjectOne() {
|
|
53
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
54
|
-
const appCode = stdAction.appCode;
|
|
55
|
-
return this.crudStdService.executeStdQuery(appCode, SPECIAL_SETTING_KEY.QUERY_ONE, otherParams, KeysOfSimpleSQL.SIMPLE_QUERY_ONE);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 单个删除
|
|
60
|
-
*/
|
|
61
|
-
@Post('/deleteObject')
|
|
62
|
-
async deleteObject() {
|
|
63
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
64
|
-
const appCode = stdAction.appCode;
|
|
65
|
-
const settingKey = stdAction.settingKey;
|
|
66
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, KeysOfSimpleSQL.SIMPLE_DELETE);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 单个创建
|
|
71
|
-
*/
|
|
72
|
-
@Post('/createObject')
|
|
73
|
-
async createObject() {
|
|
74
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
75
|
-
const appCode = stdAction.appCode;
|
|
76
|
-
const settingKey = stdAction.settingKey;
|
|
77
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, KeysOfSimpleSQL.SIMPLE_INSERT);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 单个更新
|
|
82
|
-
*/
|
|
83
|
-
@Post('/updateObject')
|
|
84
|
-
async updateObject() {
|
|
85
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
86
|
-
const appCode = stdAction.appCode;
|
|
87
|
-
const settingKey = stdAction.settingKey;
|
|
88
|
-
return this.crudStdService.executeStdQuery(appCode, settingKey, otherParams, KeysOfSimpleSQL.SIMPLE_UPDATE);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 执行操作
|
|
93
|
-
*/
|
|
94
|
-
@Post('/executeStdAction')
|
|
95
|
-
async executeStdAction() {
|
|
96
|
-
const { stdAction, ...otherParams } = this.ctx.request.body as ICrudStdParams;
|
|
97
|
-
const appCode = stdAction.appCode;
|
|
98
|
-
const settingKey = stdAction.settingKey;
|
|
99
|
-
return await this.crudStdService.executeStdActionByReq(appCode, settingKey, otherParams);
|
|
100
|
-
}
|
|
101
|
-
}
|