midway-fatcms 0.0.1-beta.2 → 0.0.1-beta.20
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/.eslintrc.json +12 -0
- package/.prettierrc.js +4 -0
- package/README.md +7 -0
- package/dist/config/config.default.js +52 -15
- package/dist/configuration.d.ts +1 -0
- package/dist/configuration.js +33 -8
- package/dist/controller/base/BaseApiController.d.ts +1 -1
- package/dist/controller/base/BaseApiController.js +9 -6
- package/dist/controller/gateway/AsyncTaskController.d.ts +14 -0
- package/dist/controller/gateway/AsyncTaskController.js +108 -0
- package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
- package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
- package/dist/controller/gateway/DocGatewayController.js +14 -9
- package/dist/controller/gateway/PublicApiController.js +4 -6
- package/dist/controller/gateway/StaticController.d.ts +2 -0
- package/dist/controller/gateway/StaticController.js +59 -40
- package/dist/controller/helpers.controller.d.ts +1 -1
- package/dist/controller/home.controller.js +2 -2
- package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
- package/dist/controller/manage/CrudStandardDesignApi.js +78 -75
- package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.d.ts +1 -1
- package/dist/controller/manage/DeployManageApi.js +38 -34
- package/dist/controller/manage/MenuManageApi.js +1 -1
- package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
- package/dist/controller/manage/SuperAdminManageApi.js +12 -8
- package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
- package/dist/controller/manage/SysConfigMangeApi.js +6 -4
- package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
- package/dist/controller/manage/SystemInfoManageApi.js +7 -1
- package/dist/controller/manage/UserAccountManageApi.d.ts +2 -2
- package/dist/controller/manage/UserAccountManageApi.js +5 -0
- package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
- package/dist/controller/myinfo/AuthController.d.ts +0 -4
- package/dist/controller/myinfo/AuthController.js +1 -54
- package/dist/controller/render/AppRenderController.js +10 -4
- package/dist/controller/test.controller.d.ts +1 -1
- package/dist/controller/test.controller.js +5 -5
- package/dist/index.d.ts +34 -4
- package/dist/index.js +34 -4
- package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
- package/dist/libs/crud-pro/CrudPro.js +5 -0
- package/dist/libs/crud-pro/defaultConfigs.js +2 -0
- package/dist/libs/crud-pro/interfaces.d.ts +7 -1
- package/dist/libs/crud-pro/models/ExecuteContext.d.ts +2 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
- package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
- package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
- package/dist/libs/crud-pro/models/ResModel.js +2 -0
- package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +1 -1
- package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +22 -11
- package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -9
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
- package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
- package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
- package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
- package/dist/libs/crud-pro/services/CrudProServiceBase.js +3 -2
- package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
- package/dist/libs/crud-pro/services/CrudProTableMetaService.js +31 -7
- package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
- package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
- package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
- package/dist/libs/global-config/global-config.d.ts +45 -0
- package/dist/libs/global-config/global-config.js +33 -0
- package/dist/libs/utils/errorToString.d.ts +2 -0
- package/dist/libs/utils/errorToString.js +57 -0
- package/dist/libs/utils/fatcms-request.js +2 -2
- package/dist/middleware/forbidden.middleware.js +4 -20
- package/dist/middleware/global.middleware.js +8 -1
- package/dist/models/AsyncTaskModel.d.ts +69 -0
- package/dist/models/AsyncTaskModel.js +26 -0
- package/dist/models/RedisKeys.d.ts +8 -0
- package/dist/models/RedisKeys.js +11 -0
- package/dist/models/SystemTables.d.ts +1 -3
- package/dist/models/SystemTables.js +2 -4
- package/dist/schedule/anonymousContext.d.ts +13 -0
- package/dist/schedule/anonymousContext.js +59 -0
- package/dist/schedule/index.d.ts +4 -3
- package/dist/schedule/index.js +8 -67
- package/dist/schedule/runSchedule.d.ts +15 -0
- package/dist/schedule/runSchedule.js +68 -0
- package/dist/schedule/scheduleNames.d.ts +13 -0
- package/dist/schedule/scheduleNames.js +17 -0
- package/dist/service/AuthService.js +8 -5
- package/dist/service/EnumInfoService.js +7 -4
- package/dist/service/FileCenterService.js +13 -9
- package/dist/service/SysConfigService.js +4 -2
- package/dist/service/UserAccountService.js +10 -6
- package/dist/service/UserSessionService.js +2 -1
- package/dist/service/VisitStatService.d.ts +1 -1
- package/dist/service/VisitStatService.js +20 -27
- package/dist/service/WorkbenchService.js +4 -2
- package/dist/service/anyapi/AnyApiService.js +4 -2
- package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +37 -0
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +226 -0
- package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
- package/dist/service/asyncTask/AsyncTaskService.js +34 -0
- package/dist/service/crudstd/CrudStdService.d.ts +1 -0
- package/dist/service/crudstd/CrudStdService.js +34 -3
- package/dist/service/curd/CrudProQuick.d.ts +24 -0
- package/dist/service/curd/CrudProQuick.js +105 -0
- package/dist/service/curd/CurdMixByAccountService.js +12 -6
- package/dist/service/curd/CurdMixByDictService.js +4 -2
- package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +10 -1
- package/dist/service/curd/CurdMixByLinkToCustomService.js +72 -24
- package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
- package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
- package/dist/service/curd/CurdMixService.d.ts +1 -1
- package/dist/service/curd/CurdMixService.js +2 -2
- package/dist/service/curd/CurdMixUtils.d.ts +7 -0
- package/dist/service/curd/CurdMixUtils.js +65 -28
- package/dist/service/curd/CurdProService.d.ts +2 -10
- package/dist/service/curd/CurdProService.js +31 -146
- package/dist/service/curd/fixCfgModel.d.ts +3 -0
- package/dist/service/curd/fixCfgModel.js +107 -0
- package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
- package/dist/views/404_app.html +31 -0
- package/dist/views/404_workbench.html +34 -0
- package/dist/views/static/favicon.ico +0 -0
- package/package.json +9 -2
- package/src/config/config.default.ts +58 -27
- package/src/configuration.ts +42 -9
- package/src/controller/base/BaseApiController.ts +19 -19
- package/src/controller/gateway/AnyApiGatewayController.ts +1 -1
- package/src/controller/gateway/AsyncTaskController.ts +83 -0
- package/src/controller/gateway/CrudMtdGatewayController.ts +17 -13
- package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
- package/src/controller/gateway/DocGatewayController.ts +25 -17
- package/src/controller/gateway/FileController.ts +8 -9
- package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
- package/src/controller/gateway/PublicApiController.ts +19 -22
- package/src/controller/gateway/StaticController.ts +234 -242
- package/src/controller/helpers.controller.ts +1 -1
- package/src/controller/home.controller.ts +8 -15
- package/src/controller/manage/AnyApiMangeApi.ts +9 -9
- package/src/controller/manage/AppLogMangeApi.ts +3 -3
- package/src/controller/manage/AppMangeApi.ts +5 -5
- package/src/controller/manage/AppPageMangeApi.ts +3 -3
- package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
- package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
- package/src/controller/manage/CrudStandardDesignApi.ts +106 -113
- package/src/controller/manage/DataDictManageApi.ts +4 -4
- package/src/controller/manage/DeployManageApi.ts +85 -89
- package/src/controller/manage/DocLibManageApi.ts +3 -3
- package/src/controller/manage/DocManageApi.ts +8 -8
- package/src/controller/manage/MenuManageApi.ts +9 -14
- package/src/controller/manage/SuperAdminManageApi.ts +14 -13
- package/src/controller/manage/SysConfigMangeApi.ts +9 -9
- package/src/controller/manage/SystemInfoManageApi.ts +11 -6
- package/src/controller/manage/UserAccountManageApi.ts +8 -2
- package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
- package/src/controller/myinfo/AuthController.ts +6 -72
- package/src/controller/render/AppRenderController.ts +24 -21
- package/src/controller/test.controller.ts +18 -18
- package/src/index.ts +38 -4
- package/src/libs/crud-pro/CrudPro.ts +7 -0
- package/src/libs/crud-pro/defaultConfigs.ts +2 -0
- package/src/libs/crud-pro/interfaces.ts +10 -3
- package/src/libs/crud-pro/models/ExecuteContext.ts +3 -3
- package/src/libs/crud-pro/models/ExecuteContextFunc.ts +11 -1
- package/src/libs/crud-pro/models/RequestCfgModel.ts +1 -1
- package/src/libs/crud-pro/models/RequestModel.ts +1 -1
- package/src/libs/crud-pro/models/ResModel.ts +19 -0
- package/src/libs/crud-pro/models/SqlCfgModel.ts +2 -2
- package/src/libs/crud-pro/models/Transaction.ts +8 -9
- package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
- package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
- package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +26 -19
- package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +38 -50
- package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +26 -45
- package/src/libs/crud-pro/services/CrudProGenSqlService.ts +23 -40
- package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +25 -29
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +5 -9
- package/src/libs/crud-pro/services/CrudProTableMetaService.ts +35 -9
- package/src/libs/crud-pro/utils/DatabaseName.ts +35 -15
- package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
- package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
- package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
- package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
- package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
- package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +2 -2
- package/src/libs/global-config/global-config.ts +78 -0
- package/src/libs/utils/crypto-utils.ts +2 -4
- package/src/libs/utils/errorToString.ts +61 -0
- package/src/libs/utils/fatcms-request.ts +9 -21
- package/src/libs/utils/ordernum-utils.ts +2 -6
- package/src/libs/utils/parseConfig.ts +7 -15
- package/src/middleware/forbidden.middleware.ts +6 -25
- package/src/middleware/global.middleware.ts +18 -16
- package/src/models/AsyncTaskModel.ts +79 -0
- package/src/models/RedisKeys.ts +13 -0
- package/src/models/SystemTables.ts +1 -4
- package/src/models/bizmodels.ts +1 -2
- package/src/schedule/anonymousContext.ts +79 -0
- package/src/schedule/index.ts +11 -72
- package/src/schedule/runSchedule.ts +83 -0
- package/src/schedule/scheduleNames.ts +21 -0
- package/src/service/AuthService.ts +13 -8
- package/src/service/EnumInfoService.ts +8 -3
- package/src/service/FileCenterService.ts +12 -6
- package/src/service/SysConfigService.ts +10 -6
- package/src/service/UserAccountService.ts +14 -4
- package/src/service/UserSessionService.ts +5 -4
- package/src/service/VisitStatService.ts +57 -70
- package/src/service/WorkbenchService.ts +7 -2
- package/src/service/anyapi/AnyApiService.ts +11 -8
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +249 -0
- package/src/service/asyncTask/AsyncTaskService.ts +21 -0
- package/src/service/base/BaseService.ts +2 -2
- package/src/service/crudstd/CrudStdService.ts +43 -5
- package/src/service/curd/CrudProQuick.ts +137 -0
- package/src/service/curd/CurdMixByAccountService.ts +14 -6
- package/src/service/curd/CurdMixByDictService.ts +8 -2
- package/src/service/curd/CurdMixByLinkToCustomService.ts +101 -50
- package/src/service/curd/CurdMixBySysConfigService.ts +7 -2
- package/src/service/curd/CurdMixByWorkbenchService.ts +6 -2
- package/src/service/curd/CurdMixService.ts +3 -3
- package/src/service/curd/CurdMixUtils.ts +82 -39
- package/src/service/curd/CurdProService.ts +45 -189
- package/src/service/curd/fixCfgModel.ts +139 -0
- package/src/service/proxyapi/ProxyApiLoadService.ts +12 -3
- package/src/views/404_app.html +31 -0
- package/src/views/404_workbench.html +34 -0
- package/src/views/static/favicon.ico +0 -0
- package/tsconfig.json +32 -0
- package/dist/controller/medstatistic/MedAdminController.d.ts +0 -35
- package/dist/controller/medstatistic/MedAdminController.js +0 -205
- package/dist/controller/medstatistic/MedClientController.d.ts +0 -28
- package/dist/controller/medstatistic/MedClientController.js +0 -188
- package/dist/controller/medstatistic/MedMessageService.d.ts +0 -19
- package/dist/controller/medstatistic/MedMessageService.js +0 -95
- package/dist/controller/medstatistic/MedScoreService.d.ts +0 -21
- package/dist/controller/medstatistic/MedScoreService.js +0 -107
- package/dist/controller/medstatistic/constants.d.ts +0 -32
- package/dist/controller/medstatistic/constants.js +0 -43
- package/src/controller/medstatistic/MedAdminController.ts +0 -221
- package/src/controller/medstatistic/MedClientController.ts +0 -188
- package/src/controller/medstatistic/MedMessageService.ts +0 -89
- package/src/controller/medstatistic/MedScoreService.ts +0 -108
- package/src/controller/medstatistic/constants.ts +0 -63
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Inject, Provide } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
|
+
import { BaseService } from '@/service/base/BaseService';
|
|
4
|
+
import { runScheduleTaskOnce } from '@/schedule';
|
|
5
|
+
import { INNER_SCHEDULE_NAMES } from '@/schedule/scheduleNames';
|
|
6
|
+
import { RedisKeys } from '@/models/RedisKeys';
|
|
7
|
+
|
|
8
|
+
@Provide()
|
|
9
|
+
export class AsyncTaskService extends BaseService {
|
|
10
|
+
@Inject()
|
|
11
|
+
protected ctx: Context;
|
|
12
|
+
|
|
13
|
+
async startTask() {
|
|
14
|
+
await this.redisService.set(RedisKeys.ASYNC_TASK_UPDATE_TIME, `${Date.now()}`);
|
|
15
|
+
runScheduleTaskOnce(INNER_SCHEDULE_NAMES.asyncTaskRunnerService).then(schedule => {
|
|
16
|
+
console.log(schedule);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async cancelTask(id: number) {}
|
|
21
|
+
}
|
|
@@ -3,8 +3,8 @@ import { Context } from '@midwayjs/koa';
|
|
|
3
3
|
import { RedisService } from '@midwayjs/redis';
|
|
4
4
|
import { OSSService, OSSServiceFactory } from '@midwayjs/oss';
|
|
5
5
|
import * as koa from '@midwayjs/koa';
|
|
6
|
-
import { consoleLogger, ContextLogger, ILoggerContext } from '
|
|
7
|
-
import { isEnableDebug, isLocalEnv } from '
|
|
6
|
+
import { consoleLogger, ContextLogger, ILoggerContext } from '@/models/contextLogger';
|
|
7
|
+
import { isEnableDebug, isLocalEnv } from '@/libs/utils/fatcms-request';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
@Provide()
|
|
@@ -2,17 +2,19 @@ import { Inject, Provide } from '@midwayjs/core';
|
|
|
2
2
|
import { Context } from '@midwayjs/koa';
|
|
3
3
|
import { CurdMixService } from '../curd/CurdMixService';
|
|
4
4
|
import { IRequestCfgModel, IRequestModel } from '../../libs/crud-pro/interfaces';
|
|
5
|
-
import { KeysOfAuthType, KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
5
|
+
import { KeysOfAuthType, KeysOfSimpleSQL, SqlDbType } from '../../libs/crud-pro/models/keys';
|
|
6
6
|
import { parseJsonObject } from '../../libs/utils/functions';
|
|
7
7
|
import { ICrudStdAppInfo, ICrudStdAppInfoForSettingKey } from '../../models/bizmodels';
|
|
8
8
|
import { BizException } from '../../models/devops';
|
|
9
9
|
import { ExecuteContext } from '../../libs/crud-pro/models/ExecuteContext';
|
|
10
|
-
import {
|
|
10
|
+
import { SystemTables } from '../../models/SystemTables';
|
|
11
11
|
import { CrudStdActionService } from './CrudStdActionService';
|
|
12
12
|
import { CrudStdRelationService } from './CrudStdRelationService';
|
|
13
13
|
import * as _ from 'lodash';
|
|
14
14
|
import { ApiBaseService } from '../base/ApiBaseService';
|
|
15
|
-
import {parseDatabaseName} from
|
|
15
|
+
import { parseDatabaseName } from '../../libs/crud-pro/utils/DatabaseName';
|
|
16
|
+
import { GLOBAL_STATIC_CONFIG } from '../../libs/global-config/global-config';
|
|
17
|
+
import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
|
|
16
18
|
|
|
17
19
|
export const SPECIAL_SETTING_KEY = {
|
|
18
20
|
QUERY_LIST: 'QUERY_LIST',
|
|
@@ -50,7 +52,7 @@ export class CrudStdService extends ApiBaseService {
|
|
|
50
52
|
|
|
51
53
|
const cfgModel: IRequestCfgModel = {
|
|
52
54
|
sqlDatabase: dbName,
|
|
53
|
-
|
|
55
|
+
sqlDbType: dbType,
|
|
54
56
|
sqlTable: stdCrudCfgObj.tableBaseInfo.tableName,
|
|
55
57
|
sqlSimpleName,
|
|
56
58
|
};
|
|
@@ -67,6 +69,13 @@ export class CrudStdService extends ApiBaseService {
|
|
|
67
69
|
|
|
68
70
|
// 根据用户配置,设置关联查询的数据信息。
|
|
69
71
|
await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
|
|
72
|
+
|
|
73
|
+
// 根据表结构的数据类型,修正数据类型
|
|
74
|
+
await this.fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, { dbType, dbName });
|
|
75
|
+
|
|
76
|
+
// 业务系统自定义的修改cfgModel
|
|
77
|
+
await GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudStd(params, cfgModel, appInfo, this.ctx);
|
|
78
|
+
|
|
70
79
|
return await this.curdMixService.executeCrudByCfg(params, cfgModel);
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -133,13 +142,15 @@ export class CrudStdService extends ApiBaseService {
|
|
|
133
142
|
* @private
|
|
134
143
|
*/
|
|
135
144
|
private async getCrudStdAppInfo(appCode?: string) {
|
|
145
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
146
|
+
|
|
136
147
|
this.logInfo('getCrudStdAppInfo', appCode);
|
|
137
148
|
|
|
138
149
|
const ss = {
|
|
139
150
|
sqlTable: SystemTables.sys_app,
|
|
140
151
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
141
152
|
sqlDatabase: SystemDbName,
|
|
142
|
-
|
|
153
|
+
sqlDbType: SystemDbType,
|
|
143
154
|
};
|
|
144
155
|
return await this.curdMixService.executeCrudByCfg({ condition: { app_code: appCode } }, ss);
|
|
145
156
|
}
|
|
@@ -185,4 +196,31 @@ export class CrudStdService extends ApiBaseService {
|
|
|
185
196
|
}
|
|
186
197
|
return true; // 无需鉴权
|
|
187
198
|
}
|
|
199
|
+
|
|
200
|
+
private async fixDataFieldTypeBySqlTableField(params: IRequestModel, cfgModel: IRequestCfgModel, appInfo: ICrudStdAppInfoForSettingKey, arg3: { dbType: SqlDbType; dbName: string }) {
|
|
201
|
+
const tableFields = _.get(appInfo, 'stdCrudCfgObj.tableFields');
|
|
202
|
+
|
|
203
|
+
const tableFieldMap = MixinUtils.toMap(tableFields, (e: any) => {
|
|
204
|
+
return e.fieldIndex;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (arg3.dbType === SqlDbType.postgres) {
|
|
208
|
+
if (cfgModel.sqlSimpleName === KeysOfSimpleSQL.SIMPLE_INSERT || cfgModel.sqlSimpleName === KeysOfSimpleSQL.SIMPLE_UPDATE) {
|
|
209
|
+
const data = params.data || {};
|
|
210
|
+
const dataKeys = Object.keys(data);
|
|
211
|
+
for (let index = 0; index < dataKeys.length; index++) {
|
|
212
|
+
const dataKey = dataKeys[index];
|
|
213
|
+
const dataValue = data[dataKey];
|
|
214
|
+
const fieldInfo = tableFieldMap[dataKey];
|
|
215
|
+
const fieldType = ('' + _.get(fieldInfo, 'type')).toUpperCase();
|
|
216
|
+
if (fieldType === 'ARRAY') {
|
|
217
|
+
const dataValueArray = parseJsonObject(dataValue);
|
|
218
|
+
if (Array.isArray(dataValueArray)) {
|
|
219
|
+
data[dataKey] = `{${dataValueArray.map(v => `"${v}"`).join(',')}}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
188
226
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { KeysOfSimpleSQL, SqlDbType } from "@/libs/crud-pro/models/keys";
|
|
2
|
+
import { IRequestCfgModel, IRequestModel, ISqlCfgModel } from "@/libs/crud-pro/interfaces";
|
|
3
|
+
import { IRequestCfgModel2 } from "@/models/bizmodels";
|
|
4
|
+
import { CrudPro } from "@/libs/crud-pro/CrudPro";
|
|
5
|
+
import { ResModelAffected, ResModelStandard } from "@/libs/crud-pro/models/ResModel";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class CrudProQuick {
|
|
10
|
+
private readonly curdPro: CrudPro;
|
|
11
|
+
private readonly sqlDbType: SqlDbType;
|
|
12
|
+
private readonly sqlDatabase: string;
|
|
13
|
+
private readonly sqlTable?: string;
|
|
14
|
+
private baseCfgModel: IRequestCfgModel2 = {};
|
|
15
|
+
|
|
16
|
+
constructor(curdPro: CrudPro, sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string) {
|
|
17
|
+
this.sqlDatabase = sqlDatabase;
|
|
18
|
+
this.sqlDbType = sqlDbType;
|
|
19
|
+
this.curdPro = curdPro;
|
|
20
|
+
this.sqlTable = sqlTable; // 全局sqlTable为空时,单独调用时就必须传sqlTable参数。
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public setBaseCfgModel(baseCfgModel: IRequestCfgModel2) {
|
|
24
|
+
Object.assign(this.baseCfgModel, baseCfgModel);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async executeCrudByCfg(reqJson: IRequestModel, cfgModel2: IRequestCfgModel2) {
|
|
28
|
+
|
|
29
|
+
const cfgModel = { ...this.baseCfgModel };
|
|
30
|
+
Object.assign(cfgModel, cfgModel2);
|
|
31
|
+
|
|
32
|
+
cfgModel.method = 'CrudProQuickAnonymous';
|
|
33
|
+
cfgModel.updateCfg = {};
|
|
34
|
+
cfgModel.sqlDatabase = this.sqlDatabase;
|
|
35
|
+
cfgModel.sqlDbType = this.sqlDbType;
|
|
36
|
+
|
|
37
|
+
if (!cfgModel.sqlTable) {
|
|
38
|
+
cfgModel.sqlTable = this.sqlTable;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!cfgModel.sqlTable) {
|
|
42
|
+
throw new Error('[CrudProQuick] sqlTable not found');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return await this.curdPro.executeCrudByCfg(reqJson, cfgModel);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public async getOne(reqJson: IRequestModel, sqlTable?: string): Promise<any> {
|
|
50
|
+
const cfgModel: IRequestCfgModel = {
|
|
51
|
+
sqlTable,
|
|
52
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
|
|
53
|
+
};
|
|
54
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
55
|
+
return res.getOneObj();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public async getList(reqJson: IRequestModel, sqlTable?: string): Promise<any[]> {
|
|
59
|
+
const cfgModel: IRequestCfgModel = {
|
|
60
|
+
sqlTable,
|
|
61
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
62
|
+
};
|
|
63
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
64
|
+
return res.getResRows();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async getListPage(reqJson: IRequestModel, sqlTable?: string): Promise<ResModelStandard> {
|
|
68
|
+
const cfgModel: IRequestCfgModel = {
|
|
69
|
+
sqlTable,
|
|
70
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_PAGE,
|
|
71
|
+
};
|
|
72
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
73
|
+
return res.getResModel(); // 因为它有2个返回值
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async getTotalCount(reqJson: IRequestModel, sqlTable?: string): Promise<number> {
|
|
77
|
+
const cfgModel: IRequestCfgModel = {
|
|
78
|
+
sqlTable,
|
|
79
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_COUNT,
|
|
80
|
+
};
|
|
81
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
82
|
+
return res.getResModel().total_count;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public async insertObject(reqJson: IRequestModel, sqlTable?: string): Promise<ResModelAffected> {
|
|
86
|
+
const cfgModel: IRequestCfgModel = {
|
|
87
|
+
sqlTable,
|
|
88
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
|
|
89
|
+
};
|
|
90
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
91
|
+
return res.getResModel().affected;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async updateObject(reqJson: IRequestModel, sqlTable?: string): Promise<ResModelAffected> {
|
|
95
|
+
const cfgModel: IRequestCfgModel = {
|
|
96
|
+
sqlTable,
|
|
97
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
|
|
98
|
+
};
|
|
99
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
100
|
+
return res.getResModel().affected;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public async insertOrUpdate(reqJson: IRequestModel, sqlTable?: string): Promise<ResModelStandard> {
|
|
104
|
+
const cfgModel: IRequestCfgModel = {
|
|
105
|
+
sqlTable,
|
|
106
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE,
|
|
107
|
+
};
|
|
108
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
109
|
+
return res.getResModel(); // 因为它有三个返回值
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public async deleteObject(reqJson: IRequestModel, sqlTable?: string): Promise<ResModelAffected> {
|
|
113
|
+
const cfgModel: IRequestCfgModel = {
|
|
114
|
+
sqlTable,
|
|
115
|
+
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_DELETE,
|
|
116
|
+
};
|
|
117
|
+
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
118
|
+
return res.getResModel().affected;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
public async executeSQL(executeSql: string, args?: any[]): Promise<any> {
|
|
123
|
+
const sqlCfgModel: ISqlCfgModel = {
|
|
124
|
+
executeSql: executeSql,
|
|
125
|
+
executeSqlArgs: args,
|
|
126
|
+
sqlDatabase: this.sqlDatabase,
|
|
127
|
+
sqlDbType: this.sqlDbType,
|
|
128
|
+
};
|
|
129
|
+
return await this.curdPro.executeSQL(sqlCfgModel);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
@@ -4,10 +4,11 @@ import * as _ from 'lodash';
|
|
|
4
4
|
import { CurdProService } from './CurdProService';
|
|
5
5
|
import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
|
|
6
6
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
7
|
-
import {
|
|
7
|
+
import { SystemTables } from '../../models/SystemTables';
|
|
8
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
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
11
12
|
|
|
12
13
|
const dictMixUtils = new CrudMixUtils(RelatedType.accountBasic);
|
|
13
14
|
|
|
@@ -22,6 +23,8 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
22
23
|
protected curdProService: CurdProService;
|
|
23
24
|
|
|
24
25
|
async handleExecuteContextPrepare(executeContext: ExecuteContext) {
|
|
26
|
+
const { SystemDbName, SystemDbType, toFatcmsUserAccountId } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
27
|
+
|
|
25
28
|
const relations = dictMixUtils.pickColumnRelations(executeContext);
|
|
26
29
|
if (!relations || relations.length === 0) {
|
|
27
30
|
return;
|
|
@@ -30,10 +33,15 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
30
33
|
const accountIds = new Set<string>();
|
|
31
34
|
dictMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
|
|
32
35
|
const { sourceColumn } = columnRelation;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (sourceColumn) {
|
|
37
|
+
const accountId = _.get(row, sourceColumn);
|
|
38
|
+
if (accountId) {
|
|
39
|
+
const fatcmsUserAccountId = toFatcmsUserAccountId(accountId);
|
|
40
|
+
accountIds.add(fatcmsUserAccountId);
|
|
41
|
+
row['__fatcmsUserAccountId__'] = fatcmsUserAccountId;
|
|
42
|
+
}
|
|
36
43
|
}
|
|
44
|
+
|
|
37
45
|
});
|
|
38
46
|
|
|
39
47
|
if (accountIds.size === 0) {
|
|
@@ -45,7 +53,7 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
45
53
|
sqlTable: SystemTables.sys_user_account,
|
|
46
54
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
47
55
|
sqlDatabase: SystemDbName,
|
|
48
|
-
|
|
56
|
+
sqlDbType: SystemDbType,
|
|
49
57
|
};
|
|
50
58
|
|
|
51
59
|
const reqJson: IRequestModel = {
|
|
@@ -77,7 +85,7 @@ export class CurdMixByAccountService implements IExecuteContextHandler {
|
|
|
77
85
|
{ from: 'avatar', to: `${sourceColumn}_user.avatar` },
|
|
78
86
|
];
|
|
79
87
|
}
|
|
80
|
-
dictMixUtils.
|
|
88
|
+
dictMixUtils.copyUserInfoToRowNoRelatedCode(row, userInfoMap, columnRelation);
|
|
81
89
|
});
|
|
82
90
|
}
|
|
83
91
|
}
|
|
@@ -3,12 +3,13 @@ import { Context } from '@midwayjs/koa';
|
|
|
3
3
|
import { CurdProService } from './CurdProService';
|
|
4
4
|
import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
|
|
5
5
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
6
|
-
import {
|
|
6
|
+
import { SystemTables} from '../../models/SystemTables';
|
|
7
7
|
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
8
8
|
import { MultiKeyMap } from '../../libs/crud-pro/utils/MultiKeyMap';
|
|
9
9
|
import { ColumnRelation } from '../../libs/crud-pro/interfaces';
|
|
10
10
|
import * as _ from 'lodash';
|
|
11
11
|
import {RedisCacheService} from "../base/RedisCacheService";
|
|
12
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
12
13
|
|
|
13
14
|
const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
|
|
14
15
|
|
|
@@ -46,6 +47,11 @@ export class CurdMixByDictService implements IExecuteContextHandler {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
private async getDictItemRows(codes: string[]) {
|
|
50
|
+
|
|
51
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
49
55
|
const noCacheCodes: string[] = [];
|
|
50
56
|
|
|
51
57
|
// 从缓存里面取
|
|
@@ -72,7 +78,7 @@ export class CurdMixByDictService implements IExecuteContextHandler {
|
|
|
72
78
|
sqlTable: SystemTables.sys_data_dict_item,
|
|
73
79
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
74
80
|
sqlDatabase: SystemDbName,
|
|
75
|
-
|
|
81
|
+
sqlDbType: SystemDbType,
|
|
76
82
|
}
|
|
77
83
|
);
|
|
78
84
|
selectedRows = res1.getResRows();
|
|
@@ -1,19 +1,46 @@
|
|
|
1
|
-
import {Inject, Provide} from '@midwayjs/core';
|
|
2
|
-
import {Context} from '@midwayjs/koa';
|
|
1
|
+
import { Inject, Provide } from '@midwayjs/core';
|
|
2
|
+
import { Context } from '@midwayjs/koa';
|
|
3
3
|
import * as _ from 'lodash';
|
|
4
|
-
import {CurdProService} from './CurdProService';
|
|
5
|
-
import {ExecuteContext, IExecuteContextHandler} from '../../libs/crud-pro/models/ExecuteContext';
|
|
6
|
-
import {CrudMixUtils, RelatedType} from './CurdMixUtils';
|
|
7
|
-
import {KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
|
|
8
|
-
import {ColumnRelation} from '../../libs/crud-pro/interfaces';
|
|
9
|
-
import {BizException} from
|
|
10
|
-
import {Exceptions} from
|
|
11
|
-
import {RedisCacheService} from
|
|
12
|
-
import {parseDatabaseName} from
|
|
4
|
+
import { CurdProService } from './CurdProService';
|
|
5
|
+
import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
|
|
6
|
+
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
7
|
+
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
8
|
+
import { ColumnRelation } from '../../libs/crud-pro/interfaces';
|
|
9
|
+
import { BizException } from '../../models/devops';
|
|
10
|
+
import { Exceptions } from '../../libs/crud-pro/exceptions';
|
|
11
|
+
import { RedisCacheService } from '../base/RedisCacheService';
|
|
12
|
+
import { parseDatabaseName } from '../../libs/crud-pro/utils/DatabaseName';
|
|
13
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
14
|
+
import { IRequestCfgModel2 } from '@/models/bizmodels';
|
|
13
15
|
|
|
14
16
|
const linkToCustomMixUtils = new CrudMixUtils(RelatedType.linkToCustom);
|
|
15
17
|
const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
|
|
16
18
|
|
|
19
|
+
function toMapObject(rows: any[], fieldsArr: string[]): Map<string, any> {
|
|
20
|
+
const valueKey = fieldsArr[0];
|
|
21
|
+
const labelKey = fieldsArr[1];
|
|
22
|
+
|
|
23
|
+
const isObjectMode = fieldsArr.length > 2 || labelKey === '*';
|
|
24
|
+
|
|
25
|
+
const map = new Map<string, any>();
|
|
26
|
+
for (let i = 0; i < rows.length; i++) {
|
|
27
|
+
const rowObj = rows[i];
|
|
28
|
+
const value = rowObj[valueKey];
|
|
29
|
+
|
|
30
|
+
if (typeof value !== 'undefined') {
|
|
31
|
+
const valueStr = '' + value;
|
|
32
|
+
if (isObjectMode) {
|
|
33
|
+
map.set(valueStr, rowObj);
|
|
34
|
+
} else {
|
|
35
|
+
const label = rowObj[labelKey];
|
|
36
|
+
if (label) {
|
|
37
|
+
map.set(valueStr, label);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
17
44
|
|
|
18
45
|
@Provide()
|
|
19
46
|
export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
@@ -26,7 +53,6 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
26
53
|
@Inject()
|
|
27
54
|
protected redisCacheService: RedisCacheService;
|
|
28
55
|
|
|
29
|
-
|
|
30
56
|
async handleExecuteContextPrepare(executeContext: ExecuteContext) {
|
|
31
57
|
const relations = linkToCustomMixUtils.pickColumnRelations(executeContext);
|
|
32
58
|
|
|
@@ -37,7 +63,7 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
37
63
|
}
|
|
38
64
|
|
|
39
65
|
async handleExecuteContext(executeContext: ExecuteContext): Promise<void> {
|
|
40
|
-
const dataInfoMap = executeContext[TMP_CTX_KEY] as Map<string,Map<string,any
|
|
66
|
+
const dataInfoMap = executeContext[TMP_CTX_KEY] as Map<string, Map<string, any>>;
|
|
41
67
|
if (!dataInfoMap || dataInfoMap.size === 0) {
|
|
42
68
|
return;
|
|
43
69
|
}
|
|
@@ -45,19 +71,17 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
45
71
|
const relatedCode = columnRelation.relatedCode;
|
|
46
72
|
const dataMap = dataInfoMap.get(relatedCode);
|
|
47
73
|
if (dataMap) {
|
|
48
|
-
|
|
49
74
|
const sourceColumn = columnRelation.sourceColumn;
|
|
50
75
|
const targetColumns = columnRelation.targetColumns;
|
|
51
76
|
if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
|
|
52
77
|
columnRelation.targetColumns = [
|
|
53
78
|
{
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
from: '*',
|
|
80
|
+
to: `${sourceColumn}_info[$ARRAY_INDEX]`,
|
|
56
81
|
},
|
|
57
82
|
];
|
|
58
83
|
}
|
|
59
84
|
|
|
60
|
-
|
|
61
85
|
// this.ctx.logger.info("CurdMixByLinkToCustomService ==> dataMap", dataMap)
|
|
62
86
|
|
|
63
87
|
linkToCustomMixUtils.copyColumnRelationToRowNoRelatedCode(row, dataMap, columnRelation);
|
|
@@ -65,11 +89,10 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
65
89
|
});
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const cacheKey = "linkToCustom@@"+code;
|
|
92
|
+
public async queryInfoByLinkToCustom(code: string): Promise<Map<string, any>> {
|
|
93
|
+
const cacheKey = 'linkToCustom@@' + code;
|
|
71
94
|
let values;
|
|
72
|
-
const expireSecond = 2 * 60
|
|
95
|
+
const expireSecond = 2 * 60; // 2分钟
|
|
73
96
|
const enumMap = await this.redisCacheService.getJsonObject(cacheKey);
|
|
74
97
|
if (!enumMap || Object.keys(enumMap).length === 0) {
|
|
75
98
|
values = await this.queryInfoByLinkToCustomImpl(code);
|
|
@@ -78,16 +101,21 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
78
101
|
return values;
|
|
79
102
|
}
|
|
80
103
|
|
|
81
|
-
|
|
82
104
|
/**
|
|
83
105
|
* code形如:mysql_________fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
|
|
84
106
|
* code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
|
|
85
107
|
* code形如:fatcms~~~sys_perm_role~~~id,*
|
|
108
|
+
* code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
|
|
109
|
+
* code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
|
|
86
110
|
* 【数据库】~~~【表名】~~~【value】,【label】,【style】
|
|
87
111
|
* @param code
|
|
88
112
|
* @private
|
|
89
113
|
*/
|
|
90
|
-
private async queryInfoByLinkToCustomImpl(code: string): Promise<Map<string,any>>{
|
|
114
|
+
private async queryInfoByLinkToCustomImpl(code: string): Promise<Map<string, any>> {
|
|
115
|
+
if (code.startsWith('GET_BY_CRUD_METHOD')) {
|
|
116
|
+
return this.queryInfoByLinkToCustomByCrudMethod(code);
|
|
117
|
+
}
|
|
118
|
+
|
|
91
119
|
const arr = code
|
|
92
120
|
.split('~~~')
|
|
93
121
|
.map(s => s.trim())
|
|
@@ -95,9 +123,10 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
95
123
|
if (arr.length !== 3) {
|
|
96
124
|
throw new BizException('linkToCustom枚举值查询字符串,必须符合固定格式', Exceptions.CFG_ERROR);
|
|
97
125
|
}
|
|
126
|
+
|
|
98
127
|
const [sqlDatabase, sqlTable, fields] = arr;
|
|
99
128
|
|
|
100
|
-
const {dbType, dbName} = parseDatabaseName(sqlDatabase);
|
|
129
|
+
const { dbType, dbName } = parseDatabaseName(sqlDatabase);
|
|
101
130
|
|
|
102
131
|
const fieldsArr = fields
|
|
103
132
|
.split(',')
|
|
@@ -108,15 +137,11 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
108
137
|
throw new BizException('linkToCustom枚举值查询字符串,fields字段必须符合固定格式', Exceptions.CFG_ERROR);
|
|
109
138
|
}
|
|
110
139
|
|
|
111
|
-
const valueKey = fieldsArr[0];
|
|
112
140
|
const labelKey = fieldsArr[1];
|
|
113
|
-
|
|
114
|
-
const isObjectMode = fieldsArr.length > 2 || labelKey === "*";
|
|
115
|
-
|
|
116
141
|
const res1 = await this.curdProService.executeCrudByCfg(
|
|
117
142
|
{
|
|
118
143
|
condition: {},
|
|
119
|
-
columns: labelKey ===
|
|
144
|
+
columns: labelKey === '*' ? null : fields,
|
|
120
145
|
limit: 4000,
|
|
121
146
|
offset: 0,
|
|
122
147
|
},
|
|
@@ -124,44 +149,70 @@ export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
|
|
|
124
149
|
sqlTable,
|
|
125
150
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
126
151
|
sqlDatabase: dbName,
|
|
127
|
-
|
|
152
|
+
sqlDbType: dbType,
|
|
128
153
|
maxLimit: 4000,
|
|
129
154
|
}
|
|
130
155
|
);
|
|
131
156
|
const rows = res1.getResRows();
|
|
132
|
-
const map =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const value = rowObj[valueKey];
|
|
136
|
-
|
|
137
|
-
if (typeof value !== 'undefined') {
|
|
138
|
-
const valueStr = "" +value;
|
|
139
|
-
if (isObjectMode) {
|
|
140
|
-
map.set(valueStr, rowObj);
|
|
141
|
-
} else {
|
|
142
|
-
const label = rowObj[labelKey];
|
|
143
|
-
if (label){
|
|
144
|
-
map.set(valueStr, label);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
157
|
+
const map = toMapObject(rows, fieldsArr);
|
|
158
|
+
return map;
|
|
159
|
+
}
|
|
148
160
|
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
* @param code
|
|
164
|
+
* code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
|
|
165
|
+
* code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
|
|
166
|
+
*/
|
|
167
|
+
private async queryInfoByLinkToCustomByCrudMethod(code: string): Promise<Map<string, any>> {
|
|
168
|
+
const arr = code
|
|
169
|
+
.split('~~~')
|
|
170
|
+
.map(s => s.trim())
|
|
171
|
+
.filter(Boolean);
|
|
172
|
+
if (arr.length !== 3) {
|
|
173
|
+
throw new BizException('linkToCustom枚举值查询字符串,必须符合固定格式。', Exceptions.CFG_ERROR);
|
|
174
|
+
}
|
|
175
|
+
const [prefix, methodCode, fields] = arr;
|
|
176
|
+
|
|
177
|
+
const fieldsArr = fields
|
|
178
|
+
.split(',')
|
|
179
|
+
.map(s => s.trim())
|
|
180
|
+
.filter(Boolean);
|
|
149
181
|
|
|
182
|
+
if (fieldsArr.length < 2) {
|
|
183
|
+
throw new BizException(`linkToCustom枚举值查询字符串,fields字段必须符合固定格式。${prefix}`, Exceptions.CFG_ERROR);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const methodInfo = (await this.curdProService.getCachedCfgByMethod(methodCode)) as any;
|
|
187
|
+
if (!methodInfo || methodInfo.status !== 1) {
|
|
188
|
+
throw new Error('接口不存在或已下线: ' + methodCode);
|
|
150
189
|
}
|
|
190
|
+
|
|
191
|
+
const cfgModel = methodInfo as IRequestCfgModel2;
|
|
192
|
+
const { dbType, dbName } = parseDatabaseName(cfgModel.sqlDatabase);
|
|
193
|
+
cfgModel.sqlDatabase = dbName;
|
|
194
|
+
cfgModel.sqlDbType = dbType;
|
|
195
|
+
|
|
196
|
+
const reqJson = {};
|
|
197
|
+
|
|
198
|
+
await GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudMtd(reqJson, cfgModel, methodInfo, this.ctx);
|
|
199
|
+
|
|
200
|
+
const exeCtx = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
|
|
201
|
+
|
|
202
|
+
const rows = exeCtx.getResRows();
|
|
203
|
+
const map = toMapObject(rows, fieldsArr);
|
|
151
204
|
return map;
|
|
152
205
|
}
|
|
153
206
|
|
|
154
|
-
|
|
155
|
-
private async loadInfoByLinkToCustomMap(relations: ColumnRelation[]): Promise<Map<string,Map<string,any>>> {
|
|
207
|
+
private async loadInfoByLinkToCustomMap(relations: ColumnRelation[]): Promise<Map<string, Map<string, any>>> {
|
|
156
208
|
const bigMap = new Map<string, Map<string, any>>();
|
|
157
209
|
for (let i = 0; i < relations.length; i++) {
|
|
158
210
|
const relation = relations[i];
|
|
159
|
-
const code = relation.relatedCode ||
|
|
211
|
+
const code = relation.relatedCode || '';
|
|
160
212
|
const codeTrim = code.trim();
|
|
161
213
|
const map = await this.queryInfoByLinkToCustom(codeTrim);
|
|
162
214
|
bigMap.set(codeTrim, map);
|
|
163
215
|
}
|
|
164
216
|
return bigMap;
|
|
165
217
|
}
|
|
166
|
-
|
|
167
218
|
}
|
|
@@ -4,11 +4,12 @@ import { CurdProService } from './CurdProService';
|
|
|
4
4
|
import { ExecuteContext, IExecuteContextHandler } from '../../libs/crud-pro/models/ExecuteContext';
|
|
5
5
|
import { CrudMixUtils, RelatedType } from './CurdMixUtils';
|
|
6
6
|
import * as _ from 'lodash';
|
|
7
|
-
import {
|
|
7
|
+
import { SystemTables} from '../../models/SystemTables';
|
|
8
8
|
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
9
9
|
import { MultiKeyMap } from '../../libs/crud-pro/utils/MultiKeyMap';
|
|
10
10
|
import { ColumnRelation } from '../../libs/crud-pro/interfaces';
|
|
11
11
|
import { parseConfigContentToEnumInfo } from "../../libs/utils/parseConfig";
|
|
12
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
12
13
|
|
|
13
14
|
const dictMixUtils = new CrudMixUtils(RelatedType.sysCfgEnum);
|
|
14
15
|
|
|
@@ -25,6 +26,10 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
25
26
|
protected curdProService: CurdProService;
|
|
26
27
|
|
|
27
28
|
async handleExecuteContextPrepare(executeContext: ExecuteContext) {
|
|
29
|
+
|
|
30
|
+
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
|
|
29
34
|
if (!codes || codes.length === 0) {
|
|
30
35
|
return;
|
|
@@ -38,7 +43,7 @@ export class CurdMixBySysConfigService implements IExecuteContextHandler {
|
|
|
38
43
|
sqlTable: SystemTables.sys_configs,
|
|
39
44
|
sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
|
|
40
45
|
sqlDatabase: SystemDbName,
|
|
41
|
-
|
|
46
|
+
sqlDbType: SystemDbType,
|
|
42
47
|
}
|
|
43
48
|
);
|
|
44
49
|
const rows = res1.getResRows();
|