【修改】 wps相关试题判分BUG修改

This commit is contained in:
DESKTOP-932OMT8\REN
2025-06-13 12:15:55 +08:00
parent 9f70635e9c
commit 7fa2d443cd
11 changed files with 343 additions and 270 deletions

View File

@@ -134,5 +134,8 @@ public class ExamQuestion extends TenantBaseDO {
/** 每题分数 */ /** 每题分数 */
@TableField(exist = false) @TableField(exist = false)
private String quScores; private String quScores;
/** 排序 */
@TableField(exist = false)
private int sort;
} }

View File

@@ -54,5 +54,9 @@ public class StuPaperScoreDO extends TenantBaseDO {
* 题型名称 * 题型名称
*/ */
private String subjectName; private String subjectName;
/**
* 排序
*/
private int sort;
} }

View File

@@ -9,7 +9,7 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/ 文档可见https://www.iocoder.cn/MyBatis/x-plugins/
--> -->
<select id="findByStuIdAndPaperId" resultType="pc.exam.pp.module.exam.dal.dataobject.student.StuPaperScoreDO"> <select id="findByStuIdAndPaperId" resultType="pc.exam.pp.module.exam.dal.dataobject.student.StuPaperScoreDO">
SELECT * FROM exam_stu_paper_score WHERE stu_id = #{stuId} AND paper_id = #{paperId} SELECT * FROM exam_stu_paper_score WHERE stu_id = #{stuId} AND paper_id = #{paperId} order by sort ASC
</select> </select>

View File

