【修改】mysql判分样式,文件夹总分输出重复
This commit is contained in:
@@ -128,8 +128,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
appendToFile(answerLogPath, "未找到答题表:" +stuDataName+ ","+e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "未找到答题表:" +stuDataName+","+ e.getMessage());
|
||||
appendToFile(answerLogPath, "未找到答题库:【" +stuDataName+"】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "未找到答题库:【" +stuDataName+"】");
|
||||
}
|
||||
|
||||
// // **建立连接到新创建的数据库**
|
||||
@@ -152,7 +152,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
String sql=examQuestionAnswer.getContent();
|
||||
if(sql.trim().toUpperCase().startsWith("CREATE TABLE")) {
|
||||
appendToFile(answerLogPath, "==================建表语句==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================建表语句==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================建表语句 ==================");
|
||||
// 匹配成功
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
@@ -241,11 +241,14 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
|
||||
if (table1Columns.equals(table2Columns)) {
|
||||
//
|
||||
appendToFile(answerLogPath, "【执行】"+"【"+showCreateTableSql+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】"+"【"+showCreateTableSql+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSQL,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
} else {
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+showCreateTableSql+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+showCreateTableSql+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSQL, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -260,9 +263,9 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// 正则表达式匹配表名
|
||||
Pattern pattern = Pattern.compile("INSERT INTO\\s+`?(\\w+)`?\\s*\\(");
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
if (matcher.find()) {
|
||||
String tableName = matcher.group(1).replace("`", ""); // 获取表名
|
||||
// 匹配成功
|
||||
@@ -283,8 +286,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案");
|
||||
// printResult(answerList,judgementStr);
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -306,8 +309,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生语句答案");
|
||||
// printResult(answerListStu,judgementStr);
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+yanzheng+"时发生错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
boolean isEquivalent =false;
|
||||
@@ -317,10 +320,16 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
|
||||
if (isEquivalent) {
|
||||
|
||||
appendToFile(answerLogPath, "【执行】"+"【"+yanzheng+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+yanzheng+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
} else {
|
||||
|
||||
appendToFile(answerLogPath, "【执行】"+"【"+yanzheng+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+yanzheng+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSql, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -331,10 +340,9 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (sql.trim().toUpperCase().startsWith("DELETE")) {
|
||||
appendToFile(answerLogPath, "==================删除语句==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================删除语句==================");
|
||||
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
sql = sql.trim().replaceAll(";+\\s*$", "");
|
||||
// 正则提取表名和 WHERE 条件
|
||||
Pattern pattern = Pattern.compile("DELETE\\s+FROM\\s+(\\w+)\\s+WHERE\\s+(.+)", Pattern.CASE_INSENSITIVE);
|
||||
@@ -366,35 +374,39 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
int countstu = rsstu.getInt(1);
|
||||
if (countstu == 0) {
|
||||
//累加删除语句的所有权值 examQuestionKeywords累加scorerate
|
||||
appendToFile(answerLogPath, "验证通过:符合 DELETE 条件的记录已删除。");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证通过:符合 DELETE 条件的记录已删除。");
|
||||
// appendToFile(answerLogPath, "验证通过:符合 DELETE 条件的记录已删除。");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证通过:符合 DELETE 条件的记录已删除。");
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+verifySql+"】 【验证】 【表】 【"+tableName+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+verifySql+"】 【验证】 【表】 【"+tableName+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+verifySql+"】 【验证】 【表】 【"+tableName+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+verifySql+"】 【验证】 【表】 【"+tableName+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(null, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
}
|
||||
}
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "验证学生库失败,"+"得分:0 ❌");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证学生库失败,"+"得分:0 ❌");
|
||||
appendToFile(answerLogPath, "验证学生库失败,"+"得分:0【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证学生库失败,"+"得分:0【❌】");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "验证答案库失败:还有 " + count + " 条记录符合 DELETE 条件,未被删除。"+"得分:0 ❌");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证答案库失败:还有 " + count + "条记录符合 DELETE 条件,未被删除。得分:0 ❌");
|
||||
// appendToFile(answerLogPath, "验证答案库失败:还有 " + count + " 条记录符合 DELETE 条件,未被删除。"+"得分:0 【❌】");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "验证答案库失败:还有 " + count + "条记录符合 DELETE 条件,未被删除。得分:0 【❌】");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行验证 SQL 出错!");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行验证 SQL 出错!");
|
||||
// appendToFile(answerLogPath, "执行验证 SQL 出错!");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行验证 SQL 出错!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -405,14 +417,25 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (sql.trim().toUpperCase().startsWith("UPDATE")) {
|
||||
appendToFile(answerLogPath, "==================更新语句==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================更新语句==================");
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
//提取表名
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// 匹配成功
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
//转换成select语句
|
||||
String selectSql = convertUpdateToSelectWhere(sql);
|
||||
// 提取表名和 WHERE 子句
|
||||
Pattern pattern = Pattern.compile(
|
||||
"UPDATE\\s+`?(\\w+)`?\\s+SET\\s+.+?\\s+WHERE\\s+(.+);?",
|
||||
Pattern.CASE_INSENSITIVE | Pattern.DOTALL
|
||||
);
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
|
||||
if (matcher.find()) {
|
||||
|
||||
String tableName = matcher.group(1);
|
||||
|
||||
List<List<String>> answerList= new ArrayList<>();
|
||||
List<List<String>> answerListStu = new ArrayList<>();
|
||||
@@ -424,8 +447,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案");
|
||||
// printResult(answerList,judgementStr);
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -448,8 +471,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生语句答案:");
|
||||
// printResult(answerListStu,judgementStr);
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "学生表执行验证语句"+selectSql+"时发生错误:" + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "学生表执行验证语句"+selectSql+"时发生错误:" + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -461,17 +484,21 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
//
|
||||
if (isEquivalent) {
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+selectSql+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+selectSql+"】【验证】【表】【"+tableName+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+selectSql+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】 "+"【"+selectSql+"】【验证】【表】【"+tableName+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSql, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (sql.trim().toUpperCase().startsWith("SELECT")) {
|
||||
appendToFile(answerLogPath, "==================查找语句==================");
|
||||
@@ -480,12 +507,12 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
|
||||
AtomicReference<String> stuAnswer = new AtomicReference<>();
|
||||
|
||||
AtomicReference<String> fileName= new AtomicReference<>();
|
||||
// 根据sql 的内容查询结果文件夹语句的文件名,再根据文件名 查找 考生
|
||||
try {
|
||||
String finalSql = sql;
|
||||
@@ -499,6 +526,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (normalizedFinalSql.equals(normalizedFileContent)) {
|
||||
|
||||
String stuPath=fileStu+"\\"+filePaths.getFileName();
|
||||
fileName.set(String.valueOf(filePaths.getFileName()));
|
||||
stuAnswer.set(readSQLFromFile(stuPath));
|
||||
System.out.println("考生语句"+stuAnswer);
|
||||
}
|
||||
@@ -519,12 +547,12 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
Statement stmtan = connanswer.createStatement()) {
|
||||
try (ResultSet answer = stmtan.executeQuery(sql)) {
|
||||
answerList = getAnswerList(answer);
|
||||
appendToFile(answerLogPath, "运行标准答案语句的查询结果:");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行标准答案语句的查询结果:");
|
||||
judgementStr = printResult(answerList,judgementStr);
|
||||
// appendToFile(answerLogPath, "运行标准答案语句的查询结果:");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行标准答案语句的查询结果:");
|
||||
// judgementStr = printResult(answerList,judgementStr);
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行验证语句"+sql+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行验证语句"+sql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行验证语句"+sql+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行验证语句"+sql+"时发生错误: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -532,20 +560,20 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
Statement stmtstu = connstu.createStatement()) {
|
||||
if (StringUtils.isBlank(stuAnswer.get())) {
|
||||
SourceAndText sourceAndTextError = new SourceAndText();
|
||||
appendToFile(answerLogPath, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
appendToFile(answerLogPath, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
sourceAndTextError.setText(judgementStr);
|
||||
sourceAndTextError.setScore(0.0);
|
||||
continue;
|
||||
}
|
||||
try (ResultSet answer = stmtstu.executeQuery(String.valueOf(stuAnswer))) {
|
||||
answerListStu = getAnswerList(answer);
|
||||
appendToFile(answerLogPath, "运行学生语句的查询结果:");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行学生语句的查询结果:");
|
||||
judgementStr= printResult(answerListStu,judgementStr);
|
||||
// appendToFile(answerLogPath, "运行学生语句的查询结果:");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行学生语句的查询结果:");
|
||||
// judgementStr= printResult(answerListStu,judgementStr);
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行学生库语句"+String.valueOf(stuAnswer)+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库语句"+String.valueOf(stuAnswer)+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行学生语句"+String.valueOf(stuAnswer)+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生语句"+String.valueOf(stuAnswer)+"时发生错误: " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -556,12 +584,16 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
|
||||
if (isEquivalent) {
|
||||
appendToFile(answerLogPath, "执行"+sql+"验证文件【"+fileName.get()+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"执行"+sql+"验证文件【"+fileName.get()+"】【✅】");
|
||||
//todo 得分
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,String.valueOf(stuAnswer),totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "执行"+sql+"验证文件【"+fileName.get()+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"执行"+sql+"验证文件【"+fileName.get()+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(String.valueOf(stuAnswer), examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -577,23 +609,21 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
// 匹配成功
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
|
||||
// 正则表达式,用于匹配 "VIEW" 后面的视图名称
|
||||
String regex = "(?<=VIEW\\s)([\\w`_]+)";
|
||||
String regex = "(?i)VIEW\\s+((`?\\w+`?\\.)?`?\\w+`?)";
|
||||
String sqlviewAnswer = removeComments(sql);
|
||||
String viewNam1 = extractViewName(sqlviewAnswer, regex);
|
||||
|
||||
String showCreateViewSql = "SHOW CREATE VIEW " + viewNam1;
|
||||
|
||||
// 执行查询,获取答案 视图的结果
|
||||
appendToFile(answerLogPath, "执行正确答案视图语句的查询结果:");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行正确答案视图语句的查询结果:");
|
||||
// appendToFile(answerLogPath, "执行正确答案视图语句的查询结果:");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行正确答案视图语句的查询结果:");
|
||||
String sql3 = "SELECT * FROM " + viewNam1;
|
||||
List<List<String>> result1 = executeQuery(stmt, sql3);
|
||||
judgementStr= printResult(result1,judgementStr);
|
||||
// judgementStr= printResult(result1,judgementStr);
|
||||
|
||||
List<List<String>> result2 =new ArrayList<>();
|
||||
String stuSQL =null;
|
||||
@@ -608,40 +638,54 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
stuSQL=createViewSqlExport;
|
||||
}
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行学生库语句"+showCreateViewSql+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库语句"+showCreateViewSql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行学生语句"+showCreateViewSql+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生语句"+showCreateViewSql+"时发生错误: " + e.getMessage());
|
||||
hasError = true; // 发生异常,设为 true
|
||||
}
|
||||
|
||||
// 执行查询,获取考生 视图的结果
|
||||
appendToFile(answerLogPath, "执行考生视图语句的查询结果:");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行考生视图语句的查询结果:");
|
||||
// appendToFile(answerLogPath, "执行考生视图语句的查询结果:");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行考生视图语句的查询结果:");
|
||||
|
||||
try {
|
||||
result2 = executeQuery(stmtstu, sql3);
|
||||
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行学生库语句"+sql3+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库语句"+sql3+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行学生语句"+sql3+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生语句"+sql3+"时发生错误: " + e.getMessage());
|
||||
hasError = true; // 发生异常,设为 true
|
||||
}
|
||||
|
||||
|
||||
judgementStr= printResult(result2,judgementStr);
|
||||
// judgementStr= printResult(result2,judgementStr);
|
||||
}
|
||||
if (result1!=null&&result1.size()>0){
|
||||
if (result2!=null&&result2.size()>0){
|
||||
if (result1.size()==result2.size()){
|
||||
appendToFile(answerLogPath, "【记录数】【"+result1.size()+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【记录数】【"+result1.size()+"】【✅】");
|
||||
}
|
||||
}else {
|
||||
appendToFile(answerLogPath, "【记录数】【"+result1.size()+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【记录数】【"+result1.size()+"】❌");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较两个视图的结果
|
||||
boolean isEquivalent =!hasError &&compareResults(result1, result2);
|
||||
appendToFile(answerLogPath, "\n是否结果等价: " + isEquivalent);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "\n是否结果等价: " + isEquivalent);
|
||||
// appendToFile(answerLogPath, "\n是否结果等价: " + isEquivalent);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "\n是否结果等价: " + isEquivalent);
|
||||
|
||||
|
||||
if (isEquivalent) {
|
||||
appendToFile(answerLogPath, "【执行】"+"【"+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】 ✅");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】"+"【"+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuSQL,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "【执行】"+"【"+showCreateViewSql+"】【验证】【视图】【"+viewNam1+"】【❌】");
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(stuSQL, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -658,13 +702,13 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
appendToFile(answerLogPath, "==================储存过程==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================储存过程==================");
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
|
||||
|
||||
AtomicReference<String> stuAnswer = new AtomicReference<>();
|
||||
|
||||
AtomicReference<String> fileName = new AtomicReference<>();
|
||||
// 根据sql 的内容查询结果文件夹语句的文件名,再根据文件名 查找 考生
|
||||
try {
|
||||
String finalSql = sql;
|
||||
@@ -679,6 +723,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
String stuPath=fileStu+"\\"+filePaths.getFileName();
|
||||
stuAnswer.set(readSQLFromFile(stuPath));
|
||||
fileName.set(String.valueOf(filePaths.getFileName()));
|
||||
System.out.println("考生语句"+stuAnswer);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -703,23 +748,23 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (extractCallStatements != null && extractCallStatements.size() > 0) {
|
||||
boolean hasError = false; // 添加标志变量
|
||||
for (String extractCallStatement : extractCallStatements) {
|
||||
appendToFile(answerLogPath, "测试 call 语句:" + extractCallStatement);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "测试 call 语句:" + extractCallStatement);
|
||||
// appendToFile(answerLogPath, "测试 call 语句:" + extractCallStatement);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "测试 call 语句:" + extractCallStatement);
|
||||
|
||||
try {
|
||||
|
||||
ResultSet newResult = stmt.executeQuery(extractCallStatement);
|
||||
anwerResults.addAll(extractResults(newResult));
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行标准库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
}
|
||||
try (Connection connstu = DriverManager.getConnection(stuDbUrl, user, password);
|
||||
Statement stmtstu = connstu.createStatement()) {
|
||||
if (StringUtils.isBlank(stuAnswer.get())) {
|
||||
SourceAndText sourceAndTextError = new SourceAndText();
|
||||
appendToFile(answerLogPath, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
appendToFile(answerLogPath, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
sourceAndTextError.setText(judgementStr);
|
||||
sourceAndTextError.setScore(0.0);
|
||||
continue;
|
||||
@@ -730,8 +775,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
ResultSet oldResult = stmtstu.executeQuery(extractCallStatement);
|
||||
stuResults.addAll(extractResults(oldResult));
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行学生库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行学生库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库 SQL CALL 语句时发生错误: " + e.getMessage());
|
||||
hasError = true; // 发生异常,设为 true
|
||||
}
|
||||
}
|
||||
@@ -739,16 +784,21 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
// 比较结果(如果发生异常,可以认为比较失败)
|
||||
MysqlBooleanVo mysqlBooleanVo = compareExtractResults(anwerResults, stuResults,judgementStr);
|
||||
judgementStr=mysqlBooleanVo.getText();
|
||||
// judgementStr=mysqlBooleanVo.getText();
|
||||
boolean flag= !hasError &&mysqlBooleanVo.isFlag();
|
||||
|
||||
if (flag) {
|
||||
//todo 得分
|
||||
appendToFile(answerLogPath, "【执行】"+extractCallStatements+"【验证】【文件】【"+fileName.get()+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【执行】"+extractCallStatements+"【验证】【文件】 【"+fileName.get()+"】【✅】");
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,stuAnswer.get(),totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
appendToFile(answerLogPath, "【执行】"+extractCallStatements+"【验证】【文件】【"+fileName.get()+"】【❌】");
|
||||
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【执行】"+extractCallStatements+"【验证】【文件】【"+fileName.get()+"】【❌】");
|
||||
//得分
|
||||
SourceAndText studentScorePojo = calculateTotalScoreRate(stuAnswer.get(), examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
@@ -767,13 +817,13 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
|
||||
|
||||
AtomicReference<String> stuAnswer = new AtomicReference<>();
|
||||
|
||||
AtomicReference<String> fileName = new AtomicReference<>();
|
||||
// 根据sql 的内容查询结果文件夹语句的文件名,再根据文件名 查找 考生
|
||||
try {
|
||||
String finalSql = sql;
|
||||
@@ -787,6 +837,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (normalizedFinalSql.equals(normalizedFileContent)) {
|
||||
|
||||
String stuPath=fileStu+"\\"+filePaths.getFileName();
|
||||
fileName.set(String.valueOf(filePaths.getFileName()));
|
||||
stuAnswer.set(readSQLFromFile(stuPath));
|
||||
System.out.println("考生语句"+stuAnswer);
|
||||
}
|
||||
@@ -822,8 +873,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
answerSQL = createTriggerSqlExport;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行答案语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行答案语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行答案语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行答案语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -832,8 +883,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
Statement stmtstu = connstu.createStatement()) {
|
||||
if (StringUtils.isBlank(stuAnswer.get())) {
|
||||
SourceAndText sourceAndTextError = new SourceAndText();
|
||||
appendToFile(answerLogPath, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌考生SQL文件丢失或未作答,无法评分,得分:0.0");
|
||||
appendToFile(answerLogPath, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "考生SQL文件丢失或未作答,无法评分,得分:0.0【❌】");
|
||||
sourceAndTextError.setText(judgementStr);
|
||||
sourceAndTextError.setScore(0.0);
|
||||
continue;
|
||||
@@ -844,8 +895,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
stuSQL = createTriggerSqlExport;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "执行学生库语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生库语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "执行学生语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "执行学生语句" + showCreateTriggerSql + "时发生错误: " + e.getMessage());
|
||||
hasError = true; // 发生异常,设为 true
|
||||
}
|
||||
}
|
||||
@@ -876,6 +927,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
boolean equals = normalizedTriggerSql1.equals(normalizedTriggerSql2);
|
||||
if (equals) {
|
||||
appendToFile(answerLogPath, "【文件】 【"+fileName.get()+"】【✅】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【文件】 【"+fileName.get()+"】【✅】");
|
||||
//todo 得分
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList, total, answerLogPath, stuAnswer.get(), totalKeyScore, score, answerId, scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
@@ -883,6 +936,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
}
|
||||
else {
|
||||
appendToFile(answerLogPath, "【文件】 【"+fileName.get()+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【文件】 【"+fileName.get()+"】【❌】");
|
||||
SourceAndText studentScorePojo = calculateTotalScoreRate(stuAnswer.get(), examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -890,6 +945,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
|
||||
else {
|
||||
appendToFile(answerLogPath, "【文件】 【"+fileName.get()+"】【❌】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【文件】 【"+fileName.get()+"】【❌】");
|
||||
SourceAndText studentScorePojo = calculateTotalScoreRate(stuAnswer.get(), examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
@@ -901,14 +958,25 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (sql.trim().toUpperCase().startsWith("ALTER TABLE")) {
|
||||
appendToFile(answerLogPath, "=================修改表语句==================");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "==================修改表语句==================");
|
||||
appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// appendToFile(answerLogPath, "答案语句: " + sql);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案语句: ");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, sql);
|
||||
// 匹配成功
|
||||
String answerId = examQuestionAnswer.getAnswerId();
|
||||
List<ExamMysqlKeyword> examMysqlKeywordList= examMysqlKeywordMapper.selectListByAnswerId(answerId);
|
||||
//转换成select语句
|
||||
String selectSql = convertAlertToSelectWhere(sql);
|
||||
// 正则提取表名和字段名(支持反引号)
|
||||
Pattern pattern = Pattern.compile(
|
||||
"ALTER\\s+TABLE\\s+`?(\\w+)`?\\s+MODIFY\\s+COLUMN\\s+`?(\\w+)`?",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("无法解析 UPDATE 语句");
|
||||
}
|
||||
|
||||
String tableName = matcher.group(1);
|
||||
|
||||
List<List<String>> answerList= new ArrayList<>();
|
||||
List<List<String>> answerListStu = new ArrayList<>();
|
||||
@@ -916,12 +984,12 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
Statement stmtan = connanswer.createStatement()) {
|
||||
try (ResultSet answer = stmtan.executeQuery(selectSql)) {
|
||||
answerList = getAnswerList(answer);
|
||||
appendToFile(answerLogPath, "查找语句标准答案");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案");
|
||||
// appendToFile(answerLogPath, "查找语句标准答案");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "查找语句标准答案");
|
||||
printResult(answerList,judgementStr);
|
||||
}catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "答案表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -930,12 +998,12 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
Statement stmtstu = connstu.createStatement()) {
|
||||
try (ResultSet answer = stmtstu.executeQuery(selectSql)) {
|
||||
answerListStu = getAnswerList(answer);
|
||||
appendToFile(answerLogPath, "运行学生语句的查询结果:");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行学生语句的查询结果:");
|
||||
judgementStr= printResult(answerListStu,judgementStr);
|
||||
// appendToFile(answerLogPath, "运行学生语句的查询结果:");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "运行学生语句的查询结果:");
|
||||
// judgementStr= printResult(answerListStu,judgementStr);
|
||||
} catch (SQLException e) {
|
||||
appendToFile(answerLogPath, "学生表执行验证语句"+selectSql+"时发生错误:" + e.getMessage());
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
// appendToFile(answerLogPath, "学生表执行验证语句"+selectSql+"时发生错误:" + e.getMessage());
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生表执行验证语句"+selectSql+"时发生错误: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -947,14 +1015,33 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
//
|
||||
if (isEquivalent) {
|
||||
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+selectSql+"】 【验证】 【表】 【"+tableName+"】【✅】");
|
||||
|
||||
|
||||
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
} else {
|
||||
SourceAndText studentScorePojo= calculateTotalScoreRate(sql, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
|
||||
|
||||
if (answerListStu.size() >= 2) {
|
||||
List<String> fieldMeta = answerListStu.get(0);
|
||||
List<String> fieldValue = answerListStu.get(1);
|
||||
|
||||
Map<String, String> columnInfo = new HashMap<>();
|
||||
for (int i = 0; i < fieldMeta.size() && i < fieldValue.size(); i++) {
|
||||
columnInfo.put(fieldMeta.get(i), fieldValue.get(i));
|
||||
}
|
||||
|
||||
String alterSQL = buildAlterFromShowColumn(tableName, columnInfo);
|
||||
appendToFile(answerLogPath, "【执行】 "+"【"+selectSql+"】 【验证】 【表】 【"+tableName+"】【❌】");
|
||||
SourceAndText studentScorePojo = calculateTotalScoreRate(alterSQL, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal, judgementStr);
|
||||
scoreTotal += studentScorePojo.getScore();
|
||||
judgementStr = studentScorePojo.getText();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -974,7 +1061,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
}
|
||||
}
|
||||
appendToFile(answerLogPath, "共得分:" + String.format("%.2f", scoreTotal));
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "共得分:" + String.format("%.2f", scoreTotal));
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "共得分:" + String.format("%.2f", scoreTotal));
|
||||
folderzip.delete();
|
||||
deleteFolder(folder);
|
||||
//todo 删除学生答题的数据库连接 单独写一个接口
|
||||
@@ -1000,6 +1087,31 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
return null;
|
||||
}
|
||||
public static String buildAlterFromShowColumn(String tableName, Map<String, String> columnInfo) {
|
||||
String field = columnInfo.get("Field");
|
||||
String type = columnInfo.get("Type");
|
||||
String isNull = columnInfo.get("Null");
|
||||
String defaultVal = columnInfo.get("Default");
|
||||
|
||||
StringBuilder sb = new StringBuilder("ALTER TABLE ");
|
||||
sb.append(tableName).append(" MODIFY COLUMN ").append(field).append(" ").append(type);
|
||||
|
||||
if ("YES".equalsIgnoreCase(isNull)) {
|
||||
sb.append(" NULL");
|
||||
} else {
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
|
||||
if (defaultVal != null && !"".equals(defaultVal)) {
|
||||
sb.append(" DEFAULT '").append(defaultVal).append("'");
|
||||
} else {
|
||||
sb.append(" DEFAULT NULL");
|
||||
}
|
||||
|
||||
sb.append(";");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delMysqlConnect(List<String> tNames) {
|
||||
@@ -1141,8 +1253,8 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
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)){
|
||||
appendToFile(answerLogPath, "❌该语句找不到试题id,请检查出题内容!" );
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌该语句找不到试题id,请检查出题内容!");
|
||||
appendToFile(answerLogPath, "该语句找不到试题id,请检查出题内容!");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "该语句找不到试题id,请检查出题内容!");
|
||||
sourceAndText.setText(judgementStr);
|
||||
sourceAndText.setScore(0.0);
|
||||
//返回累加的总分
|
||||
@@ -1167,21 +1279,21 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
String[] lines = sql2.split("\\r?\\n");
|
||||
|
||||
// 开头:✅学生语句:
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅学生语句:");
|
||||
// 第一行直接加在后面
|
||||
if (lines.length > 0) {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, StringEscapeUtils.escapeHtml4(lines[0]));
|
||||
}
|
||||
|
||||
// 后续行添加换行和缩进
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr," "+ StringEscapeUtils.escapeHtml4(lines[i].trim()));
|
||||
}
|
||||
// // 开头:✅学生语句:
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅学生语句:");
|
||||
// // 第一行直接加在后面
|
||||
// if (lines.length > 0) {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, StringEscapeUtils.escapeHtml4(lines[0]));
|
||||
// }
|
||||
//
|
||||
// // 后续行添加换行和缩进
|
||||
// for (int i = 1; i < lines.length; i++) {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr," "+ StringEscapeUtils.escapeHtml4(lines[i].trim()));
|
||||
// }
|
||||
// 最终加入 judgementStr
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,",正确,语句得分权值:"+scoreRateStr + ",得分" + singleScore);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【语句得分权值】:【"+scoreRateStr + "】,【得分】【" + singleScore+"】");
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅学生语句" + sql2 + "正确,语句得分权值:" + scoreRateStr + ",得分" + singleScore);
|
||||
appendToFile(answerLogPath, "✅学生语句" + sql2 + "正确,语句得分权值:" + scoreRateStr + ",得分" + singleScore);
|
||||
appendToFile(answerLogPath, "【语句得分权值】:【"+scoreRateStr + "】,【得分】【" + singleScore+"】");
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("无效的totalKeyScore值:" + totalKeyScore);
|
||||
}
|
||||
@@ -1263,8 +1375,23 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
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) ||StringUtils.isBlank(sql)){
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌该语句未作答,得分:0.0");
|
||||
appendToFile(answerLogPath, "❌该语句未作答,得分:0.0");
|
||||
|
||||
if (examQuestionKeywords!=null&&examQuestionKeywords.size()>0){
|
||||
for (ExamMysqlKeyword keyword : examQuestionKeywords) {
|
||||
String keywordValue = keyword.getKeyword();
|
||||
if (keywordValue != null && !keywordValue.isEmpty() ) {
|
||||
// 使用正则,确保是完整单词(字段)匹配
|
||||
String regex = keywordValue;
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【关键字】 【"+regex+"】 "+"【❌】");
|
||||
appendToFile(answerLogPath,"【关键字】 【"+regex+"】 "+"【❌】");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"该语句未设置关键字!");
|
||||
appendToFile(answerLogPath,"该语句未设置关键字!");
|
||||
}
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "该语句未作答,得分:0.0 【❌】");
|
||||
appendToFile(answerLogPath, "该语句未作答,得分:0.0 【❌】");
|
||||
sourceAndText.setText(judgementStr);
|
||||
sourceAndText.setScore(0.0);
|
||||
//返回累加的总分
|
||||
@@ -1273,8 +1400,6 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
//用answerid查对应答案的权值 。除以总权值
|
||||
String scoreRateStr= examQuestionAnswerMapper.selectExamQuestionAnswerScoreByAnswerId(answerId);
|
||||
|
||||
|
||||
|
||||
// 解析权值
|
||||
double scoreRate = 0.0;
|
||||
double totalKey = 0.0;
|
||||
@@ -1306,11 +1431,15 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
if (sql.contains(regex)) {
|
||||
try {
|
||||
totalScoreRate += Integer.parseInt(keyword.getScoreRate());
|
||||
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【关键字】 【"+regex+"】 "+"【✅】");
|
||||
appendToFile(answerLogPath,"【关键字】 【"+regex+"】 "+"【✅】");
|
||||
matchedKeywords.add(keywordValue);
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Invalid scoreRate format for keyword: " + keywordValue);
|
||||
}
|
||||
}else {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【关键字】 【"+regex+"】 "+"【❌】");
|
||||
appendToFile(answerLogPath,"【关键字】 【"+regex+"】 "+"【❌】");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1334,22 +1463,27 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
String[] lines = sql.split("\\r?\\n");
|
||||
|
||||
// 开头:✅学生语句:
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌学生语句:");
|
||||
// 第一行直接加在后面
|
||||
if (lines.length > 0) {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, StringEscapeUtils.escapeHtml4(lines[0]));
|
||||
}
|
||||
|
||||
// 开头:学生语句:
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌学生语句:");
|
||||
// // 第一行直接加在后面
|
||||
// if (lines.length > 0) {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, StringEscapeUtils.escapeHtml4(lines[0]));
|
||||
// }
|
||||
// 后续行添加换行和缩进
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr," "+StringEscapeUtils.escapeHtml4(lines[i].trim()));
|
||||
}
|
||||
// 最终加入 judgementStr
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,",不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore);
|
||||
// for (int i = 1; i < lines.length; i++) {
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr," "+StringEscapeUtils.escapeHtml4(lines[i].trim()));
|
||||
// }
|
||||
// 最终加入 judgementStr【
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【语句权值】:【"+scoreRateStr+"】,【关键字权值】:【"+totalKeyScoreInt+"】");
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr,"【答对关键得分权值】:【"+ totalScoreRate+ "】,【语句得分】:【" + finalRoundedScore+"】");
|
||||
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌语句"+sql+"不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore);
|
||||
|
||||
appendToFile(answerLogPath,"❌语句"+sql+"不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore);
|
||||
|
||||
|
||||
appendToFile(answerLogPath,"【语句权值】:【"+scoreRateStr+"】,【关键字权值】:【"+totalKeyScoreInt+"】");
|
||||
appendToFile(answerLogPath,"【答对关键得分权值】:【"+ totalScoreRate+ "】,【得分】:【" + finalRoundedScore+"】");
|
||||
// appendToFile(answerLogPath,"❌语句"+sql+"不正确,语句权值:"+scoreRateStr+",关键权值:"+totalKeyScoreInt+",答对得分点为:"+matchedKeywords+",答对关键得分权值"+ totalScoreRate+ ",得分" + finalRoundedScore);
|
||||
sourceAndText.setText(judgementStr);
|
||||
sourceAndText.setScore(finalRoundedScore);
|
||||
//返回累加的总分
|
||||
@@ -1600,7 +1734,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
|
||||
public static List<String> extractCallStatements(String sql) {
|
||||
List<String> callStatements = new ArrayList<>();
|
||||
Pattern callPattern = Pattern.compile("CALL\\s+\\w+\\s*\\([^;]*?\\);", Pattern.CASE_INSENSITIVE);
|
||||
Pattern callPattern = Pattern.compile("CALL\\s+\\w+\\s*\\([^\\)]*\\)\\s*;?", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = callPattern.matcher(sql);
|
||||
|
||||
while (matcher.find()) {
|
||||
@@ -1735,7 +1869,7 @@ public class IMysqlLocalServiceImpl implements IMysqlLocalService {
|
||||
private static String readSQLFromFile(String filePath) throws IOException {
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("❌ 找不到SQL文件:" + filePath);
|
||||
throw new FileNotFoundException("找不到SQL文件:" + filePath+"❌");
|
||||
}
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class FileServericeImpl implements IFileServerice {
|
||||
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
|
||||
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
|
||||
appendToFile(answerLogPath,"得分:"+roundedScoreRatio*score);
|
||||
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "得分:"+roundedScoreRatio*score);
|
||||
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "得分:"+roundedScoreRatio*score);
|
||||
sourceAndText.setScore(roundedScoreRatio*score);
|
||||
sourceAndText.setText(judgementStr);
|
||||
return sourceAndText;
|
||||
|
||||
Reference in New Issue
Block a user