Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mancheng
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mancheng
Commits
4d6a5bf8
Commit
4d6a5bf8
authored
Nov 15, 2022
by
dong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix20221115
parent
f0932ac0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
341 additions
and
278 deletions
+341
-278
apps/inves_manage/view.py
+340
-224
apps/models.py
+1
-54
No files found.
apps/inves_manage/view.py
View file @
4d6a5bf8
...
...
@@ -20,43 +20,49 @@ from dateutil.relativedelta import relativedelta
def
get_num
(
num
):
if
len
(
str
(
int
(
num
)))
==
1
:
if
int
(
num
)
==
9
:
num
=
'0'
+
str
(
num
+
1
)
num
=
'0'
+
str
(
int
(
num
)
+
1
)
else
:
num
=
'00'
+
str
(
num
+
1
)
num
=
'00'
+
str
(
int
(
num
)
+
1
)
elif
len
(
str
(
int
(
num
)))
==
2
:
if
int
(
num
)
==
99
:
num
=
'100'
else
:
num
=
'0'
+
str
(
num
+
1
)
num
=
'0'
+
str
(
int
(
num
)
+
1
)
elif
len
(
str
(
int
(
num
)))
==
3
:
num
=
str
(
num
+
1
)
num
=
str
(
int
(
num
)
+
1
)
else
:
num
=
'error'
return
num
# 上传线索库
def
upload_xiansuo_project
(
row_content
,
time_strf
,
upload_time
):
def
upload_xiansuo_project
(
row_content
,
time_strf
,
upload_time
,
upload_unity
,
upload_people
):
try
:
project_name
=
row_content
[
1
]
# 项目名称
investor_name
=
row_content
[
2
]
# 投资方名称
investor_district
=
row_content
[
3
]
# 投资方所在地
project_type
=
row_content
[
4
]
# 项目单位(投资方项目类型
investment_volume
=
row_content
[
5
]
# 总投资额(万元)
investor_district1
=
row_content
[
3
]
# 投资方所在地
investor_district2
=
row_content
[
4
]
# 投资方所在地
investor_district
=
investor_district1
+
investor_district2
project_type1
=
row_content
[
5
]
# 项目单位(投资方项目类型
project_type2
=
row_content
[
6
]
# 项目单位(投资方项目类型
project_type
=
project_type1
+
'-'
+
project_type2
investment_volume
=
row_content
[
7
]
# 总投资额(万元)
if
investment_volume
:
investment_volume
=
float
(
investment_volume
)
investment_volume1
=
row_content
[
6
]
# 拟引资额(万元)
investment_volume1
=
row_content
[
8
]
# 拟引资额(万元)
if
investment_volume1
:
investment_volume
=
float
(
investment_volume1
)
project_info
=
row_content
[
7
]
# 项目基本情况
project_info1
=
row_content
[
8
]
# 项目方基本情况
thread_people
=
row_content
[
9
]
# 线索提供人
thread_people_unity
=
row_content
[
1
0
]
# 线索提供人单位或职务
thread_people_mobile
=
row_content
[
1
1
]
# 线索提供人联系方式
remark
=
row_content
[
1
2
]
# 备注
project_info
=
row_content
[
9
]
# 项目基本情况
project_info1
=
row_content
[
10
]
# 项目方基本情况
thread_people
=
row_content
[
11
]
# 线索提供人
thread_people_unity
=
row_content
[
1
2
]
# 线索提供人单位或职务
thread_people_mobile
=
row_content
[
1
3
]
# 线索提供人联系方式
remark
=
row_content
[
1
4
]
# 备注
project_obj_list
=
SikuProject
.
query
.
all
()
# 项目编号
max_project_num
=
max
([
project_obj
.
project_num
for
project_obj
in
project_obj_list
])
max_project_num
=
''
if
project_obj_list
:
max_project_num
=
max
([
project_obj
.
project_num
for
project_obj
in
project_obj_list
])
if
max_project_num
:
max_project_num
=
max_project_num
[
8
:]
num
=
get_num
(
max_project_num
)
...
...
@@ -69,10 +75,12 @@ def upload_xiansuo_project(row_content, time_strf, upload_time):
# 创建项目
new_project_obj
=
SikuProject
(
upload_unity
=
upload_unity
,
upload_people
=
upload_people
,
upload_time
=
upload_time
,
project_year
=
upload_time
.
split
(
'/'
)[
0
],
project_name
=
project_name
,
project_num
=
project_num
,
project_num
=
int
(
project_num
)
,
investor_name
=
investor_name
,
investor_district
=
investor_district
,
project_type
=
project_type
,
...
...
@@ -155,7 +163,7 @@ def update_joint_project(row_content):
# 更新签约库
def
update_sign_project
(
row_content
,
upload_time
):
def
update_sign_project
(
row_content
):
try
:
project_num
=
row_content
[
0
]
# 项目编号
project_name
=
row_content
[
1
]
# 项目名称
...
...
@@ -321,8 +329,8 @@ def update_star_project(row_content):
@api_manage.route
(
"/SearchProject"
,
methods
=
[
"POST"
])
def
search_project
():
req_dic
=
request
.
get_json
()
token
=
request
.
headers
[
'token'
]
flag
=
req
uest
.
headers
[
'flag'
]
# 1为线索库,2为对接库,3为签约库,4为开工库
#
token = request.headers['token']
flag
=
req
_dic
[
'flag'
]
# 1为线索库,2为对接库,3为签约库,4为开工库
# 线索库
distribute_condition
=
req_dic
[
'distribute_condition'
]
# 分发情况
project_name
=
req_dic
[
'project_name'
]
# 项目名称
...
...
@@ -358,11 +366,11 @@ def search_project():
page
=
req_dic
[
'page'
]
per_page
=
req_dic
[
'per_page'
]
try
:
user_obj
=
verify_token
(
token
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
SESSIONERR
,
msg
=
"进行操作时用户信息校验失败,请重新登陆后尝试!"
)
#
try:
#
user_obj = verify_token(token)
#
except Exception as e:
#
current_app.logger.error(e)
#
return jsonify(code=RET.SESSIONERR, msg="进行操作时用户信息校验失败,请重新登陆后尝试!")
try
:
project_obj
=
SikuProject
.
query
.
filter
(
...
...
@@ -371,12 +379,12 @@ def search_project():
SikuProject
.
investor_name
==
investor_name
if
investor_name
else
text
(
''
),
SikuProject
.
investor_district
==
investor_district
if
investor_district
else
text
(
''
),
SikuProject
.
project_type
.
_in
(
project_type_list
)
if
project_type_list
else
SikuProject
.
project_type
==
project_type
if
project_type
else
text
(
''
),
SikuProject
.
investment_volume
>
float
(
investment_volume_list
.
split
(
'-'
)
[
0
])
if
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
<
float
(
investment_volume_list
.
split
(
'-'
)
[
1
])
if
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
>
float
(
investment_volume
.
split
(
'-'
)[
0
])
if
investment_volume
and
not
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
<
float
(
investment_volume
.
split
(
'-'
)[
1
])
if
investment_volume
and
not
investment_volume_list
else
text
(
''
),
SikuProject
.
project_year
>
project_year_list
[
0
]
if
project_year_list
else
text
(
''
),
SikuProject
.
project_year
<
project_year_list
[
1
]
if
project_year_list
else
text
(
''
),
SikuProject
.
investment_volume
>
=
float
(
investment_volume_list
[
0
])
if
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
<
=
float
(
investment_volume_list
[
1
])
if
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
>
=
float
(
investment_volume
.
split
(
'-'
)[
0
])
if
investment_volume
and
not
investment_volume_list
else
text
(
''
),
SikuProject
.
investment_volume
<
=
float
(
investment_volume
.
split
(
'-'
)[
1
])
if
investment_volume
and
not
investment_volume_list
else
text
(
''
),
SikuProject
.
project_year
>
=
project_year_list
[
0
]
if
project_year_list
else
text
(
''
),
SikuProject
.
project_year
<
=
project_year_list
[
1
]
if
project_year_list
else
text
(
''
),
SikuProject
.
project_year
==
project_year
if
project_year
and
not
project_year_list
else
text
(
''
),
SikuProject
.
thread_progress
.
_in
(
thread_progress_list
)
if
thread_progress_list
else
SikuProject
.
thread_progress
==
thread_progress
if
thread_progress
else
text
(
''
),
...
...
@@ -484,33 +492,138 @@ def search_project():
return
jsonify
(
code
=
RET
.
DBERR
,
msg
=
"查询数据库错误!"
)
# 新增线索
@api_manage.route
(
"/AddProject"
,
methods
=
[
"POST"
])
def
add_project
():
token
=
request
.
headers
[
'token'
]
try
:
user_obj
=
verify_token
(
token
)
upload_people
=
user_obj
.
real_name
user_id
=
user_obj
.
id
upload_unity
=
user_obj
.
belong_organization
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
SESSIONERR
,
msg
=
"进行批量导入操作时用户信息校验失败,请重新登陆后尝试!"
)
req_dic
=
request
.
get_json
()
project_name
=
req_dic
[
'project_name'
]
investor_name
=
req_dic
[
'investor_name'
]
investor_district
=
req_dic
[
'investor_district'
]
project_type
=
req_dic
[
'project_type'
]
investment_volume
=
req_dic
[
'investment_volume'
]
project_info
=
req_dic
[
'project_info'
]
thread_people
=
req_dic
[
'thread_people'
]
thread_people_unity
=
req_dic
[
'thread_people_unity'
]
thread_people_mobile
=
req_dic
[
'thread_people_mobile'
]
thread_progress
=
req_dic
[
'thread_progress'
]
investment_volume1
=
req_dic
[
'investment_volume1'
]
project_info1
=
req_dic
[
'project_info1'
]
stop_reason
=
req_dic
[
'stop_reason'
]
thread_source
=
req_dic
[
'thread_source'
]
cooperation_way
=
req_dic
[
'cooperation_way'
]
other_source
=
req_dic
[
'other_source'
]
remark
=
req_dic
[
'remark'
]
upload_time
=
datetime
.
now
()
.
strftime
(
"
%
Y/
%
m/
%
d"
)
time_strf
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d"
)
# 项目编号
project_obj_list
=
SikuProject
.
query
.
all
()
max_project_num
=
''
if
project_obj_list
:
max_project_num
=
max
([
project_obj
.
project_num
for
project_obj
in
project_obj_list
])
if
max_project_num
:
max_project_num
=
max_project_num
[
8
:]
num
=
get_num
(
max_project_num
)
if
num
==
'error'
:
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
'编号超出三位的规定范围,请联系管理员'
)
project_num
=
time_strf
+
num
else
:
project_num
=
time_strf
+
'001'
# 创建项目
try
:
new_project_obj
=
SikuProject
(
upload_unity
=
upload_unity
,
upload_people
=
upload_people
,
upload_time
=
upload_time
,
project_year
=
upload_time
.
split
(
'/'
)[
0
],
project_num
=
int
(
project_num
),
project_name
=
project_name
,
investor_name
=
investor_name
,
investor_district
=
investor_district
,
project_type
=
project_type
,
investment_volume
=
investment_volume
,
project_info
=
project_info
,
thread_people
=
thread_people
,
thread_people_unity
=
thread_people_unity
,
thread_people_mobile
=
thread_people_mobile
,
thread_progress
=
thread_progress
,
investment_volume1
=
investment_volume1
,
project_info1
=
project_info1
,
stop_reason
=
stop_reason
,
thread_source
=
thread_source
,
cooperation_way
=
cooperation_way
,
other_source
=
other_source
,
remark
=
remark
,
)
db
.
session
.
add
(
new_project_obj
)
db
.
session
.
commit
()
return
jsonify
(
code
=
RET
.
OK
,
msg
=
'新增成功!'
)
except
Exception
as
e
:
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
'新增失败!'
)
# 批量删除
@api_manage.route
(
"/BatchDel"
,
methods
=
[
"POST"
])
def
batch_del
():
req_dic
=
request
.
get_json
()
token
=
request
.
headers
[
'token'
]
try
:
user_obj
=
verify_token
(
token
)
user_name
=
user_obj
.
real_name
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
SESSIONERR
,
msg
=
"进行批量导入操作时用户信息校验失败,请重新登陆后尝试!"
)
select_id_list
=
req_dic
[
"select_id_list"
]
try
:
for
select_id
in
select_id_list
:
project_obj
=
SikuProject
.
query
.
get
(
select_id
)
db
.
session
.
remove
(
project_obj
)
db
.
session
.
commit
()
continue
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
"批量删除出错!"
)
# 线索库批量导入
@api_manage.route
(
"/UploadProjectData"
,
methods
=
[
"POST"
])
def
upload_project_data1
():
# token = request.headers['token']
req_dic
=
request
.
get_json
()
data_type
=
req_dic
[
'data_type'
]
# 1为线索库,2为对接库,3为签约库,4为开工库
# try:
# user_obj = verify_token(token)
# district_name = user_obj.district_name
# user_name = user_obj.real_name
# user_id = user_obj.id
# unit = user_obj.unit
# except Exception as e:
# current_app.logger.error(e)
# return jsonify(code=RET.SESSIONERR, msg="进行批量导入操作时用户信息校验失败,请重新登陆后尝试!")
token
=
request
.
headers
[
'token'
]
data_type
=
request
.
form
[
'data_type'
]
# 1为线索库,2为对接库,3为签约库,4为开工库
try
:
user_obj
=
verify_token
(
token
)
# district_name = user_obj.district_name
upload_people
=
user_obj
.
real_name
user_id
=
user_obj
.
id
upload_unity
=
user_obj
.
belong_organization
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
SESSIONERR
,
msg
=
"进行批量导入操作时用户信息校验失败,请重新登陆后尝试!"
)
# 上传的文件
file
=
request
.
files
[
'file'
]
upload_time
=
datetime
.
now
()
.
strftime
(
"
%
Y/
%
m/
%
d"
)
time_strf
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d"
)
upload_time1
=
(
datetime
.
now
()
+
relativedelta
(
months
=
2
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
year
=
str
(
datetime
.
now
()
.
year
)
try
:
f
=
file
.
read
()
# 文件内容
data
=
xlrd
.
open_workbook
(
file_contents
=
f
)
table
=
data
.
sheets
()[
data_type
]
table
=
data
.
sheets
()[
0
]
names
=
data
.
sheet_names
()
# 返回book中所有工作表的名字
status
=
data
.
sheet_loaded
(
names
[
0
])
# 检查sheet1是否导入完毕
print
(
status
)
...
...
@@ -533,20 +646,20 @@ def upload_project_data1():
return
jsonify
(
code
=
RET
.
NODATA
,
msg
=
"{}表格内无有效数据!"
.
format
(
'线索库'
if
data_type
==
1
else
'对接库'
if
data_type
==
2
else
'签约库'
if
data_type
==
3
else
'开工库'
if
data_type
==
4
else
''
))
if
data_type
==
1
:
# 上传线索库
if
int
(
data_type
)
==
1
:
# 上传线索库
# 判断该项目名称是否已经存在
# project_num = row_content[0]
project_name
=
row_content
[
1
]
project_obj
=
SikuProject
.
query
.
filter
(
SikuProject
.
project_name
==
project_name
,
SikuProject
.
is_delete
==
0
,
)
.
first
()
#
project_name = row_content[1]
#
project_obj = SikuProject.query.filter(
#
SikuProject.project_name == project_name,
#
SikuProject.is_delete == 0,
#
).first()
# 记录同名的项目名称
if
project_obj
and
project_name
==
project_obj
.
project_name
:
rep_project_num
+=
1
continue
ret
=
upload_xiansuo_project
(
row_content
,
time_strf
,
upload_time
)
#
if project_obj and project_name == project_obj.project_name:
#
rep_project_num += 1
#
continue
ret
=
upload_xiansuo_project
(
row_content
,
time_strf
,
upload_time
,
upload_unity
,
upload_people
)
if
ret
==
'continue'
:
add_num
+=
1
continue
...
...
@@ -556,7 +669,7 @@ def upload_project_data1():
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
'数据入库出错,错误位置为第【{}】行!'
.
format
(
i
))
else
:
pass
if
data_type
==
2
:
# 更新对接库
if
int
(
data_type
)
==
2
:
# 更新对接库
ret
=
update_joint_project
(
row_content
)
if
ret
==
'continue'
:
update_num
+=
1
...
...
@@ -566,7 +679,7 @@ def upload_project_data1():
else
:
pass
if
data_type
==
3
:
# 更新签约库
if
int
(
data_type
)
==
3
:
# 更新签约库
ret
=
update_sign_project
(
row_content
)
if
ret
==
'continue'
:
update_num
+=
1
...
...
@@ -575,7 +688,7 @@ def upload_project_data1():
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
'数据更新出错,错误位置为第【{}】行!'
.
format
(
i
))
else
:
pass
if
data_type
==
4
:
# 更新开工库
if
int
(
data_type
)
==
4
:
# 更新开工库
ret
=
update_star_project
(
row_content
)
if
ret
==
'continue'
:
update_num
+=
1
...
...
@@ -584,15 +697,18 @@ def upload_project_data1():
return
jsonify
(
code
=
RET
.
DATAERR
,
msg
=
'数据更新出错,错误位置为第【{}】行!'
.
format
(
i
))
else
:
pass
if
data_type
==
1
and
rep_project_li
:
if
int
(
data_type
)
==
1
and
rep_project_li
:
return
jsonify
(
code
=
RET
.
OK
,
list
=
rep_project_li
,
msg
=
'本次导入项目信息共{}个,新增项目信息{}个,其中包含重复名称项目{}个,'
'请在以下重复名称项目列表选择相应操作项并提交!'
.
format
(
total_num
,
add_num
,
rep_project_num
))
el
se
:
el
if
int
(
data_type
)
==
1
:
return
jsonify
(
code
=
RET
.
OK
,
list
=
rep_project_li
,
msg
=
'本次更新项目信息共{}个。'
.
format
(
update_num
))
msg
=
'成功新增项目共{}个。'
.
format
(
add_num
))
else
:
return
jsonify
(
code
=
RET
.
OK
,
msg
=
'成功更新项目共{}个。'
.
format
(
update_num
))
# 下载模板
...
...
@@ -607,171 +723,171 @@ def download_xlsx():
# current_app.logger.error(e)
# return jsonify(code=RET.DBERR, msg="进行{}操作时用户信息校验失败,请重新登陆后尝试!".format(action_name))
build_template
=
"http://39.100.39.50:8008/aaa_statics/线索库上传模板.xlsx"
return
build_template
return
jsonify
(
code
=
RET
.
OK
,
data
=
build_template
,
msg
=
"链接获取成功!"
)
# 批量导出-线索库数据
@api_manage.route
(
"/BatchExportProject"
,
methods
=
[
"POST"
])
# 批量导出测试
def
batch_export_project
():
req_dic
=
request
.
get_json
()
token
=
request
.
headers
[
'token'
]
try
:
user_obj
=
verify_token
(
token
)
user_name
=
user_obj
.
real_name
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
SESSIONERR
,
msg
=
"进行批量导入操作时用户信息校验失败,请重新登陆后尝试!"
)
select_id_list
=
req_dic
[
"select_id_list"
]
path
=
'./apps/statics/project_file/'
# path = 'D:/中研项目代码/new_ty
/apps/statics/project_file/'
pro_path
=
'http://39.100.39.50:5051/statics/project_file/'
# 项目路径
if
not
select_id_list
:
return
jsonify
(
code
=
RET
.
PARAMERR
,
msg
=
"参数不能为空!"
)
target_data_list
=
[]
for
select_id
in
select_id_list
:
try
:
project_obj
=
SikuProject
.
query
.
filter_by
(
id
=
select_id
)
.
first
()
# 提取数据,写入xslx表格
data_list
=
[]
distribute_condition
=
project_obj
.
distribute_condition
# 分发情况
data_list
.
append
(
distribute_condition
)
project_name
=
project_obj
.
project_name
# 项目名称
data_list
.
append
(
project_name
)
investor_name
=
project_obj
.
investor_name
# 投资方名称
data_list
.
append
(
investor_name
)
investor_district
=
project_obj
.
investor_district
# 投资方所在地
data_list
.
append
(
investor_district
)
project_type
=
project_obj
.
project_type
# 项目类型
data_list
.
append
(
project_type
)
investment_volume
=
project_obj
.
investment_volume
# 总投资额(万元)
data_list
.
append
(
investment_volume
)
project_year
=
project_obj
.
project_year
# 项目年份
data_list
.
append
(
project_year
)
project_info
=
project_obj
.
project_info
# 项目基本情况
data_list
.
append
(
project_info
)
thread_people
=
project_obj
.
thread_people
# 线索提供人
data_list
.
append
(
thread_people
)
thread_people_mobile
=
project_obj
.
thread_people_mobile
# 线索提供人联系方式
data_list
.
append
(
thread_people_mobile
)
thread_progress
=
project_obj
.
thread_progress
# 线索进展
data_list
.
append
(
thread_progress
)
target_data_list
.
append
(
data_list
)
# 记录项目动态
time
=
datetime
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
DBERR
,
msg
=
"数据库查询错误!"
)
try
:
sheet_name_titles
=
{
"sheet1"
:
[
"项目编号(自动生成)"
,
"项目名称"
,
"投资方名称"
,
"投资方所在地"
,
"项目类型"
,
"总投资额(万元)"
,
"拟引资额(万元)"
,
"项目基本情况"
,
"项目方基本情况"
,
"线索提供人"
,
"单位及职务"
,
"联系方式"
,
"备注"
,]}
# 大标题(居中、加粗、字号)
style
=
xlwt
.
XFStyle
()
al
=
xlwt
.
Alignment
()
al
.
horz
=
0x02
# 设置水平居中
al
.
vert
=
0x01
# 设置垂直居中
style
.
alignment
=
al
# 为样式创建字体
font
=
xlwt
.
Font
()
font
.
name
=
'Times New Roman'
# 字体
font
.
bold
=
True
# 加粗
font
.
height
=
0x00C8
*
2
# 设置样式
style
.
font
=
font
# 表头(居中、加粗)
style1
=
xlwt
.
XFStyle
()
al1
=
xlwt
.
Alignment
()
al1
.
horz
=
0x02
# 设置水平居中
al1
.
vert
=
0x01
# 设置垂直居中
style1
.
alignment
=
al1
# style1.alignment.wrap = 1 # 设置自动换行
# 为样式创建字体
font
=
xlwt
.
Font
()
font
.
name
=
'Times New Roman'
# 字体
font
.
bold
=
True
# 加粗
# 设置样式
style1
.
font
=
font
# 设置边框(THIN实线/DASHED虚线)
borders
=
xlwt
.
Borders
()
borders
.
left
=
xlwt
.
Borders
.
THIN
borders
.
right
=
xlwt
.
Borders
.
THIN
borders
.
top
=
xlwt
.
Borders
.
THIN
borders
.
bottom
=
xlwt
.
Borders
.
THIN
style1
.
borders
=
borders
# Add Borders to Style
# 普通内容
style2
=
xlwt
.
XFStyle
()
al2
=
xlwt
.
Alignment
()
al2
.
horz
=
0x02
# 设置水平居中
al2
.
vert
=
0x01
# 设置垂直居中
style2
.
alignment
=
al2
style2
.
alignment
.
wrap
=
1
# 设置自动换行
# 设置边框(THIN实线/DASHED虚线)
borders
=
xlwt
.
Borders
()
borders
.
left
=
xlwt
.
Borders
.
THIN
borders
.
right
=
xlwt
.
Borders
.
THIN
borders
.
top
=
xlwt
.
Borders
.
THIN
borders
.
bottom
=
xlwt
.
Borders
.
THIN
style2
.
borders
=
borders
# Add Borders to Style
# 需要左对齐的 7建设内容、12最新进展、13需要解决的问题
style3
=
xlwt
.
XFStyle
()
al3
=
xlwt
.
Alignment
()
al3
.
horz
=
0x01
# 设置左对齐
al3
.
vert
=
0x01
# 设置垂直居中
style3
.
alignment
=
al3
style3
.
alignment
.
wrap
=
1
# 设置自动换行
# 设置边框(THIN实线/DASHED虚线)
borders
=
xlwt
.
Borders
()
borders
.
left
=
xlwt
.
Borders
.
THIN
borders
.
right
=
xlwt
.
Borders
.
THIN
borders
.
top
=
xlwt
.
Borders
.
THIN
borders
.
bottom
=
xlwt
.
Borders
.
THIN
style3
.
borders
=
borders
# Add Borders to Style
# 创建excel
excel
=
xlwt
.
Workbook
(
encoding
=
'utf-8'
)
# 写入表头
for
k
,
v
in
sheet_name_titles
.
items
():
sheet_name
=
k
sheet
=
excel
.
add_sheet
(
sheet_name
)
# 写入大标题
title_name
=
'线索库'
# 合并单元格,合并第2行到第4行的第4列到第5列
sheet
.
write_merge
(
0
,
0
,
0
,
17
,
title_name
,
style
)
tall_style
=
xlwt
.
easyxf
(
'font:height 720'
)
sheet
.
row
(
0
)
.
set_style
(
tall_style
)
# 写入表头
head_list
=
v
for
j
in
range
(
len
(
head_list
)):
sheet
.
write
(
1
,
j
,
head_list
[
j
],
style1
)
# 设置单元格列宽
if
j
in
[
7
,
12
,
13
]:
sheet
.
col
(
j
)
.
width
=
50
*
256
else
:
sheet
.
col
(
j
)
.
width
=
30
*
256
"""===================我是一条木得感情的分割线============================="""
# 写入内容
for
index
,
value_list
in
enumerate
(
target_data_list
,
2
):
for
i
,
value
in
enumerate
(
value_list
):
if
i
in
[
7
,
12
,
13
]:
sheet
.
write
(
index
,
i
,
value
,
style3
)
else
:
sheet
.
write
(
index
,
i
,
value
,
style2
)
time_stamp
=
'{0:
%
Y
%
m
%
d
%
H
%
M
%
S}'
.
format
(
datetime
.
now
())
file_name
=
"招商引资项目台账{}.xlsx"
.
format
(
time_stamp
)
excel
.
save
(
path
+
file_name
)
return
jsonify
(
code
=
RET
.
OK
,
url
=
pro_path
+
file_name
,
msg
=
"导出/下载成功!"
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
jsonify
(
code
=
RET
.
DBERR
,
msg
=
"批量导出操作失败!"
)
# @api_manage.route("/BatchExportProject", methods=["POST"])
#
def batch_export_project():
#
req_dic = request.get_json()
#
token = request.headers['token']
#
#
try:
#
user_obj = verify_token(token)
#
user_name = user_obj.real_name
#
except Exception as e:
#
current_app.logger.error(e)
#
return jsonify(code=RET.SESSIONERR, msg="进行批量导入操作时用户信息校验失败,请重新登陆后尝试!")
#
#
select_id_list = req_dic["select_id_list"]
#
path = './apps/statics/project_file/'
# path = 'D:/中研项目代码/flask_jincheng
/apps/statics/project_file/'
# #
pro_path = 'http://39.100.39.50:5051/statics/project_file/' # 项目路径
#
if not select_id_list:
#
return jsonify(code=RET.PARAMERR, msg="参数不能为空!")
#
target_data_list = []
#
for select_id in select_id_list:
#
try:
#
project_obj = SikuProject.query.filter_by(id=select_id).first()
#
# 提取数据,写入xslx表格
#
data_list = []
#
distribute_condition = project_obj.distribute_condition # 分发情况
#
data_list.append(distribute_condition)
#
project_name = project_obj.project_name # 项目名称
#
data_list.append(project_name)
#
investor_name = project_obj.investor_name # 投资方名称
#
data_list.append(investor_name)
#
investor_district = project_obj.investor_district # 投资方所在地
#
data_list.append(investor_district)
#
project_type = project_obj.project_type # 项目类型
#
data_list.append(project_type)
#
investment_volume = project_obj.investment_volume # 总投资额(万元)
#
data_list.append(investment_volume)
#
project_year = project_obj.project_year # 项目年份
#
data_list.append(project_year)
#
project_info = project_obj.project_info # 项目基本情况
#
data_list.append(project_info)
#
thread_people = project_obj.thread_people # 线索提供人
#
data_list.append(thread_people)
#
thread_people_mobile = project_obj.thread_people_mobile # 线索提供人联系方式
#
data_list.append(thread_people_mobile)
#
thread_progress = project_obj.thread_progress # 线索进展
#
data_list.append(thread_progress)
#
target_data_list.append(data_list)
#
# 记录项目动态
#
time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#
except Exception as e:
#
current_app.logger.error(e)
#
return jsonify(code=RET.DBERR, msg="数据库查询错误!")
#
try:
#
sheet_name_titles = {
#
"sheet1": ["项目编号(自动生成)", "项目名称", "投资方名称", "投资方所在地", "项目类型",
#
"总投资额(万元)", "拟引资额(万元)", "项目基本情况", "项目方基本情况", "线索提供人",
#
"单位及职务", "联系方式", "备注",]}
#
#
# 大标题(居中、加粗、字号)
#
style = xlwt.XFStyle()
#
al = xlwt.Alignment()
#
al.horz = 0x02 # 设置水平居中
#
al.vert = 0x01 # 设置垂直居中
#
style.alignment = al
#
# 为样式创建字体
#
font = xlwt.Font()
#
font.name = 'Times New Roman' # 字体
#
font.bold = True # 加粗
#
font.height = 0x00C8 * 2
#
# 设置样式
#
style.font = font
#
#
# 表头(居中、加粗)
#
style1 = xlwt.XFStyle()
#
al1 = xlwt.Alignment()
#
al1.horz = 0x02 # 设置水平居中
#
al1.vert = 0x01 # 设置垂直居中
#
style1.alignment = al1
#
# style1.alignment.wrap = 1 # 设置自动换行
#
# 为样式创建字体
#
font = xlwt.Font()
#
font.name = 'Times New Roman' # 字体
#
font.bold = True # 加粗
#
# 设置样式
#
style1.font = font
#
# 设置边框(THIN实线/DASHED虚线)
#
borders = xlwt.Borders()
#
borders.left = xlwt.Borders.THIN
#
borders.right = xlwt.Borders.THIN
#
borders.top = xlwt.Borders.THIN
#
borders.bottom = xlwt.Borders.THIN
#
style1.borders = borders # Add Borders to Style
#
#
# 普通内容
#
style2 = xlwt.XFStyle()
#
al2 = xlwt.Alignment()
#
al2.horz = 0x02 # 设置水平居中
#
al2.vert = 0x01 # 设置垂直居中
#
style2.alignment = al2
#
style2.alignment.wrap = 1 # 设置自动换行
#
# 设置边框(THIN实线/DASHED虚线)
#
borders = xlwt.Borders()
#
borders.left = xlwt.Borders.THIN
#
borders.right = xlwt.Borders.THIN
#
borders.top = xlwt.Borders.THIN
#
borders.bottom = xlwt.Borders.THIN
#
style2.borders = borders # Add Borders to Style
#
#
# 需要左对齐的 7建设内容、12最新进展、13需要解决的问题
#
style3 = xlwt.XFStyle()
#
al3 = xlwt.Alignment()
#
al3.horz = 0x01 # 设置左对齐
#
al3.vert = 0x01 # 设置垂直居中
#
style3.alignment = al3
#
style3.alignment.wrap = 1 # 设置自动换行
#
# 设置边框(THIN实线/DASHED虚线)
#
borders = xlwt.Borders()
#
borders.left = xlwt.Borders.THIN
#
borders.right = xlwt.Borders.THIN
#
borders.top = xlwt.Borders.THIN
#
borders.bottom = xlwt.Borders.THIN
#
style3.borders = borders # Add Borders to Style
#
#
# 创建excel
#
excel = xlwt.Workbook(encoding='utf-8')
#
# 写入表头
#
for k, v in sheet_name_titles.items():
#
sheet_name = k
#
sheet = excel.add_sheet(sheet_name)
#
# 写入大标题
#
title_name = '线索库'
#
# 合并单元格,合并第2行到第4行的第4列到第5列
#
sheet.write_merge(0, 0, 0, 17, title_name, style)
#
tall_style = xlwt.easyxf('font:height 720')
#
sheet.row(0).set_style(tall_style)
#
# 写入表头
#
head_list = v
#
for j in range(len(head_list)):
#
sheet.write(1, j, head_list[j], style1)
#
# 设置单元格列宽
#
if j in [7, 12, 13]:
#
sheet.col(j).width = 50 * 256
#
else:
#
sheet.col(j).width = 30 * 256
#
#
"""===================我是一条木得感情的分割线============================="""
#
#
# 写入内容
#
for index, value_list in enumerate(target_data_list, 2):
#
for i, value in enumerate(value_list):
#
if i in [7, 12, 13]:
#
sheet.write(index, i, value, style3)
#
else:
#
sheet.write(index, i, value, style2)
#
time_stamp = '{0:%Y%m%d%H%M%S}'.format(datetime.now())
#
file_name = "招商引资项目台账{}.xlsx".format(time_stamp)
#
excel.save(path + file_name)
#
return jsonify(code=RET.OK, url=pro_path + file_name, msg="导出/下载成功!")
#
except Exception as e:
#
current_app.logger.error(e)
#
return jsonify(code=RET.DBERR, msg="批量导出操作失败!")
...
...
apps/models.py
View file @
4d6a5bf8
...
...
@@ -1032,59 +1032,6 @@ class GovDepartment(db.Model):
"""招商资源管理"""
# 项目化管理V2-项目信息表
# class ProjectManagement2(db.Model):
# __tablename_ = "project_management2"
# __table_args__ = ({'comment': '项目化管理V2-项目信息表'}) # 添加表注释
# # 项目标签
# id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键id')
# is_delete = db.Column(db.Integer, comment='逻辑删除 1是0否')
# upload_people = db.Column(db.String(20), comment='填报人(负责人)')
# upload_unity = db.Column(db.String(20), comment='填报人(负责人)单位')
# upload_time = db.Column(db.String(30), comment='填报时间')
# upload_time1 = db.Column(db.String(30), comment='填报后两个月的时间')
# update_time = db.Column(db.String(30), comment='更新时间')
# update_time1 = db.Column(db.String(30), comment='更新后两个月的时间')
# upload_people_id = db.Column(db.Integer, comment='填报人id')
# upload_people_district = db.Column(db.String(20), comment='填报人归属区域')
#
# project_audit_status = db.Column(db.Integer, comment='项目审核状态id 0为待审核;1为审核通过;2为未通过')
# project_audit_message = db.Column(db.String(30), comment='审核信息')
# project_audit_time = db.Column(db.String(30), comment='审核时间')
#
# project_name = db.Column(db.String(200), comment='项目名称')
# project_num = db.Column(db.String(30), comment='项目编号')
# project_type = db.Column(db.Integer, comment='项目类型 市重点项目/非市重点项目')
# district = db.Column(db.String(20), comment='承接区县')
# site = db.Column(db.String(50), comment='具体地址')
# project_unit = db.Column(db.String(100), comment='项目单位(投资方)')
# province = db.Column(db.String(150), comment='项目引进省份')
# industry = db.Column(db.String(20), comment='项目所属行业')
# investment_volume = db.Column(db.Float, comment='总投资额(亿元)')
# acre_intensity = db.Column(db.Float, comment='亩均强度(万元)')
# construction_content = db.Column(db.String(255), comment='建设内容')
# project_appeal = db.Column(db.String(255), comment='项目诉求')
# project_promise = db.Column(db.String(255), comment='项目承诺')
# schedule_node = db.Column(db.String(20), comment='进度节点 在谈,已签约,已开工,已投产,拟签约,拟开工,拟投产,暂停/终止')
# time1 = db.Column(db.String(30), comment='签约时间')
# time2 = db.Column(db.String(30), comment='开工时间')
# time3 = db.Column(db.String(30), comment='投产时间')
# project_schedule = db.Column(db.String(255), comment='最新进展')
# plan = db.Column(db.String(255), comment='近期计划')
# project_problem = db.Column(db.String(255), comment='需要解决的问题')
# schedule_condition = db.Column(db.String(20), comment='调度情况')
# supervisory_requirements = db.Column(db.String(20), comment='督办要求')
# capital_condition_type = db.Column(db.String(20), comment='资金到位情况类型 固投资金/非固投资金')
# capital_condition_money = db.Column(db.Float, comment='资金到位情况 数额')
# is_importance = db.Column(db.String(20), comment='是否属于市重点项目')
# project_source = db.Column(db.String(20), comment='项目来源')
# is_enter13710 = db.Column(db.String(20), comment='是否报入13710系统')
# project_people = db.Column(db.String(20), comment='项目单位负责人')
# district_people = db.Column(db.String(20), comment='项目承接地负责人')
# unity_people = db.Column(db.String(20), comment='项目单位负责人')
# add_or_update = db.Column(db.Integer, comment='是新增的还是更新过的 1新增,2更新')
# remind_month = db.Column(db.Integer, comment='上一次两个月未更新的提醒月份')
# # file_id_list = db.Column(db.String(255), comment='项目相关文件id列表')
class
SikuProject
(
db
.
Model
):
# 四库管理-项目信息表
...
...
@@ -1110,7 +1057,7 @@ class SikuProject(db.Model): # 四库管理-项目信息表
upload_unity
=
db
.
Column
(
db
.
String
(
20
),
comment
=
'上传部门'
)
upload_people
=
db
.
Column
(
db
.
String
(
20
),
comment
=
'上传人'
)
upload_time
=
db
.
Column
(
db
.
DateTime
,
comment
=
'上传时间'
)
project_num
=
db
.
Column
(
db
.
Integer
,
comment
=
'项目编号'
)
project_num
=
db
.
Column
(
db
.
String
(
30
)
,
comment
=
'项目编号'
)
investment_volume1
=
db
.
Column
(
db
.
Float
,
comment
=
'拟引资额(万元)'
)
project_info1
=
db
.
Column
(
db
.
String
(
300
),
comment
=
'项目方基本情况'
)
project_schedule
=
db
.
Column
(
db
.
String
(
20
),
comment
=
'项目进展'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment