【修改】 判分返回保留小数点两位

This commit is contained in:
DESKTOP-932OMT8\REN
2025-05-27 19:28:58 +08:00
parent be9e49f54a
commit 940a71ae47
3 changed files with 124 additions and 118 deletions

View File

@@ -22,6 +22,7 @@ import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService;
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@@ -50,7 +51,7 @@ public class AutoToolsController {
IExamQuestionService examQuestionService; IExamQuestionService examQuestionService;
@GetMapping("/get") @GetMapping("/get")
public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) throws Exception { public CommonResult<BigDecimal> get(StuPaperReqVo stuPaperReqVo) throws Exception {
return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
} }
@GetMapping("/getTest") @GetMapping("/getTest")

View File

@@ -2,6 +2,8 @@ package pc.exam.pp.module.judgement.service.auto_tools;
import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.framework.common.pojo.CommonResult;
import java.math.BigDecimal;
public interface AutoToolsService { public interface AutoToolsService {
@@ -32,5 +34,5 @@ public interface AutoToolsService {
* @param paperId 试卷ID * @param paperId 试卷ID
* @return 分数 * @return 分数
*/ */
CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception; CommonResult<BigDecimal> judgementScore(Long stuId, String paperId) throws Exception;
} }

View File

@@ -36,6 +36,7 @@ import pc.exam.pp.module.judgement.utils.zipfile.FolderZipper;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.Files; import java.nio.file.Files;
@@ -165,9 +166,9 @@ public class AutoToolsServiceImpl implements AutoToolsService{
* @throws Exception 异常 * @throws Exception 异常
*/ */
@Override @Override
public CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception { public CommonResult<BigDecimal> judgementScore(Long stuId, String paperId) throws Exception {
// 监控管理 生成选择题文件路径 // 监控管理 生成选择题文件路径
// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId); endStuMonitorUtils.endStuMonitor(String.valueOf(stuId), paperId);
// 获取平台文件参数 // 获取平台文件参数
ConfigDO config = configService.getConfigByKey("file_down_path"); ConfigDO config = configService.getConfigByKey("file_down_path");
double score = 0; double score = 0;
@@ -183,7 +184,6 @@ public class AutoToolsServiceImpl implements AutoToolsService{
stuPaperFileDO = stuPaperFileDOs; stuPaperFileDO = stuPaperFileDOs;
} }
} }
// 1-1、 穿插选择题判分 // 1-1、 穿插选择题判分
// 1-1-1、下载选择题文件 // 1-1-1、下载选择题文件
String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue()); String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue());
@@ -213,131 +213,134 @@ public class AutoToolsServiceImpl implements AutoToolsService{
// 2、判断文件路径是否存在 // 2、判断文件路径是否存在
if (stuPaperFileDO == null) { if (stuPaperFileDO == null) {
return CommonResult.error(100031, "试题文件没有上传,无法判分!"); // return CommonResult.error(100031, "试题文件没有上传,无法判分!");
} // 3、下载文件
// 3、下载文件 String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue()); File zip_file = new File(patn);
File zip_file = new File(patn); // 4、获取到得是zip文件需要解压
// 4、获取到得是zip文件需要解压 String stuFilePath = unzipToNamedFolder(patn);
String stuFilePath = unzipToNamedFolder(patn); // 5、解压之后得文件获取文件夹和文件
// 5、解压之后得文件获取文件夹和文件 File folder = new File(stuFilePath);
File folder = new File(stuFilePath); File[] files = folder.listFiles();
File[] files = folder.listFiles(); String stu_files = null;
String stu_files = null; // 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容)
// 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容) if (files == null) return CommonResult.error(100032, "1、试题文件上传目录不正确");
if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!"); // if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!");
// if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!"); if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!");
if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传目录不正确"); // 判断学号是否正确
// 判断学号是否正确 if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常");
if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常"); // 5.2、查询试题ID
// 5.2、查询试题ID File folders = new File(files[0].getPath());
File folders = new File(files[0].getPath()); File[] filess = folders.listFiles();
File[] filess = folders.listFiles(); if (filess == null) return CommonResult.error(100036, "4、试卷文件上传目录不正确");
if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!"); if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!");
if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!"); if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!");
if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传目录不正确"); // 判断学号是否正确
// 判断学号是否正确 if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
if (!filess[0].getName().equals(paperId)) return CommonResult.error(100039, "文件与试卷匹配异常");
// 5.3、查询出来所有试题
File qu_files = new File(filess[0].getPath());
// 所有试题文件夹
File[] filess_qu = qu_files.listFiles();
if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
for (File file : filess_qu) {
// ** 接下来已经到了,每个课程题型了 file 得名称
// 5.3、查询出来所有试题 // 5.3、查询出来所有试题
File cs_files = new File(file.getPath()); File qu_files = new File(filess[0].getPath());
// 所有试题文件夹 // 所有试题文件夹
File[] cs_file_list = cs_files.listFiles(); File[] filess_qu = qu_files.listFiles();
if (cs_file_list!=null){ if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
for (File one_file : cs_file_list) { for (File file : filess_qu) {
// 6、根据试题ID查询试题详情 // ** 接下来已经到了,每个课程题型了 file 得名称
String qu_id = file.getName(); // 5.3、查询出来所有试题
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id); File cs_files = new File(file.getPath());
if (examQuestion != null) { // 所有试题文件夹
// 7、进行对应得判分 File[] cs_file_list = cs_files.listFiles();
// --- 7.1、查询试题文件 if (cs_file_list!=null){
File qu_file = new File(one_file.getPath()); for (File one_file : cs_file_list) {
File[] qu_file_list = qu_file.listFiles(); // 6、根据试题ID查询试题详情
if (qu_file_list == null) continue; String qu_id = file.getName();
// --- 7.2、通过文件名称进行判分 ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id);
for (File file_one : qu_file_list) { if (examQuestion != null) {
// 判断名称 类似于 C语言程序设计。 课程+题型 // 7、进行对应得判分
System.out.println(one_file.getName()); // --- 7.1、查询试题文件
if (one_file.getName().split("\\.")[0].equals("C语言编程题")) { File qu_file = new File(one_file.getPath());
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), file_one.getName(), examQuestion); File[] qu_file_list = qu_file.listFiles();
score += c_score; if (qu_file_list == null) continue;
System.out.println(c_score+"C语言程序设计得分"); // --- 7.2、通过文件名称进行判分
break; for (File file_one : qu_file_list) {
} // 判断名称 类似于 C语言程序设计。 课程+题型
// wps 类型存在多级文文件夹,需要个性化设置 System.out.println(one_file.getName());
if (one_file.getName().split("\\.")[0].equals("WPS文字")) { if (one_file.getName().split("\\.")[0].equals("C语言编程题")) {
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("WPS文字")) {
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), file_one.getPath(), examQuestion); double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
score += wps_word_score; score += wps_word_score;
System.out.println(wps_word_score+"wps_word得分"); System.out.println(wps_word_score+"wps_word得分");
break; break;
} }
if (one_file.getName().split("\\.")[0].equals("WPS演示")) { if (one_file.getName().split("\\.")[0].equals("WPS演示")) {
double wps_pptx_score = judgementWpsPptxService.judgementWpsPptx(15.0, one_file.getPath(), file_one.getPath(), examQuestion); double wps_pptx_score = judgementWpsPptxService.judgementWpsPptx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
score += wps_pptx_score; score += wps_pptx_score;
System.out.println(wps_pptx_score+"wps_ppt得分"); System.out.println(wps_pptx_score+"wps_ppt得分");
break; break;
} }
if (one_file.getName().split("\\.")[0].equals("WPS表格")) { if (one_file.getName().split("\\.")[0].equals("WPS表格")) {
double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(15.0, one_file.getPath(), file_one.getPath(), examQuestion); double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
score += wps_excel_score; score += wps_excel_score;
System.out.println(wps_excel_score+"wps_excel得分"); System.out.println(wps_excel_score+"wps_excel得分");
break; break;
} }
//windows文件处理 //windows文件处理
if (one_file.getName().split("\\.")[0].equals("文件处理")) { if (one_file.getName().split("\\.")[0].equals("文件处理")) {
File win_file = new File(one_file.getPath()); File win_file = new File(one_file.getPath());
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion); double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
score += win_file_score; score += win_file_score;
System.out.println(win_file_score+"windows文件处理得分"); System.out.println(win_file_score+"windows文件处理得分");
break; break;
} }
//浏览器操作 //浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){ // if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if (one_file.getName().split("\\.")[0].equals("网络题")) { if (one_file.getName().split("\\.")[0].equals("网络题")) {
System.out.println(one_file); System.out.println(one_file);
File edge_file = new File(one_file.getPath()); File edge_file = new File(one_file.getPath());
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion); double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
score += browse_score; score += browse_score;
System.out.println(browse_score+"浏览器操作得分"); System.out.println(browse_score+"浏览器操作得分");
break; break;
}
if (one_file.getName().split("\\.")[0].equals("程序设计")) {
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;
}
} }
if (one_file.getName().split("\\.")[0].equals("程序设计")) { }
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;
}
}
} }
} }
} }
} // 8、将解压之后得问及那继续重新压缩并上传到服务器并删除文件和文件夹
// 8、将解压之后得问及那继续重新压缩并上传到服务器并删除文件和文件夹 String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, ""));
String zipPath = FolderZipper.zipFolder(files[0].getPath().replace("\\"+stuId, "")); File folderStuUpdateFile = new File(files[0].getPath());
File folderStuUpdateFile = new File(files[0].getPath()); folderStuUpdateFile.delete();
folderStuUpdateFile.delete(); // 9、上传文件
// 9、上传文件 MultipartFile file = new CustomMultipartFile(zipPath);
MultipartFile file = new CustomMultipartFile(zipPath); String path = null;
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())); // 更新学生分数
// 更新学生分数 endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score);
// endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score); // end、删除文件
// end、删除文件 System.out.println(stuFilePath);
System.out.println(stuFilePath); zip_file.delete();
zip_file.delete();
// folder.delete(); // folder.delete();
deleteFolder(folder); deleteFolder(folder);
return CommonResult.success(score); }
BigDecimal bd = new BigDecimal(Double.toString(score));
// 保留两位小数并四舍五入
bd = bd.setScale(2, RoundingMode.HALF_UP);
return CommonResult.success(bd);
} }
public static void deleteFolder(File folder) { public static void deleteFolder(File folder) {
if (folder.isDirectory()) { if (folder.isDirectory()) {