影像跑批定时任务优化

This commit is contained in:
ap007 2022-12-20 12:47:58 +08:00
parent 0145320755
commit 0c8a0352fc
3 changed files with 146 additions and 104 deletions

View File

@ -52,11 +52,11 @@ public class ImageInfoService {
Element elm = (Element) it.next();
}*/
if(node==null){
throw new Exception("未找到对应的文件信息");
return null;
}
String pageId = node.element("LEAF").getTextTrim();
if("".equals(pageId)||pageId==null){
throw new Exception("未找到对应的图片信息");
return null;
}
Element page = (Element) root.selectSingleNode("//PAGE[@PAGEID='"+pageId+"']");
String pageUrl = page.attributeValue("PAGE_URL");

View File

@ -17,7 +17,9 @@ public class ImageOcrService {
iis.setContractId(contractId);
iis.setFlowNo(flowNo);
String fileUrl = iis.getFileUrl(floder,tx);
if(fileUrl==null){
return "未找到对应的文件";
}
ImageOcr io = new ImageOcr();
String result = io.doPost(fileUrl, ocrType);

View File

@ -1,19 +1,20 @@
package com.tenwa.lease.app.quartzmession;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
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 com.ample.icms.util.PropertiesUtil;
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;
@ -23,30 +24,44 @@ public class AutoOcr implements Job {
@Override
public synchronized void execute(JobExecutionContext arg0) throws JobExecutionException {
public synchronized void execute(JobExecutionContext arg0){
JBOTransaction tx =null;
try {
tx = JBOFactory.createJBOTransaction();
ImageOcrService is = new ImageOcrService();
GetInfoUtil giu = new GetInfoUtil();
List<BizObject> 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++){
String sql = PropertiesUtil.get("auto_sql");
List<BizObject> lciBos = JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,tx).createQuery(sql).getResultList(false);
if(lciBos.size()==0){
throw new Exception("未找到需要跑批的合同");
}
int limitCount =Integer.valueOf(PropertiesUtil.get("limit_count").length()>0?PropertiesUtil.get("limit_count"):"0");
for(int i=0;i<limitCount;i++){
if(i==lciBos.size()){
return;
}
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);
String invoiceResult = is.invoiceOrc("APZLJJ000060", ImageOcr.ocrType.vehicle_invoice_ocr,tx);
System.out.println("定时任务机动车发票返回结果:"+invoiceResult);
JSONObject invoiceResultJson = this.getfullResult(contractId,projectNo,invoiceResult);
resultSave(invoiceResultJson,INVOICE_ORC_RESULT.CLASS_NAME,tx);
String bankResult = is.invoiceOrc("APZLJJ000260", ImageOcr.ocrType.bank_card_ocr,tx);
System.out.println("定时任务银行卡返回结果:"+bankResult);
JSONObject bankResultJson = this.getfullResult(contractId,projectNo,bankResult);
resultSave(bankResultJson,BANK_CARD_ORC_RESULT.CLASS_NAME,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);
JSONObject idResultJson = this.getfullResult(contractId,projectNo,idResult);
resultSave(idResultJson,ID_CARD_OCR_RESULT.CLASS_NAME,tx);
}
} catch (Exception e2) {
e2.printStackTrace();
@ -61,7 +76,6 @@ public class AutoOcr implements Job {
}finally{
try {
if(tx !=null){
tx.commit();
}
} catch (JBOException e) {
@ -69,100 +83,126 @@ public class AutoOcr implements Job {
}
}
}
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("公章"));
public void resultSave(JSONObject fullResultJson,String clazz,JBOTransaction tx) throws JBOException {
BizObjectManager bom = JBOFactory.getBizObjectManager(clazz,tx);
BizObject bo = setPublicResult(fullResultJson,bom.newObject());
if("0".equals(fullResultJson.getString("error_code"))&&jsonValidByFastjson(fullResultJson.getString("result"))){
JSONObject resultInfo = fullResultJson.getJSONObject("result");
switch (clazz){
case INVOICE_ORC_RESULT.CLASS_NAME:
bo = setInvoiceOrcResult(resultInfo,bo);
break;
case BANK_CARD_ORC_RESULT.CLASS_NAME:
setBanCardOrcResult(resultInfo,bo);
break;
case ID_CARD_OCR_RESULT.CLASS_NAME:
setIOrcResultSave(resultInfo,bo);
break;
default:
break;
}
}
IORbom.saveObject(IORbo);
bom.saveObject(bo);
}
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");
public BizObject setPublicResult(JSONObject fullResultJson,BizObject bo) throws JBOException {
String errorCode = fullResultJson.getString("error_code");
String resultStr = fullResultJson.getString("result");
String contractId = fullResultJson.getString("CONTRACT_ID");
String projectNo = fullResultJson.getString("PROJECT_NO");
bo.setAttributeValue("CONTRACT_ID", contractId);
bo.setAttributeValue("PROJECT_NO", projectNo);
bo.setAttributeValue("ERROR_CODE", errorCode);
bo.setAttributeValue("RESULT", resultInfo.toString());
bo.setAttributeValue("CONTRACT_ID",contractId);
bo.setAttributeValue("PROJECT_NO",projectNo);
bo.setAttributeValue("ERROR_CODE",errorCode);
bo.setAttributeValue("RESULT",resultStr);
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);
return 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);
public BizObject setInvoiceOrcResult(JSONObject resultInfo,BizObject bo) throws JBOException {
bo.setAttributeValue("DATEISSUED",resultInfo.getString("开票日期"));
bo.setAttributeValue("INVOICE_CODE",resultInfo.getString("发票代码"));
bo.setAttributeValue("INVOICE_NO",resultInfo.getString("发票号码"));
bo.setAttributeValue("PRINT_CODE",resultInfo.getString("机打代码"));
bo.setAttributeValue("PRINT_NO",resultInfo.getString("机打号码"));
bo.setAttributeValue("MACHINE_CODE",resultInfo.getString("机器编号"));
bo.setAttributeValue("FISCAL_CODE",resultInfo.getString("税控码"));
bo.setAttributeValue("ID_ORG_CODE",resultInfo.getString("购买方名称及身份证号码/组织机构代码"));
bo.setAttributeValue("TAX_ID",resultInfo.getString("纳税人识别号"));
bo.setAttributeValue("CAR_TYPE",resultInfo.getString("车辆类型"));
bo.setAttributeValue("CAR_MODEL",resultInfo.getString("厂牌型号"));
bo.setAttributeValue("MADE_IN",resultInfo.getString("产地"));
bo.setAttributeValue("CERTIFICATE_NO",resultInfo.getString("合格证号"));
bo.setAttributeValue("IMPORT_CERTIFICATE_NO",resultInfo.getString("进口证明书号"));
bo.setAttributeValue("COMMODITY_CHECK_NO",resultInfo.getString("商检单号"));
bo.setAttributeValue("ENGINE_NO",resultInfo.getString("发动机号码"));
bo.setAttributeValue("VIN",resultInfo.getString("车辆识别代号/车架号码"));
bo.setAttributeValue("TOTAL_IN_WORDS",resultInfo.getString("价税合计大写"));
bo.setAttributeValue("TOTAL_IN_NUMBERS",resultInfo.getString("价税合计小写"));
bo.setAttributeValue("SELLER_NAME",resultInfo.getString("销货单位名称"));
bo.setAttributeValue("SELLER_TEL",resultInfo.getString("销货单位电话"));
bo.setAttributeValue("SELLER_TAX_ID",resultInfo.getString("销货单位纳税人识别号"));
bo.setAttributeValue("SELLER_ACCOUNT",resultInfo.getString("销货单位账号"));
bo.setAttributeValue("SELLER_ADDR",resultInfo.getString("销货单位地址"));
bo.setAttributeValue("SELLER_ACCOUNT_NO",resultInfo.getString("销货单位开户银行"));
bo.setAttributeValue("VAT_RATE",resultInfo.getString("增值税税率或征收税率"));
bo.setAttributeValue("VAT_AMOUNT",resultInfo.getString("增值税税额"));
bo.setAttributeValue("TAX_OFFICE_CODE",resultInfo.getString("主管税务机关及代码"));
bo.setAttributeValue("EXCLUDING_TAX_AMOUNT",resultInfo.getString("不含税价小写"));
bo.setAttributeValue("TAX_PAYMENT_NO",resultInfo.getString("完税凭证号码"));
bo.setAttributeValue("TONNAGE",resultInfo.getString("吨位"));
bo.setAttributeValue("PERSON_LIMITED",resultInfo.getString("限乘人数"));
bo.setAttributeValue("OFFICIAL_SEAL",resultInfo.getString("公章"));
return bo;
}
public BizObject setBanCardOrcResult(JSONObject resultInfo,BizObject bo) throws JBOException {
bo.setAttributeValue("BANK_CARD_NO", resultInfo.getString("bankCardNum"));
bo.setAttributeValue("PASS_CHECK", resultInfo.getString("passCheck"));
return bo;
}
public BizObject setIOrcResultSave(JSONObject resultInfo,BizObject bo) throws JBOException {
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("类型"));
return bo;
}
public Boolean jsonValidByFastjson(String jsonStr){
try {
JSONObject.parseObject(jsonStr);
} catch (Exception e) {
try {
JSONObject.parseArray(jsonStr);
} catch (JSONException ex) {
return false;
}
}
return true;
}
public JSONObject praseJsonObject(String fullResult){
JSONObject fullResultJson = null;
if(jsonValidByFastjson(fullResult)){
fullResultJson = JSON.parseObject(fullResult);
}else{
fullResultJson = new JSONObject();
fullResultJson.put("error_code","fail");
fullResultJson.put("result",fullResult);
}
return fullResultJson;
}
public JSONObject getfullResult(String contractId, String projectNo, String responseStr) throws JBOException {
JSONObject fullResultJson = praseJsonObject(responseStr);
fullResultJson.put("CONTRACT_ID",contractId);
fullResultJson.put("PROJECT_NO",projectNo);
return fullResultJson;
}
}