Browse Source

测试出差申请单加密打印

zhouy 2 years ago
parent
commit
9327ab492e

BIN
report/lib/com/uas/report/kernel/1.0.0/kernel-1.0.0.jar


+ 9 - 0
report/lib/com/uas/report/kernel/1.0.0/kernel-1.0.0.pom

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.uas.report</groupId>
+  <artifactId>kernel</artifactId>
+  <version>1.0.0</version>
+  <description>Artifactory auto generated POM</description>
+</project>

+ 6 - 0
report/pom.xml

@@ -164,6 +164,12 @@
             <version>1.0.0</version>
         </dependency>
 
+		<dependency>
+			<groupId>com.uas.report</groupId>
+			<artifactId>kernel</artifactId>
+			<version>1.0.0</version>
+		</dependency>
+
 		<!-- 文件上传 -->
 		<dependency>
 			<groupId>commons-fileupload</groupId>

+ 30 - 1
report/src/main/java/com/uas/report/controller/PrintController.java

@@ -1,5 +1,6 @@
 package com.uas.report.controller;
 
+import com.itextpdf.kernel.pdf.*;
 import com.uas.report.DynamicProperties;
 import com.uas.report.model.ExportType;
 import com.uas.report.model.Platform;
@@ -196,6 +197,7 @@ public class PrintController {
 				+ fileService.generateFileName(userName, profile, whereCondition, otherParameters, exportFileType)
                 + "." + exportType.getQualifier();
 		File file = new File(ReportUtils.getDocumentsDir(), filePath);
+		System.out.println(file.getAbsolutePath()+'-'+file.getPath());
 		// 指定flush为true(强制刷新pdf、xls)
 		// 文件无效(不存在或过期),创建
 		if ((flush != null && flush)
@@ -204,6 +206,19 @@ public class PrintController {
 				throw new IllegalStateException("数据量过大,无法提供服务");
 			}
 			printService.export(userName, profile, reportName, whereCondition, otherParameters, exportType, file, null, true);
+			if("AccountRegZW_ccsq".equals(reportName)) {
+				PdfReader pdfReader = new PdfReader(file);
+				WriterProperties writerProperties = new WriterProperties();
+				writerProperties.setStandardEncryption(null, "edit_paaword".getBytes(), EncryptionConstants.ALLOW_PRINTING, EncryptionConstants.ENCRYPTION_AES_128);
+				String path = ReportUtils.getDocumentsDir()+"/"+reportName + "/"
+						+ fileService.generateFileEncryt(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
+						+ "." + ExportType.PDF.getQualifier();
+				PdfWriter pdfWriter = new PdfWriter(path, writerProperties);
+				PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter);
+				pdfDocument.close();
+				file = new File(path);
+			}
+
 		}
 		String exportFileName = (!StringUtils.isEmpty(title) ? title : reportName);
 		if (split) {
@@ -255,7 +270,21 @@ public class PrintController {
 			}
 			printService.export(userName, profile, reportName, whereCondition, otherParameters, ExportType.PDF, file, null, true);
 		}
-		return "pdf/preview?p=" + pdfPath;
+		if("AccountRegZW_ccsq".equals(reportName)) {
+			PdfReader pdfReader = new PdfReader(file);
+			WriterProperties writerProperties = new WriterProperties();
+			writerProperties.setStandardEncryption(null,"edit_paaword".getBytes(), EncryptionConstants.ALLOW_PRINTING,EncryptionConstants.ENCRYPTION_AES_128);
+			String path = ReportUtils.getDocumentsDir()+ "/"+ reportName + "/"
+					+ fileService.generateFileEncryt(userName, profile, whereCondition, otherParameters, ExportType.PDF.getQualifier())
+					+ "." + ExportType.PDF.getQualifier();
+			PdfWriter pdfWriter = new PdfWriter(path ,writerProperties);
+			PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter);
+			pdfDocument.close();
+			System.out.println("---"+path);
+			return "pdf/preview?p=" + path;
+		}else {
+			return "pdf/preview?p=" + pdfPath;
+		}
 	}
 
 	/**

+ 2 - 0
report/src/main/java/com/uas/report/service/FileService.java

@@ -253,6 +253,8 @@ public interface FileService {
 	 */
 	public String generateFileName(String userName, String profile, String whereCondition, String otherParameters,
 			String exportFileType);
+	public String generateFileEncryt(String userName, String profile, String whereCondition, String otherParameters,
+								   String exportFileType);
 
 	/**
 	 * 获取给定的pdf文件的页数

+ 23 - 0
report/src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -668,6 +668,29 @@ public class FileServiceImpl implements FileService {
 		return String.valueOf(stringBuilder.toString().hashCode());
 	}
 
+	@Override
+	public String generateFileEncryt(String userName, String profile, String whereCondition, String otherParameters, String exportFileType) {
+		if (StringUtils.isEmpty(userName)) {
+			return null;
+		}
+		StringBuilder stringBuilder = new StringBuilder(userName);
+		if (!StringUtils.isEmpty(profile)) {
+			stringBuilder.append(profile);
+		}
+		if (!StringUtils.isEmpty(whereCondition)) {
+			stringBuilder.append(whereCondition);
+		}
+		if (!StringUtils.isEmpty(otherParameters)) {
+			stringBuilder.append(otherParameters);
+		}
+		stringBuilder.append("encrypt");
+		if (!StringUtils.isEmpty(exportFileType)) {
+			stringBuilder.append(exportFileType);
+		}
+		// 文件名: hashCode
+		return String.valueOf(stringBuilder.toString().hashCode());
+	}
+
 	@Override
 	public int getPageSize(String pdfFileAbsolutePath) throws IOException {
 		return new PdfReader(pdfFileAbsolutePath).getNumberOfPages();

+ 1 - 0
report/src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -38,6 +38,7 @@ import java.sql.*;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import com.itextpdf.kernel.pdf.*;
 
 /**
  * 报表打印