@@ -99,7 +99,7 @@ public class AutoToolsController {
List<StuPaperFileDO> stuPaperFileDOList = stuPaperFileService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(), stuPaperReqVo.getPaperId()); List<StuPaperFileDO> stuPaperFileDOList = stuPaperFileService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(), stuPaperReqVo.getPaperId());
String judgementStr = " "; String judgementStr = " ";
for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) { for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) {
if (stuPaperFileDOs.getType() == 1) { if (stuPaperFileDOs.getType() == 0) {
if (stuPaperFileDOs.getContent() != null) { if (stuPaperFileDOs.getContent() != null) {
judgementStr = stuPaperFileDOs.getContent(); judgementStr = stuPaperFileDOs.getContent();
} }

View File

@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import pc.exam.pp.framework.common.pojo.CommonResult; import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperQu;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme; import pc.exam.pp.module.exam.dal.dataobject.EducationPaperScheme;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO; import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
@@ -21,6 +22,7 @@ import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperQuMapper;
import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSchemeMapper; import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperSchemeMapper;
import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper; import pc.exam.pp.module.exam.dal.mysql.question.ExamQuestionMapper;
import pc.exam.pp.module.exam.dal.mysql.student.StuPaperScoreMapper; import pc.exam.pp.module.exam.dal.mysql.student.StuPaperScoreMapper;
import pc.exam.pp.module.exam.service.paper.IEducationPaperQuService;
import pc.exam.pp.module.exam.service.question.IExamQuestionService; import pc.exam.pp.module.exam.service.question.IExamQuestionService;
import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService; import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService; import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
@@ -92,6 +94,8 @@ public class AutoToolsServiceImpl implements AutoToolsService{
EducationPaperSchemeMapper educationPaperSchemeMapper; EducationPaperSchemeMapper educationPaperSchemeMapper;
@Resource @Resource
EducationPaperMapper educationPaperMapper; EducationPaperMapper educationPaperMapper;
@Resource
IEducationPaperQuService iEducationPaperQuService;
@Override @Override
public String downloadStudentFile(String fileUrl, String filePath) { public String downloadStudentFile(String fileUrl, String filePath) {
try { try {
@@ -197,12 +201,13 @@ public class AutoToolsServiceImpl implements AutoToolsService{
for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) { for (StuPaperFileDO stuPaperFileDOs : stuPaperFileDOList) {
if (stuPaperFileDOs.getType() == 1) { if (stuPaperFileDOs.getType() == 1) {
noZipFileDO = stuPaperFileDOs; noZipFileDO = stuPaperFileDOs;
if (stuPaperFileDOs.getContent() != null) {
judgementStr = stuPaperFileDOs.getContent();
}
} }
if (stuPaperFileDOs.getType() == 0) { if (stuPaperFileDOs.getType() == 0) {
stuPaperFileDO = stuPaperFileDOs; stuPaperFileDO = stuPaperFileDOs;
if (stuPaperFileDOs.getContent() != null) {
judgementStr = stuPaperFileDOs.getContent();
}
} }
} }
@@ -210,16 +215,21 @@ public class AutoToolsServiceImpl implements AutoToolsService{
List<String> quIds = educationPaperQuMapper.selectPaperQuByPaperId(paperId); List<String> quIds = educationPaperQuMapper.selectPaperQuByPaperId(paperId);
List<ExamQuestion> examQuestionList = examQuestionMapper.selectExamQuestionListByQuIds(quIds); List<ExamQuestion> examQuestionList = examQuestionMapper.selectExamQuestionListByQuIds(quIds);
List<EducationPaperScheme> educationPaperSchemeList = educationPaperSchemeMapper.selectEducationPaperTaskByTaskId(educationPaperMapper.selectTaskIdByPaperId(paperId)); List<EducationPaperScheme> educationPaperSchemeList = educationPaperSchemeMapper.selectEducationPaperTaskByTaskId(educationPaperMapper.selectTaskIdByPaperId(paperId));
List<EducationPaperQu> educationPaperQus = educationPaperQuMapper.selectPaperQuListByPaperId(paperId);
// 筛选出非选择题和选择题 // 筛选出非选择题和选择题
for (ExamQuestion examQuestion : examQuestionList) { for (ExamQuestion examQuestion : examQuestionList) {
for (EducationPaperScheme educationPaperScheme : educationPaperSchemeList) { for (EducationPaperScheme educationPaperScheme : educationPaperSchemeList) {
if (examQuestion.getSubjectName().equals(educationPaperScheme.getSpName())) { if (examQuestion.getSubjectName().equals(educationPaperScheme.getSpName())) {
Optional<EducationPaperQu> result = educationPaperQus.stream().filter(strs -> Objects.equals(strs.getQuId(), examQuestion.getQuId())).findFirst();
if (!result.isEmpty()) {
examQuestion.setQuScores(educationPaperScheme.getQuScores()); examQuestion.setQuScores(educationPaperScheme.getQuScores());
examQuestion.setSort(result.get().getSort());
quList.add(examQuestion); quList.add(examQuestion);
break; break;
} }
} }
} }
}
// 判断选择题文件是否存在 // 判断选择题文件是否存在
if (noZipFileDO != null) { if (noZipFileDO != null) {
// 1-1、 穿插选择题判分 // 1-1、 穿插选择题判分
@@ -246,6 +256,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
stuPaperScoreDO.setStuId(stuId); stuPaperScoreDO.setStuId(stuId);
stuPaperScoreDO.setQuId(key); stuPaperScoreDO.setQuId(key);
stuPaperScoreDO.setPaperId(paperId); stuPaperScoreDO.setPaperId(paperId);
stuPaperScoreDO.setSort(examQuestion.getSort());
isNull = true; isNull = true;
} }
double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), key, value, stuPaperScoreDO, isNull); double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), key, value, stuPaperScoreDO, isNull);
@@ -259,6 +270,7 @@ public class AutoToolsServiceImpl implements AutoToolsService{
stuPaperScoreDO.setStuId(stuId); stuPaperScoreDO.setStuId(stuId);
stuPaperScoreDO.setQuId(examQuestion.getQuId()); stuPaperScoreDO.setQuId(examQuestion.getQuId());
stuPaperScoreDO.setPaperId(paperId); stuPaperScoreDO.setPaperId(paperId);
stuPaperScoreDO.setSort(examQuestion.getSort());
isNull = true; isNull = true;
} }
// 说明学生没有答题,直接给零分 // 说明学生没有答题,直接给零分
@@ -267,6 +279,26 @@ public class AutoToolsServiceImpl implements AutoToolsService{
} }
} }
} }
} else {
// 如果结果是null的话说明学生没有作答直接全部0分
for (ExamQuestion examQuestion : quList) {
if ("选择题".equals(examQuestion.getSubjectName())) {
StuPaperScoreDO stuPaperScoreDO = stuPaperScoreService.getStuScoreByPaperIdAndQuid(stuId, paperId, examQuestion.getQuId());
// 判断是否做过该题
boolean isNull = false;
if (stuPaperScoreDO == null) {
stuPaperScoreDO = new StuPaperScoreDO();
stuPaperScoreDO.setStuId(stuId);
stuPaperScoreDO.setQuId(examQuestion.getQuId());
stuPaperScoreDO.setPaperId(paperId);
stuPaperScoreDO.setSort(examQuestion.getSort());
isNull = true;
}
// 说明学生没有答题,直接给零分
double selectScore = judgementChoiceService.programmingChoice(Double.parseDouble(examQuestion.getQuScores()), examQuestion.getQuId(), "", stuPaperScoreDO, isNull);
score += selectScore;
}
}
} }
// 1-1-4、删除文件 // 1-1-4、删除文件
select_file.delete(); select_file.delete();
@@ -333,12 +365,15 @@ public class AutoToolsServiceImpl implements AutoToolsService{
stuPaperScoreDO.setStuId(stuId); stuPaperScoreDO.setStuId(stuId);
stuPaperScoreDO.setQuId(examQuestion.getQuId()); stuPaperScoreDO.setQuId(examQuestion.getQuId());
stuPaperScoreDO.setPaperId(paperId); stuPaperScoreDO.setPaperId(paperId);
stuPaperScoreDO.setSort(result.get().getSort());
isNull = true; isNull = true;
} }
if ("编程题".equals(one_file.getName().split("\\.")[0])) { if ("编程题".equals(one_file.getName().split("\\.")[0])) {
SourceAndText cpojo = judgementService.ProgrammingC(Double.parseDouble(quScore), one_file.getPath(), file_one.getName(), examQuestion, judgementStr); String judgementStr_C = "";
SourceAndText cpojo = judgementService.ProgrammingC(Double.parseDouble(quScore), one_file.getPath(), file_one.getName(), examQuestion, judgementStr_C);
double c_score = cpojo.getScore(); double c_score = cpojo.getScore();
judgementStr = cpojo.getText(); judgementStr += "<p>-----------------------------------------------------------</p>";
judgementStr += cpojo.getText();
score += c_score; score += c_score;
stuPaperScoreDO.setScore(new BigDecimal(c_score)); stuPaperScoreDO.setScore(new BigDecimal(c_score));
// 原始正确分数 // 原始正确分数
@@ -364,9 +399,11 @@ public class AutoToolsServiceImpl implements AutoToolsService{
} }
// wps 类型存在多级文文件夹,需要个性化设置 // wps 类型存在多级文文件夹,需要个性化设置
if ("文字".equals(one_file.getName().split("\\.")[0])) { if ("文字".equals(one_file.getName().split("\\.")[0])) {
SourceAndText wordpojo = judgementWpsWordService.judgementWpsWord(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStr); String judgementStrWord = "";
SourceAndText wordpojo = judgementWpsWordService.judgementWpsWord(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrWord);
double wps_word_score = wordpojo.getScore(); double wps_word_score = wordpojo.getScore();
judgementStr = wordpojo.getText(); judgementStr += "<p>-----------------------------------------------------------</p>";
judgementStr += wordpojo.getText();
score += wps_word_score; score += wps_word_score;
stuPaperScoreDO.setScore(new BigDecimal(wps_word_score)); stuPaperScoreDO.setScore(new BigDecimal(wps_word_score));
// 原始正确分数 // 原始正确分数
@@ -391,9 +428,11 @@ public class AutoToolsServiceImpl implements AutoToolsService{
break; break;
} }
if ("演示".equals(one_file.getName().split("\\.")[0])) { if ("演示".equals(one_file.getName().split("\\.")[0])) {
SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStr); String judgementStrPptx = "";
SourceAndText pptxpojo = judgementWpsPptxService.judgementWpsPptx(Double.parseDouble(quScore), one_file.getPath(), file_one.getPath(), examQuestion, judgementStrPptx);
double wps_pptx_score = pptxpojo.getScore(); double wps_pptx_score = pptxpojo.getScore();
judgementStr = pptxpojo.getText(); judgementStr += "<p>-----------------------------------------------------------</p>";
judgementStr += pptxpojo.getText();
score += wps_pptx_score; score += wps_pptx_score;
stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score)); stuPaperScoreDO.setScore(new BigDecimal(wps_pptx_score));
// 原始正确分数 // 原始正确分数
@@ -444,10 +483,12 @@ public class AutoToolsServiceImpl implements AutoToolsService{
// } // }
//windows文件处理 //windows文件处理
if ("文件处理".equals(one_file.getName().split("\\.")[0])) { if ("文件处理".equals(one_file.getName().split("\\.")[0])) {
String judgementStrFile = "";
File win_file = new File(one_file.getPath()); File win_file = new File(one_file.getPath());
SourceAndText winfilepojo = fileServerice.run_file_point(Double.parseDouble(quScore),win_file, examQuestion, judgementStr); SourceAndText winfilepojo = fileServerice.run_file_point(Double.parseDouble(quScore),win_file, examQuestion, judgementStrFile);
double win_file_score = winfilepojo.getScore(); double win_file_score = winfilepojo.getScore();
judgementStr = winfilepojo.getText(); judgementStr += "<p>-----------------------------------------------------------</p>";
judgementStr += winfilepojo.getText();
score += win_file_score; score += win_file_score;
stuPaperScoreDO.setScore(new BigDecimal(win_file_score)); stuPaperScoreDO.setScore(new BigDecimal(win_file_score));
// 原始正确分数 // 原始正确分数
@@ -474,11 +515,13 @@ public class AutoToolsServiceImpl implements AutoToolsService{
//浏览器操作 //浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){ // if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if ("网络题".equals(one_file.getName().split("\\.")[0])) { if ("网络题".equals(one_file.getName().split("\\.")[0])) {
String judgementStrBrow = "";
System.out.println(one_file); System.out.println(one_file);
File edge_file = new File(one_file.getPath()); File edge_file = new File(one_file.getPath());
SourceAndText browsepojo= browserServerice.Judgement(Double.parseDouble(quScore),edge_file,examQuestion, judgementStr); SourceAndText browsepojo= browserServerice.Judgement(Double.parseDouble(quScore),edge_file,examQuestion, judgementStrBrow);
double browse_score = browsepojo.getScore(); double browse_score = browsepojo.getScore();
judgementStr = browsepojo.getText(); judgementStr += "<p>-----------------------------------------------------------</p>";
judgementStr += browsepojo.getText();
score += browse_score; score += browse_score;
stuPaperScoreDO.setScore(new BigDecimal(browse_score)); stuPaperScoreDO.setScore(new BigDecimal(browse_score));
// 原始正确分数 // 原始正确分数
@@ -503,35 +546,37 @@ public class AutoToolsServiceImpl implements AutoToolsService{
break; break;
} }
if ("程序设计".equals(one_file.getName().split("\\.")[0])) { // if ("程序设计".equals(one_file.getName().split("\\.")[0])) {
System.out.println(one_file); // String judgementStrMysql = "";
File mysql_file = new File(one_file.getPath()); // System.out.println(one_file);
SourceAndText judgementpojo = mysqlServerice.Judgement(Double.parseDouble(quScore),mysql_file, examQuestion, judgementStr); // File mysql_file = new File(one_file.getPath());
double judgement = judgementpojo.getScore(); // SourceAndText judgementpojo = mysqlServerice.Judgement(Double.parseDouble(quScore),mysql_file, examQuestion, judgementStrMysql);
judgementStr = judgementpojo.getText(); // double judgement = judgementpojo.getScore();
score+=judgement; // judgementStr += "<p>-----------------------------------------------------------</p>";
stuPaperScoreDO.setScore(new BigDecimal(judgement)); // judgementStr += judgementpojo.getText();
// 原始正确分数 // score+=judgement;
stuPaperScoreDO.setTrueScore(new BigDecimal(quScore)); // stuPaperScoreDO.setScore(new BigDecimal(judgement));
// 判断题是否正确 // // 原始正确分数
if (judgement == Double.parseDouble(quScore)) { // stuPaperScoreDO.setTrueScore(new BigDecimal(quScore));
stuPaperScoreDO.setIsTrue(0); // // 判断题是否正确
} else if (judgement == 0) { // if (judgement == Double.parseDouble(quScore)) {
stuPaperScoreDO.setIsTrue(1); // stuPaperScoreDO.setIsTrue(0);
} else { // } else if (judgement == 0) {
stuPaperScoreDO.setIsTrue(2); // stuPaperScoreDO.setIsTrue(1);
} // } else {
stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName()); // stuPaperScoreDO.setIsTrue(2);
if (isNull) { // }
// 如果之前没做过,则插入该题的分数 // stuPaperScoreDO.setSubjectName(examQuestion.getSubjectName());
stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO); // if (isNull) {
} else { // // 如果之前没做过,则插入该题的分数
// 如果之前做过,则更新该题的分数 // stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO);
stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO); // } else {
} // // 如果之前做过,则更新该题的分数
System.out.println(judgement+"mysql得分"); // stuPaperScoreService.updateStuPaperScore(stuPaperScoreDO);
break; // }
} // System.out.println(judgement+"mysql得分");
// break;
// }
} }
} }
} }
@@ -544,9 +589,9 @@ public class AutoToolsServiceImpl implements AutoToolsService{
// 9、上传文件 // 9、上传文件
MultipartFile file = new CustomMultipartFile(zipPath); MultipartFile file = new CustomMultipartFile(zipPath);
String path = null; String path = null;
if (noZipFileDO != null) { if (stuPaperFileDO != null) {
noZipFileDO.setContent(judgementStr); stuPaperFileDO.setContent(judgementStr);
stuPaperFileService.updateStuPaperFile(noZipFileDO); stuPaperFileService.updateStuPaperFile(stuPaperFileDO);
} }
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream())); fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
// 更新学生分数 // 更新学生分数

