【修改】mysql读取文件夹下的myd文件
This commit is contained in:
@@ -91,14 +91,28 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
|||||||
String filePath = new File(stuFilePath, "answer.txt").getAbsolutePath(); // 结果/answer.txt
|
String filePath = new File(stuFilePath, "answer.txt").getAbsolutePath(); // 结果/answer.txt
|
||||||
|
|
||||||
// String answerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\结果素材\\结果素材\\Teacher\\db\\db_escape.myd"; // 原始 SQL 文件路径
|
// String answerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\结果素材\\结果素材\\Teacher\\db\\db_escape.myd"; // 原始 SQL 文件路径
|
||||||
String answerPath = new File(new File(stuFilePath, "db"), "db_escape.myd").getAbsolutePath();
|
File dbDir = new File(stuFilePath, "db");
|
||||||
|
String answerPath = null;
|
||||||
|
if (dbDir.exists() && dbDir.isDirectory()) {
|
||||||
|
File[] mydFiles = dbDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".myd"));
|
||||||
|
if (mydFiles != null && mydFiles.length > 0) {
|
||||||
|
answerPath = mydFiles[0].getAbsolutePath(); // 默认取第一个 .myd 文件
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// String fileStu = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student";
|
// String fileStu = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student";
|
||||||
String fileStu = filepath.getAbsolutePath();
|
String fileStu = filepath.getAbsolutePath();
|
||||||
|
|
||||||
// String stuAnswerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student\\db\\db_escape.myd";
|
// String stuAnswerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student\\db\\db_escape.myd";
|
||||||
String stuAnswerPath = new File(new File(fileStu, "db"), "db_escape.myd").getAbsolutePath();
|
File stuDbDir = new File(fileStu, "db");
|
||||||
|
String stuAnswerPath = null;
|
||||||
|
if (stuDbDir.exists() && stuDbDir.isDirectory()) {
|
||||||
|
File[] stuMydFiles = stuDbDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".myd"));
|
||||||
|
if (stuMydFiles != null && stuMydFiles.length > 0) {
|
||||||
|
stuAnswerPath = stuMydFiles[0].getAbsolutePath(); // 默认取第一个 .myd 文件
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 生成随机数据库名,临时使用
|
// 生成随机数据库名,临时使用
|
||||||
databaseName = "db_" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
databaseName = "db_" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||||
@@ -623,6 +637,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
|||||||
//考生答案 集合
|
//考生答案 集合
|
||||||
List<Map<String, Object>> stuResults = new ArrayList<>();
|
List<Map<String, Object>> stuResults = new ArrayList<>();
|
||||||
if (extractCallStatements != null && extractCallStatements.size() > 0) {
|
if (extractCallStatements != null && extractCallStatements.size() > 0) {
|
||||||
|
boolean hasError = false; // 添加标志变量
|
||||||
for (String extractCallStatement : extractCallStatements) {
|
for (String extractCallStatement : extractCallStatements) {
|
||||||
appendToFile(answerLogPath, "测试 call 语句:" + extractCallStatement);
|
appendToFile(answerLogPath, "测试 call 语句:" + extractCallStatement);
|
||||||
|
|
||||||
@@ -636,7 +651,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
appendToFile(answerLogPath, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
appendToFile(answerLogPath, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||||
}
|
}
|
||||||
boolean hasError = false; // 添加标志变量
|
|
||||||
|
|
||||||
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
|
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
|
||||||
Statement stmtstu = connstu.createStatement()) {
|
Statement stmtstu = connstu.createStatement()) {
|
||||||
@@ -660,23 +675,20 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
|||||||
hasError = true; // 发生异常,设为 true
|
hasError = true; // 发生异常,设为 true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 比较结果(如果发生异常,可以认为比较失败)
|
|
||||||
boolean flag = !hasError && compareExtractResults(anwerResults, stuResults);
|
|
||||||
|
|
||||||
if (flag) {
|
|
||||||
//todo 得分
|
|
||||||
double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal);
|
|
||||||
scoreTotal+=sr;
|
|
||||||
} else {
|
|
||||||
//得分
|
|
||||||
double sw = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal);
|
|
||||||
scoreTotal+=sw;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 比较结果(如果发生异常,可以认为比较失败)
|
||||||
|
boolean flag = !hasError && compareExtractResults(anwerResults, stuResults);
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
//todo 得分
|
||||||
|
double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal);
|
||||||
|
scoreTotal+=sr;
|
||||||
|
} else {
|
||||||
|
//得分
|
||||||
|
double sw = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal);
|
||||||
|
scoreTotal+=sw;
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
appendToFile(answerLogPath, "此存储过程无 CALL 语句");
|
appendToFile(answerLogPath, "此存储过程无 CALL 语句");
|
||||||
}
|
}
|
||||||
@@ -740,7 +752,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
|||||||
}
|
}
|
||||||
double roundedResult =0.0;
|
double roundedResult =0.0;
|
||||||
|
|
||||||
appendToFile(answerLogPath, "共得分:"+scoreTotal);
|
appendToFile(answerLogPath, "共得分:" + String.format("%.2f", scoreTotal));
|
||||||
folderzip.delete();
|
folderzip.delete();
|
||||||
deleteFolder(folder);
|
deleteFolder(folder);
|
||||||
return scoreTotal;
|
return scoreTotal;
|
||||||
|
Reference in New Issue
Block a user