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,354 +0,0 @@
1
- import { SqlSegArg } from '../models/SqlSegArg';
2
- import { MixinUtils } from '../utils/MixinUtils';
3
- import { KeysOfConditions, SqlDbType } from '../models/keys';
4
- import { CommonException, Exceptions } from '../exceptions';
5
- import { ICompareCondition, IRequestCondition } from '../interfaces';
6
- import { TypeUtils } from '../utils/TypeUtils';
7
- import { SqlCfgModel } from '../models/SqlCfgModel';
8
- import { toSqlColumnName } from '../utils/sqlConvert/convertColumnName';
9
-
10
- const { equalsIgnoreCase, isEmpty, isNotEmpty } = MixinUtils;
11
- const { isBasicType, isNumber } = TypeUtils;
12
-
13
- const createFunc = (sqlCfg: SqlCfgModel) => {
14
- return {
15
- toSqlColumnName: (columnName: string): string => {
16
- return toSqlColumnName(columnName, sqlCfg);
17
- },
18
- toMatchSqlColumnName: (columnName: string): string => {
19
- const arr = columnName.split(',');
20
- return arr.map(s => toSqlColumnName(s.trim(), sqlCfg)).join(',');
21
- },
22
- };
23
- };
24
-
25
- class ValueChecker {
26
- checkBasicArrayAndNotEmpty(value0: any, message: string) {
27
- // 不能为空
28
- if (!value0 || !Array.isArray(value0) || value0.length === 0) {
29
- throw new CommonException(Exceptions.REQUEST_PARAM_ERROR, message);
30
- }
31
-
32
- // 元素必须是基本数据类型
33
- for (let i = 0; i < value0.length; i++) {
34
- const value0Element = value0[i];
35
- if (!TypeUtils.isBasicType(value0Element)) {
36
- throw new CommonException(Exceptions.REQUEST_PARAM_ERROR, message);
37
- }
38
- }
39
- }
40
- }
41
-
42
- function hasCompareKey(compare: string): boolean {
43
- return KeysOfConditions.COMPARE_KEYS.has(compare);
44
- }
45
-
46
- const valueChecker = new ValueChecker();
47
-
48
- class CrudProGenSqlCondition {
49
- private readonly sqlCfg: SqlCfgModel;
50
- constructor(sqlCfg: SqlCfgModel) {
51
- this.sqlCfg = sqlCfg;
52
- }
53
-
54
- generateCondition(condition: any): SqlSegArg {
55
- if (isEmpty(condition)) {
56
- return new SqlSegArg(' 1=1 ');
57
- }
58
- const sqlArgModel = this.generateByLogicalKey(condition);
59
- const sql = ' 1=1 and ' + sqlArgModel.sql;
60
- return new SqlSegArg(sql, sqlArgModel.args);
61
- }
62
-
63
- /**
64
- * condition = {$or:[{name:'zhangsan'},{name:'lisi'},{age: {$gt:18}}],sex:1}
65
- * where (name = 'zhangsan' or name = 'lisi' or age > 18) and sex = 1
66
- * @param condition
67
- * @private
68
- */
69
- private generateByLogicalKey(condition: IRequestCondition): SqlSegArg {
70
- if (isEmpty(condition)) {
71
- return null;
72
- }
73
- const { toSqlColumnName } = createFunc(this.sqlCfg);
74
-
75
- const tmpSqlList = [];
76
- const tmpArgList = [];
77
-
78
- const keys = Object.keys(condition);
79
- for (let i = 0; i < keys.length; i++) {
80
- const key = keys[i];
81
- const value = condition[key];
82
-
83
- if (!hasCompareKey(key)) {
84
- // 第一层的key,不能是比较运算符。
85
- // OR
86
- if (equalsIgnoreCase(KeysOfConditions.$OR, key)) {
87
- TypeUtils.assertJsonArray(value, Exceptions.REQUEST_OR_PARAM_MUST_ARRAY);
88
-
89
- const a = this.generateByLogicalOR(value);
90
- if (a != null) {
91
- tmpSqlList.push(a.sql);
92
- if (isNotEmpty(a.args)) {
93
- tmpArgList.push(...a.args);
94
- }
95
- }
96
- }
97
-
98
- // AND
99
- else if (TypeUtils.isBasicType(value)) {
100
- tmpSqlList.push(toSqlColumnName(key) + '= ?');
101
- tmpArgList.push(value);
102
- } else {
103
- // AND
104
- const a = this.generateByCompareKey(key, value);
105
-
106
- if (a != null) {
107
- tmpSqlList.push(a.sql);
108
- if (MixinUtils.isNotEmpty(a.args)) {
109
- tmpArgList.push(...a.args);
110
- }
111
- }
112
- }
113
- }
114
- }
115
-
116
- if (isEmpty(tmpSqlList)) {
117
- return null;
118
- }
119
-
120
- // const sql = "(" + StringUtils.join(tmpSqlList, " AND ") + ")";
121
- const sql = '(' + tmpSqlList.join(' AND ') + ')';
122
- return new SqlSegArg(sql, tmpArgList);
123
- }
124
-
125
- private generateByLogicalOR(jsonArray: IRequestCondition[]): SqlSegArg {
126
- if (MixinUtils.isEmpty(jsonArray)) {
127
- return null;
128
- }
129
-
130
- const tmpSqlList = [];
131
- const tmpArgList = [];
132
-
133
- for (let i = 0; i < jsonArray.length; i++) {
134
- const jsonObject = jsonArray[i];
135
- const a = this.generateByLogicalKey(jsonObject);
136
- if (a != null) {
137
- tmpSqlList.push(a.sql);
138
- if (MixinUtils.isNotEmpty(a.args)) {
139
- tmpArgList.push(...a.args);
140
- }
141
- }
142
- }
143
- const sql = '(' + tmpSqlList.join(' OR ') + ')';
144
- return new SqlSegArg(sql, tmpArgList);
145
- }
146
-
147
- // 例如:
148
- // {name:1, age:{"$gt":5, "$lt":10}, } ==> name = 1 and (age > 5 and age < 10)
149
- // {name:1, age:{"$nin":[1,2,3],"$lt":10} } ==> name = 1 and (age not in (1,2,3) and age < 10)
150
- // 比较运算符
151
- private generateByCompareKey(key: string, map: ICompareCondition): SqlSegArg {
152
- if (isEmpty(map)) {
153
- return null;
154
- }
155
-
156
- const { toSqlColumnName, toMatchSqlColumnName } = createFunc(this.sqlCfg);
157
-
158
- this.generateByCompareKeyCheckParam(key, map);
159
-
160
- const tmpSqlList = [];
161
- const tmpArgList = [];
162
-
163
- let hasNoArgSql = false;
164
- const compareSet = Object.keys(map);
165
-
166
- for (let i = 0; i < compareSet.length; i++) {
167
- const compare = compareSet[i];
168
-
169
- if (hasCompareKey(compare)) {
170
- const value0 = map[compare];
171
-
172
- let tmpSql = '';
173
-
174
- if (equalsIgnoreCase(KeysOfConditions.$NULL, compare)) {
175
- tmpSql = `${toSqlColumnName(key)} is null `;
176
- hasNoArgSql = true;
177
- } else if (equalsIgnoreCase(KeysOfConditions.$NOT_NULL, compare)) {
178
- tmpSql = `${toSqlColumnName(key)} is not null `;
179
- hasNoArgSql = true;
180
- } else if (equalsIgnoreCase(KeysOfConditions.$GT, compare)) {
181
- tmpArgList.push(value0);
182
- tmpSql = `${toSqlColumnName(key)} > ?`;
183
- } else if (equalsIgnoreCase(KeysOfConditions.$GTE, compare)) {
184
- tmpArgList.push(value0);
185
- tmpSql = `${toSqlColumnName(key)} >= ?`;
186
- } else if (equalsIgnoreCase(KeysOfConditions.$LT, compare)) {
187
- tmpArgList.push(value0);
188
- tmpSql = `${toSqlColumnName(key)} < ?`;
189
- } else if (equalsIgnoreCase(KeysOfConditions.$LTE, compare)) {
190
- tmpArgList.push(value0);
191
- tmpSql = `${toSqlColumnName(key)} <= ?`;
192
- } else if (equalsIgnoreCase(KeysOfConditions.$NE, compare)) {
193
- tmpArgList.push(value0);
194
- tmpSql = `${toSqlColumnName(key)} != ?`;
195
- } else if (equalsIgnoreCase(KeysOfConditions.$IN, compare)) {
196
- const array = [...value0];
197
- if (isNotEmpty(array)) {
198
- const pm = array.map(() => '?').join(',');
199
- tmpSql = `${toSqlColumnName(key)} in (${pm})`;
200
- tmpArgList.push(...array);
201
- }
202
- } else if (equalsIgnoreCase(KeysOfConditions.$NIN, compare)) {
203
- const array = [...value0];
204
- if (isNotEmpty(array)) {
205
- const pm = array.map(() => '?').join(',');
206
- tmpSql = `${toSqlColumnName(key)} not in (${pm})`;
207
- tmpArgList.push(...array);
208
- }
209
- } else if (equalsIgnoreCase(KeysOfConditions.$LIKE, compare)) {
210
- tmpArgList.push(value0);
211
- tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI like concat(?, '%')`; // like前缀匹配
212
-
213
- if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
214
- tmpSql = `${toSqlColumnName(key)} like concat(?::text, '%')`; // like前缀匹配
215
- }
216
- } else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE, compare)) {
217
- tmpArgList.push(value0);
218
- tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI not like concat(?, '%')`;
219
-
220
- if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
221
- tmpSql = `${toSqlColumnName(key)} not like concat(?::text, '%')`;
222
- }
223
- } else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
224
- tmpArgList.push(value0);
225
- tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI like concat('%', ?, '%')`; // like包含
226
-
227
- if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
228
- tmpSql = `${toSqlColumnName(key)} like concat('%', ?::text, '%')`; // like包含
229
- }
230
- } else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE_INCLUDE, compare)) {
231
- tmpArgList.push(value0);
232
- tmpSql = `${toSqlColumnName(key)} COLLATE UTF8MB4_GENERAL_CI not like concat('%',?, '%')`; // like不包含
233
-
234
- if (this.sqlCfg.sqlDbType === SqlDbType.postgres) {
235
- tmpSql = `${toSqlColumnName(key)} not like concat('%',?::text, '%')`; // like不包含
236
- }
237
- } else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
238
- tmpArgList.push(value0);
239
- tmpSql = `match(${toMatchSqlColumnName(key)}) against(?)`;
240
- } else if (equalsIgnoreCase(KeysOfConditions.$MATCH_BOOL, compare)) {
241
- tmpArgList.push(value0);
242
- tmpSql = `match(${toMatchSqlColumnName(key)}) against( ? in boolean mode)`;
243
- } else if (equalsIgnoreCase(KeysOfConditions.$RANGE, compare)) {
244
- const array = [...value0];
245
- if (isNotEmpty(array) && array.length === 2) {
246
- tmpSql = `(${toSqlColumnName(key)} between ? and ? )`;
247
- tmpArgList.push(...array);
248
- }
249
- }
250
-
251
- tmpSqlList.push(tmpSql);
252
- }
253
- }
254
-
255
- if (isEmpty(tmpArgList) && !hasNoArgSql) {
256
- return null;
257
- }
258
-
259
- const sql = '( ' + tmpSqlList.join(' and ') + ' )';
260
- return new SqlSegArg(sql, tmpArgList);
261
- }
262
-
263
- /**
264
- * 参数校验
265
- * @param key
266
- * @param map
267
- * @private
268
- */
269
- private generateByCompareKeyCheckParam(key: string, map: ICompareCondition) {
270
- if (isEmpty(map)) {
271
- return null;
272
- }
273
-
274
- const compareSet = Object.keys(map);
275
-
276
- const throwCommonException = (name: string, type: string) => {
277
- throw new CommonException(Exceptions.REQUEST_PARAM_ERROR, `${name}参数必须是${type}`);
278
- };
279
-
280
- for (let i = 0; i < compareSet.length; i++) {
281
- const compare = compareSet[i];
282
-
283
- if (hasCompareKey(compare)) {
284
- const value0 = map[compare];
285
-
286
- if (equalsIgnoreCase(KeysOfConditions.$GT, compare)) {
287
- if (!isBasicType(value0)) {
288
- throwCommonException(KeysOfConditions.$GT, '字符串、数字');
289
- }
290
- } else if (equalsIgnoreCase(KeysOfConditions.$GTE, compare)) {
291
- if (!isBasicType(value0)) {
292
- throwCommonException(KeysOfConditions.$GTE, '字符串、数字');
293
- }
294
- } else if (equalsIgnoreCase(KeysOfConditions.$LT, compare)) {
295
- if (!isBasicType(value0)) {
296
- throwCommonException(KeysOfConditions.$LT, '字符串、数字');
297
- }
298
- } else if (equalsIgnoreCase(KeysOfConditions.$LTE, compare)) {
299
- if (!isBasicType(value0)) {
300
- throwCommonException(KeysOfConditions.$LTE, '字符串、数字');
301
- }
302
- } else if (equalsIgnoreCase(KeysOfConditions.$NE, compare)) {
303
- if (!isBasicType(value0)) {
304
- throwCommonException(KeysOfConditions.$NE, '字符串、数字');
305
- }
306
- } else if (equalsIgnoreCase(KeysOfConditions.$IN, compare)) {
307
- valueChecker.checkBasicArrayAndNotEmpty(value0, `操作符${compare}的参数必须是一个非空数组,且元素是基本数据类型(数字、字符串)`);
308
- } else if (equalsIgnoreCase(KeysOfConditions.$NIN, compare)) {
309
- valueChecker.checkBasicArrayAndNotEmpty(value0, `操作符${compare}的参数必须是一个非空数组,且元素是基本数据类型(数字、字符串)`);
310
- } else if (equalsIgnoreCase(KeysOfConditions.$LIKE, compare)) {
311
- if (!isBasicType(value0)) {
312
- throwCommonException(KeysOfConditions.$LIKE, '字符串');
313
- }
314
- } else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE, compare)) {
315
- if (!isBasicType(value0)) {
316
- throwCommonException(KeysOfConditions.$NOT_LIKE, '字符串');
317
- }
318
- } else if (equalsIgnoreCase(KeysOfConditions.$LIKE_INCLUDE, compare)) {
319
- if (!isBasicType(value0)) {
320
- throwCommonException(KeysOfConditions.$LIKE_INCLUDE, '字符串');
321
- }
322
- } else if (equalsIgnoreCase(KeysOfConditions.$NOT_LIKE_INCLUDE, compare)) {
323
- if (!isBasicType(value0)) {
324
- throwCommonException(KeysOfConditions.$NOT_LIKE_INCLUDE, '字符串');
325
- }
326
- } else if (equalsIgnoreCase(KeysOfConditions.$MATCH, compare)) {
327
- if (!isBasicType(value0)) {
328
- throwCommonException(KeysOfConditions.$MATCH, '字符串');
329
- }
330
- } else if (equalsIgnoreCase(KeysOfConditions.$MATCH_BOOL, compare)) {
331
- if (!isBasicType(value0)) {
332
- throwCommonException(KeysOfConditions.$MATCH_BOOL, '字符串');
333
- }
334
- } else if (equalsIgnoreCase(KeysOfConditions.$RANGE, compare)) {
335
- valueChecker.checkBasicArrayAndNotEmpty(value0, `操作符${compare}的参数必须是一个非空数组,且元素是两个数字组成的数组`);
336
-
337
- const array = [...value0];
338
- if (isNotEmpty(array) && array.length === 2) {
339
- for (let j = 0; j < array.length; j++) {
340
- const arrayElement = array[j];
341
- if (!isNumber(arrayElement)) {
342
- throwCommonException(KeysOfConditions.$RANGE, '数组(两个数字)');
343
- }
344
- }
345
- } else {
346
- throwCommonException(KeysOfConditions.$RANGE, '数组(两个数字)');
347
- }
348
- }
349
- }
350
- }
351
- }
352
- }
353
-
354
- export { CrudProGenSqlCondition };
@@ -1,185 +0,0 @@
1
- import { CrudProServiceBase } from './CrudProServiceBase';
2
- import { CommonException, Exceptions } from '../exceptions';
3
- import { MixinUtils } from '../utils/MixinUtils';
4
- import { KeysOfSimpleSQL, KeysOfSqlResPicker, SqlDbType } from '../models/keys';
5
- import { RequestCfgModel } from '../models/RequestCfgModel';
6
-
7
- const { equalsIgnoreCase, isEmpty, isNotEmpty } = MixinUtils;
8
-
9
- class CrudProGenSqlService extends CrudProServiceBase {
10
- public async generateSQLList() {
11
- const exeCtx = this.getExecuteContext();
12
- const reqCfg = exeCtx.getCfgModel();
13
- const sqlSimpleName = reqCfg.sqlSimpleName;
14
-
15
- // 简单模式
16
- const isSimpleMode = isNotEmpty(sqlSimpleName) && sqlSimpleName.startsWith('SIMPLE_');
17
-
18
- // 拼接简单模式的SQL
19
- if (isSimpleMode) {
20
- this.generateOriginSql();
21
- }
22
-
23
- await this.generateExecuteSql();
24
- }
25
-
26
- private generateOriginSql() {
27
- const exeCtx = this.getExecuteContext();
28
-
29
- const cfgModel = exeCtx.getCfgModel();
30
- const simpleSqlName = cfgModel.sqlSimpleName;
31
-
32
- // 只有当设置了simpleSqlName时,才启用内置的SQL生成
33
- if (isEmpty(simpleSqlName)) {
34
- return;
35
- }
36
-
37
- cfgModel.sqlCfgList = [];
38
-
39
- let sql1 = null;
40
- let sql2 = null;
41
- let sql3 = null;
42
- if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_QUERY, simpleSqlName)) {
43
- sql1 = 'select @@columns from @@table where @@asWhere:condition @@orderBys @@offsetLimit';
44
- cfgModel.addSqlCfgModel('rows', sql1);
45
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_QUERY_ONE, simpleSqlName)) {
46
- sql1 = 'select @@columns from @@table where @@asWhere:condition @@orderBys limit 1';
47
- cfgModel.addSqlCfgModel('row', sql1, KeysOfSqlResPicker.RESULT_FIRST_ROW);
48
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_QUERY_COUNT, simpleSqlName)) {
49
- sql1 = 'select count(0) as total_count from @@table where @@asWhere:condition';
50
-
51
- cfgModel.addSqlCfgModel('total_count', sql1, KeysOfSqlResPicker.RESULT_TOTAL_COUNT);
52
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_QUERY_PAGE, simpleSqlName)) {
53
- sql1 = 'select @@columns from @@table where @@asWhere:condition @@orderBys @@offsetLimit ';
54
- sql2 = 'select count(0) as total_count from @@table where @@asWhere:condition';
55
-
56
- cfgModel.addSqlCfgModel('rows', sql1);
57
- cfgModel.addSqlCfgModel('total_count', sql2, KeysOfSqlResPicker.RESULT_TOTAL_COUNT);
58
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_DELETE, simpleSqlName)) {
59
- sql1 = this.generateOriginSqlForDelete(cfgModel);
60
- cfgModel.addSqlCfgModel('affected', sql1, KeysOfSqlResPicker.UPDATE_RESULT);
61
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_INSERT, simpleSqlName)) {
62
- sql1 = this.generateOriginSqlForInsert(cfgModel);
63
- cfgModel.addSqlCfgModel('affected', sql1, KeysOfSqlResPicker.UPDATE_RESULT);
64
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_UPDATE, simpleSqlName)) {
65
- sql1 = 'update @@table set @@asUpdate:data where @@asWhere:condition ';
66
- cfgModel.addSqlCfgModel('affected', sql1, KeysOfSqlResPicker.UPDATE_RESULT);
67
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_INSERT_ON_DUPLICATE_UPDATE, simpleSqlName)) {
68
- sql1 = this.generateOriginSqlForDuplicateInsert(cfgModel);
69
- cfgModel.addSqlCfgModel('affected', sql1, KeysOfSqlResPicker.UPDATE_RESULT);
70
- } else if (equalsIgnoreCase(KeysOfSimpleSQL.SIMPLE_INSERT_OR_UPDATE, simpleSqlName)) {
71
- sql1 = 'select count(0) as total_count from @@table where @@asWhere:condition ';
72
- sql2 = 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data )';
73
- sql3 = 'update @@table set @@asUpdate:data where @@asWhere:condition ';
74
-
75
- const insertWhen2 = {
76
- functionName: 'eq',
77
- functionParams: [{ contextAsNumber: 'res.total_count' }, { constNumber: 0 }],
78
- };
79
- const updateWhen3 = {
80
- functionName: 'gt',
81
- functionParams: [{ contextAsNumber: 'res.total_count' }, { constNumber: 0 }],
82
- };
83
-
84
- cfgModel.addSqlCfgModel('total_count', sql1, KeysOfSqlResPicker.RESULT_TOTAL_COUNT);
85
- cfgModel.addSqlCfgModel('insert_affected', sql2, KeysOfSqlResPicker.UPDATE_RESULT, insertWhen2);
86
- cfgModel.addSqlCfgModel('update_affected', sql3, KeysOfSqlResPicker.UPDATE_RESULT, updateWhen3);
87
- }
88
-
89
- if (isEmpty(sql1)) {
90
- throw new CommonException(Exceptions.CFG_NOT_SUPPORT_THE_SIMPLE_SQL, simpleSqlName);
91
- }
92
- }
93
-
94
- /**
95
- * 删除语句
96
- * @param cfgModel
97
- * @private
98
- */
99
- private generateOriginSqlForDelete(cfgModel: RequestCfgModel): string {
100
- if (cfgModel.sqlDbType === SqlDbType.postgres) {
101
- return 'delete from @@table where @@asWhere:condition ';
102
- }
103
- if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
104
- return 'delete from @@table where @@asWhere:condition ';
105
- }
106
- return 'delete from @@table where @@asWhere:condition limit 100 '; // 删除操作,不能一次性删除太多
107
- }
108
-
109
- /**
110
- * 创建插入OR更新语句
111
- * @param cfgModel
112
- * @private
113
- */
114
- private generateOriginSqlForDuplicateInsert(cfgModel: RequestCfgModel): string {
115
- if (cfgModel.sqlDbType === SqlDbType.postgres) {
116
- const uniqueColumn = cfgModel.uniqueColumn; // id
117
- if (!Array.isArray(uniqueColumn) || uniqueColumn.length === 0) {
118
- throw new CommonException(Exceptions.CFG_ERROR_POSTGRES_UNIQUE_COLUMNS_NULL);
119
- }
120
- const unique_column = uniqueColumn
121
- .map(s => {
122
- return `"${s}"`;
123
- })
124
- .join(',');
125
- return `insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) ON CONFLICT (${unique_column}) DO UPDATE set @@asUpdate:data `; // 关键字的前后,必须有空格
126
- }
127
-
128
- if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
129
- const uniqueColumn = cfgModel.uniqueColumn; // id
130
- if (uniqueColumn.length !== 1) {
131
- throw new CommonException(Exceptions.CFG_UNIQUE_COLUMN_COUNT_MUST_ONE);
132
- }
133
-
134
- const uniqueColumnStr = uniqueColumn[0];
135
- const uniqueColumnVal = '@@data.' + uniqueColumnStr;
136
-
137
- const sql = '' + `IF EXISTS (SELECT 1 FROM @@table WHERE [${uniqueColumnStr}] = ${uniqueColumnVal})` + 'BEGIN\n' + ' UPDATE @@table\n' + ' SET @@asUpdate:data\n' + ` WHERE [${uniqueColumnStr}] = ${uniqueColumnVal} ;\n` + 'END\n' + 'ELSE\n' + 'BEGIN\n' + ' INSERT INTO @@table ( @@asInsertKeys:data )\n' + ' VALUES ( @@asInsertValues:data );\n' + 'END';
138
-
139
- return sql;
140
- }
141
-
142
- return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) on duplicate key update @@asUpdate:data '; // 关键字的前后,必须有空格
143
- }
144
-
145
- /**
146
- * 创建插入语句
147
- * @param cfgModel
148
- * @private
149
- */
150
- private generateOriginSqlForInsert(cfgModel: RequestCfgModel): string {
151
- if (cfgModel.sqlDbType === SqlDbType.postgres) {
152
- return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data ) RETURNING * ';
153
- }
154
- if (cfgModel.sqlDbType === SqlDbType.sqlserver) {
155
- return 'insert into @@table ( @@asInsertKeys:data ) OUTPUT INSERTED.* values( @@asInsertValues:data ) ';
156
- }
157
- return 'insert into @@table ( @@asInsertKeys:data ) values( @@asInsertValues:data )'; // 关键字的前后,必须有空格
158
- }
159
-
160
- private async generateExecuteSql() {
161
- const exeCtx = this.getExecuteContext();
162
-
163
- const reqCfgModel = exeCtx.getCfgModel();
164
- const sqlCfgList = reqCfgModel.sqlCfgList || [];
165
- const { sqlTable, sqlSchema, sqlDatabase, sqlDbType, maxLimit, columns, columnsRelation } = reqCfgModel;
166
-
167
- for (let i = 0; i < sqlCfgList.length; i++) {
168
- const sqlCfgModel = sqlCfgList[i];
169
-
170
- sqlCfgModel.sqlDbType = MixinUtils.selectNotEmpty(sqlCfgModel.sqlDbType, sqlDbType);
171
- sqlCfgModel.sqlDatabase = MixinUtils.selectNotEmpty(sqlCfgModel.sqlDatabase, sqlDatabase);
172
- sqlCfgModel.sqlSchema = MixinUtils.selectNotEmpty(sqlCfgModel.sqlSchema, sqlSchema);
173
- sqlCfgModel.sqlTable = MixinUtils.selectNotEmpty(sqlCfgModel.sqlTable, sqlTable);
174
- sqlCfgModel.maxLimit = MixinUtils.selectNotEmpty(sqlCfgModel.maxLimit, maxLimit);
175
- sqlCfgModel.columns = MixinUtils.selectNotEmpty(sqlCfgModel.columns, columns);
176
- sqlCfgModel.columnsRelation = MixinUtils.selectNotEmpty(sqlCfgModel.columnsRelation, columnsRelation);
177
-
178
- await this.serviceHub.convertOriginToExecuteSql(sqlCfgModel);
179
-
180
- exeCtx.getSqlCfgModels().push(sqlCfgModel);
181
- }
182
- }
183
- }
184
-
185
- export { CrudProGenSqlService };