libushang 8 ماه پیش
والد
کامیت
fde905118d
6فایلهای تغییر یافته به همراه154 افزوده شده و 4 حذف شده
  1. 23 2
      common/YzyApi.py
  2. 6 1
      main.py
  3. 25 0
      models/yjya_base.py
  4. 4 0
      routers/api/emergencyPlans/__init__.py
  5. 48 0
      routers/api/emergencyPlans/event.py
  6. 48 1
      routers/api/eventManagement/event.py

+ 23 - 2
common/YzyApi.py

@@ -11,7 +11,7 @@ import requests
 from exceptions import YzyException
 
 # 应用名称:茂名市智慧应急平台
-# https://open.weixin.qq.com/connect/Oauth2/authorize?appid=wld341060039&redirect_uri=http://19.155.220.206/#/&response_type=code&scope=snsapi_base&agentid=1004302&state=xxxxxx#wechat_redirect
+# https://open.weixin.qq.com/connect/Oauth2/authorize?appid=wld341060039&redirect_uri=https://www.baidu.com/#/&response_type=code&scope=snsapi_base&agentid=1004302&state=xxxxxx#wechat_redirect
 
 YZY_HOST = "http://19.15.0.128:8080"
 # YZY_HOST = "https://xtbg.digitalgd.com.cn"
@@ -26,7 +26,8 @@ YZH_PASSID = "yzy_demo"
 YZH_PASSTOKEN = "WjKat55cv6PrJtpCHld0trrHsv1mbCqL"
 
 def __get_access_token():
-    url = "{}/ebus/yzyapi/cgi-bin/gettoken?corpid={}&corpsecret={}".format(YZY_HOST, YZY_CORPID, YZY_CORPSECRET) 
+    url = "{}/ebus/yzyapi/cgi-bin/gettoken?corpid={}&corpsecret={}".format(YZY_HOST, YZY_CORPID, YZY_CORPSECRET)
+    print('yzy url:', url)
 
     timestamp = str(int(time.time()))
     nonce = ranstr(20)
@@ -57,6 +58,26 @@ def get_cache_access_token():
     
     return access_token
 
+def get_user_info(code: str):
+    access_token = get_cache_access_token()
+    url = "{}/ebus/yzyapi/cgi-bin/user/getuserinfo?access_token={}&code={}".format(YZY_HOST, access_token, code)
+    return __post_url__(url, {})
+
+def send_text_message(users, content: str):
+    access_token = get_cache_access_token()
+    url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(YZY_HOST, access_token)
+    
+    data = {
+        "touser": "|".join(users),
+        "msgtype" : "text",
+        "agentid" : YZY_AGENTID,
+        "text": {
+            "content": content
+        }
+    }
+
+    return __post_url__(url, data)
+
 def send_textcard_message(users, title: str, description: str, detail_url: str):
     access_token = get_cache_access_token()
     url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(YZY_HOST, access_token)

+ 6 - 1
main.py

@@ -72,7 +72,12 @@ async def exception_handler(request: Request, exc: AlertException):
     
 if __name__ == '__main__':
     from common import YzyApi
-    YzyApi.send_textcard_message(["c3o4t44nb2e1oipbs80paw"], "title", "事件进度", "https://www.baidu.com/")
+    # YzyApi.get_user_info("h4RxABdc-pfXIdhTT3UhTnKv-qTs-Yn6TfeSWE4IJd0")
+    # YzyApi.send_textcard_message(["c3o4t44nb2e1oipbs80paw"], "title", "事件进度", "https://www.baidu.com/")
+    # YzyApi.send_textcard_message(["ivj823s4b56za2jcu293f7"], "title", "事件进度", "https://www.baidu.com/")
+    # YzyApi.send_textcard_message(["ivj823s4b56za2jcu293f7"], "title", "事件进度", "https://www.baidu.com/")
+    YzyApi.send_textcard_message(["eb4kehgy6wj4qn0jhx1dk6"], "title", "事件进度", "https://www.baidu.com/")
+    YzyApi.send_text_message(["eb4kehgy6wj4qn0jhx1dk6"], "事件进度")
 
     import uvicorn
     sys = platform.system()

+ 25 - 0
models/yjya_base.py

@@ -59,6 +59,9 @@ class EmergencyFile(Base):
 
     # 关联到 EmergencyPlan 实例
 
+    class Config:
+        orm_mode = True
+
 
 class EmergencyDrill(Base):
     __tablename__ = 'emergency_drills'
@@ -81,6 +84,9 @@ class EmergencyDrill(Base):
     create_by = Column(BigInteger, default=None, comment='创建者')
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
 
