From 5524162a61283ea53bde3575118538ff4395128a Mon Sep 17 00:00:00 2001 From: lastsunday Date: Tue, 19 Nov 2024 16:36:58 +0800 Subject: [PATCH] fix(sidepanel): data upload record total for statistic task, file upload failure return error message for data upload task --- CHANGELOG.md | 9 +++++++-- src/background/service/taskService.js | 6 +++--- src/offscreen/service/taskService.js | 14 +++++++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c117c833..7ba4714a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,15 @@ ## WIP +### 🐛 Fixed + +1. (Sidepanel)修复记录上传记录数查询。 + ### ✏️ Changed -1. (Sidepanel)修复公司数据增量上传逻辑。 -2. (Sidepanel)为数据文件增加数据结构版本号。 +1. (Sidepanel)修改公司数据增量上传逻辑。 +2. (Sidepanel)修改数据上传错误处理逻辑。 +3. (Sidepanel)为数据文件增加数据结构版本号。 ## 1.30.2(2024-11-18) diff --git a/src/background/service/taskService.js b/src/background/service/taskService.js index 575ec758..4fd52289 100644 --- a/src/background/service/taskService.js +++ b/src/background/service/taskService.js @@ -429,12 +429,12 @@ async function uploadData({ userName, repoName, dirPath, dataTypeName, dataList, let zipData = await zipFileToBase64(dataTypeName, excelData); let filePath = `${dirPath}/${dataTypeName}.zip`; try { - let result = await GithubApi.createFileContent(userName, repoName, filePath, zipData, "upload job data", { getTokenFunction: getToken, setTokenFunction: setToken, }); + await GithubApi.createFileContent(userName, repoName, filePath, zipData, "upload job data", { getTokenFunction: getToken, setTokenFunction: setToken, }); infoLog(`[Task Data Upload ${dataTypeName}] create file ${filePath} success`); - return result; } catch (e) { if (e == EXCEPTION.CREATION_FAILED) { infoLog(`[Task Data Upload ${dataTypeName}] create file ${filePath} failure`); + return `upload file ${filePath} failure`; } else { throw e; } @@ -607,7 +607,7 @@ async function uploadDataByDataId(dataId, dataTypeName, getDataFunction, jsonObj let endDatetime = taskDataUpload.endDatetime; let dirPath = getPathByDatetime({ endDatetime }); await createRepoIfNotExists({ userName, repoName }); - await uploadData({ + return await uploadData({ userName, repoName, dirPath, dataTypeName, dataList: (await getDataFunction({ startDatetime, endDatetime })).items, diff --git a/src/offscreen/service/taskService.js b/src/offscreen/service/taskService.js index d9423c4b..f3512c0b 100644 --- a/src/offscreen/service/taskService.js +++ b/src/offscreen/service/taskService.js @@ -192,7 +192,7 @@ export const TaskService = { let endDatetime = dateToStr(param.endDatetime); //upload total - const uploadTotalSql = `SELECT SUM(data_count) AS count FROM task_data_upload ${genUpdatetimeCondition(startDatetime, endDatetime)}`; + const uploadTotalSql = `SELECT SUM(t2.data_count) AS count FROM task AS t1 LEFT JOIN task_data_upload AS t2 ON t1.data_id = t2.id ${genUpdatetimeCondition({ updateDatetimeColumn: "t1.update_datetime", startDatetime, endDatetime, otherConditionSql: ` AND t1.status = 'FINISHED' AND t1.type IN ('JOB_DATA_UPLOAD','COMPANY_DATA_UPLOAD','COMPANY_TAG_DATA_UPLOAD')` })}`; let uploadRecordTotalCount = []; (await getDb()).exec({ sql: uploadTotalSql, @@ -200,9 +200,9 @@ export const TaskService = { resultRows: uploadRecordTotalCount, }); result.uploadRecordTotalCount = uploadRecordTotalCount[0].count; - + //download total - const downloadTotalSql = `SELECT COUNT(*) AS count FROM task ${genUpdatetimeCondition(startDatetime, endDatetime, ` AND status = 'FINISHED' AND type IN ('JOB_DATA_DOWNLOAD','COMPANY_DATA_DOWNLOAD','COMPANY_TAG_DATA_DOWNLOAD')`)} `; + const downloadTotalSql = `SELECT COUNT(*) AS count FROM task ${genUpdatetimeCondition({ startDatetime, endDatetime, otherConditionSql: ` AND status = 'FINISHED' AND type IN ('JOB_DATA_DOWNLOAD','COMPANY_DATA_DOWNLOAD','COMPANY_TAG_DATA_DOWNLOAD')` })} `; let downloadFileTotalCount = []; (await getDb()).exec({ sql: downloadTotalSql, @@ -212,7 +212,7 @@ export const TaskService = { result.downloadFileTotalCount = downloadFileTotalCount[0].count; //merge total - const mergeTotalSql = `SELECT SUM(data_count) AS count FROM task_data_merge ${genUpdatetimeCondition(startDatetime, endDatetime)}`; + const mergeTotalSql = `SELECT SUM(data_count) AS count FROM task_data_merge ${genUpdatetimeCondition({ startDatetime, endDatetime })}`; let mergeRecordTotalCount = []; (await getDb()).exec({ sql: mergeTotalSql, @@ -231,17 +231,17 @@ export const TaskService = { }, }; -function genUpdatetimeCondition(startDatetime, endDatetime, otherConditionSql) { +function genUpdatetimeCondition({ startDatetime, endDatetime, otherConditionSql, updateDatetimeColumn }) { let whereCondition = ""; if (startDatetime) { whereCondition += - " AND update_datetime >= '" + + ` AND ${updateDatetimeColumn ?? "update_datetime"} >= '` + dayjs(startDatetime).format("YYYY-MM-DD HH:mm:ss") + "'"; } if (endDatetime) { whereCondition += - " AND update_datetime < '" + + ` AND ${updateDatetimeColumn ?? "update_datetime"} < '` + dayjs(endDatetime).format("YYYY-MM-DD HH:mm:ss") + "'"; }