b27910ff by 周伟奇

Merge branch 'feature/pres-3034' into feature/uat-tmp

2 parents 6662b486 e1b816c0
......@@ -6,6 +6,7 @@ from .models import HILDoc, AFCDoc, AFCSEOCRResult, AFCOCRResult, HILSEOCRResult
from . import consts
from prese.compare import pre_compare, get_empty_result
from common.mixins import LoggerMixin
from settings import conf
class MPOSHandler:
......@@ -179,11 +180,18 @@ class PosHandler:
@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}
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
try:
url = conf.OCR_URL_FOLDER
response = requests.post(url, json=json_data)
if response.status_code != 200:
return result_obj
response.encoding = 'unicode_escape'
ocr_res = response.json()
results = ocr_res.get('results')
if ocr_res.get('page', '') == 'VehicleRegArea':
......@@ -199,10 +207,46 @@ class PosHandler:
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': ''
}
LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
return result_obj
@staticmethod
def de_mortgage_ocr_process1(img_base64):
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
url = conf.OCR_URL_FOLDER
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
try:
response = requests.post(url, json=json_data)
# unicode转中文
response.encoding = 'unicode_escape'
if response.status_code != 200:
LoggerMixin.exception_log.error(
"[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s",
url, response.text)
return result_obj
result = response.json()
data = result.get('data', [])
for item in data:
ocr_res = item.get('data', {})
if ocr_res.get('page', '') == 'page_34':
words_result = ocr_res.get('words_result', {})
registration_bar = words_result.get('registration_bar', [])
for registration in registration_bar:
if registration.get('register_type', '') == '抵押登记':
register_info = registration.get('register_info', {})
result_obj['application'] = register_info.get('抵押权人姓名/名称', '')
elif registration.get('register_type', '') == '解除抵押':
register_info = registration.get('register_info', {})
result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '')
elif ocr_res.get('page', '') == 'page_12':
words_result = ocr_res.get('words_result', {})
for _, word_result in words_result.items():
if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码':
result_obj['customerName'] = word_result.get('words', '').split('/')[0]
except Exception as e:
LoggerMixin.exception_log.error("[PosHandler de_mortgage_ocr_process1] error", exc_info=1)
return result_obj
......
......@@ -804,8 +804,6 @@ 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]'
# 存库
......
......@@ -5,6 +5,7 @@ from apps.doc.views import CustomDecimal, CustomDate
from common import response
from apps.doc.mixins import PosHandler
from common.tools.comparison import cp
from rest_framework.permissions import IsAuthenticated
from apps.account.authentication import OAuth2AuthenticationWithUser
......@@ -36,18 +37,18 @@ class NSCInvoiceView(GenericView):
@use_args(input_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
content = args.get('content', {})
invoice_code = content['invoiceCode']
invoice_number = content['invoiceNumber']
issue_date = content['issueDate']
buyer_name = content['buyerName']
buyer_id = content['buyerId']
vin = content['vin']
dealer = content['dealer']
price_with_vat = content['priceWithVat']
price_no_vat = content['priceNoVat']
price_in_capitals = content['priceInCapitals']
vat = content['vat']
vat_rate = content['vatRate']
invoice_code = content.get('invoiceCode', '')
invoice_number = content.get('invoiceNumber', '')
issue_date = content.get('issueDate', None)
buyer_name = content.get('buyerName', '')
buyer_id = content.get('buyerId', 0)
vin = content.get('vin', '')
dealer = content.get('dealer', '')
price_with_vat = content.get('priceWithVat', 0.0)
price_no_vat = content.get('priceNoVat', 0.0)
price_in_capitals = content.get('priceInCapitals', '')
vat = content.get('vat', 0.0)
vat_rate = content.get('vatRate', 0.0)
return response.ok()
......@@ -68,46 +69,50 @@ de_mortgage_comments = {
# 解除抵押识别处理
# class DeMortgageView(GenericView):
# @use_args(de_mortgage_args, location='data')
# def post(self, request, args): # interface_report mpos to ocr
# 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": request_pass,
# "fields": fields_result
# }
# return response.ok(data=result)
class DeMortgageView(GenericView):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(de_mortgage_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
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_process1(img_file)
de_mortgage_info.update(info)
request_pass = True
fields_result = []
for field_name, input_val in fields_input.items():
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": 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!