diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java index df3f5738..200ed9c3 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/AutoWps/AutoWpsController.java @@ -14,9 +14,11 @@ import org.springframework.web.multipart.MultipartFile; import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.module.infra.controller.admin.file.vo.file.FileUploadReqVO; import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsDocxInfoVo; +import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo; 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_word.JudgementWpsWordService; +import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO; @@ -80,6 +82,22 @@ public class AutoWpsController { ); return CommonResult.success(judgementWpsWordService.docxMaster(wpsDocxInfoVos, file)); } - + /** + * 获取指定考点的数据 + * + * @return + * @throws Exception + */ + @PostMapping(value = "/slideMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public CommonResult> slideMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file) throws Exception { + // 手动解析JSON数组 + ObjectMapper objectMapper = new ObjectMapper(); + List wpsSlideInfoVos = objectMapper.readValue( + jsonData, + new TypeReference>() { + } + ); + return CommonResult.success(judgementWpsPptxService.slideMaster(wpsSlideInfoVos, file)); + } } 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 1ed8e283..c35f5cdc 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 @@ -11,6 +11,7 @@ import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; import pc.exam.pp.module.judgement.utils.wps_pptx.JudgementWpsPPT; import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideConversion; +import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideMaster; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; @@ -32,7 +33,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { @Override public List slideMaster(List wpsSlideInfoVos, MultipartFile file) throws Exception { - return List.of(); + return SlideMaster.slideMaster(file); } /** diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java index 70712f9a..ad97dc72 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideMaster.java @@ -1,6 +1,54 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j; +import org.docx4j.dml.chartDrawing.CTShape; +import org.docx4j.openpackaging.exceptions.Docx4JException; +import org.docx4j.openpackaging.packages.OpcPackage; +import org.docx4j.openpackaging.packages.PresentationMLPackage; +import org.docx4j.openpackaging.parts.PresentationML.SlidePart; +import org.pptx4j.pml.GroupShape; +import org.pptx4j.pml.Presentation; +import org.pptx4j.pml.Shape; +import org.springframework.web.multipart.MultipartFile; +import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + public class SlideMaster { + public static List slideMaster(MultipartFile file) throws IOException, Docx4JException { + List judgementSlidesVOS = new ArrayList<>(); + // 1、获取想要判断的文件地址(文件流) + try (InputStream inputStream = file.getInputStream()) { + // 加载 .pptx 文件 + PresentationMLPackage ppt = + (PresentationMLPackage) OpcPackage.load(inputStream); + + // 你可以在这里处理 ppt,比如读取文字、页数等 + List slideParts = ppt.getMainPresentationPart().getSlideParts(); + int slideIndex = 1; + for (SlidePart slidePart : slideParts) { + // 获取幻灯片内容 + System.out.println("========== 幻灯片 " + slideIndex++ + " =========="); + // 遍历 shape tree 中的 sp(shape)元素 + GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree(); + List shapes = spTree.getSpOrGrpSpOrGraphicFrame(); + for (Object shapeObj : shapes) { + if (shapeObj instanceof Shape) { + Shape shape = (Shape) shapeObj; + System.out.println("Shape name: " + shape.getNvSpPr().getCNvPr().getName()); + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return judgementSlidesVOS; + + } }