浏览代码

Merge branch 'master' of https://gogs.tjp.com.cn/maoming/python-fastapi-mm-zhcs-yj-api

baoyubo 1 月之前
父节点
当前提交
2b36e704da

+ 51 - 1
models/duty_base.py

@@ -86,4 +86,54 @@ class DutyFile(Base):
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
 
     class Config:
-        orm_mode = True
+        orm_mode = True
+
+
+class EmergencyContactDepartment(Base):
+    __tablename__ = 'tp_emergency_contact_department'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
+    parent_department_id = Column(Integer, comment='父部门id')
+    department_name = Column(String(255), nullable=False, comment='部门名称')
+    regionPath = Column(Text, comment='部门路径')
+    yzy_unitid = Column(String(100), comment='粤政易机构节点 ID')
+    yzy_regionPath = Column(Text, comment='粤政易部门路径')
+    display_order = Column(Integer, comment='显示排序')
+    del_flag = Column(CHAR(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
+    update_by = Column(BigInteger, default=None, comment='更新者')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
+
+
+class EmergencyContactUser(Base):
+    __tablename__ = 'tp_emergency_contact_user'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
+    name = Column(String(255), nullable=False, comment='姓名')
+    position = Column(String(255), comment='职务')
+    mobile_phone = Column(String(20), comment='手机号')
+    office_phone = Column(String(20), comment='办公电话')
+    department_id = Column(String(255), comment='所属部门')
+    display_order = Column(Integer, comment='显示排序')
+    yzy_unitid = Column(String(100), comment='粤政易机构节点 ID')
+    userid = Column(String(32), comment='粤政易用户 ID')
+    del_flag = Column(CHAR(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
+    update_by = Column(BigInteger, default=None, comment='更新者')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
+
+
+class DutyPosition(Base):
+    __tablename__ = 'duty_position'
+
+    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键')
+    sort_number = Column(Integer, comment='排序编号')
+    position_name = Column(String(255), nullable=False, comment='岗位名称')
+    type = Column(String(100), comment='类型')
+    del_flag = Column(CHAR(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+    create_by = Column(BigInteger, default=None, comment='创建者')
+    create_time = Column(DateTime, default=datetime.now, comment='创建时间')
+    update_by = Column(BigInteger, default=None, comment='更新者')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')

+ 3 - 1
routers/api/dutyManagement/__init__.py

@@ -1,6 +1,8 @@
 from fastapi import APIRouter
 from . import duty
+from . import contact
 
 router = APIRouter()
 
-router.include_router(duty.router, prefix="/duty")
+router.include_router(duty.router, prefix="/duty")
+router.include_router(contact.router, prefix="/contact")

+ 413 - 0
routers/api/dutyManagement/contact.py

@@ -0,0 +1,413 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+from fastapi import APIRouter, Request, Depends, Query, HTTPException, status
+from common.security import valid_access_token
+from fastapi.responses import JSONResponse
+from sqlalchemy.orm import Session
+from sqlalchemy import and_, or_
+from sqlalchemy.sql import func
+from common.auth_user import *
+from pydantic import BaseModel
+from database import get_db
+from typing import List
+from models import *
+from utils import *
+from utils.ry_system_util import *
+from utils.video_util import *
+import traceback
+import json
+
+router = APIRouter()
+
+
+def parent_id_get_contact_dept_list(db,parent_id):
+    query = db.query(EmergencyContactDepartment)
+    query = query.filter(EmergencyContactDepartment.del_flag != '2')
+    query = query.filter(EmergencyContactDepartment.parent_department_id == parent_id)
+    return query.all()
+def id_get_contact_dept_info(db,id):
+    query = db.query(EmergencyContactDepartment)
+    query = query.filter(EmergencyContactDepartment.del_flag != '2')
+    query = query.filter(EmergencyContactDepartment.id == id)
+    return query.first()
+
+@router.get('/department/data')
+async def get_dict_data_by_type(
+    db: Session = Depends(get_db),
+    user_id = Depends(valid_access_token)
+):
+
+    try:
+
+        data = parent_id_get_contact_dept_list(db,0)
+
+        def build_dept_tree(depts, parent_dept):
+            dept_tree = []  # 初始化一个列表来存储菜单树结构
+            for dept in depts:
+
+                dept_data = {
+                    "id": dept.id,
+                    "isShowSelect": False,
+                    "label": dept.department_name,
+                    "regionPath": dept.regionPath,
+                    "yzy_unitid": dept.yzy_unitid,
+                }
+                children_depts =  parent_id_get_contact_dept_list(db,dept.parent_department_id)
+                if len(children_depts) > 0:
+                    dept_data['children'] = build_dept_tree(children_depts, dept)
+                    dept_data['dept_data'] = True
+                dept_tree.append(dept_data)  # 将当前菜单数据添加到菜单树列表
+            return dept_tree
+
+        routers = build_dept_tree(data, None)
+
+        # 构建返回结果
+        result = {
+            "data": routers,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+@router.post('/department/create')
+async def create_dict_data(
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 创建一个新的 SysDictData 实例
+        new_dict_data = EmergencyContactDepartment(
+            parent_department_id=body['parent_department_id'],
+            department_name=body['department_name'],
+            regionPath=body['regionPath'],
+            yzy_unitid=body['yzy_unitid'],
+            yzy_regionPath=body['yzy_regionPath'],
+            display_order=body['display_order'],
+            create_by=user_id
+        )
+
+        # 添加到会话并提交
+        db.add(new_dict_data)
+        db.commit()
+        db.refresh(new_dict_data)  # 可选,如果需要刷新实例状态
+
+        # 构建返回结果
+        result = {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None
+        }
+        return result
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+@router.delete("/department/delete/{id}")  # 使用 ID 来标识要删除的接口
+async def delete_dict_data(
+    id: str,
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 从数据库中获取要删除的 OneShareApiEntity 实例
+        query = db.query(EmergencyContactDepartment)
+        query = query.filter(EmergencyContactDepartment.id == id)
+        query = query.filter(EmergencyContactDepartment.del_flag != '2')
+        dept_data = query.first()
+        # dict_data = db.query(SysDictData).filter(SysDictData.dict_code == dictCode and SysDictData.del_flag != '2').first()
+
+        if not dept_data:
+            return JSONResponse(status_code=404, content={
+                'code': 404,
+                'msg': 'dept不存在'
+            })
+        dept_data.del_flag = '2'
+        # 删除实例
+        # db.delete(api)
+        db.commit()
+
+        # 构建并返回响应
+        return {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None
+        }
+    except Exception as e:
+
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
+
+
+
+@router.get('/user/list')
+async def get_dict_data_by_type(
+    dept_parent_id:int =Query(None),
+    page: int = Query(1, gt=0),
+    pageSize: int = Query(10, gt=0),
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 根据 dict_type 查询字典数据
+        # dict_data = db.query(SysDictData).filter_by(dict_type=dictType).all()
+        query = db.query(EmergencyContactUser)
+
+        query = query.filter(EmergencyContactUser.del_flag != '2')
+        # 添加查询条件
+        if dept_parent_id:
+            query = query.filter(EmergencyContactUser.department_id==dept_parent_id)
+
+        # 计算总记录数
+        total_count = query.count()
+
+        # 计算分页
+        offset = (page - 1) * pageSize
+        user_data = query.offset(offset).limit(pageSize).all()
+
+        # 转换为字典
+        data_list = []
+        for d in user_data:
+            department = id_get_contact_dept_info(db,d.department_id)
+            if department is None:
+                department=''
+                continue
+            data_list.append({
+                "id": d.id,
+                "name": d.name,
+                "position":d.position,
+                "mobile_phone": d.mobile_phone,
+                "office_phone":d.office_phone,
+                "department_id":d.department_id,
+                "department":department,
+                "display_order":d.display_order,
+                "yzy_unitid":d.yzy_unitid,
+                "userid": d.userid,
+                "createTime": d.create_time.strftime('%Y-%m-%d %H:%M:%S') if d.create_time else ''
+            })
+        # 构建返回结果
+        result = {
+            "total": total_count,
+            "page": page,
+            "pageSize": pageSize,
+            "totalPages": (total_count + pageSize - 1) // pageSize,
+            "data": data_list,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
+@router.get('/user/info/{id}')
+async def get_dict_data_by_type(
+    id: str ,
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 根据 dict_type 查询字典数据
+        # dict_data = dict_type_get_dict_data_info(db,'three_proofing')
+        query = db.query(EmergencyContactUser)
+
+        # 添加查询条件
+        # if dictType:
+        query = query.filter(EmergencyContactUser.id==id)
+        query = query.filter(EmergencyContactUser.del_flag != '2')
+
+
+        d = query.first()
+        department = id_get_contact_dept_info(db, d.department_id)
+        if department is None:
+            department = ''
+            return JSONResponse(status_code=404, content={
+                'code': 404,
+                'msg': '用户部门未查到'
+            })
+        data_list = {
+            "id": d.id,
+            "name": d.name,
+            "position": d.position,
+            "mobile_phone": d.mobile_phone,
+            "office_phone": d.office_phone,
+            "department_id": d.department_id,
+            "department": department,
+            "display_order": d.display_order,
+            "yzy_unitid": d.yzy_unitid,
+            "userid": d.userid,
+            "createTime": d.create_time.strftime('%Y-%m-%d %H:%M:%S') if d.create_time else ''
+        }
+        # 构建返回结果
+        result = {
+            "data": data_list,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
+
+@router.post('/user/create')
+async def create_dict_data(
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 创建一个新的 SysDictData 实例
+        new_user_data = EmergencyContactUser(
+            name=body['name'],
+            position=body['position'],
+            mobile_phone=body['mobile_phone'],
+            office_phone=body['office_phone'],
+            department_id=body['department_id'],
+            display_order=body['display_order'],
+            yzy_unitid=body['yzy_unitid'],
+            userid=body['userid'],
+            create_by=user_id
+        )
+
+        # 添加到会话并提交
+        db.add(new_user_data)
+        db.commit()
+
+        # 构建返回结果
+        result = {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None
+        }
+        return result
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
+@router.put("/user/update")
+async def updata_dict_type(
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 从请求数据创建一个新的 SysDictType 实例
+        query = db.query(EmergencyContactUser)
+        query = query.filter(EmergencyContactUser.id == body['id'])
+        query = query.filter(EmergencyContactUser.del_flag != '2')
+
+        # query = db.query(SysDictData).filter(SysDictData.dict_code == form_data.dictCode)
+        # query = db.query(SysDictData).filter(SysDictData.del_flag != '2')
+
+        user_data = query.first()
+        if not user_data:
+            return JSONResponse(status_code=404, content={
+                'errcode': 404,
+                'errmsg': 'user不存在'
+            })
+        user_data.name=body['name']
+        user_data.position = body['position']
+        user_data.mobile_phone = body['mobile_phone']
+        user_data.position = body['position']
+        user_data.department_id = body['department_id']
+        user_data.display_order = body['display_order']
+        user_data.yzy_unitid = body['yzy_unitid']
+        user_data.userid = body['userid']
+        user_data.update_by = user_id
+        # 添加到数据库会话并提交
+        db.commit()
+        # db.refresh(new_dict_type)  # 可选,如果需要刷新实例状态
+
+        # 构建并返回响应
+        return {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None  # 根据你的响应示例,data 为 null
+        }
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
+
+
+@router.delete("/user/delete/{id}")  # 使用 ID 来标识要删除的接口
+async def delete_dict_data(
+    id: str,
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 从数据库中获取要删除的 OneShareApiEntity 实例
+        query = db.query(EmergencyContactUser)
+        query = query.filter(EmergencyContactUser.id == id)
+        query = query.filter(EmergencyContactUser.del_flag != '2')
+        user_data = query.first()
+        # dict_data = db.query(SysDictData).filter(SysDictData.dict_code == dictCode and SysDictData.del_flag != '2').first()
+
+        if not user_data:
+            return JSONResponse(status_code=404, content={
+                'errcode': 404,
+                'errmsg': 'type不存在'
+            })
+        user_data.del_flag = '2'
+        # 删除实例
+        # db.delete(api)
+        db.commit()
+
+        # 构建并返回响应
+        return {
+            "code": 200,
+            "msg": "操作成功",
+            "data": None
+        }
+    except Exception as e:
+
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })

+ 4 - 4
routers/api/resourceProvison/emergency/__init__.py

@@ -156,7 +156,7 @@ def get_projects(page: int = Query(default=1, gt=0),
     return result
 
 #查询详情
-@router.get("/projects/{project_id}/")
+@router.get("/projects/{project_id}")
 def get_project_by_id(project_id: int, db: Session = Depends(get_db), user_id=Depends(valid_access_token)):
     # 添加条件过滤 is_delete 为 0 的项目
     project = db.query(WaterResourceProject).filter(WaterResourceProject.is_delete == 0, WaterResourceProject.id == project_id).first()
@@ -286,7 +286,7 @@ def get_rescue_personnel(
 
 
 #查询详情
-@router.get("/rescue_personnel/{personnel_id}/")
+@router.get("/rescue_personnel/{personnel_id}")
 def get_rescue_personnel_by_id(personnel_id: int, db: Session = Depends(get_db)):
     # unit = db.query(Unit).filter_by(id=unit_id, is_delete=0).first()
     personnel = db.query(RescuePersonnel).filter_by(id = personnel_id, is_delete = 0).first()
@@ -457,7 +457,7 @@ def get_rescue_stations(page: int = Query(default=1, gt=0),
 
     return result
 
-@router.get("/rescue_stations/{station_id}/")
+@router.get("/rescue_stations/{station_id}")
 def get_rescue_station_by_id(station_id: int, db: Session = Depends(get_db)):
     station = db.query(RescueStation).filter_by(id=station_id, is_delete=0).first()
 
@@ -615,7 +615,7 @@ def get_defense_projects(page: int = Query(default=1, gt=0),
     return result
 
 # 查询详情
-@router.get("/defense_projects/{project_id}/")
+@router.get("/defense_projects/{project_id}")
 def get_defense_project_by_id(project_id: int, db: Session = Depends(get_db)):
     # project = db.query(DefenseProject).filter_by(id=project_id, is_delete=0).first()
     project = db.query(DefenseProject).filter_by(id=project_id, is_delete=0).first()