diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsXlsxController.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsXlsxController.java new file mode 100644 index 00000000..148b47f4 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/ExamWpsXlsxController.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.xlsx.XlsxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxRespVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSimpleRespVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx; +import pc.exam.pp.module.exam.service.wps.xlsx.ExamWpsXlsxService; + +import java.util.List; + +import static pc.exam.pp.framework.common.pojo.CommonResult.success; + +@Tag(name = "考试系统 - XLSX考点") +@RestController +@RequestMapping("/exam/xlsx") +@Validated +public class ExamWpsXlsxController { + + @Resource + private ExamWpsXlsxService examWpsXlsxService; + + @PostMapping("create") + @Operation(summary = "创建XLSX考点") + public CommonResult createXlsx(@Valid @RequestBody XlsxSaveReqVO createReqVO) { + Long XlsxId = examWpsXlsxService.createXlsx(createReqVO); + return success(XlsxId); + } + + @PutMapping("update") + @Operation(summary = "更新XLSX考点") + public CommonResult updateXlsx(@Valid @RequestBody XlsxSaveReqVO updateReqVO) { + examWpsXlsxService.updateXlsx(updateReqVO); + return success(true); + } + + @DeleteMapping("delete") + @Operation(summary = "删除XLSX考点") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult deleteXlsx(@RequestParam("id") Long id) { + examWpsXlsxService.deleteXlsx(id); + return success(true); + } + + @GetMapping("/list") + @Operation(summary = "获取XLSX考点列表") + public CommonResult> getXlsxList(XlsxListReqVO reqVO) { + List list = examWpsXlsxService.getXlsxList(reqVO); + return success(BeanUtils.toBean(list, XlsxRespVO.class)); + } + + @GetMapping(value = {"/list-all-simple", "/simple-list"}) + @Operation(summary = "获取XLSX考点精简信息列表", description = "只包含被开启的XLSX考点,主要用于前端的下拉选项") + public CommonResult> getSimpleXlsxList() { + List list = examWpsXlsxService.getXlsxList( + new XlsxListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); + return success(BeanUtils.toBean(list, XlsxSimpleRespVO.class)); + } + + @GetMapping("/get") + @Operation(summary = "获得XLSX考点信息") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult getXlsx(@RequestParam("id") Long id) { + ExamWpsXlsx xlsx = examWpsXlsxService.getXlsx(id); + return success(BeanUtils.toBean(xlsx, XlsxRespVO.class)); + } + + @GetMapping("/getByNameList") + public CommonResult> getXlsxByNameList(@RequestParam("title") String title) { + ExamWpsXlsx xlsx = examWpsXlsxService.getXlsxByTitle(title); + return success(BeanUtils.toBean(examWpsXlsxService.getChildXlsxList(xlsx.getId()), XlsxRespVO.class)); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxListReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxListReqVO.java new file mode 100644 index 00000000..924d24d1 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxListReqVO.java @@ -0,0 +1,14 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "考试模块 - XLSX考点列表 Request VO") +@Data +public class XlsxListReqVO { + + 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/xlsx/XlsxRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxRespVO.java new file mode 100644 index 00000000..15879d20 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxRespVO.java @@ -0,0 +1,32 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "考试模块 - XLSX考点信息 Response VO") +@Data +public class XlsxRespVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String functions; + + private String parameter; + + 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/xlsx/XlsxSaveReqVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxSaveReqVO.java new file mode 100644 index 00000000..ae24fdc9 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxSaveReqVO.java @@ -0,0 +1,28 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "考试模块 - XLSX考点创建/修改 Request VO") +@Data +public class XlsxSaveReqVO { + + private Long id; + + private String name; + + private Long parentId; + + private Integer sort; + + private Integer status; + + private String title; + + private String chineseName; + + private String parameter; + + private String functions; + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxSimpleRespVO.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxSimpleRespVO.java new file mode 100644 index 00000000..1044b474 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/controller/admin/wps/vo/xlsx/XlsxSimpleRespVO.java @@ -0,0 +1,20 @@ +package pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx; + +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 XlsxSimpleRespVO { + + 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/ExamWpsXlsx.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsXlsx.java new file mode 100644 index 00000000..8e0e4e52 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/wps/ExamWpsXlsx.java @@ -0,0 +1,37 @@ +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 xlsx关系对应表 + * + * @author REN + */ +@TableName("exam_wps_xlsx") +@Data +@EqualsAndHashCode(callSuper = true) +public class ExamWpsXlsx 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 functions; + private String parameter; + private Integer status; + @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/ExamWpsXlsxMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsXlsxMapper.java new file mode 100644 index 00000000..8a0884e1 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/wps/ExamWpsXlsxMapper.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.xlsx.XlsxListReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx; + +import java.util.Collection; +import java.util.List; + +@Mapper +public interface ExamWpsXlsxMapper extends BaseMapperX { + + default List selectList(XlsxListReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(ExamWpsXlsx::getName, reqVO.getName()) + .eqIfPresent(ExamWpsXlsx::getStatus, reqVO.getStatus())); + } + + default ExamWpsXlsx selectByParentIdAndName(Long parentId, String name) { + return selectOne(ExamWpsXlsx::getParentId, parentId, ExamWpsXlsx::getName, name); + } + + default ExamWpsXlsx selectByTitle(String title) { + return selectOne(ExamWpsXlsx::getTitle, title); + } + + default Long selectCountByParentId(Long parentId) { + return selectCount(ExamWpsXlsx::getParentId, parentId); + } + + default List selectListByParentId(Collection parentIds) { + return selectList(ExamWpsXlsx::getParentId, parentIds); + } +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxService.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxService.java new file mode 100644 index 00000000..4aacf21d --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxService.java @@ -0,0 +1,117 @@ +package pc.exam.pp.module.exam.service.wps.xlsx; + +import pc.exam.pp.framework.common.util.collection.CollectionUtils; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx; + +import java.util.*; + +/** + * Xlsx考点 Service 接口 + * + * @author 朋辰 + */ +public interface ExamWpsXlsxService { + + /** + * 创建Xlsx考点 + * + * @param createReqVO Xlsx考点信息 + * @return Xlsx考点编号 + */ + Long createXlsx(XlsxSaveReqVO createReqVO); + + /** + * 更新Xlsx考点 + * + * @param updateReqVO Xlsx考点信息 + */ + void updateXlsx(XlsxSaveReqVO updateReqVO); + + /** + * 删除Xlsx考点 + * + * @param id Xlsx考点编号 + */ + void deleteXlsx(Long id); + + /** + * 获得Xlsx考点信息 + * + * @param id Xlsx考点编号 + * @return Xlsx考点信息 + */ + ExamWpsXlsx getXlsx(Long id); + + /** + * 获得Xlsx考点信息 + * + * @param title Xlsx考点标签 + * @return Xlsx考点信息 + */ + ExamWpsXlsx getXlsxByTitle(String title); + + /** + * 获得Xlsx考点信息数组 + * + * @param ids Xlsx考点编号数组 + * @return Xlsx考点信息数组 + */ + List getXlsxList(Collection ids); + + /** + * 筛选Xlsx考点列表 + * + * @param reqVO 筛选条件请求 VO + * @return Xlsx考点列表 + */ + List getXlsxList(XlsxListReqVO reqVO); + + /** + * 获得指定编号的Xlsx考点 Map + * + * @param ids Xlsx考点编号数组 + * @return Xlsx考点 Map + */ + default Map getXlsxMap(Collection ids) { + List list = getXlsxList(ids); + return CollectionUtils.convertMap(list, ExamWpsXlsx::getId); + } + + /** + * 获得指定Xlsx考点的所有子Xlsx考点 + * + * @param id Xlsx考点编号 + * @return 子Xlsx考点列表 + */ + default List getChildXlsxList(Long id) { + return getChildXlsxList(Collections.singleton(id)); + } + + /** + * 获得指定Xlsx考点的所有子Xlsx考点 + * + * @param ids Xlsx考点编号数组 + * @return 子Xlsx考点列表 + */ + List getChildXlsxList(Collection ids); + + /** + * 获得所有子Xlsx考点,从缓存中 + * + * @param id 父Xlsx考点编号 + * @return 子Xlsx考点列表 + */ + Set getChildXlsxIdListFromCache(Long id); + + /** + * 校验Xlsx考点们是否有效。如下情况,视为无效: + * 1. Xlsx考点编号不存在 + * 2. Xlsx考点被禁用 + * + * @param ids 角色编号数组 + */ + void validateXlsxList(Collection ids); + +} diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxServiceImpl.java new file mode 100644 index 00000000..5149ea47 --- /dev/null +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/wps/xlsx/ExamWpsXlsxServiceImpl.java @@ -0,0 +1,221 @@ +package pc.exam.pp.module.exam.service.wps.xlsx; + +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.xlsx.XlsxListReqVO; +import pc.exam.pp.module.exam.controller.admin.wps.vo.xlsx.XlsxSaveReqVO; +import pc.exam.pp.module.exam.dal.dataobject.wps.ExamWpsXlsx; +import pc.exam.pp.module.exam.dal.mysql.wps.ExamWpsXlsxMapper; + +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.*; + +/** + * Xlsx考点 Service 实现类 + * + * @author 朋辰 + */ +@Service +@Validated +@Slf4j +public class ExamWpsXlsxServiceImpl implements ExamWpsXlsxService { + + @Resource + private ExamWpsXlsxMapper XlsxMapper; + + @Override + public Long createXlsx(XlsxSaveReqVO createReqVO) { + if (createReqVO.getParentId() == null) { + createReqVO.setParentId(ExamWpsXlsx.PARENT_ID_ROOT); + } + // 校验父Xlsx考点的有效性 + validateParentXlsx(null, createReqVO.getParentId()); + // 校验Xlsx考点名的唯一性 + validateXlsxNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); + + // 插入Xlsx考点 + ExamWpsXlsx Xlsx = BeanUtils.toBean(createReqVO, ExamWpsXlsx.class); + XlsxMapper.insert(Xlsx); + return Xlsx.getId(); + } + + @Override + public void updateXlsx(XlsxSaveReqVO updateReqVO) { + if (updateReqVO.getParentId() == null) { + updateReqVO.setParentId(ExamWpsXlsx.PARENT_ID_ROOT); + } + // 校验自己存在 + validateXlsxExists(updateReqVO.getId()); + // 校验父Xlsx考点的有效性 + validateParentXlsx(updateReqVO.getId(), updateReqVO.getParentId()); + // 校验Xlsx考点名的唯一性 + validateXlsxNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); + + // 更新Xlsx考点 + ExamWpsXlsx updateObj = BeanUtils.toBean(updateReqVO, ExamWpsXlsx.class); + XlsxMapper.updateById(updateObj); + } + + @Override + public void deleteXlsx(Long id) { + // 校验是否存在 + validateXlsxExists(id); + // 校验是否有子Xlsx考点 + if (XlsxMapper.selectCountByParentId(id) > 0) { + throw exception(XLSX_EXITS_CHILDREN); + } + // 删除Xlsx考点 + XlsxMapper.deleteById(id); + } + + @VisibleForTesting + void validateXlsxExists(Long id) { + if (id == null) { + return; + } + ExamWpsXlsx Xlsx = XlsxMapper.selectById(id); + if (Xlsx == null) { + throw exception(XLSX_NOT_FOUND); + } + } + + @VisibleForTesting + void validateParentXlsx(Long id, Long parentId) { + if (parentId == null || ExamWpsXlsx.PARENT_ID_ROOT.equals(parentId)) { + return; + } + // 1. 不能设置自己为父Xlsx考点 + if (Objects.equals(id, parentId)) { + throw exception(XLSX_PARENT_ERROR); + } + // 2. 父Xlsx考点不存在 + ExamWpsXlsx parent = XlsxMapper.selectById(parentId); + if (parent == null) { + throw exception(XLSX_PARENT_NOT_EXITS); + } + // 3. 递归校验父Xlsx考点,如果父Xlsx考点是自己的子Xlsx考点,则报错,避免形成环路 + 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(XLSX_PARENT_IS_CHILD); + } + // 3.2 继续递归下一级父Xlsx考点 + if (parentId == null || ExamWpsXlsx.PARENT_ID_ROOT.equals(parentId)) { + break; + } + parent = XlsxMapper.selectById(parentId); + if (parent == null) { + break; + } + } + } + + @VisibleForTesting + void validateXlsxNameUnique(Long id, Long parentId, String name) { + ExamWpsXlsx dept = XlsxMapper.selectByParentIdAndName(parentId, name); + if (dept == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的Xlsx考点 + if (id == null) { + throw exception(XLSX_NAME_DUPLICATE); + } + if (ObjectUtil.notEqual(dept.getId(), id)) { + throw exception(XLSX_NAME_DUPLICATE); + } + } + + @Override + public ExamWpsXlsx getXlsx(Long id) { + return XlsxMapper.selectById(id); + } + + @Override + public ExamWpsXlsx getXlsxByTitle(String title) { + return XlsxMapper.selectByTitle(title); + } + + @Override + public List getXlsxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return Collections.emptyList(); + } + return XlsxMapper.selectBatchIds(ids); + } + + @Override + public List getXlsxList(XlsxListReqVO reqVO) { + List list = XlsxMapper.selectList(reqVO); + list.sort(Comparator.comparing(ExamWpsXlsx::getSort)); + return list; + } + + @Override + public Map getXlsxMap(Collection ids) { + return ExamWpsXlsxService.super.getXlsxMap(ids); + } + + @Override + public List getChildXlsxList(Long id) { + return ExamWpsXlsxService.super.getChildXlsxList(id); + } + + @Override + public List getChildXlsxList(Collection ids) { + List children = new LinkedList<>(); + // 遍历每一层 + Collection parentIds = ids; + for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环 + // 查询当前层,所有的子Xlsx考点 + List Xlsxs = XlsxMapper.selectListByParentId(parentIds); + // 1. 如果没有子Xlsx考点,则结束遍历 + if (CollUtil.isEmpty(Xlsxs)) { + break; + } + // 2. 如果有子Xlsx考点,继续遍历 + children.addAll(Xlsxs); + parentIds = convertSet(Xlsxs, ExamWpsXlsx::getId); + } + return children; + } + + @Override + public Set getChildXlsxIdListFromCache(Long id) { + List children = getChildXlsxList(id); + return convertSet(children, ExamWpsXlsx::getId); + } + + @Override + public void validateXlsxList(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return; + } + // 获得科室信息 + Map XlsxMap = getXlsxMap(ids); + // 校验 + ids.forEach(id -> { + ExamWpsXlsx 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()); + } + }); + } + +} 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 deleted file mode 100644 index ee57d264..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/WpsController.java +++ /dev/null @@ -1,87 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps; - -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; -import pc.exam.pp.framework.common.pojo.CommonResult; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService; -import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService; -import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService; -import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; - -import java.util.List; - -/** - * wps word - * rwb - * @author REN - */ - -@RestController -@RequestMapping("/tool/wps") -@Tag( name = "测试判分 - wps相关操作") -@Validated -public class WpsController { - - @Resource - JudgementWpsWordService judgementWpsWordService; - @Resource - JudgementWpsPptxService judgementWpsPptxService; - @Resource - JudgementWpsExcelService judgementWpsExcelService; - - -// @PostMapping("/docxMaster") -// public CommonResult> docxMaster(@RequestBody List wpsDocxInfoVos) throws Exception { -// return CommonResult.success(judgementWpsWordService.docxMaster(wpsDocxInfoVos)); -// } -// /** -// * wps word -// * @return 判分 -// */ -// @PostMapping("/runWpsWordInfo") -// public CommonResult> runWpsWordInfo(@RequestBody List wordReqDto) throws Exception { -// return CommonResult.success(judgementWpsWordService.programmingInfo(wordReqDto)); -// } -// -// /** -// * wps word -// * @return 判分 -// */ -// @GetMapping("/runWpsWord") -// public CommonResult> runWpsWord(String path) throws Exception { -// return CommonResult.success(judgementWpsWordService.programmingWpsWord(path)); -// } -// /** -// * wps xlsx -// * @return 判分 -// */ -// @GetMapping("/runWpsPptx") -// public CommonResult> runWpsPptx(String path) throws Exception { -// 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)); - } - -} 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 deleted file mode 100644 index 20eb7cb8..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/XlsxController.java +++ /dev/null @@ -1,75 +0,0 @@ -//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/controller/admin/Wps/dto/WpsPptxJudgementDto.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsPptxJudgementDto.java deleted file mode 100644 index 8c5bcdea..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsPptxJudgementDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.dto; - -import lombok.Data; - -/** - * @author REN - */ -@Data -public class WpsPptxJudgementDto { - private String content; - private String contentIn; - private String image; - private String scoreRate; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordChineseFunctionDto.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordChineseFunctionDto.java deleted file mode 100644 index f83b4c0d..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordChineseFunctionDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.dto; - -import lombok.Data; - -/** - * @author REN - */ -@Data -public class WpsWordChineseFunctionDto { - - private String chineseName; - private String function; - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordJudgementDto.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordJudgementDto.java deleted file mode 100644 index 9b9d4423..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordJudgementDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.dto; - -import lombok.Data; - -/** - * @author REN - */ -@Data -public class WpsWordJudgementDto { - private String content; - private String contentIn; - private String image; - private String scoreRate; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordReqDto.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordReqDto.java deleted file mode 100644 index 06692f7e..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/dto/WpsWordReqDto.java +++ /dev/null @@ -1,39 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.List; - -/** - * @author REN - */ -@Data -public class WpsWordReqDto { - - @Schema(description = "主中文名称") - private String name; - - @Schema(description = "主英文名称") - private String englishName; - - @Schema(description = "文件路径") - private String filePath; - - @Schema(description = "内外参数(0:内参数;1:外参数)") - private String type; - - @Schema(description = "归属(0:段落;1:页眉页脚;2:图形)") - private String belongTo; - - @Schema(description = "参数类型(0:值;1:判断)") - private String isboo; - - @Schema(description = "子标签") - private String function; - - private String unit; - - private String isExam; - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordListReqVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordListReqVO.java deleted file mode 100644 index 3245ae29..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordListReqVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - WpsWord对应关系 Request VO") -@Data -public class WordListReqVO { - - @Schema(description = "节点名称模糊匹配", example = "芋道") - private String name; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - /** - * 类型 - */ - private Integer type; - - private String nodeFunction; - private Integer isboo; - private Integer belongTo; - private Integer titleType; - private String unit; - private String page; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordRespVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordRespVO.java deleted file mode 100644 index 651e6ec7..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordRespVO.java +++ /dev/null @@ -1,44 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 节点信息 Response VO") -@Data -public class WordRespVO { - - @Schema(description = "节点编号", example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - private String name; - - @Schema(description = "父节点 ID", example = "1024") - private Long parentId; - - @Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer sort; - - @Schema(description = "节点方法") - private String nodeFunction; - - @Schema(description = "转中文") - private String toChinese; - - @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") - private LocalDateTime createTime; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; - private Integer isboo; - private Integer titleType; - private String unit; - private String page; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSaveReqVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSaveReqVO.java deleted file mode 100644 index 533693d3..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSaveReqVO.java +++ /dev/null @@ -1,49 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -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 = "管理后台 - 节点创建/修改 Request VO") -@Data -public class WordSaveReqVO { - - @Schema(description = "节点编号", example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - @NotBlank(message = "节点名称不能为空") - private String name; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; - - @Schema(description = "父节点 ID", example = "1024") - private Long parentId; - - @Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "显示顺序不能为空") - private Integer sort; - - @Schema(description = "节点方法") - private String nodeFunction; - - @Schema(description = "转中文") - private String toChinese; - - @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "状态不能为空") - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") - private Integer status; - private Integer isboo; - private Integer titleType; - private String unit; - private String page; - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSimpleRespVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSimpleRespVO.java deleted file mode 100644 index a36e08af..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/WordSimpleRespVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -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 WordSimpleRespVO { - - @Schema(description = "节点编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - private String name; - - @Schema(description = "父节点 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long parentId; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; - private Integer isboo; - private Integer titleType; - private String unit; - private String page; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxListReqVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxListReqVO.java deleted file mode 100644 index 18502ffe..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxListReqVO.java +++ /dev/null @@ -1,21 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - WpsWord对应关系 Request VO") -@Data -public class XlsxListReqVO { - - @Schema(description = "节点名称模糊匹配", example = "芋道") - private String name; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - /** - * 类型 - */ - private Integer type; - - private Integer belongTo; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxRespVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxRespVO.java deleted file mode 100644 index cf7e1262..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxRespVO.java +++ /dev/null @@ -1,40 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 节点信息 Response VO") -@Data -public class XlsxRespVO { - - @Schema(description = "节点编号", example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - private String name; - - @Schema(description = "父节点 ID", example = "1024") - private Long parentId; - - @Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer sort; - - @Schema(description = "节点方法") - private String nodeFunction; - - @Schema(description = "转中文") - private String toChinese; - - @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") - private LocalDateTime createTime; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSaveReqVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSaveReqVO.java deleted file mode 100644 index cbdf9653..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSaveReqVO.java +++ /dev/null @@ -1,45 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -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 = "管理后台 - 节点创建/修改 Request VO") -@Data -public class XlsxSaveReqVO { - - @Schema(description = "节点编号", example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - @NotBlank(message = "节点名称不能为空") - private String name; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; - - @Schema(description = "父节点 ID", example = "1024") - private Long parentId; - - @Schema(description = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "显示顺序不能为空") - private Integer sort; - - @Schema(description = "节点方法") - private String nodeFunction; - - @Schema(description = "转中文") - private String toChinese; - - @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "状态不能为空") - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") - private Integer status; - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSimpleRespVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSimpleRespVO.java deleted file mode 100644 index ce72483d..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/controller/admin/Wps/vo/XlsxSimpleRespVO.java +++ /dev/null @@ -1,27 +0,0 @@ -package pc.exam.pp.module.judgement.controller.admin.Wps.vo; - -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 XlsxSimpleRespVO { - - @Schema(description = "节点编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "节点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - private String name; - - @Schema(description = "父节点 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long parentId; - /** - * 类型 - */ - private Integer type; - private Integer belongTo; -} 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 d8d8b476..b15b2d59 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 @@ -1,10 +1,6 @@ package pc.exam.pp.module.judgement.service.wps_excel; - -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -import java.util.List; - /** * 判分逻辑集合(wps excel) * @@ -18,6 +14,5 @@ public interface JudgementWpsExcelService { * @return 文件内得考点及描述 * @throws Exception 异常 */ - List programmingWpsExcel(String path) 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 35c78dd9..3344c2dd 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 @@ -2,69 +2,10 @@ package pc.exam.pp.module.judgement.service.wps_excel; -import jakarta.annotation.Resource; import org.springframework.stereotype.Service; -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.utils.wps_excel.WpsExcelUtils; - -import java.io.*; -import java.net.URL; -import java.net.URLConnection; -import java.util.List; @Service public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService { -// @Resource -// AutoToolsService autoToolsService; - @Resource - ConfigService configService; - - @Override - public List programmingWpsExcel(String path) throws Exception { - // 1、获取文件临时下载路径 - ConfigDO config = configService.getConfigByKey("file_down_path"); - // 2、下载文件并返回文件完整路径 - String pathName = downloadStudentFile(path, config.getValue()); - List margins = WpsExcelUtils.wpsExcel(pathName, "1"); - // 5、已经读取完得考点删除源文件 - File file = new File(pathName); - file.delete(); - return margins; - } - public String downloadStudentFile(String fileUrl, String filePath) { - try { - URL url = new URL(fileUrl); - URLConnection connection = url.openConnection(); - - String fileName = new File(url.getPath()).getName(); - File dir = new File(filePath); - if (!dir.exists()) dir.mkdirs(); - - File saveFile = new File(dir, fileName); - - try (InputStream in = connection.getInputStream(); - FileOutputStream out = new FileOutputStream(saveFile)) { - - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - } - - System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath()); - return saveFile.getAbsolutePath(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } catch (IOException e) { - System.err.println("❌ 下载失败: " + e.getMessage()); - return null; - } - } } 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 c35f5cdc..b0f903ea 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 @@ -1,29 +1,15 @@ package pc.exam.pp.module.judgement.service.wps_pptx; -import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -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.AutoWps.vo.WpsSlideInfoVo; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -//import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService; -import pc.exam.pp.module.judgement.utils.wps_pptx.JudgementWpsPPT; -import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideConversion; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideMaster; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO; import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO; -import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo; -import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO; -import pc.exam.pp.module.system.service.user.AdminUserService; -import java.io.*; -import java.net.URL; -import java.net.URLConnection; import java.util.List; -import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; /** * @author REN 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 80fbe5ee..0a9cd860 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 @@ -1,913 +1,1094 @@ -package pc.exam.pp.module.judgement.utils.wps_excel; - -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.DateUtil; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; -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 javax.xml.namespace.QName; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -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 WpsExcelUtils { - - public static final String namespace = "declare namespace ns='http://schemas.openxmlformats.org/spreadsheetml/2006/main' "; - - public static final List> drawingSheetVOS = new ArrayList<>(); - - 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); +//package pc.exam.pp.module.judgement.utils.wps_excel; +// +//import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +//import org.apache.poi.openxml4j.opc.OPCPackage; +//import org.apache.poi.ss.usermodel.Cell; +//import org.apache.poi.ss.usermodel.CellStyle; +//import org.apache.poi.ss.usermodel.DateUtil; +//import org.apache.poi.ss.usermodel.Row; +//import org.apache.poi.xssf.usermodel.XSSFSheet; +//import org.apache.poi.xssf.usermodel.XSSFWorkbook; +//import org.apache.xmlbeans.XmlCursor; +//import org.apache.xmlbeans.XmlObject; +//import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto; +//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 javax.xml.namespace.QName; +//import java.io.FileInputStream; +//import java.io.IOException; +//import java.io.InputStream; +//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 WpsExcelUtils { +// +// public static final String namespace = "declare namespace ns='http://schemas.openxmlformats.org/spreadsheetml/2006/main' "; +// +// public static final List> drawingSheetVOS = new ArrayList<>(); +// +// 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); - - 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, String index) throws Exception { - // 获取共享字符串 - String[] sharedStrings = extractSharedStrings(filePath); - // 读取样式xml - XmlCursor styleXml = extractStyleXml(filePath); - // 作簿中的数据连接(Data Connections),即 Excel 与外部数据源(如数据库、Web 服务、其他文件等)的链接信息 - XmlCursor connectionsXml = extractConnectionsXml(filePath); - // 获取工作簿中的图表数据 -// List chartListXmls = extractChartXml(filePath); - getDrawingInfos(filePath); - // 单元格数据 - List xlsxInfoVos = new ArrayList<>(); - try (FileInputStream fis = new FileInputStream(filePath); - OPCPackage pkg = OPCPackage.open(fis); - XSSFWorkbook workbook = new XSSFWorkbook(pkg)) { - // 获取有多少个工作表 - int sheetNumber = workbook.getNumberOfSheets(); - for (int i = 0; i < sheetNumber; i++) { -// System.out.println("第 " + (i + 1) + " 个工作表"); - // 获取工作表内容 - XSSFSheet sheetXss = workbook.getSheetAt(i); - // 获取工作表的XML对象 - XmlObject worksheetXml = sheetXss.getCTWorksheet(); - // 读取条件格式,并转化条件 - XmlCursor conditionalFormatting = worksheetXml.newCursor(); - conditionalFormatting.selectPath(namespace + "//ns:conditionalFormatting"); - String sqref = ""; - String formula = ""; - boolean conditionalFormattingFlag = false; - if (conditionalFormatting.toNextSelection()) { - conditionalFormattingFlag = true; - // 使用了条件格式,作用范围 - XmlCursor sqrefXml = conditionalFormatting.getObject().newCursor(); - sqrefXml.selectPath(namespace + "./@sqref"); - if (sqrefXml.toNextSelection()) { - sqref = sqrefXml.getTextValue(); - } - // 查询条件 - XmlCursor cfRuleXml = conditionalFormatting.getObject().newCursor(); - cfRuleXml.selectPath(namespace + "./ns:cfRule"); - if (cfRuleXml.toNextSelection()){ - dxfId = Integer.parseInt(cfRuleXml.getAttributeText(new QName("dxfId"))); - XmlCursor formulaXml = cfRuleXml.getObject().newCursor(); - formulaXml.selectPath(namespace + "./ns:formula"); - if (formulaXml.toNextSelection()) { - formula = cfRuleXml.getTextValue(); - } - } - } - try (XmlCursor cursor = worksheetXml.newCursor()) { -// drawingXmlInfo(cursor, String.valueOf(i+1)); - // 查询所有 row 元素 - cursor.selectPath(namespace + "//ns:worksheet/ns:sheetData/ns:row"); - int rowIndex = 0; - while (cursor.toNextSelection()) { - // 行的参数 - XmlCursor rowXml = cursor.getObject().newCursor(); - addXlsxInfo(String.valueOf(i+1), "行高", "ns:row/@ht", rowXml.getAttributeText(new QName("ht")), "row", "行" + rowXml.getAttributeText(new QName("r")), "style", "样式", "r"+rowXml.getAttributeText(new QName("r")), xlsxInfoVos); - addXlsxInfo(String.valueOf(i+1), "行高", "ns:row/@ht", rowXml.getAttributeText(new QName("ht")), "row", "行" + rowXml.getAttributeText(new QName("r")),"style", "样式", "r"+rowXml.getAttributeText(new QName("r")), xlsxInfoVos); - - - try (XmlCursor rowCursor = rowXml.newCursor()) { - rowCursor.selectPath(namespace + "./ns:c"); - // 接着获取单元格 - int colIndex = 0; - while (rowCursor.toNextSelection()) { - // 判断是否使用了条件样式进行判断值 - boolean isConditionalFormatting = false; - if (conditionalFormattingFlag) { - // 进行拆分单元格 - // 1. 提取列字母(正则匹配 $K2 或 K2) - // 字符串替换 - String formulas = formula.replaceAll("\\$", "").split("=")[0]; - Pattern pattern = Pattern.compile("^[A-Za-z]+"); - Matcher matcher = pattern.matcher(formulas); - String colLetters = ""; - while (matcher.find()) { - colLetters = matcher.group(0); - } - int colIndexMatcher = columnLetterToNumber(colLetters); - // 读取指定单元格 - Row row = sheetXss.getRow(rowIndex); - if (row == null) break; - Cell cell = row.getCell(colIndexMatcher-1); - String value = getCellValue(cell); - // 获取对比值 - String compareValue = formula.split("=")[1].replace("\"", "");; - if (Objects.equals(value, compareValue)) { - isConditionalFormatting = true; - } - } - Row row = sheetXss.getRow(rowIndex); - if (row == null) break; - // 获取行属性 - Cell cell = row.getCell(colIndex); - if (row != null && cell != null) { - // 获取单元格 - String rowName = rowCursor.getAttributeText(new QName("r")); - // 获取style编号 - String styleId = rowCursor.getAttributeText(new QName("s")); - // 获取共享字符串 - String tName = rowCursor.getAttributeText(new QName("t")); - // 获取具体的值 - try (XmlCursor valueXml = rowCursor.getObject().newCursor()) { - String value = ""; - valueXml.selectPath(namespace + "./ns:v"); - if (valueXml.toNextSelection()) { - value = valueXml.getTextValue(); - } - // 如果是共享字符串 - if (tName != null && tName.equals("s")) { - value = sharedStrings[Integer.parseInt(value)]; - addXlsxInfo(String.valueOf(i+1), "单元格文本", "ns:celltext", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); - } else { - addXlsxInfo(String.valueOf(i+1), "单元格文本", "ns:celltext", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); - } - - valueXml.dispose(); - } - // 获取公式 - try (XmlCursor formulaXml = rowCursor.getObject().newCursor()) { - String value = ""; - formulaXml.selectPath(namespace + "./ns:f"); - if (formulaXml.toNextSelection()) { - value = formulaXml.getTextValue(); - addXlsxInfo(String.valueOf(i+1), "单元格公式", "ns:formula", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); - } - formulaXml.dispose(); - } - // 获取单元格的格式 - CellStyle cellStyle = cell.getCellStyle(); -// System.out.println(rowIndex + "-" +colIndex); - short dataFormat = cellStyle.getDataFormat(); - String formatString = cellStyle.getDataFormatString(); -// System.out.println(formatString); - boolean isMerge = !formatString.equals("General"); -// System.out.println(rowName); - if (styleId != null) { - extractStyle(xlsxInfoVos, Integer.parseInt(styleId), styleXml, true, rowName, String.valueOf(i + 1), isConditionalFormatting); - } - XmlCursor cellXml = rowCursor.getObject().newCursor(); - cellXml.dispose(); - } - colIndex ++; - } - rowCursor.dispose(); - rowIndex ++; - } - rowXml.dispose(); - } - cursor.dispose(); - } catch (Exception e) { - e.printStackTrace(); - } - - List chartTypeEntries = getChartTypes(); - - - // 开始获取图表等信息(包含数据透视表) - try (XmlCursor drawingXmlcursor = worksheetXml.newCursor()) { - drawingXmlcursor.selectPath(namespace + "./ns:drawing"); - while (drawingXmlcursor.toNextSelection()) { - try (XmlCursor drawingXml = drawingXmlcursor.getObject().newCursor()) { - // 上指定的drawingList下进行查找 - List xlsxDrawingSheetVos = drawingSheetVOS.get(i); - // 1、已经获取到了对应sheet下的图表信息等 - // 开始进行查询 - for (XlsxDrawingSheetVo xlsxDrawingSheetVo : xlsxDrawingSheetVos) { - // TODO 校验文件名称有问题 - if (xlsxDrawingSheetVo.getTypeName().contains("chart")) { - // 添加考点 - addXlsxInfo(String.valueOf(i+1), "图表是否存在", "isChart", String.valueOf(0), "chart", "图表", "isChart", "是否存在", "", xlsxInfoVos); - // 说明是图表 - try (XmlCursor chartXml = xlsxDrawingSheetVo.getXmlCursor().newCursor()) { -// System.out.println(chartXml.xmlText()); - String chartNameSpace = getNamespace(chartXml.xmlText()); - // 开始获取标题 - XlsxInfoVo xlsxInfoVo = new XlsxInfoVo(); - XmlCursor titleXml = chartXml.newCursor(); -// System.out.println(titleXml.xmlText()); - titleXml.selectPath(chartNameSpace + ".//c:chart/c:title/c:tx/c:rich"); - while (titleXml.toNextSelection()) { - addXlsxInfo(String.valueOf(i+1), "图表标题是否存在", "isTitle", String.valueOf(0), "chart", "图表", "title", "标题", "", xlsxInfoVos); - - XmlCursor titleAnchorXml = titleXml.newCursor(); - titleAnchorXml.selectPath(chartNameSpace + ".//a:bodyPr/@anchor"); - if (titleAnchorXml.toNextSelection()) { - addXlsxInfo(String.valueOf(i+1), "图表标题位置", "a:bodyPr/@anchor", titleAnchorXml.getTextValue(), "chart", "图表", "title", "标题", "", xlsxInfoVos); - } - XmlCursor titleNameXml = titleXml.newCursor(); - titleNameXml.selectPath(chartNameSpace + ".//a:p/a:r/a:t"); - if (titleNameXml.toNextSelection()) { - addXlsxInfo(String.valueOf(i+1), "图表标题文本", "a:p/a:r/a:t", titleNameXml.getTextValue(), "chart", "图表", "title", "标题", "", xlsxInfoVos); - } - } -// titleXml.dispose(); - XmlCursor charTypeXml = chartXml.newCursor(); - charTypeXml.selectPath(chartNameSpace + ".//c:chart/c:plotArea"); - while (charTypeXml.toNextSelection()) { - addXlsxInfo(String.valueOf(i+1), "绘图是否存在", "c:chart/c:plotArea", String.valueOf(0), "chart", "图表", "plotArea", "绘图", "", xlsxInfoVos); - // 获取图表类型 - for (ChartTypeEntry chartTypeEntry : chartTypeEntries) { - XmlCursor charTypeXmlInfo = charTypeXml.newCursor(); - // 判断是否存在参数 -// System.out.println(charTypeXmlInfo.xmlText()); -// System.out.println(".//c:plotArea/" + chartTypeEntry.getTag()); - charTypeXmlInfo.selectPath(chartNameSpace + "./" + chartTypeEntry.getTag()); - if (charTypeXmlInfo.toNextSelection()) { - if (chartTypeEntry.getTag().equals("c:barChart")) { - // 说明要在继续判断值 - charTypeXmlInfo.selectPath(chartNameSpace + ".//c:barDir/@val"); - if (charTypeXmlInfo.toNextSelection()) { - String value = charTypeXmlInfo.getTextValue(); - if (value.equals("col")) { - addXlsxInfo(String.valueOf(i+1), "图表类型", "c:barDir/@val", "簇型柱状图", "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); - } - } else { - addXlsxInfo(String.valueOf(i+1), "图表类型", chartTypeEntry.getTag(), chartTypeEntry.getDisplayName(), "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); - } - } else { - addXlsxInfo(String.valueOf(i+1), "图表类型", chartTypeEntry.getTag(), chartTypeEntry.getDisplayName(), "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); - } - - } - } - - // 获取X,Y轴信息 - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidFormatException e) { - throw new RuntimeException(e); - } - List xlsxInfos = new ArrayList<>(); - for (XlsxInfoVo xlsxInfoVo : xlsxInfoVos) { - WpsPptxJudgementDto wpsPptxJudgementDto = new WpsPptxJudgementDto(); - wpsPptxJudgementDto.setContentIn(xlsxInfoVo.getSheetName() + "@" + xlsxInfoVo.getTypeName() + "@" + xlsxInfoVo.getCell() + "@" + xlsxInfoVo.getSecondTypeName() + "@" + xlsxInfoVo.getChineseName() + "@"+ xlsxInfoVo.getValue()); - wpsPptxJudgementDto.setContent(xlsxInfoVo.getSheetName() + "@" + xlsxInfoVo.getType() + "@" + xlsxInfoVo.getCell() + "@" + xlsxInfoVo.getSecondType() + "@" + xlsxInfoVo.getEnglishName() + "@"+ xlsxInfoVo.getValue()); - wpsPptxJudgementDto.setScoreRate("1"); - xlsxInfos.add(wpsPptxJudgementDto); - } - return xlsxInfos; - } - - // 扁平化多维列表 - public static List getRandomItems(List list, int count) { - List copy = new ArrayList<>(list); // 创建副本,避免修改原列表 - Collections.shuffle(copy); // 打乱顺序 - return copy.subList(0, Math.min(count, copy.size())); // 抽取前count个 - } - - // 支持所有类型的单元格 - private static String getCellValue(Cell cell) { - switch (cell.getCellType()) { - case STRING: - return cell.getStringCellValue(); - - case NUMERIC: - if (DateUtil.isCellDateFormatted(cell)) { - return cell.getDateCellValue().toString(); - } - return String.valueOf(cell.getNumericCellValue()); - - case BOOLEAN: - return String.valueOf(cell.getBooleanCellValue()); - - case FORMULA: - return cell.getCellFormula(); // 或者用 cell.getNumericCellValue() 等 - - case BLANK: - return ""; - - default: - return "[UNKNOWN TYPE]"; - } - } - - public static int columnLetterToNumber(String column) { - int result = 0; - for (int i = 0; i < column.length(); i++) { - result = result * 26 + (column.charAt(i) - 'A' + 1); - } - return result; - } - - - public static boolean isCellInRange(String cellRef, String rangeRef) { - int[] cellPos = parseCellRef(cellRef); // [col, row] - int[] startPos = parseCellRef(rangeRef.split(":")[0]); // A2 - int[] endPos = parseCellRef(rangeRef.split(":")[1]); // O18 - - return cellPos[0] >= startPos[0] && cellPos[0] <= endPos[0] && - cellPos[1] >= startPos[1] && cellPos[1] <= endPos[1]; - } - - public static int[] parseCellRef(String ref) { - String colLetters = ref.replaceAll("\\d", ""); // 取字母部分,如 A - String rowDigits = ref.replaceAll("\\D", ""); // 取数字部分,如 7 - - int colNum = columnNameToIndex(colLetters); - int rowNum = Integer.parseInt(rowDigits); - return new int[]{colNum, rowNum}; - } - - public static int columnNameToIndex(String column) { - int result = 0; - for (int i = 0; i < column.length(); i++) { - result = result * 26 + (column.charAt(i) - 'A' + 1); - } - return result; - } - - - public static List getChartTypes() { - // 创建一个图表 - List chartTypes = new ArrayList<>(); - chartTypes.add(new ChartTypeEntry("c:barChart", "横向柱状图")); - chartTypes.add(new ChartTypeEntry("c:lineChart", "折线图")); - chartTypes.add(new ChartTypeEntry("c:pieChart", "饼图")); - chartTypes.add(new ChartTypeEntry("c:areaChart", "面积图")); - chartTypes.add(new ChartTypeEntry("c:scatterChart", "散点图")); - chartTypes.add(new ChartTypeEntry("c:bubbleChart", "气泡图")); - chartTypes.add(new ChartTypeEntry("c:radarChart", "雷达图")); - chartTypes.add(new ChartTypeEntry("c:stockChart", "股票图")); - chartTypes.add(new ChartTypeEntry("c:surfaceChart", "曲面图")); - chartTypes.add(new ChartTypeEntry("c:ofPieChart", "分类饼图(饼中饼/条中饼)")); - chartTypes.add(new ChartTypeEntry("c:doughnutChart", "圆环图")); - chartTypes.add(new ChartTypeEntry("c:bar3DChart", "3D柱状图")); - chartTypes.add(new ChartTypeEntry("c:line3DChart", "3D折线图")); - chartTypes.add(new ChartTypeEntry("c:area3DChart", "3D面积图")); - chartTypes.add(new ChartTypeEntry("c:surface3DChart", "3D曲面图")); - return chartTypes; - } - - public static void addXlsxInfo(String sheetName, String chineseName, String englishName, String value, String type, String typeName, String secondType, String secondTypeName, String cellName, List xlsxInfoVos) { - XlsxInfoVo xlsxInfoVo = new XlsxInfoVo(); - xlsxInfoVo.setSheetNumber(sheetName); - // 拼接数据 - sheetName = "【sheet" + sheetName + "】"; - xlsxInfoVo.setSheetName(sheetName); - xlsxInfoVo.setChineseName(chineseName); - xlsxInfoVo.setEnglishName(englishName); - xlsxInfoVo.setValue(value); - xlsxInfoVo.setType(type); - xlsxInfoVo.setTypeName(typeName); - xlsxInfoVo.setCell(cellName); - xlsxInfoVo.setSecondType(secondType); - xlsxInfoVo.setSecondTypeName(secondTypeName); - xlsxInfoVos.add(xlsxInfoVo); - } - - public static String drawingXmlInfo(XmlCursor cursor, String sheetName) throws Exception { - // 判断是否存在表格数据 标签数据 - try (XmlCursor drawingXml = cursor.newCursor()) { - drawingXml.selectPath(namespace + "./ns:drawing"); - int drawingIndex = 0; - while (drawingXml.toNextSelection()) { - try (XmlCursor drawingXmlCursor = drawingXml.getObject().newCursor()) { -// System.out.println(drawingXmlCursor.xmlText()); - drawingXmlCursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' ./@r:id"); - if (drawingXmlCursor.toNextSelection()) { - String rId = drawingXmlCursor.getTextValue(); - - } - } - drawingIndex ++; - } - } - return ""; - } - - /** - * 从 Excel 文件中提取共享字符串 - * @param excelFilePath Excel 文件路径 - * @return 共享字符串数组 - * @throws Exception 如果文件不存在或无法读取,则抛出异常 - */ - public static String[] extractSharedStrings(String excelFilePath) throws Exception { - // 解压 Excel 文件并读取 sharedStrings.xml - ZipFile zipFile = new ZipFile(excelFilePath); - // 找到 sharedStrings.xml 文件的路径 - ZipEntry sharedStringsEntry = zipFile.getEntry("xl/sharedStrings.xml"); - - // 如果找不到 sharedStrings.xml,则返回空数组 - if (sharedStringsEntry == null) { - zipFile.close(); - return new String[0]; - } - - // 读取 sharedStrings.xml 文件 - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - // 查询所有 sharedString 元素 - cursor.selectPath(namespace + "//ns:sst/ns:si"); - - List sharedStringList = new ArrayList<>(); - - // 遍历每个 sharedString 元素并提取文本值 - while (cursor.toNextSelection()) { - // 获取单元格内容 - String sharedString = cursor.getTextValue(); - sharedStringList.add(sharedString); - } - - cursor.dispose(); // 关闭游标 - zipFile.close(); // 关闭 zip 文件 - - // 将 List 转换为数组并返回 - return sharedStringList.toArray(new String[0]); - } - - public static XmlCursor extractStyle(List xlsxInfoVos, int serialNumber, XmlCursor cursor, boolean isTrue, String colName, String sheetName, boolean isCellStyle) throws Exception { - XmlCursor xmlCursor = cursor.newCursor(); - if (isTrue) { - // 自定义格式 - xmlCursor.selectPath(namespace + "//ns:cellXfs/ns:xf"); - } else { -// xlsxStyleCellStyleXfxVo.setCol(colName); - xmlCursor.selectPath(namespace + "//ns:cellStyleXfs/ns:xf"); - } - int index = 0; - String numFmtId = null; - String fontId = null; - String fillId = null; - String borderId = null; - String applyFont = null; - String applyFill = null; - String applyProtection = null; - String wrapText = null; - String textRotation = null; - String shrinkToFit = null; - String applyBorder = null; - String applyNumberFormat = null; - String applyAlignment = null; - while(xmlCursor.toNextSelection()) { - // 通过序号查询指定数据 - if (index == serialNumber) { - XmlCursor designateXml = xmlCursor.getObject().newCursor(); - // 数字格式的ID - numFmtId = designateXml.getAttributeText(new QName("numFmtId")); - // 字体的ID - fontId = designateXml.getAttributeText(new QName("fontId")); - // 填充(背景颜色)的ID - fillId = designateXml.getAttributeText(new QName("fillId")); - // 边框样式的ID - borderId = designateXml.getAttributeText(new QName("borderId")); - // 字体设置 - applyFont = designateXml.getAttributeText(new QName("applyFont")); - // 背景填充 - applyFill = designateXml.getAttributeText(new QName("applyFill")); - // 表示不应用保护设置(即不锁定单元格) - applyProtection = designateXml.getAttributeText(new QName("applyProtection")); - // 文本旋转45度 - wrapText = designateXml.getAttributeText(new QName("wrapText")); - // 文本缩进一级。 - textRotation = designateXml.getAttributeText(new QName("textRotation")); - // 启用文本自动缩小以适应单元格。 - shrinkToFit = designateXml.getAttributeText(new QName("shrinkToFit")); - applyBorder = designateXml.getAttributeText(new QName("applyBorder")); - applyNumberFormat = designateXml.getAttributeText(new QName("applyNumberFormat")); - applyAlignment = designateXml.getAttributeText(new QName("applyAlignment")); - designateXml.selectPath(namespace + "./ns:alignment"); - if (designateXml.toNextSelection()) { - // 获取 水平对齐 属性 - String horizontal = designateXml.getAttributeText(new QName("horizontal")); - // 获取 垂直对齐 属性 - String vertical = designateXml.getAttributeText(new QName("vertical")); - if (isTrue) { - addXlsxInfo(sheetName, "水平对齐", "vertical", horizontal, "cell", "单元格", "alignment", "对齐", colName, xlsxInfoVos); - addXlsxInfo(sheetName, "垂直对齐", "horizontal", vertical, "cell", "单元格", "alignment", "对齐", colName, xlsxInfoVos); - } else { -// xlsxStyleCellStyleXfxVo.setVertical(vertical); -// xlsxStyleCellStyleXfxVo.setHorizontal(horizontal); - } - } - break; - } - index ++; - } - // 接着进行查找 - if (numFmtId != null) { - try (XmlCursor cursorNumFmts = cursor.newCursor()) { - cursorNumFmts.selectPath(namespace + "//ns:numFmts/ns:numFmt"); - while (cursorNumFmts.toNextSelection()) { - // 获取 numFmtId 属性 - String numFmtIdInfo = cursorNumFmts.getAttributeText(new QName("numFmtId")); - if (numFmtIdInfo.equals(numFmtId)) { - // 获取 formatCode 属性 - String formatCode = cursorNumFmts.getAttributeText(new QName("formatCode")); - if (isTrue) { - addXlsxInfo(sheetName, "formatCode", "formatCode", formatCode, "cell", "单元格", "formatCode", "自定义格式", colName, xlsxInfoVos); - } else { -// xlsxStyleCellStyleXfxVo.setFormatCode(formatCode); - } - break; - } - } - } - } - xmlCursor.dispose(); - // 应用了字体设置 - if (fontId != null) { - try (XmlCursor cursorFonts = cursor.newCursor()) { - cursorFonts.selectPath(namespace + "//ns:fonts/ns:font"); - int fontIndex = 0; - while (cursorFonts.toNextSelection()) { - if (fontIndex == Integer.parseInt(fontId)) { - // 判断是否加粗(是否存在 标签) - try (XmlCursor cursorsFontBold = cursorFonts.getObject().newCursor()){ - cursorsFontBold.selectPath(namespace + "./ns:b"); - boolean isBold = cursorsFontBold.toNextSelection(); - addXlsxInfo(sheetName, "文本加粗", "ns:b", String.valueOf(isBold), "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - cursorsFontBold.dispose(); - } - // 获取 sz 的 val 属性(字体大小) - try (XmlCursor cursorsFontSz = cursorFonts.getObject().newCursor()){ - cursorsFontSz.selectPath(namespace + "./ns:sz"); - if (cursorsFontSz.toNextSelection()) { - String fontSize = cursorsFontSz.getAttributeText(new QName("val")); - addXlsxInfo(sheetName, "文本大小", "ns:sz", fontSize, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - } - cursorsFontSz.dispose(); - } - // 获取 color 的 rgb 属性(字体颜色) - try (XmlCursor cursorsFontColor = cursorFonts.getObject().newCursor()){ - cursorsFontColor.selectPath(namespace + "./ns:color"); - if (cursorsFontColor.toNextSelection()) { - String fontColor = cursorsFontColor.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "文本颜色", "ns:color", fontColor, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - } - cursorsFontColor.dispose(); - } - // 获取 name 的 val 属性(字体名称) - try (XmlCursor cursorsFontName = cursorFonts.getObject().newCursor()){ - cursorsFontName.selectPath(namespace + "./ns:name"); - if (cursorsFontName.toNextSelection()) { - String fontName = cursorsFontName.getAttributeText(new QName("val")); - addXlsxInfo(sheetName, "字体名称", "ns:name", fontName, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - - } - cursorsFontName.dispose(); - } - // 获取 charset 的 val 属性(字符集) - try (XmlCursor cursorsFontCharset = cursorFonts.getObject().newCursor()){ - cursorsFontCharset.selectPath(namespace + "./ns:charset"); - if (cursorsFontCharset.toNextSelection()) { - String fontCharset = cursorsFontCharset.getAttributeText(new QName("val")); - addXlsxInfo(sheetName, "字体字符集", "ns:charset", fontCharset, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - - } - cursorsFontCharset.dispose(); - } - // 获取 scheme 的 val 属性(字体方案) - try (XmlCursor cursorsFontScheme = cursorFonts.getObject().newCursor()){ - cursorsFontScheme.selectPath(namespace + "./ns:scheme"); - if (cursorsFontScheme.toNextSelection()) { - String fontScheme = cursorsFontScheme.getAttributeText(new QName("val")); - addXlsxInfo(sheetName, "字体方案", "ns:scheme", fontScheme, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - - } - cursorsFontScheme.dispose(); - } - break; - } - fontIndex ++; - } - cursorFonts.dispose(); - } - } - // 背景颜色填充 - if (fillId != null) { - try (XmlCursor cursorFills = cursor.newCursor()) { - if (!isCellStyle) { - cursorFills.selectPath(namespace + "//ns:fills/ns:fill"); - int fillIndex = 0; - while (cursorFills.toNextSelection()) { - if (fillIndex == Integer.parseInt(fillId)) { - try (XmlCursor cursorsFill = cursorFills.getObject().newCursor()) { - cursorsFill.selectPath(namespace + "./ns:patternFill"); - if (cursorsFill.toNextSelection()) { - // 获取 patternType 属性(填充样式) - String patternType = cursorsFill.getAttributeText(new QName("patternType")); - addXlsxInfo(sheetName, "填充样式", "ns:scheme/@theme", patternType, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); - // 获取 fgColor 的 theme 和 tint 属性(填充颜色) - try (XmlCursor cursorsFgColor = cursorsFill.getObject().newCursor()) { - cursorsFgColor.selectPath(namespace + "./ns:fgColor"); - if (cursorsFgColor.toNextSelection()) { - String theme = cursorsFgColor.getAttributeText(new QName("theme")); - String rgb = cursorsFgColor.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "填充theme", "ns:scheme/@theme", theme, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); - addXlsxInfo(sheetName, "填充颜色", "ns:fgColor/@rgb", rgb, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); - } - cursorsFgColor.dispose(); - } - // 获取 bgColor 的 indexed 属性(背景色) - try (XmlCursor cursorsBgColor = cursorFills.getObject().newCursor()) { - cursorsBgColor.selectPath(namespace + "./ns:bgColor"); - if (cursorsBgColor.toNextSelection()) { - String rgb = cursorsBgColor.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "背景色", "ns:bgColor/@rgb", rgb, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); - } - cursorsBgColor.dispose(); - } - } - } - break; - } - fillIndex ++; - } - cursorFills.dispose(); - } else { - XmlCursor cursorDxf = cursorFills.newCursor(); - cursorDxf.selectPath(namespace + "//ns:dxfs/ns:dxf"); - int dxfIndex = 0; - while (cursorDxf.toNextSelection()) { - if (dxfIndex == dxfId) { - XmlCursor fontXmlCursor = cursorDxf.getObject().newCursor(); - fontXmlCursor.selectPath(namespace + "./ns:font/color/@rgb"); - if (fontXmlCursor.toNextSelection()) { - addXlsxInfo(sheetName, "文本颜色", "ns:color", fontXmlCursor.getTextValue(), "cell", "单元格", "font", "字体", colName, xlsxInfoVos); - } - fontXmlCursor.dispose(); - XmlCursor fillXmlCursor = cursorDxf.getObject().newCursor(); - fillXmlCursor.selectPath(namespace + "./ns:fill/ns:patternFill/ns:bgColor/@rgb"); - if (fillXmlCursor.toNextSelection()) { - addXlsxInfo(sheetName, "背景色", "ns:bgColor/@rgb", fillXmlCursor.getTextValue(), "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); - } - fillXmlCursor.dispose(); - } - } - } - } - } - // 是否启用了边框设置 - if (borderId != null) { - try (XmlCursor cursorBorder = cursor.newCursor()) { - cursorBorder.selectPath(namespace + "//ns:borders/ns:border"); - int borderIndex = 0; - while (cursorBorder.toNextSelection()) { - if (borderIndex == Integer.parseInt(borderId)) { - // 定义对角线边框。常用于带有斜线的单元格。如果 标签存在,表示对角线有边框,否则没有。 - try (XmlCursor cursorsDiagonal = cursorBorder.getObject().newCursor()){ - cursorsDiagonal.selectPath(namespace + "./ns:diagonal"); - boolean isDiagonal = cursorsDiagonal.toNextSelection(); - addXlsxInfo(sheetName, "斜线的单元格", "ns:diagonal", String.valueOf(isDiagonal), "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - cursorsDiagonal.dispose(); - } - // 获取上边框 - try (XmlCursor cursorsTop = cursorBorder.getObject().newCursor()){ - XmlCursor cursorsTops = cursorBorder.getObject().newCursor(); - cursorsTops.selectPath(namespace + "./ns:top"); - if (cursorsTops.toNextSelection()) { - // 样式 - String topStyle = cursorsTops.getAttributeText(new QName("style")); - addXlsxInfo(sheetName, "上边框", "ns:top/@style", topStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - cursorsTops.selectPath(namespace + "./ns:color"); - if (cursorsTops.toNextSelection()) { - String topColor = cursorsTops.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "上边框颜色", "ns:top/@rgb", topColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - cursorsTops.dispose(); - cursorsTop.dispose(); - } - // 获取下边框 - try (XmlCursor cursorsBottom = cursorBorder.getObject().newCursor()){ - XmlCursor cursorsBottoms = cursorBorder.getObject().newCursor(); - cursorsBottoms.selectPath(namespace + "./ns:bottom"); - if (cursorsBottoms.toNextSelection()) { - // 样式 - String bottomStyle = cursorsBottoms.getAttributeText(new QName("style")); - addXlsxInfo(sheetName, "下边框", "ns:top/@rgb", bottomStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - // 颜色 - cursorsBottoms.selectPath(namespace + "./ns:color"); - if (cursorsBottoms.toNextSelection()) { - String bottomColor = cursorsBottoms.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "下边框颜色", "ns:top/@rgb", bottomColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - cursorsBottoms.dispose(); - cursorsBottom.dispose(); - } - // 获取左边框 - try (XmlCursor cursorsLeft = cursorBorder.getObject().newCursor()){ - XmlCursor cursorsLefts = cursorBorder.getObject().newCursor(); - cursorsLefts.selectPath(namespace + "./ns:left"); - if (cursorsLefts.toNextSelection()) { - // 样式 - String leftStyle = cursorsLefts.getAttributeText(new QName("style")); - addXlsxInfo(sheetName, "左边框", "ns:top/@rgb", leftStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - } - // 颜色 - cursorsLefts.selectPath(namespace + "./ns:color"); - if (cursorsLefts.toNextSelection()) { - String leftColor = cursorsLefts.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "左边框颜色", "ns:top/@rgb", leftColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - cursorsLefts.dispose(); - cursorsLeft.dispose(); - } - // 获取右边框 - try (XmlCursor cursorsRight = cursorBorder.getObject().newCursor()){ - XmlCursor cursorsRights = cursorBorder.getObject().newCursor(); - cursorsRights.selectPath(namespace + "./ns:right"); - if (cursorsRights.toNextSelection()) { - // 样式 - String rightStyle = cursorsRights.getAttributeText(new QName("style")); - addXlsxInfo(sheetName, "右边框", "ns:top/@rgb", rightStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - - } - // 颜色 - cursorsRights.selectPath(namespace + "./ns:color"); - if (cursorsRights.toNextSelection()) { - String rightColor = cursorsRights.getAttributeText(new QName("rgb")); - addXlsxInfo(sheetName, "右边框颜色", "ns:top/@rgb", rightColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); - } - cursorsRights.dispose(); - cursorsRight.dispose(); - } - break; - } - borderIndex ++; - } - cursorBorder.dispose(); - } - } - return cursor; - } - - public static XmlCursor extractStyleXml(String excelFilePath) throws Exception { - // 解压 Excel 文件并读取 sharedStrings.xml - ZipFile zipFile = new ZipFile(excelFilePath); - // 找到 sharedStrings.xml 文件的路径 - ZipEntry sharedStringsEntry = zipFile.getEntry("xl/styles.xml"); - - // 如果找不到 sharedStrings.xml,则返回空数组 - if (sharedStringsEntry == null) { - zipFile.close(); - return null; - } - - // 读取 sharedStrings.xml 文件 - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - zipFile.close(); // 关闭 zip 文件 - return cursor; - } - - public static XmlCursor extractConnectionsXml(String excelFilePath) throws Exception { - // 解压 Excel 文件并读取 sharedStrings.xml - ZipFile zipFile = new ZipFile(excelFilePath); - // 找到 sharedStrings.xml 文件的路径 - ZipEntry sharedStringsEntry = zipFile.getEntry("xl/connections.xml"); - - // 如果找不到 sharedStrings.xml,则返回空数组 - if (sharedStringsEntry == null) { - zipFile.close(); - return null; - } - - // 读取 sharedStrings.xml 文件 - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - zipFile.close(); // 关闭 zip 文件 - return cursor; - } - -// public static String getDrawingInfo(String excelFilePath) throws Exception { +// 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, String index) throws Exception { +// // 获取共享字符串 +// String[] sharedStrings = extractSharedStrings(filePath); +// // 读取样式xml +// XmlCursor styleXml = extractStyleXml(filePath); +// // 作簿中的数据连接(Data Connections),即 Excel 与外部数据源(如数据库、Web 服务、其他文件等)的链接信息 +// XmlCursor connectionsXml = extractConnectionsXml(filePath); +// // 获取工作簿中的图表数据 +//// List chartListXmls = extractChartXml(filePath); +// getDrawingInfos(filePath); +// // 单元格数据 +// List xlsxInfoVos = new ArrayList<>(); +// try (FileInputStream fis = new FileInputStream(filePath); +// OPCPackage pkg = OPCPackage.open(fis); +// XSSFWorkbook workbook = new XSSFWorkbook(pkg)) { +// // 获取有多少个工作表 +// int sheetNumber = workbook.getNumberOfSheets(); +// for (int i = 0; i < sheetNumber; i++) { +//// System.out.println("第 " + (i + 1) + " 个工作表"); +// // 获取工作表内容 +// XSSFSheet sheetXss = workbook.getSheetAt(i); +// // 获取工作表的XML对象 +// XmlObject worksheetXml = sheetXss.getCTWorksheet(); +// // 读取条件格式,并转化条件 +// XmlCursor conditionalFormatting = worksheetXml.newCursor(); +// conditionalFormatting.selectPath(namespace + "//ns:conditionalFormatting"); +// String sqref = ""; +// String formula = ""; +// boolean conditionalFormattingFlag = false; +// if (conditionalFormatting.toNextSelection()) { +// conditionalFormattingFlag = true; +// // 使用了条件格式,作用范围 +// XmlCursor sqrefXml = conditionalFormatting.getObject().newCursor(); +// sqrefXml.selectPath(namespace + "./@sqref"); +// if (sqrefXml.toNextSelection()) { +// sqref = sqrefXml.getTextValue(); +// } +// // 查询条件 +// XmlCursor cfRuleXml = conditionalFormatting.getObject().newCursor(); +// cfRuleXml.selectPath(namespace + "./ns:cfRule"); +// if (cfRuleXml.toNextSelection()){ +// dxfId = Integer.parseInt(cfRuleXml.getAttributeText(new QName("dxfId"))); +// XmlCursor formulaXml = cfRuleXml.getObject().newCursor(); +// formulaXml.selectPath(namespace + "./ns:formula"); +// if (formulaXml.toNextSelection()) { +// formula = cfRuleXml.getTextValue(); +// } +// } +// } +// try (XmlCursor cursor = worksheetXml.newCursor()) { +//// drawingXmlInfo(cursor, String.valueOf(i+1)); +// // 查询所有 row 元素 +// cursor.selectPath(namespace + "//ns:worksheet/ns:sheetData/ns:row"); +// int rowIndex = 0; +// while (cursor.toNextSelection()) { +// // 行的参数 +// XmlCursor rowXml = cursor.getObject().newCursor(); +// addXlsxInfo(String.valueOf(i+1), "行高", "ns:row/@ht", rowXml.getAttributeText(new QName("ht")), "row", "行" + rowXml.getAttributeText(new QName("r")), "style", "样式", "r"+rowXml.getAttributeText(new QName("r")), xlsxInfoVos); +// addXlsxInfo(String.valueOf(i+1), "行高", "ns:row/@ht", rowXml.getAttributeText(new QName("ht")), "row", "行" + rowXml.getAttributeText(new QName("r")),"style", "样式", "r"+rowXml.getAttributeText(new QName("r")), xlsxInfoVos); +// +// +// try (XmlCursor rowCursor = rowXml.newCursor()) { +// rowCursor.selectPath(namespace + "./ns:c"); +// // 接着获取单元格 +// int colIndex = 0; +// while (rowCursor.toNextSelection()) { +// // 判断是否使用了条件样式进行判断值 +// boolean isConditionalFormatting = false; +// if (conditionalFormattingFlag) { +// // 进行拆分单元格 +// // 1. 提取列字母(正则匹配 $K2 或 K2) +// // 字符串替换 +// String formulas = formula.replaceAll("\\$", "").split("=")[0]; +// Pattern pattern = Pattern.compile("^[A-Za-z]+"); +// Matcher matcher = pattern.matcher(formulas); +// String colLetters = ""; +// while (matcher.find()) { +// colLetters = matcher.group(0); +// } +// int colIndexMatcher = columnLetterToNumber(colLetters); +// // 读取指定单元格 +// Row row = sheetXss.getRow(rowIndex); +// if (row == null) break; +// Cell cell = row.getCell(colIndexMatcher-1); +// String value = getCellValue(cell); +// // 获取对比值 +// String compareValue = formula.split("=")[1].replace("\"", "");; +// if (Objects.equals(value, compareValue)) { +// isConditionalFormatting = true; +// } +// } +// Row row = sheetXss.getRow(rowIndex); +// if (row == null) break; +// // 获取行属性 +// Cell cell = row.getCell(colIndex); +// if (row != null && cell != null) { +// // 获取单元格 +// String rowName = rowCursor.getAttributeText(new QName("r")); +// // 获取style编号 +// String styleId = rowCursor.getAttributeText(new QName("s")); +// // 获取共享字符串 +// String tName = rowCursor.getAttributeText(new QName("t")); +// // 获取具体的值 +// try (XmlCursor valueXml = rowCursor.getObject().newCursor()) { +// String value = ""; +// valueXml.selectPath(namespace + "./ns:v"); +// if (valueXml.toNextSelection()) { +// value = valueXml.getTextValue(); +// } +// // 如果是共享字符串 +// if (tName != null && tName.equals("s")) { +// value = sharedStrings[Integer.parseInt(value)]; +// addXlsxInfo(String.valueOf(i+1), "单元格文本", "ns:celltext", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); +// } else { +// addXlsxInfo(String.valueOf(i+1), "单元格文本", "ns:celltext", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); +// } +// +// valueXml.dispose(); +// } +// // 获取公式 +// try (XmlCursor formulaXml = rowCursor.getObject().newCursor()) { +// String value = ""; +// formulaXml.selectPath(namespace + "./ns:f"); +// if (formulaXml.toNextSelection()) { +// value = formulaXml.getTextValue(); +// addXlsxInfo(String.valueOf(i+1), "单元格公式", "ns:formula", value, "cell", "单元格", "text", "文本", rowName, xlsxInfoVos); +// } +// formulaXml.dispose(); +// } +// // 获取单元格的格式 +// CellStyle cellStyle = cell.getCellStyle(); +//// System.out.println(rowIndex + "-" +colIndex); +// short dataFormat = cellStyle.getDataFormat(); +// String formatString = cellStyle.getDataFormatString(); +//// System.out.println(formatString); +// boolean isMerge = !formatString.equals("General"); +//// System.out.println(rowName); +// if (styleId != null) { +// extractStyle(xlsxInfoVos, Integer.parseInt(styleId), styleXml, true, rowName, String.valueOf(i + 1), isConditionalFormatting); +// } +// XmlCursor cellXml = rowCursor.getObject().newCursor(); +// cellXml.dispose(); +// } +// colIndex ++; +// } +// rowCursor.dispose(); +// rowIndex ++; +// } +// rowXml.dispose(); +// } +// cursor.dispose(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// List chartTypeEntries = getChartTypes(); +// +// +// // 开始获取图表等信息(包含数据透视表) +// try (XmlCursor drawingXmlcursor = worksheetXml.newCursor()) { +// drawingXmlcursor.selectPath(namespace + "./ns:drawing"); +// while (drawingXmlcursor.toNextSelection()) { +// try (XmlCursor drawingXml = drawingXmlcursor.getObject().newCursor()) { +// // 上指定的drawingList下进行查找 +// List xlsxDrawingSheetVos = drawingSheetVOS.get(i); +// // 1、已经获取到了对应sheet下的图表信息等 +// // 开始进行查询 +// for (XlsxDrawingSheetVo xlsxDrawingSheetVo : xlsxDrawingSheetVos) { +// // TODO 校验文件名称有问题 +// if (xlsxDrawingSheetVo.getTypeName().contains("chart")) { +// // 添加考点 +// addXlsxInfo(String.valueOf(i+1), "图表是否存在", "isChart", String.valueOf(0), "chart", "图表", "isChart", "是否存在", "", xlsxInfoVos); +// // 说明是图表 +// try (XmlCursor chartXml = xlsxDrawingSheetVo.getXmlCursor().newCursor()) { +//// System.out.println(chartXml.xmlText()); +// String chartNameSpace = getNamespace(chartXml.xmlText()); +// // 开始获取标题 +// XlsxInfoVo xlsxInfoVo = new XlsxInfoVo(); +// XmlCursor titleXml = chartXml.newCursor(); +//// System.out.println(titleXml.xmlText()); +// titleXml.selectPath(chartNameSpace + ".//c:chart/c:title/c:tx/c:rich"); +// while (titleXml.toNextSelection()) { +// addXlsxInfo(String.valueOf(i+1), "图表标题是否存在", "isTitle", String.valueOf(0), "chart", "图表", "title", "标题", "", xlsxInfoVos); +// +// XmlCursor titleAnchorXml = titleXml.newCursor(); +// titleAnchorXml.selectPath(chartNameSpace + ".//a:bodyPr/@anchor"); +// if (titleAnchorXml.toNextSelection()) { +// addXlsxInfo(String.valueOf(i+1), "图表标题位置", "a:bodyPr/@anchor", titleAnchorXml.getTextValue(), "chart", "图表", "title", "标题", "", xlsxInfoVos); +// } +// XmlCursor titleNameXml = titleXml.newCursor(); +// titleNameXml.selectPath(chartNameSpace + ".//a:p/a:r/a:t"); +// if (titleNameXml.toNextSelection()) { +// addXlsxInfo(String.valueOf(i+1), "图表标题文本", "a:p/a:r/a:t", titleNameXml.getTextValue(), "chart", "图表", "title", "标题", "", xlsxInfoVos); +// } +// } +//// titleXml.dispose(); +// XmlCursor charTypeXml = chartXml.newCursor(); +// charTypeXml.selectPath(chartNameSpace + ".//c:chart/c:plotArea"); +// while (charTypeXml.toNextSelection()) { +// addXlsxInfo(String.valueOf(i+1), "绘图是否存在", "c:chart/c:plotArea", String.valueOf(0), "chart", "图表", "plotArea", "绘图", "", xlsxInfoVos); +// // 获取图表类型 +// for (ChartTypeEntry chartTypeEntry : chartTypeEntries) { +// XmlCursor charTypeXmlInfo = charTypeXml.newCursor(); +// // 判断是否存在参数 +//// System.out.println(charTypeXmlInfo.xmlText()); +//// System.out.println(".//c:plotArea/" + chartTypeEntry.getTag()); +// charTypeXmlInfo.selectPath(chartNameSpace + "./" + chartTypeEntry.getTag()); +// if (charTypeXmlInfo.toNextSelection()) { +// if (chartTypeEntry.getTag().equals("c:barChart")) { +// // 说明要在继续判断值 +// charTypeXmlInfo.selectPath(chartNameSpace + ".//c:barDir/@val"); +// if (charTypeXmlInfo.toNextSelection()) { +// String value = charTypeXmlInfo.getTextValue(); +// if (value.equals("col")) { +// addXlsxInfo(String.valueOf(i+1), "图表类型", "c:barDir/@val", "簇型柱状图", "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); +// } +// } else { +// addXlsxInfo(String.valueOf(i+1), "图表类型", chartTypeEntry.getTag(), chartTypeEntry.getDisplayName(), "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); +// } +// } else { +// addXlsxInfo(String.valueOf(i+1), "图表类型", chartTypeEntry.getTag(), chartTypeEntry.getDisplayName(), "chart", "图表", "plotArea","绘图", "", xlsxInfoVos); +// } +// +// } +// } +// +// // 获取X,Y轴信息 +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// } +// } +// } +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } catch (InvalidFormatException e) { +// throw new RuntimeException(e); +// } +// List xlsxInfos = new ArrayList<>(); +// for (XlsxInfoVo xlsxInfoVo : xlsxInfoVos) { +// WpsPptxJudgementDto wpsPptxJudgementDto = new WpsPptxJudgementDto(); +// wpsPptxJudgementDto.setContentIn(xlsxInfoVo.getSheetName() + "@" + xlsxInfoVo.getTypeName() + "@" + xlsxInfoVo.getCell() + "@" + xlsxInfoVo.getSecondTypeName() + "@" + xlsxInfoVo.getChineseName() + "@"+ xlsxInfoVo.getValue()); +// wpsPptxJudgementDto.setContent(xlsxInfoVo.getSheetName() + "@" + xlsxInfoVo.getType() + "@" + xlsxInfoVo.getCell() + "@" + xlsxInfoVo.getSecondType() + "@" + xlsxInfoVo.getEnglishName() + "@"+ xlsxInfoVo.getValue()); +// wpsPptxJudgementDto.setScoreRate("1"); +// xlsxInfos.add(wpsPptxJudgementDto); +// } +// return xlsxInfos; +// } +// +// // 扁平化多维列表 +// public static List getRandomItems(List list, int count) { +// List copy = new ArrayList<>(list); // 创建副本,避免修改原列表 +// Collections.shuffle(copy); // 打乱顺序 +// return copy.subList(0, Math.min(count, copy.size())); // 抽取前count个 +// } +// +// // 支持所有类型的单元格 +// private static String getCellValue(Cell cell) { +// switch (cell.getCellType()) { +// case STRING: +// return cell.getStringCellValue(); +// +// case NUMERIC: +// if (DateUtil.isCellDateFormatted(cell)) { +// return cell.getDateCellValue().toString(); +// } +// return String.valueOf(cell.getNumericCellValue()); +// +// case BOOLEAN: +// return String.valueOf(cell.getBooleanCellValue()); +// +// case FORMULA: +// return cell.getCellFormula(); // 或者用 cell.getNumericCellValue() 等 +// +// case BLANK: +// return ""; +// +// default: +// return "[UNKNOWN TYPE]"; +// } +// } +// +// public static int columnLetterToNumber(String column) { +// int result = 0; +// for (int i = 0; i < column.length(); i++) { +// result = result * 26 + (column.charAt(i) - 'A' + 1); +// } +// return result; +// } +// +// +// public static boolean isCellInRange(String cellRef, String rangeRef) { +// int[] cellPos = parseCellRef(cellRef); // [col, row] +// int[] startPos = parseCellRef(rangeRef.split(":")[0]); // A2 +// int[] endPos = parseCellRef(rangeRef.split(":")[1]); // O18 +// +// return cellPos[0] >= startPos[0] && cellPos[0] <= endPos[0] && +// cellPos[1] >= startPos[1] && cellPos[1] <= endPos[1]; +// } +// +// public static int[] parseCellRef(String ref) { +// String colLetters = ref.replaceAll("\\d", ""); // 取字母部分,如 A +// String rowDigits = ref.replaceAll("\\D", ""); // 取数字部分,如 7 +// +// int colNum = columnNameToIndex(colLetters); +// int rowNum = Integer.parseInt(rowDigits); +// return new int[]{colNum, rowNum}; +// } +// +// public static int columnNameToIndex(String column) { +// int result = 0; +// for (int i = 0; i < column.length(); i++) { +// result = result * 26 + (column.charAt(i) - 'A' + 1); +// } +// return result; +// } +// +// +// public static List getChartTypes() { +// // 创建一个图表 +// List chartTypes = new ArrayList<>(); +// chartTypes.add(new ChartTypeEntry("c:barChart", "横向柱状图")); +// chartTypes.add(new ChartTypeEntry("c:lineChart", "折线图")); +// chartTypes.add(new ChartTypeEntry("c:pieChart", "饼图")); +// chartTypes.add(new ChartTypeEntry("c:areaChart", "面积图")); +// chartTypes.add(new ChartTypeEntry("c:scatterChart", "散点图")); +// chartTypes.add(new ChartTypeEntry("c:bubbleChart", "气泡图")); +// chartTypes.add(new ChartTypeEntry("c:radarChart", "雷达图")); +// chartTypes.add(new ChartTypeEntry("c:stockChart", "股票图")); +// chartTypes.add(new ChartTypeEntry("c:surfaceChart", "曲面图")); +// chartTypes.add(new ChartTypeEntry("c:ofPieChart", "分类饼图(饼中饼/条中饼)")); +// chartTypes.add(new ChartTypeEntry("c:doughnutChart", "圆环图")); +// chartTypes.add(new ChartTypeEntry("c:bar3DChart", "3D柱状图")); +// chartTypes.add(new ChartTypeEntry("c:line3DChart", "3D折线图")); +// chartTypes.add(new ChartTypeEntry("c:area3DChart", "3D面积图")); +// chartTypes.add(new ChartTypeEntry("c:surface3DChart", "3D曲面图")); +// return chartTypes; +// } +// +// public static void addXlsxInfo(String sheetName, String chineseName, String englishName, String value, String type, String typeName, String secondType, String secondTypeName, String cellName, List xlsxInfoVos) { +// XlsxInfoVo xlsxInfoVo = new XlsxInfoVo(); +// xlsxInfoVo.setSheetNumber(sheetName); +// // 拼接数据 +// sheetName = "【sheet" + sheetName + "】"; +// xlsxInfoVo.setSheetName(sheetName); +// xlsxInfoVo.setChineseName(chineseName); +// xlsxInfoVo.setEnglishName(englishName); +// xlsxInfoVo.setValue(value); +// xlsxInfoVo.setType(type); +// xlsxInfoVo.setTypeName(typeName); +// xlsxInfoVo.setCell(cellName); +// xlsxInfoVo.setSecondType(secondType); +// xlsxInfoVo.setSecondTypeName(secondTypeName); +// xlsxInfoVos.add(xlsxInfoVo); +// } +// +// public static String drawingXmlInfo(XmlCursor cursor, String sheetName) throws Exception { +// // 判断是否存在表格数据 标签数据 +// try (XmlCursor drawingXml = cursor.newCursor()) { +// drawingXml.selectPath(namespace + "./ns:drawing"); +// int drawingIndex = 0; +// while (drawingXml.toNextSelection()) { +// try (XmlCursor drawingXmlCursor = drawingXml.getObject().newCursor()) { +//// System.out.println(drawingXmlCursor.xmlText()); +// drawingXmlCursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' ./@r:id"); +// if (drawingXmlCursor.toNextSelection()) { +// String rId = drawingXmlCursor.getTextValue(); +// +// } +// } +// drawingIndex ++; +// } +// } +// return ""; +// } +// +// /** +// * 从 Excel 文件中提取共享字符串 +// * @param excelFilePath Excel 文件路径 +// * @return 共享字符串数组 +// * @throws Exception 如果文件不存在或无法读取,则抛出异常 +// */ +// public static String[] extractSharedStrings(String excelFilePath) throws Exception { // // 解压 Excel 文件并读取 sharedStrings.xml // ZipFile zipFile = new ZipFile(excelFilePath); +// // 找到 sharedStrings.xml 文件的路径 +// ZipEntry sharedStringsEntry = zipFile.getEntry("xl/sharedStrings.xml"); +// +// // 如果找不到 sharedStrings.xml,则返回空数组 +// if (sharedStringsEntry == null) { +// zipFile.close(); +// return new String[0]; +// } +// +// // 读取 sharedStrings.xml 文件 +// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +// byte[] content = inputStream.readAllBytes(); +// String xmlContent = new String(content); +// +// // 使用 XmlObject 解析 sharedStrings.xml +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// // 查询所有 sharedString 元素 +// cursor.selectPath(namespace + "//ns:sst/ns:si"); +// +// List sharedStringList = new ArrayList<>(); +// +// // 遍历每个 sharedString 元素并提取文本值 +// while (cursor.toNextSelection()) { +// // 获取单元格内容 +// String sharedString = cursor.getTextValue(); +// sharedStringList.add(sharedString); +// } +// +// cursor.dispose(); // 关闭游标 +// zipFile.close(); // 关闭 zip 文件 +// +// // 将 List 转换为数组并返回 +// return sharedStringList.toArray(new String[0]); +// } +// +// public static XmlCursor extractStyle(List xlsxInfoVos, int serialNumber, XmlCursor cursor, boolean isTrue, String colName, String sheetName, boolean isCellStyle) throws Exception { +// XmlCursor xmlCursor = cursor.newCursor(); +// if (isTrue) { +// // 自定义格式 +// xmlCursor.selectPath(namespace + "//ns:cellXfs/ns:xf"); +// } else { +//// xlsxStyleCellStyleXfxVo.setCol(colName); +// xmlCursor.selectPath(namespace + "//ns:cellStyleXfs/ns:xf"); +// } +// int index = 0; +// String numFmtId = null; +// String fontId = null; +// String fillId = null; +// String borderId = null; +// String applyFont = null; +// String applyFill = null; +// String applyProtection = null; +// String wrapText = null; +// String textRotation = null; +// String shrinkToFit = null; +// String applyBorder = null; +// String applyNumberFormat = null; +// String applyAlignment = null; +// while(xmlCursor.toNextSelection()) { +// // 通过序号查询指定数据 +// if (index == serialNumber) { +// XmlCursor designateXml = xmlCursor.getObject().newCursor(); +// // 数字格式的ID +// numFmtId = designateXml.getAttributeText(new QName("numFmtId")); +// // 字体的ID +// fontId = designateXml.getAttributeText(new QName("fontId")); +// // 填充(背景颜色)的ID +// fillId = designateXml.getAttributeText(new QName("fillId")); +// // 边框样式的ID +// borderId = designateXml.getAttributeText(new QName("borderId")); +// // 字体设置 +// applyFont = designateXml.getAttributeText(new QName("applyFont")); +// // 背景填充 +// applyFill = designateXml.getAttributeText(new QName("applyFill")); +// // 表示不应用保护设置(即不锁定单元格) +// applyProtection = designateXml.getAttributeText(new QName("applyProtection")); +// // 文本旋转45度 +// wrapText = designateXml.getAttributeText(new QName("wrapText")); +// // 文本缩进一级。 +// textRotation = designateXml.getAttributeText(new QName("textRotation")); +// // 启用文本自动缩小以适应单元格。 +// shrinkToFit = designateXml.getAttributeText(new QName("shrinkToFit")); +// applyBorder = designateXml.getAttributeText(new QName("applyBorder")); +// applyNumberFormat = designateXml.getAttributeText(new QName("applyNumberFormat")); +// applyAlignment = designateXml.getAttributeText(new QName("applyAlignment")); +// designateXml.selectPath(namespace + "./ns:alignment"); +// if (designateXml.toNextSelection()) { +// // 获取 水平对齐 属性 +// String horizontal = designateXml.getAttributeText(new QName("horizontal")); +// // 获取 垂直对齐 属性 +// String vertical = designateXml.getAttributeText(new QName("vertical")); +// if (isTrue) { +// addXlsxInfo(sheetName, "水平对齐", "vertical", horizontal, "cell", "单元格", "alignment", "对齐", colName, xlsxInfoVos); +// addXlsxInfo(sheetName, "垂直对齐", "horizontal", vertical, "cell", "单元格", "alignment", "对齐", colName, xlsxInfoVos); +// } else { +//// xlsxStyleCellStyleXfxVo.setVertical(vertical); +//// xlsxStyleCellStyleXfxVo.setHorizontal(horizontal); +// } +// } +// break; +// } +// index ++; +// } +// // 接着进行查找 +// if (numFmtId != null) { +// try (XmlCursor cursorNumFmts = cursor.newCursor()) { +// cursorNumFmts.selectPath(namespace + "//ns:numFmts/ns:numFmt"); +// while (cursorNumFmts.toNextSelection()) { +// // 获取 numFmtId 属性 +// String numFmtIdInfo = cursorNumFmts.getAttributeText(new QName("numFmtId")); +// if (numFmtIdInfo.equals(numFmtId)) { +// // 获取 formatCode 属性 +// String formatCode = cursorNumFmts.getAttributeText(new QName("formatCode")); +// if (isTrue) { +// addXlsxInfo(sheetName, "formatCode", "formatCode", formatCode, "cell", "单元格", "formatCode", "自定义格式", colName, xlsxInfoVos); +// } else { +//// xlsxStyleCellStyleXfxVo.setFormatCode(formatCode); +// } +// break; +// } +// } +// } +// } +// xmlCursor.dispose(); +// // 应用了字体设置 +// if (fontId != null) { +// try (XmlCursor cursorFonts = cursor.newCursor()) { +// cursorFonts.selectPath(namespace + "//ns:fonts/ns:font"); +// int fontIndex = 0; +// while (cursorFonts.toNextSelection()) { +// if (fontIndex == Integer.parseInt(fontId)) { +// // 判断是否加粗(是否存在 标签) +// try (XmlCursor cursorsFontBold = cursorFonts.getObject().newCursor()){ +// cursorsFontBold.selectPath(namespace + "./ns:b"); +// boolean isBold = cursorsFontBold.toNextSelection(); +// addXlsxInfo(sheetName, "文本加粗", "ns:b", String.valueOf(isBold), "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// cursorsFontBold.dispose(); +// } +// // 获取 sz 的 val 属性(字体大小) +// try (XmlCursor cursorsFontSz = cursorFonts.getObject().newCursor()){ +// cursorsFontSz.selectPath(namespace + "./ns:sz"); +// if (cursorsFontSz.toNextSelection()) { +// String fontSize = cursorsFontSz.getAttributeText(new QName("val")); +// addXlsxInfo(sheetName, "文本大小", "ns:sz", fontSize, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// } +// cursorsFontSz.dispose(); +// } +// // 获取 color 的 rgb 属性(字体颜色) +// try (XmlCursor cursorsFontColor = cursorFonts.getObject().newCursor()){ +// cursorsFontColor.selectPath(namespace + "./ns:color"); +// if (cursorsFontColor.toNextSelection()) { +// String fontColor = cursorsFontColor.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "文本颜色", "ns:color", fontColor, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// } +// cursorsFontColor.dispose(); +// } +// // 获取 name 的 val 属性(字体名称) +// try (XmlCursor cursorsFontName = cursorFonts.getObject().newCursor()){ +// cursorsFontName.selectPath(namespace + "./ns:name"); +// if (cursorsFontName.toNextSelection()) { +// String fontName = cursorsFontName.getAttributeText(new QName("val")); +// addXlsxInfo(sheetName, "字体名称", "ns:name", fontName, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// +// } +// cursorsFontName.dispose(); +// } +// // 获取 charset 的 val 属性(字符集) +// try (XmlCursor cursorsFontCharset = cursorFonts.getObject().newCursor()){ +// cursorsFontCharset.selectPath(namespace + "./ns:charset"); +// if (cursorsFontCharset.toNextSelection()) { +// String fontCharset = cursorsFontCharset.getAttributeText(new QName("val")); +// addXlsxInfo(sheetName, "字体字符集", "ns:charset", fontCharset, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// +// } +// cursorsFontCharset.dispose(); +// } +// // 获取 scheme 的 val 属性(字体方案) +// try (XmlCursor cursorsFontScheme = cursorFonts.getObject().newCursor()){ +// cursorsFontScheme.selectPath(namespace + "./ns:scheme"); +// if (cursorsFontScheme.toNextSelection()) { +// String fontScheme = cursorsFontScheme.getAttributeText(new QName("val")); +// addXlsxInfo(sheetName, "字体方案", "ns:scheme", fontScheme, "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// +// } +// cursorsFontScheme.dispose(); +// } +// break; +// } +// fontIndex ++; +// } +// cursorFonts.dispose(); +// } +// } +// // 背景颜色填充 +// if (fillId != null) { +// try (XmlCursor cursorFills = cursor.newCursor()) { +// if (!isCellStyle) { +// cursorFills.selectPath(namespace + "//ns:fills/ns:fill"); +// int fillIndex = 0; +// while (cursorFills.toNextSelection()) { +// if (fillIndex == Integer.parseInt(fillId)) { +// try (XmlCursor cursorsFill = cursorFills.getObject().newCursor()) { +// cursorsFill.selectPath(namespace + "./ns:patternFill"); +// if (cursorsFill.toNextSelection()) { +// // 获取 patternType 属性(填充样式) +// String patternType = cursorsFill.getAttributeText(new QName("patternType")); +// addXlsxInfo(sheetName, "填充样式", "ns:scheme/@theme", patternType, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); +// // 获取 fgColor 的 theme 和 tint 属性(填充颜色) +// try (XmlCursor cursorsFgColor = cursorsFill.getObject().newCursor()) { +// cursorsFgColor.selectPath(namespace + "./ns:fgColor"); +// if (cursorsFgColor.toNextSelection()) { +// String theme = cursorsFgColor.getAttributeText(new QName("theme")); +// String rgb = cursorsFgColor.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "填充theme", "ns:scheme/@theme", theme, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); +// addXlsxInfo(sheetName, "填充颜色", "ns:fgColor/@rgb", rgb, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); +// } +// cursorsFgColor.dispose(); +// } +// // 获取 bgColor 的 indexed 属性(背景色) +// try (XmlCursor cursorsBgColor = cursorFills.getObject().newCursor()) { +// cursorsBgColor.selectPath(namespace + "./ns:bgColor"); +// if (cursorsBgColor.toNextSelection()) { +// String rgb = cursorsBgColor.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "背景色", "ns:bgColor/@rgb", rgb, "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); +// } +// cursorsBgColor.dispose(); +// } +// } +// } +// break; +// } +// fillIndex ++; +// } +// cursorFills.dispose(); +// } else { +// XmlCursor cursorDxf = cursorFills.newCursor(); +// cursorDxf.selectPath(namespace + "//ns:dxfs/ns:dxf"); +// int dxfIndex = 0; +// while (cursorDxf.toNextSelection()) { +// if (dxfIndex == dxfId) { +// XmlCursor fontXmlCursor = cursorDxf.getObject().newCursor(); +// fontXmlCursor.selectPath(namespace + "./ns:font/color/@rgb"); +// if (fontXmlCursor.toNextSelection()) { +// addXlsxInfo(sheetName, "文本颜色", "ns:color", fontXmlCursor.getTextValue(), "cell", "单元格", "font", "字体", colName, xlsxInfoVos); +// } +// fontXmlCursor.dispose(); +// XmlCursor fillXmlCursor = cursorDxf.getObject().newCursor(); +// fillXmlCursor.selectPath(namespace + "./ns:fill/ns:patternFill/ns:bgColor/@rgb"); +// if (fillXmlCursor.toNextSelection()) { +// addXlsxInfo(sheetName, "背景色", "ns:bgColor/@rgb", fillXmlCursor.getTextValue(), "cell", "单元格", "fill", "背景", colName, xlsxInfoVos); +// } +// fillXmlCursor.dispose(); +// } +// } +// } +// } +// } +// // 是否启用了边框设置 +// if (borderId != null) { +// try (XmlCursor cursorBorder = cursor.newCursor()) { +// cursorBorder.selectPath(namespace + "//ns:borders/ns:border"); +// int borderIndex = 0; +// while (cursorBorder.toNextSelection()) { +// if (borderIndex == Integer.parseInt(borderId)) { +// // 定义对角线边框。常用于带有斜线的单元格。如果 标签存在,表示对角线有边框,否则没有。 +// try (XmlCursor cursorsDiagonal = cursorBorder.getObject().newCursor()){ +// cursorsDiagonal.selectPath(namespace + "./ns:diagonal"); +// boolean isDiagonal = cursorsDiagonal.toNextSelection(); +// addXlsxInfo(sheetName, "斜线的单元格", "ns:diagonal", String.valueOf(isDiagonal), "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// cursorsDiagonal.dispose(); +// } +// // 获取上边框 +// try (XmlCursor cursorsTop = cursorBorder.getObject().newCursor()){ +// XmlCursor cursorsTops = cursorBorder.getObject().newCursor(); +// cursorsTops.selectPath(namespace + "./ns:top"); +// if (cursorsTops.toNextSelection()) { +// // 样式 +// String topStyle = cursorsTops.getAttributeText(new QName("style")); +// addXlsxInfo(sheetName, "上边框", "ns:top/@style", topStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// cursorsTops.selectPath(namespace + "./ns:color"); +// if (cursorsTops.toNextSelection()) { +// String topColor = cursorsTops.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "上边框颜色", "ns:top/@rgb", topColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// cursorsTops.dispose(); +// cursorsTop.dispose(); +// } +// // 获取下边框 +// try (XmlCursor cursorsBottom = cursorBorder.getObject().newCursor()){ +// XmlCursor cursorsBottoms = cursorBorder.getObject().newCursor(); +// cursorsBottoms.selectPath(namespace + "./ns:bottom"); +// if (cursorsBottoms.toNextSelection()) { +// // 样式 +// String bottomStyle = cursorsBottoms.getAttributeText(new QName("style")); +// addXlsxInfo(sheetName, "下边框", "ns:top/@rgb", bottomStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// // 颜色 +// cursorsBottoms.selectPath(namespace + "./ns:color"); +// if (cursorsBottoms.toNextSelection()) { +// String bottomColor = cursorsBottoms.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "下边框颜色", "ns:top/@rgb", bottomColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// cursorsBottoms.dispose(); +// cursorsBottom.dispose(); +// } +// // 获取左边框 +// try (XmlCursor cursorsLeft = cursorBorder.getObject().newCursor()){ +// XmlCursor cursorsLefts = cursorBorder.getObject().newCursor(); +// cursorsLefts.selectPath(namespace + "./ns:left"); +// if (cursorsLefts.toNextSelection()) { +// // 样式 +// String leftStyle = cursorsLefts.getAttributeText(new QName("style")); +// addXlsxInfo(sheetName, "左边框", "ns:top/@rgb", leftStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// } +// // 颜色 +// cursorsLefts.selectPath(namespace + "./ns:color"); +// if (cursorsLefts.toNextSelection()) { +// String leftColor = cursorsLefts.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "左边框颜色", "ns:top/@rgb", leftColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// cursorsLefts.dispose(); +// cursorsLeft.dispose(); +// } +// // 获取右边框 +// try (XmlCursor cursorsRight = cursorBorder.getObject().newCursor()){ +// XmlCursor cursorsRights = cursorBorder.getObject().newCursor(); +// cursorsRights.selectPath(namespace + "./ns:right"); +// if (cursorsRights.toNextSelection()) { +// // 样式 +// String rightStyle = cursorsRights.getAttributeText(new QName("style")); +// addXlsxInfo(sheetName, "右边框", "ns:top/@rgb", rightStyle, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// +// } +// // 颜色 +// cursorsRights.selectPath(namespace + "./ns:color"); +// if (cursorsRights.toNextSelection()) { +// String rightColor = cursorsRights.getAttributeText(new QName("rgb")); +// addXlsxInfo(sheetName, "右边框颜色", "ns:top/@rgb", rightColor, "cell", "单元格", "border", "边框", colName, xlsxInfoVos); +// } +// cursorsRights.dispose(); +// cursorsRight.dispose(); +// } +// break; +// } +// borderIndex ++; +// } +// cursorBorder.dispose(); +// } +// } +// return cursor; +// } +// +// public static XmlCursor extractStyleXml(String excelFilePath) throws Exception { +// // 解压 Excel 文件并读取 sharedStrings.xml +// ZipFile zipFile = new ZipFile(excelFilePath); +// // 找到 sharedStrings.xml 文件的路径 +// ZipEntry sharedStringsEntry = zipFile.getEntry("xl/styles.xml"); +// +// // 如果找不到 sharedStrings.xml,则返回空数组 +// if (sharedStringsEntry == null) { +// zipFile.close(); +// return null; +// } +// +// // 读取 sharedStrings.xml 文件 +// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +// byte[] content = inputStream.readAllBytes(); +// String xmlContent = new String(content); +// // 使用 XmlObject 解析 sharedStrings.xml +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// zipFile.close(); // 关闭 zip 文件 +// return cursor; +// } +// +// public static XmlCursor extractConnectionsXml(String excelFilePath) throws Exception { +// // 解压 Excel 文件并读取 sharedStrings.xml +// ZipFile zipFile = new ZipFile(excelFilePath); +// // 找到 sharedStrings.xml 文件的路径 +// ZipEntry sharedStringsEntry = zipFile.getEntry("xl/connections.xml"); +// +// // 如果找不到 sharedStrings.xml,则返回空数组 +// if (sharedStringsEntry == null) { +// zipFile.close(); +// return null; +// } +// +// // 读取 sharedStrings.xml 文件 +// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +// byte[] content = inputStream.readAllBytes(); +// String xmlContent = new String(content); +// // 使用 XmlObject 解析 sharedStrings.xml +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// zipFile.close(); // 关闭 zip 文件 +// return cursor; +// } +// +//// public static String getDrawingInfo(String excelFilePath) throws Exception { +//// // 解压 Excel 文件并读取 sharedStrings.xml +//// ZipFile zipFile = new ZipFile(excelFilePath); +//// Enumeration entries = zipFile.entries(); +//// while (entries.hasMoreElements()) { +//// ZipEntry entry = entries.nextElement(); +//// String entryName = entry.getName(); +//// // 1、获取sheet*.xml.rels下面的文件 +//// if (entryName.startsWith("xl/worksheets/_rels") && entryName.endsWith(".xml.rels")) { +//// XlsxDrawingSheetVo xlsxDrawingSheetVo = new XlsxDrawingSheetVo(); +//// // 读取数据 +//// ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); +//// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +//// byte[] content = inputStream.readAllBytes(); +//// String xmlContent = new String(content); +//// // 使用 XmlObject 解析 sharedStrings.xml +//// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +//// XmlCursor sheetCursor = xmlObject.newCursor(); +//// // 正则匹配:提取连续的数字 +//// StringBuilder numbers = new StringBuilder(); +//// for (char c : entryName.toCharArray()) { +//// // 检查是否是数字 +//// if (Character.isDigit(c)) { +//// numbers.append(c); +//// } +//// } +//// // 第几个sheet对应的索引 +//// int number = Integer.parseInt(numbers.toString()); +//// xlsxDrawingSheetVo.setSheetNumber(String.valueOf(number)); +//// sheetCursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +//// while (sheetCursor.toNextSelection()) { +//// // 2、开始获取内容 +//// // 2-1、获取ID +//// String id = sheetCursor.getAttributeText(new QName("Id")); +//// // 2-2、获取文件路径 +//// String target = sheetCursor.getAttributeText(new QName("Target")); +//// // 3、在往下获取对应的文件,及文件路径 +//// // 进行路径字符串替换 .. -> xl +//// String newTarget = target.replace("..", "xl"); +//// System.out.println("newTarget = " + newTarget); +//// ZipEntry sharedStringsEntry2 = zipFile.getEntry(newTarget); +//// InputStream inputStream2 = zipFile.getInputStream(sharedStringsEntry2); +//// byte[] content2 = inputStream2.readAllBytes(); +//// String xmlContent2 = new String(content2); +//// // 使用 XmlObject 解析 sharedStrings.xml +//// XmlObject xmlObject2 = XmlObject.Factory.parse(xmlContent2); +//// XmlCursor sheetCursor2 = xmlObject2.newCursor(); +//// // 4、判断是否存在对应文件的_rels * 文件 +//// // 路径自定义 xl/drawings/drawing1.xml +//// // 分割字符串 +//// String[] split = newTarget.split("/"); +//// String newRelsFilePath = split[0]+"/"+split[1]+"/_rels/"+split[2]+".rels"; +//// // 在进行获取数据,获取文件路径 +//// ZipEntry sharedStringsEntry3 = zipFile.getEntry(newRelsFilePath); +//// if (sharedStringsEntry3 != null) { +//// InputStream inputStream3 = zipFile.getInputStream(sharedStringsEntry3); +//// byte[] content3 = inputStream3.readAllBytes(); +//// String xmlContent3 = new String(content3); +//// // 使用 XmlObject 解析 sharedStrings.xml +//// XmlObject xmlObject3 = XmlObject.Factory.parse(xmlContent3); +//// XmlCursor sheetCursor3 = xmlObject3.newCursor(); +//// sheetCursor3.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +//// while (sheetCursor3.toNextSelection()) { +//// // 2、开始获取内容 +//// // 2-1、获取ID +//// String id2 = sheetCursor3.getAttributeText(new QName("Id")); +//// // 2-2、获取文件路径 +//// String target2 = sheetCursor3.getAttributeText(new QName("Target")); +//// // 3、在往下获取对应的文件,及文件路径 +//// System.out.println("target2 = " + target2); +//// // 进行路径字符串替换 .. -> xl +//// String newTarget2 = target2.replace("..", "xl"); +//// } +//// } +//// +//// } +//// } +//// } +//// zipFile.close(); // 关闭 zip 文件 +//// return ""; +//// } +// +// public static String getDrawingInfos(String excelFilePath) throws Exception { +// try (ZipFile zipFile = new ZipFile(excelFilePath)) { +// Enumeration entries = zipFile.entries(); +// +// while (entries.hasMoreElements()) { +// ZipEntry entry = entries.nextElement(); +// String entryName = entry.getName(); +// +// if (entryName.startsWith("xl/worksheets/_rels") && entryName.endsWith(".xml.rels")) { +// String xmlContent = readZipEntry(zipFile, entryName); +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// +// // 正则匹配:提取连续的数字 +// StringBuilder numbers = new StringBuilder(); +// for (char c : entryName.toCharArray()) { +// // 检查是否是数字 +// if (Character.isDigit(c)) { +// numbers.append(c); +// } +// } +// // 第几个sheet对应的索引 +// int number = Integer.parseInt(numbers.toString()); +// List drawingVOS = new ArrayList<>(); +// cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +// while (cursor.toNextSelection()) { +// // 2、开始获取内容 +// XlsxDrawingSheetVo xlsxDrawingSheetVo = new XlsxDrawingSheetVo(); +// String rId = cursor.getAttributeText(new QName("Id")); +// String target = cursor.getAttributeText(new QName("Target")); +// String nextPath = target.replace("..", "xl"); +// xlsxDrawingSheetVo.setSheetNumber(String.valueOf(number)); +// xlsxDrawingSheetVo.setRId(rId); +// traverseRels(zipFile, nextPath, xlsxDrawingSheetVo, String.valueOf(number), drawingVOS); +// } +// drawingSheetVOS.add(drawingVOS); +// } +// } +// } +// return ""; +// } +// // 递归遍历 _rels 下级文件 +// private static void traverseRels(ZipFile zipFile, String path, XlsxDrawingSheetVo xlsxDrawingSheetVo, String sheetName, List drawingVOS) throws Exception { +// if (path == null || path.isEmpty()) return; +// // 1、获取对应文件内容 +// String content = readZipEntry(zipFile, path); +// // 文件不存在,终止链 +// if (content == null) return; +// XmlObject xmlObject = XmlObject.Factory.parse(content); +// XmlCursor cursor = xmlObject.newCursor(); +// xlsxDrawingSheetVo.setXmlCursor(cursor); +//// System.out.println(cursor.xmlText()); +// // 生成对应的 .rels 路径 +// String[] parts = path.split("/"); +// String relsPath = parts[0] + "/" + parts[1] + "/_rels/" + parts[2] + ".rels"; +// xlsxDrawingSheetVo.setTypeName(path); +// drawingVOS.add(xlsxDrawingSheetVo); +// String contents = readZipEntry(zipFile, relsPath); +// // 文件不存在,终止链 +// if (contents == null) return; +// XmlObject xmlObjects = XmlObject.Factory.parse(contents); +// XmlCursor cursors = xmlObjects.newCursor(); +// cursors.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); +// // 2、开始获取内容 +// while (cursors.toNextSelection()) { +//// System.out.println(cursors.xmlText()); +// XlsxDrawingSheetVo xlsxDrawingSheetVos = new XlsxDrawingSheetVo(); +// String target = cursors.getAttributeText(new QName("Target")); +// String rId = cursors.getAttributeText(new QName("Id")); +// xlsxDrawingSheetVos.setRId(rId); +// xlsxDrawingSheetVos.setSheetNumber(sheetName); +// xlsxDrawingSheetVos.setRId(rId); +// if (target == null) continue; +// String newPath = ""; +// if (!target.contains("./")) { +// // 如果没有包含路径,可能是在原本的路径下面 +// newPath = parts[0] + "/" + parts[1] + "/" + target; +// } else { +// newPath = target.replace("..", "xl"); +// } +// +//// System.out.println("Found path: " + newPath); +// // 递归继续查找下一级 +// if (zipFile.getEntry(relsPath) != null) { +// traverseRels(zipFile, newPath, xlsxDrawingSheetVos, sheetName, drawingVOS); +// } +// } +// } +// // 工具方法:从 zip 文件中读取条目内容 +// private static String readZipEntry(ZipFile zipFile, String entryName) throws IOException { +// ZipEntry entry = zipFile.getEntry(entryName); +// if (entry == null) return null; +// try (InputStream is = zipFile.getInputStream(entry)) { +// return new String(is.readAllBytes()); +// } +// } +// +// +// public static List extractChartXml(String excelFilePath) throws Exception { +// List xlsxCharVos = new ArrayList<>(); +// // 解压 Excel 文件并读取 sharedStrings.xml +// ZipFile zipFile = new ZipFile(excelFilePath); +// // Enumeration entries = zipFile.entries(); // while (entries.hasMoreElements()) { // ZipEntry entry = entries.nextElement(); // String entryName = entry.getName(); -// // 1、获取sheet*.xml.rels下面的文件 -// if (entryName.startsWith("xl/worksheets/_rels") && entryName.endsWith(".xml.rels")) { -// XlsxDrawingSheetVo xlsxDrawingSheetVo = new XlsxDrawingSheetVo(); +// // 检查是否属于 xl/charts/ 目录下的图表文件 +// if (entryName.startsWith("xl/charts/chart") && entryName.endsWith(".xml")) { // // 读取数据 // ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); // InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); @@ -915,7 +1096,7 @@ public class WpsExcelUtils { // String xmlContent = new String(content); // // 使用 XmlObject 解析 sharedStrings.xml // XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); -// XmlCursor sheetCursor = xmlObject.newCursor(); +// XmlCursor cursor = xmlObject.newCursor(); // // 正则匹配:提取连续的数字 // StringBuilder numbers = new StringBuilder(); // for (char c : entryName.toCharArray()) { @@ -924,298 +1105,117 @@ public class WpsExcelUtils { // numbers.append(c); // } // } -// // 第几个sheet对应的索引 // int number = Integer.parseInt(numbers.toString()); -// xlsxDrawingSheetVo.setSheetNumber(String.valueOf(number)); -// sheetCursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); -// while (sheetCursor.toNextSelection()) { -// // 2、开始获取内容 -// // 2-1、获取ID -// String id = sheetCursor.getAttributeText(new QName("Id")); -// // 2-2、获取文件路径 -// String target = sheetCursor.getAttributeText(new QName("Target")); -// // 3、在往下获取对应的文件,及文件路径 -// // 进行路径字符串替换 .. -> xl -// String newTarget = target.replace("..", "xl"); -// System.out.println("newTarget = " + newTarget); -// ZipEntry sharedStringsEntry2 = zipFile.getEntry(newTarget); -// InputStream inputStream2 = zipFile.getInputStream(sharedStringsEntry2); -// byte[] content2 = inputStream2.readAllBytes(); -// String xmlContent2 = new String(content2); -// // 使用 XmlObject 解析 sharedStrings.xml -// XmlObject xmlObject2 = XmlObject.Factory.parse(xmlContent2); -// XmlCursor sheetCursor2 = xmlObject2.newCursor(); -// // 4、判断是否存在对应文件的_rels * 文件 -// // 路径自定义 xl/drawings/drawing1.xml -// // 分割字符串 -// String[] split = newTarget.split("/"); -// String newRelsFilePath = split[0]+"/"+split[1]+"/_rels/"+split[2]+".rels"; -// // 在进行获取数据,获取文件路径 -// ZipEntry sharedStringsEntry3 = zipFile.getEntry(newRelsFilePath); -// if (sharedStringsEntry3 != null) { -// InputStream inputStream3 = zipFile.getInputStream(sharedStringsEntry3); -// byte[] content3 = inputStream3.readAllBytes(); -// String xmlContent3 = new String(content3); -// // 使用 XmlObject 解析 sharedStrings.xml -// XmlObject xmlObject3 = XmlObject.Factory.parse(xmlContent3); -// XmlCursor sheetCursor3 = xmlObject3.newCursor(); -// sheetCursor3.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); -// while (sheetCursor3.toNextSelection()) { -// // 2、开始获取内容 -// // 2-1、获取ID -// String id2 = sheetCursor3.getAttributeText(new QName("Id")); -// // 2-2、获取文件路径 -// String target2 = sheetCursor3.getAttributeText(new QName("Target")); -// // 3、在往下获取对应的文件,及文件路径 -// System.out.println("target2 = " + target2); -// // 进行路径字符串替换 .. -> xl -// String newTarget2 = target2.replace("..", "xl"); -// } +// // 如果列表为空,则创建新的xlsxCharVO对象 +// // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 +// Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); +// if (result.isEmpty()) { +// // 创建新的xlsxCharVO对象 +// XlsxCharVO xlsxCharVO = new XlsxCharVO(); +// xlsxCharVO.setCount(number); +// xlsxCharVO.setChars(cursor); +// xlsxCharVos.add(xlsxCharVO); +// } else { +// XlsxCharVO lastXlsxCharVO = result.get(); +// lastXlsxCharVO.setChars(cursor); +// xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); +// xlsxCharVos.add(lastXlsxCharVO); +// } +// } +// if (entryName.startsWith("xl/charts/style") && entryName.endsWith(".xml")) { +// // 读取数据 +// ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); +// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +// byte[] content = inputStream.readAllBytes(); +// String xmlContent = new String(content); +// // 使用 XmlObject 解析 sharedStrings.xml +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// // 正则匹配:提取连续的数字 +// StringBuilder numbers = new StringBuilder(); +// for (char c : entryName.toCharArray()) { +// // 检查是否是数字 +// if (Character.isDigit(c)) { +// numbers.append(c); // } -// +// } +// int number = Integer.parseInt(numbers.toString()); +// // 如果列表为空,则创建新的xlsxCharVO对象 +// // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 +// Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); +// if (result.isEmpty()) { +// // 创建新的xlsxCharVO对象 +// XlsxCharVO xlsxCharVO = new XlsxCharVO(); +// xlsxCharVO.setCount(number); +// xlsxCharVO.setStyle(cursor); +// xlsxCharVos.add(xlsxCharVO); +// } else { +// XlsxCharVO lastXlsxCharVO = result.get(); +// lastXlsxCharVO.setStyle(cursor); +// xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); +// xlsxCharVos.add(lastXlsxCharVO); +// } +// } +// if (entryName.startsWith("xl/charts/color") && entryName.endsWith(".xml")) { +// // 读取数据 +// ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); +// InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); +// byte[] content = inputStream.readAllBytes(); +// String xmlContent = new String(content); +// // 使用 XmlObject 解析 sharedStrings.xml +// XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); +// XmlCursor cursor = xmlObject.newCursor(); +// // 正则匹配:提取连续的数字 +// StringBuilder numbers = new StringBuilder(); +// for (char c : entryName.toCharArray()) { +// // 检查是否是数字 +// if (Character.isDigit(c)) { +// numbers.append(c); +// } +// } +// int number = Integer.parseInt(numbers.toString()); +// // 如果列表为空,则创建新的xlsxCharVO对象 +// // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 +// Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); +// if (result.isEmpty()) { +// // 创建新的xlsxCharVO对象 +// XlsxCharVO xlsxCharVO = new XlsxCharVO(); +// xlsxCharVO.setCount(number); +// xlsxCharVO.setColors(cursor); +// xlsxCharVos.add(xlsxCharVO); +// } else { +// XlsxCharVO lastXlsxCharVO = result.get(); +// lastXlsxCharVO.setColors(cursor); +// xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); +// xlsxCharVos.add(lastXlsxCharVO); // } // } // } // zipFile.close(); // 关闭 zip 文件 -// return ""; +// return xlsxCharVos; // } - - public static String getDrawingInfos(String excelFilePath) throws Exception { - try (ZipFile zipFile = new ZipFile(excelFilePath)) { - Enumeration entries = zipFile.entries(); - - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String entryName = entry.getName(); - - if (entryName.startsWith("xl/worksheets/_rels") && entryName.endsWith(".xml.rels")) { - String xmlContent = readZipEntry(zipFile, entryName); - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - - // 正则匹配:提取连续的数字 - StringBuilder numbers = new StringBuilder(); - for (char c : entryName.toCharArray()) { - // 检查是否是数字 - if (Character.isDigit(c)) { - numbers.append(c); - } - } - // 第几个sheet对应的索引 - int number = Integer.parseInt(numbers.toString()); - List drawingVOS = new ArrayList<>(); - cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); - while (cursor.toNextSelection()) { - // 2、开始获取内容 - XlsxDrawingSheetVo xlsxDrawingSheetVo = new XlsxDrawingSheetVo(); - String rId = cursor.getAttributeText(new QName("Id")); - String target = cursor.getAttributeText(new QName("Target")); - String nextPath = target.replace("..", "xl"); - xlsxDrawingSheetVo.setSheetNumber(String.valueOf(number)); - xlsxDrawingSheetVo.setRId(rId); - traverseRels(zipFile, nextPath, xlsxDrawingSheetVo, String.valueOf(number), drawingVOS); - } - drawingSheetVOS.add(drawingVOS); - } - } - } - return ""; - } - // 递归遍历 _rels 下级文件 - private static void traverseRels(ZipFile zipFile, String path, XlsxDrawingSheetVo xlsxDrawingSheetVo, String sheetName, List drawingVOS) throws Exception { - if (path == null || path.isEmpty()) return; - // 1、获取对应文件内容 - String content = readZipEntry(zipFile, path); - // 文件不存在,终止链 - if (content == null) return; - XmlObject xmlObject = XmlObject.Factory.parse(content); - XmlCursor cursor = xmlObject.newCursor(); - xlsxDrawingSheetVo.setXmlCursor(cursor); -// System.out.println(cursor.xmlText()); - // 生成对应的 .rels 路径 - String[] parts = path.split("/"); - String relsPath = parts[0] + "/" + parts[1] + "/_rels/" + parts[2] + ".rels"; - xlsxDrawingSheetVo.setTypeName(path); - drawingVOS.add(xlsxDrawingSheetVo); - String contents = readZipEntry(zipFile, relsPath); - // 文件不存在,终止链 - if (contents == null) return; - XmlObject xmlObjects = XmlObject.Factory.parse(contents); - XmlCursor cursors = xmlObjects.newCursor(); - cursors.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); - // 2、开始获取内容 - while (cursors.toNextSelection()) { -// System.out.println(cursors.xmlText()); - XlsxDrawingSheetVo xlsxDrawingSheetVos = new XlsxDrawingSheetVo(); - String target = cursors.getAttributeText(new QName("Target")); - String rId = cursors.getAttributeText(new QName("Id")); - xlsxDrawingSheetVos.setRId(rId); - xlsxDrawingSheetVos.setSheetNumber(sheetName); - xlsxDrawingSheetVos.setRId(rId); - if (target == null) continue; - String newPath = ""; - if (!target.contains("./")) { - // 如果没有包含路径,可能是在原本的路径下面 - newPath = parts[0] + "/" + parts[1] + "/" + target; - } else { - newPath = target.replace("..", "xl"); - } - -// System.out.println("Found path: " + newPath); - // 递归继续查找下一级 - if (zipFile.getEntry(relsPath) != null) { - traverseRels(zipFile, newPath, xlsxDrawingSheetVos, sheetName, drawingVOS); - } - } - } - // 工具方法:从 zip 文件中读取条目内容 - private static String readZipEntry(ZipFile zipFile, String entryName) throws IOException { - ZipEntry entry = zipFile.getEntry(entryName); - if (entry == null) return null; - try (InputStream is = zipFile.getInputStream(entry)) { - return new String(is.readAllBytes()); - } - } - - - public static List extractChartXml(String excelFilePath) throws Exception { - List xlsxCharVos = new ArrayList<>(); - // 解压 Excel 文件并读取 sharedStrings.xml - ZipFile zipFile = new ZipFile(excelFilePath); - - Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - String entryName = entry.getName(); - // 检查是否属于 xl/charts/ 目录下的图表文件 - if (entryName.startsWith("xl/charts/chart") && entryName.endsWith(".xml")) { - // 读取数据 - ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - // 正则匹配:提取连续的数字 - StringBuilder numbers = new StringBuilder(); - for (char c : entryName.toCharArray()) { - // 检查是否是数字 - if (Character.isDigit(c)) { - numbers.append(c); - } - } - int number = Integer.parseInt(numbers.toString()); - // 如果列表为空,则创建新的xlsxCharVO对象 - // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 - Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); - if (result.isEmpty()) { - // 创建新的xlsxCharVO对象 - XlsxCharVO xlsxCharVO = new XlsxCharVO(); - xlsxCharVO.setCount(number); - xlsxCharVO.setChars(cursor); - xlsxCharVos.add(xlsxCharVO); - } else { - XlsxCharVO lastXlsxCharVO = result.get(); - lastXlsxCharVO.setChars(cursor); - xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); - xlsxCharVos.add(lastXlsxCharVO); - } - } - if (entryName.startsWith("xl/charts/style") && entryName.endsWith(".xml")) { - // 读取数据 - ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - // 正则匹配:提取连续的数字 - StringBuilder numbers = new StringBuilder(); - for (char c : entryName.toCharArray()) { - // 检查是否是数字 - if (Character.isDigit(c)) { - numbers.append(c); - } - } - int number = Integer.parseInt(numbers.toString()); - // 如果列表为空,则创建新的xlsxCharVO对象 - // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 - Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); - if (result.isEmpty()) { - // 创建新的xlsxCharVO对象 - XlsxCharVO xlsxCharVO = new XlsxCharVO(); - xlsxCharVO.setCount(number); - xlsxCharVO.setStyle(cursor); - xlsxCharVos.add(xlsxCharVO); - } else { - XlsxCharVO lastXlsxCharVO = result.get(); - lastXlsxCharVO.setStyle(cursor); - xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); - xlsxCharVos.add(lastXlsxCharVO); - } - } - if (entryName.startsWith("xl/charts/color") && entryName.endsWith(".xml")) { - // 读取数据 - ZipEntry sharedStringsEntry = zipFile.getEntry(entryName); - InputStream inputStream = zipFile.getInputStream(sharedStringsEntry); - byte[] content = inputStream.readAllBytes(); - String xmlContent = new String(content); - // 使用 XmlObject 解析 sharedStrings.xml - XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); - XmlCursor cursor = xmlObject.newCursor(); - // 正则匹配:提取连续的数字 - StringBuilder numbers = new StringBuilder(); - for (char c : entryName.toCharArray()) { - // 检查是否是数字 - if (Character.isDigit(c)) { - numbers.append(c); - } - } - int number = Integer.parseInt(numbers.toString()); - // 如果列表为空,则创建新的xlsxCharVO对象 - // 如果列表不为空,则检查最后一个元素的count是否等于当前数字 - Optional result = xlsxCharVos.stream().filter(xlsxCharVO -> number == xlsxCharVO.getCount()).findFirst(); - if (result.isEmpty()) { - // 创建新的xlsxCharVO对象 - XlsxCharVO xlsxCharVO = new XlsxCharVO(); - xlsxCharVO.setCount(number); - xlsxCharVO.setColors(cursor); - xlsxCharVos.add(xlsxCharVO); - } else { - XlsxCharVO lastXlsxCharVO = result.get(); - lastXlsxCharVO.setColors(cursor); - xlsxCharVos.removeIf(xlsxCharVO -> number == xlsxCharVO.getCount()); - xlsxCharVos.add(lastXlsxCharVO); - } - } - } - zipFile.close(); // 关闭 zip 文件 - return xlsxCharVos; - } - - - public static String getNamespace(String 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(); - return allPathx; - } -} +// +// +// public static String getNamespace(String 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(); +// return allPathx; +// } +//} 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 deleted file mode 100644 index bac8a952..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/DeclareNamespaceForPPT.java +++ /dev/null @@ -1,40 +0,0 @@ -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 deleted file mode 100644 index 4f640926..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementConvert.java +++ /dev/null @@ -1,161 +0,0 @@ -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 deleted file mode 100644 index ae832307..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/JudgementWpsPPT.java +++ /dev/null @@ -1,413 +0,0 @@ -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) 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 path = reqVo.getPath(); - 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 { - if (element == null) { - return null; - } - 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 { - if (element == null) { - return null; - } - 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/ReflectionAnalyzer.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/ReflectionAnalyzer.java deleted file mode 100644 index 50906514..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/ReflectionAnalyzer.java +++ /dev/null @@ -1,57 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx; - -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ReflectionAnalyzer { - - public static String analyzeReflection(String reflectionTag) { - Map attrMap = new HashMap<>(); - - // 提取属性 - Pattern pattern = Pattern.compile("(\\w+)=\"([^\"]+)\""); - Matcher matcher = pattern.matcher(reflectionTag); - while (matcher.find()) { - attrMap.put(matcher.group(1), matcher.group(2)); - } - - // 读取关键属性 - int sy = Integer.parseInt(attrMap.getOrDefault("sy", "0")); - String algn = attrMap.getOrDefault("algn", ""); - - // 分类 sy 类型 - String scaleType; - if (sy == -100000) { - scaleType = "镜像倒影"; - } else if (sy < -100000) { - scaleType = "放大倒影"; - } else if (sy < 0) { - scaleType = "缩小倒影"; - } else { - scaleType = "非倒影或非法值"; - } - - // 分类 algn 类型 - String contactType = switch (algn) { - case "bl", "b" -> "接触"; - case "ctr", "t", "tl", "tr" -> "不接触"; - default -> "未知"; - }; - - return scaleType + "," + contactType; - } - - public static void main(String[] args) { - String input1 = ""; - String input2 = ""; - String input3 = ""; - String input4 = ""; - - System.out.println(analyzeReflection(input1)); // 镜像倒影,接触 - System.out.println(analyzeReflection(input2)); // 缩小倒影,不接触 - System.out.println(analyzeReflection(input3)); // 放大倒影,接触 - System.out.println(analyzeReflection(input4)); // 非倒影或非法值,不接触 - } -} \ No newline at end of file diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java deleted file mode 100644 index 0b86bba6..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/SlideAnimationQueryByCursor.java +++ /dev/null @@ -1,74 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx; - -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; - - -public class SlideAnimationQueryByCursor { - - public static String getAnimationInfoForSpid(XmlCursor cursor, String spid, String infoType) { - cursor.toStartDoc(); - cursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + - "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' " + - "declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' " + - "$this//p: "); - - while (cursor.toNextSelection()) { - XmlObject spTgtObj = cursor.getObject(); - XmlCursor spTgtCursor = spTgtObj.newCursor(); - String spidAttr = spTgtCursor.getAttributeText(new javax.xml.namespace.QName("", "spid")); - if (!spid.equals(spidAttr)) continue; - - // 当前 spTgt 的祖先就是动画节点(通常为 anim, set, 或 cTn) - XmlCursor animCursor = spTgtObj.newCursor(); - animCursor.toParent(); // tgtEl - animCursor.toParent(); // anim, set, etc. - - String tag = animCursor.getName().getLocalPart(); - String dur = animCursor.getAttributeText(new javax.xml.namespace.QName("", "dur")); - String presetClass = animCursor.getAttributeText(new javax.xml.namespace.QName("", "presetClass")); - - switch (infoType) { - case "效果": - return (presetClass != null && !presetClass.isEmpty()) ? presetClass : tag; - - case "方向": - // 查找 - cursor.toStartDoc(); - cursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + - "$this//p:pull"); - while (cursor.toNextSelection()) { - String dir = cursor.getAttributeText(new javax.xml.namespace.QName("", "dir")); - if (dir != null) return dir; - } - return "无方向设置"; - - case "触发方式": - animCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + - "$this/p:stCondLst/p:cond"); - while (animCursor.toNextSelection()) { - String evt = animCursor.getAttributeText(new javax.xml.namespace.QName("", "evt")); - String delay = animCursor.getAttributeText(new javax.xml.namespace.QName("", "delay")); - if (evt != null) return evt; - if (delay != null) return "延迟:" + delay; - } - return "无触发信息"; - - case "持续时间": - if (dur != null) return dur + " ms"; - // 也许 有 dur - animCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " + - "$this//p:cTn"); - while (animCursor.toNextSelection()) { - String d = animCursor.getAttributeText(new javax.xml.namespace.QName("", "dur")); - if (d != null) return d + " ms"; - } - return "无持续时间信息"; - - default: - return "不支持的查询类型:" + infoType; - } - } - return "未找到 spid=" + spid + " 的动画"; - } -} \ No newline at end of file diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxNameSpaces.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxNameSpaces.java deleted file mode 100644 index 3fda9aad..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxNameSpaces.java +++ /dev/null @@ -1,35 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx; - -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -@SuppressWarnings("all") -public class WpsPptxNameSpaces { - - public static String getNameSpace(String xmlString) { - // 2、创建最全的命名空间 -// Pattern pattern = Pattern.compile("xmlns:(\\w+)='([^']+)'"); -// Matcher matcher = pattern.matcher(xmlString); -// Map namespaces = new HashMap<>(); -// while (matcher.find()) { -// // 如 w, wp, a -// String prefix = matcher.group(1); -// // 如 http://schemas.openxmlformats.org/... -// 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(); - return "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' declare namespace pic='http://schemas.openxmlformats.org/drawingml/2006/picture' declare namespace c='http://schemas.openxmlformats.org/drawingml/2006/chart' declare namespace dgm='http://schemas.openxmlformats.org/drawingml/2006/diagram' declare namespace lc='http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas' declare namespace v='urn:schemas-microsoft-com:vml' declare namespace o='urn:schemas-microsoft-com:office:office' declare namespace m='http://schemas.openxmlformats.org/officeDocument/2006/math' declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' declare namespace a15='http://schemas.microsoft.com/office/drawing/2012/main' declare namespace a16='http://schemas.microsoft.com/office/drawing/2014/main' declare namespace c14='http://schemas.microsoft.com/office/drawing/2007/8/chart' declare namespace p14='http://schemas.microsoft.com/office/powerpoint/2010/main' declare namespace p15='http://schemas.microsoft.com/office/powerpoint/2012/main' declare namespace p16='http://schemas.microsoft.com/office/powerpoint/2015/main' declare namespace pvml='urn:schemas-microsoft-com:office:powerpoint' declare namespace svg='http://schemas.microsoft.com/office/drawing/2016/SVG/main' declare namespace am3d='http://schemas.microsoft.com/office/drawing/2017/model3D' "; - } -} 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 deleted file mode 100644 index fa5a7d54..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/WpsPptxUtils.java +++ /dev/null @@ -1,808 +0,0 @@ -//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("单机鼠标换片")) { -//// -//// } -// 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 deleted file mode 100644 index 9eefaf6d..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/XmlRecursiveFinder.java +++ /dev/null @@ -1,39 +0,0 @@ -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/vo/PptxInfoPointsVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoPointsVo.java deleted file mode 100644 index f9691bb5..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoPointsVo.java +++ /dev/null @@ -1,24 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx.vo; - -import lombok.Data; - -@Data -public class PptxInfoPointsVo { - - private String name; - - private String englishName; - - private String filePath; - - private String function; - - private String belongTo; - - private String isboo; - - private String type; - - private String unit; - -} 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 deleted file mode 100644 index 4dc67f66..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxInfoReqVo.java +++ /dev/null @@ -1,30 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx.vo; - -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author REN - */ -@Data -public class PptxInfoReqVo { - - private String name; - - private String englishName; - - private String filePath; - - private String parentId; - - private String selectName; - - private String title; - - 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/vo/PptxListVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxListVo.java deleted file mode 100644 index f7bffb2e..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxListVo.java +++ /dev/null @@ -1,23 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx.vo; - -import lombok.Data; -import org.apache.xmlbeans.XmlCursor; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author REN - */ -@Data -public class PptxListVo { - - private String name; - - private XmlCursor xmlCursor; - - private String target; - - private XmlCursor resXmlCursor; - -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxSlidesVo.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxSlidesVo.java deleted file mode 100644 index 43d73f61..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxSlidesVo.java +++ /dev/null @@ -1,17 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx.vo; - -import lombok.Data; -import org.apache.xmlbeans.XmlCursor; - -import java.util.List; -import java.util.Map; - -@Data -public class PptxSlidesVo { - - private String slideName; - - private XmlCursor xmlCursor; - - private List> slideResList; -} diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxVO.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxVO.java deleted file mode 100644 index 48e80e77..00000000 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/vo/PptxVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package pc.exam.pp.module.judgement.utils.wps_pptx.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.List; - -@Data -public class PptxVO { - - @Schema(description = "考试考点") - private String examKeynote; - - @Schema(description = "考点汉化") - private String keynoteChinese; - - @Schema(description = "代码") - private String code; -} diff --git a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java index e3695cb9..b8d7071a 100644 --- a/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java +++ b/exam-module-system/exam-module-system-biz/src/main/java/pc/exam/pp/module/system/service/user/AdminUserServiceImpl.java @@ -12,6 +12,7 @@ import pc.exam.pp.framework.common.util.object.BeanUtils; import pc.exam.pp.framework.common.util.validation.ValidationUtils; import pc.exam.pp.framework.datapermission.core.util.DataPermissionUtils; import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils; +import pc.exam.pp.framework.tenant.core.context.TenantContextHolder; import pc.exam.pp.framework.web.core.util.WebFrameworkUtils; import pc.exam.pp.module.exam.controller.admin.classs.vo.ClassSaveReqVO; import pc.exam.pp.module.exam.controller.admin.specialty.vo.SpecialtListByUserReqVo; @@ -30,10 +31,12 @@ import pc.exam.pp.module.system.controller.admin.user.vo.user.*; import pc.exam.pp.module.system.dal.dataobject.dept.DeptDO; import pc.exam.pp.module.system.dal.dataobject.dept.UserPostDO; import pc.exam.pp.module.system.dal.dataobject.tenant.TenantDO; +import pc.exam.pp.module.system.dal.dataobject.tenant.TenantSpcialtyDO; import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO; import pc.exam.pp.module.system.dal.dataobject.user.TeacherClassDO; import pc.exam.pp.module.system.dal.dataobject.user.TeacherSpecialtyDO; import pc.exam.pp.module.system.dal.mysql.dept.UserPostMapper; +import pc.exam.pp.module.system.dal.mysql.tenant.TenantSpecialtyMapper; import pc.exam.pp.module.system.dal.mysql.user.AdminUserMapper; import pc.exam.pp.module.system.dal.mysql.user.TeacherClassMapper; import pc.exam.pp.module.system.dal.mysql.user.TeacherSpecialtyMapper; @@ -108,6 +111,9 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private ExamSpecialtyMapper examSpecialtyMapper; + @Resource + TenantSpecialtyMapper tenantSpecialtyMapper; + @Override @Transactional(rollbackFor = Exception.class) @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_CREATE_SUB_TYPE, bizNo = "{{#user.id}}", @@ -823,27 +829,62 @@ public class AdminUserServiceImpl implements AdminUserService { @Override public List getListByUser() { Long userId = WebFrameworkUtils.getLoginUserId(); + // 获取考点ID + Long tenantId = TenantContextHolder.getTenantId(); AdminUserDO adminUserDO = getUser(userId); List specialtyQueryVos = new ArrayList<>(); - // 判断用户类型 管理员所有专业 - if (adminUserDO.getUserType().equals("0")) { - // 查询所有专业数据 - specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); - } else { - // 判断专业是否为空,为空的话查询所有 - if (adminUserDO.getSpecialtyIds() == null) { - // 查询所有数据 + // 判断是否是中心服务器,如果是中心服务器的话直接返回所有,如果不是查询对应的授权数据 + if (tenantId == 1) { + // 判断用户类型 管理员所有专业 + if (adminUserDO.getUserType().equals("0")) { + // 查询所有专业数据 specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); } else { - // 查询部分数据 - List specialtyList = examSpecialtyMapper.selectExamSpecialtyByids(adminUserDO.getSpecialtyIds()); - for (SpecialtyQueryVo specialtyQueryVo : specialtyList) { - specialtyQueryVos.add(specialtyQueryVo); - // 查询题型 - if (specialtyQueryVo.getAncestors().contains(",")) { - List specialtyLists = examSpecialtyMapper.selectExamSpecialtyByParentId(specialtyQueryVo.getId()); - for (SpecialtyQueryVo specialtyQueryVosInfo : specialtyLists) { - specialtyQueryVos.add(specialtyQueryVosInfo); + // 判断专业是否为空,为空的话查询所有 + if (adminUserDO.getSpecialtyIds() == null) { + // 查询所有数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); + } else { + // 查询部分数据 + List specialtyList = examSpecialtyMapper.selectExamSpecialtyByids(adminUserDO.getSpecialtyIds()); + for (SpecialtyQueryVo specialtyQueryVo : specialtyList) { + specialtyQueryVos.add(specialtyQueryVo); + // 查询题型 + if (specialtyQueryVo.getAncestors().contains(",")) { + List specialtyLists = examSpecialtyMapper.selectExamSpecialtyByParentId(specialtyQueryVo.getId()); + for (SpecialtyQueryVo specialtyQueryVosInfo : specialtyLists) { + specialtyQueryVos.add(specialtyQueryVosInfo); + } + } + } + } + } + } else { + // 需要先界定 数据范围,通过考点服务器ID进行查询考点服务器的授权范围 + List tenantSpcialtyDOS = tenantSpecialtyMapper.getSpecialtyPoints(tenantId); + + + + // 判断用户类型 管理员所有专业 + if (adminUserDO.getUserType().equals("0")) { + // 查询所有专业数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); + } else { + // 判断专业是否为空,为空的话查询所有 + if (adminUserDO.getSpecialtyIds() == null) { + // 查询所有数据 + specialtyQueryVos = examSpecialtyMapper.selectExamSpecialtyAll(); + } else { + // 查询部分数据 + List specialtyList = examSpecialtyMapper.selectExamSpecialtyByids(adminUserDO.getSpecialtyIds()); + for (SpecialtyQueryVo specialtyQueryVo : specialtyList) { + specialtyQueryVos.add(specialtyQueryVo); + // 查询题型 + if (specialtyQueryVo.getAncestors().contains(",")) { + List specialtyLists = examSpecialtyMapper.selectExamSpecialtyByParentId(specialtyQueryVo.getId()); + for (SpecialtyQueryVo specialtyQueryVosInfo : specialtyLists) { + specialtyQueryVos.add(specialtyQueryVosInfo); + } } } }