From e1b84f4f53ba5cbc90f8089f841d1362898ac8e0 Mon Sep 17 00:00:00 2001 From: "DESKTOP-932OMT8\\REN" Date: Mon, 23 Jun 2025 14:23:46 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20WPS?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/wps/ExamWpsPptxController.java | 83 + .../admin/wps/vo/pptx/PptxListReqVO.java | 14 + .../admin/wps/vo/pptx/PptxRespVO.java | 40 + .../admin/wps/vo/pptx/PptxSaveReqVO.java | 42 + .../admin/wps/vo/pptx/PptxSimpleRespVO.java | 20 + .../exam/dal/dataobject/wps/ExamWpsPptx.java | 41 + .../exam/dal/mysql/wps/ExamWpsPptxMapper.java | 36 + .../service/wps/pptx/ExamWpsPptxService.java | 117 ++ .../wps/pptx/ExamWpsPptxServiceImpl.java | 221 +++ .../controller/admin/Wps/WpsController.java | 37 +- .../controller/admin/Wps/XlsxController.java | 150 +- .../auto_tools/AutoToolsServiceImpl.java | 94 +- .../wps_excel/JudgementWpsExcelService.java | 3 +- .../JudgementWpsExcelServiceImpl.java | 25 +- .../service/wps_excel/WpsXlsxLinkService.java | 227 ++- .../wps_excel/WpsXlsxLinkServiceImpl.java | 456 ++--- .../wps_pptx/JudgementWpsPptxService.java | 7 +- .../wps_pptx/JudgementWpsPptxServiceImpl.java | 62 +- .../judgement/utils/tree/TreeUtils.java | 24 - .../utils/wps_excel/WpsExcelUtils.java | 69 + .../utils/wps_excel/vo/ExcelInfoReqVo.java | 28 + .../wps_pptx/DeclareNamespaceForPPT.java | 40 + .../utils/wps_pptx/JudgementConvert.java | 161 ++ .../utils/wps_pptx/JudgementWpsPPT.java | 406 +++++ .../utils/wps_pptx/WpsPptxUtils.java | 1612 ++++++++--------- .../utils/wps_pptx/XmlRecursiveFinder.java | 39 + .../wps_pptx/judgementVO/JudgementReqVo.java | 38 + .../utils/wps_pptx/vo/PptxInfoReqVo.java | 2 + 28 files changed, 2729 insertions(+), 1365 deletions(-) create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsPptxController.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxListReqVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxRespVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSaveReqVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSimpleRespVO.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsPptx.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsPptxMapper.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxService.java create mode 100644 exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxServiceImpl.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/vo/ExcelInfoReqVo.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/DeclareNamespaceForPPT.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementConvert.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementWpsPPT.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/XmlRecursiveFinder.java create mode 100644 exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/judgementVO/JudgementReqVo.java diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsPptxController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsPptxController.java new file mode 100644 index 00000000..b0c10209 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsPptxController.java @@ -0,0 +1,83 @@ +package pc.exam.pp.module.exam.controller.admin.wps; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import pc.exam.pp.framework.common.enums.CommonStatusEnum; +import pc.exam.pp.framework.common.pojo.CommonResult; +import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxRespVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxSaveReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxSimpleRespVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsPptx; +import pc.exam.pp.module.exam.service.wps.pptx.ExamWpsPptxService; + +import java.util.List; + +import static pc.exam.pp.framework.common.pojo.CommonResult.success; + +@Tag(name = "考试系统 - PPTX考点") +@RestController +@RequestMapping("/exam/pptx") +@Validated +public class ExamWpsPptxController { + + @Resource + private ExamWpsPptxService examWpsPptxService; + + @PostMapping("create") + @Operation(summary = "创建PPTX考点") + public CommonResult createPptx(@Valid @RequestBody PptxSaveReqVO createReqVO) { + Long pptxId = examWpsPptxService.createPptx(createReqVO); + return success(pptxId); + } + + @PutMapping("update") + @Operation(summary = "更新PPTX考点") + public CommonResult updatePptx(@Valid @RequestBody PptxSaveReqVO updateReqVO) { + examWpsPptxService.updatePptx(updateReqVO); + return success(true); + } + + @DeleteMapping("delete") + @Operation(summary = "删除PPTX考点") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult deletePptx(@RequestParam("id") Long id) { + examWpsPptxService.deletePptx(id); + return success(true); + } + + @GetMapping("/list") + @Operation(summary = "获取PPTX考点列表") + public CommonResult> getPptxList(PptxListReqVO reqVO) { + List list = examWpsPptxService.getPptxList(reqVO); + return success(BeanUtils.toBean(list, PptxRespVO.class)); + } + + @GetMapping(value = {"/list-all-simple", "/simple-list"}) + @Operation(summary = "获取PPTX考点精简信息列表", description = "只包含被开启的PPTX考点,主要用于前端的下拉选项") + public CommonResult> getSimplePptxList() { + List list = examWpsPptxService.getPptxList( + new PptxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); + return success(BeanUtils.toBean(list, PptxSimpleRespVO.class)); + } + + @GetMapping("/get") + @Operation(summary = "获得PPTX考点信息") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult getPptx(@RequestParam("id") Long id) { + ExamWpsPptx pptx = examWpsPptxService.getPptx(id); + return success(BeanUtils.toBean(pptx, PptxRespVO.class)); + } + + @GetMapping("/getByNameList") + public CommonResult> getPptxByNameList(@RequestParam("title") String title) { + ExamWpsPptx pptx = examWpsPptxService.getPptxByTitle(title); + return success(BeanUtils.toBean(examWpsPptxService.getChildPptxList(pptx.getId()), PptxRespVO.class)); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxListReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxListReqVO.java new file mode 100644 index 00000000..19727c4a --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxListReqVO.java @@ -0,0 +1,14 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.pptx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "考试模块 - PPT考点列表 Request VO") +@Data +public class PptxListReqVO { + + private String name; + + private Integer status; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxRespVO.java new file mode 100644 index 00000000..9e9a734e --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxRespVO.java @@ -0,0 +1,40 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.pptx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "考试模块 - PPT考点信息 Response VO") +@Data +public class PptxRespVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String dataType; + + private Integer isText; + + private String valueList; + + private Integer isTrue; + + private Integer titleType; + + private Integer isParameter; + + private LocalDateTime createTime; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSaveReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSaveReqVO.java new file mode 100644 index 00000000..6b2cbef1 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSaveReqVO.java @@ -0,0 +1,42 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.pptx; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Data; +import pc.exam.pp.framework.common.enums.CommonStatusEnum; +import pc.exam.pp.framework.common.validation.InEnum; + +@Schema(description = "考试模块 - PPT考点创建/修改 Request VO") +@Data +public class PptxSaveReqVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String dataType; + + private Integer isText; + + private String valueList; + + private Integer isTrue; + + private Integer titleType; + + private Integer isParameter; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSimpleRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSimpleRespVO.java new file mode 100644 index 00000000..6421d5ca --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/pptx/PptxSimpleRespVO.java @@ -0,0 +1,20 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.pptx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Schema(description = "考试模块 - 精简信息 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PptxSimpleRespVO { + + private Long id; + + private String name; + + private Long parentId; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsPptx.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsPptx.java new file mode 100644 index 00000000..569bcb84 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsPptx.java @@ -0,0 +1,41 @@ +package pc.exam.pp.module.exam.dal.dataobject.wps; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import pc.exam.pp.framework.tenant.core.db.TenantBaseDO; + +import java.util.ArrayList; +import java.util.List; + +/** + * wps pptx关系对应表 + * + * @author REN + */ +@TableName("exam_wps_pptx") +@Data +@EqualsAndHashCode(callSuper = true) +public class ExamWpsPptx extends TenantBaseDO { + + public static final Long PARENT_ID_ROOT = 0L; + + @TableId + private Long id; + private String name; + private Long parentId; + private String title; + private Integer sort; + private String chineseName; + private String dataType; + private Integer status; + private String valueList; + private Integer isTrue; + private Integer isText; + private Integer titleType; + private Integer isParameter; + @TableField(exist = false) + private List children = new ArrayList<>(); +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsPptxMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsPptxMapper.java new file mode 100644 index 00000000..0c1ccfad --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsPptxMapper.java @@ -0,0 +1,36 @@ +package pc.exam.pp.module.exam.dal.mysql.wps; + +import org.apache.ibatis.annotations.Mapper; +import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX; +import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxListReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsPptx; + +import java.util.Collection; +import java.util.List; + +@Mapper +public interface ExamWpsPptxMapper extends BaseMapperX { + + default List selectList(PptxListReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(ExamWpsPptx::getName, reqVO.getName()) + .eqIfPresent(ExamWpsPptx::getStatus, reqVO.getStatus())); + } + + default ExamWpsPptx selectByParentIdAndName(Long parentId, String name) { + return selectOne(ExamWpsPptx::getParentId, parentId, ExamWpsPptx::getName, name); + } + + default ExamWpsPptx selectByTitle(String title) { + return selectOne(ExamWpsPptx::getTitle, title); + } + + default Long selectCountByParentId(Long parentId) { + return selectCount(ExamWpsPptx::getParentId, parentId); + } + + default List selectListByParentId(Collection parentIds) { + return selectList(ExamWpsPptx::getParentId, parentIds); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxService.java new file mode 100644 index 00000000..f97afb76 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxService.java @@ -0,0 +1,117 @@ +package pc.exam.pp.module.exam.service.wps.pptx; + +import pc.exam.pp.framework.common.util.collection.CollectionUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsPptx; + +import java.util.*; + +/** + * Pptx考点 Service 接口 + * + * @author 朋辰 + */ +public interface ExamWpsPptxService { + + /** + * 创建Pptx考点 + * + * @param createReqVO Pptx考点信息 + * @return Pptx考点编号 + */ + Long createPptx(PptxSaveReqVO createReqVO); + + /** + * 更新Pptx考点 + * + * @param updateReqVO Pptx考点信息 + */ + void updatePptx(PptxSaveReqVO updateReqVO); + + /** + * 删除Pptx考点 + * + * @param id Pptx考点编号 + */ + void deletePptx(Long id); + + /** + * 获得Pptx考点信息 + * + * @param id Pptx考点编号 + * @return Pptx考点信息 + */ + ExamWpsPptx getPptx(Long id); + + /** + * 获得Pptx考点信息 + * + * @param title Pptx考点标签 + * @return Pptx考点信息 + */ + ExamWpsPptx getPptxByTitle(String title); + + /** + * 获得Pptx考点信息数组 + * + * @param ids Pptx考点编号数组 + * @return Pptx考点信息数组 + */ + List getPptxList(Collection ids); + + /** + * 筛选Pptx考点列表 + * + * @param reqVO 筛选条件请求 VO + * @return Pptx考点列表 + */ + List getPptxList(PptxListReqVO reqVO); + + /** + * 获得指定编号的Pptx考点 Map + * + * @param ids Pptx考点编号数组 + * @return Pptx考点 Map + */ + default Map getPptxMap(Collection ids) { + List list = getPptxList(ids); + return CollectionUtils.convertMap(list, ExamWpsPptx::getId); + } + + /** + * 获得指定Pptx考点的所有子Pptx考点 + * + * @param id Pptx考点编号 + * @return 子Pptx考点列表 + */ + default List getChildPptxList(Long id) { + return getChildPptxList(Collections.singleton(id)); + } + + /** + * 获得指定Pptx考点的所有子Pptx考点 + * + * @param ids Pptx考点编号数组 + * @return 子Pptx考点列表 + */ + List getChildPptxList(Collection ids); + + /** + * 获得所有子Pptx考点,从缓存中 + * + * @param id 父Pptx考点编号 + * @return 子Pptx考点列表 + */ + Set getChildPptxIdListFromCache(Long id); + + /** + * 校验Pptx考点们是否有效。如下情况,视为无效: + * 1. Pptx考点编号不存在 + * 2. Pptx考点被禁用 + * + * @param ids 角色编号数组 + */ + void validatePptxList(Collection ids); + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxServiceImpl.java new file mode 100644 index 00000000..7bbb0141 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/pptx/ExamWpsPptxServiceImpl.java @@ -0,0 +1,221 @@ +package pc.exam.pp.module.exam.service.wps.pptx; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import com.google.common.annotations.VisibleForTesting; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import pc.exam.pp.framework.common.enums.CommonStatusEnum; +import pc.exam.pp.framework.common.util.object.BeanUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.pptx.PptxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsPptx; +import pc.exam.pp.module.exam.dal.mysql.wps.ExamWpsPptxMapper; + +import java.util.*; + +import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; +import static pc.exam.pp.framework.common.util.collection.CollectionUtils.convertSet; +import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*; + +/** + * PPTX考点 Service 实现类 + * + * @author 朋辰 + */ +@Service +@Validated +@Slf4j +public class ExamWpsPptxServiceImpl implements ExamWpsPptxService { + + @Resource + private ExamWpsPptxMapper pptxMapper; + + @Override + public Long createPptx(PptxSaveReqVO createReqVO) { + if (createReqVO.getParentId() == null) { + createReqVO.setParentId(ExamWpsPptx.PARENT_ID_ROOT); + } + // 校验父PPTX考点的有效性 + validateParentPptx(null, createReqVO.getParentId()); + // 校验PPTX考点名的唯一性 + validatePptxNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); + + // 插入PPTX考点 + ExamWpsPptx pptx = BeanUtils.toBean(createReqVO, ExamWpsPptx.class); + pptxMapper.insert(pptx); + return pptx.getId(); + } + + @Override + public void updatePptx(PptxSaveReqVO updateReqVO) { + if (updateReqVO.getParentId() == null) { + updateReqVO.setParentId(ExamWpsPptx.PARENT_ID_ROOT); + } + // 校验自己存在 + validatePptxExists(updateReqVO.getId()); + // 校验父PPTX考点的有效性 + validateParentPptx(updateReqVO.getId(), updateReqVO.getParentId()); + // 校验PPTX考点名的唯一性 + validatePptxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); + + // 更新PPTX考点 + ExamWpsPptx updateObj = BeanUtils.toBean(updateReqVO, ExamWpsPptx.class); + pptxMapper.updateById(updateObj); + } + + @Override + public void deletePptx(Long id) { + // 校验是否存在 + validatePptxExists(id); + // 校验是否有子PPTX考点 + if (pptxMapper.selectCountByParentId(id) > 0) { + throw exception(PPTX_EXITS_CHILDREN); + } + // 删除PPTX考点 + pptxMapper.deleteById(id); + } + + @VisibleForTesting + void validatePptxExists(Long id) { + if (id == null) { + return; + } + ExamWpsPptx pptx = pptxMapper.selectById(id); + if (pptx == null) { + throw exception(PPTX_NOT_FOUND); + } + } + + @VisibleForTesting + void validateParentPptx(Long id, Long parentId) { + if (parentId == null || ExamWpsPptx.PARENT_ID_ROOT.equals(parentId)) { + return; + } + // 1. 不能设置自己为父PPTX考点 + if (Objects.equals(id, parentId)) { + throw exception(PPTX_PARENT_ERROR); + } + // 2. 父PPTX考点不存在 + ExamWpsPptx parent = pptxMapper.selectById(parentId); + if (parent == null) { + throw exception(PPTX_PARENT_NOT_EXITS); + } + // 3. 递归校验父PPTX考点,如果父PPTX考点是自己的子PPTX考点,则报错,避免形成环路 + if (id == null) { // id 为空,说明新增,不需要考虑环路 + return; + } + for (int i = 0; i < Short.MAX_VALUE; i++) { + // 3.1 校验环路 + parentId = parent.getParentId(); + if (Objects.equals(id, parentId)) { + throw exception(PPTX_PARENT_IS_CHILD); + } + // 3.2 继续递归下一级父PPTX考点 + if (parentId == null || ExamWpsPptx.PARENT_ID_ROOT.equals(parentId)) { + break; + } + parent = pptxMapper.selectById(parentId); + if (parent == null) { + break; + } + } + } + + @VisibleForTesting + void validatePptxNameUnique(Long id, Long parentId, String name) { + ExamWpsPptx dept = pptxMapper.selectByParentIdAndName(parentId, name); + if (dept == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的PPTX考点 + if (id == null) { + throw exception(PPTX_NAME_DUPLICATE); + } + if (ObjectUtil.notEqual(dept.getId(), id)) { + throw exception(PPTX_NAME_DUPLICATE); + } + } + + @Override + public ExamWpsPptx getPptx(Long id) { + return pptxMapper.selectById(id); + } + + @Override + public ExamWpsPptx getPptxByTitle(String title) { + return pptxMapper.selectByTitle(title); + } + + @Override + public List getPptxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return pptxMapper.selectBatchIds(ids); + } + + @Override + public List getPptxList(PptxListReqVO reqVO) { + List list = pptxMapper.selectList(reqVO); + list.sort(Comparator.comparing(ExamWpsPptx::getSort)); + return list; + } + + @Override + public Map getPptxMap(Collection ids) { + return ExamWpsPptxService.super.getPptxMap(ids); + } + + @Override + public List getChildPptxList(Long id) { + return ExamWpsPptxService.super.getChildPptxList(id); + } + + @Override + public List getChildPptxList(Collection ids) { + List children = new LinkedList<>(); + // 遍历每一层 + Collection parentIds = ids; + for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 + // 查询当前层,所有的子PPTX考点 + List pptxs = pptxMapper.selectListByParentId(parentIds); + // 1. 如果没有子PPTX考点,则结束遍历 + if (CollUtil.isEmpty(pptxs)) { + break; + } + // 2. 如果有子PPTX考点,继续遍历 + children.addAll(pptxs); + parentIds = convertSet(pptxs, ExamWpsPptx::getId); + } + return children; + } + + @Override + public Set getChildPptxIdListFromCache(Long id) { + List children = getChildPptxList(id); + return convertSet(children, ExamWpsPptx::getId); + } + + @Override + public void validatePptxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return; + } + // 获得科室信息 + Map pptxMap = getPptxMap(ids); + // 校验 + ids.forEach(id -> { + ExamWpsPptx pptx = pptxMap.get(id); + if (pptx == null) { + throw exception(PPTX_NOT_FOUND); + } + if (!CommonStatusEnum.ENABLE.getStatus().equals(pptx.getStatus())) { + throw exception(PPTX_NOT_ENABLE, pptx.getName()); + } + }); + } + +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java index e72ad3f7..6454c8fb 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java @@ -13,10 +13,12 @@ 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_excel.vo.ExcelInfoReqVo; +import pc.exam.pp.module.judgement.utils.wps_excel.vo.ExcelInfoReqVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxVO; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_all.XlsxAllDataReqVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_style.XlsxStyleVO; +import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO; @@ -60,15 +62,6 @@ public class WpsController { public CommonResult> runWpsWord(String path) throws Exception { return CommonResult.success(judgementWpsWordService.programmingWpsWord(path)); } - - /** - * wps xlsx - * @return 判分 - */ - @PostMapping("/runWpsPptxInfo") - public CommonResult> runWpsPptxInfo(@RequestBody List pptxInfoPointsVos) throws Exception { - return CommonResult.success(judgementWpsPptxService.getWpsPptxInfo(pptxInfoPointsVos)); - } /** * wps xlsx * @return 判分 @@ -78,14 +71,24 @@ public class WpsController { return CommonResult.success(judgementWpsPptxService.programmingWpsPptx(path)); } + /** + * wps xlsx + * @return 判分 + */ + @PostMapping("/runTestpptx") + public CommonResult> runTestpptx(@RequestBody List judgementReq, String path) throws Exception { + return CommonResult.success(judgementWpsPptxService.judgementWpsPptx(judgementReq, path)); + } -// /** -// * wps xlsx -// * @return 判分 -// */ -// @GetMapping("/runWpsXlsx") -// public CommonResult> runWpsXlsx(String path) throws Exception { -// return CommonResult.success(judgementWpsExcelService.programmingWpsExcel(path)); -// } + + + /** + * wps xlsx + * @return 判分 + */ + @GetMapping("/runWpsXlsx") + public CommonResult> runWpsXlsx(String path) throws Exception { + return CommonResult.success(judgementWpsExcelService.programmingWpsExcel(path)); + } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/XlsxController.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/XlsxController.java index 432c51e4..20eb7cb8 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/XlsxController.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/XlsxController.java @@ -1,75 +1,75 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import pc.exam.pp.framework.common.enums.CommonStatusEnum; -import pc.exam.pp.framework.common.pojo.CommonResult; -import pc.exam.pp.framework.common.util.object.BeanUtils; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.*; -import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; -import pc.exam.pp.module.judgement.service.wps_excel.WpsXlsxLinkService; - -import java.util.List; - -import static pc.exam.pp.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - wps_xlsx") -@RestController -@RequestMapping("/wps/xlsx") -@Validated -public class XlsxController { - - @Resource - private WpsXlsxLinkService wpsXlsxLinkService; - - @PostMapping("create") - @Operation(summary = "创建wps_xlsx") - public CommonResult createXlsx(@Valid @RequestBody XlsxSaveReqVO createReqVO) { - Long xlsxId = wpsXlsxLinkService.createXlsx(createReqVO); - return success(xlsxId); - } - - @PutMapping("update") - @Operation(summary = "更新wps_xlsx") - public CommonResult updateXlsx(@Valid @RequestBody XlsxSaveReqVO updateReqVO) { - wpsXlsxLinkService.updateXlsx(updateReqVO); - return success(true); - } - - @DeleteMapping("delete") - @Operation(summary = "删除wps_xlsx") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - public CommonResult deleteXlsx(@RequestParam("id") Long id) { - wpsXlsxLinkService.deleteXlsx(id); - return success(true); - } - - @GetMapping("/list") - @Operation(summary = "获取wps_xlsx列表") - public CommonResult> getXlsxList(XlsxListReqVO reqVO) { - List list = wpsXlsxLinkService.getXlsxList(reqVO); - return success(BeanUtils.toBean(list, XlsxRespVO.class)); - } - - @GetMapping(value = {"/list-all-simple", "/simple-list"}) - @Operation(summary = "获取wps_xlsx精简信息列表", description = "只包含被开启的wps_xlsx,主要用于前端的下拉选项") - public CommonResult> getSimpleXlsxList() { - List list = wpsXlsxLinkService.getXlsxList( - new XlsxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); - return success(BeanUtils.toBean(list, XlsxSimpleRespVO.class)); - } - - @GetMapping("/get") - @Operation(summary = "获得wps_xlsx信息") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - public CommonResult getPptx(@RequestParam("id") Long id) { - WpsXlsxLinkDO xlsx = wpsXlsxLinkService.getXlsx(id); - return success(BeanUtils.toBean(xlsx, XlsxRespVO.class)); - } - -} +//package pc.exam.pp.module.judgement.controller.admin.Wps; +// +//import io.swagger.v3.oas.annotations.Operation; +//import io.swagger.v3.oas.annotations.Parameter; +//import io.swagger.v3.oas.annotations.tags.Tag; +//import jakarta.annotation.Resource; +//import jakarta.validation.Valid; +//import org.springframework.validation.annotation.Validated; +//import org.springframework.web.bind.annotation.*; +//import pc.exam.pp.framework.common.enums.CommonStatusEnum; +//import pc.exam.pp.framework.common.pojo.CommonResult; +//import pc.exam.pp.framework.common.util.object.BeanUtils; +//import pc.exam.pp.module.judgement.controller.admin.Wps.vo.*; +//import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; +//import pc.exam.pp.module.judgement.service.wps_excel.WpsXlsxLinkService; +// +//import java.util.List; +// +//import static pc.exam.pp.framework.common.pojo.CommonResult.success; +// +//@Tag(name = "管理后台 - wps_xlsx") +//@RestController +//@RequestMapping("/wps/xlsx") +//@Validated +//public class XlsxController { +// +// @Resource +// private WpsXlsxLinkService wpsXlsxLinkService; +// +// @PostMapping("create") +// @Operation(summary = "创建wps_xlsx") +// public CommonResult createXlsx(@Valid @RequestBody XlsxSaveReqVO createReqVO) { +// Long xlsxId = wpsXlsxLinkService.createXlsx(createReqVO); +// return success(xlsxId); +// } +// +// @PutMapping("update") +// @Operation(summary = "更新wps_xlsx") +// public CommonResult updateXlsx(@Valid @RequestBody XlsxSaveReqVO updateReqVO) { +// wpsXlsxLinkService.updateXlsx(updateReqVO); +// return success(true); +// } +// +// @DeleteMapping("delete") +// @Operation(summary = "删除wps_xlsx") +// @Parameter(name = "id", description = "编号", required = true, example = "1024") +// public CommonResult deleteXlsx(@RequestParam("id") Long id) { +// wpsXlsxLinkService.deleteXlsx(id); +// return success(true); +// } +// +// @GetMapping("/list") +// @Operation(summary = "获取wps_xlsx列表") +// public CommonResult> getXlsxList(XlsxListReqVO reqVO) { +// List list = wpsXlsxLinkService.getXlsxList(reqVO); +// return success(BeanUtils.toBean(list, XlsxRespVO.class)); +// } +// +// @GetMapping(value = {"/list-all-simple", "/simple-list"}) +// @Operation(summary = "获取wps_xlsx精简信息列表", description = "只包含被开启的wps_xlsx,主要用于前端的下拉选项") +// public CommonResult> getSimpleXlsxList() { +// List list = wpsXlsxLinkService.getXlsxList( +// new XlsxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); +// return success(BeanUtils.toBean(list, XlsxSimpleRespVO.class)); +// } +// +// @GetMapping("/get") +// @Operation(summary = "获得wps_xlsx信息") +// @Parameter(name = "id", description = "编号", required = true, example = "1024") +// public CommonResult getPptx(@RequestParam("id") Long id) { +// WpsXlsxLinkDO xlsx = wpsXlsxLinkService.getXlsx(id); +// return success(BeanUtils.toBean(xlsx, XlsxRespVO.class)); +// } +// +//} 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 057315df..9a7c773c 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 @@ -461,53 +461,53 @@ public class AutoToolsServiceImpl implements AutoToolsService{ break; } } - if ("演示".equals(one_file.getName().split("\\.")[0])) { - if (file_one.getPath().contains("文档")) { - String judgementStrPptx = ""; - SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrPptx); - double wps_pptx_score = pptxpojo.getScore(); - String judgementStr = "

-----------------------------------------------------------

"; - judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; - judgementStr += pptxpojo.getText(); - // 通过学号+试卷ID+试题ID进行查询 - StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); - if (stuPaperInfoDO != null) { - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); - } else { - stuPaperInfoDO = new StuPaperInfoDO(); - stuPaperInfoDO.setStuId(stuId); - stuPaperInfoDO.setPaperId(paperId); - stuPaperInfoDO.setQuId(examQuestion.getQuId()); - stuPaperInfoDO.setContent(judgementStr); - stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); - stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); - } - score += wps_pptx_score; - stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score)); - // 原始正确分数 - stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); - // 判断题是否正确 - if (wps_pptx_score == Double.parseDouble(quScore)) { - stuPaperScoreDO.setIsTrue(0); - } else if (wps_pptx_score == 0) { - stuPaperScoreDO.setIsTrue(1); - } else { - stuPaperScoreDO.setIsTrue(2); - } - stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); - if (isNull) { - // 如果之前没做过,则插入该题的分数 - stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); - } else { - // 如果之前做过,则更新该题的分数 - stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); - } - System.out.println(wps_pptx_score+"wps_ppt得分"); - break; - } - } +// if ("演示".equals(one_file.getName().split("\\.")[0])) { +// if (file_one.getPath().contains("文档")) { +// String judgementStrPptx = ""; +// SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrPptx); +// double wps_pptx_score = pptxpojo.getScore(); +// String judgementStr = "

-----------------------------------------------------------

"; +// judgementStr += "

试题编号" + examQuestion.getQuNum() + "

"; +// judgementStr += pptxpojo.getText(); +// // 通过学号+试卷ID+试题ID进行查询 +// StuPaperInfoDO stuPaperInfoDO = stuPaperInfoService.findByStuIDAndPaperIdAndExamId(stuId, paperId, examQuestion.getQuId()); +// if (stuPaperInfoDO != null) { +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.updateStuPaperInfo(stuPaperInfoDO); +// } else { +// stuPaperInfoDO = new StuPaperInfoDO(); +// stuPaperInfoDO.setStuId(stuId); +// stuPaperInfoDO.setPaperId(paperId); +// stuPaperInfoDO.setQuId(examQuestion.getQuId()); +// stuPaperInfoDO.setContent(judgementStr); +// stuPaperInfoDO.setSort(stuPaperScoreDO.getSort()); +// stuPaperInfoService.insertStuPaperInfo(stuPaperInfoDO); +// } +// score += wps_pptx_score; +// stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score)); +// // 原始正确分数 +// stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); +// // 判断题是否正确 +// if (wps_pptx_score == Double.parseDouble(quScore)) { +// stuPaperScoreDO.setIsTrue(0); +// } else if (wps_pptx_score == 0) { +// stuPaperScoreDO.setIsTrue(1); +// } else { +// stuPaperScoreDO.setIsTrue(2); +// } +// stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); +// if (isNull) { +// // 如果之前没做过,则插入该题的分数 +// stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); +// } else { +// // 如果之前做过,则更新该题的分数 +// stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); +// } +// System.out.println(wps_pptx_score+"wps_ppt得分"); +// break; +// } +// } // if ("表格".equals(one_file.getName().split("\\.")[0])) { // double wps_excel_score = judgementWpsExcelService.judgementWpsXlsx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion); // score += wps_excel_score; diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java index a2900d13..3bfac291 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/JudgementWpsExcelService.java @@ -3,6 +3,7 @@ package pc.exam.pp.module.judgement.service.wps_excel; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; +import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxVO; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_all.XlsxAllDataReqVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo; @@ -27,5 +28,5 @@ public interface JudgementWpsExcelService { */ List programmingWpsExcel(String path) throws Exception; - double judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception; + SourceAndText judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception; } 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 052fa3ef..1d9685b9 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 @@ -9,24 +9,14 @@ import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer; import pc.exam.pp.module.exam.utils.file.LogFileUtils; 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.Wps.vo.PptxListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxListReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; -import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper; import pc.exam.pp.module.judgement.dal.mysql.wpsxlsx.WpsXlsxLinkMapper; import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; +import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; +import pc.exam.pp.module.judgement.utils.HtmlAppender; import pc.exam.pp.module.judgement.utils.wps_excel.WpsExcelUtils; -import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxVO; -import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_all.XlsxAllDataReqVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo; -import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_style.XlsxStyleVO; -import pc.exam.pp.module.judgement.utils.wps_pptx.WpsPptxUtils; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO; import java.io.File; -import java.io.FileNotFoundException; import java.util.List; @Service @@ -55,7 +45,8 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { } @Override - public double judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception { + public SourceAndText judgementWpsXlsx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception { + SourceAndText sourceAndText = new SourceAndText(); // 1创建log文件txt,用于记录 File pathCDir = new File(pathC); File parentDir = pathCDir.getParentFile(); @@ -64,6 +55,7 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { String targetFilePath = new File(parentDir, "WPS_Xlsx判分过程.txt").getPath(); LogFileUtils.createFile(targetFilePath); LogFileUtils.writeLine("✅ 开始WPS_Xlsx判分"); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 开始WPS_Xlsx判分"); double wpsXlsxScore = 0; List margins = WpsExcelUtils.wpsExcel(path); // 3、获取答案得组成 @@ -92,13 +84,18 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { wpsXlsxScore += one_sorce; if (flag) { LogFileUtils.writeLine("✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); } else { LogFileUtils.writeLine("❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); } } LogFileUtils.writeLine("✅ 结束WPS_Xlsx判分,试题得分:" + wpsXlsxScore); + judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 结束WPS_Xlsx判分,试题得分:" + wpsXlsxScore); + sourceAndText.setText(judgementStr); + sourceAndText.setScore(wpsXlsxScore); // 关闭已经打开得文件 LogFileUtils.close(); - return wpsXlsxScore; + return sourceAndText; } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkService.java index c162a35e..008b3e83 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkService.java @@ -1,115 +1,112 @@ -package pc.exam.pp.module.judgement.service.wps_excel; - -import pc.exam.pp.framework.common.util.collection.CollectionUtils; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxSaveReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxSaveReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; - -import java.util.*; - -/** - * 节点 Service 接口 - * - * @author 朋辰 - */ -public interface WpsXlsxLinkService { - - /** - * 创建节点 - * - * @param createReqVO 节点信息 - * @return 节点编号 - */ - Long createXlsx(XlsxSaveReqVO createReqVO); - - /** - * 更新节点 - * - * @param updateReqVO 节点信息 - */ - void updateXlsx(XlsxSaveReqVO updateReqVO); - - /** - * 删除节点 - * - * @param id 节点编号 - */ - void deleteXlsx(Long id); - - /** - * 获得节点信息 - * - * @param id 节点编号 - * @return 节点信息 - */ - WpsXlsxLinkDO getXlsx(Long id); - - /** - * 获得节点信息数组 - * - * @param ids 节点编号数组 - * @return 节点信息数组 - */ - List getXlsxList(Collection ids); - - /** - * 筛选节点列表 - * - * @param reqVO 筛选条件请求 VO - * @return 节点列表 - */ - List getXlsxList(XlsxListReqVO reqVO); - - /** - * 获得指定编号的节点 Map - * - * @param ids 节点编号数组 - * @return 节点 Map - */ - default Map getXlsxMap(Collection ids) { - List list = getXlsxList(ids); - return CollectionUtils.convertMap(list, WpsXlsxLinkDO::getId); - } - - /** - * 获得指定节点的所有子节点 - * - * @param id 节点编号 - * @return 子节点列表 - */ - default List getChildXlsxList(Long id) { - return getChildXlsxList(Collections.singleton(id)); - } - - /** - * 获得指定节点的所有子节点 - * - * @param ids 节点编号数组 - * @return 子节点列表 - */ - List getChildXlsxList(Collection ids); - - /** - * 获得所有子节点,从缓存中 - * - * @param id 父节点编号 - * @return 子节点列表 - */ - Set getChildXlsxIdListFromCache(Long id); - - /** - * 校验节点们是否有效。如下情况,视为无效: - * 1. 节点编号不存在 - * 2. 节点被禁用 - * - * @param ids 角色编号数组 - */ - void validateXlsxList(Collection ids); - - List getXlsxTreeList(); - -} +//package pc.exam.pp.module.judgement.service.wps_excel; +// +//import pc.exam.pp.framework.common.util.collection.CollectionUtils; +//import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxListReqVO; +//import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxSaveReqVO; +//import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; +//import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; +// +//import java.util.*; +// +///** +// * 节点 Service 接口 +// * +// * @author 朋辰 +// */ +//public interface WpsXlsxLinkService { +// +// /** +// * 创建节点 +// * +// * @param createReqVO 节点信息 +// * @return 节点编号 +// */ +// Long createXlsx(XlsxSaveReqVO createReqVO); +// +// /** +// * 更新节点 +// * +// * @param updateReqVO 节点信息 +// */ +// void updateXlsx(XlsxSaveReqVO updateReqVO); +// +// /** +// * 删除节点 +// * +// * @param id 节点编号 +// */ +// void deleteXlsx(Long id); +// +// /** +// * 获得节点信息 +// * +// * @param id 节点编号 +// * @return 节点信息 +// */ +// WpsXlsxLinkDO getXlsx(Long id); +// +// /** +// * 获得节点信息数组 +// * +// * @param ids 节点编号数组 +// * @return 节点信息数组 +// */ +// List getXlsxList(Collection ids); +// +// /** +// * 筛选节点列表 +// * +// * @param reqVO 筛选条件请求 VO +// * @return 节点列表 +// */ +// List getXlsxList(XlsxListReqVO reqVO); +// +// /** +// * 获得指定编号的节点 Map +// * +// * @param ids 节点编号数组 +// * @return 节点 Map +// */ +// default Map getXlsxMap(Collection ids) { +// List list = getXlsxList(ids); +// return CollectionUtils.convertMap(list, WpsXlsxLinkDO::getId); +// } +// +// /** +// * 获得指定节点的所有子节点 +// * +// * @param id 节点编号 +// * @return 子节点列表 +// */ +// default List getChildXlsxList(Long id) { +// return getChildXlsxList(Collections.singleton(id)); +// } +// +// /** +// * 获得指定节点的所有子节点 +// * +// * @param ids 节点编号数组 +// * @return 子节点列表 +// */ +// List getChildXlsxList(Collection ids); +// +// /** +// * 获得所有子节点,从缓存中 +// * +// * @param id 父节点编号 +// * @return 子节点列表 +// */ +// Set getChildXlsxIdListFromCache(Long id); +// +// /** +// * 校验节点们是否有效。如下情况,视为无效: +// * 1. 节点编号不存在 +// * 2. 节点被禁用 +// * +// * @param ids 角色编号数组 +// */ +// void validateXlsxList(Collection ids); +// +// List getXlsxTreeList(); +// +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkServiceImpl.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkServiceImpl.java index be87ae10..a3dd86ce 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkServiceImpl.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_excel/WpsXlsxLinkServiceImpl.java @@ -1,228 +1,228 @@ -package pc.exam.pp.module.judgement.service.wps_excel; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import com.google.common.annotations.VisibleForTesting; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; -import pc.exam.pp.framework.common.enums.CommonStatusEnum; -import pc.exam.pp.framework.common.util.object.BeanUtils; -import pc.exam.pp.framework.datapermission.core.annotation.DataPermission; -import pc.exam.pp.framework.tenant.core.aop.TenantIgnore; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxSaveReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; -import pc.exam.pp.module.judgement.dal.mysql.wpsxlsx.WpsXlsxLinkMapper; -import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; -import pc.exam.pp.module.system.dal.redis.RedisKeyConstants; - -import java.util.*; - -import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; -import static pc.exam.pp.framework.common.util.collection.CollectionUtils.convertSet; -import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*; - -/** - * 节点 Service 实现类 - * - */ -@Service -@Validated -@Slf4j -public class WpsXlsxLinkServiceImpl implements WpsXlsxLinkService { - - @Resource - private WpsXlsxLinkMapper wpsXlsxLinkMapper; - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public Long createXlsx(XlsxSaveReqVO createReqVO) { - if (createReqVO.getParentId() == null) { - createReqVO.setParentId(WpsPptxLinkDO.PARENT_ID_ROOT); - } - // 校验父节点的有效性 - validateParentXlsx(null, createReqVO.getParentId()); - // 校验节点名的唯一性 - validateXlsxNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); - - // 插入节点 - WpsXlsxLinkDO wpsXlsxLinkDO = BeanUtils.toBean(createReqVO, WpsXlsxLinkDO.class); - wpsXlsxLinkMapper.insert(wpsXlsxLinkDO); - return wpsXlsxLinkDO.getId(); - } - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public void updateXlsx(XlsxSaveReqVO updateReqVO) { - if (updateReqVO.getParentId() == null) { - updateReqVO.setParentId(WpsPptxLinkDO.PARENT_ID_ROOT); - } - // 校验自己存在 - validateXlsxExists(updateReqVO.getId()); - // 校验父节点的有效性 - validateParentXlsx(updateReqVO.getId(), updateReqVO.getParentId()); - // 校验节点名的唯一性 - validateXlsxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); - - // 更新节点 - WpsXlsxLinkDO updateObj = BeanUtils.toBean(updateReqVO, WpsXlsxLinkDO.class); - wpsXlsxLinkMapper.updateById(updateObj); - } - - @Override - @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, - allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 - public void deleteXlsx(Long id) { - // 校验是否存在 - validateXlsxExists(id); - // 校验是否有子节点 - if (wpsXlsxLinkMapper.selectCountByParentId(id) > 0) { - throw exception(XLSX_NOT_FOUND); - } - // 删除节点 - wpsXlsxLinkMapper.deleteById(id); - } - - @VisibleForTesting - void validateXlsxExists(Long id) { - if (id == null) { - return; - } - WpsXlsxLinkDO wpsXlsxLinkDO = wpsXlsxLinkMapper.selectById(id); - if (wpsXlsxLinkDO == null) { - throw exception(XLSX_NOT_FOUND); - } - } - - @VisibleForTesting - void validateParentXlsx(Long id, Long parentId) { - if (parentId == null || WpsXlsxLinkDO.PARENT_ID_ROOT.equals(parentId)) { - return; - } - // 1. 不能设置自己为父节点 - if (Objects.equals(id, parentId)) { - throw exception(DEPT_PARENT_ERROR); - } - // 2. 父节点不存在 - WpsXlsxLinkDO parentXlsx = wpsXlsxLinkMapper.selectById(parentId); - if (parentXlsx == null) { - throw exception(XLSX_PARENT_NOT_EXITS); - } - // 3. 递归校验父节点,如果父节点是自己的子节点,则报错,避免形成环路 - // id 为空,说明新增,不需要考虑环路 - if (id == null) { - return; - } - for (int i = 0; i < Short.MAX_VALUE; i++) { - // 3.1 校验环路 - parentId = parentXlsx.getParentId(); - if (Objects.equals(id, parentId)) { - throw exception(XLSX_PARENT_IS_CHILD); - } - // 3.2 继续递归下一级父节点 - if (parentId == null || WpsPptxLinkDO.PARENT_ID_ROOT.equals(parentId)) { - break; - } - parentXlsx = wpsXlsxLinkMapper.selectById(parentId); - if (parentXlsx == null) { - break; - } - } - } - - @VisibleForTesting - void validateXlsxNameUnique(Long id, Long parentId, String name) { - WpsXlsxLinkDO wpsXlsxLinkDO = wpsXlsxLinkMapper.selectByParentIdAndName(parentId, name); - if (wpsXlsxLinkDO == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的节点 - if (id == null) { - throw exception(XLSX_NAME_DUPLICATE); - } - if (ObjectUtil.notEqual(wpsXlsxLinkDO.getId(), id)) { - throw exception(XLSX_NAME_DUPLICATE); - } - } - - @Override - public WpsXlsxLinkDO getXlsx(Long id) { - return wpsXlsxLinkMapper.selectById(id); - } - - @Override - public List getXlsxList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return Collections.emptyList(); - } - return wpsXlsxLinkMapper.selectBatchIds(ids); - } - - @Override - public List getXlsxList(XlsxListReqVO reqVO) { - List list = wpsXlsxLinkMapper.selectList(reqVO); - list.sort(Comparator.comparing(WpsXlsxLinkDO::getSort)); - return list; - } - - @Override - public List getChildXlsxList(Collection ids) { - List children = new LinkedList<>(); - // 遍历每一层 - Collection parentIds = ids; - // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 - for (int i = 0; i < Short.MAX_VALUE; i++) { - // 查询当前层,所有的子节点 - List xlsxs = wpsXlsxLinkMapper.selectListByParentId(parentIds); - // 1. 如果没有子节点,则结束遍历 - if (CollUtil.isEmpty(xlsxs)) { - break; - } - // 2. 如果有子节点,继续遍历 - children.addAll(xlsxs); - parentIds = convertSet(xlsxs, WpsXlsxLinkDO::getId); - } - return children; - } - - @Override - @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存 - @Cacheable(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, key = "#id") - public Set getChildXlsxIdListFromCache(Long id) { - List children = getChildXlsxList(id); - return convertSet(children, WpsXlsxLinkDO::getId); - } - - @Override - public void validateXlsxList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 获得科室信息 - Map xlsxMap = getXlsxMap(ids); - // 校验 - ids.forEach(id -> { - WpsXlsxLinkDO xlsx = xlsxMap.get(id); - if (xlsx == null) { - throw exception(XLSX_NOT_FOUND); - } - if (!CommonStatusEnum.ENABLE.getStatus().equals(xlsx.getStatus())) { - throw exception(XLSX_NOT_ENABLE, xlsx.getName()); - } - }); - } - - @Override - @TenantIgnore - public List getXlsxTreeList() { - return wpsXlsxLinkMapper.selectTreeListByNodeFunction(); - } - -} +//package pc.exam.pp.module.judgement.service.wps_excel; +// +//import cn.hutool.core.collection.CollUtil; +//import cn.hutool.core.util.ObjectUtil; +//import com.google.common.annotations.VisibleForTesting; +//import jakarta.annotation.Resource; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.cache.annotation.CacheEvict; +//import org.springframework.cache.annotation.Cacheable; +//import org.springframework.stereotype.Service; +//import org.springframework.validation.annotation.Validated; +//import pc.exam.pp.framework.common.enums.CommonStatusEnum; +//import pc.exam.pp.framework.common.util.object.BeanUtils; +//import pc.exam.pp.framework.datapermission.core.annotation.DataPermission; +//import pc.exam.pp.framework.tenant.core.aop.TenantIgnore; +//import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxListReqVO; +//import pc.exam.pp.module.judgement.controller.admin.Wps.vo.XlsxSaveReqVO; +//import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; +//import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; +//import pc.exam.pp.module.judgement.dal.mysql.wpsxlsx.WpsXlsxLinkMapper; +//import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO; +//import pc.exam.pp.module.system.dal.redis.RedisKeyConstants; +// +//import java.util.*; +// +//import static pc.exam.pp.framework.common.exception.util.ServiceExceptionUtil.exception; +//import static pc.exam.pp.framework.common.util.collection.CollectionUtils.convertSet; +//import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*; +// +///** +// * 节点 Service 实现类 +// * +// */ +//@Service +//@Validated +//@Slf4j +//public class WpsXlsxLinkServiceImpl implements WpsXlsxLinkService { +// +// @Resource +// private WpsXlsxLinkMapper wpsXlsxLinkMapper; +// +// @Override +// @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, +// allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 +// public Long createXlsx(XlsxSaveReqVO createReqVO) { +// if (createReqVO.getParentId() == null) { +// createReqVO.setParentId(WpsPptxLinkDO.PARENT_ID_ROOT); +// } +// // 校验父节点的有效性 +// validateParentXlsx(null, createReqVO.getParentId()); +// // 校验节点名的唯一性 +// validateXlsxNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); +// +// // 插入节点 +// WpsXlsxLinkDO wpsXlsxLinkDO = BeanUtils.toBean(createReqVO, WpsXlsxLinkDO.class); +// wpsXlsxLinkMapper.insert(wpsXlsxLinkDO); +// return wpsXlsxLinkDO.getId(); +// } +// +// @Override +// @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, +// allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 +// public void updateXlsx(XlsxSaveReqVO updateReqVO) { +// if (updateReqVO.getParentId() == null) { +// updateReqVO.setParentId(WpsPptxLinkDO.PARENT_ID_ROOT); +// } +// // 校验自己存在 +// validateXlsxExists(updateReqVO.getId()); +// // 校验父节点的有效性 +// validateParentXlsx(updateReqVO.getId(), updateReqVO.getParentId()); +// // 校验节点名的唯一性 +// validateXlsxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); +// +// // 更新节点 +// WpsXlsxLinkDO updateObj = BeanUtils.toBean(updateReqVO, WpsXlsxLinkDO.class); +// wpsXlsxLinkMapper.updateById(updateObj); +// } +// +// @Override +// @CacheEvict(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, +// allEntries = true) // allEntries 清空所有缓存,因为操作一个节点,涉及到多个缓存 +// public void deleteXlsx(Long id) { +// // 校验是否存在 +// validateXlsxExists(id); +// // 校验是否有子节点 +// if (wpsXlsxLinkMapper.selectCountByParentId(id) > 0) { +// throw exception(XLSX_NOT_FOUND); +// } +// // 删除节点 +// wpsXlsxLinkMapper.deleteById(id); +// } +// +// @VisibleForTesting +// void validateXlsxExists(Long id) { +// if (id == null) { +// return; +// } +// WpsXlsxLinkDO wpsXlsxLinkDO = wpsXlsxLinkMapper.selectById(id); +// if (wpsXlsxLinkDO == null) { +// throw exception(XLSX_NOT_FOUND); +// } +// } +// +// @VisibleForTesting +// void validateParentXlsx(Long id, Long parentId) { +// if (parentId == null || WpsXlsxLinkDO.PARENT_ID_ROOT.equals(parentId)) { +// return; +// } +// // 1. 不能设置自己为父节点 +// if (Objects.equals(id, parentId)) { +// throw exception(DEPT_PARENT_ERROR); +// } +// // 2. 父节点不存在 +// WpsXlsxLinkDO parentXlsx = wpsXlsxLinkMapper.selectById(parentId); +// if (parentXlsx == null) { +// throw exception(XLSX_PARENT_NOT_EXITS); +// } +// // 3. 递归校验父节点,如果父节点是自己的子节点,则报错,避免形成环路 +// // id 为空,说明新增,不需要考虑环路 +// if (id == null) { +// return; +// } +// for (int i = 0; i < Short.MAX_VALUE; i++) { +// // 3.1 校验环路 +// parentId = parentXlsx.getParentId(); +// if (Objects.equals(id, parentId)) { +// throw exception(XLSX_PARENT_IS_CHILD); +// } +// // 3.2 继续递归下一级父节点 +// if (parentId == null || WpsPptxLinkDO.PARENT_ID_ROOT.equals(parentId)) { +// break; +// } +// parentXlsx = wpsXlsxLinkMapper.selectById(parentId); +// if (parentXlsx == null) { +// break; +// } +// } +// } +// +// @VisibleForTesting +// void validateXlsxNameUnique(Long id, Long parentId, String name) { +// WpsXlsxLinkDO wpsXlsxLinkDO = wpsXlsxLinkMapper.selectByParentIdAndName(parentId, name); +// if (wpsXlsxLinkDO == null) { +// return; +// } +// // 如果 id 为空,说明不用比较是否为相同 id 的节点 +// if (id == null) { +// throw exception(XLSX_NAME_DUPLICATE); +// } +// if (ObjectUtil.notEqual(wpsXlsxLinkDO.getId(), id)) { +// throw exception(XLSX_NAME_DUPLICATE); +// } +// } +// +// @Override +// public WpsXlsxLinkDO getXlsx(Long id) { +// return wpsXlsxLinkMapper.selectById(id); +// } +// +// @Override +// public List getXlsxList(Collection ids) { +// if (CollUtil.isEmpty(ids)) { +// return Collections.emptyList(); +// } +// return wpsXlsxLinkMapper.selectBatchIds(ids); +// } +// +// @Override +// public List getXlsxList(XlsxListReqVO reqVO) { +// List list = wpsXlsxLinkMapper.selectList(reqVO); +// list.sort(Comparator.comparing(WpsXlsxLinkDO::getSort)); +// return list; +// } +// +// @Override +// public List getChildXlsxList(Collection ids) { +// List children = new LinkedList<>(); +// // 遍历每一层 +// Collection parentIds = ids; +// // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 +// for (int i = 0; i < Short.MAX_VALUE; i++) { +// // 查询当前层,所有的子节点 +// List xlsxs = wpsXlsxLinkMapper.selectListByParentId(parentIds); +// // 1. 如果没有子节点,则结束遍历 +// if (CollUtil.isEmpty(xlsxs)) { +// break; +// } +// // 2. 如果有子节点,继续遍历 +// children.addAll(xlsxs); +// parentIds = convertSet(xlsxs, WpsXlsxLinkDO::getId); +// } +// return children; +// } +// +// @Override +// @DataPermission(enable = false) // 禁用数据权限,避免建立不正确的缓存 +// @Cacheable(cacheNames = RedisKeyConstants.WPS_XLSX_CHILDREN_ID_LIST, key = "#id") +// public Set getChildXlsxIdListFromCache(Long id) { +// List children = getChildXlsxList(id); +// return convertSet(children, WpsXlsxLinkDO::getId); +// } +// +// @Override +// public void validateXlsxList(Collection ids) { +// if (CollUtil.isEmpty(ids)) { +// return; +// } +// // 获得科室信息 +// Map xlsxMap = getXlsxMap(ids); +// // 校验 +// ids.forEach(id -> { +// WpsXlsxLinkDO xlsx = xlsxMap.get(id); +// if (xlsx == null) { +// throw exception(XLSX_NOT_FOUND); +// } +// if (!CommonStatusEnum.ENABLE.getStatus().equals(xlsx.getStatus())) { +// throw exception(XLSX_NOT_ENABLE, xlsx.getName()); +// } +// }); +// } +// +// @Override +// @TenantIgnore +// public List getXlsxTreeList() { +// return wpsXlsxLinkMapper.selectTreeListByNodeFunction(); +// } +// +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java index a7018884..56cc5d6b 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/service/wps_pptx/JudgementWpsPptxService.java @@ -3,6 +3,7 @@ package pc.exam.pp.module.judgement.service.wps_pptx; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; +import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO; @@ -16,8 +17,10 @@ import java.util.List; public interface JudgementWpsPptxService { List programmingWpsPptx(String path) throws Exception; - +// SourceAndText judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion, String judgementStr) throws Exception; - List getWpsPptxInfo(List pptxInfoPointsVos) throws IOException; +// List getWpsPptxInfo(List pptxInfoPointsVos) throws IOException; + + List judgementWpsPptx(List judgementReq, String path) throws Exception; } 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 09f6c510..cd601788 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 @@ -8,28 +8,17 @@ import pc.exam.pp.module.exam.utils.file.LogFileUtils; 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.Wps.dto.WpsPptxJudgementDto; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxListReqVO; -import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; -import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; -import pc.exam.pp.module.judgement.dal.mysql.wpspptx.WpsPptxLinkMapper; import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; import pc.exam.pp.module.judgement.service.auto_tools.vo.SourceAndText; import pc.exam.pp.module.judgement.utils.HtmlAppender; -import pc.exam.pp.module.judgement.utils.wps_pptx.WpsPptxUtils; +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.vo.PptxInfoPointsVo; import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO; -import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils; -import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO; import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO; import pc.exam.pp.module.system.service.user.AdminUserService; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -47,18 +36,21 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { @Resource ConfigService configService; - @Resource - WpsPptxLinkMapper wpsPptxLinkMapper; - @Resource private AdminUserService userService; +// @Override +// public List getWpsPptxInfo(List pptxInfoPointsVos) throws IOException { +// List judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos); +// return judgementDtos; +// } + @Override - public List getWpsPptxInfo(List pptxInfoPointsVos) throws IOException { - List judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos); - return judgementDtos; + public List judgementWpsPptx(List judgementReq, String path) throws Exception { + return JudgementWpsPPT.getValues(judgementReq, path); } + @Override public List programmingWpsPptx(String path) throws Exception { String pathName = ""; @@ -75,7 +67,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { // } // 4、pptx文件读取并返回考点及说明信息 // List margins = WpsPptxUtils.wpsPptx(pathName, paragraphList); - List pptxInfoList = WpsPptxUtils.wpsPptxInfo(pathName); + List pptxInfoList = JudgementWpsPPT.wpsPptxInfo(pathName); // 5、已经读取完得考点删除源文件 // File file = new File(pathName); // file.delete(); @@ -90,26 +82,24 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { LogFileUtils.writeLine("✅ 开始WPS_Pptx判分"); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 开始WPS_Pptx判分"); double wpsPptScore = 0; - List pptxInfoPointsVos = new ArrayList<>(); + List judgementReq = new ArrayList<>(); // 3、获取答案得组成 List answerList = examQuestion.getAnswerList(); for (ExamQuestionAnswer examQuestionAnswer : answerList) { - PptxInfoPointsVo pptxInfoPointsVo = new PptxInfoPointsVo(); + JudgementReqVo judgementReqVo = new JudgementReqVo(); // 拆分数据、 - String[] pptxInfos = examQuestionAnswer.getContent().split("\\?"); - String[] chineseName = examQuestionAnswer.getContentIn().split("-"); - String[] typeList = examQuestionAnswer.getImage().split("-"); - pptxInfoPointsVo.setName(examQuestionAnswer.getContentIn()); - pptxInfoPointsVo.setEnglishName(pptxInfos[0]); - pptxInfoPointsVo.setFunction(pptxInfos[1]); - pptxInfoPointsVo.setType(typeList[0]); - pptxInfoPointsVo.setBelongTo(typeList[1]); - pptxInfoPointsVo.setIsboo(typeList[2]); - pptxInfoPointsVo.setFilePath(path); - pptxInfoPointsVos.add(pptxInfoPointsVo); + String[] pptxInfos = examQuestionAnswer.getContent().split("@!"); + judgementReqVo.setFileNama(pptxInfos[0]); + judgementReqVo.setParagraph(pptxInfos[1]); + judgementReqVo.setTitle(pptxInfos[2]); + judgementReqVo.setValueList(pptxInfos[3]); + judgementReqVo.setType(pptxInfos[4]); + judgementReqVo.setIsText(pptxInfos[5]); + judgementReqVo.setIsTrue(pptxInfos[6]); + judgementReqVo.setIsParameter(pptxInfos[7]); + judgementReq.add(judgementReqVo); } - List judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos); - + List judgementDtos = JudgementWpsPPT.getValues(judgementReq, path); // 4、进行关联判断 for (ExamQuestionAnswer examQuestionAnswer : answerList) { boolean flag = false; @@ -129,7 +119,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService { } wpsPptScore += one_sorce; if (flag) { - LogFileUtils.writeLine("✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); + LogFileUtils.writeLine("✅" + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ " + examQuestionAnswer.getContentIn() + " 得分成功,得分:" + one_sorce); } else { LogFileUtils.writeLine("❌ " + examQuestionAnswer.getContentIn() + " 得分失败"); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java index 7309cce0..14d3fb46 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/tree/TreeUtils.java @@ -1,6 +1,5 @@ package pc.exam.pp.module.judgement.utils.tree; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO; import pc.exam.pp.module.judgement.dal.dataobject.wpsxlsx.WpsXlsxLinkDO; import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; @@ -56,29 +55,6 @@ public class TreeUtils { } return roots; } - - public static List buildTreePptx(List flatList) { - Map nodeMap = new HashMap<>(); - List roots = new ArrayList<>(); - - // 先放入 map - for (WpsPptxLinkDO node : flatList) { - nodeMap.put(Math.toIntExact(node.getId()), node); - } - - // 构建树关系 - for (WpsPptxLinkDO node : flatList) { - if (node.getParentId() == 0) { - roots.add(node); - } else { - WpsPptxLinkDO parent = nodeMap.get(node.getParentId().intValue()); - if (parent != null) { - parent.getChildren().add(node); - } - } - } - return roots; - } public static List buildTreeXlsx(List flatList) { Map nodeMap = new HashMap<>(); List roots = new ArrayList<>(); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/WpsExcelUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/WpsExcelUtils.java index a1627c1d..3bce7f4e 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/WpsExcelUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/WpsExcelUtils.java @@ -14,6 +14,8 @@ import pc.exam.pp.module.judgement.utils.wps_excel.vo.*; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_chart.ChartTypeEntry; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo; import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxDrawingSheetVo; +import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; +import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; import javax.xml.namespace.QName; import java.io.FileInputStream; @@ -36,6 +38,73 @@ public class WpsExcelUtils { public static int dxfId = 0; + + public static String getStringRandom() { + String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + + // 生成指定长度的随机字符字符串 + for (int i = 0; i < 10; i++) { + int randomIndex = random.nextInt(characters.length()); + // 随机字符 + sb.append(characters.charAt(randomIndex)); + } + return sb.toString(); + } + + public static List wpsExcelInfo(String filePath) throws Exception { + List excelInfoReqVoList = new ArrayList<>(); + try (FileInputStream fis = new FileInputStream(filePath); + OPCPackage pkg = OPCPackage.open(fis); + XSSFWorkbook workbook = new XSSFWorkbook(pkg)) { + // 获取有多少个工作表 + int sheetNumber = workbook.getNumberOfSheets(); + String firstIdSheet = getStringRandom(); + for (int i = 0; i < sheetNumber; i++) { + String secondIdSheet = getStringRandom(); + // 获取工作表内容 + XSSFSheet sheetXss = workbook.getSheetAt(i); + // 获取工作表的XML对象 + XmlObject worksheetXml = sheetXss.getCTWorksheet(); + setWordInfo("Sheet" + sheetNumber + 1, "Sheet" + sheetNumber + 1, "sheet" + sheetNumber + 1 + ".xml", filePath, secondIdSheet, firstIdSheet, excelInfoReqVoList); + + // 开始查找指定得 单元格、范围、行、列、数据排序、数据透视表、表格、图标、页面、试图、属性 + String thirdIdC = getStringRandom(); + setWordInfo("单元格", "c", "c", filePath, thirdIdC, secondIdSheet, excelInfoReqVoList); + String thirdIdCC = getStringRandom(); + setWordInfo("范围", "cc", "cc", filePath, thirdIdCC, secondIdSheet, excelInfoReqVoList); + String thirdIdRow = getStringRandom(); + setWordInfo("行", "row", "row", filePath, thirdIdRow, secondIdSheet, excelInfoReqVoList); + String thirdIdCol = getStringRandom(); + setWordInfo("列", "cols", "cols", filePath, thirdIdCol, secondIdSheet, excelInfoReqVoList); +// String thirdIdCol = getStringRandom(); + // 判断是否存在图表 + setWordInfo("列", "cols", "cols", filePath, thirdIdCol, secondIdSheet, excelInfoReqVoList); + + System.out.println(worksheetXml.xmlText()); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidFormatException e) { + throw new RuntimeException(e); + } + + + return excelInfoReqVoList; + } + public static void setWordInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List excelInfoReqVos) throws Exception { + ExcelInfoReqVo excelInfos = new ExcelInfoReqVo(); + excelInfos.setName(chineseName); + excelInfos.setEnglishName(englishName); + excelInfos.setFilePath(filePath); + excelInfos.setId(id); + excelInfos.setSelectName(selectName); + excelInfos.setParentId(parentId); + excelInfoReqVos.add(excelInfos); + } + + public static List wpsExcel(String filePath) throws Exception { // 获取共享字符串 String[] sharedStrings = extractSharedStrings(filePath); diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/vo/ExcelInfoReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/vo/ExcelInfoReqVo.java new file mode 100644 index 00000000..0e4e70a6 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_excel/vo/ExcelInfoReqVo.java @@ -0,0 +1,28 @@ +package pc.exam.pp.module.judgement.utils.wps_excel.vo; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author REN + */ +@Data +public class ExcelInfoReqVo { + + private String name; + + private String englishName; + + private String filePath; + + private String parentId; + + private String selectName; + + private String id; + + private List children = new ArrayList<>(); + +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/DeclareNamespaceForPPT.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/DeclareNamespaceForPPT.java new file mode 100644 index 00000000..bac8a952 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/DeclareNamespaceForPPT.java @@ -0,0 +1,40 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx; + +/** + * @author REN + */ +public class DeclareNamespaceForPPT { + public static String getNameSpace(String titleName) { + if ("p".equals(titleName)) { + return "http://schemas.openxmlformats.org/presentationml/2006/main"; + } + if ("a".equals(titleName)) { + return "http://schemas.openxmlformats.org/drawingml/2006/main"; + } + if ("pic".equals(titleName)) { + return "http://schemas.openxmlformats.org/drawingml/2006/picture"; + } + if ("c".equals(titleName)) { + return "http://schemas.openxmlformats.org/drawingml/2006/chart"; + } + if ("dgm".equals(titleName)) { + return "http://schemas.openxmlformats.org/drawingml/2006/diagram"; + } + if ("lc".equals(titleName)) { + return "http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"; + } + if ("v".equals(titleName)) { + return "urn:schemas-microsoft-com:vml"; + } + if ("m".equals(titleName)) { + return "http://schemas.openxmlformats.org/officeDocument/2006/math"; + } + if ("mc".equals(titleName)) { + return "http://schemas.openxmlformats.org/markup-compatibility/2006"; + } + if ("a14".equals(titleName)) { + return "http://schemas.microsoft.com/office/drawing/2010/main"; + } + return ""; + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementConvert.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementConvert.java new file mode 100644 index 00000000..4f640926 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementConvert.java @@ -0,0 +1,161 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx; + + +import java.util.List; + +/** + * @author REN + */ +public class JudgementConvert { + public static String getConvert(List valueList, String formula){ + String value = ""; + if ("NULL".equals(formula)) { + value = valueList.get(0); + } else if (formula.contains("PageSize")) { + value = pageSize(valueList.get(0), valueList.get(1)); + } else if (formula.contains("timing")) { + // 查询自定义动画效果 + value = getTiming(valueList.get(0), valueList.get(1)); + } else if (formula.contains("Timing_filter")) { + // 动画方向查询 + value = getTimingFilter(valueList.get(0)); + } else if (formula.contains("Timing_Evt")) { + // 动画触发方式 + value = getTimingEvt(valueList.get(0)); + } + // 继续转换 + return value; + } + + private static String getTimingEvt(String evt) { + String evtValue = ""; + if (evt.contains("onBegin")) { + if (evt.contains("downRight")) { + evtValue += "自动开始"; + } + if (evt.contains("onClick")) { + evtValue += "鼠标点击时开始"; + } + if (evt.contains("afterPrevious")) { + evtValue += "在上一个动画之后开始"; + } + if (evt.contains("withPrevious")) { + evtValue += "与上一个动画同时开始"; + } + if (evt.contains("onEnd")) { + evtValue += "在另一个动画结束时开始"; + } + if (evt.contains("onNext")) { + evtValue += "在下一动画前触发"; + } + if (evt.contains("onPrev")) { + evtValue += "在上一动画前触发"; + } + } + return evtValue; + } + + private static String getTimingFilter(String filter) { + String filterValue = ""; + if (filter.contains("strips")) { + if (filter.contains("downRight")) { + filterValue += "从左上往右下飞入"; + } + if (filter.contains("upLeft")) { + filterValue += "从右下往左上飞入"; + } + if (filter.contains("upRight")) { + filterValue += "从左下往右上飞入"; + } + if (filter.contains("downLeft")) { + filterValue += "从右上往左下飞入"; + } + } + return filterValue; + } + private static String getTiming(String transition, String filter){ + String transitionValue = ""; + String filterValue = ""; + if ("in".equals(transition)) { + transitionValue = "进入动画"; + if ("fade".equals(filter)) { + filterValue = "淡入淡出"; + } else if ("fly(fromLeft)".equals(filter)) { + filterValue = "飞入(从左)"; + } else if ("fly(fromRight)".equals(filter)) { + filterValue = "飞入(从右)"; + } else if ("fly(fromTop)".equals(filter)) { + filterValue = "飞入(从上)"; + } else if ("fly(fromBottom)".equals(filter)) { + filterValue = "飞入(从下)"; + } else if ("strips(downRight)".equals(filter)) { + filterValue = "条纹(右下)"; + } else if ("strips(upLeft)".equals(filter)) { + filterValue = "条纹(左上)"; + } else if ("checkerboard(across)".equals(filter)) { + filterValue = "棋盘格(横向)"; + } else if ("wipe(right)".equals(filter)) { + filterValue = "擦除(从左向右)"; + } else if ("wipe(left)".equals(filter)) { + filterValue = "擦除(从右向左)"; + } else if ("randomBars(vertical)".equals(filter)) { + filterValue = "随机条形(垂直)"; + } else if ("zoom".equals(filter)) { + filterValue = "缩放"; + } else if ("circle(out)".equals(filter)) { + filterValue = "圆形展开"; + } else if ("plus(out)".equals(filter)) { + filterValue = "十字形展开"; + } else if ("diamond(out)".equals(filter)) { + filterValue = "菱形展开"; + } else if ("shape(circle)".equals(filter)) { + filterValue = "使用形状(圆形)"; + } + } else if ("out".equals(transition)) { + transitionValue = "退出动画"; + if ("fade".equals(filter)) { + filterValue = "淡出"; + } else if ("fly(toLeft)".equals(filter)) { + filterValue = "飞出(向左)"; + } else if ("fly(toRight)".equals(filter)) { + filterValue = "飞出(向右)"; + } else if ("strips(upLeft)".equals(filter)) { + filterValue = "条纹(左上)"; + } else if ("wipe(left)".equals(filter)) { + filterValue = "擦除(向左)"; + } else if ("zoom".equals(filter)) { + filterValue = "缩小"; + } else if ("shape(diamond)".equals(filter)) { + filterValue = "菱形消失"; + } + } else if ("emph".equals(transition)) { + transitionValue = "强调动画"; + } else if ("path".equals(transition)) { + transitionValue = "动作路径动画"; + } + return transitionValue + filterValue; + } + private static String pageSize(String widthTwip, String heightTwip){ + // 转换为 cm:1 twip = 1/1440 英寸 = 2.54 / 1440 cm + double widthCm = Double.parseDouble(widthTwip) / 360000; + double heightCm = Double.parseDouble(heightTwip) / 360000; + + // 四舍五入保留一位小数 + widthCm = Math.round(widthCm * 10) / 10.0; + heightCm = Math.round(heightCm * 10) / 10.0; + + // 判断标准纸型(以 cm 为单位进行匹配) + String paperType = "自定义"; + if (approx(widthCm, 21.0) && approx(heightCm, 29.7)) { + paperType = "A4"; + } else if (approx(widthCm, 29.7) && approx(heightCm, 42.0)) { + paperType = "A3"; + } else if (approx(widthCm, 14.8) && approx(heightCm, 21.0)) { + paperType = "A5"; + } + return paperType; + } + private static boolean approx(double a, double b) { + return Math.abs(a - b) < 0.5; // 误差范围 0.5cm 内 + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementWpsPPT.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementWpsPPT.java new file mode 100644 index 00000000..105011f4 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementWpsPPT.java @@ -0,0 +1,406 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx; + +import org.apache.commons.io.IOUtils; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackagePart; +import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.apache.poi.xslf.usermodel.XSLFSlide; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; +import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; +import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; +import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxSlidesVo; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; + +/** + * @author REN + */ +public class JudgementWpsPPT { + public static List getValues(List judgementReq, String path) throws InvalidFormatException, IOException, ParserConfigurationException, SAXException { + // 1、文件路径或者文件的属性 + // 2、查找文件的属性其中字段为:name firstFunction SecondFunction ThirdFunction FourthFunction isboo betong 转换 + // 3、名称 标签 标签段落 值标签 关联关系 关联文件名称 ) + // 4、逻辑关系 : 通过name查询文档数据,根据标签段落查询对应的段落值,再根据标签地址查询对应,在查询对应的值标签(外部文件暂定) +// String fileNama = "presentation"; +// String functions = "(//p:presentation)[1]"; +// String slide = "p:sldSz"; +// String values = "cx#cy"; + // 创建返回值 + List judgementList = new ArrayList<>(); + + for (JudgementReqVo reqVo : judgementReq) { + String chineseName = reqVo.getChineseName(); + String fileNama = reqVo.getFileNama(); + String paragraph = reqVo.getParagraph(); + String title = reqVo.getTitle(); + String values = reqVo.getValueList(); + String type = reqVo.getType(); + String isText = reqVo.getIsText(); + String isTrue = reqVo.getIsTrue(); + String isParameter = reqVo.getIsParameter(); + + String firstName = paragraph.split(":")[0].split("/")[paragraph.split(":")[0].split("/").length -1]; + // 组合之后可能用到的考点信息 + String englishName = fileNama + "@!" + paragraph + "@!" + title + "@!" + values + "@!" + type + "@!" + isText + "@!" + isTrue + "@!" + isParameter; + XmlCursor cursor = getXmlCursor(path, fileNama, null); + System.out.println(cursor.xmlText()); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder builder = factory.newDocumentBuilder(); + XmlCursor slideCursor = cursor; + if (title.contains(">")) { + // 说明想要 + title = title.replace(">", ""); + judgementList = setData(judgementList, chineseName + "正在开发中", englishName + "正在开发中"); + + } else + // 当标签存在特定值得时候,不需要继续第一段得查询,直接用所有得进行查找 + if (title.contains("?")) { + title = title.replace("?", ""); + // 条件成立 + // 获取 XML 字符串 + String xmlText = slideCursor.getObject().xmlText(); + InputStream is = new ByteArrayInputStream(xmlText.getBytes(StandardCharsets.UTF_8)); + // 然后再用 builder.parse + Document doc = builder.parse(is); + System.out.println(xmlText); + // 通过递归调用 查询标签位置,可能出现得层级关系,避免出现一层不对得情况查询多个标签地址 + Element element = XmlRecursiveFinder.findElement(doc, title); + List valuesList = new ArrayList<>(); + if ("1".equals(isTrue)) { + String value = element == null ? "否" : "是" ; + judgementList = setData(judgementList, chineseName + value, englishName + value); + } else { + String[] valuesArr = values.split("#"); + String oneValue = ""; + for (String yivalue : valuesArr) { + if ("0".equals(isText)) { + oneValue = element.getAttribute(yivalue); + } else { + oneValue = element.getTextContent(); + } + valuesList.add(oneValue); + } + // 开始进行考点等的判断 + String pointValue = JudgementConvert.getConvert(valuesList, type); + if ("1".equals(isTrue)) { + pointValue = pointValue != null ? "是" : "否"; + } + judgementList = setData(judgementList, chineseName + pointValue, englishName + pointValue); + } + } else { + if (!paragraph.isEmpty()) { + slideCursor.selectPath("declare namespace " + firstName + "='" + DeclareNamespaceForPPT.getNameSpace(firstName) + "' " + paragraph); + } + // 当查询到或者说不需要查询的时候进入 + if (slideCursor.toNextSelection() || paragraph.isEmpty()) { + // 获取 XML 字符串 + String xmlText = slideCursor.getObject().xmlText(); + InputStream is = new ByteArrayInputStream(xmlText.getBytes(StandardCharsets.UTF_8)); + // 然后再用 builder.parse + Document doc = builder.parse(is); + if ("Filling_Method".equals(type)) { + // 说明判断填充方式 + String value = getFillingMethod(doc, slideCursor, title); + judgementList = setData(judgementList, chineseName + value, englishName + value); + } else if ("Filling_Bg".equals(type)) { + // 说明判断背景填充方式 + String value = getFillingBg(doc, slideCursor, title); + judgementList = setData(judgementList, chineseName + value, englishName + value); + } else if ("Line_Spacing".equals(type)) { + // 行距类型 + String value = getLineSpacing(doc, slideCursor, title); + judgementList = setData(judgementList, chineseName + value, englishName + value); + } + else { + // 通过递归调用 查询标签位置,可能出现得层级关系,避免出现一层不对得情况查询多个标签地址 + Element element = XmlRecursiveFinder.findElement(doc, title); + List valuesList = new ArrayList<>(); + if ("1".equals(isTrue)) { + String value = element == null ? "否" : "是" ; + judgementList = setData(judgementList, chineseName + value, englishName + value); + } else { + String[] valuesArr = values.split("#"); + String oneValue = ""; + for (String yivalue : valuesArr) { + if ("0".equals(isText)) { + oneValue = element.getAttribute(yivalue); + } else { + oneValue = element.getTextContent(); + } + valuesList.add(oneValue); + } + // 开始进行考点等的判断 + String pointValue = JudgementConvert.getConvert(valuesList, type); + if ("1".equals(isTrue)) { + pointValue = pointValue != null ? "是" : "否"; + } + judgementList = setData(judgementList, chineseName + pointValue, englishName + pointValue); + } + } + } else { + // 如果存在备选方案,使用备选的参数 + // 先过去RID的对应的值所有方法中带有了#区分第一段是获取值,第二段是获取外文件的参数 + + } + } + + } + return judgementList; + } + // 大纲 + // 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他 + // 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作 + // 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作 + public static List wpsPptxInfo(String filePath) throws FileNotFoundException { + List pptxInfoReqVos = new ArrayList<>(); + try (FileInputStream fis = new FileInputStream(filePath); + XMLSlideShow pptxXml = new XMLSlideShow(fis)) { + int index = 0; + String firstId = getStringRandom(); + setPptxInfo("幻灯片", "p:sld", "p:sld", filePath, firstId, "0", "", pptxInfoReqVos); + for (XSLFSlide slides : pptxXml.getSlides()){ + index += 1; + String secondId = getStringRandom(); + setPptxInfo("第"+index+"页", "slide"+index, "slide"+index, filePath, secondId, firstId, "", pptxInfoReqVos); + // 第三层 + String thirdId = getStringRandom(); + int indexCnvPr = 1; + setPptxInfo("幻灯片设置", "slide"+index, "(//p:bg)["+indexCnvPr+"]", filePath, thirdId, secondId, + "slide@setting", pptxInfoReqVos); + XmlCursor spCursor = slides.getXmlObject().newCursor(); + spCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:sp"); + while (spCursor.toNextSelection()) { + XmlCursor cNvPrXml = spCursor.newCursor(); + cNvPrXml.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:cNvPr/@name"); + if (cNvPrXml.toNextSelection()) { + String name = cNvPrXml.getTextValue(); + String fourId = getStringRandom(); + setPptxInfo("形状"+indexCnvPr+"->"+name, + "slide"+index, + "(//p:sp)["+indexCnvPr+"]", + filePath, + fourId, + secondId, + "p:sp@p:pic", pptxInfoReqVos); + indexCnvPr += 1; + } + } + XmlCursor picCursor = slides.getXmlObject().newCursor(); + System.out.println(picCursor.xmlText()); + picCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:pic"); + int indexCnvPrPic = 1; + while (picCursor.toNextSelection()) { + String fourId = getStringRandom(); + setPptxInfo("图像"+indexCnvPrPic+"->图像", "slide"+index, "(//p:pic)["+indexCnvPrPic+"]", filePath, fourId, secondId, + "p:sp@p:pic", pptxInfoReqVos); + indexCnvPrPic += 1; + } + } + // 设置 + String firstIds = getStringRandom(); + setPptxInfo("设置", "p:presentation", "p:presentation", filePath, firstIds, "0", + "p:sp@p:pic", pptxInfoReqVos); + String secondIds = getStringRandom(); + setPptxInfo("幻灯片设置", "p:presentation", "p:presentation", filePath, secondIds, firstIds, + "p:sp@p:pic", pptxInfoReqVos); + + // 母版 +// String dFirstId = getStringRandom(); +// setPptxInfo("母版", "p:sld", "p:sld", filePath, dFirstId, "0", pptxInfoReqVos); + } catch (Exception e) { + throw new RuntimeException(e); + } + return pptxInfoReqVos; + } + + public static String getFillingMethod(Document doc, XmlCursor cursor, String titleName) { + String value = ""; + for (String title : titleName.split("#")) { + // 获取填充方法 + NodeList nodeList = doc.getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(title.split(":")[0]), title.split(":")[1]); + if (nodeList.getLength() > 0) { + if (title.equals("a:solidFill")) { + value = "纯色填充"; + } + } + } + return value; + } + public static String getLineSpacing(Document doc, XmlCursor cursor, String titleName) { + String value = ""; + for (String title : titleName.split("#")) { + // 获取填充方法 + NodeList nodeList = doc.getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(title.split(":")[0]), title.split(":")[1]); + if (nodeList.getLength() > 0) { + if (title.equals("a:spcPts")) { + value = "固定行距"; + } + if (title.equals("a:spcPct")) { + value = "多倍行距"; + } + } + } + return value; + } + public static String getProjectSymbols(Document doc, XmlCursor cursor, String titleName) { + String value = ""; + for (String title : titleName.split("#")) { + // 获取填充方法 + NodeList nodeList = doc.getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(title.split(":")[0]), title.split(":")[1]); + if (nodeList.getLength() > 0) { + if (title.equals("a:buChar")) { + value = "普通圆点"; + } + if (title.equals("a:buBlip")) { + value = "图片项目符号"; + } + if (title.equals("a:buAutoNum")) { + value = "自动编号"; + } + } + } + return value; + } + public static String getFillingBg(Document doc, XmlCursor cursor, String titleName) { + String value = ""; + for (String title : titleName.split("#")) { + // 获取填充方法 + NodeList nodeList = doc.getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(title.split(":")[0]), title.split(":")[1]); + if (nodeList.getLength() > 0) { + if (title.equals("a:solidFill")) { + value = "纯色填充"; + } + if (title.equals("a:gradFill")) { + value = "渐变填充"; + } + if (title.equals("a:blipFill")) { + value = "图片填充"; + } + if (title.equals("a:pattFill")) { + value = "图案填充"; + } + if (title.equals("a:grpFill")) { + value = "分组填充"; + } + } + } + return value; + } + + + public static XmlCursor getXmlCursor(String path, String titleName, String value) throws IOException, InvalidFormatException { + XmlCursor cursor = null; + try (OPCPackage pkg = OPCPackage.open(path)) { + for (PackagePart part : pkg.getParts()) { + String entryName = part.getPartName().getName(); + if (value == null) { + // 如果说明是空的话,直接查询文件名称 + if (entryName.contains(titleName) && entryName.contains(".xml") && !entryName.contains(".rels")) { + try (InputStream is = part.getInputStream()) { + String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); + XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); + cursor = xmlObject.newCursor(); + break; + } catch (XmlException e) { + throw new RuntimeException(e); + } + } + } else { + // 想查询外置文件 + if (entryName.contains(titleName) && entryName.contains(".xml") && entryName.contains(".rels")) { + try (InputStream is = part.getInputStream()) { + String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); + XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); + xmlObject.newCursor().selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); + if (xmlObject.newCursor().toNextSelection()) { + String id = xmlObject.newCursor().getAttributeText(new QName("Id")); + if (id.equals(value)) { + String target = xmlObject.newCursor().getAttributeText(new QName("Target")); + getXmlCursor(path, target.split("/")[target.split("/").length-1], null); + } + } + } catch (XmlException e) { + throw new RuntimeException(e); + } + + } + } + } + } + return cursor; + } + + /** + * 生成随机码 + * @return 随机码 + */ + public static String getStringRandom() { + String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + + // 生成指定长度的随机字符字符串 + for (int i = 0; i < 10; i++) { + int randomIndex = random.nextInt(characters.length()); + // 随机字符 + sb.append(characters.charAt(randomIndex)); + } + return sb.toString(); + } + + /** + * + * @param chineseName + * @param englishName + * @param selectName + * @param filePath + * @param id + * @param parentId + * @param pptxInfoReqVos + * @throws Exception + */ + public static void setPptxInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, String title, List pptxInfoReqVos) throws Exception { + PptxInfoReqVo pptxInfos = new PptxInfoReqVo(); + pptxInfos.setName(chineseName); + pptxInfos.setEnglishName(englishName); + pptxInfos.setFilePath(filePath); + pptxInfos.setId(id); + pptxInfos.setSelectName(selectName); + pptxInfos.setParentId(parentId); + pptxInfos.setTitle(title); + pptxInfoReqVos.add(pptxInfos); + } + + /** + * 向考点对象存放数据 + * @param wpsPptxJudgementDtoList 考点对象数组 + * @param chineseName 给考点对象添加的中文描述 + * @param englishName 给考点对象添加的英文描述 + * @return 考点对象数组 + */ + private static List setData(List wpsPptxJudgementDtoList, + String chineseName, + String englishName) { + WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); + judgementDto.setContentIn(chineseName); + judgementDto.setContent(englishName); + judgementDto.setScoreRate("1"); + wpsPptxJudgementDtoList.add(judgementDto); + return wpsPptxJudgementDtoList; + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java index a6e8db4b..fa5a7d54 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java @@ -1,808 +1,808 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx; - -import org.apache.commons.io.IOUtils; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.openxml4j.opc.PackagePart; -import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.apache.poi.xslf.usermodel.XSLFSlide; -import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlException; -import org.apache.xmlbeans.XmlObject; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; -import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; -import pc.exam.pp.module.judgement.utils.TwipConverter; -import pc.exam.pp.module.judgement.utils.tree.TreeUtils; -import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxCharVO; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.*; -import pc.exam.pp.module.judgement.utils.wps_word.ColorNameFinder; -import pc.exam.pp.module.judgement.utils.wps_word.PageSizeDetector; -import pc.exam.pp.module.judgement.utils.wps_word.ShadowDirectionUtils; -import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; -import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils; - -import javax.xml.namespace.QName; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -/** - * @author REN - */ -public class WpsPptxUtils { - - public static ListgetWpsPptxInfos(List pptxInfoPointsVos) throws IOException { - List judgementList = new ArrayList<>(); - String filePath = pptxInfoPointsVos.get(0).getFilePath(); - List pptxSlidesVos = new ArrayList<>(); - List pptxSlidesOrgVos = new ArrayList<>(); - // 获取所有相关res得记录 - List> slideList = new ArrayList<>(); - try (OPCPackage pkg = OPCPackage.open(filePath)) { - for (PackagePart part : pkg.getParts()) { - String entryName = part.getPartName().getName(); - if (entryName.contains("ppt/slides/_rels") && entryName.contains(".xml.rels")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - PptxSlidesVo pptxSlidesVo = new PptxSlidesVo(); - String[] names = entryName.split("/"); - pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); - // 存放数据 - while (cursor.toNextSelection()) { - Map map = new HashMap<>(); - String rId = cursor.getAttributeText(new QName("Id")); - String target = cursor.getAttributeText(new QName("Target")); - map.put(rId, target); - slideList.add(map); - } - pptxSlidesVo.setSlideResList(slideList); - pptxSlidesOrgVos.add(pptxSlidesVo); - } - } - if (entryName.contains("ppt/slides") && entryName.contains(".xml") && !entryName.contains(".rels")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - String[] names = entryName.split("/"); - Optional result = pptxSlidesOrgVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(names[entryName.split("/").length-1])).findFirst(); - PptxSlidesVo pptxSlidesVo = result.get(); - pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - pptxSlidesVo.setXmlCursor(cursor); - pptxSlidesVos.add(pptxSlidesVo); - } - - } - } - for (PptxInfoPointsVo pptxInfoPointsVo : pptxInfoPointsVos) { - // 判断幻灯片形状 - if ("0".equals(pptxInfoPointsVo.getBelongTo())) { - Optional result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst(); - PptxSlidesVo pptxSlidesVo = result.get(); - XmlCursor slideCursor = pptxSlidesVo.getXmlCursor(); - String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText()); - if (pptxInfoPointsVo.getName().contains("动画")) { - String[] functions = pptxInfoPointsVo.getFunction().split("#"); - String functionStr = functions[0]; - if (pptxInfoPointsVo.getFunction().contains("pic")) { - functionStr = functionStr.replace("nvSpPr", "nvPicPr"); - } - XmlCursor dongCursor = slideCursor; - XmlCursor cTnCursor = slideCursor; - dongCursor.selectPath(namespace + functionStr); - if (dongCursor.toNextSelection()) { - String number = dongCursor.getTextValue(); - cTnCursor.selectPath(namespace + "//p:cTn[@id='"+number+"']"); - if (cTnCursor.toNextSelection()) { - System.out.println(cTnCursor.xmlText()); - if (pptxInfoPointsVo.getName().contains("效果")) { - if (pptxInfoPointsVo.getFunction().contains("pic")) { - String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "效果"); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - cTnCursor.selectPath(namespace + "//p:animEffect"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String transition = cTnCursor.getAttributeText(new QName("transition")); - String filter = cTnCursor.getAttributeText(new QName("filter")); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - if (transition.contains("in")) { - value += "进入效果"; - } - if (filter.contains("strips")) { - value += "->阶梯状"; - } - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - if (pptxInfoPointsVo.getName().contains("方向")) { - cTnCursor.selectPath(namespace + "//p:animEffect"); - if (pptxInfoPointsVo.getFunction().contains("pic")) { - String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "方向"); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - if (cTnCursor.toNextSelection()) { - String value = ""; - String filter = cTnCursor.getAttributeText(new QName("filter")); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - if (filter.contains("downRight")) { - value += "右下"; - } - if (filter.contains("plus(out)")) { - value += "十字形扩展"; - } - if (filter.contains("plus(in)")) { - value += "十字形聚合"; - } - if (filter.contains("blinds(vertical)")) { - value += "百叶窗 - 垂直"; - } - if (filter.contains("blinds(horizontal)")) { - value += "百叶窗 - 水平"; - } - if (filter.contains("circle(in)")) { - value += "圆形聚焦进入"; - } - if (filter.contains("circle(out)")) { - value += "圆形扩散"; - } - if (filter.contains("diamond(out)")) { - value += "菱形扩散"; - } - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - if (pptxInfoPointsVo.getName().contains("触发方式")) { - if (pptxInfoPointsVo.getFunction().contains("pic")) { - String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "触发方式"); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - - } - } - if (pptxInfoPointsVo.getName().contains("持续时间")) { - if (pptxInfoPointsVo.getFunction().contains("pic")) { - String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "持续时间"); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - cTnCursor.selectPath(namespace + "//p:animEffect/p:cBhvr/p:cTn"); - if (cTnCursor.toNextSelection()) { - String value = ""; - String dur = cTnCursor.getAttributeText(new QName("dur")); - if (dur == null) { - value = "0秒"; - } else { - value = String.valueOf((double) Integer.parseInt(dur) / 1000); - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - } - } - } else if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { - // 查询 - XmlCursor otherSlideCurors = slideCursor.newCursor(); - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - // 判断填充方式的 - if (slideCursor.toNextSelection()) { - String value = slideCursor.xmlText(); - value = getValueType(pptxInfoPointsVo, value); - if (value.contains("未知填充")) { - otherSlideCurors.selectPath(namespace + pptxInfoPointsVo.getFunction().split("]")[0] + "]/p:txBody"); - if (otherSlideCurors.toNextSelection()) { - value = otherSlideCurors.xmlText(); - value = getValueType(pptxInfoPointsVo, value); - } - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } else if (pptxInfoPointsVo.getName().contains("形状效果") && pptxInfoPointsVo.getName().contains("预设")) { - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - if (slideCursor.toNextSelection()) { - String value = slideCursor.xmlText(); - value = ReflectionAnalyzer.analyzeReflection(value); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } else if (pptxInfoPointsVo.getName().contains("纯色填充-颜色")) { - String[] functionList = pptxInfoPointsVo.getFunction().split("#"); - slideCursor.selectPath(namespace + functionList[0]); - String english = functionList[0].split("]")[0] + "]"; - if (slideCursor.toNextSelection()) { - String value = slideCursor.getTextValue(); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - slideCursor.selectPath(namespace + english + functionList[1]); - if (slideCursor.toNextSelection()) { - String value = slideCursor.getTextValue(); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } else if (pptxInfoPointsVo.getName().contains("锁定横纵比")) { - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - String value = ""; - if (slideCursor.toNextSelection()) { - System.out.println(slideCursor.xmlText()); - String values = slideCursor.getTextValue(); - value = values.equals("1") ? "是" : "否"; - } else { - // 没有查询到说明没有 - value = "否"; - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else if (pptxInfoPointsVo.getName().contains("短划线类型")){ - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - if (slideCursor.toNextSelection()) { - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + slideCursor.getTextValue()); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ slideCursor.getTextValue()); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - // 如果没有查询到说明使用了默认值 - String value = "实线"; - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } else { - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - if (slideCursor.toNextSelection()) { - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - // 判断是值还是类型 - if ("1".equals(pptxInfoPointsVo.getIsboo())) { - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + "是"); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + "true"); - } else { - String value = slideCursor.getTextValue(); - value = getValueType(pptxInfoPointsVo, value); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + value); - - } - judgementDto.setImage(pptxInfoPointsVo.getType() + "-" + pptxInfoPointsVo.getBelongTo() + "-" + pptxInfoPointsVo.getIsboo() + "-" + pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } else { - if ("1".equals(pptxInfoPointsVo.getIsboo())) { - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + "否"); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + "false"); - judgementDto.setImage(pptxInfoPointsVo.getType() + "-" + pptxInfoPointsVo.getBelongTo() + "-" + pptxInfoPointsVo.getIsboo() + "-" + pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - } - // 单个幻灯片设置 - if ("1".equals(pptxInfoPointsVo.getBelongTo())) { - Optional result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst(); - PptxSlidesVo pptxSlidesVo = result.get(); - XmlCursor slideCursor = pptxSlidesVo.getXmlCursor(); - String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText()); - // 查询 - if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { - // 判断填充方式的 - slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); - if (slideCursor.toNextSelection()) { - String value = slideCursor.xmlText(); - value = getValueType(pptxInfoPointsVo, value); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } else if (pptxInfoPointsVo.getName().contains("幻灯片切换")){ - if (pptxInfoPointsVo.getName().contains("切换效果")) { - slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); - if (slideCursor.toNextSelection()) { - String value = slideCursor.xmlText(); - if (value.contains("p:fade")) { - value = "淡入淡出"; - } else if (value.contains("p:push")) { - value = "推入"; - } else if (value.contains("p:wipe")) { - value = " 擦除"; - } else if (value.contains("p:split")) { - value = "分割"; - }else if (value.contains("p:cut")) { - value = "瞬间切换(无动画)"; - } else if (value.contains("p:random")) { - value = " 随机一种切换效果"; - } else if (value.contains("p:pull")) { - value = "拉出"; - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - if (pptxInfoPointsVo.getName().contains("切换声音")) { - slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); - if (slideCursor.toNextSelection()) { - String value = slideCursor.getTextValue(); - if (value.contains("wind.wav")) { - value = "风声"; - } else if (value.contains("water.wav")) { - value = "水声"; - } else if (value.contains("fire.wav")) { - value = "火声"; - } else if (value.contains("thunder.wav")) { - value = "雷声"; - } else if (value.contains("applause.wav")) { - value = "掌声"; - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } -// if (pptxInfoPointsVo.getName().contains("单机鼠标换片")) { +//package pc.exam.pp.module.judgement.utils.wps_pptx; // +//import org.apache.commons.io.IOUtils; +//import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +//import org.apache.poi.openxml4j.opc.OPCPackage; +//import org.apache.poi.openxml4j.opc.PackagePart; +//import org.apache.poi.xslf.usermodel.XMLSlideShow; +//import org.apache.poi.xslf.usermodel.XSLFSlide; +//import org.apache.poi.xwpf.usermodel.XWPFDocument; +//import org.apache.xmlbeans.XmlCursor; +//import org.apache.xmlbeans.XmlException; +//import org.apache.xmlbeans.XmlObject; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto; +//import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO; +//import pc.exam.pp.module.judgement.utils.TwipConverter; +//import pc.exam.pp.module.judgement.utils.tree.TreeUtils; +//import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxCharVO; +//import pc.exam.pp.module.judgement.utils.wps_pptx.vo.*; +//import pc.exam.pp.module.judgement.utils.wps_word.ColorNameFinder; +//import pc.exam.pp.module.judgement.utils.wps_word.PageSizeDetector; +//import pc.exam.pp.module.judgement.utils.wps_word.ShadowDirectionUtils; +//import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo; +//import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils; +// +//import javax.xml.namespace.QName; +//import java.io.FileInputStream; +//import java.io.FileNotFoundException; +//import java.io.IOException; +//import java.io.InputStream; +//import java.nio.charset.StandardCharsets; +//import java.util.*; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +//import java.util.zip.ZipEntry; +//import java.util.zip.ZipFile; +// +///** +// * @author REN +// */ +//public class WpsPptxUtils { +// +// public static ListgetWpsPptxInfos(List pptxInfoPointsVos) throws IOException { +// List judgementList = new ArrayList<>(); +// String filePath = pptxInfoPointsVos.get(0).getFilePath(); +// List pptxSlidesVos = new ArrayList<>(); +// List pptxSlidesOrgVos = new ArrayList<>(); +// // 获取所有相关res得记录 +// List> slideList = new ArrayList<>(); +// try (OPCPackage pkg = OPCPackage.open(filePath)) { +// for (PackagePart part : pkg.getParts()) { +// String entryName = part.getPartName().getName(); +// if (entryName.contains("ppt/slides/_rels") && entryName.contains(".xml.rels")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// PptxSlidesVo pptxSlidesVo = new PptxSlidesVo(); +// String[] names = entryName.split("/"); +// pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +// // 存放数据 +// while (cursor.toNextSelection()) { +// Map map = new HashMap<>(); +// String rId = cursor.getAttributeText(new QName("Id")); +// String target = cursor.getAttributeText(new QName("Target")); +// map.put(rId, target); +// slideList.add(map); // } - if (pptxInfoPointsVo.getName().contains("换片间隔时间")){ - slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); - if (slideCursor.toNextSelection()) { - String value = slideCursor.getTextValue(); - int values = Integer.parseInt(value) / 1000; - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + values); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ values); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - } - // 幻灯片设置 - if ("2".equals(pptxInfoPointsVo.getBelongTo())) { - XmlCursor presentationcursor = null; - String namespace = ""; - for (PackagePart part : pkg.getParts()) { - String entryName = part.getPartName().getName(); - if (entryName.contains("ppt/presentation") && entryName.contains(".xml")) { - try (InputStream is = part.getInputStream()) { - String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - presentationcursor = xmlObject.newCursor(); - namespace = WpsPptxNameSpaces.getNameSpace(presentationcursor.xmlText()); - } - } - } - if ("1".equals(pptxInfoPointsVo.getType())) { - // 如果是外参数 - if (pptxInfoPointsVo.getName().contains("幻灯片大小")) { - presentationcursor.selectPath(namespace + "//p:presentation/p:sldSz"); - if (presentationcursor.toNextSelection()) { - String value = PageSizeDetector.detectPaperPPTSize(presentationcursor.xmlText()); - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - if (pptxInfoPointsVo.getName().contains("放映类型")) { - presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); - if (presentationcursor.toNextSelection()) { - System.out.println("放映类型" + presentationcursor.xmlText()); - } else { - // 如果没有标签的话说明是默认的ppt方式 - String value = "演示者放映(全屏)"; - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() +value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - if (pptxInfoPointsVo.getName().contains("放映范围")) { - presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); - if (presentationcursor.toNextSelection()) { - System.out.println("放映范围" + presentationcursor.xmlText()); - } else { - // 说明全页面放映,查询有多少页 - presentationcursor.selectPath(namespace + "//p:presentation/p:sldIdLst/p:sldId"); - int count = 0; - String value = ""; - while (presentationcursor.toNextSelection()) { - count ++; - value += "第" + count + "页 "; - } - WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); - judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); - judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); - judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); - judgementDto.setScoreRate("1"); - judgementList.add(judgementDto); - } - } - } - } - } - - } catch (IOException e) { - e.printStackTrace(); - } catch (XmlException e) { - throw new RuntimeException(e); - } catch (InvalidFormatException e) { - throw new RuntimeException(e); - } - return judgementList; - } - - public static String getValueType(PptxInfoPointsVo pptxInfoPointsVo, String value) { - String values = value; - if (pptxInfoPointsVo.getUnit().contains("twiptopt")) { - values = TwipConverter.formatDouble(TwipConverter.toPoints(Integer.parseInt(value))) + "磅"; - } - if (pptxInfoPointsVo.getUnit().contains("emustopt")) { - values = TwipConverter.formatDouble(TwipConverter.toEmus(Integer.parseInt(value))) + "磅"; - } - if (pptxInfoPointsVo.getUnit().contains("color")) { - values = ColorNameFinder.getColorName(value); - } - if (pptxInfoPointsVo.getUnit().contains("direction")) { - // 方向英文转换 - if ("landscape".equals(value)) { - values = "横向"; - } else if ("portrait".equals(value)) { - values = "纵向"; - } else if ("up".equals(value)) { - values = "上对齐"; - } else if ("down".equals(value)) { - values = "下对齐"; - } - } - if (value.contains("center")) { - values = "居中对齐"; - } - if (pptxInfoPointsVo.getUnit().contains("textdirection")) { - // 方向英文转换 - if ("left".equals(value)) { - values = "左对齐"; - } else if ("center".equals(value)) { - values = "居中对齐"; - } else if ("right".equals(value)) { - values = "右对齐"; - } else if ("both".equals(value)) { - values = "两端对齐"; - } - } - if (pptxInfoPointsVo.getUnit().contains("halfpt")) { - values = String.valueOf (Integer.parseInt(value) / 2); - } - if (pptxInfoPointsVo.getUnit().contains("baipt")) { - values = String.valueOf (Integer.parseInt(value) / 100); - } - if (pptxInfoPointsVo.getUnit().contains("milli")) { - values = String.valueOf (Integer.parseInt(value) / 1000); - } - if (pptxInfoPointsVo.getUnit().contains("shadowdirection")) { - ShadowDirectionUtils.ShadowDirection direction = ShadowDirectionUtils.getShadowDirection(Long.valueOf(value)); - values = direction.getLabel(); - } - if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { - if (value.contains("solidFill")) { - values = "纯色填充"; - } else if (value.contains("gradFill")) { - values = "渐变填充"; - } else if (value.contains("pattFill")) { - values = "图案填充"; - } else if (value.contains("blipFill")) { - values = "图片填充"; - } else { - values = "未知填充"; - } - } - return values; - } - - public static String getStringName(String name) { - // 提取字母部分 - String letters = name.replaceAll("[^a-zA-Z]", ""); - // 提取数字部分 - String digits = name.replaceAll("[^0-9]", ""); - String chineseName = ""; - if ("slide".equalsIgnoreCase(letters)) { - try { - int slideNumber = Integer.parseInt(digits); - chineseName = "【第 " + slideNumber + " 页】"; - } catch (NumberFormatException e) { - System.out.println("数字解析失败:" + e.getMessage()); - } - } - return chineseName; - } - - // 大纲 - // 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他 - // 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作 - // 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作 - public static List wpsPptxInfo(String filePath) throws FileNotFoundException { - List pptxInfoReqVos = new ArrayList<>(); - try (FileInputStream fis = new FileInputStream(filePath); - XMLSlideShow pptxXml = new XMLSlideShow(fis)) { - int index = 0; - String firstId = getStringRandom(); - setPptxInfo("幻灯片", "p:sld", "p:sld", filePath, firstId, "0", pptxInfoReqVos); - for (XSLFSlide slides : pptxXml.getSlides()){ - index += 1; - String secondId = getStringRandom(); - setPptxInfo("第"+index+"页", "p:sld"+index, "p:sld"+index, filePath, secondId, firstId, pptxInfoReqVos); - // 第三层 - String thirdId = getStringRandom(); - int indexCnvPr = 1; - setPptxInfo("幻灯片设置", "slide"+index, "(//p:bg)["+indexCnvPr+"]", filePath, thirdId, secondId, pptxInfoReqVos); - XmlCursor spCursor = slides.getXmlObject().newCursor(); - spCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:sp"); - while (spCursor.toNextSelection()) { - XmlCursor cNvPrXml = spCursor.newCursor(); - cNvPrXml.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:cNvPr/@name"); - if (cNvPrXml.toNextSelection()) { - String name = cNvPrXml.getTextValue(); - String fourId = getStringRandom(); - setPptxInfo("形状"+indexCnvPr+"->"+name, "slide"+index, "(//p:sp)["+indexCnvPr+"]", filePath, fourId, secondId, pptxInfoReqVos); - indexCnvPr += 1; - } - } - XmlCursor picCursor = slides.getXmlObject().newCursor(); - System.out.println(picCursor.xmlText()); - picCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:pic"); - int indexCnvPrPic = 1; - while (picCursor.toNextSelection()) { - String fourId = getStringRandom(); - setPptxInfo("图像"+indexCnvPrPic+"->图像", "slide"+index, "(//p:pic)["+indexCnvPrPic+"]", filePath, fourId, secondId, pptxInfoReqVos); - indexCnvPrPic += 1; - } - } - // 设置 - String firstIds = getStringRandom(); - setPptxInfo("设置", "p:presentation", "p:presentation", filePath, firstIds, "0", pptxInfoReqVos); - String secondIds = getStringRandom(); - setPptxInfo("幻灯片设置", "p:presentation", "p:presentation", filePath, secondIds, firstIds, pptxInfoReqVos); - - // 母版 -// String dFirstId = getStringRandom(); -// setPptxInfo("母版", "p:sld", "p:sld", filePath, dFirstId, "0", pptxInfoReqVos); - } catch (Exception e) { - throw new RuntimeException(e); - } - return pptxInfoReqVos; - } - - - public static List wpsPptx(String filePath, List cSldList) { - List pptxVOS = new ArrayList<>(); - // 转换数据 - List cSldTree = TreeUtils.buildTreePptx(cSldList); - // 1、读取文件内容 - try (FileInputStream fis = new FileInputStream(filePath); - XMLSlideShow pptxXml = new XMLSlideShow(fis)) { - // 索引 - int index = 0; - // 获取了所有的幻灯片 - for (XSLFSlide slides : pptxXml.getSlides()){ - index += 1; - String xmlText = slides.getXmlObject().xmlText(); - // 1-1、创建最全的命名空间 - Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); - Matcher matcher = pattern.matcher(xmlText); - Map namespaces = new HashMap<>(); - while (matcher.find()) { - String prefix = matcher.group(1); - String uri = matcher.group(2); - namespaces.put(prefix, uri); - } - StringBuilder xpathBuilder = new StringBuilder(); - namespaces.forEach((prefix, uri) -> - xpathBuilder.append("declare namespace ") - .append(prefix) - .append("='") - .append(uri) - .append("' ") - ); - // 2-1、获取出来最全的命名空间 - String allPathx = xpathBuilder.toString(); - // 3、获取CTDocument对象 - XmlObject docXml = slides.getXmlObject(); - // 命名 - String typeName = "【第" + index + "页】"; - String englishName = "@" + index; - for (WpsPptxLinkDO node : cSldTree) { - // 4、查询形状下的所有数据 先查询有多少个形状 - XmlCursor xmlCursor = docXml.newCursor(); - xmlCursor.selectPath(allPathx + "//" + node.getName()); - System.out.println(xmlCursor.xmlText()); - // 获取p:sp形状下的数据 - int pIndex = 0; - while (xmlCursor.toNextSelection()) { - pIndex += 1; - for (WpsPptxLinkDO anchor :node.getChildren()) { - String spName = "【第" + pIndex + "个形状】"; - String englishSpName = "@" + pIndex; - XmlCursor pXmlCursor = xmlCursor.getObject().newCursor(); - String nextString = allPathx + anchor.getName(); - pXmlCursor.selectPath(nextString); - while (pXmlCursor.toNextSelection()) { - XmlCursor pXmlCursors = pXmlCursor.getObject().newCursor(); - String textValue = pXmlCursors.getTextValue(); - PptxVO pptxVO = new PptxVO(); - pptxVO.setExamKeynote(englishName + englishSpName + anchor.getName()+ " " + textValue); - pptxVO.setKeynoteChinese(typeName + spName + "【" + anchor.getToChinese() + "】" + textValue); - pptxVOS.add(pptxVO); -// System.out.println(typeName + spName + "【" + anchor.getToChinese() + "】" + textValue); - } - pXmlCursor.dispose(); - } - // traverseTreeAndQueryXml(pptxVOS, typeName + "-第" + pIndex + "个形状", allPathx, node, pXmlObject, new ArrayList<>(), new ArrayList<>(), index, 1); - } - xmlCursor.dispose(); - } - } - - } catch (IOException e) { - throw new RuntimeException(e); - } - return pptxVOS; - } - - public static void setPptxInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List pptxInfoReqVos) throws Exception { - PptxInfoReqVo pptxInfos = new PptxInfoReqVo(); - pptxInfos.setName(chineseName); - pptxInfos.setEnglishName(englishName); - pptxInfos.setFilePath(filePath); - pptxInfos.setId(id); - pptxInfos.setSelectName(selectName); - pptxInfos.setParentId(parentId); - pptxInfoReqVos.add(pptxInfos); - } - - public static String getStringRandom() { - String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - Random random = new Random(); - StringBuilder sb = new StringBuilder(); - - // 生成指定长度的随机字符字符串 - for (int i = 0; i < 10; i++) { - int randomIndex = random.nextInt(characters.length()); - // 随机字符 - sb.append(characters.charAt(randomIndex)); - } - return sb.toString(); - } - - /** - * @param pptxVOS List 用来存放结果 - * @param firstTitle String 用来存放一级标题 - * @param xpath String 用来存放xpath - * @param node WpsWordLinkDO 用来存放节点 - * @param currentXml XmlObject 用来存放当前xml - * @param pathSoFar List 用来存放路径 - * @param pathChinese List 用来存放中文路径 - * @param index int 用来存放索引 - * @param beginIndex int 用来存放开始索引 - */ - public static void traverseTreeAndQueryXml(List pptxVOS, String firstTitle, String xpath, WpsPptxLinkDO node, XmlObject currentXml, List pathSoFar, List pathChinese, int index, int beginIndex) { - // 到达参数节点,构造 XPath 路径查询它的值 - if (beginIndex == 1) { - xpath += "./"; - } - if (beginIndex > 1) { - pathSoFar.add(node.getName()); - pathChinese.add(node.getToChinese() + index); - } - - if (node.getType() == 1 || node.getType() == 2) { - xpath += String.join("/", pathSoFar); - try (XmlCursor cursors = currentXml.newCursor()) { - System.out.println(cursors.xmlText()); - System.out.println(xpath); - cursors.selectPath(xpath); - if (cursors.toNextSelection()) { - String textValue = cursors.getTextValue(); - cursors.dispose(); - } - } - } else { - for (WpsPptxLinkDO child : node.getChildren()) { - traverseTreeAndQueryXml(pptxVOS, firstTitle, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2); - } - } - if (!pathSoFar.isEmpty()) { - pathSoFar.remove(pathSoFar.size() - 1); - pathChinese.remove(pathChinese.size() - 1); - } - - } - -} +// pptxSlidesVo.setSlideResList(slideList); +// pptxSlidesOrgVos.add(pptxSlidesVo); +// } +// } +// if (entryName.contains("ppt/slides") && entryName.contains(".xml") && !entryName.contains(".rels")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// String[] names = entryName.split("/"); +// Optional result = pptxSlidesOrgVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(names[entryName.split("/").length-1])).findFirst(); +// PptxSlidesVo pptxSlidesVo = result.get(); +// pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// pptxSlidesVo.setXmlCursor(cursor); +// pptxSlidesVos.add(pptxSlidesVo); +// } +// +// } +// } +// for (PptxInfoPointsVo pptxInfoPointsVo : pptxInfoPointsVos) { +// // 判断幻灯片形状 +// if ("0".equals(pptxInfoPointsVo.getBelongTo())) { +// Optional result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst(); +// PptxSlidesVo pptxSlidesVo = result.get(); +// XmlCursor slideCursor = pptxSlidesVo.getXmlCursor(); +// String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText()); +// if (pptxInfoPointsVo.getName().contains("动画")) { +// String[] functions = pptxInfoPointsVo.getFunction().split("#"); +// String functionStr = functions[0]; +// if (pptxInfoPointsVo.getFunction().contains("pic")) { +// functionStr = functionStr.replace("nvSpPr", "nvPicPr"); +// } +// XmlCursor dongCursor = slideCursor; +// XmlCursor cTnCursor = slideCursor; +// dongCursor.selectPath(namespace + functionStr); +// if (dongCursor.toNextSelection()) { +// String number = dongCursor.getTextValue(); +// cTnCursor.selectPath(namespace + "//p:cTn[@id='"+number+"']"); +// if (cTnCursor.toNextSelection()) { +// System.out.println(cTnCursor.xmlText()); +// if (pptxInfoPointsVo.getName().contains("效果")) { +// if (pptxInfoPointsVo.getFunction().contains("pic")) { +// String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "效果"); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// cTnCursor.selectPath(namespace + "//p:animEffect"); +// if (cTnCursor.toNextSelection()) { +// String value = ""; +// String transition = cTnCursor.getAttributeText(new QName("transition")); +// String filter = cTnCursor.getAttributeText(new QName("filter")); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// if (transition.contains("in")) { +// value += "进入效果"; +// } +// if (filter.contains("strips")) { +// value += "->阶梯状"; +// } +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// if (pptxInfoPointsVo.getName().contains("方向")) { +// cTnCursor.selectPath(namespace + "//p:animEffect"); +// if (pptxInfoPointsVo.getFunction().contains("pic")) { +// String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "方向"); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// if (cTnCursor.toNextSelection()) { +// String value = ""; +// String filter = cTnCursor.getAttributeText(new QName("filter")); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// if (filter.contains("downRight")) { +// value += "右下"; +// } +// if (filter.contains("plus(out)")) { +// value += "十字形扩展"; +// } +// if (filter.contains("plus(in)")) { +// value += "十字形聚合"; +// } +// if (filter.contains("blinds(vertical)")) { +// value += "百叶窗 - 垂直"; +// } +// if (filter.contains("blinds(horizontal)")) { +// value += "百叶窗 - 水平"; +// } +// if (filter.contains("circle(in)")) { +// value += "圆形聚焦进入"; +// } +// if (filter.contains("circle(out)")) { +// value += "圆形扩散"; +// } +// if (filter.contains("diamond(out)")) { +// value += "菱形扩散"; +// } +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// if (pptxInfoPointsVo.getName().contains("触发方式")) { +// if (pptxInfoPointsVo.getFunction().contains("pic")) { +// String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "触发方式"); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// +// } +// } +// if (pptxInfoPointsVo.getName().contains("持续时间")) { +// if (pptxInfoPointsVo.getFunction().contains("pic")) { +// String results = SlideAnimationQueryByCursor.getAnimationInfoForSpid(cTnCursor, number, "持续时间"); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + results); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ results); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// cTnCursor.selectPath(namespace + "//p:animEffect/p:cBhvr/p:cTn"); +// if (cTnCursor.toNextSelection()) { +// String value = ""; +// String dur = cTnCursor.getAttributeText(new QName("dur")); +// if (dur == null) { +// value = "0秒"; +// } else { +// value = String.valueOf((double) Integer.parseInt(dur) / 1000); +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// } +// } +// } else if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { +// // 查询 +// XmlCursor otherSlideCurors = slideCursor.newCursor(); +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// // 判断填充方式的 +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.xmlText(); +// value = getValueType(pptxInfoPointsVo, value); +// if (value.contains("未知填充")) { +// otherSlideCurors.selectPath(namespace + pptxInfoPointsVo.getFunction().split("]")[0] + "]/p:txBody"); +// if (otherSlideCurors.toNextSelection()) { +// value = otherSlideCurors.xmlText(); +// value = getValueType(pptxInfoPointsVo, value); +// } +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } else if (pptxInfoPointsVo.getName().contains("形状效果") && pptxInfoPointsVo.getName().contains("预设")) { +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.xmlText(); +// value = ReflectionAnalyzer.analyzeReflection(value); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } else if (pptxInfoPointsVo.getName().contains("纯色填充-颜色")) { +// String[] functionList = pptxInfoPointsVo.getFunction().split("#"); +// slideCursor.selectPath(namespace + functionList[0]); +// String english = functionList[0].split("]")[0] + "]"; +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.getTextValue(); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// slideCursor.selectPath(namespace + english + functionList[1]); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.getTextValue(); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } else if (pptxInfoPointsVo.getName().contains("锁定横纵比")) { +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// String value = ""; +// if (slideCursor.toNextSelection()) { +// System.out.println(slideCursor.xmlText()); +// String values = slideCursor.getTextValue(); +// value = values.equals("1") ? "是" : "否"; +// } else { +// // 没有查询到说明没有 +// value = "否"; +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else if (pptxInfoPointsVo.getName().contains("短划线类型")){ +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// if (slideCursor.toNextSelection()) { +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + slideCursor.getTextValue()); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ slideCursor.getTextValue()); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// // 如果没有查询到说明使用了默认值 +// String value = "实线"; +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } else { +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// if (slideCursor.toNextSelection()) { +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// // 判断是值还是类型 +// if ("1".equals(pptxInfoPointsVo.getIsboo())) { +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + "是"); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + "true"); +// } else { +// String value = slideCursor.getTextValue(); +// value = getValueType(pptxInfoPointsVo, value); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + value); +// +// } +// judgementDto.setImage(pptxInfoPointsVo.getType() + "-" + pptxInfoPointsVo.getBelongTo() + "-" + pptxInfoPointsVo.getIsboo() + "-" + pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } else { +// if ("1".equals(pptxInfoPointsVo.getIsboo())) { +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + "否"); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName() + "?" + pptxInfoPointsVo.getFunction() + "?" + "false"); +// judgementDto.setImage(pptxInfoPointsVo.getType() + "-" + pptxInfoPointsVo.getBelongTo() + "-" + pptxInfoPointsVo.getIsboo() + "-" + pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// } +// // 单个幻灯片设置 +// if ("1".equals(pptxInfoPointsVo.getBelongTo())) { +// Optional result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst(); +// PptxSlidesVo pptxSlidesVo = result.get(); +// XmlCursor slideCursor = pptxSlidesVo.getXmlCursor(); +// String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText()); +// // 查询 +// if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { +// // 判断填充方式的 +// slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", "")); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.xmlText(); +// value = getValueType(pptxInfoPointsVo, value); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } else if (pptxInfoPointsVo.getName().contains("幻灯片切换")){ +// if (pptxInfoPointsVo.getName().contains("切换效果")) { +// slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.xmlText(); +// if (value.contains("p:fade")) { +// value = "淡入淡出"; +// } else if (value.contains("p:push")) { +// value = "推入"; +// } else if (value.contains("p:wipe")) { +// value = " 擦除"; +// } else if (value.contains("p:split")) { +// value = "分割"; +// }else if (value.contains("p:cut")) { +// value = "瞬间切换(无动画)"; +// } else if (value.contains("p:random")) { +// value = " 随机一种切换效果"; +// } else if (value.contains("p:pull")) { +// value = "拉出"; +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// if (pptxInfoPointsVo.getName().contains("切换声音")) { +// slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.getTextValue(); +// if (value.contains("wind.wav")) { +// value = "风声"; +// } else if (value.contains("water.wav")) { +// value = "水声"; +// } else if (value.contains("fire.wav")) { +// value = "火声"; +// } else if (value.contains("thunder.wav")) { +// value = "雷声"; +// } else if (value.contains("applause.wav")) { +// value = "掌声"; +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +//// if (pptxInfoPointsVo.getName().contains("单机鼠标换片")) { +//// +//// } +// if (pptxInfoPointsVo.getName().contains("换片间隔时间")){ +// slideCursor.selectPath(namespace + "./" + pptxInfoPointsVo.getFunction().split("]")[1]); +// if (slideCursor.toNextSelection()) { +// String value = slideCursor.getTextValue(); +// int values = Integer.parseInt(value) / 1000; +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + values); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ values); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// } +// // 幻灯片设置 +// if ("2".equals(pptxInfoPointsVo.getBelongTo())) { +// XmlCursor presentationcursor = null; +// String namespace = ""; +// for (PackagePart part : pkg.getParts()) { +// String entryName = part.getPartName().getName(); +// if (entryName.contains("ppt/presentation") && entryName.contains(".xml")) { +// try (InputStream is = part.getInputStream()) { +// String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// presentationcursor = xmlObject.newCursor(); +// namespace = WpsPptxNameSpaces.getNameSpace(presentationcursor.xmlText()); +// } +// } +// } +// if ("1".equals(pptxInfoPointsVo.getType())) { +// // 如果是外参数 +// if (pptxInfoPointsVo.getName().contains("幻灯片大小")) { +// presentationcursor.selectPath(namespace + "//p:presentation/p:sldSz"); +// if (presentationcursor.toNextSelection()) { +// String value = PageSizeDetector.detectPaperPPTSize(presentationcursor.xmlText()); +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// if (pptxInfoPointsVo.getName().contains("放映类型")) { +// presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); +// if (presentationcursor.toNextSelection()) { +// System.out.println("放映类型" + presentationcursor.xmlText()); +// } else { +// // 如果没有标签的话说明是默认的ppt方式 +// String value = "演示者放映(全屏)"; +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() +value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// if (pptxInfoPointsVo.getName().contains("放映范围")) { +// presentationcursor.selectPath(namespace + "//p:presentation/p:showPr"); +// if (presentationcursor.toNextSelection()) { +// System.out.println("放映范围" + presentationcursor.xmlText()); +// } else { +// // 说明全页面放映,查询有多少页 +// presentationcursor.selectPath(namespace + "//p:presentation/p:sldIdLst/p:sldId"); +// int count = 0; +// String value = ""; +// while (presentationcursor.toNextSelection()) { +// count ++; +// value += "第" + count + "页 "; +// } +// WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto(); +// judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName() + value); +// judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+ value); +// judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo()+"-"+pptxInfoPointsVo.getUnit()); +// judgementDto.setScoreRate("1"); +// judgementList.add(judgementDto); +// } +// } +// } +// } +// } +// +// } catch (IOException e) { +// e.printStackTrace(); +// } catch (XmlException e) { +// throw new RuntimeException(e); +// } catch (InvalidFormatException e) { +// throw new RuntimeException(e); +// } +// return judgementList; +// } +// +// public static String getValueType(PptxInfoPointsVo pptxInfoPointsVo, String value) { +// String values = value; +// if (pptxInfoPointsVo.getUnit().contains("twiptopt")) { +// values = TwipConverter.formatDouble(TwipConverter.toPoints(Integer.parseInt(value))) + "磅"; +// } +// if (pptxInfoPointsVo.getUnit().contains("emustopt")) { +// values = TwipConverter.formatDouble(TwipConverter.toEmus(Integer.parseInt(value))) + "磅"; +// } +// if (pptxInfoPointsVo.getUnit().contains("color")) { +// values = ColorNameFinder.getColorName(value); +// } +// if (pptxInfoPointsVo.getUnit().contains("direction")) { +// // 方向英文转换 +// if ("landscape".equals(value)) { +// values = "横向"; +// } else if ("portrait".equals(value)) { +// values = "纵向"; +// } else if ("up".equals(value)) { +// values = "上对齐"; +// } else if ("down".equals(value)) { +// values = "下对齐"; +// } +// } +// if (value.contains("center")) { +// values = "居中对齐"; +// } +// if (pptxInfoPointsVo.getUnit().contains("textdirection")) { +// // 方向英文转换 +// if ("left".equals(value)) { +// values = "左对齐"; +// } else if ("center".equals(value)) { +// values = "居中对齐"; +// } else if ("right".equals(value)) { +// values = "右对齐"; +// } else if ("both".equals(value)) { +// values = "两端对齐"; +// } +// } +// if (pptxInfoPointsVo.getUnit().contains("halfpt")) { +// values = String.valueOf (Integer.parseInt(value) / 2); +// } +// if (pptxInfoPointsVo.getUnit().contains("baipt")) { +// values = String.valueOf (Integer.parseInt(value) / 100); +// } +// if (pptxInfoPointsVo.getUnit().contains("milli")) { +// values = String.valueOf (Integer.parseInt(value) / 1000); +// } +// if (pptxInfoPointsVo.getUnit().contains("shadowdirection")) { +// ShadowDirectionUtils.ShadowDirection direction = ShadowDirectionUtils.getShadowDirection(Long.valueOf(value)); +// values = direction.getLabel(); +// } +// if (pptxInfoPointsVo.getUnit().contains("Filling_method")) { +// if (value.contains("solidFill")) { +// values = "纯色填充"; +// } else if (value.contains("gradFill")) { +// values = "渐变填充"; +// } else if (value.contains("pattFill")) { +// values = "图案填充"; +// } else if (value.contains("blipFill")) { +// values = "图片填充"; +// } else { +// values = "未知填充"; +// } +// } +// return values; +// } +// +// public static String getStringName(String name) { +// // 提取字母部分 +// String letters = name.replaceAll("[^a-zA-Z]", ""); +// // 提取数字部分 +// String digits = name.replaceAll("[^0-9]", ""); +// String chineseName = ""; +// if ("slide".equalsIgnoreCase(letters)) { +// try { +// int slideNumber = Integer.parseInt(digits); +// chineseName = "【第 " + slideNumber + " 页】"; +// } catch (NumberFormatException e) { +// System.out.println("数字解析失败:" + e.getMessage()); +// } +// } +// return chineseName; +// } +// +// // 大纲 +// // 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他 +// // 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作 +// // 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作 +// public static List wpsPptxInfo(String filePath) throws FileNotFoundException { +// List pptxInfoReqVos = new ArrayList<>(); +// try (FileInputStream fis = new FileInputStream(filePath); +// XMLSlideShow pptxXml = new XMLSlideShow(fis)) { +// int index = 0; +// String firstId = getStringRandom(); +// setPptxInfo("幻灯片", "p:sld", "p:sld", filePath, firstId, "0", pptxInfoReqVos); +// for (XSLFSlide slides : pptxXml.getSlides()){ +// index += 1; +// String secondId = getStringRandom(); +// setPptxInfo("第"+index+"页", "p:sld"+index, "p:sld"+index, filePath, secondId, firstId, pptxInfoReqVos); +// // 第三层 +// String thirdId = getStringRandom(); +// int indexCnvPr = 1; +// setPptxInfo("幻灯片设置", "slide"+index, "(//p:bg)["+indexCnvPr+"]", filePath, thirdId, secondId, pptxInfoReqVos); +// XmlCursor spCursor = slides.getXmlObject().newCursor(); +// spCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:sp"); +// while (spCursor.toNextSelection()) { +// XmlCursor cNvPrXml = spCursor.newCursor(); +// cNvPrXml.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:cNvPr/@name"); +// if (cNvPrXml.toNextSelection()) { +// String name = cNvPrXml.getTextValue(); +// String fourId = getStringRandom(); +// setPptxInfo("形状"+indexCnvPr+"->"+name, "slide"+index, "(//p:sp)["+indexCnvPr+"]", filePath, fourId, secondId, pptxInfoReqVos); +// indexCnvPr += 1; +// } +// } +// XmlCursor picCursor = slides.getXmlObject().newCursor(); +// System.out.println(picCursor.xmlText()); +// picCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:pic"); +// int indexCnvPrPic = 1; +// while (picCursor.toNextSelection()) { +// String fourId = getStringRandom(); +// setPptxInfo("图像"+indexCnvPrPic+"->图像", "slide"+index, "(//p:pic)["+indexCnvPrPic+"]", filePath, fourId, secondId, pptxInfoReqVos); +// indexCnvPrPic += 1; +// } +// } +// // 设置 +// String firstIds = getStringRandom(); +// setPptxInfo("设置", "p:presentation", "p:presentation", filePath, firstIds, "0", pptxInfoReqVos); +// String secondIds = getStringRandom(); +// setPptxInfo("幻灯片设置", "p:presentation", "p:presentation", filePath, secondIds, firstIds, pptxInfoReqVos); +// +// // 母版 +//// String dFirstId = getStringRandom(); +//// setPptxInfo("母版", "p:sld", "p:sld", filePath, dFirstId, "0", pptxInfoReqVos); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// return pptxInfoReqVos; +// } +// +// +// public static List wpsPptx(String filePath, List cSldList) { +// List pptxVOS = new ArrayList<>(); +// // 转换数据 +// List cSldTree = TreeUtils.buildTreePptx(cSldList); +// // 1、读取文件内容 +// try (FileInputStream fis = new FileInputStream(filePath); +// XMLSlideShow pptxXml = new XMLSlideShow(fis)) { +// // 索引 +// int index = 0; +// // 获取了所有的幻灯片 +// for (XSLFSlide slides : pptxXml.getSlides()){ +// index += 1; +// String xmlText = slides.getXmlObject().xmlText(); +// // 1-1、创建最全的命名空间 +// Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); +// Matcher matcher = pattern.matcher(xmlText); +// Map namespaces = new HashMap<>(); +// while (matcher.find()) { +// String prefix = matcher.group(1); +// String uri = matcher.group(2); +// namespaces.put(prefix, uri); +// } +// StringBuilder xpathBuilder = new StringBuilder(); +// namespaces.forEach((prefix, uri) -> +// xpathBuilder.append("declare namespace ") +// .append(prefix) +// .append("='") +// .append(uri) +// .append("' ") +// ); +// // 2-1、获取出来最全的命名空间 +// String allPathx = xpathBuilder.toString(); +// // 3、获取CTDocument对象 +// XmlObject docXml = slides.getXmlObject(); +// // 命名 +// String typeName = "【第" + index + "页】"; +// String englishName = "@" + index; +// for (WpsPptxLinkDO node : cSldTree) { +// // 4、查询形状下的所有数据 先查询有多少个形状 +// XmlCursor xmlCursor = docXml.newCursor(); +// xmlCursor.selectPath(allPathx + "//" + node.getName()); +// System.out.println(xmlCursor.xmlText()); +// // 获取p:sp形状下的数据 +// int pIndex = 0; +// while (xmlCursor.toNextSelection()) { +// pIndex += 1; +// for (WpsPptxLinkDO anchor :node.getChildren()) { +// String spName = "【第" + pIndex + "个形状】"; +// String englishSpName = "@" + pIndex; +// XmlCursor pXmlCursor = xmlCursor.getObject().newCursor(); +// String nextString = allPathx + anchor.getName(); +// pXmlCursor.selectPath(nextString); +// while (pXmlCursor.toNextSelection()) { +// XmlCursor pXmlCursors = pXmlCursor.getObject().newCursor(); +// String textValue = pXmlCursors.getTextValue(); +// PptxVO pptxVO = new PptxVO(); +// pptxVO.setExamKeynote(englishName + englishSpName + anchor.getName()+ " " + textValue); +// pptxVO.setKeynoteChinese(typeName + spName + "【" + anchor.getChineseName() + "】" + textValue); +// pptxVOS.add(pptxVO); +//// System.out.println(typeName + spName + "【" + anchor.getToChinese() + "】" + textValue); +// } +// pXmlCursor.dispose(); +// } +// // traverseTreeAndQueryXml(pptxVOS, typeName + "-第" + pIndex + "个形状", allPathx, node, pXmlObject, new ArrayList<>(), new ArrayList<>(), index, 1); +// } +// xmlCursor.dispose(); +// } +// } +// +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// return pptxVOS; +// } +// +// public static void setPptxInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List pptxInfoReqVos) throws Exception { +// PptxInfoReqVo pptxInfos = new PptxInfoReqVo(); +// pptxInfos.setName(chineseName); +// pptxInfos.setEnglishName(englishName); +// pptxInfos.setFilePath(filePath); +// pptxInfos.setId(id); +// pptxInfos.setSelectName(selectName); +// pptxInfos.setParentId(parentId); +// pptxInfoReqVos.add(pptxInfos); +// } +// +// public static String getStringRandom() { +// String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; +// Random random = new Random(); +// StringBuilder sb = new StringBuilder(); +// +// // 生成指定长度的随机字符字符串 +// for (int i = 0; i < 10; i++) { +// int randomIndex = random.nextInt(characters.length()); +// // 随机字符 +// sb.append(characters.charAt(randomIndex)); +// } +// return sb.toString(); +// } +// +// /** +// * @param pptxVOS List 用来存放结果 +// * @param firstTitle String 用来存放一级标题 +// * @param xpath String 用来存放xpath +// * @param node WpsWordLinkDO 用来存放节点 +// * @param currentXml XmlObject 用来存放当前xml +// * @param pathSoFar List 用来存放路径 +// * @param pathChinese List 用来存放中文路径 +// * @param index int 用来存放索引 +// * @param beginIndex int 用来存放开始索引 +// */ +// public static void traverseTreeAndQueryXml(List pptxVOS, String firstTitle, String xpath, WpsPptxLinkDO node, XmlObject currentXml, List pathSoFar, List pathChinese, int index, int beginIndex) { +// // 到达参数节点,构造 XPath 路径查询它的值 +// if (beginIndex == 1) { +// xpath += "./"; +// } +// if (beginIndex > 1) { +// pathSoFar.add(node.getName()); +// pathChinese.add(node.getChineseName() + index); +// } +// +// if (node.getType() == 1 || node.getType() == 2) { +// xpath += String.join("/", pathSoFar); +// try (XmlCursor cursors = currentXml.newCursor()) { +// System.out.println(cursors.xmlText()); +// System.out.println(xpath); +// cursors.selectPath(xpath); +// if (cursors.toNextSelection()) { +// String textValue = cursors.getTextValue(); +// cursors.dispose(); +// } +// } +// } else { +// for (WpsPptxLinkDO child : node.getChildren()) { +// traverseTreeAndQueryXml(pptxVOS, firstTitle, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2); +// } +// } +// if (!pathSoFar.isEmpty()) { +// pathSoFar.remove(pathSoFar.size() - 1); +// pathChinese.remove(pathChinese.size() - 1); +// } +// +// } +// +//} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/XmlRecursiveFinder.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/XmlRecursiveFinder.java new file mode 100644 index 00000000..9eefaf6d --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/XmlRecursiveFinder.java @@ -0,0 +1,39 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class XmlRecursiveFinder { + // 递归入口 + public static Element findElementRecursive(Node startNode, String[] tags, int index) { + if (index >= tags.length || startNode == null) return null; + + String tag = tags[index].split(":")[1]; + String namespace = tags[index].split(":")[0]; + NodeList children; + + if (startNode instanceof Document) { + children = ((Document) startNode).getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(namespace), tag); + } else { + children = ((Element) startNode).getElementsByTagNameNS(DeclareNamespaceForPPT.getNameSpace(namespace), tag); + } + + if (children.getLength() == 0) return null; + + Element child = (Element) children.item(0); + if (index == tags.length - 1) { + // 最后一层,返回当前节点 + return child; + } + + return findElementRecursive(child, tags, index + 1); + } + + // 封装外部调用 + public static Element findElement(Document doc, String titleName) { + String[] title = titleName.split("@"); + return findElementRecursive(doc, title, 0); + } +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/judgementVO/JudgementReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/judgementVO/JudgementReqVo.java new file mode 100644 index 00000000..0e266fa0 --- /dev/null +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/judgementVO/JudgementReqVo.java @@ -0,0 +1,38 @@ +package pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO; + +import lombok.Data; + +/** + * @author REN + */ +@Data +public class JudgementReqVo { + + // 中文考点 + private String chineseName; + + // 查询段落所在文件名称 + private String fileNama; + + // 查询的段落 + private String paragraph; + + // 需要查询的标签 + private String title; + + // 需要查询的参数 当isText == 1 为null + private String valueList; + + // 值转换类型 String + private String type; + + // 需要查找的是文本还是参数(0:参数;1:文本) + private String isText; + + // 对结果的判断(0:否 返回值,1:是 返回 是否) + private String isTrue; + + // 0:内参数;1:外参数;2;内外参数(方法使用#继续分割) + private String isParameter; + +} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoReqVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoReqVo.java index 5a724567..4dc67f66 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoReqVo.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoReqVo.java @@ -21,6 +21,8 @@ public class PptxInfoReqVo { private String selectName; + private String title; + private String id; private List children = new ArrayList<>();