From 0a4cd9e61f9ae1fc0947b524cd1fda1e52efff91 Mon Sep 17 00:00:00 2001 From: dlaren Date: Fri, 15 Aug 2025 13:25:12 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E9=AA=8C=E8=AF=81pptx=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AutoWps/AutoWpsController.java | 21 +++++++++++-------- .../admin/autoTools/AutoToolsController.java | 2 +- .../utils/wps_pptx/pptx4j/ShapePage.java | 16 ++++++++++---- .../utils/wps_pptx/pptx4j/SlideMaster.java | 19 ++++++++++------- .../utils/wps_pptx/pptx4j/SlideUtils.java | 18 ++++++++++++++++ 5 files changed, 55 insertions(+), 21 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 4a2dc3e1..e696a5fa 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 @@ -98,15 +98,18 @@ public class AutoWpsController { * @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>() { - } - ); +// @PostMapping(value = "/slideMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(value = "/slideMaster") + public CommonResult> slideMaster(@RequestBody List wpsSlideInfoVos) throws Exception { +// 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>() { +// } +// ); + MultipartFile file = null; 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/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 3ea297dc..fb38749f 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 @@ -74,7 +74,7 @@ public class AutoToolsController { // 1、创建对象 StuPaperScoreInfoVo stuPaperScoreInfoVos = new StuPaperScoreInfoVo(); // 2、查询学生试卷信息 - StuScoreVo stuScoreVo = stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()); + StuScoreVo stuScoreVo = stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId()); stuPaperScoreInfoVos.setStuInfoReqVo(stuScoreVo); // 3、查询学生试卷得分信息 stuPaperScoreInfoVos.setStuPaperScoreDOList(stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId())); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java index 380bfa2b..1734bba9 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java @@ -1,14 +1,17 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; import org.docx4j.dml.*; -import org.docx4j.openpackaging.packages.PresentationMLPackage; +import org.docx4j.jaxb.XPathBinderAssociationIsPartialException; import org.docx4j.openpackaging.parts.PresentationML.SlidePart; import org.pptx4j.pml.CTSlideTiming; +import org.pptx4j.pml.CTTimeNodeList; import java.math.BigInteger; -import java.text.DecimalFormat; +import java.util.List; -public class Shape { +public class ShapePage { // 大小 - 高度 public static String getShapeSizeHeight(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { @@ -355,11 +358,16 @@ public class Shape { // 动画 效果 - public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { + public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing, SlidePart slidePart) throws JAXBException, XPathBinderAssociationIsPartialException { // 获取形状中的ID if (sp == null) return "无动画"; long spId = sp.getNvSpPr().getCNvPr().getId(); // 获取动画效果 + // 1. 查询所有 p:spTgt 节点(形状目标) + List shapeTargets = slidePart.getJAXBNodesViaXPath("//p:spTgt", false); + for (Object target : shapeTargets) { + + } return ""; } 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 221a127c..19f3c649 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 @@ -8,6 +8,7 @@ import org.docx4j.openpackaging.parts.PresentationML.SlidePart; import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart; import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart; import org.docx4j.wml.P; +import org.pptx4j.pml.CTSlideTiming; import org.pptx4j.pml.GroupShape; import org.pptx4j.pml.Shape; import org.springframework.web.multipart.MultipartFile; @@ -15,6 +16,7 @@ import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO; import pc.exam.pp.module.judgement.utils.wps_word.docx4j.paragraph.Paragraphs; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; @@ -24,12 +26,14 @@ import java.util.List; public class SlideMaster { public static List slideMaster(List wpsSlideInfoVos, MultipartFile file) throws IOException, Docx4JException { + File files = new File("E:\\Project\\Exam\\Software\\Temp\\1.pptx"); List judgementSlidesVOS = new ArrayList<>(); // 1、获取想要判断的文件地址(文件流) - try (InputStream inputStream = file.getInputStream()) { +// try (InputStream inputStream = file.getInputStream()) { + try { // 加载 .pptx 文件 PresentationMLPackage ppt = - (PresentationMLPackage) OpcPackage.load(inputStream); + (PresentationMLPackage) OpcPackage.load(files); // 你可以在这里处理 ppt,比如读取文字、页数等 for (WpsSlideInfoVo wpsSlideInfoVo : wpsSlideInfoVos) { // 幻灯片位置(第几张幻灯片) @@ -50,7 +54,7 @@ public class SlideMaster { if (type.equals("shape")) { // 查询幻灯片图片 List slideParts = ppt.getMainPresentationPart().getSlideParts(); - int slideIndexFoFile = 1; + int slideIndexFoFile = 0; for (SlidePart slidePart : slideParts) { // 获取幻灯片内容 slideIndexFoFile++; @@ -58,8 +62,9 @@ public class SlideMaster { // 查询幻灯片 // 遍历 shape tree 中的 sp(shape)元素 GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree(); + CTSlideTiming timing = slidePart.getJaxbElement().getTiming(); List shapes = spTree.getSpOrGrpSpOrGraphicFrame(); - int shapeIndexFoFile = 1; + int shapeIndexFoFile = 0; for (Object shapeObj : shapes) { shapeIndexFoFile++; if (shapeObj instanceof Shape) { @@ -67,13 +72,13 @@ public class SlideMaster { if (shapeIndex.equals(String.valueOf(shapeIndexFoFile))) { // 查询出具体想要查询哪个段落的数据 // 目标对象 - Shape shapeFunction = new Shape(); + ShapePage shapeFunction = new ShapePage(); // 获取参数中类型的定义 - Class[] paramTypes = {Shape.class}; + Class[] paramTypes = {Shape.class, CTSlideTiming.class, SlidePart.class}; // 带参数的方法调用示例 Method methodWithArgs = shapeFunction.getClass().getMethod(function, paramTypes); // 实际参数值 - Object[] arguments = {shape}; + Object[] arguments = {shape, timing, slidePart}; String value = (String) methodWithArgs.invoke(shapeFunction, arguments); System.out.println(value); } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideUtils.java index 9ebcb6d1..342b8172 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/SlideUtils.java @@ -136,4 +136,22 @@ public class SlideUtils { return new DecimalFormat("#.##").format(d); // 保留 1~2 位,去掉多余 0 } + + public static String rgbBytesToHex(byte[] val) { + if (val == null || val.length != 3) return "000000"; + return String.format("%02X%02X%02X", val[0] & 0xFF, val[1] & 0xFF, val[2] & 0xFF); + } + public static String extractAlpha(java.util.List alphas) { + if (alphas != null && !alphas.isEmpty()) { + double pct = alphas.get(0).getVal() / 1000.0; + return String.format("%.0f%%", pct); + } + return null; + } + public static int iOr0(BigInteger bi) { + return bi == null ? 0 : bi.intValue(); + } + public static String fmt(double d) { + return (Math.round(d * 100.0) / 100.0) + ""; // 保留 2 位小数 + } }