```
refactor: 移除审批和回写功能模块 移除了整个审批(approvals)和官方回写(writebacks)功能模块, 包括相关模型、路由、服务和配置项。更新了数据库迁移文件, 删除了相关的审批请求表和官方回写运行表。同时从API路由器中 移除了相应的路由,并调整了安全常量和字段验证器以匹配变更。 ```
This commit is contained in:
@@ -8,30 +8,23 @@ class EventStatus(StrEnum):
|
||||
|
||||
|
||||
class EventType(StrEnum):
|
||||
APPROVAL_DECIDED = "approval.decided"
|
||||
RISK_ACTION_RECORDED = "risk.action_recorded"
|
||||
REPORT_PUSH_SUCCEEDED = "report.push_succeeded"
|
||||
REPORT_PUSH_FAILED = "report.push_failed"
|
||||
LEGACY_SYNC_COMPLETED = "legacy.sync_completed"
|
||||
WRITEBACK_REQUESTED = "writeback.requested"
|
||||
WRITEBACK_SUBMITTED = "writeback.submitted"
|
||||
|
||||
|
||||
class EventSource(StrEnum):
|
||||
APPROVAL = "approval"
|
||||
RISK = "risk"
|
||||
REPORTS = "reports"
|
||||
LEGACY_MYSQL = "legacy_mysql"
|
||||
WRITEBACK = "writeback"
|
||||
API = "api"
|
||||
|
||||
|
||||
class EventAggregateType(StrEnum):
|
||||
APPROVAL = "approval"
|
||||
RISK_EVENT = "risk-event"
|
||||
REPORT_PUSH_RUN = "report-push-run"
|
||||
LEGACY_SYNC_RUN = "legacy-sync-run"
|
||||
WRITEBACK_RUN = "writeback-run"
|
||||
|
||||
|
||||
class EventResponseKey(StrEnum):
|
||||
@@ -43,10 +36,8 @@ class EventResponseKey(StrEnum):
|
||||
class EventPayloadKey(StrEnum):
|
||||
ACTION = "action"
|
||||
STATUS = "status"
|
||||
TICKET_ID = "ticket_id"
|
||||
DOMAIN = "domain"
|
||||
RECORD_ID = "record_id"
|
||||
APPROVED = "approved"
|
||||
COMMENT = "comment"
|
||||
CODE = "code"
|
||||
CREATED = "created"
|
||||
|
||||
@@ -2,6 +2,7 @@ from fastapi import APIRouter, Depends, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.operation_guard import require_operations_enabled
|
||||
from app.core.security import require_api_key
|
||||
from app.modules.events.constants import EventResponseKey
|
||||
from app.modules.events.service import EventService, _serialize_event
|
||||
@@ -30,6 +31,7 @@ def dispatch_event(
|
||||
event_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict:
|
||||
require_operations_enabled()
|
||||
return {EventResponseKey.EVENT: _serialize_event(EventService(db).dispatch_event(event_id))}
|
||||
|
||||
|
||||
@@ -38,4 +40,5 @@ def dispatch_pending(
|
||||
limit: int = Query(default=100, ge=1, le=500),
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict:
|
||||
require_operations_enabled()
|
||||
return {EventResponseKey.ITEMS: EventService(db).dispatch_pending(limit=limit)}
|
||||
|
||||
@@ -131,9 +131,6 @@ class EventService:
|
||||
def _handle_event(self, record: DomainEvent) -> None:
|
||||
if record.event_type == EventType.RISK_ACTION_RECORDED:
|
||||
self._handle_risk_action(record)
|
||||
return
|
||||
if record.event_type in {EventType.WRITEBACK_REQUESTED, EventType.WRITEBACK_SUBMITTED}:
|
||||
self._handle_writeback(record)
|
||||
|
||||
def _handle_risk_action(self, record: DomainEvent) -> None:
|
||||
from app.modules.risk.constants import RiskEventActionValue
|
||||
@@ -157,28 +154,3 @@ class EventService:
|
||||
actor=record.actor,
|
||||
payload=payload,
|
||||
)
|
||||
|
||||
def _handle_writeback(self, record: DomainEvent) -> None:
|
||||
from app.modules.workflows.service import WorkflowService
|
||||
from app.modules.workflows.constants import WorkflowStatus, WorkflowType
|
||||
from app.modules.writebacks.constants import WritebackStatus
|
||||
|
||||
payload = record.payload or {}
|
||||
run_status = str(payload.get(EventPayloadKey.STATUS) or "")
|
||||
if run_status == WritebackStatus.SENT:
|
||||
workflow_status = WorkflowStatus.COMPLETED
|
||||
elif run_status == WritebackStatus.FAILED:
|
||||
workflow_status = WorkflowStatus.FAILED
|
||||
elif run_status == WritebackStatus.DISABLED:
|
||||
workflow_status = WorkflowStatus.BLOCKED
|
||||
else:
|
||||
workflow_status = WorkflowStatus.WAITING_APPROVAL
|
||||
WorkflowService(self.db).start_or_update(
|
||||
workflow_type=WorkflowType.OFFICIAL_WRITEBACK,
|
||||
aggregate_type=EventAggregateType.WRITEBACK_RUN,
|
||||
aggregate_id=record.aggregate_id,
|
||||
status_value=workflow_status,
|
||||
action=record.event_type,
|
||||
actor=record.actor,
|
||||
payload=payload,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user