619710a3 by 冯轩

Merge branch 'feature/uat-tmp' of gitlab.situdata.com:zhouweiqi/bmw-ocr into feature/uat-tmp

2 parents bd43dc3a 0b550510
...@@ -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):
...@@ -293,7 +296,7 @@ document_args = { ...@@ -293,7 +296,7 @@ document_args = {
293 'documentName': fields.Str(required=True, validate=validate.Length(max=255)), 296 'documentName': fields.Str(required=True, validate=validate.Length(max=255)),
294 # Acceptance/Settlement/Contract Management 297 # Acceptance/Settlement/Contract Management
295 'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)), 298 'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)),
296 'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002 299 'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002
297 'uploadFinishTime': fields.DateTime(required=True), 300 'uploadFinishTime': fields.DateTime(required=True),
298 'dataSource': fields.Str(required=True, validate=validate.Length(max=64)), # POS/EAPP/Econtract 301 'dataSource': fields.Str(required=True, validate=validate.Length(max=64)), # POS/EAPP/Econtract
299 'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)), 302 'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)),
...@@ -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,30 +884,75 @@ class SECompareView(GenericView, PreSEHandler): ...@@ -876,30 +884,75 @@ 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
879 # 存库, 用于银行卡比对 887 if fsm_special_car:
880 try: 888 compare_result = {
881 bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification 889 "is_pass": False,
882 bank_obj = bank_class.objects.filter(application_id=application_id).first() 890 "particulars": [{
883 891 "object_name": "",
884 if bank_obj is None and bank_verify == 'PASS': 892 "fields": [{
885 bank_class.objects.create( 893 "input": "",
886 application_id=application_id, 894 "ocr": "",
887 ) 895 "field_is_pass": False,
888 elif bank_obj is not None and bank_verify == 'PASS' and bank_obj.on_off is False: 896 "comments": "此申请为FSM 特殊申请,暂不支持预放款流程"
889 bank_obj.on_off = True 897 }]
890 bank_obj.save() 898 }]
891 elif bank_obj is not None and bank_verify != 'PASS' and bank_obj.on_off is True: 899 }
892 bank_obj.on_off = False 900 elif fsm_best_price:
893 bank_obj.save() 901 compare_result = {
894 except Exception as e: 902 "is_pass": False,
895 self.running_log.info('{0} [bankCard verify save db error] [applicationEntity={1}] ' 903 "particulars": [{
896 '[application_id={2}] [bank_status={3}] [error={4}]'.format( 904 "object_name": "",
897 log_base, business_type, application_id, bank_verify, traceback.format_exc())) 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:
931 # 存库, 用于银行卡比对
932 try:
933 bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification
934 bank_obj = bank_class.objects.filter(application_id=application_id).first()
935
936 if bank_obj is None and bank_verify == 'PASS':
937 bank_class.objects.create(
938 application_id=application_id,
939 )
940 elif bank_obj is not None and bank_verify == 'PASS' and bank_obj.on_off is False:
941 bank_obj.on_off = True
942 bank_obj.save()
943 elif bank_obj is not None and bank_verify != 'PASS' and bank_obj.on_off is True:
944 bank_obj.on_off = False
945 bank_obj.save()
946 except Exception as e:
947 self.running_log.info('{0} [bankCard verify save db error] [applicationEntity={1}] '
948 '[application_id={2}] [bank_status={3}] [error={4}]'.format(
949 log_base, business_type, application_id, bank_verify, traceback.format_exc()))
898 950
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,13 +1487,14 @@ class SECMSView(GenericView): ...@@ -1430,13 +1487,14 @@ 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:
1437 # 触发比对 1495 # 触发比对
1438 compare.apply_async((application_id, business_type, None, None, False, True), 1496 compare.apply_async((application_id, business_type, None, None, False, True),
1439 queue='queue_compare') 1497 queue='queue_compare')
1440 1498
1441 try: 1499 try:
1442 end_time = time.time() 1500 end_time = time.time()
...@@ -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)) \
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!