midway-fatcms 0.0.1-beta.26 → 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,131 +0,0 @@
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
- const DEFAULT_MAX_LIMIT = 10 * 10000;
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
- maxLimit: DEFAULT_MAX_LIMIT,
16
- };
17
-
18
- constructor(curdPro: CrudPro, sqlDatabase: string, sqlDbType: SqlDbType, sqlTable?: string) {
19
- this.sqlDatabase = sqlDatabase;
20
- this.sqlDbType = sqlDbType;
21
- this.curdPro = curdPro;
22
- this.sqlTable = sqlTable; // 全局sqlTable为空时,单独调用时就必须传sqlTable参数。
23
- }
24
-
25
- public setBaseCfgModel(baseCfgModel: IRequestCfgModel2) {
26
- Object.assign(this.baseCfgModel, baseCfgModel);
27
- }
28
-
29
- private async executeCrudByCfg(reqJson: IRequestModel, cfgModel2: IRequestCfgModel2) {
30
- const cfgModel = { ...this.baseCfgModel };
31
- Object.assign(cfgModel, cfgModel2);
32
-
33
- cfgModel.method = 'CrudProQuickAnonymous';
34
- cfgModel.updateCfg = {};
35
- cfgModel.sqlDatabase = this.sqlDatabase;
36
- cfgModel.sqlDbType = this.sqlDbType;
37
-
38
- if (!cfgModel.sqlTable) {
39
- cfgModel.sqlTable = this.sqlTable;
40
- }
41
-
42
- if (!cfgModel.sqlTable) {
43
- throw new Error('[CrudProQuick] sqlTable not found');
44
- }
45
-
46
- return await this.curdPro.executeCrudByCfg(reqJson, cfgModel);
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
- public async executeSQL(executeSql: string, args?: any[]): Promise<any> {
122
- const sqlCfgModel: ISqlCfgModel = {
123
- executeSql: executeSql,
124
- executeSqlArgs: args,
125
- sqlDatabase: this.sqlDatabase,
126
- sqlDbType: this.sqlDbType,
127
- maxLimit: this.baseCfgModel.maxLimit || DEFAULT_MAX_LIMIT,
128
- };
129
- return await this.curdPro.executeSQL(sqlCfgModel);
130
- }
131
- }
@@ -1,90 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import * as _ from 'lodash';
4
- import { CurdProService } from './CurdProService';
5
- import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
6
- import { CrudMixUtils, RelatedType } from './CurdMixUtils';
7
- import { SystemTables } from '@/models/SystemTables';
8
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
9
- import { ColumnRelation, IRequestCfgModel, IRequestModel } from '@/libs/crud-pro/interfaces';
10
- import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
11
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
12
-
13
- const dictMixUtils = new CrudMixUtils(RelatedType.accountBasic);
14
-
15
- const TMP_CTX_KEY = _.uniqueId('CurdMixByAccountService');
16
-
17
- @Provide()
18
- export class CurdMixByAccountService implements IExecuteContextHandler {
19
- @Inject()
20
- protected ctx: Context;
21
-
22
- @Inject()
23
- protected curdProService: CurdProService;
24
-
25
- async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
26
- const { SystemDbName, SystemDbType, toFatcmsUserAccountId } = GLOBAL_STATIC_CONFIG.getConfig();
27
-
28
- const relations = dictMixUtils.pickColumnRelations(executeContext);
29
- if (!relations || relations.length === 0) {
30
- return;
31
- }
32
-
33
- const accountIds = new Set<string>();
34
- dictMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
35
- const { sourceColumn } = columnRelation;
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
- }
43
- }
44
- });
45
-
46
- if (accountIds.size === 0) {
47
- return;
48
- }
49
-
50
- const cfgModel: IRequestCfgModel = {
51
- method: 'UserAccountService.queryAccountBasicInfoByIds',
52
- sqlTable: SystemTables.sys_user_account,
53
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
54
- sqlDatabase: SystemDbName,
55
- sqlDbType: SystemDbType,
56
- };
57
-
58
- const reqJson: IRequestModel = {
59
- columns: ['nick_name', 'avatar', 'account_id'],
60
- condition: {
61
- account_id: {
62
- $in: [...accountIds],
63
- },
64
- },
65
- };
66
-
67
- const res = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
68
- const userInfos = res.getResRows();
69
- executeContext[TMP_CTX_KEY] = MixinUtils.toNewMap(userInfos, (obj: any) => obj.account_id);
70
- }
71
-
72
- async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
73
- const userInfoMap = executeContext[TMP_CTX_KEY] as Map<string, any>;
74
- if (!userInfoMap || userInfoMap.size === 0) {
75
- return;
76
- }
77
-
78
- dictMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
79
- const sourceColumn = columnRelation.sourceColumn;
80
- const targetColumns = columnRelation.targetColumns;
81
- if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
82
- columnRelation.targetColumns = [
83
- { from: 'nick_name', to: `${sourceColumn}_user.nick_name` },
84
- { from: 'avatar', to: `${sourceColumn}_user.avatar` },
85
- ];
86
- }
87
- dictMixUtils.copyUserInfoToRowNoRelatedCode(row, userInfoMap, columnRelation);
88
- });
89
- }
90
- }
@@ -1,114 +0,0 @@
1
- import * as _ from 'lodash';
2
- import { Inject, Provide } from '@midwayjs/core';
3
- import { Context } from '@midwayjs/koa';
4
- import { CurdProService } from './CurdProService';
5
- import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
6
- import { CrudMixUtils, RelatedType } from './CurdMixUtils';
7
- import { SystemTables } from '@/models/SystemTables';
8
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
9
- import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
10
- import { ColumnRelation } from '@/libs/crud-pro/interfaces';
11
- import { RedisCacheService } from '../base/RedisCacheService';
12
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
13
- import { RedisKeys } from '@/models/RedisKeys';
14
-
15
- const TMP_CTX_KEY = _.uniqueId('CurdMixByDictService');
16
-
17
- const dictMixUtils = new CrudMixUtils(RelatedType.dict);
18
-
19
- @Provide()
20
- export class CurdMixByDictService implements IExecuteContextHandler {
21
- @Inject()
22
- ctx: Context;
23
-
24
- @Inject()
25
- private curdProService: CurdProService;
26
-
27
- @Inject()
28
- protected redisCacheService: RedisCacheService;
29
-
30
- private async getFromCache(code: string): Promise<any> {
31
- const cacheKey = `${RedisKeys.CURD_MIX_BY_DICT_PREFIX}${code}`;
32
- return this.redisCacheService.getJsonObject(cacheKey);
33
- }
34
- private async setToCache(code: string, value: any): Promise<any> {
35
- const cacheKey = `${RedisKeys.CURD_MIX_BY_DICT_PREFIX}${code}`;
36
- return this.redisCacheService.setJsonObject(cacheKey, value, 60 * 60);
37
- }
38
-
39
- async handleExecuteContextPrepare(executeContext: HandleExecuteContextType): Promise<void> {
40
- const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
41
- if (!codes || codes.length === 0) {
42
- return;
43
- }
44
- const rows = await this.getDictItemRows(codes);
45
- executeContext[TMP_CTX_KEY] = new MultiKeyMap(rows, 'dict_code', 'value');
46
- }
47
-
48
- private async getDictItemRows(codes: string[]) {
49
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
50
- const noCacheCodes: string[] = [];
51
-
52
- // 从缓存里面取
53
- let cachedRows = [];
54
- for (let i = 0; i < codes.length; i++) {
55
- const code = codes[i];
56
- const rows1: any[] = await this.getFromCache(code);
57
- // const rows1 = [];
58
- if (rows1 && rows1.length > 0) {
59
- cachedRows = cachedRows.concat(rows1);
60
- } else {
61
- noCacheCodes.push(code);
62
- }
63
- }
64
-
65
- // 从数据库里面取
66
- let selectedRows = [];
67
- if (noCacheCodes.length > 0) {
68
- const res1 = await this.curdProService.executeCrudByCfg(
69
- {
70
- condition: { dict_code: { $in: noCacheCodes } },
71
- },
72
- {
73
- sqlTable: SystemTables.sys_data_dict_item,
74
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
75
- sqlDatabase: SystemDbName,
76
- sqlDbType: SystemDbType,
77
- }
78
- );
79
- selectedRows = res1.getResRows();
80
-
81
- //放到缓存里
82
- for (let i = 0; i < noCacheCodes.length; i++) {
83
- const noCacheCode = noCacheCodes[i];
84
- const rows1 = selectedRows.filter(e => e.dict_code === noCacheCode);
85
- await this.setToCache(noCacheCode, rows1);
86
- }
87
- }
88
-
89
- return cachedRows.concat(selectedRows);
90
- }
91
-
92
- async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
93
- const multiKeyMap = executeContext[TMP_CTX_KEY] as MultiKeyMap;
94
- if (!multiKeyMap || multiKeyMap.isEmpty()) {
95
- return;
96
- }
97
-
98
- dictMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
99
- const sourceColumn = columnRelation.sourceColumn;
100
- const targetColumns = columnRelation.targetColumns;
101
-
102
- if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
103
- columnRelation.targetColumns = [
104
- {
105
- from: '*',
106
- to: `${sourceColumn}_info[$ARRAY_INDEX]`,
107
- },
108
- ];
109
- }
110
-
111
- dictMixUtils.copyColumnRelationToRow(row, multiKeyMap, columnRelation);
112
- });
113
- }
114
- }
@@ -1,219 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import * as _ from 'lodash';
4
- import { CurdProService } from './CurdProService';
5
- import { HandleExecuteContextType, 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';
15
- import { RedisKeys } from '@/models/RedisKeys';
16
-
17
- const linkToCustomMixUtils = new CrudMixUtils(RelatedType.linkToCustom);
18
- const TMP_CTX_KEY = _.uniqueId('CurdMixByLinkToCustomService');
19
-
20
- function toMapObject(rows: any[], fieldsArr: string[]): Map<string, any> {
21
- const valueKey = fieldsArr[0];
22
- const labelKey = fieldsArr[1];
23
-
24
- const isObjectMode = fieldsArr.length > 2 || labelKey === '*';
25
-
26
- const map = new Map<string, any>();
27
- for (let i = 0; i < rows.length; i++) {
28
- const rowObj = rows[i];
29
- const value = rowObj[valueKey];
30
-
31
- if (typeof value !== 'undefined') {
32
- const valueStr = '' + value;
33
- if (isObjectMode) {
34
- map.set(valueStr, rowObj);
35
- } else {
36
- const label = rowObj[labelKey];
37
- if (label) {
38
- map.set(valueStr, label);
39
- }
40
- }
41
- }
42
- }
43
- return map;
44
- }
45
-
46
- @Provide()
47
- export class CurdMixByLinkToCustomService implements IExecuteContextHandler {
48
- @Inject()
49
- protected ctx: Context;
50
-
51
- @Inject()
52
- protected curdProService: CurdProService;
53
-
54
- @Inject()
55
- protected redisCacheService: RedisCacheService;
56
-
57
- async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
58
- const relations = linkToCustomMixUtils.pickColumnRelations(executeContext);
59
-
60
- if (!relations || relations.length === 0) {
61
- return;
62
- }
63
- executeContext[TMP_CTX_KEY] = await this.loadInfoByLinkToCustomMap(relations);
64
- }
65
-
66
- async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
67
- const dataInfoMap = executeContext[TMP_CTX_KEY] as Map<string, Map<string, any>>;
68
- if (!dataInfoMap || dataInfoMap.size === 0) {
69
- return;
70
- }
71
- linkToCustomMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
72
- const relatedCode = columnRelation.relatedCode;
73
- const dataMap = dataInfoMap.get(relatedCode);
74
- if (dataMap) {
75
- const sourceColumn = columnRelation.sourceColumn;
76
- const targetColumns = columnRelation.targetColumns;
77
- if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
78
- columnRelation.targetColumns = [
79
- {
80
- from: '*',
81
- to: `${sourceColumn}_info[$ARRAY_INDEX]`,
82
- },
83
- ];
84
- }
85
-
86
- // this.ctx.logger.info("CurdMixByLinkToCustomService ==> dataMap", dataMap)
87
-
88
- linkToCustomMixUtils.copyColumnRelationToRowNoRelatedCode(row, dataMap, columnRelation);
89
- }
90
- });
91
- }
92
-
93
- public async queryInfoByLinkToCustom(code: string): Promise<Map<string, any>> {
94
- const cacheKey = RedisKeys.LINK_TO_CUSTOM_PREFIX + code;
95
- let values;
96
- const expireSecond = 2 * 60; // 2分钟
97
- const enumMap = await this.redisCacheService.getJsonObject(cacheKey);
98
- if (!enumMap || Object.keys(enumMap).length === 0) {
99
- values = await this.queryInfoByLinkToCustomImpl(code);
100
- await this.redisCacheService.setJsonObject(cacheKey, values, expireSecond);
101
- }
102
- return values;
103
- }
104
-
105
- /**
106
- * code形如:mysql_________fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
107
- * code形如:fatcms~~~sys_perm_role~~~role_code,role_name,xxx_name
108
- * code形如:fatcms~~~sys_perm_role~~~id,*
109
- * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
110
- * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
111
- * 【数据库】~~~【表名】~~~【value】,【label】,【style】
112
- * @param code
113
- * @private
114
- */
115
- private async queryInfoByLinkToCustomImpl(code: string): Promise<Map<string, any>> {
116
- if (code.startsWith('GET_BY_CRUD_METHOD')) {
117
- return this.queryInfoByLinkToCustomByCrudMethod(code);
118
- }
119
-
120
- const arr = code
121
- .split('~~~')
122
- .map(s => s.trim())
123
- .filter(Boolean);
124
- if (arr.length !== 3) {
125
- throw new BizException('linkToCustom枚举值查询字符串,必须符合固定格式', Exceptions.CFG_ERROR);
126
- }
127
-
128
- const [sqlDatabase, sqlTable, fields] = arr;
129
-
130
- const { dbType, dbName } = parseDatabaseName(sqlDatabase);
131
-
132
- const fieldsArr = fields
133
- .split(',')
134
- .map(s => s.trim())
135
- .filter(Boolean);
136
-
137
- if (fieldsArr.length < 2) {
138
- throw new BizException('linkToCustom枚举值查询字符串,fields字段必须符合固定格式', Exceptions.CFG_ERROR);
139
- }
140
-
141
- const labelKey = fieldsArr[1];
142
- const res1 = await this.curdProService.executeCrudByCfg(
143
- {
144
- condition: {},
145
- columns: labelKey === '*' ? null : fields,
146
- limit: 4000,
147
- offset: 0,
148
- },
149
- {
150
- sqlTable,
151
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
152
- sqlDatabase: dbName,
153
- sqlDbType: dbType,
154
- maxLimit: 4000,
155
- }
156
- );
157
- const rows = res1.getResRows();
158
- const map = toMapObject(rows, fieldsArr);
159
- return map;
160
- }
161
-
162
- /**
163
- *
164
- * @param code
165
- * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,*
166
- * code形如:GET_BY_CRUD_METHOD~~~GetActiveLineEnum~~~id,name
167
- */
168
- private async queryInfoByLinkToCustomByCrudMethod(code: string): Promise<Map<string, any>> {
169
- const arr = code
170
- .split('~~~')
171
- .map(s => s.trim())
172
- .filter(Boolean);
173
- if (arr.length !== 3) {
174
- throw new BizException('linkToCustom枚举值查询字符串,必须符合固定格式。', Exceptions.CFG_ERROR);
175
- }
176
- const [prefix, methodCode, fields] = arr;
177
-
178
- const fieldsArr = fields
179
- .split(',')
180
- .map(s => s.trim())
181
- .filter(Boolean);
182
-
183
- if (fieldsArr.length < 2) {
184
- throw new BizException(`linkToCustom枚举值查询字符串,fields字段必须符合固定格式。${prefix}`, Exceptions.CFG_ERROR);
185
- }
186
-
187
- const methodInfo = (await this.curdProService.getCachedCfgByMethod(methodCode)) as any;
188
- if (!methodInfo || methodInfo.status !== 1) {
189
- throw new Error('接口不存在或已下线: ' + methodCode);
190
- }
191
-
192
- const cfgModel = methodInfo as IRequestCfgModel2;
193
- const { dbType, dbName } = parseDatabaseName(cfgModel.sqlDatabase);
194
- cfgModel.sqlDatabase = dbName;
195
- cfgModel.sqlDbType = dbType;
196
-
197
- const reqJson = {};
198
-
199
- await GLOBAL_STATIC_CONFIG.getConfig().bizUpdateCfgModelForCrudMtd(reqJson, cfgModel, methodInfo, this.ctx);
200
-
201
- const exeCtx = await this.curdProService.executeCrudByCfg(reqJson, cfgModel);
202
-
203
- const rows = exeCtx.getResRows();
204
- const map = toMapObject(rows, fieldsArr);
205
- return map;
206
- }
207
-
208
- private async loadInfoByLinkToCustomMap(relations: ColumnRelation[]): Promise<Map<string, Map<string, any>>> {
209
- const bigMap = new Map<string, Map<string, any>>();
210
- for (let i = 0; i < relations.length; i++) {
211
- const relation = relations[i];
212
- const code = relation.relatedCode || '';
213
- const codeTrim = code.trim();
214
- const map = await this.queryInfoByLinkToCustom(codeTrim);
215
- bigMap.set(codeTrim, map);
216
- }
217
- return bigMap;
218
- }
219
- }
@@ -1,78 +0,0 @@
1
- import { Inject, Provide } from '@midwayjs/core';
2
- import { Context } from '@midwayjs/koa';
3
- import { CurdProService } from './CurdProService';
4
- import { HandleExecuteContextType, IExecuteContextHandler } from '@/libs/crud-pro/models/ExecuteContext';
5
- import { CrudMixUtils, RelatedType } from './CurdMixUtils';
6
- import * as _ from 'lodash';
7
- import { SystemTables } from '@/models/SystemTables';
8
- import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
9
- import { MultiKeyMap } from '@/libs/crud-pro/utils/MultiKeyMap';
10
- import { ColumnRelation } from '@/libs/crud-pro/interfaces';
11
- import { parseConfigContentToEnumInfo } from '@/libs/utils/parseConfig';
12
- import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
13
-
14
- const dictMixUtils = new CrudMixUtils(RelatedType.sysCfgEnum);
15
-
16
- const TMP_CTX_KEY = _.uniqueId('CurdMixBySysConfigService');
17
-
18
- @Provide()
19
- export class CurdMixBySysConfigService implements IExecuteContextHandler {
20
- @Inject()
21
- ctx: Context;
22
-
23
- @Inject()
24
- protected curdProService: CurdProService;
25
-
26
- async handleExecuteContextPrepare(executeContext: HandleExecuteContextType) {
27
- const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
28
-
29
- const codes = dictMixUtils.pickColumnRelationCodes(executeContext);
30
- if (!codes || codes.length === 0) {
31
- return;
32
- }
33
-
34
- const res1 = await this.curdProService.executeCrudByCfg(
35
- {
36
- condition: { config_code: { $in: codes } },
37
- },
38
- {
39
- sqlTable: SystemTables.sys_configs,
40
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
41
- sqlDatabase: SystemDbName,
42
- sqlDbType: SystemDbType,
43
- }
44
- );
45
- const rows = res1.getResRows();
46
- const multiKeyMap = new MultiKeyMap();
47
-
48
- if (Array.isArray(rows)) {
49
- for (let i = 0; i < rows.length; i++) {
50
- const row = rows[i];
51
- const { config_code } = row;
52
- const config_content_rows = parseConfigContentToEnumInfo(row); // 数组元素必须有value字段
53
- multiKeyMap.addRowsValue1(config_content_rows, config_code, 'value');
54
- }
55
- }
56
-
57
- executeContext[TMP_CTX_KEY] = multiKeyMap;
58
- }
59
-
60
- async handleExecuteContext(executeContext: HandleExecuteContextType): Promise<void> {
61
- const multiKeyMap = executeContext[TMP_CTX_KEY] as MultiKeyMap;
62
- if (!multiKeyMap || multiKeyMap.isEmpty()) {
63
- return;
64
- }
65
-
66
- dictMixUtils.forEachRowAndColumnsRelation(executeContext, (row: any, columnRelation: ColumnRelation) => {
67
- const sourceColumn = columnRelation.sourceColumn;
68
- const targetColumns = columnRelation.targetColumns;
69
- if (!Array.isArray(targetColumns) || targetColumns.length === 0) {
70
- columnRelation.targetColumns = [
71
- { from: 'label', to: `${sourceColumn}_info.label` },
72
- { from: 'style', to: `${sourceColumn}_info.style` },
73
- ];
74
- }
75
- dictMixUtils.copyColumnRelationToRow(row, multiKeyMap, columnRelation);
76
- });
77
- }
78
- }