yaoyu 2 anni fa
parent
commit
f59ab9f3fe

+ 12 - 1
pu/pu/src/client/nc/pub/filesystem/newui/ThFileContentPanel.java

@@ -420,6 +420,8 @@ public class ThFileContentPanel extends JPanel {
 	
 	/**ocr识别*/
 	private ThOCRAction thocrAction = new ThOCRAction(ThFileContentPanel.this);//ocr识别
+	/**从发票云选择发票*/
+	private ThSelectAction thSelectAction = new ThSelectAction(ThFileContentPanel.this);
 	
 	
 	/** 引用文档ation */
@@ -439,6 +441,8 @@ public class ThFileContentPanel extends JPanel {
 	
 	private JButton btnocr;
 	
+	private JButton btnose;
+	
 	
 	/* 2010-10-24    以下按照uif2 画button 工具栏***/
 	ActionButton getupmenu(){
@@ -456,6 +460,13 @@ public class ThFileContentPanel extends JPanel {
 		return (ActionButton)btnocr;
 	}
 	
+	ActionButton getselectmenu(){
+		if(btnose==null){
+			btnose =new ActionButton(thSelectAction);
+		}
+		return (ActionButton)btnose;
+	}
+	
 	
 	
 	
@@ -609,7 +620,7 @@ public class ThFileContentPanel extends JPanel {
 			bar.setPreferredSize(new Dimension(0,30));
 			bar.addMenuComp(getupmenu());//上传按钮添加  zth
 			bar.addMenuComp(getocrmenu());//ocr按钮添加  zth
-			
+			bar.addMenuComp(getselectmenu());//发票获取  yy
 			
 //			bar.addMenuComp(getPastemenu());
 //			bar.addMenuComp(getuprefmenu());

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

@@ -110,15 +110,16 @@ public class ThOCRAction extends AbstractNCAction{
 			
 			sb.append(idjson).append("\n");
 			
-			//发票识别
-			String ocrinvoicejson=ocrservice.ocrIdentification(token,idjson);
-			sb2.append(ocrinvoicejson).append("\n");
 			
-            //识别数据保存数据库 add by pcy
-//			JSONObject json =iInvoiceOCRMaintain.startInvoiceOCR(file);
-			JSONObject json = JSONObject.parseObject(ocrinvoicejson);
+			JSONObject json = null;
 			String checkresult;
 			try {
+				//发票识别
+				String ocrinvoicejson=ocrservice.ocrIdentification(token,idjson);
+				sb2.append(ocrinvoicejson).append("\n");
+				 //识别数据保存数据库 add by pcy
+//				JSONObject json =iInvoiceOCRMaintain.startInvoiceOCR(file);
+				json = JSONObject.parseObject(ocrinvoicejson);
 				checkresult = checkJson(json);
 				if(checkresult != null){
 					MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
@@ -127,29 +128,28 @@ public class ThOCRAction extends AbstractNCAction{
 				}
 				
 			} catch (Exception e) {
-				// TODO 自动生成的 catch 块
-				e.printStackTrace();
+				MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+						,"ocr返回数据校验:\n"+e.getMessage());
 			}
 			JSONObject data = json.getJSONObject("data");
 			JSONArray infos = data.getJSONArray("infos");
 			for(int j = 0;j < infos.size();j++){
 				JSONObject info = infos.getJSONObject(j).getJSONObject("info");
 				String ret = infos.getJSONObject(j).getString("ret");
+				String name = filewjlis.get(i);
 				String memo = info.getString("number");//发票号
 				String code = info.getString("number");//发票代码
 				if(!"0".equals(ret)) {
 					String message = infos.getJSONObject(j).getString("message");
 					MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
-							,"ocr返回数据校验:\n"+"发票:"+code+":"+message);
-					//return;
+							,"ocr返回数据校验:\n"+"发票:"+name+":"+message);
+					return;
 				}
 				String fid = info.getString("fid");
 				String ext = info.getString("ext");
 				JSONObject extobj = JSONObject.parseObject(ext);
 				String trate = extobj.getString("trate");//税率
-				
 				JSONArray flist = info.getJSONArray("flist");
-				String name = filewjlis.get(i);
 				JSONObject comm_info = info.getJSONObject("comm_info");
 				JSONObject pro = comm_info.getJSONObject("pro");
 				String date = pro.getString("date");//发票日期
@@ -161,7 +161,7 @@ public class ThOCRAction extends AbstractNCAction{
 					ocrservice.InvoiceCheck(token,fid);
 				} catch (Exception e) {
 					MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
-							,"发票查验:\n"+"发票:"+code+":"+e.getMessage());
+							,"发票查验:\n"+"发票:"+name+":"+e.getMessage());
 				}
 				String amount = "";
 				String total = "";

+ 207 - 0
pu/pu/src/client/nc/pub/filesystem/newui/ThSelectAction.java

@@ -0,0 +1,207 @@
+package nc.pub.filesystem.newui;
+
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import nc.bs.framework.common.InvocationInfoProxy;
+import nc.bs.framework.common.NCLocator;
+import nc.funcnode.ui.action.AbstractNCAction;
+import nc.itf.bd.defdoc.IDefdocService;
+import nc.itf.th.IThOcrService;
+import nc.itf.uap.IUAPQueryBS;
+import nc.jdbc.framework.processor.BeanListProcessor;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.ui.ml.NCLangRes;
+import nc.ui.pub.beans.MessageDialog;
+import nc.vo.bd.defdoc.DefdocVO;
+import nc.vo.pub.BusinessException;
+
+public class ThSelectAction extends AbstractNCAction{
+
+	private ThFileContentPanel parentpanel;
+	private IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
+	
+	public ThSelectAction(ThFileContentPanel para){
+		parentpanel = para;
+		this.putValue(AbstractAction.NAME,"发票获取");
+		this.putValue(Action.SHORT_DESCRIPTION, "发票获取");
+	}
+
+	@Override
+	public void actionPerformed(ActionEvent actionevent) {
+		MessageDialog.showHintDlg(parentpanel, "提示","开始发票获取!");
+		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 billmaker = InvocationInfoProxy.getInstance().getUserId();
+		IThOcrService  ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
+		//获取token
+		String token="";
+		JSONObject json = null;
+		try {
+			 token=ocrservice.getToken(billmaker);
+		} catch (Exception e) {
+			MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+					,"获取token:\n"+e.getMessage());
+			return;
+		}
+		
+		try {
+			json = ocrservice.SelectORCInvoice(token);
+		} catch (Exception e) {
+			MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+					,"获取发票云发票:\n"+e.getMessage());
+		}
+			JSONObject data = json.getJSONObject("data");
+			JSONArray infos = data.getJSONArray("infos");
+			for(int j = 0;j < infos.size();j++){
+				JSONObject info = infos.getJSONObject(j);
+				String memo = info.getString("number");//发票号
+				String code = info.getString("number");//发票代码
+				String fid = info.getString("fid");
+				String ext = info.getString("ext");
+				JSONObject extobj = JSONObject.parseObject(ext);
+				String trate = extobj.getString("trate");//税率
+				JSONObject modify_info = info.getJSONObject("modify_info");
+				String name = modify_info.getString("fname");
+				JSONObject comm_info = info.getJSONObject("comm_info");
+				JSONObject pro = comm_info.getJSONObject("pro");
+				String date = pro.getString("date");//发票日期
+				String type = pro.getString("type");//发票类型
+				String cname = pro.getString("cname");//发票类型名称
+				JSONObject price = comm_info.getJSONObject("price");
+				String amount = "";
+				String total = "";
+				String dtax = "";
+				//专票带税额,不是专票无税金额=价税合计
+				if(type.equals("1")||type.equals("28")||type.equals("32")){
+					amount = price.getString("amount");//无税金额
+					total = price.getString("total");//价税合计
+					dtax = price.getString("dtax");//可抵扣税额
+				}
+				else{
+					amount = price.getString("total");//无税金额
+					total = amount;//价税合计
+					dtax = "0";//可抵扣税额
+					trate = "0";//非专票税率也为0
+				}
+				JSONObject buyer = comm_info.getJSONObject("buyer");
+				String mnecode = buyer.getString("tcode");//购买方纳税人识别号
+				String name2 = buyer.getString("company");//购买方公司名称
+				JSONObject payer = comm_info.getJSONObject("payer");
+				String name3 = payer.getString("tcode");//销售方纳税人识别号
+				String name4 = payer.getString("company");//购买方公司名称
+				
+				IDefdocService idefservice = NCLocator.getInstance().lookup(IDefdocService.class);
+				
+				DefdocVO[] updatevos=QryDefdocvoInfo(code);
+				
+				if(updatevos.length>0){
+					//自定义档案存在这个编码,走修改
+					DefdocVO defvo =updatevos[0];
+					//赋值
+					defvo.setAttributeValue("name", memo);
+					defvo.setAttributeValue("memo", name);
+					defvo.setAttributeValue("mnecode", mnecode);
+					defvo.setAttributeValue("name2", name2);
+					defvo.setAttributeValue("name3", name3);
+					defvo.setAttributeValue("name4", name4);
+					defvo.setAttributeValue("name5", fid);
+					defvo.setAttributeValue("name6", vdef17);
+					defvo.setAttributeValue("shortname", amount);
+					defvo.setAttributeValue("shortname2", total);
+					defvo.setAttributeValue("shortname3", dtax);
+					defvo.setAttributeValue("shortname4", date);
+					defvo.setAttributeValue("shortname5", cname);
+					defvo.setAttributeValue("shortname6", trate);
+					defvo.setAttributeValue("enablestate", 2);
+					try {
+						idefservice.updateDefdocs(pk_group,updatevos);
+					} catch (BusinessException e1) {
+						MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+								,"修改自定义档案数据:\n"+e1.getMessage());
+						return;
+					}
+				}else{
+					DefdocVO[] vos = new DefdocVO[1];
+					DefdocVO defvo = new DefdocVO();
+					//赋值
+					defvo.setAttributeValue("code", code);
+					defvo.setAttributeValue("name", memo);
+					defvo.setAttributeValue("memo", name );
+					defvo.setAttributeValue("mnecode", mnecode);
+					defvo.setAttributeValue("name2", name2);
+					defvo.setAttributeValue("name3", name3);
+					defvo.setAttributeValue("name4", name4);
+					defvo.setAttributeValue("name5", fid);
+					defvo.setAttributeValue("name6", vdef17);
+					defvo.setAttributeValue("pk_defdoclist", QryOCRPk());
+					defvo.setAttributeValue("pk_group", pk_group);
+					defvo.setAttributeValue("pk_org", pk_group);
+					defvo.setAttributeValue("datatype", 1);
+					defvo.setAttributeValue("enablestate", 2);
+					defvo.setAttributeValue("shortname", amount);
+					defvo.setAttributeValue("shortname2", total);
+					defvo.setAttributeValue("shortname3", dtax);
+					defvo.setAttributeValue("shortname4", date);
+					defvo.setAttributeValue("shortname5", cname);
+					defvo.setAttributeValue("shortname6", trate);
+					vos[0] = defvo;
+					try {
+						idefservice.insertDefdocs(pk_group, vos);
+					} catch (BusinessException e) {
+						// TODO 自动生成的 catch 块
+						MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
+									,"保存自定义档案数据:\n"+e.getMessage());
+						return;
+					}
+					
+					MessageDialog.showHintDlg(parentpanel, "提示","获取成功!");
+				}
+			}
+	}
+	
+    @SuppressWarnings("unchecked")
+	private DefdocVO[]  QryDefdocvoInfo(String code){
+        	String sql = "select * from  bd_defdoc where  nvl(dr, 0) = 0 and pk_defdoclist="
+        			+ "(select pk_defdoclist from bd_defdoclist where code='OCRTHNC' and nvl(dr,0)=0) and code='" + code + "' ";
+        	ArrayList<Object> arrayvos=null;
+        	try {
+				arrayvos=(ArrayList<Object>) iuap.executeQuery(sql, new BeanListProcessor(DefdocVO.class));
+			} catch (BusinessException e) {
+				// TODO 自动生成的 catch 块
+				e.printStackTrace();
+			}
+        	
+        	if (arrayvos==null||arrayvos.size()==0) {
+      			return new DefdocVO[0];
+      		}else {
+      			return arrayvos.toArray(new DefdocVO[0]);
+      		}
+        	
+        } 
+    
+    //查询自定义档案的pk
+    private String QryOCRPk(){
+    	String sql = "select pk_defdoclist from bd_defdoclist where code='OCRTHNC' and nvl(dr,0)=0";
+    	Object object = null;
+		try {
+			object = iuap.executeQuery(sql, new ColumnProcessor());
+		} catch (BusinessException e) {
+			// TODO 自动生成的 catch 块
+			e.printStackTrace();
+		}
+		if (object==null) {
+			return null;
+		}else {
+			return object.toString();
+		}
+    }
+
+}

