From db4d3b10102aa50ed92d83fc983ec7c4b903bded Mon Sep 17 00:00:00 2001 From: dlaren Date: Wed, 6 Aug 2025 17:09:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=20pptx=20?= =?UTF-8?q?=E7=9A=84=E5=9F=BA=E7=A1=80=E6=96=B9=E6=B3=95=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AutoWps/AutoWpsController.java | 20 +++++++- .../wps_pptx/JudgementWpsPptxServiceImpl.java | 3 +- .../utils/wps_pptx/pptx4j/SlideMaster.java | 48 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) 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; + + } }