Merge branch 'hotfix/2025-02'
Showing
3 changed files
with
196 additions
and
157 deletions
... | @@ -2130,10 +2130,20 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2130,10 +2130,20 @@ class Command(BaseCommand, LoggerMixin): |
2130 | # 更新OCR累计识别结果表 | 2130 | # 更新OCR累计识别结果表 |
2131 | if business_type == consts.HIL_PREFIX: | 2131 | if business_type == consts.HIL_PREFIX: |
2132 | result_class = HILOCRResult if is_ca else HILSEOCRResult | 2132 | result_class = HILOCRResult if is_ca else HILSEOCRResult |
2133 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | 2133 | try: |
2134 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2135 | except Exception as e: | ||
2136 | # 遇到报错重试一次,希望解决两个文件首次入库都插入的问题 | ||
2137 | self.online_log.error('{0} [process error (ocr result save) retry] [task={1}] [error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
2138 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2134 | else: | 2139 | else: |
2135 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2140 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2136 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | 2141 | try: |
2142 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2143 | except Exception as e: | ||
2144 | # 遇到报错重试一次,希望解决两个文件首次入库都插入的问题 | ||
2145 | self.online_log.error('{0} [process error (ocr result save) retry] [task={1}] [error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
2146 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2137 | 2147 | ||
2138 | except Exception as e: | 2148 | except Exception as e: |
2139 | self.online_log.error( | 2149 | self.online_log.error( |
... | @@ -2172,10 +2182,20 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -2172,10 +2182,20 @@ class Command(BaseCommand, LoggerMixin): |
2172 | # 更新OCR累计识别结果表 | 2182 | # 更新OCR累计识别结果表 |
2173 | if business_type == consts.HIL_PREFIX: | 2183 | if business_type == consts.HIL_PREFIX: |
2174 | result_class = HILOCRResult if is_ca else HILSEOCRResult | 2184 | result_class = HILOCRResult if is_ca else HILSEOCRResult |
2175 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | 2185 | try: |
2186 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2187 | except Exception as e: | ||
2188 | # 遇到报错重试一次,希望解决两个文件首次入库都插入的问题 | ||
2189 | self.online_log.error('{0} [process error (ocr result save) retry] [task={1}] [error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
2190 | res_obj = atomicSaveDBHIL(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2176 | else: | 2191 | else: |
2177 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult | 2192 | result_class = AFCOCRResult if is_ca else AFCSEOCRResult |
2178 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | 2193 | try: |
2194 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2195 | except Exception as e: | ||
2196 | # 遇到报错重试一次,希望解决两个文件首次入库都插入的问题 | ||
2197 | self.online_log.error('{0} [process error (ocr result save) retry] [task={1}] [error={2}]'.format(self.log_base, task_str, traceback.format_exc())) | ||
2198 | res_obj = atomicSaveDBAFC(self,result_class,doc,license_summary,ic_merge,rp_merge, task_str, financial_statement_dict, financial_explanation_dict) | ||
2179 | except Exception as e: | 2199 | except Exception as e: |
2180 | self.online_log.error( | 2200 | self.online_log.error( |
2181 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | 2201 | '{0} [process error (ocr result save)] [task={1}] [error={2}]'.format( | ... | ... |
... | @@ -3773,68 +3773,78 @@ def fsm_compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca= | ... | @@ -3773,68 +3773,78 @@ def fsm_compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca= |
3773 | 3773 | ||
3774 | compare_log.info('[fsm thread]') | 3774 | compare_log.info('[fsm thread]') |
3775 | #pool = ThreadPoolExecutor(max_workers=6, thread_name_prefix="fsm_thread_") | 3775 | #pool = ThreadPoolExecutor(max_workers=6, thread_name_prefix="fsm_thread_") |
3776 | pool.submit(fsm_compare_thread, application_id, application_entity, uniq_seq, ocr_res_id, is_ca, is_cms) | 3776 | try: |
3777 | # 这个try不生效 | ||
3778 | pool.submit(fsm_compare_thread, application_id, application_entity, uniq_seq, ocr_res_id, is_ca, is_cms) | ||
3779 | except Exception as e: | ||
3780 | compare_log.info('[fsm thread fail] [error={0}]'.format(traceback.format_exc())) | ||
3777 | #pool.shutdown(wait=True) | 3781 | #pool.shutdown(wait=True) |
3778 | 3782 | ||
3779 | 3783 | ||
3780 | def fsm_compare_thread(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True, is_cms=False): | 3784 | def fsm_compare_thread(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True, is_cms=False): |
3781 | compare_log.info('{0} [receive fsm task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}] ' | 3785 | try: |
3786 | compare_log.info('{0} [receive fsm task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}] ' | ||
3782 | '[is_cms={6}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, | 3787 | '[is_cms={6}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, |
3783 | is_ca, is_cms)) | 3788 | is_ca, is_cms)) |
3784 | 3789 | ||
3785 | # 查看此订单号下是否有未完成的文件,如果有,等1分钟 | 3790 | # 查看此订单号下是否有未完成的文件,如果有,等1分钟 |
3786 | doc_wait_file_class = HILDoc if application_entity == consts.HIL_PREFIX else AFCDoc | ||
3787 | doc_wait_file_result = doc_wait_file_class.objects.filter(application_id=application_id, status=1).first() | ||
3788 | compare_log.info('doc_wait_file_result:{0}'.format(doc_wait_file_result)) | ||
3789 | compare_log.info('{0} [comparison unfinished file check] [entity={1}] [id={2}] [doc_wait_file_result={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result)) | ||
3790 | if doc_wait_file_result is not None: | ||
3791 | # 实时查询延迟时间 | ||
3792 | try: | 3791 | try: |
3793 | delay_time_config = Configs.objects.filter(id=4).first() | 3792 | doc_wait_file_class = HILDoc if application_entity == consts.HIL_PREFIX else AFCDoc |
3794 | if delay_time_config is not None and delay_time_config.value is not None and delay_time_config.value.isdigit(): | 3793 | doc_wait_file_result = doc_wait_file_class.objects.filter(application_id=application_id, status=1).first() |
3795 | delay_time = delay_time_config.value | 3794 | compare_log.info('doc_wait_file_result:{0}'.format(doc_wait_file_result)) |
3796 | else: | 3795 | compare_log.info('{0} [comparison unfinished file check] [entity={1}] [id={2}] [doc_wait_file_result={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result)) |
3797 | delay_time = 0 | ||
3798 | except Exception as e: | 3796 | except Exception as e: |
3799 | delay_time = 0 | 3797 | doc_wait_file_result = None |
3800 | compare_log.info('[get delay_time_config fail] [error={0}]'.format(traceback.format_exc())) | 3798 | compare_log.info('[get doc_wait_file_result fail] [error={0}]'.format(traceback.format_exc())) |
3801 | compare_log.info('delay_time:{0}'.format(delay_time)) | 3799 | if doc_wait_file_result is not None: |
3802 | compare_log.info('{0} [comparison unfinished file wait delay_time start] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | 3800 | # 实时查询延迟时间 |
3803 | try: | 3801 | try: |
3804 | time.sleep(int(delay_time)) | 3802 | delay_time_config = Configs.objects.filter(id=4).first() |
3805 | except Exception as e: | 3803 | if delay_time_config is not None and delay_time_config.value is not None and delay_time_config.value.isdigit(): |
3806 | compare_log.info('[sleep error] [error={0}]'.format(traceback.format_exc())) | 3804 | delay_time = delay_time_config.value |
3807 | compare_log.info('{0} [comparison unfinished file wait delay_time end] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | 3805 | else: |
3806 | delay_time = 0 | ||
3807 | except Exception as e: | ||
3808 | delay_time = 0 | ||
3809 | compare_log.info('[get delay_time_config fail] [error={0}]'.format(traceback.format_exc())) | ||
3810 | compare_log.info('delay_time:{0}'.format(delay_time)) | ||
3811 | compare_log.info('{0} [comparison unfinished file wait delay_time start] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | ||
3812 | try: | ||
3813 | time.sleep(int(delay_time)) | ||
3814 | except Exception as e: | ||
3815 | compare_log.info('[sleep error] [error={0}]'.format(traceback.format_exc())) | ||
3816 | compare_log.info('{0} [comparison unfinished file wait delay_time end] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | ||
3808 | 3817 | ||
3818 | # 调用java fsm 比对流程接口(http) | ||
3819 | # 调用Java fsm 比对流程接口, fsm 是se流程, ca可以暂时忽略 | ||
3820 | auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement | ||
3821 | auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first() | ||
3822 | if auto_obj is not None: | ||
3823 | url = conf.FSM_AUTO_URL | ||
3824 | is_auto = True | ||
3825 | else: | ||
3826 | url = conf.FSM_URL | ||
3827 | is_auto = False | ||
3809 | 3828 | ||
3810 | # 调用java fsm 比对流程接口(http) | 3829 | body = { |
3811 | # 调用Java fsm 比对流程接口, fsm 是se流程, ca可以暂时忽略 | 3830 | 'applicationId': application_id, |
3812 | auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement | 3831 | 'businessType': application_entity, |
3813 | auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first() | 3832 | 'ocrResId': ocr_res_id, |
3814 | if auto_obj is not None: | 3833 | 'isCa': is_ca, |
3815 | url = conf.FSM_AUTO_URL | 3834 | 'isCms': is_cms |
3816 | is_auto = True | ||
3817 | else: | ||
3818 | url = conf.FSM_URL | ||
3819 | is_auto = False | ||
3820 | |||
3821 | body = { | ||
3822 | 'applicationId': application_id, | ||
3823 | 'businessType': application_entity, | ||
3824 | 'ocrResId': ocr_res_id, | ||
3825 | 'isCa': is_ca, | ||
3826 | 'isCms': is_cms | ||
3827 | } | ||
3828 | try: | ||
3829 | compare_log.info("request java fsm api, url:{0}, body:{1}, is_auto:{2}".format(url, json.dumps(body), is_auto)) | ||
3830 | headers = { | ||
3831 | 'Content-Type': 'application/json' | ||
3832 | } | 3835 | } |
3833 | resp = requests.post(url, headers=headers, json=body) | 3836 | try: |
3834 | compare_log.info("response from fsm api, resp:{0}".format(resp.text)) | 3837 | compare_log.info("request java fsm api, url:{0}, body:{1}, is_auto:{2}".format(url, json.dumps(body), is_auto)) |
3838 | headers = { | ||
3839 | 'Content-Type': 'application/json' | ||
3840 | } | ||
3841 | resp = requests.post(url, headers=headers, json=body) | ||
3842 | compare_log.info("response from fsm api, resp:{0}".format(resp.text)) | ||
3843 | except Exception as e: | ||
3844 | compare_log.error("fsm full request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | ||
3845 | url, json.dumps(body), traceback.format_exc())) | ||
3835 | except Exception as e: | 3846 | except Exception as e: |
3836 | compare_log.error("fsm full request to java error, url:{0}, param:{1}, errorMsg:{2}".format( | 3847 | compare_log.info('[fsm_compare_thread error] [error={0}]'.format(traceback.format_exc())) |
3837 | url, json.dumps(body), traceback.format_exc())) | ||
3838 | 3848 | ||
3839 | 3849 | ||
3840 | @app.task | 3850 | @app.task |
... | @@ -3851,122 +3861,131 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True | ... | @@ -3851,122 +3861,131 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True |
3851 | 3861 | ||
3852 | compare_log.info('[non fsm thread]') | 3862 | compare_log.info('[non fsm thread]') |
3853 | #pool = ThreadPoolExecutor(max_workers=6, thread_name_prefix="non_fsm_thread_") | 3863 | #pool = ThreadPoolExecutor(max_workers=6, thread_name_prefix="non_fsm_thread_") |
3854 | pool.submit(compare_thread, application_id, application_entity, uniq_seq, ocr_res_id, is_ca, is_cms) | 3864 | try: |
3865 | # 这个try不生效 | ||
3866 | pool.submit(compare_thread, application_id, application_entity, uniq_seq, ocr_res_id, is_ca, is_cms) | ||
3867 | except Exception as e: | ||
3868 | compare_log.info('[non fsm thread fail] [error={0}]'.format(traceback.format_exc())) | ||
3855 | #pool.shutdown(wait=True) | 3869 | #pool.shutdown(wait=True) |
3856 | 3870 | ||
3857 | def compare_thread(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True, is_cms=False): | 3871 | def compare_thread(application_id, application_entity, uniq_seq, ocr_res_id, is_ca=True, is_cms=False): |
3858 | # POS: application_id, application_entity, uniq_seq, None | 3872 | # POS: application_id, application_entity, uniq_seq, None |
3859 | # OCR: application_id, business_type(application_entity), None, ocr_res_id | 3873 | # OCR: application_id, business_type(application_entity), None, ocr_res_id |
3860 | 3874 | try: | |
3861 | compare_log.info('{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}] ' | 3875 | compare_log.info('{0} [receive task] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] [is_ca={5}] ' |
3862 | '[is_cms={6}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, | 3876 | '[is_cms={6}]'.format(log_base, application_entity, application_id, uniq_seq, ocr_res_id, |
3863 | is_ca, is_cms)) | 3877 | is_ca, is_cms)) |
3864 | 3878 | ||
3865 | # 查看此订单号下是否有未完成的文件,如果有,等?分钟 | 3879 | # 根据application_id查找最新的比对信息,如果没有,结束 |
3866 | doc_wait_file_class = HILDoc if application_entity == consts.HIL_PREFIX else AFCDoc | 3880 | if is_ca: |
3867 | doc_wait_file_result = doc_wait_file_class.objects.filter(application_id=application_id, status=1).first() | 3881 | comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo |
3868 | compare_log.info('doc_wait_file_result:{0}'.format(doc_wait_file_result)) | 3882 | else: |
3869 | compare_log.info('{0} [comparison unfinished file check] [entity={1}] [id={2}] [doc_wait_file_result={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result)) | 3883 | if application_entity == consts.HIL_PREFIX: |
3870 | if doc_wait_file_result is not None: | 3884 | comparison_class = HILSECMSInfo if is_cms else HILSEComparisonInfo |
3871 | # 实时查询延迟时间 | ||
3872 | try: | ||
3873 | delay_time_config = Configs.objects.filter(id=4).first() | ||
3874 | if delay_time_config is not None and delay_time_config.value is not None and delay_time_config.value.isdigit(): | ||
3875 | delay_time = delay_time_config.value | ||
3876 | else: | 3885 | else: |
3877 | delay_time = 0 | 3886 | comparison_class = AFCSECMSInfo if is_cms else AFCSEComparisonInfo |
3878 | except Exception as e: | 3887 | last_obj = comparison_class.objects.filter(application_id=application_id).last() |
3879 | delay_time = 0 | 3888 | if last_obj is None: |
3880 | compare_log.info('[get delay_time_config fail] [error={0}]'.format(traceback.format_exc())) | 3889 | compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' |
3881 | compare_log.info('delay_time:{0}'.format(delay_time)) | 3890 | '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id, uniq_seq, |
3882 | compare_log.info('{0} [comparison unfinished file wait delay_time start] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | 3891 | ocr_res_id, is_ca, is_cms)) |
3883 | try: | 3892 | return |
3884 | time.sleep(int(delay_time)) | ||
3885 | except Exception as e: | ||
3886 | compare_log.info('[sleep error] [error={0}]'.format(traceback.format_exc())) | ||
3887 | compare_log.info('{0} [comparison unfinished file wait delay_time end] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | ||
3888 | |||
3889 | 3893 | ||
3890 | # 根据application_id查找最新的比对信息,如果没有,结束 | 3894 | # 根据application_id查找OCR累计结果指定license字段,如果没有,结束 |
3891 | if is_ca: | 3895 | if is_ca: |
3892 | comparison_class = HILComparisonInfo if application_entity == consts.HIL_PREFIX else AFCComparisonInfo | 3896 | result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult |
3893 | else: | 3897 | ca_ocr_res_dict = dict() |
3894 | if application_entity == consts.HIL_PREFIX: | ||
3895 | comparison_class = HILSECMSInfo if is_cms else HILSEComparisonInfo | ||
3896 | else: | 3898 | else: |
3897 | comparison_class = AFCSECMSInfo if is_cms else AFCSEComparisonInfo | 3899 | result_class = HILSEOCRResult if application_entity == consts.HIL_PREFIX else AFCSEOCRResult |
3898 | last_obj = comparison_class.objects.filter(application_id=application_id).last() | 3900 | ca_result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult |
3899 | if last_obj is None: | 3901 | # if ocr_res_id is None: |
3900 | compare_log.info('{0} [comparison info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' | 3902 | ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values( |
3901 | '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id, uniq_seq, | 3903 | *consts.CA_ADD_COMPARE_FIELDS).first() |
3902 | ocr_res_id, is_ca, is_cms)) | 3904 | # else: |
3903 | return | 3905 | # ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values( |
3904 | 3906 | # *consts.CA_ADD_COMPARE_FIELDS).first() | |
3905 | # 根据application_id查找OCR累计结果指定license字段,如果没有,结束 | 3907 | if ocr_res_id is None: |
3906 | if is_ca: | 3908 | ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first() |
3907 | result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult | ||
3908 | ca_ocr_res_dict = dict() | ||
3909 | else: | ||
3910 | result_class = HILSEOCRResult if application_entity == consts.HIL_PREFIX else AFCSEOCRResult | ||
3911 | ca_result_class = HILOCRResult if application_entity == consts.HIL_PREFIX else AFCOCRResult | ||
3912 | # if ocr_res_id is None: | ||
3913 | ca_ocr_res_dict = ca_result_class.objects.filter(application_id=application_id).values( | ||
3914 | *consts.CA_ADD_COMPARE_FIELDS).first() | ||
3915 | # else: | ||
3916 | # ca_ocr_res_dict = ca_result_class.objects.filter(id=ocr_res_id).values( | ||
3917 | # *consts.CA_ADD_COMPARE_FIELDS).first() | ||
3918 | if ocr_res_id is None: | ||
3919 | ocr_res_dict = result_class.objects.filter(application_id=application_id).values(*consts.COMPARE_FIELDS).first() | ||
3920 | else: | ||
3921 | ocr_res_dict = result_class.objects.filter(id=ocr_res_id).values(*consts.COMPARE_FIELDS).first() | ||
3922 | if ocr_res_dict is None: | ||
3923 | compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' | ||
3924 | '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id, | ||
3925 | uniq_seq, ocr_res_id, is_ca, is_cms)) | ||
3926 | return | ||
3927 | |||
3928 | if is_ca: | ||
3929 | ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict) | ||
3930 | else: | ||
3931 | id_res_list = [] | ||
3932 | for field_name in consts.CA_ADD_COMPARE_FIELDS: | ||
3933 | if field_name == consts.IC_OCR_FIELD: | ||
3934 | id_res_list.append(ca_ocr_res_dict.get(field_name) if isinstance(ca_ocr_res_dict, dict) else None) | ||
3935 | id_res_list.append(ocr_res_dict.get(field_name)) | ||
3936 | |||
3937 | if isinstance(ca_ocr_res_dict, dict) and isinstance(ca_ocr_res_dict.get(field_name), str): | ||
3938 | tmp_ca_result = json.loads(ca_ocr_res_dict.get(field_name)) | ||
3939 | if isinstance(ocr_res_dict.get(field_name), str): | ||
3940 | tmp_se_result = json.loads(ocr_res_dict.get(field_name)) | ||
3941 | tmp_ca_result.extend(tmp_se_result) | ||
3942 | ocr_res_dict[field_name] = json.dumps(tmp_ca_result) | ||
3943 | # auto settlement | ||
3944 | auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement | ||
3945 | auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first() | ||
3946 | bank_class = HILbankVerification if application_entity == consts.HIL_PREFIX else AFCbankVerification | ||
3947 | ignore_bank = bank_class.objects.filter(application_id=application_id, on_off=True).exists() | ||
3948 | data_source = '' | ||
3949 | if application_entity == consts.AFC_PREFIX: | ||
3950 | doc_obj = AFCDoc.objects.filter(application_id=application_id, document_name__icontains='电子签署-车辆抵押贷款合同').last() | ||
3951 | if doc_obj is not None: | ||
3952 | data_source = doc_obj.data_source | ||
3953 | compare_log.info('{0} [get data_source] [id={1}] [data_source={2}]]'.format( | ||
3954 | log_base, application_id, data_source)) | ||
3955 | if auto_obj is not None: | ||
3956 | auto_result = se_compare_auto(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, auto_obj, ignore_bank, id_res_list, data_source) | ||
3957 | else: | 3909 | else: |
3958 | auto_result = None | 3910 | ocr_res_dict = result_class.objects.filter(id=ocr_res_id).values(*consts.COMPARE_FIELDS).first() |
3959 | 3911 | if ocr_res_dict is None: | |
3960 | full_result = se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms, auto_result, ignore_bank, id_res_list, data_source) | 3912 | compare_log.info('{0} [ocr info empty] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' |
3913 | '[is_ca={5}] [is_cms]={6}'.format(log_base, application_entity, application_id, | ||
3914 | uniq_seq, ocr_res_id, is_ca, is_cms)) | ||
3915 | return | ||
3961 | 3916 | ||
3962 | if auto_obj is not None: | 3917 | # 查看此订单号下是否有未完成的文件,如果有,等?分钟 |
3918 | try: | ||
3919 | doc_wait_file_class = HILDoc if application_entity == consts.HIL_PREFIX else AFCDoc | ||
3920 | doc_wait_file_result = doc_wait_file_class.objects.filter(application_id=application_id, status=1).first() | ||
3921 | compare_log.info('doc_wait_file_result:{0}'.format(doc_wait_file_result)) | ||
3922 | compare_log.info('{0} [comparison unfinished file check] [entity={1}] [id={2}] [doc_wait_file_result={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result)) | ||
3923 | except Exception as e: | ||
3924 | doc_wait_file_result = None | ||
3925 | compare_log.info('[get doc_wait_file_result fail] [error={0}]'.format(traceback.format_exc())) | ||
3926 | if doc_wait_file_result is not None: | ||
3927 | # 实时查询延迟时间 | ||
3963 | try: | 3928 | try: |
3964 | auto_obj.ocr_whole_result_pass = full_result | 3929 | delay_time_config = Configs.objects.filter(id=4).first() |
3965 | auto_obj.save() | 3930 | if delay_time_config is not None and delay_time_config.value is not None and delay_time_config.value.isdigit(): |
3966 | compare_log.info('{0} [Auto SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | 3931 | delay_time = delay_time_config.value |
3967 | log_base, application_entity, application_id, ocr_res_id)) | 3932 | else: |
3933 | delay_time = 0 | ||
3968 | except Exception as e: | 3934 | except Exception as e: |
3969 | compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' | 3935 | delay_time = 0 |
3970 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, | 3936 | compare_log.info('[get delay_time_config fail] [error={0}]'.format(traceback.format_exc())) |
3971 | traceback.format_exc())) | 3937 | compare_log.info('delay_time:{0}'.format(delay_time)) |
3938 | compare_log.info('{0} [comparison unfinished file wait delay_time start] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | ||
3939 | try: | ||
3940 | time.sleep(int(delay_time)) | ||
3941 | except Exception as e: | ||
3942 | compare_log.info('[sleep error] [error={0}]'.format(traceback.format_exc())) | ||
3943 | compare_log.info('{0} [comparison unfinished file wait delay_time end] [entity={1}] [id={2}] [doc_id={3}]'.format(log_base, application_entity, application_id, doc_wait_file_result.id)) | ||
3972 | 3944 | ||
3945 | |||
3946 | if is_ca: | ||
3947 | ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict) | ||
3948 | else: | ||
3949 | id_res_list = [] | ||
3950 | for field_name in consts.CA_ADD_COMPARE_FIELDS: | ||
3951 | if field_name == consts.IC_OCR_FIELD: | ||
3952 | id_res_list.append(ca_ocr_res_dict.get(field_name) if isinstance(ca_ocr_res_dict, dict) else None) | ||
3953 | id_res_list.append(ocr_res_dict.get(field_name)) | ||
3954 | |||
3955 | if isinstance(ca_ocr_res_dict, dict) and isinstance(ca_ocr_res_dict.get(field_name), str): | ||
3956 | tmp_ca_result = json.loads(ca_ocr_res_dict.get(field_name)) | ||
3957 | if isinstance(ocr_res_dict.get(field_name), str): | ||
3958 | tmp_se_result = json.loads(ocr_res_dict.get(field_name)) | ||
3959 | tmp_ca_result.extend(tmp_se_result) | ||
3960 | ocr_res_dict[field_name] = json.dumps(tmp_ca_result) | ||
3961 | # auto settlement | ||
3962 | auto_class = HILAutoSettlement if application_entity == consts.HIL_PREFIX else AFCAutoSettlement | ||
3963 | auto_obj = auto_class.objects.filter(application_id=application_id, on_off=True).first() | ||
3964 | bank_class = HILbankVerification if application_entity == consts.HIL_PREFIX else AFCbankVerification | ||
3965 | ignore_bank = bank_class.objects.filter(application_id=application_id, on_off=True).exists() | ||
3966 | data_source = '' | ||
3967 | if application_entity == consts.AFC_PREFIX: | ||
3968 | doc_obj = AFCDoc.objects.filter(application_id=application_id, document_name__icontains='电子签署-车辆抵押贷款合同').last() | ||
3969 | if doc_obj is not None: | ||
3970 | data_source = doc_obj.data_source | ||
3971 | compare_log.info('{0} [get data_source] [id={1}] [data_source={2}]]'.format( | ||
3972 | log_base, application_id, data_source)) | ||
3973 | if auto_obj is not None: | ||
3974 | auto_result = se_compare_auto(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, auto_obj, ignore_bank, id_res_list, data_source) | ||
3975 | else: | ||
3976 | auto_result = None | ||
3977 | |||
3978 | full_result = se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res_dict, is_cms, auto_result, ignore_bank, id_res_list, data_source) | ||
3979 | |||
3980 | if auto_obj is not None: | ||
3981 | try: | ||
3982 | auto_obj.ocr_whole_result_pass = full_result | ||
3983 | auto_obj.save() | ||
3984 | compare_log.info('{0} [Auto SE] [result save success] [entity={1}] [id={2}] [ocr_res_id={3}]'.format( | ||
3985 | log_base, application_entity, application_id, ocr_res_id)) | ||
3986 | except Exception as e: | ||
3987 | compare_log.error('{0} [Auto SE] [result save error] [entity={1}] [id={2}] [ocr_res_id={3}] ' | ||
3988 | '[error={4}]'.format(log_base, application_entity, application_id, ocr_res_id, | ||
3989 | traceback.format_exc())) | ||
3990 | except Exception as e: | ||
3991 | compare_log.info('[compare_thread error] [error={0}]'.format(traceback.format_exc())) | ... | ... |
... | @@ -102,7 +102,7 @@ for db_setting in DATABASES.values(): | ... | @@ -102,7 +102,7 @@ for db_setting in DATABASES.values(): |
102 | 'driver': 'ODBC Driver 17 for SQL Server', | 102 | 'driver': 'ODBC Driver 17 for SQL Server', |
103 | 'extra_params': "odbc_cursortype=2" | 103 | 'extra_params': "odbc_cursortype=2" |
104 | } | 104 | } |
105 | 105 | db_setting['CONN_MAX_AGE'] = 60 | |
106 | # set this to False if you want to turn off pyodbc's connection pooling | 106 | # set this to False if you want to turn off pyodbc's connection pooling |
107 | DATABASE_CONNECTION_POOLING = True | 107 | DATABASE_CONNECTION_POOLING = True |
108 | 108 | ... | ... |
-
Please register or sign in to post a comment