mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-27 21:28:12 +00:00
- 优化后端提示词:描述生成、子任务拆分、负责人推荐,新增栏目信息,去掉无效的 similar_count
- 优化前端提示词:去掉硬性字数限制,即时消息改为简短输出
- 新增 :::ai-action{...}::: 语法处理,支持单独采纳/忽略 assignee 和 similar
- 采纳/忽略后更新消息状态显示
- 负责人改为追加模式,保留现有负责人
- 新增任务关联功能,similar 采纳时自动创建双向关联
- 相似度阈值从 0.7 调整为 0.5,搜索结果增加到 200
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>
189 lines
6.5 KiB
PHP
189 lines
6.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Module\Base;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* App\Models\ProjectTaskRelation
|
|
*
|
|
* @property int $id
|
|
* @property int $task_id 任务ID
|
|
* @property int $related_task_id 关联任务ID
|
|
* @property string $direction 关系方向: mention/mentioned_by
|
|
* @property int|null $dialog_id 来源会话ID
|
|
* @property int|null $msg_id 来源消息ID
|
|
* @property int|null $userid 提及人
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\ProjectTask|null $relatedTask
|
|
* @property-read \App\Models\ProjectTask|null $task
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelAppend()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel cancelHidden()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel change($array)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel remove()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereDialogId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereDirection($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereMsgId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereRelatedTaskId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereTaskId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|ProjectTaskRelation whereUserid($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class ProjectTaskRelation extends AbstractModel
|
|
{
|
|
public const DIRECTION_MENTION = 'mention';
|
|
public const DIRECTION_MENTIONED_BY = 'mentioned_by';
|
|
|
|
protected $fillable = [
|
|
'task_id',
|
|
'related_task_id',
|
|
'direction',
|
|
'dialog_id',
|
|
'msg_id',
|
|
'userid',
|
|
];
|
|
|
|
public function task(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProjectTask::class, 'task_id');
|
|
}
|
|
|
|
public function relatedTask(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ProjectTask::class, 'related_task_id');
|
|
}
|
|
|
|
/**
|
|
* 创建双向任务关联
|
|
*
|
|
* @param int $sourceTaskId 源任务ID
|
|
* @param int $targetTaskId 目标任务ID
|
|
* @param int|null $dialogId 来源对话ID
|
|
* @param int|null $msgId 来源消息ID
|
|
* @param int|null $userid 操作人
|
|
* @param bool $push 是否推送更新
|
|
* @return bool 是否创建成功
|
|
*/
|
|
public static function createRelation(
|
|
int $sourceTaskId,
|
|
int $targetTaskId,
|
|
?int $dialogId = null,
|
|
?int $msgId = null,
|
|
?int $userid = null,
|
|
bool $push = true
|
|
): bool {
|
|
if ($sourceTaskId === $targetTaskId) {
|
|
return false;
|
|
}
|
|
|
|
$sourceTask = ProjectTask::with('project')->find($sourceTaskId);
|
|
$targetTask = ProjectTask::with('project')->find($targetTaskId);
|
|
|
|
if (!$sourceTask || !$targetTask) {
|
|
return false;
|
|
}
|
|
|
|
if ($sourceTask->deleted_at || $targetTask->deleted_at) {
|
|
return false;
|
|
}
|
|
|
|
// 创建正向关联:源任务提及目标任务
|
|
$mentionRelation = static::updateOrCreate(
|
|
[
|
|
'task_id' => $sourceTaskId,
|
|
'related_task_id' => $targetTaskId,
|
|
'direction' => self::DIRECTION_MENTION,
|
|
],
|
|
[
|
|
'dialog_id' => $dialogId,
|
|
'msg_id' => $msgId,
|
|
'userid' => $userid,
|
|
]
|
|
);
|
|
|
|
// 创建反向关联:目标任务被源任务提及
|
|
$reverseRelation = static::updateOrCreate(
|
|
[
|
|
'task_id' => $targetTaskId,
|
|
'related_task_id' => $sourceTaskId,
|
|
'direction' => self::DIRECTION_MENTIONED_BY,
|
|
],
|
|
[
|
|
'dialog_id' => $dialogId,
|
|
'msg_id' => $msgId,
|
|
'userid' => $userid,
|
|
]
|
|
);
|
|
|
|
// 推送关联更新
|
|
if ($push) {
|
|
$needPush = $mentionRelation->wasRecentlyCreated || $mentionRelation->wasChanged()
|
|
|| $reverseRelation->wasRecentlyCreated || $reverseRelation->wasChanged();
|
|
|
|
if ($needPush) {
|
|
if ($sourceTask->project) {
|
|
$sourceTask->pushMsg('relation', null, null, false);
|
|
}
|
|
if ($targetTask->project) {
|
|
$targetTask->pushMsg('relation', null, null, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function recordMentionsFromMessage(WebSocketDialogMsg $msg): void
|
|
{
|
|
if ($msg->type !== 'text') {
|
|
return;
|
|
}
|
|
|
|
$payload = $msg->msg;
|
|
if (!is_array($payload)) {
|
|
$payload = Base::json2array($msg->getRawOriginal('msg'));
|
|
}
|
|
|
|
$text = $payload['text'] ?? '';
|
|
if (!$text || !preg_match_all('/<span class="mention task" data-id="(\d+)">#?(.*?)<\/span>/i', $text, $matches)) {
|
|
return;
|
|
}
|
|
|
|
$targetIds = array_values(array_unique(array_filter(array_map('intval', $matches[1] ?? []))));
|
|
if (empty($targetIds)) {
|
|
return;
|
|
}
|
|
|
|
$sourceTaskIds = ProjectTask::whereDialogId($msg->dialog_id)
|
|
->whereNull('deleted_at')
|
|
->pluck('id')
|
|
->toArray();
|
|
|
|
if (empty($sourceTaskIds)) {
|
|
return;
|
|
}
|
|
|
|
foreach ($sourceTaskIds as $sourceTaskId) {
|
|
foreach ($targetIds as $targetId) {
|
|
self::createRelation(
|
|
$sourceTaskId,
|
|
$targetId,
|
|
$msg->dialog_id,
|
|
$msg->id,
|
|
$msg->userid
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|