mirror of
https://github.com/zhouxiaoka/autoclip.git
synced 2026-09-03 06:24:14 +08:00
- 修复WebSocketNotificationService.send_processing_progress方法参数不匹配问题 - 修复前端RealTimeStatus组件WebSocket消息处理逻辑 - 修复Celery Worker队列配置,确保任务正确路由到processing队列 - 修复Celery应用导入冲突,统一使用正确的celery_app配置 - 添加实时项目状态更新功能,前端无需手动刷新即可看到处理进度 - 完善系统启动脚本,修复PYTHONPATH未绑定变量错误 - 优化流水线处理逻辑,确保所有6个步骤正常执行 - 添加完整的项目文档和启动指南 测试结果: - WebSocket进度更新正常工作(16%, 33%, 100%) - 流水线处理完全正常(6个步骤全部成功) - 前端状态自动更新正常 - 项目状态正确同步到数据库
86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
"""
|
|
基础服务类
|
|
提供通用的业务逻辑操作
|
|
"""
|
|
|
|
from typing import Generic, TypeVar, Type, Optional, List, Dict, Any
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import and_, or_
|
|
from ..repositories.base import BaseRepository, ModelType as RepoModelType
|
|
from ..schemas.base import BaseSchema, PaginationParams, PaginationResponse
|
|
|
|
|
|
CreateSchemaType = TypeVar("CreateSchemaType")
|
|
UpdateSchemaType = TypeVar("UpdateSchemaType")
|
|
ResponseSchemaType = TypeVar("ResponseSchemaType")
|
|
|
|
|
|
class BaseService(Generic[RepoModelType, CreateSchemaType, UpdateSchemaType, ResponseSchemaType]):
|
|
"""Base service class with common CRUD operations."""
|
|
|
|
def __init__(self, repository: BaseRepository[RepoModelType]):
|
|
self.repository = repository
|
|
|
|
def get(self, id: str) -> Optional[RepoModelType]:
|
|
"""Get a single record by ID."""
|
|
return self.repository.get_by_id(id)
|
|
|
|
def get_multi(
|
|
self,
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
filters: Optional[Dict[str, Any]] = None
|
|
) -> List[RepoModelType]:
|
|
"""Get multiple records with optional filtering."""
|
|
if filters:
|
|
return self.repository.find_by(**filters)
|
|
return self.repository.get_all(skip=skip, limit=limit)
|
|
|
|
def create(self, **kwargs) -> RepoModelType:
|
|
"""Create a new record."""
|
|
return self.repository.create(**kwargs)
|
|
|
|
def update(self, id: str, **kwargs) -> Optional[RepoModelType]:
|
|
"""Update an existing record."""
|
|
return self.repository.update(id, **kwargs)
|
|
|
|
def delete(self, id: str) -> bool:
|
|
"""Delete a record by ID."""
|
|
return self.repository.delete(id)
|
|
|
|
def count(self, filters: Optional[Dict[str, Any]] = None) -> int:
|
|
"""Count records with optional filtering."""
|
|
if filters:
|
|
return len(self.repository.find_by(**filters))
|
|
return self.repository.count()
|
|
|
|
def exists(self, id: str) -> bool:
|
|
"""Check if a record exists by ID."""
|
|
return self.repository.exists(id)
|
|
|
|
def get_paginated(
|
|
self,
|
|
pagination: PaginationParams,
|
|
filters: Optional[Dict[str, Any]] = None
|
|
) -> tuple[List[RepoModelType], PaginationResponse]:
|
|
"""Get paginated results."""
|
|
skip = (pagination.page - 1) * pagination.size
|
|
limit = pagination.size
|
|
|
|
items = self.get_multi(skip=skip, limit=limit, filters=filters)
|
|
total = self.count(filters)
|
|
|
|
pages = (total + pagination.size - 1) // pagination.size
|
|
has_next = pagination.page < pages
|
|
has_prev = pagination.page > 1
|
|
|
|
pagination_response = PaginationResponse(
|
|
page=pagination.page,
|
|
size=pagination.size,
|
|
total=total,
|
|
pages=pages,
|
|
has_next=has_next,
|
|
has_prev=has_prev
|
|
)
|
|
|
|
return items, pagination_response |