Procházet zdrojové kódy

配置文件逻辑修改,数据库引擎写入app对象

zhangnaiwen před 2 roky
rodič
revize
173996cb51

+ 1 - 0
Dockerfile

@@ -1,5 +1,6 @@
 FROM operation_management_center_base:latest
 FROM operation_management_center_base:latest
 
 
+COPY ./conf/uwsgi.ini /work/operation_management_center/conf/uwsgi.ini
 COPY ./src /work/operation_management_center/src
 COPY ./src /work/operation_management_center/src
 
 
 WORKDIR /work/operation_management_center/src
 WORKDIR /work/operation_management_center/src

+ 4 - 5
base/Dockerfile

@@ -1,16 +1,15 @@
-FROM debian11_py3.11:latest
+FROM debian11_py3.9_slim:latest
 
 
 COPY ./requirements.txt /tmp/
 COPY ./requirements.txt /tmp/
 COPY ./conf/bootstrap.sh /opt/bootstrap.sh
 COPY ./conf/bootstrap.sh /opt/bootstrap.sh
-COPY ./conf/uwsgi.ini /work/operation_management_center/conf/uwsgi.ini
 COPY ./conf/supervisord.conf /etc/
 COPY ./conf/supervisord.conf /etc/
 COPY ./conf/supervisor.conf /etc/supervisord.d/supervisor.conf
 COPY ./conf/supervisor.conf /etc/supervisord.d/supervisor.conf
 
 
 RUN apt-get -y update \
 RUN apt-get -y update \
     && apt-get -y upgrade \
     && apt-get -y upgrade \
-    && apt-get install -y supervisor libpq-dev python-dev\
-    && pip3.11 install -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \
-    && pip3.11 install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple \
+    && apt-get install -y supervisor libpq-dev python3-dev\
+    && pip3 install -r /tmp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \
+    && pip3 install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/simple \
     # 默认是128,当server处理请求较慢,以至于socket监听队列被填满后,新来的请求会被拒绝。
     # 默认是128,当server处理请求较慢,以至于socket监听队列被填满后,新来的请求会被拒绝。
     && mkdir /opt/init  \
     && mkdir /opt/init  \
     && echo "echo 2048 > /proc/sys/net/core/somaxconn" > /opt/init/sysctl.sh  \
     && echo "echo 2048 > /proc/sys/net/core/somaxconn" > /opt/init/sysctl.sh  \

+ 34 - 0
config/config.yml

@@ -0,0 +1,34 @@
+common:
+  JWT_SECRET: SKYversation0816
+  JWT_EXPIRY: 3600
+  MESSAGR_TYPE: ["普通消息","提醒消息"]
+  # 公司商标存储地址
+  COMPANY_LOGO_PATH: /Users/mac/data/company_logo
+  COMPANY_LOGO_URL: http://127.0.0.1/company_logo/
+  # 模版存储地址
+  TEMPLATE_FILE_PATH: /Users/mac/data/template
+  TEMPLATE_FILE_URL: http://127.0.0.1/template/
+  # 公司图片存醋地址
+  COMPANY_PICTURE_PATH: /Users/mac/data/company
+  COMPANY_PICTURE_URL: http://127.0.0.1/company/
+  # 楼宇图片存醋地址
+  BUILDING_PICTURE_PATH: /Users/mac/data/building
+  BUILDING_PICTURE_URL: http://127.0.0.1/building/
+  # 底层系统信息图片存醋地址
+  UNDERLYING_SYSTEM_PICTURE_PATH: /Users/mac/data/underlying_system
+  UNDERLYING_SYSTEM_PICTURE_URL: http://127.0.0.1/underlying_system/
+
+#redis:
+#  # redis配置
+#  HOST: 192.168.2.35 # 使用容器运行服务时,该HOST信息无用,容器内部会自动获取redis容器的ip
+#  PORT: 6379 # 不要修改该端口号,除非明确了解使用场景
+#  DB: 0
+
+database:
+  # 数据库配置信息
+  # 如果使用外部数据库,例如polardb,请修改以下配置信息
+  HOST: 127.0.0.1 # 数据库IP地址
+  PORT: 5432 # 数据库端口号
+  USER: mac # 用户名
+  PASSWORD: ''  # 密码
+  DB: postgres # 数据库名

+ 9 - 3
docker-compose-v3.yml

@@ -3,10 +3,10 @@ services:
   sky-gistools-server:
   sky-gistools-server:
       container_name: operation_management_center
       container_name: operation_management_center
 
 
-      image: operation_management_center:1.0.0
+      image: operation_management_center:latest
 
 
       ports:
       ports:
-        - "5001:5000"
+        - "5000:5000"
 
 
       environment:
       environment:
         - UWSGI_PROCESSES=8
         - UWSGI_PROCESSES=8
@@ -17,7 +17,13 @@ services:
         - UWSGI_PY_OPTIMIZE=0
         - UWSGI_PY_OPTIMIZE=0
 
 
       volumes:
       volumes:
