知情同意书合并打印
This commit is contained in:
parent
6dbebb37f3
commit
ea24436a1a
@ -8,4 +8,12 @@ public class BloodPrintTypeConstants {
|
|||||||
* 输血前评估单
|
* 输血前评估单
|
||||||
*/
|
*/
|
||||||
public static final String ASSESS_BEFORE = "ASSESS_BEFORE";
|
public static final String ASSESS_BEFORE = "ASSESS_BEFORE";
|
||||||
|
/**
|
||||||
|
* 知情同意书1
|
||||||
|
*/
|
||||||
|
public static final String INFORMED_CONSENT_1 = "INFORMED_CONSENT_1";
|
||||||
|
/**
|
||||||
|
* 知情同意书2
|
||||||
|
*/
|
||||||
|
public static final String INFORMED_CONSENT_2 = "INFORMED_CONSENT_2";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,14 +7,18 @@ import com.czblood.common.core.domain.Result;
|
|||||||
import com.czblood.common.utils.file.FileUtils;
|
import com.czblood.common.utils.file.FileUtils;
|
||||||
import com.czblood.common.utils.file.ImageUtils;
|
import com.czblood.common.utils.file.ImageUtils;
|
||||||
import com.czblood.common.utils.ip.IpUtils;
|
import com.czblood.common.utils.ip.IpUtils;
|
||||||
|
import com.lowagie.text.Document;
|
||||||
|
import com.lowagie.text.pdf.PdfCopy;
|
||||||
|
import com.lowagie.text.pdf.PdfReader;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -71,4 +75,75 @@ public class ReportUtil {
|
|||||||
}
|
}
|
||||||
return httpPath;
|
return httpPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并多个Base64编码的PDF为一个PDF文件
|
||||||
|
* @param base64PdfList 包含多个PDF的Base64字符串列表
|
||||||
|
* @param outputFilePath 合并后PDF的输出路径(如:D:/merged.pdf)
|
||||||
|
* @throws Exception 处理过程中的异常
|
||||||
|
*/
|
||||||
|
public static void mergeToFile(List<String> base64PdfList, String outputFilePath) throws Exception {
|
||||||
|
// 1. 合并所有PDF字节流为一个字节数组
|
||||||
|
byte[] mergedBytes = mergeBase64Pdfs(base64PdfList);
|
||||||
|
|
||||||
|
// 2. 将合并后的字节数组写入文件
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(outputFilePath)) {
|
||||||
|
fos.write(mergedBytes);
|
||||||
|
}
|
||||||
|
log.info("PDF合并完成,输出路径:{}", outputFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并多个Base64编码的PDF为字节数组
|
||||||
|
*
|
||||||
|
* @param base64PdfList Base64字符串列表
|
||||||
|
* @return 合并后的PDF字节数组
|
||||||
|
* @throws Exception 处理异常
|
||||||
|
*/
|
||||||
|
private static byte[] mergeBase64Pdfs(List<String> base64PdfList) throws Exception {
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
Document document = null;
|
||||||
|
PdfCopy pdfCopy = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < base64PdfList.size(); i++) {
|
||||||
|
// 解码Base64为PDF字节数组
|
||||||
|
String base64Str = base64PdfList.get(i);
|
||||||
|
byte[] pdfBytes = Base64.decode(base64Str); // 使用Hutool解码
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(pdfBytes);
|
||||||
|
|
||||||
|
// 读取PDF文件
|
||||||
|
PdfReader reader = new PdfReader(inputStream);
|
||||||
|
|
||||||
|
// 初始化文档(仅第一次循环时)
|
||||||
|
if (i == 0) {
|
||||||
|
document = new Document(reader.getPageSizeWithRotation(1));
|
||||||
|
pdfCopy = new PdfCopy(document, outputStream);
|
||||||
|
document.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 合并所有页面
|
||||||
|
for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) {
|
||||||
|
pdfCopy.addPage(pdfCopy.getImportedPage(reader, pageNum));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 释放资源
|
||||||
|
pdfCopy.freeReader(reader);
|
||||||
|
reader.close();
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// 关闭文档和输出流
|
||||||
|
if (document != null) {
|
||||||
|
document.close();
|
||||||
|
}
|
||||||
|
if (outputStream != null) {
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,9 +56,9 @@ public class TransfuseApplyBeforeController {
|
|||||||
return transfuseApplyBeforeService.delete(billNo);
|
return transfuseApplyBeforeService.delete(billNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("打印输血前评估单")
|
@ApiOperation("打印单据")
|
||||||
@GetMapping("/print")
|
@GetMapping("/print")
|
||||||
public Result print(String billNo){
|
public Result print(String billNo,String templateName){
|
||||||
return transfuseApplyBeforeService.print(billNo);
|
return transfuseApplyBeforeService.print(billNo,templateName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,5 +15,5 @@ public interface TransfuseApplyBeforeService {
|
|||||||
|
|
||||||
Result delete(String billNo);
|
Result delete(String billNo);
|
||||||
|
|
||||||
Result print(String billNo);
|
Result print(String billNo,String templateName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.czblood.busDoctor.service.impl;
|
package com.czblood.busDoctor.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.czblood.bus.constants.BloodPrintTypeConstants;
|
import com.czblood.bus.constants.BloodPrintTypeConstants;
|
||||||
@ -16,15 +17,21 @@ import com.czblood.bus.utils.ReportUtil;
|
|||||||
import com.czblood.busDoctor.pojo.TransfuseApplyBeforeDTO;
|
import com.czblood.busDoctor.pojo.TransfuseApplyBeforeDTO;
|
||||||
import com.czblood.busDoctor.service.TransfuseApplyBeforeService;
|
import com.czblood.busDoctor.service.TransfuseApplyBeforeService;
|
||||||
import com.czblood.busDoctor.utils.TransfuseApplyBeforeUtil;
|
import com.czblood.busDoctor.utils.TransfuseApplyBeforeUtil;
|
||||||
|
import com.czblood.common.config.RuoYiConfig;
|
||||||
import com.czblood.common.core.domain.Result;
|
import com.czblood.common.core.domain.Result;
|
||||||
|
import com.czblood.common.utils.file.FileUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class TransfuseApplyBeforeServiceImpl implements TransfuseApplyBeforeService {
|
public class TransfuseApplyBeforeServiceImpl implements TransfuseApplyBeforeService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -129,11 +136,40 @@ public class TransfuseApplyBeforeServiceImpl implements TransfuseApplyBeforeServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result print(String billNo) {
|
public Result print(String billNo,String templateName) {
|
||||||
//打印输血前评估单
|
|
||||||
ReportParam reportParam = new ReportParam();
|
ReportParam reportParam = new ReportParam();
|
||||||
reportParam.setBillNo(billNo);
|
reportParam.setBillNo(billNo);
|
||||||
|
switch (templateName){
|
||||||
|
case "ASSESS_BEFORE": //打印输血前评估单
|
||||||
return reportUtil.printToPdf(BloodPrintTypeConstants.ASSESS_BEFORE, reportParam, true);
|
return reportUtil.printToPdf(BloodPrintTypeConstants.ASSESS_BEFORE, reportParam, true);
|
||||||
|
case "INFORMED_CONSENT": //打印知情同意书
|
||||||
|
//有两页,分了两个模版,分别生成pdf之后合并再发给前端
|
||||||
|
String pdfName = UUID.randomUUID().toString();
|
||||||
|
String path = RuoYiConfig.getProfile() +"/static/printPDF/"+pdfName+".pdf";
|
||||||
|
List<String> mergeBgdhList = new ArrayList<>();
|
||||||
|
Result result = reportUtil.printToPdf(BloodPrintTypeConstants.INFORMED_CONSENT_1, reportParam, true);
|
||||||
|
if(!result.getCode().equals("0")) return result;
|
||||||
|
mergeBgdhList.add(BloodBankUtil.isBank(result.getData()));
|
||||||
|
Result result1 = reportUtil.printToPdf(BloodPrintTypeConstants.INFORMED_CONSENT_2, reportParam, true);
|
||||||
|
if(!result1.getCode().equals("0")) return result1;
|
||||||
|
mergeBgdhList.add(BloodBankUtil.isBank(result1.getData()));
|
||||||
|
try {
|
||||||
|
ReportUtil.mergeToFile(mergeBgdhList, path);
|
||||||
|
//转成base64字符串
|
||||||
|
File file = new File(path);
|
||||||
|
String encode = Base64.encode(file);
|
||||||
|
//删除pdf文件
|
||||||
|
FileUtils.deleteFile(path);
|
||||||
|
return new Result("0","打印成功!",encode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("合并pdf:{}报告失败:{}",mergeBgdhList,e);
|
||||||
|
return new Result("-1",e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return new Result("-1","没有找到对应的打印模版!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result canModify(String billNo){
|
public Result canModify(String billNo){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user