【修改】 修改pptx关联表相关方法
This commit is contained in:
@@ -153,15 +153,16 @@
|
||||
<version>2.4.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.docx4j</groupId>
|
||||
<artifactId>docx4j-core</artifactId>
|
||||
<version>11.5.3</version> <!-- 或使用最新版本 -->
|
||||
<version>11.5.4</version> <!-- 或使用最新版本 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.docx4j</groupId>
|
||||
<artifactId>docx4j-JAXB-MOXy</artifactId>
|
||||
<version>11.5.3</version>
|
||||
<version>11.5.4</version>
|
||||
</dependency>
|
||||
<!-- 必须加这个,不然 marshaltoString 会报错 -->
|
||||
<dependency>
|
||||
|
@@ -17,6 +17,7 @@ import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsDocxInfoVo;
|
||||
import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
|
||||
import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService;
|
||||
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO;
|
||||
|
||||
@@ -25,12 +26,13 @@ import java.util.List;
|
||||
/**
|
||||
* wps word
|
||||
* rwb
|
||||
*
|
||||
* @author REN
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/auto/wps")
|
||||
@Tag( name = "测试判分2 - wps相关操作")
|
||||
@Tag(name = "测试判分2 - wps相关操作")
|
||||
@Validated
|
||||
public class AutoWpsController {
|
||||
|
||||
@@ -41,9 +43,29 @@ public class AutoWpsController {
|
||||
@Resource
|
||||
JudgementWpsExcelService judgementWpsExcelService;
|
||||
|
||||
/**
|
||||
* wps word
|
||||
*
|
||||
* @return 获取大类
|
||||
*/
|
||||
@PostMapping("/docxDataInfo")
|
||||
public CommonResult<List<DocxDataInfoVO>> runWpsWord(FileUploadReqVO file) throws Exception {
|
||||
return CommonResult.success(judgementWpsWordService.docxDataInfo(file.getFile()));
|
||||
}
|
||||
|
||||
/**
|
||||
* wps pptx
|
||||
*
|
||||
* @return 获取大类
|
||||
*/
|
||||
@PostMapping("/slideDataInfo")
|
||||
public CommonResult<List<SlideDataInfoVO>> runWpsSlide(FileUploadReqVO file) throws Exception {
|
||||
return CommonResult.success(judgementWpsPptxService.docxDataInfo(file.getFile()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定考点的数据
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -53,19 +75,11 @@ public class AutoWpsController {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<WpsDocxInfoVo> wpsDocxInfoVos = objectMapper.readValue(
|
||||
jsonData,
|
||||
new TypeReference<List<WpsDocxInfoVo>>() {}
|
||||
new TypeReference<List<WpsDocxInfoVo>>() {
|
||||
}
|
||||
);
|
||||
return CommonResult.success(judgementWpsWordService.docxMaster(wpsDocxInfoVos, file));
|
||||
}
|
||||
|
||||
/**
|
||||
* wps word
|
||||
* @return 获取大类
|
||||
*/
|
||||
@PostMapping("/docxDataInfo")
|
||||
public CommonResult<List<DocxDataInfoVO>> runWpsWord(FileUploadReqVO file) throws Exception {
|
||||
return CommonResult.success(judgementWpsWordService.docxDataInfo(file.getFile()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.AutoWps.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
public class WpsDocxInfoVo {
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package pc.exam.pp.module.judgement.controller.admin.AutoWps.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WpsSlideInfoVo {
|
||||
|
||||
// 大类名称
|
||||
private String firstName;
|
||||
|
||||
// 序号
|
||||
private String index;
|
||||
|
||||
// 方法名称
|
||||
private String function;
|
||||
|
||||
// 考点名称
|
||||
private String examName;
|
||||
|
||||
// 考点代码
|
||||
private String examCode;
|
||||
|
||||
// 方式方法
|
||||
private String method;
|
||||
}
|
@@ -55,23 +55,23 @@ public class WpsController {
|
||||
// public CommonResult<List<WordInfoReqVo>> runWpsWord(String path) throws Exception {
|
||||
// return CommonResult.success(judgementWpsWordService.programmingWpsWord(path));
|
||||
// }
|
||||
/**
|
||||
* wps xlsx
|
||||
* @return 判分
|
||||
*/
|
||||
@GetMapping("/runWpsPptx")
|
||||
public CommonResult<List<PptxInfoReqVo>> runWpsPptx(String path) throws Exception {
|
||||
return CommonResult.success(judgementWpsPptxService.programmingWpsPptx(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* wps xlsx
|
||||
* @return 判分
|
||||
*/
|
||||
@PostMapping("/runTestpptx")
|
||||
public CommonResult<List<WpsPptxJudgementDto>> runTestpptx(@RequestBody List<JudgementReqVo> judgementReq, String path) throws Exception {
|
||||
return CommonResult.success(judgementWpsPptxService.judgementWpsPptx(judgementReq, path));
|
||||
}
|
||||
// /**
|
||||
// * wps xlsx
|
||||
// * @return 判分
|
||||
// */
|
||||
// @GetMapping("/runWpsPptx")
|
||||
// public CommonResult<List<PptxInfoReqVo>> runWpsPptx(String path) throws Exception {
|
||||
// return CommonResult.success(judgementWpsPptxService.programmingWpsPptx(path));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * wps xlsx
|
||||
// * @return 判分
|
||||
// */
|
||||
// @PostMapping("/runTestpptx")
|
||||
// public CommonResult<List<WpsPptxJudgementDto>> runTestpptx(@RequestBody List<JudgementReqVo> judgementReq, String path) throws Exception {
|
||||
// return CommonResult.success(judgementWpsPptxService.judgementWpsPptx(judgementReq, path));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package pc.exam.pp.module.judgement.service.wps_pptx;
|
||||
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -10,10 +12,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface JudgementWpsPptxService {
|
||||
|
||||
List<PptxInfoReqVo> programmingWpsPptx(String path) throws Exception;
|
||||
List<JudgementSlidesVO> slideMaster(List<WpsSlideInfoVo> wpsSlideInfoVos, MultipartFile file) throws Exception;
|
||||
|
||||
// List<WpsPptxJudgementDto> getWpsPptxInfo(List<PptxInfoPointsVo> pptxInfoPointsVos) throws IOException;
|
||||
|
||||
List<WpsPptxJudgementDto> judgementWpsPptx(List<JudgementReqVo> judgementReq, String path) throws Exception;
|
||||
List<SlideDataInfoVO> docxDataInfo(MultipartFile file) throws Exception;
|
||||
|
||||
}
|
||||
|
@@ -2,12 +2,17 @@ package pc.exam.pp.module.judgement.service.wps_pptx;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
|
||||
import pc.exam.pp.module.infra.service.config.ConfigService;
|
||||
import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo;
|
||||
import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
//import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.JudgementWpsPPT;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideConversion;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import pc.exam.pp.module.system.service.user.AdminUserService;
|
||||
@@ -25,81 +30,19 @@ import static pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils.get
|
||||
@Service
|
||||
public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService {
|
||||
|
||||
// @Resource
|
||||
// AutoToolsService autoToolsService;
|
||||
|
||||
@Resource
|
||||
ConfigService configService;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
|
||||
// @Override
|
||||
// public List<WpsPptxJudgementDto> getWpsPptxInfo(List<PptxInfoPointsVo> pptxInfoPointsVos) throws IOException {
|
||||
// List<WpsPptxJudgementDto> judgementDtos = WpsPptxUtils.getWpsPptxInfos(pptxInfoPointsVos);
|
||||
// return judgementDtos;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<WpsPptxJudgementDto> judgementWpsPptx(List<JudgementReqVo> judgementReq, String path) throws Exception {
|
||||
return JudgementWpsPPT.getValues(judgementReq);
|
||||
public List<JudgementSlidesVO> slideMaster(List<WpsSlideInfoVo> wpsSlideInfoVos, MultipartFile file) throws Exception {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param file pptx文件流
|
||||
* @return 所有考点大类
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@Override
|
||||
public List<PptxInfoReqVo> programmingWpsPptx(String path) throws Exception {
|
||||
String pathName = "";
|
||||
String[] strPaht = path.split("/");
|
||||
// 1、获取文件临时下载路径
|
||||
ConfigDO config = configService.getConfigByKey("file_down_wps_pptx_path");
|
||||
AdminUserDO user = userService.getUser(getLoginUserId());
|
||||
// Path paths = Paths.get(config.getValue() + "\\" + user.getId());
|
||||
// if (Files.exists(paths)) {
|
||||
// pathName = config.getValue() + "\\" + user.getId() + "\\" + strPaht[strPaht.length - 1];
|
||||
// } else {
|
||||
// 2、下载文件并返回文件完整路径
|
||||
pathName = downloadStudentFile(path, config.getValue() + "\\" + user.getId());
|
||||
// }
|
||||
// 4、pptx文件读取并返回考点及说明信息
|
||||
// List<PptxVO> margins = WpsPptxUtils.wpsPptx(pathName, paragraphList);
|
||||
List<PptxInfoReqVo> pptxInfoList = JudgementWpsPPT.wpsPptxInfo(pathName);
|
||||
// 5、已经读取完得考点删除源文件
|
||||
// File file = new File(pathName);
|
||||
// file.delete();
|
||||
return pptxInfoList;
|
||||
public List<SlideDataInfoVO> docxDataInfo(MultipartFile file) throws Exception {
|
||||
return SlideConversion.SlideDataInfos(file);
|
||||
}
|
||||
|
||||
public String downloadStudentFile(String fileUrl, String filePath) {
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
URLConnection connection = url.openConnection();
|
||||
|
||||
String fileName = new File(url.getPath()).getName();
|
||||
File dir = new File(filePath);
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
|
||||
File saveFile = new File(dir, fileName);
|
||||
|
||||
try (InputStream in = connection.getInputStream();
|
||||
FileOutputStream out = new FileOutputStream(saveFile)) {
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
System.out.println("✅ 下载成功: " + saveFile.getAbsolutePath());
|
||||
return saveFile.getAbsolutePath();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("❌ 下载失败: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,97 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
|
||||
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class SlideConversion {
|
||||
// 大纲
|
||||
// 1、获取第一层目录 幻灯片 - 母版 - 设置 - 其他
|
||||
// 2、获取第二层目录 第x页 - 幻灯片母版/备注母版 - 幻灯片设置 - 文件操作
|
||||
// 3、获取第三层目录 幻灯片设置/形状 - 幻灯片母版 - 幻灯片设置 - 文件操作
|
||||
public static List<SlideDataInfoVO> SlideDataInfos(MultipartFile file) throws Exception {
|
||||
List<SlideDataInfoVO> dataInfoVOS = new ArrayList<>();
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
XMLSlideShow pptxXml = new XMLSlideShow(inputStream)) {
|
||||
int index = 0;
|
||||
String firstId = getStringRandom();
|
||||
setSlideDataInfo(firstId, "", "幻灯片", "w:p", "", false, dataInfoVOS);
|
||||
for (XSLFSlide slides : pptxXml.getSlides()){
|
||||
index += 1;
|
||||
String secondId = getStringRandom();
|
||||
setSlideDataInfo(secondId, firstId, "第"+index+"页", "p:sld", String.valueOf(index), true, dataInfoVOS);
|
||||
// 第三层
|
||||
String thirdId = getStringRandom();
|
||||
int indexCnvPr = 1;
|
||||
setSlideDataInfo(thirdId, secondId, "幻灯片设置", "slide", String.valueOf(index), true, dataInfoVOS);
|
||||
XmlCursor spCursor = slides.getXmlObject().newCursor();
|
||||
spCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:sp");
|
||||
while (spCursor.toNextSelection()) {
|
||||
XmlCursor cNvPrXml = spCursor.newCursor();
|
||||
cNvPrXml.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:cNvPr/@name");
|
||||
if (cNvPrXml.toNextSelection()) {
|
||||
String name = cNvPrXml.getTextValue();
|
||||
String fourId = getStringRandom();
|
||||
setSlideDataInfo(fourId, secondId, "形状"+indexCnvPr+"->"+name, "slides", String.valueOf(indexCnvPr), true, dataInfoVOS);
|
||||
indexCnvPr += 1;
|
||||
}
|
||||
}
|
||||
XmlCursor picCursor = slides.getXmlObject().newCursor();
|
||||
System.out.println(picCursor.xmlText());
|
||||
picCursor.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//p:pic");
|
||||
int indexCnvPrPic = 1;
|
||||
while (picCursor.toNextSelection()) {
|
||||
String fourId = getStringRandom();
|
||||
setSlideDataInfo(fourId, secondId, "图像"+indexCnvPrPic+"->图像", "p:pic", String.valueOf(indexCnvPrPic), true, dataInfoVOS);
|
||||
indexCnvPrPic += 1;
|
||||
}
|
||||
}
|
||||
// 设置
|
||||
String firstIds = getStringRandom();
|
||||
setSlideDataInfo(firstIds, "", "设置", "p:presentation", String.valueOf(0), false, dataInfoVOS);
|
||||
String secondIds = getStringRandom();
|
||||
setSlideDataInfo(secondIds, firstIds, "幻灯片设置", "p:presentation", String.valueOf(0), true, dataInfoVOS);
|
||||
|
||||
// 母版
|
||||
// String dFirstId = getStringRandom();
|
||||
// setPptxInfo("母版", "p:sld", "p:sld", filePath, dFirstId, "0", pptxInfoReqVos);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return dataInfoVOS;
|
||||
}
|
||||
|
||||
public static String getStringRandom() {
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 生成指定长度的随机字符字符串
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int randomIndex = random.nextInt(characters.length());
|
||||
// 随机字符
|
||||
sb.append(characters.charAt(randomIndex));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// 想数组中添加数据
|
||||
public static void setSlideDataInfo(String id, String parentId, String text,
|
||||
String type, String index, boolean isTrue, List<SlideDataInfoVO> dataInfoVOS) throws Exception {
|
||||
SlideDataInfoVO dataInfo = new SlideDataInfoVO();
|
||||
dataInfo.setId(id);
|
||||
dataInfo.setParentId(parentId);
|
||||
dataInfo.setName(text);
|
||||
dataInfo.setType(type);
|
||||
dataInfo.setIndex(index);
|
||||
dataInfo.setClick(isTrue);
|
||||
dataInfoVOS.add(dataInfo);
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
|
||||
|
||||
public class SlideMaster {
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author REN
|
||||
*/
|
||||
@Data
|
||||
public class JudgementSlidesVO {
|
||||
|
||||
// 考点
|
||||
private String content;
|
||||
|
||||
// 考点名称
|
||||
private String contentIn;
|
||||
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SlideDataInfoVO {
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
private String id;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private String index;
|
||||
|
||||
private boolean isClick;
|
||||
}
|
Reference in New Issue
Block a user