```
feat(core): 添加多API密钥支持和配置字段 添加了api_keys、audit_api_keys、approval_api_keys等字段用于支持多个服务密钥, 新增masked_response_fields用于配置响应掩码字段,以及legacy相关配置项。 feat(core): 增强响应数据掩码功能 扩展mask_configured函数支持域名参数,实现更精确的敏感字段掩码控制, 添加自定义掩码字段配置验证器。 feat(scheduler): 添加遗留系统同步调度任务 集成遗留项目和任务同步到定时调度器中,支持通过配置启用或禁用同步功能, 并可设置不同的执行时间计划。 feat(security): 实现多服务密钥认证机制 重构API密钥验证逻辑,支持单个主密钥和多个配置密钥的混合验证模式, 增加服务密钥启用状态检查和角色映射功能。 feat(task_queue): 扩展现有队列任务处理 为日常简报和周报推送任务添加Celery异步处理支持,新增遗留项目和任务同步任务, 统一任务分发接口。 feat(business): 扩展业务模型字段 为工作任务模型添加外部系统标识和外部ID字段,为风险事件模型增加分配、解决、关闭 等相关字段,并创建风险事件操作记录表。 feat(legacy_mysql): 实现遗留任务同步功能 添加遗留任务查询和同步路由,支持从旧MySQL数据库同步任务数据到内部系统, 包括同步结果统计和运行记录。 refactor(dashboard): 更新仪表板统计数据 增加未分配风险和失败推送运行统计,在概览中显示最新的推送和同步运行记录, 完善数据序列化展示。 fix(feishu): 修复审批事件重复处理 实现审批卡片操作事件的唯一性检查,防止重复审批操作,添加事件审计日志记录。 ```
This commit is contained in:
@@ -27,10 +27,19 @@ from app.modules.business.constants import (
|
||||
RiskLevel,
|
||||
StatusValue,
|
||||
)
|
||||
from app.modules.business.models import FundAccount, Project, RiskEvent, Supplier, WorkTask
|
||||
from app.modules.business.models import (
|
||||
FundAccount,
|
||||
Project,
|
||||
RiskEvent,
|
||||
RiskEventAction,
|
||||
Supplier,
|
||||
WorkTask,
|
||||
)
|
||||
from app.modules.business.service import serialize_model
|
||||
from app.modules.risk.constants import (
|
||||
RISK_SCORE_WEIGHTS,
|
||||
RiskEventActionKey,
|
||||
RiskEventActionValue,
|
||||
RiskGenerationAction,
|
||||
RiskGenerationResultKey,
|
||||
RiskEventPayloadKey,
|
||||
@@ -95,6 +104,142 @@ class RiskService:
|
||||
)
|
||||
return [serialize_model(item) for item in self.db.execute(stmt).scalars()]
|
||||
|
||||
def list_actions(self, risk_event_id: int, limit: int = 100) -> list[dict[str, Any]]:
|
||||
self._get_event(risk_event_id)
|
||||
stmt = (
|
||||
select(RiskEventAction)
|
||||
.where(RiskEventAction.risk_event_id == risk_event_id)
|
||||
.order_by(RiskEventAction.id.desc())
|
||||
.limit(bounded_limit(limit))
|
||||
)
|
||||
return [serialize_model(item) for item in self.db.execute(stmt).scalars()]
|
||||
|
||||
def assign_event(
|
||||
self,
|
||||
risk_event_id: int,
|
||||
assigned_to: str,
|
||||
comment: str | None = None,
|
||||
actor: str = ActorValue.API,
|
||||
) -> dict[str, Any]:
|
||||
record = self._get_event(risk_event_id)
|
||||
from_status = record.status
|
||||
record.assigned_to = assigned_to
|
||||
action = self._record_action(
|
||||
record,
|
||||
RiskEventActionValue.ASSIGN,
|
||||
actor,
|
||||
from_status,
|
||||
record.status,
|
||||
comment,
|
||||
{"assigned_to": assigned_to},
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
self.db.refresh(action)
|
||||
return self._action_response(record, action)
|
||||
|
||||
def comment_event(
|
||||
self,
|
||||
risk_event_id: int,
|
||||
comment: str,
|
||||
payload: dict[str, Any] | None = None,
|
||||
actor: str = ActorValue.API,
|
||||
) -> dict[str, Any]:
|
||||
record = self._get_event(risk_event_id)
|
||||
action = self._record_action(
|
||||
record,
|
||||
RiskEventActionValue.COMMENT,
|
||||
actor,
|
||||
record.status,
|
||||
record.status,
|
||||
comment,
|
||||
payload or {},
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
self.db.refresh(action)
|
||||
return self._action_response(record, action)
|
||||
|
||||
def resolve_event(
|
||||
self,
|
||||
risk_event_id: int,
|
||||
comment: str | None = None,
|
||||
payload: dict[str, Any] | None = None,
|
||||
actor: str = ActorValue.API,
|
||||
) -> dict[str, Any]:
|
||||
record = self._get_event(risk_event_id)
|
||||
from_status = record.status
|
||||
record.status = StatusValue.RESOLVED
|
||||
record.resolved_at = utc_now()
|
||||
action = self._record_action(
|
||||
record,
|
||||
RiskEventActionValue.RESOLVE,
|
||||
actor,
|
||||
from_status,
|
||||
record.status,
|
||||
comment,
|
||||
payload or {},
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
self.db.refresh(action)
|
||||
return self._action_response(record, action)
|
||||
|
||||
def close_event(
|
||||
self,
|
||||
risk_event_id: int,
|
||||
closed_reason: str,
|
||||
review_summary: str | None = None,
|
||||
actor: str = ActorValue.API,
|
||||
) -> dict[str, Any]:
|
||||
record = self._get_event(risk_event_id)
|
||||
from_status = record.status
|
||||
now = utc_now()
|
||||
record.status = StatusValue.CLOSED
|
||||
record.closed_reason = closed_reason
|
||||
record.review_summary = review_summary
|
||||
record.closed_at = now
|
||||
if record.resolved_at is None:
|
||||
record.resolved_at = now
|
||||
action = self._record_action(
|
||||
record,
|
||||
RiskEventActionValue.CLOSE,
|
||||
actor,
|
||||
from_status,
|
||||
record.status,
|
||||
closed_reason,
|
||||
{"review_summary": review_summary},
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
self.db.refresh(action)
|
||||
return self._action_response(record, action)
|
||||
|
||||
def reopen_event(
|
||||
self,
|
||||
risk_event_id: int,
|
||||
comment: str | None = None,
|
||||
actor: str = ActorValue.API,
|
||||
) -> dict[str, Any]:
|
||||
record = self._get_event(risk_event_id)
|
||||
from_status = record.status
|
||||
record.status = StatusValue.OPEN
|
||||
record.resolved_at = None
|
||||
record.closed_at = None
|
||||
action = self._record_action(
|
||||
record,
|
||||
RiskEventActionValue.REOPEN,
|
||||
actor,
|
||||
from_status,
|
||||
record.status,
|
||||
comment,
|
||||
{},
|
||||
)
|
||||
self.db.commit()
|
||||
self.db.refresh(record)
|
||||
self.db.refresh(action)
|
||||
return self._action_response(record, action)
|
||||
|
||||
def summary(self) -> dict[str, Any]:
|
||||
overdue_tasks = self.overdue_tasks()
|
||||
delayed_projects = self.delayed_projects()
|
||||
@@ -127,6 +272,62 @@ class RiskService:
|
||||
RiskSummaryKey.OPEN_EVENTS: open_events,
|
||||
}
|
||||
|
||||
def _get_event(self, risk_event_id: int) -> RiskEvent:
|
||||
record = self.db.get(RiskEvent, risk_event_id)
|
||||
if record is None:
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Risk event not found")
|
||||
return record
|
||||
|
||||
def _record_action(
|
||||
self,
|
||||
record: RiskEvent,
|
||||
action: str,
|
||||
actor: str,
|
||||
from_status: str | None,
|
||||
to_status: str | None,
|
||||
comment: str | None,
|
||||
payload: dict[str, Any],
|
||||
) -> RiskEventAction:
|
||||
action_record = RiskEventAction(
|
||||
code=f"RISK-ACTION-{utc_now():%Y%m%d%H%M%S%f}",
|
||||
risk_event_id=record.id,
|
||||
action=action,
|
||||
actor=actor,
|
||||
from_status=from_status,
|
||||
to_status=to_status,
|
||||
assigned_to=record.assigned_to,
|
||||
comment=comment,
|
||||
payload=payload,
|
||||
)
|
||||
self.db.add(action_record)
|
||||
AuditService(self.db).log(
|
||||
AuditLogCreate(
|
||||
actor=actor,
|
||||
source=AuditSource.RISK,
|
||||
action=AuditAction.RISK_EVENT_ACTION,
|
||||
target_type=BusinessDomain.RISK_EVENTS,
|
||||
target_id=str(record.id),
|
||||
risk_level=AuditRiskLevel.MEDIUM,
|
||||
request_payload={
|
||||
RiskEventActionKey.ACTION: action,
|
||||
"from_status": from_status,
|
||||
"to_status": to_status,
|
||||
"comment": comment,
|
||||
"payload": payload,
|
||||
},
|
||||
)
|
||||
)
|
||||
return action_record
|
||||
|
||||
@staticmethod
|
||||
def _action_response(record: RiskEvent, action: RiskEventAction) -> dict[str, Any]:
|
||||
return {
|
||||
RiskEventActionKey.RISK_EVENT: serialize_model(record),
|
||||
RiskEventActionKey.ACTION_RECORD: serialize_model(action),
|
||||
}
|
||||
|
||||
def generate_events(self, actor: str = ActorValue.API) -> dict[str, Any]:
|
||||
"""Generate or refresh risk-event ledger entries from current signals."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user