【新增】mysql、浏览器、win文件判分,试卷任务学生端接口,监控管理后端接口

This commit is contained in:
YOHO\20373
2025-05-07 09:49:46 +08:00
parent d2c9c399d7
commit cdb75a5b44
28 changed files with 362 additions and 85 deletions

View File

@@ -21,9 +21,9 @@ public class BrowserComtroller {
* 浏览器判分
* @return 得分
*/
@PostMapping("/run_judgement")
public CommonResult run_C_code() throws IOException {
return CommonResult.success(browserServerice.Judgement());
}
// @PostMapping("/run_judgement")
// public CommonResult run_C_code() throws IOException {
// return CommonResult.success(browserServerice.Judgement());
// }
}

View File

@@ -25,9 +25,9 @@ public class MysqlController {
* Mysql判分
* @return 得分
*/
@PostMapping("/run_judgement")
public CommonResult run_C_code() throws SQLException, IOException {
return CommonResult.success(mysqlServerice.Judgement());
}
// @PostMapping("/run_judgement")
// public CommonResult run_C_code() throws SQLException, IOException {
// return CommonResult.success(mysqlServerice.Judgement( ));
// }
}

View File

@@ -27,10 +27,10 @@ public class WindowsFileController {
* 文件操作题判分
* @return 判分
*/
@PostMapping("/run_judgement")
public CommonResult run_file_point() throws IOException {
//"权值得分比重"
return CommonResult.success(fileServerice.run_file_point());
}
// @PostMapping("/run_judgement")
// public CommonResult run_file_point() throws IOException {
// //"权值得分比重"
// return CommonResult.success(fileServerice.run_file_point());
// }
}

View File

