|
@@ -7,10 +7,11 @@ 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
|
|
|
+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
|
|
|
+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
|
|
@@ -253,9 +254,10 @@ company_data.add_argument(name='picture', type=FileStorage, location='files', re
|
|
|
|
|
|
@ns.route('/company')
|
|
|
class CompanyApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
|
|
|
@ns.doc(id='get_company', description='获取公司信息')
|
|
|
- @ns.expect(batch_delete_template)
|
|
|
+ @ns.expect(company_id)
|
|
|
def get(self):
|
|
|
"""获取公司基本信息"""
|
|
|
company_id = request.args.get('company_id')
|
|
@@ -280,17 +282,17 @@ class CompanyApi(Resource):
|
|
|
introduction = request.form.get('introduction')
|
|
|
contact_person = request.form.get('contact_person')
|
|
|
contact_information = request.form.get('contact_information')
|
|
|
- picture = request.files.get('picture')
|
|
|
+ pictures = request.files.getlist('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
|
|
|
+ # 多图片存储(url),
|
|
|
+ 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)
|
|
|
|
|
|
with Session(engine) as session:
|
|
|
# 判断是否存在
|
|
@@ -306,7 +308,7 @@ class CompanyApi(Resource):
|
|
|
introduction=introduction,
|
|
|
contact_person=contact_person,
|
|
|
contact_information=contact_information,
|
|
|
- picture=picture_url,
|
|
|
+ picture=json.dumps(picture_urls),
|
|
|
)
|
|
|
session.execute(stmt)
|
|
|
|
|
@@ -314,7 +316,7 @@ class CompanyApi(Resource):
|
|
|
|
|
|
save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='新增成功', data='')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='新增成功')
|
|
|
|
|
|
@ns.doc(id='update_company', description='修改公司信息')
|
|
|
@ns.expect(company_data)
|
|
@@ -327,17 +329,17 @@ class CompanyApi(Resource):
|
|
|
introduction = request.form.get('introduction')
|
|
|
contact_person = request.form.get('contact_person')
|
|
|
contact_information = request.form.get('contact_information')
|
|
|
- picture = request.files.get('picture')
|
|
|
+ pictures = request.files.getlist('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
|
|
|
+ # 多图片存储(url),
|
|
|
+ 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)
|
|
|
|
|
|
with Session(engine) as session:
|
|
|
stmt = update(CompanyData).where(CompanyData.id == company_id).values(
|
|
@@ -346,7 +348,7 @@ class CompanyApi(Resource):
|
|
|
introduction=introduction,
|
|
|
contact_person=contact_person,
|
|
|
contact_information=contact_information,
|
|
|
- picture=picture_url,
|
|
|
+ picture=json.dumps(picture_urls),
|
|
|
)
|
|
|
|
|
|
session.execute(stmt)
|
|
@@ -354,52 +356,198 @@ class CompanyApi(Resource):
|
|
|
|
|
|
save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
- 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='楼宇图片')
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
|
|
|
|
|
|
@ns.route('/building_list')
|
|
|
class BuildingListApi(Resource):
|
|
|
+ @ns.doc(id='building_list', description='获取楼宇列表')
|
|
|
def get(self):
|
|
|
"""获取楼宇列表"""
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data='')
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(Building)
|
|
|
+ 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))
|
|
|
+
|
|
|
+
|
|
|
+building = reqparse.RequestParser(bundle_errors=True)
|
|
|
+building.add_argument(name='building_id', type=int, location='args', required=False, help='楼宇id')
|
|
|
+
|
|
|
+building_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
+building_details.add_argument(name='building_id', type=int, location='form', required=False, help='楼宇id')
|
|
|
+building_details.add_argument(name='building_name', type=str, location='form', required=False, help='楼宇名')
|
|
|
+building_details.add_argument(name='building_area', type=str, location='form', required=False, help='楼宇面积')
|
|
|
+building_details.add_argument(name='building_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=str, location='form', required=False, help='建成日期')
|
|
|
+building_details.add_argument(name='contact_person', type=str, location='form', required=False, help='联系人')
|
|
|
+building_details.add_argument(name='contact_information', type=str, location='form', required=False, help='联系人方式')
|
|
|
+building_details.add_argument(name='building_introduction', type=str, location='form', required=False, help='楼宇简介')
|
|
|
+building_details.add_argument(name='picture', type=FileStorage, location='files', required=False, help='楼宇图片')
|
|
|
|
|
|
|
|
|
@ns.route('/building')
|
|
|
class BuildingApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
|
|
|
+ @ns.doc(id='building_list', description='获取楼宇列表')
|
|
|
+ @ns.expect(building)
|
|
|
def get(self):
|
|
|
"""获取楼宇信息"""
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='获取成功', data='')
|
|
|
+ building_id = request.args.get('building_id')
|
|
|
+
|
|
|
+ if building_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(Building).where(Building.id == building_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_building', description='增加楼宇')
|
|
|
+ @ns.expect(building_details)
|
|
|
def post(self):
|
|
|
"""添加楼宇"""
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功', data='')
|
|
|
+ building_name = request.form.get('building_name')
|
|
|
+ building_area = request.form.get('building_area')
|
|
|
+ building_floor = request.form.get('building_floor')
|
|
|
+ trem = request.form.get('trem')
|
|
|
+ date = request.form.get('date')
|
|
|
+ contact_person = request.form.get('contact_person')
|
|
|
+ contact_information = request.form.get('contact_information')
|
|
|
+ building_introduction = request.form.get('building_introduction')
|
|
|
+ pictures = request.files.getlist('picture')
|
|
|
+
|
|
|
+ if building_name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇名称不能为空')
|
|
|
+
|
|
|
+ # 多图片存储(url),
|
|
|
+ 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)
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = insert(Building).values(
|
|
|
+ name=building_name,
|
|
|
+ area=building_area,
|
|
|
+ floor=building_floor,
|
|
|
+ trem=trem,
|
|
|
+ date=date,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ introduction=building_introduction,
|
|
|
+ picture=json.dumps(picture_urls)
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
|
|
|
+ save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+
|
|
|
+ @ns.doc(id='update_building', description='修改楼宇')
|
|
|
+ @ns.expect(building_details)
|
|
|
def put(self):
|
|
|
"""修改楼宇"""
|
|
|
+ building_id = request.form.get('building_id')
|
|
|
+ building_name = request.form.get('building_name')
|
|
|
+ building_area = request.form.get('building_area')
|
|
|
+ building_floor = request.form.get('building_floor')
|
|
|
+ trem = request.form.get('trem')
|
|
|
+ date = request.form.get('date')
|
|
|
+ contact_person = request.form.get('contact_person')
|
|
|
+ contact_information = request.form.get('contact_information')
|
|
|
+ building_introduction = request.form.get('building_introduction')
|
|
|
+ pictures = request.files.getlist('picture')
|
|
|
+
|
|
|
+ if building_id is None and building_name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id和楼宇名称不能为空')
|
|
|
+
|
|
|
+ # 多图片存储(url),
|
|
|
+ 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)
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = update(Building).where(Building.id == building_id).values(
|
|
|
+ name=building_name,
|
|
|
+ area=building_area,
|
|
|
+ floor=building_floor,
|
|
|
+ trem=trem,
|
|
|
+ date=date,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_information=contact_information,
|
|
|
+ introduction=building_introduction,
|
|
|
+ picture=json.dumps(picture_urls)
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
return jsonify(code=StatesCode.SUCCESS, message='修改成功', data='')
|
|
|
|
|
|
+ @ns.doc(id='delete_building', description='删除楼宇')
|
|
|
+ @ns.expect(building_details)
|
|
|
def delete(self):
|
|
|
"""删除楼宇"""
|
|
|
+ building_id = request.form.get('building_id')
|
|
|
+ if building_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = delete(Building).where(Building.id == building_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.DATA, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
return jsonify(code=StatesCode.SUCCESS, message='删除成功', data='')
|
|
|
|
|
|
|
|
|
+underlying_system = reqparse.RequestParser(bundle_errors=True)
|
|
|
+underlying_system.add_argument(name='picture', type=FileStorage, location='files', required=False, help='楼宇图片')
|
|
|
+
|
|
|
+
|
|
|
@ns.route('/underlying_system')
|
|
|
class UnderlyingSystemMessageApi(Resource):
|
|
|
+ @ns.doc(id='underlying_system_list', description='获取底层系统')
|
|
|
+ @ns.expect()
|
|
|
+ def get(self):
|
|
|
+ """获取底层系统"""
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = select(UnderlyingSystem)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功', data=to_dict(results))
|
|
|
+
|
|
|
+ @ns.doc(id='update_underlying_system', description='添加底层系统')
|
|
|
+ @ns.expect(underlying_system)
|
|
|
def post(self):
|
|
|
"""添加底层系统信息"""
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='添加成功', data='')
|
|
|
+ picture = request.files.get('picture')
|
|
|
+
|
|
|
+ # 存储(url),
|
|
|
+ if picture:
|
|
|
+ picture.save(os.path.join(UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
|
|
|
+ picture_url = UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
|
|
|
+
|
|
|
+ with Session(engine) as session:
|
|
|
+ stmt = insert(UnderlyingSystem).values(
|
|
|
+ picture=picture_url
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|