diff --git a/src/apps/doc/management/commands/ocr_process.py b/src/apps/doc/management/commands/ocr_process.py index df4c385..32e6b06 100644 --- a/src/apps/doc/management/commands/ocr_process.py +++ b/src/apps/doc/management/commands/ocr_process.py @@ -888,40 +888,53 @@ class Command(BaseCommand, LoggerMixin): os.remove(excel_path) finally: # TODO 识别结果存一张表,方便跑报表 - # 更新OCR累计识别结果表 - result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult - res_obj = result_class.objects.filter(application_id=doc.application_id).first() - if res_obj is None: - res_obj = result_class() - for classify, field in consts.RESULT_MAPPING.items(): - license_list = license_summary.get(classify) - if not license_list: - continue - if classify == consts.IC_CLASSIFY and ic_merge: - new_res_list = list() - new_res_list.append(license_list[0].update(license_list[1])) - license_list = new_res_list - new_res_list = None - elif classify == consts.RP_CLASSIFY and rp_merge: - new_res_list = list() - new_res_list.append(license_list[0].update(license_list[1])) - license_list = new_res_list - new_res_list = None - old_res_str = getattr(res_obj, field) - if old_res_str is None: - last_res_str = json.dumps(license_list) + try: + # 更新OCR累计识别结果表 + result_class = HILOCRResult if business_type == consts.HIL_PREFIX else AFCOCRResult + res_obj = result_class.objects.filter(application_id=doc.application_id).first() + if res_obj is None: + res_obj = result_class() + res_obj.application_id = doc.application_id + for classify, field in consts.RESULT_MAPPING.items(): + license_list = license_summary.get(classify) + if not license_list: + continue + if classify == consts.IC_CLASSIFY and ic_merge: + license_list[0].update(license_list[1]) + license_list.pop(1) + elif classify == consts.RP_CLASSIFY and rp_merge: + license_list[0].update(license_list[1]) + license_list.pop(1) + if not hasattr(res_obj, field): + continue + old_res_str = getattr(res_obj, field) + if old_res_str is None: + last_res_str = json.dumps(license_list) + else: + old_res_list = json.loads(old_res_str) + old_res_list.extend(license_list) + last_res_str = json.dumps(old_res_list) + setattr(res_obj, field, last_res_str) + res_obj.save() + except Exception as e: + self.online_log.error( + '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( + self.log_base, task_str, traceback.format_exc())) + else: + self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( + self.log_base, task_str, res_obj.id)) + # 触发比对 + try: + pass + # compare.apply_async((doc.application_id, business_type, None, res_obj.id), + # queue='queue_compare') + except Exception as e: + self.online_log.error( + '{0} [process error (comparison info send)] [task={1}] [error={2}]'.format( + self.log_base, task_str, traceback.format_exc())) else: - old_res_list = json.loads(old_res_str) - old_res_list.extend(license_list) - last_res_str = json.dumps(old_res_list) - setattr(res_obj, field, last_res_str) - res_obj.save() - - self.online_log.info('{0} [ocr result save success] [task={1}] [res_id={2}]'.format( - self.log_base, task_str, res_obj.id)) - - # 触发比对 - # compare.apply_async((doc.application_id, business_type, None, ocr_res_id), queue='queue_compare') + self.online_log.info('{0} [comparison info send success] [task={1}] ' + '[res_id={2}]'.format(self.log_base, task_str, res_obj.id)) finally: try: img_save_path = os.path.join(doc_data_path, 'img') @@ -929,7 +942,7 @@ class Command(BaseCommand, LoggerMixin): shutil.rmtree(img_save_path, ignore_errors=True) pdf_path = os.path.join(doc_data_path, '{0}.pdf'.format(doc_id_str)) os.remove(pdf_path) - self.online_log.info('{0} [pdf & img remove] [task={1}]'.format(self.log_base, task_str)) + self.online_log.info('{0} [pdf & img removed] [task={1}]'.format(self.log_base, task_str)) except Exception as e: self.online_log.error('{0} [process error (pdf & img remove)] [task={1}] [error={2}]'.format( self.log_base, task_str, traceback.format_exc())) diff --git a/src/apps/doc/views.py b/src/apps/doc/views.py index 4355679..bc4ab6c 100644 --- a/src/apps/doc/views.py +++ b/src/apps/doc/views.py @@ -332,8 +332,8 @@ class CompareView(GenericView): application_id = content.get('applicationId') individual_cus_info = json.dumps(content.get('individualCusInfo')) usedcar_info = json.dumps(content.get('usedCarInfo')) if isinstance(content.get('usedCarInfo'), dict) else None - corporate_cus_info = json.dumps(content.get('corporateCusInfo')) if isinstance(content.get('corporateCusInfo'), - dict) else None + corporate_cus_info = json.dumps(content.get('corporateCusInfo')) if isinstance( + content.get('corporateCusInfo'), dict) else None comparison_class = HILComparisonInfo if business_type in consts.HIL_SET else AFCComparisonInfo comparison_class.objects.create( uniq_seq=uniq_seq,