be68ba59 by 王聪

de_mortgage 接口更新,兼容不同文档类型

1 parent 297f47e6
......@@ -211,12 +211,7 @@ class PosHandler:
return result_obj
@staticmethod
def de_mortgage_ocr_process1(img_base64):
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
def greenbook_process(result_obj, img_base64):
url = conf.OCR_URL_FOLDER
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
try:
......@@ -227,7 +222,7 @@ class PosHandler:
LoggerMixin.exception_log.error(
"[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s",
url, response.text)
return result_obj
return
result = response.json()
data = result.get('data', [])
for item in data:
......@@ -248,5 +243,18 @@ class PosHandler:
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)
LoggerMixin.exception_log.error("[PosHandler greenbook_process] error", exc_info=1)
@staticmethod
def de_mortgage_ocr_process1(file_obj):
result_obj = {
'customerName': '',
'application': '',
'deMortgageDate': ''
}
doc_type = file_obj.get('documentType', '')
img_base64 = file_obj.get('fileBase64')
if doc_type == 'Greenbook':
PosHandler.greenbook_process(result_obj, img_base64)
return result_obj
......
......@@ -53,11 +53,16 @@ class NSCInvoiceView(GenericView):
return response.ok()
file_param = {
'documentType': fields.Str(required=True, validate=validate.Length(max=20)),
'fileBase64': fields.Str(required=True),
}
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)),
'files': fields.Nested(file_param, required=True),
}
......@@ -75,7 +80,7 @@ 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', [])
files = args.get('files', [])
customer_name = args.get('customerName', '')
application = args.get('application', '')
de_mortgage_date = args.get('deMortgageDate')
......@@ -87,8 +92,8 @@ class DeMortgageView(GenericView):
}
de_mortgage_info = {}
# 绿本必须分开ocr
for img_file in img_files:
info = PosHandler.de_mortgage_ocr_process1(img_file)
for file_obj in files:
info = PosHandler.de_mortgage_ocr_process1(file_obj)
de_mortgage_info.update(info)
request_pass = True
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!