bug 处理

This commit is contained in:
朱春云 2025-09-04 15:35:16 +08:00
parent 739bb7f29a
commit 70d3ab00f2
2 changed files with 102 additions and 47 deletions

View File

@ -46,7 +46,6 @@ import java.util.*;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import static com.ruoyi.script.util.ShellUtil.shUtil;
import static com.ruoyi.script.util.YmlUtil.createDtiFile; import static com.ruoyi.script.util.YmlUtil.createDtiFile;
import static com.ruoyi.script.util.YmlUtil.createFile; import static com.ruoyi.script.util.YmlUtil.createFile;
import static com.ruoyi.system.util.pdfUtil.PdfUtil.chineseFont; import static com.ruoyi.system.util.pdfUtil.PdfUtil.chineseFont;
@ -245,7 +244,7 @@ public class PatientScriptServiceImpl implements PatientScriptService {
} }
//处理数据处理格式 //处理数据处理格式
ShellUtil.execCmd("dos2unix "+dealDataSh); ShellUtil.execCmd("dos2unix "+dealDataSh);
shUtil(dealDataSh,patientScript); ShellUtil.execScriptLineByLine(dealDataSh, patientScript);
if (StringUtils.isEmpty(patientScript.getPatientAge())){ if (StringUtils.isEmpty(patientScript.getPatientAge())){
patientScript.setPatientAge("0"); patientScript.setPatientAge("0");
} }
@ -257,7 +256,7 @@ public class PatientScriptServiceImpl implements PatientScriptService {
//处理脚本文件格式 //处理脚本文件格式
ShellUtil.execCmd("dos2unix "+shPath); ShellUtil.execCmd("dos2unix "+shPath);
ShellUtil.execCmd("dos2unix "+imgPath); ShellUtil.execCmd("dos2unix "+imgPath);
String status=shUtil(shPath,patientScript); String status=ShellUtil.execScriptLineByLine(shPath,patientScript);
//再处理图片的生成 //再处理图片的生成
//处理脚本文件格式 //处理脚本文件格式
@ -346,7 +345,7 @@ public class PatientScriptServiceImpl implements PatientScriptService {
//处理脚本文件格式 //处理脚本文件格式
ShellUtil.execCmd("dos2unix "+shPath); ShellUtil.execCmd("dos2unix "+shPath);
String status=shUtil(shPath,patientScript); String status=ShellUtil.execScriptLineByLine(shPath,patientScript);
//再处理图片的生成 //再处理图片的生成
//处理脚本文件格式 //处理脚本文件格式
ShellUtil.execCmd("dos2unix "+imgPath); ShellUtil.execCmd("dos2unix "+imgPath);
@ -1354,7 +1353,7 @@ public class PatientScriptServiceImpl implements PatientScriptService {
} }
//处理数据处理格式 //处理数据处理格式
ShellUtil.execCmd("dos2unix "+dealDataSh); ShellUtil.execCmd("dos2unix "+dealDataSh);
shUtil(dealDataSh,patientScript); ShellUtil.execScriptLineByLine(dealDataSh,patientScript);
if (StringUtils.isEmpty(patientScript.getPatientAge())){ if (StringUtils.isEmpty(patientScript.getPatientAge())){
patientScript.setPatientAge("0"); patientScript.setPatientAge("0");
} }
@ -1366,7 +1365,7 @@ public class PatientScriptServiceImpl implements PatientScriptService {
//处理脚本文件格式 //处理脚本文件格式
ShellUtil.execCmd("dos2unix "+shPath); ShellUtil.execCmd("dos2unix "+shPath);
ShellUtil.execCmd("dos2unix "+imgPath); ShellUtil.execCmd("dos2unix "+imgPath);
String status=shUtil(shPath,patientScript); String status=ShellUtil.execScriptLineByLine(shPath,patientScript);
//再处理图片的生成 //再处理图片的生成
//处理脚本文件格式 //处理脚本文件格式

View File

@ -5,55 +5,113 @@ import com.ruoyi.script.entity.PatientScript;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class ShellUtil { public class ShellUtil {
public static String shUtil(String commandStr,PatientScript patientScript) throws Exception { // ... existing code ...
String resInfo="异常";
System.out.println("commandStr: " + commandStr); /**
ProcessBuilder processBuilder = new ProcessBuilder(commandStr); * 逐条执行脚本中的命令同时保留原有的业务逻辑处理
Process process = processBuilder.start(); * @param scriptPath 脚本文件路径
* @param patientScript 患者脚本对象
* @return 执行结果状态
* @throws Exception 执行异常
*/
public static String execScriptLineByLine(String scriptPath, PatientScript patientScript) throws Exception {
String resInfo = "异常";
// 读取脚本文件内容
List<String> lines = Files.readAllLines(Paths.get(scriptPath));
// 逐行执行命令跳过空行和注释行
for (String line : lines) {
// 去掉首尾空格
line = line.trim();
// 跳过空行和注释行
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
System.out.println("Executing command: " + line);
// 执行单条命令
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("sh", "-c", line);
Process process = processBuilder.start();
// 复用原有的业务逻辑处理
resInfo = processScriptOutput(process, patientScript, resInfo);
// 等待命令执行完成
int exitCode = process.waitFor();
System.out.println("Command exited with code: " + exitCode);
// 如果命令执行失败可以选择停止执行后续命令
if (exitCode != 0) {
System.err.println("Command failed, stopping script execution");
break;
}
}
return resInfo;
}
/**
* 处理脚本输出复用原有的业务逻辑
* @param process 进程对象
* @param patientScript 患者脚本对象
* @param resInfo 结果信息
* @return 更新后的结果信息
* @throws Exception 处理异常
*/
private static String processScriptOutput(Process process, PatientScript patientScript, String resInfo) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
System.out.println(line); System.out.println(line);
if (line.contains("\"tr\"")&&line.contains("{")&&line.contains("}")){ if (line.contains("\"tr\"") && line.contains("{") && line.contains("}")) {
System.out.println(line+"tr11111111************************************************************"); System.out.println(line + "tr11111111************************************************************");
JSONObject jsonObject = JSONObject.parseObject(line); JSONObject jsonObject = JSONObject.parseObject(line);
patientScript.setRepetitionTime(jsonObject.get("tr").toString()); patientScript.setRepetitionTime(jsonObject.get("tr").toString());
} }
if (line.contains("姓名")){ if (line.contains("姓名")) {
System.out.println(line+"姓名************************************************************"); System.out.println(line + "姓名************************************************************");
String[] parts = line.split(":"); String[] parts = line.split(":");
if (parts.length > 1) { if (parts.length > 1) {
String name = parts[1].trim(); String name = parts[1].trim();
if(StringUtils.isNotEmpty(name)&&StringUtils.isEmpty(patientScript.getPatientName())&&!name.equals("Unknown")){ if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(patientScript.getPatientName()) && !name.equals("Unknown")) {
patientScript.setPatientName(name); patientScript.setPatientName(name);
} }
} }
} }
if (line.contains("性别")){
System.out.println(line+"性别************************************************************"); if (line.contains("性别")) {
System.out.println(line + "性别************************************************************");
String[] parts = line.split(":"); String[] parts = line.split(":");
if (parts.length > 1) { if (parts.length > 1) {
String sex = parts[1].trim(); String sex = parts[1].trim();
if(StringUtils.isNotEmpty(sex)&&StringUtils.isEmpty(patientScript.getPatientSex())&&!sex.equals("Unknown")){ if (StringUtils.isNotEmpty(sex) && StringUtils.isEmpty(patientScript.getPatientSex()) && !sex.equals("Unknown")) {
if ("".equals(sex)){ if ("".equals(sex)) {
patientScript.setPatientSex(""); patientScript.setPatientSex("");
}else { } else {
patientScript.setPatientSex(""); patientScript.setPatientSex("");
} }
} }
} }
} }
if (line.contains("年龄")){
System.out.println(line+"年龄************************************************************"); if (line.contains("年龄")) {
System.out.println(line + "年龄************************************************************");
String[] parts = line.split(":"); String[] parts = line.split(":");
if (parts.length > 1) { if (parts.length > 1) {
String age = parts[1].trim(); String age = parts[1].trim();
if (StringUtils.isNotEmpty(age)&&StringUtils.isEmpty(patientScript.getPatientAge())&&!age.equals("Unknown")){ if (StringUtils.isNotEmpty(age) && StringUtils.isEmpty(patientScript.getPatientAge()) && !age.equals("Unknown")) {
// 去除非数字字符 // 去除非数字字符
String numericAge = age.replaceAll("[^0-9]", ""); String numericAge = age.replaceAll("[^0-9]", "");
// 将字符串转换为整数 // 将字符串转换为整数
@ -64,38 +122,32 @@ public class ShellUtil {
} }
} }
if (line.contains("brain_regions")||line.contains("correlation")){ if (line.contains("brain_regions") || line.contains("correlation")) {
String resInfo1 = patientScript.getResInfo(); String resInfo1 = patientScript.getResInfo();
if (StringUtils.isEmpty(resInfo1)){ if (StringUtils.isEmpty(resInfo1)) {
resInfo1=line; resInfo1 = line;
}else{ } else {
resInfo1=resInfo1+"&*&*&"+line; resInfo1 = resInfo1 + "&*&*&" + line;
} }
patientScript.setResInfo(resInfo1); patientScript.setResInfo(resInfo1);
} }
if (line.contains("result===")){
System.out.println(line+"result1************************************************************"); if (line.contains("result===")) {
if (line.contains("1")){ System.out.println(line + "result1************************************************************");
resInfo= "异常"; if (line.contains("1")) {
}else { resInfo = "异常";
resInfo= "正常"; } else {
resInfo = "正常";
} }
} }
if (line.contains("检查数据完整性")){
throw new Exception("生成异常"); if (line.contains("检查数据完整性")) {
throw new Exception("生成异常");
} }
} }
return resInfo;
int exitCode = process.waitFor();
System.out.println("Exit code: " + exitCode);
return resInfo;
} }
public static void execCmd(String cmd) throws IOException { public static void execCmd(String cmd) throws IOException {
Runtime run = Runtime.getRuntime(); Runtime run = Runtime.getRuntime();
Process proc = null; Process proc = null;
@ -134,4 +186,8 @@ public class ShellUtil {
br.close(); br.close();
} }
} }
// ... existing code ...
} }