Browse Source

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

baoyubo 8 months ago
parent
commit
d0ef819317

+ 19 - 8
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()
@@ -20,15 +20,26 @@ def add_msg(db: Session, msg_type: str, msg_id: int, 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()
+
+        c1 = 0
+        if msg_type == '事件管理':
+            # 等同 list_active
+            where = and_(EventBase.del_flag == '0', EventBase.event_title != '', EventBase.event_status.in_(['0', '1']))
+            c1 = db.query(EventBase).filter(where).count() 
+        else:
+            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
 
-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 已阅')

+ 23 - 1
models/online_roll_call.py

@@ -52,4 +52,26 @@ class OnlineRollCallDetail(Base):
     standby_staff_id = Column(Integer, default=0, server_default='0', comment="备班人员ID")
 
     class Config:
-        orm_mode = True
+        orm_mode = True
+
+
+
+class OnlineRollCallFile(Base):
+    __tablename__ = 'online_roll_call_file'
+
+    id = Column(Integer, autoincrement=True, primary_key=True)
+    file_name = Column(String(255), nullable=False, comment='文件名称')
+    storage_file_name = Column(String(255), nullable=False, comment='文件名称原名')
+    file_path = Column(String(255), comment='文件存储路径')
+    file_size = Column(String(50), comment='文件大小')
+    status = Column(String(50), comment='文件状态')
+    foreign_key = Column(String(50), comment='文件外键 --技术字段')
+    from_scenario = Column(String(50), comment='对应标识 --技术字段')
+    create_time = Column(DateTime, default=datetime.now, comment='数据创建时间')
+    update_time = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='数据更新时间')
+    create_dept = Column(Integer, default=None, comment='创建部门')
+    create_by = Column(Integer, default=None, comment='创建者')
+    del_flag = Column(String(1), default='0', comment='删除标志(0代表存在 2代表删除)')
+
+    class Config:
+        orm_mode = True

+ 1 - 1
routers/api/eventManagement/checkin.py

@@ -37,7 +37,7 @@ async def get_qrcode(
     print('url:', url)
     url = url.replace("qrcode", "qrcode2") + "&r="+rnd()
 
-    url = url.replace(request.url.hostname, settings.YZY_WEB_ROOT)
+    url = url.replace("http://" + request.url.hostname, settings.YZY_WEB_ROOT)
     logger.info('替换到互联网ip: {}', url)   
 
     qr = qrcode.QRCode(

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

@@ -114,7 +114,8 @@ def send_yzy_msg(db: Session, event_base: EventBase, user_id: int) -> None:
     }
     YzyApi.add_to_msg_queue(db, data)
 
-    db_msg_center.add_msg(db, "事件管理", event_base.id, to_user_id)
+    # 改为没用关闭的事件统计
+    # db_msg_center.add_msg(db, "事件管理", event_base.id, to_user_id)
 
 @router.get('/list')
 async def get_event_list(

+ 45 - 4
routers/api/onlineRollCall/call.py

@@ -27,6 +27,7 @@ from exceptions import AppException
 from typing import List, Dict,Set
 import openpyxl
 from io import BytesIO
+from PIL import Image
 
 router = APIRouter()
 
@@ -420,7 +421,17 @@ async def ack_all(
     body = Depends(remove_xss_json),
     user_id = Depends(valid_access_token)
 ):
-    call_id = body['call_id']
+    call_id = get_req_param(body, 'call_id')
+    base64_data = get_req_param(body, "photo_data")
+
+    file_name = new_guid() + ".png"
+    file_path = f'/data/upload/mergefile/uploads/{file_name}'
+    
+    base64_data = base64_data.replace("data:image/png;base64,", "")
+    binary_data = base64.b64decode(base64_data)
+    bytes_io = BytesIO(binary_data)
+    image = Image.open(bytes_io)
+    image.save(file_path)
 
     base_row = db.query(OnlineRollCallBase).filter(OnlineRollCallBase.id == call_id).first()
     if base_row is None:
@@ -429,17 +440,37 @@ async def ack_all(
             "msg": "点名记录不存在"
         }
     
-    detail_row = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.pid == call_id, OnlineRollCallDetail.leader_id == user_id)).first()
+    user_or_where = or_(OnlineRollCallDetail.leader_id == user_id, OnlineRollCallDetail.primary_staff_id == user_id, OnlineRollCallDetail.secondary_staff_id == user_id, OnlineRollCallDetail.standby_staff_id == user_id)
+    detail_row = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.pid == call_id, user_or_where)).first()
     if detail_row is None:
         return {
             "code": 500,
             "msg": "点名记录不存在!"
         }
     
