libushang 6 hónapja
szülő
commit
af51862cb9
3 módosított fájl, 54 hozzáadás és 5 törlés
  1. 4 4
      common/db/db_msg_center.py
  2. 1 1
      models/base.py
  3. 49 0
      utils/riskManagement_uitl.py

+ 4 - 4
common/db/db_msg_center.py

@@ -8,9 +8,9 @@ from models import *
 from extensions import logger
 from utils import *
 
-def add_msg(db: Session, msg_type: str, msg_id: int, user_id: int) -> None:
+def add_msg(db: Session, msg_type: str, msg_id: str , user_id: int) -> None:
     new_msg = MsgCenter(
-        msg_type = msg_type, msg_id = msg_id, recv_time = datetime.now(), recv_userid = user_id, recv_status = 0, update_time = datetime.now()
+        msg_type = msg_type, msg_id = str(msg_id), recv_time = datetime.now(), recv_userid = user_id, recv_status = 0, update_time = datetime.now()
     )
     db.add(new_msg)
     db.commit()
@@ -29,6 +29,6 @@ def get_unread_msg_count(db: Session, user_id: int, msg_type_list: dict) -> dict
     logger.info(data)
     return data
 
-def update_msg_read(db: Session, user_id: int, msg_type: str, msg_id: int) -> None:
-    db.query(MsgCenter).filter(and_(MsgCenter.msg_type == msg_type, MsgCenter.recv_userid == user_id, MsgCenter.msg_id == msg_id)).update({"recv_status": 1, "update_time": datetime.now()})
+def update_msg_read(db: Session, user_id: int, msg_type: str, msg_id: str) -> None:
+    db.query(MsgCenter).filter(and_(MsgCenter.msg_type == msg_type, MsgCenter.recv_userid == user_id, MsgCenter.msg_id == str(msg_id))).update({"recv_status": 1, "update_time": datetime.now()})
     db.commit()

+ 1 - 1
models/base.py

@@ -108,7 +108,7 @@ class MsgCenter(Base):
     __tablename__ = "msg_center"
     id = Column(Integer, primary_key=True, autoincrement=True, comment='id')
     msg_type = Column(String, comment='消息类型')
-    msg_id = Column(Integer,comment='消息ID')
+    msg_id = Column(String,comment='消息ID')
     recv_time = Column(DateTime, default=datetime.now, comment='接收时间')
     recv_userid = Column(Integer, comment='接收用户ID')
     recv_status = Column(Integer, default="0", comment='接收状态 0 未阅 1 已阅')

+ 49 - 0
utils/riskManagement_uitl.py

@@ -3,6 +3,9 @@ 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 import YzyApi
+from config import settings
 
 def area_code_get_ancestors_names(db,area_info, ancestors_name=''):
     # print(area_info)
@@ -160,6 +163,8 @@ def rang_get_user_list(db,rang):
     area_list = get_area_code_list(db, rang)
     user_list = db.query(RiskManagementInspectionUser).filter(RiskManagementInspectionUser.del_flag=='0').filter(RiskManagementInspectionUser.area_code.in_(area_list)).all()
     return user_list
+
+# 巡查业务
 def create_children_task(db,task_info,corn_query):
     cycle = task_info.inspection_cycle
     task_range = task_info.inspection_range
@@ -177,6 +182,50 @@ def create_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_task_title_by_type(task_info.type)
+        description = f"你有一个{task_title}任务需要处理,点击处理"
+        detail_url = "{}/yjxp/#/worker/inspectionWork".format(settings.YZY_WEB_ROOT)
+        foreign_key = "0"
+        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:
+    if type == 0:
+        return '城市隐患巡查'
+    if type == 1:
+        return '森林防火巡查'
+    if type == 2:
+        return '重点危化企业巡查'
+    if type == 3:
+        return '重点水库水位巡查'
+    
+    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:
+    yzy_userid = db_yzy.get_userid_by_account(db, yzy_account)
+    
+    data = {
+        "yzy_userid": yzy_userid,
+        "mobile": yzy_account,
+        "content": description,
+        "recorded_by": 0,
+        "detail_url": detail_url,
+        "foreign_key": str(task_id),
+        "from_scenario": "risk_management_inspection_task",
+        "title": "数据报送提醒"
+    }
+    YzyApi.add_to_msg_queue(db, data)
+
+    db_msg_center.add_msg(db, "隐患巡查", 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