|
@@ -0,0 +1,194 @@
|
|
|
+import datetime
|
|
|
+import json
|
|
|
+import os
|
|
|
+
|
|
|
+from flask import request, jsonify, 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.defines import Module, OperationType, StatesCode
|
|
|
+from app.modle.information import FloorConfiguration, StaffConfiguration
|
|
|
+from app.utils.jwt_util import login_required
|
|
|
+from app.utils.save_log import save_log
|
|
|
+from app.utils.util import to_dict
|
|
|
+from config import Config
|
|
|
+
|
|
|
+ns = Namespace('information', description='信息管理接口')
|
|
|
+
|
|
|
+config = Config()
|
|
|
+
|
|
|
+
|
|
|
+def information_list(rows):
|
|
|
+ res = []
|
|
|
+ for row in rows:
|
|
|
+ res.append({"id": row.id, "name": row.name})
|
|
|
+
|
|
|
+ return res
|
|
|
+
|
|
|
+
|
|
|
+@ns.route('/information_list')
|
|
|
+class InformationTypeApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
+
|
|
|
+ @ns.doc(id='information_list', description='信息列表')
|
|
|
+ def get(self):
|
|
|
+ """获取信息列表"""
|
|
|
+ information_type = config.common.INFORMATION_TYPE
|
|
|
+
|
|
|
+ data = {}
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+
|
|
|
+ for information in information_type:
|
|
|
+ if information == '楼层地图信息配置':
|
|
|
+
|
|
|
+ stmt = select(FloorConfiguration.id, FloorConfiguration.name)
|
|
|
+
|
|
|
+ data[information] = information_list(session.execute(stmt))
|
|
|
+
|
|
|
+ elif information == '安保人员信息配置':
|
|
|
+
|
|
|
+ stmt = select(StaffConfiguration.id, StaffConfiguration.name)
|
|
|
+
|
|
|
+ data[information] = information_list(session.execute(stmt))
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=data)
|
|
|
+
|
|
|
+
|
|
|
+floor_configuration_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
+floor_configuration_details.add_argument(name='id', type=str, location='args', required=False, help='配置id')
|
|
|
+
|
|
|
+floor_configuration = reqparse.RequestParser(bundle_errors=True)
|
|
|
+floor_configuration.add_argument(name='id', type=str, location='form', required=False, help='配置id')
|
|
|
+floor_configuration.add_argument(name='name', type=str, location='form', required=False, help='配置名称')
|
|
|
+floor_configuration.add_argument(name='location', type=str, location='form', required=False, help='楼层位置')
|
|
|
+floor_configuration.add_argument(name='use', type=str, location='form', required=False, help='楼层用途')
|
|
|
+floor_configuration.add_argument(name='remark', type=str, location='form', required=False, help='备注')
|
|
|
+floor_configuration.add_argument(name='attachment', type=FileStorage, location='files', required=False, help='附件')
|
|
|
+
|
|
|
+
|
|
|
+@ns.route('/floor_configuration')
|
|
|
+class FloorConfigurationApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
+
|
|
|
+ @ns.doc(id='floor_configuration', description='获取楼层地图信息配置')
|
|
|
+ @ns.expect(floor_configuration_details)
|
|
|
+ def get(self):
|
|
|
+ """获取楼层地图信息配置"""
|
|
|
+
|
|
|
+ floor_configuration_id = request.args.get('id')
|
|
|
+
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(FloorConfiguration).where(FloorConfiguration.id == floor_configuration_id)
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
|
+
|
|
|
+ @ns.doc(id='add_floor_configuration', description='添加楼层地图信息配置')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
+ def post(self):
|
|
|
+ """添加楼层地图信息配置"""
|
|
|
+ name = request.form.get('name')
|
|
|
+ location = request.form.get('location')
|
|
|
+ use = request.form.get('use')
|
|
|
+ remark = request.form.get('remark')
|
|
|
+ attachment = request.files.get('attachment')
|
|
|
+
|
|
|
+ if name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置名不能为空")
|
|
|
+
|
|
|
+ # 附件存储(url),
|
|
|
+ if attachment:
|
|
|
+ attachment.save(os.path.join(config.common.FLOOR_CONFIGURATION_PATH, attachment.filename))
|
|
|
+ attachment_url = config.common.FLOOR_CONFIGURATION_URL + attachment.filename
|
|
|
+ else:
|
|
|
+ attachment_url = None
|
|
|
+
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = insert(FloorConfiguration).values(
|
|
|
+ name=name,
|
|
|
+ location=location,
|
|
|
+ use=use,
|
|
|
+ remark=remark,
|
|
|
+ attachment=attachment_url
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='添加成功')
|
|
|
+
|
|
|
+ @ns.doc(id='update_floor_configuration', description='修改楼层地图信息配置')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
+ def put(self):
|
|
|
+ """修改楼层地图信息配置"""
|
|
|
+
|
|
|
+ floor_configuration_id = request.form.get('id')
|
|
|
+ name = request.form.get('name')
|
|
|
+ location = request.form.get('location')
|
|
|
+ use = request.form.get('use')
|
|
|
+ remark = request.form.get('remark')
|
|
|
+ attachment = request.files.get('attachment')
|
|
|
+
|
|
|
+ if name is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置名不能为空")
|
|
|
+
|
|
|
+ # 附件存储(url),
|
|
|
+ if attachment:
|
|
|
+ attachment.save(os.path.join(config.common.FLOOR_CONFIGURATION_PATH, attachment.filename))
|
|
|
+ attachment_url = config.common.FLOOR_CONFIGURATION_URL + attachment.filename
|
|
|
+ else:
|
|
|
+ attachment_url = None
|
|
|
+
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = update(FloorConfiguration).where(FloorConfiguration.id == floor_configuration_id).values(
|
|
|
+ name=name,
|
|
|
+ location=location,
|
|
|
+ use=use,
|
|
|
+ remark=remark,
|
|
|
+ attachment=attachment_url
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='修改成功')
|
|
|
+
|
|
|
+ @ns.doc(id='delete_floor_configuration', description='删除楼层地图信息配置')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
+ def delete(self):
|
|
|
+ """删除楼层地图信息配置"""
|
|
|
+ floor_configuration_id = request.form.get('id')
|
|
|
+
|
|
|
+ if floor_configuration_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
+
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = delete(FloorConfiguration).where(FloorConfiguration.id == floor_configuration_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.ORGANIZATION, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message="删除成功")
|
|
|
+
|
|
|
+
|
|
|
+class StaffConfigurationApi(Resource):
|
|
|
+ def get(self):
|
|
|
+ """获取安保人员信息配置"""
|
|
|
+
|
|
|
+ def post(self):
|
|
|
+ """添加安保人员信息配置"""
|
|
|
+
|
|
|
+ def put(self):
|
|
|
+ """修改安保人员信息配置"""
|
|
|
+
|
|
|
+ def delete(self):
|
|
|
+ """删除安保人员信息配置"""
|