feat: 通用导出工具
This commit is contained in:
+22
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -171,4 +172,25 @@ public class ProcessStandardComplianceCheckController extends JeroController<Pro
|
|||||||
return Result.OK("批量删除成功!");
|
return Result.OK("批量删除成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出excel
|
||||||
|
*/
|
||||||
|
@AutoLog(value = "法规符合性排查流程-分发列表导出")
|
||||||
|
@ApiOperation(value="法规符合性排查流程-分发列表导出", notes="法规符合性排查流程-分发列表导出")
|
||||||
|
@GetMapping(value = "/exportXlsDistribute")
|
||||||
|
public void exportXlsDistribute(@RequestParam("taskId") String taskId, HttpServletResponse response) {
|
||||||
|
sccService.exportXlsDistribute(taskId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出excel
|
||||||
|
*/
|
||||||
|
@AutoLog(value = "法规符合性排查流程-不分发列表导出")
|
||||||
|
@ApiOperation(value="法规符合性排查流程-不分发列表导出", notes="法规符合性排查流程-不分发列表导出")
|
||||||
|
@GetMapping(value = "/exportXlsNotDistribute")
|
||||||
|
public void exportXlsNotDistribute(@RequestParam("taskId") String taskId, HttpServletResponse response) {
|
||||||
|
sccService.exportXlsNotDistribute(taskId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -7,6 +7,7 @@ import com.jero.modules.activiti.process.standardComplianceCheck.entity.ProcessS
|
|||||||
import com.jero.modules.activiti.process.standardComplianceCheck.entity.vo.ProcessSccVO;
|
import com.jero.modules.activiti.process.standardComplianceCheck.entity.vo.ProcessSccVO;
|
||||||
import org.activiti.engine.delegate.DelegateTask;
|
import org.activiti.engine.delegate.DelegateTask;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,4 +28,8 @@ public interface IProcessStandardComplianceCheckService extends IService<Process
|
|||||||
void submit(ProcessInfoVO<ProcessSccVO> processInfoVO);
|
void submit(ProcessInfoVO<ProcessSccVO> processInfoVO);
|
||||||
|
|
||||||
List<ProcessStandardComplianceCheckDetail> generate(ProcessStandardComplianceCheck scc) throws Exception;
|
List<ProcessStandardComplianceCheckDetail> generate(ProcessStandardComplianceCheck scc) throws Exception;
|
||||||
|
|
||||||
|
void exportXlsDistribute(String taskId, HttpServletResponse response);
|
||||||
|
|
||||||
|
void exportXlsNotDistribute(String taskId, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
+55
-9
@@ -41,6 +41,7 @@ import com.jero.modules.split.service.ISarFileSplitInfoService;
|
|||||||
import com.jero.modules.sys.utils.UserUtils;
|
import com.jero.modules.sys.utils.UserUtils;
|
||||||
import com.jero.modules.system.entity.SysDepart;
|
import com.jero.modules.system.entity.SysDepart;
|
||||||
import com.jero.modules.system.service.ISysDepartService;
|
import com.jero.modules.system.service.ISysDepartService;
|
||||||
|
import com.jero.modules.system.util.SysWaterMarkUtil;
|
||||||
import org.activiti.engine.RuntimeService;
|
import org.activiti.engine.RuntimeService;
|
||||||
import org.activiti.engine.TaskService;
|
import org.activiti.engine.TaskService;
|
||||||
import org.activiti.engine.delegate.DelegateTask;
|
import org.activiti.engine.delegate.DelegateTask;
|
||||||
@@ -48,11 +49,14 @@ import org.activiti.engine.runtime.ProcessInstance;
|
|||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -73,35 +77,32 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IProcessHandleService processHandleService;
|
private IProcessHandleService processHandleService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ActFlowCommonService actFlowCommonService;
|
private ActFlowCommonService actFlowCommonService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ProcessNodeLinkService processNodeLinkService;
|
private ProcessNodeLinkService processNodeLinkService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ISysDepartService sysDepartService;
|
private ISysDepartService sysDepartService;
|
||||||
@Resource
|
@Resource
|
||||||
private RuntimeService runtimeService;
|
private RuntimeService runtimeService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IProcessStandardComplianceCheckDetailService sccDetailService;
|
private IProcessStandardComplianceCheckDetailService sccDetailService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IDocumentSplitService documentSplitService;
|
private IDocumentSplitService documentSplitService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IOSSFileService ossFileService;
|
private IOSSFileService ossFileService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ISarFileSplitInfoService sarFileSplitInfoService;
|
private ISarFileSplitInfoService sarFileSplitInfoService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DocumentSplitMapper documentSplitMapper;
|
private DocumentSplitMapper documentSplitMapper;
|
||||||
|
@Resource
|
||||||
|
private SysWaterMarkUtil sysWaterMarkUtil;
|
||||||
|
|
||||||
|
@Value("${jero.path.exportExcelTempPath}")
|
||||||
|
private String exportExcelTempPath;
|
||||||
|
private static final String EXPORT_EXCEL_TEMP = "exportExcelTemp";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startProcess(ProcessInfoVO<ProcessSccVO> processInfoVO) {
|
public void startProcess(ProcessInfoVO<ProcessSccVO> processInfoVO) {
|
||||||
@@ -420,6 +421,51 @@ public class ProcessStandardComplianceCheckServiceImpl extends ServiceImpl<Proce
|
|||||||
return this.saveAllDetailData(modelExcelVOList, detailInfoList);
|
return this.saveAllDetailData(modelExcelVOList, detailInfoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportXlsDistribute(String taskId, HttpServletResponse response) {
|
||||||
|
ProcessInfoVO<ProcessSccVO> handleData = this.getHandleData(taskId);
|
||||||
|
List<ProcessStandardComplianceCheckDetail> detailInfoList = handleData.getBusinessInfoDTO().getDetailInfoList();
|
||||||
|
String fileName = "";
|
||||||
|
String url = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, fileName);
|
||||||
|
File file = new File(url);
|
||||||
|
// if (!file.exists()) {
|
||||||
|
// boolean mkdirs = file.mkdirs();
|
||||||
|
// log.info("创建临时目录:{}", mkdirs);
|
||||||
|
// }
|
||||||
|
// try (FileOutputStream fos = new FileOutputStream(url + File.separator + fileName + ".xls")){
|
||||||
|
// // 获取数据
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// this.settleDocuments(url, records);
|
||||||
|
//
|
||||||
|
// // 生成excel
|
||||||
|
// ExportParams exportParams = new ExportParams();
|
||||||
|
// exportParams.setType(ExcelType.HSSF);
|
||||||
|
// // 复制一份数据
|
||||||
|
// List<LawsEvaluationNotMetLibrary> newRecordsExport = new ArrayList<>(records);
|
||||||
|
// Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsEvaluationNotMetLibrary.class, records);
|
||||||
|
// // 生成超链接
|
||||||
|
// generateHyperlink(newRecordsExport, workbook);
|
||||||
|
// // 导出excel
|
||||||
|
// workbook.write(fos);
|
||||||
|
// // 生成并导出zip
|
||||||
|
// ZipUtil.toZip(url, response.getOutputStream(), response, true);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// log.error("导出excel异常", e);
|
||||||
|
// throw new JeroBootException("导出excel异常", e);
|
||||||
|
// } finally {
|
||||||
|
// // 删除文件
|
||||||
|
// if (new File(url).exists()) {
|
||||||
|
// FileUtils.deleteFolders(url);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportXlsNotDistribute(String taskId, HttpServletResponse response) {
|
||||||
|
ProcessInfoVO<ProcessSccVO> handleData = this.getHandleData(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
private List<ProcessStandardComplianceCheckDetail> getSplitDataByStandard(ProcessStandardComplianceCheck scc) {
|
private List<ProcessStandardComplianceCheckDetail> getSplitDataByStandard(ProcessStandardComplianceCheck scc) {
|
||||||
String standardId = scc.getStandardId();
|
String standardId = scc.getStandardId();
|
||||||
String fileType = scc.getSplitFileSource();
|
String fileType = scc.getSplitFileSource();
|
||||||
|
|||||||
+9
-1
@@ -6,13 +6,16 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.jero.common.aspect.annotation.Dict;
|
import com.jero.common.aspect.annotation.Dict;
|
||||||
|
import com.jero.modules.laws.utils.ExcelExportUtilPro;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,6 +26,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@TableName(value ="laws_evaluation_not_met_library")
|
@TableName(value ="laws_evaluation_not_met_library")
|
||||||
@Data
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class LawsEvaluationNotMetLibrary implements Serializable {
|
public class LawsEvaluationNotMetLibrary implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
@@ -218,7 +222,11 @@ public class LawsEvaluationNotMetLibrary implements Serializable {
|
|||||||
@ApiModelProperty(value = "附件")
|
@ApiModelProperty(value = "附件")
|
||||||
@ExcelCollection(name = "", orderNum = "13")
|
@ExcelCollection(name = "", orderNum = "13")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<NotMetFile> fileList = Collections.emptyList();
|
private List<ExcelExportUtilPro.FileDetails> fileList = Collections.emptyList();
|
||||||
|
|
||||||
|
public List<String> obtainFileIds() {
|
||||||
|
return file != null ? Arrays.asList(file.split(",")) : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标准ID
|
* 标准ID
|
||||||
|
|||||||
+1
-3
@@ -13,9 +13,7 @@
|
|||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="pageList" resultType="com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary">
|
<select id="pageList" resultType="com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary">
|
||||||
select nm.* ,
|
select nm.*
|
||||||
d.standard_name,
|
|
||||||
d.standard_number
|
|
||||||
from laws_evaluation_not_met_library nm
|
from laws_evaluation_not_met_library nm
|
||||||
left join laws_domestic_standard as d on d.id = nm.standard_id
|
left join laws_domestic_standard as d on d.id = nm.standard_id
|
||||||
|
|
||||||
|
|||||||
+83
-89
@@ -9,19 +9,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.common.system.query.QueryGenerator;
|
import com.jero.common.system.query.QueryGenerator;
|
||||||
import com.jero.common.util.FileUtils;
|
import com.jero.common.util.FileUtils;
|
||||||
import com.jero.common.util.MinioUtil;
|
|
||||||
import com.jero.common.util.ZipUtil;
|
import com.jero.common.util.ZipUtil;
|
||||||
import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary;
|
import com.jero.modules.assessmentLibrary.entity.LawsEvaluationNotMetLibrary;
|
||||||
import com.jero.modules.assessmentLibrary.entity.NotMetFile;
|
|
||||||
import com.jero.modules.assessmentLibrary.mapper.LawsEvaluationNotMetLibraryMapper;
|
import com.jero.modules.assessmentLibrary.mapper.LawsEvaluationNotMetLibraryMapper;
|
||||||
import com.jero.modules.assessmentLibrary.service.ILawsEvaluationNotMetLibraryService;
|
import com.jero.modules.assessmentLibrary.service.ILawsEvaluationNotMetLibraryService;
|
||||||
import com.jero.modules.oss.entity.OSSFile;
|
import com.jero.modules.laws.utils.ExcelExportUtilPro;
|
||||||
import com.jero.modules.oss.service.IOSSFileService;
|
|
||||||
import com.jero.modules.projectLibrary.common.AssessCommon;
|
import com.jero.modules.projectLibrary.common.AssessCommon;
|
||||||
import com.jero.modules.system.util.SysWaterMarkUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||||
@@ -33,9 +29,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.io.InputStream;
|
import java.util.Arrays;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ThinkBook
|
* @author ThinkBook
|
||||||
@@ -47,12 +43,10 @@ import java.util.*;
|
|||||||
public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEvaluationNotMetLibraryMapper, LawsEvaluationNotMetLibrary>
|
public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEvaluationNotMetLibraryMapper, LawsEvaluationNotMetLibrary>
|
||||||
implements ILawsEvaluationNotMetLibraryService {
|
implements ILawsEvaluationNotMetLibraryService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IOSSFileService ossFileService;
|
|
||||||
@Resource
|
|
||||||
private SysWaterMarkUtil sysWaterMarkUtil;
|
|
||||||
@Resource
|
@Resource
|
||||||
private LawsEvaluationNotMetLibraryMapper notMetMapper;
|
private LawsEvaluationNotMetLibraryMapper notMetMapper;
|
||||||
|
@Resource
|
||||||
|
private ExcelExportUtilPro excelExportUtilPro;
|
||||||
|
|
||||||
@Value("${jero.path.exportExcelTempPath}")
|
@Value("${jero.path.exportExcelTempPath}")
|
||||||
private String exportExcelTempPath;
|
private String exportExcelTempPath;
|
||||||
@@ -113,7 +107,7 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
|
|||||||
IPage<LawsEvaluationNotMetLibrary> lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE, req);
|
IPage<LawsEvaluationNotMetLibrary> lawsEvaluationNotMets = this.queryPage(lawsEvaluationNotMet, 1, Integer.MAX_VALUE, req);
|
||||||
List<LawsEvaluationNotMetLibrary> records = lawsEvaluationNotMets.getRecords();
|
List<LawsEvaluationNotMetLibrary> records = lawsEvaluationNotMets.getRecords();
|
||||||
|
|
||||||
this.settleDocuments(url, records);
|
excelExportUtilPro.settleDocuments(url, records, LawsEvaluationNotMetLibrary::obtainFileIds, LawsEvaluationNotMetLibrary::setFileList);
|
||||||
|
|
||||||
// 生成excel
|
// 生成excel
|
||||||
ExportParams exportParams = new ExportParams();
|
ExportParams exportParams = new ExportParams();
|
||||||
@@ -122,7 +116,7 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
|
|||||||
List<LawsEvaluationNotMetLibrary> newRecordsExport = new ArrayList<>(records);
|
List<LawsEvaluationNotMetLibrary> newRecordsExport = new ArrayList<>(records);
|
||||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsEvaluationNotMetLibrary.class, records);
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, LawsEvaluationNotMetLibrary.class, records);
|
||||||
// 生成超链接
|
// 生成超链接
|
||||||
generateHyperlink(newRecordsExport, workbook);
|
excelExportUtilPro.generateHyperlink(newRecordsExport, workbook, LawsEvaluationNotMetLibrary::getFileList, 12);
|
||||||
// 导出excel
|
// 导出excel
|
||||||
workbook.write(fos);
|
workbook.write(fos);
|
||||||
// 生成并导出zip
|
// 生成并导出zip
|
||||||
@@ -140,80 +134,80 @@ public class LawsEvaluationNotMetLibraryServiceImpl extends ServiceImpl<LawsEval
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void generateHyperlink(List<LawsEvaluationNotMetLibrary> vos, Workbook workbook) {
|
// private static void generateHyperlink(List<LawsEvaluationNotMetLibrary> vos, Workbook workbook) {
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
// Sheet sheet = workbook.getSheetAt(0);
|
||||||
// 设置字体颜色、下划线
|
// // 设置字体颜色、下划线
|
||||||
CellStyle cellStyle = workbook.createCellStyle();
|
// CellStyle cellStyle = workbook.createCellStyle();
|
||||||
Font font = workbook.createFont();
|
// Font font = workbook.createFont();
|
||||||
font.setColor(IndexedColors.BLUE.getIndex());
|
// font.setColor(IndexedColors.BLUE.getIndex());
|
||||||
font.setUnderline(Font.U_SINGLE);
|
// font.setUnderline(Font.U_SINGLE);
|
||||||
cellStyle.setFont(font);
|
// cellStyle.setFont(font);
|
||||||
cellStyle.setWrapText(true);
|
// cellStyle.setWrapText(true);
|
||||||
int i = 1;
|
// int i = 1;
|
||||||
for (LawsEvaluationNotMetLibrary vo : vos) {
|
// for (LawsEvaluationNotMetLibrary vo : vos) {
|
||||||
if (!Objects.isNull(vo.getFile()) && !vo.getFileList().isEmpty()) {
|
// if (!Objects.isNull(vo.getFile()) && !vo.getFileList().isEmpty()) {
|
||||||
for (NotMetFile notMetFile : vo.getFileList()) {
|
// for (NotMetFile notMetFile : vo.getFileList()) {
|
||||||
Row row = sheet.getRow(i);
|
// Row row = sheet.getRow(i);
|
||||||
Cell cell = row.getCell(12);
|
// Cell cell = row.getCell(12);
|
||||||
cell.setCellFormula("HYPERLINK(\"" + notMetFile.getFileName() + "\", \"" + notMetFile.getFileName() + "\")");
|
// cell.setCellFormula("HYPERLINK(\"" + notMetFile.getFileName() + "\", \"" + notMetFile.getFileName() + "\")");
|
||||||
cell.setCellStyle(cellStyle);
|
// cell.setCellStyle(cellStyle);
|
||||||
i += 1;
|
// i += 1;
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
i += 1;
|
// i += 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void settleDocuments(String url, List<LawsEvaluationNotMetLibrary> excelVos) throws
|
// private void settleDocuments(String url, List<LawsEvaluationNotMetLibrary> excelVos) throws
|
||||||
IOException {
|
// IOException {
|
||||||
for (LawsEvaluationNotMetLibrary vo : excelVos) {
|
// for (LawsEvaluationNotMetLibrary vo : excelVos) {
|
||||||
// 查询文件
|
// // 查询文件
|
||||||
if (StringUtils.isNotBlank(vo.getFile())) {
|
// if (StringUtils.isNotBlank(vo.getFile())) {
|
||||||
List<String> fileIdList = Arrays.asList(vo.getFile().split(","));
|
// List<String> fileIdList = Arrays.asList(vo.getFile().split(","));
|
||||||
List<OSSFile> ossFileList = ossFileService.listByIds(fileIdList);
|
// List<OSSFile> ossFileList = ossFileService.listByIds(fileIdList);
|
||||||
if (!ossFileList.isEmpty()) {
|
// if (!ossFileList.isEmpty()) {
|
||||||
// 赋值
|
// // 赋值
|
||||||
List<NotMetFile> notMetFileList = com.jero.common.util.BeanCopyUtils.copyBeanList(ossFileList, NotMetFile.class);
|
// List<NotMetFile> notMetFileList = com.jero.common.util.BeanCopyUtils.copyBeanList(ossFileList, NotMetFile.class);
|
||||||
vo.setFileList(notMetFileList);
|
// vo.setFileList(notMetFileList);
|
||||||
// 写出文件
|
// // 写出文件
|
||||||
for (OSSFile ossFile : ossFileList) {
|
// for (OSSFile ossFile : ossFileList) {
|
||||||
InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl());
|
// InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl());
|
||||||
// pdf加水印
|
// // pdf加水印
|
||||||
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
|
// if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
|
||||||
inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
|
// inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
|
||||||
}
|
// }
|
||||||
// 导出文件
|
// // 导出文件
|
||||||
String filePath = url + File.separator + ossFile.getFileName();
|
// String filePath = url + File.separator + ossFile.getFileName();
|
||||||
writeToLocal(filePath, inputStream);
|
// writeToLocal(filePath, inputStream);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 将InputStream写入本地文件
|
// * 将InputStream写入本地文件
|
||||||
*
|
// *
|
||||||
* @param filePath
|
// * @param filePath
|
||||||
* @param input
|
// * @param input
|
||||||
* @throws IOException
|
// * @throws IOException
|
||||||
*/
|
// */
|
||||||
public void writeToLocal(String filePath, InputStream input)
|
// public void writeToLocal(String filePath, InputStream input)
|
||||||
throws IOException {
|
// throws IOException {
|
||||||
int index;
|
// int index;
|
||||||
byte[] bytes = new byte[1024];
|
// byte[] bytes = new byte[1024];
|
||||||
try (FileOutputStream downloadFile = new FileOutputStream(filePath)) {
|
// try (FileOutputStream downloadFile = new FileOutputStream(filePath)) {
|
||||||
while ((index = input.read(bytes)) != -1) {
|
// while ((index = input.read(bytes)) != -1) {
|
||||||
downloadFile.write(bytes, 0, index);
|
// downloadFile.write(bytes, 0, index);
|
||||||
downloadFile.flush();
|
// downloadFile.flush();
|
||||||
}
|
// }
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("将InputStream写入本地失败:{}", e.getMessage());
|
// log.error("将InputStream写入本地失败:{}", e.getMessage());
|
||||||
} finally {
|
// } finally {
|
||||||
input.close();
|
// input.close();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package com.jero.modules.laws.utils;
|
||||||
|
|
||||||
|
import com.jero.common.util.BeanCopyUtils;
|
||||||
|
import com.jero.common.util.MinioUtil;
|
||||||
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
|
import com.jero.modules.system.util.SysWaterMarkUtil;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ExcelExportUtilPro {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IOSSFileService ossFileService;
|
||||||
|
@Resource
|
||||||
|
private SysWaterMarkUtil sysWaterMarkUtil;
|
||||||
|
|
||||||
|
// 文件详细信息类
|
||||||
|
@Getter
|
||||||
|
public static class FileDetails {
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Excel(name = "附件", width = 15)
|
||||||
|
@ApiModelProperty(value = "附件")
|
||||||
|
private String fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void generateHyperlink(List<T> items, Workbook workbook,
|
||||||
|
Function<T, List<FileDetails>> fileDetailsProvider,
|
||||||
|
Integer cellNum) {
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
CellStyle cellStyle = createHyperlinkCellStyle(workbook);
|
||||||
|
int rowIndex = 1;
|
||||||
|
for (T item : items) {
|
||||||
|
List<FileDetails> fileDetailsList = fileDetailsProvider.apply(item);
|
||||||
|
if (fileDetailsList != null && !fileDetailsList.isEmpty()) {
|
||||||
|
for (FileDetails fileDetails : fileDetailsList) {
|
||||||
|
Row row = sheet.getRow(rowIndex);
|
||||||
|
Cell cell = row.getCell(cellNum);
|
||||||
|
cell.setCellFormula("HYPERLINK(\"" + fileDetails.getFileName() + "\", \"" + fileDetails.getFileName() + "\")");
|
||||||
|
cell.setCellStyle(cellStyle);
|
||||||
|
rowIndex++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rowIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CellStyle createHyperlinkCellStyle(Workbook workbook) {
|
||||||
|
CellStyle cellStyle = workbook.createCellStyle();
|
||||||
|
Font font = workbook.createFont();
|
||||||
|
font.setColor(IndexedColors.BLUE.getIndex());
|
||||||
|
font.setUnderline(Font.U_SINGLE);
|
||||||
|
cellStyle.setFont(font);
|
||||||
|
cellStyle.setWrapText(true);
|
||||||
|
return cellStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void settleDocuments(String url, List<T> items,
|
||||||
|
Function<T, List<String>> fileIdProvider,
|
||||||
|
BiConsumer<T, List<FileDetails>> fileDetailsConsumer) throws IOException {
|
||||||
|
for (T item : items) {
|
||||||
|
List<String> fileIdList = fileIdProvider.apply(item);
|
||||||
|
if (fileIdList != null && !fileIdList.isEmpty()) {
|
||||||
|
List<OSSFile> ossFileList = ossFileService.listByIds(fileIdList);
|
||||||
|
if (!ossFileList.isEmpty()) {
|
||||||
|
List<FileDetails> fileDetailsList = BeanCopyUtils.copyBeanList(ossFileList, FileDetails.class);
|
||||||
|
fileDetailsConsumer.accept(item, fileDetailsList);
|
||||||
|
for (OSSFile ossFile : ossFileList) {
|
||||||
|
InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl());
|
||||||
|
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")) {
|
||||||
|
inputStream = sysWaterMarkUtil.addWatermarkToPdf(inputStream);
|
||||||
|
}
|
||||||
|
String filePath = url + File.separator + ossFile.getFileName();
|
||||||
|
writeToLocal(filePath, inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToLocal(String filePath, InputStream input) throws IOException {
|
||||||
|
int index;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
try (FileOutputStream downloadFile = new FileOutputStream(filePath)) {
|
||||||
|
while ((index = input.read(bytes)) != -1) {
|
||||||
|
downloadFile.write(bytes, 0, index);
|
||||||
|
downloadFile.flush();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("将InputStream写入本地失败:{}", e.getMessage());
|
||||||
|
} finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user