Accept Merge Request #127: (hyc -> master)

Merge Request: 【修改】mysql判分明细改为对象属性

Created By: @华允传
Accepted By: @华允传
URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/127?initial=true
This commit is contained in:
华允传
2025-06-16 14:35:31 +08:00
committed by Coding

View File

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