mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 12:42:51 +00:00
perf: AI机器人支持多会话
This commit is contained in:
parent
30d88761b4
commit
0272933f70
@ -541,6 +541,8 @@ class DialogController extends AbstractController
|
|||||||
//
|
//
|
||||||
if ($session_id > 0) {
|
if ($session_id > 0) {
|
||||||
$builder->whereSessionId($session_id);
|
$builder->whereSessionId($session_id);
|
||||||
|
} elseif ($dialog->session_id > 0) {
|
||||||
|
$builder->whereSessionId($dialog->session_id);
|
||||||
}
|
}
|
||||||
if ($msg_type) {
|
if ($msg_type) {
|
||||||
if ($msg_type === 'tag') {
|
if ($msg_type === 'tag') {
|
||||||
|
|||||||
@ -19,6 +19,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string|null $type 对话类型
|
* @property string|null $type 对话类型
|
||||||
* @property string|null $group_type 聊天室类型
|
* @property string|null $group_type 聊天室类型
|
||||||
|
* @property int|null $session_id 会话ID(最新)
|
||||||
* @property string|null $name 对话名称
|
* @property string|null $name 对话名称
|
||||||
* @property string $avatar 头像(群)
|
* @property string $avatar 头像(群)
|
||||||
* @property int|null $owner_id 群主用户ID
|
* @property int|null $owner_id 群主用户ID
|
||||||
@ -48,6 +49,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereLinkId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereLinkId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereName($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereName($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereOwnerId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereOwnerId($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereSessionId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereTopMsgId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereTopMsgId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereTopUserid($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereTopUserid($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereType($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialog whereType($value)
|
||||||
|
|||||||
@ -7,7 +7,6 @@ namespace App\Models;
|
|||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $dialog_id 对话ID
|
* @property int $dialog_id 对话ID
|
||||||
* @property int $userid 用户ID
|
|
||||||
* @property string $title 会话标题
|
* @property string $title 会话标题
|
||||||
* @property \Illuminate\Support\Carbon|null $created_at
|
* @property \Illuminate\Support\Carbon|null $created_at
|
||||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
@ -27,7 +26,6 @@ namespace App\Models;
|
|||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereId($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereTitle($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereTitle($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereUpdatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereUpdatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|WebSocketDialogSession whereUserid($value)
|
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
*/
|
*/
|
||||||
class WebSocketDialogSession extends AbstractModel
|
class WebSocketDialogSession extends AbstractModel
|
||||||
@ -50,12 +48,4 @@ class WebSocketDialogSession extends AbstractModel
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(WebSocketDialog::class, 'dialog_id');
|
return $this->belongsTo(WebSocketDialog::class, 'dialog_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取关联的用户
|
|
||||||
*/
|
|
||||||
public function user()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(User::class, 'userid');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class WebSocketDialogsAddSessionId extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('web_socket_dialogs', function (Blueprint $table) {
|
||||||
|
if (!Schema::hasColumn('web_socket_dialogs', 'session_id')) {
|
||||||
|
$table->bigInteger('session_id')->index()->nullable()->default(0)->after('group_type')->comment('会话ID(最新)');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('web_socket_dialogs', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('session_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\WebSocketDialog;
|
||||||
|
use App\Models\WebSocketDialogMsg;
|
||||||
|
use App\Models\WebSocketDialogSession;
|
||||||
|
use App\Module\Base;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
@ -13,14 +17,31 @@ class CreateWebSocketDialogSessionsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
if (!Schema::hasTable('web_socket_dialog_sessions')) {
|
if (Schema::hasTable('web_socket_dialog_sessions')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Schema::create('web_socket_dialog_sessions', function (Blueprint $table) {
|
Schema::create('web_socket_dialog_sessions', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->bigInteger('dialog_id')->unsigned()->index()->comment('对话ID');
|
$table->bigInteger('dialog_id')->unsigned()->index()->comment('对话ID');
|
||||||
$table->bigInteger('userid')->unsigned()->index()->comment('用户ID');
|
|
||||||
$table->string('title', 255)->default('')->comment('会话标题');
|
$table->string('title', 255)->default('')->comment('会话标题');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
$list = WebSocketDialog::select(['web_socket_dialogs.*', 'u.email'])
|
||||||
|
->join('web_socket_dialog_users as du', 'web_socket_dialogs.id', '=', 'du.dialog_id')
|
||||||
|
->join('users as u', 'du.userid', '=', 'u.userid')
|
||||||
|
->where('u.email', 'like', 'ai-%@bot.system')
|
||||||
|
->where('web_socket_dialogs.type', 'user')
|
||||||
|
->get();
|
||||||
|
foreach ($list as $item) {
|
||||||
|
$title = WebSocketDialogMsg::whereDialogId($item->id)->where('key', '!=', '')->orderBy('id')->value('key');
|
||||||
|
$session = WebSocketDialogSession::create([
|
||||||
|
'dialog_id' => $item->id,
|
||||||
|
'title' => $title ? Base::cutStr($title, 100) : 'Unknown',
|
||||||
|
]);
|
||||||
|
$session->save();
|
||||||
|
$item->session_id = $session->id;
|
||||||
|
$item->save();
|
||||||
|
WebSocketDialogMsg::whereDialogId($item->id)->update(['session_id' => $session->id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user