midway-fatcms 0.0.1-beta.17 → 0.0.1-beta.19

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 (131) hide show
  1. package/.eslintrc.json +3 -1
  2. package/dist/configuration.js +18 -7
  3. package/dist/controller/gateway/AsyncTaskController.js +3 -3
  4. package/dist/controller/gateway/DocGatewayController.js +1 -1
  5. package/dist/controller/gateway/PublicApiController.js +4 -6
  6. package/dist/controller/gateway/StaticController.js +25 -22
  7. package/dist/controller/helpers.controller.d.ts +1 -1
  8. package/dist/controller/manage/CrudStandardDesignApi.d.ts +1 -1
  9. package/dist/controller/manage/CrudStandardDesignApi.js +4 -16
  10. package/dist/controller/manage/DataDictManageApi.d.ts +1 -1
  11. package/dist/controller/manage/DeployManageApi.d.ts +1 -1
  12. package/dist/controller/manage/DeployManageApi.js +32 -30
  13. package/dist/controller/manage/MenuManageApi.js +1 -1
  14. package/dist/controller/manage/SuperAdminManageApi.d.ts +2 -2
  15. package/dist/controller/manage/SysConfigMangeApi.d.ts +1 -1
  16. package/dist/controller/manage/SysConfigMangeApi.js +3 -3
  17. package/dist/controller/manage/SystemInfoManageApi.d.ts +1 -1
  18. package/dist/controller/manage/SystemInfoManageApi.js +7 -1
  19. package/dist/controller/manage/UserAccountManageApi.d.ts +1 -1
  20. package/dist/controller/manage/WorkbenchMangeApi.js +1 -1
  21. package/dist/controller/myinfo/AuthController.js +1 -1
  22. package/dist/controller/render/AppRenderController.js +6 -2
  23. package/dist/controller/test.controller.d.ts +1 -1
  24. package/dist/controller/test.controller.js +4 -4
  25. package/dist/libs/crud-pro/models/ExecuteContext.d.ts +1 -1
  26. package/dist/libs/crud-pro/models/TransactionSqlServer.js +1 -1
  27. package/dist/libs/crud-pro/services/CrudProCachedCfgService.js +1 -1
  28. package/dist/libs/crud-pro/services/CrudProExecuteSqlService.js +7 -6
  29. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.d.ts +1 -1
  30. package/dist/libs/crud-pro/services/CrudProGenSqlCondition.js +2 -4
  31. package/dist/libs/crud-pro/services/CrudProGenSqlService.js +6 -15
  32. package/dist/libs/crud-pro/services/CrudProOriginToExecuteSql.js +5 -4
  33. package/dist/libs/crud-pro/services/CrudProTableMetaService.js +2 -2
  34. package/dist/libs/crud-pro/utils/MixinUtils.js +1 -1
  35. package/dist/libs/crud-pro/utils/ValidateUtils.js +1 -1
  36. package/dist/libs/utils/fatcms-request.js +2 -2
  37. package/dist/middleware/forbidden.middleware.js +4 -20
  38. package/dist/middleware/global.middleware.js +1 -4
  39. package/dist/models/AsyncTaskModel.d.ts +2 -1
  40. package/dist/models/RedisKeys.d.ts +8 -0
  41. package/dist/models/RedisKeys.js +11 -0
  42. package/dist/schedule/index.d.ts +3 -3
  43. package/dist/schedule/index.js +3 -4
  44. package/dist/schedule/runSchedule.d.ts +11 -2
  45. package/dist/schedule/runSchedule.js +49 -15
  46. package/dist/schedule/scheduleNames.d.ts +8 -3
  47. package/dist/schedule/scheduleNames.js +12 -12
  48. package/dist/service/UserSessionService.js +2 -1
  49. package/dist/service/VisitStatService.d.ts +1 -1
  50. package/dist/service/VisitStatService.js +16 -25
  51. package/dist/service/asyncTask/AsyncTaskRunnerService.d.ts +9 -3
  52. package/dist/service/asyncTask/AsyncTaskRunnerService.js +57 -21
  53. package/dist/service/asyncTask/AsyncTaskService.d.ts +1 -1
  54. package/dist/service/asyncTask/AsyncTaskService.js +4 -3
  55. package/package.json +1 -1
  56. package/src/configuration.ts +23 -11
  57. package/src/controller/base/BaseApiController.ts +6 -6
  58. package/src/controller/gateway/AsyncTaskController.ts +17 -22
  59. package/src/controller/gateway/CrudMtdGatewayController.ts +7 -7
  60. package/src/controller/gateway/CrudStdGatewayController.ts +4 -4
  61. package/src/controller/gateway/DocGatewayController.ts +17 -17
  62. package/src/controller/gateway/FileController.ts +8 -9
  63. package/src/controller/gateway/ProxyApiGatewayController.ts +4 -4
  64. package/src/controller/gateway/PublicApiController.ts +19 -22
  65. package/src/controller/gateway/StaticController.ts +234 -264
  66. package/src/controller/helpers.controller.ts +1 -1
  67. package/src/controller/home.controller.ts +0 -5
  68. package/src/controller/manage/AnyApiMangeApi.ts +4 -4
  69. package/src/controller/manage/AppLogMangeApi.ts +3 -3
  70. package/src/controller/manage/AppMangeApi.ts +5 -5
  71. package/src/controller/manage/AppPageMangeApi.ts +3 -3
  72. package/src/controller/manage/AppSchemaHistoryApi.ts +1 -1
  73. package/src/controller/manage/CrudMethodsMangeApi.ts +3 -3
  74. package/src/controller/manage/CrudStandardDesignApi.ts +25 -77
  75. package/src/controller/manage/DataDictManageApi.ts +4 -4
  76. package/src/controller/manage/DeployManageApi.ts +84 -91
  77. package/src/controller/manage/DocLibManageApi.ts +3 -3
  78. package/src/controller/manage/DocManageApi.ts +3 -3
  79. package/src/controller/manage/MenuManageApi.ts +9 -14
  80. package/src/controller/manage/SuperAdminManageApi.ts +2 -10
  81. package/src/controller/manage/SysConfigMangeApi.ts +8 -11
  82. package/src/controller/manage/SystemInfoManageApi.ts +11 -6
  83. package/src/controller/manage/UserAccountManageApi.ts +2 -2
  84. package/src/controller/manage/WorkbenchMangeApi.ts +6 -6
  85. package/src/controller/myinfo/AuthController.ts +4 -8
  86. package/src/controller/render/AppRenderController.ts +8 -8
  87. package/src/controller/test.controller.ts +17 -17
  88. package/src/index.ts +0 -1
  89. package/src/libs/crud-pro/CrudPro.ts +0 -1
  90. package/src/libs/crud-pro/interfaces.ts +1 -3
  91. package/src/libs/crud-pro/models/ExecuteContext.ts +1 -4
  92. package/src/libs/crud-pro/models/ExecuteContextFunc.ts +1 -2
  93. package/src/libs/crud-pro/models/RequestModel.ts +1 -1
  94. package/src/libs/crud-pro/models/ResModel.ts +7 -12
  95. package/src/libs/crud-pro/models/SqlCfgModel.ts +1 -1
  96. package/src/libs/crud-pro/models/Transaction.ts +8 -9
  97. package/src/libs/crud-pro/models/TransactionPostgres.ts +1 -1
  98. package/src/libs/crud-pro/models/TransactionSqlServer.ts +8 -13
  99. package/src/libs/crud-pro/services/CrudProCachedCfgService.ts +1 -3
  100. package/src/libs/crud-pro/services/CrudProExecuteSqlService.ts +36 -48
  101. package/src/libs/crud-pro/services/CrudProGenSqlCondition.ts +19 -38
  102. package/src/libs/crud-pro/services/CrudProGenSqlService.ts +15 -32
  103. package/src/libs/crud-pro/services/CrudProOriginToExecuteSql.ts +23 -27
  104. package/src/libs/crud-pro/services/CrudProServiceBase.ts +1 -2
  105. package/src/libs/crud-pro/services/CrudProTableMetaService.ts +6 -14
  106. package/src/libs/crud-pro/utils/DateTimeUtils.ts +2 -2
  107. package/src/libs/crud-pro/utils/MixinUtils.ts +1 -1
  108. package/src/libs/crud-pro/utils/ValidateUtils.ts +1 -3
  109. package/src/libs/crud-pro/utils/pool/MySQLUtils.ts +1 -1
  110. package/src/libs/crud-pro/utils/pool/PostgresUtils.ts +3 -3
  111. package/src/libs/crud-pro/utils/pool/SqlServerUtils.ts +3 -3
  112. package/src/libs/global-config/global-config.ts +0 -5
  113. package/src/libs/utils/crypto-utils.ts +2 -4
  114. package/src/libs/utils/errorToString.ts +3 -8
  115. package/src/libs/utils/fatcms-request.ts +9 -21
  116. package/src/libs/utils/ordernum-utils.ts +2 -6
  117. package/src/libs/utils/parseConfig.ts +7 -15
  118. package/src/middleware/forbidden.middleware.ts +6 -25
  119. package/src/middleware/global.middleware.ts +10 -21
  120. package/src/models/AsyncTaskModel.ts +3 -2
  121. package/src/models/RedisKeys.ts +13 -0
  122. package/src/models/bizmodels.ts +1 -2
  123. package/src/schedule/index.ts +4 -6
  124. package/src/schedule/runSchedule.ts +65 -17
  125. package/src/schedule/scheduleNames.ts +12 -11
  126. package/src/service/UserSessionService.ts +5 -4
  127. package/src/service/VisitStatService.ts +55 -72
  128. package/src/service/anyapi/AnyApiService.ts +7 -7
  129. package/src/service/asyncTask/AsyncTaskRunnerService.ts +118 -87
  130. package/src/service/asyncTask/AsyncTaskService.ts +10 -10
  131. package/src/service/proxyapi/ProxyApiLoadService.ts +4 -3
