Accept Merge Request #108: (hyc -> master)
Merge Request: 【修改】mysql读取文件夹下的myd文件 Created By: @华允传 Accepted By: @华允传 URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/108?initial=true
This commit is contained in:
@@ -491,11 +491,36 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
|
||||
PageResult<QuestionExamineDO> questionExamineDOPageResult = questionExamineMapper.selectPage(questionVo);
|
||||
List<QuestionExamineDO> list = questionExamineDOPageResult.getList();
|
||||
List<ExamQuestion> examQuestionList=new ArrayList<>();
|
||||
|
||||
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
|
||||
// 构造 ID → 名称映射
|
||||
Map<Long, String> idNameMap = examKnowledgePoints.stream()
|
||||
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
|
||||
if (list!=null&&list.size()>0){
|
||||
for (QuestionExamineDO questionExamineDO : list) {
|
||||
String schoolName =questionExamineMapper.selectSchoolName(questionExamineDO.getSource());
|
||||
ExamQuestion examQuestion = examQuestionMapper.selectExamQuestionByQuId(questionExamineDO.getQuId());
|
||||
String pointIdStr = examQuestion.getPointNames();
|
||||
String chapterIdStr = examQuestion.getChapteridDictText();
|
||||
if (examQuestion!=null){
|
||||
try {
|
||||
if (pointIdStr != null) {
|
||||
Long pointId = Long.valueOf(pointIdStr);
|
||||
if (idNameMap.containsKey(pointId)) {
|
||||
examQuestion.setPointNamesVo(idNameMap.get(pointId));
|
||||
}
|
||||
}
|
||||
|
||||
if (chapterIdStr != null) {
|
||||
Long chapterId = Long.valueOf(chapterIdStr);
|
||||
if (idNameMap.containsKey(chapterId)) {
|
||||
examQuestion.setChapteridDictTextVo(idNameMap.get(chapterId));
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 日志记录或跳过处理
|
||||
System.err.println("ID格式错误:" + e.getMessage());
|
||||
}
|
||||
examQuestion.setCreateTeacher(questionExamineDO.getCreateTeacher());
|
||||
examQuestion.setSchoolName(schoolName);
|
||||
examQuestion.setSource(questionExamineDO.getSource());
|
||||
|
@@ -91,14 +91,28 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
||||
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 = 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 = filepath.getAbsolutePath();
|
||||
|
||||
// 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);
|
||||
@@ -623,6 +637,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
||||
//考生答案 集合
|
||||
List<Map<String, Object>> stuResults = new ArrayList<>();
|
||||
if (extractCallStatements != null && extractCallStatements.size() > 0) {
|
||||
boolean hasError = false; // 添加标志变量
|
||||
for (String extractCallStatement : extractCallStatements) {
|
||||
appendToFile(answerLogPath, "测试 call 语句:" + extractCallStatement);
|
||||
|
||||
@@ -636,7 +651,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
}
|
||||
boolean hasError = false; // 添加标志变量
|
||||
|
||||
|
||||
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
|
||||
Statement stmtstu = connstu.createStatement()) {
|
||||
@@ -660,23 +675,20 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
||||
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 {
|
||||
appendToFile(answerLogPath, "此存储过程无 CALL 语句");
|
||||
}
|
||||
@@ -740,7 +752,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
|
||||
}
|
||||
double roundedResult =0.0;
|
||||
|
||||
appendToFile(answerLogPath, "共得分:"+scoreTotal);
|
||||
appendToFile(answerLogPath, "共得分:" + String.format("%.2f", scoreTotal));
|
||||
folderzip.delete();
|
||||
deleteFolder(folder);
|
||||
return scoreTotal;
|
||||
|
Reference in New Issue
Block a user