mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-26 20:48:12 +00:00
- Add STATUS_APPLIED and STATUS_DISMISSED constants to model - Add markApplied() and markDismissed() methods - Update event status after apply/dismiss actions (prevent duplicate ops) - Validate related_task_id exists and user has permission - Filter empty or overly long subtask names before creation Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
155 lines
3.5 KiB
PHP
155 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* App\Models\ProjectTaskAiEvent
|
|
*
|
|
* @property int $id
|
|
* @property int $task_id 任务ID
|
|
* @property string $event_type 事件类型
|
|
* @property string $status 状态
|
|
* @property int $retry_count 重试次数
|
|
* @property array|null $result 执行结果
|
|
* @property string|null $error 错误信息
|
|
* @property int $msg_id 消息ID
|
|
* @property \Illuminate\Support\Carbon|null $executed_at
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
*/
|
|
class ProjectTaskAiEvent extends AbstractModel
|
|
{
|
|
const EVENT_DESCRIPTION = 'description';
|
|
const EVENT_SUBTASKS = 'subtasks';
|
|
const EVENT_ASSIGNEE = 'assignee';
|
|
const EVENT_SIMILAR = 'similar';
|
|
|
|
const STATUS_PENDING = 'pending';
|
|
const STATUS_PROCESSING = 'processing';
|
|
const STATUS_COMPLETED = 'completed';
|
|
const STATUS_FAILED = 'failed';
|
|
const STATUS_SKIPPED = 'skipped';
|
|
const STATUS_APPLIED = 'applied';
|
|
const STATUS_DISMISSED = 'dismissed';
|
|
|
|
const MAX_RETRY = 3;
|
|
|
|
protected $table = 'project_task_ai_events';
|
|
|
|
protected $fillable = [
|
|
'task_id',
|
|
'event_type',
|
|
'status',
|
|
'retry_count',
|
|
'result',
|
|
'error',
|
|
'msg_id',
|
|
'executed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'result' => '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;
|
|
}
|
|
|
|
/**
|
|
* 标记为已采纳
|
|
*/
|
|
public function markApplied(): bool
|
|
{
|
|
return $this->update([
|
|
'status' => self::STATUS_APPLIED,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 标记为已忽略
|
|
*/
|
|
public function markDismissed(): bool
|
|
{
|
|
return $this->update([
|
|
'status' => self::STATUS_DISMISSED,
|
|
]);
|
|
}
|
|
}
|