29 lines
845 B
Python
29 lines
845 B
Python
"""客户-投顾关系查询仓储。"""
|
|
|
|
from sqlalchemy import select
|
|
|
|
from model.customer_relation import CustomerRelation
|
|
from repositories.base import BaseRepository
|
|
|
|
|
|
class CustomerRelationRepo(BaseRepository):
|
|
"""按客户 ID 隔离读取有效关系。"""
|
|
|
|
model = CustomerRelation
|
|
|
|
async def list_by_customer(self, customer_id: int) -> list[CustomerRelation]:
|
|
"""返回指定客户尚未结束的关系。"""
|
|
statement = (
|
|
select(CustomerRelation)
|
|
.where(
|
|
CustomerRelation.customer_id == customer_id,
|
|
CustomerRelation.status != "已结束",
|
|
)
|
|
.order_by(CustomerRelation.assign_time.desc(), CustomerRelation.id.desc())
|
|
)
|
|
return list((await self.db.scalars(statement)).all())
|
|
|
|
|
|
__all__ = ["CustomerRelationRepo"]
|
|
|