add ecm search
Showing
1 changed file
with
32 additions
and
1 deletions
... | @@ -14,6 +14,7 @@ class ECM: | ... | @@ -14,6 +14,7 @@ class ECM: |
14 | self.oauth_url = conf.ECM_OAUTH_URL | 14 | self.oauth_url = conf.ECM_OAUTH_URL |
15 | self.download_url = conf.ECM_DOWNLOAD_URL | 15 | self.download_url = conf.ECM_DOWNLOAD_URL |
16 | self.upload_url = conf.ECM_UPLOAD_URL | 16 | self.upload_url = conf.ECM_UPLOAD_URL |
17 | self.search_url = conf.ECM_SEARCH_URL | ||
17 | self.oauth_headers = { | 18 | self.oauth_headers = { |
18 | 'Content-Type': 'application/x-www-form-urlencoded' | 19 | 'Content-Type': 'application/x-www-form-urlencoded' |
19 | } | 20 | } |
... | @@ -26,9 +27,10 @@ class ECM: | ... | @@ -26,9 +27,10 @@ class ECM: |
26 | self.token_type = 'Bearer' | 27 | self.token_type = 'Bearer' |
27 | self.token_type_key = 'token_type' | 28 | self.token_type_key = 'token_type' |
28 | self.expires_key = 'expires_in' | 29 | self.expires_key = 'expires_in' |
30 | self.settlement_type = 'settlement' | ||
29 | self.doc_type_map = { | 31 | self.doc_type_map = { |
30 | 'ACCEPTANCE': ('acceptance', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL), | 32 | 'ACCEPTANCE': ('acceptance', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL), |
31 | 'SETTLEMENT': ('settlement', conf.ECM_FOLDER_SE, conf.ECM_FOLDER_SE_HIL), | 33 | 'SETTLEMENT': (self.settlement_type, conf.ECM_FOLDER_SE, conf.ECM_FOLDER_SE_HIL), |
32 | 'CONTRACTMANAGEMENT': ('contract_management', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL), | 34 | 'CONTRACTMANAGEMENT': ('contract_management', conf.ECM_FOLDER_CA, conf.ECM_FOLDER_CA_HIL), |
33 | } | 35 | } |
34 | self.doc_base_map = { | 36 | self.doc_base_map = { |
... | @@ -42,6 +44,7 @@ class ECM: | ... | @@ -42,6 +44,7 @@ class ECM: |
42 | "b_coborrower_id", "b_coborrower_name", "b_guarantor_id", "b_guarantor_name", | 44 | "b_coborrower_id", "b_coborrower_name", "b_guarantor_id", "b_guarantor_name", |
43 | "b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_input_date", "b_comment", | 45 | "b_frontend_partner", "b_dealer_code", "b_dealer_name", "b_input_date", "b_comment", |
44 | "b_contract_no", "b_location"] | 46 | "b_contract_no", "b_location"] |
47 | self.contract_prefix = '电子' | ||
45 | 48 | ||
46 | def update_oauth_token(self): | 49 | def update_oauth_token(self): |
47 | response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False) | 50 | response = requests.post(self.oauth_url, headers=self.oauth_headers, data=self.oauth_payload, verify=False) |
... | @@ -66,6 +69,34 @@ class ECM: | ... | @@ -66,6 +69,34 @@ class ECM: |
66 | def get_headers(self): | 69 | def get_headers(self): |
67 | return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} | 70 | return {'Authorization': '{0} {1}'.format(self.token_type, self.get_oauth_token())} |
68 | 71 | ||
72 | def search(self, application_id, business_type): | ||
73 | sql = "select * from {0} where b_application_no='{1}' and object_name like '{2}%'".format( | ||
74 | self.settlement_type, application_id, self.contract_prefix) | ||
75 | search_args = { | ||
76 | "userName": self.username, | ||
77 | "password": self.pwd, | ||
78 | "docbase": self.doc_base_map.get(business_type), | ||
79 | "documentType": self.settlement_type, | ||
80 | "dql": sql | ||
81 | } | ||
82 | response = requests.post(self.search_url, headers=self.get_headers(), json=search_args, verify=False) | ||
83 | if response.status_code != 200: | ||
84 | raise ECMException('ECM search failed with code: {0} , with headers: {1}'.format( | ||
85 | response.status_code, response.headers)) | ||
86 | result = [] | ||
87 | for object_dict in response.json().get('Envelope', {}).get('Body', {}).get('executeResponse', {}).get( | ||
88 | 'return', {}).get('dataPackage', {}).get('DataObjects', []): | ||
89 | object_id = object_dict.get('Identity', {}).get('ObjectId', {}).get('@id', '') | ||
90 | object_name = '' | ||
91 | for attr_dict in object_dict.get('Properties', {}).get('Properties', []): | ||
92 | if attr_dict.get('@name', '') == 'object_name': | ||
93 | object_name = attr_dict.get('Value', '') | ||
94 | break | ||
95 | if len(object_id) > 0 and len(object_name) > 0: | ||
96 | result.append((object_name, object_id)) | ||
97 | return result | ||
98 | |||
99 | |||
69 | def download(self, save_path, object_id, document_scheme, business_type): | 100 | def download(self, save_path, object_id, document_scheme, business_type): |
70 | doc_type, _, _ = self.doc_type_map.get(document_scheme) | 101 | doc_type, _, _ = self.doc_type_map.get(document_scheme) |
71 | download_json = { | 102 | download_json = { | ... | ... |
-
Please register or sign in to post a comment