feat:add
This commit is contained in:
parent
789a67bd03
commit
8dd0ddd2dd
|
@ -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;
|
||||||
return new TemplateExportParams(templatePath);
|
try {
|
||||||
|
File tempFile = File.createTempFile(tempPath, null);
|
||||||
|
FileUtils.copyInputStreamToFile(inputStream, tempFile);
|
||||||
|
String templatePath = tempFile.getAbsolutePath();
|
||||||
|
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,
|
||||||
|
|
|
@ -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,45 +4399,49 @@ 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));
|
||||||
// 使数据适配导出模板
|
|
||||||
String pathPrefix = "excelTemplate/";
|
|
||||||
String path = pathPrefix + SAVETOTXT.getName();
|
|
||||||
String template = ClassUtil.classPath(path);
|
|
||||||
List<String> lines = FileUtil.readUtf8Lines(template);
|
|
||||||
// 正则表达式,匹配${}中的内容
|
|
||||||
String regex = "\\$\\{([^}]+)}";
|
|
||||||
List<String> newLines = new ArrayList<>();
|
|
||||||
List<String> list = ListUtil.toList("sampleNewCalibration","sampleRoi", "detNewCalibration", "detRoi", "gasNewCalibration", "gasRoi","grossRoi",
|
|
||||||
"netRoi", "concRoi", "resultSummary");
|
|
||||||
List<String> skip = ListUtil.toList("${sampleNewCalibration}","${sampleRoi}", "${detNewCalibration}", "${detRoi}", "${gasNewCalibration}", "${gasRoi}",
|
|
||||||
"${grossRoi}", "${netRoi}", "${concRoi}", "${resultSummary}");
|
|
||||||
for (String line : lines) {
|
|
||||||
List<String> fieldNames = ReUtil.findAllGroup1(regex, line);
|
|
||||||
if (CollUtil.isEmpty(fieldNames)){
|
|
||||||
newLines.add(line);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (String fieldName : fieldNames) {
|
|
||||||
Object value = analyze.get(fieldName);
|
|
||||||
if (CollUtil.contains(list, fieldName)){
|
|
||||||
newLines.addAll((List<String>)value);
|
|
||||||
}else {
|
|
||||||
String search = "${" + fieldName + "}";
|
|
||||||
String replacement = StrUtil.toString(value);
|
|
||||||
replacement = StrUtil.isBlank(replacement) ? "null" : replacement;
|
|
||||||
line = StrUtil.replace(line, search, replacement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!CollUtil.contains(skip, line))
|
|
||||||
newLines.add(line);
|
|
||||||
}
|
|
||||||
PrintWriter writer = null;
|
PrintWriter writer = null;
|
||||||
try {
|
try {
|
||||||
String export = "SaveToTxt.txt";
|
// 使数据适配导出模板
|
||||||
writer = ExportUtil.streamWriter(response, export);
|
String pathPrefix = "excelTemplate/";
|
||||||
for (String newLine : newLines) {
|
String path = pathPrefix + SAVETOTXT.getName();
|
||||||
writer.println(newLine);
|
/*String template = ClassUtil.classPath(path);
|
||||||
|
List<String> lines = FileUtil.readUtf8Lines(template);*/
|
||||||
|
InputStream inputStream = ClassUtil.classPathStream(path);
|
||||||
|
List<String> lines = IOUtils.readLines(inputStream, "UTF-8");
|
||||||
|
// 正则表达式,匹配${}中的内容
|
||||||
|
String regex = "\\$\\{([^}]+)}";
|
||||||
|
List<String> newLines = new ArrayList<>();
|
||||||
|
List<String> list = ListUtil.toList("sampleNewCalibration","sampleRoi", "detNewCalibration", "detRoi", "gasNewCalibration", "gasRoi","grossRoi",
|
||||||
|
"netRoi", "concRoi", "resultSummary");
|
||||||
|
List<String> skip = ListUtil.toList("${sampleNewCalibration}","${sampleRoi}", "${detNewCalibration}", "${detRoi}", "${gasNewCalibration}", "${gasRoi}",
|
||||||
|
"${grossRoi}", "${netRoi}", "${concRoi}", "${resultSummary}");
|
||||||
|
for (String line : lines) {
|
||||||
|
List<String> fieldNames = ReUtil.findAllGroup1(regex, line);
|
||||||
|
if (CollUtil.isEmpty(fieldNames)){
|
||||||
|
newLines.add(line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (String fieldName : fieldNames) {
|
||||||
|
Object value = analyze.get(fieldName);
|
||||||
|
if (CollUtil.contains(list, fieldName)){
|
||||||
|
newLines.addAll((List<String>)value);
|
||||||
|
}else {
|
||||||
|
String search = "${" + fieldName + "}";
|
||||||
|
String replacement = StrUtil.toString(value);
|
||||||
|
replacement = StrUtil.isBlank(replacement) ? "null" : replacement;
|
||||||
|
line = StrUtil.replace(line, search, replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!CollUtil.contains(skip, line))
|
||||||
|
newLines.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String export = "SaveToTxt.txt";
|
||||||
|
writer = ExportUtil.streamWriter(response, export);
|
||||||
|
for (String newLine : newLines) {
|
||||||
|
writer.println(newLine);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}finally {
|
}finally {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user