|
@@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Enumeration;
|
|
|
import java.util.List;
|
|
|
|
|
|
import javax.swing.AbstractAction;
|
|
@@ -16,20 +17,16 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
import nc.bs.framework.common.NCLocator;
|
|
|
import nc.bs.framework.common.RuntimeEnv;
|
|
|
-import nc.bs.logging.Logger;
|
|
|
import nc.funcnode.ui.action.AbstractNCAction;
|
|
|
import nc.itf.bd.defdoc.IDefdocService;
|
|
|
-import nc.itf.pu.service.IInvoiceOCRMaintain;
|
|
|
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.ui.pub.bill.BillCardPanel;
|
|
|
import nc.vo.bd.defdoc.DefdocVO;
|
|
|
import nc.vo.pub.BusinessException;
|
|
|
-import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -45,7 +42,7 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
private static final Long cid=773676128725336064l;
|
|
|
private static final String secret="6726dea9883f4f6bb2725ac8750d01de";
|
|
|
private static final String useid="2108";
|
|
|
-
|
|
|
+ private IUAPQueryBS iuap= (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
|
|
|
private ThFileContentPanel parentpanel ;
|
|
|
public ThOCRAction(ThFileContentPanel para){
|
|
|
parentpanel = para;
|
|
@@ -55,7 +52,7 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent actionevent) {
|
|
|
- MessageDialog.showHintDlg(parentpanel, "提示","OCR识别!");
|
|
|
+ MessageDialog.showHintDlg(parentpanel, "提示","开发OCR识别!");
|
|
|
|
|
|
String vdef17 =(String) parentpanel.editor_.getBillCardPanel().getHeadItem("vdef17").getValueObject();//附件id
|
|
|
String pk_org = (String) parentpanel.editor_.getBillCardPanel().getHeadItem("pk_org").getValueObject();
|
|
@@ -65,29 +62,35 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
|
|
|
List<String> filewjlis=getFileNames(filepath);
|
|
|
|
|
|
-// IThOcrService ocrservice=(IThOcrService) NCLocator.getInstance().lookup(IThOcrService.class.getName());
|
|
|
+ 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());
|
|
|
+// IInvoiceOCRMaintain iInvoiceOCRMaintain = (IInvoiceOCRMaintain) NCLocator.getInstance().lookup(IInvoiceOCRMaintain.class.getName());
|
|
|
|
|
|
|
|
|
//获取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);
|
|
|
StringBuffer sb=new StringBuffer();
|
|
@@ -96,30 +99,31 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
for(int i=0;i<filewjlis.size();i++){
|
|
|
File file=new File(filepath+File.separator+filewjlis.get(i));
|
|
|
//发票上传
|
|
|
-// 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");
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- JSONObject json =iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
|
+ sb.append(idjson).append("\n");
|
|
|
|
|
|
- //add by pcy
|
|
|
- // JSONObject json = JSONObject.fromObject(ocrinvoicejson);
|
|
|
+ //发票识别
|
|
|
+ String ocrinvoicejson=ocrservice.ocrIdentification(inverurl, token,idjson);
|
|
|
+ sb2.append(ocrinvoicejson).append("\n");
|
|
|
+
|
|
|
+ //识别数据保存数据库 add by pcy
|
|
|
+// JSONObject json =iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
|
+ JSONObject json = JSONObject.parseObject(ocrinvoicejson);
|
|
|
String checkresult;
|
|
|
try {
|
|
|
checkresult = checkJson(json);
|
|
|
if(checkresult != null){
|
|
|
- ExceptionUtils.wrappBusinessException(checkresult);
|
|
|
+ MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
+ ,"保存自定义档案数据:\n"+checkresult);
|
|
|
+ return;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
// TODO 自动生成的 catch 块
|
|
@@ -133,66 +137,82 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
JSONArray flist = info.getJSONArray("flist");
|
|
|
String name = "";
|
|
|
for(int k = 0;k < flist.size();k++){
|
|
|
- name = flist.getJSONObject(k).getString("name");//发票名称
|
|
|
+ name = flist.getJSONObject(k).getString("name").replace("\"", "");//发票名称
|
|
|
}
|
|
|
String memo = info.getString("number");//发票号
|
|
|
JSONObject comm_info = info.getJSONObject("comm_info");
|
|
|
- JSONObject price = comm_info.getJSONObject("price");
|
|
|
- String amount = price.getString("amount");//无税金额
|
|
|
- String total = price.getString("total");//价税合计
|
|
|
- String dtax = price.getString("dtax");//可抵扣税额
|
|
|
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_group);
|
|
|
- defvo.setAttributeValue("datatype", 1);
|
|
|
- defvo.setAttributeValue("enablestate", 2);
|
|
|
- defvo.setAttributeValue("shortname", amount);
|
|
|
- defvo.setAttributeValue("shortname2", total);
|
|
|
- defvo.setAttributeValue("shortname3", dtax);
|
|
|
- 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());
|
|
|
+
|
|
|
+ DefdocVO[] updatevos=QryDefdocvoInfo(code);
|
|
|
+
|
|
|
+ if(updatevos.length>0){
|
|
|
+ //自定义档案存在这个编码,走修改
|
|
|
+ DefdocVO defvo =updatevos[0];
|
|
|
+ //赋值
|
|
|
+ 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);
|
|
|
+ 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", 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("pk_org", pk_group);
|
|
|
+ defvo.setAttributeValue("datatype", 1);
|
|
|
+ defvo.setAttributeValue("enablestate", 2);
|
|
|
+ vos[0] = defvo;
|
|
|
+ try {
|
|
|
+ // idefservice.insertDefdocs(pk_org, vos);
|
|
|
+ idefservice.insertDefdocs(pk_group, vos);
|
|
|
+ } catch (BusinessException e) {
|
|
|
+ // TODO 自动生成的 catch 块
|
|
|
+ //ExceptionUtils.wrappBusinessException(e.getMessage());
|
|
|
+ MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
+ ,"保存自定义档案数据:\n"+e.getMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-// JSONObject scanjb = iInvoiceOCRMaintain.startInvoiceOCR(file);
|
|
|
-// sb3.append(scanjb.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, "提示","识别成功!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 得到文件名称
|
|
|
*
|
|
@@ -227,38 +247,58 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ 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(){
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @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) {
|
|
|
+ return new DefdocVO[0];
|
|
|
+ }else {
|
|
|
+ return arrayvos.toArray(new DefdocVO[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|