diff --git a/core/backend/src/main/java/io/dataease/controller/exportCenter/ExportCenterController.java b/core/backend/src/main/java/io/dataease/controller/exportCenter/ExportCenterController.java index d2fe24bfb0..fa6a9ada08 100644 --- a/core/backend/src/main/java/io/dataease/controller/exportCenter/ExportCenterController.java +++ b/core/backend/src/main/java/io/dataease/controller/exportCenter/ExportCenterController.java @@ -38,4 +38,10 @@ public class ExportCenterController { public void download(@PathVariable String id, HttpServletResponse response) throws Exception { exportCenterService.download(id, response); } + + @PostMapping("/retry/{id}") + public void retry(@PathVariable String id){ + exportCenterService.retry(id); + } + } diff --git a/core/backend/src/main/java/io/dataease/service/exportCenter/ExportCenterService.java b/core/backend/src/main/java/io/dataease/service/exportCenter/ExportCenterService.java index 5bba19521f..b6e876cbfe 100644 --- a/core/backend/src/main/java/io/dataease/service/exportCenter/ExportCenterService.java +++ b/core/backend/src/main/java/io/dataease/service/exportCenter/ExportCenterService.java @@ -117,11 +117,16 @@ public class ExportCenterService { response.setContentType("application/vnd.ms-excel"); //文件名称 response.setHeader("Content-disposition", "attachment;filename=" + exportTask.getFileName()); - - XSSFWorkbook wb = new XSSFWorkbook(exportData_path + id + "/" + exportTask.getFileName()); - wb.write(outputStream); + InputStream fileInputStream = new FileInputStream(exportData_path + id + "/" + exportTask.getFileName()); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = fileInputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } outputStream.flush(); outputStream.close(); + fileInputStream.close(); + response.flushBuffer(); } public void delete(String id) { @@ -135,6 +140,23 @@ public class ExportCenterService { }); } + public void retry(String id){ + ExportTask exportTask = exportTaskMapper.selectByPrimaryKey(id); + exportTask.setExportStatus("PENDING"); + exportTask.setExportPogress("0"); + exportTask.setExportMachineName(hostName()); + exportTask.setExportTime(System.currentTimeMillis()); + exportTaskMapper.updateByPrimaryKey(exportTask); + FileUtil.deleteDirectoryRecursively(exportData_path + id); + if(exportTask.getExportFromType().equalsIgnoreCase("dataset")){ + DataSetExportRequest request = new Gson().fromJson(exportTask.getParams(), DataSetExportRequest.class); + startDatasetTask(exportTask, request); + } + if(exportTask.getExportFromType().equalsIgnoreCase("chart")){ + PanelViewDetailsRequest request = new Gson().fromJson(exportTask.getParams(), PanelViewDetailsRequest.class); + startViewTask(exportTask, request); + } + } public List exportTasks(String status) { if (!STATUS.contains(status)) { DataEaseException.throwException("Invalid status: " + status); @@ -161,7 +183,6 @@ public class ExportCenterService { private void setExportFromName(ExportTaskDTO exportTaskDTO) { if (exportTaskDTO.getExportFromType().equalsIgnoreCase("chart")) { - exportTaskDTO.setExportFromName(panelGroupService.getAbsPath(exportTaskDTO.getExportFrom())); } if (exportTaskDTO.getExportFromType().equalsIgnoreCase("dataset")) { @@ -440,6 +461,8 @@ public class ExportCenterService { exportTask.setExportPogress("100"); exportTask.setExportStatus("SUCCESS"); + + setFileSize(dataPath + "/" + dataPath + "/" + request.getViewName() + ".xlsx", exportTask); } catch (Exception e) { e.printStackTrace(); exportTask.setExportStatus("FAILED"); @@ -647,6 +670,7 @@ public class ExportCenterService { } exportTask.setExportPogress("100"); exportTask.setExportStatus("SUCCESS"); + setFileSize(dataPath + "/" + request.getFilename() + ".xlsx", exportTask); } catch (Exception e) { exportTask.setExportStatus("FAILED"); } finally { @@ -655,6 +679,27 @@ public class ExportCenterService { }); } + private void setFileSize(String filePath, ExportTask exportTask ){ + File file = new File(filePath); + long length = file.length(); + String unit = "Mb"; + Double size = 0.0; + if((double) length/1024/1024 > 1){ + if((double) length/1024/1024 > 1){ + unit = "Gb"; + size = Double.valueOf(String.format("%.2f", (double) length/1024/1024/1024)); + }else { + size = Double.valueOf(String.format("%.2f", (double) length/1024/1024)); + } + + }else { + unit = "Kb"; + size = Double.valueOf(String.format("%.2f", (double) length/1024)); + } + exportTask.setFileSize(size); + exportTask.setFileSizeUnit(unit); + } + public Boolean checkEngineTableIsExists(String id) throws Exception { Datasource engine = engineService.getDeEngine(); JdbcProvider jdbcProvider = CommonBeanFactory.getBean(JdbcProvider.class); @@ -1179,8 +1224,6 @@ public class ExportCenterService { DataEaseException.throwException(Translator.get("i18n_ds_error") + "->" + e.getMessage()); } - - } } diff --git a/core/backend/src/main/resources/db/migration/V64__1.18.19_export_task.sql b/core/backend/src/main/resources/db/migration/V64__1.18.19_export_task.sql index 46ad8ba5ad..d48bbabb7e 100644 --- a/core/backend/src/main/resources/db/migration/V64__1.18.19_export_task.sql +++ b/core/backend/src/main/resources/db/migration/V64__1.18.19_export_task.sql @@ -4,6 +4,7 @@ CREATE TABLE `export_task` ( `user_id` bigint(20) NOT NULL , `file_name` varchar(2048) DEFAULT NULL, `file_size` DOUBLE DEFAULT NULL, + `file_size_unit` varchar(255) DEFAULT NULL, `export_from` varchar(255) DEFAULT NULL, `export_status` varchar(255) DEFAULT NULL, `export_from_type` varchar(255) DEFAULT NULL, diff --git a/core/frontend/src/views/dataset/exportExcel/index.vue b/core/frontend/src/views/dataset/exportExcel/index.vue index 423826173e..ae57372c2b 100644 --- a/core/frontend/src/views/dataset/exportExcel/index.vue +++ b/core/frontend/src/views/dataset/exportExcel/index.vue @@ -33,6 +33,13 @@ {{ scope.row.fileName }} +
+ 导出失败 +
+
+
+ {{scope.row.fileSize}}{{scope.row.fileSizeUnit}} +
@@ -59,8 +66,15 @@ /> - {{ $t("dataset.delete") }} + +
+ +
+
+ +
+ +
@@ -85,7 +99,7 @@ export default { mixins: [msgCfm], data() { return { - activeName: "IN_PROGRESS", + activeName: "ALL", multipleSelection: [], errImg: require("@/assets/none-data.png"), tableData: [{ name: "附件名称" }], @@ -113,6 +127,7 @@ export default { name: "ALL", }, ], + loading : false }; }, created() { @@ -124,15 +139,46 @@ export default { this.handleClick() this.timer = setInterval(() => { if(this.activeName === 'IN_PROGRESS'){ - this.handleClick() + console.log(this.activeName) + post( + '/exportCenter/exportTasks/' + this.activeName,{}, true + ).then( + (res) => { + this.tabList.forEach( item => { + if(item.name === 'ALL'){ + item.label = '全部' + '(' + res.data.length + ')' + } + if(item.name === 'IN_PROGRESS'){ + item.label = '导出中' + '(' + res.data.filter(task => task.exportStatus === 'IN_PROGRESS').length + ')' + } + if(item.name === 'SUCCESS'){ + item.label = '成功' + '(' + res.data.filter(task => task.exportStatus === 'SUCCESS').length + ')' + } + if(item.name === 'FAILED'){ + item.label = '失败' + '(' + res.data.filter(task => task.exportStatus === 'FAILED').length + ')' + } + if(item.name === 'PENDING'){ + item.label = '等待中' + '(' + res.data.filter(task => task.exportStatus === 'PENDING').length + ')' + } + }) + if(this.activeName === 'ALL'){ + this.tableData = res.data + }else { + this.tableData = res.data.filter(task => task.exportStatus === this.activeName) + } + }, + ) } }, 5000); }, + format(percentage) { + return ''; + }, handleClick() { - request({ - url: '/exportCenter/exportTasks/' + this.activeName, - method: 'post' - }).then( + this.tableData = [] + post( + '/exportCenter/exportTasks/' + this.activeName,{}, true + ).then( (res) => { this.tabList.forEach( item => { if(item.name === 'ALL'){ @@ -156,7 +202,8 @@ export default { }else { this.tableData = res.data.filter(task => task.exportStatus === this.activeName) } - } + }, + ) }, downloadClick(item) { @@ -174,6 +221,16 @@ export default { }) }, + retry(item) { + post( + '/exportCenter/retry/' + item.id,{}, + true + ).then( + (res) => { + this.handleClick() + } + ) + }, deleteField(item) { request({ url: '/exportCenter/delete/' + item.id, @@ -197,10 +254,14 @@ export default { this.handlerConfirm(options); }, delAll() { + if(this.multipleSelection.length === 0 ){ + this.openMessageSuccess("请选择", 'error') + return + } post( '/exportCenter/delete', this.multipleSelection.map((ele) => ele.id), - false + true ).then( (res) => { this.handleClick() @@ -248,6 +309,11 @@ export default { th.el-table__cell.is-leaf { border-color: #1f232926; } + + .red-line { + border: 2px solid red; + margin: 10px 0; + } } } diff --git a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTask.java b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTask.java index c0f0c08817..81bd51c052 100644 --- a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTask.java +++ b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTask.java @@ -13,6 +13,8 @@ public class ExportTask implements Serializable { private Double fileSize; + private String fileSizeUnit; + private String exportFrom; private String exportStatus; diff --git a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTaskExample.java b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTaskExample.java index d9f0bd3d0a..899084fe47 100644 --- a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTaskExample.java +++ b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/domain/ExportTaskExample.java @@ -364,6 +364,76 @@ public class ExportTaskExample { return (Criteria) this; } + public Criteria andFileSizeUnitIsNull() { + addCriterion("file_size_unit is null"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitIsNotNull() { + addCriterion("file_size_unit is not null"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitEqualTo(String value) { + addCriterion("file_size_unit =", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitNotEqualTo(String value) { + addCriterion("file_size_unit <>", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitGreaterThan(String value) { + addCriterion("file_size_unit >", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitGreaterThanOrEqualTo(String value) { + addCriterion("file_size_unit >=", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitLessThan(String value) { + addCriterion("file_size_unit <", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitLessThanOrEqualTo(String value) { + addCriterion("file_size_unit <=", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitLike(String value) { + addCriterion("file_size_unit like", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitNotLike(String value) { + addCriterion("file_size_unit not like", value, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitIn(List values) { + addCriterion("file_size_unit in", values, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitNotIn(List values) { + addCriterion("file_size_unit not in", values, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitBetween(String value1, String value2) { + addCriterion("file_size_unit between", value1, value2, "fileSizeUnit"); + return (Criteria) this; + } + + public Criteria andFileSizeUnitNotBetween(String value1, String value2) { + addCriterion("file_size_unit not between", value1, value2, "fileSizeUnit"); + return (Criteria) this; + } + public Criteria andExportFromIsNull() { addCriterion("export_from is null"); return (Criteria) this; diff --git a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/mapper/ExportTaskMapper.xml b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/mapper/ExportTaskMapper.xml index d66d9ce619..c22dd5f28c 100644 --- a/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/mapper/ExportTaskMapper.xml +++ b/sdk/dataease-plugin-common/src/main/java/io/dataease/plugins/common/base/mapper/ExportTaskMapper.xml @@ -6,6 +6,7 @@ + @@ -75,7 +76,7 @@ - id, user_id, file_name, file_size, export_from, export_status, export_from_type, + id, user_id, file_name, file_size, file_size_unit, export_from, export_status, export_from_type, export_time, export_pogress, export_machine_name @@ -131,13 +132,15 @@ insert into export_task (id, user_id, file_name, - file_size, export_from, export_status, - export_from_type, export_time, export_pogress, - export_machine_name, params) + file_size, file_size_unit, export_from, + export_status, export_from_type, export_time, + export_pogress, export_machine_name, params + ) values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, #{fileName,jdbcType=VARCHAR}, - #{fileSize,jdbcType=DOUBLE}, #{exportFrom,jdbcType=VARCHAR}, #{exportStatus,jdbcType=VARCHAR}, - #{exportFromType,jdbcType=VARCHAR}, #{exportTime,jdbcType=BIGINT}, #{exportPogress,jdbcType=VARCHAR}, - #{exportMachineName,jdbcType=VARCHAR}, #{params,jdbcType=LONGVARCHAR}) + #{fileSize,jdbcType=DOUBLE}, #{fileSizeUnit,jdbcType=VARCHAR}, #{exportFrom,jdbcType=VARCHAR}, + #{exportStatus,jdbcType=VARCHAR}, #{exportFromType,jdbcType=VARCHAR}, #{exportTime,jdbcType=BIGINT}, + #{exportPogress,jdbcType=VARCHAR}, #{exportMachineName,jdbcType=VARCHAR}, #{params,jdbcType=LONGVARCHAR} + ) insert into export_task @@ -154,6 +157,9 @@ file_size, + + file_size_unit, + export_from, @@ -189,6 +195,9 @@ #{fileSize,jdbcType=DOUBLE}, + + #{fileSizeUnit,jdbcType=VARCHAR}, + #{exportFrom,jdbcType=VARCHAR}, @@ -233,6 +242,9 @@ file_size = #{record.fileSize,jdbcType=DOUBLE}, + + file_size_unit = #{record.fileSizeUnit,jdbcType=VARCHAR}, + export_from = #{record.exportFrom,jdbcType=VARCHAR}, @@ -265,6 +277,7 @@ user_id = #{record.userId,jdbcType=BIGINT}, file_name = #{record.fileName,jdbcType=VARCHAR}, file_size = #{record.fileSize,jdbcType=DOUBLE}, + file_size_unit = #{record.fileSizeUnit,jdbcType=VARCHAR}, export_from = #{record.exportFrom,jdbcType=VARCHAR}, export_status = #{record.exportStatus,jdbcType=VARCHAR}, export_from_type = #{record.exportFromType,jdbcType=VARCHAR}, @@ -282,6 +295,7 @@ user_id = #{record.userId,jdbcType=BIGINT}, file_name = #{record.fileName,jdbcType=VARCHAR}, file_size = #{record.fileSize,jdbcType=DOUBLE}, + file_size_unit = #{record.fileSizeUnit,jdbcType=VARCHAR}, export_from = #{record.exportFrom,jdbcType=VARCHAR}, export_status = #{record.exportStatus,jdbcType=VARCHAR}, export_from_type = #{record.exportFromType,jdbcType=VARCHAR}, @@ -304,6 +318,9 @@ file_size = #{fileSize,jdbcType=DOUBLE}, + + file_size_unit = #{fileSizeUnit,jdbcType=VARCHAR}, + export_from = #{exportFrom,jdbcType=VARCHAR}, @@ -333,6 +350,7 @@ set user_id = #{userId,jdbcType=BIGINT}, file_name = #{fileName,jdbcType=VARCHAR}, file_size = #{fileSize,jdbcType=DOUBLE}, + file_size_unit = #{fileSizeUnit,jdbcType=VARCHAR}, export_from = #{exportFrom,jdbcType=VARCHAR}, export_status = #{exportStatus,jdbcType=VARCHAR}, export_from_type = #{exportFromType,jdbcType=VARCHAR}, @@ -347,6 +365,7 @@ set user_id = #{userId,jdbcType=BIGINT}, file_name = #{fileName,jdbcType=VARCHAR}, file_size = #{fileSize,jdbcType=DOUBLE}, + file_size_unit = #{fileSizeUnit,jdbcType=VARCHAR}, export_from = #{exportFrom,jdbcType=VARCHAR}, export_status = #{exportStatus,jdbcType=VARCHAR}, export_from_type = #{exportFromType,jdbcType=VARCHAR},