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 ...@@ -6,6 +6,7 @@ from .models import HILDoc, AFCDoc, AFCSEOCRResult, AFCOCRResult, HILSEOCRResult
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 from common.mixins import LoggerMixin
9 from settings import conf
9 10
10 11
11 class MPOSHandler: 12 class MPOSHandler:
...@@ -179,11 +180,18 @@ class PosHandler: ...@@ -179,11 +180,18 @@ class PosHandler:
179 180
180 @staticmethod 181 @staticmethod
181 def de_mortgage_ocr_process(img_base64): 182 def de_mortgage_ocr_process(img_base64):
182 result_obj = {} 183 result_obj = {
183 url = 'http://file-classification.situdata.com/bs/all' 184 'customerName': '',
184 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY} 185 'application': '',
186 'deMortgageDate': ''
187 }
188 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
185 try: 189 try:
190 url = conf.OCR_URL_FOLDER
186 response = requests.post(url, json=json_data) 191 response = requests.post(url, json=json_data)
192 if response.status_code != 200:
193 return result_obj
194 response.encoding = 'unicode_escape'
187 ocr_res = response.json() 195 ocr_res = response.json()
188 results = ocr_res.get('results') 196 results = ocr_res.get('results')
189 if ocr_res.get('page', '') == 'VehicleRegArea': 197 if ocr_res.get('page', '') == 'VehicleRegArea':
...@@ -199,10 +207,46 @@ class PosHandler: ...@@ -199,10 +207,46 @@ class PosHandler:
199 info = results.get('1.机动车所有人/身份证名称/号码', {}) 207 info = results.get('1.机动车所有人/身份证名称/号码', {})
200 result_obj['customerName'] = info.get('words', '').split('/')[0] 208 result_obj['customerName'] = info.get('words', '').split('/')[0]
201 except Exception as e: 209 except Exception as e:
202 LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc())) 210 LoggerMixin.running_log.error("[PosHandler de_mortgage_ocr_process] error", exc_info=1)
203 result_obj = { 211 return result_obj
204 'customerName': '', 212
205 'application': '', 213 @staticmethod
206 'deMortgageDate': '' 214 def de_mortgage_ocr_process1(img_base64):
207 } 215 result_obj = {
216 'customerName': '',
217 'application': '',
218 'deMortgageDate': ''
219 }
220 url = conf.OCR_URL_FOLDER
221 json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"}
222 try:
223 response = requests.post(url, json=json_data)
224 # unicode转中文
225 response.encoding = 'unicode_escape'
226 if response.status_code != 200:
227 LoggerMixin.exception_log.error(
228 "[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s",
229 url, response.text)
230 return result_obj
231 result = response.json()
232 data = result.get('data', [])
233 for item in data:
234 ocr_res = item.get('data', {})
235 if ocr_res.get('page', '') == 'page_34':
236 words_result = ocr_res.get('words_result', {})
237 registration_bar = words_result.get('registration_bar', [])
238 for registration in registration_bar:
239 if registration.get('register_type', '') == '抵押登记':
240 register_info = registration.get('register_info', {})
241 result_obj['application'] = register_info.get('抵押权人姓名/名称', '')
242 elif registration.get('register_type', '') == '解除抵押':
243 register_info = registration.get('register_info', {})
244 result_obj['deMortgageDate'] = register_info.get('解除抵押日期', '')
245 elif ocr_res.get('page', '') == 'page_12':
246 words_result = ocr_res.get('words_result', {})
247 for _, word_result in words_result.items():
248 if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码':
249 result_obj['customerName'] = word_result.get('words', '').split('/')[0]
250 except Exception as e:
251 LoggerMixin.exception_log.error("[PosHandler de_mortgage_ocr_process1] error", exc_info=1)
208 return result_obj 252 return result_obj
......
...@@ -804,8 +804,6 @@ class SECompareView(GenericView, PreSEHandler): ...@@ -804,8 +804,6 @@ 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)
809 start_time = time.time() 807 start_time = time.time()
810 log_base = '[prese]' 808 log_base = '[prese]'
811 # 存库 809 # 存库
......
...@@ -5,6 +5,7 @@ from apps.doc.views import CustomDecimal, CustomDate ...@@ -5,6 +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 rest_framework.permissions import IsAuthenticated 9 from rest_framework.permissions import IsAuthenticated
9 from apps.account.authentication import OAuth2AuthenticationWithUser 10 from apps.account.authentication import OAuth2AuthenticationWithUser
10 11
...@@ -36,18 +37,18 @@ class NSCInvoiceView(GenericView): ...@@ -36,18 +37,18 @@ class NSCInvoiceView(GenericView):
36 @use_args(input_args, location='data') 37 @use_args(input_args, location='data')
37 def post(self, request, args): # interface_report mpos to ocr 38 def post(self, request, args): # interface_report mpos to ocr
38 content = args.get('content', {}) 39 content = args.get('content', {})
39 invoice_code = content['invoiceCode'] 40 invoice_code = content.get('invoiceCode', '')
40 invoice_number = content['invoiceNumber'] 41 invoice_number = content.get('invoiceNumber', '')
41 issue_date = content['issueDate'] 42 issue_date = content.get('issueDate', None)
42 buyer_name = content['buyerName'] 43 buyer_name = content.get('buyerName', '')
43 buyer_id = content['buyerId'] 44 buyer_id = content.get('buyerId', 0)
44 vin = content['vin'] 45 vin = content.get('vin', '')
45 dealer = content['dealer'] 46 dealer = content.get('dealer', '')
46 price_with_vat = content['priceWithVat'] 47 price_with_vat = content.get('priceWithVat', 0.0)
47 price_no_vat = content['priceNoVat'] 48 price_no_vat = content.get('priceNoVat', 0.0)
48 price_in_capitals = content['priceInCapitals'] 49 price_in_capitals = content.get('priceInCapitals', '')
49 vat = content['vat'] 50 vat = content.get('vat', 0.0)
50 vat_rate = content['vatRate'] 51 vat_rate = content.get('vatRate', 0.0)
51 52
52 return response.ok() 53 return response.ok()
53 54
...@@ -68,46 +69,50 @@ de_mortgage_comments = { ...@@ -68,46 +69,50 @@ de_mortgage_comments = {
68 69
69 70
70 # 解除抵押识别处理 71 # 解除抵押识别处理
71 # class DeMortgageView(GenericView): 72 class DeMortgageView(GenericView):
72 # @use_args(de_mortgage_args, location='data') 73 permission_classes = [IsAuthenticated]
73 # def post(self, request, args): # interface_report mpos to ocr 74 authentication_classes = [OAuth2AuthenticationWithUser]
74 # img_files = args.get('file_base64', []) 75
75 # customer_name = args.get('customerName', '') 76 @use_args(de_mortgage_args, location='data')
76 # application = args.get('application', '') 77 def post(self, request, args): # interface_report mpos to ocr
77 # de_mortgage_date = args.get('deMortgageDate') 78 img_files = args.get('file_base64', [])
78 # 79 customer_name = args.get('customerName', '')
79 # fields_input = { 80 application = args.get('application', '')
80 # 'customerName': customer_name, 81 de_mortgage_date = args.get('deMortgageDate')
81 # 'application': application, 82
82 # 'deMortgageDate': de_mortgage_date 83 fields_input = {
83 # } 84 'customerName': customer_name,
84 # de_mortgage_info = {} 85 'application': application,
85 # # 绿本必须分开ocr 86 'deMortgageDate': de_mortgage_date
86 # for img_file in img_files: 87 }
87 # info = PosHandler.de_mortgage_ocr_process(img_file) 88 de_mortgage_info = {}
88 # de_mortgage_info.update(info) 89 # 绿本必须分开ocr
89 # 90 for img_file in img_files:
90 # request_pass = True 91 info = PosHandler.de_mortgage_ocr_process1(img_file)
91 # fields_result = [] 92 de_mortgage_info.update(info)
92 # for field_name, input_val in enumerate(fields_input): 93
93 # field_result = { 94 request_pass = True
94 # "name": field_name, 95 fields_result = []
95 # "input": input_val, 96 for field_name, input_val in fields_input.items():
96 # "ocr": de_mortgage_info.get(field_name, ''), 97 field_result = {
97 # "field_is_pass": False, 98 "name": field_name,
98 # "comments": '' 99 "input": input_val,
99 # } 100 "ocr": de_mortgage_info.get(field_name, ''),
100 # result, _ = cp.common_compare(field_result['input'], field_result['ocr']) 101 "field_is_pass": False,
101 # if result == cp.RESULT_Y: 102 "comments": ''
102 # fields_result['field_is_pass'] = result 103 }
103 # else: 104 result, _ = cp.common_compare(field_result['input'], field_result['ocr'])
104 # request_pass = False 105 if result == cp.RESULT_Y:
105 # fields_result['comments'] = de_mortgage_comments.get(field_name, '') 106 fields_result['field_is_pass'] = result
106 # 107 else:
107 # fields_result.append(field_result) 108 request_pass = False
108 # 109 fields_result['comments'] = de_mortgage_comments.get(field_name, '')
109 # result = { 110
110 # "is_pass": request_pass, 111 fields_result.append(field_result)
111 # "fields": fields_result 112
112 # } 113 result = {
113 # return response.ok(data=result) 114 "is_pass": request_pass,
115 "fields": fields_result
116 }
117 return response.ok(data=result)
118
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!