midway-fatcms 0.0.1-beta.25 → 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.
Files changed (171) hide show
  1. package/dist/controller/home.controller.js +2 -1
  2. package/dist/controller/render/AppRenderController.js +2 -1
  3. package/dist/models/bizmodels.d.ts +1 -0
  4. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +1 -1
  5. package/dist/service/crudstd/CrudStdService.d.ts +0 -6
  6. package/dist/service/crudstd/CrudStdService.js +13 -33
  7. package/package.json +1 -5
  8. package/src/config/config.default.ts +0 -207
  9. package/src/config/seed/aeskey.txt +0 -1
  10. package/src/config/utils.ts +0 -22
  11. package/src/configuration.ts +0 -109
  12. package/src/controller/base/BaseApiController.ts +0 -170
  13. package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
  14. package/src/controller/gateway/AsyncTaskController.ts +0 -157
  15. package/src/controller/gateway/CrudMtdGatewayController.ts +0 -111
  16. package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
  17. package/src/controller/gateway/DocGatewayController.ts +0 -173
  18. package/src/controller/gateway/FileController.ts +0 -109
  19. package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
  20. package/src/controller/gateway/PublicApiController.ts +0 -142
  21. package/src/controller/gateway/StaticController.ts +0 -298
  22. package/src/controller/helpers.controller.ts +0 -161
  23. package/src/controller/home.controller.ts +0 -64
  24. package/src/controller/manage/AnyApiMangeApi.ts +0 -66
  25. package/src/controller/manage/AppLogMangeApi.ts +0 -53
  26. package/src/controller/manage/AppMangeApi.ts +0 -53
  27. package/src/controller/manage/AppPageMangeApi.ts +0 -52
  28. package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
  29. package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
  30. package/src/controller/manage/CrudStandardDesignApi.ts +0 -346
  31. package/src/controller/manage/DataDictManageApi.ts +0 -78
  32. package/src/controller/manage/DeployManageApi.ts +0 -175
  33. package/src/controller/manage/DocLibManageApi.ts +0 -69
  34. package/src/controller/manage/DocManageApi.ts +0 -99
  35. package/src/controller/manage/FileManageApi.ts +0 -45
  36. package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
  37. package/src/controller/manage/MenuManageApi.ts +0 -58
  38. package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
  39. package/src/controller/manage/SuperAdminManageApi.ts +0 -139
  40. package/src/controller/manage/SysConfigMangeApi.ts +0 -95
  41. package/src/controller/manage/SystemInfoManageApi.ts +0 -53
  42. package/src/controller/manage/UserAccountManageApi.ts +0 -94
  43. package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
  44. package/src/controller/myinfo/AuthController.ts +0 -108
  45. package/src/controller/myinfo/MyInfoController.ts +0 -32
  46. package/src/controller/render/AppRenderController.ts +0 -79
  47. package/src/controller/test.controller.ts +0 -37
  48. package/src/filter/default.filter.ts +0 -13
  49. package/src/filter/notfound.filter.ts +0 -10
  50. package/src/index.ts +0 -106
  51. package/src/interface.ts +0 -31
  52. package/src/libs/crud-pro/CrudPro.ts +0 -165
  53. package/src/libs/crud-pro/defaultConfigs.ts +0 -15
  54. package/src/libs/crud-pro/exceptions.ts +0 -124
  55. package/src/libs/crud-pro/interfaces.ts +0 -190
  56. package/src/libs/crud-pro/models/ExecuteContext.ts +0 -120
  57. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -96
  58. package/src/libs/crud-pro/models/FuncContext.ts +0 -21
  59. package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
  60. package/src/libs/crud-pro/models/RequestModel.ts +0 -141
  61. package/src/libs/crud-pro/models/ResModel.ts +0 -19
  62. package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
  63. package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
  64. package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
  65. package/src/libs/crud-pro/models/Transaction.ts +0 -73
  66. package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
  67. package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
  68. package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -102
  69. package/src/libs/crud-pro/models/keys.ts +0 -159
  70. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -83
  71. package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
  72. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -262
  73. package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
  74. package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
  75. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -354
  76. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -185
  77. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -393
  78. package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -94
  79. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -86
  80. package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
  81. package/src/libs/crud-pro/sql.txt +0 -120
  82. package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
  83. package/src/libs/crud-pro/utils/DatabaseName.ts +0 -60
  84. package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
  85. package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
  86. package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
  87. package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
  88. package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
  89. package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
  90. package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
  91. package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
  92. package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -165
  93. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
  94. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
  95. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
  96. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
  97. package/src/libs/crud-pro/utils/sqlConvert/convertMix.ts +0 -26
  98. package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
  99. package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
  100. package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
  101. package/src/libs/global-config/global-config.ts +0 -78
  102. package/src/libs/utils/common-dto.ts +0 -52
  103. package/src/libs/utils/crypto-utils.ts +0 -50
  104. package/src/libs/utils/errorToString.ts +0 -61
  105. package/src/libs/utils/fatcms-request.ts +0 -103
  106. package/src/libs/utils/functions.ts +0 -73
  107. package/src/libs/utils/ordernum-utils.ts +0 -14
  108. package/src/libs/utils/parseConfig.ts +0 -54
  109. package/src/libs/utils/parseCreateSql.ts +0 -91
  110. package/src/libs/utils/render-utils.ts +0 -184
  111. package/src/middleware/forbidden.middleware.ts +0 -52
  112. package/src/middleware/global.middleware.ts +0 -280
  113. package/src/middleware/permission.middleware.ts +0 -80
  114. package/src/middleware/tx.middleware.ts +0 -30
  115. package/src/models/AsyncTaskModel.ts +0 -82
  116. package/src/models/RedisKeys.ts +0 -13
  117. package/src/models/SystemEntities.ts +0 -115
  118. package/src/models/SystemPerm.ts +0 -105
  119. package/src/models/SystemTables.ts +0 -27
  120. package/src/models/bizmodels.ts +0 -120
  121. package/src/models/contextLogger.ts +0 -132
  122. package/src/models/devops.ts +0 -17
  123. package/src/models/userSession.ts +0 -216
  124. package/src/schedule/anonymousContext.ts +0 -73
  125. package/src/schedule/index.ts +0 -12
  126. package/src/schedule/runSchedule.ts +0 -82
  127. package/src/schedule/scheduleNames.ts +0 -21
  128. package/src/service/AuthService.ts +0 -272
  129. package/src/service/EnumInfoService.ts +0 -130
  130. package/src/service/FileCenterService.ts +0 -395
  131. package/src/service/SysConfigService.ts +0 -37
  132. package/src/service/UserAccountService.ts +0 -107
  133. package/src/service/UserSessionService.ts +0 -78
  134. package/src/service/VisitStatService.ts +0 -166
  135. package/src/service/WorkbenchService.ts +0 -165
  136. package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
  137. package/src/service/anyapi/AnyApiService.ts +0 -186
  138. package/src/service/asyncTask/AsyncTaskRunnerService.ts +0 -266
  139. package/src/service/asyncTask/AsyncTaskService.ts +0 -21
  140. package/src/service/asyncTask/handler/ExcelInfoModel.ts +0 -11
  141. package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +0 -245
  142. package/src/service/asyncTask/handler/ExportExcelByInnerHttpHandler.ts +0 -147
  143. package/src/service/asyncTask/handler/ExportExcelByStdCrudHandler.ts +0 -138
  144. package/src/service/base/ApiBaseService.ts +0 -42
  145. package/src/service/base/ApiRateLimiter.ts +0 -59
  146. package/src/service/base/BaseService.ts +0 -100
  147. package/src/service/base/RedisCacheService.ts +0 -38
  148. package/src/service/crudstd/CrudStdActionService.ts +0 -27
  149. package/src/service/crudstd/CrudStdConstant.ts +0 -62
  150. package/src/service/crudstd/CrudStdRelationService.ts +0 -78
  151. package/src/service/crudstd/CrudStdService.ts +0 -283
  152. package/src/service/curd/CrudProQuick.ts +0 -131
  153. package/src/service/curd/CurdMixByAccountService.ts +0 -90
  154. package/src/service/curd/CurdMixByDictService.ts +0 -114
  155. package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -219
  156. package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
  157. package/src/service/curd/CurdMixByWorkbenchService.ts +0 -71
  158. package/src/service/curd/CurdMixService.ts +0 -97
  159. package/src/service/curd/CurdMixUtils.ts +0 -311
  160. package/src/service/curd/CurdProService.ts +0 -229
  161. package/src/service/curd/fixCfgModel.ts +0 -139
  162. package/src/service/proxyapi/ProxyApiLoadService.ts +0 -174
  163. package/src/service/proxyapi/ProxyApiService.ts +0 -262
  164. package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
  165. package/src/service/proxyapi/RouteHandler.ts +0 -8
  166. package/src/service/proxyapi/RouteTrie.ts +0 -74
  167. package/src/service/proxyapi/WeightedRandom.ts +0 -37
  168. package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
  169. package/src/views/404_app.html +0 -31
  170. package/src/views/404_workbench.html +0 -34
  171. package/src/views/static/favicon.ico +0 -0
