midway-fatcms 0.0.1-beta.2 → 0.0.1-beta.20

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 (246) hide show
  1. package/.eslintrc.json +12 -0
  2. package/.prettierrc.js +4 -0
  3. package/README.md +7 -0
  4. package/dist/config/config.default.js +52 -15
  5. package/dist/configuration.d.ts +1 -0
  6. package/dist/configuration.js +33 -8
  7. package/dist/controller/base/BaseApiController.d.ts +1 -1
  8. package/dist/controller/base/BaseApiController.js +9 -6
  9. package/dist/controller/gateway/AsyncTaskController.d.ts +14 -0
  10. package/dist/controller/gateway/AsyncTaskController.js +108 -0
  11. package/dist/controller/gateway/CrudMtdGatewayController.d.ts +3 -3
  12. package/dist/controller/gateway/CrudMtdGatewayController.js +9 -6
  13. package/dist/controller/gateway/DocGatewayController.js +14 -9
  14. package/dist/controller/gateway/PublicApiController.js +4 -6
  15. package/dist/controller/gateway/StaticController.d.ts +2 -0
  16. package/dist/controller/gateway/StaticController.js +59 -40
  17. package/dist/controller/helpers.controller.d.ts +1 -1
  18. package/dist/controller/home.controller.js +2 -2
  19. package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
  20. package/dist/controller/manage/CrudStandardDesignApi.js +78 -75
  21. package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
  22. package/dist/controller/manage/DeployManageApi.d.ts +1 -1
  23. package/dist/controller/manage/DeployManageApi.js +38 -34
  24. package/dist/controller/manage/MenuManageApi.js +1 -1
  25. package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
  26. package/dist/controller/manage/SuperAdminManageApi.js +12 -8
  27. package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
  28. package/dist/controller/manage/SysConfigMangeApi.js +6 -4
  29. package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
  30. package/dist/controller/manage/SystemInfoManageApi.js +7 -1
  31. package/dist/controller/manage/UserAccountManageApi.d.ts +2 -2
  32. package/dist/controller/manage/UserAccountManageApi.js +5 -0
  33. package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
  34. package/dist/controller/myinfo/AuthController.d.ts +0 -4
  35. package/dist/controller/myinfo/AuthController.js +1 -54
  36. package/dist/controller/render/AppRenderController.js +10 -4
  37. package/dist/controller/test.controller.d.ts +1 -1
  38. package/dist/controller/test.controller.js +5 -5
  39. package/dist/index.d.ts +34 -4
  40. package/dist/index.js +34 -4
  41. package/dist/libs/crud-pro/CrudPro.d.ts +1 -0
  42. package/dist/libs/crud-pro/CrudPro.js +5 -0
  43. package/dist/libs/crud-pro/defaultConfigs.js +2 -0
  44. package/dist/libs/crud-pro/interfaces.d.ts +7 -1
  45. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +2 -1
  46. package/dist/libs/crud-pro/models/ExecuteContextFunc.d.ts +8 -1
  47. package/dist/libs/crud-pro/models/ExecuteContextFunc.js +8 -0
  48. package/dist/libs/crud-pro/models/RequestCfgModel.d.ts +1 -1
  49. package/dist/libs/crud-pro/models/ResModel.d.ts +16 -0
  50. package/dist/libs/crud-pro/models/ResModel.js +2 -0
  51. package/dist/libs/crud-pro/models/SqlCfgModel.d.ts +1 -1
  52. package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
  53. package/dist/libs/crud-pro/services/CrudProCachedCfgService.d.ts +1 -0
  54. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +22 -11
  55. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +10 -9
  56. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
  57. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +10 -12
  58. package/dist/libs/crud-pro/services/CrudProGenSqlService.js +14 -23
  59. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +7 -6
  60. package/dist/libs/crud-pro/services/CrudProServiceBase.d.ts +2 -6
  61. package/dist/libs/crud-pro/services/CrudProServiceBase.js +3 -2
  62. package/dist/libs/crud-pro/services/CrudProTableMetaService.d.ts +1 -0
  63. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +31 -7
  64. package/dist/libs/crud-pro/utils/DatabaseName.js +24 -3
  65. package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
  66. package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
  67. package/dist/libs/crud-pro/utils/sqlConvert/convertColumnName.js +2 -2
  68. package/dist/libs/global-config/global-config.d.ts +45 -0
  69. package/dist/libs/global-config/global-config.js +33 -0
  70. package/dist/libs/utils/errorToString.d.ts +2 -0
  71. package/dist/libs/utils/errorToString.js +57 -0
  72. package/dist/libs/utils/fatcms-request.js +2 -2
  73. package/dist/middleware/forbidden.middleware.js +4 -20
  74. package/dist/middleware/global.middleware.js +8 -1
  75. package/dist/models/AsyncTaskModel.d.ts +69 -0
  76. package/dist/models/AsyncTaskModel.js +26 -0
  77. package/dist/models/RedisKeys.d.ts +8 -0
  78. package/dist/models/RedisKeys.js +11 -0
  79. package/dist/models/SystemTables.d.ts +1 -3
  80. package/dist/models/SystemTables.js +2 -4
  81. package/dist/schedule/anonymousContext.d.ts +13 -0
  82. package/dist/schedule/anonymousContext.js +59 -0
  83. package/dist/schedule/index.d.ts +4 -3
  84. package/dist/schedule/index.js +8 -67
  85. package/dist/schedule/runSchedule.d.ts +15 -0
  86. package/dist/schedule/runSchedule.js +68 -0
  87. package/dist/schedule/scheduleNames.d.ts +13 -0
  88. package/dist/schedule/scheduleNames.js +17 -0
  89. package/dist/service/AuthService.js +8 -5
  90. package/dist/service/EnumInfoService.js +7 -4
  91. package/dist/service/FileCenterService.js +13 -9
  92. package/dist/service/SysConfigService.js +4 -2
  93. package/dist/service/UserAccountService.js +10 -6
  94. package/dist/service/UserSessionService.js +2 -1
  95. package/dist/service/VisitStatService.d.ts +1 -1
  96. package/dist/service/VisitStatService.js +20 -27
  97. package/dist/service/WorkbenchService.js +4 -2
  98. package/dist/service/anyapi/AnyApiService.js +4 -2
  99. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +37 -0
  100. package/dist/service/asyncTask/AsyncTaskRunnerService.js +226 -0
  101. package/dist/service/asyncTask/AsyncTaskService.d.ts +7 -0
  102. package/dist/service/asyncTask/AsyncTaskService.js +34 -0
  103. package/dist/service/crudstd/CrudStdService.d.ts +1 -0
  104. package/dist/service/crudstd/CrudStdService.js +34 -3
  105. package/dist/service/curd/CrudProQuick.d.ts +24 -0
  106. package/dist/service/curd/CrudProQuick.js +105 -0
  107. package/dist/service/curd/CurdMixByAccountService.js +12 -6
  108. package/dist/service/curd/CurdMixByDictService.js +4 -2
  109. package/dist/service/curd/CurdMixByLinkToCustomService.d.ts +10 -1
  110. package/dist/service/curd/CurdMixByLinkToCustomService.js +72 -24
  111. package/dist/service/curd/CurdMixBySysConfigService.js +4 -2
  112. package/dist/service/curd/CurdMixByWorkbenchService.js +4 -2
  113. package/dist/service/curd/CurdMixService.d.ts +1 -1
  114. package/dist/service/curd/CurdMixService.js +2 -2
  115. package/dist/service/curd/CurdMixUtils.d.ts +7 -0
  116. package/dist/service/curd/CurdMixUtils.js +65 -28
  117. package/dist/service/curd/CurdProService.d.ts +2 -10
  118. package/dist/service/curd/CurdProService.js +31 -146
  119. package/dist/service/curd/fixCfgModel.d.ts +3 -0
  120. package/dist/service/curd/fixCfgModel.js +107 -0
  121. package/dist/service/proxyapi/ProxyApiLoadService.js +7 -4
  122. package/dist/views/404_app.html +31 -0
  123. package/dist/views/404_workbench.html +34 -0
  124. package/dist/views/static/favicon.ico +0 -0
  125. package/package.json +9 -2
  126. package/src/config/config.default.ts +58 -27
  127. package/src/configuration.ts +42 -9
  128. package/src/controller/base/BaseApiController.ts +19 -19
  129. package/src/controller/gateway/AnyApiGatewayController.ts +1 -1
  130. package/src/controller/gateway/AsyncTaskController.ts +83 -0
  131. package/src/controller/gateway/CrudMtdGatewayController.ts +17 -13
  132. package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
  133. package/src/controller/gateway/DocGatewayController.ts +25 -17
  134. package/src/controller/gateway/FileController.ts +8 -9
  135. package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
  136. package/src/controller/gateway/PublicApiController.ts +19 -22
  137. package/src/controller/gateway/StaticController.ts +234 -242
  138. package/src/controller/helpers.controller.ts +1 -1
  139. package/src/controller/home.controller.ts +8 -15
  140. package/src/controller/manage/AnyApiMangeApi.ts +9 -9
  141. package/src/controller/manage/AppLogMangeApi.ts +3 -3
  142. package/src/controller/manage/AppMangeApi.ts +5 -5
  143. package/src/controller/manage/AppPageMangeApi.ts +3 -3
  144. package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
  145. package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
  146. package/src/controller/manage/CrudStandardDesignApi.ts +106 -113
  147. package/src/controller/manage/DataDictManageApi.ts +4 -4
  148. package/src/controller/manage/DeployManageApi.ts +85 -89
  149. package/src/controller/manage/DocLibManageApi.ts +3 -3
  150. package/src/controller/manage/DocManageApi.ts +8 -8
  151. package/src/controller/manage/MenuManageApi.ts +9 -14
  152. package/src/controller/manage/SuperAdminManageApi.ts +14 -13
  153. package/src/controller/manage/SysConfigMangeApi.ts +9 -9
  154. package/src/controller/manage/SystemInfoManageApi.ts +11 -6
  155. package/src/controller/manage/UserAccountManageApi.ts +8 -2
  156. package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
  157. package/src/controller/myinfo/AuthController.ts +6 -72
  158. package/src/controller/render/AppRenderController.ts +24 -21
  159. package/src/controller/test.controller.ts +18 -18
  160. package/src/index.ts +38 -4
  161. package/src/libs/crud-pro/CrudPro.ts +7 -0
  162. package/src/libs/crud-pro/defaultConfigs.ts +2 -0
  163. package/src/libs/crud-pro/interfaces.ts +10 -3
  164. package/src/libs/crud-pro/models/ExecuteContext.ts +3 -3
  165. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +11 -1
  166. package/src/libs/crud-pro/models/RequestCfgModel.ts +1 -1
  167. package/src/libs/crud-pro/models/RequestModel.ts +1 -1
  168. package/src/libs/crud-pro/models/ResModel.ts +19 -0
  169. package/src/libs/crud-pro/models/SqlCfgModel.ts +2 -2
  170. package/src/libs/crud-pro/models/Transaction.ts +8 -9
  171. package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
  172. package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
  173. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +26 -19
  174. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +38 -50
  175. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +26 -45
  176. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +23 -40
  177. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +25 -29
  178. package/src/libs/crud-pro/services/CrudProServiceBase.ts +5 -9
  179. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +35 -9
  180. package/src/libs/crud-pro/utils/DatabaseName.ts +35 -15
  181. package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
  182. package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
  183. package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
  184. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
  185. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
  186. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
  187. package/src/libs/crud-pro/utils/sqlConvert/convertColumnName.ts +2 -2
  188. package/src/libs/global-config/global-config.ts +78 -0
  189. package/src/libs/utils/crypto-utils.ts +2 -4
  190. package/src/libs/utils/errorToString.ts +61 -0
  191. package/src/libs/utils/fatcms-request.ts +9 -21
  192. package/src/libs/utils/ordernum-utils.ts +2 -6
  193. package/src/libs/utils/parseConfig.ts +7 -15
  194. package/src/middleware/forbidden.middleware.ts +6 -25
  195. package/src/middleware/global.middleware.ts +18 -16
  196. package/src/models/AsyncTaskModel.ts +79 -0
  197. package/src/models/RedisKeys.ts +13 -0
  198. package/src/models/SystemTables.ts +1 -4
  199. package/src/models/bizmodels.ts +1 -2
  200. package/src/schedule/anonymousContext.ts +79 -0
  201. package/src/schedule/index.ts +11 -72
  202. package/src/schedule/runSchedule.ts +83 -0
  203. package/src/schedule/scheduleNames.ts +21 -0
  204. package/src/service/AuthService.ts +13 -8
  205. package/src/service/EnumInfoService.ts +8 -3
  206. package/src/service/FileCenterService.ts +12 -6
  207. package/src/service/SysConfigService.ts +10 -6
  208. package/src/service/UserAccountService.ts +14 -4
  209. package/src/service/UserSessionService.ts +5 -4
  210. package/src/service/VisitStatService.ts +57 -70
  211. package/src/service/WorkbenchService.ts +7 -2
  212. package/src/service/anyapi/AnyApiService.ts +11 -8
  213. package/src/service/asyncTask/AsyncTaskRunnerService.ts +249 -0
  214. package/src/service/asyncTask/AsyncTaskService.ts +21 -0
  215. package/src/service/base/BaseService.ts +2 -2
  216. package/src/service/crudstd/CrudStdService.ts +43 -5
  217. package/src/service/curd/CrudProQuick.ts +137 -0
  218. package/src/service/curd/CurdMixByAccountService.ts +14 -6
  219. package/src/service/curd/CurdMixByDictService.ts +8 -2
  220. package/src/service/curd/CurdMixByLinkToCustomService.ts +101 -50
  221. package/src/service/curd/CurdMixBySysConfigService.ts +7 -2
  222. package/src/service/curd/CurdMixByWorkbenchService.ts +6 -2
  223. package/src/service/curd/CurdMixService.ts +3 -3
  224. package/src/service/curd/CurdMixUtils.ts +82 -39
  225. package/src/service/curd/CurdProService.ts +45 -189
  226. package/src/service/curd/fixCfgModel.ts +139 -0
  227. package/src/service/proxyapi/ProxyApiLoadService.ts +12 -3
  228. package/src/views/404_app.html +31 -0
  229. package/src/views/404_workbench.html +34 -0
  230. package/src/views/static/favicon.ico +0 -0
  231. package/tsconfig.json +32 -0
  232. package/dist/controller/medstatistic/MedAdminController.d.ts +0 -35
  233. package/dist/controller/medstatistic/MedAdminController.js +0 -205
  234. package/dist/controller/medstatistic/MedClientController.d.ts +0 -28
  235. package/dist/controller/medstatistic/MedClientController.js +0 -188
  236. package/dist/controller/medstatistic/MedMessageService.d.ts +0 -19
  237. package/dist/controller/medstatistic/MedMessageService.js +0 -95
  238. package/dist/controller/medstatistic/MedScoreService.d.ts +0 -21
  239. package/dist/controller/medstatistic/MedScoreService.js +0 -107
  240. package/dist/controller/medstatistic/constants.d.ts +0 -32
  241. package/dist/controller/medstatistic/constants.js +0 -43
  242. package/src/controller/medstatistic/MedAdminController.ts +0 -221
  243. package/src/controller/medstatistic/MedClientController.ts +0 -188
  244. package/src/controller/medstatistic/MedMessageService.ts +0 -89
  245. package/src/controller/medstatistic/MedScoreService.ts +0 -108
  246. package/src/controller/medstatistic/constants.ts +0 -63
