8c2c2380 by 周伟奇

fix upload bug

1 parent 4de905f7
......@@ -27,16 +27,16 @@ class ECM:
self.token_type_key = 'token_type'
self.expires_key = 'expires_in'
self.doc_type_map = {
'ACCEPTANCE': ('acceptance', conf.ECM_FOLDER_CA),
'SETTLEMENT': ('settlement', conf.ECM_FOLDER_SE),
'CONTRACTMANAGEMENT': ('contract_management', conf.ECM_FOLDER_CA),
'ACCEPTANCE': ('acceptance', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL),
'SETTLEMENT': ('settlement', conf.ECM_FOLDER_SE, conf.ECM_FOLDER_SE_HIL),
'CONTRACTMANAGEMENT': ('contract_management', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL),
}
self.doc_base_map = {
'AFC': 'SF5_CN',
'HIL': 'SF5_CL',
}
self.prefix = 'OCR'
self.upload_fields = ["b_region", "b_region_name", "r_object_type", "r_content_type", "r_creation_date",
self.upload_fields = ["b_region", "b_region_name", "r_object_type", "r_creation_date",
"r_creator_name", "r_modify_date", "r_modifier", "owner", "b_short_application_no",
"b_short_contract_no", "b_customer_id", "b_customer_name", "b_customer_mobile",
"b_coborrower_id", "b_coborrower_name", "b_guarantor_id", "b_guarantor_name",
......@@ -67,7 +67,7 @@ class ECM:
return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())}
def download(self, save_path, object_id, document_scheme, business_type):
doc_type, _ = self.doc_type_map.get(document_scheme)
doc_type, _, _ = self.doc_type_map.get(document_scheme)
download_json = {
"userName": self.username,
"password": self.pwd,
......@@ -96,7 +96,8 @@ class ECM:
return '{0}{1}'.format(self.prefix, doc_name)
def upload(self, file_path, doc, business_type):
doc_type, folder = self.doc_type_map.get(doc.document_scheme)
doc_type, folder_afc, folder_hil = self.doc_type_map.get(doc.document_scheme)
folder = folder_afc if business_type == 'AFC' else folder_hil
args = {
"username": self.username,
"password": self.pwd,
......@@ -104,9 +105,10 @@ class ECM:
"documentType": doc_type,
"object_name": self.get_doc_file_name(doc.document_name),
"folder": folder,
"format": "xlsx",
"format": "excel12book",
"r_content_type": "excel12book",
"b_application_no": doc.application_id,
"file_base64_content": "",
# "file_base64_content": "",
}
for key in self.upload_fields:
args[key] = ''
......@@ -117,6 +119,7 @@ class ECM:
args['file_base64_content'] = file_data
response = requests.post(self.upload_url, headers=self.get_headers(), json=args, verify=False)
if response.status_code != 200:
raise ECMException('ECM upload failed with code: {0}'.format(response.status_code))
raise ECMException('ECM upload failed with code: {0} , with headers: {1}'.format(
response.status_code, response.headers))
if 'ns6:createResponse' not in response.json().get('S:Envelope', {}).get('S:Body', {}):
raise ECMException('ECM upload failed: {0}'.format(response.json()))
raise ECMException('ECM upload failed: {0} , with headers: {1}'.format(response.json(), response.headers))
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!