package com.miniframe.solverconfig.hcfd; import com.miniframe.constant.MFConstant; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.model.system.*; import com.miniframe.model.system.dao.SysFileMapper; import com.miniframe.tools.XIDateTimeUtils; import com.miniframe.tools.XIFileUtils; import java.io.*; import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.*; /** * 对执行所需要的文件进行文件夹规整已满足求解 */ public class HcfdPath { public static List hcfdTeps(String pid) throws Exception{ String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+pid; String exePath = jobPath+ MFConstant.separator+"hcfd"; String testPath = exePath+ MFConstant.separator+"test"; String exeOutPath = testPath+ MFConstant.separator+"data_out"; File exeOutDir = new File(exeOutPath); if(!exeOutDir.exists()){ throw new BusinessException("EB4000017"); } List steps = new ArrayList<>(); File[] files =exeOutDir.listFiles(); for (File sonFile: files) { if(sonFile.getName().indexOf("hcfd_tec_boundary_timestep")>-1){ String stip=sonFile.getName().replace("hcfd_tec_boundary_timestep","").replace(".dat",""); steps.add(Integer.valueOf(stip)); } } Collections.sort(steps); return steps; } public static void hcfdCreatPath(AdiModeling modeling, AdiSolverConfig config, AdiSolverJob job ) throws IOException { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+job.getPid(); System.out.println(jobPath); String exePath = jobPath+ MFConstant.separator+"hcfd"; String exeInPath = exePath+ MFConstant.separator+"data_in"; File exeInDir = new File(exeInPath); if(!exeInDir.exists()){ exeInDir.mkdirs(); } String testPath = exePath+ MFConstant.separator+"test"; String exeOutPath = testPath+ MFConstant.separator+"data_out"; File exeOutDir = new File(exeOutPath); if(!exeOutDir.exists()){ exeOutDir.mkdirs(); } SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); SysFile nmlFile= fileMapper.selectByPrimaryKey(config.getNmlFile()); fileMove(nmlFile,testPath+MFConstant.separator+"hcfd.nml"); SysFile mapbcFile= fileMapper.selectByPrimaryKey(config.getMapbcFile()); fileMove(mapbcFile,exeInPath+MFConstant.separator+"hcfd.mapbc"); SysFile grid= fileMapper.selectByPrimaryKey(modeling.getGridFile()); fileMove(grid,exeInPath+MFConstant.separator+"hcfd.ugrid"); } /** * 文件移动 * @param file * @param pathStr * @throws IOException */ public static void fileMove(SysFile file ,String pathStr) throws IOException { Path path = Paths.get(pathStr); SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); Files.move(Paths.get( XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()), path, StandardCopyOption.REPLACE_EXISTING); String fielRelativePath = XIFileUtils.getRelativizePathStr(path); file.setFilepath(fielRelativePath); file.setFilename(path.getFileName().toString()); fileMapper.updateByPrimaryKey(file); } public static void main(String[] args) { String stip="hcfd_tec_boundary_timestep100.dat".replace("hcfd_tec_boundary_timestep","").replace(".dat",""); Integer s ="hcfd_tec_boundary_timestep100.dat".indexOf("hcf2d_tec_boundary_timestep"); System.out.println(s); } }