Browse Source

2023-5-23 完善信息管理安保人员配置

zhangnaiwen 2 năm trước cách đây
mục cha
commit
1412e0c1ae

+ 123 - 104
src/app/api/information.py

@@ -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)
 
 

+ 39 - 15
src/app/api/organization.py

@@ -3,7 +3,7 @@ import json
 
 
 from flask import request, jsonify, current_app
 from flask import request, jsonify, current_app
 from flask_restx import Resource, Namespace, reqparse
 from flask_restx import Resource, Namespace, reqparse
-from sqlalchemy import select, insert, delete, update, func
+from sqlalchemy import select, insert, delete, update, func, alias
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 from werkzeug.datastructures import FileStorage
 
 
@@ -18,12 +18,31 @@ ns = Namespace('organization', description='组织管理接口')
 company_list = reqparse.RequestParser(bundle_errors=True)
 company_list = reqparse.RequestParser(bundle_errors=True)
 company_list.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
 company_list.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
 company_list.add_argument(name='page', type=int, location='args', required=False, help='页数')
 company_list.add_argument(name='page', type=int, location='args', required=False, help='页数')
-company_list.add_argument(name='name', type=str, location='args', required=False, help='过滤公司名')
+
+company_search = reqparse.RequestParser(bundle_errors=True)
+company_search.add_argument(name='name', type=str, location='args', required=False, help='过滤公司名')
+
+
+@ns.route('/company_search')
+class CompanySearch(Resource):
+
+    @ns.doc(description='公司搜索')
+    @ns.expect(company_search)
+    def get(self):
+        """公司查询"""
+        company_name = request.args.get('name')
+        with Session(current_app.engine) as session:
+            if company_name:
+                stmt = select(Company).where(Company.company_name.like("%{}%".format(company_name)))
+                results = session.execute(stmt).scalars().all()
+                save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.SUCCESS)
+
+                return jsonify(code=StatesCode.SUCCESS, message='成功', data=to_dict(results))
 
 
 
 
 @ns.route('/company_list')
 @ns.route('/company_list')
 class CompanyListApi(Resource):
 class CompanyListApi(Resource):
-    #method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='get_company_list', description='获取公司列表')
     @ns.doc(id='get_company_list', description='获取公司列表')
     @ns.expect(company_list)
     @ns.expect(company_list)
@@ -32,23 +51,28 @@ class CompanyListApi(Resource):
 
 
         page_size = int(request.args.get('page_size', 20))
         page_size = int(request.args.get('page_size', 20))
         page = int(request.args.get('page', 1))
         page = int(request.args.get('page', 1))
-        company_name = request.args.get('name')
 
 
         try:
         try:
             with Session(current_app.engine) as session:
             with Session(current_app.engine) as session:
+                # 统计总数
                 count = select(func.count(Company.id))
                 count = select(func.count(Company.id))
                 count_results = session.execute(count).scalars().first()
                 count_results = session.execute(count).scalars().first()
 
 
-                stmt = select(Company)
-                if company_name:
-                    stmt = stmt.where(Company.company_name.like("%{}%".format(company_name)))
-
+                # 查询无上级公司的公司
+                stmt = select(Company).where(Company.parent_company == None)
                 stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
                 stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
                 results = session.execute(stmt).scalars().all()
                 results = session.execute(stmt).scalars().all()
+                results = to_dict(results)
 
 
+                # 获取下级公司
+                for result in results:
+                    stmt = select(Company).where(Company.parent_company == result.get('id'))
+                    parent_company = session.execute(stmt).scalars().all()
+                    parent_company = to_dict(parent_company)
+                    result['parent_company'] = parent_company
             save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.SUCCESS)
             save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.SUCCESS)
 
 
-            return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=to_dict(results))
+            return jsonify(code=StatesCode.SUCCESS, message='成功', total=count_results, data=results)
 
 
         except Exception as e:
         except Exception as e:
             save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
             save_log(request, Module.ORGANIZATION, OperationType.INQUIRE, StatesCode.UNKNOWN_ERROR)