View File

@@ -178,6 +178,7 @@ public class JudgementServiceImpl implements JudgementService
judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 测试用例全部正确:"+ score); judgementStr = HtmlAppender.appendHtmlLine(judgementStr, "✅ 测试用例全部正确:"+ score);
LogFileUtils.close(); LogFileUtils.close();
sourceAndText.setScore(score); sourceAndText.setScore(score);
sourceAndText.setText(judgementStr);
return sourceAndText; return sourceAndText;
} else if (test_case_number > true_test_case_number) { } else if (test_case_number > true_test_case_number) {
// 2、测试用例没有完全正确对多少个就是多少分 // 2、测试用例没有完全正确对多少个就是多少分

View File

@@ -116,6 +116,8 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
wpsWordReqDto.setFunction(wordInfos[0]); wpsWordReqDto.setFunction(wordInfos[0]);
wpsWordReqDto.setIsExam("1"); wpsWordReqDto.setIsExam("1");
wordReqDto.add(wpsWordReqDto); wordReqDto.add(wpsWordReqDto);
System.out.println(examQuestionAnswer.getContentIn());
System.out.println(examQuestionAnswer.getContent());
List<WpsWordJudgementDto> judgementDtos = WpsWordUtils.getWordInfo(wordReqDto); List<WpsWordJudgementDto> judgementDtos = WpsWordUtils.getWordInfo(wordReqDto);
boolean flag = false; boolean flag = false;
double one_sorce = 0; double one_sorce = 0;

View File

@@ -10,26 +10,26 @@ public class WpsPptxNameSpaces {
public static String getNameSpace(String xmlString) { public static String getNameSpace(String xmlString) {
// 2、创建最全的命名空间 // 2、创建最全的命名空间
Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); // Pattern pattern = Pattern.compile("xmlns:(\\w+)='([^']+)'");
Matcher matcher = pattern.matcher(xmlString); // Matcher matcher = pattern.matcher(xmlString);
Map<String, String> namespaces = new HashMap<>(); // Map<String, String> namespaces = new HashMap<>();
while (matcher.find()) { // while (matcher.find()) {
// 如 w, wp, a // // 如 w, wp, a
String prefix = matcher.group(1); // String prefix = matcher.group(1);
// 如 http://schemas.openxmlformats.org/... // // 如 http://schemas.openxmlformats.org/...
String uri = matcher.group(2); // String uri = matcher.group(2);
namespaces.put(prefix, uri); // namespaces.put(prefix, uri);
} // }
StringBuilder xpathBuilder = new StringBuilder(); // StringBuilder xpathBuilder = new StringBuilder();
namespaces.forEach((prefix, uri) -> // namespaces.forEach((prefix, uri) ->
xpathBuilder.append("declare namespace ") // xpathBuilder.append("declare namespace ")
.append(prefix) // .append(prefix)
.append("='") // .append("='")
.append(uri) // .append(uri)
.append("' ") // .append("' ")
); // );
// 2-1、获取出来最全的命名空间 // // 2-1、获取出来最全的命名空间
String allPathx = xpathBuilder.toString(); // String allPathx = xpathBuilder.toString();
return allPathx; 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' ";
} }
} }

