瀏覽代碼

消息模块 楼层地图信息配置

zhangnaiwen 2 年之前
父節點
當前提交
105745a809
共有 4 個文件被更改,包括 232 次插入3 次删除
  1. 5 1
      config/config.yml
  2. 194 0
      src/app/api/information.py
  3. 2 2
      src/app/api/organization.py
  4. 31 0
      src/app/modle/information.py

+ 5 - 1
config/config.yml

@@ -1,13 +1,17 @@
 common:
   JWT_SECRET: SKYversation0816
-  JWT_EXPIRY: 3600
+  JWT_EXPIRY: 86400
   MESSAGR_TYPE: ["普通消息","提醒消息"]
+  INFORMATION_TYPE: ["楼层地图信息配置", "安保人员信息配置"]
   # 公司商标存储地址
   COMPANY_LOGO_PATH: /data/company_logo
   COMPANY_LOGO_URL: http://127.0.0.1/company_logo/
   # 模版存储地址
   TEMPLATE_FILE_PATH: /data/template
   TEMPLATE_FILE_URL: http://127.0.0.1/template/
+  # 楼层地图信息配置附件存醋位置
+  FLOOR_CONFIGURATION_PATH: /data/floor_configuration
+  FLOOR_CONFIGURATION_URL: http://127.0.0.1/floor_configuration/
   # 公司图片存醋地址
   COMPANY_PICTURE_PATH: /data/company
   COMPANY_PICTURE_URL: http://127.0.0.1/company/

+ 194 - 0
src/app/api/information.py

@@ -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):
+        """删除安保人员信息配置"""

+ 2 - 2
src/app/api/organization.py

@@ -199,9 +199,9 @@ class CompanyApi(Resource):
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
 
         with Session(current_app.engine) as session:
-            stmt = select(Company).where(Company.id == company_id)
+            stmt = delete(Company).where(Company.id == company_id)
 
-            session.delete(session.execute(stmt).scalars().first())
+            session.execute(stmt)
             session.commit()
 
         save_log(request, Module.ORGANIZATION, OperationType.DELETE, StatesCode.SUCCESS)

+ 31 - 0
src/app/modle/information.py

@@ -0,0 +1,31 @@
+from sqlalchemy import String, Column, Integer
+
+from app.modle import Base
+
+
+class FloorConfiguration(Base):
+    """楼层表"""
+
+    __tablename__ = 'FloorConfiguration'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    name = Column(String, nullable=False, unique=False, index=False, doc='配置名称')
+    location = Column(String, nullable=True, unique=False, index=False, doc='楼层位置')
+    use = Column(String, nullable=True, unique=False, index=False, doc='楼层用途')
+    remark = Column(String, nullable=True, unique=False, index=False, doc='备注')
+    attachment = Column(String, nullable=True, unique=False, index=False, doc='附件')
+
+
+class StaffConfiguration(Base):
+    """人员配置"""
+
+    __tablename__ = 'StaffConfiguration'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    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='备注')
+
+