mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-26 04:18:29 +00:00
no message
This commit is contained in:
parent
270ddc6487
commit
c388fe373d
@ -3,6 +3,7 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\WebSocketDialogMsg;
|
use App\Models\WebSocketDialogMsg;
|
||||||
|
use App\Module\Apps;
|
||||||
use App\Module\ZincSearch\ZincSearchKeyValue;
|
use App\Module\ZincSearch\ZincSearchKeyValue;
|
||||||
use App\Module\ZincSearch\ZincSearchDialogMsg;
|
use App\Module\ZincSearch\ZincSearchDialogMsg;
|
||||||
use Cache;
|
use Cache;
|
||||||
@ -27,6 +28,11 @@ class SyncUserMsgToZincSearch extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
if (!Apps::isInstalled("search")) {
|
||||||
|
$this->error("应用「ZincSearch」未安装");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// 注册信号处理器(仅在支持pcntl扩展的环境下)
|
// 注册信号处理器(仅在支持pcntl扩展的环境下)
|
||||||
if (extension_loaded('pcntl')) {
|
if (extension_loaded('pcntl')) {
|
||||||
pcntl_async_signals(true); // 启用异步信号处理
|
pcntl_async_signals(true); // 启用异步信号处理
|
||||||
|
|||||||
@ -51,6 +51,7 @@ class Apps
|
|||||||
'office' => 'OnlyOffice',
|
'office' => 'OnlyOffice',
|
||||||
'drawio' => 'Drawio',
|
'drawio' => 'Drawio',
|
||||||
'minder' => 'Minder',
|
'minder' => 'Minder',
|
||||||
|
'search' => 'ZincSearch',
|
||||||
default => $appId,
|
default => $appId,
|
||||||
};
|
};
|
||||||
throw new ApiException("应用「{$name}」未安装");
|
throw new ApiException("应用「{$name}」未安装");
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Module\ZincSearch;
|
namespace App\Module\ZincSearch;
|
||||||
|
|
||||||
|
use App\Module\Apps;
|
||||||
|
use App\Module\Doo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZincSearch 公共类
|
* ZincSearch 公共类
|
||||||
*/
|
*/
|
||||||
@ -28,6 +31,13 @@ class ZincSearchBase
|
|||||||
*/
|
*/
|
||||||
private function request($path, $body = null, $method = 'POST')
|
private function request($path, $body = null, $method = 'POST')
|
||||||
{
|
{
|
||||||
|
if (!Apps::isInstalled("search")) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'error' => Doo::translate("应用「ZincSearch」未安装")
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, "http://{$this->host}:{$this->port}{$path}");
|
curl_setopt($ch, CURLOPT_URL, "http://{$this->host}:{$this->port}{$path}");
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||||
@ -38,7 +48,6 @@ class ZincSearchBase
|
|||||||
$headers = ['Content-Type: application/json'];
|
$headers = ['Content-Type: application/json'];
|
||||||
if ($method === 'BULK') {
|
if ($method === 'BULK') {
|
||||||
$headers = ['Content-Type: text/plain'];
|
$headers = ['Content-Type: text/plain'];
|
||||||
$method = 'POST';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|||||||
@ -4,9 +4,10 @@ namespace App\Module\ZincSearch;
|
|||||||
|
|
||||||
use App\Models\WebSocketDialogMsg;
|
use App\Models\WebSocketDialogMsg;
|
||||||
use App\Models\WebSocketDialogUser;
|
use App\Models\WebSocketDialogUser;
|
||||||
|
use App\Module\Apps;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Swoole\Coroutine;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZincSearch 会话消息类
|
* ZincSearch 会话消息类
|
||||||
@ -129,6 +130,11 @@ class ZincSearchDialogMsg
|
|||||||
*/
|
*/
|
||||||
public static function search(string $userid, string $keyword, int $from = 0, int $size = 20): array
|
public static function search(string $userid, string $keyword, int $from = 0, int $size = 20): array
|
||||||
{
|
{
|
||||||
|
if (!Apps::isInstalled("search")) {
|
||||||
|
// 如果搜索功能未安装,使用数据库查询
|
||||||
|
return self::searchByMysql($userid, $keyword, $from, $size);
|
||||||
|
}
|
||||||
|
|
||||||
$searchParams = [
|
$searchParams = [
|
||||||
'query' => [
|
'query' => [
|
||||||
'bool' => [
|
'bool' => [
|
||||||
@ -144,7 +150,6 @@ class ZincSearchDialogMsg
|
|||||||
['updated_at' => 'desc']
|
['updated_at' => 'desc']
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = ZincSearchBase::elasticSearch(self::$indexNameMsg, $searchParams);
|
$result = ZincSearchBase::elasticSearch(self::$indexNameMsg, $searchParams);
|
||||||
$hits = $result['data']['hits']['hits'] ?? [];
|
$hits = $result['data']['hits']['hits'] ?? [];
|
||||||
@ -184,6 +189,48 @@ class ZincSearchDialogMsg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID和消息关键词搜索会话(MySQL 版本,主要用于未安装ZincSearch的情况)
|
||||||
|
*
|
||||||
|
* @param string $userid 用户ID
|
||||||
|
* @param string $keyword 消息关键词
|
||||||
|
* @param int $from 起始位置
|
||||||
|
* @param int $size 返回结果数量
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function searchByMysql(string $userid, string $keyword, int $from = 0, int $size = 20): array
|
||||||
|
{
|
||||||
|
$items = DB::table('web_socket_dialog_users as u')
|
||||||
|
->select(['d.*', 'u.top_at', 'u.last_at', 'u.mark_unread', 'u.silence', 'u.hide', 'u.color', 'u.updated_at as user_at', 'm.id as search_msg_id'])
|
||||||
|
->join('web_socket_dialogs as d', 'u.dialog_id', '=', 'd.id')
|
||||||
|
->join('web_socket_dialog_msgs as m', 'm.dialog_id', '=', 'd.id')
|
||||||
|
->where('u.userid', $userid)
|
||||||
|
->where('m.bot', 0)
|
||||||
|
->whereNull('d.deleted_at')
|
||||||
|
->where('m.key', 'like', "%{$keyword}%")
|
||||||
|
->orderByDesc('m.id')
|
||||||
|
->offset($from)
|
||||||
|
->limit($size)
|
||||||
|
->get()
|
||||||
|
->all();
|
||||||
|
$msgs = [];
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$msgs[] = [
|
||||||
|
'id' => $item->id,
|
||||||
|
'search_msg_id' => $item->search_msg_id,
|
||||||
|
'user_at' => Carbon::parse($item->user_at)->format('Y-m-d H:i:s'),
|
||||||
|
|
||||||
|
'mark_unread' => $item->mark_unread,
|
||||||
|
'silence' => $item->silence,
|
||||||
|
'hide' => $item->hide,
|
||||||
|
'color' => $item->color,
|
||||||
|
'top_at' => Carbon::parse($item->top_at)->format('Y-m-d H:i:s'),
|
||||||
|
'last_at' => Carbon::parse($item->last_at)->format('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $msgs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据对话用户ID搜索用户信息
|
* 根据对话用户ID搜索用户信息
|
||||||
* @param array $dialogUserids
|
* @param array $dialogUserids
|
||||||
|
|||||||
@ -4,6 +4,7 @@ namespace App\Tasks;
|
|||||||
|
|
||||||
use App\Models\WebSocketDialogMsg;
|
use App\Models\WebSocketDialogMsg;
|
||||||
use App\Models\WebSocketDialogUser;
|
use App\Models\WebSocketDialogUser;
|
||||||
|
use App\Module\Apps;
|
||||||
use App\Module\ZincSearch\ZincSearchDialogMsg;
|
use App\Module\ZincSearch\ZincSearchDialogMsg;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
@ -26,6 +27,11 @@ class ZincSearchSyncTask extends AbstractTask
|
|||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
{
|
{
|
||||||
|
if (!Apps::isInstalled("search")) {
|
||||||
|
// 如果没有安装搜索模块,则不执行
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->action) {
|
switch ($this->action) {
|
||||||
case 'sync':
|
case 'sync':
|
||||||
// 同步消息数据
|
// 同步消息数据
|
||||||
|
|||||||
@ -80,23 +80,6 @@ services:
|
|||||||
- extnetwork
|
- extnetwork
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
search:
|
|
||||||
container_name: "dootask-search-${APP_ID}"
|
|
||||||
image: "public.ecr.aws/zinclabs/zincsearch:0.4.10"
|
|
||||||
volumes:
|
|
||||||
- search_data:/data
|
|
||||||
environment:
|
|
||||||
ZINC_DATA_PATH: "/data"
|
|
||||||
ZINC_FIRST_ADMIN_USER: "${DB_USERNAME}"
|
|
||||||
ZINC_FIRST_ADMIN_PASSWORD: "${DB_PASSWORD}"
|
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
cpus: '2'
|
|
||||||
networks:
|
|
||||||
- extnetwork
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
appstore:
|
appstore:
|
||||||
container_name: "dootask-appstore-${APP_ID}"
|
container_name: "dootask-appstore-${APP_ID}"
|
||||||
privileged: true
|
privileged: true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user