package com.caesolver.server; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class SolverFemOrderUtil { @Value("${FEM.workdir}") private String fem_workdir; @Value("${FEM.exePath}") private String exePath; @Value("${FEM.postPath}") private String postPath; @Value("${FEM.rootPath}") private String rootPath; public String createOrder(String projectId) throws IOException { String jobOrder=""; if(this.isWindows()) {//windows jobOrder=createWindowBat(projectId); }else {//Linux // jobOrder=createUnixexe(projectId); } return jobOrder; } private String getUgriName(String flow_dir) { String short_1=flow_dir.substring(0, flow_dir.length()-1); short_1.lastIndexOf("/"); String ugrname =short_1.substring(short_1.lastIndexOf("/")+1,short_1.length()); return ugrname; } /** * 创建 windows 下bat 执行文件 * @param caeProject * @param reader * @return * @throws IOException */ private String createWindowBat(String projectId) throws IOException { Path pFilePaths = Files.walk(Paths.get(this.fem_workdir+"/"+projectId)) .filter(path -> !path.toFile().isDirectory()) .filter(path->path.endsWith("fem_analysis.in")) .collect(Collectors.toList()).get(0); String flow_dir =pFilePaths.toString().replace("fem_analysis.in", "").replace("\\", "/"); String flow_wind_dir =flow_dir; Path dbfPath = Files.walk(Paths.get(this.fem_workdir+"/"+projectId)) .filter(path -> !path.toFile().isDirectory()) .filter(path-> path.toString().endsWith(".bdf")) .collect(Collectors.toList()).get(0); String dateInDbf =dbfPath.toString().replace("\\", "/"); String gridname =getUgriName(flow_dir); String dateOutFE =flow_dir+"data_out/"+gridname+"_FE.rst"; String dateOutFENS =flow_dir+"data_out/"+gridname+"_FE_NS.rst"; String dateOutTransient=flow_dir+"data_out/"+"dynamicResponse-transient"; File batFile = new File(flow_dir+ "fem.bat"); FileWriter writer =null; try { if (batFile.exists()) { batFile.delete(); } batFile.createNewFile(); writer = new FileWriter(batFile,true); writer.write(rootPath+":"); writer.write("\r\n");//换行 writer.write("cd "+flow_wind_dir); writer.write("\r\n");//换行 writer.write(exePath+" -p "+"\""+flow_wind_dir+"\"" +" -c fem_analysis.in"); writer.write("\r\n");//换行 writer.write(postPath +" "+dateInDbf+" "+dateOutFE+" "+dateOutFENS+" "+dateOutTransient); writer.write("\r\n");//换行 writer.close(); }catch (Exception o){ o.printStackTrace(); }finally { if (writer != null) { try { writer.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return flow_wind_dir+"fem.bat"; } private boolean isWindows() { return System.getProperty("os.name").toUpperCase().indexOf("WINDOWS")>=0?true:false; } }