@@ -80,7 +104,7 @@ get_company_details.add_argument(name='company_id', type=int, location='args', r
 
 
 @ns.route('/company')
 @ns.route('/company')
 class CompanyApi(Resource):
 class CompanyApi(Resource):
-    #method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='get_company_details', description='获取公司详情')
     @ns.doc(id='get_company_details', description='获取公司详情')
     @ns.expect(get_company_details)
     @ns.expect(get_company_details)
@@ -155,7 +179,7 @@ class CompanyApi(Resource):
                     company_code=company_code,
                     company_code=company_code,
                     staff_size=staff_size,
                     staff_size=staff_size,
                     on_guard_size=on_guard_size,
                     on_guard_size=on_guard_size,
-                    Parent_company=parent_company
+                    parent_company=parent_company
                 )
                 )
                 session.execute(stmt)
                 session.execute(stmt)
 
 
@@ -212,7 +236,7 @@ class CompanyApi(Resource):
                     company_code=company_code,
                     company_code=company_code,
                     staff_size=staff_size,
                     staff_size=staff_size,
                     on_guard_size=on_guard_size,
                     on_guard_size=on_guard_size,
-                    Parent_company=parent_company
+                    parent_company=parent_company
                 )
                 )
                 session.execute(stmt)
                 session.execute(stmt)
                 session.commit()
                 session.commit()