View File

@@ -271,6 +271,8 @@ public class WpsPptxUtils {
} }
} }
} catch (IOException e) {
e.printStackTrace();
} catch (XmlException e) { } catch (XmlException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@@ -10,26 +10,26 @@ public class WpsWordNameSpaces {
public static String getNameSpace(String xmlString) { public static String getNameSpace(String xmlString) {
// 2、创建最全的命名空间 // 2、创建最全的命名空间
Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\""); // Pattern pattern = Pattern.compile("xmlns:(\\w+)='([^']+)'");
Matcher matcher = pattern.matcher(xmlString); // Matcher matcher = pattern.matcher(xmlString);
Map<String, String> namespaces = new HashMap<>(); // Map<String, String> namespaces = new HashMap<>();
while (matcher.find()) { // while (matcher.find()) {
// 如 w, wp, a // // 如 w, wp, a
String prefix = matcher.group(1); // String prefix = matcher.group(1);
// 如 http://schemas.openxmlformats.org/... // // 如 http://schemas.openxmlformats.org/...
String uri = matcher.group(2); // String uri = matcher.group(2);
namespaces.put(prefix, uri); // namespaces.put(prefix, uri);
} // }
StringBuilder xpathBuilder = new StringBuilder(); // StringBuilder xpathBuilder = new StringBuilder();
namespaces.forEach((prefix, uri) -> // namespaces.forEach((prefix, uri) ->
xpathBuilder.append("declare namespace ") // xpathBuilder.append("declare namespace ")
.append(prefix) // .append(prefix)
.append("='") // .append("='")
.append(uri) // .append(uri)
.append("' ") // .append("' ")
); // );
// 2-1、获取出来最全的命名空间 // // 2-1、获取出来最全的命名空间
String allPathx = xpathBuilder.toString(); // String allPathx = xpathBuilder.toString();
return allPathx; return "declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' declare namespace pic='http://schemas.openxmlformats.org/drawingml/2006/picture' declare namespace wp='http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing' declare namespace wp14='http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing' declare namespace w14='http://schemas.microsoft.com/office/word/2010/wordml' declare namespace w15='http://schemas.microsoft.com/office/word/2012/wordml' declare namespace w16='http://schemas.microsoft.com/office/word/2018/wordml' declare namespace w16cid='http://schemas.microsoft.com/office/word/2016/wordml/cid' 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 wpg='http://schemas.microsoft.com/office/word/2010/wordprocessingGroup' declare namespace wpi='http://schemas.microsoft.com/office/word/2010/wordprocessingInk' declare namespace wps='http://schemas.microsoft.com/office/word/2010/wordprocessingShape' declare namespace c='http://schemas.openxmlformats.org/drawingml/2006/chart' declare namespace cx='http://schemas.microsoft.com/office/drawing/2014/chart' declare namespace dgm='http://schemas.openxmlformats.org/drawingml/2006/diagram' declare namespace lc='http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas' declare namespace svg='http://schemas.microsoft.com/office/drawing/2016/SVG/main' declare namespace aink='http://schemas.microsoft.com/office/drawing/2016/ink' declare namespace am3d='http://schemas.microsoft.com/office/drawing/2017/model3D' declare namespace wne='http://schemas.microsoft.com/office/word/2006/wordml' ";
} }
} }

