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
924771cd
authored
2022-10-19 14:37:09 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add interface report
1 parent
530a9a8c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
18 deletions
src/apps/doc/models.py
src/apps/doc/named_enum.py
src/apps/doc/views.py
src/celery_compare/tasks.py
src/common/tools/mssql_script21.py
src/apps/doc/models.py
View file @
924771c
...
...
@@ -978,3 +978,22 @@ class GenericOCRReport(models.Model):
class
Meta
:
managed
=
False
db_table
=
'generic_ocr_report'
class
InterfaceReport
(
models
.
Model
):
id
=
models
.
AutoField
(
primary_key
=
True
,
verbose_name
=
"id"
)
# 主键
source
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"来源"
)
target
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
"目标"
)
body
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"请求体"
)
response
=
models
.
TextField
(
null
=
True
,
verbose_name
=
"响应"
)
status
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
"是否成功"
)
retry_times
=
models
.
SmallIntegerField
(
default
=
0
,
verbose_name
=
"重试次数"
)
duration
=
models
.
IntegerField
(
verbose_name
=
'处理时长'
)
create_time
=
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'创建时间'
)
class
Meta
:
managed
=
False
db_table
=
'interface_report'
...
...
src/apps/doc/named_enum.py
View file @
924771c
...
...
@@ -95,3 +95,14 @@ class BSCheckResult(NamedEnum):
class
OfflineFailureReason
(
NamedEnum
):
OS_ERROR
=
(
0
,
'OS_ERROR'
)
PROCESS_ERROR
=
(
1
,
'PROCESS_ERROR'
)
class
SystemName
(
NamedEnum
):
POS
=
(
0
,
'POS'
)
EAPP
=
(
1
,
'EAPP'
)
ECONTRACT
=
(
2
,
'ECONTRACT'
)
GCAP
=
(
3
,
'GCAP'
)
CMS
=
(
4
,
'CMS'
)
MPOS
=
(
5
,
'MPOS'
)
UNKNOWN
=
(
6
,
'Unknown'
)
OCR
=
(
7
,
'OCR'
)
...
...
src/apps/doc/views.py
View file @
924771c
This diff is collapsed.
Click to expand it.
src/celery_compare/tasks.py
View file @
924771c
...
...
@@ -31,12 +31,13 @@ from apps.doc.models import (
AFCAutoSettlement
,
HILbankVerification
,
AFCbankVerification
,
InterfaceReport
,
)
from
apps.doc
import
consts
from
apps.doc.ocr.gcap
import
gcap
from
apps.doc.ocr.cms
import
cms
from
apps.doc.exceptions
import
GCAPException
from
apps.doc.named_enum
import
RequestTeam
,
RequestTrigger
,
ProcessName
,
ErrorType
from
apps.doc.named_enum
import
RequestTeam
,
RequestTrigger
,
ProcessName
,
ErrorType
,
SystemName
from
common.tools.comparison
import
cp
from
common.tools.des
import
decode_des
...
...
@@ -748,16 +749,20 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
time
.
sleep
(
5
)
# 将比对结果发送GCAP
start_time
=
time
.
time
()
try
:
data
=
gcap
.
dict_to_xml
(
comparison_res
)
except
Exception
as
e
:
compare_log
.
error
(
'{0} [CA] [dict to xml failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
else
:
final_times
=
0
is_success
=
True
try
:
for
times
in
range
(
consts
.
RETRY_TIMES
):
final_times
=
times
try
:
res_text
=
gcap
.
send
(
data
)
res_text
=
gcap
.
send
(
data
)
# interface_report ocr to gcap
except
Exception
as
e
:
gcap_exc
=
str
(
e
)
else
:
...
...
@@ -765,6 +770,7 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
else
:
raise
GCAPException
(
gcap_exc
)
except
Exception
as
e
:
is_success
=
False
compare_log
.
error
(
'{0} [CA] [gcap failed] [entity={1}] [id={2}] [ocr_res_id={3}] [error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
else
:
...
...
@@ -772,6 +778,21 @@ def ca_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
res_text
))
compare_log
.
info
(
'{0} [CA] [task success] [entity={1}] [id={2}] [ocr_res_id={3}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
finally
:
end_time
=
time
.
time
()
duration_second
=
int
(
end_time
-
start_time
)
try
:
InterfaceReport
.
objects
.
create
(
source
=
SystemName
.
OCR
.
name
,
target
=
SystemName
.
GCAP
.
name
,
body
=
data
,
response
=
res_text
if
is_success
else
None
,
status
=
is_success
,
retry_times
=
final_times
,
duration
=
duration_second
,
)
except
Exception
as
e
:
compare_log
.
error
(
'{0} [CA] [db save failed] [error={1}]'
.
format
(
log_base
,
traceback
.
format_exc
()))
# report
try
:
...
...
@@ -3087,24 +3108,28 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
compare_log
.
info
(
'{0} [SE] [cms closed] [entity={1}] [id={2}] [ocr_res_id={3}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
))
return
successful_at_this_level
try
:
application_link
=
'{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'
.
format
(
conf
.
BASE_URL
,
application_entity
,
consts
.
COMPARE_DOC_SCHEME_LIST
[
1
],
application_id
)
data
=
{
"SubtenantId"
:
consts
.
TENANT_MAP
[
application_entity
],
"Data"
:
{
"Result_Message"
:
"Pass"
if
successful_at_this_level
else
"Fail"
,
"AutoCheckResult"
:
"Pass"
if
auto_result
else
"Fail"
,
"Failure_Reason"
:
cn_failure_reason_str
,
"Application_Number"
:
application_id
,
"Bank_Statement"
:
bs_failure_reason_str
,
"Link_URL"
:
application_link
,
"OCR_Version"
:
1
,
"Origin"
:
consts
.
INFO_SOURCE
[
1
]
}
is_success
=
True
start_time
=
time
.
time
()
application_link
=
'{0}/showList/showList?entity={1}&scheme={2}&case_id={3}'
.
format
(
conf
.
BASE_URL
,
application_entity
,
consts
.
COMPARE_DOC_SCHEME_LIST
[
1
],
application_id
)
data
=
{
"SubtenantId"
:
consts
.
TENANT_MAP
[
application_entity
],
"Data"
:
{
"Result_Message"
:
"Pass"
if
successful_at_this_level
else
"Fail"
,
"AutoCheckResult"
:
"Pass"
if
auto_result
else
"Fail"
,
"Failure_Reason"
:
cn_failure_reason_str
,
"Application_Number"
:
application_id
,
"Bank_Statement"
:
bs_failure_reason_str
,
"Link_URL"
:
application_link
,
"OCR_Version"
:
1
,
"Origin"
:
consts
.
INFO_SOURCE
[
1
]
}
response
=
cms
.
send
(
data
)
}
try
:
response
=
cms
.
send
(
data
)
# interface_report ocr to cms
except
Exception
as
e
:
is_success
=
False
compare_log
.
error
(
'{0} [SE] [cms error] [entity={1}] [id={2}] [ocr_res_id={3}] '
'[error={4}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
traceback
.
format_exc
()))
...
...
@@ -3112,6 +3137,21 @@ def se_compare(application_id, application_entity, ocr_res_id, last_obj, ocr_res
compare_log
.
info
(
'{0} [SE] [cms success] [entity={1}] [id={2}] [ocr_res_id={3}] [data={4}] '
'[response={5}]'
.
format
(
log_base
,
application_entity
,
application_id
,
ocr_res_id
,
data
,
response
))
finally
:
end_time
=
time
.
time
()
duration_second
=
int
(
end_time
-
start_time
)
try
:
InterfaceReport
.
objects
.
create
(
source
=
SystemName
.
OCR
.
name
,
target
=
SystemName
.
CMS
.
name
,
body
=
json
.
dumps
(
data
),
response
=
json
.
dumps
(
response
)
if
is_success
else
None
,
status
=
is_success
,
# retry_times=None,
duration
=
duration_second
,
)
except
Exception
as
e
:
compare_log
.
error
(
'{0} [SE] [db save failed] [error={1}]'
.
format
(
log_base
,
traceback
.
format_exc
()))
return
successful_at_this_level
...
...
src/common/tools/mssql_script21.py
0 → 100644
View file @
924771c
import
pyodbc
hil_sql
=
"""
create table interface_report
(
id bigint identity primary key,
source nvarchar(64) not null,
target nvarchar(64) not null,
body nvarchar(max),
response nvarchar(max),
status bit default 1 not null,
retry_times tinyint default 0 not null,
duration smallint not null,
create_time datetime not null
);
"""
afc_sql
=
"""
"""
hil_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
hil_cursor
=
hil_cnxn
.
cursor
()
hil_cursor
.
execute
(
hil_sql
)
hil_cursor
.
close
()
hil_cnxn
.
close
()
afc_cnxn
=
pyodbc
.
connect
(
'DRIVER={ODBC Driver 17 for SQL Server};'
,
autocommit
=
True
)
afc_cursor
=
afc_cnxn
.
cursor
()
afc_cursor
.
execute
(
afc_sql
)
afc_cursor
.
close
()
afc_cnxn
.
close
()
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