|
@@ -1,4 +1,4 @@
|
|
|
-import os
|
|
|
+import base64
|
|
|
|
|
|
from flask import request, jsonify, current_app, g
|
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
@@ -7,7 +7,7 @@ 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.modle.information import FloorConfiguration, StaffConfiguration, SecurityPerson
|
|
|
from app.utils.jwt_util import login_required
|
|
|
from app.utils.save_log import save_log
|
|
|
from app.utils.util import to_dict
|
|
@@ -109,12 +109,12 @@ class FloorConfigurationApi(Resource):
|
|
|
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
|
|
|
+ ext = attachment.filename.split('.')[-1]
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(attachment.read())
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
else:
|
|
|
- attachment_url = None
|
|
|
+ base64_data = None
|
|
|
|
|
|
try:
|
|
|
with Session(current_app.engine) as session:
|
|
@@ -123,7 +123,7 @@ class FloorConfigurationApi(Resource):
|
|
|
location=location,
|
|
|
use=use,
|
|
|
remark=remark,
|
|
|
- attachment=attachment_url,
|
|
|
+ attachment=base64_data,
|
|
|
account=g.user_name
|
|
|
)
|
|
|
session.execute(stmt)
|
|
@@ -151,12 +151,12 @@ class FloorConfigurationApi(Resource):
|
|
|
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
|
|
|
+ ext = attachment.filename.split('.')[-1]
|
|
|
+ base64_data = b'data:image/%s;base64,' % ext.encode('utf-8') + base64.b64encode(attachment.read())
|
|
|
+ base64_data = base64_data.decode('utf-8')
|
|
|
else:
|
|
|
- attachment_url = None
|
|
|
+ base64_data = None
|
|
|
|
|
|
try:
|
|
|
with Session(current_app.engine) as session:
|
|
@@ -165,7 +165,7 @@ class FloorConfigurationApi(Resource):
|
|
|
location=location,
|
|
|
use=use,
|
|
|
remark=remark,
|
|
|
- attachment=attachment_url,
|
|
|
+ attachment=base64_data,
|
|
|
account=g.user_name
|
|
|
)
|
|
|
session.execute(stmt)
|
|
@@ -201,15 +201,147 @@ class FloorConfigurationApi(Resource):
|
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
+@ns.route('/security_person')
|
|
|
+class GetSecurityPersonApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
+
|
|
|
+ def get(self):
|
|
|
+ """获取人员名单"""
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(SecurityPerson)
|
|
|
+ results = information_list(session.execute(stmt))
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=results)
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+
|
|
|
+staff_configuration_details = reqparse.RequestParser(bundle_errors=True)
|
|
|
+staff_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='personnel_type', type=str, location='form', required=False, help='人员类别')
|
|
|
+floor_configuration.add_argument(name='responsibility_range', type=str, location='form', required=False,
|
|
|
+ help='职责范围')
|
|
|
+floor_configuration.add_argument(name='staff_list', type=str, location='form', required=False, help='人员名单')
|
|
|
+floor_configuration.add_argument(name='remark', type=str, location='form', required=False, help='备注')
|
|
|
+
|
|
|
+
|
|
|
+@ns.route('/staff_configuration')
|
|
|
class StaffConfigurationApi(Resource):
|
|
|
+ method_decorators = [login_required]
|
|
|
+
|
|
|
+ @ns.doc(id='staff_configuration', description='获取人员配置信息')
|
|
|
+ @ns.expect(staff_configuration_details)
|
|
|
def get(self):
|
|
|
"""获取安保人员信息配置"""
|
|
|
|
|
|
+ staff_configuration_id = request.args.get('id')
|
|
|
+ if staff_configuration_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
+
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = select(StaffConfiguration).where(StaffConfiguration.id == staff_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))
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+ @ns.doc(id='add_staff_configuration', description='添加人员配置信息')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
def post(self):
|
|
|
"""添加安保人员信息配置"""
|
|
|
+ name = request.form.get('name')
|
|
|
+ personnel_type = request.form.get('personnel_type')
|
|
|
+ responsibility_range = request.form.get('responsibility_range')
|
|
|
+ staff_list = request.form.get('staff_list')
|
|
|
+ remark = request.form.get('remark')
|
|
|
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = insert(StaffConfiguration).values(
|
|
|
+ name=name,
|
|
|
+ personnel_type=personnel_type,
|
|
|
+ responsibility_range=responsibility_range,
|
|
|
+ staff_list=staff_list,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+ @ns.doc(id='update_staff_configuration', description='修改人员配置信息')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
def put(self):
|
|
|
"""修改安保人员信息配置"""
|
|
|
+ staff_configuration_id = request.form.get('id')
|
|
|
+ name = request.form.get('name')
|
|
|
+ personnel_type = request.form.get('personnel_type')
|
|
|
+ responsibility_range = request.form.get('responsibility_range')
|
|
|
+ staff_list = request.form.get('staff_list')
|
|
|
+ remark = request.form.get('remark')
|
|
|
+
|
|
|
+ if staff_configuration_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
+
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = update(StaffConfiguration).where(StaffConfiguration.id == staff_configuration_id).values(
|
|
|
+ name=name,
|
|
|
+ personnel_type=personnel_type,
|
|
|
+ responsibility_range=responsibility_range,
|
|
|
+ staff_list=staff_list,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
+
|
|
|
+ @ns.doc(id='delete_staff_configuration', description='删除人员配置信息')
|
|
|
+ @ns.expect(floor_configuration)
|
|
|
def delete(self):
|
|
|
"""删除安保人员信息配置"""
|
|
|
+
|
|
|
+ staff_configuration_id = request.form.get('id')
|
|
|
+
|
|
|
+ if staff_configuration_id is None:
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
+
|
|
|
+ try:
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
+ stmt = delete(StaffConfiguration).where(StaffConfiguration.id == staff_configuration_id)
|
|
|
+ session.execute(stmt)
|
|
|
+ session.commit()
|
|
|
+
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
+
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.DELETE, StatesCode.UNKNOWN_ERROR)
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|