event
This commit is contained in:
parent
a30dabb454
commit
2b4c97dab3
|
|
@ -63,4 +63,10 @@ public class RunProcessController {
|
|||
return Result.OK("运行成功!");
|
||||
}
|
||||
|
||||
@PostMapping(value = "/runTest")
|
||||
public Result<String> runTest(String engineeringId) {
|
||||
runProcessService.runTest(engineeringId);
|
||||
return Result.OK("运行成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ import org.jeecg.runProcess.VO.RunProcessParamVO;
|
|||
import java.util.Map;
|
||||
|
||||
public interface RunProcessService {
|
||||
public void runTest(String engineeringId);
|
||||
Result<String> runAllExe(RunProcessParamVO paramVO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,19 @@ public class RunProcessServiceImpl implements RunProcessService {
|
|||
private final EventServerProperties eventServerProperties;
|
||||
private final EventTypeService eventTypeService;
|
||||
|
||||
@Override
|
||||
public void runTest(String engineeringId){
|
||||
Engineering engineering = engineeringService.getById(engineeringId);
|
||||
Wrf wrf = wrfService.getOne(new LambdaQueryWrapper<Wrf>().eq(Wrf::getEnginId,engineeringId));
|
||||
//各种路径前缀
|
||||
String allRunPath = baseAPIService.buildEngineeringFilePath("" ,engineering.getCreateBy(), engineering.getEngineeringName());
|
||||
String resultFilePath = baseAPIService.buildEngineeringFilePath(eventServerProperties.getResultFilePrefix() ,engineering.getCreateBy(), engineering.getEngineeringName());
|
||||
//生成CMAQ脚本
|
||||
genMcipRunShell(allRunPath, resultFilePath, wrf);
|
||||
//运行CMAQ程序
|
||||
Result<String> cmaqResult = cmaqService.runAllCmaq(engineering, wrf);
|
||||
System.out.println();
|
||||
}
|
||||
@Override
|
||||
public Result<String> runAllExe(RunProcessParamVO paramVO){
|
||||
try{
|
||||
|
|
@ -58,12 +71,12 @@ public class RunProcessServiceImpl implements RunProcessService {
|
|||
return wrfResult;
|
||||
}
|
||||
//生成CMAQ脚本
|
||||
// genMcipRunShell(allRunPath,resultFilePath,mcipPath,wrf);
|
||||
genMcipRunShell(allRunPath, resultFilePath, wrf);
|
||||
//运行CMAQ程序
|
||||
// Result<String> cmaqResult = cmaqService.runAllCmaq(engineering, wrf);
|
||||
// if(!cmaqResult.isSuccess()){
|
||||
// return cmaqResult;
|
||||
// }
|
||||
Result<String> cmaqResult = cmaqService.runAllCmaq(engineering, wrf);
|
||||
if(!cmaqResult.isSuccess()){
|
||||
return cmaqResult;
|
||||
}
|
||||
|
||||
String sDate = wrf.getStartTime().substring(0, 10).replace("-","");
|
||||
String eDate = LocalDateTime.parse( wrf.getEndTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
|
|
@ -101,14 +114,11 @@ public class RunProcessServiceImpl implements RunProcessService {
|
|||
return Result.OK("运行成功!");
|
||||
}
|
||||
|
||||
// private void executePythonScript(String sDate, String eDate, String vNames, String inputPath,
|
||||
// String outputPath, String outFileName, String pattern, String desc) {
|
||||
|
||||
public Result<String> genWrfRunShell(String allRunPath, String scriptsPath, Wrf wrf) {
|
||||
try {
|
||||
wrfService.genWpsShell(scriptsPath, "run_wps.sh", wrf);
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_wps.sh", wrf.getStartTime(), wrf.getRunDays(),"./run_wps.sh");
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_wrf.sh", wrf.getStartTime(), wrf.getRunDays(),"./run_wrf.sh");
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_wps.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_wrf.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("生成Txt文件异常!");
|
||||
|
|
@ -117,30 +127,21 @@ public class RunProcessServiceImpl implements RunProcessService {
|
|||
|
||||
}
|
||||
|
||||
// public Result<String> genMcipRunShell(String allRunPath ,String resultFilePath, String scriptsPath ,String mcipPath ,Wrf wrf) {
|
||||
// try {
|
||||
// genProjectShell(allRunPath,resultFilePath,scriptsPath,"run_project_mcip.sh",wrf.getStartTime(),wrf.getRunDays(),"./run_mcip.sh");
|
||||
// genProjectShell(allRunPath,resultFilePath,scriptsPath,"run_project_icon.sh",wrf.getStartTime(),wrf.getRunDays(),"./run_icon.sh");
|
||||
// genProjectShell(allRunPath,resultFilePath,scriptsPath,"run_project_bcon.sh",wrf.getStartTime(),wrf.getRunDays(),"./run_bcon.sh");
|
||||
// genProjectShell(allRunPath,resultFilePath,scriptsPath,"run_project_cctm.sh",wrf.getStartTime(),wrf.getRunDays(),"./run_cctm.sh");
|
||||
//
|
||||
// genPython(allRunPath,resultFilePath,mcipPath,"ocean_base.py","ocean_base_tem.py");
|
||||
// genPython(allRunPath,resultFilePath,mcipPath,"ocean_update.py","ocean_update_tem.py");
|
||||
// genPython(allRunPath,resultFilePath,mcipPath,"emis_base_sf6.py","emis_base_sf6_tem.py");
|
||||
// genPython(allRunPath,resultFilePath,mcipPath,"emis_update_emis_ic.py","emis_update_emis_ic_tem.py");
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return Result.error("生成Txt文件异常!");
|
||||
// } catch (SftpException e) {
|
||||
// e.printStackTrace();
|
||||
// return Result.error("生成脚本文件异常!");
|
||||
// }
|
||||
// return Result.ok();
|
||||
//
|
||||
// }
|
||||
public Result<String> genMcipRunShell(String allRunPath , String scriptsPath, Wrf wrf) {
|
||||
try {
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_mcip.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_icon.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_bcon.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
genProjectShell(allRunPath, scriptsPath, "run_project_cctm.sh", wrf.getStartTime(), wrf.getRunDays());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("生成Txt文件异常!");
|
||||
}
|
||||
return Result.ok();
|
||||
|
||||
private String genProjectShell(String allRunPath, String scriptsPath, String fileName, String startTime, String runDays ,String runShellCmd) throws IOException {
|
||||
}
|
||||
|
||||
private String genProjectShell(String allRunPath, String scriptsPath, String fileName, String startTime, String runDays) throws IOException {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime startDateTime = LocalDateTime.parse(startTime, formatter);
|
||||
String templateContent = Files.readString(Path.of(scriptsPath, fileName));
|
||||
|
|
@ -149,22 +150,11 @@ public class RunProcessServiceImpl implements RunProcessService {
|
|||
.replace("#{YEAR}", String.valueOf(startDateTime.getYear()))
|
||||
.replace("#{MONTH}", String.format("%02d", startDateTime.getMonthValue()))
|
||||
.replace("#{DAY}", String.format("%02d", startDateTime.getDayOfMonth()))
|
||||
.replace("#{RUN_DAYS}", runDays)
|
||||
.replace("#{runShellCmd}", runShellCmd);
|
||||
.replace("#{RUN_DAYS}", runDays);
|
||||
Files.writeString(Path.of(scriptsPath, fileName), processedContent, StandardCharsets.UTF_8);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// private String genPython(String allRunPath,String mcipPath,String fileName,String temFileName) throws IOException, SftpException {
|
||||
//
|
||||
// String data = new String(readAllBytes(get(eventServerProperties.getCshTemFilePath() + "/" + temFileName)));
|
||||
// data = data.replace("#{base_path}", allRunPath);
|
||||
// FileUtil.writeString(data, resultFilePath + fileName, "UTF-8");
|
||||
// sftpAPIService.sftpUpload(resultFilePath + fileName,mcipPath, fileName);
|
||||
//
|
||||
// return fileName;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 执行Python脚本
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package org.jeecg.sync.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.modules.base.entity.Cmaq;
|
||||
import org.jeecg.modules.base.entity.Engineering;
|
||||
import org.jeecg.modules.base.entity.Wrf;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -12,6 +15,7 @@ import org.jeecg.modules.base.entity.Cmaq;
|
|||
*/
|
||||
public interface CmaqService extends IService<Cmaq> {
|
||||
|
||||
Result<String> runAllCmaq(Engineering engineering, Wrf wrf);
|
||||
Cmaq getCmaqTem(Integer sceneType);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,38 @@
|
|||
package org.jeecg.sync.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.baseAPI.service.BaseAPIService;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.properties.EventServerProperties;
|
||||
import org.jeecg.common.util.RemoteExecuteCommand;
|
||||
import org.jeecg.engineering.service.EngineeringService;
|
||||
import org.jeecg.modules.base.entity.Engineering;
|
||||
import org.jeecg.modules.base.entity.Wrf;
|
||||
import org.jeecg.modules.base.mapper.WrfMapper;
|
||||
import org.jeecg.sync.service.CmaqService;
|
||||
import org.jeecg.common.exception.JeecgBootException;
|
||||
import org.jeecg.modules.base.entity.Cmaq;
|
||||
import org.jeecg.modules.base.mapper.CmaqMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.nio.file.Paths.get;
|
||||
|
||||
/**
|
||||
* @Description: CMAQ
|
||||
* @Author: jeecg-boot
|
||||
|
|
@ -15,8 +40,158 @@ import org.springframework.stereotype.Service;
|
|||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CmaqServiceImpl extends ServiceImpl<CmaqMapper, Cmaq> implements CmaqService {
|
||||
|
||||
private final BaseAPIService baseAPIService;
|
||||
private final EventServerProperties eventServerProperties;
|
||||
|
||||
@Override
|
||||
public Result<String> runAllCmaq(Engineering engineering, Wrf wrf){
|
||||
Cmaq cmaq = this.baseMapper.selectOne(new LambdaQueryWrapper<Cmaq>().eq(Cmaq::getEnginId,engineering.getId()));
|
||||
//各种路径前缀
|
||||
String allRunPath = baseAPIService.buildEngineeringFilePath("" ,engineering.getCreateBy(), engineering.getEngineeringName());
|
||||
String targetFilePath = baseAPIService.buildEngineeringFilePath(eventServerProperties.getResultFilePrefix() ,engineering.getCreateBy(), engineering.getEngineeringName());
|
||||
// String targetFilePath = localFilePrefix + engineering.getCreateBy() + "/" + engineering.getEngineeringName() + "/";
|
||||
String workdirPath = allRunPath + "workdir/";
|
||||
String mcipPath = allRunPath + "workdir/MCIP/";
|
||||
String shRunPath = "cd " + allRunPath + "scripts/;";
|
||||
|
||||
//运行mcip程序
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
shRunPath + "chmod +x run_project_mcip.sh;./run_project_mcip.sh");
|
||||
|
||||
//将mcip文件拷贝到指定目录
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
"cp -rf " + allRunPath + "scripts/mcip/* " + mcipPath);
|
||||
|
||||
//下载mcip结果文件
|
||||
File griddescFile = new File(targetFilePath + "GRIDDESC.d03");
|
||||
boolean mcipSuccesfully = griddescFile.exists();
|
||||
if(!mcipSuccesfully){
|
||||
return Result.error("MCIP运行失败,请查看日志信息!");
|
||||
}
|
||||
|
||||
//生成McipTxt文件
|
||||
genMcipTxtFile(targetFilePath, cmaq, wrf.getRefLon(), wrf.getRefLat());
|
||||
|
||||
//运行部分脚本
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath ,"ocean_base.py",""));
|
||||
// RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(), runPyPath(mcipPath ,"ocean_update.py",""));
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath ,"emis_base_sf6.py",""));
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath ,"1exportZF.py",""));
|
||||
|
||||
String sDate = wrf.getStartTime().substring(0, 10).replace("-","");
|
||||
//工程总运行天数
|
||||
Integer sumDay = Integer.valueOf(wrf.getAnalogTime()) / 24;
|
||||
String metcr03dName= "METCRO3D_d03_" + sDate;
|
||||
List<String> locMetValues = new ArrayList<>();
|
||||
locMetValues.add("latitude=" + wrf.getRefLat());
|
||||
locMetValues.add("lontitude=" + wrf.getRefLon());
|
||||
locMetValues.add("mcip=" + metcr03dName);
|
||||
FileUtil.writeLines(locMetValues, targetFilePath + "loc_met.txt", "UTF-8");
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath ,"2generateMultiPointEmis_icupdate_v1.py","emis"));
|
||||
|
||||
String multipointemisParam = sDate + " multipointemis.nc";
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath ,"emis_update_emis_ic.py",multipointemisParam));
|
||||
|
||||
boolean emisSuccesfully = getFileExists(mcipPath + "multipointemis.nc");
|
||||
if(!emisSuccesfully){
|
||||
return Result.error("EMIS运行失败,请查看日志信息!");
|
||||
}
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
shRunPath + "chmod +x run_project_icon.sh;./run_project_icon.sh");
|
||||
boolean iconSuccesfully = getFileExists(allRunPath + "workdir/ICON/icon_d03_*");
|
||||
if(!iconSuccesfully){
|
||||
return Result.error("ICON运行失败,请查看日志信息!");
|
||||
}
|
||||
|
||||
//ICON执行完成后,修改ICON结果文件的内容
|
||||
String iconFilePath = workdirPath + "ICON/icon_d03_" + sDate;
|
||||
String asijParam = String.format("icon ASIJ %s %s_ASIJ",iconFilePath,iconFilePath);
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath, "2generateMultiPointEmis_icupdate_v1.py",asijParam));
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
"rm -rf " + iconFilePath);
|
||||
|
||||
String coParam = String.format("icon CO %s_ASIJ %s",iconFilePath,iconFilePath);
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath, "2generateMultiPointEmis_icupdate_v1.py",coParam));
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
shRunPath + "chmod +x run_project_bcon.sh;./run_project_bcon.sh");
|
||||
boolean bconSuccesfully = getFileExists(allRunPath + "workdir/BCON/bcon_d03_*");
|
||||
if(!bconSuccesfully){
|
||||
return Result.error("BCON运行失败,请查看日志信息!");
|
||||
}
|
||||
|
||||
//BCON执行完成后,修改BCON结果文件的内容
|
||||
String bconFilePath = workdirPath + "BCON/bcon_d03_" + sDate;
|
||||
String asijBconParam = String.format("bcon ASIJ %s %s_ASIJ",bconFilePath,bconFilePath);
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath, "2generateMultiPointEmis_icupdate_v1.py",asijBconParam));
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
"rm -rf " + bconFilePath);
|
||||
|
||||
String coBconParam = String.format("bcon CO %s_ASIJ %s",bconFilePath,bconFilePath);
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
runPyPath(mcipPath, "2generateMultiPointEmis_icupdate_v1.py",coBconParam));
|
||||
|
||||
RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
shRunPath + "chmod +x run_project_cctm.sh;./run_project_cctm.sh");
|
||||
boolean cctmSuccesfully = getFileExists(allRunPath + "workdir/CCTM/CCTM.ACONC.d03.*");
|
||||
if(!cctmSuccesfully){
|
||||
return Result.error("CCTM运行失败,请查看日志信息!");
|
||||
}
|
||||
return Result.ok("CMAQ运行成功!");
|
||||
}
|
||||
|
||||
public Result<String> genMcipTxtFile(String targetFilePath, Cmaq cmaq, Double lon, Double lat) {
|
||||
try {
|
||||
List<String> gridDescFileValue = Files.readAllLines(get(targetFilePath + "GRIDDESC.d03"));
|
||||
List<String> fileValues = Arrays.stream(gridDescFileValue.get(5).split(" ")).filter(s -> StringUtils.isNotBlank(s)).collect(Collectors.toList());
|
||||
|
||||
List<String> domainValues = new ArrayList<>();
|
||||
domainValues.add("domainXorig=" + fileValues.get(1));
|
||||
domainValues.add("domainYorig=" + fileValues.get(2));
|
||||
domainValues.add("domainCols=" + fileValues.get(5));
|
||||
domainValues.add("domainRows=" + fileValues.get(6));
|
||||
domainValues.add("domainCell=" + String.format("%.0f",Double.valueOf(fileValues.get(3))));
|
||||
FileUtil.writeLines(domainValues, targetFilePath + "domain.txt", "UTF-8");
|
||||
|
||||
List<String> pointSourceValues = new ArrayList<>();
|
||||
pointSourceValues.add("latitude\tlontitude");
|
||||
pointSourceValues.add(lon + "\t" + lat);
|
||||
pointSourceValues.add("No\tdy\tdx\tshour\tehour");
|
||||
pointSourceValues.add(String.format("%s\t%s\t%s\t%s\t%s",1,0,0,cmaq.getEmisShour(),cmaq.getEmisEhour()));
|
||||
FileUtil.writeLines(pointSourceValues, targetFilePath + "pointsource.txt", "UTF-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("生成Txt文件异常!");
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
public String runPyPath(String allRunPath,String pyFileName,String param){
|
||||
return String.format("cd %s;chmod +x %s;%srtm/bin/python3 %s %s", allRunPath, pyFileName, eventServerProperties.getPythonPath(), pyFileName, param);
|
||||
}
|
||||
|
||||
public boolean getFileExists(String filePath){
|
||||
String cmdResult = RemoteExecuteCommand.runRemoteLinuxCmd(eventServerProperties.getIp(), eventServerProperties.getUsername(), eventServerProperties.getPassword(),
|
||||
"ls " + filePath);
|
||||
boolean succesfully = cmdResult.indexOf("没有那个文件或目录") < 0;
|
||||
return succesfully;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cmaq getCmaqTem(Integer sceneType) {
|
||||
LambdaQueryWrapper<Cmaq> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user