30509ad4 by 周伟奇

Merge branch 'feature/uat-tmp' into fix/report_ca

2 parents df148313 cd639176
......@@ -7,6 +7,7 @@ from . import consts
from prese.compare import pre_compare, get_empty_result
from common.mixins import LoggerMixin
from settings import conf
from pos.consts import DocumentType
class MPOSHandler:
......@@ -211,23 +212,21 @@ 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"}
json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "vrc_format": "v2"}
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",
"[PosHandler greenbook_process] request error, url: %s, response: %s",
url, response.text)
return
LoggerMixin.running_log.info(
"[PosHandler greenbook_process] request success, url: %s, response: %s",
url, response.text)
return result_obj
result = response.json()
data = result.get('data', [])
for item in data:
......@@ -238,7 +237,7 @@ class PosHandler:
for registration in registration_bar:
if registration.get('register_type', '') == '抵押登记':
register_info = registration.get('register_info', {})
result_obj['application'] = register_info.get('抵押权人姓名/名称', '')
result_obj['applicationName'] = register_info.get('抵押权人姓名/名称', '')
elif registration.get('register_type', '') == '解除抵押':
register_info = registration.get('register_info', {})
result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '')
......@@ -248,5 +247,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': '',
'applicationName': '',
'deMortgageDate': ''
}
doc_type = file_obj.get('documentType', '')
img_base64 = file_obj.get('fileBase64')
if doc_type == DocumentType.GREEN_BOOK.value.en_name:
PosHandler.greenbook_process(result_obj, img_base64)
return result_obj
......
......@@ -4,4 +4,5 @@ from pos import views
urlpatterns = [
path(r'nsc/invoice', views.NSCInvoiceView.as_view()),
path(r'de-mortgage', views.DeMortgageView.as_view()),
path(r'de-mortgage1', views.DeMortgageView1.as_view()),
]
......
......@@ -244,6 +244,9 @@ se_compare_content = {
'customerType': fields.Str(required=True, validate=validate.OneOf(consts.CUSTOMER_TYPE)),
"firstSubmmisonDate": CustomDate(required=True),
'propertyDocumentPolicy': fields.Str(required=False, validate=validate.Length(max=16)),
'fsmFlag': fields.Boolean(required=False),
'fsmSpecialCar': fields.Boolean(required=False),
'fsmBestPrice': fields.Boolean(required=False),
'isAutoSettlement': fields.Boolean(required=False),
'individualCusInfo': fields.List(fields.Nested(se_individual_args),
......@@ -573,6 +576,15 @@ class UploadDocView(GenericView, DocHandler):
self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args))
return response.ok()
if data_source == consts.DATA_SOURCE_LIST[-1] and document_scheme == consts.DOC_SCHEME_LIST[1]:
# 电子合同来源的压缩包直接返回,避免被ocr识别导致线上问题
if document_name.endswith('.zip') \
or document_name.endswith('.rar') \
or document_name.endswith('.ZIP') \
or document_name.endswith('.RAR'):
self.running_log.info('[doc upload success] [SETTLEMENT ECONTRACT zip skip] [args={0}]'.format(args))
return response.ok()
# 2. 根据业务类型分库存储
doc_class, prefix = self.get_doc_class(business_type)
doc = doc_class.objects.create(
......@@ -813,6 +825,11 @@ class SECompareView(GenericView, PreSEHandler):
uniq_seq = content.get('uniqSeq')
bank_verify = content.get('bankInfo', {}).get('bankVerificationStatus', '')
# fsm
fsm_flag = content.get('fsmFlag', False)
fsm_special_car = content.get('fsmSpecialCar', False)
fsm_best_price = content.get('fsmBestPrice', False)
# 存库, 用于银行卡比对
try:
bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification
......
from enum import Enum
class DocumentTypeModel:
def __init__(self, code, en_name, cn_name):
self.code = code;
self.en_name = en_name
self.cn_name = cn_name
class DocumentType(Enum):
GREEN_BOOK = DocumentTypeModel("DTGBK", "Green Book", "机动车登记证")
CONFIRMATION_LETTER = DocumentTypeModel("DTCLE", "Confirmation Letter", "解抵押确认函")
WEBSITE_SCREENSHOT = DocumentTypeModel("DTWES", "Website Screenshot", "网页截图")
if __name__ == '__main__':
print(DocumentType.GREEN_BOOK.value.en_name)
......@@ -5,7 +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 common.mixins import LoggerMixin
from rest_framework.permissions import IsAuthenticated
from apps.account.authentication import OAuth2AuthenticationWithUser
......@@ -53,18 +53,23 @@ 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)),
'applicationName': fields.Str(required=True, validate=validate.Length(max=64)),
'deMortgageDate': fields.Str(required=True),
'files': fields.List(fields.Nested(file_param))
}
de_mortgage_comments = {
'customerName': ('机动车所有人识别不一致', ),
'application': ('抵押权人姓名/名称识别不一致', ),
'deMortgageDate': ('解除抵押日期不一致', )
'customerName': '机动车所有人识别不一致',
'applicationName': '抵押权人姓名/名称识别不一致',
'deMortgageDate': '解除抵押日期不一致'
}
......@@ -75,20 +80,20 @@ 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', '')
application_name = args.get('applicationName', '')
de_mortgage_date = args.get('deMortgageDate')
fields_input = {
'customerName': customer_name,
'application': application,
'applicationName': application_name,
'deMortgageDate': de_mortgage_date
}
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
......@@ -101,12 +106,16 @@ class DeMortgageView(GenericView):
"field_is_pass": False,
"comments": ''
}
result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
result, _ = cp.common_compare(field_result['input'], field_result['ocr'], None)
LoggerMixin.running_log.info(
"[DeMortgageView common_compare] input: %s, ocr: %s, result:%s ",
field_result['input'], field_result['ocr'], result)
if result == cp.RESULT_Y:
fields_result['field_is_pass'] = result
field_result['field_is_pass'] = True
else:
request_pass = False
fields_result['comments'] = de_mortgage_comments.get(field_name, '')
field_result['comments'] = de_mortgage_comments.get(field_name, '')
fields_result.append(field_result)
......@@ -116,3 +125,16 @@ class DeMortgageView(GenericView):
}
return response.ok(data=result)
class DeMortgageView1(GenericView):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
@use_args(de_mortgage_args, location='data')
def post(self, request, args): # interface_report mpos to ocr
files = args.get('files', [])
customer_name = args.get('customerName', '')
application_name = args.get('applicationName', '')
de_mortgage_date = args.get('deMortgageDate')
return response.ok(data=args)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!