diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java index 2743a37c..3760ed08 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java @@ -314,11 +314,13 @@ public class MysqlServericeImpl implements IMysqlServerice { String sql3 = resultStu.get(entry.getKey()); if (table1Columns.equals(table2Columns)) { // - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql3,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql3,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } else { - double sw= calculateTotalScoreRate(sql3, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } } @@ -354,11 +356,13 @@ public class MysqlServericeImpl implements IMysqlServerice { boolean equals = sql1.equals(sql2); if (equals) { - double sr=accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } else { - double sw= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } @@ -414,11 +418,14 @@ public class MysqlServericeImpl implements IMysqlServerice { //累加删除语句的所有权值 examQuestionKeywords累加scorerate appendToFile(answerLogPath, "验证通过:符合 DELETE 条件的记录已删除。"); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证通过:符合 DELETE 条件的记录已删除。"); - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); + } else { - double sw= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } } }catch (SQLException e) { @@ -472,11 +479,17 @@ public class MysqlServericeImpl implements IMysqlServerice { // if (b) { - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); + + + + } else { - double sw= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } @@ -510,7 +523,7 @@ public class MysqlServericeImpl implements IMysqlServerice { answerList = getAnswerList(answer); appendToFile(answerLogPath, "查找语句标准答案"); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案"); - printResult(answerList); + printResult(answerList,judgementStr); }catch (SQLException e) { appendToFile(answerLogPath, "执行验证语句"+sql1+"时发生错误: " + e.getMessage()); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行验证语句"+sql1+"时发生错误: " + e.getMessage()); @@ -523,7 +536,7 @@ public class MysqlServericeImpl implements IMysqlServerice { answerListStu = getAnswerList(answer); appendToFile(answerLogPath, "学生语句答案"); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生语句答案"); - printResult(answerListStu); + printResult(answerListStu,judgementStr); } catch (SQLException e) { appendToFile(answerLogPath, "执行学生库语句"+sql2+"时发生错误: " + e.getMessage()); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库语句"+sql2+"时发生错误: " + e.getMessage()); @@ -539,12 +552,14 @@ public class MysqlServericeImpl implements IMysqlServerice { if (isEquivalent) { //todo 得分 - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } else { - double sw= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } @@ -612,13 +627,13 @@ public class MysqlServericeImpl implements IMysqlServerice { judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行正确答案视图语句的查询结果:"); String sql3 = "SELECT * FROM " + viewName1; List> result1 = executeQuery(stmt, sql3); - printResult(result1); + printResult(result1,judgementStr); // 执行查询,获取视图2的结果 appendToFile(answerLogPath, "执行考生视图语句的查询结果:"); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行考生视图语句的查询结果:"); String sql4 = "SELECT * FROM " + viewName2; List> result2 = executeQuery(stmt, sql4); - printResult(result2); + printResult(result2,judgementStr); // 比较两个视图的结果 boolean isEquivalent = !hasError &&compareResults(result1, result2); @@ -630,11 +645,17 @@ public class MysqlServericeImpl implements IMysqlServerice { stmt.execute("DROP VIEW IF EXISTS " + viewName1); stmt.execute("DROP VIEW IF EXISTS " + viewName2); if (isEquivalent) { - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); + + + + } else { - double sw= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } // } @@ -711,16 +732,19 @@ public class MysqlServericeImpl implements IMysqlServerice { } // 比较结果(如果发生异常,可以认为比较失败) - boolean flag = !hasError && compareExtractResults(anwerResults, stuResults); + boolean flag = !hasError && compareExtractResults(anwerResults, stuResults,judgementStr); if (flag) { //todo 得分 - double sr= accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql2,totalKeyScore,score,answerId,scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); + } else { //得分 - double sw = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } } else { @@ -763,11 +787,13 @@ public class MysqlServericeImpl implements IMysqlServerice { boolean equals = normalizedTriggerSql1.equals(normalizedTriggerSql2); if (equals) { //todo 得分 - double sr= accumulateScoreAndLog(examMysqlKeywordList, total, answerLogPath, sql2, totalKeyScore, score, answerId, scoreTotal,judgementStr); - scoreTotal+=sr; + SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList, total, answerLogPath, sql2, totalKeyScore, score, answerId, scoreTotal,judgementStr); + + } else { - double sw = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr); - scoreTotal+=sw; + SourceAndText studentScorePojo = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr); + scoreTotal += studentScorePojo.getScore(); + judgementStr = studentScorePojo.getText(); } @@ -811,11 +837,15 @@ public class MysqlServericeImpl implements IMysqlServerice { folder.delete(); // 删除空文件夹或文件 } //如果这个小题对了,直接累加对应的权值分 - private double accumulateScoreAndLog(List examMysqlKeywordList, AtomicInteger total, String answerLogPath, String sql2, String totalKeyScore, double score,String answerId,double scoreTotal,String judgementStr) { + private SourceAndText accumulateScoreAndLog(List examMysqlKeywordList, AtomicInteger total, String answerLogPath, String sql2, String totalKeyScore, double score,String answerId,double scoreTotal,String judgementStr) { + SourceAndText sourceAndText = new SourceAndText(); if(StringUtils.isBlank(answerId)){ appendToFile(answerLogPath, "❌该语句找不到试题id,请检查出题内容!" ); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌该语句找不到试题id,请检查出题内容!"); - return 0.0; + sourceAndText.setText(judgementStr); + sourceAndText.setScore(0.0); + //返回累加的总分 + return sourceAndText; } //用answerid查对应答案的权值 。除以总权值 String scoreRateStr= examQuestionAnswerMapper.selectExamQuestionAnswerScoreByAnswerId(answerId); @@ -843,16 +873,23 @@ public class MysqlServericeImpl implements IMysqlServerice { } catch (NumberFormatException e) { System.err.println("无效的totalKeyScore值:" + totalKeyScore); } - return singleScore; + sourceAndText.setText(judgementStr); + sourceAndText.setScore(singleScore); + //返回累加的总分 + return sourceAndText; } - public double calculateTotalScoreRate(String sql, List examQuestionKeywords, String totalKeyScore, double score,String answerId,double scoreTotal,String judgementStr) { + public SourceAndText calculateTotalScoreRate(String sql, List examQuestionKeywords, String totalKeyScore, double score,String answerId,double scoreTotal,String judgementStr) { + SourceAndText sourceAndText = new SourceAndText(); if(StringUtils.isBlank(answerId)){ judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌该语句找不到试题id,请检查出题内容!"); appendToFile(answerLogPath, "❌该语句找不到试题id,请检查出题内容!" ); - return 0.0; + sourceAndText.setText(judgementStr); + sourceAndText.setScore(0.0); + //返回累加的总分 + return sourceAndText; } //用answerid查对应答案的权值 。除以总权值 String scoreRateStr= examQuestionAnswerMapper.selectExamQuestionAnswerScoreByAnswerId(answerId); @@ -918,7 +955,10 @@ public class MysqlServericeImpl implements IMysqlServerice { judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌学生语句"+sql+"不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore); appendToFile(answerLogPath,"❌学生语句"+sql+"不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore); - return finalRoundedScore; + sourceAndText.setText(judgementStr); + sourceAndText.setScore(finalRoundedScore); + //返回累加的总分 + return sourceAndText; } // 预处理函数:去除空格和换行并转为大写 @@ -976,19 +1016,23 @@ public class MysqlServericeImpl implements IMysqlServerice { // 比较两个结果集 - private static boolean compareExtractResults(List> newResults, List> oldResults) { + private static boolean compareExtractResults(List> newResults, List> oldResults,String judgementStr) { appendToFile(answerLogPath,"==== 标准答案 ===="); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==== 标准答案 ===="); for (Map row : newResults) { + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, row.toString()); appendToFile(answerLogPath,row.toString()); } appendToFile(answerLogPath,"==== 考生答案 ===="); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==== 考生答案 ===="); for (Map row : oldResults) { appendToFile(answerLogPath,row.toString()); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, row.toString()); } if (newResults.size() != oldResults.size()) { appendToFile(answerLogPath,"❌考生答案与标准答案个数不对"); - + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌考生答案与标准答案个数不对"); return false; } @@ -997,7 +1041,7 @@ public class MysqlServericeImpl implements IMysqlServerice { Set> oldSet = new HashSet<>(oldResults); if (!newSet.equals(oldSet)) { - + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌ 内容相同但顺序不同,或存在差异:"); appendToFile(answerLogPath,"❌ 内容相同但顺序不同,或存在差异:"); Set> onlyInNew = new HashSet<>(newSet); onlyInNew.removeAll(oldSet); @@ -1007,17 +1051,18 @@ public class MysqlServericeImpl implements IMysqlServerice { for (Map row : onlyInNew) { appendToFile(answerLogPath,"⚠️ 标准答案中有但考生答案中没有: " + row); - + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "⚠️ 标准答案中有但考生答案中没有: " + row); } for (Map row : onlyInOld) { appendToFile(answerLogPath,"⚠️ 考生答案中有但标准答案中没有: " + row); - + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "⚠️ 考生答案中有但标准答案中没有: " + row); } return false; } appendToFile(answerLogPath,"两个结果集内容一致(不考虑顺序)!"); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "两个结果集内容一致(不考虑顺序)!"); return true; } @@ -1168,9 +1213,11 @@ public class MysqlServericeImpl implements IMysqlServerice { /** * 打印查询结果 */ - private static void printResult(List> result) { + private static void printResult(List> result,String judgementStr) { if (result.isEmpty()) { appendToFile(answerLogPath, "查询结果为空"); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查询结果为空"); + } else { for (int i = 0; i < result.size(); i++) { List row = result.get(i); @@ -1186,6 +1233,7 @@ public class MysqlServericeImpl implements IMysqlServerice { // 输出整行 appendToFile(answerLogPath, sb.toString()); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sb.toString()); } } }