midway-fatcms 0.0.1-beta.5 → 0.0.1-beta.51

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 (330) hide show
  1. package/.eslintrc.json +14 -0
  2. package/.prettierrc.js +4 -0
  3. package/README.md +7 -0
  4. package/dist/config/config.default.js +25 -13
  5. package/dist/config/seed/aeskey.txt +1 -1
  6. package/dist/configuration.d.ts +1 -0
  7. package/dist/configuration.js +35 -11
  8. package/dist/controller/base/BaseApiController.d.ts +7 -1
  9. package/dist/controller/base/BaseApiController.js +32 -6
  10. package/dist/controller/gateway/AsyncTaskController.d.ts +20 -0
  11. package/dist/controller/gateway/AsyncTaskController.js +181 -0
  12. package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
  13. package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
  14. package/dist/controller/gateway/CrudStdGatewayController.js +8 -16
  15. package/dist/controller/gateway/DocGatewayController.js +14 -9
  16. package/dist/controller/gateway/FileController.d.ts +3 -2
  17. package/dist/controller/gateway/PublicApiController.js +4 -6
  18. package/dist/controller/gateway/StaticController.d.ts +0 -1
  19. package/dist/controller/gateway/StaticController.js +40 -39
  20. package/dist/controller/helpers.controller.d.ts +1 -1
  21. package/dist/controller/home.controller.js +4 -3
  22. package/dist/controller/manage/AnyApiMangeApi.js +2 -2
  23. package/dist/controller/manage/AppLogMangeApi.js +2 -2
  24. package/dist/controller/manage/AppMangeApi.js +2 -2
  25. package/dist/controller/manage/AppPageMangeApi.js +2 -2
  26. package/dist/controller/manage/AppSchemaHistoryApi.js +2 -2
  27. package/dist/controller/manage/CrudMethodsMangeApi.js +2 -2
  28. package/dist/controller/manage/CrudStandardDesignApi.d.ts +9 -1
  29. package/dist/controller/manage/CrudStandardDesignApi.js +135 -79
  30. package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
  31. package/dist/controller/manage/DataDictManageApi.js +1 -1
  32. package/dist/controller/manage/DeployManageApi.d.ts +1 -1
  33. package/dist/controller/manage/DeployManageApi.js +38 -34
  34. package/dist/controller/manage/DocLibManageApi.js +2 -2
  35. package/dist/controller/manage/DocManageApi.js +2 -2
  36. package/dist/controller/manage/FileManageApi.js +1 -1
  37. package/dist/controller/manage/LowCodeTplManageApi.js +2 -2
  38. package/dist/controller/manage/MenuManageApi.js +2 -2
  39. package/dist/controller/manage/ProxyApiMangeApi.js +2 -2
  40. package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
  41. package/dist/controller/manage/SuperAdminManageApi.js +12 -8
  42. package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
  43. package/dist/controller/manage/SysConfigMangeApi.js +8 -6
  44. package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
  45. package/dist/controller/manage/SystemInfoManageApi.js +7 -1
  46. package/dist/controller/manage/UserAccountManageApi.d.ts +1 -1
  47. package/dist/controller/manage/UserAccountManageApi.js +9 -4
  48. package/dist/controller/manage/WorkbenchMangeApi.js +3 -3
  49. package/dist/controller/myinfo/AuthController.d.ts +0 -4
  50. package/dist/controller/myinfo/AuthController.js +1 -54
  51. package/dist/controller/render/AppRenderController.js +12 -5
  52. package/dist/controller/test.controller.d.ts +1 -1
  53. package/dist/controller/test.controller.js +5 -5
  54. package/dist/index.d.ts +10 -0
  55. package/dist/index.js +10 -0
  56. package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
  57. package/dist/libs/crud-pro/CrudPro.js +5 -0
  58. package/dist/libs/crud-pro/defaultConfigs.js +2 -0
  59. package/dist/libs/crud-pro/interfaces.d.ts +7 -1
  60. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +12 -5
  61. package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
  62. package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
  63. package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -1
  64. package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
  65. package/dist/libs/crud-pro/models/ResModel.js +2 -0
  66. package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +1 -1
  67. package/dist/libs/crud-pro/models/Transaction.d.ts +1 -0
  68. package/dist/libs/crud-pro/models/Transaction.js +7 -0
  69. package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
  70. package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
  71. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +27 -15
  72. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +17 -19
  73. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
  74. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
  75. package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
  76. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
  77. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
  78. package/dist/libs/crud-pro/services/CrudProServiceBase.js +15 -3
  79. package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
  80. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +32 -7
  81. package/dist/libs/crud-pro/sql.txt +120 -120
  82. package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
  83. package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
  84. package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
  85. package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
  86. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.d.ts +3 -0
  87. package/dist/libs/crud-pro/utils/sqlConvert/convertMix.js +22 -0
  88. package/dist/libs/global-config/global-config.d.ts +60 -0
  89. package/dist/libs/global-config/global-config.js +35 -0
  90. package/dist/libs/utils/base64.d.ts +9 -0
  91. package/dist/libs/utils/base64.js +42 -0
  92. package/dist/libs/utils/errorToString.d.ts +2 -0
  93. package/dist/libs/utils/errorToString.js +57 -0
  94. package/dist/libs/utils/fatcms-request.js +2 -2
  95. package/dist/libs/utils/functions.d.ts +2 -1
  96. package/dist/libs/utils/functions.js +12 -3
  97. package/dist/libs/utils/parseCreateSql.d.ts +6 -1
  98. package/dist/libs/utils/parseCreateSql.js +2 -1
  99. package/dist/middleware/forbidden.middleware.js +6 -22
  100. package/dist/middleware/global.middleware.js +30 -10
  101. package/dist/middleware/permission.middleware.js +1 -1
  102. package/dist/middleware/rediscache.middleware.d.ts +3 -0
  103. package/dist/middleware/rediscache.middleware.js +77 -0
  104. package/dist/middleware/redislock.middleware.d.ts +7 -0
  105. package/dist/middleware/redislock.middleware.js +72 -0
  106. package/dist/models/AsyncTaskModel.d.ts +74 -0
  107. package/dist/models/AsyncTaskModel.js +31 -0
  108. package/dist/models/RedisKeys.d.ts +15 -0
  109. package/dist/models/RedisKeys.js +18 -0
  110. package/dist/models/SystemEntities.d.ts +8 -1
  111. package/dist/models/SystemEntities.js +7 -0
  112. package/dist/models/SystemTables.d.ts +1 -3
  113. package/dist/models/SystemTables.js +2 -4
  114. package/dist/models/bizmodels.d.ts +30 -0
  115. package/dist/models/bizmodels.js +6 -1
  116. package/dist/models/userSession.d.ts +1 -0
  117. package/dist/schedule/anonymousContext.d.ts +14 -0
  118. package/dist/schedule/anonymousContext.js +59 -0
  119. package/dist/schedule/index.d.ts +4 -3
  120. package/dist/schedule/index.js +8 -67
  121. package/dist/schedule/runSchedule.d.ts +12 -0
  122. package/dist/schedule/runSchedule.js +68 -0
  123. package/dist/schedule/scheduleNames.d.ts +13 -0
  124. package/dist/schedule/scheduleNames.js +17 -0
  125. package/dist/service/AuthService.js +8 -5
  126. package/dist/service/EnumInfoService.js +9 -5
  127. package/dist/service/FileCenterService.js +13 -9
  128. package/dist/service/SysConfigService.d.ts +1 -1
  129. package/dist/service/SysConfigService.js +4 -2
  130. package/dist/service/UserAccountService.js +10 -6
  131. package/dist/service/UserSessionService.d.ts +22 -0
  132. package/dist/service/UserSessionService.js +74 -2
  133. package/dist/service/VisitStatService.d.ts +1 -1
  134. package/dist/service/VisitStatService.js +20 -27
  135. package/dist/service/WorkbenchService.d.ts +33 -0
  136. package/dist/service/WorkbenchService.js +70 -12
  137. package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
  138. package/dist/service/anyapi/AnyApiService.js +4 -2
  139. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +50 -0
  140. package/dist/service/asyncTask/AsyncTaskRunnerService.js +287 -0
  141. package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
  142. package/dist/service/asyncTask/AsyncTaskService.js +34 -0
  143. package/dist/service/asyncTask/handler/ExcelInfoModel.d.ts +10 -0
  144. package/dist/service/asyncTask/handler/ExcelInfoModel.js +2 -0
  145. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.d.ts +7 -0
  146. package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +216 -0
  147. package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.d.ts +36 -0
  148. package/dist/service/asyncTask/handler/ExportExcelByInnerHttpHandler.js +141 -0
  149. package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.d.ts +46 -0
  150. package/dist/service/asyncTask/handler/ExportExcelByStdCrudHandler.js +135 -0
  151. package/dist/service/base/BaseService.d.ts +12 -0
  152. package/dist/service/base/BaseService.js +22 -0
  153. package/dist/service/base/RedisCacheService.d.ts +7 -0
  154. package/dist/service/base/RedisCacheService.js +7 -0
  155. package/dist/service/crudstd/CrudStdRelationService.js +63 -36
  156. package/dist/service/crudstd/CrudStdService.d.ts +21 -5
  157. package/dist/service/crudstd/CrudStdService.js +137 -21
  158. package/dist/service/curd/CrudProQuick.d.ts +44 -0
  159. package/dist/service/curd/CrudProQuick.js +147 -0
  160. package/dist/service/curd/CurdMixByAccountService.d.ts +4 -4
  161. package/dist/service/curd/CurdMixByAccountService.js +11 -6
  162. package/dist/service/curd/CurdMixByDictService.d.ts +4 -4
  163. package/dist/service/curd/CurdMixByDictService.js +10 -7
  164. package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +13 -4
  165. package/dist/service/curd/CurdMixByLinkToCustomService.js +73 -24
  166. package/dist/service/curd/CurdMixBySysConfigService.d.ts +3 -3
  167. package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
  168. package/dist/service/curd/CurdMixByWorkbenchService.d.ts +3 -3
  169. package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
  170. package/dist/service/curd/CurdMixService.d.ts +16 -5
  171. package/dist/service/curd/CurdMixService.js +26 -2
  172. package/dist/service/curd/CurdMixUtils.d.ts +27 -4
  173. package/dist/service/curd/CurdMixUtils.js +117 -41
  174. package/dist/service/curd/CurdProService.d.ts +3 -10
  175. package/dist/service/curd/CurdProService.js +38 -148
  176. package/dist/service/curd/fixCfgModel.d.ts +3 -0
  177. package/dist/service/curd/fixCfgModel.js +104 -0
  178. package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
  179. package/dist/service/proxyapi/ProxyApiService.d.ts +1 -0
  180. package/dist/service/proxyapi/ProxyApiService.js +43 -9
  181. package/dist/views/404_app.html +31 -31
  182. package/dist/views/404_workbench.html +34 -34
  183. package/package.json +28 -24
  184. package/tsconfig.json +32 -0
  185. package/src/config/config.default.ts +0 -172
  186. package/src/config/seed/aeskey.txt +0 -1
  187. package/src/config/utils.ts +0 -23
  188. package/src/configuration.ts +0 -83
  189. package/src/controller/base/BaseApiController.ts +0 -145
  190. package/src/controller/gateway/AnyApiGatewayController.ts +0 -33
  191. package/src/controller/gateway/CrudMtdGatewayController.ts +0 -107
  192. package/src/controller/gateway/CrudStdGatewayController.ts +0 -101
  193. package/src/controller/gateway/DocGatewayController.ts +0 -165
  194. package/src/controller/gateway/FileController.ts +0 -110
  195. package/src/controller/gateway/ProxyApiGatewayController.ts +0 -47
  196. package/src/controller/gateway/PublicApiController.ts +0 -145
  197. package/src/controller/gateway/StaticController.ts +0 -328
  198. package/src/controller/helpers.controller.ts +0 -161
  199. package/src/controller/home.controller.ts +0 -71
  200. package/src/controller/manage/AnyApiMangeApi.ts +0 -66
  201. package/src/controller/manage/AppLogMangeApi.ts +0 -53
  202. package/src/controller/manage/AppMangeApi.ts +0 -53
  203. package/src/controller/manage/AppPageMangeApi.ts +0 -52
  204. package/src/controller/manage/AppSchemaHistoryApi.ts +0 -49
  205. package/src/controller/manage/CrudMethodsMangeApi.ts +0 -49
  206. package/src/controller/manage/CrudStandardDesignApi.ts +0 -353
  207. package/src/controller/manage/DataDictManageApi.ts +0 -78
  208. package/src/controller/manage/DeployManageApi.ts +0 -179
  209. package/src/controller/manage/DocLibManageApi.ts +0 -69
  210. package/src/controller/manage/DocManageApi.ts +0 -99
  211. package/src/controller/manage/FileManageApi.ts +0 -45
  212. package/src/controller/manage/LowCodeTplManageApi.ts +0 -52
  213. package/src/controller/manage/MenuManageApi.ts +0 -63
  214. package/src/controller/manage/ProxyApiMangeApi.ts +0 -52
  215. package/src/controller/manage/SuperAdminManageApi.ts +0 -138
  216. package/src/controller/manage/SysConfigMangeApi.ts +0 -95
  217. package/src/controller/manage/SystemInfoManageApi.ts +0 -48
  218. package/src/controller/manage/UserAccountManageApi.ts +0 -88
  219. package/src/controller/manage/WorkbenchMangeApi.ts +0 -72
  220. package/src/controller/myinfo/AuthController.ts +0 -174
  221. package/src/controller/myinfo/MyInfoController.ts +0 -32
  222. package/src/controller/render/AppRenderController.ts +0 -76
  223. package/src/controller/test.controller.ts +0 -37
  224. package/src/filter/default.filter.ts +0 -13
  225. package/src/filter/notfound.filter.ts +0 -10
  226. package/src/index.ts +0 -99
  227. package/src/interface.ts +0 -31
  228. package/src/libs/crud-pro/CrudPro.ts +0 -158
  229. package/src/libs/crud-pro/defaultConfigs.ts +0 -13
  230. package/src/libs/crud-pro/exceptions.ts +0 -124
  231. package/src/libs/crud-pro/interfaces.ts +0 -183
  232. package/src/libs/crud-pro/models/ExecuteContext.ts +0 -111
  233. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +0 -86
  234. package/src/libs/crud-pro/models/FuncContext.ts +0 -21
  235. package/src/libs/crud-pro/models/RequestCfgModel.ts +0 -141
  236. package/src/libs/crud-pro/models/RequestModel.ts +0 -141
  237. package/src/libs/crud-pro/models/ServiceHub.ts +0 -32
  238. package/src/libs/crud-pro/models/SqlCfgModel.ts +0 -52
  239. package/src/libs/crud-pro/models/SqlSegArg.ts +0 -13
  240. package/src/libs/crud-pro/models/Transaction.ts +0 -74
  241. package/src/libs/crud-pro/models/TransactionMySQL.ts +0 -79
  242. package/src/libs/crud-pro/models/TransactionPostgres.ts +0 -91
  243. package/src/libs/crud-pro/models/TransactionSqlServer.ts +0 -107
  244. package/src/libs/crud-pro/models/keys.ts +0 -159
  245. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +0 -75
  246. package/src/libs/crud-pro/services/CrudProExecuteFuncService.ts +0 -128
  247. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +0 -279
  248. package/src/libs/crud-pro/services/CrudProFieldUpdateService.ts +0 -60
  249. package/src/libs/crud-pro/services/CrudProFieldValidateService.ts +0 -180
  250. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +0 -373
  251. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +0 -202
  252. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +0 -397
  253. package/src/libs/crud-pro/services/CrudProServiceBase.ts +0 -98
  254. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +0 -59
  255. package/src/libs/crud-pro/services/CurdProServiceHub.ts +0 -92
  256. package/src/libs/crud-pro/sql.txt +0 -120
  257. package/src/libs/crud-pro/utils/CompareUtils.ts +0 -23
  258. package/src/libs/crud-pro/utils/DatabaseName.ts +0 -40
  259. package/src/libs/crud-pro/utils/DateTimeUtils.ts +0 -20
  260. package/src/libs/crud-pro/utils/MemoryRefreshCache.ts +0 -64
  261. package/src/libs/crud-pro/utils/MessageParseUtils.ts +0 -33
  262. package/src/libs/crud-pro/utils/MixinUtils.ts +0 -285
  263. package/src/libs/crud-pro/utils/ModelUtils.ts +0 -55
  264. package/src/libs/crud-pro/utils/MultiKeyMap.ts +0 -72
  265. package/src/libs/crud-pro/utils/SqlFuncUtils.ts +0 -29
  266. package/src/libs/crud-pro/utils/TypeUtils.ts +0 -188
  267. package/src/libs/crud-pro/utils/ValidateUtils.ts +0 -167
  268. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +0 -20
  269. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +0 -22
  270. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +0 -22
  271. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +0 -26
  272. package/src/libs/crud-pro/utils/sqlConvert/convertMsSql.ts +0 -11
  273. package/src/libs/crud-pro/utils/sqlConvert/convertPgSql.ts +0 -11
  274. package/src/libs/crud-pro/utils/sqlConvert/convertPgType.ts +0 -129
  275. package/src/libs/utils/common-dto.ts +0 -52
  276. package/src/libs/utils/crypto-utils.ts +0 -52
  277. package/src/libs/utils/fatcms-request.ts +0 -115
  278. package/src/libs/utils/functions.ts +0 -67
  279. package/src/libs/utils/ordernum-utils.ts +0 -18
  280. package/src/libs/utils/parseConfig.ts +0 -62
  281. package/src/libs/utils/parseCreateSql.ts +0 -91
  282. package/src/libs/utils/render-utils.ts +0 -184
  283. package/src/middleware/forbidden.middleware.ts +0 -71
  284. package/src/middleware/global.middleware.ts +0 -278
  285. package/src/middleware/permission.middleware.ts +0 -81
  286. package/src/middleware/tx.middleware.ts +0 -30
  287. package/src/models/SystemEntities.ts +0 -115
  288. package/src/models/SystemPerm.ts +0 -105
  289. package/src/models/SystemTables.ts +0 -30
  290. package/src/models/bizmodels.ts +0 -89
  291. package/src/models/contextLogger.ts +0 -132
  292. package/src/models/devops.ts +0 -17
  293. package/src/models/userSession.ts +0 -216
  294. package/src/schedule/index.ts +0 -73
  295. package/src/service/AuthService.ts +0 -270
  296. package/src/service/EnumInfoService.ts +0 -129
  297. package/src/service/FileCenterService.ts +0 -394
  298. package/src/service/SysConfigService.ts +0 -34
  299. package/src/service/UserAccountService.ts +0 -100
  300. package/src/service/UserSessionService.ts +0 -81
  301. package/src/service/VisitStatService.ts +0 -179
  302. package/src/service/WorkbenchService.ts +0 -160
  303. package/src/service/anyapi/AnyApiSandboxService.ts +0 -121
  304. package/src/service/anyapi/AnyApiService.ts +0 -184
  305. package/src/service/base/ApiBaseService.ts +0 -42
  306. package/src/service/base/ApiRateLimiter.ts +0 -59
  307. package/src/service/base/BaseService.ts +0 -74
  308. package/src/service/base/RedisCacheService.ts +0 -38
  309. package/src/service/crudstd/CrudStdActionService.ts +0 -27
  310. package/src/service/crudstd/CrudStdConstant.ts +0 -62
  311. package/src/service/crudstd/CrudStdRelationService.ts +0 -78
  312. package/src/service/crudstd/CrudStdService.ts +0 -188
  313. package/src/service/curd/CurdMixByAccountService.ts +0 -83
  314. package/src/service/curd/CurdMixByDictService.ts +0 -113
  315. package/src/service/curd/CurdMixByLinkToCustomService.ts +0 -167
  316. package/src/service/curd/CurdMixBySysConfigService.ts +0 -78
  317. package/src/service/curd/CurdMixByWorkbenchService.ts +0 -68
  318. package/src/service/curd/CurdMixService.ts +0 -65
  319. package/src/service/curd/CurdMixUtils.ts +0 -248
  320. package/src/service/curd/CurdProService.ts +0 -379
  321. package/src/service/proxyapi/ProxyApiLoadService.ts +0 -165
  322. package/src/service/proxyapi/ProxyApiService.ts +0 -262
  323. package/src/service/proxyapi/ProxyApiUtils.ts +0 -32
  324. package/src/service/proxyapi/RouteHandler.ts +0 -8
  325. package/src/service/proxyapi/RouteTrie.ts +0 -74
  326. package/src/service/proxyapi/WeightedRandom.ts +0 -37
  327. package/src/service/proxyapi/WeightedRoundRobin.ts +0 -44
  328. package/src/views/404_app.html +0 -31
  329. package/src/views/404_workbench.html +0 -34
  330. package/src/views/static/favicon.ico +0 -0
