From b8e19dcde64ae79805a19b121c9e47cdebfe629c Mon Sep 17 00:00:00 2001 From: Admin Date: Wed, 28 Jan 2026 17:06:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E5=91=BD=E5=90=8D=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=B8=A0=E9=81=93=E6=A8=A1=E5=9E=8B=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E4=B8=8E=20alert=20=E6=A8=A1=E5=9D=97=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - NotificationChannel -> TaskNotifyChannel - platform_notification_channels -> platform_task_notify_channels --- backend/app/models/__init__.py | 4 ++-- backend/app/models/notification_channel.py | 8 +++---- backend/app/routers/notification_channels.py | 24 ++++++++++---------- backend/app/services/scheduler.py | 10 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py index 343c160..04b74c8 100644 --- a/backend/app/models/__init__.py +++ b/backend/app/models/__init__.py @@ -9,7 +9,7 @@ from .logs import PlatformLog from .alert import AlertRule, AlertRecord, NotificationChannel from .pricing import ModelPricing, TenantBilling from .scheduled_task import ScheduledTask, TaskLog, ScriptVar, Secret -from .notification_channel import NotificationChannel +from .notification_channel import TaskNotifyChannel __all__ = [ "Tenant", @@ -31,5 +31,5 @@ __all__ = [ "TaskLog", "ScriptVar", "Secret", - "NotificationChannel" + "TaskNotifyChannel" ] diff --git a/backend/app/models/notification_channel.py b/backend/app/models/notification_channel.py index d4f8342..313eb6c 100644 --- a/backend/app/models/notification_channel.py +++ b/backend/app/models/notification_channel.py @@ -1,12 +1,12 @@ -"""通知渠道模型""" +"""任务通知渠道模型""" from datetime import datetime from sqlalchemy import Column, Integer, String, Enum, Boolean, DateTime from ..database import Base -class NotificationChannel(Base): - """通知渠道表""" - __tablename__ = "platform_notification_channels" +class TaskNotifyChannel(Base): + """任务通知渠道表(用于定时任务推送)""" + __tablename__ = "platform_task_notify_channels" id = Column(Integer, primary_key=True, autoincrement=True) tenant_id = Column(String(50), nullable=False) diff --git a/backend/app/routers/notification_channels.py b/backend/app/routers/notification_channels.py index b8432cc..84932b9 100644 --- a/backend/app/routers/notification_channels.py +++ b/backend/app/routers/notification_channels.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import Session from sqlalchemy import desc from ..database import get_db -from ..models.notification_channel import NotificationChannel +from ..models.notification_channel import TaskNotifyChannel router = APIRouter(prefix="/api/notification-channels", tags=["notification-channels"]) @@ -42,17 +42,17 @@ async def list_channels( db: Session = Depends(get_db) ): """获取通知渠道列表""" - query = db.query(NotificationChannel) + query = db.query(TaskNotifyChannel) if tenant_id: - query = query.filter(NotificationChannel.tenant_id == tenant_id) + query = query.filter(TaskNotifyChannel.tenant_id == tenant_id) if channel_type: - query = query.filter(NotificationChannel.channel_type == channel_type) + query = query.filter(TaskNotifyChannel.channel_type == channel_type) if is_enabled is not None: - query = query.filter(NotificationChannel.is_enabled == is_enabled) + query = query.filter(TaskNotifyChannel.is_enabled == is_enabled) total = query.count() - items = query.order_by(desc(NotificationChannel.created_at)).offset((page - 1) * size).limit(size).all() + items = query.order_by(desc(TaskNotifyChannel.created_at)).offset((page - 1) * size).limit(size).all() return { "total": total, @@ -63,7 +63,7 @@ async def list_channels( @router.get("/{channel_id}") async def get_channel(channel_id: int, db: Session = Depends(get_db)): """获取渠道详情""" - channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first() + channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first() if not channel: raise HTTPException(status_code=404, detail="渠道不存在") return format_channel(channel) @@ -72,7 +72,7 @@ async def get_channel(channel_id: int, db: Session = Depends(get_db)): @router.post("") async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)): """创建通知渠道""" - channel = NotificationChannel( + channel = TaskNotifyChannel( tenant_id=data.tenant_id, channel_name=data.channel_name, channel_type=data.channel_type, @@ -91,7 +91,7 @@ async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)): @router.put("/{channel_id}") async def update_channel(channel_id: int, data: ChannelUpdate, db: Session = Depends(get_db)): """更新通知渠道""" - channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first() + channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first() if not channel: raise HTTPException(status_code=404, detail="渠道不存在") @@ -113,7 +113,7 @@ async def update_channel(channel_id: int, data: ChannelUpdate, db: Session = Dep @router.delete("/{channel_id}") async def delete_channel(channel_id: int, db: Session = Depends(get_db)): """删除通知渠道""" - channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first() + channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first() if not channel: raise HTTPException(status_code=404, detail="渠道不存在") @@ -127,7 +127,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)): """测试通知渠道""" import httpx - channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first() + channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first() if not channel: raise HTTPException(status_code=404, detail="渠道不存在") @@ -166,7 +166,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)): # ==================== Helpers ==================== -def format_channel(channel: NotificationChannel) -> dict: +def format_channel(channel: TaskNotifyChannel) -> dict: """格式化渠道数据""" return { "id": channel.id, diff --git a/backend/app/services/scheduler.py b/backend/app/services/scheduler.py index b8f80a8..7558ffe 100644 --- a/backend/app/services/scheduler.py +++ b/backend/app/services/scheduler.py @@ -10,7 +10,7 @@ from sqlalchemy.orm import Session from ..database import SessionLocal from ..models.scheduled_task import ScheduledTask, TaskLog -from ..models.notification_channel import NotificationChannel +from ..models.notification_channel import TaskNotifyChannel from .script_executor import ScriptExecutor @@ -260,9 +260,9 @@ class SchedulerService: # 发送到通知渠道 for channel_id in channel_ids: try: - channel = db.query(NotificationChannel).filter( - NotificationChannel.id == channel_id, - NotificationChannel.is_enabled == True + channel = db.query(TaskNotifyChannel).filter( + TaskNotifyChannel.id == channel_id, + TaskNotifyChannel.is_enabled == True ).first() if not channel: @@ -280,7 +280,7 @@ class SchedulerService: except Exception as e: print(f"发送企微应用消息失败: {e}") - async def _send_to_channel(self, channel: NotificationChannel, content: str, title: str): + async def _send_to_channel(self, channel: TaskNotifyChannel, content: str, title: str): """发送消息到通知渠道""" if channel.channel_type == 'dingtalk_bot': payload = {