926995d4 by 王聪

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

1 parent aabb5a3e
...@@ -5,6 +5,7 @@ from .named_enum import DocStatus ...@@ -5,6 +5,7 @@ from .named_enum import DocStatus
5 from .models import HILDoc, AFCDoc, AFCSEOCRResult, AFCOCRResult, HILSEOCRResult, HILOCRResult 5 from .models import HILDoc, AFCDoc, AFCSEOCRResult, AFCOCRResult, HILSEOCRResult, HILOCRResult
6 from . import consts 6 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 9
9 10
10 class MPOSHandler: 11 class MPOSHandler:
...@@ -170,3 +171,38 @@ class PreSEHandler: ...@@ -170,3 +171,38 @@ class PreSEHandler:
170 171
171 rebuild_compare_result = pre_compare(pos_content, ocr_res_dict, id_res_list) 172 rebuild_compare_result = pre_compare(pos_content, ocr_res_dict, id_res_list)
172 return rebuild_compare_result 173 return rebuild_compare_result
174
175
176 class PosHandler:
177 VehicleRegArea_fields = ['抵押权人姓名/名称', '解除抵押日期']
178 VehicleRCI_fields = ['1.机动车所有人/身份证名称/号码']
179
180 @staticmethod
181 def de_mortgage_ocr_process(img_base64):
182 result_obj = {}
183 url = 'http://file-classification.situdata.com/bs/all'
184 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY}
185 try:
186 response = requests.post(url, json=json_data)
187 ocr_res = response.json()
188 results = ocr_res.get('results')
189 if ocr_res.get('page', '') == 'VehicleRegArea':
190 register_infos = results.get('register_info', [])
191 for register_info in register_infos:
192 if register_info.get('register_type', -1) == 1:
193 info = register_info.get('解除抵押日期', {})
194 result_obj['deMortgageDate'] = info.get('words', '')
195 elif register_info.get('register_type', -1) == 0:
196 info = register_info.get('抵押权人姓名/名称', {})
197 result_obj['application'] = info.get('words', '')
198 elif ocr_res.get('page', '') == 'VehicleRCI':
199 info = results.get('1.机动车所有人/身份证名称/号码', {})
200 result_obj['customerName'] = info.get('words', '').split('/')[0]
201 except Exception as e:
202 LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc()))
203 result_obj = {
204 'customerName': '',
205 'application': '',
206 'deMortgageDate': ''
207 }
208 return result_obj
......
...@@ -55,7 +55,7 @@ from . import consts ...@@ -55,7 +55,7 @@ from . import consts
55 from apps.account.authentication import OAuth2AuthenticationWithUser 55 from apps.account.authentication import OAuth2AuthenticationWithUser
56 from celery_compare.tasks import compare 56 from celery_compare.tasks import compare
57 57
58 58 import time
59 class CustomDate(fields.Date): 59 class CustomDate(fields.Date):
60 60
61 def _deserialize(self, value, attr, data, **kwargs): 61 def _deserialize(self, value, attr, data, **kwargs):
...@@ -804,6 +804,8 @@ class SECompareView(GenericView, PreSEHandler): ...@@ -804,6 +804,8 @@ class SECompareView(GenericView, PreSEHandler):
804 # SE preSettlement 804 # SE preSettlement
805 @use_args(se_compare_args, location='data') 805 @use_args(se_compare_args, location='data')
806 def post(self, request, args): # interface_report pos to ocr 806 def post(self, request, args): # interface_report pos to ocr
807 # 模拟耗时操作
808 time.sleep(25)
807 start_time = time.time() 809 start_time = time.time()
808 log_base = '[prese]' 810 log_base = '[prese]'
809 # 存库 811 # 存库
......
...@@ -26,7 +26,7 @@ urlpatterns = [ ...@@ -26,7 +26,7 @@ urlpatterns = [
26 path(r'api/compare/', include('apps.doc.compare_urls')), 26 path(r'api/compare/', include('apps.doc.compare_urls')),
27 path(r'api/doc/', include('apps.doc.internal_urls')), 27 path(r'api/doc/', include('apps.doc.internal_urls')),
28 path(r'api/mpos/', include('apps.doc.mpos_urls')), 28 path(r'api/mpos/', include('apps.doc.mpos_urls')),
29 path(r'api/pos/', include('apps.doc.pos_urls')), 29 path(r'api/poss/', include('apps.doc.pos_urls')),
30 path(r'api/go/', include('apps.doc.go_urls')), 30 path(r'api/go/', include('apps.doc.go_urls')),
31 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')), 31 path('api/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')),
32 ] 32 ]
......
File mode changed
...@@ -3,8 +3,8 @@ from webargs.djangoparser import use_args, parser ...@@ -3,8 +3,8 @@ from webargs.djangoparser import use_args, parser
3 from webargs import fields, validate 3 from webargs import fields, validate
4 from apps.doc.views import CustomDecimal, CustomDate 4 from apps.doc.views import CustomDecimal, CustomDate
5 from common import response 5 from common import response
6 from apps.doc.models import HILSEOCRResult, HILOCRResult, AFCSEOCRResult, AFCOCRResult 6 from apps.doc.mixins import PosHandler
7 from prese import consts 7 from common.tools.comparison import cp
8 8
9 params = { 9 params = {
10 'invoiceCode': fields.Str(required=True, validate=validate.Length(max=128)), 10 'invoiceCode': fields.Str(required=True, validate=validate.Length(max=128)),
...@@ -26,7 +26,7 @@ input_args = { ...@@ -26,7 +26,7 @@ input_args = {
26 } 26 }
27 27
28 28
29 # pos 接口接收NSC 发票信息 29 # poss 接口接收NSC 发票信息
30 class NSCInvoiceView(GenericView): 30 class NSCInvoiceView(GenericView):
31 @use_args(input_args, location='data') 31 @use_args(input_args, location='data')
32 def post(self, request, args): # interface_report mpos to ocr 32 def post(self, request, args): # interface_report mpos to ocr
...@@ -47,12 +47,18 @@ class NSCInvoiceView(GenericView): ...@@ -47,12 +47,18 @@ class NSCInvoiceView(GenericView):
47 return response.ok() 47 return response.ok()
48 48
49 49
50 de_mortgage_params = { 50 de_mortgage_args = {
51 51 'customerName': fields.Str(required=True, validate=validate.Length(max=64)),
52 'application': fields.Str(required=True, validate=validate.Length(max=64)),
53 'deMortgageDate': fields.Date(required=True),
54 'file_base64': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)),
52 } 55 }
53 56
54 de_mortgage_args = { 57
55 'content': fields.Nested(de_mortgage_params, required=True) 58 de_mortgage_comments = {
59 'customerName': ('机动车所有人识别不一致', ),
60 'application': ('抵押权人姓名/名称识别不一致', ),
61 'deMortgageDate': ('解除抵押日期不一致', )
56 } 62 }
57 63
58 64
...@@ -60,46 +66,43 @@ de_mortgage_args = { ...@@ -60,46 +66,43 @@ de_mortgage_args = {
60 class DeMortgageView(GenericView): 66 class DeMortgageView(GenericView):
61 @use_args(de_mortgage_args, location='data') 67 @use_args(de_mortgage_args, location='data')
62 def post(self, request, args): # interface_report mpos to ocr 68 def post(self, request, args): # interface_report mpos to ocr
63 content = args.get('content', {}) 69 img_files = args.get('file_base64', [])
64 application_id = content['applicationId'] 70 customer_name = args.get('customerName', '')
65 customer_name = content['customerName'] 71 application = args.get('application', '')
66 application_entity = content['applicationEntity'] 72 de_mortgage_date = args.get('deMortgageDate')
67 de_mortgage_date = content['deMortgageDate'] 73
68 74 fields_input = {
69 # ocr 检测 75 'customerName': customer_name,
70 # 根据application_id查找OCR累计结果指定license字段,如果没有,结束 76 'application': application,
71 result_class = HILSEOCRResult if application_entity in consts.HIL_SET else AFCSEOCRResult 77 'deMortgageDate': de_mortgage_date
72 ca_result_class = HILOCRResult if application_entity in consts.HIL_SET else AFCOCRResult 78 }
73 79 de_mortgage_info = {}
74 ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values( 80 # 绿本必须分开ocr
75 *consts.CA_ADD_COMPARE_FIELDS_PRE).first() 81 for img_file in img_files:
76 ocr_res_dict = result_class.objects.filter(application_id=application_id).values( 82 info = PosHandler.de_mortgage_ocr_process(img_file)
77 *consts.PRE_COMPARE_FIELDS).first() 83 de_mortgage_info.update(info)
78 # if ocr_res_dict is None: 84
79 # return get_empty_result() 85 request_pass = True
80 86 fields_result = []
81 ic_res_list = [] 87 for field_name, input_val in enumerate(fields_input):
82 ic_res_list.append(ca_ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None) 88 field_result = {
83 ic_res_list.append(ocr_res_dict.get(consts.IC_OCR_FIELD) if isinstance(ca_ocr_res_dict, dict) else None) 89 "name": field_name,
84 90 "input": input_val,
85 field_name, compare_logic, args, comment = consts.ID_COMPARE_LOGIC.get(consts.ID_FIELDS[0]) 91 "ocr": de_mortgage_info.get(field_name, ''),
86 for ic_res in ic_res_list: 92 "field_is_pass": False,
87 if ic_res: 93 "comments": ''
88 value = ic_res.get(field_name, '') 94 }
89 compare_logic 95 result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
96 if result == cp.RESULT_Y:
97 fields_result['field_is_pass'] = result
98 else:
99 request_pass = False
100 fields_result['comments'] = de_mortgage_comments.get(field_name, '')
101
102 fields_result.append(field_result)
90 103
91 result = { 104 result = {
92 "is_pass": True, 105 "is_pass": request_pass,
93 "fields": [{ 106 "fields": fields_result
94 "name": "",
95 "input": "张三",
96 "ocr": "张三",
97 "field_is_pass": True,
98 "comments": "身份证姓名与系统不一致"
99 }]
100 # "customer_name": True,
101 # "application_entity": True,
102 # "de_mortgage_date": True
103 } 107 }
104 return response.ok(data=result) 108 return response.ok(data=result)
105
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!