Merge branch 'feature/uat-tmp' into fix/report_ca
Showing
5 changed files
with
96 additions
and
26 deletions
| ... | @@ -7,6 +7,7 @@ from . import consts | ... | @@ -7,6 +7,7 @@ from . import consts |
| 7 | from prese.compare import pre_compare, get_empty_result | 7 | from prese.compare import pre_compare, get_empty_result |
| 8 | from common.mixins import LoggerMixin | 8 | from common.mixins import LoggerMixin |
| 9 | from settings import conf | 9 | from settings import conf |
| 10 | from pos.consts import DocumentType | ||
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | class MPOSHandler: | 13 | class MPOSHandler: |
| ... | @@ -211,23 +212,21 @@ class PosHandler: | ... | @@ -211,23 +212,21 @@ class PosHandler: |
| 211 | return result_obj | 212 | return result_obj |
| 212 | 213 | ||
| 213 | @staticmethod | 214 | @staticmethod |
| 214 | def de_mortgage_ocr_process1(img_base64): | 215 | def greenbook_process(result_obj, img_base64): |
| 215 | result_obj = { | ||
| 216 | 'customerName': '', | ||
| 217 | 'application': '', | ||
| 218 | 'deMortgageDate': '' | ||
| 219 | } | ||
| 220 | url = conf.OCR_URL_FOLDER | 216 | url = conf.OCR_URL_FOLDER |
| 221 | json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"} | 217 | json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "vrc_format": "v2"} |
| 222 | try: | 218 | try: |
| 223 | response = requests.post(url, json=json_data) | 219 | response = requests.post(url, json=json_data) |
| 224 | # unicode转中文 | 220 | # unicode转中文 |
| 225 | response.encoding = 'unicode_escape' | 221 | response.encoding = 'unicode_escape' |
| 226 | if response.status_code != 200: | 222 | if response.status_code != 200: |
| 227 | LoggerMixin.exception_log.error( | 223 | LoggerMixin.exception_log.error( |
| 228 | "[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s", | 224 | "[PosHandler greenbook_process] request error, url: %s, response: %s", |
| 225 | url, response.text) | ||
| 226 | return | ||
| 227 | LoggerMixin.running_log.info( | ||
| 228 | "[PosHandler greenbook_process] request success, url: %s, response: %s", | ||
| 229 | url, response.text) | 229 | url, response.text) |
| 230 | return result_obj | ||
| 231 | result = response.json() | 230 | result = response.json() |
| 232 | data = result.get('data', []) | 231 | data = result.get('data', []) |
| 233 | for item in data: | 232 | for item in data: |
| ... | @@ -238,7 +237,7 @@ class PosHandler: | ... | @@ -238,7 +237,7 @@ class PosHandler: |
| 238 | for registration in registration_bar: | 237 | for registration in registration_bar: |
| 239 | if registration.get('register_type', '') == '抵押登记': | 238 | if registration.get('register_type', '') == '抵押登记': |
| 240 | register_info = registration.get('register_info', {}) | 239 | register_info = registration.get('register_info', {}) |
| 241 | result_obj['application'] = register_info.get('抵押权人姓名/名称', '') | 240 | result_obj['applicationName'] = register_info.get('抵押权人姓名/名称', '') |
| 242 | elif registration.get('register_type', '') == '解除抵押': | 241 | elif registration.get('register_type', '') == '解除抵押': |
| 243 | register_info = registration.get('register_info', {}) | 242 | register_info = registration.get('register_info', {}) |
| 244 | result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '') | 243 | result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '') |
| ... | @@ -248,5 +247,18 @@ class PosHandler: | ... | @@ -248,5 +247,18 @@ class PosHandler: |
| 248 | if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码': | 247 | if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码': |
| 249 | result_obj['customerName'] = word_result.get('words', '').split('/')[0] | 248 | result_obj['customerName'] = word_result.get('words', '').split('/')[0] |
| 250 | except Exception as e: | 249 | except Exception as e: |
| 251 | LoggerMixin.exception_log.error("[PosHandler de_mortgage_ocr_process1] error", exc_info=1) | 250 | LoggerMixin.exception_log.error("[PosHandler greenbook_process] error", exc_info=1) |
| 251 | |||
| 252 | @staticmethod | ||
| 253 | def de_mortgage_ocr_process1(file_obj): | ||
| 254 | result_obj = { | ||
| 255 | 'customerName': '', | ||
| 256 | 'applicationName': '', | ||
| 257 | 'deMortgageDate': '' | ||
| 258 | } | ||
| 259 | |||
| 260 | doc_type = file_obj.get('documentType', '') | ||
| 261 | img_base64 = file_obj.get('fileBase64') | ||
| 262 | if doc_type == DocumentType.GREEN_BOOK.value.en_name: | ||
| 263 | PosHandler.greenbook_process(result_obj, img_base64) | ||
| 252 | return result_obj | 264 | return result_obj | ... | ... |
| ... | @@ -4,4 +4,5 @@ from pos import views | ... | @@ -4,4 +4,5 @@ from pos import views |
| 4 | urlpatterns = [ | 4 | urlpatterns = [ |
| 5 | path(r'nsc/invoice', views.NSCInvoiceView.as_view()), | 5 | path(r'nsc/invoice', views.NSCInvoiceView.as_view()), |
| 6 | path(r'de-mortgage', views.DeMortgageView.as_view()), | 6 | path(r'de-mortgage', views.DeMortgageView.as_view()), |
| 7 | path(r'de-mortgage1', views.DeMortgageView1.as_view()), | ||
| 7 | ] | 8 | ] | ... | ... |
| ... | @@ -244,6 +244,9 @@ se_compare_content = { | ... | @@ -244,6 +244,9 @@ se_compare_content = { |
| 244 | 'customerType': fields.Str(required=True, validate=validate.OneOf(consts.CUSTOMER_TYPE)), | 244 | 'customerType': fields.Str(required=True, validate=validate.OneOf(consts.CUSTOMER_TYPE)), |
| 245 | "firstSubmmisonDate": CustomDate(required=True), | 245 | "firstSubmmisonDate": CustomDate(required=True), |
| 246 | 'propertyDocumentPolicy': fields.Str(required=False, validate=validate.Length(max=16)), | 246 | 'propertyDocumentPolicy': fields.Str(required=False, validate=validate.Length(max=16)), |
| 247 | 'fsmFlag': fields.Boolean(required=False), | ||
| 248 | 'fsmSpecialCar': fields.Boolean(required=False), | ||
| 249 | 'fsmBestPrice': fields.Boolean(required=False), | ||
| 247 | 'isAutoSettlement': fields.Boolean(required=False), | 250 | 'isAutoSettlement': fields.Boolean(required=False), |
| 248 | 251 | ||
| 249 | 'individualCusInfo': fields.List(fields.Nested(se_individual_args), | 252 | 'individualCusInfo': fields.List(fields.Nested(se_individual_args), |
| ... | @@ -573,6 +576,15 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -573,6 +576,15 @@ class UploadDocView(GenericView, DocHandler): |
| 573 | self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args)) | 576 | self.running_log.info('[doc upload success] [eapp license skip] [args={0}]'.format(args)) |
| 574 | return response.ok() | 577 | return response.ok() |
| 575 | 578 | ||
| 579 | if data_source == consts.DATA_SOURCE_LIST[-1] and document_scheme == consts.DOC_SCHEME_LIST[1]: | ||
| 580 | # 电子合同来源的压缩包直接返回,避免被ocr识别导致线上问题 | ||
| 581 | if document_name.endswith('.zip') \ | ||
| 582 | or document_name.endswith('.rar') \ | ||
| 583 | or document_name.endswith('.ZIP') \ | ||
| 584 | or document_name.endswith('.RAR'): | ||
| 585 | self.running_log.info('[doc upload success] [SETTLEMENT ECONTRACT zip skip] [args={0}]'.format(args)) | ||
| 586 | return response.ok() | ||
| 587 | |||
| 576 | # 2. 根据业务类型分库存储 | 588 | # 2. 根据业务类型分库存储 |
| 577 | doc_class, prefix = self.get_doc_class(business_type) | 589 | doc_class, prefix = self.get_doc_class(business_type) |
| 578 | doc = doc_class.objects.create( | 590 | doc = doc_class.objects.create( |
| ... | @@ -813,6 +825,11 @@ class SECompareView(GenericView, PreSEHandler): | ... | @@ -813,6 +825,11 @@ class SECompareView(GenericView, PreSEHandler): |
| 813 | uniq_seq = content.get('uniqSeq') | 825 | uniq_seq = content.get('uniqSeq') |
| 814 | bank_verify = content.get('bankInfo', {}).get('bankVerificationStatus', '') | 826 | bank_verify = content.get('bankInfo', {}).get('bankVerificationStatus', '') |
| 815 | 827 | ||
| 828 | # fsm | ||
| 829 | fsm_flag = content.get('fsmFlag', False) | ||
| 830 | fsm_special_car = content.get('fsmSpecialCar', False) | ||
| 831 | fsm_best_price = content.get('fsmBestPrice', False) | ||
| 832 | |||
| 816 | # 存库, 用于银行卡比对 | 833 | # 存库, 用于银行卡比对 |
| 817 | try: | 834 | try: |
| 818 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification | 835 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification | ... | ... |
src/pos/consts.py
0 → 100644
| 1 | from enum import Enum | ||
| 2 | |||
| 3 | |||
| 4 | class DocumentTypeModel: | ||
| 5 | def __init__(self, code, en_name, cn_name): | ||
| 6 | self.code = code; | ||
| 7 | self.en_name = en_name | ||
| 8 | self.cn_name = cn_name | ||
| 9 | |||
| 10 | |||
| 11 | class DocumentType(Enum): | ||
| 12 | GREEN_BOOK = DocumentTypeModel("DTGBK", "Green Book", "机动车登记证") | ||
| 13 | CONFIRMATION_LETTER = DocumentTypeModel("DTCLE", "Confirmation Letter", "解抵押确认函") | ||
| 14 | WEBSITE_SCREENSHOT = DocumentTypeModel("DTWES", "Website Screenshot", "网页截图") | ||
| 15 | |||
| 16 | |||
| 17 | if __name__ == '__main__': | ||
| 18 | print(DocumentType.GREEN_BOOK.value.en_name) |
| ... | @@ -5,7 +5,7 @@ from apps.doc.views import CustomDecimal, CustomDate | ... | @@ -5,7 +5,7 @@ from apps.doc.views import CustomDecimal, CustomDate |
| 5 | from common import response | 5 | from common import response |
| 6 | from apps.doc.mixins import PosHandler | 6 | from apps.doc.mixins import PosHandler |
| 7 | from common.tools.comparison import cp | 7 | from common.tools.comparison import cp |
| 8 | 8 | from common.mixins import LoggerMixin | |
| 9 | from rest_framework.permissions import IsAuthenticated | 9 | from rest_framework.permissions import IsAuthenticated |
| 10 | from apps.account.authentication import OAuth2AuthenticationWithUser | 10 | from apps.account.authentication import OAuth2AuthenticationWithUser |
| 11 | 11 | ||
| ... | @@ -53,18 +53,23 @@ class NSCInvoiceView(GenericView): | ... | @@ -53,18 +53,23 @@ class NSCInvoiceView(GenericView): |
| 53 | return response.ok() | 53 | return response.ok() |
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | file_param = { | ||
| 57 | 'documentType': fields.Str(required=True, validate=validate.Length(max=20)), | ||
| 58 | 'fileBase64': fields.Str(required=True), | ||
| 59 | } | ||
| 60 | |||
| 56 | de_mortgage_args = { | 61 | de_mortgage_args = { |
| 57 | 'customerName': fields.Str(required=True, validate=validate.Length(max=64)), | 62 | 'customerName': fields.Str(required=True, validate=validate.Length(max=64)), |
| 58 | 'application': fields.Str(required=True, validate=validate.Length(max=64)), | 63 | 'applicationName': fields.Str(required=True, validate=validate.Length(max=64)), |
| 59 | 'deMortgageDate': fields.Date(required=True), | 64 | 'deMortgageDate': fields.Str(required=True), |
| 60 | 'file_base64': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), | 65 | 'files': fields.List(fields.Nested(file_param)) |
| 61 | } | 66 | } |
| 62 | 67 | ||
| 63 | 68 | ||
| 64 | de_mortgage_comments = { | 69 | de_mortgage_comments = { |
| 65 | 'customerName': ('机动车所有人识别不一致', ), | 70 | 'customerName': '机动车所有人识别不一致', |
| 66 | 'application': ('抵押权人姓名/名称识别不一致', ), | 71 | 'applicationName': '抵押权人姓名/名称识别不一致', |
| 67 | 'deMortgageDate': ('解除抵押日期不一致', ) | 72 | 'deMortgageDate': '解除抵押日期不一致' |
| 68 | } | 73 | } |
| 69 | 74 | ||
| 70 | 75 | ||
| ... | @@ -75,20 +80,20 @@ class DeMortgageView(GenericView): | ... | @@ -75,20 +80,20 @@ class DeMortgageView(GenericView): |
| 75 | 80 | ||
| 76 | @use_args(de_mortgage_args, location='data') | 81 | @use_args(de_mortgage_args, location='data') |
| 77 | def post(self, request, args): # interface_report mpos to ocr | 82 | def post(self, request, args): # interface_report mpos to ocr |
| 78 | img_files = args.get('file_base64', []) | 83 | files = args.get('files', []) |
| 79 | customer_name = args.get('customerName', '') | 84 | customer_name = args.get('customerName', '') |
| 80 | application = args.get('application', '') | 85 | application_name = args.get('applicationName', '') |
| 81 | de_mortgage_date = args.get('deMortgageDate') | 86 | de_mortgage_date = args.get('deMortgageDate') |
| 82 | 87 | ||
| 83 | fields_input = { | 88 | fields_input = { |
| 84 | 'customerName': customer_name, | 89 | 'customerName': customer_name, |
| 85 | 'application': application, | 90 | 'applicationName': application_name, |
| 86 | 'deMortgageDate': de_mortgage_date | 91 | 'deMortgageDate': de_mortgage_date |
| 87 | } | 92 | } |
| 88 | de_mortgage_info = {} | 93 | de_mortgage_info = {} |
| 89 | # 绿本必须分开ocr | 94 | # 绿本必须分开ocr |
| 90 | for img_file in img_files: | 95 | for file_obj in files: |
| 91 | info = PosHandler.de_mortgage_ocr_process1(img_file) | 96 | info = PosHandler.de_mortgage_ocr_process1(file_obj) |
| 92 | de_mortgage_info.update(info) | 97 | de_mortgage_info.update(info) |
| 93 | 98 | ||
| 94 | request_pass = True | 99 | request_pass = True |
| ... | @@ -101,12 +106,16 @@ class DeMortgageView(GenericView): | ... | @@ -101,12 +106,16 @@ class DeMortgageView(GenericView): |
| 101 | "field_is_pass": False, | 106 | "field_is_pass": False, |
| 102 | "comments": '' | 107 | "comments": '' |
| 103 | } | 108 | } |
| 104 | result, _ = cp.common_compare(field_result['input'], field_result['ocr']) | 109 | result, _ = cp.common_compare(field_result['input'], field_result['ocr'], None) |
| 110 | LoggerMixin.running_log.info( | ||
| 111 | "[DeMortgageView common_compare] input: %s, ocr: %s, result:%s ", | ||
| 112 | field_result['input'], field_result['ocr'], result) | ||
| 105 | if result == cp.RESULT_Y: | 113 | if result == cp.RESULT_Y: |
| 106 | fields_result['field_is_pass'] = result | 114 | field_result['field_is_pass'] = True |
| 115 | |||
| 107 | else: | 116 | else: |
| 108 | request_pass = False | 117 | request_pass = False |
| 109 | fields_result['comments'] = de_mortgage_comments.get(field_name, '') | 118 | field_result['comments'] = de_mortgage_comments.get(field_name, '') |
| 110 | 119 | ||
| 111 | fields_result.append(field_result) | 120 | fields_result.append(field_result) |
| 112 | 121 | ||
| ... | @@ -116,3 +125,16 @@ class DeMortgageView(GenericView): | ... | @@ -116,3 +125,16 @@ class DeMortgageView(GenericView): |
| 116 | } | 125 | } |
| 117 | return response.ok(data=result) | 126 | return response.ok(data=result) |
| 118 | 127 | ||
| 128 | |||
| 129 | class DeMortgageView1(GenericView): | ||
| 130 | permission_classes = [IsAuthenticated] | ||
| 131 | authentication_classes = [OAuth2AuthenticationWithUser] | ||
| 132 | |||
| 133 | @use_args(de_mortgage_args, location='data') | ||
| 134 | def post(self, request, args): # interface_report mpos to ocr | ||
| 135 | files = args.get('files', []) | ||
| 136 | customer_name = args.get('customerName', '') | ||
| 137 | application_name = args.get('applicationName', '') | ||
| 138 | de_mortgage_date = args.get('deMortgageDate') | ||
| 139 | |||
| 140 | return response.ok(data=args) | ... | ... |
-
Please register or sign in to post a comment