From 5dce40ae47a030db575f07b1d6f6b828a0bd8ec2 Mon Sep 17 00:00:00 2001 From: "YOHO\\20373" <2037305722@qq.com> Date: Thu, 22 May 2025 02:24:21 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=96=87=E4=BB=B6=EF=BC=8Cwps=E5=88=A4=E5=88=86log?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9C=B0=E5=9D=80=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?mysql=E7=BB=93=E6=9E=9C=E6=96=87=E4=BB=B6=E9=9A=8F=E9=A2=98?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../question/ExamQuestionAnswerMapper.java | 2 + .../mapper/exam/ExamQuestionAnswerMapper.xml | 3 ++ .../service/mysql/MysqlServericeImpl.java | 39 ++++++++++++++++--- .../auto_tools/AutoToolsServiceImpl.java | 24 +++++++++--- .../JudgementWpsExcelServiceImpl.java | 7 +++- .../wps_pptx/JudgementWpsPptxServiceImpl.java | 9 ++++- .../wps_word/JudgementWpsWordServiceImpl.java | 7 +++- 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionAnswerMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionAnswerMapper.java index 09b1d4ed..cf4accab 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionAnswerMapper.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionAnswerMapper.java @@ -75,4 +75,6 @@ public interface ExamQuestionAnswerMapper extends BaseMapperX selectExamQuestionAnswerIdByQuId(String quId); + String selectAnswerFile(String quId); + } diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionAnswerMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionAnswerMapper.xml index 7f92677a..2e2d47b6 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionAnswerMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionAnswerMapper.xml @@ -92,6 +92,9 @@ + insert into exam_question_answer (answer_id, qu_id, is_right, image, content,contentIn,score_rate,sort) diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java index 3ce6cb04..0b98af49 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/service/mysql/MysqlServericeImpl.java @@ -3,6 +3,7 @@ package pc.exam.pp.module.judgement.controller.service.mysql; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.module.exam.dal.dataobject.ExamMysqlKeyword; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer; @@ -13,6 +14,7 @@ import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; 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; +import pc.exam.pp.module.judgement.controller.utils.zip.ZipUtil; import pc.exam.pp.module.judgement.domain.SqlExecutionResult; import pc.exam.pp.module.judgement.utils.EndStuMonitorUtils; @@ -47,6 +49,19 @@ public class MysqlServericeImpl implements IMysqlServerice { @Override public double Judgement(double score,File filepath, ExamQuestion examQuestion) throws IOException, SQLException { + + String fileUrl= examQuestionAnswerMapper.selectAnswerFile(examQuestion.getQuId()); + String path = ZipUtil.downloadStudentFile(fileUrl, "data"); + // 4、获取到得是zip文件,需要解压 + String stuFilePath = ZipUtil.unzipToNamedFolder(path); + File folderzip = new File(path); + File folder = new File(stuFilePath); + // 5、解压之后得文件获取文件夹和文件 + String stu_files = null; + + // 5.2、查询试题ID + + List examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(examQuestion.getQuId()); String totalKeyScore ="0"; if (examQuestionAnswers!=null&&examQuestionAnswers.size()>0){ @@ -63,16 +78,16 @@ public class MysqlServericeImpl implements IMysqlServerice { // 文件路径 // String file = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\结果素材\\结果素材\\Teacher"; - String file = new File(filepath, "结果").getAbsolutePath(); +// String file = new File(filepath, "结果").getAbsolutePath(); // String filePath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\结果素材\\结果素材\\Teacher\\answer.txt"; // 答案文件路径 - String filePath = new File(file, "answer.txt").getAbsolutePath(); // 结果/answer.txt + String filePath = new File(stuFilePath, "answer.txt").getAbsolutePath(); // 结果/answer.txt // String answerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\结果素材\\结果素材\\Teacher\\db\\db_escape.myd"; // 原始 SQL 文件路径 - String answerPath = new File(new File(file, "db"), "db_escape.myd").getAbsolutePath(); + String answerPath = new File(new File(stuFilePath, "db"), "db_escape.myd").getAbsolutePath(); // String fileStu = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student"; - String fileStu = new File(filepath, "素材").getAbsolutePath(); + String fileStu = filepath.getAbsolutePath(); // String stuAnswerPath = "D:\\Desktop\\202504211120_mysql\\71\\MYS_010_122\\考试素材\\考试素材\\Student\\db\\db_escape.myd"; String stuAnswerPath = new File(new File(fileStu, "db"), "db_escape.myd").getAbsolutePath(); @@ -121,7 +136,7 @@ public class MysqlServericeImpl implements IMysqlServerice { if (sqlFileExecuted && sqlFileExecutedstu) { - Map result = readFilesAsMap(file); + Map result = readFilesAsMap(stuFilePath); Map resultStu = readFilesAsMap(fileStu); try (Connection conn = DriverManager.getConnection(stuDbUrl, user, password); Statement stmt = conn.createStatement()) { @@ -695,11 +710,23 @@ public class MysqlServericeImpl implements IMysqlServerice { System.out.println("无效的 totalKeyScore 值:" + totalKeyScore); } appendToFile(answerLogPath, "共得分:"+roundedResult); + folderzip.delete(); + deleteFolder(folder); return roundedResult; } - + public static void deleteFolder(File folder) { + if (folder.isDirectory()) { + File[] files = folder.listFiles(); + if (files != null) { + for (File file : files) { + deleteFolder(file); // 递归删除所有子文件/文件夹 + } + } + } + folder.delete(); // 删除空文件夹或文件 + } private static void accumulateScoreAndLog(List examMysqlKeywordList, AtomicInteger total, String answerLogPath, String sql2, String totalKeyScore, double score) { AtomicInteger singleTotal = new AtomicInteger(); // 单独累加 scoreRateStr 的总和 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 0b9cad70..36e96dc1 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 @@ -272,10 +272,10 @@ public class AutoToolsServiceImpl implements AutoToolsService{ } // wps 类型存在多级文文件夹,需要个性化设置 if (one_file.getName().split("\\.")[0].equals("WPS文字")) { - 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_word得分"); - break; + 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_word得分"); + break; } if (one_file.getName().split("\\.")[0].equals("WPS演示")) { double wps_pptx_score = judgementWpsPptxService.judgementWpsPptx(15.0, one_file.getPath(), file_one.getPath(), examQuestion); @@ -333,11 +333,23 @@ public class AutoToolsServiceImpl implements AutoToolsService{ // 更新学生分数 // endStuMonitorUtils.endStuMonitor(String.valueOf(stuId),paperId,score); // end、删除文件 + System.out.println(stuFilePath); zip_file.delete(); - folder.delete(); +// folder.delete(); + deleteFolder(folder); return CommonResult.success(score); } - + public static void deleteFolder(File folder) { + if (folder.isDirectory()) { + File[] files = folder.listFiles(); + if (files != null) { + for (File file : files) { + deleteFolder(file); // 递归删除所有子文件/文件夹 + } + } + } + folder.delete(); // 删除空文件夹或文件 + } /** * 读取学生选择题答案 * @param filePath 文件路径 diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java index 18ef862c..052fa3ef 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelServiceImpl.java @@ -57,7 +57,12 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { @Override public double judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception { // 1创建log文件txt,用于记录 - LogFileUtils.createFile(pathC + "/WPS_Xlsx判分过程.txt"); + File pathCDir = new File(pathC); + File parentDir = pathCDir.getParentFile(); + + // 拼接同级目录下的目标文件路径 + String targetFilePath = new File(parentDir, "WPS_Xlsx判分过程.txt").getPath(); + LogFileUtils.createFile(targetFilePath); LogFileUtils.writeLine("✅ 开始WPS_Xlsx判分"); double wpsXlsxScore = 0; List margins = WpsExcelUtils.wpsExcel(path); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java index 0cd31d61..789f52de 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxServiceImpl.java @@ -59,8 +59,15 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { @Override public double judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception { + + // 创建log文件txt,用于记录 + File pathCDir = new File(pathC); + File parentDir = pathCDir.getParentFile(); + + // 拼接同级目录下的目标文件路径 + String targetFilePath = new File(parentDir, "WPS_Pptx判分过程.txt").getPath(); // 1创建log文件txt,用于记录 - LogFileUtils.createFile(pathC + "/WPS_Pptx判分过程.txt"); + LogFileUtils.createFile(targetFilePath); LogFileUtils.writeLine("✅ 开始WPS_Pptx判分"); double wpsPptScore = 0; // 2、pptx文件读取并返回考点及说明信息 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 1db8a347..f97e1ed7 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 @@ -57,7 +57,12 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService { @Override public double judgementWpsWord(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception { // 创建log文件txt,用于记录 - LogFileUtils.createFile(pathC + "/WPS_Word判分过程.txt"); + File pathCDir = new File(pathC); + File parentDir = pathCDir.getParentFile(); + + // 拼接同级目录下的目标文件路径 + String targetFilePath = new File(parentDir, "WPS_Word判分过程.txt").getPath(); + LogFileUtils.createFile(targetFilePath); LogFileUtils.writeLine("✅ 开始WPS_Word判分"); double wps_word_sorce = 0; // 1、查询Word考点tree