-        - /data:/data
+        - /data/logs:/data/logs # 日志
+        - /data/company_logo:data/company_logo  # 公司商标存储地址
+        - /data/template:/data/template  # 模版存储地址
+        - /data/company:/data/company  # 公司图片存醋地址
+        - /data/building:/data/building  # 楼宇图片存醋地址
+        - /data/underlying_system:/data/underlying_system  # 底层系统信息图片存醋地址
+        - ./config:/work/operation_management_center/config  # 配置文件目录,包括软件配置信息
 
 
       privileged: true
       privileged: true
 
 

+ 8 - 1
docker-compose.yml

@@ -15,7 +15,14 @@ service:
     - UWSGI_PY_OPTIMIZE=0
     - UWSGI_PY_OPTIMIZE=0
 
 
   volumes:
   volumes:
-    - /data:/data
+    - /data/logs:/data/logs # 日志
+    - /data/company_logo:data/company_logo  # 公司商标存储地址
+    - /data/template:/data/template  # 模版存储地址
+    - /data/company:/data/company  # 公司图片存醋地址
+    - /data/building:/data/building  # 楼宇图片存醋地址
+    - /data/underlying_system:/data/underlying_system  # 底层系统信息图片存醋地址
+    - ./config:/work/operation_management_center/config  # 配置文件目录,包括软件配置信息
+
 
 
   privileged: true
   privileged: true
 
 

+ 1 - 0
requirements.txt

@@ -16,6 +16,7 @@ psycopg2==2.9.5
 pycparser==2.21
 pycparser==2.21
 pyrsistent==0.19.3
 pyrsistent==0.19.3
 pytz==2022.7.1
 pytz==2022.7.1
+pyyaml
 six==1.16.0
 six==1.16.0
 SQLAlchemy==2.0.7
 SQLAlchemy==2.0.7
 SQLAlchemy-Utils==0.40.0
 SQLAlchemy-Utils==0.40.0

+ 14 - 0
src/app/__init__.py

@@ -1,18 +1,32 @@
+import os
+
 from flask import Flask
 from flask import Flask
 from flask_cors import CORS
 from flask_cors import CORS
 
 
+from sqlalchemy import create_engine
 from app.api import api
 from app.api import api
 from app.helpers import request_handlers
 from app.helpers import request_handlers
+from config import Config
+
+manage_path = os.path.dirname(os.path.abspath(__file__))
+config_yml_path = os.path.join(os.path.dirname(os.path.dirname(manage_path)), 'config', 'config.yml')
 
 
 
 
 def create_app():
 def create_app():
     """创建app并初始化相关配置参数"""
     """创建app并初始化相关配置参数"""
+
+    config = Config()
+    config.load(config_yml_path)
+
     app = Flask(__name__)
     app = Flask(__name__)
 
 
     CORS(app)
     CORS(app)
 
 
     request_handlers.configure(app)
     request_handlers.configure(app)
 
 
+    url = f'postgresql+psycopg2://{config.database.USER}:{config.database.PASSWORD}@{config.database.HOST}:{config.database.PORT}/{config.database.DB}'
+    app.engine = create_engine(url)
+
     api.init_app(app)
     api.init_app(app)
 
 
     return app
     return app

+ 37 - 36
src/app/api/data.py

@@ -1,20 +1,18 @@
 import json
 import json
 import os
 import os
 
 
-from flask import request, jsonify, g
+from flask import request, jsonify, g, current_app
 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
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 from werkzeug.datastructures import FileStorage
 
 
-from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL, COMPANY_PICTURE_PATH, COMPANY_PICTURE_URL, \
-    BUILDING_PICTURE_PATH, BUILDING_PICTURE_URL, UNDERLYING_SYSTEM_PICTURE_PATH, UNDERLYING_SYSTEM_PICTURE_URL
-from app.database import engine
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
 from app.modle.data import Template, CompanyData, Building, UnderlyingSystem
 from app.modle.data import Template, CompanyData, Building, UnderlyingSystem
 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
+from config import Config
 
 
 ns = Namespace('data', description='数据管理接口')
 ns = Namespace('data', description='数据管理接口')
 
 
@@ -27,6 +25,8 @@ template_list.add_argument(name='template_type', type=str, location='args', requ
                            help='模版类型 0:报表,1:报告')
                            help='模版类型 0:报表,1:报告')
 template_list.add_argument(name='report_type', type=str, location='args', required=False, help='报告类型')
 template_list.add_argument(name='report_type', type=str, location='args', required=False, help='报告类型')
 
 
+config = Config()
+
 
 
 @ns.route('/template_list')
 @ns.route('/template_list')
 class TemplateConfigListApi(Resource):
 class TemplateConfigListApi(Resource):
@@ -43,7 +43,7 @@ class TemplateConfigListApi(Resource):
         report_type = request.args.get('report_type')
         report_type = request.args.get('report_type')
         template_type = request.args.get('template_type')
         template_type = request.args.get('template_type')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Template).where(Template.template_type == template_type)
             stmt = select(Template).where(Template.template_type == template_type)
 
 
             if template_name:
             if template_name:
