|
@@ -1,4 +1,5 @@
|
|
import json
|
|
import json
|
|
|
|
+import base64
|
|
import os
|
|
import os
|
|
|
|
|
|
from flask import request, jsonify, g, current_app
|
|
from flask import request, jsonify, g, current_app
|
|
@@ -124,12 +125,11 @@ class TemplateConfigApi(Resource):
|
|
if template_name is None and template_type is None:
|
|
if template_name is None and template_type is None:
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='报表模版名和模版类型不能为空')
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='报表模版名和模版类型不能为空')
|
|
|
|
|
|
- # 模版存储(url),
|
|
|
|
if template_file:
|
|
if template_file:
|
|
- template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
|
- template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
|
|
|
|
|
|
+ template_file.save(os.path.join(config.common.SAVE_FILE_PATH, template_file.filename))
|
|
|
|
+ template_file_name = template_file.filename
|
|
else:
|
|
else:
|
|
- template_url = None
|
|
|
|
|
|
+ template_file_name = None
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
@@ -148,7 +148,7 @@ class TemplateConfigApi(Resource):
|
|
creator=g.user_name,
|
|
creator=g.user_name,
|
|
create_time=cn_now(),
|
|
create_time=cn_now(),
|
|
update_time=cn_now(),
|
|
update_time=cn_now(),
|
|
- template_url=template_url,
|
|
|
|
|
|
+ template=template_file_name,
|
|
template_type=template_type
|
|
template_type=template_type
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
@@ -177,12 +177,11 @@ class TemplateConfigApi(Resource):
|
|
if template_id is None or template_name is None:
|
|
if template_id is None or template_name is None:
|
|
return jsonify(code=StatesCode.PARA_ERROR, message="模版id和模版名不能为空")
|
|
return jsonify(code=StatesCode.PARA_ERROR, message="模版id和模版名不能为空")
|
|
|
|
|
|
- # 报表模版存储(url),
|
|
|
|
if template_file:
|
|
if template_file:
|
|
- template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
|
- template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
|
|
|
|
|
|
+ template_file.save(os.path.join(config.common.SAVE_FILE_PATH, template_file.filename))
|
|
|
|
+ template_file_name = template_file.filename
|
|
else:
|
|
else:
|
|
- template_url = None
|
|
|
|
|
|
+ template_file_name = None
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
stmt = update(Template).where(Template.id == template_id).values(
|
|
stmt = update(Template).where(Template.id == template_id).values(
|
|
@@ -193,7 +192,7 @@ class TemplateConfigApi(Resource):
|
|
creator=g.user_name,
|
|
creator=g.user_name,
|
|
create_time=cn_now(),
|
|
create_time=cn_now(),
|
|
update_time=cn_now(),
|
|
update_time=cn_now(),
|
|
- template_url=template_url,
|
|
|
|
|
|
+ template=template_file_name,
|
|
template_type=template_type
|
|
template_type=template_type
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
@@ -318,12 +317,14 @@ class CompanyApi(Resource):
|
|
if management_unit is None:
|
|
if management_unit is None:
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='管理单位不能为空')
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='管理单位不能为空')
|
|
|
|
|
|
- # 多图片存储(url),
|
|
|
|
- picture_urls = []
|
|
|
|
|
|
+ pictures_base64 = []
|
|
|
|
+
|
|
if pictures:
|
|
if pictures:
|
|
for picture in pictures:
|
|
for picture in pictures:
|
|
- picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
|
- picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
+ ext = picture.filename.split('.')[-1]
|
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
|
+ pictures_base64.append(base64_data)
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
@@ -340,7 +341,7 @@ class CompanyApi(Resource):
|
|
introduction=introduction,
|
|
introduction=introduction,
|
|
contact_person=contact_person,
|
|
contact_person=contact_person,
|
|
contact_information=contact_information,
|
|
contact_information=contact_information,
|
|
- picture=json.dumps(picture_urls),
|
|
|
|
|
|
+ picture=json.dumps(pictures_base64),
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
|
|
|
|
@@ -369,12 +370,15 @@ class CompanyApi(Resource):
|
|
if company_id is None:
|
|
if company_id is None:
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
return jsonify(code=StatesCode.PARA_ERROR, message='公司id不能为空')
|
|
|
|
|
|
- # 多图片存储(url),
|
|
|
|
- picture_urls = []
|
|
|
|
|
|
+ pictures_base64 = []
|
|
|
|
+
|
|
if pictures:
|
|
if pictures:
|
|
for picture in pictures:
|
|
for picture in pictures:
|
|
- picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
|
- picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
+
|
|
|
|
+ ext = picture.filename.split('.')[-1]
|
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
|
+ pictures_base64.append(base64_data)
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
@@ -384,7 +388,7 @@ class CompanyApi(Resource):
|
|
introduction=introduction,
|
|
introduction=introduction,
|
|
contact_person=contact_person,
|
|
contact_person=contact_person,
|
|
contact_information=contact_information,
|
|
contact_information=contact_information,
|
|
- picture=json.dumps(picture_urls),
|
|
|
|
|
|
+ picture=json.dumps(pictures_base64),
|
|
)
|
|
)
|
|
|
|
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
@@ -476,12 +480,14 @@ class BuildingApi(Resource):
|
|
if building_name is None:
|
|
if building_name is None:
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇名称不能为空')
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇名称不能为空')
|
|
|
|
|
|
- # 多图片存储(url),
|
|
|
|
- picture_urls = []
|
|
|
|
|
|
+ pictures_base64 = []
|
|
if pictures:
|
|
if pictures:
|
|
for picture in pictures:
|
|
for picture in pictures:
|
|
- picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
|
- picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
+
|
|
|
|
+ ext = picture.filename.split('.')[-1]
|
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
|
+ pictures_base64.append(base64_data)
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
@@ -494,7 +500,7 @@ class BuildingApi(Resource):
|
|
contact_person=contact_person,
|
|
contact_person=contact_person,
|
|
contact_information=contact_information,
|
|
contact_information=contact_information,
|
|
introduction=building_introduction,
|
|
introduction=building_introduction,
|
|
- picture=json.dumps(picture_urls)
|
|
|
|
|
|
+ picture=json.dumps(pictures_base64)
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
session.commit()
|
|
session.commit()
|
|
@@ -524,12 +530,14 @@ class BuildingApi(Resource):
|
|
if building_id is None and building_name is None:
|
|
if building_id is None and building_name is None:
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id和楼宇名称不能为空')
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id和楼宇名称不能为空')
|
|
|
|
|
|
- # 多图片存储(url),
|
|
|
|
- picture_urls = []
|
|
|
|
|
|
+ pictures_base64 = []
|
|
if pictures:
|
|
if pictures:
|
|
for picture in pictures:
|
|
for picture in pictures:
|
|
- picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
|
- picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
+
|
|
|
|
+ ext = picture.filename.split('.')[-1]
|
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
|
+ pictures_base64.append(base64_data)
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
@@ -542,7 +550,7 @@ class BuildingApi(Resource):
|
|
contact_person=contact_person,
|
|
contact_person=contact_person,
|
|
contact_information=contact_information,
|
|
contact_information=contact_information,
|
|
introduction=building_introduction,
|
|
introduction=building_introduction,
|
|
- picture=json.dumps(picture_urls)
|
|
|
|
|
|
+ picture=json.dumps(pictures_base64)
|
|
)
|
|
)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
session.commit()
|
|
session.commit()
|
|
@@ -607,23 +615,25 @@ class UnderlyingSystemMessageApi(Resource):
|
|
"""添加底层系统信息"""
|
|
"""添加底层系统信息"""
|
|
picture = request.files.get('picture')
|
|
picture = request.files.get('picture')
|
|
|
|
|
|
- # 存储(url),
|
|
|
|
if picture:
|
|
if picture:
|
|
- picture.save(os.path.join(config.common.UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
|
|
|
|
- picture_url = config.common.UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
|
|
|
|
|
|
+ ext = picture.filename.split('.')[-1]
|
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(picture.read())
|
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
|
+ else:
|
|
|
|
+ base64_data = None
|
|
|
|
|
|
- try:
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
|
- stmt = insert(UnderlyingSystem).values(
|
|
|
|
- picture=picture_url
|
|
|
|
- )
|
|
|
|
- session.execute(stmt)
|
|
|
|
- session.commit()
|
|
|
|
|
|
+ try:
|
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
|
+ stmt = insert(UnderlyingSystem).values(
|
|
|
|
+ picture=base64_data
|
|
|
|
+ )
|
|
|
|
+ session.execute(stmt)
|
|
|
|
+ session.commit()
|
|
|
|
|
|
- save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
|
|
- except Exception as e:
|
|
|
|
- save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
+ except Exception as e:
|
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|