feat:processFile

This commit is contained in:
nieziyan 2023-10-20 16:56:29 +08:00
parent a6de89bc0d
commit 12d13d5852
3 changed files with 116 additions and 1 deletions

View File

@ -45,7 +45,8 @@ public class ExportUtil {
response.setCharacterEncoding(UTF_8);
response.setContentType("application/octet-stream");
String name = URLEncoder.encode(fileName, UTF_8);
response.setHeader("Content-disposition", "attachment;filename=" + name);
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment;filename=" + name);
return response.getOutputStream();
}
public static PrintWriter streamWriter(HttpServletResponse response, String fileName) throws IOException {

View File

@ -0,0 +1,110 @@
package org.jeecg.modules;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import java.io.*;
import java.util.*;
public class Demo {
public static Map<String, NuclideInfo> processFile(File file){
Map<String, NuclideInfo> m_mapNuclideInfo = new TreeMap<>();
if (ObjectUtil.isNull(file)) return m_mapNuclideInfo;
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String nucline_flag = "-----------------------------------------";
String energy_flag = "REL. IMPULSANZ. KORR.FAKTOR";
String line = reader.readLine();
String nucName;
while (line != null) {
if (line.trim().equals(nucline_flag)) {
line = reader.readLine(); // 空行
nucName = reader.readLine().trim(); // 核素名称
nucName = StrUtil.subBefore(nucName, " ", false);
while (line != null && !line.trim().equals(nucline_flag)) {
if (line.trim().equals(energy_flag)) {
line = reader.readLine(); // 空行
line = reader.readLine();
List<Double> energyList = new LinkedList<>();
List<Double> factorList = new LinkedList<>();
while (line != null && !line.trim().isEmpty()) {
List<String> strList = StrUtil.splitTrim(line.trim(), " ");
if (strList.size() == 3) {
energyList.add(Double.parseDouble(strList.get(0)));
factorList.add(Double.parseDouble(strList.get(2)));
}
line = reader.readLine();
}
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setEnergy(energyList);
nuclideInfo.setFactor(factorList);
m_mapNuclideInfo.put(nucName, nuclideInfo);
} else {
line = reader.readLine();
}
}
} else {
line = reader.readLine();
}
}
} catch (IOException e) {
e.printStackTrace();
}
// 排序
for (NuclideInfo ni : m_mapNuclideInfo.values()) {
for (int i = 0; i < ni.energy.size() - 1; ++i) {
for (int j = i + 1; j < ni.energy.size(); ++j) {
if (ni.energy.get(i) > ni.energy.get(j)) {
double tempEnergy = ni.energy.get(i);
double tempFactor = ni.factor.get(i);
ni.energy.set(i, ni.energy.get(j));
ni.factor.set(i, ni.factor.get(j));
ni.energy.set(j, tempEnergy);
ni.factor.set(j, tempFactor);
}
}
}
}
return m_mapNuclideInfo;
}
private static class NuclideInfo {
List<Double> energy;
List<Double> factor;
public List<Double> getEnergy() {
return energy;
}
public void setEnergy(List<Double> energy) {
this.energy = energy;
}
public List<Double> getFactor() {
return factor;
}
public void setFactor(List<Double> factor) {
this.factor = factor;
}
NuclideInfo() {
energy = new LinkedList<>();
factor = new LinkedList<>();
}
@Override
public String toString() {
return "NuclideInfo{" +
"energy=" + energy +
", factor=" + factor +
'}';
}
}
}

View File

@ -4511,6 +4511,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
//设置响应类型
response.setContentType("application/octet-stream");
//解决中文不能生成文件
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(IecName,"UTF-8"));
fos = response.getOutputStream();
fos.write(iecValue.getBytes());
@ -4556,6 +4557,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
//设置响应类型
response.setContentType("application/octet-stream");
//解决中文不能生成文件
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(ImsName,"UTF-8"));
fos = response.getOutputStream();
fos.write(imsValue.getBytes());
@ -4596,6 +4598,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
//设置响应类型
response.setContentType("application/octet-stream");
//解决中文不能生成文件
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(ImsName,"UTF-8"));
fos = response.getOutputStream();
fos.write(imsValue.getBytes());
@ -4682,6 +4685,7 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
//设置响应类型
response.setContentType("application/octet-stream");
//解决中文不能生成文件
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(IecName,"UTF-8"));
fos = response.getOutputStream();
fos.write(iecValue.getBytes());