View File

@@ -1,5 +1,8 @@
package pc.exam.pp.module.judgement.utils.wps_word; package pc.exam.pp.module.judgement.utils.wps_word;
import org.apache.commons.io.IOUtils;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.xwpf.usermodel.*; import org.apache.poi.xwpf.usermodel.*;
import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
@@ -14,6 +17,9 @@ import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -46,13 +52,14 @@ public class WpsWordUtils {
// 创建文件路径数组 // 创建文件路径数组
List<Map<String, String>> filePathList = new ArrayList<>(); List<Map<String, String>> filePathList = new ArrayList<>();
for (WpsWordReqDto wpsWordReqDto : wpsWordReqDtos) { for (WpsWordReqDto wpsWordReqDto : wpsWordReqDtos) {
try (ZipFile zipFile = new ZipFile(wpsWordReqDto.getFilePath())) { try (OPCPackage pkg = OPCPackage.open(wpsWordReqDto.getFilePath());
Enumeration<? extends ZipEntry> entries = zipFile.entries(); XWPFDocument document = new XWPFDocument(pkg)) {
while (entries.hasMoreElements()) { for (PackagePart part : pkg.getParts()) {
ZipEntry entry = entries.nextElement(); String entryName = part.getPartName().getName();
String entryName = entry.getName(); if (entryName.contains("word/_rels") && entryName.contains(".xml.rels")) {
if (entryName.startsWith("word/_rels") && entryName.endsWith(".xml.rels")) { try (InputStream is = part.getInputStream()) {
String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName); String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8);
// 解析 xmlContent
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
XmlCursor cursor = xmlObject.newCursor(); XmlCursor cursor = xmlObject.newCursor();
cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship"); cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship");
@@ -66,7 +73,7 @@ public class WpsWordUtils {
} }
} }
} }
XWPFDocument document = new XWPFDocument(new FileInputStream(wpsWordReqDto.getFilePath())); }
XmlObject docXml = document.getDocument(); XmlObject docXml = document.getDocument();
XmlCursor cursor = docXml.newCursor(); XmlCursor cursor = docXml.newCursor();
String nameSpace = WpsWordNameSpaces.getNameSpace(cursor.xmlText()); String nameSpace = WpsWordNameSpaces.getNameSpace(cursor.xmlText());
@@ -95,7 +102,11 @@ public class WpsWordUtils {
flag = false; flag = false;
} }
} }
if (numbers > 20) {
flag = false;
} }
}
if (wColsCursors != null) {
String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1]; String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1];
System.out.println(wColsCursors.xmlText()); System.out.println(wColsCursors.xmlText());
wColsCursors.selectPath(nameSpaceCols); wColsCursors.selectPath(nameSpaceCols);
@@ -109,6 +120,7 @@ public class WpsWordUtils {
// 查询指定值,返回固定的文本 // 查询指定值,返回固定的文本
judgementList.add(judgement); judgementList.add(judgement);
} }
}
} else { } else {
String function = wpsWordReqDto.getFunction(); String function = wpsWordReqDto.getFunction();
String chineseName = wpsWordReqDto.getName(); String chineseName = wpsWordReqDto.getName();
@@ -136,12 +148,11 @@ public class WpsWordUtils {
wpCursor.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + "/w:pPr/w:pStyle/@w:val"); wpCursor.selectPath(nameSpace + wpsWordReqDto.getEnglishName() + "/w:pPr/w:pStyle/@w:val");
if (wpCursor.toNextSelection()) { if (wpCursor.toNextSelection()) {
String value = wpCursor.getTextValue(); String value = wpCursor.getTextValue();
Enumeration<? extends ZipEntry> entriesStyle = zipFile.entries(); for (PackagePart part : pkg.getParts()) {
while (entriesStyle.hasMoreElements()) { String entryName = part.getPartName().getName();
ZipEntry entry = entriesStyle.nextElement(); if (entryName.contains("word/styles") && entryName.contains(".xml")) {
String entryName = entry.getName(); try (InputStream is = part.getInputStream()) {
if (entryName.startsWith("word/styles") && entryName.endsWith(".xml")) { String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8);
String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName);
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
XmlCursor cursorStyle = xmlObject.newCursor(); XmlCursor cursorStyle = xmlObject.newCursor();
String nameSpaceStyle = WpsWordNameSpaces.getNameSpace(cursorStyle.xmlText()); String nameSpaceStyle = WpsWordNameSpaces.getNameSpace(cursorStyle.xmlText());
@@ -173,6 +184,7 @@ public class WpsWordUtils {
} }
} }
} }
}
} else if ("1".equals(wpsWordReqDto.getIsboo())) { } else if ("1".equals(wpsWordReqDto.getIsboo())) {
judgement.setContentIn(chineseName + ""); judgement.setContentIn(chineseName + "");
judgement.setContent(function + "-/false"); judgement.setContent(function + "-/false");
@@ -495,6 +507,7 @@ public class WpsWordUtils {
WpsWordJudgementDto judgement = new WpsWordJudgementDto(); WpsWordJudgementDto judgement = new WpsWordJudgementDto();
// 1-1、创建新的数据组 // 1-1、创建新的数据组
XmlCursor wpCursor = cursor.newCursor(); XmlCursor wpCursor = cursor.newCursor();
System.out.println(nameSpace + function);
wpCursor.selectPath(nameSpace + function); wpCursor.selectPath(nameSpace + function);
if (wpCursor.toNextSelection()) { if (wpCursor.toNextSelection()) {
if ("1".equals(wpsWordReqDto.getIsboo())) { if ("1".equals(wpsWordReqDto.getIsboo())) {
@@ -541,12 +554,11 @@ public class WpsWordUtils {
} }
} }
} else { } else {
Enumeration<? extends ZipEntry> entriess = zipFile.entries(); for (PackagePart part : pkg.getParts()) {
while (entriess.hasMoreElements()) { String entryName = part.getPartName().getName();
ZipEntry entry = entriess.nextElement(); if (entryName.contains("word/endnotes") && entryName.contains(".xml")) {
String entryName = entry.getName(); try (InputStream is = part.getInputStream()) {
if (entryName.startsWith("word/endnotes") && entryName.endsWith(".xml")) { String xmlContent = IOUtils.toString(is, StandardCharsets.UTF_8);
String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName);
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent); XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
XmlCursor cursorEnd = xmlObject.newCursor(); XmlCursor cursorEnd = xmlObject.newCursor();
String namespace = WpsWordNameSpaces.getNameSpace(cursorEnd.xmlText()); String namespace = WpsWordNameSpaces.getNameSpace(cursorEnd.xmlText());
@@ -564,6 +576,7 @@ public class WpsWordUtils {
} }
} }
} }
}
// 表格属性 // 表格属性
if ("4".equals(wpsWordReqDto.getBelongTo())) { if ("4".equals(wpsWordReqDto.getBelongTo())) {
XmlCursor tblCursor = cursor.newCursor(); XmlCursor tblCursor = cursor.newCursor();
@@ -607,9 +620,10 @@ public class WpsWordUtils {
} }
} }
} }
} catch (IOException e) {
e.printStackTrace();
} }
} }
return judgementList; return judgementList;
} }
public static String getValueType(WpsWordReqDto wpsWordReqDto, String value) { public static String getValueType(WpsWordReqDto wpsWordReqDto, String value) {
@@ -763,7 +777,7 @@ public class WpsWordUtils {
public static List<WordInfoReqVo> wpWord(String filePath) throws Exception { public static List<WordInfoReqVo> wpWord(String filePath) throws Exception {
List<WordInfoReqVo> wordInfoReqVos = new ArrayList<>(); List<WordInfoReqVo> wordInfoReqVos = new ArrayList<>();
XWPFDocument document = new XWPFDocument(new FileInputStream(filePath)); try (XWPFDocument document = new XWPFDocument(new FileInputStream(filePath))) {
String xmlString = XmlUtil.getDocumentXml(document); String xmlString = XmlUtil.getDocumentXml(document);
String namespace = WpsWordNameSpaces.getNameSpace(xmlString); String namespace = WpsWordNameSpaces.getNameSpace(xmlString);
XmlObject docXml = document.getDocument(); XmlObject docXml = document.getDocument();
@@ -872,6 +886,8 @@ public class WpsWordUtils {
return wordInfoReqVos; return wordInfoReqVos;
} }
}
/** /**
* 获取文档段落W:P标签得数量判断出一个有多少段 * 获取文档段落W:P标签得数量判断出一个有多少段
* @param filePath 文件路径 * @param filePath 文件路径