+    new_file = OnlineRollCallFile(
+        file_name=f"点名头像{user_id}.png",
+        storage_file_name=file_name,
+        file_path=f'/data/upload/mergefile/uploads/{file_name}',
+        file_size=os.path.getsize(f'/data/upload/mergefile/uploads/{file_name}'),
+        foreign_key=str(detail_row.id),
+        from_scenario="online_call_photo_file",
+        update_time=datetime.now(),
+        create_time=datetime.now(),
+        create_by=user_id,
+        create_dept=0,
+        del_flag='0',
+        status=0,
+    )
+    db.add(new_file)
+
     detail_row.ack_status = 1 # 已应答
     detail_row.ack_time = datetime.now()
     db.commit()
 
+    logger.info("标记[在线点名]已读 {}", str(detail_row.id))
+    db_msg_center.update_msg_read(db, user_id, "在线点名", str(detail_row.id))
+
     # 统计应答数
     ack_count = db.query(OnlineRollCallDetail).filter(and_(OnlineRollCallDetail.pid == call_id, OnlineRollCallDetail.ack_status == 1)).count()
     # 统计未应答数
@@ -658,7 +689,11 @@ async def get_event_list(
 ):
 
     try:
-        where = and_(OnlineRollCallDetail.leader_id == user_id, OnlineRollCallDetail.del_flag == '0')
+        is_myid_where = or_(OnlineRollCallDetail.standby_staff_id == user_id, 
+                      OnlineRollCallDetail.leader_id == user_id, 
+                      OnlineRollCallDetail.primary_staff_id == user_id, 
+                      OnlineRollCallDetail.secondary_staff_id == user_id)
+        where = and_(is_myid_where, OnlineRollCallDetail.del_flag == '0')
 
         if begin_date is not None and begin_date != '':
             begin_date = datetime.strptime(begin_date, "%Y-%m-%d")
@@ -683,8 +718,13 @@ async def get_event_list(
 
         for row in rows:
             duration_time = ""
+            img_url = ""
             # 已应答
             if row.ack_status == 1:
+
+                file_info  = db.query(OnlineRollCallFile).filter(and_(OnlineRollCallFile.foreign_key == str(row.id), OnlineRollCallFile.from_scenario == 'online_call_photo_file', OnlineRollCallFile.del_flag == '0')).first()
+                if file_info is not None:
+                    img_url = file_info.storage_file_name
                 time_diff = row.ack_time - row.create_time
                 if time_diff.days < 0:
                     duration_time = "超过{}天".format(abs(time_diff.days))
@@ -696,7 +736,8 @@ async def get_event_list(
                 "id": row.id,
                 "create_time": get_datetime_str(row.create_time),
                 "duration_time": duration_time,
-                "ack_status": row.ack_status
+                "ack_status": row.ack_status,
+                "img_url": img_url
             })
 
         # 返回结果

+ 7 - 0
routers/api/riskManagement/rescue_resources.py

