From b1e4b516c49e0fbe1a0bd4f87b74f0025a333022 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Fri, 3 Sep 2021 16:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=88=9D=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gaea/business/enums/ExportTypeEnum.java | 30 +++++++++++++ .../service/impl/ReportExcelServiceImpl.java | 43 ++++++++++++++++++- .../views/report/excelreport/viewer/index.vue | 14 ++++-- 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/enums/ExportTypeEnum.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/ExportTypeEnum.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/ExportTypeEnum.java new file mode 100644 index 00000000..6b01a17e --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/enums/ExportTypeEnum.java @@ -0,0 +1,30 @@ +package com.anjiplus.template.gaea.business.enums; + +/** + * Created by raodeming on 2021/9/3. + */ +public enum ExportTypeEnum { + + /**gaea_excel*/ + GAEA_TEMPLATE_EXCEL("gaea_template_excel", "gaea_template_excel"), + /**gaea_pdf*/ + GAEA_TEMPLATE_PDF("gaea_template_pdf", "gaea_template_pdf"), + ; + + private String codeValue; + private String codeDesc; + + private ExportTypeEnum(String codeValue, String codeDesc) { + this.codeValue = codeValue; + this.codeDesc = codeDesc; + } + + public String getCodeValue() { + return this.codeValue; + } + + public String getCodeDesc() { + return this.codeDesc; + } + +} diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java index 211a131d..e35cdd83 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java @@ -10,9 +10,12 @@ import com.anji.plus.gaea.exception.BusinessException; import com.anji.plus.gaea.utils.GaeaAssert; import com.anji.plus.gaea.utils.GaeaBeanUtils; import com.anjiplus.template.gaea.business.code.ResponseCode; +import com.anjiplus.template.gaea.business.enums.ExportTypeEnum; import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.DataSetDto; import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto; import com.anjiplus.template.gaea.business.modules.dataset.service.DataSetService; +import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper; +import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile; import com.anjiplus.template.gaea.business.modules.report.dao.ReportMapper; import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report; import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; @@ -20,14 +23,17 @@ import com.anjiplus.template.gaea.business.modules.reportexcel.dao.ReportExcelMa import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel; import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService; import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsSheetUtil; +import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.*; import java.util.*; /** @@ -51,6 +57,15 @@ public class ReportExcelServiceImpl implements ReportExcelService { @Autowired private ReportMapper reportMapper; + @Value("${customer.file.dist-path:''}") + private String dictPath; + + @Value("${customer.file.downloadPath:''}") + private String fileDownloadPath; + + @Autowired + private GaeaFileMapper gaeaFileMapper; + @Override public GaeaBaseMapper getMapper() { @@ -115,7 +130,33 @@ public class ReportExcelServiceImpl implements ReportExcelService { @Override public Boolean exportExcel(ReportExcelDto reportExcelDto) { - + String reportCode = reportExcelDto.getReportCode(); + String exportType = reportExcelDto.getExportType(); + + if (exportType.equals(ExportTypeEnum.GAEA_TEMPLATE_EXCEL)) { + String jsonStr = analysisReportData(reportExcelDto); + List lists=(List ) JSON.parse(jsonStr); + OutputStream out = null; + try { + String fileId = UUID.randomUUID().toString(); + String filePath = dictPath + File.separator + fileId + ".xlsx"; + String urlPath = fileDownloadPath + java.io.File.separator + fileId; + + GaeaFile gaeaFile = new GaeaFile(); + gaeaFile.setFilePath(filePath); + gaeaFile.setFileId(fileId); + gaeaFile.setUrlPath(urlPath); + gaeaFile.setFileType("xlsx"); + gaeaFile.setFileInstruction(reportCode + ".xlsx"); + + out = new FileOutputStream(filePath); + XlsUtil.exportXlsFile(out, true, lists); + + gaeaFileMapper.insert(gaeaFile); + } catch (IOException e) { + logger.error("导出失败", e); + } + } return true; } diff --git a/report-ui/src/views/report/excelreport/viewer/index.vue b/report-ui/src/views/report/excelreport/viewer/index.vue index de6b962e..af401923 100644 --- a/report-ui/src/views/report/excelreport/viewer/index.vue +++ b/report-ui/src/views/report/excelreport/viewer/index.vue @@ -12,7 +12,7 @@ + @click="download('gaea_template_excel')"> 导出excel @@ -115,14 +115,20 @@ export default { // console.log(this.sheetData) this.createSheet(); }, - download (val) { - const result = {} + async download(val) { + if (val == 'gaea_template_pdf') { + this.$message('暂不支持pdf'); + return + } + const result = {}; result['reportCode'] = this.reportCode result['setParam'] = JSON.stringify(this.params.setParam) if (val != '') { result['exportType'] = val } - exportExcel(result) + const {code, message} = await exportExcel(result) + if (code != 200) return + this.$message.success(message); }, // 表单封装json toObject (val) {