【修改】 wps相关试题判分BUG修改
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,5 +54,9 @@ public class StuPaperScoreDO extends TenantBaseDO {
|
|||||||
* 题型名称
|
* 题型名称
|
||||||
*/
|
*/
|
||||||
private String subjectName;
|
private String subjectName;
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private int sort;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,13 +215,18 @@ 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())) {
|
||||||
examQuestion.setQuScores(educationPaperScheme.getQuScores());
|
Optional<EducationPaperQu> result = educationPaperQus.stream().filter(strs -> Objects.equals(strs.getQuId(), examQuestion.getQuId())).findFirst();
|
||||||
quList.add(examQuestion);
|
if (!result.isEmpty()) {
|
||||||
break;
|
examQuestion.setQuScores(educationPaperScheme.getQuScores());
|
||||||
|
examQuestion.setSort(result.get().getSort());
|
||||||
|
quList.add(examQuestion);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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()));
|
||||||
// 更新学生分数
|
// 更新学生分数
|
||||||
|
|||||||
@@ -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、测试用例没有完全正确,对多少个就是多少分
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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' ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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' ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,27 +52,28 @@ 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);
|
||||||
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
|
// 解析 xmlContent
|
||||||
XmlCursor cursor = xmlObject.newCursor();
|
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
|
||||||
cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship");
|
XmlCursor cursor = xmlObject.newCursor();
|
||||||
// 存放数据
|
cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship");
|
||||||
while (cursor.toNextSelection()) {
|
// 存放数据
|
||||||
Map<String, String> map = new HashMap<>();
|
while (cursor.toNextSelection()) {
|
||||||
String rId = cursor.getAttributeText(new QName("Id"));
|
Map<String, String> map = new HashMap<>();
|
||||||
String target = cursor.getAttributeText(new QName("Target"));
|
String rId = cursor.getAttributeText(new QName("Id"));
|
||||||
map.put(rId, target);
|
String target = cursor.getAttributeText(new QName("Target"));
|
||||||
filePathList.add(map);
|
map.put(rId, target);
|
||||||
|
filePathList.add(map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,19 +102,24 @@ public class WpsWordUtils {
|
|||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (numbers > 20) {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1];
|
if (wColsCursors != null) {
|
||||||
System.out.println(wColsCursors.xmlText());
|
String nameSpaceCols = nameSpace + "." + wpsWordReqDto.getFunction().split("]")[1];
|
||||||
wColsCursors.selectPath(nameSpaceCols);
|
System.out.println(wColsCursors.xmlText());
|
||||||
WpsWordJudgementDto judgement = new WpsWordJudgementDto();
|
wColsCursors.selectPath(nameSpaceCols);
|
||||||
if (wColsCursors.toNextSelection()) {
|
WpsWordJudgementDto judgement = new WpsWordJudgementDto();
|
||||||
String value = wColsCursors.getTextValue();
|
if (wColsCursors.toNextSelection()) {
|
||||||
judgement.setContentIn(wpsWordReqDto.getName() + value);
|
String value = wColsCursors.getTextValue();
|
||||||
judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value);
|
judgement.setContentIn(wpsWordReqDto.getName() + value);
|
||||||
judgement.setScoreRate("1");
|
judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value);
|
||||||
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
judgement.setScoreRate("1");
|
||||||
// 查询指定值,返回固定的文本
|
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
||||||
judgementList.add(judgement);
|
// 查询指定值,返回固定的文本
|
||||||
|
judgementList.add(judgement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String function = wpsWordReqDto.getFunction();
|
String function = wpsWordReqDto.getFunction();
|
||||||
@@ -136,39 +148,39 @@ 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());
|
cursorStyle.selectPath(nameSpaceStyle + ".//w:style[@w:styleId='"+value+"']");
|
||||||
cursorStyle.selectPath(nameSpaceStyle + ".//w:style[@w:styleId='"+value+"']");
|
|
||||||
if (cursorStyle.toNextSelection()) {
|
|
||||||
String functions = wpsWordReqDto.getFunction().replace("/w:r/", "");
|
|
||||||
if (functions.charAt(0) == '/') {
|
|
||||||
functions = ".//" + functions.split("]")[1];
|
|
||||||
} else {
|
|
||||||
functions = "./" + functions.split("]")[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
cursorStyle.selectPath(nameSpaceStyle + functions);
|
|
||||||
if (cursorStyle.toNextSelection()) {
|
if (cursorStyle.toNextSelection()) {
|
||||||
|
String functions = wpsWordReqDto.getFunction().replace("/w:r/", "");
|
||||||
if ("1".equals(wpsWordReqDto.getIsboo())) {
|
if (functions.charAt(0) == '/') {
|
||||||
judgement.setContentIn(chineseName + "是");
|
functions = ".//" + functions.split("]")[1];
|
||||||
judgement.setContent(function + "-/true");
|
|
||||||
} else {
|
} else {
|
||||||
String valueStyle = cursorStyle.getTextValue();
|
functions = "./" + functions.split("]")[1];
|
||||||
valueStyle = getValueType(wpsWordReqDto, valueStyle);
|
}
|
||||||
judgement.setContentIn(chineseName + valueStyle);
|
|
||||||
judgement.setContent(function + "-/" + valueStyle);
|
cursorStyle.selectPath(nameSpaceStyle + functions);
|
||||||
|
if (cursorStyle.toNextSelection()) {
|
||||||
|
|
||||||
|
if ("1".equals(wpsWordReqDto.getIsboo())) {
|
||||||
|
judgement.setContentIn(chineseName + "是");
|
||||||
|
judgement.setContent(function + "-/true");
|
||||||
|
} else {
|
||||||
|
String valueStyle = cursorStyle.getTextValue();
|
||||||
|
valueStyle = getValueType(wpsWordReqDto, valueStyle);
|
||||||
|
judgement.setContentIn(chineseName + valueStyle);
|
||||||
|
judgement.setContent(function + "-/" + valueStyle);
|
||||||
|
}
|
||||||
|
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
||||||
|
judgement.setScoreRate("1");
|
||||||
|
judgementList.add(judgement);
|
||||||
}
|
}
|
||||||
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
|
||||||
judgement.setScoreRate("1");
|
|
||||||
judgementList.add(judgement);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,24 +554,24 @@ 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());
|
if (wpsWordReqDto.getName().contains("内容")) {
|
||||||
if (wpsWordReqDto.getName().contains("内容")) {
|
System.out.println(cursorEnd.xmlText());
|
||||||
System.out.println(cursorEnd.xmlText());
|
String value = cursorEnd.getTextValue();
|
||||||
String value = cursorEnd.getTextValue();
|
WpsWordJudgementDto judgement = new WpsWordJudgementDto();
|
||||||
WpsWordJudgementDto judgement = new WpsWordJudgementDto();
|
judgement.setContentIn(wpsWordReqDto.getName() + value);
|
||||||
judgement.setContentIn(wpsWordReqDto.getName() + value);
|
judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value);
|
||||||
judgement.setContent(wpsWordReqDto.getFunction() + "-/" + value);
|
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
||||||
judgement.setImage(wpsWordReqDto.getType()+"-"+wpsWordReqDto.getBelongTo()+"-"+wpsWordReqDto.getIsboo()+"-"+wpsWordReqDto.getUnit());
|
judgement.setScoreRate("1");
|
||||||
judgement.setScoreRate("1");
|
judgementList.add(judgement);
|
||||||
judgementList.add(judgement);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,113 +777,115 @@ 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();
|
||||||
// 1、获取文档段落W:P标签得数量,判断出一个有多少段
|
// 1、获取文档段落W:P标签得数量,判断出一个有多少段
|
||||||
XmlCursor wpCursor = docXml.newCursor();
|
XmlCursor wpCursor = docXml.newCursor();
|
||||||
String wpPath = namespace + "/w:document/w:body/w:p";
|
String wpPath = namespace + "/w:document/w:body/w:p";
|
||||||
wpCursor.selectPath(wpPath);
|
wpCursor.selectPath(wpPath);
|
||||||
int wpIndex = 0;
|
int wpIndex = 0;
|
||||||
// 段落
|
// 段落
|
||||||
String firstIdWp = getStringRandom();
|
String firstIdWp = getStringRandom();
|
||||||
setWordInfo("段落", "w:p", "w:p", filePath, firstIdWp, "0", wordInfoReqVos);
|
setWordInfo("段落", "w:p", "w:p", filePath, firstIdWp, "0", wordInfoReqVos);
|
||||||
List<WordSecondInfoVo> wordSecondWp = new ArrayList<>();
|
List<WordSecondInfoVo> wordSecondWp = new ArrayList<>();
|
||||||
while (wpCursor.toNextSelection()) {
|
while (wpCursor.toNextSelection()) {
|
||||||
wpIndex ++;
|
wpIndex ++;
|
||||||
// 段落属性
|
// 段落属性
|
||||||
if (!wpCursor.xmlText().contains("w:sectPr")) {
|
if (!wpCursor.xmlText().contains("w:sectPr")) {
|
||||||
// 获取文本
|
// 获取文本
|
||||||
XmlCursor wpTextXml = wpCursor.newCursor();
|
XmlCursor wpTextXml = wpCursor.newCursor();
|
||||||
wpTextXml.selectPath(namespace + ".//w:r/w:t");
|
wpTextXml.selectPath(namespace + ".//w:r/w:t");
|
||||||
if (wpTextXml.toNextSelection()) {
|
if (wpTextXml.toNextSelection()) {
|
||||||
String secondIdWp = getStringRandom();
|
String secondIdWp = getStringRandom();
|
||||||
String text = wpTextXml.getTextValue();
|
String text = wpTextXml.getTextValue();
|
||||||
setWordInfo("段落" + wpIndex + ":" + text, "(//w:p)[" + wpIndex + "]", "w:pPr", filePath, secondIdWp, firstIdWp, wordInfoReqVos);
|
setWordInfo("段落" + wpIndex + ":" + text, "(//w:p)[" + wpIndex + "]", "w:pPr", filePath, secondIdWp, firstIdWp, wordInfoReqVos);
|
||||||
// 使用 。 判断句子
|
// 使用 。 判断句子
|
||||||
String[] texts = text.split("。");
|
String[] texts = text.split("。");
|
||||||
int textsIndex = 0;
|
int textsIndex = 0;
|
||||||
for (String s : texts) {
|
for (String s : texts) {
|
||||||
String thirdIdWp = getStringRandom();
|
String thirdIdWp = getStringRandom();
|
||||||
textsIndex ++;
|
textsIndex ++;
|
||||||
setWordInfo("句子" + textsIndex + ":" + s, "(//w:p)[" + wpIndex + "]", "w:r", filePath, thirdIdWp, secondIdWp, wordInfoReqVos);
|
setWordInfo("句子" + textsIndex + ":" + s, "(//w:p)[" + wpIndex + "]", "w:r", filePath, thirdIdWp, secondIdWp, wordInfoReqVos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// 2、页面
|
||||||
// 2、页面
|
XmlCursor wSectPrCursor = docXml.newCursor();
|
||||||
XmlCursor wSectPrCursor = docXml.newCursor();
|
String wSectPrPath = namespace + "//w:sectPr";
|
||||||
String wSectPrPath = namespace + "//w:sectPr";
|
wSectPrCursor.selectPath(wSectPrPath);
|
||||||
wSectPrCursor.selectPath(wSectPrPath);
|
int wSectPrIndex = 0;
|
||||||
int wSectPrIndex = 0;
|
String firstIdSectPr = getStringRandom();
|
||||||
String firstIdSectPr = getStringRandom();
|
setWordInfo("页面", "w:sectPr", "w:sectPr", filePath, firstIdSectPr, "", wordInfoReqVos);
|
||||||
setWordInfo("页面", "w:sectPr", "w:sectPr", filePath, firstIdSectPr, "", wordInfoReqVos);
|
List<WordSecondInfoVo> wordSecondWSectPr = new ArrayList<>();
|
||||||
List<WordSecondInfoVo> wordSecondWSectPr = new ArrayList<>();
|
while (wSectPrCursor.toNextSelection()) {
|
||||||
while (wSectPrCursor.toNextSelection()) {
|
wSectPrIndex ++;
|
||||||
wSectPrIndex ++;
|
String secondIdSectPr = getStringRandom();
|
||||||
String secondIdSectPr = getStringRandom();
|
setWordInfo("节" + wSectPrIndex, "(//w:sectPr)[" + wSectPrIndex + "]", "w:sectPr", filePath, secondIdSectPr, firstIdSectPr, wordInfoReqVos);
|
||||||
setWordInfo("节" + wSectPrIndex, "(//w:sectPr)[" + wSectPrIndex + "]", "w:sectPr", filePath, secondIdSectPr, firstIdSectPr, wordInfoReqVos);
|
|
||||||
}
|
|
||||||
// 3、图形
|
|
||||||
XmlCursor wDrawingCursor = docXml.newCursor();
|
|
||||||
String wDrawingPath = namespace + "//w:drawing";
|
|
||||||
wDrawingCursor.selectPath(wDrawingPath);
|
|
||||||
int wDrawingIndex = 0;
|
|
||||||
String firstIdDrawing = getStringRandom();
|
|
||||||
setWordInfo("图形", "w:drawing", "w:drawing", filePath, firstIdDrawing, "", wordInfoReqVos);
|
|
||||||
while (wDrawingCursor.toNextSelection()) {
|
|
||||||
wDrawingIndex ++;
|
|
||||||
String secondIdDrawing = getStringRandom();
|
|
||||||
XmlCursor wDrawingXml = wDrawingCursor.newCursor();
|
|
||||||
wDrawingXml.selectPath(namespace + ".//wp:anchor/wp:docPr/@name");
|
|
||||||
if (wDrawingXml.toNextSelection()) {
|
|
||||||
setWordInfo("图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "(//w:drawing)[" + wDrawingIndex + "]", "w:drawing", filePath, secondIdDrawing, firstIdDrawing, wordInfoReqVos);
|
|
||||||
}
|
}
|
||||||
}
|
// 3、图形
|
||||||
// 4、尾注
|
XmlCursor wDrawingCursor = docXml.newCursor();
|
||||||
XmlCursor endnoteReferenceCursor = docXml.newCursor();
|
String wDrawingPath = namespace + "//w:drawing";
|
||||||
String endnoteReferencePath = namespace + "//w:endnoteReference";
|
wDrawingCursor.selectPath(wDrawingPath);
|
||||||
endnoteReferenceCursor.selectPath(endnoteReferencePath);
|
int wDrawingIndex = 0;
|
||||||
int endnoteReferenceIndex = 0;
|
String firstIdDrawing = getStringRandom();
|
||||||
String firstIdEndnoteReference = getStringRandom();
|
setWordInfo("图形", "w:drawing", "w:drawing", filePath, firstIdDrawing, "", wordInfoReqVos);
|
||||||
while (endnoteReferenceCursor.toNextSelection()) {
|
while (wDrawingCursor.toNextSelection()) {
|
||||||
if (endnoteReferenceIndex == 0) {
|
wDrawingIndex ++;
|
||||||
setWordInfo("引用", "w:endnoteReference", "w:endnoteReference", filePath, firstIdEndnoteReference, "", wordInfoReqVos);
|
String secondIdDrawing = getStringRandom();
|
||||||
|
XmlCursor wDrawingXml = wDrawingCursor.newCursor();
|
||||||
|
wDrawingXml.selectPath(namespace + ".//wp:anchor/wp:docPr/@name");
|
||||||
|
if (wDrawingXml.toNextSelection()) {
|
||||||
|
setWordInfo("图形" + wDrawingIndex + ":" + wDrawingXml.getTextValue(), "(//w:drawing)[" + wDrawingIndex + "]", "w:drawing", filePath, secondIdDrawing, firstIdDrawing, wordInfoReqVos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
endnoteReferenceIndex ++;
|
// 4、尾注
|
||||||
String secondIdEndnoteReference = getStringRandom();
|
XmlCursor endnoteReferenceCursor = docXml.newCursor();
|
||||||
setWordInfo("尾注", "(//w:endnoteReference)[" + endnoteReferenceIndex + "]", "w:endnoteReference", filePath, secondIdEndnoteReference, firstIdEndnoteReference, wordInfoReqVos);
|
String endnoteReferencePath = namespace + "//w:endnoteReference";
|
||||||
}
|
endnoteReferenceCursor.selectPath(endnoteReferencePath);
|
||||||
// 5、表格
|
int endnoteReferenceIndex = 0;
|
||||||
XmlCursor tblCursor = docXml.newCursor();
|
String firstIdEndnoteReference = getStringRandom();
|
||||||
String tblCursorPath = namespace + "//w:tbl";
|
while (endnoteReferenceCursor.toNextSelection()) {
|
||||||
endnoteReferenceCursor.selectPath(tblCursorPath);
|
if (endnoteReferenceIndex == 0) {
|
||||||
int tblIndex = 0;
|
setWordInfo("引用", "w:endnoteReference", "w:endnoteReference", filePath, firstIdEndnoteReference, "", wordInfoReqVos);
|
||||||
String firstIdTbl = getStringRandom();
|
}
|
||||||
while (endnoteReferenceCursor.toNextSelection()) {
|
endnoteReferenceIndex ++;
|
||||||
if (tblIndex == 0) {
|
String secondIdEndnoteReference = getStringRandom();
|
||||||
setWordInfo("表格", "w:endnoteReference", "w:endnoteReference", filePath, firstIdTbl, "", wordInfoReqVos);
|
setWordInfo("尾注", "(//w:endnoteReference)[" + endnoteReferenceIndex + "]", "w:endnoteReference", filePath, secondIdEndnoteReference, firstIdEndnoteReference, wordInfoReqVos);
|
||||||
}
|
}
|
||||||
tblIndex ++;
|
// 5、表格
|
||||||
String secondIdTbl = getStringRandom();
|
XmlCursor tblCursor = docXml.newCursor();
|
||||||
setWordInfo("表格:"+tblIndex, "(//w:tbl)[" + tblIndex + "]", "w:tbl", filePath, secondIdTbl, firstIdTbl, wordInfoReqVos);
|
String tblCursorPath = namespace + "//w:tbl";
|
||||||
}
|
endnoteReferenceCursor.selectPath(tblCursorPath);
|
||||||
// 5、域
|
int tblIndex = 0;
|
||||||
XmlCursor yuCursor = docXml.newCursor();
|
String firstIdTbl = getStringRandom();
|
||||||
String yuCursorPath = namespace + "//w:instrText";
|
while (endnoteReferenceCursor.toNextSelection()) {
|
||||||
endnoteReferenceCursor.selectPath(yuCursorPath);
|
if (tblIndex == 0) {
|
||||||
int yuIndex = 0;
|
setWordInfo("表格", "w:endnoteReference", "w:endnoteReference", filePath, firstIdTbl, "", wordInfoReqVos);
|
||||||
String firstIdyu = getStringRandom();
|
}
|
||||||
while (endnoteReferenceCursor.toNextSelection()) {
|
tblIndex ++;
|
||||||
if (yuIndex == 0) {
|
String secondIdTbl = getStringRandom();
|
||||||
setWordInfo("域", "w:instrText", "w:instrText", filePath, firstIdyu, "", wordInfoReqVos);
|
setWordInfo("表格:"+tblIndex, "(//w:tbl)[" + tblIndex + "]", "w:tbl", filePath, secondIdTbl, firstIdTbl, wordInfoReqVos);
|
||||||
}
|
}
|
||||||
yuIndex ++;
|
// 5、域
|
||||||
String secondIdyu = getStringRandom();
|
XmlCursor yuCursor = docXml.newCursor();
|
||||||
setWordInfo("域:"+yuIndex, "(//w:instrText)[" + yuIndex + "]", "w:instrText", filePath, secondIdyu, firstIdyu, wordInfoReqVos);
|
String yuCursorPath = namespace + "//w:instrText";
|
||||||
|
endnoteReferenceCursor.selectPath(yuCursorPath);
|
||||||
|
int yuIndex = 0;
|
||||||
|
String firstIdyu = getStringRandom();
|
||||||
|
while (endnoteReferenceCursor.toNextSelection()) {
|
||||||
|
if (yuIndex == 0) {
|
||||||
|
setWordInfo("域", "w:instrText", "w:instrText", filePath, firstIdyu, "", wordInfoReqVos);
|
||||||
|
}
|
||||||
|
yuIndex ++;
|
||||||
|
String secondIdyu = getStringRandom();
|
||||||
|
setWordInfo("域:"+yuIndex, "(//w:instrText)[" + yuIndex + "]", "w:instrText", filePath, secondIdyu, firstIdyu, wordInfoReqVos);
|
||||||
|
}
|
||||||
|
return wordInfoReqVos;
|
||||||
}
|
}
|
||||||
return wordInfoReqVos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user