瀏覽代碼

发票保存修改

zthwr 2 年之前
父節點
當前提交
0ecb6c4fe0

+ 22 - 19
pu/pu/src/client/nc/pub/filesystem/newui/ThOCRAction.java

@@ -57,22 +57,24 @@ public class ThOCRAction extends AbstractNCAction{
 		String vdef17 =(String) parentpanel.editor_.getBillCardPanel().getHeadItem("vdef17").getValueObject();//附件id
 		String pk_org = (String) parentpanel.editor_.getBillCardPanel().getHeadItem("pk_org").getValueObject();
 		String pk_group = (String) parentpanel.editor_.getBillCardPanel().getHeadItem("pk_group").getValueObject();
-		String filepath =  RuntimeEnv.getInstance().getNCHome()
-			      +File.separator +"uploadfile" + File.separator+ vdef17; // 文件保存的路径
-		
-		List<String> filewjlis=getFileNames(filepath);
-		
-		 if(null==filewjlis||filewjlis.size()==0){
-	        	MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
-						,"请先上传发票,再进行OCR识别!");
-				return;
-	        }
 		
 		IThOcrService  ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
 		
 //		IInvoiceOCRMaintain iInvoiceOCRMaintain = (IInvoiceOCRMaintain) NCLocator.getInstance().lookup(IInvoiceOCRMaintain.class.getName());
 		
+//		String filepath =  RuntimeEnv.getInstance().getNCHome()
+//			      +File.separator +"uploadfile" + File.separator+ vdef17; // 文件保存的路径
+//		List<String> filewjlis=getFileNames(filepath);
 		
