From 85ea237b3789f57096c29f28a0316ed45a655dbd Mon Sep 17 00:00:00 2001 From: "RENWEIBING\\letre" Date: Mon, 5 May 2025 12:00:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E5=AD=A6=E7=94=9F=E7=AB=AF=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20=E5=AD=A6=E5=8F=B7-=E8=AF=95=E5=8D=B7ID-=E6=96=87=E4=BB=B6Ur?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataobject/student/StuPaperFileDO.java | 38 ++++++++++++++ .../dal/mysql/student/StuPaperFileMapper.java | 18 +++++++ .../stu_paper_file/StuPaperFileService.java | 24 +++++++++ .../StuPaperFileServiceImpl.java | 35 +++++++++++++ .../mapper/student/StuPaperFileMapper.xml | 15 ++++++ .../exam-module-infra-biz/pom.xml | 6 +++ .../controller/admin/file/FileController.java | 8 +++ .../file/vo/file/StuFileUploadReqVO.java | 25 +++++++++ .../infra/service/file/FileService.java | 10 ++++ .../infra/service/file/FileServiceImpl.java | 52 +++++++++++++++++++ 10 files changed, 231 insertions(+) create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperFileDO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperFileMapper.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileService.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileServiceImpl.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperFileMapper.xml create mode 100644 exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/vo/file/StuFileUploadReqVO.java diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperFileDO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperFileDO.java new file mode 100644 index 00000000..fbec5417 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/student/StuPaperFileDO.java @@ -0,0 +1,38 @@ +package pc.exam.pp.module.exam.dal.dataobject.student; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import pc.exam.pp.framework.tenant.core.db.TenantBaseDO; + +/** + * 学生-试卷-文件表 DO + * + * @author rwb + */ +@TableName("exam_stu_paper_fileurl") +@Data +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class StuPaperFileDO extends TenantBaseDO { + + /** + * Id + */ + @TableId + private Long id; + /** + * 学生号 + */ + private Long stuId; + /** + * 试卷ID + */ + private String paperId; + /** + * 学生文件URL + */ + private String url; +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperFileMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperFileMapper.java new file mode 100644 index 00000000..f13a583a --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/student/StuPaperFileMapper.java @@ -0,0 +1,18 @@ +package pc.exam.pp.module.exam.dal.mysql.student; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; +import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; + +/** + * 学生-试卷-文件 Mapper + * + * @author rwb + */ +@Mapper +public interface StuPaperFileMapper extends BaseMapperX { + StuPaperFileDO findByStuIdAndPaperId(@Param("stuId") Long stuId, @Param("paperId") String paperId); + +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileService.java new file mode 100644 index 00000000..4dc63a73 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileService.java @@ -0,0 +1,24 @@ +package pc.exam.pp.module.exam.service.stu_paper_file; + +import jakarta.validation.Valid; +import pc.exam.pp.framework.common.pojo.PageResult; +import pc.exam.pp.module.exam.controller.admin.student.vo.StudentPageReqVO; +import pc.exam.pp.module.exam.controller.admin.student.vo.StudentSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; +import pc.exam.pp.module.exam.dal.dataobject.student.StudentDO; + +import java.util.List; + +/** + * 学生-试卷-文件 Service 接口 + * + * @author rwb + */ +public interface StuPaperFileService { + + StuPaperFileDO findByStuIDAndPaperId(Long stuID, String paperID); + + void insertStuPaperFile(StuPaperFileDO stuPaperFileDO); + + void updateStuPaperFile(StuPaperFileDO stuPaperFileDO); +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileServiceImpl.java new file mode 100644 index 00000000..3089ef9a --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/stu_paper_file/StuPaperFileServiceImpl.java @@ -0,0 +1,35 @@ +package pc.exam.pp.module.exam.service.stu_paper_file; + +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; +import pc.exam.pp.module.exam.dal.mysql.student.StuPaperFileMapper; + +/** + * 学生-试卷-文件 Service 实现类 + * + * @author rwb + */ +@Service +@Validated +public class StuPaperFileServiceImpl implements StuPaperFileService { + + @Resource + private StuPaperFileMapper stuPaperFileMapper; + + @Override + public StuPaperFileDO findByStuIDAndPaperId(Long stuID, String paperID) { + return stuPaperFileMapper.findByStuIdAndPaperId(stuID, paperID); + } + + @Override + public void insertStuPaperFile(StuPaperFileDO stuPaperFileDO) { + stuPaperFileMapper.insert(stuPaperFileDO); + } + + @Override + public void updateStuPaperFile(StuPaperFileDO stuPaperFileDO) { + stuPaperFileMapper.updateById(stuPaperFileDO); + } +} \ No newline at end of file diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperFileMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperFileMapper.xml new file mode 100644 index 00000000..0620ad05 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/student/StuPaperFileMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/exam-module-infra/exam-module-infra-biz/pom.xml b/exam-module-infra/exam-module-infra-biz/pom.xml index 874aeba2..871be7c9 100644 --- a/exam-module-infra/exam-module-infra-biz/pom.xml +++ b/exam-module-infra/exam-module-infra-biz/pom.xml @@ -124,6 +124,12 @@ org.apache.tika tika-core + + pc.exam.gg + exam-module-exam-biz + 2.4.2-SNAPSHOT + compile + diff --git a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/FileController.java b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/FileController.java index 6b7a0192..95da0b54 100644 --- a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/FileController.java +++ b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/FileController.java @@ -66,6 +66,14 @@ public class FileController { return success(true); } + @PostMapping("/upload_stu") + @Operation(summary = "上传学生考试文件", description = "模式三:后端上传文件,带有学生ID") + public CommonResult uploadStuFile(StuFileUploadReqVO uploadReqVO) throws Exception { + MultipartFile file = uploadReqVO.getFile(); + String path = uploadReqVO.getPath(); + return success(fileService.createStuFile(uploadReqVO.getStuId(), uploadReqVO.getPaperId(), file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()))); + } + @GetMapping("/{configId}/get/**") @PermitAll @Operation(summary = "下载文件") diff --git a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/vo/file/StuFileUploadReqVO.java b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/vo/file/StuFileUploadReqVO.java new file mode 100644 index 00000000..f7126567 --- /dev/null +++ b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/controller/admin/file/vo/file/StuFileUploadReqVO.java @@ -0,0 +1,25 @@ +package pc.exam.pp.module.infra.controller.admin.file.vo.file; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +@Schema(description = "管理后台 - 上传文件 Request VO") +@Data +public class StuFileUploadReqVO { + + @Schema(description = "文件附件", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "文件附件不能为空") + private MultipartFile file; + + @Schema(description = "文件附件", example = "examyuanma.png") + private String path; + + @Schema(description = "学生ID") + private Long stuId; + + @Schema(description = "试卷ID") + private String paperId; + +} diff --git a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileService.java b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileService.java index eda97d7d..fe2d14ad 100644 --- a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileService.java +++ b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileService.java @@ -31,6 +31,16 @@ public interface FileService { */ String createFile(String name, String path, byte[] content); + /** + * 保存文件,并返回文件的访问路径 + * + * @param name 文件名称 + * @param path 文件路径 + * @param content 文件内容 + * @return 文件路径 + */ + String createStuFile(Long stuId, String paperId, String name, String path, byte[] content); + /** * 创建文件 * diff --git a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileServiceImpl.java b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileServiceImpl.java index 20c1cb6c..f277aea2 100644 --- a/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileServiceImpl.java +++ b/exam-module-infra/exam-module-infra-biz/src/main/java/pc/exam/pp/module/infra/service/file/FileServiceImpl.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.StrUtil; import pc.exam.pp.framework.common.pojo.PageResult; import pc.exam.pp.framework.common.util.io.FileUtils; import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; +import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService; import pc.exam.pp.module.infra.framework.file.core.client.FileClient; import pc.exam.pp.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO; import pc.exam.pp.module.infra.framework.file.core.utils.FileTypeUtils; @@ -34,6 +36,9 @@ public class FileServiceImpl implements FileService { @Resource private FileMapper fileMapper; + @Resource + private StuPaperFileService stuPaperFileService; + @Override public PageResult getFilePage(FilePageReqVO pageReqVO) { return fileMapper.selectPage(pageReqVO); @@ -69,6 +74,53 @@ public class FileServiceImpl implements FileService { return url; } + @Override + @SneakyThrows + public String createStuFile(Long stuId, String paperId, String name, String path, byte[] content) { + // 计算默认的 path 名 + String type = FileTypeUtils.getMineType(content, name); + if (StrUtil.isEmpty(path)) { + path = FileUtils.generatePath(content, name); + } + // 如果 name 为空,则使用 path 填充 + if (StrUtil.isEmpty(name)) { + name = path; + } + + // 上传到文件存储器 + FileClient client = fileConfigService.getMasterFileClient(); + Assert.notNull(client, "客户端(master) 不能为空"); + String url = client.upload(content, path, type); + + // 保存到数据库 + FileDO file = new FileDO(); + file.setConfigId(client.getId()); + file.setName(name); + file.setPath(path); + file.setUrl(url); + file.setType(type); + file.setSize(content.length); + fileMapper.insert(file); + // 需要更新学生表 + // 1、先查询学生,试卷 是否已经存在数据 + StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); + if (stuPaperFileDO == null) { + // 说明没有上传过,需要新增进去 + StuPaperFileDO stuPaperFile = new StuPaperFileDO(); + stuPaperFile.setPaperId(paperId); + stuPaperFile.setStuId(stuId); + stuPaperFile.setUrl(url); + stuPaperFileService.insertStuPaperFile(stuPaperFile); + } else { + // 说明已经上传过,判断url是否一致,不一致得,需要进行更新操作 + if (!url.equals(stuPaperFileDO.getUrl())) { + stuPaperFileDO.setUrl(url); + stuPaperFileService.updateStuPaperFile(stuPaperFileDO); + } + } + return url; + } + @Override public Long createFile(FileCreateReqVO createReqVO) { FileDO file = BeanUtils.toBean(createReqVO, FileDO.class); From 04a73be66814f1564f6bd4ee10084ff4963b683f Mon Sep 17 00:00:00 2001 From: "RENWEIBING\\letre" Date: Mon, 5 May 2025 20:20:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E5=88=A4=E5=88=86=E6=80=BB=E5=85=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=EF=BC=88=E5=AD=A6=E5=8F=B7=EF=BC=8C=E8=AF=95=E5=8D=B7ID?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/autoTools/AutoToolsController.java | 22 +++++ ...adFileZipReqVo.java => StuPaperReqVo.java} | 6 +- .../service/auto_tools/AutoToolsService.java | 10 +++ .../auto_tools/AutoToolsServiceImpl.java | 80 +++++++++++++++++++ .../c_programming/JudgementService.java | 5 +- .../c_programming/JudgementServiceImpl.java | 10 +-- .../wps_word/JudgementWpsWordService.java | 12 +++ .../wps_word/JudgementWpsWordServiceImpl.java | 30 +++++++ 8 files changed, 163 insertions(+), 12 deletions(-) rename exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/{StudentUploadFileZipReqVo.java => StuPaperReqVo.java} (63%) 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 669cce78..2cfd31b3 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 @@ -1,4 +1,26 @@ package pc.exam.pp.module.judgement.controller.admin.autoTools; + +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperReqVo; +import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; + +@RestController +@RequestMapping("/tool") +@Tag( name = "测试判分") +@Validated public class AutoToolsController { + @Resource + private AutoToolsService autoToolsService; + + @GetMapping("/get") + public CommonResult get(StuPaperReqVo stuPaperReqVo) { + 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/controller/admin/autoTools/vo/StudentUploadFileZipReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java similarity index 63% rename from exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StudentUploadFileZipReqVo.java rename to exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java index 9f789cf4..771cd962 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StudentUploadFileZipReqVo.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/autoTools/vo/StuPaperReqVo.java @@ -5,15 +5,13 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data -public class StudentUploadFileZipReqVo { +public class StuPaperReqVo { @Schema(description = "学号") - private Long studentId; + private Long stuId; @Schema(description = "试卷号") private String paperId; - @Schema(description = "上传文件路径") - private String filePath; } 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 5cd1cefa..59078212 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 @@ -1,5 +1,7 @@ package pc.exam.pp.module.judgement.service.auto_tools; +import pc.exam.pp.framework.common.pojo.CommonResult; + public interface AutoToolsService { @@ -23,4 +25,12 @@ public interface AutoToolsService { * @return 解压后的目录 */ String unzipToNamedFolder(String zipFilePath); + + /** + * 判分 + * @param stuId 学号 + * @param paperId 试卷ID + * @return 分数 + */ + CommonResult judgementScore(Long stuId, String paperId); } 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 1021ed73..e0e21119 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 @@ -1,6 +1,16 @@ package pc.exam.pp.module.judgement.service.auto_tools; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import pc.exam.pp.framework.common.exception.ErrorCode; +import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; +import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; +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.service.c_programming.JudgementService; import java.io.*; import java.net.MalformedURLException; @@ -11,6 +21,14 @@ import java.util.zip.ZipInputStream; @Service public class AutoToolsServiceImpl implements AutoToolsService{ + @Resource + private StuPaperFileService stuPaperFileService; + @Resource + ConfigService configService; + @Resource + IExamQuestionService examQuestionService; + @Resource + JudgementService judgementService; @Override public String downloadStudentFile(String fileUrl, String filePath) { @@ -94,4 +112,66 @@ public class AutoToolsServiceImpl implements AutoToolsService{ return null; } } + + @Override + public CommonResult judgementScore(Long stuId, String paperId) { + double score = 0; + // 1、通过学号,试卷ID查询文件路径 + StuPaperFileDO stuPaperFileDO = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId); + // 2、判断文件路径是否存在 + if (stuPaperFileDO == null) { + return CommonResult.error(100031, "试题文件没有上传,无法判分!"); + } + // 3、下载文件 + // 获取平台文件参数 + ConfigDO config = configService.getConfigByKey("file_down_path"); + String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue()); + // 4、获取到得是zip文件,需要解压 + String stuFilePath = unzipToNamedFolder(patn); + // 5、解压之后得文件获取文件夹和文件 + File folder = new File(stuFilePath); + File[] files = folder.listFiles(); + String stu_files = null; + // 5.1、 只查询文件夹 (学号-试卷ID-试题ID-具体内容) + if (files == null) return CommonResult.error(100032, "1、试题文件上传,目录不正确!"); + if (files.length > 1) return CommonResult.error(100033, "2、试题文件上传,目录不正确!"); + if (!files[0].isDirectory()) return CommonResult.error(100034, "3、试题文件上传,目录不正确!"); + // 判断学号是否正确 + if (!files[0].getName().equals(stuId.toString())) return CommonResult.error(100035, "文件与学号匹配异常"); + // 5.2、查询试题ID + File folders = new File(files[0].getPath()); + File[] filess = folders.listFiles(); + if (filess == null) return CommonResult.error(100036, "4、试卷文件上传,目录不正确!"); + 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, "文件与试卷匹配异常"); + // 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) { + // 6、根据试题ID查询试题详情 + ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(file.getName()); + // 7、进行对应得判分 + // --- 7.1、查询试题文件 + File qu_file = new File(file.getPath()); + File[] qu_file_list = qu_files.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; + } + // wps 类型存在多级文文件夹,需要个性化设置 +// if () + } + } + + 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/JudgementService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementService.java index f4f195bf..fa286f97 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/c_programming/JudgementService.java @@ -12,11 +12,12 @@ public interface JudgementService { /** * 程序设计判分 * @param examQuestion 程序设计题内容 - * @param path 文件路径 + * @param fileName 文件名称 + * @param pathC 文件路径 C语言文件 * @param score 分数 * @return 返回判分 */ - public double ProgrammingC(double score, String path, ExamQuestion examQuestion); + public double ProgrammingC(double score, String pathC, String fileName, ExamQuestion examQuestion); /** 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 1da72d73..9fce1937 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 @@ -21,11 +21,11 @@ public class JudgementServiceImpl implements JudgementService /** * 程序设计判分 * @param examQuestion 程序设计题内容 - * @param path 文件路径 + * @param fileName 文件名称 * @param score 分数 * @return 返回判分 */ - public double ProgrammingC(double score, String path, ExamQuestion examQuestion) { + public double ProgrammingC(double score, String pathC, String fileName, ExamQuestion examQuestion) { // 关键字比对,超过权重-测试用例/运行(测试用例全对,直接满分-不全对)-结果,不超过权重只给关键字几个的分 // 获取该题有多少分 @@ -61,11 +61,9 @@ public class JudgementServiceImpl implements JudgementService // 编译分数分数占比 double pass_score = score * is_pass_score; - // 试卷其中有C语言的试题 - String path_c = path + "/" + examQuestion.getQuBankName(); // 创建log文件txt,用于记录 - LogFileUtils.createFile(path_c + "/log.txt"); - String code = JudgementCUtils.readFile(path_c, examQuestion.getQuId()+".txt"); + LogFileUtils.createFile(pathC + "/log.txt"); + String code = JudgementCUtils.readFile(pathC, fileName); LogFileUtils.writeLine("✅ 系统开始读取文件:" + code); if (code == null) { // 如果没有读到源码 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 318e57e7..8d8eb119 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 @@ -2,8 +2,10 @@ package pc.exam.pp.module.judgement.service.wps_word; +import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; +import java.math.BigDecimal; import java.util.List; /** @@ -20,4 +22,14 @@ public interface JudgementWpsWordService { * @throws Exception 异常 */ public List ProgrammingWpsWord(String path) throws Exception; + + /** + * 读取考生文件,与题型中要求进行判断 + * @param path 文件路径 + * @param examQuestion 试题参数 + * @param sorce 试题分数 + * @return 得分 + * @throws Exception 异常 + */ + public BigDecimal judgementWpsWord(BigDecimal 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 6175f1ca..5e56ffdf 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 @@ -4,6 +4,8 @@ package pc.exam.pp.module.judgement.service.wps_word; import jakarta.annotation.Resource; 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.infra.dal.dataobject.config.ConfigDO; import pc.exam.pp.module.infra.service.config.ConfigService; import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO; @@ -14,6 +16,8 @@ import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; import java.io.File; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; @Service @@ -46,5 +50,31 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService { return margins1; } + @Override + public BigDecimal judgementWpsWord(BigDecimal sorce, String path, ExamQuestion examQuestion) throws Exception { + BigDecimal wps_word_sorce = new BigDecimal(0); + // 1、查询Word考点tree + WordListReqVO wordListReqVO = new WordListReqVO(); + wordListReqVO.setBelongTo(0); + List list = wpsWordLinkMapper.selectList(wordListReqVO); + // 2、docx文件读取并返回考点及说明信息 + List margins1 = WpsWordUtils.wps_word(path, list); + // 3、获取答案得组成 + List answerList = examQuestion.getAnswerList(); + // 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); + } + } + } + } + return wps_word_sorce; + } + }