@@ -1,12 +1,14 @@
package pc.exam.pp.module.judgement.controller.service.browser;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.judgement.controller.utils.brower.BookmarkChecker;
import pc.exam.pp.module.judgement.controller.utils.brower.BookmarkDeleter;
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
@@ -16,13 +18,13 @@ import java.util.Map;
@Service
public class BrowserServericeImpl implements IBrowserServerice {
static String answerLogPath = "answerLogBrower.txt"; // 文件路径
static String answerLogPath ; // 文件路径
//考生试题文件夹
static final String BASE_DIR = "D:/exam/4/";
// static final String BASE_DIR = "D:/exam/4/";
//谷歌浏览器
String chromeBookmarkPath = System.getenv("LOCALAPPDATA") + "\\Google\\Chrome\\User Data\\Default\\Bookmarks";
@Override
public String Judgement() throws IOException {
public double Judgement(double score, File file, ExamQuestion question) throws IOException {
//根据题目,查找考点
//得到该试题的得分点
@@ -30,9 +32,9 @@ public class BrowserServericeImpl implements IBrowserServerice {
// 添加到文件夹 1
// 添加到收藏夹 2
List<ExamQuestionAnswer> answerList=new ArrayList<>();
answerList.add(new ExamQuestionAnswer("","","","","1", "文件名1", "1", "1"));
answerList.add(new ExamQuestionAnswer("","","","","1", "文件名2", "1", "2"));
answerList.add(new ExamQuestionAnswer("","","","","2", "百度一下,你就知道", "1", "3"));
answerList.add(new ExamQuestionAnswer("","","","","1", "人民大学", "1", "1"));
answerList.add(new ExamQuestionAnswer("","","","","1", "校情", "1", "2"));
answerList.add(new ExamQuestionAnswer("","","","","1", "机构", "1", "3"));
//判断如果类型为1为添加到文件夹的html后缀加 .html
for (ExamQuestionAnswer answer : answerList) {
if ("1".equals(answer.getContent())) {
@@ -49,10 +51,10 @@ public class BrowserServericeImpl implements IBrowserServerice {
// 2收藏夹--去浏览器去找 根据值 文件名 查找
// 找到后 —————— +权值 ,根据文件名删除
answerLogPath = file.getParent() + File.separator + "log.txt";
//根据路径,得到考生答题文件集合
Map<String, String> stuFiles = GetDifferencesBetweenFolders.listFilesAndFoldersWithAttributes(Paths.get(BASE_DIR));
Map<String, String> stuFiles = GetDifferencesBetweenFolders.listFilesAndFoldersWithAttributes(file.toPath());
// 输出学生提交的内容
@@ -87,9 +89,10 @@ public class BrowserServericeImpl implements IBrowserServerice {
.sum();
// 计算最终得分比例(保留两位小数)
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
String formattedScoreRatio = String.format("%.2f", scoreRatio);
return formattedScoreRatio;
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
return roundedScoreRatio*score;
}

View File

@@ -1,8 +1,12 @@
package pc.exam.pp.module.judgement.controller.service.browser;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import java.io.File;
import java.io.IOException;
public interface IBrowserServerice {
String Judgement() throws IOException;
double Judgement(double score, File file, ExamQuestion question) throws IOException;
}

View File

@@ -1,10 +1,12 @@
package pc.exam.pp.module.judgement.controller.service.file;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.exam.utils.file.GetDifferencesBetweenFolders;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
@@ -12,17 +14,15 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
public class FileServericeImpl implements IFileServerice {
static final String BASE_DIR = "D:/exam/3/";
static String answerLogPath = "answerLogFile.txt"; // 文件路径
static String answerLogPath ; // 文件路径
@Override
public String run_file_point() throws IOException {
public double run_file_point(double score,File file, ExamQuestion question) throws IOException {
//todo 得到学生的考题答案
List<ExamQuestionAnswer> answerList=new ArrayList<>();
answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\RLQM.MEM", "考察删除", "1", "1"));
@@ -30,10 +30,16 @@ public class FileServericeImpl implements IFileServerice {
answerList.add(new ExamQuestionAnswer("","","","","AHEWL\\KMENS", "考察名称", "1", "3"));
answerList.add(new ExamQuestionAnswer("","","","","EDZK\\RONGHE.COM", "考察名称", "1", "4"));
answerList.add(new ExamQuestionAnswer("","","","","HGACYL\\PLAY.MEM", "考察名称", "1", "5"));
answerList.add(new ExamQuestionAnswer("","","","","WUE\\PB6.txt", "考察名称", "1", "6"));
String stuPath = BASE_DIR + "stu";
File stuPath = file;
// 设置日志文件路径为file所在目录下的answerLogFile.txt
answerLogPath = file.getParent() + File.separator + "log.txt";
// 获取 stu 文件夹的内容
Map<String, String> stuFiles = GetDifferencesBetweenFolders.listFilesAndFoldersWithAttributes(Paths.get( stuPath));
Map<String, String> stuFiles = GetDifferencesBetweenFolders.listFilesAndFoldersWithAttributes(stuPath.toPath());
// 输出学生提交的内容
appendToFile(answerLogPath,"=== 学生提交内容stu 目录) ===");
@@ -52,9 +58,9 @@ public class FileServericeImpl implements IFileServerice {
.sum();
// 计算最终得分比例(保留两位小数)
double scoreRatio = totalScore == 0 ? 0 : (double) studentScore / totalScore;
String formattedScoreRatio = String.format("%.2f", scoreRatio);
double roundedScoreRatio = Math.round(scoreRatio * 100.0) / 100.0; // 四舍五入到2位小数
return formattedScoreRatio;
return roundedScoreRatio*score;
}

View File

@@ -1,8 +1,10 @@
package pc.exam.pp.module.judgement.controller.service.file;
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.util.List;
@@ -11,7 +13,7 @@ public interface IFileServerice {
String run_file_point() throws IOException;
double run_file_point(double score,File file, ExamQuestion question) throws IOException;
}

View File

@@ -1,6 +1,7 @@
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.IOException;
@@ -9,7 +10,7 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public interface IMysqlServerice {
AtomicInteger Judgement() throws IOException, SQLException;
double Judgement(double sorce, ExamQuestion examQuestion) throws IOException, SQLException;

View File

@@ -1,6 +1,7 @@
package pc.exam.pp.module.judgement.controller.service.mysql;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionKeyword;
import pc.exam.pp.module.judgement.controller.utils.Mysql.MySQLExporterUtil;
@@ -28,7 +29,7 @@ public class MysqlServericeImpl implements IMysqlServerice {
static String databaseName;
static String answerLogPath = "answerLogMysql.txt"; // 文件路径
@Override
public AtomicInteger Judgement() throws IOException, SQLException {
public double Judgement(double score, ExamQuestion examQuestion) throws IOException, SQLException {
AtomicInteger totalScoreAnswer= new AtomicInteger();
@@ -796,10 +797,20 @@ public class MysqlServericeImpl implements IMysqlServerice {
System.out.println("文件不存在: " + fileback);
}
}
String totalscore = "44";
double Score = score * (totalScoreAnswer.get() / Double.parseDouble(totalscore));
return Score;
return totalScoreAnswer;
}
/**
* 将指定内容追加写入到指定文件中。
*

View File

@@ -12,6 +12,9 @@ import pc.exam.pp.module.exam.service.question.IExamQuestionService;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.controller.service.browser.IBrowserServerice;
import pc.exam.pp.module.judgement.controller.service.file.IFileServerice;
import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice;
import pc.exam.pp.module.judgement.service.c_programming.JudgementService;
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
@@ -35,7 +38,12 @@ public class AutoToolsServiceImpl implements AutoToolsService{
JudgementService judgementService;
@Resource
JudgementWpsWordService judgementWpsWordService;
@Resource
IMysqlServerice mysqlServerice;
@Resource
IFileServerice fileServerice;
@Resource
IBrowserServerice browserServerice;
@Override
public String downloadStudentFile(String fileUrl, String filePath) {
try {
@@ -187,7 +195,30 @@ public class AutoToolsServiceImpl implements AutoToolsService{
score += wps_word_score;
break;
}
// D:\1d70c404e6d42d144d0028496e893565dd2dec447f7e9b1db66466f00472424d\160\cb3cc9089b104a1e9e92deb330d0cfe8\d9f988d5ae6d435ba12d4d979d044219\stu
//windows文件处理
if (file_one.getName().equals("stu")) {
File win_file = new File(file_one.getPath());
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
score += win_file_score;
}
System.out.println(file_one);
//浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if (file_one.getName().equals("edge")) {
File edge_file = new File(file_one.getPath());
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
score += browse_score;
}
}
ExamQuestion mysql=new ExamQuestion();
double judgement = mysqlServerice.Judgement(20, mysql);
score+=judgement;
}
return CommonResult.success(score);
}