+		List<String> filewjlis=ocrservice.getInvoiceInfo(vdef17);//获取"+vdef17+"文件夹下所有发票名
+		
+		 if(null==filewjlis||filewjlis.size()==0){
+	        	MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+						,"请先上传发票,再进行OCR识别!");
+				return;
+	      }
+		 
+		 
 		//获取token
 		String token="";
 		try {
@@ -92,16 +94,17 @@ public class ThOCRAction extends AbstractNCAction{
 			return;
 		}
 		
-		MessageDialog.showHintDlg(parentpanel, "提示","token:"+token);
+//		MessageDialog.showHintDlg(parentpanel, "提示","token:"+token);
 		StringBuffer sb=new StringBuffer();
 		StringBuffer sb2=new StringBuffer();
 		StringBuffer sb3=new StringBuffer();
 		for(int i=0;i<filewjlis.size();i++){
-			File file=new File(filepath+File.separator+filewjlis.get(i));
+		//	File file=new File(filepath+File.separator+filewjlis.get(i));
 			//发票上传
 			String idjson="";
 			try {
-				idjson=ocrservice.uploadInvoice(upurl,token, file);
+//				idjson=ocrservice.uploadInvoice(upurl,token, file);
+				idjson=ocrservice.uploadInvoice(upurl,token, vdef17,filewjlis.get(i));
 			} catch (Exception e) {
 				MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
 						,"发票上传:\n"+e.getMessage());
@@ -247,9 +250,9 @@ public class ThOCRAction extends AbstractNCAction{
 			
 		}
 		
-		MessageDialog.showHintDlg(parentpanel, "提示","发票上传json:\n"+sb.toString());
+/*		MessageDialog.showHintDlg(parentpanel, "提示","发票上传json:\n"+sb.toString());
 		MessageDialog.showHintDlg(parentpanel, "提示","ocr识别json:\n"+sb2.toString());
-//		MessageDialog.showHintDlg(parentpanel, "提示","ocr识别YY:\n"+sb3.toString());
+//		MessageDialog.showHintDlg(parentpanel, "提示","ocr识别YY:\n"+sb3.toString());*/
 		MessageDialog.showHintDlg(parentpanel, "提示","识别成功!");
 	}
 	
@@ -260,14 +263,14 @@ public class ThOCRAction extends AbstractNCAction{
      * @param path 路径
      * @return {@link List}<{@link String}>
      */
-    private  List<String> getFileNames(String path) {
+   /* private  List<String> getFileNames(String path) {
         File file = new File(path);
         if (!file.exists()) {
             return null;
         }
         List<String> fileNames = new ArrayList<String>();
         return getFileNames(file, fileNames);
-    }
+    }*/
 
 /**
      * 得到文件名称
@@ -276,7 +279,7 @@ public class ThOCRAction extends AbstractNCAction{
      * @param fileNames 文件名
      * @return {@link List}<{@link String}>
      */
-    private  List<String> getFileNames(File file, List<String> fileNames) {
+/*    private  List<String> getFileNames(File file, List<String> fileNames) {
         File[] files = file.listFiles();
         for (File f : files) {
             if (f.isDirectory()) {
@@ -286,7 +289,7 @@ public class ThOCRAction extends AbstractNCAction{
             }
         }
         return fileNames;
-    }
+    }*/
     
     private String checkJson(JSONObject json) throws Exception {
 		

+ 25 - 6
pu/pu/src/client/nc/pub/filesystem/newui/ThUploadAction.java

@@ -1,10 +1,12 @@
 package nc.pub.filesystem.newui;
 
 import java.awt.event.ActionEvent;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
-
+import nc.itf.th.IThOcrService;
 import nc.bs.framework.common.RuntimeEnv;
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -20,6 +22,7 @@ import nc.bs.logging.Logger;
 import nc.desktop.ui.WorkbenchEnvironment;
 import nc.funcnode.ui.action.AbstractNCAction;
 import nc.itf.pu.service.IInvoiceOCRMaintain;
+import nc.log.NcLog;
 import nc.ui.ml.NCLangRes;
 import nc.ui.pub.beans.MessageDialog;
 import nc.ui.pub.bill.BillCardPanel;
@@ -74,7 +77,7 @@ public class ThUploadAction extends AbstractNCAction {
 			String creator = WorkbenchEnvironment.getInstance().getLoginUser().getCuserid();
 			FileInputStream input = null;
 			
-			
+			IThOcrService  ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
 				
 			
 			try {
@@ -91,11 +94,15 @@ public class ThUploadAction extends AbstractNCAction {
 						continue ;
 					}
 					input = new FileInputStream(file);
-					
-					/***********************发票图片保存到文件夹 home/uploadfile/vdef17  ****************************/
+//					String absolutePath = file.getAbsolutePath();
+//					MessageDialog.showHintDlg(parentpanel, "提示","absolutePath:"+absolutePath);
+//					String pathww = file.getPath();
+//					MessageDialog.showHintDlg(parentpanel, "提示","pathww:"+pathww);
+					/***********************发票图片保存到文件夹 home/uploadfile/"+vdef17+"  ****************************/
 					BillCardPanel cpanel=parentpanel.editor_.getBillCardPanel();
 					String vdef17 = (String) cpanel.getHeadItem("vdef17").getValueObject();
-					String filepath =  RuntimeEnv.getInstance().getNCHome()
+					
+					/*String filepath =  ocrservice.getNCHomePath()
 						      +File.separator +"uploadfile" + File.separator+ vdef17; // 文件保存的路径
 					File folder = new File(filepath);
 					if(!folder.exists() && !folder.isDirectory()){
@@ -110,7 +117,19 @@ public class ThUploadAction extends AbstractNCAction {
 			            outputStream.write(buffer, 0, len);
 			        }
 			        outputStream.close();
-			        fis.close();
+			        fis.close();*/
+					
+					//转为byte传输
+					BufferedInputStream bis=new BufferedInputStream(input);
+                    ByteArrayOutputStream bos=new ByteArrayOutputStream();
+					int date=-1;
+					while ((date = bis.read()) != -1) {
+						bos.write(date);
+			        }
+					byte[] 	bytes=	bos.toByteArray();
+					
+					String patch=ocrservice.saveUploadFile(vdef17, fileName, bytes);//保存发票到home里
+			//		MessageDialog.showHintDlg(parentpanel, "提示","保存发票路径:"+patch);
 					/***************************************end**********************************************/