feat: 企标带文件导出PDF文件先解密后加水印再加密

This commit is contained in:
2024-05-11 14:21:26 +08:00
parent a985191bdc
commit aad080b900
4 changed files with 68 additions and 7 deletions
@@ -182,6 +182,14 @@ public interface ILawsCommonService {
*/
byte[] getMinioFileContent(OSSFile file) throws Exception;
/**
* 获取文件内容(企标专用 特殊处理了加解密)
* @param file
* @return
* @throws Exception
*/
byte[] getMinioFileContentES(OSSFile file) throws Exception;
/**
* 企标的模板下载是压缩包,里面有两个Excel模板
* @param response
@@ -223,6 +223,9 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
@Value("#{'${enterpriseDetailRoleCode}'.split(',')}")
private List<String> enterpriseDetailRoleCodeList;
@Value("#{'${download.enable}'}")
private boolean enable;
/**
* @Author: liao
* @Date: 2023/8/23 16:57
@@ -1613,7 +1616,11 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
ZipEntry fileEntry = new ZipEntry(file.getFileRelativePath());
zipOut.putNextEntry(fileEntry);
// 将文件取出存入流中
bytes = this.getMinioFileContent(file);
if(TableNameEnum.ENTERPRISE_STANDARDS.getValue().equals(parameterMap.get(FieldCommon.MODULE))) {
bytes = this.getMinioFileContentES(file);
} else {
bytes = this.getMinioFileContent(file);
}
zipOut.write(bytes, 0, bytes.length);
zipOut.closeEntry();
}
@@ -2558,6 +2565,10 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
@Override
public byte[] getMinioFileContent(OSSFile file) throws Exception {
return this.getMinioFileContentNormal(file, false);
}
private byte[] getMinioFileContentNormal(OSSFile file, boolean esSpecial) throws Exception {
String fileUrl = file.getUrl();
String fileName = file.getFileName();
String minioUrl = MinioUtil.getMinioUrl();
@@ -2568,14 +2579,21 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
byte[] buf = new byte[1024];
int len;
if ("pdf".equalsIgnoreCase(FileUtil.extName(fileName))) {
// 如果是PDF文件, 添加水印
try (InputStream originalInputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url);
InputStream watermarkedInputStream = sysWaterMarkUtil.addWatermarkToPdf(originalInputStream)) {
// 如果是系统开启了加密并且处理的是企标 则需要将加水印的pdf文件再次加密
InputStream is = watermarkedInputStream;
if (esSpecial && enable) {
// 加密企标的PDF
is = IntekeyUtils.autoEncryptInputStreamFile(is, fileName);
}
if (originalInputStream == null) {
return null;
}
while ((len = watermarkedInputStream.read(buf)) > 0) {
while ((len = is.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
} catch (Exception e) {
@@ -2600,6 +2618,11 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
}
}
@Override
public byte[] getMinioFileContentES(OSSFile file) throws Exception {
return this.getMinioFileContentNormal(file, true);
}
@Override
public void esTemplateDownload(HttpServletResponse response) throws Exception {
// 1. 生成企标的模板