优化“知识库模块“--基本完善
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from typing import Sequence
|
||||
|
||||
from sqlalchemy import or_, select, update as sa_update
|
||||
from sqlalchemy import func, or_, select, update as sa_update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.faq_category import FaqCategory
|
||||
@@ -23,8 +23,8 @@ async def create_item(db: AsyncSession, item_in: FaqCreate, *, created_by: uuid.
|
||||
study_id=item_in.study_id,
|
||||
category_id=item_in.category_id,
|
||||
question=item_in.question,
|
||||
answer=item_in.answer,
|
||||
keywords=item_in.keywords,
|
||||
answer=item_in.answer or "",
|
||||
status="PENDING",
|
||||
version=1,
|
||||
is_active=True,
|
||||
created_by=created_by,
|
||||
@@ -56,7 +56,7 @@ async def list_items(
|
||||
elif study_scope == "global":
|
||||
stmt = stmt.where(FaqItem.study_id.is_(None))
|
||||
else: # project (default)
|
||||
stmt = stmt.where((FaqItem.study_id == study_id) | (FaqItem.study_id.is_(None)))
|
||||
stmt = stmt.where(FaqItem.study_id == study_id)
|
||||
|
||||
if category_id:
|
||||
stmt = stmt.where(FaqItem.category_id == category_id)
|
||||
@@ -88,3 +88,38 @@ async def update_item(db: AsyncSession, item: FaqItem, item_in: FaqUpdate) -> Fa
|
||||
await db.commit()
|
||||
await db.refresh(item)
|
||||
return item
|
||||
|
||||
|
||||
async def touch_item(db: AsyncSession, item_id: uuid.UUID) -> None:
|
||||
await db.execute(
|
||||
sa_update(FaqItem)
|
||||
.where(FaqItem.id == item_id)
|
||||
.values(updated_at=func.now())
|
||||
)
|
||||
await db.commit()
|
||||
|
||||
|
||||
async def set_best_reply(db: AsyncSession, item_id: uuid.UUID, reply_id: uuid.UUID | None) -> None:
|
||||
await db.execute(
|
||||
sa_update(FaqItem)
|
||||
.where(FaqItem.id == item_id)
|
||||
.values(best_reply_id=reply_id, updated_at=func.now())
|
||||
)
|
||||
await db.commit()
|
||||
|
||||
|
||||
async def set_status(db: AsyncSession, item_id: uuid.UUID, status: str, resolved_by_confirm: bool | None = None) -> None:
|
||||
values: dict[str, object] = {"status": status, "updated_at": func.now()}
|
||||
if resolved_by_confirm is not None:
|
||||
values["resolved_by_confirm"] = resolved_by_confirm
|
||||
await db.execute(
|
||||
sa_update(FaqItem)
|
||||
.where(FaqItem.id == item_id)
|
||||
.values(**values)
|
||||
)
|
||||
await db.commit()
|
||||
|
||||
|
||||
async def count_items_by_category(db: AsyncSession, category_id: uuid.UUID) -> int:
|
||||
result = await db.execute(select(func.count()).select_from(FaqItem).where(FaqItem.category_id == category_id))
|
||||
return int(result.scalar_one())
|
||||
|
||||
Reference in New Issue
Block a user