| 
					
				 | 
			
			
				@@ -2,6 +2,8 @@ package nckd.base.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.dataentity.entity.DynamicObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.fileservice.FileServiceFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import kd.bos.logging.Log; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import kd.bos.logging.LogFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.orm.query.QCP; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.orm.query.QFilter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import kd.bos.servicehelper.AttachmentDto; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -25,6 +27,7 @@ import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class FileSECUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final Log logger = LogFactory.getLog(FileSECUtils.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public static InputStream getFileTest() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -53,8 +56,6 @@ public class FileSECUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 检查文件是否加密的REST接口调用方法 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 该方法会从配置中获取检查URL,构造请求并发送文件流进行检测。 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -63,7 +64,7 @@ public class FileSECUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      *   0: 文件是明文(未加密状态) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      *  -1: 发生错误或未找到配置信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public static int checkFileIsEncryptionRest(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static int checkFileIsEncryptionRest(InputStream inputStream){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, String> mapentity = CommonHelperUtils.getCommonParams("SEC"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(mapentity == null){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -76,8 +77,8 @@ public class FileSECUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             HttpPost post = new HttpPost(url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             post.addHeader("method~name", "checkFileIsEncryptionRest");//文件加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            String filePath = "C:\\Users\\Administrator\\Desktop\\test.txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            InputStream inputStream = new FileInputStream(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //String filePath = "C:\\Users\\Administrator\\Desktop\\test.txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //InputStream inputStream = new FileInputStream(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AbstractHttpEntity entity = new InputStreamEntity(inputStream); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             post.setEntity(entity); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -100,14 +101,111 @@ public class FileSECUtils { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            System.out.println("ERR content1: " + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件 ERR content1: " + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } catch (Exception e1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             e1.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            System.out.println("ERR content2: " + e1.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件 ERR content2: " + e1.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static InputStream encodeFileForSEC(InputStream inputStream){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> mapentity = CommonHelperUtils.getCommonParams("SEC"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(mapentity == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String url = mapentity.get("url"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String filePath = "C:\\Users\\turbo_i49t4d3\\Downloads\\副本经理人周会数据.xlsx"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            File file = new File(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CloseableHttpClient httpclient = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            HttpPost post = new HttpPost(url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("method~name", "fileEncryptionRest"); //文件加密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("data~fileOffset", "0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("data~counSize", file.length()+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("data~secLevel", "10"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //String filePath = "C:\\Users\\Administrator\\Desktop\\test.txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            InputStream inputStream1 = new FileInputStream(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AbstractHttpEntity entity = new InputStreamEntity(inputStream1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.setEntity(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            httpclient = buildSSLCloseableHttpClient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CloseableHttpResponse response = httpclient.execute(post); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String result = response.getFirstHeader("data~returnFlag").getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 获取响应状态码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if("0".equals(result)){//1表示秘文 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                InputStream ins = response.getEntity().getContent(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.info("SEC附件加密成功: " + result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return ins; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.debug("SEC附件加密失败: " + result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件加密 ERR content1: " + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e1.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件加密 ERR content2: " + e1.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public static InputStream decodeFileForSEC(InputStream inputStream){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, String> mapentity = CommonHelperUtils.getCommonParams("SEC"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(mapentity == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String url = mapentity.get("url"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String filePath = "C:\\Users\\turbo_i49t4d3\\Downloads\\PMS项目预算编制维度-01.xlsx"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            File file = new File(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CloseableHttpClient httpclient = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            HttpPost post = new HttpPost(url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("method~name", "fileDecryptionRest"); //文件解密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("data~fileOffset", "0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.addHeader("data~counSize", file.length()+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            InputStream inputStream1 = new FileInputStream(filePath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            AbstractHttpEntity entity = new InputStreamEntity(inputStream1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            post.setEntity(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            httpclient = buildSSLCloseableHttpClient(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CloseableHttpResponse response = httpclient.execute(post); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String result = response.getFirstHeader("data~returnFlag").getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 获取响应状态码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if("0".equals(result)){//1表示秘文 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                InputStream ins = response.getEntity().getContent(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.info("SEC附件解密成功: " + result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return ins; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.info("SEC附件解密失败: " + result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件解密 ERR content1: " + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            e1.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("SEC附件解密 ERR content2: " + e1.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static CloseableHttpClient buildSSLCloseableHttpClient() throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @Override 
			 |