38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import List
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
from app.api.v1.module_common.activity.model import ActivityModel
|
|
from app.api.v1.module_common.activity.schema import ActivityCreate, ActivityUpdate
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
|
|
|
|
class ActivityCRUD(CRUDBase[ActivityModel, ActivityCreate, ActivityUpdate]):
|
|
"""活动记录CRUD"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
super().__init__(ActivityModel, auth)
|
|
|
|
async def get_display_list(self, limit: int = 10) -> List[str]:
|
|
"""
|
|
获取前端展示格式的活动列表
|
|
|
|
参数:
|
|
- limit: 返回数量限制
|
|
|
|
返回:
|
|
- List[str]: 格式化的活动文本列表
|
|
"""
|
|
activities = await self.list(
|
|
search={"status": "0"},
|
|
order_by=[{"sort_order": "asc"}, {"created_time": "desc"}]
|
|
)
|
|
|
|
result = []
|
|
for activity in activities[:limit]:
|
|
text = f"{activity.user_name} {activity.action}了 {activity.service_name} {activity.service_type or ''}".strip()
|
|
result.append(text)
|
|
|
|
return result
|