导出初实现

Raod 3 years ago
parent 07ed946a91
commit b1e4b516c4

@ -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;
}
}

@ -10,9 +10,12 @@ import com.anji.plus.gaea.exception.BusinessException;
import com.anji.plus.gaea.utils.GaeaAssert; import com.anji.plus.gaea.utils.GaeaAssert;
import com.anji.plus.gaea.utils.GaeaBeanUtils; import com.anji.plus.gaea.utils.GaeaBeanUtils;
import com.anjiplus.template.gaea.business.code.ResponseCode; 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.DataSetDto;
import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto; 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.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.ReportMapper;
import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report; import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto; 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.dao.entity.ReportExcel;
import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService; 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.XlsSheetUtil;
import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.*;
import java.util.*; import java.util.*;
/** /**
@ -51,6 +57,15 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Autowired @Autowired
private ReportMapper reportMapper; private ReportMapper reportMapper;
@Value("${customer.file.dist-path:''}")
private String dictPath;
@Value("${customer.file.downloadPath:''}")
private String fileDownloadPath;
@Autowired
private GaeaFileMapper gaeaFileMapper;
@Override @Override
public GaeaBaseMapper<ReportExcel> getMapper() { public GaeaBaseMapper<ReportExcel> getMapper() {
@ -115,7 +130,33 @@ public class ReportExcelServiceImpl implements ReportExcelService {
@Override @Override
public Boolean exportExcel(ReportExcelDto reportExcelDto) { 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<JSONObject> lists=(List<JSONObject> ) 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; return true;
} }

@ -12,7 +12,7 @@
<a v-if="reportCode != null" <a v-if="reportCode != null"
download="xxx.xlsx"> download="xxx.xlsx">
<el-button type="text" <el-button type="text"
@click="download('')"> @click="download('gaea_template_excel')">
<i class="iconfont iconexcel"></i>导出excel <i class="iconfont iconexcel"></i>导出excel
</el-button> </el-button>
</a> </a>
@ -115,14 +115,20 @@ export default {
// console.log(this.sheetData) // console.log(this.sheetData)
this.createSheet(); this.createSheet();
}, },
download (val) { async download(val) {
const result = {} if (val == 'gaea_template_pdf') {
this.$message('暂不支持pdf');
return
}
const result = {};
result['reportCode'] = this.reportCode result['reportCode'] = this.reportCode
result['setParam'] = JSON.stringify(this.params.setParam) result['setParam'] = JSON.stringify(this.params.setParam)
if (val != '') { if (val != '') {
result['exportType'] = val result['exportType'] = val
} }
exportExcel(result) const {code, message} = await exportExcel(result)
if (code != 200) return
this.$message.success(message);
}, },
// json // json
toObject (val) { toObject (val) {

Loading…
Cancel
Save