midway-fatcms 0.0.1-beta.44 → 0.0.1-beta.45
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/manage/CrudStandardDesignApi.d.ts +8 -0
- package/dist/controller/manage/CrudStandardDesignApi.js +54 -9
- package/dist/libs/global-config/global-config.d.ts +13 -2
- package/dist/libs/global-config/global-config.js +2 -1
- package/dist/libs/utils/parseCreateSql.d.ts +6 -1
- package/dist/libs/utils/parseCreateSql.js +2 -1
- package/dist/service/crudstd/CrudStdService.js +5 -2
- package/dist/service/curd/CurdMixService.d.ts +3 -2
- package/package.json +1 -1
|
@@ -35,4 +35,12 @@ export declare class CrudStandardDesignApi extends BaseApiController {
|
|
|
35
35
|
private getTableListOfPostgreSQL;
|
|
36
36
|
private getTableFieldsOfSqlServer;
|
|
37
37
|
private getTableFieldsOfPostgreSQL;
|
|
38
|
+
/**
|
|
39
|
+
* 获取PostgreSQL建表语句的注释
|
|
40
|
+
* @param dbName
|
|
41
|
+
* @param schemaname
|
|
42
|
+
* @param tableName
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
private getTableFieldsCommentsMapOfPostgreSQL;
|
|
38
46
|
}
|
|
@@ -254,14 +254,14 @@ let CrudStandardDesignApi = class CrudStandardDesignApi extends BaseApiControlle
|
|
|
254
254
|
throw new exceptions_1.CommonException('DB_NOT_FOUND', '数据库配置没有找到:' + dbName);
|
|
255
255
|
}
|
|
256
256
|
const schemaname = 'public';
|
|
257
|
-
const columnArraySql = `
|
|
258
|
-
|
|
259
|
-
SELECT
|
|
260
|
-
*
|
|
261
|
-
FROM information_schema.columns
|
|
262
|
-
WHERE table_schema = $1 and table_name = $2
|
|
263
|
-
ORDER BY ordinal_position;
|
|
264
|
-
|
|
257
|
+
const columnArraySql = `
|
|
258
|
+
|
|
259
|
+
SELECT
|
|
260
|
+
*
|
|
261
|
+
FROM information_schema.columns
|
|
262
|
+
WHERE table_schema = $1 and table_name = $2
|
|
263
|
+
ORDER BY ordinal_position;
|
|
264
|
+
|
|
265
265
|
`.trim();
|
|
266
266
|
const dbType = keys_1.SqlDbType.postgres;
|
|
267
267
|
const columnArray = await this.curdMixService.executeSQL({
|
|
@@ -271,11 +271,12 @@ let CrudStandardDesignApi = class CrudStandardDesignApi extends BaseApiControlle
|
|
|
271
271
|
crudType: keys_1.KeyOfCrudTypes.SYS_QUERY,
|
|
272
272
|
executeSqlArgs: [schemaname, tableName],
|
|
273
273
|
});
|
|
274
|
+
const commentMap = await this.getTableFieldsCommentsMapOfPostgreSQL(dbName, schemaname, tableName);
|
|
274
275
|
const fields = columnArray.map(columnObj => {
|
|
275
276
|
const { column_name, is_nullable, column_default, data_type, is_identity, ...others } = columnObj;
|
|
276
277
|
return {
|
|
277
278
|
fieldIndex: column_name || '',
|
|
278
|
-
fieldTitle: column_name || '',
|
|
279
|
+
fieldTitle: commentMap[column_name] || column_name || '',
|
|
279
280
|
isNullable: is_nullable,
|
|
280
281
|
defaultValue: column_default || '',
|
|
281
282
|
extra: others,
|
|
@@ -293,6 +294,50 @@ let CrudStandardDesignApi = class CrudStandardDesignApi extends BaseApiControlle
|
|
|
293
294
|
},
|
|
294
295
|
};
|
|
295
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* 获取PostgreSQL建表语句的注释
|
|
299
|
+
* @param dbName
|
|
300
|
+
* @param schemaname
|
|
301
|
+
* @param tableName
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
304
|
+
async getTableFieldsCommentsMapOfPostgreSQL(dbName, schemaname, tableName) {
|
|
305
|
+
const commentArraySql = `
|
|
306
|
+
SELECT
|
|
307
|
+
n.nspname AS schema_name,
|
|
308
|
+
c.relname AS table_name,
|
|
309
|
+
a.attname AS column_name,
|
|
310
|
+
d.description AS column_comment
|
|
311
|
+
FROM
|
|
312
|
+
pg_class c
|
|
313
|
+
JOIN
|
|
314
|
+
pg_namespace n ON c.relnamespace = n.oid
|
|
315
|
+
JOIN
|
|
316
|
+
pg_attribute a ON c.oid = a.attrelid
|
|
317
|
+
LEFT JOIN
|
|
318
|
+
pg_description d ON c.oid = d.objoid AND a.attnum = d.objsubid
|
|
319
|
+
WHERE
|
|
320
|
+
n.nspname = $1
|
|
321
|
+
AND c.relname = $2
|
|
322
|
+
AND a.attnum > 0
|
|
323
|
+
ORDER BY
|
|
324
|
+
a.attnum
|
|
325
|
+
`;
|
|
326
|
+
const dbType = keys_1.SqlDbType.postgres;
|
|
327
|
+
const commentArray = await this.curdMixService.executeSQL({
|
|
328
|
+
executeSql: commentArraySql,
|
|
329
|
+
sqlDatabase: dbName,
|
|
330
|
+
sqlDbType: dbType,
|
|
331
|
+
crudType: keys_1.KeyOfCrudTypes.SYS_QUERY,
|
|
332
|
+
executeSqlArgs: [schemaname, tableName],
|
|
333
|
+
});
|
|
334
|
+
const map = {};
|
|
335
|
+
commentArray.forEach(commentObj => {
|
|
336
|
+
const { column_name, column_comment } = commentObj;
|
|
337
|
+
map[column_name] = (0, parseCreateSql_1.parseTableFieldTitleFromComment)(column_comment);
|
|
338
|
+
});
|
|
339
|
+
return map;
|
|
340
|
+
}
|
|
296
341
|
};
|
|
297
342
|
__decorate([
|
|
298
343
|
(0, core_1.Config)('mysql2'),
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import { IRequestCfgModel, IRequestModel } from '../crud-pro/interfaces';
|
|
2
|
+
import { ExecuteContext } from '../crud-pro/models/ExecuteContext';
|
|
1
3
|
import { SqlDbType } from '../crud-pro/models/keys';
|
|
4
|
+
import { Context } from '@midwayjs/koa';
|
|
2
5
|
interface IGlobalStaticConfig {
|
|
3
6
|
/**
|
|
4
|
-
* CrudStd:
|
|
7
|
+
* CrudStd: 业务系统自定义的修改:查询前的查询条件:cfgModel
|
|
5
8
|
* @param reqJson
|
|
6
9
|
* @param cfgModel
|
|
7
10
|
* @param appInfo
|
|
8
11
|
* @param ctx
|
|
9
12
|
*/
|
|
10
|
-
bizUpdateCfgModelForCrudStd(reqJson:
|
|
13
|
+
bizUpdateCfgModelForCrudStd(reqJson: IRequestModel, cfgModel: IRequestCfgModel, appInfo: any, ctx: Context): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* CrudStd: 业务系统自定义的修改:查询后的返回值。
|
|
16
|
+
* @param reqJson
|
|
17
|
+
* @param cfgModel
|
|
18
|
+
* @param appInfo
|
|
19
|
+
* @param ctx
|
|
20
|
+
*/
|
|
21
|
+
bizUpdateExecuteContextForCrudStd(reqJson: IRequestModel, cfgModel: IRequestCfgModel, appInfo: any, ctx: Context, executeContext: ExecuteContext): Promise<any>;
|
|
11
22
|
/**
|
|
12
23
|
* CrudMtd: 业务系统自定义的修改cfgModel
|
|
13
24
|
* @param reqJson
|
|
@@ -9,6 +9,7 @@ class GlobalStaticConfig {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
this.configObject = {
|
|
11
11
|
bizUpdateCfgModelForCrudStd: noop,
|
|
12
|
+
bizUpdateExecuteContextForCrudStd: noop,
|
|
12
13
|
bizUpdateCfgModelForCrudMtd: noop,
|
|
13
14
|
bizUpdateCfgModelForCrudPro: noop,
|
|
14
15
|
generateUserAccountId: null,
|
|
@@ -17,7 +18,7 @@ class GlobalStaticConfig {
|
|
|
17
18
|
},
|
|
18
19
|
SystemDbName: 'fatcms',
|
|
19
20
|
SystemDbType: keys_1.SqlDbType.mysql,
|
|
20
|
-
maxPageSizeOfExportExcel: 1000
|
|
21
|
+
maxPageSizeOfExportExcel: 1000,
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
getConfig() {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 移除引号
|
|
3
|
+
* @param s
|
|
4
|
+
*/
|
|
5
|
+
declare function parseTableFieldTitleFromComment(s: string): string;
|
|
1
6
|
declare function parseCreateSqlToTitleMap(createSqlStr: string): {
|
|
2
7
|
tableTitle: string;
|
|
3
8
|
fieldsTitleMap: {};
|
|
4
9
|
};
|
|
5
|
-
export { parseCreateSqlToTitleMap };
|
|
10
|
+
export { parseCreateSqlToTitleMap, parseTableFieldTitleFromComment };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCreateSqlToTitleMap = void 0;
|
|
3
|
+
exports.parseTableFieldTitleFromComment = exports.parseCreateSqlToTitleMap = void 0;
|
|
4
4
|
function isChineseChar(char) {
|
|
5
5
|
const reg = /[\u4e00-\u9fff]/;
|
|
6
6
|
return reg.test(char);
|
|
@@ -34,6 +34,7 @@ function parseTableFieldTitleFromComment(s) {
|
|
|
34
34
|
}
|
|
35
35
|
return arr.join('');
|
|
36
36
|
}
|
|
37
|
+
exports.parseTableFieldTitleFromComment = parseTableFieldTitleFromComment;
|
|
37
38
|
/**
|
|
38
39
|
* 从最后一行中提取表格的标题
|
|
39
40
|
* @param arr
|
|
@@ -69,9 +69,12 @@ let CrudStdService = class CrudStdService extends ApiBaseService_1.ApiBaseServic
|
|
|
69
69
|
await this.crudStdRelationService.addCfgModelColumnsRelation(cfgModel, appInfo);
|
|
70
70
|
// 根据表结构的数据类型,修正数据类型
|
|
71
71
|
await this.fixDataFieldTypeBySqlTableField(params, cfgModel, appInfo, { dbType, dbName });
|
|
72
|
-
//
|
|
72
|
+
// 业务系统自定义的修改:查询前的查询条件:cfgModel
|
|
73
73
|
await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudStd(params, cfgModel, appInfo, this.ctx);
|
|
74
|
-
|
|
74
|
+
const crudExeCtx = await this.curdMixService.executeCrudByCfg(params, cfgModel);
|
|
75
|
+
// 业务系统自定义的修改:查询后的返回值。
|
|
76
|
+
await global_config_1.GLOBAL_STATIC_CONFIG.getConfig().bizUpdateExecuteContextForCrudStd(params, cfgModel, appInfo, this.ctx, crudExeCtx);
|
|
77
|
+
return crudExeCtx;
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
77
80
|
* 获取appInfo 并且拿到当前settingKey相关的信息
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ColumnRelation, IRequestCfgModel, IRequestModel, ISqlCfgModel } from '../../libs/crud-pro/interfaces';
|
|
2
2
|
import { IRequestCfgModel2 } from '../../models/bizmodels';
|
|
3
3
|
import { SqlDbType } from '../../libs/crud-pro/models/keys';
|
|
4
|
+
import { ExecuteContext } from '../../libs/crud-pro/models/ExecuteContext';
|
|
4
5
|
export interface ILinkColumnRelationParam {
|
|
5
6
|
columnsRelations: ColumnRelation[];
|
|
6
7
|
}
|
|
@@ -12,10 +13,10 @@ export declare class CurdMixService {
|
|
|
12
13
|
private curdMixByWorkbenchService;
|
|
13
14
|
private curdMixByLinkToCustomService;
|
|
14
15
|
private prepare;
|
|
15
|
-
executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2): Promise<
|
|
16
|
+
executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2): Promise<ExecuteContext>;
|
|
16
17
|
getBbUtil(sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string): import("./CrudProQuick").CrudProQuick;
|
|
17
18
|
executeSQL(sqlCfgModel: ISqlCfgModel): Promise<any>;
|
|
18
|
-
executeCrud(reqJson: IRequestModel): Promise<
|
|
19
|
+
executeCrud(reqJson: IRequestModel): Promise<ExecuteContext>;
|
|
19
20
|
getCachedCfgByMethod(method: string): Promise<IRequestCfgModel>;
|
|
20
21
|
/**
|
|
21
22
|
* 根据配置的关联关系,直接关联数据
|