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

Merge Request: 【新增】mysql判分关键点,【修改】mysql判分全部读文件,后面改到云数据库上

Created By: @华允传
Accepted By: @华允传
URL: https://g-iswv8783.coding.net/p/education/d/pengchen-exam-java/git/merge/56?initial=true
This commit is contained in:
华允传
2025-05-13 17:50:24 +08:00
committed by Coding
7 changed files with 1043 additions and 1286 deletions

View File

@@ -0,0 +1,35 @@
package pc.exam.pp.module.exam.dal.dataobject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@TableName(value = "exam_mysql_keyword", autoResultMap = true)
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class ExamMysqlKeyword {
/**
* 主键id
*/
@TableId(type = IdType.INPUT)
private String keywordId;
/**
* 答案id
*/
private String answerId;
/**
* 关键字
*/
private String keyword;
/**
* 权值
*/
private String scoreRate;
}

View File

@@ -0,0 +1,14 @@
package pc.exam.pp.module.exam.dal.mysql.question;
import org.apache.ibatis.annotations.Mapper;
import pc.exam.pp.module.exam.dal.dataobject.ExamMysqlKeyword;
import java.util.List;
@Mapper
public interface ExamMysqlKeywordMapper {
List<ExamMysqlKeyword> selectListByAnswerId(String answerId);
String selectByAnswerIds(List<String> answerIdList);
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pc.exam.pp.module.exam.dal.mysql.question.ExamMysqlKeywordMapper">
<resultMap type="ExamMysqlKeyword" id="ExamMysqlKeywordResult">
<result property="keywordId" column="keyword_id" />
<result property="answerId" column="answer_id" />
<result property="keyword" column="keyword" />
<result property="scoreRate" column="score_rate" />
</resultMap>
<sql id="selectExamMysqlKeywordVo">
select keyword_id, answer_id, keyword, score_rate from exam_mysql_keyword
</sql>
<select id="selectListByAnswerId" resultMap="ExamMysqlKeywordResult">
<include refid="selectExamMysqlKeywordVo"/>
where answer_id =#{answerId}
</select>
<select id="selectByAnswerIds" resultType="java.lang.String" parameterType="java.util.List">
SELECT CAST(SUM(CAST(score_rate AS UNSIGNED)) AS CHAR)
FROM exam_mysql_keyword
WHERE answer_id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@@ -4,13 +4,14 @@ package pc.exam.pp.module.judgement.controller.service.mysql;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public interface IMysqlServerice {
double Judgement(double sorce, ExamQuestion examQuestion) throws IOException, SQLException;
double Judgement(double sorce, File file, ExamQuestion examQuestion) throws IOException, SQLException;

View File

@@ -8,6 +8,8 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* SQL 查询结果比较工具类
@@ -145,5 +147,86 @@ public class SQLComparatorUtil {
// 比较行数据(无顺序)
return rowSet1.equals(rowSet2);
}
//比较两个udate语句
public static boolean areUpdateStatementsEqual(String updateQuery1, String updateQuery2) {
// 1. 提取表名(忽略大小写)
String tableName1 = extractTableName(updateQuery1);
String tableName2 = extractTableName(updateQuery2);
if (tableName1 == null || tableName2 == null || !tableName1.equalsIgnoreCase(tableName2)) {
return false;
}
// 2. 提取 SET 和 WHERE 部分,移除表名前缀,统一格式
String setPart1 = normalizeSqlPart(extractSetPart(updateQuery1), tableName1);
String setPart2 = normalizeSqlPart(extractSetPart(updateQuery2), tableName2);
if (!setPart1.equalsIgnoreCase(setPart2)) {
return false;
}
String wherePart1 = normalizeSqlPart(extractWherePart(updateQuery1), tableName1);
String wherePart2 = normalizeSqlPart(extractWherePart(updateQuery2), tableName2);
return wherePart1.equalsIgnoreCase(wherePart2);
}
// 提取表名
private static String extractTableName(String updateQuery) {
Pattern pattern = Pattern.compile("UPDATE\\s+([a-zA-Z0-9_]+)", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(updateQuery);
return matcher.find() ? matcher.group(1).trim() : null;
}
// 提取 SET 子句
private static String extractSetPart(String updateQuery) {
Pattern pattern = Pattern.compile("SET\\s+(.*?)\\s+WHERE", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(updateQuery);
return matcher.find() ? matcher.group(1).trim() : null;
}
// 提取 WHERE 子句
private static String extractWherePart(String updateQuery) {
Pattern pattern = Pattern.compile("WHERE\\s+(.*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(updateQuery);
return matcher.find() ? matcher.group(1).trim() : null;
}
// 移除表前缀和多余空格
private static String normalizeSqlPart(String part, String tableName) {
if (part == null) return null;
return part.replaceAll("(?i)\\b" + Pattern.quote(tableName) + "\\.", "") // 去掉表名前缀
.replaceAll("\\s+", " ") // 统一空格
.trim();
}
// 标准化 SQL 字符串
public static String simplifyCreateTableSql(String sql) {
if (sql == null || sql.isEmpty()) return sql;
// 移除字段中的 CHARACTER SET 和 COLLATE
sql = sql.replaceAll("(?i)CHARACTER SET\\s+\\w+", "");
sql = sql.replaceAll("(?i)COLLATE\\s+\\w+", "");
// 移除主键中的 USING BTREE
sql = sql.replaceAll("(?i)USING\\s+BTREE", "");
// 移除表级 ENGINE、AUTO_INCREMENT、CHARSET、COLLATE、ROW_FORMAT
sql = sql.replaceAll("(?i)ENGINE\\s*=\\s*\\w+", "");
sql = sql.replaceAll("(?i)AUTO_INCREMENT\\s*=\\s*\\d+", "");
sql = sql.replaceAll("(?i)(DEFAULT\\s+)?CHARSET\\s*=\\s*\\w+", "");
sql = sql.replaceAll("(?i)CHARACTER SET\\s*=\\s*\\w+", "");
sql = sql.replaceAll("(?i)ROW_FORMAT\\s*=\\s*\\w+", "");
sql = sql.replaceAll("(?i)COLLATE\\s*=\\s*\\w+", "");
// 清理多余逗号与空格
sql = sql.replaceAll(",\\s*\\)", "\n)");
sql = sql.replaceAll(" +", " ");
sql = sql.replaceAll("(?m)^\\s*$", ""); // 清除空行
sql = sql.trim();
return sql;
}
}

View File

@@ -230,7 +230,6 @@ public class AutoToolsServiceImpl implements AutoToolsService{
if (cs_file_list!=null){
for (File one_file : cs_file_list) {
// 6、根据试题ID查询试题详情
// String qu_id = file.getName();
String qu_id = file.getName();
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id);
if (examQuestion != null) {
@@ -238,29 +237,32 @@ public class AutoToolsServiceImpl implements AutoToolsService{
// --- 7.1、查询试题文件
File qu_file = new File(one_file.getPath());
File[] qu_file_list = qu_file.listFiles();
if (qu_file_list == null) continue;
if (qu_file_list == null) continue;
// --- 7.2、通过文件名称进行判分
// for (File file_one : qu_file_list) {
// 判断名称 类似于 C语言程序设计。 课程+题型
if (one_file.getName().split("\\.")[0].equals(examQuestion.getCourseName()+examQuestion.getSubjectName())) {
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), one_file.getName(), examQuestion);
for (File file_one : qu_file_list) {
// 判断名称 类似于 C语言程序设计。 课程+题型
System.out.println(one_file.getName());
if (one_file.getName().split("\\.")[0].equals(examQuestion.getCourseName()+examQuestion.getSubjectName())) {
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), file_one.getName(), examQuestion);
score += c_score;
System.out.println(c_score+"C语言程序设计得分");
break;
}
// wps 类型存在多级文文件夹,需要个性化设置
if (one_file.getName().split("\\.")[0].equals("文档")) {
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), one_file.getPath(), examQuestion);
if (file_one.getName().split("\\.")[0].equals("文档")) {
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
score += wps_word_score;
System.out.println(wps_word_score+"wps得分");
break;
}
// D:\1d70c404e6d42d144d0028496e893565dd2dec447f7e9b1db66466f00472424d\160\cb3cc9089b104a1e9e92deb330d0cfe8\d9f988d5ae6d435ba12d4d979d044219\stu
//windows文件处理
if (one_file.getName().equals("stu")) {
File win_file = new File(one_file.getPath());
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
score += win_file_score;
System.out.println(win_file_score+"windows文件处理得分");
break;
}
System.out.println(one_file);
//浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if (one_file.getName().equals("edge")) {
@@ -268,8 +270,20 @@ public class AutoToolsServiceImpl implements AutoToolsService{
File edge_file = new File(one_file.getPath());
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
score += browse_score;
System.out.println(browse_score+"浏览器操作得分");
break;
}
// }
if (one_file.getName().equals("mysql")) {
System.out.println(one_file);
File mysql_file = new File(one_file.getPath());
double judgement = mysqlServerice.Judgement(20.0,mysql_file, examQuestion);
score+=judgement;
System.out.println(judgement+"mysql得分");
break;
}
}
}
@@ -277,15 +291,13 @@ public class AutoToolsServiceImpl implements AutoToolsService{
}
}
ExamQuestion mysql=new ExamQuestion();
double judgement = mysqlServerice.Judgement(20, mysql);
score+=judgement;
// 8、将解压之后得问及那继续重新压缩并上传到服务器并删除文件和文件夹
String zipPath = FolderZipper.zipFolder(files[0].getPath());
// 9、上传文件
MultipartFile file = new CustomMultipartFile(zipPath);
MultipartFile file = new CustomMultipartFile(zipPath);
String path = null;
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
// 10、将分数存入数据库
StuPaperScoreDO stuPaperScoreDO = new StuPaperScoreDO();
stuPaperScoreDO.setStuId(stuId);