Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
bmw-ocr
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e9d7ce17
authored
2021-10-30 14:45:09 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add ecm search
1 parent
8c2c2380
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletions
src/apps/doc/ocr/ecm.py
src/apps/doc/ocr/ecm.py
View file @
e9d7ce1
...
...
@@ -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
=
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment