1.实现获取告警消息类型分布接口

This commit is contained in:
haotian 2025-08-01 15:05:58 +08:00
parent f36a41ff8c
commit aa4c2a9c4e
3 changed files with 23 additions and 1 deletions

View File

@ -29,7 +29,8 @@ async def get_alarm_type_distribution(
query_db: AsyncSession = Depends(get_db),
):
result = await MessageService.get_alarm_type_distribution_services(query_db)
pass
return ResponseUtil.success(data=result)
# 一键处理未处理的告警消息

View File

@ -12,6 +12,15 @@ class MessageDao:
系统消息模块数据库操作层
"""
@classmethod
async def get_alarm_type_distribution(cls, db: AsyncSession):
stmt = (
select(Message.specific_type, func.count(Message.specific_type).label("cnt"))
.where(Message.type == '0')
.group_by(Message.specific_type)
)
return (await db.execute(stmt)).mappings().all()
@classmethod
async def handle_all_message(cls, db: AsyncSession):
query = (

View File

@ -13,6 +13,18 @@ class MessageService:
"""
系统消息模块服务层
"""
# 获取告警消息分布
@classmethod
async def get_alarm_type_distribution_services(cls, query_db: AsyncSession):
result = await MessageDao.get_alarm_type_distribution(query_db)
# d = dict()
# t = 0
# for k, v in result.items():
# d[k] = v
# t += v
# for k, v in d.items():
# result[k] = round(v/t, 2)
return result
@classmethod
async def handle_all_message_services(cls,query_db: AsyncSession):