bug 处理
This commit is contained in:
parent
8aeba6f773
commit
9f40e901f5
2
pom.xml
2
pom.xml
@ -28,7 +28,7 @@
|
||||
<oshi.version>6.4.0</oshi.version>
|
||||
<commons.io.version>2.11.0</commons.io.version>
|
||||
<commons.collections.version>3.2.2</commons.collections.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<poi.version>5.2.0</poi.version>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<jwt.version>0.9.1</jwt.version>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
|
@ -52,8 +52,23 @@
|
||||
<artifactId>jfreechart</artifactId>
|
||||
<version>1.5.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.docx4j/docx4j-core -->
|
||||
<dependency>
|
||||
<groupId>aspose</groupId>
|
||||
<artifactId>aspose-words</artifactId>
|
||||
<version>15.8.0-jdk16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>aspose</groupId>
|
||||
<artifactId>aspose-slides</artifactId>
|
||||
<version>19.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.deepoove</groupId>
|
||||
<artifactId>poi-tl</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itextpdf</artifactId>
|
||||
|
@ -83,7 +83,7 @@ public class PatientScriptController extends BaseController {
|
||||
*/
|
||||
@PostMapping("/exportReport")
|
||||
public void exportReport(HttpServletResponse response, @RequestParam("id") Long reportId) throws Exception {
|
||||
this.patientScriptService.exportReport(response,reportId);
|
||||
this.patientScriptService.exportReportTest(response,reportId);
|
||||
}
|
||||
|
||||
@PostMapping("/test")
|
||||
|
@ -72,6 +72,9 @@ public class PatientScript extends BaseEntity {
|
||||
private String shDoctor;
|
||||
//0否1是
|
||||
private String isAll;
|
||||
private String kydw;
|
||||
private String fzr;
|
||||
private String phone;
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,9 @@ public interface PatientScriptService {
|
||||
|
||||
Boolean removeByIds(List<Long> idList);
|
||||
void exportReport(HttpServletResponse response, Long reportId) throws Exception;
|
||||
void exportReportTest(HttpServletResponse response, Long reportId) throws Exception;
|
||||
|
||||
|
||||
void exportReport2(HttpServletResponse response, Long reportId) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.ruoyi.script.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.deepoove.poi.data.Pictures;
|
||||
import com.itextpdf.text.*;
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
import com.itextpdf.text.pdf.PdfChunk;
|
||||
@ -11,6 +13,9 @@ import com.ruoyi.script.entity.PatientScript;
|
||||
import com.ruoyi.script.mapper.PatientScriptMapper;
|
||||
import com.ruoyi.script.service.PatientScriptService;
|
||||
import com.ruoyi.script.util.ShellUtil;
|
||||
import com.ruoyi.script.util.Word2PdfUtil;
|
||||
import com.ruoyi.script.util.WordToPdfConverter;
|
||||
import com.ruoyi.script.util.WorldToPdf;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
@ -20,12 +25,17 @@ import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
@ -34,6 +44,8 @@ import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static com.ruoyi.script.util.ShellUtil.shUtil;
|
||||
import static com.ruoyi.script.util.WordToPdfConverter.convertToPdf;
|
||||
import static com.ruoyi.script.util.WordToPdfConverter.replacePlaceholders;
|
||||
import static com.ruoyi.script.util.YmlUtil.createFile;
|
||||
import static com.ruoyi.system.util.pdfUtil.PdfUtil.chineseFont;
|
||||
import static com.ruoyi.system.util.pdfUtil.PdfUtil.getImageFromInputStream;
|
||||
@ -927,6 +939,142 @@ public class PatientScriptServiceImpl implements PatientScriptService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportReportTest(HttpServletResponse response, Long reportId) throws Exception {
|
||||
PatientScript patientScript = scriptMapper.getById(reportId);
|
||||
if (null==patientScript.getStatus()||patientScript.getStatus().equals("生成中")){
|
||||
return;
|
||||
}
|
||||
|
||||
String resInfo = patientScript.getResInfo();
|
||||
String[] brainList ={};
|
||||
//分类信息
|
||||
Map<String,Integer> classMap = new HashMap<>();
|
||||
String[] correlationList ={};
|
||||
List<String> msgList = new ArrayList<>();
|
||||
if (resInfo.contains("brain_regions:")){
|
||||
String[] split = resInfo.split("', '");
|
||||
String replace = split[0].replace("('brain_regions:", "");
|
||||
brainList = replace.split(",");
|
||||
}
|
||||
if (resInfo.contains("correlation:")){
|
||||
String[] split = resInfo.split("', '");
|
||||
String replace = split[1].replace("correlation:", "").replace("')","");
|
||||
correlationList = replace.split(",");
|
||||
|
||||
}
|
||||
for (String key : brainList) {
|
||||
key = key.replaceAll(" ","");
|
||||
try {
|
||||
MriInfo mriInfo = scriptMapper.getMriInfo(key.trim());
|
||||
if(StringUtils.isNotEmpty(mriInfo.getBrainInfo())){
|
||||
if (classMap.containsKey(mriInfo.getBrainStr())){
|
||||
classMap.put(mriInfo.getBrainStr(),classMap.get(mriInfo.getBrainInfo())+1);
|
||||
|
||||
}else {
|
||||
classMap.put(mriInfo.getBrainStr(),1);
|
||||
msgList.add(mriInfo.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Word 模板路径
|
||||
String wordTemplatePath = "/opt/mriTemp.docx";
|
||||
//随机十个生成的文件名称数组
|
||||
String[] fileNames =
|
||||
{"output1.docx", "output2.docx", "output3.docx", "output4.docx", "output5.docx", "output6.docx", "output7.docx", "output8.docx", "output9.docx", "output10.docx"};
|
||||
//随机一个名字
|
||||
String fileName = fileNames[new Random().nextInt(fileNames.length)];
|
||||
String outPath = "/opt/"+fileName;
|
||||
|
||||
|
||||
// 占位符和实际值的映射
|
||||
Map<String, Object> placeholders = new HashMap<>();
|
||||
placeholders.put("patientName", patientScript.getPatientName());
|
||||
placeholders.put("patientSex", patientScript.getPatientSex());
|
||||
placeholders.put("patientAge", patientScript.getPatientSex());
|
||||
|
||||
placeholders.put("patientCard", patientScript.getPatientCard());
|
||||
placeholders.put("blOrder", patientScript.getBlOrder());
|
||||
placeholders.put("scanPosition", patientScript.getScanPosition());
|
||||
|
||||
placeholders.put("scanDoctor", patientScript.getScanDoctor());
|
||||
placeholders.put("scanTime", DateUtil.format(patientScript.getScanTime(),"yyyy年MM月dd日"));
|
||||
// 图片文件
|
||||
placeholders.put("image1", Pictures.ofLocal(patientScript.getResImage()).size(260, 260).create());
|
||||
// 图片文件
|
||||
placeholders.put("image2", Pictures.ofLocal(patientScript.getResImage().replace("Net","Net2")).size(260, 260).create());
|
||||
// 图片文件
|
||||
placeholders.put("image3", Pictures.ofLocal(patientScript.getResImage().replace("Net","Net3")).size(260, 260).create());
|
||||
// 图片文件
|
||||
placeholders.put("image4", Pictures.ofLocal(patientScript.getResImage().replace("Net","Net4")).size(260, 260).create());
|
||||
|
||||
placeholders.put("kydw", Optional.ofNullable(patientScript.getKydw()).orElse(" "));
|
||||
placeholders.put("fzr", Optional.ofNullable(patientScript.getFzr()).orElse(" "));
|
||||
placeholders.put("phone", Optional.ofNullable(patientScript.getPhone()).orElse(" "));
|
||||
String brainInfo = "";
|
||||
for (int i = 0; i < brainList.length; i++) {
|
||||
if (i==brainList.length-1){
|
||||
brainInfo= brainInfo+brainList[i];
|
||||
}else {
|
||||
brainInfo= brainInfo+brainList[i]+"\n";
|
||||
}
|
||||
}
|
||||
|
||||
placeholders.put("brainInfo",brainInfo);
|
||||
|
||||
String joinInfo = "";
|
||||
for (int i = 0; i < correlationList.length; i++) {
|
||||
if (i==correlationList.length-1){
|
||||
joinInfo= joinInfo+correlationList[i];
|
||||
}else {
|
||||
joinInfo= joinInfo+correlationList[i]+"\n";
|
||||
}
|
||||
}
|
||||
placeholders.put("joinInfo",joinInfo);
|
||||
final String[] diagInfo = {""};
|
||||
classMap.forEach((item, index)->{
|
||||
diagInfo[0] = diagInfo[0] +index+"个属于"+item+",";
|
||||
});
|
||||
int idx = diagInfo[0].lastIndexOf(",");
|
||||
diagInfo[0] = diagInfo[0].substring(0,idx);
|
||||
diagInfo[0]=diagInfo[0]+"。"+"\n";
|
||||
for (int i = 0; i < msgList.size(); i++) {
|
||||
if (i==msgList.size()-1){
|
||||
diagInfo[0]= diagInfo[0]+" "+msgList.get(i);
|
||||
}else {
|
||||
diagInfo[0]= diagInfo[0]+" "+msgList.get(i)+"\n";
|
||||
}
|
||||
}
|
||||
placeholders.put("diagInfo", " 异常脑区中,"+diagInfo[0]);
|
||||
placeholders.put("resInfo", patientScript.getResInfo().equals("异常")?"孤独症谱系障碍":"正常发育个体");
|
||||
|
||||
placeholders.put("zdDoctor", patientScript.getZdDoctor());
|
||||
placeholders.put("shDoctor", patientScript.getShDoctor());
|
||||
try {
|
||||
|
||||
// 文件操作
|
||||
XWPFTemplate template = XWPFTemplate.compile(new File(wordTemplatePath)).render(
|
||||
placeholders);
|
||||
template.writeAndClose(Files.newOutputStream(Paths.get(outPath)));
|
||||
try {
|
||||
Word2PdfUtil.wordConvertPdfFile(outPath,response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (IOException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成六位随机数字
|
||||
*/
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.ruoyi.script.util;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ConvertToMultipartFile implements MultipartFile {
|
||||
private byte[] fileBytes;
|
||||
String name;
|
||||
String originalFilename;
|
||||
String contentType;
|
||||
boolean isEmpty;
|
||||
long size;
|
||||
|
||||
public ConvertToMultipartFile(byte[] fileBytes, String name, String originalFilename, String contentType,
|
||||
long size) {
|
||||
this.fileBytes = fileBytes;
|
||||
this.name = name;
|
||||
this.originalFilename = originalFilename;
|
||||
this.contentType = contentType;
|
||||
this.size = size;
|
||||
this.isEmpty = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return isEmpty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
return fileBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(fileBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
new FileOutputStream(dest).write(fileBytes);
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.ruoyi.script.util;
|
||||
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.License;
|
||||
import com.aspose.words.SaveFormat;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* word转pdf工具类
|
||||
*
|
||||
* @author shmily
|
||||
*/
|
||||
public class Word2PdfUtil {
|
||||
|
||||
/**
|
||||
* 许可证字符串(可以放到resource下的xml文件中也可)
|
||||
*/
|
||||
private static final String LICENSE = "<License>" +
|
||||
"<Data>" +
|
||||
"<Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products>" +
|
||||
"<EditionType>Enterprise</EditionType>" +
|
||||
"<SubscriptionExpiry>20991231</SubscriptionExpiry>" +
|
||||
"<LicenseExpiry>20991231</LicenseExpiry>" +
|
||||
"<SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>" +
|
||||
"</Data>" +
|
||||
"<Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>" +
|
||||
"</License>";
|
||||
|
||||
|
||||
/**
|
||||
* 设置 license 去除水印
|
||||
*/
|
||||
private static void setLicense() {
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(LICENSE.getBytes());
|
||||
License license = new License();
|
||||
try {
|
||||
license.setLicense(byteArrayInputStream);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* word 转 pdf 生成至指定路径,pdf为空则上传至word同级目录
|
||||
*
|
||||
* @param wordPath word文件路径
|
||||
* @param pdfPath pdf文件路径
|
||||
*/
|
||||
public static void wordConvertPdfFile(String wordPath, OutputStream outputStream) {
|
||||
try {
|
||||
setLicense();
|
||||
Document doc = new Document(wordPath);
|
||||
doc.save(outputStream, SaveFormat.PDF);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* word 转 pdf 生成byte字节流
|
||||
*
|
||||
* @param wordPath word所在的目录地址
|
||||
* @return
|
||||
*/
|
||||
public static byte[] wordConvertPdfByte(String wordPath) {
|
||||
ByteArrayOutputStream fileOutputStream = null;
|
||||
try {
|
||||
setLicense();
|
||||
fileOutputStream = new ByteArrayOutputStream();
|
||||
Document doc = new Document(wordPath);
|
||||
doc.save(fileOutputStream, SaveFormat.PDF);
|
||||
return fileOutputStream.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
assert fileOutputStream != null;
|
||||
fileOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取 生成的 pdf 文件路径,默认与源文件同一目录
|
||||
*
|
||||
* @param wordPath word文件
|
||||
* @return 生成的 pdf 文件
|
||||
*/
|
||||
private static String getPdfFilePath(String wordPath) {
|
||||
int lastIndexOfPoint = wordPath.lastIndexOf(".");
|
||||
String pdfFilePath = "";
|
||||
if (lastIndexOfPoint > -1) {
|
||||
pdfFilePath = wordPath.substring(0, lastIndexOfPoint);
|
||||
}
|
||||
return pdfFilePath + ".pdf";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.ruoyi.script.util;
|
||||
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WordToPdfConverter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// // Word 模板路径
|
||||
// String wordTemplatePath = "template.docx";
|
||||
// // 输出 PDF 路径
|
||||
// String pdfOutputPath = "output.pdf";
|
||||
//
|
||||
// // 占位符和实际值的映射
|
||||
// Map<String, String> placeholders = new HashMap<>();
|
||||
// placeholders.put("${name}", "John Doe");
|
||||
// placeholders.put("${date}", "2023-10-15");
|
||||
// placeholders.put("${description}", "This is a sample description.");
|
||||
//
|
||||
// try {
|
||||
// // 读取 Word 模板
|
||||
// XWPFDocument document = new XWPFDocument(new FileInputStream(wordTemplatePath));
|
||||
//
|
||||
// // 替换占位符
|
||||
// replacePlaceholders(document, placeholders);
|
||||
//
|
||||
// // 将内容写入 PDF
|
||||
//// convertToPdf(document, pdfOutputPath);
|
||||
//
|
||||
// System.out.println("PDF generated successfully!");
|
||||
//
|
||||
// } catch (IOException | DocumentException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换 Word 文档中的占位符
|
||||
*/
|
||||
public static void replacePlaceholders(XWPFDocument document, Map<String, String> placeholders) {
|
||||
for (XWPFParagraph paragraph : document.getParagraphs()) {
|
||||
List<XWPFRun> runs = paragraph.getRuns();
|
||||
if (runs != null) {
|
||||
for (XWPFRun run : runs) {
|
||||
String text = run.getText(0);
|
||||
if (text != null) {
|
||||
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
if (text.contains(entry.getKey())) {
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
run.setText(text, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Word 文档内容写入 PDF
|
||||
*/
|
||||
public static void convertToPdf(XWPFDocument document, ServletOutputStream servletOutputStream) throws DocumentException, IOException {
|
||||
Document pdfDocument = new Document();
|
||||
PdfWriter.getInstance(pdfDocument, servletOutputStream);
|
||||
pdfDocument.open();
|
||||
|
||||
// 将 Word 文档的每一段内容写入 PDF
|
||||
for (XWPFParagraph paragraph : document.getParagraphs()) {
|
||||
String text = paragraph.getText();
|
||||
if (text != null && !text.isEmpty()) {
|
||||
pdfDocument.add(new Paragraph(text));
|
||||
}
|
||||
}
|
||||
|
||||
pdfDocument.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.script.util;
|
||||
|
||||
import lombok.var;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class WordToPdfConverter2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 模板文件路径(相对于 resources 目录)
|
||||
String templatePath = "static/mriTemp.docx";
|
||||
|
||||
try (InputStream inputStream = WordToPdfConverter.class.getClassLoader().getResourceAsStream(templatePath)) {
|
||||
if (inputStream == null) {
|
||||
System.err.println("模板文件未找到: " + templatePath);
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取 Word 模板
|
||||
XWPFDocument document = new XWPFDocument(inputStream);
|
||||
|
||||
// 打印文档内容(测试用)
|
||||
for (var paragraph : document.getParagraphs()) {
|
||||
System.out.println(paragraph.getText());
|
||||
}
|
||||
|
||||
System.out.println("模板读取成功!");
|
||||
|
||||
} catch (NotOfficeXmlFileException e) {
|
||||
System.err.println("文件格式不正确,请确保是 .docx 文件: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
System.err.println("读取文件时发生错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.ruoyi.script.util;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.documents4j.api.DocumentType;
|
||||
import com.documents4j.api.IConverter;
|
||||
import com.documents4j.job.LocalConverter;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
public class WorldToPdf {
|
||||
|
||||
/**
|
||||
* 在Word模版中写入指定内容
|
||||
* @param filePath 模版文件地址
|
||||
* @param targetPath 生成文件的目标地址
|
||||
* @param map 填充内容
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void writForTemplate(String filePath, String targetPath, Map<String,Object> map) throws IOException {
|
||||
|
||||
XWPFTemplate template = XWPFTemplate.compile(filePath).render(map);
|
||||
|
||||
template.writeAndClose(Files.newOutputStream(Paths.get(targetPath)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param wordPath word 文件路径
|
||||
* @param pdfPath pdf 输出路径
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void wordConvertPdf(String wordPath, OutputStream outputStream) throws IOException {
|
||||
try {
|
||||
// // Load the Word document
|
||||
// WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(wordPath));
|
||||
//
|
||||
//
|
||||
// Docx4J.toPDF(wordMLPackage, outputStream);
|
||||
//
|
||||
// System.out.println("Word document converted to PDF successfully.");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param wordPath word 文件路径
|
||||
* @param pdfPath pdf 输出路径
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void wordConvertPdfs(String wordPath, String pdfPath) throws IOException {
|
||||
InputStream wordInputStream = Files.newInputStream(Paths.get(wordPath));
|
||||
// 转成 pdf
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get(pdfPath));
|
||||
IConverter converter = LocalConverter.builder().build();
|
||||
converter.convert(wordInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
||||
converter.shutDown();
|
||||
}
|
||||
|
||||
// 文件转换
|
||||
|
||||
// 文件转换
|
||||
|
||||
|
||||
}
|
@ -13,8 +13,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -61,4 +64,26 @@ public class OverdueController {
|
||||
}
|
||||
return R.ok("激活成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 加密算法
|
||||
private static final String ALGORITHM = "AES";
|
||||
// 常量密钥
|
||||
private static final String SECRET_KEY = "jinanshandongdianliangxinxijishu";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String data = "山东点亮20250311175500信息技术";
|
||||
SecretKeySpec keySpec = generateKey();
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
|
||||
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
|
||||
System.err.println(Base64.getEncoder().encodeToString(encryptedBytes));
|
||||
}
|
||||
|
||||
// 生成密钥
|
||||
private static SecretKeySpec generateKey() throws Exception {
|
||||
byte[] keyBytes = SECRET_KEY.getBytes();
|
||||
return new SecretKeySpec(keyBytes, ALGORITHM);
|
||||
}
|
||||
}
|
||||
|
BIN
ruoyi-admin/src/main/resources/static/mriTemp.docx
Normal file
BIN
ruoyi-admin/src/main/resources/static/mriTemp.docx
Normal file
Binary file not shown.
@ -52,13 +52,13 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- JSON工具类 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 动态数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
@ -83,7 +83,17 @@
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- word 转 pdf -->
|
||||
<dependency>
|
||||
<groupId>com.documents4j</groupId>
|
||||
<artifactId>documents4j-local</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.documents4j</groupId>
|
||||
<artifactId>documents4j-transformer-msoffice-word</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
<!-- yml解析器 -->
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
@ -133,5 +143,8 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -5,13 +5,14 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.ruoyi.common.utils.poi.ExcelHandlerAdapter;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import com.ruoyi.common.utils.poi.ExcelHandlerAdapter;
|
||||
|
||||
/**
|
||||
* 自定义导出Excel数据注解
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ -184,4 +185,4 @@ public @interface Excel
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ import com.ruoyi.common.utils.reflect.ReflectUtils;
|
||||
|
||||
/**
|
||||
* Excel相关处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ExcelUtil<T>
|
||||
@ -279,7 +279,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对excel表单默认第一个索引名转换成list
|
||||
*
|
||||
*
|
||||
* @param is 输入流
|
||||
* @return 转换后集合
|
||||
*/
|
||||
@ -290,7 +290,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对excel表单默认第一个索引名转换成list
|
||||
*
|
||||
*
|
||||
* @param is 输入流
|
||||
* @param titleNum 标题占用行数
|
||||
* @return 转换后集合
|
||||
@ -302,7 +302,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对excel表单指定表格索引名转换成list
|
||||
*
|
||||
*
|
||||
* @param sheetName 表格索引名
|
||||
* @param titleNum 标题占用行数
|
||||
* @param is 输入流
|
||||
@ -482,7 +482,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @return 结果
|
||||
@ -494,7 +494,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
@ -508,7 +508,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param response 返回数据
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
@ -521,7 +521,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param response 返回数据
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
@ -538,7 +538,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param sheetName 工作表的名称
|
||||
* @return 结果
|
||||
*/
|
||||
@ -549,7 +549,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
* @return 结果
|
||||
@ -562,7 +562,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param sheetName 工作表的名称
|
||||
* @return 结果
|
||||
*/
|
||||
@ -573,7 +573,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @param sheetName 工作表的名称
|
||||
* @param title 标题
|
||||
* @return 结果
|
||||
@ -588,7 +588,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public void exportExcel(HttpServletResponse response)
|
||||
@ -610,7 +610,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
public AjaxResult exportExcel()
|
||||
@ -678,7 +678,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 填充excel数据
|
||||
*
|
||||
*
|
||||
* @param index 序号
|
||||
* @param row 单元格行
|
||||
*/
|
||||
@ -749,7 +749,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 创建表格样式
|
||||
*
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 样式列表
|
||||
*/
|
||||
@ -802,7 +802,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格头样式
|
||||
*
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
@ -835,7 +835,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格列样式
|
||||
*
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
@ -897,7 +897,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 设置单元格信息
|
||||
*
|
||||
*
|
||||
* @param value 单元格值
|
||||
* @param attr 注解相关
|
||||
* @param cell 单元格信息
|
||||
@ -1061,7 +1061,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 设置 POI XSSFSheet 单元格提示或选择框
|
||||
*
|
||||
*
|
||||
* @param sheet 表单
|
||||
* @param textlist 下拉框显示的内容
|
||||
* @param promptContent 提示内容
|
||||
@ -1098,7 +1098,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框).
|
||||
*
|
||||
*
|
||||
* @param sheet 要设置的sheet.
|
||||
* @param textlist 下拉框显示的内容
|
||||
* @param promptContent 提示内容
|
||||
@ -1150,7 +1150,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 解析导出值 0=男,1=女,2=未知
|
||||
*
|
||||
*
|
||||
* @param propertyValue 参数值
|
||||
* @param converterExp 翻译注解
|
||||
* @param separator 分隔符
|
||||
@ -1187,7 +1187,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 反向解析值 男=0,女=1,未知=2
|
||||
*
|
||||
*
|
||||
* @param propertyValue 参数值
|
||||
* @param converterExp 翻译注解
|
||||
* @param separator 分隔符
|
||||
@ -1224,7 +1224,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 解析字典值
|
||||
*
|
||||
*
|
||||
* @param dictValue 字典值
|
||||
* @param dictType 字典类型
|
||||
* @param separator 分隔符
|
||||
@ -1237,7 +1237,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 反向解析值字典值
|
||||
*
|
||||
*
|
||||
* @param dictLabel 字典标签
|
||||
* @param dictType 字典类型
|
||||
* @param separator 分隔符
|
||||
@ -1250,7 +1250,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 数据处理器
|
||||
*
|
||||
*
|
||||
* @param value 数据值
|
||||
* @param excel 数据注解
|
||||
* @return
|
||||
@ -1327,7 +1327,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 获取下载路径
|
||||
*
|
||||
*
|
||||
* @param filename 文件名称
|
||||
*/
|
||||
public String getAbsoluteFile(String filename)
|
||||
@ -1343,7 +1343,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 获取bean中的属性值
|
||||
*
|
||||
*
|
||||
* @param vo 实体对象
|
||||
* @param field 字段
|
||||
* @param excel 注解
|
||||
@ -1374,7 +1374,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 以类的属性的get方法方法形式获取值
|
||||
*
|
||||
*
|
||||
* @param o
|
||||
* @param name
|
||||
* @return value
|
||||
@ -1480,7 +1480,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 创建工作表
|
||||
*
|
||||
*
|
||||
* @param sheetNo sheet数量
|
||||
* @param index 序号
|
||||
*/
|
||||
@ -1497,7 +1497,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 获取单元格值
|
||||
*
|
||||
*
|
||||
* @param row 获取的行
|
||||
* @param column 获取单元格列号
|
||||
* @return 单元格值
|
||||
@ -1557,7 +1557,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 判断是否是空行
|
||||
*
|
||||
*
|
||||
* @param row 判断的行
|
||||
* @return
|
||||
*/
|
||||
@ -1634,8 +1634,8 @@ public class ExcelUtil<T>
|
||||
XSSFPicture pic = (XSSFPicture) shape;
|
||||
XSSFClientAnchor anchor = pic.getPreferredSize();
|
||||
CTMarker ctMarker = anchor.getFrom();
|
||||
String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
|
||||
sheetIndexPicMap.put(picIndex, pic.getPictureData());
|
||||
// String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
|
||||
// sheetIndexPicMap.put(picIndex, pic.getPictureData());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1645,7 +1645,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 格式化不同类型的日期对象
|
||||
*
|
||||
*
|
||||
* @param dateFormat 日期格式
|
||||
* @param val 被格式化的日期对象
|
||||
* @return 格式化后的日期字符
|
||||
@ -1711,7 +1711,7 @@ public class ExcelUtil<T>
|
||||
|
||||
/**
|
||||
* 获取对象的子列表方法
|
||||
*
|
||||
*
|
||||
* @param name 名称
|
||||
* @param pojoClass 类对象
|
||||
* @return 子列表方法
|
||||
|
@ -6,5 +6,5 @@ public interface Constants {
|
||||
// 常量密钥
|
||||
String SECRET_KEY = "jinanshandongdianliangxinxijishu";
|
||||
//密钥存储文件地址
|
||||
String KEY_FILE_PATH = "E:/overdue.txt";
|
||||
}
|
||||
String KEY_FILE_PATH = "D:/overdue.txt";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user