2d500b7a by 王聪

Merge branch 'feature/fsm-full' into feature/uat-tmp

2 parents 68af8930 303c44f8
......@@ -1072,7 +1072,6 @@ class NscInvoice(models.Model):
class Meta:
managed = False
db_table = 'nsc_invoice'
situ_db_label = 'hil'
class AFCCmsStatusInfo(models.Model):
......@@ -1100,4 +1099,3 @@ class HILCmsStatusInfo(models.Model):
class Meta:
managed = False
db_table = 'hil_cms_status_info'
situ_db_label = 'hil'
\ No newline at end of file
......
......@@ -60,8 +60,11 @@ from .mixins import DocHandler, MPOSHandler, PreSEHandler
from . import consts
from apps.account.authentication import OAuth2AuthenticationWithUser
from celery_compare.tasks import compare, fsm_compare
from prese.compare import get_empty_result
import time
class CustomDate(fields.Date):
def _deserialize(self, value, attr, data, **kwargs):
......@@ -292,7 +295,7 @@ document_args = {
'documentName': fields.Str(required=True, validate=validate.Length(max=255)),
# Acceptance/Settlement/Contract Management
'documentScheme': fields.Str(required=True, validate=validate.Length(max=64)),
'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002
'businessType': fields.Str(required=True, validate=validate.Length(max=64)), # CO00001/CO00002
'uploadFinishTime': fields.DateTime(required=True),
'dataSource': fields.Str(required=True, validate=validate.Length(max=64)), # POS/EAPP/Econtract
'metadataVersionId': fields.Str(required=True, validate=validate.Length(max=64)),
......@@ -557,6 +560,7 @@ class UploadDocView(GenericView, DocHandler):
# authentication_classes = []
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
# required_scopes = ['write']
# 上传(接收)文件接口
......@@ -581,7 +585,8 @@ class UploadDocView(GenericView, DocHandler):
# fsm激活状态, 更新ocr_result 表fsm状态
self.running_log.info('[doc upload applicationId-{0}] [applicationStatus-{1}, activated-{2}]'
.format(application_id, application_status, True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False))
.format(application_id, application_status,
True if consts.FSM_ACTIVITED_STATUS.get(application_status) else False))
if consts.FSM_ACTIVITED_STATUS.get(application_status):
result_class = None
if business_type == consts.HIL_PREFIX:
......@@ -852,6 +857,9 @@ class CompareView(GenericView):
'''
pre_fsm_url = conf.PRE_FSM_URL
class SECompareView(GenericView, PreSEHandler):
permission_classes = [IsAuthenticated]
authentication_classes = [OAuth2AuthenticationWithUser]
......@@ -873,30 +881,75 @@ class SECompareView(GenericView, PreSEHandler):
fsm_special_car = content.get('fsmSpecialCar', False)
fsm_best_price = content.get('fsmBestPrice', False)
# 存库, 用于银行卡比对
try:
bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification
bank_obj = bank_class.objects.filter(application_id=application_id).first()
if bank_obj is None and bank_verify == 'PASS':
bank_class.objects.create(
application_id=application_id,
)
elif bank_obj is not None and bank_verify == 'PASS' and bank_obj.on_off is False:
bank_obj.on_off = True
bank_obj.save()
elif bank_obj is not None and bank_verify != 'PASS' and bank_obj.on_off is True:
bank_obj.on_off = False
bank_obj.save()
except Exception as e:
self.running_log.info('{0} [bankCard verify save db error] [applicationEntity={1}] '
'[application_id={2}] [bank_status={3}] [error={4}]'.format(
log_base, business_type, application_id, bank_verify, traceback.format_exc()))
if fsm_special_car:
compare_result = {
"is_pass": False,
"particulars": [{
"object_name": "",
"fields": [{
"input": "",
"ocr": "",
"field_is_pass": False,
"comments": "此申请为FSM 特殊申请,暂不支持预放款流程"
}]
}]
}
elif fsm_best_price:
compare_result = {
"is_pass": False,
"particulars": [{
"object_name": "",
"fields": [{
"input": "",
"ocr": "",
"field_is_pass": False,
"comments": "此申请为FSM 特殊申请,暂不支持预放款流程"
}]
}]
}
elif fsm_flag and (not fsm_special_car or not fsm_best_price):
# 调用Java pre fsm接口
try:
self.running_log.info("{0} request java pre fsm api, url:{1}, body:{2}".format(log_base, pre_fsm_url, json.dumps(content)))
headers = {
'Content-Type': 'application/json'
}
resp = requests.post(pre_fsm_url, headers=headers, json=content)
self.running_log.info("{0} response from java pre fsm api, resp:{1}".format(log_base, resp.text))
result = json.loads(resp.text)
compare_result = result.get("result")
if not compare_result:
compare_result = get_empty_result()
except Exception as e:
self.running_log.error("{0} pre fsm request to java error, url:{1}, param:{2}, errorMsg:{3}".format(
log_base, pre_fsm_url, json.dumps(content), traceback.format_exc()))
compare_result = get_empty_result()
elif not fsm_flag:
# 存库, 用于银行卡比对
try:
bank_class = HILbankVerification if business_type in consts.HIL_SET else AFCbankVerification
bank_obj = bank_class.objects.filter(application_id=application_id).first()
if bank_obj is None and bank_verify == 'PASS':
bank_class.objects.create(
application_id=application_id,
)
elif bank_obj is not None and bank_verify == 'PASS' and bank_obj.on_off is False:
bank_obj.on_off = True
bank_obj.save()
elif bank_obj is not None and bank_verify != 'PASS' and bank_obj.on_off is True:
bank_obj.on_off = False
bank_obj.save()
except Exception as e:
self.running_log.info('{0} [bankCard verify save db error] [applicationEntity={1}] '
'[application_id={2}] [bank_status={3}] [error={4}]'.format(
log_base, business_type, application_id, bank_verify, traceback.format_exc()))
# preSettlement比对
compare_result = self.pre_compare_entrance(content)
self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] '
'[result={4}]'.format(log_base, business_type, application_id, uniq_seq, compare_result))
# preSettlement比对
compare_result = self.pre_compare_entrance(content)
self.running_log.info('{0} [prese completed] [applicationEntity={1}] [application_id={2}] [uniq_seq={3}] '
'[result={4}]'.format(log_base, business_type, application_id, uniq_seq,
compare_result))
try:
end_time = time.time()
......@@ -999,10 +1052,10 @@ class DocView(GenericView, DocHandler):
application_id_query = Q(application_id__contains=application_id) if application_id is not None else Q()
data_source_query = Q(data_source=data_source) if data_source is not None else Q()
upload_finish_time_query = Q(upload_finish_time__gte=upload_time_start,
upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1))\
upload_finish_time__lt=upload_time_end + datetime.timedelta(days=1)) \
if upload_time_start is not None and upload_time_end is not None else Q()
create_time_query = Q(create_time__gte=create_time_start,
create_time__lt=create_time_end + datetime.timedelta(days=1))\
create_time__lt=create_time_end + datetime.timedelta(days=1)) \
if create_time_start is not None and create_time_end is not None else Q()
query = application_id_query & status_query & data_source_query & upload_finish_time_query & create_time_query
val_tuple = ('id', 'application_id', 'upload_finish_time', 'create_time', 'document_scheme', 'data_source',
......@@ -1014,10 +1067,11 @@ class DocView(GenericView, DocHandler):
if start_index >= total > 0:
raise self.invalid_params('页数不存在')
doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[start_index: end_index]
doc_queryset = doc_class.objects.filter(query).values(*val_tuple).order_by('-create_time')[
start_index: end_index]
# doc_list = self.get_doc_list(doc_queryset, prefix)
for doc_dict in doc_queryset:
tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0]\
tmp_scheme = consts.COMPARE_DOC_SCHEME_LIST[0] if doc_dict['document_scheme'] == consts.DOC_SCHEME_LIST[0] \
else consts.COMPARE_DOC_SCHEME_LIST[1]
application_link = '{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'.format(
conf.BASE_URL, prefix, tmp_scheme, doc_dict['application_id'])
......@@ -1064,7 +1118,6 @@ class DocView(GenericView, DocHandler):
# os.remove(tmp_save_path)
# raise self.invalid_params(msg='invalid params: PDF file XSS')
file.close()
# 1. 上传信息记录
application_id = '{0}{1}'.format(consts.FIXED_APPLICATION_ID_PREFIX, metadata_version_id)
......@@ -1147,7 +1200,8 @@ class CompareResultView(GenericView):
latest_compared_time = ''
else:
whole_result = consts.RESULT_Y if result_obj.ocr_auto_result_pass else consts.RESULT_N
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')
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')
source = consts.INFO_SOURCE[1]
version = comments = ''
......@@ -1163,7 +1217,8 @@ class CompareResultView(GenericView):
'source': source,
'version': version,
'comments': comments,
'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(result_obj.ocr_auto_result)
'result': [] if result_obj is None or not result_obj.ocr_auto_result else json.loads(
result_obj.ocr_auto_result)
}
return response.ok(data=compare_result)
......@@ -1198,7 +1253,8 @@ class CompareResultView(GenericView):
'id': 0 if result_obj is None else result_obj.id,
'application_id': case_id,
'entity': entity,
'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else consts.DOC_SCHEME_LIST[1],
'scheme': consts.DOC_SCHEME_LIST[0] if scheme == consts.COMPARE_DOC_SCHEME_LIST[0] else
consts.DOC_SCHEME_LIST[1],
'whole_result': whole_result,
'latest_compared_time': '' if result_obj is None else result_obj.update_time.strftime('%Y-%m-%d %H:%M'),
'source': source,
......@@ -1371,7 +1427,8 @@ class SECMSView(GenericView):
args = request.data
cms_info = args.get('content', {})
business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith('宝马') else consts.HIL_PREFIX
business_type = consts.AFC_PREFIX if cms_info.get('financeCompany', '').startswith(
'宝马') else consts.HIL_PREFIX
src_application_id = cms_info.get('settlemnetVerification', {}).get('applicationNo', '')
application_id = src_application_id[:src_application_id.rfind('-')]
......@@ -1416,21 +1473,25 @@ class SECMSView(GenericView):
cms_status_info = cms_status_class.objects.filter(application_id=application_id).first()
if cms_status_info:
cms_status_info.is_fsm = 1
cms_status_info.update_time = datetime.datetime.now()
cms_status_info.save()
else:
cms_status_info = cms_status_class()
cms_status_info.application_id = application_id
cms_status_info.business_type = business_type
cms_status_info.is_fsm = 1
cms_status_info.update_time = datetime.datetime.now()
cms_status_info.create_time = datetime.datetime.now()
cms_status_info.save()
except Exception as e:
self.exception_log.exception('[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc()))
self.exception_log.exception(
'[cms view] [cms_status_info db save failed] [error={0}]'.format(traceback.format_exc()))
fsm_compare.apply_async((application_id, business_type, None, None, False, True),
queue='queue_compare')
queue='queue_compare')
else:
# 触发比对
compare.apply_async((application_id, business_type, None, None, False, True),
queue='queue_compare')
queue='queue_compare')
try:
end_time = time.time()
......@@ -1523,7 +1584,7 @@ class AutoSettlementView(GenericView):
whole_result_query = Q(ocr_whole_result_pass=whole_result) if not isinstance(whole_result, str) else Q()
rpa_result_query = Q(rpa_result=rpa_result) if not isinstance(rpa_result, str) else Q()
time1_query = Q(rpa_get_case_from_ocr_time__gte=get_case_from_ocr_time_start,
rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1))\
rpa_get_case_from_ocr_time__lt=get_case_from_ocr_time_end + datetime.timedelta(days=1)) \
if get_case_from_ocr_time_start is not None and get_case_from_ocr_time_end is not None else Q()
time2_query = Q(rpa_activated_time__gte=activated_time_start,
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!