@@ -91,7 +91,7 @@ class TemplateConfigApi(Resource):
         if template_id is None:
         if template_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Template).where(Template.id == template_id)
             stmt = select(Template).where(Template.id == template_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -115,12 +115,12 @@ class TemplateConfigApi(Resource):
 
 
         # 模版存储(url),
         # 模版存储(url),
         if template_file:
         if template_file:
-            template_file.save(os.path.join(TEMPLATE_FILE_PATH, template_file.filename))
-            template_url = TEMPLATE_FILE_URL + template_file.filename
+            template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
+            template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
         else:
         else:
             template_url = None
             template_url = None
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             # 判断是否存在
             # 判断是否存在
             stmt = select(Template).where(Template.name == template_name)
             stmt = select(Template).where(Template.name == template_name)
             result = session.execute(stmt).scalars().first()
             result = session.execute(stmt).scalars().first()
@@ -164,12 +164,12 @@ class TemplateConfigApi(Resource):
 
 
         # 报表模版存储(url),
         # 报表模版存储(url),
         if template_file:
         if template_file:
-            template_file.save(os.path.join(TEMPLATE_FILE_PATH, template_file.filename))
-            template_url = TEMPLATE_FILE_URL + template_file.filename
+            template_file.save(os.path.join(config.common.TEMPLATE_FILE_PATH, template_file.filename))
+            template_url = config.common.TEMPLATE_FILE_URL + template_file.filename
         else:
         else:
             template_url = None
             template_url = None
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(Template).where(Template.id == template_id).values(
             stmt = update(Template).where(Template.id == template_id).values(
                 name=template_name,
                 name=template_name,
                 format=template_format,
                 format=template_format,
@@ -197,7 +197,7 @@ class TemplateConfigApi(Resource):
         if template_id is None:
         if template_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="模版id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = delete(Template).where(Template.id == template_id)
             stmt = delete(Template).where(Template.id == template_id)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -226,7 +226,7 @@ class BatchTemplateConfigApi(Resource):
         else:
         else:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='模版id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Template).where(Template.id.in_(template_ids))
             stmt = select(Template).where(Template.id.in_(template_ids))
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -265,7 +265,7 @@ class CompanyApi(Resource):
         if company_id is None:
         if company_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(CompanyData).where(CompanyData.id == company_id)
             stmt = select(CompanyData).where(CompanyData.id == company_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -291,10 +291,10 @@ class CompanyApi(Resource):
         picture_urls = []
         picture_urls = []
         if pictures:
         if pictures:
             for picture in pictures:
             for picture in pictures:
-                picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
-                picture_urls.append(COMPANY_PICTURE_URL + picture.filename)
+                picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
+                picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             # 判断是否存在
             # 判断是否存在
             stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
             stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
             result = session.execute(stmt).scalars().first()
             result = session.execute(stmt).scalars().first()
@@ -338,10 +338,10 @@ class CompanyApi(Resource):
         picture_urls = []
         picture_urls = []
         if pictures:
         if pictures:
             for picture in pictures:
             for picture in pictures:
-                picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
-                picture_urls.append(COMPANY_PICTURE_URL + picture.filename)
+                picture.save(os.path.join(config.common.COMPANY_PICTURE_PATH, picture.filename))
+                picture_urls.append(config.common.COMPANY_PICTURE_URL + picture.filename)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(CompanyData).where(CompanyData.id == company_id).values(
             stmt = update(CompanyData).where(CompanyData.id == company_id).values(
                 management_unit=management_unit,
                 management_unit=management_unit,
                 custodian_unit=custodian_unit,
                 custodian_unit=custodian_unit,
@@ -367,7 +367,7 @@ class BuildingListApi(Resource):
     def get(self):
     def get(self):
         """获取楼宇列表"""
         """获取楼宇列表"""
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Building)
             stmt = select(Building)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -405,7 +405,7 @@ class BuildingApi(Resource):
         if building_id is None:
         if building_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Building).where(Building.id == building_id)
             stmt = select(Building).where(Building.id == building_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -434,10 +434,10 @@ class BuildingApi(Resource):
         picture_urls = []
         picture_urls = []
         if pictures:
         if pictures:
             for picture in pictures:
             for picture in pictures:
-                picture.save(os.path.join(BUILDING_PICTURE_PATH, picture.filename))
-                picture_urls.append(BUILDING_PICTURE_URL + picture.filename)
+                picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
+                picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = insert(Building).values(
             stmt = insert(Building).values(
                 name=building_name,
                 name=building_name,
                 area=building_area,
                 area=building_area,
@@ -478,10 +478,10 @@ class BuildingApi(Resource):
         picture_urls = []
         picture_urls = []
         if pictures:
         if pictures:
             for picture in pictures:
             for picture in pictures:
-                picture.save(os.path.join(BUILDING_PICTURE_PATH, picture.filename))
-                picture_urls.append(BUILDING_PICTURE_URL + picture.filename)
+                picture.save(os.path.join(config.common.BUILDING_PICTURE_PATH, picture.filename))
+                picture_urls.append(config.common.BUILDING_PICTURE_URL + picture.filename)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(Building).where(Building.id == building_id).values(
             stmt = update(Building).where(Building.id == building_id).values(
                 name=building_name,
                 name=building_name,
                 area=building_area,
                 area=building_area,
@@ -508,7 +508,7 @@ class BuildingApi(Resource):
         if building_id is None:
         if building_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='楼宇id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = delete(Building).where(Building.id == building_id)
             stmt = delete(Building).where(Building.id == building_id)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -524,13 +524,14 @@ underlying_system.add_argument(name='picture', type=FileStorage, location='files
 
 
 @ns.route('/underlying_system')
 @ns.route('/underlying_system')
 class UnderlyingSystemMessageApi(Resource):
 class UnderlyingSystemMessageApi(Resource):
-    method_decorators = [login_required]
+    # method_decorators = [login_required]
 
 
     @ns.doc(id='underlying_system_list', description='获取底层系统')
     @ns.doc(id='underlying_system_list', description='获取底层系统')
     @ns.expect()
     @ns.expect()
     def get(self):
     def get(self):
         """获取底层系统"""
         """获取底层系统"""
-        with Session(engine) as session:
+
+        with Session(current_app.engine) as session:
             stmt = select(UnderlyingSystem)
             stmt = select(UnderlyingSystem)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -544,14 +545,14 @@ class UnderlyingSystemMessageApi(Resource):
 
 
         # 存储(url),
         # 存储(url),
         if picture:
         if picture:
-            picture.save(os.path.join(UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
-            picture_url = UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
+            picture.save(os.path.join(config.common.UNDERLYING_SYSTEM_PICTURE_PATH, picture.filename))
+            picture_url = config.common.UNDERLYING_SYSTEM_PICTURE_URL + picture.filename
 
 
-            with Session(engine) as session:
+            with Session(current_app.engine) as session:
                 stmt = insert(UnderlyingSystem).values(
                 stmt = insert(UnderlyingSystem).values(
                     picture=picture_url
                     picture=picture_url
                 )
                 )
                 session.execute(stmt)
                 session.execute(stmt)
                 session.commit()
                 session.commit()
 
 
-            return jsonify(code=StatesCode.SUCCESS, message='添加成功')
+            return jsonify(code=StatesCode.SUCCESS, message='成功')

+ 3 - 4
src/app/api/log.py

@@ -1,12 +1,11 @@
 import json
 import json
 from io import StringIO
 from io import StringIO
 
 
-from flask import request, jsonify, Response
+from flask import request, jsonify, Response, current_app
 from flask_restx import Resource, Namespace, reqparse
 from flask_restx import Resource, Namespace, reqparse
 from sqlalchemy import select
 from sqlalchemy import select
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
 from app.modle.log import Log
 from app.modle.log import Log
 from app.utils.jwt_util import login_required
 from app.utils.jwt_util import login_required
@@ -40,7 +39,7 @@ class LogList(Resource):
         operation_type = request.args.get('operation_type')
         operation_type = request.args.get('operation_type')
         operation_status = request.args.get('operation_status')
         operation_status = request.args.get('operation_status')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Log)
             stmt = select(Log)
 
 
             if module:
             if module:
@@ -68,7 +67,7 @@ class LogExportApi(Resource):
     @ns.doc(id='log_export', description='日志导出')
     @ns.doc(id='log_export', description='日志导出')
     def get(self):
     def get(self):
         """日志导出"""
         """日志导出"""
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Log)
             stmt = select(Log)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 

+ 2 - 3
src/app/api/login.py

@@ -1,9 +1,8 @@
-from flask import request, jsonify, g
+from flask import request, jsonify, g, current_app
 from sqlalchemy import select
 from sqlalchemy import select
 from flask_restx import Resource, Namespace, reqparse
 from flask_restx import Resource, Namespace, reqparse
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.modle.users import User
 from app.modle.users import User
 from app.utils.jwt_util import generate_jwt
 from app.utils.jwt_util import generate_jwt
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
@@ -25,7 +24,7 @@ class LoginApi(Resource):
         username = request.form.get('username')
         username = request.form.get('username')
         password = request.form.get('password')
         password = request.form.get('password')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User).where(User.user_name == username)
             stmt = select(User).where(User.user_name == username)
             result = session.execute(stmt).scalars().first()
             result = session.execute(stmt).scalars().first()
             # statement = session.query(User).filter_by(user_name=username).first()
             # statement = session.query(User).filter_by(user_name=username).first()

+ 7 - 6
src/app/api/message.py

@@ -1,17 +1,18 @@
-from flask import request, jsonify
+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
 from sqlalchemy import select
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
-from app.configs.config import MESSAGR_TYPE
 from app.modle.message import Message
 from app.modle.message import Message
 from app.utils.save_log import save_log
 from app.utils.save_log import save_log
 from app.utils.util import to_dict
 from app.utils.util import to_dict
+from config import Config
 
 
 ns = Namespace('message', description='消息管理接口')
 ns = Namespace('message', description='消息管理接口')
 
 
+config = Config()
+
 
 
 @ns.route('/message_list')
 @ns.route('/message_list')
 class MessageTypeApi(Resource):
 class MessageTypeApi(Resource):
@@ -19,8 +20,8 @@ class MessageTypeApi(Resource):
     def get(self):
     def get(self):
         """获取消息列表"""
         """获取消息列表"""
         data = {}
         data = {}
-        for message in MESSAGR_TYPE:
-            with Session(engine) as session:
+        for message in config.common.MESSAGR_TYPE:
+            with Session(current_app.engine) as session:
                 stmt = select(Message.id, Message.name).where(Message.type == message)
                 stmt = select(Message.id, Message.name).where(Message.type == message)
 
 
                 for row in session.execute(stmt):
                 for row in session.execute(stmt):
@@ -50,7 +51,7 @@ class MessageApi(Resource):
         if message_id is None:
         if message_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='消息id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='消息id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Message).where(Message.id == message_id)
             stmt = select(Message).where(Message.id == message_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 

+ 19 - 18
src/app/api/organization.py

@@ -1,19 +1,18 @@
 import json
 import json
 import os
 import os
 
 
-from flask import request, jsonify
+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
 from sqlalchemy import select, insert, delete, update
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 from werkzeug.datastructures import FileStorage
 
 
-from app.configs.config import COMPANY_LOGO_PATH, COMPANY_LOGO_URL
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
-from app.database import engine
 from app.modle.organization import Company, Department
 from app.modle.organization import Company, Department
 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
 from app.utils.util import to_dict
+from config import Config
 
 
 ns = Namespace('organization', description='组织管理接口')
 ns = Namespace('organization', description='组织管理接口')
 
 
@@ -21,6 +20,8 @@ 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='页数')
 
 
+config = Config()
+
 
 
 @ns.route('/company_list')
 @ns.route('/company_list')
 class CompanyListApi(Resource):
 class CompanyListApi(Resource):
@@ -34,7 +35,7 @@ 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))
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Company).offset(page_size * (page - 1)).limit(page_size)
             stmt = select(Company).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -77,7 +78,7 @@ class CompanyApi(Resource):
         if company_id is None:
         if company_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Company).where(Company.id == company_id)
             stmt = select(Company).where(Company.id == company_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -106,12 +107,12 @@ class CompanyApi(Resource):
 
 
         # 公司商标存储(url),
         # 公司商标存储(url),
         if logo:
         if logo:
-            logo.save(os.path.join(COMPANY_LOGO_PATH, logo.filename))
-            logo_url = COMPANY_LOGO_URL + logo.filename
+            logo.save(os.path.join(config.common.COMPANY_LOGO_PATH, logo.filename))
+            logo_url = config.common.COMPANY_LOGO_URL + logo.filename
         else:
         else:
             logo_url = None
             logo_url = None
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             # 判断公司是否存在
             # 判断公司是否存在
             stmt = select(Company).where(Company.company_name == company_name)
             stmt = select(Company).where(Company.company_name == company_name)
             result = session.execute(stmt).scalars().first()
             result = session.execute(stmt).scalars().first()
@@ -160,12 +161,12 @@ class CompanyApi(Resource):
 
 
         # 公司商标存储(url),
         # 公司商标存储(url),
         if logo:
         if logo:
-            logo.save(os.path.join(COMPANY_LOGO_PATH, logo.filename))
-            logo_url = COMPANY_LOGO_URL + logo.filename
+            logo.save(os.path.join(config.common.COMPANY_LOGO_PATH, logo.filename))
+            logo_url = config.common.COMPANY_LOGO_URL + logo.filename
         else:
         else:
             logo_url = None
             logo_url = None
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(Company).where(Company.id == company_id).values(
             stmt = update(Company).where(Company.id == company_id).values(
                 company_name=company_name,
                 company_name=company_name,
                 logo=logo_url,
                 logo=logo_url,
@@ -194,7 +195,7 @@ class CompanyApi(Resource):
         if company_id is None:
         if company_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Company).where(Company.id == company_id)
             stmt = select(Company).where(Company.id == company_id)
 
 
             session.delete(session.execute(stmt).scalars().first())
             session.delete(session.execute(stmt).scalars().first())
@@ -233,7 +234,7 @@ class DepartmentListApi(Resource):
         if company_id is None:
         if company_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="公司id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Department.id, Department.department_name).where(Department.company_id == company_id)
             stmt = select(Department.id, Department.department_name).where(Department.company_id == company_id)
             results = session.execute(stmt)
             results = session.execute(stmt)
 
 
@@ -264,7 +265,7 @@ class DepartmentApi(Resource):
         if department_id is None:
         if department_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Department).where(Department.id == department_id)
             stmt = select(Department).where(Department.id == department_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -290,7 +291,7 @@ class DepartmentApi(Resource):
         if company_id is None or department_name is None:
         if company_id is None or department_name is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = insert(Department).values(
             stmt = insert(Department).values(
                 company_id=company_id,
                 company_id=company_id,
                 department_name=department_name,
                 department_name=department_name,
@@ -331,7 +332,7 @@ class DepartmentApi(Resource):
         if company_id is None or department_name is None:
         if company_id is None or department_name is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="上级公司和部门名称不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(Department).where(Department.id == department_id).values(
             stmt = update(Department).where(Department.id == department_id).values(
                 company_id=company_id,
                 company_id=company_id,
                 department_name=department_name,
                 department_name=department_name,
@@ -361,7 +362,7 @@ class DepartmentApi(Resource):
         if department_id is None:
         if department_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="部门id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = delete(Department).where(Department.id == department_id)
             stmt = delete(Department).where(Department.id == department_id)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -390,7 +391,7 @@ class BatchDeletecompanyApi(Resource):
         else:
         else:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Company).where(Company.id.in_(company_ids))
             stmt = select(Company).where(Company.id.in_(company_ids))
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 

+ 3 - 4
src/app/api/permission.py

@@ -1,9 +1,8 @@
-from flask import request, jsonify, g
+from flask import request, jsonify, g, current_app
 from flask_restx import Resource, Namespace, reqparse
 from flask_restx import Resource, Namespace, reqparse
 from sqlalchemy import select
 from sqlalchemy import select
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.defines import StatesCode
 from app.defines import StatesCode
 from app.modle.menus import Menus
 from app.modle.menus import Menus
 from app.modle.role import Role
 from app.modle.role import Role
@@ -22,7 +21,7 @@ class PermissionApi(Resource):
     def get(self):
     def get(self):
         """获取权限信息"""
         """获取权限信息"""
         data = []
         data = []
-        with Session(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).where(Menus.parent_id == 0)
             results = session.execute(stmt)
             results = session.execute(stmt)
             for result in results:
             for result in results:
@@ -54,7 +53,7 @@ class AuthPermissionApi(Resource):
         """权限认证"""
         """权限认证"""
         path = request.args.get('path')
         path = request.args.get('path')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             # todo role_id 写入token?
             # todo role_id 写入token?
             # 根据用户id获取角色id
             # 根据用户id获取角色id
             stmt = select(User.role).where(User.id == g.user_id)
             stmt = select(User.role).where(User.id == g.user_id)

+ 8 - 11
src/app/api/role.py

@@ -5,7 +5,6 @@ from flask_restx import Resource, Namespace, reqparse
 from sqlalchemy import select, insert, update, delete, func
 from sqlalchemy import select, insert, update, delete, func
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
 from app.modle.role import Role
 from app.modle.role import Role
 from app.modle.users import User
 from app.modle.users import User
@@ -32,7 +31,7 @@ class GetUserListApi(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))
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Role).offset(page_size * (page - 1)).limit(page_size)
             stmt = select(Role).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -64,7 +63,7 @@ class RoleApi(Resource):
         if role_id is None:
         if role_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="角色id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="角色id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(Role).where(Role.id == role_id)
             stmt = select(Role).where(Role.id == role_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -87,7 +86,7 @@ class RoleApi(Resource):
         if role_permission:
         if role_permission:
             role_permission = json.loads(role_permission)
             role_permission = json.loads(role_permission)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
 
 
             stmt = insert(Role).values(
             stmt = insert(Role).values(
                 role_name=role_name,
                 role_name=role_name,
@@ -117,7 +116,7 @@ class RoleApi(Resource):
         if role_permission:
         if role_permission:
             role_permission = json.loads(role_permission)
             role_permission = json.loads(role_permission)
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
 
 
             stmt = update(Role).where(Role.id == role_id).values(
             stmt = update(Role).where(Role.id == role_id).values(
                 role_name=role_name,
                 role_name=role_name,
@@ -141,7 +140,7 @@ class RoleApi(Resource):
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="角色名和角色id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="角色名和角色id不能为空")
 
 
         # 查询用户,用户的角色为当前角色,无法删除角色
         # 查询用户,用户的角色为当前角色,无法删除角色
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(func.count(User.role)).where(User.role == role_id)
             stmt = select(func.count(User.role)).where(User.role == role_id)
             results = session.execute(stmt).scalars().first()
             results = session.execute(stmt).scalars().first()
 
 
@@ -180,7 +179,7 @@ class RoleMemberApi(Resource):
         if role_id is None:
         if role_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='角色id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='角色id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User).where(User.role == role_id)
             stmt = select(User).where(User.role == role_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -197,7 +196,7 @@ class RoleMemberApi(Resource):
         if user_id is None:
         if user_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(User).where(User.id == user_id).values(role=None)
             stmt = update(User).where(User.id == user_id).values(role=None)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -222,7 +221,7 @@ class RoleMemberApi(Resource):
         for user_id in users_id:
         for user_id in users_id:
             values.append({"id": user_id, "role": None})
             values.append({"id": user_id, "role": None})
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             session.execute(
             session.execute(
                 update(User),
                 update(User),
                 values
                 values
@@ -232,5 +231,3 @@ class RoleMemberApi(Resource):
         save_log(request, Module.ROLE, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
         save_log(request, Module.ROLE, OperationType.BATCH_DELETE, StatesCode.SUCCESS)
 
 
         return jsonify(code=StatesCode.SUCCESS, message='批量移除成功')
         return jsonify(code=StatesCode.SUCCESS, message='批量移除成功')
-
-

+ 10 - 11
src/app/api/users.py

@@ -1,13 +1,12 @@
 import json
 import json
 from io import StringIO
 from io import StringIO
 
 
-from flask import request, jsonify, Response
+from flask import request, jsonify, Response, current_app
 from flask_restx import Resource, Namespace, reqparse
 from flask_restx import Resource, Namespace, reqparse
 from sqlalchemy import insert, select, update, delete
 from sqlalchemy import insert, select, update, delete
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
 from app.defines import StatesCode, Module, OperationType
 from app.defines import StatesCode, Module, OperationType
-from app.database import engine
 from app.modle.users import User
 from app.modle.users import User
 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
@@ -36,7 +35,7 @@ class GetUserListApi(Resource):
         if status is None:
         if status is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户状态不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户状态不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User).where(User.account_status == status).offset(page_size * (page - 1)).limit(page_size)
             stmt = select(User).where(User.account_status == status).offset(page_size * (page - 1)).limit(page_size)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -79,7 +78,7 @@ class UsersApi(Resource):
         if user_id is None:
         if user_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User).where(User.id == user_id)
             stmt = select(User).where(User.id == user_id)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -108,7 +107,7 @@ class UsersApi(Resource):
         if username is None or password is None:
         if username is None or password is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户名或密码不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户名或密码不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
 
 
             # 判断用户是否存在
             # 判断用户是否存在
             stmt = select(User).where(User.user_name == username)
             stmt = select(User).where(User.user_name == username)
@@ -162,7 +161,7 @@ class UsersApi(Resource):
         duty = request.form.get('duty')
         duty = request.form.get('duty')
         nationality = request.form.get('nationality')
         nationality = request.form.get('nationality')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(User).where(User.id == user_id).values(
             stmt = update(User).where(User.id == user_id).values(
                 user_name=username,
                 user_name=username,
                 password=User().generate_password(password),
                 password=User().generate_password(password),
@@ -194,7 +193,7 @@ class UsersApi(Resource):
         if user_id is None:
         if user_id is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = delete(User).where(User.id == user_id)
             stmt = delete(User).where(User.id == user_id)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -223,7 +222,7 @@ class GetUsersApi(Resource):
         if user_id is None or account_status is None:
         if user_id is None or account_status is None:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id或用户状态不能为空")
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message="用户id或用户状态不能为空")
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = update(User).where(User.id == user_id).values(account_status=account_status)
             stmt = update(User).where(User.id == user_id).values(account_status=account_status)
             session.execute(stmt)
             session.execute(stmt)
             session.commit()
             session.commit()
@@ -252,7 +251,7 @@ class BatchDeleteUserApi(Resource):
         else:
         else:
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户id不能为空')
             return jsonify(code=StatesCode.UNKNOWN_ERROR, message='用户id不能为空')
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User).where(User.id.in_(users_id))
             stmt = select(User).where(User.id.in_(users_id))
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 
@@ -292,7 +291,7 @@ class BatchModifyUsersStatusApi(Resource):
         for user_id in users_id:
         for user_id in users_id:
             values.append({"id": user_id, "account_status": account_status})
             values.append({"id": user_id, "account_status": account_status})
 
 
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             session.execute(
             session.execute(
                 update(User),
                 update(User),
                 values
                 values
@@ -312,7 +311,7 @@ class ExportDataApi(Resource):
     @ns.expect()
     @ns.expect()
     def get(self):
     def get(self):
         """导出用户数据"""
         """导出用户数据"""
-        with Session(engine) as session:
+        with Session(current_app.engine) as session:
             stmt = select(User)
             stmt = select(User)
             results = session.execute(stmt).scalars().all()
             results = session.execute(stmt).scalars().all()
 
 

+ 0 - 0
src/app/configs/__init__.py


+ 0 - 33
src/app/configs/config.py

@@ -1,33 +0,0 @@
-import json
-import os
-
-JWT_SECRET = str(os.environ.get('JWT_SECRET', 'SKYversation0816'))
-JWT_EXPIRY = int(os.environ.get('JWT_EXPIRY', 3600))
-
-MESSAGR_TYPE = json.loads(os.environ.get('MESSAGR_TYPE', '["普通消息","提醒消息"]'))
-
-# 公司商标存储地址
-COMPANY_LOGO_PATH = os.environ.get('COMPANY_LOGO_PATH', "/data/company_logo")
-COMPANY_LOGO_URL = os.environ.get('COMPANY_LOGO_URL', 'http://127.0.0.1/company_logo/')
-
-# 模版存储地址
-TEMPLATE_FILE_PATH = os.environ.get('TEMPLATE_FILE_PATH', '/data/template')
-TEMPLATE_FILE_URL = os.environ.get('TEMPLATE_FILE_URL', 'http://127.0.0.1/template/')
-
-# 公司图片存醋地址
-COMPANY_PICTURE_PATH = os.environ.get('COMPANY_PICTURE_PATH', '/data/company')
-COMPANY_PICTURE_URL = os.environ.get('COMPANY_PICTURE_URL', 'http://127.0.0.1/company/')
-
-# 楼宇图片存醋地址
-BUILDING_PICTURE_PATH = os.environ.get('BUILDING_PICTURE_PATH', '/data/building')
-BUILDING_PICTURE_URL = os.environ.get('BUILDING_PICTURE_URL', 'http://127.0.0.1/building/')
-
-# 底层系统信息图片存醋地址
-UNDERLYING_SYSTEM_PICTURE_PATH = os.environ.get('UNDERLYING_SYSTEM_PICTURE_PATH', '/data/underlying_system')
-UNDERLYING_SYSTEM_PICTURE_URL = os.environ.get('UNDERLYING_SYSTEM_PICTURE_URL', 'http://127.0.0.1/underlying_system/')
-
-for path in [COMPANY_LOGO_PATH, TEMPLATE_FILE_PATH, COMPANY_PICTURE_PATH, BUILDING_PICTURE_PATH,
-             UNDERLYING_SYSTEM_PICTURE_PATH]:
-
-    if not os.path.exists(path):
-        os.makedirs(path)

+ 0 - 10
src/app/database.py

@@ -1,10 +0,0 @@
-from sqlalchemy import create_engine
-
-user = 'mac'
-password = ''
-host = 'localhost'
-port = 5432
-database = 'postgres'
-uri = f'postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}'
-
-engine = create_engine(uri)

+ 5 - 4
src/app/utils/jwt_util.py

@@ -3,9 +3,10 @@ import time
 import jwt
 import jwt
 from flask import g, jsonify
 from flask import g, jsonify
 
 
-from app.configs.config import JWT_SECRET, JWT_EXPIRY
 from app.defines import StatesCode
 from app.defines import StatesCode
+from config import Config
 
 
+config = Config()
 headers = {
 headers = {
     "alg": "HS256",
     "alg": "HS256",
     "typ": "JWT"
     "typ": "JWT"
@@ -21,10 +22,10 @@ def generate_jwt(user_id, user_name):
     payload = {
     payload = {
         'user_id': user_id,
         'user_id': user_id,
         'user_name': user_name,
         'user_name': user_name,
-        'exp': int(time.time() + JWT_EXPIRY)
+        'exp': int(time.time() + config.common.JWT_EXPIRY)
     }
     }
 
 
-    token = jwt.encode(payload, JWT_SECRET, algorithm='HS256', headers=headers)
+    token = jwt.encode(payload, config.common.JWT_SECRET, algorithm='HS256', headers=headers)
     return token
     return token
 
 
 
 
@@ -36,7 +37,7 @@ def verify_jwt(token):
     """
     """
 
 
     try:
     try:
-        payload = jwt.decode(token, JWT_SECRET, algorithms=['HS256'], headers=headers)
+        payload = jwt.decode(token, config.common.JWT_SECRET, algorithms=['HS256'], headers=headers)
     except jwt.DecodeError:
     except jwt.DecodeError:
         payload = None
         payload = None
 
 

+ 2 - 3
src/app/utils/save_log.py

@@ -1,8 +1,7 @@
-from flask import g
+from flask import g, current_app
 from sqlalchemy import insert
 from sqlalchemy import insert
 from sqlalchemy.orm import Session
 from sqlalchemy.orm import Session
 
 
-from app.database import engine
 from app.modle.log import Log
 from app.modle.log import Log
 
 
 
 
@@ -14,7 +13,7 @@ def save_log(request, module, operation_type, operation_status):
     :param operation_status: 操作状态
     :param operation_status: 操作状态
     :return:
     :return:
     """
     """
-    with Session(engine) as session:
+    with Session(current_app.engine) as session:
         stmt = insert(Log).values(
         stmt = insert(Log).values(
             module=module,
             module=module,
             operation_type=operation_type,
             operation_type=operation_type,

+ 50 - 0
src/config.py

@@ -0,0 +1,50 @@
+import yaml
+
+
+class Object(dict):
+
+    def __init__(self):
+
+        super(Object, self).__init__()
+
+    def __getattr__(self, key):
+
+        return self.get(key)
+
+    def __setattr__(self, key, value):
+
+        if isinstance(value, dict):
+
+            o = Object()
+
+            o.set(value)
+
+            self[key] = o
+
+        else:
+
+            self[key] = value
+
+    def set(self, dictionary, clear=False):
+
+        if clear:
+            self.clear()
+
+        for key, value in dictionary.items():
+            self.__setattr__(key, value)
+
+
+class Config(Object):
+    _instance = None
+
+    def __new__(cls, *args, **kwargs):
+        if Config._instance is None:
+            Config._instance = super().__new__(cls)
+
+        return Config._instance
+
+    def load(self, filename):
+        with open(filename, 'r', encoding='utf8') as stream:
+            data = yaml.load(stream, Loader=yaml.FullLoader)
+
+            self.set(data)