|
@@ -62,12 +62,6 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
String billmaker = InvocationInfoProxy.getInstance().getUserId();
|
|
|
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){
|
|
@@ -82,38 +76,25 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
try {
|
|
|
token=ocrservice.getToken(billmaker);
|
|
|
} catch (Exception 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();
|
|
|
StringBuffer sb2=new StringBuffer();
|
|
|
- StringBuffer sb3=new StringBuffer();
|
|
|
for(int i=0;i<filewjlis.size();i++){
|
|
|
NCFileVO oldvo = (NCFileVO) parentpanel.getfiletablemodel()
|
|
|
.getVO(i);
|
|
|
NCFileVO newvo = oldvo.clone();
|
|
|
//已识别的发票不需要再次查询
|
|
|
String filedesc = newvo.getFiledesc();
|
|
|
- if(filedesc != null && "OCR已识别".equals(filedesc)) {
|
|
|
+ if(filedesc != null) {
|
|
|
continue;
|
|
|
}
|
|
|
- // File file=new File(filepath+File.separator+filewjlis.get(i));
|
|
|
//发票上传
|
|
|
String idjson="";
|
|
|
try {
|
|
|
-// idjson=ocrservice.uploadInvoice(upurl,token, file);
|
|
|
idjson=ocrservice.uploadInvoice(token, vdef17,newvo.getName());
|
|
|
} catch (Exception e) {
|
|
|
MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
@@ -131,7 +112,6 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
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){
|
|
@@ -149,10 +129,10 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
JSONObject data = json.getJSONObject("data");
|
|
|
JSONArray infos = data.getJSONArray("infos");
|
|
|
for(int j = 0;j < infos.size();j++){
|
|
|
+ String message = "OCR已识别";//发票识别标识
|
|
|
JSONObject info = infos.getJSONObject(j).getJSONObject("info");
|
|
|
String ret = infos.getJSONObject(j).getString("ret");
|
|
|
String is_valid = infos.getJSONObject(j).getString("is_valid");
|
|
|
-// String name = filewjlis.get(i);
|
|
|
String name =newvo.getName();
|
|
|
String memo = info.getString("number");//发票号
|
|
|
String code = info.getString("fid");
|
|
@@ -165,153 +145,21 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
if(memo == null || "".equals(memo)) {
|
|
|
memo = "0";
|
|
|
}
|
|
|
- if(!"0".equals(ret)) {
|
|
|
- String message = infos.getJSONObject(j).getString("message");
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
- ,"ocr返回数据校验:\n"+"发票:"+name+":"+message);
|
|
|
- return;
|
|
|
+ if(!"0".equals(ret)) {
|
|
|
+ message = infos.getJSONObject(j).getString("message");
|
|
|
}
|
|
|
- String ext = info.getString("ext");
|
|
|
- JSONObject extobj = JSONObject.parseObject(ext);
|
|
|
- String trate = extobj.getString("trate");//税率
|
|
|
- JSONArray flist = info.getJSONArray("flist");
|
|
|
- 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");//发票类型名称
|
|
|
- //String kind = pro.getString("kind");//开票内容
|
|
|
- String kind = extobj.getString("content");
|
|
|
- JSONObject price = comm_info.getJSONObject("price");
|
|
|
//发票识别之后进行发票查验
|
|
|
//是否需要查验 0不需要 1需要
|
|
|
- if("1".equals(is_valid)) {
|
|
|
+ if("OCR已识别".equals(message) && "1".equals(is_valid)) {
|
|
|
try {
|
|
|
ocrservice.InvoiceCheck(token,fid);
|
|
|
} catch (Exception e) {
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
- ,"发票查验:\n"+"发票:"+name+":"+e.getMessage());
|
|
|
- return;
|
|
|
+ message = e.getMessage();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String amount = "";
|
|
|
- String total = price.getString("total");//价税合计
|
|
|
- String dtax = price.getString("dtax");//可抵扣税额
|
|
|
- String ttax = "";
|
|
|
-
|
|
|
- //专票带税额,不是专票无税金额=价税合计
|
|
|
-// 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
|
|
|
-// }
|
|
|
-
|
|
|
- //如有可抵扣税额,无税金额等于无税金额,税额等于可抵扣税额,税率等于税率
|
|
|
- //如没有可抵扣税额,无税金额等于无税金额+税额,税额等于0,税率等于0
|
|
|
- if("0".equals(dtax)) {
|
|
|
- //无税金额+税额 = 价税合计
|
|
|
- amount = total;
|
|
|
- ttax = "0";//税额
|
|
|
- trate = "0";//税率
|
|
|
- }else {
|
|
|
- amount = price.getString("amount");//无税金额
|
|
|
- ttax = extobj.getString("ttax");//税额
|
|
|
- }
|
|
|
- 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", ttax);
|
|
|
-// defvo.setAttributeValue("pid", date);
|
|
|
-// defvo.setAttributeValue("shortname5", cname);
|
|
|
-// defvo.setAttributeValue("shortname6", trate);
|
|
|
-// defvo.setAttributeValue("enablestate", 2);
|
|
|
-// defvo.setAttributeValue("innercode", "0");
|
|
|
-// defvo.setAttributeValue("shortname4", kind);
|
|
|
-// defvo.setAttributeValue("modifier", codenumber);
|
|
|
-//
|
|
|
-// 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", ttax);
|
|
|
- defvo.setAttributeValue("pid", date);
|
|
|
- defvo.setAttributeValue("shortname5", cname);
|
|
|
- defvo.setAttributeValue("shortname6", trate);
|
|
|
- defvo.setAttributeValue("dataoriginflag", 0);
|
|
|
- defvo.setAttributeValue("shortname4", kind);
|
|
|
- defvo.setAttributeValue("innercode", codenumber);
|
|
|
- defvo.setAttributeValue("modifier", dtax);
|
|
|
- vos[0] = defvo;
|
|
|
- try {
|
|
|
- idefservice.insertDefdocs(pk_group, vos);
|
|
|
-
|
|
|
- Map<String,String> map = new HashMap<String,String>();
|
|
|
- map.put("KYHSJE", "~");
|
|
|
- map.put("KYWSJE", "~");
|
|
|
- map.put("JYSE", "~");
|
|
|
- map.put("FPXZ", url);
|
|
|
- map.put("VDEF17",vdef17);
|
|
|
- map.put("NUMBERID",code);
|
|
|
- ocrservice.addORC(map);
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO 自动生成的 catch 块
|
|
|
- MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
- ,"保存自定义档案数据:\n"+e.getMessage());
|
|
|
- return;
|
|
|
- }
|
|
|
- //}
|
|
|
- newvo.setFiledesc("OCR已识别");
|
|
|
+ //添加描述
|
|
|
+ newvo.setFiledesc(message);
|
|
|
// 修改人
|
|
|
newvo.setModifier(InvocationInfoProxy.getInstance()
|
|
|
.getUserId());
|
|
@@ -327,7 +175,7 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
.getFullPath());
|
|
|
if (b) {
|
|
|
// 更新table
|
|
|
- oldvo.setFiledesc("OCR已识别");
|
|
|
+ oldvo.setFiledesc(message);
|
|
|
oldvo.setModifier(newvo.getModifier());
|
|
|
oldvo.setModifytime(newvo.getModifytime());
|
|
|
parentpanel.getfiletablemodel().clearTable();
|
|
@@ -352,45 +200,94 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
+ if(!"OCR已识别".equals(message)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String ext = info.getString("ext");
|
|
|
+ JSONObject extobj = JSONObject.parseObject(ext);
|
|
|
+ String trate = extobj.getString("trate");//税率
|
|
|
+ JSONObject comm_info = info.getJSONObject("comm_info");
|
|
|
+ JSONObject pro = comm_info.getJSONObject("pro");
|
|
|
+ String date = pro.getString("date");//发票日期
|
|
|
+ String cname = pro.getString("cname");//发票类型名称
|
|
|
+ String kind = extobj.getString("content");
|
|
|
+ JSONObject price = comm_info.getJSONObject("price");
|
|
|
+ String amount = "";
|
|
|
+ String total = price.getString("total");//价税合计
|
|
|
+ String dtax = price.getString("dtax");//可抵扣税额
|
|
|
+ String ttax = "";
|
|
|
+ //如有可抵扣税额,无税金额等于无税金额,税额等于可抵扣税额,税率等于税率
|
|
|
+ //如没有可抵扣税额,无税金额等于无税金额+税额,税额等于0,税率等于0
|
|
|
+ if("0".equals(dtax)) {
|
|
|
+ //无税金额+税额 = 价税合计
|
|
|
+ amount = total;
|
|
|
+ ttax = "0";//税额
|
|
|
+ trate = "0";//税率
|
|
|
+ }else {
|
|
|
+ amount = price.getString("amount");//无税金额
|
|
|
+ ttax = extobj.getString("ttax");//税额
|
|
|
+ }
|
|
|
+ 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[] 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", ttax);
|
|
|
+ defvo.setAttributeValue("pid", date);
|
|
|
+ defvo.setAttributeValue("shortname5", cname);
|
|
|
+ defvo.setAttributeValue("shortname6", trate);
|
|
|
+ defvo.setAttributeValue("dataoriginflag", 0);
|
|
|
+ defvo.setAttributeValue("shortname4", kind);
|
|
|
+ defvo.setAttributeValue("innercode", codenumber);
|
|
|
+ defvo.setAttributeValue("modifier", dtax);
|
|
|
+ vos[0] = defvo;
|
|
|
+ try {
|
|
|
+ idefservice.insertDefdocs(pk_group, vos);
|
|
|
+
|
|
|
+ Map<String,String> map = new HashMap<String,String>();
|
|
|
+ map.put("KYHSJE", "~");
|
|
|
+ map.put("KYWSJE", "~");
|
|
|
+ map.put("JYSE", "~");
|
|
|
+ map.put("FPXZ", url);
|
|
|
+ map.put("VDEF17",vdef17);
|
|
|
+ map.put("NUMBERID",code);
|
|
|
+ ocrservice.addORC(map);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO 自动生成的 catch 块
|
|
|
+ MessageDialog.showErrorDlg(parentpanel, NCLangRes.getInstance().getStrByID("pc", "FileManageUI-000000")/*错误*/
|
|
|
+ ,"保存自定义档案数据:\n"+e.getMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
MessageDialog.showHintDlg(parentpanel, "提示","识别结束!");
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 得到文件名称
|
|
|
- *
|
|
|
- * @param path 路径
|
|
|
- * @return {@link List}<{@link String}>
|
|
|
- */
|
|
|
- /* 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);
|
|
|
- }*/
|
|
|
-
|
|
|
-/**
|
|
|
- * 得到文件名称
|
|
|
- *
|
|
|
- * @param file 文件
|
|
|
- * @param fileNames 文件名
|
|
|
- * @return {@link List}<{@link String}>
|
|
|
- */
|
|
|
-/* private List<String> getFileNames(File file, List<String> fileNames) {
|
|
|
- File[] files = file.listFiles();
|
|
|
- for (File f : files) {
|
|
|
- if (f.isDirectory()) {
|
|
|
- getFileNames(f, fileNames);
|
|
|
- } else {
|
|
|
- fileNames.add(f.getName());
|
|
|
- }
|
|
|
- }
|
|
|
- return fileNames;
|
|
|
- }*/
|
|
|
|
|
|
private String checkJson(JSONObject json) throws Exception {
|
|
|
|
|
@@ -423,27 +320,4 @@ public class ThOCRAction extends AbstractNCAction{
|
|
|
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||arrayvos.size()==0) {
|
|
|
- return new DefdocVO[0];
|
|
|
- }else {
|
|
|
- return arrayvos.toArray(new DefdocVO[0]);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
}
|