midway-fatcms 0.0.1-beta.24 → 0.0.1-beta.25
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.
- package/dist/models/RedisKeys.d.ts +1 -0
- package/dist/models/RedisKeys.js +2 -1
- package/dist/service/EnumInfoService.js +2 -1
- package/dist/service/anyapi/AnyApiSandboxService.js +12 -12
- package/dist/service/asyncTask/AsyncTaskRunnerService.js +3 -3
- package/dist/service/asyncTask/handler/ExportExcelAsyncTaskHandler.js +36 -17
- package/package.json +1 -1
- package/src/models/AsyncTaskModel.ts +82 -82
- package/src/models/RedisKeys.ts +2 -1
- package/src/service/AuthService.ts +272 -275
- package/src/service/EnumInfoService.ts +5 -4
- package/src/service/FileCenterService.ts +4 -4
- package/src/service/anyapi/AnyApiSandboxService.ts +121 -121
- package/src/service/anyapi/AnyApiService.ts +186 -187
- package/src/service/asyncTask/AsyncTaskRunnerService.ts +3 -3
- package/src/service/asyncTask/handler/ExportExcelAsyncTaskHandler.ts +37 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IMidwayKoaContext } from '@midwayjs/koa';
|
|
2
|
-
import { ISysAsyncTaskHandler, SysAsyncTaskContext } from '@/models/AsyncTaskModel';
|
|
2
|
+
import { ISysAsyncTaskHandler, SysAsyncTaskContext, SysAsyncTaskStatus } from '@/models/AsyncTaskModel';
|
|
3
3
|
import { ANONYMOUS_CONTEXT } from '@/schedule';
|
|
4
4
|
import { IExcelHeaderInfo, IExcelAsyncTaskHandler } from './ExcelInfoModel';
|
|
5
5
|
import { SysAsyncFileFormat } from '@/models/AsyncTaskModel';
|
|
@@ -14,6 +14,7 @@ import * as fs2 from 'node:fs/promises';
|
|
|
14
14
|
import * as path from 'node:path';
|
|
15
15
|
import { parseJsonObject } from '@/libs/utils/functions';
|
|
16
16
|
import { UserSessionInfo } from '@/models/userSession';
|
|
17
|
+
import { errorToString } from '@/libs/utils/errorToString';
|
|
17
18
|
|
|
18
19
|
const indexRef = { current: 0 };
|
|
19
20
|
|
|
@@ -33,7 +34,7 @@ function getExcelAsyncTaskHandler(asyncTaskContext: SysAsyncTaskContext, ctx: IM
|
|
|
33
34
|
if (inputParams && inputParams.appType === StdCrudExportInputParamsAppType.INNER_HTTP) {
|
|
34
35
|
return new ExportExcelByInnerHttpHandler(asyncTaskContext, inputParams, ctx);
|
|
35
36
|
}
|
|
36
|
-
throw new Error('[getExcelAsyncTaskHandler]appType
|
|
37
|
+
throw new Error('[getExcelAsyncTaskHandler]appType不支持;appType = ' + inputParams.appType);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
@@ -63,7 +64,10 @@ class ExportExcelAsyncTask {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
async executeWithContext() {
|
|
66
|
-
this.
|
|
67
|
+
const taskElement = this.asyncTaskContext.task;
|
|
68
|
+
const taskId = _.get(this.asyncTaskContext, 'task.id');
|
|
69
|
+
|
|
70
|
+
this.ctx.logger.info('[ExportExcelAsyncTask] executeWithContext start, taskId=' + taskId);
|
|
67
71
|
|
|
68
72
|
const pageSize = await this.excelAsyncTaskHandler.getPageSize();
|
|
69
73
|
|
|
@@ -94,29 +98,43 @@ class ExportExcelAsyncTask {
|
|
|
94
98
|
|
|
95
99
|
let processed_records = 0;
|
|
96
100
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
try {
|
|
102
|
+
if (typeof totalCount === 'number' && totalCount > 0) {
|
|
103
|
+
const batchCount = Math.ceil(totalCount / pageSize);
|
|
104
|
+
for (let i = 0; i < batchCount; i++) {
|
|
105
|
+
const num = await this.writeExcelBatchData(csvStream, i + 1, pageSize);
|
|
106
|
+
processed_records = processed_records + num;
|
|
107
|
+
const progress = Math.round((processed_records / totalCount) * 100);
|
|
108
|
+
await this.asyncTaskContext.updateTaskStatus({
|
|
109
|
+
processed_records,
|
|
110
|
+
progress,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
107
113
|
}
|
|
114
|
+
|
|
115
|
+
taskElement.task_status = SysAsyncTaskStatus.SUCCEEDED;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
taskElement.task_status = SysAsyncTaskStatus.FAILED;
|
|
118
|
+
taskElement.error_message = errorToString(error);
|
|
119
|
+
const progress = Math.round((processed_records / totalCount) * 100);
|
|
120
|
+
await this.asyncTaskContext.updateTaskStatus({
|
|
121
|
+
processed_records,
|
|
122
|
+
progress,
|
|
123
|
+
task_status: taskElement.task_status,
|
|
124
|
+
error_message: taskElement.error_message,
|
|
125
|
+
});
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
csvStream.end();
|
|
111
129
|
ws.on('finish', async () => {
|
|
112
|
-
this.ctx.logger.info('[ExportExcelAsyncTask] executeWithContext finish');
|
|
130
|
+
this.ctx.logger.info('[ExportExcelAsyncTask] executeWithContext finish, taskId=' + taskId);
|
|
113
131
|
const fsStat = await fs2.stat(diskFilePath);
|
|
114
132
|
const output_file_size = fsStat.size;
|
|
115
133
|
this.asyncTaskContext.updateTaskStatus({
|
|
116
134
|
output_file_size,
|
|
117
135
|
});
|
|
118
136
|
});
|
|
119
|
-
this.ctx.logger.info('[ExportExcelAsyncTask] executeWithContext end');
|
|
137
|
+
this.ctx.logger.info('[ExportExcelAsyncTask] executeWithContext end, taskId=' + taskId);
|
|
120
138
|
}
|
|
121
139
|
|
|
122
140
|
private formatToCsvHeader(headerColumns: IExcelHeaderInfo[]): string[] {
|
|
@@ -209,7 +227,10 @@ class ExportExcelAsyncTask {
|
|
|
209
227
|
*/
|
|
210
228
|
export class ExportExcelAsyncTaskHandler implements ISysAsyncTaskHandler {
|
|
211
229
|
public async execute(asyncTaskContext: SysAsyncTaskContext): Promise<any> {
|
|
212
|
-
|
|
230
|
+
const taskId = _.get(asyncTaskContext, 'task.id');
|
|
231
|
+
|
|
232
|
+
console.log('[ExportExcelAsyncTaskHandler] execute, taskId=>' + taskId);
|
|
233
|
+
|
|
213
234
|
const res = await ANONYMOUS_CONTEXT.runServiceAtAnonymousContext(async (ctx: IMidwayKoaContext) => {
|
|
214
235
|
const createdUserSession = parseJsonObject(asyncTaskContext?.task?.created_user_session);
|
|
215
236
|
ctx.userSession = new UserSessionInfo(createdUserSession, false);
|