Commit 8030520d by songxiang

错题本发UAT

parent 71055296
...@@ -62,7 +62,12 @@ public enum TranscodeFromEnum { ...@@ -62,7 +62,12 @@ public enum TranscodeFromEnum {
/** /**
* 错题本-答案 * 错题本-答案
*/ */
NOTE_ANSWER("NOTE_ANSWER"); NOTE_ANSWER("NOTE_ANSWER"),
/**
* 错题本-打印
*/
NOTE_PRINT("NOTE_PRINT");
/** /**
* 值 * 值
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
*/ */
package com.pcloud.common.enums; package com.pcloud.common.enums;
import com.google.common.collect.Maps;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Maps;
/** /**
* @描述:应用类型常量枚举 * @描述:应用类型常量枚举
* @作者:songx * @作者:songx
......
...@@ -69,7 +69,7 @@ public class WordUtils { ...@@ -69,7 +69,7 @@ public class WordUtils {
/** /**
* 创建WORD * 创建WORD
* *
* @param pdfChunkDOs * @param wordPOs
* @return * @return
* @throws Exception * @throws Exception
*/ */
...@@ -110,7 +110,7 @@ public class WordUtils { ...@@ -110,7 +110,7 @@ public class WordUtils {
/** /**
* 添加内容到PDF中 * 添加内容到PDF中
* *
* @param pdfPOs * @param wordPOs
* @param document * @param document
* @throws BizException * @throws BizException
* @throws DocumentException * @throws DocumentException
...@@ -133,7 +133,7 @@ public class WordUtils { ...@@ -133,7 +133,7 @@ public class WordUtils {
/** /**
* 添加块 * 添加块
* *
* @param pdfPO * @param wordPO
* @throws BizException * @throws BizException
* @throws DocumentException * @throws DocumentException
*/ */
...@@ -173,7 +173,7 @@ public class WordUtils { ...@@ -173,7 +173,7 @@ public class WordUtils {
/** /**
* 添加表格 * 添加表格
* *
* @param pdfPO * @param wordPO
* @throws BizException * @throws BizException
* @throws DocumentException * @throws DocumentException
*/ */
...@@ -232,7 +232,7 @@ public class WordUtils { ...@@ -232,7 +232,7 @@ public class WordUtils {
/** /**
* 添加图片 * 添加图片
* *
* @param pdfPO * @param wordPO
* @param document * @param document
* @throws MalformedURLException * @throws MalformedURLException
* @throws IOException * @throws IOException
...@@ -286,30 +286,9 @@ public class WordUtils { ...@@ -286,30 +286,9 @@ public class WordUtils {
} }
/** /**
* 结束关闭文件流
*
* @param document
* @param os
*/
private static void close(CustomXWPFDocument document, OutputStream os) {
try {
if (document != null) {
document.close();
document = null;
}
if (os != null) {
os.close();
os = null;
}
} catch (Exception e) {
LOGGER.error("【WORD】WORD文件流关闭失败:" + e.getMessage(), e);
}
}
/**
* 创建WORD * 创建WORD
* *
* @param pdfChunkDOs * @param wordPOs
* @return * @return
* @throws Exception * @throws Exception
*/ */
...@@ -338,7 +317,7 @@ public class WordUtils { ...@@ -338,7 +317,7 @@ public class WordUtils {
LOGGER.error("【WORD】创建WORD文档失败:" + e.getMessage(), e); LOGGER.error("【WORD】创建WORD文档失败:" + e.getMessage(), e);
throw new FileException(FileException.FILE_CONTENT_ERROR, e.getMessage()); throw new FileException(FileException.FILE_CONTENT_ERROR, e.getMessage());
} finally { } finally {
close(document, fos); WordNewUtils.close(document, fos);
FileUtils.deleteFile(wordTemplate); FileUtils.deleteFile(wordTemplate);
} }
LOGGER.info("【WORD】创建WORD文档,<END>.[outPath]=" + outPath); LOGGER.info("【WORD】创建WORD文档,<END>.[outPath]=" + outPath);
...@@ -348,7 +327,7 @@ public class WordUtils { ...@@ -348,7 +327,7 @@ public class WordUtils {
/** /**
* 添加内容到WORD中 * 添加内容到WORD中
* *
* @param pdfPOs * @param wordPOs
* @param document * @param document
* @throws BizException * @throws BizException
* @throws DocumentException * @throws DocumentException
...@@ -356,7 +335,7 @@ public class WordUtils { ...@@ -356,7 +335,7 @@ public class WordUtils {
* @throws IOException * @throws IOException
*/ */
private static void addChunks(List<WordPO> wordPOs, CustomXWPFDocument document) private static void addChunks(List<WordPO> wordPOs, CustomXWPFDocument document)
throws BizException, DocumentException, MalformedURLException, IOException { throws BizException, DocumentException {
for (WordPO wordPO : wordPOs) { for (WordPO wordPO : wordPOs) {
if (wordPO instanceof WordChunkPO) { if (wordPO instanceof WordChunkPO) {
addChunk(wordPO, document); addChunk(wordPO, document);
...@@ -380,8 +359,9 @@ public class WordUtils { ...@@ -380,8 +359,9 @@ public class WordUtils {
XWPFParagraph paragraph = document.createParagraph(); XWPFParagraph paragraph = document.createParagraph();
XWPFRun xwpfRun = paragraph.createRun(); XWPFRun xwpfRun = paragraph.createRun();
xwpfRun.setText(wordChunkPO.getText()); xwpfRun.setText(wordChunkPO.getText());
if (wordChunkPO.getFontSize() > 0) if (wordChunkPO.getFontSize() > 0) {
xwpfRun.setFontSize(wordChunkPO.getFontSize()); xwpfRun.setFontSize(wordChunkPO.getFontSize());
}
// //
paragraph.setFontAlignment(wordChunkPO.getFontAlign()); paragraph.setFontAlignment(wordChunkPO.getFontAlign());
paragraph.setSpacingBeforeLines((int) wordChunkPO.getSpacingBefore()); paragraph.setSpacingBeforeLines((int) wordChunkPO.getSpacingBefore());
...@@ -394,7 +374,7 @@ public class WordUtils { ...@@ -394,7 +374,7 @@ public class WordUtils {
wordPOs.add(new WordChunkPO("标题", ParagraphAlignment.CENTER.getValue(), 20, 20, 20)); wordPOs.add(new WordChunkPO("标题", ParagraphAlignment.CENTER.getValue(), 20, 20, 20));
wordPOs.add(new WordChunkPO("qweqweasdasd\raweqdasd\nasdasfas\tfasdfca", ParagraphAlignment.CENTER.getValue(), wordPOs.add(new WordChunkPO("qweqweasdasd\raweqdasd\nasdasfas\tfasdfca", ParagraphAlignment.CENTER.getValue(),
13, 13, 20)); 13, 13, 20));
wordPOs.add(new WordTablePO(new String[][] { { "a", "b", "c", "d" }, { "q", "w", "e" } }, 60, wordPOs.add(new WordTablePO(new String[][]{{"a", "b", "c", "d"}, {"q", "w", "e"}}, 60,
XWPFVertAlign.CENTER)); XWPFVertAlign.CENTER));
wordPOs.add(new WordImagePO("D:\\1.png", ParagraphAlignment.CENTER.getValue(), 200, 200, "1.", null)); wordPOs.add(new WordImagePO("D:\\1.png", ParagraphAlignment.CENTER.getValue(), 200, 200, "1.", null));
wordPOs.add(new WordImagePO("D:\\读者圈.jpg", ParagraphAlignment.CENTER.getValue(), 200, 200, "2.", null)); wordPOs.add(new WordImagePO("D:\\读者圈.jpg", ParagraphAlignment.CENTER.getValue(), 200, 200, "2.", null));
...@@ -409,7 +389,7 @@ public class WordUtils { ...@@ -409,7 +389,7 @@ public class WordUtils {
/** /**
* 添加表格 * 添加表格
* *
* @param pdfPO * @param wordPO
* @throws BizException * @throws BizException
* @throws DocumentException * @throws DocumentException
*/ */
...@@ -448,15 +428,16 @@ public class WordUtils { ...@@ -448,15 +428,16 @@ public class WordUtils {
cell.setVerticalAlignment(wordTablePO.getVertAlign()); cell.setVerticalAlignment(wordTablePO.getVertAlign());
} }
// 行高 // 行高
if (wordTablePO.getHeight() > 0) if (wordTablePO.getHeight() > 0) {
comTableRow.setHeight(wordTablePO.getHeight()); comTableRow.setHeight(wordTablePO.getHeight());
} }
} }
}
/** /**
* 添加图片 * 添加图片
* *
* @param pdfPO * @param wordPO
* @param document * @param document
* @throws MalformedURLException * @throws MalformedURLException
* @throws IOException * @throws IOException
...@@ -487,9 +468,10 @@ public class WordUtils { ...@@ -487,9 +468,10 @@ public class WordUtils {
if (!StringUtil.isEmpty(beforeText)) { if (!StringUtil.isEmpty(beforeText)) {
XWPFRun xwpfRun = paragraph.createRun(); XWPFRun xwpfRun = paragraph.createRun();
xwpfRun.setText(beforeText); xwpfRun.setText(beforeText);
if (wordImagePO.getFontSize() > 0) if (wordImagePO.getFontSize() > 0) {
xwpfRun.setFontSize(wordImagePO.getFontSize()); xwpfRun.setFontSize(wordImagePO.getFontSize());
} }
}
// 图片 // 图片
int id = document.getAllPictures().size() - 1; int id = document.getAllPictures().size() - 1;
document.createPicture(paragraph, relationId, id, wordImagePO.getWidth(), wordImagePO.getHeight()); document.createPicture(paragraph, relationId, id, wordImagePO.getWidth(), wordImagePO.getHeight());
...@@ -498,9 +480,10 @@ public class WordUtils { ...@@ -498,9 +480,10 @@ public class WordUtils {
if (!StringUtil.isEmpty(afterText)) { if (!StringUtil.isEmpty(afterText)) {
XWPFRun xwpfRun = paragraph.createRun(); XWPFRun xwpfRun = paragraph.createRun();
xwpfRun.setText(afterText); xwpfRun.setText(afterText);
if (wordImagePO.getFontSize() > 0) if (wordImagePO.getFontSize() > 0) {
xwpfRun.setFontSize(wordImagePO.getFontSize()); xwpfRun.setFontSize(wordImagePO.getFontSize());
} }
}
paragraph.setFontAlignment(wordPO.getFontAlign()); paragraph.setFontAlignment(wordPO.getFontAlign());
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -508,28 +491,4 @@ public class WordUtils { ...@@ -508,28 +491,4 @@ public class WordUtils {
} }
} }
/**
* 根据图片类型获取对应的图片类型代码
*
* @param picType
* @return
*/
public static int getPictureType(String picType) {
int res = CustomXWPFDocument.PICTURE_TYPE_PICT;
if (picType != null) {
if (picType.equalsIgnoreCase("png")) {
res = CustomXWPFDocument.PICTURE_TYPE_PNG;
} else if (picType.equalsIgnoreCase("dib")) {
res = CustomXWPFDocument.PICTURE_TYPE_DIB;
} else if (picType.equalsIgnoreCase("emf")) {
res = CustomXWPFDocument.PICTURE_TYPE_EMF;
} else if (picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")) {
res = CustomXWPFDocument.PICTURE_TYPE_JPEG;
} else if (picType.equalsIgnoreCase("wmf")) {
res = CustomXWPFDocument.PICTURE_TYPE_WMF;
}
}
return res;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment