فهرست منبع

数据管理(公司基本信息),数据管理表设计(公司基本信息、楼宇基本信息、底层系统信息)

zhangnaiwen 2 سال پیش
والد
کامیت
d9d1dcda75
7فایلهای تغییر یافته به همراه202 افزوده شده و 44 حذف شده
  1. BIN
      requirements.txt
  2. 137 16
      src/app/api/data.py
  3. 4 4
      src/app/configs/config.py
  4. 60 0
      src/app/modle/data.py
  5. 1 1
      src/app/modle/log.py
  6. 0 21
      src/app/modle/template.py
  7. 0 2
      src/app/modle/users.py

BIN
requirements.txt


+ 137 - 16
src/app/api/data.py

@@ -7,10 +7,10 @@ from sqlalchemy import select, insert, update, delete
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 
-from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL
+from app.configs.config import TEMPLATE_FILE_PATH, TEMPLATE_FILE_URL, COMPANY_PICTURE_PATH, COMPANY_PICTURE_URL
 from app.database import engine
 from app.defines import StatesCode, Module, OperationType
-from app.modle.template import Template
+from app.modle.data import Template, CompanyData
 from app.utils.jwt_util import login_required
 from app.utils.save_log import save_log
 from app.utils.util import to_dict, cn_now
@@ -66,14 +66,14 @@ class TemplateConfigListApi(Resource):
 template = reqparse.RequestParser(bundle_errors=True)
 template.add_argument(name='template_id', type=int, location='args', required=False, help='模版id')
 
-template_details = reqparse.RequestParser(bundle_errors=True)
-template_details.add_argument(name='template_id', type=int, location='form', required=False, help='模版id')
-template_details.add_argument(name='template_name', type=str, location='form', required=False, help='模版名称')
-template_details.add_argument(name='template_format', type=str, location='form', required=False, help='模版格式')
-template_details.add_argument(name='report_type', type=str, location='form', required=False, help='报告类型')
-template_details.add_argument(name='introduction', type=str, location='form', required=False, help='模版简介')
-template_details.add_argument(name='template_file', type=FileStorage, location='files', required=False, help='模版文件')
-template_details.add_argument(name='template_type', type=int, location='files', required=False,
+building_details = reqparse.RequestParser(bundle_errors=True)
+building_details.add_argument(name='template_id', type=int, location='form', required=False, help='模版id')
+building_details.add_argument(name='template_name', type=str, location='form', required=False, help='模版名称')
+building_details.add_argument(name='template_format', type=str, location='form', required=False, help='模版格式')
+building_details.add_argument(name='report_type', type=str, location='form', required=False, help='报告类型')
+building_details.add_argument(name='introduction', type=str, location='form', required=False, help='模版简介')
+building_details.add_argument(name='template_file', type=FileStorage, location='files', required=False, help='模版文件')
+building_details.add_argument(name='template_type', type=int, location='files', required=False,
                               help='模版类型 0:报表,1:报告')
 
 
@@ -99,7 +99,7 @@ class TemplateConfigApi(Resource):
         return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
 
     @ns.doc(id='add_template', description='添加报表模版')
-    @ns.expect(template_details)
+    @ns.expect(building_details)
     def post(self):
         """添加模版"""
         template_name = request.form.get('template_name')
@@ -130,7 +130,7 @@ class TemplateConfigApi(Resource):
             stmt = insert(Template).values(
                 name=template_name,
                 format=template_format,
-                Introduction=introduction,
+                introduction=introduction,
                 report_type=report_type,
                 creator=g.user_name,
                 create_time=cn_now(),
@@ -147,7 +147,7 @@ class TemplateConfigApi(Resource):
         return jsonify(code=StatesCode.SUCCESS, message='添加成功')
 
     @ns.doc(id='update_templatet', description='修改模版信息')
-    @ns.expect(template_details)
+    @ns.expect(building_details)
     def put(self):
         """修改模版"""
         template_id = request.form.get('template_id')
@@ -172,7 +172,7 @@ class TemplateConfigApi(Resource):
             stmt = update(Template).where(Template.id == template_id).values(
                 name=template_name,
                 format=template_format,
-                Introduction=introduction,
+                introduction=introduction,
                 report_type=report_type,
                 creator=g.user_name,
                 create_time=cn_now(),
@@ -188,7 +188,7 @@ class TemplateConfigApi(Resource):
         return jsonify(code=StatesCode.SUCCESS, message='修改成功')
 
     @ns.doc(id='delete_template', description='删除模版')
-    @ns.expect(template_details)
+    @ns.expect(building_details)
     def delete(self):
         """删除模版"""
         template_id = request.form.get('template_id')
@@ -238,17 +238,138 @@ class BatchTemplateConfigApi(Resource):
         return jsonify(code=StatesCode.SUCCESS, message='批量删除成功')
 
 
+company_id = reqparse.RequestParser(bundle_errors=True)
+company_id.add_argument(name='company_id', type=int, location='args', required=False, help='公司id')
+
+company_data = reqparse.RequestParser(bundle_errors=True)
+company_data.add_argument(name='company_id', type=int, location='form', required=False, help='公司id')
+company_data.add_argument(name='management_unit', type=str, location='form', required=False, help='管理单位')
+company_data.add_argument(name='custodian_unit', type=str, location='form', required=False, help='托管单位')
+company_data.add_argument(name='introduction', type=str, location='form', required=False, help='楼宇简介')
+company_data.add_argument(name='contact_person', type=str, location='form', required=False, help='联系人')
+company_data.add_argument(name='contact_information', type=str, location='form', required=False, help='联系人方式')
+company_data.add_argument(name='picture', type=FileStorage, location='files', required=False, help='公司图片')
+
+
 @ns.route('/company')
 class CompanyApi(Resource):
+
+    @ns.doc(id='get_company', description='获取公司信息')
+    @ns.expect(batch_delete_template)
     def get(self):
         """获取公司基本信息"""
-        return jsonify(code=StatesCode.SUCCESS, message='获取成功', data='')
+        company_id = request.args.get('company_id')
+
+        if company_id is None:
+            return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
+
+        with Session(engine) as session:
+            stmt = select(CompanyData).where(CompanyData.id == company_id)
+            results = session.execute(stmt).scalars().all()
+
+        save_log(request, Module.DATA, OperationType.INQUIRE, StatesCode.SUCCESS)
+
+        return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=to_dict(results))
+
+    @ns.doc(id='add_company', description='添加公司信息')
+    @ns.expect(company_data)
+    def post(self):
+        """添加公司基本信息"""
+        management_unit = request.form.get('management_unit')
+        custodian_unit = request.form.get('custodian_unit')
+        introduction = request.form.get('introduction')
+        contact_person = request.form.get('contact_person')
+        contact_information = request.form.get('contact_information')
+        picture = request.files.get('picture')
+
+        if management_unit is None:
+            return jsonify(code=StatesCode.UNKNOWN_ERROR, message='管理单位不能为空')
+
+        # 存储(url),
+        if picture:
+            picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
+            picture_url = COMPANY_PICTURE_URL + picture.filename
+        else:
+            picture_url = None
+
+        with Session(engine) as session:
+            # 判断是否存在
+            stmt = select(CompanyData).where(CompanyData.management_unit == management_unit)
+            result = session.execute(stmt).scalars().first()
+            if result:
+                return jsonify(code=StatesCode.UNKNOWN_ERROR, message="管理单位已存在")
 
+            # 添加
+            stmt = insert(CompanyData).values(
+                management_unit=management_unit,
+                custodian_unit=custodian_unit,
+                introduction=introduction,
+                contact_person=contact_person,
+                contact_information=contact_information,
+                picture=picture_url,
+            )
+            session.execute(stmt)
+
+            session.commit()
+
+        save_log(request, Module.DATA, OperationType.ADD, StatesCode.SUCCESS)
+
+        return jsonify(code=StatesCode.SUCCESS, message='新增成功', data='')
+
+    @ns.doc(id='update_company', description='修改公司信息')
+    @ns.expect(company_data)
     def put(self):
         """修改公司基本信息"""
+
+        company_id = request.form.get('company_id')
+        management_unit = request.form.get('management_unit')
+        custodian_unit = request.form.get('custodian_unit')
+        introduction = request.form.get('introduction')
+        contact_person = request.form.get('contact_person')
+        contact_information = request.form.get('contact_information')
+        picture = request.files.get('picture')
+
+        if company_id is None:
+            return jsonify(code=StatesCode.UNKNOWN_ERROR, message='公司id不能为空')
+
+        # 存储(url),
+        if picture:
+            picture.save(os.path.join(COMPANY_PICTURE_PATH, picture.filename))
+            picture_url = COMPANY_PICTURE_URL + picture.filename
+        else:
+            picture_url = None
+
+        with Session(engine) as session:
+            stmt = update(CompanyData).where(CompanyData.id == company_id).values(
+                management_unit=management_unit,
+                custodian_unit=custodian_unit,
+                introduction=introduction,
+                contact_person=contact_person,
+                contact_information=contact_information,
+                picture=picture_url,
+            )
+
+            session.execute(stmt)
+            session.commit()
+
+        save_log(request, Module.DATA, OperationType.UPDATE, StatesCode.SUCCESS)
+
         return jsonify(code=StatesCode.SUCCESS, message='修改成功', data='')
 
 
+building_details = reqparse.RequestParser(bundle_errors=True)
+building_details.add_argument(name='id', type=int, location='form', required=False, help='公司id')
+building_details.add_argument(name='name', type=str, location='form', required=False, help='楼宇名')
+building_details.add_argument(name='area', type=str, location='form', required=False, help='楼宇面积')
+building_details.add_argument(name='floor', type=str, location='form', required=False, help='建筑楼层')
+building_details.add_argument(name='trem', type=str, location='form', required=False, help='建筑年限')
+building_details.add_argument(name='date', type=int, location='form', required=False, help='建成日期')
+building_details.add_argument(name='contact_person', type=int, location='form', required=False, help='联系人')
+building_details.add_argument(name='contact_information', type=int, location='form', required=False, help='联系人方式')
+building_details.add_argument(name='introduction', type=int, location='form', required=False, help='楼宇简介')
+building_details.add_argument(name='picture', type=FileStorage, location='files', required=False, help='楼宇图片')
+
+
 @ns.route('/building_list')
 class BuildingListApi(Resource):
     def get(self):

+ 4 - 4
src/app/configs/config.py

@@ -5,10 +5,10 @@ JWT_EXPIRY = 3600
 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/'

+ 60 - 0
src/app/modle/data.py

@@ -0,0 +1,60 @@
+from sqlalchemy import String, Column, Integer, Float
+
+from app.modle import Base
+
+
+class Template(Base):
+    """模版表"""
+
+    __tablename__ = 'template'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    name = Column(String, nullable=False, unique=False, index=False, doc='模版名称')
+    format = Column(String, nullable=True, unique=False, index=False, doc='模版格式')
+    report_type = Column(String, nullable=True, unique=False, index=False, doc='报告类型')
+    introduction = Column(String, nullable=True, unique=False, index=False, doc='模版简介')
+    creator = Column(String, nullable=True, unique=False, index=False, doc='创建者')
+    create_time = Column(String, nullable=True, unique=False, index=False, doc='创建时间')
+    update_time = Column(String, nullable=True, unique=False, index=False, doc='修改时间')
+    template_url = Column(String, nullable=True, unique=False, index=False, doc='模版存储地址')
+    template_type = Column(String, nullable=True, unique=False, index=False, doc='模版类型')
+
+
+class CompanyData(Base):
+    """公司基本信息"""
+
+    __tablename__ = 'company_data'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    management_unit = Column(String, nullable=True, unique=False, index=False, doc='管理单位')
+    custodian_unit = Column(String, nullable=True, unique=False, index=False, doc='托管单位')
+    introduction = Column(String, nullable=True, unique=False, index=False, doc='公司简介')
+    contact_person = Column(String, nullable=True, unique=False, index=False, doc='联系人')
+    contact_information = Column(Integer, nullable=True, unique=False, index=False, doc='联系人方式')
+    picture = Column(String, nullable=True, unique=False, index=False, doc='公司图片url')
+
+
+class Building(Base):
+    """楼宇基本信息"""
+
+    __tablename__ = 'building'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    name = Column(String, nullable=True, unique=False, index=False, doc='楼宇名')
+    area = Column(Float, nullable=True, unique=False, index=False, doc='楼宇面积')
+    floor = Column(String, nullable=True, unique=False, index=False, doc='建筑楼层')
+    trem = Column(String, nullable=True, unique=False, index=False, doc='建筑年限')
+    date = Column(String, nullable=True, unique=False, index=False, doc='建成日期')
+    contact_person = Column(String, nullable=True, unique=False, index=False, doc='联系人')
+    contact_information = Column(Integer, nullable=True, unique=False, index=False, doc='联系人方式')
+    introduction = Column(String, nullable=True, unique=False, index=False, doc='楼宇简介')
+    picture = Column(String, nullable=True, unique=False, index=False, doc='楼宇图片url')
+
+
+class UnderlyingSystem(Base):
+    """底层系统信息"""
+
+    __tablename__ = 'underlying_system'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
+    picture = Column(String, nullable=True, unique=False, index=False, doc='图片url')

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

@@ -1,4 +1,4 @@
-from sqlalchemy import String, Column, Integer, DateTime
+from sqlalchemy import String, Column, Integer
 
 from app.modle import Base
 from app.utils.util import cn_now

+ 0 - 21
src/app/modle/template.py

@@ -1,21 +0,0 @@
-from sqlalchemy import String, Column, Integer
-
-from app.modle import Base
-from app.utils.util import cn_now
-
-
-class Template(Base):
-    """模版表"""
-
-    __tablename__ = 'template'
-
-    id = Column(Integer, primary_key=True, autoincrement=True, nullable=False, unique=True, doc='id')
-    name = Column(String, nullable=False, unique=False, index=False, doc='模版名称')
-    format = Column(String, nullable=True, unique=False, index=False, doc='模版格式')
-    report_type = Column(String, nullable=True, unique=False, index=False, doc='报告类型')
-    Introduction = Column(String, nullable=True, unique=False, index=False, doc='模版简介')
-    creator = Column(String, nullable=True, unique=False, index=False, doc='创建者')
-    create_time = Column(String, nullable=True, unique=False, index=False, doc='创建时间')
-    update_time = Column(String, nullable=True, unique=False, index=False, doc='修改时间')
-    template_url = Column(String, nullable=True, unique=False, index=False, doc='模版存储地址')
-    template_type = Column(String, nullable=True, unique=False, index=False, doc='模版类型')

+ 0 - 2
src/app/modle/users.py

@@ -1,5 +1,3 @@
-from datetime import datetime
-
 from sqlalchemy import String, Column, Integer
 from werkzeug.security import check_password_hash, generate_password_hash