Browse Source

no message

libushang 4 months ago
parent
commit
2011138810
2 changed files with 56 additions and 13 deletions
  1. 8 4
      common/db/db_msg_center.py
  2. 48 9
      utils/riskManagement_uitl.py

+ 8 - 4
common/db/db_msg_center.py

@@ -20,11 +20,15 @@ def add_msg(db: Session, msg_type: str, msg_id: str , user_id: int) -> None:
 def get_unread_msg_count(db: Session, user_id: int, msg_type_list: dict) -> dict:
     data = []
     for msg_type in msg_type_list:
-        where = and_(MsgCenter.msg_type == msg_type.strip(), MsgCenter.recv_userid == user_id, MsgCenter.recv_status == 0)
+        where = and_(MsgCenter.msg_type == msg_type.strip())
         logger.info(msg_type)
-        if msg_type == '消息中心':
-            where = and_(MsgCenter.recv_userid == user_id, MsgCenter.recv_status == 0)
-        c1 = db.query(MsgCenter).filter(where).count()
+        
+        if msg_type == '巡查工作':
+            where = and_(MsgCenter.msg_type == '隐患巡查')
+        elif msg_type == '数据管理':
+            where = and_(MsgCenter.msg_type == '数据采集')
+
+        c1 = db.query(MsgCenter).filter(where).filter(and_(MsgCenter.recv_userid == user_id, MsgCenter.recv_status == 0)).count()
         data.append({"name" : msg_type, "num": c1})
     logger.info(data)
     return data

+ 48 - 9
utils/riskManagement_uitl.py

@@ -3,7 +3,7 @@ from utils import *
 from sqlalchemy import and_, or_
 from datetime import datetime, timedelta
 from dateutil.relativedelta import relativedelta
-from common.db import db_user, db_yzy, db_msg_center
+from common.db import db_user, db_yzy, db_msg_center, db_dict
 from common import YzyApi
 from config import settings
 
@@ -191,12 +191,12 @@ def create_children_task(db,task_info,corn_query):
         task_title = get_task_title_by_type(task_info.inspection_business)
         description = f"你有一个{task_title}任务需要处理,点击处理"
         detail_url = "{}/yjxp/#/worker/inspectionWork".format(settings.YZY_WEB_ROOT)
-        foreign_key = "0"
-        from_scenario = ""
+        foreign_key = str(task_info.id)
+        from_scenario = "risk_management_inspection_task"
 
-        send_yzy_msg(db, to_user_id, task_info.id, yzy_account, description, detail_url, foreign_key, from_scenario)
+        send_yzy_msg(db, "隐患巡查", to_user_id, task_info.id, yzy_account, description, detail_url, foreign_key, from_scenario)
 
-def get_task_title_by_type(type: int) -> str:
+def get_task_title_by_type(type: str) -> str:
     if type == '0':
         return '城市隐患巡查'
     elif type == '1':
@@ -209,7 +209,7 @@ def get_task_title_by_type(type: int) -> str:
         return str(type)
 
 # 发送粤政易消息
-def send_yzy_msg(db: Session, to_user_id: int, task_id: int, yzy_account: str, description: str, detail_url: str, foreign_key:str, from_scenario: str) -> None:
+def send_yzy_msg(db: Session, msg_type: str, to_user_id: int, task_id: int, yzy_account: str, description: str, detail_url: str, foreign_key:str, from_scenario: str) -> None:
     yzy_userid = db_yzy.get_userid_by_account(db, yzy_account)
     
     data = {
@@ -218,14 +218,15 @@ def send_yzy_msg(db: Session, to_user_id: int, task_id: int, yzy_account: str, d
         "content": description,
         "recorded_by": 0,
         "detail_url": detail_url,
-        "foreign_key": str(task_id),
-        "from_scenario": "risk_management_inspection_task",
+        "foreign_key": foreign_key,
+        "from_scenario": from_scenario,
         "title": "数据报送提醒"
     }
     YzyApi.add_to_msg_queue(db, data)
 
-    db_msg_center.add_msg(db, "隐患巡查", str(task_id), to_user_id)
+    db_msg_center.add_msg(db, msg_type, str(task_id), to_user_id)
 
+# 风险防控
 def create_risk_children_task(db,task_info,corn_query):
     cycle = task_info.task_cycle
     task_range = task_info.task_range
@@ -243,6 +244,20 @@ def create_risk_children_task(db,task_info,corn_query):
         )
         db.add(new_children_task)
     db.commit()
+
+    # 发送粤政易消息
+    user_list = rang_get_user_list(db, task_range)
+    for user_info in user_list:
+        to_user_id = user_info.user_id
+        yzy_account = user_info.yzy_account
+        task_title = db_dict.get_dict_label(db, 'risk_type', task_info.risk_type)
+        description = f"你有一个{task_title}任务需要处理,点击处理"
+        detail_url = "{}/yjxp/#/worker/riskManagement".format(settings.YZY_WEB_ROOT)
+        foreign_key = str(task_info.id)
+        from_scenario = "risk_management_risk_task"
+
+        send_yzy_msg(db, "风险防控", to_user_id, task_info.id, yzy_account, description, detail_url, foreign_key, from_scenario)
+    
 def create_rescue_resources_children_task(db,task_info,corn_query):
     cycle = task_info.task_cycle
     task_range = task_info.task_range
@@ -260,6 +275,30 @@ def create_rescue_resources_children_task(db,task_info,corn_query):
         )
         db.add(new_children_task)
     db.commit()
+
+    # 发送粤政易消息
+    user_list = rang_get_user_list(db, task_range)
+    for user_info in user_list:
+        to_user_id = user_info.user_id
+        yzy_account = user_info.yzy_account
+        task_title = get_rescue_resources_task_title_by_type(task_info.type)
+        description = f"你有一个{task_title}任务需要处理,点击处理"
+        detail_url = "{}/yjxp/#/worker/rescueManagement".format(settings.YZY_WEB_ROOT)
+        foreign_key = str(task_info.id)
+        from_scenario = "risk_management_rescue_resources_task"
+
+        send_yzy_msg(db, "数据采集", to_user_id, task_info.id, yzy_account, description, detail_url, foreign_key, from_scenario)
+
+def get_rescue_resources_task_title_by_type(type: str) -> str:
+    if type == '0':
+        return '庇护场所'
+    elif type == '1':
+        return '救援队伍'
+    elif type == '2':
+        return '救援设备'
+    else:
+        return str(type)
+
 def inspection_task_id_get_inspection_task_info(db,id):
     query = db.query(RiskManagementInspectionTask)
     query = query.filter(RiskManagementInspectionTask.del_flag != '2')