+ 4 - 3
pu/pu/src/private/nc/bs/ic/base/InvoiceAfterCheckEvent.java

@@ -84,10 +84,11 @@ public class InvoiceAfterCheckEvent implements IBusinessListener{
 						sql.append(" WHERE");
 						sql.append(" ic_purchasein_h.cgeneralhid = '"+csourceid+"'");
 						listMap = (List<Map<Object, Object>>) bs.executeQuery(sql.toString(), new MapListProcessor());
-					}else {
-						//只有来源是采购订单或者采购入库单的才进行保存校验
-						return;
 					}
+//					else {
+//						//只有来源是采购订单或者采购入库单的才进行保存校验
+//						return;
+//					}
 						for (InvoiceItemVO invoiceItemVO : arrInvoiceItemVO) {
 						//没传发票不比较日期、抬头、纳税人识别号
 						if(invoiceItemVO.getVbdef20() != null && !"".equals(invoiceItemVO.getVbdef20())) {

+ 38 - 7
pu/pu/src/private/nc/impl/th/ThOcrServiceImpl.java

@@ -68,10 +68,14 @@ public class ThOcrServiceImpl implements IThOcrService{
 	private static String cid="1438490101547343873";
 	private String upurl="https://up.mypiaojia.com/api/invoiceApi/file/uploadFileSpilit";
 	private String inverurl="https://api.mypiaojia.com/api/invoiceApi/invoice/ocr";
+	//发票验伪地址
 	private String person_local_valid = "https://api.mypiaojia.com/api/invoiceApi/invoice/person_local_valid";
 	//发票锁定地址
 	private String ec_comm = "https://api.mypiaojia.com/api/invoiceApi/invoice/ec_comm";
+	//获取token地址
 	private String buildToken="https://api.mypiaojia.com/api/invoiceApi/token/buildToken";
+	//获取发票云发票地址
+	private String sync_rt = "https://api.mypiaojia.com/api/invoiceApi/invoice/sync_rt";
 	public String[] insert(ArrayList<?> arrlist) throws BusinessException {
 		return this.IVOPersistence.insertVOList(arrlist);
 	}
@@ -89,7 +93,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 		if(Toolkits.isEmpty(userToken)){
 			
 			//调用OCR接口
-			userToken=getOcrToken(appId,cid,secret,billmaker);
+			userToken=getOcrToken(billmaker);
 			//保存到redis,设置失效时间36000秒
 			RedisTokenManager.setTokenTTL(billmaker,36000, userToken);
 		}
@@ -128,9 +132,10 @@ public class ThOcrServiceImpl implements IThOcrService{
 
 	/**
 	 * OCR识别
+	 * @throws Exception 
 	 */
 	@Override
-	public String ocrIdentification(String token,String data) {
+	public String ocrIdentification(String token,String data) throws Exception {
 		// TODO 自动生成的方法存根
 		 NcLog.info("=======发票OCR识别开始=======");
 		 JSONObject jsondata = JSONObject.parseObject(data);
@@ -181,7 +186,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 	
 	
 
-	public String getOcrToken(String appId,String cid,String secret,String userid)  throws Exception{
+	public String getOcrToken(String userid)  throws Exception{
     	HttpClient httpClient = new HttpClient();
     	httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
         httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000);
@@ -197,7 +202,8 @@ public class ThOcrServiceImpl implements IThOcrService{
         map.put("cid", cid);
         String s1 = JSONObject.toJSONString(map);
         String s2 = s1 + "&time=" + l + "&secret="+secret;
-        String newMd5 = DigestUtils.md5Hex(s2);
+        byte[] requestBodyBytes = s2.getBytes("UTF-8");
+        String newMd5 = DigestUtils.md5Hex(requestBodyBytes);
         String s4 = s1 + "&time=" + l + "&md5=" + newMd5;
         RequestEntity entity = new StringRequestEntity (s4 ,"application/json" ,"UTF-8");
         postMethod.setRequestEntity(entity);
@@ -283,7 +289,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 
 
 
-		 public  String doPost(String pathUrl, String token,String data){
+		 public  String doPost(String pathUrl, String token,String data) throws Exception{
 			OutputStreamWriter out = null;
 	        BufferedReader br = null;
 	        String result = "";
@@ -359,7 +365,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 	            //断开连接,disconnect是在底层tcp socket链接空闲时才切断,如果正在被其他线程使用就不切断。
 	            conn.disconnect();
 	        }catch (Exception e) {
-	            e.printStackTrace();
+	        	throw new Exception(e);
 	        }finally {
 	            try {
 	                if (out != null){
@@ -369,7 +375,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 	                    br.close();
 	                }
 	            } catch (IOException e) {
-	                e.printStackTrace();
+	            	throw new Exception(e);
 	            }
 	        } 
 			return result;
@@ -691,6 +697,7 @@ public class ThOcrServiceImpl implements IThOcrService{
 		public void UpdateInvoiceStatus(String status, InvoiceVO[] vos) throws Exception {
 			NcLog.info("=======锁定发票、修改开始=======");
 			for (InvoiceVO invoiceVO : vos) {
+				int vostatus = invoiceVO.getParentVO().getStatus();
 				Map<String,String> oamap = QueryOAUserid(invoiceVO.getParent().getAttributeValue("billmaker").toString());
 				//审批结果Y2代表通过 N0代表不通过 R0代表驳回T1报销中
 				InvoiceItemVO[] arrInvoiceItemVO = (InvoiceItemVO[]) invoiceVO.getChildren(InvoiceItemVO.class);
@@ -781,6 +788,28 @@ public class ThOcrServiceImpl implements IThOcrService{
 		}
 		
 		
+		/**
+		 * 从发票云获取发票
+		 */
+		@Override
+		public JSONObject SelectORCInvoice(String token) throws Exception{
+			NcLog.info("=======发票云获取发票开始=======");
+			JSONObject jsonobject = new JSONObject();
+			jsonobject.put("tag", "1");
+			jsonobject.put("sreim", "0");
+			jsonobject.put("mask", "281474976710655");
+			jsonobject.put("mext", "4031");
+			jsonobject.put("page_size", "9999");
+			jsonobject.put("start_pos", "0");
+			JSONArray sorts = new JSONArray();
+			jsonobject.put("sorts", sorts);
+			String json = doPost(sync_rt,token,jsonobject.toString());
+			NcLog.info("发票云获取发票返回json:"+json.toString());
+	        return JSONObject.parseObject(json);
+	        
+		}
+		
+		
 		private Map<String,String> QueryOAUserid(String cuserid) throws Exception {
 			StringBuffer sql = new StringBuffer();
 			sql.append("SELECT");
@@ -797,4 +826,6 @@ public class ThOcrServiceImpl implements IThOcrService{
 			}
 			return map;
 		}
+		
+		
 }

+ 12 - 2
pu/pu/src/public/nc/itf/th/IThOcrService.java

@@ -9,6 +9,8 @@ import java.util.List;
 
 import org.apache.commons.httpclient.HttpException;
 
+import com.alibaba.fastjson.JSONObject;
+
 import nc.vo.bd.defdoc.DefdocVO;
 import nc.vo.pu.m25.entity.InvoiceVO;
 import nc.vo.pub.BusinessException;
@@ -36,7 +38,7 @@ public interface IThOcrService {
 	/**
 	 * OCR识别
 	 */
-	public String ocrIdentification(String token,String data);
+	public String ocrIdentification(String token,String data) throws Exception;
 	
 	
 	/**
@@ -85,7 +87,15 @@ public interface IThOcrService {
 	 */
 	public void UpdateInvoiceStatus(String status,InvoiceVO[] vos) throws Exception;
 	
-	
+	/**
+	 * 发票验伪
+	 */
 	public void InvoiceCheck(String token,String fid) throws Exception;
 	
+	
+	/**
+	 * 从发票云获取发票
+	 */
+	public JSONObject SelectORCInvoice(String token) throws Exception;
+	
 }