|
@@ -7,10 +7,10 @@ from sqlalchemy import select, insert, update, delete
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
from werkzeug.datastructures import FileStorage
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
-from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL
|
|
|
|
|
|
+from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL, COMPANY_PICTURE_PATH, COMPANY_PICTURE_URL
|
|
from app.database import engine
|
|
from app.database import engine
|
|
from app.defines import StatesCode, Module, OperationType
|
|
from app.defines import StatesCode, Module, OperationType
|
|
-from app.modle.template import Template
|
|
|
|
|
|
+from app.modle.data import Template, CompanyData
|
|
from app.utils.jwt_util import login_required
|
|
from app.utils.jwt_util import login_required
|
|
from app.utils.save_log import save_log
|
|
from app.utils.save_log import save_log
|
|
from app.utils.util import to_dict, cn_now
|
|
from app.utils.util import to_dict, cn_now
|
|
@@ -66,14 +66,14 @@ class TemplateConfigListApi(Resource):
|
|
template = reqparse.RequestParser(bundle_errors=True)
|
|
template = reqparse.RequestParser(bundle_errors=True)
|
|
template.add_argument(name='template_id', type=int, location='args', required=False, help='模版id')
|
|
template.add_argument(name='template_id', type=int, location='args', required=False, help='模版id')
|
|
|
|
|
|
-template_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
-template_details.add_argument(name='template_id', type=int, location='form', required=False, help='模版id')
|
|
|
|
-template_details.add_argument(name='template_name', type=str, location='form', required=False, help='模版名称')
|
|
|
|
-template_details.add_argument(name='template_format', type=str, location='form', required=False, help='模版格式')
|
|
|
|
-template_details.add_argument(name='report_type', type=str, location='form', required=False, help='报告类型')
|
|
|
|
-template_details.add_argument(name='introduction', type=str, location='form', required=False, help='模版简介')
|
|
|
|
-template_details.add_argument(name='template_file', type=FileStorage, location='files', required=False, help='模版文件')
|
|
|
|
-template_details.add_argument(name='template_type', type=int, location='files', required=False,
|
|
|
|
|
|
+building_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+building_details.add_argument(name='template_id', type=int, location='form', required=False, help='模版id')
|
|
|
|
+building_details.add_argument(name='template_name', type=str, location='form', required=False, help='模版名称')
|
|
|
|
+building_details.add_argument(name='template_format', type=str, location='form', required=False, help='模版格式')
|
|
|
|
+building_details.add_argument(name='report_type', type=str, location='form', required=False, help='报告类型')
|
|
|
|
+building_details.add_argument(name='introduction', type=str, location='form', required=False, help='模版简介')
|
|
|
|
+building_details.add_argument(name='template_file', type=FileStorage, location='files', required=False, help='模版文件')
|
|
|
|
+building_details.add_argument(name='template_type', type=int, location='files', required=False,
|
|
help='模版类型 0:报表,1:报告')
|
|
help='模版类型 0:报表,1:报告')
|
|
|
|
|
|
|
|
|
|
@@ -99,7 +99,7 @@ class TemplateConfigApi(Resource):
|
|
return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
|
|
|
@ns.doc(id='add_template', description='添加报表模版')
|
|
@ns.doc(id='add_template', description='添加报表模版')
|
|
- @ns.expect(template_details)
|
|
|
|
|
|
+ @ns.expect(building_details)
|
|
def post(self):
|
|
def post(self):
|
|
"""添加模版"""
|
|
"""添加模版"""
|
|
template_name = request.form.get('template_name')
|
|
template_name = request.form.get('template_name')
|
|
@@ -130,7 +130,7 @@ class TemplateConfigApi(Resource):
|
|
stmt = insert(Template).values(
|
|
stmt = insert(Template).values(
|
|
name=template_name,
|
|
name=template_name,
|
|
format=template_format,
|
|
format=template_format,
|
|
- Introduction=introduction,
|
|
|
|
|
|
+ introduction=introduction,
|
|
report_type=report_type,
|
|
report_type=report_type,
|
|
creator=g.user_name,
|
|
creator=g.user_name,
|
|
create_time=cn_now(),
|
|
create_time=cn_now(),
|
|
@@ -147,7 +147,7 @@ class TemplateConfigApi(Resource):
|
|
return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
|
|
|
@ns.doc(id='update_templatet', description='修改模版信息')
|
|
@ns.doc(id='update_templatet', description='修改模版信息')
|
|
- @ns.expect(template_details)
|
|
|
|
|
|
+ @ns.expect(building_details)
|
|
def put(self):
|
|
def put(self):
|
|
"""修改模版"""
|
|
"""修改模版"""
|
|
template_id = request.form.get('template_id')
|
|
template_id = request.form.get('template_id')
|
|
@@ -172,7 +172,7 @@ class TemplateConfigApi(Resource):
|
|
stmt = update(Template).where(Template.id == template_id).values(
|
|
stmt = update(Template).where(Template.id == template_id).values(
|
|
name=template_name,
|
|
name=template_name,
|
|
format=template_format,
|
|
format=template_format,
|
|
- Introduction=introduction,
|
|
|
|
|
|
+ introduction=introduction,
|
|
report_type=report_type,
|
|
report_type=report_type,
|
|
creator=g.user_name,
|
|
creator=g.user_name,
|
|
create_time=cn_now(),
|
|
create_time=cn_now(),
|
|
@@ -188,7 +188,7 @@ class TemplateConfigApi(Resource):
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
|
|
|
@ns.doc(id='delete_template', description='删除模版')
|
|
@ns.doc(id='delete_template', description='删除模版')
|
|
- @ns.expect(template_details)
|
|
|
|
|
|
+ @ns.expect(building_details)
|
|
def delete(self):
|
|
def delete(self):
|
|
"""删除模版"""
|
|
"""删除模版"""
|
|
template_id = request.form.get('template_id')
|
|
template_id = request.form.get('template_id')
|
|
@@ -238,17 +238,138 @@ class BatchTemplateConfigApi(Resource):
|
|
return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
|
|
|
|
|
|
|
|
|
|
|
|
+company_id = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+company_id.add_argument(name='company_id', type=int, location='args', required=False, help='公司id')
|
|
|
|
+
|
|
|
|
+company_data = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+company_data.add_argument(name='company_id', type=int, location='form', required=False, help='公司id')
|
|
|
|
+company_data.add_argument(name='management_unit', type=str, location='form', required=False, help='管理单位')
|
|
|
|
+company_data.add_argument(name='custodian_unit', type=str, location='form', required=False, help='托管单位')
|
|
|
|
+company_data.add_argument(name='introduction', type=str, location='form', required=False, help='楼宇简介')
|
|
|
|
+company_data.add_argument(name='contact_person', type=str, location='form', required=False, help='联系人')
|
|
|
|
+company_data.add_argument(name='contact_information', type=str, location='form', required=False, help='联系人方式')
|
|
|
|
+company_data.add_argument(name='picture', type=FileStorage, location='files', required=False, help='公司图片')
|
|
|
|
+
|
|
|
|
+
|
|
@ns.route('/company')
|
|
@ns.route('/company')
|
|
class CompanyApi(Resource):
|
|
class CompanyApi(Resource):
|
|
|
|
+
|
|
|
|
+ @ns.doc(id='get_company', description='获取公司信息')
|
|
|
|
+ @ns.expect(batch_delete_template)
|
|
def get(self):
|
|
def get(self):
|
|
"""获取公司基本信息"""
|
|
"""获取公司基本信息"""
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data='')
|
|
|
|
|
|
+ company_id = request.args.get('company_id')
|
|
|
|
+
|
|
|
|
+ if company_id is None:
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
|
+
|
|
|
|
+ with Session(engine) as session:
|
|
|
|
+ stmt = select(CompanyData).where(CompanyData.id == company_id)
|
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
|
|
|
|
+
|
|
|
|
+ @ns.doc(id='add_company', description='添加公司信息')
|
|
|
|
+ @ns.expect(company_data)
|
|
|
|
+ def post(self):
|
|
|
|
+ """添加公司基本信息"""
|
|
|
|
+ management_unit = request.form.get('management_unit')
|
|
|
|
+ custodian_unit = request.form.get('custodian_unit')
|
|
|
|
+ introduction = request.form.get('introduction')
|
|
|
|
+ contact_person = request.form.get('contact_person')
|
|
|
|
+ contact_information = request.form.get('contact_information')
|
|
|
|
+ picture = request.files.get('picture')
|
|
|
|
+
|
|
|
|
+ if management_unit is None:
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='管理单位不能为空')
|
|
|
|
+
|
|
|
|
+ # 存储(url),
|
|
|
|
+ if picture:
|
|
|
|
+ picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
|
|
|
|
+ picture_url = COMPANY_PICTURE_URL + picture.filename
|
|
|
|
+ else:
|
|
|
|
+ picture_url = None
|
|
|
|
+
|
|
|
|
+ with Session(engine) as session:
|
|
|
|
+ # 判断是否存在
|
|
|
|
+ stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
|
|
|
|
+ result = session.execute(stmt).scalars().first()
|
|
|
|
+ if result:
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="管理单位已存在")
|
|
|
|
|
|
|
|
+ # 添加
|
|
|
|
+ stmt = insert(CompanyData).values(
|
|
|
|
+ management_unit=management_unit,
|
|
|
|
+ custodian_unit=custodian_unit,
|
|
|
|
+ introduction=introduction,
|
|
|
|
+ contact_person=contact_person,
|
|
|
|
+ contact_information=contact_information,
|
|
|
|
+ picture=picture_url,
|
|
|
|
+ )
|
|
|
|
+ session.execute(stmt)
|
|
|
|
+
|
|
|
|
+ session.commit()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='新增成功', data='')
|
|
|
|
+
|
|
|
|
+ @ns.doc(id='update_company', description='修改公司信息')
|
|
|
|
+ @ns.expect(company_data)
|
|
def put(self):
|
|
def put(self):
|
|
"""修改公司基本信息"""
|
|
"""修改公司基本信息"""
|
|
|
|
+
|
|
|
|
+ company_id = request.form.get('company_id')
|
|
|
|
+ management_unit = request.form.get('management_unit')
|
|
|
|
+ custodian_unit = request.form.get('custodian_unit')
|
|
|
|
+ introduction = request.form.get('introduction')
|
|
|
|
+ contact_person = request.form.get('contact_person')
|
|
|
|
+ contact_information = request.form.get('contact_information')
|
|
|
|
+ picture = request.files.get('picture')
|
|
|
|
+
|
|
|
|
+ if company_id is None:
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
|
|
|
|
+
|
|
|
|
+ # 存储(url),
|
|
|
|
+ if picture:
|
|
|
|
+ picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
|
|
|
|
+ picture_url = COMPANY_PICTURE_URL + picture.filename
|
|
|
|
+ else:
|
|
|
|
+ picture_url = None
|
|
|
|
+
|
|
|
|
+ with Session(engine) as session:
|
|
|
|
+ stmt = update(CompanyData).where(CompanyData.id == company_id).values(
|
|
|
|
+ management_unit=management_unit,
|
|
|
|
+ custodian_unit=custodian_unit,
|
|
|
|
+ introduction=introduction,
|
|
|
|
+ contact_person=contact_person,
|
|
|
|
+ contact_information=contact_information,
|
|
|
|
+ picture=picture_url,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ session.execute(stmt)
|
|
|
|
+ session.commit()
|
|
|
|
+
|
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
+
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功', data='')
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功', data='')
|
|
|
|
|
|
|
|
|
|
|
|
+building_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+building_details.add_argument(name='id', type=int, location='form', required=False, help='公司id')
|
|
|
|
+building_details.add_argument(name='name', type=str, location='form', required=False, help='楼宇名')
|
|
|
|
+building_details.add_argument(name='area', type=str, location='form', required=False, help='楼宇面积')
|
|
|
|
+building_details.add_argument(name='floor', type=str, location='form', required=False, help='建筑楼层')
|
|
|
|
+building_details.add_argument(name='trem', type=str, location='form', required=False, help='建筑年限')
|
|
|
|
+building_details.add_argument(name='date', type=int, location='form', required=False, help='建成日期')
|
|
|
|
+building_details.add_argument(name='contact_person', type=int, location='form', required=False, help='联系人')
|
|
|
|
+building_details.add_argument(name='contact_information', type=int, location='form', required=False, help='联系人方式')
|
|
|
|
+building_details.add_argument(name='introduction', type=int, location='form', required=False, help='楼宇简介')
|
|
|
|
+building_details.add_argument(name='picture', type=FileStorage, location='files', required=False, help='楼宇图片')
|
|
|
|
+
|
|
|
|
+
|
|
@ns.route('/building_list')
|
|
@ns.route('/building_list')
|
|
class BuildingListApi(Resource):
|
|
class BuildingListApi(Resource):
|
|
def get(self):
|
|
def get(self):
|