【修改】 PPTX出题考点优化
This commit is contained in:
@@ -12,6 +12,7 @@ import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
import pc.exam.pp.framework.common.util.object.BeanUtils;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.*;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||
import pc.exam.pp.module.judgement.service.wps_pptx.WpsPptxLinkService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -71,5 +72,10 @@ public class PptxController {
|
||||
WpsPptxLinkDO pptx = wpsPptxLinkService.getPptx(id);
|
||||
return success(BeanUtils.toBean(pptx, PptxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/listInfo")
|
||||
@Operation(summary = "获取wps_pptx列表")
|
||||
public CommonResult<List<PptxRespVO>> getPptxListInfo(PptxListReqVO reqVO) {
|
||||
List<WpsPptxLinkDO> list = wpsPptxLinkService.getPptxListInfo(reqVO);
|
||||
return success(BeanUtils.toBean(list, PptxRespVO.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordReqDto;
|
||||
import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
|
||||
@@ -15,6 +16,8 @@ import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_all.XlsxAllDataReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_drawing.XlsxInfoVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_excel.vo.xlsx_style.XlsxStyleVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
||||
@@ -56,6 +59,23 @@ public class WpsController {
|
||||
public CommonResult<List<WordInfoReqVo>> runWpsWord(String path) throws Exception {
|
||||
return CommonResult.success(judgementWpsWordService.programmingWpsWord(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* wps xlsx
|
||||
* @return 判分
|
||||
*/
|
||||
@PostMapping("/runWpsPptxInfo")
|
||||
public CommonResult<List<WpsPptxJudgementDto>> runWpsPptxInfo(@RequestBody List<PptxInfoPointsVo> pptxInfoPointsVos) throws Exception {
|
||||
return CommonResult.success(judgementWpsPptxService.getWpsPptxInfo(pptxInfoPointsVos));
|
||||
}
|
||||
/**
|
||||
* wps xlsx
|
||||
* @return 判分
|
||||
*/
|
||||
@GetMapping("/runWpsPptx")
|
||||
public CommonResult<List<PptxInfoReqVo>> runWpsPptx(String path) throws Exception {
|
||||
return CommonResult.success(judgementWpsPptxService.programmingWpsPptx(path));
|
||||
}
|
||||
// /**
|
||||
// * wps xlsx
|
||||
// * @return 判分
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.Wps.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author REN
|
||||
*/
|
||||
@Data
|
||||
public class WpsPptxJudgementDto {
|
||||
private String content;
|
||||
private String contentIn;
|
||||
private String image;
|
||||
private String scoreRate;
|
||||
}
|
||||
@@ -18,4 +18,7 @@ public class PptxListReqVO {
|
||||
private Integer type;
|
||||
|
||||
private Integer belongTo;
|
||||
private String nodeFunction;
|
||||
private Integer isboo;
|
||||
private Integer titleType;
|
||||
}
|
||||
|
||||
@@ -37,4 +37,6 @@ public class PptxRespVO {
|
||||
*/
|
||||
private Integer type;
|
||||
private Integer belongTo;
|
||||
private Integer isboo;
|
||||
private Integer titleType;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class PptxSaveReqVO {
|
||||
*/
|
||||
private Integer type;
|
||||
private Integer belongTo;
|
||||
private Integer isboo;
|
||||
private Integer titleType;
|
||||
|
||||
@Schema(description = "父节点 ID", example = "1024")
|
||||
private Long parentId;
|
||||
|
||||
@@ -24,4 +24,6 @@ public class PptxSimpleRespVO {
|
||||
*/
|
||||
private Integer type;
|
||||
private Integer belongTo;
|
||||
private Integer isboo;
|
||||
private Integer titleType;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,9 @@ public class WpsPptxLinkDO extends TenantBaseDO {
|
||||
*/
|
||||
private Integer type;
|
||||
private String belongTo;
|
||||
private Integer isboo;
|
||||
private Integer titleType;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<WpsPptxLinkDO> children = new ArrayList<>();
|
||||
|
||||
@@ -5,6 +5,7 @@ import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxListReqVO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -23,7 +24,14 @@ public interface WpsPptxLinkMapper extends BaseMapperX<WpsPptxLinkDO> {
|
||||
default WpsPptxLinkDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(WpsPptxLinkDO::getParentId, parentId, WpsPptxLinkDO::getName, name);
|
||||
}
|
||||
default WpsPptxLinkDO selectByNodeFunction(String nodeFunction) {
|
||||
return selectOne(WpsPptxLinkDO::getNodeFunction, nodeFunction);
|
||||
}
|
||||
|
||||
default List<WpsPptxLinkDO> selectInfoList(Long id) {
|
||||
return selectList(new LambdaQueryWrapperX<WpsPptxLinkDO>()
|
||||
.eqIfPresent(WpsPptxLinkDO::getParentId, id));
|
||||
}
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
return selectCount(WpsPptxLinkDO::getParentId, parentId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package pc.exam.pp.module.judgement.service.wps_pptx;
|
||||
|
||||
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -10,7 +14,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface JudgementWpsPptxService {
|
||||
|
||||
List<PptxVO> programmingWpsPptx(String path) throws Exception;
|
||||
List<PptxInfoReqVo> programmingWpsPptx(String path) throws Exception;
|
||||
|
||||
double judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception;
|
||||
|
||||
List<WpsPptxJudgementDto> getWpsPptxInfo(List<PptxInfoPointsVo> pptxInfoPointsVos) throws IOException;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
|
||||
import pc.exam.pp.module.exam.utils.file.LogFileUtils;
|
||||
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
|
||||
import pc.exam.pp.module.infra.service.config.ConfigService;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxListReqVO;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.WordListReqVO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO;
|
||||
@@ -14,11 +15,15 @@ import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||
import pc.exam.pp.module.judgement.dal.mysql.wpspptx.WpsPptxLinkMapper;
|
||||
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.WpsPptxUtils;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoPointsVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -37,66 +42,68 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService {
|
||||
WpsPptxLinkMapper wpsPptxLinkMapper;
|
||||
|
||||
@Override
|
||||
public List<PptxVO> programmingWpsPptx(String path) throws Exception {
|
||||
public List<WpsPptxJudgementDto> getWpsPptxInfo(List<PptxInfoPointsVo> pptxInfoPointsVos) throws IOException {
|
||||
List<WpsPptxJudgementDto> judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos);
|
||||
return judgementDtos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PptxInfoReqVo> programmingWpsPptx(String path) throws Exception {
|
||||
// 1、获取文件临时下载路径
|
||||
ConfigDO config = configService.getConfigByKey("file_down_path");
|
||||
ConfigDO config = configService.getConfigByKey("file_down_wps_pptx_path");
|
||||
// 2、下载文件并返回文件完整路径
|
||||
String pathName = autoToolsService.downloadStudentFile(path, config.getValue());
|
||||
// 3、创建pptx考点tree
|
||||
PptxListReqVO pptxListReqVO = new PptxListReqVO();
|
||||
// 查询形状狭的所有数据
|
||||
pptxListReqVO.setBelongTo(0);
|
||||
// 3-1、查询段落的标签
|
||||
List<WpsPptxLinkDO> paragraphList = wpsPptxLinkMapper.selectList(pptxListReqVO);
|
||||
String pathName = autoToolsService.downloadStudentFile(path, config.getValue() + "\\" + WpsWordUtils.getStringRandom());
|
||||
// 4、pptx文件读取并返回考点及说明信息
|
||||
List<PptxVO> margins = WpsPptxUtils.wpsPptx(pathName, paragraphList);
|
||||
// List<PptxVO> margins = WpsPptxUtils.wpsPptx(pathName, paragraphList);
|
||||
List<PptxInfoReqVo> pptxInfoList = WpsPptxUtils.wpsPptxInfo(pathName);
|
||||
// 5、已经读取完得考点删除源文件
|
||||
File file = new File(pathName);
|
||||
file.delete();
|
||||
return margins;
|
||||
// File file = new File(pathName);
|
||||
// file.delete();
|
||||
return pptxInfoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double judgementWpsPptx(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception {
|
||||
|
||||
// 创建log文件txt,用于记录
|
||||
File pathCDir = new File(pathC);
|
||||
File parentDir = pathCDir.getParentFile();
|
||||
|
||||
// 拼接同级目录下的目标文件路径
|
||||
String targetFilePath = new File(parentDir, "WPS_Pptx判分过程.txt").getPath();
|
||||
// 1创建log文件txt,用于记录
|
||||
LogFileUtils.createFile(targetFilePath);
|
||||
LogFileUtils.createFile(pathC + "/WPS_Word判分过程.txt");
|
||||
LogFileUtils.writeLine("✅ 开始WPS_Pptx判分");
|
||||
double wpsPptScore = 0;
|
||||
// 2、pptx文件读取并返回考点及说明信息
|
||||
// 创建pptx考点tree
|
||||
PptxListReqVO pptxListReqVO = new PptxListReqVO();
|
||||
// 查询形状狭的所有数据
|
||||
pptxListReqVO.setBelongTo(0);
|
||||
// 查询段落的标签
|
||||
List<WpsPptxLinkDO> paragraphList = wpsPptxLinkMapper.selectList(pptxListReqVO);
|
||||
List<PptxVO> margins = WpsPptxUtils.wpsPptx(path, paragraphList);
|
||||
List<PptxInfoPointsVo> pptxInfoPointsVos = new ArrayList<>();
|
||||
// 3、获取答案得组成
|
||||
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
|
||||
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
|
||||
PptxInfoPointsVo pptxInfoPointsVo = new PptxInfoPointsVo();
|
||||
// 拆分数据、
|
||||
String[] pptxInfos = examQuestionAnswer.getContent().split("\\?");
|
||||
String[] chineseName = examQuestionAnswer.getContentIn().split("-");
|
||||
String[] typeList = examQuestionAnswer.getImage().split("-");
|
||||
pptxInfoPointsVo.setName("判分");
|
||||
pptxInfoPointsVo.setEnglishName(pptxInfos[0]);
|
||||
pptxInfoPointsVo.setFunction(pptxInfos[1]);
|
||||
pptxInfoPointsVo.setType(typeList[0]);
|
||||
pptxInfoPointsVo.setBelongTo(typeList[1]);
|
||||
pptxInfoPointsVo.setIsboo(typeList[2]);
|
||||
pptxInfoPointsVo.setFilePath(path);
|
||||
pptxInfoPointsVos.add(pptxInfoPointsVo);
|
||||
}
|
||||
List<WpsPptxJudgementDto> judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos);
|
||||
|
||||
// 4、进行关联判断
|
||||
for (ExamQuestionAnswer examQuestionAnswer : answerList) {
|
||||
boolean flag = false;
|
||||
double one_sorce = 0;
|
||||
for (PptxVO pptxVO : margins) {
|
||||
if (pptxVO.getExamKeynote() != null) {
|
||||
if (pptxVO.getExamKeynote().equals(examQuestionAnswer.getContent())) {
|
||||
flag = true;
|
||||
// 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重
|
||||
if (examQuestionAnswer.getScoreRate().equals("1")) {
|
||||
// 说明权重相等,直接平分分数
|
||||
one_sorce = sorce / answerList.size();
|
||||
} else {
|
||||
one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate());
|
||||
}
|
||||
break;
|
||||
for (WpsPptxJudgementDto pptxJudgementDto : judgementDtos) {
|
||||
if (pptxJudgementDto.getContent().equals(examQuestionAnswer.getContent())) {
|
||||
flag = true;
|
||||
// 得分 根据权重进行得分 每个选项分值 = 总分 / 总权重
|
||||
if (examQuestionAnswer.getScoreRate().equals("1")) {
|
||||
// 说明权重相等,直接平分分数
|
||||
one_sorce = sorce / answerList.size();
|
||||
} else {
|
||||
one_sorce = sorce * Double.parseDouble(examQuestionAnswer.getScoreRate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
wpsPptScore += one_sorce;
|
||||
|
||||
@@ -60,6 +60,7 @@ public interface WpsPptxLinkService {
|
||||
* @return 节点列表
|
||||
*/
|
||||
List<WpsPptxLinkDO> getPptxList(PptxListReqVO reqVO);
|
||||
List<WpsPptxLinkDO> getPptxListInfo(PptxListReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 获得指定编号的节点 Map
|
||||
|
||||
@@ -16,6 +16,7 @@ import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxListReqVO;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.vo.PptxSaveReqVO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
|
||||
import pc.exam.pp.module.judgement.dal.mysql.wpspptx.WpsPptxLinkMapper;
|
||||
import pc.exam.pp.module.judgement.utils.tree.vo.TreeVO;
|
||||
import pc.exam.pp.module.system.dal.redis.RedisKeyConstants;
|
||||
@@ -171,6 +172,28 @@ public class WpsPptxLinkServiceImpl implements WpsPptxLinkService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WpsPptxLinkDO> getPptxListInfo(PptxListReqVO reqVO) {
|
||||
String nodeFunction = reqVO.getNodeFunction().split("\\[")[0];
|
||||
List<WpsPptxLinkDO> pptxList = new ArrayList<>();
|
||||
WpsPptxLinkDO data = wpsPptxLinkMapper.selectByNodeFunction(nodeFunction);
|
||||
if (data == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<WpsPptxLinkDO> wpsPptxLinkDOS = wpsPptxLinkMapper.selectInfoList(data.getId());
|
||||
// 在依次判断是否还有子数据
|
||||
for (WpsPptxLinkDO wpsPptxLinkDO : wpsPptxLinkDOS) {
|
||||
pptxList.add(wpsPptxLinkDO);
|
||||
List<WpsPptxLinkDO> datas = wpsPptxLinkMapper.selectInfoList(wpsPptxLinkDO.getId());
|
||||
if (datas != null) {
|
||||
for (WpsPptxLinkDO wpsPptxLinkDO1 : datas) {
|
||||
pptxList.add(wpsPptxLinkDO1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pptxList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WpsPptxLinkDO> getChildPptxList(Collection<Long> ids) {
|
||||
List<WpsPptxLinkDO> children = new LinkedList<>();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class WpsPptxNameSpaces {
|
||||
|
||||
public static String getNameSpace(String xmlString) {
|
||||
// 2、创建最全的命名空间
|
||||
Pattern pattern = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\"");
|
||||
Matcher matcher = pattern.matcher(xmlString);
|
||||
Map<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();
|
||||
return allPathx;
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,180 @@ package pc.exam.pp.module.judgement.utils.wps_pptx;
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.apache.xmlbeans.XmlObject;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsWordJudgementDto;
|
||||
import pc.exam.pp.module.judgement.dal.dataobject.wpspptx.WpsPptxLinkDO;
|
||||
import pc.exam.pp.module.judgement.utils.tree.TreeUtils;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_excel.vo.XlsxCharVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.*;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordInfoReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.zipfile.ZipXmlUtils;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* @author REN
|
||||
*/
|
||||
public class WpsPptxUtils {
|
||||
|
||||
public static List<WpsPptxJudgementDto>getWpsPptxInfos(List<PptxInfoPointsVo> pptxInfoPointsVos) throws IOException {
|
||||
List<WpsPptxJudgementDto> judgementList = new ArrayList<>();
|
||||
String filePath = pptxInfoPointsVos.get(0).getFilePath();
|
||||
List<PptxSlidesVo> pptxSlidesVos = new ArrayList<>();
|
||||
List<PptxSlidesVo> pptxSlidesOrgVos = new ArrayList<>();
|
||||
// 获取所有相关res得记录
|
||||
List<Map<String, String>> slideList = new ArrayList<>();
|
||||
try (ZipFile zipFile = new ZipFile(filePath)) {
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
String entryName = entry.getName();
|
||||
if (entryName.startsWith("ppt/slides/_rels") && entryName.endsWith(".xml.rels")) {
|
||||
PptxSlidesVo pptxSlidesVo = new PptxSlidesVo();
|
||||
String[] names = entryName.split("/");
|
||||
pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]);
|
||||
String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName);
|
||||
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
|
||||
XmlCursor cursor = xmlObject.newCursor();
|
||||
cursor.selectPath("declare namespace r='http://schemas.openxmlformats.org/package/2006/relationships' .//r:Relationships/r:Relationship");
|
||||
// 存放数据
|
||||
while (cursor.toNextSelection()) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String rId = cursor.getAttributeText(new QName("Id"));
|
||||
String target = cursor.getAttributeText(new QName("Target"));
|
||||
map.put(rId, target);
|
||||
slideList.add(map);
|
||||
}
|
||||
pptxSlidesVo.setSlideResList(slideList);
|
||||
pptxSlidesOrgVos.add(pptxSlidesVo);
|
||||
}
|
||||
if (entryName.startsWith("ppt/slides") && entryName.endsWith(".xml") && !entryName.contains(".rels")) {
|
||||
String[] names = entryName.split("/");
|
||||
Optional<PptxSlidesVo> result = pptxSlidesOrgVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(names[entryName.split("/").length-1])).findFirst();
|
||||
PptxSlidesVo pptxSlidesVo = result.get();
|
||||
pptxSlidesVo.setSlideName(names[entryName.split("/").length-1]);
|
||||
String xmlContent = ZipXmlUtils.readZipEntry(zipFile, entryName);
|
||||
XmlObject xmlObject = XmlObject.Factory.parse(xmlContent);
|
||||
XmlCursor cursor = xmlObject.newCursor();
|
||||
pptxSlidesVo.setXmlCursor(cursor);
|
||||
pptxSlidesVos.add(pptxSlidesVo);
|
||||
}
|
||||
}
|
||||
for (PptxInfoPointsVo pptxInfoPointsVo : pptxInfoPointsVos) {
|
||||
// 判断幻灯片形状
|
||||
if ("0".equals(pptxInfoPointsVo.getBelongTo())) {
|
||||
Optional<PptxSlidesVo> result = pptxSlidesVos.stream().filter(pptxSlidesVo -> pptxSlidesVo.getSlideName().contains(pptxInfoPointsVo.getEnglishName())).findFirst();
|
||||
PptxSlidesVo pptxSlidesVo = result.get();
|
||||
XmlCursor slideCursor = pptxSlidesVo.getXmlCursor();
|
||||
String namespace = WpsPptxNameSpaces.getNameSpace(slideCursor.xmlText());
|
||||
// 查询
|
||||
System.out.println(slideCursor.xmlText());
|
||||
slideCursor.selectPath(namespace + pptxInfoPointsVo.getFunction().replace("-", ""));
|
||||
|
||||
if (slideCursor.toNextSelection()) {
|
||||
WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto();
|
||||
// 判断是值还是类型
|
||||
if ("1".equals(pptxInfoPointsVo.getIsboo())) {
|
||||
judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName()+"true");
|
||||
judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+"true");
|
||||
} else {
|
||||
String value = slideCursor.getTextValue();
|
||||
judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName()+value);
|
||||
judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+value);
|
||||
|
||||
}
|
||||
judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo());
|
||||
judgementDto.setScoreRate("1");
|
||||
judgementList.add(judgementDto);
|
||||
} else {
|
||||
if ("1".equals(pptxInfoPointsVo.getIsboo())) {
|
||||
WpsPptxJudgementDto judgementDto = new WpsPptxJudgementDto();
|
||||
judgementDto.setContentIn(getStringName(pptxInfoPointsVo.getEnglishName()) + pptxInfoPointsVo.getName()+"false");
|
||||
judgementDto.setContent(pptxInfoPointsVo.getEnglishName()+"?"+pptxInfoPointsVo.getFunction()+"?"+"false");
|
||||
judgementDto.setImage(pptxInfoPointsVo.getType()+"-"+pptxInfoPointsVo.getBelongTo()+"-"+pptxInfoPointsVo.getIsboo());
|
||||
judgementDto.setScoreRate("1");
|
||||
judgementList.add(judgementDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (XmlException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return judgementList;
|
||||
}
|
||||
|
||||
public static String getStringName(String name) {
|
||||
// 提取字母部分
|
||||
String letters = name.replaceAll("[^a-zA-Z]", "");
|
||||
// 提取数字部分
|
||||
String digits = name.replaceAll("[^0-9]", "");
|
||||
String chineseName = "";
|
||||
if ("slide".equalsIgnoreCase(letters)) {
|
||||
try {
|
||||
int slideNumber = Integer.parseInt(digits);
|
||||
chineseName = "【第 " + slideNumber + " 页】";
|
||||
} catch (NumberFormatException e) {
|
||||
System.out.println("数字解析失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
// 大纲
|
||||
// 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他
|
||||
// 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作
|
||||
// 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作
|
||||
public static List<PptxInfoReqVo> wpsPptxInfo(String filePath) throws FileNotFoundException {
|
||||
List<PptxInfoReqVo> pptxInfoReqVos = new ArrayList<>();
|
||||
try (FileInputStream fis = new FileInputStream(filePath);
|
||||
XMLSlideShow pptxXml = new XMLSlideShow(fis)) {
|
||||
int index = 0;
|
||||
String firstId = getStringRandom();
|
||||
setPptxInfo("幻灯片", "p:sld", "p:sld", filePath, firstId, "0", pptxInfoReqVos);
|
||||
for (XSLFSlide slides : pptxXml.getSlides()){
|
||||
index += 1;
|
||||
String secondId = getStringRandom();
|
||||
setPptxInfo("第"+index+"页", "p:sld"+index, "p:sld"+index, filePath, secondId, firstId, pptxInfoReqVos);
|
||||
// 第三层
|
||||
String thirdId = getStringRandom();
|
||||
int indexCnvPr = 1;
|
||||
setPptxInfo("幻灯片设置", "slide"+indexCnvPr, "(//p:sp)-["+indexCnvPr+"]", filePath, thirdId, secondId, pptxInfoReqVos);
|
||||
XmlCursor spCursor = slides.getXmlObject().newCursor();
|
||||
spCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:sp");
|
||||
while (spCursor.toNextSelection()) {
|
||||
XmlCursor cNvPrXml = spCursor.newCursor();
|
||||
cNvPrXml.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:cNvPr/@name");
|
||||
if (cNvPrXml.toNextSelection()) {
|
||||
System.out.println(cNvPrXml.xmlText());
|
||||
String name = cNvPrXml.getTextValue();
|
||||
String fourId = getStringRandom();
|
||||
setPptxInfo("形状"+indexCnvPr+"->"+name, "slide"+indexCnvPr, "(//p:sp)["+indexCnvPr+"]", filePath, fourId, secondId, pptxInfoReqVos);
|
||||
indexCnvPr += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 母版
|
||||
// String dFirstId = getStringRandom();
|
||||
// setPptxInfo("母版", "p:sld", "p:sld", filePath, dFirstId, "0", pptxInfoReqVos);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return pptxInfoReqVos;
|
||||
}
|
||||
|
||||
|
||||
public static List<PptxVO> wpsPptx(String filePath, List<WpsPptxLinkDO> cSldList) {
|
||||
List<PptxVO> pptxVOS = new ArrayList<>();
|
||||
// 转换数据
|
||||
@@ -93,6 +252,31 @@ public class WpsPptxUtils {
|
||||
return pptxVOS;
|
||||
}
|
||||
|
||||
public static void setPptxInfo(String chineseName, String englishName, String selectName, String filePath, String id, String parentId, List<PptxInfoReqVo> pptxInfoReqVos) throws Exception {
|
||||
PptxInfoReqVo pptxInfos = new PptxInfoReqVo();
|
||||
pptxInfos.setName(chineseName);
|
||||
pptxInfos.setEnglishName(englishName);
|
||||
pptxInfos.setFilePath(filePath);
|
||||
pptxInfos.setId(id);
|
||||
pptxInfos.setSelectName(selectName);
|
||||
pptxInfos.setParentId(parentId);
|
||||
pptxInfoReqVos.add(pptxInfos);
|
||||
}
|
||||
|
||||
public static String getStringRandom() {
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 生成指定长度的随机字符字符串
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int randomIndex = random.nextInt(characters.length());
|
||||
// 随机字符
|
||||
sb.append(characters.charAt(randomIndex));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pptxVOS List<PptxVO> 用来存放结果
|
||||
* @param firstTitle String 用来存放一级标题
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PptxInfoPointsVo {
|
||||
|
||||
private String name;
|
||||
|
||||
private String englishName;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String function;
|
||||
|
||||
private String belongTo;
|
||||
|
||||
private String isboo;
|
||||
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author REN
|
||||
*/
|
||||
@Data
|
||||
public class PptxInfoReqVo {
|
||||
|
||||
private String name;
|
||||
|
||||
private String englishName;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private String selectName;
|
||||
|
||||
private String id;
|
||||
|
||||
private List<PptxInfoReqVo> children = new ArrayList<>();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author REN
|
||||
*/
|
||||
@Data
|
||||
public class PptxListVo {
|
||||
|
||||
private String name;
|
||||
|
||||
private XmlCursor xmlCursor;
|
||||
|
||||
private String target;
|
||||
|
||||
private XmlCursor resXmlCursor;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class PptxSlidesVo {
|
||||
|
||||
private String slideName;
|
||||
|
||||
private XmlCursor xmlCursor;
|
||||
|
||||
private List<Map<String, String>> slideResList;
|
||||
}
|
||||
@@ -13,4 +13,7 @@ public class PptxVO {
|
||||
|
||||
@Schema(description = "考点汉化")
|
||||
private String keynoteChinese;
|
||||
|
||||
@Schema(description = "代码")
|
||||
private String code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user