pre fsm update
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): |
| ... | @@ -557,6 +560,7 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -557,6 +560,7 @@ class UploadDocView(GenericView, DocHandler): |
| 557 | # authentication_classes = [] | 560 | # authentication_classes = [] |
| 558 | permission_classes = [IsAuthenticated] | 561 | permission_classes = [IsAuthenticated] |
| 559 | authentication_classes = [OAuth2AuthenticationWithUser] | 562 | authentication_classes = [OAuth2AuthenticationWithUser] |
| 563 | |||
| 560 | # required_scopes = ['write'] | 564 | # required_scopes = ['write'] |
| 561 | 565 | ||
| 562 | # 上传(接收)文件接口 | 566 | # 上传(接收)文件接口 |
| ... | @@ -581,7 +585,8 @@ class UploadDocView(GenericView, DocHandler): | ... | @@ -581,7 +585,8 @@ class UploadDocView(GenericView, DocHandler): |
| 581 | 585 | ||
| 582 | # fsm激活状态, 更新ocr_result 表fsm状态 | 586 | # fsm激活状态, 更新ocr_result 表fsm状态 |
| 583 | self.running_log.info('[doc upload applicationId-{0}] [applicationStatus-{1}, activated-{2}]' | 587 | self.running_log.info('[doc upload applicationId-{0}] [applicationStatus-{1}, activated-{2}]' |
| 584 | .format(application_id, application_status, True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False)) | 588 | .format(application_id, application_status, |
| 589 | True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False)) | ||
| 585 | if consts.FSM_ACTIVITED_STATUS.get(application_status): | 590 | if consts.FSM_ACTIVITED_STATUS.get(application_status): |
| 586 | result_class = None | 591 | result_class = None |
| 587 | if business_type == consts.HIL_PREFIX: | 592 | if business_type == consts.HIL_PREFIX: |
| ... | @@ -843,6 +848,9 @@ class CompareView(GenericView): | ... | @@ -843,6 +848,9 @@ class CompareView(GenericView): |
| 843 | ''' | 848 | ''' |
| 844 | 849 | ||
| 845 | 850 | ||
| 851 | pre_fsm_url = conf.PRE_FSM_URL | ||
| 852 | |||
| 853 | |||
| 846 | class SECompareView(GenericView, PreSEHandler): | 854 | class SECompareView(GenericView, PreSEHandler): |
| 847 | permission_classes = [IsAuthenticated] | 855 | permission_classes = [IsAuthenticated] |
| 848 | authentication_classes = [OAuth2AuthenticationWithUser] | 856 | authentication_classes = [OAuth2AuthenticationWithUser] |
| ... | @@ -864,6 +872,50 @@ class SECompareView(GenericView, PreSEHandler): | ... | @@ -864,6 +872,50 @@ class SECompareView(GenericView, PreSEHandler): |
| 864 | fsm_special_car = content.get('fsmSpecialCar', False) | 872 | fsm_special_car = content.get('fsmSpecialCar', False) |
| 865 | fsm_best_price = content.get('fsmBestPrice', False) | 873 | fsm_best_price = content.get('fsmBestPrice', False) |
| 866 | 874 | ||
| 875 | if fsm_special_car: | ||
| 876 | compare_result = { | ||
| 877 | "is_pass": False, | ||
| 878 | "particulars": [{ | ||
| 879 | "object_name": "", | ||
| 880 | "fields": [{ | ||
| 881 | "input": "", | ||
| 882 | "ocr": "", | ||
| 883 | "field_is_pass": False, | ||
| 884 | "comments": "此申请为FSM 特殊申请,暂不支持预放款流程" | ||
| 885 | }] | ||
| 886 | }] | ||
| 887 | } | ||
| 888 | elif fsm_best_price: | ||
| 889 | compare_result = { | ||
| 890 | "is_pass": False, | ||
| 891 | "particulars": [{ | ||
| 892 | "object_name": "", | ||
| 893 | "fields": [{ | ||
| 894 | "input": "", | ||
| 895 | "ocr": "", | ||
| 896 | "field_is_pass": False, | ||
| 897 | "comments": "此申请为FSM 特殊申请,暂不支持预放款流程" | ||
| 898 | }] | ||
| 899 | }] | ||
| 900 | } | ||
| 901 | elif fsm_flag and (not fsm_special_car or not fsm_best_price): | ||
| 902 | # 调用Java pre fsm接口 | ||
| 903 | try: | ||
| 904 | self.running_log.info("{0} request java pre fsm api, url:{1}, body:{2}".format(log_base, pre_fsm_url, json.dumps(content))) | ||
| 905 | headers = { | ||
| 906 | 'Content-Type': 'application/json' | ||
| 907 | } | ||
| 908 | resp = requests.post(pre_fsm_url, headers=headers, json=content) | ||
| 909 | self.running_log.info("{0} response from java pre fsm api, resp:{1}".format(log_base, resp.text)) | ||
| 910 | result = json.loads(resp.text) | ||
| 911 | compare_result = result.get("result") | ||
| 912 | if not compare_result: | ||
| 913 | compare_result = get_empty_result() | ||
| 914 | except Exception as e: | ||
| 915 | self.running_log.error("{0} pre fsm request to java error, url:{1}, param:{2}, errorMsg:{3}".format( | ||
| 916 | log_base, pre_fsm_url, json.dumps(content), traceback.format_exc())) | ||
| 917 | compare_result = get_empty_result() | ||
| 918 | elif not fsm_flag: | ||
| 867 | # 存库, 用于银行卡比对 | 919 | # 存库, 用于银行卡比对 |
| 868 | try: | 920 | try: |
| 869 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification | 921 | bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification |
| ... | @@ -887,7 +939,8 @@ class SECompareView(GenericView, PreSEHandler): | ... | @@ -887,7 +939,8 @@ class SECompareView(GenericView, PreSEHandler): |
| 887 | # preSettlement比对 | 939 | # preSettlement比对 |
| 888 | compare_result = self.pre_compare_entrance(content) | 940 | compare_result = self.pre_compare_entrance(content) |
| 889 | self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] ' | 941 | self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] ' |
| 890 | '[result={4}]'.format(log_base, business_type, application_id, uniq_seq, compare_result)) | 942 | '[result={4}]'.format(log_base, business_type, application_id, uniq_seq, |
| 943 | compare_result)) | ||
| 891 | 944 | ||
| 892 | try: | 945 | try: |
| 893 | end_time = time.time() | 946 | end_time = time.time() |
| ... | @@ -990,10 +1043,10 @@ class DocView(GenericView, DocHandler): | ... | @@ -990,10 +1043,10 @@ class DocView(GenericView, DocHandler): |
| 990 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() | 1043 | application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q() |
| 991 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() | 1044 | data_source_query = Q(data_source=data_source) if data_source is not None else Q() |
| 992 | upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start, | 1045 | upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start, |
| 993 | upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1))\ | 1046 | upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1)) \ |
| 994 | if upload_time_start is not None and upload_time_end is not None else Q() | 1047 | if upload_time_start is not None and upload_time_end is not None else Q() |
| 995 | create_time_query = Q(create_time__gte=create_time_start, | 1048 | create_time_query = Q(create_time__gte=create_time_start, |
| 996 | create_time__lt=create_time_end + datetime.timedelta(days=1))\ | 1049 | create_time__lt=create_time_end + datetime.timedelta(days=1)) \ |
| 997 | if create_time_start is not None and create_time_end is not None else Q() | 1050 | if create_time_start is not None and create_time_end is not None else Q() |
| 998 | query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query | 1051 | query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query |
| 999 | val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source', | 1052 | val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source', |
| ... | @@ -1005,10 +1058,11 @@ class DocView(GenericView, DocHandler): | ... | @@ -1005,10 +1058,11 @@ class DocView(GenericView, DocHandler): |
| 1005 | if start_index >= total > 0: | 1058 | if start_index >= total > 0: |
| 1006 | raise self.invalid_params('页数不存在') | 1059 | raise self.invalid_params('页数不存在') |
| 1007 | 1060 | ||
| 1008 | doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[start_index: end_index] | 1061 | doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[ |
| 1062 | start_index: end_index] | ||
| 1009 | # doc_list = self.get_doc_list(doc_queryset, prefix) | 1063 | # doc_list = self.get_doc_list(doc_queryset, prefix) |
| 1010 | for doc_dict in doc_queryset: | 1064 | for doc_dict in doc_queryset: |
| 1011 | tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0]\ | 1065 | tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0] \ |
| 1012 | else consts.COMPARE_DOC_SCHEME_LIST[1] | 1066 | else consts.COMPARE_DOC_SCHEME_LIST[1] |
| 1013 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( | 1067 | application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format( |
| 1014 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) | 1068 | conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id']) |
| ... | @@ -1055,7 +1109,6 @@ class DocView(GenericView, DocHandler): | ... | @@ -1055,7 +1109,6 @@ class DocView(GenericView, DocHandler): |
| 1055 | # os.remove(tmp_save_path) | 1109 | # os.remove(tmp_save_path) |
| 1056 | # raise self.invalid_params(msg='invalid params: PDF file XSS') | 1110 | # raise self.invalid_params(msg='invalid params: PDF file XSS') |
| 1057 | 1111 | ||
| 1058 | |||
| 1059 | file.close() | 1112 | file.close() |
| 1060 | # 1. 上传信息记录 | 1113 | # 1. 上传信息记录 |
| 1061 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) | 1114 | application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id) |
| ... | @@ -1138,7 +1191,8 @@ class CompareResultView(GenericView): | ... | @@ -1138,7 +1191,8 @@ class CompareResultView(GenericView): |
| 1138 | latest_compared_time = '' | 1191 | latest_compared_time = '' |
| 1139 | else: | 1192 | else: |
| 1140 | whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N | 1193 | whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N |
| 1141 | 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') | 1194 | latest_compared_time = '' if result_obj.ocr_latest_comparison_time is None else result_obj.ocr_latest_comparison_time.strftime( |
| 1195 | '%Y-%m-%d %H:%M') | ||
| 1142 | 1196 | ||
| 1143 | source = consts.INFO_SOURCE[1] | 1197 | source = consts.INFO_SOURCE[1] |
| 1144 | version = comments = '' | 1198 | version = comments = '' |
| ... | @@ -1154,7 +1208,8 @@ class CompareResultView(GenericView): | ... | @@ -1154,7 +1208,8 @@ class CompareResultView(GenericView): |
| 1154 | 'source': source, | 1208 | 'source': source, |
| 1155 | 'version': version, | 1209 | 'version': version, |
| 1156 | 'comments': comments, | 1210 | 'comments': comments, |
| 1157 | 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(result_obj.ocr_auto_result) | 1211 | 'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads( |
| 1212 | result_obj.ocr_auto_result) | ||
| 1158 | } | 1213 | } |
| 1159 | 1214 | ||
| 1160 | return response.ok(data=compare_result) | 1215 | return response.ok(data=compare_result) |
| ... | @@ -1189,7 +1244,8 @@ class CompareResultView(GenericView): | ... | @@ -1189,7 +1244,8 @@ class CompareResultView(GenericView): |
| 1189 | 'id': 0 if result_obj is None else result_obj.id, | 1244 | 'id': 0 if result_obj is None else result_obj.id, |
| 1190 | 'application_id': case_id, | 1245 | 'application_id': case_id, |
| 1191 | 'entity': entity, | 1246 | 'entity': entity, |
| 1192 | 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else consts.DOC_SCHEME_LIST[1], | 1247 | 'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else |
| 1248 | consts.DOC_SCHEME_LIST[1], | ||
| 1193 | 'whole_result': whole_result, | 1249 | 'whole_result': whole_result, |
| 1194 | 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'), | 1250 | 'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'), |
| 1195 | 'source': source, | 1251 | 'source': source, |
| ... | @@ -1362,7 +1418,8 @@ class SECMSView(GenericView): | ... | @@ -1362,7 +1418,8 @@ class SECMSView(GenericView): |
| 1362 | 1418 | ||
| 1363 | args = request.data | 1419 | args = request.data |
| 1364 | cms_info = args.get('content', {}) | 1420 | cms_info = args.get('content', {}) |
| 1365 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX | 1421 | business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith( |
| 1422 | '宝马') else consts.HIL_PREFIX | ||
| 1366 | src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '') | 1423 | src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '') |
| 1367 | application_id = src_application_id[:src_application_id.rfind('-')] | 1424 | application_id = src_application_id[:src_application_id.rfind('-')] |
| 1368 | 1425 | ||
| ... | @@ -1418,7 +1475,8 @@ class SECMSView(GenericView): | ... | @@ -1418,7 +1475,8 @@ class SECMSView(GenericView): |
| 1418 | cms_status_info.create_time = datetime.datetime.now() | 1475 | cms_status_info.create_time = datetime.datetime.now() |
| 1419 | cms_status_info.save() | 1476 | cms_status_info.save() |
| 1420 | except Exception as e: | 1477 | except Exception as e: |
| 1421 | self.exception_log.exception('[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc())) | 1478 | self.exception_log.exception( |
| 1479 | '[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc())) | ||
| 1422 | fsm_compare.apply_async((application_id, business_type, None, None, False, True), | 1480 | fsm_compare.apply_async((application_id, business_type, None, None, False, True), |
| 1423 | queue='queue_compare') | 1481 | queue='queue_compare') |
| 1424 | else: | 1482 | else: |
| ... | @@ -1517,7 +1575,7 @@ class AutoSettlementView(GenericView): | ... | @@ -1517,7 +1575,7 @@ class AutoSettlementView(GenericView): |
| 1517 | whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q() | 1575 | whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q() |
| 1518 | rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q() | 1576 | rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q() |
| 1519 | time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start, | 1577 | time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start, |
| 1520 | rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1))\ | 1578 | rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1)) \ |
| 1521 | if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q() | 1579 | if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q() |
| 1522 | time2_query = Q(rpa_activated_time__gte=activated_time_start, | 1580 | time2_query = Q(rpa_activated_time__gte=activated_time_start, |
| 1523 | rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \ | 1581 | rpa_activated_time__lt=activated_time_end + datetime.timedelta(days=1)) \ | ... | ... |
-
Please register or sign in to post a comment