@@ -264,7 +288,7 @@ department_details.add_argument(name='censure', type=str, location='form', requi
 
 
 @ns.route('/department_list')
 @ns.route('/department_list')
 class DepartmentListApi(Resource):
 class DepartmentListApi(Resource):
-    #method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='department_list', description='获取公司下部门列表')
     @ns.doc(id='department_list', description='获取公司下部门列表')
     @ns.expect(get_company_details)
     @ns.expect(get_company_details)
@@ -299,7 +323,7 @@ get_department.add_argument(name='department_id', type=str, location='args', req
 
 
 @ns.route('/department')
 @ns.route('/department')
 class DepartmentApi(Resource):
 class DepartmentApi(Resource):
-    #method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='get_department_details', description='获取部门详情')
     @ns.doc(id='get_department_details', description='获取部门详情')
     @ns.expect(get_department)
     @ns.expect(get_department)
@@ -440,7 +464,7 @@ batch_delete_company.add_argument(name='company_ids', type=list, location='form'
 
 
 @ns.route('/batch_delete_company')
 @ns.route('/batch_delete_company')
 class BatchDeleteCompanyApi(Resource):
 class BatchDeleteCompanyApi(Resource):
-    #method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='batch_delete_users', description='批量删除公司')
     @ns.doc(id='batch_delete_users', description='批量删除公司')
     @ns.expect(batch_delete_company)
     @ns.expect(batch_delete_company)

+ 2 - 1
src/app/api/permission.py

@@ -22,7 +22,7 @@ class PermissionApi(Resource):
         """获取权限信息"""
         """获取权限信息"""
         data = []
         data = []
         with Session(current_app.engine) as session:
         with Session(current_app.engine) as session:
-            stmt = select(Menus.id, Menus.name).where(Menus.parent_id == 0)
+            stmt = select(Menus.id, Menus.name, Menus.menu_type).where(Menus.parent_id == 0)
             results = session.execute(stmt)
             results = session.execute(stmt)
             for result in results:
             for result in results:
                 stmt2 = select(Menus.id, Menus.name, Menus.menu_type).where(Menus.parent_id == result.id)
                 stmt2 = select(Menus.id, Menus.name, Menus.menu_type).where(Menus.parent_id == result.id)
@@ -30,6 +30,7 @@ class PermissionApi(Resource):
                     {
                     {
                         'id': result.id,
                         'id': result.id,
                         'name': result.name,
                         'name': result.name,
+                        'menu_type': result.menu_type,
                         'children': [
                         'children': [
                             {'id': result1.id, 'name': result1.name, 'menu_type': result1.menu_type} for result1 in session.execute(stmt2)
                             {'id': result1.id, 'name': result1.name, 'menu_type': result1.menu_type} for result1 in session.execute(stmt2)
                         ]
                         ]

+ 59 - 25
src/app/modle/information.py

@@ -1,6 +1,4 @@
-from urllib import parse
-
-from sqlalchemy import String, Column, Integer, DateTime, JSON, create_engine
+from sqlalchemy import String, Column, Integer, DateTime, JSON, create_engine, Text
 
 
 from app.modle import Base
 from app.modle import Base
 from app.utils.util import cn_now
 from app.utils.util import cn_now
@@ -38,38 +36,74 @@ class StaffConfiguration(Base):
 
 
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
     name = Column(String, nullable=False, unique=False, index=False, doc='配置名称')
     name = Column(String, nullable=False, unique=False, index=False, doc='配置名称')
-    personnel_type = Column(String, nullable=True, unique=False, index=False, doc='人员类别')
-    responsibility_range = Column(String, nullable=True, unique=False, index=False, doc='职责范围')
-    staff_list = Column(String, nullable=True, unique=False, index=False, doc='人员名单')
-    remark = Column(String, nullable=True, unique=False, index=False, doc='备注')
-    duty_time = Column(JSON, nullable=True, unique=False, index=False, doc="值班日期:{'start_time': '', end_time: ''}")
-
+    # personnel_type = Column(String, nullable=True, unique=False, index=False, doc='人员类别')
+    # responsibility_range = Column(String, nullable=True, unique=False, index=False, doc='职责范围')
+    # staff_list = Column(String, nullable=True, unique=False, index=False, doc='人员名单')
+    # remark = Column(String, nullable=True, unique=False, index=False, doc='备注')
+    # duty_time = Column(JSON, nullable=True, unique=False, index=False, doc="值班日期:{'start_time': '', end_time: ''}")
 
 
-class StaffConfigurationHistory(Base):
-    """安保人员信息配置历史记录"""
 
 
-    __tablename__ = 'StaffConfigurationHistory'
+class StaffConfigurationStaff(Base):
+    """安保人员信息配置人员"""
 
 
+    __tablename__ = 'StaffConfigurationStaff'
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
-    configuration_id = Column(String, nullable=True, unique=False, index=False, doc='配置id')
-    staff_list = Column(String, nullable=True, unique=False, index=False, doc='人员名单')
+    Configuration_id = Column(String, nullable=True, unique=False, index=False, doc='配置id')
+    responsibility_range = Column(String, nullable=True, unique=False, index=False, doc='职责范围')
+    staff = Column(String, nullable=True, unique=False, index=False, doc='人员')
+    remark = Column(String, nullable=True, unique=False, index=False, doc='备注')
     duty_time = Column(JSON, nullable=True, unique=False, index=False, doc="值班日期:{'start_time': '', end_time: ''}")
     duty_time = Column(JSON, nullable=True, unique=False, index=False, doc="值班日期:{'start_time': '', end_time: ''}")
+    update_time = Column(String, nullable=True, unique=False, index=False, doc='更新时间')
+    staff_details = Column(Text, nullable=True, unique=False, index=False, doc='人员信息')
+
+
+# class StaffConfigurationHistory(Base):
+#     """安保人员信息配置历史记录"""
+#
+#     __tablename__ = 'StaffConfigurationHistory'
+#
+#     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+#     configuration_id = Column(String, nullable=True, unique=False, index=False, doc='配置id')
+#     staff_list = Column(String, nullable=True, unique=False, index=False, doc='人员名单')
+#     duty_time = Column(JSON, nullable=True, unique=False, index=False, doc="值班日期:{'start_time': '', end_time: ''}")
 
 
 
 
 class SecurityPerson(Base):
 class SecurityPerson(Base):
     """人员表"""
     """人员表"""
 
 
-    __tablename__ = 'security_person'
+    __tablename__ = 'person'
 
 
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
     id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
     name = Column(String, nullable=True, unique=False, index=False, doc='姓名')
     name = Column(String, nullable=True, unique=False, index=False, doc='姓名')
-    work_number = Column(String, nullable=True, unique=False, index=False, doc='工号')
-    phone = Column(String, nullable=True, unique=False, index=False, doc='联系电话')
-    scope = Column(String, nullable=True, unique=False, index=False, doc='工作区域')
-    company_id = Column(Integer, nullable=True, unique=False, index=False, doc='单位id')
-    dept_id = Column(Integer, nullable=True, unique=False, index=False, doc='部门id')
-    company = Column(String, nullable=True, unique=False, index=False, doc='单位')
-    department = Column(String, nullable=True, unique=False, index=False, doc='部门')
-    register_time = Column(String, nullable=True, unique=False, index=False, doc='入职时间')
-    type = Column(Integer, nullable=True, unique=False, index=False, doc='人员类型 1安防人员 2前台人员')
-    photo = Column(String, nullable=True, unique=False, index=False, doc='头像')
+    phone = Column(String, nullable=True, unique=False, index=False, doc='手机号')
+    type = Column(Integer, nullable=True, unique=False, index=False, doc='人员类型 * 0 正式员工  1 外协员工 2 驻场物业3 施工人员 4 厂商 5 其他')
+    status = Column(Integer, nullable=True, unique=False, index=False, doc=' 0 正常1 已离职2 暂时冻结')
+    is_del = Column(Integer, nullable=True, unique=False, index=False, doc='')
+    company_id = Column(Integer, nullable=True, unique=False, index=False, doc='')
+    company_name = Column(String, nullable=True, unique=False, index=False, doc='')
+    dept_id = Column(Integer, nullable=True, unique=False, index=False, doc='')
+    dept_name = Column(String, nullable=True, unique=False, index=False, doc='')
+    create_time = Column(DateTime, nullable=True, unique=False, index=False, doc='')
+    update_time = Column(DateTime, nullable=True, unique=False, index=False, doc='')
+    email = Column(String, nullable=True, unique=False, index=False, doc='邮箱')
+    duty = Column(String, nullable=True, unique=False, index=False, doc='职务')
+    hiredate = Column(DateTime, nullable=True, unique=False, index=False, doc='入职时间')
+    address = Column(String, nullable=True, unique=False, index=False, doc='家庭住址')
+    function_type = Column(String, nullable=True, unique=False, index=False, doc='职能类型')
+    hr_number = Column(String, nullable=True, unique=False, index=False, doc='HR编号')
+    work_address = Column(String, nullable=True, unique=False, index=False, doc='办公驻地')
+    floor = Column(String, nullable=True, unique=False, index=False, doc='办公楼层')
+    zy_number = Column(String, nullable=True, unique=False, index=False, doc='主语人员编码')
+    room_number = Column(String, nullable=True, unique=False, index=False, doc='房间号')
+    site_number = Column(String, nullable=True, unique=False, index=False, doc='工位号')
+    id_card = Column(String, nullable=True, unique=False, index=False, doc='身份证号')
+    physics_card = Column(String, nullable=True, unique=False, index=False, doc='物理卡号')
+    account = Column(String, nullable=True, unique=False, index=False, doc='消费账号')
+    car_number = Column(String, nullable=True, unique=False, index=False, doc='车牌号')
+    role = Column(String, nullable=True, unique=False, index=False, doc='角色')
+    operate_status = Column(String, nullable=True, unique=False, index=False, doc='操作状态')
+    issue_status = Column(String, nullable=True, unique=False, index=False, doc='下发状态')
+    impower_time = Column(DateTime, nullable=True, unique=False, index=False, doc='授权时间')
+    in_out = Column(String, nullable=True, unique=False, index=False, doc='出入口权限')
+    access = Column(String, nullable=True, unique=False, index=False, doc='门禁权限')
+    card_number = Column(String, nullable=True, unique=False, index=False, doc='卡片编号')

+ 1 - 1
src/app/modle/organization.py

@@ -22,7 +22,7 @@ class Company(Base):
     company_code = Column(String, nullable=True, unique=False, index=False, doc='公司编码')
     company_code = Column(String, nullable=True, unique=False, index=False, doc='公司编码')
     staff_size = Column(Integer, nullable=True, unique=False, index=False, doc='编制人数')
     staff_size = Column(Integer, nullable=True, unique=False, index=False, doc='编制人数')
     on_guard_size = Column(Integer, nullable=True, unique=False, index=False, doc='在岗人数')
     on_guard_size = Column(Integer, nullable=True, unique=False, index=False, doc='在岗人数')
-    Parent_company = Column(Integer, nullable=True, unique=False, index=False, doc='上级公司id')
+    parent_company = Column(Integer, nullable=True, unique=False, index=False, doc='上级公司id')
     area_id = Column(Integer, nullable=True, unique=False, index=False, doc='区域id')
     area_id = Column(Integer, nullable=True, unique=False, index=False, doc='区域id')
     office_id = Column(Integer, nullable=True, unique=False, index=False, doc='部门id')
     office_id = Column(Integer, nullable=True, unique=False, index=False, doc='部门id')
     department = relationship('Department', cascade='all, delete-orphan')
     department = relationship('Department', cascade='all, delete-orphan')

+ 4 - 0
src/manage.py

@@ -57,3 +57,7 @@ def dbinit():
 @application.cli.command('ceshi')
 @application.cli.command('ceshi')
 def ceshi():
 def ceshi():
     print('this is a test')
     print('this is a test')
+
+
+if __name__ == '__main__':
+    dbinit()