【修改】 1、文件名称修改;2、word考点完善
This commit is contained in:
@@ -1,27 +1,21 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord;
|
package pc.exam.pp.module.judgement.controller.admin.Wps;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import pc.exam.pp.framework.common.enums.CommonStatusEnum;
|
import pc.exam.pp.framework.common.enums.CommonStatusEnum;
|
||||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||||
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordRespVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordRespVO;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordSaveReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordSimpleRespVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSimpleRespVO;
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||||
import pc.exam.pp.module.judgement.service.wps_word.WpsWordLinkService;
|
import pc.exam.pp.module.judgement.service.wps_word.WpsWordLinkService;
|
||||||
import pc.exam.pp.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
||||||
import pc.exam.pp.module.system.controller.admin.dept.vo.dept.DeptRespVO;
|
|
||||||
import pc.exam.pp.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
||||||
import pc.exam.pp.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO;
|
|
||||||
import pc.exam.pp.module.system.dal.dataobject.dept.DeptDO;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord;
|
package pc.exam.pp.module.judgement.controller.admin.Wps;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||||
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
|
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
|
||||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,8 +18,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/tool/wps_word")
|
@RequestMapping("/tool/wps")
|
||||||
@Tag( name = "WPSWORD")
|
@Tag( name = "wps相关操作")
|
||||||
@Validated
|
@Validated
|
||||||
public class WpsWordController {
|
public class WpsWordController {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord.vo;
|
package pc.exam.pp.module.judgement.controller.admin.Wps.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord.vo;
|
package pc.exam.pp.module.judgement.controller.admin.Wps.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord.vo;
|
package pc.exam.pp.module.judgement.controller.admin.Wps.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.Email;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package pc.exam.pp.module.judgement.controller.admin.WpsWord.vo;
|
package pc.exam.pp.module.judgement.controller.admin.Wps.vo;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package pc.exam.pp.module.judgement.dal.mysql.wpsword;
|
package pc.exam.pp.module.judgement.dal.mysql.wpsword;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||||
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
||||||
|
|
||||||
@@ -17,6 +16,7 @@ public interface WpsWordLinkMapper extends BaseMapperX<WpsWordLinkDO> {
|
|||||||
default List<WpsWordLinkDO> selectList(WordListReqVO reqVO) {
|
default List<WpsWordLinkDO> selectList(WordListReqVO reqVO) {
|
||||||
return selectList(new LambdaQueryWrapperX<WpsWordLinkDO>()
|
return selectList(new LambdaQueryWrapperX<WpsWordLinkDO>()
|
||||||
.likeIfPresent(WpsWordLinkDO::getName, reqVO.getName())
|
.likeIfPresent(WpsWordLinkDO::getName, reqVO.getName())
|
||||||
|
.eq(reqVO.getBelongTo() != null, WpsWordLinkDO::getBelongTo, reqVO.getBelongTo())
|
||||||
.eqIfPresent(WpsWordLinkDO::getStatus, reqVO.getStatus()));
|
.eqIfPresent(WpsWordLinkDO::getStatus, reqVO.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,21 +4,12 @@ package pc.exam.pp.module.judgement.service.wps_excel;
|
|||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
|
|
||||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
|
||||||
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
|
|
||||||
import pc.exam.pp.module.infra.service.config.ConfigService;
|
import pc.exam.pp.module.infra.service.config.ConfigService;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
|
||||||
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
||||||
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
||||||
import pc.exam.pp.module.judgement.utils.wps_excel.WpsExcelUtils;
|
import pc.exam.pp.module.judgement.utils.wps_excel.WpsExcelUtils;
|
||||||
import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils;
|
|
||||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService {
|
public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
|||||||
import pc.exam.pp.module.exam.utils.file.LogFileUtils;
|
import pc.exam.pp.module.exam.utils.file.LogFileUtils;
|
||||||
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
|
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
|
||||||
import pc.exam.pp.module.infra.service.config.ConfigService;
|
import pc.exam.pp.module.infra.service.config.ConfigService;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||||
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
||||||
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
||||||
@@ -17,8 +17,6 @@ import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils;
|
|||||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -35,6 +33,7 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WordVO> ProgrammingWpsWord(String path) throws Exception {
|
public List<WordVO> ProgrammingWpsWord(String path) throws Exception {
|
||||||
|
|
||||||
// 1、获取文件临时下载路径
|
// 1、获取文件临时下载路径
|
||||||
ConfigDO config = configService.getConfigByKey("file_down_path");
|
ConfigDO config = configService.getConfigByKey("file_down_path");
|
||||||
// 2、下载文件并返回文件完整路径
|
// 2、下载文件并返回文件完整路径
|
||||||
@@ -42,9 +41,13 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
|
|||||||
// 3、创建word考点tree
|
// 3、创建word考点tree
|
||||||
WordListReqVO wordListReqVO = new WordListReqVO();
|
WordListReqVO wordListReqVO = new WordListReqVO();
|
||||||
wordListReqVO.setBelongTo(0);
|
wordListReqVO.setBelongTo(0);
|
||||||
List<WpsWordLinkDO> list = wpsWordLinkMapper.selectList(wordListReqVO);
|
// 3-1、查询段落的标签
|
||||||
|
List<WpsWordLinkDO> paragraphList = wpsWordLinkMapper.selectList(wordListReqVO);
|
||||||
|
// 3-2、查询锚点的标签
|
||||||
|
wordListReqVO.setBelongTo(3);
|
||||||
|
List<WpsWordLinkDO> anchorList = wpsWordLinkMapper.selectList(wordListReqVO);
|
||||||
// 4、docx文件读取并返回考点及说明信息
|
// 4、docx文件读取并返回考点及说明信息
|
||||||
List<WordVO> margins1 = WpsWordUtils.wps_word(pathName, list);
|
List<WordVO> margins1 = WpsWordUtils.wps_word(pathName, paragraphList, anchorList);
|
||||||
// 5、已经读取完得考点删除源文件
|
// 5、已经读取完得考点删除源文件
|
||||||
File file = new File(pathName);
|
File file = new File(pathName);
|
||||||
file.delete();
|
file.delete();
|
||||||
@@ -60,9 +63,13 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
|
|||||||
// 1、查询Word考点tree
|
// 1、查询Word考点tree
|
||||||
WordListReqVO wordListReqVO = new WordListReqVO();
|
WordListReqVO wordListReqVO = new WordListReqVO();
|
||||||
wordListReqVO.setBelongTo(0);
|
wordListReqVO.setBelongTo(0);
|
||||||
List<WpsWordLinkDO> list = wpsWordLinkMapper.selectList(wordListReqVO);
|
// 3-1、查询段落的标签
|
||||||
|
List<WpsWordLinkDO> paragraphList = wpsWordLinkMapper.selectList(wordListReqVO);
|
||||||
|
// 3-2、查询锚点的标签
|
||||||
|
wordListReqVO.setBelongTo(3);
|
||||||
|
List<WpsWordLinkDO> anchorList = wpsWordLinkMapper.selectList(wordListReqVO);
|
||||||
// 2、docx文件读取并返回考点及说明信息
|
// 2、docx文件读取并返回考点及说明信息
|
||||||
List<WordVO> margins1 = WpsWordUtils.wps_word(path, list);
|
List<WordVO> margins1 = WpsWordUtils.wps_word(path, paragraphList, anchorList);
|
||||||
// 3、获取答案得组成
|
// 3、获取答案得组成
|
||||||
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
|
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
|
||||||
// 4、进行关联判断
|
// 4、进行关联判断
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package pc.exam.pp.module.judgement.service.wps_word;
|
package pc.exam.pp.module.judgement.service.wps_word;
|
||||||
|
|
||||||
import pc.exam.pp.framework.common.util.collection.CollectionUtils;
|
import pc.exam.pp.framework.common.util.collection.CollectionUtils;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordSaveReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO;
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||||
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import pc.exam.pp.framework.common.enums.CommonStatusEnum;
|
|||||||
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
||||||
import pc.exam.pp.framework.datapermission.core.annotation.DataPermission;
|
import pc.exam.pp.framework.datapermission.core.annotation.DataPermission;
|
||||||
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
|
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||||
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordSaveReqVO;
|
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordSaveReqVO;
|
||||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||||
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
|
||||||
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
||||||
|
|||||||
@@ -18,36 +18,105 @@ public class WpsWordUtils {
|
|||||||
/**
|
/**
|
||||||
* 获取文档段落W:P标签得数量,判断出一个有多少段
|
* 获取文档段落W:P标签得数量,判断出一个有多少段
|
||||||
*/
|
*/
|
||||||
public static List<WordVO> wps_word(String filePath, List<WpsWordLinkDO> wpsWordLinkDOS) throws Exception {
|
public static List<WordVO> wps_word(String filePath, List<WpsWordLinkDO> paragraphList, List<WpsWordLinkDO> anchorList) throws Exception {
|
||||||
List<WordVO> wordVO = new ArrayList<>();
|
List<WordVO> wordVO = new ArrayList<>();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
// 路径初始化
|
// 1、路径初始化
|
||||||
String xmlpath = "";
|
String xmlpath = "";
|
||||||
|
String type = "";
|
||||||
XWPFDocument document = new XWPFDocument(new FileInputStream(filePath));
|
XWPFDocument document = new XWPFDocument(new FileInputStream(filePath));
|
||||||
String xmlString = XmlUtil.getDocumentXml(document);
|
String xmlString = XmlUtil.getDocumentXml(document);
|
||||||
// 获取CTDocument对象
|
// 2、创建最全的命名空间
|
||||||
|
Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\"");
|
||||||
|
Matcher matcher = pattern.matcher(xmlString);
|
||||||
|
Map<String, String> 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();
|
||||||
|
// 3、获取CTDocument对象
|
||||||
XmlObject docXml = document.getDocument();
|
XmlObject docXml = document.getDocument();
|
||||||
List<WpsWordLinkDO> tree = TreeUtils.buildTree(wpsWordLinkDOS); // flatList 是你贴出的 JSON 解析出来的
|
// 3-1、段落的树数据
|
||||||
XmlObject xmlObject = document.getDocument(); // Word XML document
|
List<WpsWordLinkDO> paragraphTree = TreeUtils.buildTree(paragraphList);
|
||||||
// 创建一个list,存放word读取的数据
|
// 3-2、锚点的树数据
|
||||||
for (WpsWordLinkDO wpsWordLinkDO : tree) {
|
List<WpsWordLinkDO> anchorTree = TreeUtils.buildTree(anchorList);
|
||||||
|
// Word XML document
|
||||||
|
XmlObject xmlObject = document.getDocument();
|
||||||
|
for (WpsWordLinkDO anchor : anchorTree) {
|
||||||
|
String xpathAnchor = allPathx + "//" + anchor.getName();
|
||||||
|
XmlCursor cursorAnchor = docXml.newCursor();
|
||||||
|
int index = 0;
|
||||||
|
cursorAnchor.selectPath(xpathAnchor);
|
||||||
|
while (cursorAnchor.toNextSelection()) {
|
||||||
|
type = "图片";
|
||||||
|
index += 1;
|
||||||
|
XmlCursor cursorAnchorXml = cursorAnchor.getObject().newCursor();
|
||||||
|
XmlCursor cursorAnchorText = cursorAnchor.getObject().newCursor();
|
||||||
|
// 首先:判断类型 1 :图片,2:文本框
|
||||||
|
cursorAnchorXml.selectPath(allPathx + ".//wp:anchor/wp:docPr/@id");
|
||||||
|
String typeValue = "";
|
||||||
|
while (cursorAnchorXml.toNextSelection()) {
|
||||||
|
typeValue = cursorAnchorXml.getTextValue();
|
||||||
|
}
|
||||||
|
String anchorName = "图片";
|
||||||
|
if (Objects.equals(typeValue, "2")) {
|
||||||
|
System.out.println(cursorAnchorText.xmlText());
|
||||||
|
// 要获取文本框的文本
|
||||||
|
cursorAnchorText.selectPath(allPathx + ".//wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx");
|
||||||
|
while (cursorAnchorText.toNextSelection()) {
|
||||||
|
System.out.println(cursorAnchorText.getObject().xmlText());
|
||||||
|
anchorName = cursorAnchorText.getTextValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursorAnchorText.dispose();
|
||||||
|
cursorAnchorXml.dispose();
|
||||||
|
XmlObject paraObj = cursorAnchor.getObject();
|
||||||
|
for (WpsWordLinkDO root : anchor.getChildren()) {
|
||||||
|
traverseTreeAndQueryXml(type, wordVO, anchor.getName(), anchorName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursorAnchor.dispose();
|
||||||
|
}
|
||||||
|
// 创建一个list,存放word读取的数据(段落数据)
|
||||||
|
for (WpsWordLinkDO paragraph : paragraphTree) {
|
||||||
|
type = "段落";
|
||||||
// 段落划分 根据w:p标签
|
// 段落划分 根据w:p标签
|
||||||
// 到达参数节点,构造 XPath 路径查询它的值
|
// 到达参数节点,构造 XPath 路径查询它的值
|
||||||
String xpath = "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ";
|
String wpPath = allPathx + "/w:document/w:body/" + paragraph.getName();
|
||||||
xpath += "//"+wpsWordLinkDO.getName();
|
|
||||||
XmlCursor cursor = docXml.newCursor();
|
XmlCursor cursor = docXml.newCursor();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
cursor.selectPath(xpath);
|
cursor.selectPath(wpPath);
|
||||||
String xpathName = "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ";
|
|
||||||
while (cursor.toNextSelection()) {
|
while (cursor.toNextSelection()) {
|
||||||
|
String rTextName = "";
|
||||||
|
index += 1;
|
||||||
// 每一段进行赋值,进行判断
|
// 每一段进行赋值,进行判断
|
||||||
XmlObject paraObj = cursor.getObject();
|
XmlObject paraObj = cursor.getObject();
|
||||||
String paraText = paraObj.xmlText();
|
String paraText = paraObj.xmlText();
|
||||||
// System.out.println(paraText);
|
XmlCursor rCursor = paraObj.newCursor();
|
||||||
// System.out.println(cursor.getTextValue());
|
// 想要查询指定的path
|
||||||
index += 1;
|
rCursor.selectPath(allPathx + ".//w:r/w:t");
|
||||||
for (WpsWordLinkDO root : wpsWordLinkDO.getChildren()) {
|
while (rCursor.toNextSelection()) {
|
||||||
traverseTreeAndQueryXml(wordVO, wpsWordLinkDO.getName(), cursor.getTextValue(), xpathName, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1);
|
XmlCursor rsCursor = rCursor.getObject().newCursor();
|
||||||
|
rTextName = rsCursor.getTextValue();
|
||||||
|
rsCursor.dispose();
|
||||||
|
}
|
||||||
|
rCursor.dispose();
|
||||||
|
// 创建新的
|
||||||
|
for (WpsWordLinkDO root : paragraph.getChildren()) {
|
||||||
|
traverseTreeAndQueryXml(type, wordVO, paragraph.getName(), rTextName, allPathx, root, paraObj, new ArrayList<>(), new ArrayList<>(), index,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,14 +128,13 @@ public class WpsWordUtils {
|
|||||||
}
|
}
|
||||||
// 获取底层 XML 对象
|
// 获取底层 XML 对象
|
||||||
CTHdrFtr ctHdrFtr = header._getHdrFtr(); // ✅ 正确方法
|
CTHdrFtr ctHdrFtr = header._getHdrFtr(); // ✅ 正确方法
|
||||||
String xpath = "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' ";
|
String xpath = allPathx + "//w:hdr/w:p/w:r/w:pict";
|
||||||
xpath += "//w:hdr/w:p/w:r/w:pict";
|
|
||||||
XmlCursor cursor = ctHdrFtr.newCursor();
|
XmlCursor cursor = ctHdrFtr.newCursor();
|
||||||
cursor.selectPath(xpath);
|
cursor.selectPath(xpath);
|
||||||
while (cursor.toNextSelection()) {
|
while (cursor.toNextSelection()) {
|
||||||
// 查询 v:textpath 节点
|
// 查询 v:textpath 节点
|
||||||
cursor.selectPath(
|
cursor.selectPath(
|
||||||
"declare namespace v='urn:schemas-microsoft-com:vml' " +
|
allPathx +
|
||||||
".//v:textpath"
|
".//v:textpath"
|
||||||
);
|
);
|
||||||
while (cursor.toNextSelection()) {
|
while (cursor.toNextSelection()) {
|
||||||
@@ -86,6 +154,7 @@ public class WpsWordUtils {
|
|||||||
path.add("name:"+stringAttr);
|
path.add("name:"+stringAttr);
|
||||||
path.add("style:"+styleAttr);
|
path.add("style:"+styleAttr);
|
||||||
attr_word.setExamKeynote(path);
|
attr_word.setExamKeynote(path);
|
||||||
|
attr_word.setType("水印");
|
||||||
wordVO.add(attr_word);
|
wordVO.add(attr_word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,6 +175,7 @@ public class WpsWordUtils {
|
|||||||
email_word.setWordText("邮件合并");
|
email_word.setWordText("邮件合并");
|
||||||
email_word.setExamKeynote(email);
|
email_word.setExamKeynote(email);
|
||||||
email_word.setKeynoteChinese(email);
|
email_word.setKeynoteChinese(email);
|
||||||
|
email_word.setType("邮件合并");
|
||||||
wordVO.add(email_word);
|
wordVO.add(email_word);
|
||||||
}
|
}
|
||||||
return wordVO;
|
return wordVO;
|
||||||
@@ -126,6 +196,7 @@ public class WpsWordUtils {
|
|||||||
style_list.add("加粗: " + run.isBold());
|
style_list.add("加粗: " + run.isBold());
|
||||||
style_list.add("斜体: " + run.isItalic());
|
style_list.add("斜体: " + run.isItalic());
|
||||||
wordVO1.setKeynoteChinese(style_list);
|
wordVO1.setKeynoteChinese(style_list);
|
||||||
|
wordVO1.setType("页眉,页脚");
|
||||||
wordVO.add(wordVO1);
|
wordVO.add(wordVO1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,17 +216,31 @@ public class WpsWordUtils {
|
|||||||
style_list.add("加粗: " + run.isBold());
|
style_list.add("加粗: " + run.isBold());
|
||||||
style_list.add("斜体: " + run.isItalic());
|
style_list.add("斜体: " + run.isItalic());
|
||||||
wordVO1.setKeynoteChinese(style_list);
|
wordVO1.setKeynoteChinese(style_list);
|
||||||
|
wordVO1.setType("页眉,页脚");
|
||||||
wordVO.add(wordVO1);
|
wordVO.add(wordVO1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void traverseTreeAndQueryXml(List<WordVO> wordVOs, String firstTitle, String text, String xpath, WpsWordLinkDO node, XmlObject currentXml, List<String> pathSoFar, List<String> pathChinese, int index, int beginIndex) {
|
|
||||||
|
/**
|
||||||
|
* @param type String 用来存放类型
|
||||||
|
* @param wordVOs List<WordVO> 用来存放结果
|
||||||
|
* @param firstTitle String 用来存放一级标题
|
||||||
|
* @param text String 用来存放文本
|
||||||
|
* @param xpath String 用来存放xpath
|
||||||
|
* @param node WpsWordLinkDO 用来存放节点
|
||||||
|
* @param currentXml XmlObject 用来存放当前xml
|
||||||
|
* @param pathSoFar List<String> 用来存放路径
|
||||||
|
* @param pathChinese List<String> 用来存放中文路径
|
||||||
|
* @param index int 用来存放索引
|
||||||
|
* @param beginIndex int 用来存放开始索引
|
||||||
|
*/
|
||||||
|
public static void traverseTreeAndQueryXml(String type, List<WordVO> wordVOs, String firstTitle, String text, String xpath, WpsWordLinkDO node, XmlObject currentXml, List<String> pathSoFar, List<String> pathChinese, int index, int beginIndex) {
|
||||||
// 到达参数节点,构造 XPath 路径查询它的值
|
// 到达参数节点,构造 XPath 路径查询它的值
|
||||||
if (beginIndex == 1) {
|
if (beginIndex == 1) {
|
||||||
xpath += "//" + firstTitle + "[" + index + "]/";
|
xpath += "./";
|
||||||
}
|
}
|
||||||
pathSoFar.add(node.getName());
|
pathSoFar.add(node.getName());
|
||||||
pathChinese.add(node.getToChinese() + index);
|
pathChinese.add(node.getToChinese() + index);
|
||||||
@@ -163,9 +248,9 @@ public class WpsWordUtils {
|
|||||||
if (node.getType() == 1) {
|
if (node.getType() == 1) {
|
||||||
// pathSoFar.remove(0);
|
// pathSoFar.remove(0);
|
||||||
xpath += String.join("/", pathSoFar);
|
xpath += String.join("/", pathSoFar);
|
||||||
// System.out.println(xpath);
|
|
||||||
try (XmlCursor cursors = currentXml.newCursor()) {
|
try (XmlCursor cursors = currentXml.newCursor()) {
|
||||||
// System.out.println(xpath);
|
// System.out.println(xpath);
|
||||||
|
// System.out.println(cursors.xmlText());
|
||||||
cursors.selectPath(xpath);
|
cursors.selectPath(xpath);
|
||||||
if (cursors.toNextSelection()) {
|
if (cursors.toNextSelection()) {
|
||||||
// System.out.println(cursors.xmlText());
|
// System.out.println(cursors.xmlText());
|
||||||
@@ -175,11 +260,11 @@ public class WpsWordUtils {
|
|||||||
// System.out.println("值:" + texts);
|
// System.out.println("值:" + texts);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String text_value = cursors.getTextValue();
|
String textValue = cursors.getTextValue();
|
||||||
if (!Objects.equals(text_value, "")) {
|
if (!Objects.equals(textValue, "")) {
|
||||||
// 查找List里面是否已经存在相应文本的数据
|
// 查找List里面是否已经存在相应文本的数据
|
||||||
String finalText = text;
|
String finalText = text;
|
||||||
int list_index = IntStream.range(0, wordVOs.size())
|
int listIndex = IntStream.range(0, wordVOs.size())
|
||||||
.filter(i -> finalText.equals(wordVOs.get(i).getWordText()))
|
.filter(i -> finalText.equals(wordVOs.get(i).getWordText()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(-1);
|
.orElse(-1);
|
||||||
@@ -197,15 +282,16 @@ public class WpsWordUtils {
|
|||||||
woVo.setIsTrue(true);
|
woVo.setIsTrue(true);
|
||||||
List<String> kchinese = woVo.getKeynoteChinese();
|
List<String> kchinese = woVo.getKeynoteChinese();
|
||||||
List<String> examKeynote = woVo.getExamKeynote();
|
List<String> examKeynote = woVo.getExamKeynote();
|
||||||
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + text_value);
|
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + textValue);
|
||||||
kchinese.add(String.join(" → ", pathChinese) + ",值:" + text_value);
|
kchinese.add(String.join(" → ", pathChinese) + ",值:" + textValue);
|
||||||
wordVO.setKeynoteChinese(kchinese);
|
wordVO.setKeynoteChinese(kchinese);
|
||||||
wordVO.setExamKeynote(examKeynote);
|
wordVO.setExamKeynote(examKeynote);
|
||||||
|
wordVO.setType(type);
|
||||||
wordVOs.set(tindex, woVo);
|
wordVOs.set(tindex, woVo);
|
||||||
}
|
}
|
||||||
tindex += 1;
|
tindex += 1;
|
||||||
}
|
}
|
||||||
} else if (list_index < 0) { // 如果没有查询到了
|
} else if (listIndex < 0) { // 如果没有查询到了
|
||||||
if (xpath.indexOf("w:sectPr[") > 0) {
|
if (xpath.indexOf("w:sectPr[") > 0) {
|
||||||
// 页面属性
|
// 页面属性
|
||||||
// 文本
|
// 文本
|
||||||
@@ -219,35 +305,37 @@ public class WpsWordUtils {
|
|||||||
// 创建list进行存放数据
|
// 创建list进行存放数据
|
||||||
List<String> kchinese = new ArrayList<>();
|
List<String> kchinese = new ArrayList<>();
|
||||||
List<String> examKeynote = new ArrayList<>();
|
List<String> examKeynote = new ArrayList<>();
|
||||||
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + text_value);
|
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + textValue);
|
||||||
|
kchinese.add(String.join(" → ", pathChinese) + ",值:" + textValue);
|
||||||
kchinese.add(String.join(" → ", pathChinese) + ",值:" + text_value);
|
|
||||||
// 组合完数据后进行存放数据
|
// 组合完数据后进行存放数据
|
||||||
wordVO.setKeynoteChinese(kchinese);
|
wordVO.setKeynoteChinese(kchinese);
|
||||||
wordVO.setExamKeynote(examKeynote);
|
wordVO.setExamKeynote(examKeynote);
|
||||||
wordVO.setIsTrue(false);
|
wordVO.setIsTrue(false);
|
||||||
|
wordVO.setType(type);
|
||||||
wordVOs.add(wordVO);
|
wordVOs.add(wordVO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // 如果找到了
|
} else { // 如果找到了
|
||||||
WordVO wordVO = wordVOs.get(list_index);
|
WordVO wordVO = wordVOs.get(listIndex);
|
||||||
List<String> kchinese = wordVO.getKeynoteChinese();
|
List<String> kchinese = wordVO.getKeynoteChinese();
|
||||||
List<String> examKeynote = wordVO.getExamKeynote();
|
List<String> examKeynote = wordVO.getExamKeynote();
|
||||||
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + text_value);
|
examKeynote.add(String.join(" → ", pathSoFar) + ",value:" + textValue);
|
||||||
kchinese.add(String.join(" → ", pathChinese) + ",值:" + text_value);
|
kchinese.add(String.join(" → ", pathChinese) + ",值:" + textValue);
|
||||||
wordVO.setKeynoteChinese(kchinese);
|
wordVO.setKeynoteChinese(kchinese);
|
||||||
wordVO.setExamKeynote(examKeynote);
|
wordVO.setExamKeynote(examKeynote);
|
||||||
wordVO.setIsTrue(false);
|
wordVO.setIsTrue(false);
|
||||||
wordVOs.remove(list_index);
|
wordVO.setType(type);
|
||||||
|
wordVOs.remove(listIndex);
|
||||||
wordVOs.add(wordVO);
|
wordVOs.add(wordVO);
|
||||||
}
|
}
|
||||||
// System.out.println("文本:" + text + " 参数路径:" + String.join(" → ", pathChinese) + ",值:" + text_value);
|
// System.out.println("文本:" + text + " 参数路径:" + String.join(" → ", pathChinese) + ",值:" + text_value);
|
||||||
}
|
}
|
||||||
|
cursors.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (WpsWordLinkDO child : node.getChildren()) {
|
for (WpsWordLinkDO child : node.getChildren()) {
|
||||||
traverseTreeAndQueryXml(wordVOs, firstTitle, text, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2);
|
traverseTreeAndQueryXml(type, wordVOs, firstTitle, text, xpath, child, currentXml, new ArrayList<>(pathSoFar), new ArrayList<>(pathChinese), index,2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pathSoFar.remove(pathSoFar.size() - 1);
|
pathSoFar.remove(pathSoFar.size() - 1);
|
||||||
|
|||||||
@@ -20,5 +20,7 @@ public class WordVO {
|
|||||||
@Schema(description = "是否有样式修饰")
|
@Schema(description = "是否有样式修饰")
|
||||||
private Boolean isTrue;
|
private Boolean isTrue;
|
||||||
|
|
||||||
|
@Schema(description = "类型")
|
||||||
|
private String type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user