de_mortgage 接口更新,兼容不同文档类型
Showing
2 changed files
with
25 additions
and
12 deletions
... | @@ -211,12 +211,7 @@ class PosHandler: | ... | @@ -211,12 +211,7 @@ class PosHandler: |
211 | return result_obj | 211 | return result_obj |
212 | 212 | ||
213 | @staticmethod | 213 | @staticmethod |
214 | def de_mortgage_ocr_process1(img_base64): | 214 | def greenbook_process(result_obj, img_base64): |
215 | result_obj = { | ||
216 | 'customerName': '', | ||
217 | 'application': '', | ||
218 | 'deMortgageDate': '' | ||
219 | } | ||
220 | url = conf.OCR_URL_FOLDER | 215 | url = conf.OCR_URL_FOLDER |
221 | json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"} | 216 | json_data = {"file": img_base64, "classify": consts.MVC_CLASSIFY, "version": "green"} |
222 | try: | 217 | try: |
... | @@ -227,7 +222,7 @@ class PosHandler: | ... | @@ -227,7 +222,7 @@ class PosHandler: |
227 | LoggerMixin.exception_log.error( | 222 | LoggerMixin.exception_log.error( |
228 | "[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s", | 223 | "[PosHandler de_mortgage_ocr_process1] request error, url: %s, response: %s", |
229 | url, response.text) | 224 | url, response.text) |
230 | return result_obj | 225 | return |
231 | result = response.json() | 226 | result = response.json() |
232 | data = result.get('data', []) | 227 | data = result.get('data', []) |
233 | for item in data: | 228 | for item in data: |
... | @@ -248,5 +243,18 @@ class PosHandler: | ... | @@ -248,5 +243,18 @@ class PosHandler: |
248 | if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码': | 243 | if word_result.get('chinese_key', '') == '1.机动车所有人/身份证名称/号码': |
249 | result_obj['customerName'] = word_result.get('words', '').split('/')[0] | 244 | result_obj['customerName'] = word_result.get('words', '').split('/')[0] |
250 | except Exception as e: | 245 | except Exception as e: |
251 | LoggerMixin.exception_log.error("[PosHandler de_mortgage_ocr_process1] error", exc_info=1) | 246 | LoggerMixin.exception_log.error("[PosHandler greenbook_process] error", exc_info=1) |
247 | |||
248 | @staticmethod | ||
249 | def de_mortgage_ocr_process1(file_obj): | ||
250 | result_obj = { | ||
251 | 'customerName': '', | ||
252 | 'application': '', | ||
253 | 'deMortgageDate': '' | ||
254 | } | ||
255 | |||
256 | doc_type = file_obj.get('documentType', '') | ||
257 | img_base64 = file_obj.get('fileBase64') | ||
258 | if doc_type == 'Greenbook': | ||
259 | PosHandler.greenbook_process(result_obj, img_base64) | ||
252 | return result_obj | 260 | return result_obj | ... | ... |
... | @@ -53,11 +53,16 @@ class NSCInvoiceView(GenericView): | ... | @@ -53,11 +53,16 @@ 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 | 'application': fields.Str(required=True, validate=validate.Length(max=64)), |
59 | 'deMortgageDate': fields.Date(required=True), | 64 | 'deMortgageDate': fields.Date(required=True), |
60 | 'file_base64': fields.List(fields.Str(), required=True, validate=validate.Length(min=1)), | 65 | 'files': fields.Nested(file_param, required=True), |
61 | } | 66 | } |
62 | 67 | ||
63 | 68 | ||
... | @@ -75,7 +80,7 @@ class DeMortgageView(GenericView): | ... | @@ -75,7 +80,7 @@ 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 = args.get('application', '') |
81 | de_mortgage_date = args.get('deMortgageDate') | 86 | de_mortgage_date = args.get('deMortgageDate') |
... | @@ -87,8 +92,8 @@ class DeMortgageView(GenericView): | ... | @@ -87,8 +92,8 @@ class DeMortgageView(GenericView): |
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 | ... | ... |
-
Please register or sign in to post a comment