feat:add

This commit is contained in:
nieziyan 2023-10-27 19:45:03 +08:00
parent 789a67bd03
commit 8dd0ddd2dd
2 changed files with 62 additions and 39 deletions

View File

@ -1,7 +1,9 @@
package org.jeecg.common.util; package org.jeecg.common.util;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import org.apache.commons.io.FileUtils;
import org.apache.poi.ss.usermodel.Workbook; 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;
@ -15,6 +17,8 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -102,9 +106,23 @@ public class ExportUtil {
String pathPrefix = "excelTemplate/"; String pathPrefix = "excelTemplate/";
String path = pathPrefix + template; String path = pathPrefix + template;
InputStream inputStream = classPathStream(path); InputStream inputStream = classPathStream(path);
String tempDir = System.getProperty("java.io.tmpdir");
String templatePath = ""; String tempPath = tempDir + File.separator + template;
try {
File tempFile = File.createTempFile(tempPath, null);
FileUtils.copyInputStreamToFile(inputStream, tempFile);
String templatePath = tempFile.getAbsolutePath();
return new TemplateExportParams(templatePath); return new TemplateExportParams(templatePath);
} catch (IOException e) {
e.printStackTrace();
return null;
}finally {
try {
if (ObjectUtil.isNotNull(inputStream)) inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
public static void exportXls(HttpServletResponse response, String template, public static void exportXls(HttpServletResponse response, String template,

View File

@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@ -4398,11 +4399,16 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
analyze.put("gasRoi", roiChannels(roiChannelsDtosG)); analyze.put("gasRoi", roiChannels(roiChannelsDtosG));
analyze.putAll(roiResults(roiResultsDtos)); analyze.putAll(roiResults(roiResultsDtos));
analyze.put("resultSummary", xeResults(xeResultsDtos)); analyze.put("resultSummary", xeResults(xeResultsDtos));
PrintWriter writer = null;
try {
// 使数据适配导出模板 // 使数据适配导出模板
String pathPrefix = "excelTemplate/"; String pathPrefix = "excelTemplate/";
String path = pathPrefix + SAVETOTXT.getName(); String path = pathPrefix + SAVETOTXT.getName();
String template = ClassUtil.classPath(path); /*String template = ClassUtil.classPath(path);
List<String> lines = FileUtil.readUtf8Lines(template); List<String> lines = FileUtil.readUtf8Lines(template);*/
InputStream inputStream = ClassUtil.classPathStream(path);
List<String> lines = IOUtils.readLines(inputStream, "UTF-8");
// 正则表达式匹配${}中的内容 // 正则表达式匹配${}中的内容
String regex = "\\$\\{([^}]+)}"; String regex = "\\$\\{([^}]+)}";
List<String> newLines = new ArrayList<>(); List<String> newLines = new ArrayList<>();
@ -4430,8 +4436,7 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
if (!CollUtil.contains(skip, line)) if (!CollUtil.contains(skip, line))
newLines.add(line); newLines.add(line);
} }
PrintWriter writer = null;
try {
String export = "SaveToTxt.txt"; String export = "SaveToTxt.txt";
writer = ExportUtil.streamWriter(response, export); writer = ExportUtil.streamWriter(response, export);
for (String newLine : newLines) { for (String newLine : newLines) {