From 5158602c7958e743459a5fb5f0cda87614a844f4 Mon Sep 17 00:00:00 2001 From: ap007 Date: Fri, 9 Dec 2022 22:26:52 +0800 Subject: [PATCH] =?UTF-8?q?ocr=E6=89=AB=E6=8F=8F=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebContent/WEB-INF/etc/jbo/jbo_oti.xml | 95 ++++++++++ src_jbo/jbo/oti/BANK_CARD_ORC_RESULT.java | 48 +++++ src_jbo/jbo/oti/ID_CARD_OCR_RESULT.java | 88 +++++++++ src_jbo/jbo/oti/INVOICE_ORC_RESULT.java | 172 ++++++++++++++++++ .../lease/app/quartzmession/AutoOcr.java | 168 +++++++++++++++++ 5 files changed, 571 insertions(+) create mode 100644 src_jbo/jbo/oti/BANK_CARD_ORC_RESULT.java create mode 100644 src_jbo/jbo/oti/ID_CARD_OCR_RESULT.java create mode 100644 src_jbo/jbo/oti/INVOICE_ORC_RESULT.java create mode 100644 src_tenwa/com/tenwa/lease/app/quartzmession/AutoOcr.java diff --git a/WebContent/WEB-INF/etc/jbo/jbo_oti.xml b/WebContent/WEB-INF/etc/jbo/jbo_oti.xml index 1c4a634a6..69ec4224f 100644 --- a/WebContent/WEB-INF/etc/jbo/jbo_oti.xml +++ b/WebContent/WEB-INF/etc/jbo/jbo_oti.xml @@ -556,5 +556,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src_jbo/jbo/oti/BANK_CARD_ORC_RESULT.java b/src_jbo/jbo/oti/BANK_CARD_ORC_RESULT.java new file mode 100644 index 000000000..cec08630b --- /dev/null +++ b/src_jbo/jbo/oti/BANK_CARD_ORC_RESULT.java @@ -0,0 +1,48 @@ +package jbo.oti; + +import java.lang.String; + +/** +* 银行卡ocr识别结果 - JBO命名常量类

+* Note: This file is generated by ADE tools, dont modify it.
+ +*/ +public interface BANK_CARD_ORC_RESULT{ + /** + * 银行卡ocr识别结果

+ * 代表本类映射的BizObjectClass + */ + public static final String CLASS_NAME = "jbo.oti.BANK_CARD_ORC_RESULT"; + /** + * 唯一标识 STRING(32)
+ */ + public static final String ID = "ID"; + /** + * 合同ID STRING(32)
+ */ + public static final String CONTRACT_ID = "CONTRACT_ID"; + /** + * 项目编号 STRING(32)
+ */ + public static final String PROJECT_NO = "PROJECT_NO"; + /** + * 错误码 STRING(32)
+ */ + public static final String ERROR_CODE = "ERROR_CODE"; + /** + * 结果全文 STRING(32)
+ */ + public static final String RESULT = "RESULT"; + /** + * 银行卡号 STRING(32)
+ */ + public static final String BANK_CARD_NO = "BANK_CARD_NO"; + /** + * 银行卡号校验 STRING(32)
+ */ + public static final String PASS_CHECK = "PASS_CHECK"; + /** + * 创建时间 STRING(32)
+ */ + public static final String INPUTTIME = "INPUTTIME"; +} \ No newline at end of file diff --git a/src_jbo/jbo/oti/ID_CARD_OCR_RESULT.java b/src_jbo/jbo/oti/ID_CARD_OCR_RESULT.java new file mode 100644 index 000000000..80ea7b681 --- /dev/null +++ b/src_jbo/jbo/oti/ID_CARD_OCR_RESULT.java @@ -0,0 +1,88 @@ +package jbo.oti; + +import java.lang.String; + +/** +* 身份证ocr识别结果 - JBO命名常量类

+* Note: This file is generated by ADE tools, dont modify it.
+ +*/ +public interface ID_CARD_OCR_RESULT{ + /** + * 身份证ocr识别结果

+ * 代表本类映射的BizObjectClass + */ + public static final String CLASS_NAME = "jbo.oti.ID_CARD_OCR_RESULT"; + /** + * 唯一标识 STRING(32)
+ */ + public static final String ID = "ID"; + /** + * 合同ID STRING(32)
+ */ + public static final String CONTRACT_ID = "CONTRACT_ID"; + /** + * 项目编号 STRING(32)
+ */ + public static final String PROJECT_NO = "PROJECT_NO"; + /** + * 错误码 STRING(32)
+ */ + public static final String ERROR_CODE = "ERROR_CODE"; + /** + * 结果全文 STRING(32)
+ */ + public static final String RESULT = "RESULT"; + /** + * 姓名 STRING(32)
+ */ + public static final String FULL_NAME = "FULL_NAME"; + /** + * 性别 STRING(32)
+ */ + public static final String GENDER = "GENDER"; + /** + * 民族 STRING(32)
+ */ + public static final String ETHNICITY = "ETHNICITY"; + /** + * 出生年月 STRING(32)
+ */ + public static final String BRITH = "BRITH"; + /** + * 住址 STRING(32)
+ */ + public static final String ADDR = "ADDR"; + /** + * 公民身份号码 STRING(32)
+ */ + public static final String ID_NO = "ID_NO"; + /** + * 头像 STRING(32)
+ */ + public static final String HEAD = "HEAD"; + /** + * 验证 STRING(32)
+ */ + public static final String VERIFY = "VERIFY"; + /** + * 人像面复印件 STRING(32)
+ */ + public static final String HEAD_COPY = "HEAD_COPY"; + /** + * 签发机关 STRING(32)
+ */ + public static final String ISSUED_OFFICE = "ISSUED_OFFICE"; + /** + * 有限期限 STRING(32)
+ */ + public static final String TERM_VALIDITY = "TERM_VALIDITY"; + /** + * 类型 STRING(32)
+ */ + public static final String TYPE = "TYPE"; + /** + * 创建时间 STRING(32)
+ */ + public static final String INPUTTIME = "INPUTTIME"; +} \ No newline at end of file diff --git a/src_jbo/jbo/oti/INVOICE_ORC_RESULT.java b/src_jbo/jbo/oti/INVOICE_ORC_RESULT.java new file mode 100644 index 000000000..3ac4b334e --- /dev/null +++ b/src_jbo/jbo/oti/INVOICE_ORC_RESULT.java @@ -0,0 +1,172 @@ +package jbo.oti; + +import java.lang.String; + +/** +* 发票ocr识别结果 - JBO命名常量类

+* Note: This file is generated by ADE tools, dont modify it.
+ +*/ +public interface INVOICE_ORC_RESULT{ + /** + * 发票ocr识别结果

+ * 代表本类映射的BizObjectClass + */ + public static final String CLASS_NAME = "jbo.oti.INVOICE_ORC_RESULT"; + /** + * 唯一标识 STRING(32)
+ */ + public static final String ID = "ID"; + /** + * 合同ID STRING(32)
+ */ + public static final String CONTRACT_ID = "CONTRACT_ID"; + /** + * 项目编号 STRING(32)
+ */ + public static final String PROJECT_NO = "PROJECT_NO"; + /** + * 错误码 STRING(32)
+ */ + public static final String ERROR_CODE = "ERROR_CODE"; + /** + * 结果全文 STRING(32)
+ */ + public static final String RESULT = "RESULT"; + /** + * 开票日期 STRING(32)
+ */ + public static final String DATEISSUED = "DATEISSUED"; + /** + * 发票代码 STRING(32)
+ */ + public static final String INVOICE_CODE = "INVOICE_CODE"; + /** + * 发票号码 STRING(32)
+ */ + public static final String INVOICE_NO = "INVOICE_NO"; + /** + * 机打代码 STRING(32)
+ */ + public static final String PRINT_CODE = "PRINT_CODE"; + /** + * 机打号码 STRING(32)
+ */ + public static final String PRINT_NO = "PRINT_NO"; + /** + * 机器编号 STRING(32)
+ */ + public static final String MACHINE_CODE = "MACHINE_CODE"; + /** + * 税控码 STRING(32)
+ */ + public static final String FISCAL_CODE = "FISCAL_CODE"; + /** + * 购买方名称及身份证号码/组织机构代码 STRING(32)
+ */ + public static final String ID_ORG_CODE = "ID_ORG_CODE"; + /** + * 纳税人识别号 STRING(32)
+ */ + public static final String TAX_ID = "TAX_ID"; + /** + * 车辆类型 STRING(32)
+ */ + public static final String CAR_TYPE = "CAR_TYPE"; + /** + * 厂商型号 STRING(32)
+ */ + public static final String CAR_MODEL = "CAR_MODEL"; + /** + * 产地 STRING(32)
+ */ + public static final String MADE_IN = "MADE_IN"; + /** + * 合格证号 STRING(32)
+ */ + public static final String CERTIFICATE_NO = "CERTIFICATE_NO"; + /** + * 进口证明书号 STRING(32)
+ */ + public static final String IMPORT_CERTIFICATE_NO = "IMPORT_CERTIFICATE_NO"; + /** + * 商检单号 STRING(32)
+ */ + public static final String COMMODITY_CHECK_NO = "COMMODITY_CHECK_NO"; + /** + * 发动机号码 STRING(32)
+ */ + public static final String ENGINE_NO = "ENGINE_NO"; + /** + * 车辆识别代码/车架号 STRING(32)
+ */ + public static final String VIN = "VIN"; + /** + * 税价合计(大写) STRING(32)
+ */ + public static final String TOTAL_IN_WORDS = "TOTAL_IN_WORDS"; + /** + * 税价合计(小写) STRING(32)
+ */ + public static final String TOTAL_IN_NUMBERS = "TOTAL_IN_NUMBERS"; + /** + * 销售方名称 STRING(32)
+ */ + public static final String SELLER_NAME = "SELLER_NAME"; + /** + * 销货单位电话 STRING(32)
+ */ + public static final String SELLER_TEL = "SELLER_TEL"; + /** + * 销货单位纳税人识别号 STRING(32)
+ */ + public static final String SELLER_TAX_ID = "SELLER_TAX_ID"; + /** + * 销货单位账号 STRING(32)
+ */ + public static final String SELLER_ACCOUNT = "SELLER_ACCOUNT"; + /** + * 销货单位地址 STRING(32)
+ */ + public static final String SELLER_ADDR = "SELLER_ADDR"; + /** + * 销货单位开户银行 STRING(32)
+ */ + public static final String SELLER_ACCOUNT_NO = "SELLER_ACCOUNT_NO"; + /** + * 增值税税率或征收税率 STRING(32)
+ */ + public static final String VAT_RATE = "VAT_RATE"; + /** + * 增值税税额 STRING(32)
+ */ + public static final String VAT_AMOUNT = "VAT_AMOUNT"; + /** + * 主管税务机关及代码 STRING(32)
+ */ + public static final String TAX_OFFICE_CODE = "TAX_OFFICE_CODE"; + /** + * 不含税价小写 STRING(32)
+ */ + public static final String EXCLUDING_TAX_AMOUNT = "EXCLUDING_TAX_AMOUNT"; + /** + * 完税凭证号码 STRING(32)
+ */ + public static final String TAX_PAYMENT_NO = "TAX_PAYMENT_NO"; + /** + * 吨位 STRING(32)
+ */ + public static final String TONNAGE = "TONNAGE"; + /** + * 限乘人数 STRING(32)
+ */ + public static final String PERSON_LIMITED = "PERSON_LIMITED"; + /** + * 公章 STRING(32)
+ */ + public static final String OFFICIAL_SEAL = "OFFICIAL_SEAL"; + /** + * 创建时间 STRING(32)
+ */ + public static final String INPUTTIME = "INPUTTIME"; +} \ No newline at end of file diff --git a/src_tenwa/com/tenwa/lease/app/quartzmession/AutoOcr.java b/src_tenwa/com/tenwa/lease/app/quartzmession/AutoOcr.java new file mode 100644 index 000000000..936b9820f --- /dev/null +++ b/src_tenwa/com/tenwa/lease/app/quartzmession/AutoOcr.java @@ -0,0 +1,168 @@ +package com.tenwa.lease.app.quartzmession; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.amarsoft.are.jbo.*; +import com.amarsoft.are.util.StringFunction; +import com.ample.icms.scan.ImageOcr; +import com.ample.icms.service.ImageOcrService; +import com.ample.icms.util.GetInfoUtil; +import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO; +import jbo.oti.BANK_CARD_ORC_RESULT; +import jbo.oti.ID_CARD_OCR_RESULT; +import jbo.oti.INVOICE_ORC_RESULT; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import java.util.List; + +public class AutoOcr implements Job { + + private JobInitUserName jboName; + + + @Override + public synchronized void execute(JobExecutionContext arg0) throws JobExecutionException { + JBOTransaction tx =null; + + try { + tx = JBOFactory.createJBOTransaction(); + ImageOcrService is = new ImageOcrService(); + GetInfoUtil giu = new GetInfoUtil(); + List lciBos = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx).createQuery("select id from O where BUSINESSTYPE=1 and CONTRACT_STATUS>=31 and project_date>'2022/01/01 00:00:00'").getResultList(false); + for(int i=0;i<30;i++){ + BizObject bo = lciBos.get(i); + String contractId = bo.getAttribute("ID").toString(); + String projectNo = giu.getProjectNoByContractId(contractId,tx); + is.setContractId(contractId); + is.setFlowNo("FundPaymentCarFlow"); + String incoveResult = is.invoiceOrc("APZLJJ000060", ImageOcr.ocrType.vehicle_invoice_ocr,tx); + System.out.println("定时任务机动车发票返回结果:"+incoveResult); + invoiceOrcResultSave(contractId,projectNo,incoveResult,tx); + is.setFlowNo("BusinessApplyFlow"); + String idResult = is.invoiceOrc("APZLJJ000130", ImageOcr.ocrType.id_card,tx); + System.out.println("定时任务身份证返回结果:"+idResult); + idOrcResultSave(contractId,projectNo,idResult,tx); + String bankResult = is.invoiceOrc("APZLJJ000260", ImageOcr.ocrType.bank_card_ocr,tx); + System.out.println("定时任务银行卡返回结果:"+bankResult); + banCardOrcResultSave(contractId,projectNo,bankResult,tx); + } + } catch (Exception e2) { + e2.printStackTrace(); + if (tx != null) { + try { + tx.rollback(); + tx=null; + } catch (JBOException e1) { + e1.printStackTrace(); + } + } + }finally{ + try { + if(tx !=null){ + + tx.commit(); + } + } catch (JBOException e) { + e.printStackTrace(); + } + } + } + public void invoiceOrcResultSave(String contractId, String projectNo, String result,JBOTransaction tx) throws JBOException { + BizObjectManager IORbom = JBOFactory.getBizObjectManager(INVOICE_ORC_RESULT.CLASS_NAME,tx); + BizObject IORbo = IORbom.newObject(); + JSONObject resultJson= JSON.parseObject(result); + String errorCode = resultJson.get("error_code").toString(); + JSONObject resultInfo = resultJson.getJSONObject("result"); + + IORbo.setAttributeValue("CONTRACT_ID",contractId); + IORbo.setAttributeValue("PROJECT_NO",projectNo); + IORbo.setAttributeValue("ERROR_CODE",errorCode); + IORbo.setAttributeValue("RESULT",resultInfo.toString()); + IORbo.setAttributeValue("INPUTTIME", StringFunction.getTodayNow()); + + if("0".equals(errorCode)){ + IORbo.setAttributeValue("DATEISSUED",resultInfo.getString("开票日期")); + IORbo.setAttributeValue("INVOICE_CODE",resultInfo.getString("发票代码")); + IORbo.setAttributeValue("INVOICE_NO",resultInfo.getString("发票号码")); + IORbo.setAttributeValue("PRINT_CODE",resultInfo.getString("机打代码")); + IORbo.setAttributeValue("PRINT_NO",resultInfo.getString("机打号码")); + IORbo.setAttributeValue("MACHINE_CODE",resultInfo.getString("机器编号")); + IORbo.setAttributeValue("FISCAL_CODE",resultInfo.getString("税控码")); + IORbo.setAttributeValue("ID_ORG_CODE",resultInfo.getString("购买方名称及身份证号码/组织机构代码")); + IORbo.setAttributeValue("TAX_ID",resultInfo.getString("纳税人识别号")); + IORbo.setAttributeValue("CAR_TYPE",resultInfo.getString("车辆类型")); + IORbo.setAttributeValue("CAR_MODEL",resultInfo.getString("厂牌型号")); + IORbo.setAttributeValue("MADE_IN",resultInfo.getString("产地")); + IORbo.setAttributeValue("CERTIFICATE_NO",resultInfo.getString("合格证号")); + IORbo.setAttributeValue("IMPORT_CERTIFICATE_NO",resultInfo.getString("进口证明书号")); + IORbo.setAttributeValue("COMMODITY_CHECK_NO",resultInfo.getString("商检单号")); + IORbo.setAttributeValue("ENGINE_NO",resultInfo.getString("发动机号码")); + IORbo.setAttributeValue("VIN",resultInfo.getString("车辆识别代号/车架号码")); + IORbo.setAttributeValue("TOTAL_IN_WORDS",resultInfo.getString("价税合计大写")); + IORbo.setAttributeValue("TOTAL_IN_NUMBERS",resultInfo.getString("价税合计小写")); + IORbo.setAttributeValue("SELLER_NAME",resultInfo.getString("销货单位名称")); + IORbo.setAttributeValue("SELLER_TEL",resultInfo.getString("销货单位电话")); + IORbo.setAttributeValue("SELLER_TAX_ID",resultInfo.getString("销货单位纳税人识别号")); + IORbo.setAttributeValue("SELLER_ACCOUNT",resultInfo.getString("销货单位账号")); + IORbo.setAttributeValue("SELLER_ADDR",resultInfo.getString("销货单位地址")); + IORbo.setAttributeValue("SELLER_ACCOUNT_NO",resultInfo.getString("销货单位开户银行")); + IORbo.setAttributeValue("VAT_RATE",resultInfo.getString("增值税税率或征收税率")); + IORbo.setAttributeValue("VAT_AMOUNT",resultInfo.getString("增值税税额")); + IORbo.setAttributeValue("TAX_OFFICE_CODE",resultInfo.getString("主管税务机关及代码")); + IORbo.setAttributeValue("EXCLUDING_TAX_AMOUNT",resultInfo.getString("不含税价小写")); + IORbo.setAttributeValue("TAX_PAYMENT_NO",resultInfo.getString("完税凭证号码")); + IORbo.setAttributeValue("TONNAGE",resultInfo.getString("吨位")); + IORbo.setAttributeValue("PERSON_LIMITED",resultInfo.getString("限乘人数")); + IORbo.setAttributeValue("OFFICIAL_SEAL",resultInfo.getString("公章")); + } + IORbom.saveObject(IORbo); + } + public void banCardOrcResultSave(String contractId, String projectNo, String result,JBOTransaction tx) throws JBOException { + BizObjectManager BCRbom = JBOFactory.getBizObjectManager(BANK_CARD_ORC_RESULT.CLASS_NAME,tx); + BizObject bo = BCRbom.newObject(); + JSONObject resultJson = JSON.parseObject(result); + String errorCode = resultJson.get("error_code").toString(); + JSONObject resultInfo = resultJson.getJSONObject("result"); + + bo.setAttributeValue("CONTRACT_ID", contractId); + bo.setAttributeValue("PROJECT_NO", projectNo); + bo.setAttributeValue("ERROR_CODE", errorCode); + bo.setAttributeValue("RESULT", resultInfo.toString()); + bo.setAttributeValue("INPUTTIME", StringFunction.getTodayNow()); + if("0".equals(errorCode)){ + bo.setAttributeValue("BANK_CARD_NO", resultInfo.getString("bankCardNum")); + bo.setAttributeValue("PASS_CHECK", resultInfo.getString("passCheck")); + } + BCRbom.saveObject(bo); + } + public void idOrcResultSave(String contractId, String projectNo, String result,JBOTransaction tx) throws JBOException { + BizObjectManager ICRbom = JBOFactory.getBizObjectManager(ID_CARD_OCR_RESULT.CLASS_NAME,tx); + BizObject bo = ICRbom.newObject(); + JSONObject resultJson = JSON.parseObject(result); + String errorCode = resultJson.get("error_code").toString(); + JSONObject resultInfo = resultJson.getJSONObject("result"); + + bo.setAttributeValue("CONTRACT_ID", contractId); + bo.setAttributeValue("PROJECT_NO", projectNo); + bo.setAttributeValue("ERROR_CODE", errorCode); + bo.setAttributeValue("RESULT", resultInfo.toString()); + bo.setAttributeValue("INPUTTIME", StringFunction.getTodayNow()); + if("0".equals(errorCode)){ + bo.setAttributeValue("FULL_NAME", resultInfo.getString("姓名")); + bo.setAttributeValue("GENDER", resultInfo.getString("性别")); + bo.setAttributeValue("ETHNICITY", resultInfo.getString("民族")); + bo.setAttributeValue("BRITH", resultInfo.getString("出生年月")); + bo.setAttributeValue("ADDR", resultInfo.getString("住址")); + bo.setAttributeValue("ID_NO", resultInfo.getString("公民身份号码")); + bo.setAttributeValue("HEAD", resultInfo.getString("头像")); + bo.setAttributeValue("VERIFY", resultInfo.getString("验证")); + bo.setAttributeValue("HEAD_COPY", resultInfo.getString("人像面复印件")); + bo.setAttributeValue("ISSUED_OFFICE", resultInfo.getString("签发机关")); + bo.setAttributeValue("TERM_VALIDITY", resultInfo.getString("有效期限")); + bo.setAttributeValue("TYPE", resultInfo.getString("类型")); + } + ICRbom.saveObject(bo); + } +}