|
@@ -10,16 +10,27 @@ import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.Action;
|
|
|
|
|
|
import org.apache.commons.httpclient.HttpException;
|
|
import org.apache.commons.httpclient.HttpException;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+
|
|
import nc.bs.framework.common.NCLocator;
|
|
import nc.bs.framework.common.NCLocator;
|
|
import nc.bs.framework.common.RuntimeEnv;
|
|
import nc.bs.framework.common.RuntimeEnv;
|
|
import nc.bs.logging.Logger;
|
|
import nc.bs.logging.Logger;
|
|
import nc.funcnode.ui.action.AbstractNCAction;
|
|
import nc.funcnode.ui.action.AbstractNCAction;
|
|
|
|
+import nc.itf.bd.defdoc.IDefdocService;
|
|
import nc.itf.pu.service.IInvoiceOCRMaintain;
|
|
import nc.itf.pu.service.IInvoiceOCRMaintain;
|
|
import nc.itf.th.IThOcrService;
|
|
import nc.itf.th.IThOcrService;
|
|
|
|
+import nc.itf.uap.IUAPQueryBS;
|
|
|
|
+import nc.jdbc.framework.processor.ColumnProcessor;
|
|
import nc.ui.ml.NCLangRes;
|
|
import nc.ui.ml.NCLangRes;
|
|
import nc.ui.pub.beans.MessageDialog;
|
|
import nc.ui.pub.beans.MessageDialog;
|
|
import nc.ui.pub.bill.BillCardPanel;
|
|
import nc.ui.pub.bill.BillCardPanel;
|
|
|
|
+import nc.vo.bd.defdoc.DefdocVO;
|
|
import nc.vo.pub.BusinessException;
|
|
import nc.vo.pub.BusinessException;
|
|
|
|
+import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
public class ThOCRAction extends AbstractNCAction{
|
|
public class ThOCRAction extends AbstractNCAction{
|
|
@@ -47,35 +58,36 @@ public class ThOCRAction extends AbstractNCAction{
|
|
MessageDialog.showHintDlg(parentpanel, "提示","OCR识别!");
|
|
MessageDialog.showHintDlg(parentpanel, "提示","OCR识别!");
|
|
|
|
|
|
String vdef17 =(String) parentpanel.editor_.getBillCardPanel().getHeadItem("vdef17").getValueObject();//附件id
|
|
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()
|
|
String filepath = RuntimeEnv.getInstance().getNCHome()
|
|
+File.separator +"uploadfile" + File.separator+ vdef17; // 文件保存的路径
|
|
+File.separator +"uploadfile" + File.separator+ vdef17; // 文件保存的路径
|
|
|
|
|
|
List<String> filewjlis=getFileNames(filepath);
|
|
List<String> filewjlis=getFileNames(filepath);
|
|
|
|
|
|
- IThOcrService ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
|
|
|
|
|
|
+// IThOcrService ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
|
|
|
|
|
|
-// IInvoiceOCRMaintain iInvoiceOCRMaintain = (IInvoiceOCRMaintain) NCLocator.getInstance().lookup(IInvoiceOCRMaintain.class.getName());
|
|
|
|
|
|
+ IInvoiceOCRMaintain iInvoiceOCRMaintain = (IInvoiceOCRMaintain) NCLocator.getInstance().lookup(IInvoiceOCRMaintain.class.getName());
|
|
|
|
|
|
|
|
|
|
//获取token
|
|
//获取token
|
|
String token="";
|
|
String token="";
|
|
- try {
|
|
|
|
- token=ocrservice.getToken(appId,cid,secret,useid);
|
|
|
|
- } catch (HttpException e) {
|
|
|
|
- // Logger.error(e.getMessage(), e);
|
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
- ,"获取token:\n"+e.getMessage());
|
|
|
|
- return;
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
- ,"获取token:\n"+e.getMessage());
|
|
|
|
- return;
|
|
|
|
- } catch (BusinessException e) {
|
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
- ,"获取token:\n"+e.getMessage());
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+// try {
|
|
|
|
+// token=ocrservice.getToken(appId,cid,secret,useid);
|
|
|
|
+// } catch (HttpException e) {
|
|
|
|
+// // Logger.error(e.getMessage(), e);
|
|
|
|
+// MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
+// ,"获取token:\n"+e.getMessage());
|
|
|
|
+// return;
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
+// MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
+// ,"获取token:\n"+e.getMessage());
|
|
|
|
+// return;
|
|
|
|
+// } catch (BusinessException e) {
|
|
|
|
+// MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
+// ,"获取token:\n"+e.getMessage());
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
|
|
MessageDialog.showHintDlg(parentpanel, "提示","token:"+token);
|
|
MessageDialog.showHintDlg(parentpanel, "提示","token:"+token);
|
|
StringBuffer sb=new StringBuffer();
|
|
StringBuffer sb=new StringBuffer();
|
|
@@ -84,22 +96,78 @@ public class ThOCRAction extends AbstractNCAction{
|
|
for(int i=0;i<filewjlis.size();i++){
|
|
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="";
|
|
|
|
|
|
+// String idjson="";
|
|
|
|
+// try {
|
|
|
|
+// idjson=ocrservice.uploadInvoice(upurl,token, file);
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
+// ,"发票上传:\n"+e.getMessage());
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// sb.append(idjson).append("\n");
|
|
|
|
+//
|
|
|
|
+// //发票识别
|
|
|
|
+// String ocrinvoicejson=ocrservice.ocrIdentification(inverurl, token,idjson);
|
|
|
|
+// sb2.append(ocrinvoicejson).append("\n");
|
|
|
|
+
|
|
|
|
+ JSONObject json =iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
|
|
+
|
|
|
|
+ //add by pcy
|
|
|
|
+ // JSONObject json = JSONObject.fromObject(ocrinvoicejson);
|
|
|
|
+ String checkresult;
|
|
try {
|
|
try {
|
|
- idjson=ocrservice.uploadInvoice(upurl,token, file);
|
|
|
|
|
|
+ checkresult = checkJson(json);
|
|
|
|
+ if(checkresult != null){
|
|
|
|
+ ExceptionUtils.wrappBusinessException(checkresult);
|
|
|
|
+ }
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
|
- ,"发票上传:\n"+e.getMessage());
|
|
|
|
- return;
|
|
|
|
|
|
+ // TODO 自动生成的 catch 块
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ 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 code = info.getString("code");//发票代码
|
|
|
|
+ JSONArray flist = info.getJSONArray("flist");
|
|
|
|
+ String name = "";
|
|
|
|
+ for(int k = 0;k < flist.size();k++){
|
|
|
|
+ name = flist.getJSONObject(k).getString("name");//发票名称
|
|
|
|
+ }
|
|
|
|
+ String memo = info.getString("number");//发票号
|
|
|
|
+ JSONObject comm_info = info.getJSONObject("comm_info");
|
|
|
|
+ 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");//购买方公司名称
|
|
|
|
+ DefdocVO[] vos = new DefdocVO[1];
|
|
|
|
+ DefdocVO defvo = new DefdocVO();
|
|
|
|
+ //赋值
|
|
|
|
+ defvo.setAttributeValue("code", code);
|
|
|
|
+ defvo.setAttributeValue("name", name);
|
|
|
|
+ defvo.setAttributeValue("memo", memo);
|
|
|
|
+ defvo.setAttributeValue("mnecode", mnecode);
|
|
|
|
+ defvo.setAttributeValue("name2", name2);
|
|
|
|
+ defvo.setAttributeValue("name3", name3);
|
|
|
|
+ defvo.setAttributeValue("name4", name4);
|
|
|
|
+ defvo.setAttributeValue("name6", vdef17);
|
|
|
|
+ defvo.setAttributeValue("pk_defdoclist", QryOCRPk());
|
|
|
|
+ defvo.setAttributeValue("pk_group", pk_group);
|
|
|
|
+ defvo.setAttributeValue("pk_org", pk_org);
|
|
|
|
+ defvo.setAttributeValue("datatype", 1);
|
|
|
|
+ defvo.setAttributeValue("enablestate", 2);
|
|
|
|
+ vos[0] = defvo;
|
|
|
|
+ IDefdocService idefservice = NCLocator.getInstance().lookup(IDefdocService.class);
|
|
|
|
+ try {
|
|
|
|
+ idefservice.insertDefdocs(pk_org, vos);
|
|
|
|
+ } catch (BusinessException e) {
|
|
|
|
+ // TODO 自动生成的 catch 块
|
|
|
|
+ ExceptionUtils.wrappBusinessException(e.getMessage());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- sb.append(idjson).append("\n");
|
|
|
|
-
|
|
|
|
- //发票识别
|
|
|
|
- String ocrinvoicejson=ocrservice.ocrIdentification(inverurl, token,idjson);
|
|
|
|
- sb2.append(ocrinvoicejson).append("\n");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// JSONObject scanjb = iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
// JSONObject scanjb = iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
// sb3.append(scanjb.toString());
|
|
// sb3.append(scanjb.toString());
|
|
|
|
|
|
@@ -151,5 +219,39 @@ public class ThOCRAction extends AbstractNCAction{
|
|
}
|
|
}
|
|
return fileNames;
|
|
return fileNames;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private String checkJson(JSONObject json) throws Exception {
|
|
|
|
+
|
|
|
|
+ StringBuffer mags = new StringBuffer();
|
|
|
|
+ Boolean empty = true;
|
|
|
|
+
|
|
|
|
+ JSONObject oprepObjectBs = json.getJSONObject("data");
|
|
|
|
+
|
|
|
|
+ if (oprepObjectBs == null || oprepObjectBs.size() == 0) {
|
|
|
|
+ return "返回值不可为空!";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询自定义档案的pk
|
|
|
|
+ private String QryOCRPk(){
|
|
|
|
+ IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|