926995d4 by 王聪

[CHINARPA-3045] [De-mortgage Supporting Documents Identification] 更新

1 parent aabb5a3e
......@@ -5,6 +5,7 @@ from .named_enum import DocStatus
from .models import HILDoc, AFCDoc, AFCSEOCRResult, AFCOCRResult, HILSEOCRResult, HILOCRResult
from . import consts
from prese.compare import pre_compare, get_empty_result
from common.mixins import LoggerMixin
class MPOSHandler:
......@@ -170,3 +171,38 @@ class PreSEHandler:
rebuild_compare_result = pre_compare(pos_content, ocr_res_dict, id_res_list)
return rebuild_compare_result
class PosHandler:
VehicleRegArea_fields = ['抵押权人姓名/名称', '解除抵押日期']
VehicleRCI_fields = ['1.机动车所有人/身份证名称/号码']
@staticmethod
def de_mortgage_ocr_process(img_base64):
result_obj = {}
url = 'http://file-classification.situdata.com/bs/all'
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY}
try:
response = requests.post(url, json=json_data)
ocr_res = response.json()
results = ocr_res.get('results')
if ocr_res.get('page', '') == 'VehicleRegArea':
register_infos = results.get('register_info', [])
for register_info in register_infos:
if register_info.get('register_type', -1) == 1:
info = register_info.get('解除抵押日期', {})
result_obj['deMortgageDate'] = info.get('words', '')
elif register_info.get('register_type', -1) == 0:
info = register_info.get('抵押权人姓名/名称', {})
result_obj['application'] = info.get('words', '')
elif ocr_res.get('page', '') == 'VehicleRCI':
info = results.get('1.机动车所有人/身份证名称/号码', {})
result_obj['customerName'] = info.get('words', '').split('/')[0]
except Exception as e:
LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc()))
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
return result_obj
......
......@@ -55,7 +55,7 @@ from . import consts
from apps.account.authentication import OAuth2AuthenticationWithUser
from celery_compare.tasks import compare
import time
class CustomDate(fields.Date):
def _deserialize(self, value, attr, data, **kwargs):
......@@ -804,6 +804,8 @@ class SECompareView(GenericView, PreSEHandler):
# SE preSettlement
@use_args(se_compare_args, location='data')
def post(self, request, args): # interface_report pos to ocr
# 模拟耗时操作
time.sleep(25)
start_time = time.time()
log_base = '[prese]'
# 存库
......
......@@ -26,7 +26,7 @@ urlpatterns = [
path(r'api/compare/', include('apps.doc.compare_urls')),
path(r'api/doc/', include('apps.doc.internal_urls')),
path(r'api/mpos/', include('apps.doc.mpos_urls')),
path(r'api/pos/', include('apps.doc.pos_urls')),
path(r'api/poss/', include('apps.doc.pos_urls')),
path(r'api/go/', include('apps.doc.go_urls')),
path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')),
]
......
File mode changed
......@@ -3,8 +3,8 @@ from webargs.djangoparser import use_args, parser
from webargs import fields, validate
from apps.doc.views import CustomDecimal, CustomDate
from common import response
from apps.doc.models import HILSEOCRResult, HILOCRResult, AFCSEOCRResult, AFCOCRResult
from prese import consts
from apps.doc.mixins import PosHandler
from common.tools.comparison import cp
params = {
'invoiceCode': fields.Str(required=True, validate=validate.Length(max=128)),
......@@ -26,7 +26,7 @@ input_args = {
}
# pos 接口接收NSC 发票信息
# poss 接口接收NSC 发票信息
class NSCInvoiceView(GenericView):
@use_args(input_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
......@@ -47,12 +47,18 @@ class NSCInvoiceView(GenericView):
return response.ok()
de_mortgage_params = {
de_mortgage_args = {
'customerName': fields.Str(required=True, validate=validate.Length(max=64)),
'application': fields.Str(required=True, validate=validate.Length(max=64)),
'deMortgageDate': fields.Date(required=True),
'file_base64': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)),
}
de_mortgage_args = {
'content': fields.Nested(de_mortgage_params, required=True)
de_mortgage_comments = {
'customerName': ('机动车所有人识别不一致', ),
'application': ('抵押权人姓名/名称识别不一致', ),
'deMortgageDate': ('解除抵押日期不一致', )
}
......@@ -60,46 +66,43 @@ de_mortgage_args = {
class DeMortgageView(GenericView):
@use_args(de_mortgage_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
content = args.get('content', {})
application_id = content['applicationId']
customer_name = content['customerName']
application_entity = content['applicationEntity']
de_mortgage_date = content['deMortgageDate']
# ocr 检测
# 根据application_id查找OCR累计结果指定license字段,如果没有,结束
result_class = HILSEOCRResult if application_entity in consts.HIL_SET else AFCSEOCRResult
ca_result_class = HILOCRResult if application_entity in consts.HIL_SET else AFCOCRResult
ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values(
*consts.CA_ADD_COMPARE_FIELDS_PRE).first()
ocr_res_dict = result_class.objects.filter(application_id=application_id).values(
*consts.PRE_COMPARE_FIELDS).first()
# if ocr_res_dict is None:
# return get_empty_result()
ic_res_list = []
ic_res_list.append(ca_ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None)
ic_res_list.append(ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None)
field_name, compare_logic, args, comment = consts.ID_COMPARE_LOGIC.get(consts.ID_FIELDS[0])
for ic_res in ic_res_list:
if ic_res:
value = ic_res.get(field_name, '')
compare_logic
img_files = args.get('file_base64', [])
customer_name = args.get('customerName', '')
application = args.get('application', '')
de_mortgage_date = args.get('deMortgageDate')
fields_input = {
'customerName': customer_name,
'application': application,
'deMortgageDate': de_mortgage_date
}
de_mortgage_info = {}
# 绿本必须分开ocr
for img_file in img_files:
info = PosHandler.de_mortgage_ocr_process(img_file)
de_mortgage_info.update(info)
request_pass = True
fields_result = []
for field_name, input_val in enumerate(fields_input):
field_result = {
"name": field_name,
"input": input_val,
"ocr": de_mortgage_info.get(field_name, ''),
"field_is_pass": False,
"comments": ''
}
result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
if result == cp.RESULT_Y:
fields_result['field_is_pass'] = result
else:
request_pass = False
fields_result['comments'] = de_mortgage_comments.get(field_name, '')
fields_result.append(field_result)
result = {
"is_pass": True,
"fields": [{
"name": "",
"input": "张三",
"ocr": "张三",
"field_is_pass": True,
"comments": "身份证姓名与系统不一致"
}]
# "customer_name": True,
# "application_entity": True,
# "de_mortgage_date": True
"is_pass": request_pass,
"fields": fields_result
}
return response.ok(data=result)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!