@@ -19,6 +19,7 @@ const SystemTables_1 = require("../../models/SystemTables");
19
19
  const keys_1 = require("../../libs/crud-pro/models/keys");
20
20
  const errorToString_1 = require("../../libs/utils/errorToString");
21
21
  const schedule_1 = require("../../schedule");
22
+ const RedisKeys_1 = require("../../models/RedisKeys");
22
23
  class AsyncTaskRunner {
23
24
  constructor() {
24
25
  this.isBusy = false;
@@ -40,10 +41,13 @@ class AsyncTaskRunner {
40
41
  taskElement.error_message = (0, errorToString_1.errorToString)(error);
41
42
  }
42
43
  try {
43
- await this.updateTaskStatus(taskElement);
44
+ await this.updateTaskStatus(taskElement, {
45
+ task_status: taskElement.task_status,
46
+ error_message: taskElement.error_message,
47
+ });
44
48
  }
45
49
  catch (error) {
46
- schedule_1.ANONYMOUS_CONTEXT.getApp().getCoreLogger().error("executeTaskList error", error);
50
+ schedule_1.ANONYMOUS_CONTEXT.getApp().getCoreLogger().error('executeTaskList error', error);
47
51
  }
48
52
  }
49
53
  this.isBusy = false;
@@ -54,26 +58,29 @@ class AsyncTaskRunner {
54
58
  if (!taskHandler) {
55
59
  throw new Error('TaskHandler not found , taskType = ' + taskType);
56
60
  }
57
- const updateTaskStatus = () => {
58
- return this.updateTaskStatus(taskElement);
61
+ const updateTaskStatus = (updatePartials) => {
62
+ return this.updateTaskStatus(taskElement, updatePartials);
59
63
  };
60
64
  await taskHandler.execute({ task: taskElement, updateTaskStatus });
61
65
  }
62
66
  /**
63
67
  * 更新任务状态或任务进度
64
68
  * @param taskElement
69
+ * @param updatePartials
65
70
  * @private
66
71
  */
67
- async updateTaskStatus(taskElement) {
72
+ async updateTaskStatus(taskElement, updatePartials) {
73
+ if (!updatePartials) {
74
+ throw new Error('updatePartials not found');
75
+ }
68
76
  return await schedule_1.ANONYMOUS_CONTEXT.runServiceAtAnonymousContext(async (ctx) => {
69
- const curdProService = await ctx.requestContext.getAsync("curdProService");
77
+ const curdProService = await ctx.requestContext.getAsync('curdProService');
70
78
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
71
- const { id, ...otherTaskProps } = taskElement;
72
79
  const res = await curdProService.executeCrudByCfg({
73
80
  condition: {
74
- id: id
81
+ id: taskElement.id,
75
82
  },
76
- data: otherTaskProps
83
+ data: updatePartials,
77
84
  }, {
78
85
  sqlTable: SystemTables_1.SystemTables.sys_async_tasks,
79
86
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
@@ -98,7 +105,10 @@ exports.ASYNC_TASK_RUNNER = new AsyncTaskRunner();
98
105
  /**
99
106
  * Redis锁
100
107
  */
101
- const LOCK_KEY_ASYNC_TASK_RUNNER = "LOCK_KEY_ASYNC_TASK_RUNNER";
108
+ const ASYNC_TASK_LOCK = RedisKeys_1.RedisKeys.ASYNC_TASK_LOCK;
109
+ const ASYNC_TASK_RUNTIME_OBJ = {
110
+ LAST_CHECK_ASYNC_TASK_UPDATE_TIME: 0,
111
+ };
102
112
  let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.BaseService {
103
113
  async fetchPendingTasks() {
104
114
  const { SystemDbName, SystemDbType } = global_config_1.GLOBAL_STATIC_CONFIG.getConfig();
@@ -112,11 +122,11 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
112
122
  condition: {
113
123
  task_status: AsyncTaskModel_1.SysAsyncTaskStatus.PENDING,
114
124
  task_type: {
115
- "$in": taskTypeList
116
- }
125
+ $in: taskTypeList,
126
+ },
117
127
  },
118
128
  orderBy: 'id+',
119
- limit: 10
129
+ limit: 10,
120
130
  }, {
121
131
  sqlTable: SystemTables_1.SystemTables.sys_async_tasks,
122
132
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_QUERY_PAGE,
@@ -132,12 +142,12 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
132
142
  await this.curdProService.executeCrudByCfg({
133
143
  condition: {
134
144
  id: {
135
- "$in": taskIds
136
- }
145
+ $in: taskIds,
146
+ },
137
147
  },
138
148
  data: {
139
- task_status: AsyncTaskModel_1.SysAsyncTaskStatus.RUNNING
140
- }
149
+ task_status: AsyncTaskModel_1.SysAsyncTaskStatus.RUNNING,
150
+ },
141
151
  }, {
142
152
  sqlTable: SystemTables_1.SystemTables.sys_async_tasks,
143
153
  sqlSimpleName: keys_1.KeysOfSimpleSQL.SIMPLE_UPDATE,
@@ -146,16 +156,22 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
146
156
  });
147
157
  // 开始执行。
148
158
  exports.ASYNC_TASK_RUNNER.executeTaskList(taskList).then(() => {
149
- console.log("ASYNC_TASK_RUNNER finished taskIds ==> " + JSON.stringify(taskIds));
159
+ console.log('ASYNC_TASK_RUNNER finished taskIds ==> ' + JSON.stringify(taskIds));
150
160
  });
151
161
  }
152
162
  async runBySchedule() {
163
+ // 1. 当前很忙
153
164
  if (exports.ASYNC_TASK_RUNNER.isBusy) {
154
165
  return Promise.resolve();
155
166
  }
167
+ // 2. 发现了新任务
168
+ const isExistNewTask = await this.isExistNewTask();
169
+ if (!isExistNewTask) {
170
+ return Promise.resolve();
171
+ }
156
172
  // 这里的过期时间1分钟即可。fetchPendingTasks函数不可能超过一分钟。
157
173
  // 因为这里只是从数据库中获取一批任务,放到自己的任务队列里。还没触发执行。
158
- const lock = await this.redisService.set(LOCK_KEY_ASYNC_TASK_RUNNER, 1, "EX", 60, "NX");
174
+ const lock = await this.redisService.set(ASYNC_TASK_LOCK, 1, 'EX', 60, 'NX');
159
175
  if (lock !== 'OK') {
160
176
  return Promise.resolve();
161
177
  }
@@ -163,11 +179,31 @@ let AsyncTaskRunnerService = class AsyncTaskRunnerService extends BaseService_1.
163
179
  await this.fetchPendingTasks();
164
180
  }
165
181
  catch (e) {
166
- console.error("fetchPendingTasks error", (0, errorToString_1.errorToString)(e));
182
+ console.error('fetchPendingTasks error', (0, errorToString_1.errorToString)(e));
167
183
  }
168
- await this.redisService.del(LOCK_KEY_ASYNC_TASK_RUNNER);
184
+ await this.redisService.del(ASYNC_TASK_LOCK);
169
185
  return Promise.resolve();
170
186
  }
187
+ /**
188
+ * 是否存在新任务
189
+ * @private
190
+ */
191
+ async isExistNewTask() {
192
+ // 刚启动,没有检查过。
193
+ if (!ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME) {
194
+ return true;
195
+ }
196
+ //Redis没有任何内容
197
+ const updateTime = await this.redisService.get(RedisKeys_1.RedisKeys.ASYNC_TASK_UPDATE_TIME);
198
+ if (!updateTime) {
199
+ ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME = Date.now();
200
+ return false;
201
+ }
202
+ const updateTimeNumber = Number.parseInt(updateTime, 10);
203
+ const isExistNewTask = updateTimeNumber > ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME;
204
+ ASYNC_TASK_RUNTIME_OBJ.LAST_CHECK_ASYNC_TASK_UPDATE_TIME = updateTimeNumber;
205
+ return isExistNewTask;
206
+ }
171
207
  };
172
208
  __decorate([
173
209
  (0, core_1.Inject)(),
@@ -1,5 +1,5 @@
1
1
  import { Context } from '@midwayjs/koa';
2
- import { BaseService } from "../../service/base/BaseService";
2
+ import { BaseService } from '../../service/base/BaseService';
3
3
  export declare class AsyncTaskService extends BaseService {
4
4
  protected ctx: Context;
5
5
  startTask(): Promise<void>;
@@ -14,14 +14,15 @@ const core_1 = require("@midwayjs/core");
14
14
  const BaseService_1 = require("../../service/base/BaseService");
15
15
  const schedule_1 = require("../../schedule");
16
16
  const scheduleNames_1 = require("../../schedule/scheduleNames");
17
+ const RedisKeys_1 = require("../../models/RedisKeys");
17
18
  let AsyncTaskService = class AsyncTaskService extends BaseService_1.BaseService {
18
19
  async startTask() {
19
- (0, schedule_1.runScheduleTaskOnce)(scheduleNames_1.SCHEDULE_NAMES.asyncTaskRunnerService).then(schedule => {
20
+ await this.redisService.set(RedisKeys_1.RedisKeys.ASYNC_TASK_UPDATE_TIME, `${Date.now()}`);
21
+ (0, schedule_1.runScheduleTaskOnce)(scheduleNames_1.INNER_SCHEDULE_NAMES.asyncTaskRunnerService).then(schedule => {
20
22
  console.log(schedule);
21
23
  });
22
24
  }
23
- async cancelTask(id) {
24
- }
25
+ async cancelTask(id) { }
25
26
  };
26
27
  __decorate([
27
28
  (0, core_1.Inject)(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midway-fatcms",
3
- "version": "0.0.1-beta.17",
3
+ "version": "0.0.1-beta.19",
4
4
  "description": "This is a midway component sample",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -13,9 +13,8 @@ import { join } from 'path';
13
13
  // import { NotFoundFilter } from './filter/notfound.filter';
14
14
  import { GlobalMiddleware } from './middleware/global.middleware';
15
15
  import { ForbiddenMiddleware } from './middleware/forbidden.middleware';
16
- import { startScheduleLoop } from './schedule';
16
+ import { SCHEDULE_QUEUE , ANONYMOUS_CONTEXT, INNER_SCHEDULE_INTERVAL } from './schedule';
17
17
  import { privateAES } from './libs/utils/crypto-utils';
18
- import { ALL_SCHEDULE_NAMES } from "@/schedule/scheduleNames";
19
18
 
20
19
  @Configuration({
21
20
  // namespace: 'fatcms',
@@ -65,6 +64,11 @@ export class ContainerLifeCycle {
65
64
 
66
65
  async onReady() {
67
66
 
67
+ /**
68
+ * 让ANONYMOUS_CONTEXT获取app对象
69
+ */
70
+ ANONYMOUS_CONTEXT.setApp(this.app);
71
+
68
72
  /**
69
73
  * 启动定时任务
70
74
  */
@@ -78,25 +82,33 @@ export class ContainerLifeCycle {
78
82
  // this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
79
83
  }
80
84
 
81
- private async startScheduleOnReady(){
85
+ private async startScheduleOnReady() {
82
86
  const logger = this.app.getLogger();
83
87
  const config = this.app.getConfig();
84
- const fatcmsScheduleService: boolean | string[] = config.fatcmsScheduleService;
88
+ const fatcmsScheduleService: boolean | any = config.fatcmsScheduleService;
85
89
 
86
90
  // 关闭定时任务
87
91
  if (fatcmsScheduleService === false || fatcmsScheduleService === null) {
88
92
  return;
89
93
  }
90
94
 
95
+ let scheduleIntervalCfg = INNER_SCHEDULE_INTERVAL;
96
+ if (typeof fatcmsScheduleService === "object") {
97
+ scheduleIntervalCfg = fatcmsScheduleService
98
+ }
91
99
 
92
- let scheduleServiceList = ALL_SCHEDULE_NAMES
93
-
94
- // 启动部分定时任务
95
- if (Array.isArray(fatcmsScheduleService)){
96
- scheduleServiceList = fatcmsScheduleService;
100
+ const keys = Object.keys(scheduleIntervalCfg);
101
+ for (let i = 0; i < keys.length; i++) {
102
+ const service = keys[i];
103
+ const interval = scheduleIntervalCfg[service];
104
+ if (typeof interval !== "number") {
105
+ throw new Error('Invalid scheduleIntervalCfg ' + service + ", interval must be a number");
106
+ }
107
+ SCHEDULE_QUEUE.setScheduleTask(service, interval);
97
108
  }
98
- await startScheduleLoop(scheduleServiceList);
99
- logger.info('ContainerLifeCycle ==> onReady 启动定时任务 : ' + JSON.stringify(scheduleServiceList) );
109
+
110
+ await SCHEDULE_QUEUE.startScheduleLoop();
111
+ logger.info('ContainerLifeCycle ==> onReady 启动定时任务 : ' + JSON.stringify(scheduleIntervalCfg));
100
112
  }
101
113
 
102
114
 
@@ -1,12 +1,12 @@
1
1
  import { Controller, Inject } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
- import { CurdMixService } from '../../service/curd/CurdMixService';
4
- import { IFuncCfgModel, IRequestCfgModel, IValidatorCfgItem } from '../../libs/crud-pro/interfaces';
5
- import { KeyOfCrudTypes, KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
3
+ import { CurdMixService } from '@/service/curd/CurdMixService';
4
+ import { IFuncCfgModel, IRequestCfgModel, IValidatorCfgItem } from '@/libs/crud-pro/interfaces';
5
+ import { KeyOfCrudTypes, KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
6
6
  import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
7
- import { UserAccountService } from '../../service/UserAccountService';
8
- import { RelatedType } from '../../service/curd/CurdMixUtils';
9
- import { BaseService } from '../../service/base/BaseService';
7
+ import { UserAccountService } from '@/service/UserAccountService';
8
+ import { RelatedType } from '@/service/curd/CurdMixUtils';
9
+ import { BaseService } from '@/service/base/BaseService';
10
10
 
11
11
  export interface IExecuteSimpleSqlParams {
12
12
  updateCfg?: Record<string, IFuncCfgModel>;
@@ -2,31 +2,29 @@ import { Controller, Inject, Post, Query } from '@midwayjs/core';
2
2
 
3
3
  import { Context } from '@midwayjs/koa';
4
4
  import { BaseApiController } from '../base/BaseApiController';
5
- import {AsyncTaskService} from "@/service/asyncTask/AsyncTaskService";
6
- import {SysAsyncTaskEntity, SysAsyncTaskStatus} from "@/models/AsyncTaskModel";
7
- import {KeysOfSimpleSQL} from "@/libs/crud-pro/models/keys";
8
- import {SystemTables} from "@/models/SystemTables";
9
- import {CommonException} from "@/libs/crud-pro/exceptions";
10
- import {checkLogin} from "@/middleware/permission.middleware";
11
-
12
-
13
- function fixMyTasksCondition(body:any,ctx: Context){
14
- if(!body.condition) {
15
- throw new CommonException("参数不正确");
5
+ import { AsyncTaskService } from '@/service/asyncTask/AsyncTaskService';
6
+ import { SysAsyncTaskEntity, SysAsyncTaskStatus } from '@/models/AsyncTaskModel';
7
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
8
+ import { SystemTables } from '@/models/SystemTables';
9
+ import { CommonException } from '@/libs/crud-pro/exceptions';
10
+ import { checkLogin } from '@/middleware/permission.middleware';
11
+
12
+ function fixMyTasksCondition(body: any, ctx: Context) {
13
+ if (!body.condition) {
14
+ throw new CommonException('参数不正确');
16
15
  }
17
16
  body.condition.created_by = ctx.userSession.getSessionInfo().accountId;
18
17
  }
19
18
 
20
-
21
- function fixCancelBodyData(body:any, id: number) {
22
- if(!body.data || !body.condition) {
23
- throw new CommonException("参数不正确");
19
+ function fixCancelBodyData(body: any, id: number) {
20
+ if (!body.data || !body.condition) {
21
+ throw new CommonException('参数不正确');
24
22
  }
25
23
 
26
24
  // fix condition
27
25
  const conditionObj: SysAsyncTaskEntity = (body.condition || {}) as any;
28
26
  conditionObj.id = id;
29
- body.condition = conditionObj;
27
+ body.condition = conditionObj;
30
28
 
31
29
  // fix data
32
30
  const dataObj: SysAsyncTaskEntity = (body.data || {}) as any;
@@ -34,10 +32,9 @@ function fixCancelBodyData(body:any, id: number) {
34
32
  body.data = dataObj;
35
33
  }
36
34
 
37
-
38
- function fixCreateBodyData(body:any, ctx: Context) {
39
- if(!body.data) {
40
- throw new CommonException("参数不正确");
35
+ function fixCreateBodyData(body: any, ctx: Context) {
36
+ if (!body.data) {
37
+ throw new CommonException('参数不正确');
41
38
  }
42
39
 
43
40
  const sessionInfo = ctx.userSession.getSessionInfo();
@@ -48,7 +45,6 @@ function fixCreateBodyData(body:any, ctx: Context) {
48
45
  dataObj.created_user_session = JSON.stringify(sessionInfo); // 创建人的session信息。用于执行时的鉴权。
49
46
  }
50
47
 
51
-
52
48
  /**
53
49
  * 异步任务框架
54
50
  */
@@ -84,5 +80,4 @@ export class AsyncTaskController extends BaseApiController {
84
80
  await this.executeSysSimpleSQL(SystemTables.sys_async_tasks, KeysOfSimpleSQL.SIMPLE_UPDATE);
85
81
  return { success: true };
86
82
  }
87
-
88
83
  }
@@ -2,13 +2,13 @@ import * as _ from 'lodash';
2
2
  import { decamelizeKeys } from 'humps';
3
3
  import { Controller, Inject, Param, All } from '@midwayjs/core';
4
4
  import { Context } from '@midwayjs/koa';
5
- import { CommonResult } from '../../libs/utils/common-dto';
6
- import { WorkbenchService } from '../../service/WorkbenchService';
7
- import { API_BASE_TYPE, ApiBaseService } from '../../service/base/ApiBaseService';
8
- import { CurdProService } from '../../service/curd/CurdProService';
9
- import { CurdMixService } from '../../service/curd/CurdMixService';
10
- import { IRequestCfgModel2 } from '../../models/bizmodels';
11
- import { parseDatabaseName } from "../../libs/crud-pro/utils/DatabaseName";
5
+ import { CommonResult } from '@/libs/utils/common-dto';
6
+ import { WorkbenchService } from '@/service/WorkbenchService';
7
+ import { API_BASE_TYPE, ApiBaseService } from '@/service/base/ApiBaseService';
8
+ import { CurdProService } from '@/service/curd/CurdProService';
9
+ import { CurdMixService } from '@/service/curd/CurdMixService';
10
+ import { IRequestCfgModel2 } from '@/models/bizmodels';
11
+ import { parseDatabaseName } from '@/libs/crud-pro/utils/DatabaseName';
12
12
  import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
13
13
 
14
14
  const QUERY_AS_LIST = ['condition', 'data'];
@@ -1,10 +1,10 @@
1
1
  import { Controller, Inject, Post } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { BaseApiController } from '../base/BaseApiController';
4
- import { CrudStdService, SPECIAL_SETTING_KEY } from '../../service/crudstd/CrudStdService';
5
- import { KeysOfSimpleSQL } from '../../libs/crud-pro/models/keys';
6
- import { IRequestModel } from '../../libs/crud-pro/interfaces';
7
- import { CommonResult } from '../../libs/utils/common-dto';
4
+ import { CrudStdService, SPECIAL_SETTING_KEY } from '@/service/crudstd/CrudStdService';
5
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
6
+ import { IRequestModel } from '@/libs/crud-pro/interfaces';
7
+ import { CommonResult } from '@/libs/utils/common-dto';
8
8
 
9
9
  interface ICrudStdActionParams {
10
10
  appCode: string;
@@ -1,11 +1,11 @@
1
- import {Get, Controller, Inject, Query} from '@midwayjs/core';
2
- import {Context} from '@midwayjs/koa';
3
- import {BaseApiController} from '../base/BaseApiController';
4
- import { SystemTables} from '../../models/SystemTables';
1
+ import { Get, Controller, Inject, Query } from '@midwayjs/core';
2
+ import { Context } from '@midwayjs/koa';
3
+ import { BaseApiController } from '../base/BaseApiController';
4
+ import { SystemTables } from '@/models/SystemTables';
5
5
  import { GLOBAL_STATIC_CONFIG } from '@/libs/global-config/global-config';
6
- import {KeysOfSimpleSQL} from '../../libs/crud-pro/models/keys';
7
- import {WorkbenchService} from '../../service/WorkbenchService';
8
- import {CommonResult} from '../../libs/utils/common-dto';
6
+ import { KeysOfSimpleSQL } from '@/libs/crud-pro/models/keys';
7
+ import { WorkbenchService } from '@/service/WorkbenchService';
8
+ import { CommonResult } from '@/libs/utils/common-dto';
9
9
 
10
10
  function checkIsNumber(value: string, name: string) {
11
11
  if (!value) {
@@ -28,21 +28,21 @@ export class DocGatewayController extends BaseApiController {
28
28
  @Inject()
29
29
  protected workbenchService: WorkbenchService;
30
30
 
31
-
32
31
  private async updateDocPV(docId: string, docLibId: string, pv: number) {
33
32
  const ip = this.ctx.headers['x-real-ip'];
34
33
  const lockKey = `doc_ip_pv_${docId}_${ip}`;
35
34
  const EXPIRE_TIME = 5 * 60 * 1000; // 在五分钟内,同一个IP地址重复刷新同一篇文章,认为是一个PV
36
- const nxRes = await this.redisService.set(lockKey, 1, 'EX', EXPIRE_TIME, 'NX')
35
+ const nxRes = await this.redisService.set(lockKey, 1, 'EX', EXPIRE_TIME, 'NX');
37
36
  if (nxRes !== 'OK') {
38
37
  return;
39
38
  }
40
39
 
41
- const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
40
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
42
41
 
43
- await this.curdMixService.executeCrudByCfg({
42
+ await this.curdMixService.executeCrudByCfg(
43
+ {
44
44
  data: {
45
- pv: pv + 1
45
+ pv: pv + 1,
46
46
  },
47
47
  condition: {
48
48
  id: parseInt(docId),
@@ -54,10 +54,10 @@ export class DocGatewayController extends BaseApiController {
54
54
  sqlSimpleName: KeysOfSimpleSQL.SIMPLE_UPDATE,
55
55
  sqlDatabase: SystemDbName,
56
56
  sqlDbType: SystemDbType,
57
- });
57
+ }
58
+ );
58
59
  }
59
60
 
60
-
61
61
  /**
62
62
  * @param docId
63
63
  * @param docLibId 文档库
@@ -72,7 +72,7 @@ export class DocGatewayController extends BaseApiController {
72
72
  return docLibInfoRes;
73
73
  }
74
74
 
75
- const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
75
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
76
76
 
77
77
  const res = await this.curdMixService.executeCrudByCfg(
78
78
  {
@@ -111,7 +111,7 @@ export class DocGatewayController extends BaseApiController {
111
111
  return docLibInfoRes;
112
112
  }
113
113
 
114
- const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
114
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
115
115
 
116
116
  return this.curdMixService.executeCrudByCfg(
117
117
  {
@@ -141,7 +141,7 @@ export class DocGatewayController extends BaseApiController {
141
141
  async getDocLibInfo(@Query('docLibId') docLibId: string) {
142
142
  checkIsNumber(docLibId, 'docLibId');
143
143
 
144
- const {SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
144
+ const { SystemDbName, SystemDbType } = GLOBAL_STATIC_CONFIG.getConfig();
145
145
 
146
146
  const s = await this.curdMixService.executeCrudByCfg(
147
147
  {
@@ -2,18 +2,17 @@ import { Get, Post, Inject, Controller, Files, Fields, Param, Query } from '@mid
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import * as _ from 'lodash';
4
4
  import { BaseApiController } from '../base/BaseApiController';
5
- import { BizException } from '../../models/devops';
6
- import {AccessType, FILE_GET_TYPES} from '../../models/bizmodels';
7
- import { FileCenterService, PATH_PREFIX, toDownloadPaths, isImageFile } from '../../service/FileCenterService';
8
- import { checkPermission } from '../../middleware/permission.middleware';
9
- import { CommonResult } from '../../libs/utils/common-dto';
10
- import {SystemFuncCode} from "../../models/SystemPerm";
5
+ import { BizException } from '@/models/devops';
6
+ import { AccessType, FILE_GET_TYPES } from '@/models/bizmodels';
7
+ import { FileCenterService, PATH_PREFIX, toDownloadPaths, isImageFile } from '@/service/FileCenterService';
8
+ import { checkPermission } from '@/middleware/permission.middleware';
9
+ import { CommonResult } from '@/libs/utils/common-dto';
10
+ import { SystemFuncCode } from '@/models/SystemPerm';
11
11
 
12
12
  function isTrue(obj: any) {
13
13
  return obj === true || obj === 'true';
14
14
  }
15
15
 
16
-
17
16
  /**
18
17
  * 文件上传下载服务
19
18
  */
@@ -31,7 +30,7 @@ export class FileController extends BaseApiController {
31
30
  * @param fields
32
31
  * @param queryData
33
32
  */
34
- @Post('/uploadFile', { middleware: [checkPermission([SystemFuncCode.DocMangeWrite, SystemFuncCode.FileMangeWrite, SystemFuncCode.UserAccountMangeWrite])] } )
33
+ @Post('/uploadFile', { middleware: [checkPermission([SystemFuncCode.DocMangeWrite, SystemFuncCode.FileMangeWrite, SystemFuncCode.UserAccountMangeWrite])] })
35
34
  async uploadFile(@Files() files, @Fields() fields, @Query() queryData): Promise<CommonResult> {
36
35
  const accessType = queryData?.accessType || fields?.accessType || AccessType.open;
37
36
  const referer = this.ctx.req.headers.referer;
@@ -64,7 +63,7 @@ export class FileController extends BaseApiController {
64
63
  * @param streaming 是否直接返回流,默认返回 302 跳转
65
64
  */
66
65
  @Get('/get/:byMethod/:fileKey*')
67
- async downloadFile(@Param('byMethod') byMethod: string ,@Param('fileKey') fileKey: string) {
66
+ async downloadFile(@Param('byMethod') byMethod: string, @Param('fileKey') fileKey: string) {
68
67
  if (!fileKey) {
69
68
  throw new BizException('fileKey不能为空');
70
69
  }
@@ -1,10 +1,10 @@
1
1
  import { All, Controller, Inject, Query } from '@midwayjs/core';
2
2
  import { Context } from '@midwayjs/koa';
3
3
  import { BaseApiController } from '../base/BaseApiController';
4
- import { ProxyApiService } from '../../service/proxyapi/ProxyApiService';
5
- import { WorkbenchService } from '../../service/WorkbenchService';
6
- import { CommonResult } from '../../libs/utils/common-dto';
7
- import { ProxyApiLoadService } from '../../service/proxyapi/ProxyApiLoadService';
4
+ import { ProxyApiService } from '@/service/proxyapi/ProxyApiService';
5
+ import { WorkbenchService } from '@/service/WorkbenchService';
6
+ import { CommonResult } from '@/libs/utils/common-dto';
7
+ import { ProxyApiLoadService } from '@/service/proxyapi/ProxyApiLoadService';
8
8
 
9
9
  /**
10
10
  * 只支持前缀匹配
@@ -1,14 +1,14 @@
1
- import {Controller, Get, Inject, Post} from '@midwayjs/core';
2
- import {Context} from '@midwayjs/koa';
1
+ import { Controller, Get, Inject, Post } from '@midwayjs/core';
2
+ import { Context } from '@midwayjs/koa';
3
3
  import * as _ from 'lodash';
4
- import {BaseApiController} from '../base/BaseApiController';
5
- import {SystemTables} from '../../models/SystemTables';
6
- import {EnumInfoService} from '../../service/EnumInfoService';
7
- import {CommonResult} from '../../libs/utils/common-dto';
8
- import {parseJsonObject} from '../../libs/utils/functions';
9
- import {WorkbenchService} from '../../service/WorkbenchService';
10
- import {SystemRoleCode} from "../../models/SystemPerm";
11
- import {KeysOfAuthType} from "../../libs/crud-pro/models/keys";
4
+ import { BaseApiController } from '../base/BaseApiController';
5
+ import { SystemTables } from '@/models/SystemTables';
6
+ import { EnumInfoService } from '@/service/EnumInfoService';
7
+ import { CommonResult } from '@/libs/utils/common-dto';
8
+ import { parseJsonObject } from '@/libs/utils/functions';
9
+ import { WorkbenchService } from '@/service/WorkbenchService';
10
+ import { SystemRoleCode } from '@/models/SystemPerm';
11
+ import { KeysOfAuthType } from '@/libs/crud-pro/models/keys';
12
12
 
13
13
  /**
14
14
  * 公开的API,无需鉴权,所有人可以直接访问
@@ -52,12 +52,12 @@ export class PublicApiController extends BaseApiController {
52
52
  return CommonResult.errorRes('param workbenchMenuCode is null');
53
53
  }
54
54
 
55
- const workbenchMenuCodeStr = "" + workbenchMenuCode;
56
- const workbenchMenuCodeArray = workbenchMenuCodeStr.split(',');
55
+ const workbenchMenuCodeStr = '' + workbenchMenuCode;
56
+ const workbenchMenuCodeArray = workbenchMenuCodeStr.split(',');
57
57
 
58
58
  const condition = {
59
59
  menu_code: {
60
- "$in": workbenchMenuCodeArray
60
+ $in: workbenchMenuCodeArray,
61
61
  },
62
62
  };
63
63
  const rows = await this.sysDBUtil.getList({ condition }, SystemTables.sys_menus);
@@ -72,22 +72,19 @@ export class PublicApiController extends BaseApiController {
72
72
  const view_auth_config = rowElement.view_auth_config;
73
73
  const view_auth_type = rowElement.view_auth_type;
74
74
 
75
- const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config)
75
+ const hasPermission = this.ctx.userSession.isAuthPass(view_auth_type, view_auth_config);
76
76
 
77
77
  const menu_config_content = rowElement.menu_config_content;
78
78
  delete rowElement.menu_config_content;
79
79
  const menu_list = parseJsonObject(menu_config_content) || [];
80
- map[menu_code] = { ...rowElement, menu_list, hasPermission }
80
+ map[menu_code] = { ...rowElement, menu_list, hasPermission };
81
81
  }
82
82
 
83
-
84
83
  // 特殊的devops菜单
85
84
  map['devops'] = {
86
85
  menu_list: [], // 这个特殊的菜单在前端写死。
87
- hasPermission: this.ctx.userSession.isAuthPass(KeysOfAuthType.byRoleCode, [
88
- SystemRoleCode.DevOpsWriter,SystemRoleCode.DevOpsViewer, SystemRoleCode.SuperAdmin
89
- ])
90
- }
86
+ hasPermission: this.ctx.userSession.isAuthPass(KeysOfAuthType.byRoleCode, [SystemRoleCode.DevOpsWriter, SystemRoleCode.DevOpsViewer, SystemRoleCode.SuperAdmin]),
87
+ };
91
88
 
92
89
  return CommonResult.successRes(map);
93
90
  }
@@ -108,7 +105,7 @@ export class PublicApiController extends BaseApiController {
108
105
  if (oneData && oneData['app_schema']) {
109
106
  oneData['app_schema'] = parseJsonObject(oneData['app_schema']);
110
107
  }
111
- resultData[key] = oneData
108
+ resultData[key] = oneData;
112
109
  }
113
110
  };
114
111
 
@@ -126,7 +123,7 @@ export class PublicApiController extends BaseApiController {
126
123
  const body = this.ctx.request.body as any;
127
124
  const query = this.ctx.query || {};
128
125
  let codeList = _.get(body, 'codeList');
129
- let refreshCache = `${_.get(body, 'refreshCache')}` === 'true' || query.refreshCache === 'true';
126
+ const refreshCache = `${_.get(body, 'refreshCache')}` === 'true' || query.refreshCache === 'true';
130
127
 
131
128
  if (query.codeList) {
132
129
  //codeList=dict@@SexEnum,sysCfgEnum@@EntityStatusEnum