+    class Config:
+        orm_mode = True
+
 
 class EmergencyTrainingSession(Base):
     __tablename__ = 'emergency_training_sessions'
@@ -104,6 +110,9 @@ class EmergencyTrainingSession(Base):
     create_by = Column(BigInteger, default=None, comment='创建者')
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
 
+    class Config:
+        orm_mode = True
+
 
 class EmergencyResponse(Base):
     __tablename__ = 'emergency_responses'
@@ -123,3 +132,19 @@ class EmergencyResponse(Base):
     create_dept = Column(BigInteger, default=None, comment='创建部门')
     create_by = Column(BigInteger, default=None, comment='创建者')
     del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+
+    class Config:
+        orm_mode = True
+
+class EmergencyUnit(Base):
+    __tablename__ = 'emergency_unit'
+
+    id = Column(Integer, autoincrement=True, primary_key=True)
+    plan_id = Column(String(50), nullable=False,comment='预案id')
+    dept_id = Column(Integer, nullable=False,comment='部门id')
+    dept_name = Column(String(100), nullable=False,comment='部门名称')
+    content = Column(String(255), nullable=False,comment='单位职责')
+    dept_order = Column(Integer, comment='排序')
+
+    class Config:
+        orm_mode = True

+ 4 - 0
routers/api/emergencyPlans/__init__.py

@@ -15,8 +15,12 @@ from utils import *
 import json
 import traceback
 
+from . import event
+
 router = APIRouter()
 
+router.include_router(event.router, prefix="/event", tags=["事件相关"])
+
 class File(BaseModel):
     status :str
     name : str

+ 48 - 0
routers/api/emergencyPlans/event.py

@@ -0,0 +1,48 @@
+from fastapi import APIRouter, Request, Depends, HTTPException, Query
+from sqlalchemy.exc import IntegrityError
+from fastapi.responses import HTMLResponse, FileResponse
+from fastapi.responses import JSONResponse
+from database import get_db
+from sqlalchemy import text, exists, and_, or_, not_
+from sqlalchemy.orm import Session
+from models import *
+import json
+import random
+from sqlalchemy import create_engine, select
+from typing import Optional
+from utils.StripTagsHTMLParser import *
+from common.db import db_event_management, db_user, db_area, db_emergency_plan
+from common.security import valid_access_token
+import traceback
+from utils import *
+from datetime import datetime, timedelta
+
+router = APIRouter()
+
+# 列出预案单位职责
+@router.post('/unit_list')
+async def unit_list(
+    request: Request, 
+    db: Session = Depends(get_db), 
+    body = Depends(remove_xss_json), 
+    user_id = Depends(valid_access_token)
+):
+    plan_id = body['plan_id']
+
+    rows = db.query(EmergencyUnit).filter(EmergencyUnit.plan_id == plan_id).order_by(EmergencyUnit.dept_order.asc()).all()
+    data = [
+        {
+            "id": row.id,
+            "dept_id": row.dept_id,
+            "dept_name": row.dept_name,
+            "content": row.content
+        }
+        for row in rows
+    ]
+
+    # 返回结果
+    return {
+        "code": 200,
+        "msg": "查询成功",
+        "data": data
+    }

+ 48 - 1
routers/api/eventManagement/event.py

@@ -489,4 +489,51 @@ async def list_registered(
     return {
         "code": 200,
         "msg": "登记事发地点成功"
-    }
+    }
+
+# 启动预案
+@router.post("/lauch_emergency_plan")
+async def lauch_emergency_plan(
+    request: Request,  
+    body = Depends(remove_xss_json), 
+    db: Session = Depends(get_db)
+):
+    eventId = body['eventId']
+    event_row = db.query(EventBase).filter(EventBase.event_code == eventId).first()
+    if event_row is None:
+        return {
+            "code": 500,
+            "msg": "事件编号不存在"
+        }
+    
+    event_type = event_row.event_type
+    
+    # 事件类型和预案类型匹配
+    if event_type == "1":
+        pass
+    else:
+        pass
+
+    plan_type = "1"
+
+    if plan_type == '':
+        return {
+            "code": 500,
+            "msg": "没有匹配的预案"
+        }
+    
+    plan_row = db.query(EmergencyPlan).filter(EmergencyPlan.plan_type == plan_type).first()
+    if plan_row is None:
+        return {
+            "code": 500,
+            "msg": "预案不存在"
+        }
+    
+    # 绑定预案ID
+    event_row.plan_id = plan_row.id
+    db.commit()
+    
+    return {
+        "code": 200,
+        "msg": "启动预案成功"
+    }