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
2b705da4
authored
2020-11-24 16:59:18 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add license statistics
1 parent
0c124b56
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
src/apps/doc/management/commands/license_statistics.py
src/apps/doc/management/commands/license_statistics.py
0 → 100644
View file @
2b705da
import
json
import
re
import
ast
from
openpyxl
import
Workbook
from
django.core.management
import
BaseCommand
from
common.mixins
import
LoggerMixin
from
apps.doc.models
import
HILDoc
,
AFCDoc
from
apps.doc
import
consts
class
Command
(
BaseCommand
,
LoggerMixin
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
log_base
=
'[license statistics]'
self
.
header_map
=
{
consts
.
MVI_CLASSIFY
:
[(
'申请ID'
,
'发票代码'
,
'发票号码'
,
'开票日期'
,
'不含税价'
,
'发票联'
,
'购买方名称'
,
'购买方证件号码'
,
'纳税人识别号'
,
'车架号'
,
'价税合计小写'
,
'销货单位名称'
,
'增值税税额'
,
'增值税税率'
,
'发票章有无'
,
'价税合计大写'
,
'发动机号'
,
'车辆类型'
,
'厂牌型号'
,
'产地'
,
'合格证号'
,
'进口证明书号'
,
'商检单号'
,
'电话'
,
'销货方纳税人识别号'
,
'账号'
,
'地址'
,
'开户银行'
,
'主管税务机关及代码'
,
'吨位'
,
'限乘人数'
)],
consts
.
IC_CLASSIFY
:
[(
'申请ID'
,
'姓名'
,
'公民身份号码'
,
'出生年月'
,
'住址'
,
'性别'
,
'民族'
),
(
'申请ID'
,
'有效期限'
,
'签发机关'
)],
consts
.
RP_CLASSIFY
:
[(
'申请ID'
,
'姓名'
,
'公民身份号码'
,
'出生年月'
,
'住址'
,
'性别'
),
(
'申请ID'
,
'有效期限'
,
'签发机关'
)],
consts
.
BC_CLASSIFY
:
[(
'申请ID'
,
'发卡行名称'
,
'银行卡号'
,
'银行卡类型'
,
'持卡人姓名'
)],
consts
.
BL_CLASSIFY
:
[(
'申请ID'
,
'统一社会信用代码'
,
'名称'
,
'类型'
,
'法定代表人'
,
'成立日期'
,
'营业期限'
,
'注册资本'
,
'住所'
,
'经营范围'
)],
consts
.
UCI_CLASSIFY
:
[(
'申请ID'
,
'发票代码'
,
'发票号码'
,
'开票日期'
,
'车价合计小写'
,
'发票联'
,
'买方单位/个人'
,
'买方单位代码/身份证号码'
,
'车架号'
,
'车价合计大写'
,
'二手车市场'
,
'发票章有无'
,
'车牌照号'
,
'登记证号'
,
'买方单位/住址'
,
'车辆类型'
,
'厂牌型号'
,
'转入地车辆管理所名称'
,
'卖方单位/个人'
,
'卖方单位代码/身份证号码'
,
'卖方单位/个人住址'
)],
consts
.
EEP_CLASSIFY
:
[(
'申请ID'
,
'姓名'
,
'证件号码'
,
'换证次数(签发次数)'
,
'有效期限'
,
'出生日期'
,
'性别'
,
'签发机关'
,
'签发地点'
)],
consts
.
DL_CLASSIFY
:
[(
'申请ID'
,
'1 号牌号码'
,
'3 所有人'
,
'5 使用性质'
,
'7 车辆识别代号'
,
'9 注册日期'
,
'10 发证日期'
,
'2 车辆类型'
,
'4 住址'
,
'6 品牌型号'
,
'8 发动机号码'
),
(
'申请ID'
,
'1 号牌号码'
,
'11 档案编号'
,
'12 核定载人数'
,
'13 总质量'
,
'14 整备质量'
,
'15 核对载质量'
,
'16 外廓尺寸'
,
'17 准牵引总质量'
)],
consts
.
PP_CLASSIFY
:
[(
'申请ID'
,
'类型/Type'
,
'姓名/Name'
,
'护照号码/Passport No'
,
'有效期至/Date of expiry'
,
'签发日期/Date of issue'
,
'国家码/Country Code'
,
'性别/Sex'
,
'国籍/Nationality'
,
'出生日期/Date of birth'
,
'出生地点/Place of birth'
,
'签发地点/Place of issue'
)],
consts
.
MVC_CLASSIFY
:
[(
'申请ID'
,
'机动车所有人/身份证明名称/号码'
,
'登记日期'
,
'车辆识别代号/车架号'
,
'车辆出厂日期'
,
'发证日期'
,
'使用性质'
,
'车辆获得方式'
,
'机动车登记编号'
,
'车辆类型'
,
'车辆品牌'
,
'车辆型号'
,
'车身颜色'
,
'国产/进口'
,
'发动机号'
,
'发动机型号'
,
'制造厂名称'
,
'登记机关'
,
'机动车登记证书编号'
),
(
'姓名/名称'
,
'身份证明名称/号码'
,
'转移登记日期'
)],
consts
.
VAT_CLASSIFY
:
[(
'申请ID'
,
'发票代码'
,
'发票代码(开具)'
,
'发票号码'
,
'发票号码(开具)'
,
'开票日期'
,
'校验码'
,
'货物或应税劳务、服务名称'
,
'开具金额合计(不含税)'
,
'税率'
,
'税额合计'
,
'价税合计(小写)'
,
'价税合计(大写)'
,
'购买方名称'
,
'购买方纳税人识别号'
,
'购买方地址、电话'
,
'购买方开户行及账号'
,
'销售方名称'
,
'销售方纳税人识别号'
,
'销售方地址、电话'
,
'销售方开户行及账号'
,
'销售方:(章)'
,
'备注'
)],
}
def
handle
(
self
,
*
args
,
**
kwargs
):
excel_path
=
'/bmw-ocr/data/license_res.xlsx'
wb
=
Workbook
()
for
classify
,
(
_
,
name
,
_
,
_
,
_
,
_
)
in
consts
.
LICENSE_ORDER
:
ws
=
wb
.
create_sheet
(
name
)
headers
=
self
.
header_map
.
get
(
classify
,
[])
for
header
in
headers
:
ws
.
append
(
header
)
wb
.
remove
(
wb
.
get_sheet_by_name
(
'Sheet'
))
with
open
(
'/bmw-ocr/logs/license_bak.log'
,
'r'
,
encoding
=
'utf-8'
)
as
fp
:
for
line
in
fp
:
search_obj
=
re
.
search
(
r'task=(.*) license_summary=(.*)'
,
line
)
task_str
=
search_obj
.
group
(
1
)
license_summary
=
ast
.
literal_eval
(
search_obj
.
group
(
2
))
business_type
,
doc_id_str
=
task_str
.
split
(
consts
.
SPLIT_STR
)
doc_id
=
int
(
doc_id_str
)
doc_class
=
HILDoc
if
business_type
==
consts
.
HIL_PREFIX
else
AFCDoc
application_id
=
doc_class
.
objects
.
filter
(
id
=
doc_id
)
.
values_list
(
'application_id'
,
flat
=
True
)
for
classify
,
(
_
,
name
,
field_order
,
side_diff
,
_
,
_
)
in
consts
.
LICENSE_ORDER
:
license_list
=
license_summary
.
get
(
classify
)
if
not
license_list
:
continue
ws
=
wb
.
get_sheet_by_name
(
name
)
for
license_dict
in
license_list
:
if
classify
==
consts
.
IC_CLASSIFY
and
license_dict
.
get
(
'类别'
)
==
'1'
:
# 居住证处理
license_summary
.
setdefault
(
consts
.
RP_CLASSIFY
,
[])
.
append
(
license_dict
)
continue
if
side_diff
:
key
,
field_order_yes
,
field_order_no
=
consts
.
FIELD_ORDER_MAP
.
get
(
classify
)
field_order
=
field_order_yes
if
key
in
license_dict
else
field_order_no
all_value
=
[]
for
search_field
,
write_field
in
field_order
:
if
write_field
is
None
:
continue
field_value
=
license_dict
.
get
(
search_field
,
''
)
if
isinstance
(
field_value
,
list
):
all_value
.
append
(
'
\n
'
.
join
(
field_value
))
else
:
all_value
.
append
(
field_value
)
ws
.
append
((
application_id
[
0
],
*
all_value
))
wb
.
save
(
excel_path
)
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