@@ -1,128 +0,0 @@
1
- import { CrudProServiceBase } from './CrudProServiceBase';
2
- import { IFuncCfgModel, IFunctionParam } from '../interfaces';
3
- import { FuncContext } from '../models/FuncContext';
4
- import { TypeUtils } from '../utils/TypeUtils';
5
- import { MixinUtils } from '../utils/MixinUtils';
6
- import * as _ from 'lodash';
7
- import { CommonException, Exceptions } from '../exceptions';
8
- import { KeysOfFunCtx } from '../models/keys';
9
-
10
- const { isNil, isNumeric } = TypeUtils;
11
- const { isEmpty } = MixinUtils;
12
-
13
- function isNotNil(obj: any): boolean {
14
- return !isNil(obj);
15
- }
16
-
17
- class CrudProExecuteFuncService extends CrudProServiceBase {
18
- executeFuncCfg(funCfg: IFuncCfgModel, funcContext: FuncContext) {
19
- if (isNil(funCfg)) {
20
- return null;
21
- }
22
-
23
- if (funCfg.___PLAIN_OBJECT___ === true) {
24
- return funCfg;
25
- }
26
-
27
- if (isNotNil(funCfg.const)) {
28
- return funCfg.const;
29
- }
30
- if (isNotNil(funCfg.constString)) {
31
- return '' + funCfg.constString;
32
- }
33
- if (isNotNil(funCfg.constNumber) && isNumeric(funCfg.constNumber)) {
34
- return Number(funCfg.constNumber);
35
- }
36
- if (isNotNil(funCfg.constBool)) {
37
- return Boolean(funCfg.constBool);
38
- }
39
-
40
- if (isNotNil(funCfg.context)) {
41
- return this.pickContextValue(funCfg.context, funcContext);
42
- }
43
- if (isNotNil(funCfg.contextAsString)) {
44
- return '' + this.pickContextValue(funCfg.contextAsString, funcContext);
45
- }
46
- if (isNotNil(funCfg.contextAsNumber)) {
47
- return Number(this.pickContextValue(funCfg.contextAsNumber, funcContext));
48
- }
49
- if (isNotNil(funCfg.contextAsBool)) {
50
- return Boolean(this.pickContextValue(funCfg.contextAsBool, funcContext));
51
- }
52
-
53
- if (isNotNil(funCfg.functionName)) {
54
- const func = this.getExecuteFunction(funCfg.functionName);
55
- if (!func) {
56
- throw new CommonException(Exceptions.RUN_FUNCTION_NOT_FOUND, funCfg.functionName);
57
- }
58
- const functionParamValues = this.getFunctionParamValues(funCfg.functionParams, funcContext);
59
- return func.apply(funcContext, functionParamValues);
60
- }
61
- return null;
62
- }
63
-
64
- private pickContextValue(pickString: string, funcCtx: FuncContext) {
65
- if (!pickString) {
66
- return null;
67
- }
68
-
69
- if (pickString === KeysOfFunCtx.FUNC_CTX) {
70
- return funcCtx;
71
- }
72
-
73
- if (pickString === KeysOfFunCtx.CURRENT_VALUE) {
74
- return funcCtx.currentValue;
75
- }
76
-
77
- // 例如:accountId, 访问此变量,用户必须登录。
78
- if (pickString.startsWith(KeysOfFunCtx.VISITOR_ATTR)) {
79
- const reqModel = funcCtx?.reqModel;
80
- const attrValue = _.get(reqModel, pickString); // visitor.nickName
81
- if (isNil(attrValue)) {
82
- throw new CommonException(Exceptions.RUN_PICK_ERR_VISITOR_NULL, '获取用户ID失败, 可能用户没有登陆');
83
- }
84
- return attrValue;
85
- }
86
-
87
- // 例如:accountId, 访问此变量,用户必须登录。
88
- if (pickString === KeysOfFunCtx.VISITOR) {
89
- const visitor = funcCtx?.reqModel?.visitor;
90
- if (isNil(visitor)) {
91
- throw new CommonException(Exceptions.RUN_PICK_ERR_VISITOR_NULL, '获取用户对象失败, 可能用户没有登陆');
92
- }
93
- return visitor;
94
- }
95
-
96
- // 例如: req.data.name
97
- if (pickString.startsWith(KeysOfFunCtx.REQUEST)) {
98
- const reqExpress = pickString.substring(KeysOfFunCtx.REQUEST.length);
99
- return _.get(funcCtx.reqModel, reqExpress);
100
- }
101
-
102
- // 例如: res.total_count
103
- if (pickString.startsWith(KeysOfFunCtx.RESULT)) {
104
- const reqExpress = pickString.substring(KeysOfFunCtx.RESULT.length);
105
- return _.get(funcCtx.resModel, reqExpress);
106
- }
107
-
108
- return null;
109
- }
110
-
111
- private getFunctionParamValues(functionParams: IFunctionParam[], funcContext: FuncContext): any[] {
112
- if (isNil(functionParams) || isEmpty(functionParams)) {
113
- return [];
114
- }
115
- return functionParams.map(p => {
116
- if (typeof p === 'undefined' || p === null) {
117
- return null;
118
- }
119
-
120
- if (typeof p === 'string' || typeof p === 'number' || typeof p === 'boolean') {
121
- return p;
122
- }
123
- return this.executeFuncCfg(p, funcContext);
124
- });
125
- }
126
- }
127
-
128
- export { CrudProExecuteFuncService };
@@ -1,279 +0,0 @@
1
- import * as _ from 'lodash';
2
- import {PoolClient} from 'pg'
3
- import {CrudProServiceBase} from './CrudProServiceBase';
4
- import {SqlCfgModel} from '../models/SqlCfgModel';
5
- import {KeyOfCrudTypes, KeysOfCustomSQL, KeysOfSqlResPicker, SqlDbType} from '../models/keys';
6
- import {CommonException, Exceptions} from '../exceptions';
7
- import {pickAndConvertPgRows} from '../utils/sqlConvert/convertPgType';
8
- import {replaceQuestionMarks} from "../utils/sqlConvert/convertPgSql";
9
- import {replaceQuestionMarksForMssql} from "../utils/sqlConvert/convertMsSql";
10
- import {ModelUtils} from '../utils/ModelUtils';
11
- import {MixinUtils} from '../utils/MixinUtils';
12
- import {FuncContext} from '../models/FuncContext';
13
- import {ExecuteContext} from "../models/ExecuteContext";
14
-
15
- const { checkFuncCfgValid } = ModelUtils;
16
- const { isEmpty } = MixinUtils;
17
-
18
- class CrudProExecuteSqlService extends CrudProServiceBase {
19
- async executeSqlCfgModels(): Promise<void> {
20
- const exeCtx = this.getExecuteContext();
21
- const sqlCfgModels = exeCtx.getSqlCfgModels();
22
- for (let i = 0; i < sqlCfgModels.length; i++) {
23
- const sqlCfgModel = sqlCfgModels[i];
24
- const checkResult = this.executeSqlCfgModelPreCheck(sqlCfgModel);
25
- if (checkResult) {
26
- await this.executeSqlCfgModel(sqlCfgModel);
27
- }
28
- }
29
- }
30
-
31
- private async executeSqlCfgModel(sqlCfgModel: SqlCfgModel) {
32
- this.logger.info('executeSqlCfgModel1', sqlCfgModel.executeSql, sqlCfgModel.executeSqlArgs);
33
-
34
- const exeCtx = this.getExecuteContext();
35
- const connection = await this.getTxConnectionBySqlCfg(sqlCfgModel);
36
- const executeSqlArgs = this.handleExecuteSqlArgsByResModel(exeCtx, sqlCfgModel.executeSqlArgs || [])
37
-
38
-
39
- let sqlRes: any;
40
- let queryRes : any;
41
-
42
- if (sqlCfgModel.sqlDdType === SqlDbType.postgres) { // import { PoolClient } from 'pg';
43
-
44
- const pgClient: PoolClient = connection as any;
45
- const pgSql = replaceQuestionMarks(sqlCfgModel.executeSql);
46
-
47
- this.logger.info('executeSqlCfgModel_postgres', pgSql, executeSqlArgs, sqlCfgModel.resPicker);
48
-
49
-
50
- queryRes = await pgClient.query({
51
- text: pgSql,
52
- values: executeSqlArgs || []
53
- });
54
- sqlRes = pickAndConvertPgRows(queryRes)
55
-
56
- }
57
-
58
- else if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
59
-
60
- const mssql = replaceQuestionMarksForMssql(sqlCfgModel.executeSql);
61
-
62
- this.logger.info('executeSqlCfgModel_sqlserver', mssql, executeSqlArgs, sqlCfgModel.resPicker);
63
- // SQLServer
64
- queryRes = await connection.query(mssql, executeSqlArgs);
65
- sqlRes = _.get(queryRes,'recordsets[0]') || []
66
- }
67
-
68
- else {
69
-
70
- this.logger.info('executeSqlCfgModel_mysql', sqlCfgModel.executeSql, executeSqlArgs, sqlCfgModel.resPicker);
71
-
72
-
73
- // MYSQL
74
- queryRes = await connection.query(sqlCfgModel.executeSql, executeSqlArgs);
75
- sqlRes = queryRes[0]
76
- }
77
-
78
- const resObject = this.toQueryResByResPicker(sqlRes, queryRes, sqlCfgModel);
79
- exeCtx.setResModelItem(sqlCfgModel.resName, resObject);
80
- }
81
-
82
-
83
- private handleExecuteSqlArgsByResModel(exeCtx: ExecuteContext, executeSqlArgs: any[]): any[] {
84
- return executeSqlArgs.map((arg)=> {
85
- if (arg && typeof arg === 'object' && typeof arg.___GENERATE_GET_RES_ATTR___ === 'string' ) {
86
- const word: string = arg.___GENERATE_GET_RES_ATTR___;
87
- if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)) {
88
- const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_NUMBER)
89
- this.logger.info('handleExecuteSqlArgsByResModel resName', resName);
90
- this.logger.info('handleExecuteSqlArgsByResModel getResModel', exeCtx.getResModel());
91
- return Number(exeCtx.getResModelItemLodash(resName) || 0);
92
- }
93
- if (word.startsWith(KeysOfCustomSQL.SQL_PICK_RES_AS_STRING)) {
94
- const resName = MixinUtils.removeStringPrefix(word, KeysOfCustomSQL.SQL_PICK_RES_AS_STRING)
95
- return String(exeCtx.getResModelItemLodash(resName) || "");
96
- }
97
- }
98
- return arg;
99
- })
100
- }
101
-
102
-
103
- private executeSqlCfgModelPreCheck(sqlCfgModel: SqlCfgModel): boolean {
104
- const crudType = sqlCfgModel.getCrudType();
105
-
106
- if (KeyOfCrudTypes.EMPTY_SQL === crudType) {
107
- // 允许空SQL,没有需要执行的正常。
108
- return false;
109
- }
110
-
111
- if (KeyOfCrudTypes.NOT_CRUD === crudType) {
112
- // 只支持增删改查,其他语句不支持。
113
- throw new CommonException(Exceptions.CFG_NOT_SUPPORT_THE_SQL, sqlCfgModel.executeSql);
114
- }
115
-
116
- // 此SQL不需要执行
117
- if (!this.isNeedExecute(sqlCfgModel)) {
118
- return false;
119
- }
120
-
121
- // 执行之前,根据配置校验一下此SQL是否可以执行
122
- this.assertByValidate(sqlCfgModel);
123
-
124
- return true;
125
- }
126
-
127
- private assertByValidate(sqlCfgModel: SqlCfgModel) {
128
- const exeCtx = this.getExecuteContext();
129
- const funcCfg = sqlCfgModel.validate;
130
- if (!funcCfg) {
131
- return; // 没有配置。
132
- }
133
-
134
- if (!checkFuncCfgValid(funcCfg)) {
135
- throw new CommonException(Exceptions.CFG_SQL_CFG_EXECUTE_VALIDATE_EMPTY, {
136
- funcCfg: funcCfg,
137
- originSql: sqlCfgModel.originSql,
138
- });
139
- }
140
-
141
- const errMsg = funcCfg.message || '执行前校验失败';
142
-
143
- let result;
144
- try {
145
- const exeFunCtx = new FuncContext();
146
-
147
- exeFunCtx.currentValue = null;
148
- exeFunCtx.reqModel = exeCtx.getReqModel();
149
- exeFunCtx.resModel = exeCtx.getResModel();
150
-
151
- result = this.serviceHub.executeFuncCfg(funcCfg, exeFunCtx); // 可以抛出异常
152
- } catch (e) {
153
- this.logger.debug('assertByValidate', e);
154
- throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, {
155
- funcCfg: funcCfg,
156
- originSql: sqlCfgModel.originSql,
157
- error: '' + e,
158
- });
159
- }
160
-
161
- if (!(typeof result === 'boolean')) {
162
- // 自定义的校验函数,必须返回boolean类型的树枝
163
- throw new CommonException(Exceptions.CFG_IS_NEED_EXECUTE_FUNC_MUST_RETURN_BOOL, {
164
- funcCfg: funcCfg,
165
- originSql: sqlCfgModel.originSql,
166
- });
167
- }
168
-
169
- if (result === false) {
170
- throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, errMsg);
171
- }
172
- }
173
-
174
- /**
175
- * 判断此SQL是否需要执行
176
- * @param sqlCfgModel
177
- * @param exeCtx
178
- * @private
179
- */
180
- private isNeedExecute(sqlCfgModel: SqlCfgModel) {
181
- const exeCtx = this.getExecuteContext();
182
- const funcCfg = sqlCfgModel.executeWhen;
183
- if (!funcCfg || Object.keys(funcCfg).length === 0) {
184
- return true; // 没有配置。默认,需要执行。
185
- }
186
-
187
- if (!checkFuncCfgValid(funcCfg)) {
188
- throw new CommonException(Exceptions.CFG_CHECK_EXECUTE_WHEN_EMPTY, {
189
- funcCfg: funcCfg,
190
- originSql: sqlCfgModel.originSql,
191
- });
192
- }
193
-
194
- let result;
195
-
196
- try {
197
- const exeFunCtx = new FuncContext();
198
-
199
- exeFunCtx.currentValue = null;
200
- exeFunCtx.reqModel = exeCtx.getReqModel();
201
- exeFunCtx.resModel = exeCtx.getResModel();
202
-
203
- result = this.serviceHub.executeFuncCfg(funcCfg, exeFunCtx);
204
- } catch (e) {
205
- this.logger.debug('isNeedExecute', e);
206
- throw new CommonException(Exceptions.RUN_IS_NEED_EXECUTE_ERR, {
207
- funcCfg: funcCfg,
208
- originSql: sqlCfgModel.originSql,
209
- error: '' + e,
210
- });
211
- }
212
-
213
- if (!(typeof result === 'boolean')) {
214
- // 自定义的校验函数,必须返回boolean类型的树枝
215
- throw new CommonException(Exceptions.CFG_IS_NEED_EXECUTE_FUNC_MUST_RETURN_BOOL, {
216
- funcCfg: funcCfg,
217
- originSql: sqlCfgModel.originSql,
218
- });
219
- }
220
-
221
- return result === true;
222
- }
223
-
224
- private toQueryResByResPicker(sqlRes: any, queryRes: any, sqlCfgModel: SqlCfgModel) {
225
- const resPicker = sqlCfgModel.resPicker;
226
-
227
- // 返回第一行
228
- if (KeysOfSqlResPicker.RESULT_FIRST_ROW === resPicker) {
229
- const rows = sqlRes as any[];
230
- if (rows && rows.length > 0) {
231
- return rows[0];
232
- }
233
- return null;
234
- }
235
-
236
- // $ResultSet[0].total_count , 只取第一行的的total_count
237
- if (KeysOfSqlResPicker.RESULT_TOTAL_COUNT === resPicker) {
238
- const rows = sqlRes as any[];
239
- if (isEmpty(rows)) {
240
- return 0;
241
- }
242
- const map0 = rows[0];
243
- return Number(map0['total_count'] || 0);
244
- }
245
-
246
- // 增删改res的内容是修改结果:包括: insert\delete\update
247
- if (KeysOfSqlResPicker.UPDATE_RESULT === resPicker) {
248
- if (sqlCfgModel.sqlDdType === SqlDbType.postgres) {
249
- return {
250
- insertId: _.get(queryRes,'rows[0].id'),
251
- affectedRows: _.get(queryRes,'rowCount')
252
- }
253
- }
254
-
255
- if (sqlCfgModel.sqlDdType === SqlDbType.sqlserver) {
256
- return {
257
- insertId: _.get(queryRes,'recordset[0].id'),
258
- affectedRows: _.get(queryRes,'rowsAffected[0]')
259
- }
260
- }
261
-
262
- return sqlRes;
263
- }
264
-
265
- //其他配置:形如: sqlRes[0].total_count
266
- if (typeof resPicker === 'string') {
267
- if (resPicker.startsWith('sqlRes')){
268
- return _.get({ sqlRes }, resPicker);
269
- } else {
270
- throw new CommonException(Exceptions.RUN_EXECUTE_VALIDATE, 'resPicker必须是以sqlRes开头')
271
- }
272
- }
273
-
274
- return sqlRes;
275
- }
276
-
277
- }
278
-
279
- export { CrudProExecuteSqlService };
@@ -1,60 +0,0 @@
1
- import { RequestModel } from '../models/RequestModel';
2
- import { CrudProServiceBase } from './CrudProServiceBase';
3
- import { RequestCfgModel } from '../models/RequestCfgModel';
4
- import { MixinUtils } from '../utils/MixinUtils';
5
- import { IFuncCfgModel } from '../interfaces';
6
- import * as _ from 'lodash';
7
- import { ModelUtils } from '../utils/ModelUtils';
8
- import { CommonException, Exceptions } from '../exceptions';
9
- import { FuncContext } from '../models/FuncContext';
10
- const { checkFuncCfgValid } = ModelUtils;
11
- const { isEmpty } = MixinUtils;
12
-
13
- class CrudProFieldUpdateService extends CrudProServiceBase {
14
- updateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel) {
15
- const updateCfgMap = cfgModel.updateCfg;
16
- if (isEmpty(updateCfgMap)) {
17
- return;
18
- }
19
-
20
- const keys = Object.keys(updateCfgMap);
21
- for (let i = 0; i < keys.length; i++) {
22
- const key = keys[i]; // data.name
23
- const updateCfg = updateCfgMap[key];
24
- this.updateByJsonObject(updateCfg, key, reqModel);
25
- }
26
- }
27
-
28
- private updateByJsonObject(updateCfg: IFuncCfgModel, key: string, reqModel: RequestModel) {
29
- if (isEmpty(updateCfg)) {
30
- return;
31
- }
32
- const itemOldValue = _.get(reqModel, key);
33
- const newValue = this.getUpdateNewValueByCfg(updateCfg, itemOldValue, key, reqModel);
34
- _.set(reqModel, key, newValue);
35
- }
36
-
37
- private getUpdateNewValueByCfg(updateCfg: IFuncCfgModel, itemOldValue: any, key: string, reqModel: RequestModel) {
38
- if (!checkFuncCfgValid(updateCfg)) {
39
- throw new CommonException(Exceptions.CFG_UPDATE_ITEM_MUST_FUNC_CFG, 'updateCfg配置项必须是满足IFuncCfgModel' + key);
40
- }
41
-
42
- let result;
43
-
44
- try {
45
- const exeFunCtx = new FuncContext();
46
-
47
- exeFunCtx.currentValue = itemOldValue;
48
- exeFunCtx.reqModel = reqModel;
49
-
50
- result = this.serviceHub.executeFuncCfg(updateCfg, exeFunCtx);
51
- } catch (e) {
52
- this.logger.error('getUpdateNewValueByCfg->executeFuncCfg', e);
53
- throw new CommonException(Exceptions.UPDATE_EXCEPTION, key + '.' + e);
54
- }
55
-
56
- return result;
57
- }
58
- }
59
-
60
- export { CrudProFieldUpdateService };
@@ -1,180 +0,0 @@
1
- import { RequestModel } from '../models/RequestModel';
2
- import { CrudProServiceBase } from './CrudProServiceBase';
3
- import { RequestCfgModel } from '../models/RequestCfgModel';
4
- import { MixinUtils } from '../utils/MixinUtils';
5
- import { KeysOfConditions, KeysOfValidators } from '../models/keys';
6
- import { CommonException, Exceptions } from '../exceptions';
7
- import { ModelUtils } from '../utils/ModelUtils';
8
- import { ICustomValidateFunc, IFuncCfgModel, IValidatorCfgItem } from '../interfaces';
9
- import { FuncContext } from '../models/FuncContext';
10
- import { validateByCfgString } from '../utils/ValidateUtils';
11
-
12
- const { checkFuncCfgValid } = ModelUtils;
13
-
14
- const { isEmpty, isNotEmpty, deepTravelObject } = MixinUtils;
15
-
16
- class CrudProFieldValidateService extends CrudProServiceBase {
17
- validateByAllow(cfgModel: RequestCfgModel, reqModel: RequestModel) {
18
- const allowCfg = cfgModel.allowCfg; // allowCfg: {data: ['login_name', 'nick_name', 'avatar', 'status'],},
19
- if (isEmpty(allowCfg)) {
20
- return;
21
- }
22
-
23
- const keys = Object.keys(allowCfg);
24
-
25
- const validateAllowByJsonObject = (allowList: string[], targetObj: any, key: string) => {
26
- if (isEmpty(allowList)) {
27
- return;
28
- }
29
-
30
- const isCondition = key.startsWith('condition');
31
-
32
- // 任意一个key,不在allow列表中,就不合法
33
- deepTravelObject(
34
- targetObj,
35
- (value, key, index, keyPath) => {
36
- if (isCondition) {
37
- if (!KeysOfConditions.ALL_KEYS.has(key) && !allowList.includes(key)) {
38
- throw new CommonException(Exceptions.VALIDATE_ALLOW_ERR, keyPath);
39
- }
40
- } else {
41
- if (!allowList.includes(key)) {
42
- throw new CommonException(Exceptions.VALIDATE_ALLOW_ERR, keyPath);
43
- }
44
- }
45
- },
46
- key
47
- );
48
- };
49
-
50
- for (let i = 0; i < keys.length; i++) {
51
- const key = keys[i]; // demo: data or condition
52
- const allowList = MixinUtils.parseStringArray(allowCfg[key]);
53
- if (Array.isArray(allowList) && allowList.length > 0) {
54
- const targetObj = reqModel.getCondOrDataJsonObject(key);
55
- validateAllowByJsonObject(allowList, targetObj, key);
56
- }
57
- }
58
- }
59
-
60
- validateByReject(cfgModel: RequestCfgModel, reqModel: RequestModel) {
61
- const rejectCfgMap = cfgModel.rejectCfg;
62
- if (isEmpty(rejectCfgMap)) {
63
- return;
64
- }
65
-
66
- const keys = Object.keys(rejectCfgMap);
67
-
68
- const validateRejectByJsonObject = (rejectList: string[], targetObj: any, conditionName: string) => {
69
- if (isEmpty(rejectList)) {
70
- return;
71
- }
72
- // 任意一个key,出现在reject列表中,就不合法
73
- deepTravelObject(
74
- targetObj,
75
- (value, key, index, keyPath) => {
76
- if (rejectList.includes(key)) {
77
- throw new CommonException(Exceptions.VALIDATE_REJECT_ERR, keyPath);
78
- }
79
- },
80
- conditionName
81
- );
82
- };
83
-
84
- for (let i = 0; i < keys.length; i++) {
85
- const conditionName = keys[i];
86
- const rejectList = MixinUtils.parseStringArray(rejectCfgMap[conditionName]);
87
- if (Array.isArray(rejectList) && rejectList.length > 0) {
88
- const targetObj = reqModel.getCondOrDataJsonObject(conditionName);
89
- validateRejectByJsonObject(rejectList, targetObj, conditionName);
90
- }
91
- }
92
- }
93
-
94
- validateByCfg(cfgModel: RequestCfgModel, reqModel: RequestModel) {
95
- const validateCfg = cfgModel.validateCfg;
96
- if (isEmpty(validateCfg)) {
97
- return;
98
- }
99
- const keys = Object.keys(validateCfg);
100
- for (const key of keys) {
101
- const itemValue = reqModel.getJsonObjectValue(key);
102
- const cfgList = validateCfg[key];
103
-
104
- if (isNotEmpty(cfgList)) {
105
- // 先校验是否必填。
106
- this.validateRequired(cfgList, itemValue, key);
107
-
108
- // 除REQUIRED之外的其他配置
109
- const cfgList2 = cfgList.filter(cfg => {
110
- return cfg !== KeysOfValidators.REQUIRED;
111
- });
112
-
113
- // 只有数值不为空时,才需要校验。非必填情况下:内容为空,不需要校验
114
- if (isNotEmpty(itemValue)) {
115
- for (const cfg of cfgList2) {
116
- if (typeof cfg === 'string') {
117
- this.validateByCfgString(cfg, reqModel, itemValue, key);
118
- } else if (typeof cfg === 'function') {
119
- this.validateByCfgCustomFunction(cfg, reqModel, itemValue, key);
120
- } else {
121
- this.validateByCfgFunc(cfg, reqModel, itemValue, key);
122
- }
123
- }
124
- }
125
- }
126
- }
127
- }
128
-
129
- private validateByCfgCustomFunction(cfg: ICustomValidateFunc, reqModel: RequestModel, itemValue: any, key: string) {
130
- // 使用自定义函数校验
131
- cfg(itemValue);
132
- }
133
-
134
- private validateByCfgString(itemCfg: KeysOfValidators | string, reqModel: RequestModel, itemValue: any, errPath: string) {
135
- return validateByCfgString(itemCfg, itemValue, errPath);
136
- }
137
-
138
- private validateByCfgFunc(funcCfg: IFuncCfgModel, reqModel: RequestModel, itemValue: any, errPath: string) {
139
- if (!checkFuncCfgValid(funcCfg)) {
140
- throw new CommonException(Exceptions.CFG_VALIDATE_CUSTOM_FUNCTION_EMPTY);
141
- }
142
-
143
- let result;
144
-
145
- try {
146
- const exeFunCtx = new FuncContext();
147
-
148
- exeFunCtx.currentValue = itemValue;
149
- exeFunCtx.reqModel = reqModel;
150
-
151
- result = this.serviceHub.executeFuncCfg(funcCfg, exeFunCtx);
152
- } catch (e) {
153
- this.logger.error('validateByCfgFunc', e);
154
- throw new CommonException(Exceptions.VALIDATE_EXCEPTION, errPath + '.' + e);
155
- }
156
-
157
- if (!(typeof result === 'boolean')) {
158
- // 自定义的校验函数,必须返回boolean类型的树枝
159
- throw new CommonException(Exceptions.CFG_VALIDATE_CUSTOM_FUNCTION_MUST_RETURN_BOOL, errPath);
160
- }
161
-
162
- if (result === false) {
163
- throw new CommonException(Exceptions.VALIDATE_ERR, funcCfg.message || errPath);
164
- }
165
- }
166
-
167
- private validateRequired(cfgList: IValidatorCfgItem[], itemValue: any, errPath: string) {
168
- const required = cfgList.find(cfg => {
169
- return cfg === KeysOfValidators.REQUIRED;
170
- });
171
-
172
- if (required) {
173
- if (isEmpty(itemValue)) {
174
- throw new CommonException(Exceptions.VALIDATE_ERR, '参数校验错误,缺少必填字段:' + errPath);
175
- }
176
- }
177
- }
178
- }
179
-
180
- export { CrudProFieldValidateService };