Merge branch 'feature/uat-tmp' of gitlab.situdata.com:zhouweiqi/bmw-ocr into feature/uat-tmp
Showing
1 changed file
with
71 additions
and
13 deletions
| ... | @@ -60,8 +60,11 @@ from .mixins import DocHandler, MPOSHandler, PreSEHandler | ... | @@ -60,8 +60,11 @@ from .mixins import DocHandler, MPOSHandler, PreSEHandler |
| 60 | from . import consts | 60 | from . import consts |
| 61 | from apps.account.authentication import OAuth2AuthenticationWithUser | 61 | from apps.account.authentication import OAuth2AuthenticationWithUser |
| 62 | from celery_compare.tasks import compare, fsm_compare | 62 | from celery_compare.tasks import compare, fsm_compare |
| 63 | from prese.compare import get_empty_result | ||
| 63 | 64 | ||
| 64 | import time | 65 | import time |
| 66 | |||
| 67 | |||
| 65 | class CustomDate(fields.Date): | 68 | class CustomDate(fields.Date): |
| 66 | 69 | ||
| 67 | def _deserialize(self, value, attr, data, **kwargs): | 70 | def _deserialize(self, value, attr, data, **kwargs): |
| ... | @@ -558,6 +561,7 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -558,6 +561,7 @@ class UploadDocView(GenericView, DocHandler): |
| 558 | # authentication_classes = [] | 561 | # authentication_classes = [] |
| 559 | permission_classes = [IsAuthenticated] | 562 | permission_classes = [IsAuthenticated] |
| 560 | authentication_classes = [OAuth2AuthenticationWithUser] | 563 | authentication_classes = [OAuth2AuthenticationWithUser] |
| 564 | |||
| 561 | # required_scopes = ['write'] | 565 | # required_scopes = ['write'] |
| 562 | 566 | ||
| 563 | # 上传(接收)文件接口 | 567 | # 上传(接收)文件接口 |
| ... | @@ -582,7 +586,8 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -582,7 +586,8 @@ class UploadDocView(GenericView, DocHandler): |
| 582 | 586 | ||
| 583 | # fsm激活状态, 更新ocr_result 表fsm状态 | 587 | # fsm激活状态, 更新ocr_result 表fsm状态 |
| 584 | self.running_log.info('[doc upload applicationId-{0}] [applicationStatus-{1}, activated-{2}]' | 588 | self.running_log.info('[doc upload applicationId-{0}] [applicationStatus-{1}, activated-{2}]' |
| 585 | .format(application_id, application_status, True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False)) | 589 | .format(application_id, application_status, |
| 590 | True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False)) | ||
| 586 | if consts.FSM_ACTIVITED_STATUS.get(application_status): | 591 | if consts.FSM_ACTIVITED_STATUS.get(application_status): |
| 587 | result_class = None | 592 | result_class = None |
| 588 | if business_type == consts.HIL_PREFIX: | 593 | if business_type == consts.HIL_PREFIX: |
| ... | @@ -854,6 +859,9 @@ class CompareView(GenericView): | ... | @@ -854,6 +859,9 @@ class CompareView(GenericView): |
| 854 | ''' | 859 | ''' |
| 855 | 860 | ||
| 856 | 861 | ||
| 862 | pre_fsm_url = conf.PRE_FSM_URL | ||
| 863 | |||
| 864 | |||
| 857 | class SECompareView(GenericView, PreSEHandler): | 865 | class SECompareView(GenericView, PreSEHandler): |
| 858 | permission_classes = [IsAuthenticated] | 866 | permission_classes = [IsAuthenticated] |
| 859 | authentication_classes = [OAuth2AuthenticationWithUser] | 867 | authentication_classes = [OAuth2AuthenticationWithUser] |
| ... | @@ -876,6 +884,50 @@ class SECompareView(GenericView, PreSEHandler): | ... | @@ -876,6 +884,50 @@ class SECompareView(GenericView, PreSEHandler): |
| 876 | fsm_best_price = content.get('fsmBestPrice', False) | 884 | fsm_best_price = content.get('fsmBestPrice', False) |
| 877 | fsm_landing_dealer = content.get('fsmLandingDealer') | 885 | fsm_landing_dealer = content.get('fsmLandingDealer') |
| 878 | 886 | ||
| 887 | if fsm_special_car: | ||
| 888 | compare_result = { | ||
| 889 | "is_pass": False, | ||
| 890 | "particulars": [{ | ||
| 891 | "object_name": "", | ||
| 892 | "fields": [{ | ||
| 893 | "input": "", | ||
| 894 | "ocr": "", | ||
| 895 | "field_is_pass": False, | ||
| 896 | "comments": "此申请为FSM 特殊申请,暂不支持预放款流程" | ||
| 897 | }] | ||
| 898 | }] | ||
| 899 | } | ||
| 900 | elif fsm_best_price: | ||
| 901 | compare_result = { | ||
| 902 | "is_pass": False, | ||
| 903 | "particulars": [{ | ||
| 904 | "object_name": "", | ||
| 905 | "fields": [{ | ||
| 906 | "input": "", | ||
| 907 | "ocr": "", | ||
| 908 | "field_is_pass": False, | ||
| 909 | "comments": "此申请为FSM 特殊申请,暂不支持预放款流程" | ||
| 910 | }] | ||
| 911 | }] | ||
| 912 | } | ||
| 913 | elif fsm_flag and (not fsm_special_car or not fsm_best_price): | ||
| 914 | # 调用Java pre fsm接口 | ||
| 915 | try: | ||
| 916 | self.running_log.info("{0} request java pre fsm api, url:{1}, body:{2}".format(log_base, pre_fsm_url, json.dumps(content))) | ||
| 917 | headers = { | ||
| 918 | 'Content-Type': 'application/json' | ||
| 919 | } | ||
| 920 | resp = requests.post(pre_fsm_url, headers=headers, json=content) | ||
| 921 | self.running_log.info("{0} response from java pre fsm api, resp:{1}".format(log_base, resp.text)) | ||
| 922 | result = json.loads(resp.text) | ||
| 923 | compare_result = result.get("result") | ||
| 924 | if not compare_result: | ||
| 925 | compare_result = get_empty_result() | ||
| 926 | except Exception as e: | ||
| 927 | self.running_log.error("{0} pre fsm request to java error, url:{1}, param:{2}, errorMsg:{3}".format( | ||
| 928 | log_base, pre_fsm_url, json.dumps(content), traceback.format_exc())) | ||
| 929 | compare_result = get_empty_result() | ||
| 930 | elif not fsm_flag: | ||
| 879 | # 存库, 用于银行卡比对 | 931 | # 存库, 用于银行卡比对 |
| 880 | try: | 932 | try: |
| 881 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification | 933 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification |
| ... | @@ -899,7 +951,8 @@ class SECompareView(GenericView, PreSEHandler): | ... | @@ -899,7 +951,8 @@ class SECompareView(GenericView, PreSEHandler): |
| 899 | # preSettlement比对 | 951 | # preSettlement比对 |
| 900 | compare_result = self.pre_compare_entrance(content) | 952 | compare_result = self.pre_compare_entrance(content) |
| 901 | self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] ' | 953 | self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] ' |
| 902 | '[result={4}]'.format(log_base, business_type, application_id, uniq_seq, compare_result)) | 954 | '[result={4}]'.format(log_base, business_type, application_id, uniq_seq, |
| 955 | compare_result)) | ||
| 903 | 956 | ||
| 904 | try: | 957 | try: |
| 905 | end_time = time.time() | 958 | end_time = time.time() |
| ... | @@ -1002,10 +1055,10 @@ class DocView(GenericView, DocHandler): | ... | @@ -1002,10 +1055,10 @@ class DocView(GenericView, DocHandler): |
| 1002 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() | 1055 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() |
| 1003 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() | 1056 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() |
| 1004 | upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start, | 1057 | upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start, |
| 1005 | upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1))\ | 1058 | upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1)) \ |
| 1006 | if upload_time_start is not None and upload_time_end is not None else Q() | 1059 | if upload_time_start is not None and upload_time_end is not None else Q() |
| 1007 | create_time_query = Q(create_time__gte=create_time_start, | 1060 | create_time_query = Q(create_time__gte=create_time_start, |
| 1008 | create_time__lt=create_time_end + datetime.timedelta(days=1))\ | 1061 | create_time__lt=create_time_end + datetime.timedelta(days=1)) \ |
| 1009 | if create_time_start is not None and create_time_end is not None else Q() | 1062 | if create_time_start is not None and create_time_end is not None else Q() |
| 1010 | query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query | 1063 | query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query |
| 1011 | val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source', | 1064 | val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source', |
| ... | @@ -1017,10 +1070,11 @@ class DocView(GenericView, DocHandler): | ... | @@ -1017,10 +1070,11 @@ class DocView(GenericView, DocHandler): |
| 1017 | if start_index >= total > 0: | 1070 | if start_index >= total > 0: |
| 1018 | raise self.invalid_params('页数不存在') | 1071 | raise self.invalid_params('页数不存在') |
| 1019 | 1072 | ||
| 1020 | doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[start_index: end_index] | 1073 | doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[ |
| 1074 | start_index: end_index] | ||
| 1021 | # doc_list = self.get_doc_list(doc_queryset, prefix) | 1075 | # doc_list = self.get_doc_list(doc_queryset, prefix) |
| 1022 | for doc_dict in doc_queryset: | 1076 | for doc_dict in doc_queryset: |
| 1023 | tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0]\ | 1077 | tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0] \ |
| 1024 | else consts.COMPARE_DOC_SCHEME_LIST[1] | 1078 | else consts.COMPARE_DOC_SCHEME_LIST[1] |
| 1025 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( | 1079 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( |
| 1026 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) | 1080 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) |
| ... | @@ -1067,7 +1121,6 @@ class DocView(GenericView, DocHandler): | ... | @@ -1067,7 +1121,6 @@ class DocView(GenericView, DocHandler): |
| 1067 | # os.remove(tmp_save_path) | 1121 | # os.remove(tmp_save_path) |
| 1068 | # raise self.invalid_params(msg='invalid params: PDF file XSS') | 1122 | # raise self.invalid_params(msg='invalid params: PDF file XSS') |
| 1069 | 1123 | ||
| 1070 | |||
| 1071 | file.close() | 1124 | file.close() |
| 1072 | # 1. 上传信息记录 | 1125 | # 1. 上传信息记录 |
| 1073 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) | 1126 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) |
| ... | @@ -1150,7 +1203,8 @@ class CompareResultView(GenericView): | ... | @@ -1150,7 +1203,8 @@ class CompareResultView(GenericView): |
| 1150 | latest_compared_time = '' | 1203 | latest_compared_time = '' |
| 1151 | else: | 1204 | else: |
| 1152 | whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N | 1205 | whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N |
| 1153 | latest_compared_time = '' if result_obj.ocr_latest_comparison_time is None else result_obj.ocr_latest_comparison_time.strftime('%Y-%m-%d %H:%M') | 1206 | latest_compared_time = '' if result_obj.ocr_latest_comparison_time is None else result_obj.ocr_latest_comparison_time.strftime( |
| 1207 | '%Y-%m-%d %H:%M') | ||
| 1154 | 1208 | ||
| 1155 | source = consts.INFO_SOURCE[1] | 1209 | source = consts.INFO_SOURCE[1] |
| 1156 | version = comments = '' | 1210 | version = comments = '' |
| ... | @@ -1166,7 +1220,8 @@ class CompareResultView(GenericView): | ... | @@ -1166,7 +1220,8 @@ class CompareResultView(GenericView): |
| 1166 | 'source': source, | 1220 | 'source': source, |
| 1167 | 'version': version, | 1221 | 'version': version, |
| 1168 | 'comments': comments, | 1222 | 'comments': comments, |
| 1169 | 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(result_obj.ocr_auto_result) | 1223 | 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads( |
| 1224 | result_obj.ocr_auto_result) | ||
| 1170 | } | 1225 | } |
| 1171 | 1226 | ||
| 1172 | return response.ok(data=compare_result) | 1227 | return response.ok(data=compare_result) |
| ... | @@ -1201,7 +1256,8 @@ class CompareResultView(GenericView): | ... | @@ -1201,7 +1256,8 @@ class CompareResultView(GenericView): |
| 1201 | 'id': 0 if result_obj is None else result_obj.id, | 1256 | 'id': 0 if result_obj is None else result_obj.id, |
| 1202 | 'application_id': case_id, | 1257 | 'application_id': case_id, |
| 1203 | 'entity': entity, | 1258 | 'entity': entity, |
| 1204 | 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else consts.DOC_SCHEME_LIST[1], | 1259 | 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else |
| 1260 | consts.DOC_SCHEME_LIST[1], | ||
| 1205 | 'whole_result': whole_result, | 1261 | 'whole_result': whole_result, |
| 1206 | 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'), | 1262 | 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'), |
| 1207 | 'source': source, | 1263 | 'source': source, |
| ... | @@ -1374,7 +1430,8 @@ class SECMSView(GenericView): | ... | @@ -1374,7 +1430,8 @@ class SECMSView(GenericView): |
| 1374 | 1430 | ||
| 1375 | args = request.data | 1431 | args = request.data |
| 1376 | cms_info = args.get('content', {}) | 1432 | cms_info = args.get('content', {}) |
| 1377 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX | 1433 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith( |
| 1434 | '宝马') else consts.HIL_PREFIX | ||
| 1378 | src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '') | 1435 | src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '') |
| 1379 | application_id = src_application_id[:src_application_id.rfind('-')] | 1436 | application_id = src_application_id[:src_application_id.rfind('-')] |
| 1380 | 1437 | ||
| ... | @@ -1430,7 +1487,8 @@ class SECMSView(GenericView): | ... | @@ -1430,7 +1487,8 @@ class SECMSView(GenericView): |
| 1430 | cms_status_info.create_time = datetime.datetime.now() | 1487 | cms_status_info.create_time = datetime.datetime.now() |
| 1431 | cms_status_info.save() | 1488 | cms_status_info.save() |
| 1432 | except Exception as e: | 1489 | except Exception as e: |
| 1433 | self.exception_log.exception('[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc())) | 1490 | self.exception_log.exception( |
| 1491 | '[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc())) | ||
| 1434 | fsm_compare.apply_async((application_id, business_type, None, None, False, True), | 1492 | fsm_compare.apply_async((application_id, business_type, None, None, False, True), |
| 1435 | queue='queue_compare') | 1493 | queue='queue_compare') |
| 1436 | else: | 1494 | else: |
| ... | @@ -1529,7 +1587,7 @@ class AutoSettlementView(GenericView): | ... | @@ -1529,7 +1587,7 @@ class AutoSettlementView(GenericView): |
| 1529 | whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q() | 1587 | whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q() |
| 1530 | rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q() | 1588 | rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q() |
| 1531 | time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start, | 1589 | time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start, |
| 1532 | rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1))\ | 1590 | rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1)) \ |
| 1533 | if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q() | 1591 | if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q() |
| 1534 | time2_query = Q(rpa_activated_time__gte=activated_time_start, | 1592 | time2_query = Q(rpa_activated_time__gte=activated_time_start, |
| 1535 | rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \ | 1593 | rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \ | ... | ... |
-
Please register or sign in to post a comment