认证-上报库-自定义导出word模板修改
This commit is contained in:
+30
-10
@@ -1,15 +1,21 @@
|
||||
package com.jero.modules.cert.report.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.modules.cert.report.entity.ParamsExportTemplateEO;
|
||||
import com.jero.modules.cert.report.entity.ParamsReportConfigEO;
|
||||
import com.jero.modules.cert.report.entity.ParamsReportDetailEO;
|
||||
import com.jero.modules.cert.report.service.IParamsExportTemplateEOService;
|
||||
import com.jero.modules.cert.report.service.IParamsReportConfigEOService;
|
||||
import com.jero.modules.cert.report.service.IParamsReportDetailEOService;
|
||||
import com.jero.modules.cert.report.vo.ParamsReportDetailVO;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -43,6 +49,13 @@ public class ParamsReportDetailEOController extends JeroController<ParamsReportD
|
||||
@Autowired
|
||||
private IParamsReportConfigEOService paramsReportConfigEOService;
|
||||
|
||||
@Autowired
|
||||
private IOSSFileService ossFileService;
|
||||
|
||||
@Autowired
|
||||
private IParamsExportTemplateEOService paramsExportTemplateEOService;
|
||||
|
||||
|
||||
/**
|
||||
* 表头中英文切换
|
||||
*
|
||||
@@ -150,17 +163,24 @@ public class ParamsReportDetailEOController extends JeroController<ParamsReportD
|
||||
public void exportCustom(ParamsReportDetailVO paramsReportDetailVO,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request) {
|
||||
paramsReportDetailEOService.exportCustom(paramsReportDetailVO, response, request);
|
||||
}
|
||||
// 判断模板类型是word 还是 excel
|
||||
ParamsExportTemplateEO paramsExportTemplateEO = paramsExportTemplateEOService.getById(paramsReportDetailVO.getExportTemplateId());
|
||||
List<OSSFile> ossFiles = ossFileService.getFileInfosByConnectId(paramsExportTemplateEO.getFileConnectId());
|
||||
if (CollectionUtil.isNotEmpty(ossFiles)) {
|
||||
String fileName = ossFiles.get(0).getFileName();
|
||||
String templateFileType = fileName.substring(fileName.lastIndexOf("."));
|
||||
if (".doc,.DOC,.docx,.DOCX".contains(templateFileType)) {
|
||||
paramsReportDetailEOService.exportCustomWord(paramsReportDetailVO, response, request);
|
||||
|
||||
// @ApiOperation(value = "上报库参数项-自定义导出excel")
|
||||
// @GetMapping(value = "/exportCustomExcel")
|
||||
//// @RequiresPermissions("report:detail:export:custom")
|
||||
// public void exportCustomExcel(ParamsReportDetailVO paramsReportDetailVO,
|
||||
// HttpServletResponse response,
|
||||
// HttpServletRequest request) {
|
||||
// paramsReportDetailEOService.exportCustomExcel(paramsReportDetailVO, response, request);
|
||||
// }
|
||||
} else if (".xls, .XLS,.xlsx,.XLSX".contains(templateFileType)) {
|
||||
paramsReportDetailEOService.exportCustomExcel(paramsReportDetailVO, response, request);
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new JeroBootException("没有找到导出模板!");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
|
||||
+4
-1
@@ -50,6 +50,9 @@ public interface IParamsReportDetailEOService extends IService<ParamsReportDetai
|
||||
// 导出模板下拉选项
|
||||
List<Map<String, String>> getTemplateLabelList();
|
||||
|
||||
void exportCustom(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request);
|
||||
// 自定义导出-word模板
|
||||
void exportCustomWord(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
void exportCustomExcel(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request);
|
||||
|
||||
}
|
||||
|
||||
+209
-59
@@ -1,5 +1,7 @@
|
||||
package com.jero.modules.cert.report.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
@@ -23,23 +25,25 @@ import com.jero.modules.cert.report.entity.*;
|
||||
import com.jero.modules.cert.report.enums.ExportTypeEnum;
|
||||
import com.jero.modules.cert.report.mapper.ParamsReportDetailEOMapper;
|
||||
import com.jero.modules.cert.report.service.*;
|
||||
import com.jero.modules.cert.report.util.Docx4jUtil;
|
||||
import com.jero.modules.cert.report.vo.ParamsReportDetailVO;
|
||||
import com.jero.modules.cert.template.enums.ControlTypeEnum;
|
||||
import com.jero.modules.ocr.util.LineHumpUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.project.util.WordUtil;
|
||||
import com.jero.modules.split.common.ReadExcel;
|
||||
import com.jero.modules.system.entity.SysDictItem;
|
||||
import com.jero.modules.system.service.ISysDictItemService;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.aspectj.util.FileUtil;
|
||||
import org.docx4j.Docx4J;
|
||||
import org.docx4j.openpackaging.exceptions.Docx4JException;
|
||||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@@ -504,7 +508,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
//创建临时文件夹
|
||||
String fileNowPath = uploadpath + "/tempZip/" + UUID.randomUUID().toString().replace("-","") + File.separator + fileOriName;
|
||||
File nowFile = new File(fileNowPath);
|
||||
if (nowFile.exists()){
|
||||
if (nowFile.exists()) {
|
||||
nowFile.delete();
|
||||
}
|
||||
nowFile.mkdirs();
|
||||
@@ -669,7 +673,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportCustom(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request) {
|
||||
public void exportCustomWord(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request) {
|
||||
OutputStream os = null;
|
||||
OutputStream wordOS = null;
|
||||
String fileOriName = "上报库参数项自定义导出信息";
|
||||
@@ -691,6 +695,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
// 查询导出数据
|
||||
List<Map> allParamsInfoList = queryForExportCustom(paramsReportDetailVO);
|
||||
Map<String, String> params = allParamsInfoList.get(0);
|
||||
List<Map<String, Object>> imgListAll = (List<Map<String, Object>>) allParamsInfoList.get(1).get("imgListAll");
|
||||
|
||||
String templateUrl = "";
|
||||
ParamsExportTemplateEO paramsExportTemplateEO = paramsExportTemplateEOService.getById(paramsReportDetailVO.getExportTemplateId());
|
||||
@@ -702,7 +707,7 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
// 替换模板中的占位符
|
||||
try {
|
||||
//下载关联文件内容
|
||||
List<OSSFile> allRelevFileList = (List<OSSFile>) allParamsInfoList.get(1).get("fileListAll");
|
||||
List<OSSFile> allRelevFileList = (List<OSSFile>) allParamsInfoList.get(2).get("fileListAll");
|
||||
if (allRelevFileList != null && !allRelevFileList.isEmpty()) {
|
||||
allRelevFileList = allRelevFileList.stream().distinct().collect(Collectors.toList());
|
||||
downLoadFileList(allRelevFileList,fileNowPath + File.separator + "导出文件");
|
||||
@@ -713,23 +718,15 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
wordOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
if (CosBootUtil.doesObjectExist(templateUrl)) {
|
||||
InputStream wordTemplate = CosBootUtil.download(templateUrl);
|
||||
com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS);
|
||||
}
|
||||
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(wordTemplate);
|
||||
// 替换占位符内容
|
||||
WordUtil.replacePictureBatch(wordMLPackage, imgListAll);
|
||||
WordUtil.replaceVariable(wordMLPackage, params);
|
||||
Docx4J.save(wordMLPackage, wordOS);
|
||||
|
||||
// 替换占位符内容
|
||||
byte[] wordContent = Docx4jUtil.of(fileNowPath + File.separator + repFileName)
|
||||
.addParams(params)
|
||||
.get();
|
||||
ByteArrayInputStream wordis = new ByteArrayInputStream(wordContent);
|
||||
OutputStream wordFileOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
int len1 = 0;
|
||||
while ((len1 = wordis.read()) != -1) {
|
||||
wordFileOS.write(len1);
|
||||
wordOS.flush();
|
||||
wordOS.close();
|
||||
}
|
||||
wordOS.flush();
|
||||
wordOS.close();
|
||||
wordFileOS.flush();
|
||||
wordFileOS.close();
|
||||
|
||||
// 打包导出压缩包
|
||||
response.setHeader("Content-Disposition",
|
||||
@@ -745,15 +742,16 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
}
|
||||
|
||||
// 添加导出历史
|
||||
/*String uploadFileName = fileOriName + ".zip";
|
||||
MultipartFile mFile = new MockMultipartFile(uploadFileName, uploadFileName, ContentType.APPLICATION_OCTET_STREAM.toString(), fis); // 用于上传
|
||||
String uploadFileName = fileOriName + ".zip";
|
||||
InputStream uploadFileio = new FileInputStream(new File(fileNowPath+".zip"));
|
||||
MultipartFile mFile = new MockMultipartFile(uploadFileName, uploadFileName, "text/plain", uploadFileio); // 用于上传
|
||||
OSSFile ossFile = ossFileService.uploadLocalOfCos(mFile, "/report", "", CutEnum.CN.getValue()); // 上传导出的压缩包
|
||||
ParamsReportExportHistoryEO paramsReportExportHistoryEO = new ParamsReportExportHistoryEO();
|
||||
paramsReportExportHistoryEO.setExportType(ExportTypeEnum.NORMAL.getValue());
|
||||
paramsReportExportHistoryEO.setExportType(ExportTypeEnum.CUSTOM.getValue());
|
||||
paramsReportExportHistoryEO.setExportFileId(ossFile.getId());
|
||||
paramsReportExportHistoryEO.setParamsManifestId(paramsReportDetailVO.getParamsManifestId());
|
||||
paramsReportExportHistoryEO.setExportTime(new Date());
|
||||
paramsReportExportHistoryEOService.add(paramsReportExportHistoryEO);*/
|
||||
paramsReportExportHistoryEOService.add(paramsReportExportHistoryEO);
|
||||
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
@@ -775,6 +773,90 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportCustomExcel(ParamsReportDetailVO paramsReportDetailVO, HttpServletResponse response, HttpServletRequest request) {
|
||||
OutputStream os = null;
|
||||
OutputStream wordOS = null;
|
||||
String fileOriName = "上报库参数项自定义导出信息";
|
||||
if (CutEnum.EN.getValue().equals(paramsReportDetailVO.getCut())) {
|
||||
fileOriName = "Params report custom data";
|
||||
}
|
||||
if (StringUtils.isNotEmpty(paramsReportDetailVO.getExportName())) {
|
||||
fileOriName = paramsReportDetailVO.getExportName();
|
||||
}
|
||||
//创建临时文件夹
|
||||
String fileNowPath = uploadpath + "/tempZip/" + UUID.randomUUID().toString().replace("-","") + File.separator + fileOriName;
|
||||
File nowFile = new File(fileNowPath);
|
||||
if (nowFile.exists()){
|
||||
nowFile.delete();
|
||||
}
|
||||
nowFile.mkdirs();
|
||||
String fileName = fileOriName + ".xlsx";
|
||||
|
||||
// 查询导出数据
|
||||
List<Map> allParamsInfoList = queryForExportCustom(paramsReportDetailVO);
|
||||
Map<String, Object> params = allParamsInfoList.get(0);
|
||||
|
||||
String templateUrl = "";
|
||||
ParamsExportTemplateEO paramsExportTemplateEO = paramsExportTemplateEOService.getById(paramsReportDetailVO.getExportTemplateId());
|
||||
List<OSSFile> ossFiles = ossFileService.getFileInfosByConnectId(paramsExportTemplateEO.getFileConnectId());
|
||||
if (CollectionUtil.isNotEmpty(ossFiles)) {
|
||||
templateUrl = ossFiles.get(0).getUrl();
|
||||
}
|
||||
|
||||
// 替换模板中的占位符
|
||||
try {
|
||||
|
||||
// 拿取模板
|
||||
String repFileName = fileName.replaceAll("/","_");
|
||||
wordOS = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
if (CosBootUtil.doesObjectExist(templateUrl)) {
|
||||
InputStream wordTemplate = CosBootUtil.download(templateUrl);
|
||||
com.qcloud.cos.utils.IOUtils.copy(wordTemplate, wordOS);
|
||||
}
|
||||
|
||||
// 替换占位符内容
|
||||
TemplateExportParams templateExportParams = new TemplateExportParams();
|
||||
templateExportParams.setTemplateUrl(fileNowPath + File.separator + repFileName);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(templateExportParams, params);
|
||||
|
||||
OutputStream word = new FileOutputStream(fileNowPath + File.separator + repFileName);
|
||||
workbook.write(word);
|
||||
wordOS.flush();
|
||||
wordOS.close();
|
||||
word.flush();
|
||||
word.close();
|
||||
|
||||
// 打包导出压缩包
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment; filename=\""+ ReadExcel.encodeFileName(fileOriName+".zip", request) +"\"");
|
||||
response.setContentType("application/force-download");
|
||||
response.flushBuffer();
|
||||
os = response.getOutputStream();
|
||||
ZipUtil.zip(fileNowPath,fileNowPath+".zip");
|
||||
FileInputStream fis = new FileInputStream(fileNowPath+".zip");
|
||||
int len2 = 0;
|
||||
while ((len2 = fis.read()) != -1) {
|
||||
os.write(len2);
|
||||
}
|
||||
|
||||
os.flush();
|
||||
os.close(); // 后开先关
|
||||
fis.close(); // 先开后关
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new JeroBootException("下载文件失败,请重试");
|
||||
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
IOUtils.closeQuietly(wordOS);
|
||||
File tempZipFile = new File(uploadpath + "/tempZip");
|
||||
FileUtil.deleteContents(tempZipFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void downLoadFileList(List<OSSFile> allRelevFileList,String fileNowPath) {
|
||||
File nowFile = new File(fileNowPath);
|
||||
if (nowFile.exists()){
|
||||
@@ -852,23 +934,23 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
ParamsReportConfigDataEO paramsConfigDataEO = paramsReportConfigDataEOService.queryByConfigIdAndCollectManifestId(paramsConfigId, paramsCollectManifestId); // 参数配置数据
|
||||
StringBuilder configDataBuilder = new StringBuilder(); // 重新组合配置数据
|
||||
if (StringUtils.isNotEmpty(paramsConfigDataEO.getTextData())) {
|
||||
configDataBuilder.append(paramsConfigDataEO.getTextData()).append("&");
|
||||
configDataBuilder.append(paramsConfigDataEO.getTextData()).append("#");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(paramsConfigDataEO.getPullData())) {
|
||||
configDataBuilder.append(paramsConfigDataEO.getPullData()).append("&");
|
||||
configDataBuilder.append(paramsConfigDataEO.getPullData()).append("#");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(paramsConfigDataEO.getFileConnectId())) {
|
||||
List<OSSFile> ossFileList = ossFileService.getFileInfosByConnectId(paramsConfigDataEO.getFileConnectId());
|
||||
if (CollectionUtil.isNotEmpty(ossFileList)) {
|
||||
configDataBuilder.append(ossFileList.get(0).getFileName()).append("&");
|
||||
configDataBuilder.append(ossFileList.get(0).getFileName()).append("#");
|
||||
|
||||
fileList.addAll(ossFileList);
|
||||
}
|
||||
}
|
||||
|
||||
String configData = configDataBuilder.toString();
|
||||
if (configData.contains("&")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("&"));
|
||||
if (configData.contains("#")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("#"));
|
||||
}
|
||||
|
||||
record1.put(paramsConfigEO.getId(), configData);
|
||||
@@ -902,17 +984,17 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
|
||||
StringBuilder configDataBuilder = new StringBuilder(); // 重新组合配置数据
|
||||
if (StringUtils.isNotEmpty(textDatas)) {
|
||||
configDataBuilder.append(textDatas).append("&");
|
||||
configDataBuilder.append(textDatas).append("#");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(pullDatas)) {
|
||||
configDataBuilder.append(pullDatas).append("&");
|
||||
configDataBuilder.append(pullDatas).append("#");
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(fileNameList)) {
|
||||
configDataBuilder.append(StringUtils.join(fileNameList, paramsReportDetailVO.getSeparator())).append("&");
|
||||
configDataBuilder.append(StringUtils.join(fileNameList, paramsReportDetailVO.getSeparator())).append("#");
|
||||
}
|
||||
configData = configDataBuilder.toString();
|
||||
if (configData.contains("&")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("&"));
|
||||
if (configData.contains("#")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("#"));
|
||||
}
|
||||
record1.put("params_value", configData);
|
||||
|
||||
@@ -925,77 +1007,145 @@ public class ParamsReportDetailEOServiceImpl extends ServiceImpl<ParamsReportDet
|
||||
}
|
||||
|
||||
private List<Map> queryForExportCustom(ParamsReportDetailVO paramsReportDetailVO) {
|
||||
paramsReportDetailVO.setSeparator("&"); // 设置分隔符
|
||||
paramsReportDetailVO.setSeparator("*"); // 设置分隔符
|
||||
|
||||
List<String> idList = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(paramsReportDetailVO.getIds())) {
|
||||
idList = Arrays.asList(paramsReportDetailVO.getIds().split(","));
|
||||
}
|
||||
List<String> configIdList = Arrays.asList(paramsReportDetailVO.getConfigIds().split(","));
|
||||
List<Map<String, Object>> dataList = paramsReportDetailEOMapper.listInfoForExport(idList, paramsReportDetailVO);
|
||||
List<String> configIdList = Arrays.asList(paramsReportDetailVO.getConfigIds().split(",")); // 需要导出的配置列
|
||||
List<Map<String, Object>> dataList = paramsReportDetailEOMapper.listInfoForExport(idList, paramsReportDetailVO); // 查询需要导出的数据
|
||||
|
||||
List<ParamsReportConfigEO> paramsConfigEOList = paramsReportConfigEOService.queryList(paramsReportDetailVO.getParamsManifestId()); // 查询所有配置列
|
||||
|
||||
List<Map> resultList = new ArrayList<>();
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
List<OSSFile> fileListAll = new ArrayList<>();
|
||||
|
||||
List<Map<String, Object>> imgListAll = new ArrayList<>(); // 存放图片信息
|
||||
List<OSSFile> fileListAll = new ArrayList<>(); // 存放文件
|
||||
String fileTypeStr = ".png,.PNG,.jfif,.JFIF,.pjpeg,.PJPEG,.jpeg,.JPEG,.pjp,.PJP,.jpg,.JPG";
|
||||
// 查询配置列数据
|
||||
for (Map<String, Object> record1 : dataList) {
|
||||
|
||||
String paramsCollectManifestId = (String) record1.get("id");
|
||||
String nioNumber = (String) record1.get("nio_number");
|
||||
String controlType = (String) record1.get("control_type");
|
||||
|
||||
if (CollectionUtil.isNotEmpty(paramsConfigEOList)) {
|
||||
List<OSSFile> fileList = new ArrayList<>();
|
||||
List<OSSFile> imgFileList = new ArrayList<>();
|
||||
|
||||
// 合并配置数据
|
||||
String configData = "";
|
||||
List<ParamsReportConfigDataEO> paramsReportConfigDataEOS = paramsReportConfigDataEOService.queryByConfigIdListAndCollectManifestId(configIdList, paramsCollectManifestId);
|
||||
|
||||
String textDatas = paramsReportConfigDataEOS.stream().filter(e->StringUtils.isNotEmpty(e.getTextData()))
|
||||
.map(ParamsReportConfigDataEO::getTextData).distinct().collect(Collectors.joining(paramsReportDetailVO.getSeparator()));
|
||||
.map(ParamsReportConfigDataEO::getTextData).distinct().collect(Collectors.joining(paramsReportDetailVO.getSeparator())); // 整合文本数据
|
||||
|
||||
String pullDatas = paramsReportConfigDataEOS.stream().filter(e->StringUtils.isNotEmpty(e.getPullData()))
|
||||
.map(ParamsReportConfigDataEO::getPullData).distinct().collect(Collectors.joining(paramsReportDetailVO.getSeparator()));
|
||||
.map(ParamsReportConfigDataEO::getPullData).distinct().collect(Collectors.joining(paramsReportDetailVO.getSeparator())); // 整合下拉数据
|
||||
|
||||
List<String> fileNameList = new ArrayList<>();
|
||||
paramsReportConfigDataEOS.forEach(paramsReportConfigDataEO -> {
|
||||
for (ParamsReportConfigDataEO paramsReportConfigDataEO : paramsReportConfigDataEOS) { // 获取”导出文件夹“下的文件
|
||||
if (StringUtils.isNotEmpty(paramsReportConfigDataEO.getFileConnectId())) {
|
||||
List<OSSFile> ossFileList = ossFileService.getFileInfosByConnectId(paramsReportConfigDataEO.getFileConnectId());
|
||||
if (CollectionUtil.isNotEmpty(ossFileList)) {
|
||||
fileNameList.add(ossFileList.get(0).getFileName());
|
||||
String fileName = ossFileList.get(0).getFileName();
|
||||
if (!fileTypeStr.contains(fileName.substring(fileName.lastIndexOf(".")))) { // 图片不放入”导出文件夹“下,直接插入正文
|
||||
fileNameList.add(ossFileList.get(0).getFileName());
|
||||
|
||||
fileList.addAll(ossFileList);
|
||||
fileList.addAll(ossFileList);
|
||||
} else {
|
||||
imgFileList.addAll(ossFileList);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
fileListAll.addAll(fileList);
|
||||
|
||||
StringBuilder configDataBuilder = new StringBuilder(); // 重新组合配置数据
|
||||
if (StringUtils.isNotEmpty(textDatas)) {
|
||||
configDataBuilder.append(textDatas).append("&");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(pullDatas)) {
|
||||
configDataBuilder.append(pullDatas).append("&");
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(fileNameList)) {
|
||||
configDataBuilder.append(StringUtils.join(fileNameList, ",")).append("&");
|
||||
}
|
||||
configData = configDataBuilder.toString();
|
||||
if (configData.contains("&")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("&"));
|
||||
}
|
||||
resultMap.put(nioNumber, configData);
|
||||
if ((ControlTypeEnum.FILE.getValue().equals(controlType)
|
||||
|| ControlTypeEnum.TEXT_FILE.getValue().equals(controlType)
|
||||
|| ControlTypeEnum.PULL_SINGLE_FILE.getValue().equals(controlType)
|
||||
|| ControlTypeEnum.PULL_MORE_FILE.getValue().equals(controlType)
|
||||
|| ControlTypeEnum.TEXT_PULL_SINGLE_FILE.getValue().equals(controlType)) && CollectionUtil.isNotEmpty(imgFileList)) {
|
||||
|
||||
// 获取图片字节
|
||||
// 附件为图片类型的配置数据,直接插入正文
|
||||
Map<String, Object> imgMap = new HashMap<>();
|
||||
List<byte[]> bytesList =new ArrayList<>();
|
||||
|
||||
fileListAll.addAll(fileList);
|
||||
int lengthTotal = 0; // 总长度
|
||||
for (OSSFile ossFile : imgFileList){
|
||||
if (CosBootUtil.doesObjectExist(ossFile.getUrl())) {
|
||||
InputStream is = CosBootUtil.download(ossFile.getUrl());
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try {
|
||||
IOUtils.copy(is, os);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new JeroBootException(e.getMessage());
|
||||
}
|
||||
byte[] bytes = os.toByteArray();
|
||||
lengthTotal += bytes.length;
|
||||
bytesList.add(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并多个bytes
|
||||
byte[] totalByte = new byte[lengthTotal];
|
||||
int begin = 0;
|
||||
for (byte[] bytes : bytesList){
|
||||
System.arraycopy(bytes, 0, totalByte, begin, bytes.length);
|
||||
begin += bytes.length;
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(textDatas)) {
|
||||
configDataBuilder.append(textDatas).append("#"); //
|
||||
}
|
||||
if (StringUtils.isNotEmpty(pullDatas)) {
|
||||
configDataBuilder.append(pullDatas).append("#"); //
|
||||
}
|
||||
configData = configDataBuilder.toString();
|
||||
if (configData.contains("#")) { //
|
||||
configData = configData.substring(0, configData.lastIndexOf("#"));
|
||||
}
|
||||
|
||||
imgMap.put("key", nioNumber);
|
||||
imgMap.put("text", configData);
|
||||
imgMap.put("bytes", totalByte);
|
||||
|
||||
imgListAll.add(imgMap);
|
||||
|
||||
} else {
|
||||
|
||||
if (StringUtils.isNotEmpty(textDatas)) {
|
||||
configDataBuilder.append(textDatas).append("#");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(pullDatas)) {
|
||||
configDataBuilder.append(pullDatas).append("#");
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(fileNameList)) {
|
||||
configDataBuilder.append(StringUtils.join(fileNameList, ",")).append("#");
|
||||
}
|
||||
configData = configDataBuilder.toString();
|
||||
if (configData.contains("#")) {
|
||||
configData = configData.substring(0, configData.lastIndexOf("#"));
|
||||
}
|
||||
|
||||
resultMap.put(nioNumber, configData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> imgMap = new HashMap<>();
|
||||
imgMap.put("imgListAll", imgListAll);
|
||||
Map<String, Object> fileMap = new HashMap<>();
|
||||
fileMap.put("fileListAll", fileListAll);
|
||||
|
||||
resultList.add(resultMap);
|
||||
resultList.add(imgMap);
|
||||
resultList.add(fileMap);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user