diff --git a/app/Models/ProjectTaskAiEvent.php b/app/Models/ProjectTaskAiEvent.php new file mode 100644 index 000000000..4c1deb80e --- /dev/null +++ b/app/Models/ProjectTaskAiEvent.php @@ -0,0 +1,132 @@ + 'array', + 'executed_at' => 'datetime', + ]; + + /** + * 关联任务 + */ + public function task(): BelongsTo + { + return $this->belongsTo(ProjectTask::class, 'task_id', 'id'); + } + + /** + * 获取所有事件类型 + */ + public static function getEventTypes(): array + { + return [ + self::EVENT_DESCRIPTION, + self::EVENT_SUBTASKS, + self::EVENT_ASSIGNEE, + self::EVENT_SIMILAR, + ]; + } + + /** + * 标记为处理中 + */ + public function markProcessing(): bool + { + return $this->update([ + 'status' => self::STATUS_PROCESSING, + ]); + } + + /** + * 标记为完成 + */ + public function markCompleted(array $result, int $msgId = 0): bool + { + return $this->update([ + 'status' => self::STATUS_COMPLETED, + 'result' => $result, + 'msg_id' => $msgId, + 'executed_at' => now(), + ]); + } + + /** + * 标记为失败 + */ + public function markFailed(string $error): bool + { + return $this->update([ + 'status' => self::STATUS_FAILED, + 'retry_count' => $this->retry_count + 1, + 'error' => $error, + 'executed_at' => now(), + ]); + } + + /** + * 标记为跳过 + */ + public function markSkipped(string $reason = ''): bool + { + return $this->update([ + 'status' => self::STATUS_SKIPPED, + 'error' => $reason, + 'executed_at' => now(), + ]); + } + + /** + * 是否可以重试 + */ + public function canRetry(): bool + { + return $this->status === self::STATUS_FAILED + && $this->retry_count < self::MAX_RETRY; + } +}