@@ -766,6 +766,13 @@ async def create_inspection_task(
         db.add(new_task_log)
 
         db.commit()
+
+        # 标记消息已读
+        child_task_info = db.query(RiskManagementRescueResourcesTaskChildrenTask).filter(RiskManagementRescueResourcesTaskChildrenTask.id == children_task_id).first()
+        if child_task_info is not None:
+            logger.info("标记[数据采集任务]已读 {}", str(child_task_info.task_id))
+            db_msg_center.update_msg_read(db, user_id, "数据采集", str(child_task_info.task_id))
+
         # 返回创建成功的响应
         return {
             "code": 200,

+ 7 - 1
routers/api/riskManagement/risk_router.py

@@ -764,8 +764,14 @@ async def create_inspection_task(
                 db.add(new_file)
         # 添加到数据库会话并提交
         db.add(new_task_log)
-
         db.commit()
+        
+        # 标记消息已读
+        child_task_info = db.query(RiskManagementRiskTaskChildrenTask).filter(RiskManagementRiskTaskChildrenTask.id == children_task_id).first()
+        if child_task_info is not None:
+            logger.info("标记[风险防控任务]已读 {}", str(child_task_info.task_id))
+            db_msg_center.update_msg_read(db, user_id, "风险防控", str(child_task_info.task_id))
+
         # 返回创建成功的响应
         return {
             "code": 200,

+ 7 - 1
routers/api/riskManagement/task.py

@@ -746,8 +746,14 @@ async def create_inspection_task(
                 db.add(new_file)
         # 添加到数据库会话并提交
         db.add(new_task_log)
-
         db.commit()
+        
+        # 标记消息已读
+        child_task_info = db.query(RiskManagementInspectionTaskChildrenTask).filter(RiskManagementInspectionTaskChildrenTask.id == children_task_id).first()
+        if child_task_info is not None:
+            logger.info("标记[隐患巡查任务]已读 {}", str(child_task_info.task_id))
+            db_msg_center.update_msg_read(db, user_id, "隐患巡查", str(child_task_info.task_id))
+
         # 返回创建成功的响应
         return {
             "code": 200,

+ 51 - 3
routers/api/videoResource/avcon.py

@@ -73,8 +73,6 @@ async def get_start_mini_param(
     if password == "":
         password = "123"
 
-    roomid = get_req_param_optional(body, "roomid")
-
     windowpos = get_req_param(body, "windowpos")
     x = windowpos['x']
     y = windowpos['y']
@@ -90,7 +88,6 @@ async def get_start_mini_param(
         "serverip": "19.152.196.106",
         "userid": userid,
         "password": password,
-        "roomid": roomid,
         "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
         "members": members
     }
@@ -100,6 +97,57 @@ async def get_start_mini_param(
     json_str = json.dumps(params, ensure_ascii=False)
     base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
 
+    return {
+        "code": 0,
+        "msg": "success",
+        "data": "" + "avcon6://" + base64_str
+    }
+
+@router.post("/get_start_mini_with_no_param")
+async def get_start_mini_param(
+    body = Depends(remove_xss_json),
+    db: Session = Depends(get_db),
+    user_id = Depends(valid_access_token)
+):
+    userid = get_req_param_optional(body, "userid")
+    if userid == "":
+        user_info = db.query(AvconUser).filter(AvconUser.user_id).first()
+        if user_info is None:
+            return {
+                "code": 500,
+                "msg": "当前账号对应的融合设备为空,请联系管理员配置。"
+            }
+
+        userid = user_info.dev_id
+
+    password = get_req_param_optional(body, "password")
+    if password == "":
+        password = "123"
+
+    roomcode = get_req_param_optional(body, "roomcode")
+
+    windowpos = get_req_param(body, "windowpos")
+    x = windowpos['x']
+    y = windowpos['y']
+    width = windowpos['width']
+    height = windowpos['height']
+    top = windowpos['top']
+
+    params = {
+        "mode": "mini",
+        "cmd": "enterroom",
+        "serverip": "19.152.196.106",
+        "userid": userid,
+        "password": password,
+        "roomcode": roomcode,
+        "windowpos": {"x": x,"y": y,"width": width,"height": height,"top": top},
+    }
+    
+    logger.info("发起融合通信mini客户端入会: {}", params)
+
+    json_str = json.dumps(params, ensure_ascii=False)
+    base64_str = base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
+
     return {
         "code": 0,
         "msg": "success",

+ 88 - 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, db_dict
+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,51 @@ 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.inspection_business)
+        description = f"你有一个{task_title}任务需要处理,点击处理"
+        detail_url = "{}/yjxp/#/worker/inspectionWork".format(settings.YZY_WEB_ROOT)
+        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)
+
+def get_task_title_by_type(type: str) -> str:
+    if type == '0':
+        return '城市隐患巡查'
+    elif type == '1':
+        return '森林防火巡查'
+    elif type == '2':
+        return '重点危化企业巡查'
+    elif type == '3':
+        return '重点水库水位巡查'
+    else:
+        return str(type)
+
+# 发送粤政易消息
+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 = {
+        "yzy_userid": yzy_userid,
+        "mobile": yzy_account,
+        "content": description,
+        "recorded_by": 0,
+        "detail_url": detail_url,
+        "foreign_key": foreign_key,
+        "from_scenario": from_scenario,
+        "title": "数据报送提醒"
+    }
+    YzyApi.add_to_msg_queue(db, data)
+
+    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
@@ -194,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
@@ -211,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')