From 4b962fa609100b0e22c49f98ca9cf282814b2f20 Mon Sep 17 00:00:00 2001 From: "RENWEIBING\\letre" Date: Tue, 6 May 2025 15:07:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=20?= =?UTF-8?q?=E5=88=A4=E5=88=86=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=EF=BC=88?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E8=B7=AF=E5=BE=84=E8=A1=A5=E5=85=A8?= =?UTF-8?q?=EF=BC=89=EF=BC=8CGCC=E9=80=BB=E8=BE=91=E5=88=A4=E5=88=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8CWord=E5=88=A4=E5=88=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/WpsWord/WpsWordController.java | 4 +-- .../admin/autoTools/AutoToolsController.java | 2 +- .../service/auto_tools/AutoToolsService.java | 2 +- .../auto_tools/AutoToolsServiceImpl.java | 29 ++++++++++++++----- .../c_programming/JudgementServiceImpl.java | 2 +- .../wps_word/JudgementWpsWordService.java | 2 +- .../wps_word/JudgementWpsWordServiceImpl.java | 24 ++++++++++----- .../judgement/utils/JudgementCUtils.java | 12 ++++---- 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/WpsWord/WpsWordController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/WpsWord/WpsWordController.java index 0596ccbc..b439607b 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/WpsWord/WpsWordController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/WpsWord/WpsWordController.java @@ -33,8 +33,8 @@ public class WpsWordController { * @return 判分 */ @GetMapping("/run_wps_word") - public CommonResult> run_wps_word() throws Exception { - return CommonResult.success(judgementWpsWordService.ProgrammingWpsWord("1")); + public CommonResult> run_wps_word(String path) throws Exception { + return CommonResult.success(judgementWpsWordService.ProgrammingWpsWord(path)); } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java index 2cfd31b3..7ecbc036 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/AutoToolsController.java @@ -20,7 +20,7 @@ public class AutoToolsController { private AutoToolsService autoToolsService; @GetMapping("/get") - public CommonResult get(StuPaperReqVo stuPaperReqVo) { + public CommonResult get(StuPaperReqVo stuPaperReqVo) throws Exception { return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java index 59078212..d5e87a85 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsService.java @@ -32,5 +32,5 @@ public interface AutoToolsService { * @param paperId 试卷ID * @return 分数 */ - CommonResult judgementScore(Long stuId, String paperId); + CommonResult judgementScore(Long stuId, String paperId) throws Exception; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java index e0e21119..0ae92196 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/auto_tools/AutoToolsServiceImpl.java @@ -11,8 +11,10 @@ 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.service.c_programming.JudgementService; +import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; import java.io.*; +import java.math.BigDecimal; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -29,6 +31,8 @@ public class AutoToolsServiceImpl implements AutoToolsService{ IExamQuestionService examQuestionService; @Resource JudgementService judgementService; + @Resource + JudgementWpsWordService judgementWpsWordService; @Override public String downloadStudentFile(String fileUrl, String filePath) { @@ -114,7 +118,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{ } @Override - public CommonResult judgementScore(Long stuId, String paperId) { + public CommonResult judgementScore(Long stuId, String paperId) throws Exception { double score = 0; // 1、通过学号,试卷ID查询文件路径 StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); @@ -145,7 +149,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{ if (filess.length > 1) return CommonResult.error(100037, "5、试卷文件上传,目录不正确!"); if (!filess[0].isDirectory()) return CommonResult.error(100038, "6、试卷文件上传,目录不正确!"); // 判断学号是否正确 - if (!files[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()); // 所有试题文件夹 @@ -157,21 +161,30 @@ public class AutoToolsServiceImpl implements AutoToolsService{ // 7、进行对应得判分 // --- 7.1、查询试题文件 File qu_file = new File(file.getPath()); - File[] qu_file_list = qu_files.listFiles(); + File[] qu_file_list = qu_file.listFiles(); if (qu_file_list == null) continue; // --- 7.2、通过文件名称进行判分 for (File file_one : qu_file_list) { // 判断名称 类似于 C语言程序设计。 if (file_one.getName().split("\\.")[0].equals(examQuestion.getCourseName()+examQuestion.getSubjectName())) { - double c_score = judgementService.ProgrammingC(15.0, file.getPath(), file_one.getName(), examQuestion); - score += c_score; - break; + double c_score = judgementService.ProgrammingC(15.0, file.getPath(), file_one.getName(), examQuestion); + score += c_score; + break; } // wps 类型存在多级文文件夹,需要个性化设置 -// if () + if (file_one.getName().equals("结果")) { + // 进入到学生作答得文件,直接判断文件是否存在 + File wps_file = new File(file_one.getPath()); + File[] wps_file_list = wps_file.listFiles(); + if (wps_file_list == null) break; + if (wps_file_list[0].getName().equals("结果.docx")) { + // 开始调用wps_word判分 + double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, wps_file_list[0].getPath(), examQuestion); + score += wps_word_score; + } + } } } - return CommonResult.success(score); } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementServiceImpl.java index 9fce1937..9d27657e 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementServiceImpl.java @@ -65,7 +65,7 @@ public class JudgementServiceImpl implements JudgementService LogFileUtils.createFile(pathC + "/log.txt"); String code = JudgementCUtils.readFile(pathC, fileName); LogFileUtils.writeLine("✅ 系统开始读取文件:" + code); - if (code == null) { + if (code == "") { // 如果没有读到源码 LogFileUtils.writeLine("❌ 系统没有读取到文件。"); LogFileUtils.close(); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java index 8d8eb119..26e29be7 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordService.java @@ -31,5 +31,5 @@ public interface JudgementWpsWordService { * @return 得分 * @throws Exception 异常 */ - public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception; + public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception; } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java index 5e56ffdf..533a34f6 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_word/JudgementWpsWordServiceImpl.java @@ -51,8 +51,8 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService { } @Override - public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception { - BigDecimal wps_word_sorce = new BigDecimal(0); + public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception { + double wps_word_sorce = 0; // 1、查询Word考点tree WordListReqVO wordListReqVO = new WordListReqVO(); wordListReqVO.setBelongTo(0); @@ -64,11 +64,21 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService { // 4、进行关联判断 for (ExamQuestionAnswer examQuestionAnswer : answerList) { for (WordVO wordVO : margins1) { - for (String str : wordVO.getExamKeynote()) { - if (str.equals(examQuestionAnswer.getContent())) { - // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 - BigDecimal one_sorce = sorce.multiply(new BigDecimal(examQuestionAnswer.getScoreRate())).setScale(2, RoundingMode.HALF_UP); - wps_word_sorce = wps_word_sorce.add(one_sorce); + if (wordVO.getExamKeynote() != null) { + for (String str : wordVO.getExamKeynote()) { + int index = 0; + if ((index+str).equals(examQuestionAnswer.getContent())) { + double one_sorce = 0; + // 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重 + if (examQuestionAnswer.getScoreRate().equals("1")) { + // 说明权重相等,直接平分分数 + one_sorce = sorce / answerList.size(); + } else { + one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate()); + } + wps_word_sorce += one_sorce; + break; + } } } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/JudgementCUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/JudgementCUtils.java index 9f94b335..8187cdea 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/JudgementCUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/JudgementCUtils.java @@ -1,6 +1,8 @@ package pc.exam.pp.module.judgement.utils; +import pc.exam.pp.module.exam.utils.file.LogFileUtils; + import javax.swing.*; import java.io.*; import java.nio.charset.StandardCharsets; @@ -67,7 +69,7 @@ public class JudgementCUtils public static String run_code(String code, String input, String standard, String text) { try { boolean hasInput = code.contains("scanf") || code.contains("fgets") || code.contains("getchar"); - + System.out.println(System.getenv("PATH")); // 写入 C 源码到文件 File file = new File("program.c"); try (FileWriter writer = new FileWriter(file)) { @@ -232,7 +234,7 @@ public class JudgementCUtils // 判断路径是否存在 if (!Files.exists(folderPath)) { -// LogFileUtils.writeLine("❗ 文件夹路径不存在: " + folderPath.toString()); + LogFileUtils.writeLine("❗ 文件夹路径不存在: " + folderPath.toString()); return null; // 或者 return null,或者 throw new RuntimeException(...),看你的函数定义 } @@ -241,9 +243,9 @@ public class JudgementCUtils try (Stream paths = Files.walk(folderPath)) { paths.filter(Files::isRegularFile) - .filter(path -> path.toString().toLowerCase().endsWith(fileName)) + .filter(path -> path.getFileName().toString().equalsIgnoreCase(fileName)) .forEach(path -> { -// LogFileUtils.writeLine("📄 文件: " + path); + LogFileUtils.writeLine("📄 文件: " + path); try { List lines = Files.readAllLines(path, StandardCharsets.UTF_8); for (String line : lines) { @@ -251,7 +253,7 @@ public class JudgementCUtils System.out.println(" " + line); } } catch (IOException e) { -// LogFileUtils.writeLine("❗ 无法读取文件: " + path); + LogFileUtils.writeLine("❗ 无法读取文件: " + path); } }); } catch (IOException e) {