midway-fatcms 0.0.1-beta.56 → 0.0.1-beta.57
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 +34 -1
- 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 +52 -10
- 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
|
|
|
@@ -95,6 +95,7 @@ export class CrudStdService extends ApiBaseService {
|
|
|
95
95
|
|
|
96
96
|
// 接口返回最大值
|
|
97
97
|
const maxLimit = _.get(stdCrudCfgObj, 'othersSetting.values.maxLimit');
|
|
98
|
+
|
|
98
99
|
if (typeof maxLimit === 'number' && maxLimit > 0) {
|
|
99
100
|
cfgModel.maxLimit = maxLimit;
|
|
100
101
|
}
|
|
@@ -103,6 +104,9 @@ export class CrudStdService extends ApiBaseService {
|
|
|
103
104
|
throw new BizException('没有权限');
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
// 软删除操作。
|
|
108
|
+
await this.fixCfgModelAndParamBySoftDelete(params, cfgModel, appInfo, sqlSimpleName);
|
|
109
|
+
|
|
106
110
|
// 根据用户配置,设置关联查询的数据信息。
|
|
107
111
|
await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
|
|
108
112
|
|
|
@@ -274,7 +278,7 @@ export class CrudStdService extends ApiBaseService {
|
|
|
274
278
|
* @private
|
|
275
279
|
*/
|
|
276
280
|
public async getParsedCrudStdAppInfo(appCode: string): Promise<ICrudStdAppInfo> {
|
|
277
|
-
const cacheKey =
|
|
281
|
+
const cacheKey = 'getParsedCrudStdAppInfo:' + appCode;
|
|
278
282
|
let appInfo: ICrudStdAppInfo = this.getFromCtxCache(cacheKey) as any;
|
|
279
283
|
if (!appInfo) {
|
|
280
284
|
appInfo = await this.getParsedCrudStdAppInfoPrivate(appCode);
|
|
@@ -334,6 +338,44 @@ export class CrudStdService extends ApiBaseService {
|
|
|
334
338
|
|
|
335
339
|
|
|
336
340
|
|
|
341
|
+
private async fixCfgModelAndParamBySoftDelete(params: IRequestModelCrudProExt, cfgModel: IRequestCfgModel, appInfo: ICrudStdAppInfoForSettingKey, sqlSimpleName: KeysOfSimpleSQL) {
|
|
342
|
+
const stdCrudCfgObj = appInfo.stdCrudCfgObj;
|
|
343
|
+
//删除策略
|
|
344
|
+
const deleteStrategy = _.get(stdCrudCfgObj, 'othersSetting.values.deleteStrategy');
|
|
345
|
+
|
|
346
|
+
if(deleteStrategy !== 'soft') {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 删除操作,如果是软删除修改为update语句。
|
|
351
|
+
// 标准软删除:deleted_at 字段为0代表未删除,有任意时间字段代表已删除。
|
|
352
|
+
if(KeysOfSimpleSQL.SIMPLE_DELETE === sqlSimpleName) {
|
|
353
|
+
const userSession = this.ctx?.userSession?.getSessionInfo();
|
|
354
|
+
if(!params.data) {
|
|
355
|
+
params.data = {};
|
|
356
|
+
}
|
|
357
|
+
params.data.deleted_at = Date.now(); // 默认值为 0; 0代表未删除
|
|
358
|
+
params.data.deleted_by = userSession?.accountId || "";
|
|
359
|
+
|
|
360
|
+
// 执行update操作
|
|
361
|
+
cfgModel.sqlSimpleName = KeysOfSimpleSQL.SIMPLE_UPDATE;
|
|
362
|
+
|
|
363
|
+
if(!params.condition || Object.keys(params.condition).length === 0) {
|
|
364
|
+
throw new Error('执行删除操作,必须指定删除条件')
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// 查询操作。强制查询未删除的。
|
|
369
|
+
if (KeysOfSimpleSQL.SIMPLE_QUERY_ONE === sqlSimpleName || KeysOfSimpleSQL.SIMPLE_QUERY_PAGE === sqlSimpleName) {
|
|
370
|
+
if(!params.condition) {
|
|
371
|
+
params.condition = {};
|
|
372
|
+
}
|
|
373
|
+
params.condition.deleted_at = 0; // 未删除
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
337
379
|
private async fixCfgModelByFilterValue(params: IRequestModelCrudProExt, cfgModel: IRequestCfgModel, appInfo: ICrudStdAppInfoForSettingKey, arg3: { dbType: SqlDbType; dbName: string }) {
|
|
338
380
|
|
|
339
381
|
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
|
}
|