```
feat: 添加飞书用户模块和订阅功能支持 - 新增feishu_users模块用于处理飞书用户身份验证和权限管理 - 新增subscriptions模块用于处理订阅相关功能 - 新增personalization模块用于个性化服务 - 在alembic迁移配置中注册新的模型模块 - 在API路由器中添加feishu_users和subscriptions路由 - 实现事件调度服务的改进,包括错误处理和状态更新优化 - 添加飞书命令处理的权限检查机制 - 实现飞书应用票据事件处理 - 改进审计日志记录功能 ```
This commit is contained in:
@@ -780,15 +780,31 @@ class MarketService:
|
||||
report["content"] = "\n".join(lines)
|
||||
return report
|
||||
|
||||
def add_watchlist(self, actor: str, symbol: str) -> dict[str, Any]:
|
||||
def add_watchlist(
|
||||
self,
|
||||
actor: str,
|
||||
symbol: str,
|
||||
owner_id: int | None = None,
|
||||
) -> dict[str, Any]:
|
||||
code = normalize_symbol(symbol)
|
||||
owner_clause = (
|
||||
MarketWatchlist.owner_id.is_(None)
|
||||
if owner_id is None
|
||||
else MarketWatchlist.owner_id == owner_id
|
||||
)
|
||||
record = self.db.execute(
|
||||
select(MarketWatchlist).where(
|
||||
MarketWatchlist.actor == actor, MarketWatchlist.symbol == code
|
||||
owner_clause,
|
||||
MarketWatchlist.symbol == code,
|
||||
*(
|
||||
(MarketWatchlist.actor == actor,)
|
||||
if owner_id is None
|
||||
else ()
|
||||
),
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
if record is None:
|
||||
record = MarketWatchlist(actor=actor, symbol=code)
|
||||
record = MarketWatchlist(owner_id=owner_id, actor=actor, symbol=code)
|
||||
self.db.add(record)
|
||||
else:
|
||||
record.enabled = True
|
||||
@@ -804,16 +820,77 @@ class MarketService:
|
||||
response_payload={"enabled": True},
|
||||
)
|
||||
)
|
||||
return {"actor": actor, "symbol": code, "enabled": True}
|
||||
return {
|
||||
"actor": actor,
|
||||
"owner_id": owner_id,
|
||||
"symbol": code,
|
||||
"enabled": True,
|
||||
}
|
||||
|
||||
def watchlist(self, actor: str) -> list[dict[str, Any]]:
|
||||
def watchlist(
|
||||
self,
|
||||
actor: str,
|
||||
owner_id: int | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
owner_clause = (
|
||||
MarketWatchlist.owner_id.is_(None)
|
||||
if owner_id is None
|
||||
else MarketWatchlist.owner_id == owner_id
|
||||
)
|
||||
records = self.db.execute(
|
||||
select(MarketWatchlist).where(
|
||||
MarketWatchlist.actor == actor, MarketWatchlist.enabled.is_(True)
|
||||
owner_clause,
|
||||
MarketWatchlist.enabled.is_(True),
|
||||
*(
|
||||
(MarketWatchlist.actor == actor,)
|
||||
if owner_id is None
|
||||
else ()
|
||||
),
|
||||
)
|
||||
).scalars()
|
||||
return [{"symbol": r.symbol} for r in records]
|
||||
|
||||
def claim_legacy_watchlist(self, owner_id: int, open_id: str) -> int:
|
||||
"""Claim still-unowned rows created by the verified legacy Feishu actor."""
|
||||
|
||||
legacy_records = list(
|
||||
self.db.execute(
|
||||
select(MarketWatchlist).where(
|
||||
MarketWatchlist.owner_id.is_(None),
|
||||
MarketWatchlist.actor == open_id,
|
||||
)
|
||||
).scalars()
|
||||
)
|
||||
claimed = 0
|
||||
for legacy in legacy_records:
|
||||
existing = self.db.execute(
|
||||
select(MarketWatchlist).where(
|
||||
MarketWatchlist.owner_id == owner_id,
|
||||
MarketWatchlist.symbol == legacy.symbol,
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
if existing is not None:
|
||||
existing.enabled = existing.enabled or legacy.enabled
|
||||
self.db.delete(legacy)
|
||||
continue
|
||||
legacy.owner_id = owner_id
|
||||
claimed += 1
|
||||
self.db.commit()
|
||||
return claimed
|
||||
|
||||
def delete_owner_watchlist(self, owner_id: int) -> int:
|
||||
"""Stage deletion of all personal watchlist rows for an owner."""
|
||||
|
||||
records = list(
|
||||
self.db.execute(
|
||||
select(MarketWatchlist).where(MarketWatchlist.owner_id == owner_id)
|
||||
).scalars()
|
||||
)
|
||||
for record in records:
|
||||
self.db.delete(record)
|
||||
self.db.flush()
|
||||
return len(records)
|
||||
|
||||
def _ai(self, skill: AISkillId, report: dict[str, Any], actor: str) -> dict[str, Any]:
|
||||
try:
|
||||
result = AIService(self.db).run_skill(
|
||||
|
||||
Reference in New Issue
Block a user