|
@@ -4,13 +4,13 @@ import os
|
|
|
|
|
|
from flask import request, jsonify, current_app, g
|
|
from flask import request, jsonify, current_app, g
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
from flask_restx import Resource, Namespace, reqparse
|
|
-from sqlalchemy import select, insert, update, delete
|
|
|
|
|
|
+from sqlalchemy import select, insert, update, delete, func, and_
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.orm import Session
|
|
from werkzeug.datastructures import FileStorage
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
from app.defines import Module, OperationType, StatesCode
|
|
from app.defines import Module, OperationType, StatesCode
|
|
from app.modle.information import FloorConfiguration, StaffConfiguration, SecurityPerson, FloorConfigurationHistory, \
|
|
from app.modle.information import FloorConfiguration, StaffConfiguration, SecurityPerson, FloorConfigurationHistory, \
|
|
- StaffConfigurationHistory
|
|
|
|
|
|
+ StaffConfigurationStaff
|
|
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
|
|
@@ -57,24 +57,6 @@ def upload_history(floor_configuration_id, url):
|
|
session.commit()
|
|
session.commit()
|
|
|
|
|
|
|
|
|
|
-def staff_upload_history(staff_configuration_id, staff_list, duty_time):
|
|
|
|
- """
|
|
|
|
- 记录安保人员信息配置历史记录
|
|
|
|
- :param staff_configuration_id: 配置id
|
|
|
|
- :param staff_list: 人员列表
|
|
|
|
- :param duty_time: 值班时间
|
|
|
|
- :return:
|
|
|
|
- """
|
|
|
|
- with Session(current_app.engine) as session:
|
|
|
|
- stmt = insert(StaffConfigurationHistory).values(
|
|
|
|
- configuration_id=staff_configuration_id,
|
|
|
|
- staff_list=staff_list,
|
|
|
|
- duty_time=duty_time
|
|
|
|
- )
|
|
|
|
- session.execute(stmt)
|
|
|
|
- session.commit()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
@ns.route('/information_list')
|
|
@ns.route('/information_list')
|
|
class InformationTypeApi(Resource):
|
|
class InformationTypeApi(Resource):
|
|
# method_decorators = [login_required]
|
|
# method_decorators = [login_required]
|
|
@@ -240,20 +222,32 @@ class FloorConfigurationApi(Resource):
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
+security_person = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+security_person.add_argument(name='type_id', type=str, location='args', required=False,
|
|
|
|
+ help='人员类别id 1 外协员工')
|
|
|
|
+
|
|
|
|
+
|
|
@ns.route('/security_person')
|
|
@ns.route('/security_person')
|
|
class GetSecurityPersonApi(Resource):
|
|
class GetSecurityPersonApi(Resource):
|
|
# method_decorators = [login_required]
|
|
# method_decorators = [login_required]
|
|
-
|
|
|
|
|
|
+ @ns.expect(security_person)
|
|
def get(self):
|
|
def get(self):
|
|
"""获取人员名单"""
|
|
"""获取人员名单"""
|
|
|
|
+ type_id = request.args.get('type_id')
|
|
|
|
+
|
|
|
|
+ if type_id:
|
|
|
|
+ type_id = int(type_id)
|
|
|
|
+ else:
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="类别id不能为空")
|
|
|
|
+
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
- stmt = select(SecurityPerson.id, SecurityPerson.name)
|
|
|
|
- results = information_list(session.execute(stmt))
|
|
|
|
|
|
+ stmt = select(SecurityPerson).where(SecurityPerson.type == type_id)
|
|
|
|
+ results = session.execute(stmt).scalars().all()
|
|
|
|
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', data=results)
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
|
|
except Exception as e:
|
|
except Exception as e:
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
@@ -261,17 +255,12 @@ class GetSecurityPersonApi(Resource):
|
|
|
|
|
|
staff_configuration_details = reqparse.RequestParser(bundle_errors=True)
|
|
staff_configuration_details = reqparse.RequestParser(bundle_errors=True)
|
|
staff_configuration_details.add_argument(name='id', type=str, location='args', required=False, help='配置id')
|
|
staff_configuration_details.add_argument(name='id', type=str, location='args', required=False, help='配置id')
|
|
|
|
+staff_configuration_details.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
|
|
|
|
+staff_configuration_details.add_argument(name='page', type=int, location='args', required=False, help='第几页')
|
|
|
|
|
|
-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='备注')
|
|
|
|
-floor_configuration.add_argument(name='duty_time', type=str, location='form', required=False,
|
|
|
|
- help="值班日期:{'start_time': '', end_time: ''}")
|
|
|
|
|
|
+configuration = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+configuration.add_argument(name='id', type=str, location='form', required=False, help='配置id')
|
|
|
|
+configuration.add_argument(name='name', type=str, location='form', required=False, help='配置名称')
|
|
|
|
|
|
|
|
|
|
@ns.route('/staff_configuration')
|
|
@ns.route('/staff_configuration')
|
|
@@ -284,57 +273,55 @@ class StaffConfigurationApi(Resource):
|
|
"""获取安保人员信息配置"""
|
|
"""获取安保人员信息配置"""
|
|
|
|
|
|
staff_configuration_id = request.args.get('id')
|
|
staff_configuration_id = request.args.get('id')
|
|
|
|
+ page_size = int(request.args.get('page_size', 20))
|
|
|
|
+ page = int(request.args.get('page', 1))
|
|
|
|
+
|
|
if staff_configuration_id is None:
|
|
if staff_configuration_id is None:
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
- stmt = select(StaffConfiguration).where(StaffConfiguration.id == staff_configuration_id)
|
|
|
|
- results = session.execute(stmt).scalars().first().__dict__
|
|
|
|
- del results['_sa_instance_state']
|
|
|
|
-
|
|
|
|
- # 获取人员
|
|
|
|
- staff_list = []
|
|
|
|
- for staff_id in json.loads(results['staff_list']):
|
|
|
|
- stmt = select(SecurityPerson).where(SecurityPerson.id == staff_id)
|
|
|
|
- staff = session.execute(stmt).scalars().first().__dict__
|
|
|
|
- del staff['_sa_instance_state']
|
|
|
|
- staff_list.append(staff)
|
|
|
|
- results['staff_list'] = staff_list
|
|
|
|
|
|
+ stmt = select(StaffConfigurationStaff.staff,
|
|
|
|
+ func.max(StaffConfigurationStaff.update_time)) \
|
|
|
|
+ .where(StaffConfigurationStaff.Configuration_id == staff_configuration_id) \
|
|
|
|
+ .group_by(StaffConfigurationStaff.staff)
|
|
|
|
+ staff_res = session.execute(stmt).all()
|
|
|
|
+
|
|
|
|
+ data = []
|
|
|
|
+ count = 0
|
|
|
|
+ for staff in staff_res:
|
|
|
|
+ count_stmt = select(func.count(StaffConfigurationStaff.id)).where(and_(StaffConfigurationStaff.staff == staff[0],
|
|
|
|
+ StaffConfigurationStaff.update_time == staff[1]))
|
|
|
|
+ count_res = session.execute(count_stmt).scalars().first()
|
|
|
|
+ count += count_res
|
|
|
|
+ stmt = select(StaffConfigurationStaff).where(and_(StaffConfigurationStaff.staff == staff[0],
|
|
|
|
+ StaffConfigurationStaff.update_time == staff[1]))\
|
|
|
|
+ .offset(page_size * (page - 1)).limit(page_size)
|
|
|
|
+ data.append(session.execute(stmt).scalars().first())
|
|
|
|
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|
|
- return jsonify(code=StatesCode.SUCCESS, message='成功', data=results)
|
|
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功',total=count, data=to_dict(data))
|
|
except Exception as e:
|
|
except Exception as e:
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
@ns.doc(id='add_staff_configuration', description='添加人员配置信息')
|
|
@ns.doc(id='add_staff_configuration', description='添加人员配置信息')
|
|
- @ns.expect(floor_configuration)
|
|
|
|
|
|
+ @ns.expect(configuration)
|
|
def post(self):
|
|
def post(self):
|
|
"""添加安保人员信息配置"""
|
|
"""添加安保人员信息配置"""
|
|
name = request.form.get('name')
|
|
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')
|
|
|
|
- duty_time = request.form.get('duty_time')
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
stmt = insert(StaffConfiguration).values(
|
|
stmt = insert(StaffConfiguration).values(
|
|
name=name,
|
|
name=name,
|
|
- personnel_type=personnel_type,
|
|
|
|
- responsibility_range=responsibility_range,
|
|
|
|
- staff_list=staff_list,
|
|
|
|
- remark=remark,
|
|
|
|
- duty_time=duty_time
|
|
|
|
)
|
|
)
|
|
- result = session.execute(stmt)
|
|
|
|
|
|
+ session.execute(stmt)
|
|
session.commit()
|
|
session.commit()
|
|
|
|
|
|
- # 添加历史记录
|
|
|
|
- staff_upload_history(result.inserted_primary_key[0], staff_list, duty_time)
|
|
|
|
|
|
+ # # 添加历史记录
|
|
|
|
+ # staff_upload_history(result.inserted_primary_key[0], staff_list, duty_time)
|
|
|
|
|
|
save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.SUCCESS)
|
|
|
|
|
|
@@ -344,62 +331,99 @@ class StaffConfigurationApi(Resource):
|
|
save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
save_log(request, Module.INFORMATION, OperationType.ADD, StatesCode.UNKNOWN_ERROR)
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
- @ns.doc(id='update_staff_configuration', description='修改人员配置信息')
|
|
|
|
|
|
+ @ns.doc(id='delete_staff_configuration', description='删除人员配置信息')
|
|
@ns.expect(floor_configuration)
|
|
@ns.expect(floor_configuration)
|
|
- def put(self):
|
|
|
|
- """修改安保人员信息配置"""
|
|
|
|
|
|
+ def delete(self):
|
|
|
|
+ """删除安保人员信息配置"""
|
|
|
|
+
|
|
staff_configuration_id = request.form.get('id')
|
|
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')
|
|
|
|
- duty_time = request.form.get('duty_time')
|
|
|
|
|
|
|
|
if staff_configuration_id is None:
|
|
if staff_configuration_id is None:
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
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,
|
|
|
|
- duty_time=duty_time
|
|
|
|
- )
|
|
|
|
|
|
+ stmt = delete(StaffConfiguration).where(StaffConfiguration.id == staff_configuration_id)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
session.commit()
|
|
session.commit()
|
|
|
|
|
|
- # 记录历史
|
|
|
|
- staff_upload_history(staff_configuration_id, staff_list, duty_time)
|
|
|
|
-
|
|
|
|
- save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.UNKNOWN_ERROR)
|
|
|
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.DELETE, StatesCode.UNKNOWN_ERROR)
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message=str(e))
|
|
|
|
|
|
- @ns.doc(id='delete_staff_configuration', description='删除人员配置信息')
|
|
|
|
- @ns.expect(floor_configuration)
|
|
|
|
- def delete(self):
|
|
|
|
- """删除安保人员信息配置"""
|
|
|
|
|
|
|
|
|
|
+del_staff = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+del_staff.add_argument(name='id', type=str, location='form', required=False, help='id')
|
|
|
|
+
|
|
|
|
+staff_configuration = reqparse.RequestParser(bundle_errors=True)
|
|
|
|
+staff_configuration.add_argument(name='id', type=str, location='form', required=False, help='配置id')
|
|
|
|
+staff_configuration.add_argument(name='responsibility_range', type=str, location='form', required=False,
|
|
|
|
+ help='职责范围')
|
|
|
|
+staff_configuration.add_argument(name='staff_list', type=str, location='form', required=False, help='人员名单')
|
|
|
|
+staff_configuration.add_argument(name='remark', type=str, location='form', required=False, help='备注')
|
|
|
|
+staff_configuration.add_argument(name='duty_time', type=str, location='form', required=False,
|
|
|
|
+ help="值班日期:{'start_time': '', end_time: ''}")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@ns.route('/staff')
|
|
|
|
+class DelStaff(Resource):
|
|
|
|
+ @ns.doc(id='staff_configuration', description='新建人员配置')
|
|
|
|
+ @ns.expect(staff_configuration)
|
|
|
|
+ def post(self):
|
|
|
|
+ """新建人员配置"""
|
|
|
|
+ configuration_id = request.form.get('id')
|
|
|
|
+ responsibility_range = request.form.get('responsibility_range')
|
|
|
|
+ staff_list = request.form.get('staff_list')
|
|
|
|
+ remark = request.form.get('remark')
|
|
|
|
+ duty_time = request.form.get('duty_time')
|
|
|
|
+
|
|
|
|
+ if staff_list:
|
|
|
|
+ staff_list = json.loads(staff_list)
|
|
|
|
+ if duty_time:
|
|
|
|
+ duty_time = json.loads(duty_time)
|
|
|
|
+
|
|
|
|
+ data = []
|
|
|
|
+ for staff in staff_list:
|
|
|
|
+ data.append(
|
|
|
|
+ {
|
|
|
|
+ 'Configuration_id': configuration_id,
|
|
|
|
+ 'responsibility_range': responsibility_range,
|
|
|
|
+ 'staff': staff.get('id'),
|
|
|
|
+ 'remark': remark,
|
|
|
|
+ 'duty_time': duty_time,
|
|
|
|
+ 'staff_details': json.dumps(staff.get('details')),
|
|
|
|
+ 'update_time': cn_now()
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ with Session(current_app.engine) as session:
|
|
|
|
+ session.execute(
|
|
|
|
+ insert(StaffConfigurationStaff), data
|
|
|
|
+ )
|
|
|
|
+ session.commit()
|
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
+
|
|
|
|
+ return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
+
|
|
|
|
+ @ns.doc(description='删除人员')
|
|
|
|
+ @ns.expect(del_staff)
|
|
|
|
+ def delete(self):
|
|
|
|
+ """删除人员"""
|
|
staff_configuration_id = request.form.get('id')
|
|
staff_configuration_id = request.form.get('id')
|
|
|
|
|
|
if staff_configuration_id is None:
|
|
if staff_configuration_id is None:
|
|
- return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
|
|
|
+ return jsonify(code=StatesCode.UNKNOWN_ERROR, message="id不能为空")
|
|
|
|
|
|
try:
|
|
try:
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
- stmt = delete(StaffConfiguration).where(StaffConfiguration.id == staff_configuration_id)
|
|
|
|
|
|
+ stmt = delete(StaffConfigurationStaff).where(StaffConfigurationStaff.id == staff_configuration_id)
|
|
session.execute(stmt)
|
|
session.execute(stmt)
|
|
session.commit()
|
|
session.commit()
|
|
|
|
|
|
- save_log(request, Module.INFORMATION, OperationType.DELETE, StatesCode.SUCCESS)
|
|
|
|
|
|
+ save_log(request, Module.INFORMATION, OperationType.UPDATE, StatesCode.SUCCESS)
|
|
|
|
|
|
return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
return jsonify(code=StatesCode.SUCCESS, message='成功')
|
|
|
|
|
|
@@ -474,21 +498,16 @@ class GetStaffConfigurationHistory(Resource):
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
return jsonify(code=StatesCode.UNKNOWN_ERROR, message="配置id不能为空")
|
|
|
|
|
|
try:
|
|
try:
|
|
|
|
+ results = []
|
|
with Session(current_app.engine) as session:
|
|
with Session(current_app.engine) as session:
|
|
- stmt = select(StaffConfigurationHistory).where(
|
|
|
|
- StaffConfigurationHistory.configuration_id == staff_configuration_id
|
|
|
|
- )
|
|
|
|
- results = session.execute(stmt).scalars().all()
|
|
|
|
- results = to_dict(results)
|
|
|
|
- for result in results:
|
|
|
|
- pass
|
|
|
|
- staff_list = []
|
|
|
|
- for staff_id in json.loads(result['staff_list']):
|
|
|
|
- stmt = select(SecurityPerson).where(SecurityPerson.id == staff_id)
|
|
|
|
- staff = session.execute(stmt).scalars().first().__dict__
|
|
|
|
- del staff['_sa_instance_state']
|
|
|
|
- staff_list.append(staff)
|
|
|
|
- result['staff_list'] = staff_list
|
|
|
|
|
|
+ stmt = select(StaffConfigurationStaff.update_time) \
|
|
|
|
+ .where(StaffConfigurationStaff.Configuration_id == staff_configuration_id) \
|
|
|
|
+ .group_by(StaffConfigurationStaff.update_time)
|
|
|
|
+ update_time_res = session.execute(stmt).fetchall()
|
|
|
|
+
|
|
|
|
+ for update_time in update_time_res:
|
|
|
|
+ stmt = select(StaffConfigurationStaff).where(StaffConfigurationStaff.update_time == update_time[0])
|
|
|
|
+ results.append({update_time[0]: to_dict(session.execute(stmt).scalars().all())})
|
|
|
|
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
save_log(request, Module.INFORMATION, OperationType.INQUIRE, StatesCode.SUCCESS)
|
|
|
|
|