|
@@ -1,20 +1,18 @@
|
|
|
import json
|
|
|
import os
|
|
|
|
|
|
-from flask import request, jsonify, g
|
|
|
+from flask import request, jsonify, g, current_app
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
|
from sqlalchemy import select, insert, update, delete
|
|
|
from sqlalchemy.orm import Session
|
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
-from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL, COMPANY_PICTURE_PATH, COMPANY_PICTURE_URL, \
|
|
|
- BUILDING_PICTURE_PATH, BUILDING_PICTURE_URL, UNDERLYING_SYSTEM_PICTURE_PATH, UNDERLYING_SYSTEM_PICTURE_URL
|
|
|
-from app.database import engine
|
|
|
from app.defines import StatesCode, Module, OperationType
|
|
|
from app.modle.data import Template, CompanyData, Building, UnderlyingSystem
|
|
|
from app.utils.jwt_util import login_required
|
|
|
from app.utils.save_log import save_log
|
|
|
from app.utils.util import to_dict, cn_now
|
|
|
+from config import Config
|
|
|
|
|
|
ns = Namespace('data', description='数据管理接口')
|
|
|
|
|
@@ -27,6 +25,8 @@ template_list.add_argument(name='template_type', type=str, location='args', requ
|
|
|
help='模版类型 0:报表,1:报告')
|
|
|
template_list.add_argument(name='report_type', type=str, location='args', required=False, help='报告类型')
|
|
|
|
|
|
+config = Config()
|
|
|
+
|
|
|
|
|
|
@ns.route('/template_list')
|
|
|
class TemplateConfigListApi(Resource):
|
|
@@ -43,7 +43,7 @@ class TemplateConfigListApi(Resource):
|
|
|
report_type = request.args.get('report_type')
|
|
|
template_type = request.args.get('template_type')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(Template).where(Template.template_type == template_type)
|
|
|
|
|
|
if template_name:
|
|
@@ -91,7 +91,7 @@ class TemplateConfigApi(Resource):
|
|
|
if template_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(Template).where(Template.id == template_id)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -115,12 +115,12 @@ class TemplateConfigApi(Resource):
|
|
|
|
|
|
# 模版存储(url),
|
|
|
if template_file:
|
|
|
- template_file.save(os.path.join(TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
- template_url = TEMPLATE_FILE_URL + template_file.filename
|
|
|
+ template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
+ template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
|
|
|
else:
|
|
|
template_url = None
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
# 判断是否存在
|
|
|
stmt = select(Template).where(Template.name == template_name)
|
|
|
result = session.execute(stmt).scalars().first()
|
|
@@ -164,12 +164,12 @@ class TemplateConfigApi(Resource):
|
|
|
|
|
|
# 报表模版存储(url),
|
|
|
if template_file:
|
|
|
- template_file.save(os.path.join(TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
- template_url = TEMPLATE_FILE_URL + template_file.filename
|
|
|
+ template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
|
|
|
+ template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
|
|
|
else:
|
|
|
template_url = None
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = update(Template).where(Template.id == template_id).values(
|
|
|
name=template_name,
|
|
|
format=template_format,
|
|
@@ -197,7 +197,7 @@ class TemplateConfigApi(Resource):
|
|
|
if template_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版id不能为空")
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = delete(Template).where(Template.id == template_id)
|
|
|
session.execute(stmt)
|
|
|
session.commit()
|
|
@@ -226,7 +226,7 @@ class BatchTemplateConfigApi(Resource):
|
|
|
else:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(Template).where(Template.id.in_(template_ids))
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -265,7 +265,7 @@ class CompanyApi(Resource):
|
|
|
if company_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(CompanyData).where(CompanyData.id == company_id)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -291,10 +291,10 @@ class CompanyApi(Resource):
|
|
|
picture_urls = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
- picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
|
|
|
- picture_urls.append(COMPANY_PICTURE_URL + picture.filename)
|
|
|
+ picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
+ picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
# 判断是否存在
|
|
|
stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
|
|
|
result = session.execute(stmt).scalars().first()
|
|
@@ -338,10 +338,10 @@ class CompanyApi(Resource):
|
|
|
picture_urls = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
- picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
|
|
|
- picture_urls.append(COMPANY_PICTURE_URL + picture.filename)
|
|
|
+ picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
|
|
|
+ picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = update(CompanyData).where(CompanyData.id == company_id).values(
|
|
|
management_unit=management_unit,
|
|
|
custodian_unit=custodian_unit,
|
|
@@ -367,7 +367,7 @@ class BuildingListApi(Resource):
|
|
|
def get(self):
|
|
|
"""获取楼宇列表"""
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(Building)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -405,7 +405,7 @@ class BuildingApi(Resource):
|
|
|
if building_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(Building).where(Building.id == building_id)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -434,10 +434,10 @@ class BuildingApi(Resource):
|
|
|
picture_urls = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
- picture.save(os.path.join(BUILDING_PICTURE_PATH, picture.filename))
|
|
|
- picture_urls.append(BUILDING_PICTURE_URL + picture.filename)
|
|
|
+ picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
+ picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = insert(Building).values(
|
|
|
name=building_name,
|
|
|
area=building_area,
|
|
@@ -478,10 +478,10 @@ class BuildingApi(Resource):
|
|
|
picture_urls = []
|
|
|
if pictures:
|
|
|
for picture in pictures:
|
|
|
- picture.save(os.path.join(BUILDING_PICTURE_PATH, picture.filename))
|
|
|
- picture_urls.append(BUILDING_PICTURE_URL + picture.filename)
|
|
|
+ picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
|
|
|
+ picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = update(Building).where(Building.id == building_id).values(
|
|
|
name=building_name,
|
|
|
area=building_area,
|
|
@@ -508,7 +508,7 @@ class BuildingApi(Resource):
|
|
|
if building_id is None:
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = delete(Building).where(Building.id == building_id)
|
|
|
session.execute(stmt)
|
|
|
session.commit()
|
|
@@ -524,13 +524,14 @@ underlying_system.add_argument(name='picture', type=FileStorage, location='files
|
|
|
|
|
|
@ns.route('/underlying_system')
|
|
|
class UnderlyingSystemMessageApi(Resource):
|
|
|
- method_decorators = [login_required]
|
|
|
+ # method_decorators = [login_required]
|
|
|
|
|
|
@ns.doc(id='underlying_system_list', description='获取底层系统')
|
|
|
@ns.expect()
|
|
|
def get(self):
|
|
|
"""获取底层系统"""
|
|
|
- with Session(engine) as session:
|
|
|
+
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = select(UnderlyingSystem)
|
|
|
results = session.execute(stmt).scalars().all()
|
|
|
|
|
@@ -544,14 +545,14 @@ class UnderlyingSystemMessageApi(Resource):
|
|
|
|
|
|
# 存储(url),
|
|
|
if picture:
|
|
|
- picture.save(os.path.join(UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
|
|
|
- picture_url = UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
|
|
|
+ picture.save(os.path.join(config.common.UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
|
|
|
+ picture_url = config.common.UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
|
|
|
|
|
|
- with Session(engine) as session:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
stmt = insert(UnderlyingSystem).values(
|
|
|
picture=picture_url
|
|
|
)
|
|
|
session.execute(stmt)
|
|
|
session.commit()
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|