fix: 重命名通知渠道模型避免与 alert 模块冲突
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- NotificationChannel -> TaskNotifyChannel - platform_notification_channels -> platform_task_notify_channels
This commit is contained in:
@@ -9,7 +9,7 @@ from .logs import PlatformLog
|
|||||||
from .alert import AlertRule, AlertRecord, NotificationChannel
|
from .alert import AlertRule, AlertRecord, NotificationChannel
|
||||||
from .pricing import ModelPricing, TenantBilling
|
from .pricing import ModelPricing, TenantBilling
|
||||||
from .scheduled_task import ScheduledTask, TaskLog, ScriptVar, Secret
|
from .scheduled_task import ScheduledTask, TaskLog, ScriptVar, Secret
|
||||||
from .notification_channel import NotificationChannel
|
from .notification_channel import TaskNotifyChannel
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Tenant",
|
"Tenant",
|
||||||
@@ -31,5 +31,5 @@ __all__ = [
|
|||||||
"TaskLog",
|
"TaskLog",
|
||||||
"ScriptVar",
|
"ScriptVar",
|
||||||
"Secret",
|
"Secret",
|
||||||
"NotificationChannel"
|
"TaskNotifyChannel"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
"""通知渠道模型"""
|
"""任务通知渠道模型"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import Column, Integer, String, Enum, Boolean, DateTime
|
from sqlalchemy import Column, Integer, String, Enum, Boolean, DateTime
|
||||||
from ..database import Base
|
from ..database import Base
|
||||||
|
|
||||||
|
|
||||||
class NotificationChannel(Base):
|
class TaskNotifyChannel(Base):
|
||||||
"""通知渠道表"""
|
"""任务通知渠道表(用于定时任务推送)"""
|
||||||
__tablename__ = "platform_notification_channels"
|
__tablename__ = "platform_task_notify_channels"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
tenant_id = Column(String(50), nullable=False)
|
tenant_id = Column(String(50), nullable=False)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from sqlalchemy.orm import Session
|
|||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
|
|
||||||
from ..database import get_db
|
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"])
|
router = APIRouter(prefix="/api/notification-channels", tags=["notification-channels"])
|
||||||
@@ -42,17 +42,17 @@ async def list_channels(
|
|||||||
db: Session = Depends(get_db)
|
db: Session = Depends(get_db)
|
||||||
):
|
):
|
||||||
"""获取通知渠道列表"""
|
"""获取通知渠道列表"""
|
||||||
query = db.query(NotificationChannel)
|
query = db.query(TaskNotifyChannel)
|
||||||
|
|
||||||
if tenant_id:
|
if tenant_id:
|
||||||
query = query.filter(NotificationChannel.tenant_id == tenant_id)
|
query = query.filter(TaskNotifyChannel.tenant_id == tenant_id)
|
||||||
if channel_type:
|
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:
|
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()
|
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 {
|
return {
|
||||||
"total": total,
|
"total": total,
|
||||||
@@ -63,7 +63,7 @@ async def list_channels(
|
|||||||
@router.get("/{channel_id}")
|
@router.get("/{channel_id}")
|
||||||
async def get_channel(channel_id: int, db: Session = Depends(get_db)):
|
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:
|
if not channel:
|
||||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||||
return format_channel(channel)
|
return format_channel(channel)
|
||||||
@@ -72,7 +72,7 @@ async def get_channel(channel_id: int, db: Session = Depends(get_db)):
|
|||||||
@router.post("")
|
@router.post("")
|
||||||
async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)):
|
async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)):
|
||||||
"""创建通知渠道"""
|
"""创建通知渠道"""
|
||||||
channel = NotificationChannel(
|
channel = TaskNotifyChannel(
|
||||||
tenant_id=data.tenant_id,
|
tenant_id=data.tenant_id,
|
||||||
channel_name=data.channel_name,
|
channel_name=data.channel_name,
|
||||||
channel_type=data.channel_type,
|
channel_type=data.channel_type,
|
||||||
@@ -91,7 +91,7 @@ async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)):
|
|||||||
@router.put("/{channel_id}")
|
@router.put("/{channel_id}")
|
||||||
async def update_channel(channel_id: int, data: ChannelUpdate, db: Session = Depends(get_db)):
|
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:
|
if not channel:
|
||||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
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}")
|
@router.delete("/{channel_id}")
|
||||||
async def delete_channel(channel_id: int, db: Session = Depends(get_db)):
|
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:
|
if not channel:
|
||||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)):
|
|||||||
"""测试通知渠道"""
|
"""测试通知渠道"""
|
||||||
import httpx
|
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:
|
if not channel:
|
||||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
# ==================== Helpers ====================
|
# ==================== Helpers ====================
|
||||||
|
|
||||||
def format_channel(channel: NotificationChannel) -> dict:
|
def format_channel(channel: TaskNotifyChannel) -> dict:
|
||||||
"""格式化渠道数据"""
|
"""格式化渠道数据"""
|
||||||
return {
|
return {
|
||||||
"id": channel.id,
|
"id": channel.id,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
from ..database import SessionLocal
|
from ..database import SessionLocal
|
||||||
from ..models.scheduled_task import ScheduledTask, TaskLog
|
from ..models.scheduled_task import ScheduledTask, TaskLog
|
||||||
from ..models.notification_channel import NotificationChannel
|
from ..models.notification_channel import TaskNotifyChannel
|
||||||
from .script_executor import ScriptExecutor
|
from .script_executor import ScriptExecutor
|
||||||
|
|
||||||
|
|
||||||
@@ -260,9 +260,9 @@ class SchedulerService:
|
|||||||
# 发送到通知渠道
|
# 发送到通知渠道
|
||||||
for channel_id in channel_ids:
|
for channel_id in channel_ids:
|
||||||
try:
|
try:
|
||||||
channel = db.query(NotificationChannel).filter(
|
channel = db.query(TaskNotifyChannel).filter(
|
||||||
NotificationChannel.id == channel_id,
|
TaskNotifyChannel.id == channel_id,
|
||||||
NotificationChannel.is_enabled == True
|
TaskNotifyChannel.is_enabled == True
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if not channel:
|
if not channel:
|
||||||
@@ -280,7 +280,7 @@ class SchedulerService:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"发送企微应用消息失败: {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':
|
if channel.channel_type == 'dingtalk_bot':
|
||||||
payload = {
|
payload = {
|
||||||
|
|||||||
Reference in New Issue
Block a user