fix ocr result save
Showing
2 changed files
with
49 additions
and
36 deletions
... | @@ -888,40 +888,53 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -888,40 +888,53 @@ class Command(BaseCommand, LoggerMixin): |
888 | os.remove(excel_path) | 888 | os.remove(excel_path) |
889 | finally: | 889 | finally: |
890 | # TODO 识别结果存一张表,方便跑报表 | 890 | # TODO 识别结果存一张表,方便跑报表 |
891 | # 更新OCR累计识别结果表 | 891 | try: |
892 | result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult | 892 | # 更新OCR累计识别结果表 |
893 | res_obj = result_class.objects.filter(application_id=doc.application_id).first() | 893 | result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult |
894 | if res_obj is None: | 894 | res_obj = result_class.objects.filter(application_id=doc.application_id).first() |
895 | res_obj = result_class() | 895 | if res_obj is None: |
896 | for classify, field in consts.RESULT_MAPPING.items(): | 896 | res_obj = result_class() |
897 | license_list = license_summary.get(classify) | 897 | res_obj.application_id = doc.application_id |
898 | if not license_list: | 898 | for classify, field in consts.RESULT_MAPPING.items(): |
899 | continue | 899 | license_list = license_summary.get(classify) |
900 | if classify == consts.IC_CLASSIFY and ic_merge: | 900 | if not license_list: |
901 | new_res_list = list() | 901 | continue |
902 | new_res_list.append(license_list[0].update(license_list[1])) | 902 | if classify == consts.IC_CLASSIFY and ic_merge: |
903 | license_list = new_res_list | 903 | license_list[0].update(license_list[1]) |
904 | new_res_list = None | 904 | license_list.pop(1) |
905 | elif classify == consts.RP_CLASSIFY and rp_merge: | 905 | elif classify == consts.RP_CLASSIFY and rp_merge: |
906 | new_res_list = list() | 906 | license_list[0].update(license_list[1]) |
907 | new_res_list.append(license_list[0].update(license_list[1])) | 907 | license_list.pop(1) |
908 | license_list = new_res_list | 908 | if not hasattr(res_obj, field): |
909 | new_res_list = None | 909 | continue |
910 | old_res_str = getattr(res_obj, field) | 910 | old_res_str = getattr(res_obj, field) |
911 | if old_res_str is None: | 911 | if old_res_str is None: |
912 | last_res_str = json.dumps(license_list) | 912 | last_res_str = json.dumps(license_list) |
913 | else: | ||
914 | old_res_list = json.loads(old_res_str) | ||
915 | old_res_list.extend(license_list) | ||
916 | last_res_str = json.dumps(old_res_list) | ||
917 | setattr(res_obj, field, last_res_str) | ||
918 | res_obj.save() | ||
919 | except Exception as e: | ||
920 | self.online_log.error( | ||
921 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | ||
922 | self.log_base, task_str, traceback.format_exc())) | ||
923 | else: | ||
924 | self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( | ||
925 | self.log_base, task_str, res_obj.id)) | ||
926 | # 触发比对 | ||
927 | try: | ||
928 | pass | ||
929 | # compare.apply_async((doc.application_id, business_type, None, res_obj.id), | ||
930 | # queue='queue_compare') | ||
931 | except Exception as e: | ||
932 | self.online_log.error( | ||
933 | '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format( | ||
934 | self.log_base, task_str, traceback.format_exc())) | ||
913 | else: | 935 | else: |
914 | old_res_list = json.loads(old_res_str) | 936 | self.online_log.info('{0} [comparison info send success] [task={1}] ' |
915 | old_res_list.extend(license_list) | 937 | '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) |
916 | last_res_str = json.dumps(old_res_list) | ||
917 | setattr(res_obj, field, last_res_str) | ||
918 | res_obj.save() | ||
919 | |||
920 | self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( | ||
921 | self.log_base, task_str, res_obj.id)) | ||
922 | |||
923 | # 触发比对 | ||
924 | # compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare') | ||
925 | finally: | 938 | finally: |
926 | try: | 939 | try: |
927 | img_save_path = os.path.join(doc_data_path, 'img') | 940 | img_save_path = os.path.join(doc_data_path, 'img') |
... | @@ -929,7 +942,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -929,7 +942,7 @@ class Command(BaseCommand, LoggerMixin): |
929 | shutil.rmtree(img_save_path, ignore_errors=True) | 942 | shutil.rmtree(img_save_path, ignore_errors=True) |
930 | pdf_path = os.path.join(doc_data_path, '{0}.pdf'.format(doc_id_str)) | 943 | pdf_path = os.path.join(doc_data_path, '{0}.pdf'.format(doc_id_str)) |
931 | os.remove(pdf_path) | 944 | os.remove(pdf_path) |
932 | self.online_log.info('{0} [pdf & img remove] [task={1}]'.format(self.log_base, task_str)) | 945 | self.online_log.info('{0} [pdf & img removed] [task={1}]'.format(self.log_base, task_str)) |
933 | except Exception as e: | 946 | except Exception as e: |
934 | self.online_log.error('{0} [process error (pdf & img remove)] [task={1}] [error={2}]'.format( | 947 | self.online_log.error('{0} [process error (pdf & img remove)] [task={1}] [error={2}]'.format( |
935 | self.log_base, task_str, traceback.format_exc())) | 948 | self.log_base, task_str, traceback.format_exc())) | ... | ... |
... | @@ -332,8 +332,8 @@ class CompareView(GenericView): | ... | @@ -332,8 +332,8 @@ class CompareView(GenericView): |
332 | application_id = content.get('applicationId') | 332 | application_id = content.get('applicationId') |
333 | individual_cus_info = json.dumps(content.get('individualCusInfo')) | 333 | individual_cus_info = json.dumps(content.get('individualCusInfo')) |
334 | usedcar_info = json.dumps(content.get('usedCarInfo')) if isinstance(content.get('usedCarInfo'), dict) else None | 334 | usedcar_info = json.dumps(content.get('usedCarInfo')) if isinstance(content.get('usedCarInfo'), dict) else None |
335 | corporate_cus_info = json.dumps(content.get('corporateCusInfo')) if isinstance(content.get('corporateCusInfo'), | 335 | corporate_cus_info = json.dumps(content.get('corporateCusInfo')) if isinstance( |
336 | dict) else None | 336 | content.get('corporateCusInfo'), dict) else None |
337 | comparison_class = HILComparisonInfo if business_type in consts.HIL_SET else AFCComparisonInfo | 337 | comparison_class = HILComparisonInfo if business_type in consts.HIL_SET else AFCComparisonInfo |
338 | comparison_class.objects.create( | 338 | comparison_class.objects.create( |
339 | uniq_seq=uniq_seq, | 339 | uniq_seq=uniq_seq, | ... | ... |
-
Please register or sign in to post a comment