@@ -1,9 +1,10 @@
1
1
  import { Inject, Provide } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL} from "../libs/crud-pro/models/keys";
4
- import {SystemDbName, SystemDbType, SystemTables} from "../models/SystemTables";
5
- import {BaseService} from "./base/BaseService";
6
- import {CurdProService} from "./curd/CurdProService";
3
+ import { KeysOfSimpleSQL } from "../libs/crud-pro/models/keys";
4
+ import { SystemTables } from "../models/SystemTables";
5
+ import { BaseService } from "./base/BaseService";
6
+ import { CurdProService } from "./curd/CurdProService";
7
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
7
8
 
8
9
  @Provide()
9
10
  export class SysConfigService extends BaseService {
@@ -14,9 +15,12 @@ export class SysConfigService extends BaseService {
14
15
  private curdProService: CurdProService;
15
16
 
16
17
  async getSysConfigOne(config_code: string): Promise<any> {
17
- if (!config_code){
18
+ if (!config_code) {
18
19
  throw new Error('[getSysConfigOne] config_code required');
19
20
  }
21
+
22
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
23
+
20
24
  const res1 = await this.curdProService.executeCrudByCfg(
21
25
  {
22
26
  condition: { config_code },
@@ -25,7 +29,7 @@ export class SysConfigService extends BaseService {
25
29
  sqlTable: SystemTables.sys_configs,
26
30
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
27
31
  sqlDatabase: SystemDbName,
28
- sqlDdType: SystemDbType,
32
+ sqlDbType: SystemDbType,
29
33
  }
30
34
  );
31
35
  return res1.getOneObj();
@@ -6,8 +6,9 @@ import { CurdMixService } from './curd/CurdMixService';
6
6
  import { createUniqueId } from '../libs/utils/functions';
7
7
  import { CommonException, Exceptions } from '../libs/crud-pro/exceptions';
8
8
  import { IRequestCfgModel, IRequestModel } from '../libs/crud-pro/interfaces';
9
- import {SystemDbName, SystemDbType, SystemTables} from '../models/SystemTables';
9
+ import {SystemTables} from '../models/SystemTables';
10
10
  import { CommonResult } from '../libs/utils/common-dto';
11
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
11
12
 
12
13
  @Provide()
13
14
  export class UserAccountService {
@@ -21,6 +22,9 @@ export class UserAccountService {
21
22
  * @param loginName
22
23
  */
23
24
  public async queryUserAccountByLoginName(loginName: string) {
25
+
26
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
27
+
24
28
  const query = await this.curdMixService.executeCrudByCfg(
25
29
  {
26
30
  condition: { login_name: loginName },
@@ -30,7 +34,7 @@ export class UserAccountService {
30
34
  sqlTable: SystemTables.sys_user_account,
31
35
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
32
36
  sqlDatabase: SystemDbName,
33
- sqlDdType: SystemDbType,
37
+ sqlDbType: SystemDbType,
34
38
  }
35
39
  );
36
40
  const { row } = query.getResModel();
@@ -47,6 +51,9 @@ export class UserAccountService {
47
51
  return [];
48
52
  }
49
53
 
54
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
55
+
56
+
50
57
  const accountIds = accountIdList.map(userId => {
51
58
  return `${userId}`;
52
59
  });
@@ -56,7 +63,7 @@ export class UserAccountService {
56
63
  sqlTable: SystemTables.sys_user_account,
57
64
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
58
65
  sqlDatabase: SystemDbName,
59
- sqlDdType: SystemDbType,
66
+ sqlDbType: SystemDbType,
60
67
  };
61
68
 
62
69
  const reqJson: IRequestModel = {
@@ -81,6 +88,9 @@ export class UserAccountService {
81
88
  if (!loginName) {
82
89
  throw new CommonException(Exceptions.OTHER_EXCEPTION, 'loginName不存在');
83
90
  }
91
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
92
+
93
+
84
94
  const pwd_salt = createUniqueId();
85
95
  const pwd_md5 = md5(unsaltedPwd + pwd_salt);
86
96
  const res1 = await this.curdMixService.executeCrudByCfg(
@@ -92,7 +102,7 @@ export class UserAccountService {
92
102
  sqlTable: SystemTables.sys_user_account,
93
103
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
94
104
  sqlDatabase: SystemDbName,
95
- sqlDdType: SystemDbType,
105
+ sqlDbType: SystemDbType,
96
106
  }
97
107
  );
98
108
  return CommonResult.successRes(res1.getResModel());
@@ -1,8 +1,9 @@
1
1
  import {Inject, Provide} from '@midwayjs/core';
2
2
  import {Context} from '@midwayjs/koa';
3
- import {parseJsonObject} from '../libs/utils/functions';
4
- import {ISessionInfo, SESSION_ID_KEY, sessionCookieCfg} from '../models/userSession';
3
+ import {parseJsonObject} from '@/libs/utils/functions';
4
+ import {ISessionInfo, SESSION_ID_KEY, sessionCookieCfg} from '@/models/userSession';
5
5
  import {RedisCacheService} from "./base/RedisCacheService";
6
+ import {RedisKeys} from "@/models/RedisKeys";
6
7
 
7
8
 
8
9
  function pickUserAvatar(avatar: any): string {
@@ -35,8 +36,8 @@ function pickUserAvatar(avatar: any): string {
35
36
 
36
37
  const SESSION_KEEP_TIME_SECOND: number = 3600 * 24 * 30;
37
38
 
38
- const toCacheKey = (sessionId: string)=>{
39
- return `UserSession@@${sessionId}`;
39
+ const toCacheKey = (sessionId: string): string =>{
40
+ return `${RedisKeys.USER_SESSION_PREFIX}${sessionId}`;
40
41
  }
41
42
 
42
43
  @Provide()
@@ -1,13 +1,14 @@
1
- import {Inject, Provide} from '@midwayjs/core';
2
- import {Context} from '@midwayjs/koa';
3
- import {IScheduleService} from '../interface';
4
- import {BaseService} from "./base/BaseService";
5
- import {CurdProService} from "./curd/CurdProService";
6
- import {SystemDbName, SystemDbType, SystemTables} from "../models/SystemTables";
7
- import {KeysOfSimpleSQL} from "../libs/crud-pro/models/keys";
8
- import {FILE_GET_TYPES} from "../models/bizmodels";
9
- import {CommonResult} from "../libs/utils/common-dto";
10
-
1
+ import { Inject, Provide } from '@midwayjs/core';
2
+ import { Context } from '@midwayjs/koa';
3
+ import { IScheduleService } from '@/interface';
4
+ import { BaseService } from './base/BaseService';
5
+ import { CurdProService } from './curd/CurdProService';
6
+ import { SystemTables } from '@/models/SystemTables';
7
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
8
+ import { FILE_GET_TYPES } from '@/models/bizmodels';
9
+ import { CommonResult } from '@/libs/utils/common-dto';
10
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
11
+ import { RedisKeys } from '@/models/RedisKeys';
11
12
 
12
13
  // 3天 的秒数
13
14
  const EXPIRE_TIME = 3 * 24 * 60 * 60;
@@ -18,7 +19,6 @@ const STAT_TYPES = {
18
19
  uv_uid: 'uv_uid',
19
20
  };
20
21
 
21
-
22
22
  @Provide()
23
23
  export class VisitStatService extends BaseService implements IScheduleService {
24
24
  @Inject()
@@ -29,32 +29,32 @@ export class VisitStatService extends BaseService implements IScheduleService {
29
29
 
30
30
  async runBySchedule(): Promise<any> {
31
31
  const hours = new Date().getHours();
32
- this.logInfo("[VisitStatService] runBySchedule called, hours = " + hours);
32
+ this.logInfo('[VisitStatService] runBySchedule called, hours = ' + hours);
33
33
  return this.flushVisitStatToDB();
34
34
  }
35
35
 
36
+ async flushVisitStatToDB(): Promise<any> {
37
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
36
38
 
37
- async flushVisitStatToDB(): Promise<any> {
38
39
  // 统计昨天的数据。
39
40
  const stat_date = new Date(Date.now() - 24 * 3600 * 1000).toISOString().split('T')[0];
40
41
 
41
- const lockKey = `vs_lock_${stat_date}`;
42
+ const lockKey = `${RedisKeys.VISIT_STAT_LOCK_PREFIX}${stat_date}`;
42
43
  // 每天只能执行一次
43
44
  const client = this.redisService;
44
- const nxRes = await client.set(lockKey, 1, 'EX', EXPIRE_TIME, 'NX')
45
+ const nxRes = await client.set(lockKey, 1, 'EX', EXPIRE_TIME, 'NX');
45
46
  if (nxRes !== 'OK') {
46
- this.logInfo("[VisitStatService] flushVisitStatToDB 每天只能执行一次 ");
47
- return CommonResult.errorRes("每天只能执行一次")
47
+ this.logInfo('[VisitStatService] flushVisitStatToDB 每天只能执行一次 ');
48
+ return CommonResult.errorRes('每天只能执行一次');
48
49
  }
49
50
 
50
- this.logInfo("[VisitStatService] flushVisitStatToDB start ");
51
+ this.logInfo('[VisitStatService] flushVisitStatToDB start ');
51
52
 
52
- let totalCount = 0 ;
53
+ let totalCount = 0;
53
54
  let successCount = 0;
54
55
 
55
56
  try {
56
-
57
- const keys = await client.keys(`vs_${stat_date}::*`);
57
+ const keys = await client.keys(`${RedisKeys.VISIT_STAT_DATE_PREFIX}${stat_date}::*`);
58
58
  // `vs_${date}::${req_host}::${resource_type}::${stat_type}::${resource}`;
59
59
  totalCount = keys.length;
60
60
 
@@ -68,112 +68,99 @@ export class VisitStatService extends BaseService implements IScheduleService {
68
68
  const stat_resource = parts[4];
69
69
 
70
70
  let stat_count: number;
71
- if (stat_type === STAT_TYPES.uv_ip || stat_type == STAT_TYPES.uv_uid) {
71
+ if (stat_type === STAT_TYPES.uv_ip || stat_type === STAT_TYPES.uv_uid) {
72
72
  stat_count = await client.scard(key);
73
73
  } else {
74
74
  stat_count = parseInt(await client.get(key)) || 0;
75
75
  }
76
76
 
77
- await this.curdProService.executeCrudByCfg({
78
- data: {
79
- stat_date,
80
- stat_resource,
81
- stat_type,
82
- resource_type,
83
- stat_count,
84
- req_host
77
+ await this.curdProService.executeCrudByCfg(
78
+ {
79
+ data: {
80
+ stat_date,
81
+ stat_resource,
82
+ stat_type,
83
+ resource_type,
84
+ stat_count,
85
+ req_host,
86
+ },
87
+ },
88
+ {
89
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
90
+ sqlDatabase: SystemDbName,
91
+ sqlDbType: SystemDbType,
92
+ sqlTable: SystemTables.sys_visit_stats,
85
93
  }
86
- }, {
87
- sqlSimpleName: KeysOfSimpleSQL.SIMPLE_INSERT,
88
- sqlDatabase: SystemDbName,
89
- sqlDdType: SystemDbType,
90
- sqlTable: SystemTables.sys_visit_stats,
91
- })
94
+ );
92
95
 
93
96
  await client.del(key);
94
97
  successCount++;
95
98
  }
96
- } catch (e){
99
+ } catch (e) {
97
100
  this.logError('[VisitStatService] flushVisitStatToDB: key = ' + key, e);
98
101
  console.log('[VisitStatService] flushVisitStatToDB: key = ' + key, e);
99
102
  }
100
103
  }
101
104
  } catch (error) {
102
- this.logError('[VisitStatService] flushVisitStatToDB' , error);
103
- console.log('[VisitStatService] flushVisitStatToDB' , error);
105
+ this.logError('[VisitStatService] flushVisitStatToDB', error);
106
+ console.log('[VisitStatService] flushVisitStatToDB', error);
104
107
  }
105
108
 
106
- this.logInfo("[VisitStatService] flushVisitStatToDB end ");
109
+ this.logInfo('[VisitStatService] flushVisitStatToDB end ');
107
110
 
108
- return CommonResult.successRes({successCount, totalCount})
111
+ return CommonResult.successRes({ successCount, totalCount });
109
112
  }
110
113
 
111
-
112
114
  /**
113
115
  * 统计请求数据
114
116
  */
115
117
  async trackRequest(resource: string, resourceType: string) {
116
-
117
118
  // 文件下载定制
118
119
  if (resource.startsWith('/ns/gw/file/get/')) {
119
120
  for (let i = 0; i < FILE_GET_TYPES.length; i++) {
120
121
  const fileGetType = FILE_GET_TYPES[i];
121
- const pathPrefix = `/ns/gw/file/get/${fileGetType}/`
122
+ const pathPrefix = `/ns/gw/file/get/${fileGetType}/`;
122
123
  if (resource.startsWith(pathPrefix)) {
123
124
  const res2 = resource.substring(pathPrefix.length);
124
- return this.trackRequestImpl(res2, fileGetType)
125
+ return this.trackRequestImpl(res2, fileGetType);
125
126
  }
126
127
  }
127
128
  }
128
129
 
129
130
  // 文档访问定制
130
131
  if (resource.startsWith('/ns/app/doc-editor/libview')) {
131
- const {docLibId,docId} = this.ctx.query || {};
132
- return this.trackRequestImpl(`${docLibId},${docId}`, 'docLibView')
132
+ const { docLibId, docId } = this.ctx.query || {};
133
+ return this.trackRequestImpl(`${docLibId},${docId}`, 'docLibView');
133
134
  }
134
135
 
135
-
136
- return this.trackRequestImpl(resource, resourceType)
136
+ return this.trackRequestImpl(resource, resourceType);
137
137
  }
138
138
 
139
-
140
139
  private async trackRequestImpl(resource: string, resource_type: string) {
141
140
  const client = this.redisService;
142
141
  const ip = this.ctx.headers['x-real-ip'];
143
- const userSession = this.ctx.userSession
144
- const req_host = this.ctx?.request?.host || "null" // 域名
142
+ const userSession = this.ctx.userSession;
143
+ const req_host = this.ctx?.request?.host || 'null'; // 域名
145
144
  const date = new Date().toISOString().split('T')[0];
146
145
 
147
146
  const toDateResourceKey = (stat_type: string): string => {
148
- return `vs_${date}::${req_host}::${resource_type}::${stat_type}::${resource}`;
149
- }
147
+ return `${RedisKeys.VISIT_STAT_DATE_PREFIX}${date}::${req_host}::${resource_type}::${stat_type}::${resource}`;
148
+ };
150
149
 
151
150
  const pv_key = toDateResourceKey(STAT_TYPES.pv);
152
151
  const uv_ip_key = toDateResourceKey(STAT_TYPES.uv_ip);
153
152
  const uv_uid_key = toDateResourceKey(STAT_TYPES.uv_uid);
154
153
 
155
-
156
154
  // 统计 PV
157
- await Promise.all([
158
- client.incr(pv_key),
159
- client.expire(pv_key, EXPIRE_TIME)
160
- ]);
155
+ await Promise.all([client.incr(pv_key), client.expire(pv_key, EXPIRE_TIME)]);
161
156
 
162
157
  // IP 访问 UV
163
- await Promise.all([
164
- client.sadd(uv_ip_key, `${ip}`),
165
- client.expire(uv_ip_key, EXPIRE_TIME)
166
- ]);
158
+ await Promise.all([client.sadd(uv_ip_key, `${ip}`), client.expire(uv_ip_key, EXPIRE_TIME)]);
167
159
 
168
160
  if (userSession && userSession.isLogin()) {
169
161
  const accountId = userSession.getSessionInfo().accountId;
170
162
  // 统计 UV
171
- await Promise.all([
172
- client.sadd(uv_uid_key, accountId),
173
- client.expire(uv_uid_key, EXPIRE_TIME)
174
- ]);
163
+ await Promise.all([client.sadd(uv_uid_key, accountId), client.expire(uv_uid_key, EXPIRE_TIME)]);
175
164
  }
176
-
177
- };
178
-
165
+ }
179
166
  }
@@ -1,7 +1,7 @@
1
1
  import { Inject, Provide } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { KeysOfSimpleSQL } from '../libs/crud-pro/models/keys';
4
- import {SystemDbName, SystemDbType, SystemTables} from '../models/SystemTables';
4
+ import { SystemTables} from '../models/SystemTables';
5
5
  import { BaseService } from './base/BaseService';
6
6
  // import { LRUCache } from 'lru-cache';
7
7
  import { CurdProService } from './curd/CurdProService';
@@ -11,6 +11,7 @@ import { IWorkbenchEntity } from '../models/SystemEntities';
11
11
  import { IScheduleService } from '../interface';
12
12
  import { getDebugWorkbenchCode } from '../libs/utils/fatcms-request';
13
13
  import { MixinUtils } from '../libs/crud-pro/utils/MixinUtils';
14
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
14
15
  //
15
16
  // const lruCache = new LRUCache<string, any>({
16
17
  // max: 500,
@@ -42,6 +43,10 @@ export class WorkbenchService extends BaseService implements IScheduleService {
42
43
  }
43
44
 
44
45
  public async getAllWorkbenchInfoList(isForceRefresh?: boolean): Promise<IWorkbenchEntity[]> {
46
+
47
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
48
+
49
+
45
50
  let listData = lruCache.get(CACHE_KEY_WORKBENCH_LIST);
46
51
  if (!listData || isForceRefresh === true) {
47
52
  const reqJson = { condition: {}, pageSize: 1000, limit: 1000 };
@@ -49,7 +54,7 @@ export class WorkbenchService extends BaseService implements IScheduleService {
49
54
  sqlTable: SystemTables.sys_workbench,
50
55
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY,
51
56
  sqlDatabase: SystemDbName,
52
- sqlDdType: SystemDbType,
57
+ sqlDbType: SystemDbType,
53
58
  });
54
59
  listData = res.getResRows();
55
60
  lruCache.set(CACHE_KEY_WORKBENCH_LIST, listData);
@@ -1,18 +1,19 @@
1
1
  import { Inject, Provide } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
- import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
4
- import {SystemDbName, SystemDbType, SystemTables} from '../../models/SystemTables';
3
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
4
+ import { SystemTables} from '@/models/SystemTables';
5
5
  import { LRUCache } from 'lru-cache';
6
- import { BizException } from '../../models/devops';
6
+ import { BizException } from '@/models/devops';
7
7
  import { CurdMixService } from '../curd/CurdMixService';
8
- import { ISysAnyApiEntity } from '../../models/SystemEntities';
8
+ import { ISysAnyApiEntity } from '@/models/SystemEntities';
9
9
  import { AnyApiSandboxService, IRunInSandboxParams } from './AnyApiSandboxService';
10
- import { parseJsonObject } from '../../libs/utils/functions';
10
+ import { parseJsonObject } from '@/libs/utils/functions';
11
11
  import * as _ from 'lodash';
12
- import { MixinUtils } from '../../libs/crud-pro/utils/MixinUtils';
12
+ import { MixinUtils } from '@/libs/crud-pro/utils/MixinUtils';
13
13
  import { WorkbenchService } from '../WorkbenchService';
14
- import { validateByCfgString } from '../../libs/crud-pro/utils/ValidateUtils';
14
+ import { validateByCfgString } from '@/libs/crud-pro/utils/ValidateUtils';
15
15
  import { API_BASE_TYPE, ApiBaseService } from '../base/ApiBaseService';
16
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
16
17
 
17
18
  const lruCache = new LRUCache<string, any>({
18
19
  max: 500,
@@ -80,6 +81,8 @@ export class AnyApiService extends ApiBaseService {
80
81
  }
81
82
 
82
83
  private async _getAnyApiMethod(methodCode: string): Promise<ISysAnyApiEntity> {
84
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
85
+
83
86
  const res = await this.curdMixService.executeCrudByCfg(
84
87
  { condition: { method: methodCode } },
85
88
  {
@@ -87,7 +90,7 @@ export class AnyApiService extends ApiBaseService {
87
90
  method: `get_sys_anyapi_${methodCode}`,
88
91
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_ONE,
89
92
  sqlDatabase: SystemDbName,
90
- sqlDdType: SystemDbType,
93
+ sqlDbType: SystemDbType,
91
94
  updateCfg: {},
92
95
  }
93
96
  );
@@ -0,0 +1,249 @@
1
+ import { Inject, Provide } from '@midwayjs/core';
2
+ import { Context, IMidwayKoaContext } from '@midwayjs/koa';
3
+ import { BaseService } from '@/service/base/BaseService';
4
+ import { IScheduleService } from '@/interface';
5
+ import { CurdProService } from '@/service/curd/CurdProService';
6
+ import { ISysAsyncTaskHandler, SysAsyncTaskEntity, SysAsyncTaskPartial, SysAsyncTaskStatus } from '@/models/AsyncTaskModel';
7
+ import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
8
+ import { SystemTables } from '@/models/SystemTables';
9
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
10
+ import { errorToString } from '@/libs/utils/errorToString';
11
+ import { ANONYMOUS_CONTEXT } from '@/schedule';
12
+ import { RedisKeys } from '@/models/RedisKeys';
13
+
14
+ const END_STATUS_LIST = [SysAsyncTaskStatus.SUCCEEDED, SysAsyncTaskStatus.FAILED, SysAsyncTaskStatus.PART_SUCCEEDED];
15
+
16
+ class AsyncTaskRunner {
17
+ isBusy = false;
18
+ taskHandlerMap: Map<string, ISysAsyncTaskHandler> = new Map();
19
+
20
+ async executeTaskList(taskList: SysAsyncTaskEntity[]) {
21
+ if (!taskList || taskList.length === 0) {
22
+ return;
23
+ }
24
+
25
+ this.isBusy = true;
26
+
27
+ for (let i = 0; i < taskList.length; i++) {
28
+ const taskElement = taskList[i];
29
+ taskElement.task_status = SysAsyncTaskStatus.RUNNING;
30
+
31
+ try {
32
+ // 任务状态的设置在自定义的执行器里面。
33
+ await this.executeTask(taskElement);
34
+
35
+ // 当前不是终止状态,并且没有异常就设置成成功。
36
+ if (!END_STATUS_LIST.includes(taskElement.task_status)) {
37
+ taskElement.task_status = SysAsyncTaskStatus.SUCCEEDED;
38
+ }
39
+
40
+ } catch (error) {
41
+ taskElement.task_status = SysAsyncTaskStatus.FAILED;
42
+ taskElement.error_message = errorToString(error);
43
+ }
44
+
45
+ try {
46
+ await this.updateTaskStatus(taskElement, {
47
+ task_status: taskElement.task_status,
48
+ error_message: taskElement.error_message,
49
+ });
50
+ } catch (error) {
51
+ ANONYMOUS_CONTEXT.getApp().getCoreLogger().error('executeTaskList error', error);
52
+ }
53
+ }
54
+
55
+ this.isBusy = false;
56
+ }
57
+
58
+ private async executeTask(taskElement: SysAsyncTaskEntity) {
59
+ const taskType = taskElement.task_type;
60
+ const taskHandler = this.taskHandlerMap.get(taskType);
61
+ if (!taskHandler) {
62
+ throw new Error('TaskHandler not found , taskType = ' + taskType);
63
+ }
64
+ const updateTaskStatus = (updatePartials: SysAsyncTaskPartial) => {
65
+ return this.updateTaskStatus(taskElement, updatePartials);
66
+ };
67
+ await taskHandler.execute({ task: taskElement, updateTaskStatus });
68
+ }
69
+
70
+ /**
71
+ * 更新任务状态或任务进度
72
+ * @param taskElement
73
+ * @param updatePartials
74
+ * @private
75
+ */
76
+ private async updateTaskStatus(taskElement: SysAsyncTaskEntity, updatePartials: SysAsyncTaskPartial) {
77
+ if (!updatePartials) {
78
+ throw new Error('updatePartials not found');
79
+ }
80
+ return await ANONYMOUS_CONTEXT.runServiceAtAnonymousContext(async (ctx: IMidwayKoaContext) => {
81
+ const curdProService: CurdProService = await ctx.requestContext.getAsync('curdProService');
82
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
83
+
84
+ const res = await curdProService.executeCrudByCfg(
85
+ {
86
+ condition: {
87
+ id: taskElement.id,
88
+ },
89
+ data: updatePartials,
90
+ },
91
+ {
92
+ sqlTable: SystemTables.sys_async_tasks,
93
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
94
+ sqlDatabase: SystemDbName,
95
+ sqlDbType: SystemDbType,
96
+ }
97
+ );
98
+ return res.getResModel().affected;
99
+ });
100
+ }
101
+
102
+ /**
103
+ * 获取当前进程可以处理的任务类型。
104
+ */
105
+ public getHandlerTaskTypeList(): string[] {
106
+ const keys = this.taskHandlerMap.keys();
107
+ return [...keys];
108
+ }
109
+ }
110
+
111
+ /**
112
+ * 业务可以扩展
113
+ */
114
+ export const ASYNC_TASK_RUNNER = new AsyncTaskRunner();
115
+
116
+ /**
117
+ * Redis锁
118
+ */
119
+ const ASYNC_TASK_LOCK = RedisKeys.ASYNC_TASK_LOCK;
120
+
121
+ const ASYNC_TASK_RUNTIME_OBJ = {
122
+ LAST_CHECK_ASYNC_TASK_UPDATE_TIME: 0,
123
+ };
124
+
125
+ @Provide()
126
+ export class AsyncTaskRunnerService extends BaseService implements IScheduleService {
127
+ @Inject()
128
+ protected ctx: Context;
129
+
130
+ @Inject()
131
+ private curdProService: CurdProService;
132
+
133
+ async fetchPendingTasks(): Promise<void> {
134
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
135
+
136
+ // 只获取本进程能够处理的任务类型。
137
+ const taskTypeList = ASYNC_TASK_RUNNER.getHandlerTaskTypeList();
138
+ if (taskTypeList.length === 0) {
139
+ return Promise.resolve();
140
+ }
141
+
142
+ // 查询等待处理的任务。
143
+ const queryRes = await this.curdProService.executeCrudByCfg(
144
+ {
145
+ condition: {
146
+ task_status: SysAsyncTaskStatus.PENDING,
147
+ task_type: {
148
+ $in: taskTypeList,
149
+ },
150
+ },
151
+ orderBy: 'id+',
152
+ limit: 10,
153
+ },
154
+ {
155
+ sqlTable: SystemTables.sys_async_tasks,
156
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_QUERY_PAGE,
157
+ sqlDatabase: SystemDbName,
158
+ sqlDbType: SystemDbType,
159
+ }
160
+ );
161
+
162
+ const taskList = queryRes.getResRows();
163
+
164
+ if (taskList.length === 0) {
165
+ return Promise.resolve();
166
+ }
167
+ const taskIds = taskList.map(elem => elem.id).filter(Boolean);
168
+
169
+ // 将状态更新为处理中。防止其它进程重复处理。
170
+ await this.curdProService.executeCrudByCfg(
171
+ {
172
+ condition: {
173
+ id: {
174
+ $in: taskIds,
175
+ },
176
+ },
177
+ data: {
178
+ task_status: SysAsyncTaskStatus.RUNNING,
179
+ },
180
+ },
181
+ {
182
+ sqlTable: SystemTables.sys_async_tasks,
183
+ sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
184
+ sqlDatabase: SystemDbName,
185
+ sqlDbType: SystemDbType,
186
+ }
187
+ );
188
+
189
+ // 开始执行。
190
+ ASYNC_TASK_RUNNER.executeTaskList(taskList).then(() => {
191
+ console.log('ASYNC_TASK_RUNNER finished taskIds ==> ' + JSON.stringify(taskIds));
192
+ });
193
+ }
194
+
195
+ async runBySchedule() {
196
+ // 1. 当前很忙
197
+ if (ASYNC_TASK_RUNNER.isBusy) {
198
+ return Promise.resolve();
199
+ }
200
+
201
+ // 2. 发现了新任务
202
+ const isExistNewTask = await this.isExistNewTask();
203
+ if (!isExistNewTask) {
204
+ return Promise.resolve();
205
+ }
206
+
207
+ // 这里的过期时间1分钟即可。fetchPendingTasks函数不可能超过一分钟。
208
+ // 因为这里只是从数据库中获取一批任务,放到自己的任务队列里。还没触发执行。
209
+ const lock = await this.redisService.set(ASYNC_TASK_LOCK, 1, 'EX', 60, 'NX');
210
+ if (lock !== 'OK') {
211
+ return Promise.resolve();
212
+ }
213
+
214
+ try {
215
+ await this.fetchPendingTasks();
216
+ } catch (e) {
217
+ console.error('fetchPendingTasks error', errorToString(e));
218
+ }
219
+
220
+ await this.redisService.del(ASYNC_TASK_LOCK);
221
+
222
+ return Promise.resolve();
223
+ }
224
+
225
+ /**
226
+ * 是否存在新任务
227
+ * @private
228
+ */
229
+ private async isExistNewTask(): Promise<boolean> {
230
+ // 刚启动,没有检查过。
231
+ if (!ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME) {
232
+ ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME = Date.now();
233
+ return true;
234
+ }
235
+
236
+ //Redis没有任何内容
237
+ const updateTime = await this.redisService.get(RedisKeys.ASYNC_TASK_UPDATE_TIME);
238
+ if (!updateTime) {
239
+ ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME = Date.now();
240
+ return false;
241
+ }
242
+
243
+ const updateTimeNumber = Number.parseInt(updateTime, 10);
244
+
245
+ const isExistNewTask: boolean = updateTimeNumber > ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME;
246
+ ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME = updateTimeNumber;
247
+ return isExistNewTask;
248
+ }
249
+ }