midway-fatcms 0.0.1-beta.56 → 0.0.1-beta.58
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/libs/crud-pro/utils/sqlConvert/convertColumnName.d.ts +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertMsSql.d.ts +1 -1
- package/dist/libs/crud-pro/utils/sqlConvert/convertPgSql.d.ts +1 -1
- package/dist/libs/utils/base64.d.ts +5 -5
- package/dist/libs/utils/base64.js +5 -5
- package/dist/libs/utils/render-utils.js +12 -14
- package/dist/schedule/runSchedule.js +1 -1
- package/dist/schedule/scheduleNames.js +2 -2
- package/dist/service/UserSessionService.js +1 -1
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +3 -3
- package/dist/service/crudstd/CrudStdService.d.ts +1 -0
- package/dist/service/crudstd/CrudStdService.js +45 -2
- package/dist/service/curd/CurdProService.js +2 -2
- package/package.json +1 -1
- package/src/controller/gateway/AnyApiGatewayController.ts +33 -1
- package/src/controller/gateway/PublicApiController.ts +1 -1
- package/src/controller/gateway/StaticController.ts +2 -2
- package/src/libs/crud-pro/models/Transaction.ts +3 -5
- package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -1
- package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +3 -8
- package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +17 -19
- package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +4 -6
- package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +4 -6
- package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +1 -3
- package/src/libs/global-config/global-config.ts +5 -6
- package/src/libs/utils/base64.ts +32 -39
- package/src/libs/utils/render-utils.ts +25 -34
- package/src/models/SystemEntities.ts +1 -3
- package/src/models/SystemPerm.ts +10 -11
- package/src/models/SystemTables.ts +0 -1
- package/src/models/bizmodels.ts +2 -4
- package/src/schedule/index.ts +4 -11
- package/src/schedule/runSchedule.ts +4 -12
- package/src/schedule/scheduleNames.ts +5 -11
- package/src/service/AuthService.ts +2 -3
- package/src/service/UserSessionService.ts +20 -24
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +3 -9
- package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -1
- package/src/service/base/BaseService.ts +4 -9
- package/src/service/base/RedisCacheService.ts +7 -10
- package/src/service/crudstd/CrudStdService.ts +65 -11
- package/src/service/curd/CrudProQuick.ts +12 -14
- package/src/service/curd/CurdMixUtils.ts +0 -2
- package/src/service/curd/CurdProService.ts +2 -2
- package/src/service/proxyapi/ProxyApiLoadService.ts +1 -5
|
@@ -4,18 +4,18 @@ import * as ejs from 'ejs';
|
|
|
4
4
|
import { Inject, Provide } from '@midwayjs/core';
|
|
5
5
|
import { Context } from '@midwayjs/koa';
|
|
6
6
|
import { CurdMixService } from '../curd/CurdMixService';
|
|
7
|
-
import { IRequestCfgModel, IRequestModel } from '
|
|
8
|
-
import { KeysOfAuthType, KeysOfSimpleSQL, SqlDbType } from '
|
|
9
|
-
import { parseJsonObject } from '
|
|
10
|
-
import { ICrudStdAppInfo, ICrudStdAppInfoForSettingKey } from '
|
|
11
|
-
import { BizException } from '
|
|
12
|
-
import { ExecuteContext } from '
|
|
13
|
-
import { SystemTables } from '
|
|
7
|
+
import { IRequestCfgModel, IRequestModel } from '@/libs/crud-pro/interfaces';
|
|
8
|
+
import { KeysOfAuthType, KeysOfSimpleSQL, SqlDbType } from '@/libs/crud-pro/models/keys';
|
|
9
|
+
import { parseJsonObject } from '@/libs/utils/functions';
|
|
10
|
+
import { ICrudStdAppInfo, ICrudStdAppInfoForSettingKey } from '@/models/bizmodels';
|
|
11
|
+
import { BizException } from '@/models/devops';
|
|
12
|
+
import { ExecuteContext } from '@/libs/crud-pro/models/ExecuteContext';
|
|
13
|
+
import { SystemTables } from '@/models/SystemTables';
|
|
14
14
|
import { CrudStdActionService } from './CrudStdActionService';
|
|
15
15
|
import { CrudStdRelationService } from './CrudStdRelationService';
|
|
16
16
|
import { ApiBaseService } from '../base/ApiBaseService';
|
|
17
|
-
import { parseDatabaseName } from '
|
|
18
|
-
import { GLOBAL_STATIC_CONFIG } from '
|
|
17
|
+
import { parseDatabaseName } from '@/libs/crud-pro/utils/DatabaseName';
|
|
18
|
+
import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
|
|
19
19
|
import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
|
|
20
20
|
|
|
21
21
|
|
|
@@ -36,6 +36,9 @@ export interface IRequestModelCrudProExt extends IRequestModel {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
function isNotEmptyStr(str: any): boolean {
|
|
40
|
+
return typeof str === 'string' && str.trim().length > 0;
|
|
41
|
+
}
|
|
39
42
|
|
|
40
43
|
function getExecuteTableNameBySettingKey(appInfo: ICrudStdAppInfoForSettingKey, stdAction: ICrudStdActionParams): string {
|
|
41
44
|
const { settingKey } = stdAction || {};
|
|
@@ -43,14 +46,23 @@ function getExecuteTableNameBySettingKey(appInfo: ICrudStdAppInfoForSettingKey,
|
|
|
43
46
|
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
44
47
|
const actionsMap = appInfo.actionsMap || {};
|
|
45
48
|
|
|
49
|
+
|
|
50
|
+
// 操作按钮单独设置了mainTableName字段
|
|
46
51
|
const actionCfg = actionsMap[settingKey];
|
|
47
52
|
if (actionCfg) {
|
|
48
53
|
const mainTableName = _.get(actionCfg, 'component.props.mainTableName');
|
|
49
|
-
if (
|
|
54
|
+
if (isNotEmptyStr(mainTableName)) {
|
|
50
55
|
return mainTableName.trim();
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
// 全局配置了mainTableName字段
|
|
60
|
+
const globalMainTableName: string = _.get(stdCrudCfgObj, 'othersSetting.values.globalMainTableName');
|
|
61
|
+
if (isNotEmptyStr(globalMainTableName)) {
|
|
62
|
+
return globalMainTableName.trim();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 视图中配置的表。
|
|
54
66
|
return stdCrudCfgObj.tableBaseInfo.tableName;
|
|
55
67
|
}
|
|
56
68
|
|
|
@@ -95,6 +107,7 @@ export class CrudStdService extends ApiBaseService {
|
|
|
95
107
|
|
|
96
108
|
// 接口返回最大值
|
|
97
109
|
const maxLimit = _.get(stdCrudCfgObj, 'othersSetting.values.maxLimit');
|
|
110
|
+
|
|
98
111
|
if (typeof maxLimit === 'number' && maxLimit > 0) {
|
|
99
112
|
cfgModel.maxLimit = maxLimit;
|
|
100
113
|
}
|
|
@@ -103,6 +116,9 @@ export class CrudStdService extends ApiBaseService {
|
|
|
103
116
|
throw new BizException('没有权限');
|
|
104
117
|
}
|
|
105
118
|
|
|
119
|
+
// 软删除操作。
|
|
120
|
+
await this.fixCfgModelAndParamBySoftDelete(params, cfgModel, appInfo, sqlSimpleName);
|
|
121
|
+
|
|
106
122
|
// 根据用户配置,设置关联查询的数据信息。
|
|
107
123
|
await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
|
|
108
124
|
|
|
@@ -274,7 +290,7 @@ export class CrudStdService extends ApiBaseService {
|
|
|
274
290
|
* @private
|
|
275
291
|
*/
|
|
276
292
|
public async getParsedCrudStdAppInfo(appCode: string): Promise<ICrudStdAppInfo> {
|
|
277
|
-
const cacheKey =
|
|
293
|
+
const cacheKey = 'getParsedCrudStdAppInfo:' + appCode;
|
|
278
294
|
let appInfo: ICrudStdAppInfo = this.getFromCtxCache(cacheKey) as any;
|
|
279
295
|
if (!appInfo) {
|
|
280
296
|
appInfo = await this.getParsedCrudStdAppInfoPrivate(appCode);
|
|
@@ -334,6 +350,44 @@ export class CrudStdService extends ApiBaseService {
|
|
|
334
350
|
|
|
335
351
|
|
|
336
352
|
|
|
353
|
+
private async fixCfgModelAndParamBySoftDelete(params: IRequestModelCrudProExt, cfgModel: IRequestCfgModel, appInfo: ICrudStdAppInfoForSettingKey, sqlSimpleName: KeysOfSimpleSQL) {
|
|
354
|
+
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
355
|
+
//删除策略
|
|
356
|
+
const deleteStrategy = _.get(stdCrudCfgObj, 'othersSetting.values.deleteStrategy');
|
|
357
|
+
|
|
358
|
+
if (deleteStrategy !== 'soft') {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 删除操作,如果是软删除修改为update语句。
|
|
363
|
+
// 标准软删除:deleted_at 字段为0代表未删除,有任意时间字段代表已删除。
|
|
364
|
+
if (KeysOfSimpleSQL.SIMPLE_DELETE === sqlSimpleName) {
|
|
365
|
+
const userSession = this.ctx?.userSession?.getSessionInfo();
|
|
366
|
+
if (!params.data) {
|
|
367
|
+
params.data = {};
|
|
368
|
+
}
|
|
369
|
+
params.data.deleted_at = Date.now(); // 默认值为 0; 0代表未删除
|
|
370
|
+
params.data.deleted_by = userSession?.accountId || "";
|
|
371
|
+
|
|
372
|
+
// 执行update操作
|
|
373
|
+
cfgModel.sqlSimpleName = KeysOfSimpleSQL.SIMPLE_UPDATE;
|
|
374
|
+
|
|
375
|
+
if (!params.condition || Object.keys(params.condition).length === 0) {
|
|
376
|
+
throw new Error('执行删除操作,必须指定删除条件')
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// 查询操作。强制查询未删除的。
|
|
381
|
+
if (KeysOfSimpleSQL.SIMPLE_QUERY_ONE === sqlSimpleName || KeysOfSimpleSQL.SIMPLE_QUERY_PAGE === sqlSimpleName) {
|
|
382
|
+
if (!params.condition) {
|
|
383
|
+
params.condition = {};
|
|
384
|
+
}
|
|
385
|
+
params.condition.deleted_at = 0; // 未删除
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
337
391
|
private async fixCfgModelByFilterValue(params: IRequestModelCrudProExt, cfgModel: IRequestCfgModel, appInfo: ICrudStdAppInfoForSettingKey, arg3: { dbType: SqlDbType; dbName: string }) {
|
|
338
392
|
|
|
339
393
|
const { filterValue } = params || {};
|
|
@@ -49,9 +49,9 @@ export class CrudProQuick {
|
|
|
49
49
|
/**
|
|
50
50
|
* 随便获取一个。不推荐使用。建议使用getUniqueOne。
|
|
51
51
|
* @deprecated
|
|
52
|
-
* @param reqJson
|
|
53
|
-
* @param sqlTable
|
|
54
|
-
* @returns
|
|
52
|
+
* @param reqJson
|
|
53
|
+
* @param sqlTable
|
|
54
|
+
* @returns
|
|
55
55
|
*/
|
|
56
56
|
public async getOne(reqJson: IRequestModel, sqlTable?: string): Promise<any> {
|
|
57
57
|
const cfgModel: IRequestCfgModel = {
|
|
@@ -62,12 +62,11 @@ export class CrudProQuick {
|
|
|
62
62
|
return res.getOneObj();
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
65
|
/**
|
|
67
66
|
* 期望获取唯一的一个对象,如果数据库中的数量不唯一,则报错。
|
|
68
|
-
* @param reqJson
|
|
69
|
-
* @param sqlTable
|
|
70
|
-
* @returns
|
|
67
|
+
* @param reqJson
|
|
68
|
+
* @param sqlTable
|
|
69
|
+
* @returns
|
|
71
70
|
*/
|
|
72
71
|
public async getUniqueOne(reqJson: IRequestModel, sqlTable?: string): Promise<any> {
|
|
73
72
|
const cfgModel: IRequestCfgModel = {
|
|
@@ -77,24 +76,23 @@ export class CrudProQuick {
|
|
|
77
76
|
reqJson.pageNo = 1;
|
|
78
77
|
reqJson.pageSize = 1;
|
|
79
78
|
const res = await this.executeCrudByCfg(reqJson, cfgModel);
|
|
80
|
-
const resModel =
|
|
79
|
+
const resModel = res.getResModel();
|
|
81
80
|
const total_count = resModel.total_count;
|
|
82
81
|
const rows = resModel.rows;
|
|
83
|
-
if(total_count === 0) {
|
|
82
|
+
if (total_count === 0) {
|
|
84
83
|
return null;
|
|
85
84
|
}
|
|
86
|
-
if(total_count > 1) {
|
|
87
|
-
throw new Error(`[CrudProQuick][getUniqueOne] only one object is required, but got ${total_count}`)
|
|
85
|
+
if (total_count > 1) {
|
|
86
|
+
throw new Error(`[CrudProQuick][getUniqueOne] only one object is required, but got ${total_count}`);
|
|
88
87
|
}
|
|
89
88
|
return rows[0];
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
|
|
93
91
|
/**
|
|
94
92
|
* 获取数据列表
|
|
95
|
-
* @param reqJson
|
|
93
|
+
* @param reqJson
|
|
96
94
|
* @param sqlTable 数据库表名称
|
|
97
|
-
* @returns
|
|
95
|
+
* @returns
|
|
98
96
|
*/
|
|
99
97
|
public async getList(reqJson: IRequestModel, sqlTable?: string): Promise<any[]> {
|
|
100
98
|
const cfgModel: IRequestCfgModel = {
|
|
@@ -286,7 +286,6 @@ class CrudMixUtils {
|
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
|
|
290
289
|
const accountId = _.get(row, sourceColumn);
|
|
291
290
|
if (!accountId) {
|
|
292
291
|
return;
|
|
@@ -295,7 +294,6 @@ class CrudMixUtils {
|
|
|
295
294
|
const { toFatcmsUserAccountId } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
296
295
|
const fatcmsUserAccountId = toFatcmsUserAccountId(accountId);
|
|
297
296
|
|
|
298
|
-
|
|
299
297
|
const getValue = (code: string) => {
|
|
300
298
|
if (!map) {
|
|
301
299
|
return null;
|
|
@@ -34,7 +34,7 @@ function toVisitor(ctx: Context): IVisitorExt {
|
|
|
34
34
|
roleCodes: [],
|
|
35
35
|
functionCodes: [],
|
|
36
36
|
workbenchCode: workbenchInfo?.workbench_code || '',
|
|
37
|
-
bizExt: {}
|
|
37
|
+
bizExt: {},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -49,7 +49,7 @@ function toVisitor(ctx: Context): IVisitorExt {
|
|
|
49
49
|
roleCodes: sessionInfo.roleCodes || [],
|
|
50
50
|
functionCodes: sessionInfo.functionCodes || [],
|
|
51
51
|
workbenchCode: workbenchInfo?.workbench_code || '',
|
|
52
|
-
bizExt: sessionInfo.bizExt || {}
|
|
52
|
+
bizExt: sessionInfo.bizExt || {},
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -5,7 +5,7 @@ import { BaseService } from '../base/BaseService';
|
|
|
5
5
|
import { getRouteTrie, RouteTrie } from './RouteTrie';
|
|
6
6
|
import { RouteHandler } from './RouteHandler';
|
|
7
7
|
import { CurdProService } from '../curd/CurdProService';
|
|
8
|
-
import { SystemTables} from '../../models/SystemTables';
|
|
8
|
+
import { SystemTables } from '../../models/SystemTables';
|
|
9
9
|
import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
|
|
10
10
|
import { IProxyApiEntity, IUpstreamInfo } from '../../models/SystemEntities';
|
|
11
11
|
import { parseJsonObject } from '../../libs/utils/functions';
|
|
@@ -86,7 +86,6 @@ export class ProxyApiLoadService extends BaseService implements IScheduleService
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
private async buildUpstreamMap() {
|
|
89
|
-
|
|
90
89
|
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
91
90
|
|
|
92
91
|
// biz_tag={'upstream'}
|
|
@@ -114,10 +113,8 @@ export class ProxyApiLoadService extends BaseService implements IScheduleService
|
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
private async loadProxyApiEntity(workbench_code: string, upstreamMap: Record<string, IUpstreamInfo>): Promise<IProxyApiEntity[]> {
|
|
117
|
-
|
|
118
116
|
const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
|
|
119
117
|
|
|
120
|
-
|
|
121
118
|
const res = await this.curdProService.executeCrudByCfg(
|
|
122
119
|
{
|
|
123
120
|
condition: {},
|
|
@@ -170,5 +167,4 @@ export class ProxyApiLoadService extends BaseService implements IScheduleService
|
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
|
-
|
|
174
170
|
}
|