e9d7ce17 by 周伟奇

add ecm search

1 parent 8c2c2380
......@@ -14,6 +14,7 @@ class ECM:
self.oauth_url = conf.ECM_OAUTH_URL
self.download_url = conf.ECM_DOWNLOAD_URL
self.upload_url = conf.ECM_UPLOAD_URL
self.search_url = conf.ECM_SEARCH_URL
self.oauth_headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
......@@ -26,9 +27,10 @@ class ECM:
self.token_type = 'Bearer'
self.token_type_key = 'token_type'
self.expires_key = 'expires_in'
self.settlement_type = 'settlement'
self.doc_type_map = {
'ACCEPTANCE': ('acceptance', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL),
'SETTLEMENT': ('settlement', conf.ECM_FOLDER_SE, conf.ECM_FOLDER_SE_HIL),
'SETTLEMENT': (self.settlement_type, 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 = {
......@@ -42,6 +44,7 @@ class ECM:
"b_coborrower_id", "b_coborrower_name", "b_guarantor_id", "b_guarantor_name",
"b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_input_date", "b_comment",
"b_contract_no", "b_location"]
self.contract_prefix = '电子'
def update_oauth_token(self):
response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False)
......@@ -66,6 +69,34 @@ class ECM:
def get_headers(self):
return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())}
def search(self, application_id, business_type):
sql = "select * from {0} where b_application_no='{1}' and object_name like '{2}%'".format(
self.settlement_type, application_id, self.contract_prefix)
search_args = {
"userName": self.username,
"password": self.pwd,
"docbase": self.doc_base_map.get(business_type),
"documentType": self.settlement_type,
"dql": sql
}
response = requests.post(self.search_url, headers=self.get_headers(), json=search_args, verify=False)
if response.status_code != 200:
raise ECMException('ECM search failed with code: {0} , with headers: {1}'.format(
response.status_code, response.headers))
result = []
for object_dict in response.json().get('Envelope', {}).get('Body', {}).get('executeResponse', {}).get(
'return', {}).get('dataPackage', {}).get('DataObjects', []):
object_id = object_dict.get('Identity', {}).get('ObjectId', {}).get('@id', '')
object_name = ''
for attr_dict in object_dict.get('Properties', {}).get('Properties', []):
if attr_dict.get('@name', '') == 'object_name':
object_name = attr_dict.get('Value', '')
break
if len(object_id) > 0 and len(object_name) > 0:
result.append((object_name, object_id))
return result
def download(self, save_path, object_id, document_scheme, business_type):
doc_type, _, _ = self.doc_type_map.get(document_scheme)
download_json = {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!