【修改】mysql判分分析,mysql出题增加数据库名,试卷换题增加关键字搜索

This commit is contained in:
YOHO\20373
2025-06-16 22:18:02 +08:00
parent 70ad20151a
commit 2669397cd6
11 changed files with 154 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionKeyword;
import pc.exam.pp.module.exam.dal.mysql.question.ExamMysqlKeywordMapper;
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionAnswerMapper;
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
import pc.exam.pp.module.judgement.controller.service.mysql.vo.MysqlVo;
import pc.exam.pp.module.judgement.controller.utils.Mysql.MySQLExporterUtil;
import pc.exam.pp.module.judgement.controller.utils.Mysql.SQLComparatorUtil;
import pc.exam.pp.module.judgement.controller.utils.Mysql.SqlFileProcessor;
@@ -287,8 +288,8 @@ public class MysqlServericeImpl implements IMysqlServerice {
table1Columns.add(column);
}
appendToFile(answerLogPath, "标准答案建表键值对:"+table1Columns);
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "标准答案建表键值对:"+table1Columns);
// appendToFile(answerLogPath, "标准答案建表键值对:"+table1Columns);
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "标准答案建表键值对:"+table1Columns);
}
@@ -306,19 +307,27 @@ public class MysqlServericeImpl implements IMysqlServerice {
column.put("EXTRA", rsstu.getString("EXTRA"));
table2Columns.add(column);
}
appendToFile(answerLogPath, "学生答案建表键值对:"+table2Columns);
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生答案建表键值对:"+table2Columns);
// appendToFile(answerLogPath, "学生答案建表键值对:"+table2Columns);
// judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "学生答案建表键值对:"+table2Columns);
}
}
String sql3 = resultStu.get(entry.getKey());
Matcher matcherStu = pattern.matcher(sql3);
String tableNameStu ="";
if (matcherStu.find()) {
tableNameStu= matcherStu.group(1).replace("`", ""); // 获取表名
}
String yuju= compareTables(table1Columns, table2Columns, examQuestion.getTname(),tableName, tableNameStu,judgementStr);
judgementStr=yuju;
if (table1Columns.equals(table2Columns)) {
//
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList,total,answerLogPath,sql3,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
} else {
SourceAndText studentScorePojo= calculateTotalScoreRate(sql2, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
SourceAndText studentScorePojo= calculateTotalScoreRate(sql3, examMysqlKeywordList,totalKeyScore,score,answerId,scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
}
@@ -788,7 +797,8 @@ public class MysqlServericeImpl implements IMysqlServerice {
if (equals) {
//todo 得分
SourceAndText studentScorePojo = accumulateScoreAndLog(examMysqlKeywordList, total, answerLogPath, sql2, totalKeyScore, score, answerId, scoreTotal,judgementStr);
scoreTotal += studentScorePojo.getScore();
judgementStr = studentScorePojo.getText();
} else {
SourceAndText studentScorePojo = calculateTotalScoreRate(sql2, examMysqlKeywordList, totalKeyScore, score, answerId, scoreTotal,judgementStr);
@@ -824,7 +834,88 @@ public class MysqlServericeImpl implements IMysqlServerice {
return sourceAndText;
}
private static String compareTables(Set<Map<String, String>> standardSet, Set<Map<String, String>> studentSet, String dbTable, String tableName,String tableNameStu,String judgementStr) {
String yuju="";
int index = 1;
// 判断表名是否一致
String tableNameCheck = tableName.equalsIgnoreCase(tableNameStu) ? "" : "x";
// 输出
System.out.printf("%02d.【数据表】【%s】【名称】【%s】【%s】\n", index, dbTable, tableName, tableNameCheck);
appendToFile(answerLogPath, "%02d.【数据表】【%s】【名称】【%s】【%s】\n", index, dbTable, tableName, tableNameCheck);
judgementStr = HtmlAppender.appendHtmlLineMysql(judgementStr, "%02d.【数据表】【%s】【名称】【%s】【%s】\n", index, dbTable, tableName, tableNameCheck);
// 把Set转成Map方便通过字段名快速取值
Map<String, Map<String, String>> standardMap = convertSetToMap(standardSet);
Map<String, Map<String, String>> studentMap = convertSetToMap(studentSet);
for (String columnName : standardMap.keySet()) {
Map<String, String> stdCol = standardMap.get(columnName);
Map<String, String> stuCol = studentMap.get(columnName);
String fullName = dbTable + "." + columnName;
String nameCheck = stuCol != null ? "" : "x";
judgementStr = HtmlAppender.appendHtmlLineMysql(judgementStr, "%02d.【字段】【%s】【名称】【%s】【%s】\n", index++, fullName, columnName, nameCheck);
appendToFile(answerLogPath, "%02d.【字段】【%s】【名称】【%s】【%s】\n", index++, fullName, columnName, nameCheck);
if (stuCol != null) {
MysqlVo mysqlVo1 = compareField(index, fullName, "类型", stdCol.get("COLUMN_TYPE"), stuCol.get("COLUMN_TYPE"),judgementStr);
index=mysqlVo1.getIndex();
yuju=mysqlVo1.getText();
MysqlVo mysqlVo2 = compareField(index, fullName, "允许为空", stdCol.get("IS_NULLABLE"), stuCol.get("IS_NULLABLE"),yuju);
index=mysqlVo2.getIndex();
yuju=mysqlVo2.getText();
MysqlVo mysqlVo3 = compareField(index, fullName, "扩展", stdCol.get("EXTRA"), stuCol.get("EXTRA"),yuju);
index=mysqlVo3.getIndex();
yuju=mysqlVo3.getText();
MysqlVo mysqlVo4 = compareField(index, fullName, "键类型", stdCol.get("COLUMN_KEY"), stuCol.get("COLUMN_KEY"),yuju);
yuju=mysqlVo4.getText();
} else {
// 缺失字段,直接输出所有属性错误
MysqlVo mysqlVo1 = printMissing(index, fullName, "类型", stdCol.get("COLUMN_TYPE"),judgementStr);
index=mysqlVo1.getIndex();
yuju=mysqlVo1.getText();
MysqlVo mysqlVo2 = printMissing(index, fullName, "允许为空", stdCol.get("IS_NULLABLE"),yuju);
index=mysqlVo2.getIndex();
yuju=mysqlVo2.getText();
MysqlVo mysqlVo3 = printMissing(index, fullName, "扩展", stdCol.get("EXTRA"),yuju);
index=mysqlVo3.getIndex();
yuju=mysqlVo3.getText();
MysqlVo mysqlVo4 = printMissing(index, fullName, "键类型", stdCol.get("COLUMN_KEY"),yuju);
yuju=mysqlVo4.getText();
}
}
return yuju;
}
private static MysqlVo compareField(int index, String fullName, String property, String stdValue, String stuValue, String judgementStr) {
MysqlVo mysqlVo=new MysqlVo();
String mark = stdValue.equalsIgnoreCase(stuValue) ? "" : "x";
System.out.printf("%02d.【字段】【%s】【%s】【%s】【%s】\n", index, fullName, property, stuValue, mark);
appendToFile(answerLogPath, "%02d.【字段】【%s】【%s】【%s】【%s】\n", index, fullName, property, stuValue, mark);
judgementStr = HtmlAppender.appendHtmlLineMysql(judgementStr, "%02d.【字段】【%s】【%s】【%s】【%s】\n", index, fullName, property, stuValue, mark);
mysqlVo.setText(judgementStr);
mysqlVo.setIndex(index + 1);
return mysqlVo;
}
private static MysqlVo printMissing(int index, String fullName, String property, String stdValue,String judgementStr) {
MysqlVo mysqlVo=new MysqlVo();
System.out.printf("%02d.【字段】【%s】【%s】【%s】【x】\n", index, fullName, property, stdValue);
appendToFile(answerLogPath, "%02d.【字段】【%s】【%s】【%s】【x】\n", index, fullName, property, stdValue);
judgementStr = HtmlAppender.appendHtmlLineMysql(judgementStr, "%02d.【字段】【%s】【%s】【%s】【x】\n", index, fullName, property, stdValue);
mysqlVo.setText(judgementStr);
mysqlVo.setIndex(index + 1);
return mysqlVo;
}
private static Map<String, Map<String, String>> convertSetToMap(Set<Map<String, String>> set) {
Map<String, Map<String, String>> map = new LinkedHashMap<>();
for (Map<String, String> column : set) {
map.put(column.get("COLUMN_NAME"), column);
}
return map;
}
public static void deleteFolder(File folder) {
if (folder.isDirectory()) {
File[] files = folder.listFiles();
@@ -1448,4 +1539,16 @@ public class MysqlServericeImpl implements IMysqlServerice {
e.printStackTrace();
}
}
public static void appendToFile(String filePath, String format, Object... args) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) {
String timestamp = LocalDateTime.now().format(formatter);
String content = String.format(format, args);
String logLine = String.format("[%s] %s", timestamp, content);
writer.write(logLine);
writer.newLine(); // 可选:添加换行符
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,16 @@
package pc.exam.pp.module.judgement.controller.service.mysql.vo;
import lombok.Data;
@Data
public class MysqlVo {
/**
* 序列
*/
private int index;
/**
* 文本
*/
private String text;
}

View File

@@ -20,6 +20,18 @@ public class HtmlAppender {
return result.toString();
}
public static String appendHtmlLineMysql(String originalText, String format, Object... args) {
StringBuilder result = new StringBuilder(originalText == null ? "" : originalText);
if (format != null && !format.isEmpty()) {
String newLine = String.format(format, args);
result.append("<p>")
.append(escapeHtml(newLine))
.append("</p>\n");
}
return result.toString();
}
// 简单HTML转义防止注入攻击
private static String escapeHtml(String text) {