@@ -1,71 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import * as _ from 'lodash';
4
- import { LRUCache } from 'lru-cache';
5
- import { CurdProService } from './CurdProService';
6
- import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
7
- import { CrudMixUtils, RelatedType } from './CurdMixUtils';
8
- import { SystemTables } from '@/models/SystemTables';
9
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
10
- import { ColumnRelation } from '@/libs/crud-pro/interfaces';
11
- import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
12
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
13
-
14
- const lruCache = new LRUCache<string, any>({
15
- max: 500,
16
- ttl: 1000 * 60 * 5,
17
- ttlAutopurge: true,
18
- });
19
-
20
- const workbenchMixUtils = new CrudMixUtils(RelatedType.workbenchBasic);
21
-
22
- const TMP_CTX_KEY = _.uniqueId('CurdMixByWorkbenchService');
23
-
24
- @Provide()
25
- export class CurdMixByWorkbenchService implements IExecuteContextHandler {
26
- @Inject()
27
- ctx: Context;
28
-
29
- @Inject()
30
- protected curdProService: CurdProService;
31
-
32
- private async loadWorkbenchListMap() {
33
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
34
-
35
- let workbenchListMap = lruCache.get('workbenchListMap');
36
- if (!workbenchListMap) {
37
- const reqJson = {
38
- columns: 'workbench_code,workbench_name,workbench_domain',
39
- condition: {},
40
- };
41
- const res = await this.curdProService.executeCrudByCfg(reqJson, {
42
- sqlTable: SystemTables.sys_workbench,
43
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
44
- sqlDatabase: SystemDbName,
45
- sqlDbType: SystemDbType,
46
- });
47
- const workbenchList = res.getResRows();
48
- workbenchListMap = MixinUtils.toNewMap(workbenchList, (obj: any) => obj.workbench_code);
49
- lruCache.set('workbenchListMap', workbenchListMap);
50
- }
51
- return workbenchListMap;
52
- }
53
-
54
- async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
55
- const relations = workbenchMixUtils.pickColumnRelations(executeContext);
56
- if (!relations || relations.length === 0) {
57
- return;
58
- }
59
- executeContext[TMP_CTX_KEY] = await this.loadWorkbenchListMap();
60
- }
61
-
62
- async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
63
- const userInfoMap = executeContext[TMP_CTX_KEY] as Map<string, any>;
64
- if (!userInfoMap || userInfoMap.size === 0) {
65
- return;
66
- }
67
- workbenchMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
68
- workbenchMixUtils.copyColumnRelationToRowNoRelatedCode(row, userInfoMap, columnRelation);
69
- });
70
- }
71
- }
@@ -1,97 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { CurdProService } from './CurdProService';
3
- import { CurdMixByDictService } from './CurdMixByDictService';
4
- import { ColumnRelation, IRequestCfgModel, IRequestModel, ISqlCfgModel } from '@/libs/crud-pro/interfaces';
5
- import { CurdMixBySysConfigService } from './CurdMixBySysConfigService';
6
- import { CurdMixByAccountService } from './CurdMixByAccountService';
7
- import { RelatedType } from './CurdMixUtils';
8
- import { CurdMixByWorkbenchService } from './CurdMixByWorkbenchService';
9
- import { IRequestCfgModel2 } from '@/models/bizmodels';
10
- import { CurdMixByLinkToCustomService } from './CurdMixByLinkToCustomService';
11
- import { SqlDbType } from '@/libs/crud-pro/models/keys';
12
- import { IExecuteContextCustom } from '@/libs/crud-pro/models/ExecuteContext';
13
-
14
- export interface ILinkColumnRelationParam {
15
- columnsRelations: ColumnRelation[];
16
- }
17
-
18
- @Provide()
19
- export class CurdMixService {
20
- @Inject()
21
- private curdProService: CurdProService;
22
-
23
- @Inject()
24
- private curdMixByDictService: CurdMixByDictService;
25
-
26
- @Inject()
27
- private curdMixBySysConfigService: CurdMixBySysConfigService;
28
-
29
- @Inject()
30
- private curdMixByAccountService: CurdMixByAccountService;
31
-
32
- @Inject()
33
- private curdMixByWorkbenchService: CurdMixByWorkbenchService;
34
-
35
- @Inject()
36
- private curdMixByLinkToCustomService: CurdMixByLinkToCustomService;
37
-
38
- private prepare() {
39
- this.curdProService.setResponseCfgHandlers(RelatedType.dict, this.curdMixByDictService);
40
- this.curdProService.setResponseCfgHandlers(RelatedType.sysCfgEnum, this.curdMixBySysConfigService);
41
- this.curdProService.setResponseCfgHandlers(RelatedType.accountBasic, this.curdMixByAccountService);
42
- this.curdProService.setResponseCfgHandlers(RelatedType.workbenchBasic, this.curdMixByWorkbenchService);
43
- this.curdProService.setResponseCfgHandlers(RelatedType.linkToCustom, this.curdMixByLinkToCustomService);
44
- }
45
-
46
- async executeCrudByCfg(reqJson: IRequestModel, cfgModel: IRequestCfgModel2) {
47
- this.prepare();
48
- return this.curdProService.executeCrudByCfg(reqJson, cfgModel);
49
- }
50
-
51
- getBbUtil(sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string) {
52
- this.prepare();
53
- return this.curdProService.getBbUtil(sqlDatabase, sqlDbType, sqlTable);
54
- }
55
-
56
- async executeSQL(sqlCfgModel: ISqlCfgModel) {
57
- this.prepare();
58
- return this.curdProService.executeSQL(sqlCfgModel);
59
- }
60
-
61
- async executeCrud(reqJson: IRequestModel) {
62
- this.prepare();
63
- return this.curdProService.executeCrud(reqJson);
64
- }
65
-
66
- public async getCachedCfgByMethod(method: string): Promise<IRequestCfgModel> {
67
- return this.curdProService.getCachedCfgByMethod(method);
68
- }
69
-
70
- /**
71
- * 根据配置的关联关系,直接关联数据
72
- * @param rows
73
- * @param param
74
- * @returns
75
- */
76
- public async linkColumnRelationDatas(rows: any[], param: ILinkColumnRelationParam) {
77
- if (!Array.isArray(rows) || rows.length === 0) {
78
- return;
79
- }
80
-
81
- this.prepare();
82
-
83
- const exeCtx: IExecuteContextCustom = {
84
- rows,
85
- columnsRelation: param.columnsRelations,
86
- isCustomContext: true,
87
- };
88
-
89
- const responseCfgHandlers = this.curdProService.getResponseCfgHandlers();
90
- const handlers = Object.values(responseCfgHandlers);
91
- for (let i = 0; i < handlers.length; i++) {
92
- const handler = handlers[i];
93
- await handler.handleExecuteContextPrepare(exeCtx);
94
- await handler.handleExecuteContext(exeCtx);
95
- }
96
- }
97
- }
@@ -1,311 +0,0 @@
1
- import { ColumnRelation, CopyAttr } from '@/libs/crud-pro/interfaces';
2
- import { ExecuteContext, HandleExecuteContextType, IExecuteContextCustom } from '@/libs/crud-pro/models/ExecuteContext';
3
- import { KeyOfCrudTypes } from '@/libs/crud-pro/models/keys';
4
- import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
5
- import { SqlCfgModel } from '@/libs/crud-pro/models/SqlCfgModel';
6
- import { RequestCfgModel } from '@/libs/crud-pro/models/RequestCfgModel';
7
- import * as _ from 'lodash';
8
- import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
9
- import { parseJsonObject } from '@/libs/utils/functions';
10
-
11
- enum RelatedType {
12
- dict = 'dict', // 关联数据字典
13
- sysCfgEnum = 'sysCfgEnum', // 配置文件中,必须包含code一列,作为唯一键。
14
- linkToCustom = 'linkToCustom', // 自定义指定任何表
15
- accountBasic = 'accountBasic', // 个人账号基本信息
16
- workbenchBasic = 'workbenchBasic', // 站点基本信息
17
- }
18
-
19
- type FuncRowColumnRelation = (row: any, columnRelation: ColumnRelation) => void;
20
-
21
- const { isNotEmpty } = MixinUtils;
22
-
23
- function getColumnsRelationAll(sqlCfg: SqlCfgModel, cfgModel: RequestCfgModel): ColumnRelation[] {
24
- if (sqlCfg && Array.isArray(sqlCfg.columnsRelation) && sqlCfg.columnsRelation.length > 0) {
25
- return sqlCfg.columnsRelation;
26
- }
27
- if (cfgModel && Array.isArray(cfgModel.columnsRelation) && cfgModel.columnsRelation.length > 0) {
28
- return cfgModel.columnsRelation;
29
- }
30
- return [];
31
- }
32
-
33
- const forEachColumnsRelation = (row: any, columnsRelation: ColumnRelation[], func: FuncRowColumnRelation) => {
34
- for (let i = 0; i < columnsRelation.length; i++) {
35
- func(row, columnsRelation[i]);
36
- }
37
- };
38
-
39
- function copyBySingleSourceValue(row: any, sourceValue: any, targetColumns: CopyAttr[], getValue: any) {
40
- // const codeObject = map.get(sourceValue);
41
- const codeObject = getValue(sourceValue);
42
- if (typeof codeObject === 'undefined' || codeObject === null) {
43
- return;
44
- }
45
-
46
- if (Array.isArray(targetColumns)) {
47
- for (let i = 0; i < targetColumns.length; i++) {
48
- const targetColumn = targetColumns[i];
49
- const toStr = targetColumn.to.replace('[$ARRAY_INDEX]', '');
50
- if (targetColumn.from === '*') {
51
- _.set(row, toStr, codeObject);
52
- } else {
53
- const dictAttrValue = _.get(codeObject, targetColumn.from);
54
- if (typeof dictAttrValue !== 'undefined' && dictAttrValue !== null) {
55
- _.set(row, toStr, dictAttrValue);
56
- }
57
- }
58
- }
59
- }
60
- }
61
-
62
- function copyByArraySourceValueInner(row: any, codes: any[], targetColumns: CopyAttr[], getValue: any, resultObj: any) {
63
- for (let codeIndex = 0; codeIndex < codes.length; codeIndex++) {
64
- const code = codes[codeIndex];
65
- // const codeObject = map.get(code);
66
- const codeObject = getValue(code);
67
- if (codeObject) {
68
- if (Array.isArray(targetColumns)) {
69
- for (let i = 0; i < targetColumns.length; i++) {
70
- const targetColumn = targetColumns[i];
71
-
72
- if (targetColumn.from === '*') {
73
- const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
74
- _.set(row, toStr, codeObject);
75
-
76
- resultObj.isSetArray = true;
77
- } else {
78
- const dictAttrValue = _.get(codeObject, targetColumn.from);
79
- if (typeof dictAttrValue !== 'undefined' && dictAttrValue !== null) {
80
- const toStr = targetColumn.to.replace('$ARRAY_INDEX', `${codeIndex}`);
81
- _.set(row, toStr, dictAttrValue);
82
- resultObj.isSetArray = true;
83
- }
84
- }
85
- }
86
- }
87
- }
88
- }
89
- }
90
-
91
- function copyByArraySourceValue(row: any, sourceValue: any, targetColumns: CopyAttr[], getValue: any): boolean {
92
- const resultObj = { isSetArray: false };
93
- // 支持关联JSON数组。使用 字符串存储的类型
94
- if (typeof sourceValue === 'string' && sourceValue.startsWith('[') && sourceValue.endsWith(']')) {
95
- const codes = parseJsonObject(sourceValue);
96
- if (Array.isArray(codes)) {
97
- copyByArraySourceValueInner(row, codes, targetColumns, getValue, resultObj);
98
- }
99
- } else if (Array.isArray(sourceValue)) {
100
- // 直接使用JSON或者postgres的数组存储的类型
101
- copyByArraySourceValueInner(row, sourceValue, targetColumns, getValue, resultObj);
102
- }
103
- return resultObj.isSetArray;
104
- }
105
-
106
- class CrudMixUtils {
107
- private readonly relatedType: RelatedType;
108
- constructor(relatedType: RelatedType) {
109
- this.relatedType = relatedType;
110
- }
111
-
112
- private getColumnsRelation(sqlCfg: SqlCfgModel, cfgModel: RequestCfgModel): ColumnRelation[] {
113
- const ss = getColumnsRelationAll(sqlCfg, cfgModel);
114
- const relatedType = this.relatedType;
115
- return ss.filter(s => s.relatedType === relatedType);
116
- }
117
-
118
- /**
119
- * 从执行上下文,获取所有的关联关系
120
- * @param exeCtxType
121
- * @returns
122
- */
123
- public pickColumnRelations(exeCtxType: HandleExecuteContextType): ColumnRelation[] {
124
- // 自定义的关联关系
125
- const customExeCtx = exeCtxType as IExecuteContextCustom;
126
- if (customExeCtx.isCustomContext) {
127
- const customExeCtx = exeCtxType as IExecuteContextCustom;
128
- return customExeCtx.columnsRelation;
129
- }
130
-
131
- // 默认的执行上下文
132
- const relationResult: ColumnRelation[] = [];
133
- const exeCtx: ExecuteContext = exeCtxType as ExecuteContext;
134
- const cfgModel = exeCtx.getCfgModel();
135
- const sqlModels = exeCtx.getSqlCfgModels();
136
- if (Array.isArray(sqlModels) && sqlModels.length > 0) {
137
- for (let i = 0; i < sqlModels.length; i++) {
138
- const sqlModel = sqlModels[i];
139
- // 只有Select语句需要
140
- if (sqlModel && sqlModel.getCrudType() === KeyOfCrudTypes.SELECT) {
141
- const columnsRelation = this.getColumnsRelation(sqlModel, cfgModel);
142
- for (let j = 0; j < columnsRelation.length; j++) {
143
- const relation = columnsRelation[j];
144
- if (relation.relatedType === this.relatedType) {
145
- relationResult.push(relation);
146
- }
147
- }
148
- }
149
- }
150
- }
151
-
152
- return _.uniqBy(relationResult, (obj: ColumnRelation) => {
153
- return `${obj.relatedCode}_${obj.relatedType}_${obj.sourceColumn}_${JSON.stringify(obj.targetColumns)}`;
154
- });
155
- }
156
-
157
- /**
158
- * 从执行上下文,获取所有的关联关系的代码
159
- * @param exeCtx
160
- * @returns
161
- */
162
- public pickColumnRelationCodes(exeCtx: HandleExecuteContextType): string[] {
163
- const relationResult: ColumnRelation[] = this.pickColumnRelations(exeCtx);
164
- const codes = relationResult.map(e => e.relatedCode);
165
- if (!codes || codes.length === 0) {
166
- return [];
167
- }
168
- return [...new Set(codes)]; // 去重
169
- }
170
-
171
- /**
172
- * 遍历每一行,每一个关联列
173
- * @param exeCtxType
174
- * @param func
175
- * @returns
176
- */
177
- public forEachRowAndColumnsRelation(exeCtxType: HandleExecuteContextType, func: FuncRowColumnRelation) {
178
- // 自定义的关联关系
179
- const customExeCtx = exeCtxType as IExecuteContextCustom;
180
- if (customExeCtx.isCustomContext) {
181
- const rows = customExeCtx.rows || [];
182
- const columnsRelation = customExeCtx.columnsRelation;
183
- for (let index = 0; index < rows.length; index++) {
184
- const row = rows[index];
185
- forEachColumnsRelation(row, columnsRelation, func);
186
- }
187
-
188
- return;
189
- }
190
-
191
- // 默认的执行上下文
192
- const exeCtx: ExecuteContext = exeCtxType as ExecuteContext;
193
- const sqlCfgList = exeCtx.getSqlCfgModels();
194
- const resModel = exeCtx.getResModel();
195
- const cfgModel = exeCtx.getCfgModel();
196
-
197
- for (let i = 0; i < sqlCfgList.length; i++) {
198
- const sqlCfg = sqlCfgList[i];
199
-
200
- // 只有Select语句需要
201
- if (sqlCfg && sqlCfg.getCrudType() === KeyOfCrudTypes.SELECT) {
202
- const columnsRelation = this.getColumnsRelation(sqlCfg, cfgModel);
203
-
204
- if (isNotEmpty(columnsRelation)) {
205
- const resValue = resModel[sqlCfg.resName];
206
- if (Array.isArray(resValue) && isNotEmpty(resValue)) {
207
- // 多行查询时
208
- for (const row of resValue) {
209
- forEachColumnsRelation(row, columnsRelation, func);
210
- }
211
- } else if (typeof resValue === 'object' && isNotEmpty(resValue)) {
212
- // 单行查询时
213
- forEachColumnsRelation(resValue, columnsRelation, func);
214
- }
215
- }
216
- }
217
- }
218
- }
219
-
220
- public copyColumnRelationToRow(row: any, multiKeyMap: MultiKeyMap, columnRelation: ColumnRelation) {
221
- const { relatedCode, sourceColumn, targetColumns } = columnRelation;
222
-
223
- if (!sourceColumn || !targetColumns) {
224
- return;
225
- }
226
-
227
- const sourceValue = _.get(row, sourceColumn);
228
- if (typeof sourceValue === 'undefined' || sourceValue === null) {
229
- return;
230
- }
231
-
232
- const getValue = (code: string) => {
233
- return multiKeyMap.getValue(relatedCode, code);
234
- };
235
-
236
- const isSetArray = copyByArraySourceValue(row, sourceValue, targetColumns, getValue);
237
- if (!isSetArray) {
238
- copyBySingleSourceValue(row, sourceValue, targetColumns, getValue);
239
- }
240
- }
241
-
242
- /**
243
- * 无relatedCode模式
244
- * @param row
245
- * @param map
246
- * @param columnRelation
247
- */
248
- public copyColumnRelationToRowNoRelatedCode(row: any, map: Map<string, any>, columnRelation: ColumnRelation) {
249
- const { sourceColumn, targetColumns } = columnRelation;
250
- if (!sourceColumn || !targetColumns) {
251
- return;
252
- }
253
-
254
- const sourceValue = _.get(row, sourceColumn);
255
- if (!sourceValue) {
256
- return;
257
- }
258
-
259
- const getValue = (code: string) => {
260
- if (!map) {
261
- return null;
262
- }
263
- if (typeof map.get === 'function') {
264
- return map.get(`${code}`);
265
- }
266
- return map[code];
267
- };
268
-
269
- const isSetArray = copyByArraySourceValue(row, sourceValue, targetColumns, getValue);
270
- if (!isSetArray) {
271
- copyBySingleSourceValue(row, sourceValue, targetColumns, getValue);
272
- }
273
- }
274
-
275
- /**
276
- * 专门COPY用户信息到row上面。无relatedCode模式
277
- * @param row
278
- * @param map
279
- * @param columnRelation
280
- */
281
- public copyUserInfoToRowNoRelatedCode(row: any, map: Map<string, any>, columnRelation: ColumnRelation) {
282
- const { targetColumns } = columnRelation;
283
- if (!targetColumns) {
284
- return;
285
- }
286
-
287
- const tmpSourceColumn = '__fatcmsUserAccountId__';
288
-
289
- const sourceValue = _.get(row, tmpSourceColumn);
290
- if (!sourceValue) {
291
- return;
292
- }
293
-
294
- const getValue = (code: string) => {
295
- if (!map) {
296
- return null;
297
- }
298
- if (typeof map.get === 'function') {
299
- return map.get(`${code}`);
300
- }
301
- return map[code];
302
- };
303
-
304
- const isSetArray = copyByArraySourceValue(row, sourceValue, targetColumns, getValue);
305
- if (!isSetArray) {
306
- copyBySingleSourceValue(row, sourceValue, targetColumns, getValue);
307
- }
308
- }
309
- }
310
-
311
- export { CrudMixUtils, RelatedType, FuncRowColumnRelation };