更新
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\assistantservice\AssistantServiceAlert as AlertScanner;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
/** 扫描员工聊天和通话转写。不调用模型,不发送消息。 */
|
||||
final class AssistantServiceAlert extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('assistant-service:alert')->setDescription('扫描员工聊天和通话转写并写入行为预警;不调用模型或发送消息')
|
||||
->addOption('once', null, Option::VALUE_NONE, '只检查一轮')
|
||||
->addOption('sleep', null, Option::VALUE_REQUIRED, '检查轮询间隔秒数', '60');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
{
|
||||
$running = true;
|
||||
if (function_exists('pcntl_async_signals')) {
|
||||
pcntl_async_signals(true);
|
||||
pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; });
|
||||
pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; });
|
||||
}
|
||||
$pause = max(1, min(60, (int) $input->getOption('sleep')));
|
||||
$scanner = new AlertScanner();
|
||||
do {
|
||||
$result = $scanner->tick();
|
||||
$output->writeln('ASSISTANT_SERVICE_ALERT state=' . $result['state'] . ' scanned=' . $result['scanned']
|
||||
. ' created=' . $result['created']);
|
||||
if (in_array($result['state'], ['error', 'unavailable'], true)) {
|
||||
try { Db::connect()->close(); } catch (\Throwable $ignored) {}
|
||||
if ($input->getOption('once')) { return 1; }
|
||||
}
|
||||
if (!$input->getOption('once') && $running) { sleep($pause); }
|
||||
} while (!$input->getOption('once') && $running);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\assistantservice\AssistantServiceAutomation;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
final class AssistantServiceAuto extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('assistant-service:auto')->setDescription('按真实来源自动发现医助分析任务;独立消费者处理模型调用')
|
||||
->addOption('once', null, Option::VALUE_NONE, '只检查一轮')
|
||||
->addOption('sleep', null, Option::VALUE_REQUIRED, '检查轮询间隔秒数', '60');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
{
|
||||
$running = true;
|
||||
if (function_exists('pcntl_async_signals')) {
|
||||
pcntl_async_signals(true);
|
||||
pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; });
|
||||
pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; });
|
||||
}
|
||||
$pause = max(1, min(60, (int) $input->getOption('sleep')));
|
||||
$automation = new AssistantServiceAutomation();
|
||||
do {
|
||||
$result = $automation->tick();
|
||||
$output->writeln('ASSISTANT_SERVICE_AUTO state=' . $result['state'] . ' scanned=' . $result['scanned'] . ' enqueued=' . $result['enqueued']);
|
||||
if ($result['state'] === 'error') {
|
||||
try { Db::connect()->close(); } catch (\Throwable $ignored) {}
|
||||
if ($input->getOption('once')) { return 1; }
|
||||
}
|
||||
if (!$input->getOption('once') && $running) { sleep($pause); }
|
||||
} while (!$input->getOption('once') && $running);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\assistantservice\AssistantServiceDailyContact;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
/** 独立于 AI 消费者的当日计划调度,不发送消息。 */
|
||||
final class AssistantServiceDaily extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('assistant-service:daily')->setDescription('固化上海今日联系计划并复核来源状态;不调用模型或发送消息')
|
||||
->addOption('once', null, Option::VALUE_NONE, '只检查一轮')
|
||||
->addOption('sleep', null, Option::VALUE_REQUIRED, '检查轮询间隔秒数', '60');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
{
|
||||
$running = true;
|
||||
if (function_exists('pcntl_async_signals')) {
|
||||
pcntl_async_signals(true);
|
||||
pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; });
|
||||
pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; });
|
||||
}
|
||||
$pause = max(1, min(60, (int) $input->getOption('sleep')));
|
||||
$planner = new AssistantServiceDailyContact();
|
||||
do {
|
||||
$result = $planner->tick();
|
||||
$output->writeln('ASSISTANT_SERVICE_DAILY state=' . $result['state'] . ' scanned=' . $result['scanned']
|
||||
. ' created=' . $result['created'] . ' exempted=' . $result['exempted']);
|
||||
if ($result['state'] === 'error') {
|
||||
try { Db::connect()->close(); } catch (\Throwable $ignored) {}
|
||||
if ($input->getOption('once')) { return 1; }
|
||||
}
|
||||
if (!$input->getOption('once') && $running) { sleep($pause); }
|
||||
} while (!$input->getOption('once') && $running);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\assistantservice\AssistantServiceWorker;
|
||||
use app\common\service\assistantservice\AssistantServiceAutomation;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
final class AssistantServiceWork extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('assistant-service:work')->setDescription('医助服务持久队列;未知执行结果不自动重试')
|
||||
->addOption('once', null, Option::VALUE_NONE, '只处理一轮')
|
||||
->addOption('sleep', null, Option::VALUE_REQUIRED, '空闲轮询间隔秒数', '3');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
{
|
||||
$running = true;
|
||||
if (function_exists('pcntl_async_signals')) {
|
||||
pcntl_async_signals(true);
|
||||
pcntl_signal(SIGTERM, static function () use (&$running): void { $running = false; });
|
||||
pcntl_signal(SIGINT, static function () use (&$running): void { $running = false; });
|
||||
}
|
||||
$pause = max(1, min(60, (int) $input->getOption('sleep')));
|
||||
$worker = new AssistantServiceWorker();
|
||||
try { do {
|
||||
$worked = false;
|
||||
try {
|
||||
$this->heartbeat('working');
|
||||
$worked = $worker->runOnce();
|
||||
$this->heartbeat('idle');
|
||||
if ($worked || $input->getOption('once')) { $output->writeln('ASSISTANT_SERVICE processed=' . ($worked ? '1' : '0')); }
|
||||
} catch (\Throwable $e) {
|
||||
$this->heartbeat('error');
|
||||
$output->writeln('ASSISTANT_SERVICE storage_or_configuration_error');
|
||||
try { Db::connect()->close(); } catch (\Throwable $ignored) {}
|
||||
if ($input->getOption('once')) { return 1; }
|
||||
}
|
||||
if (!$input->getOption('once') && $running && !$worked) { sleep($pause); }
|
||||
} while (!$input->getOption('once') && $running);
|
||||
} finally { $this->heartbeat('stopped'); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function heartbeat(string $phase): void
|
||||
{
|
||||
// 心跳存储故障不能改变原消费者生成/提交语义;总览将显示心跳缺失。
|
||||
try { AssistantServiceAutomation::workerHeartbeat($phase); } catch (\Throwable $ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace app\command;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\DiagnosisTodo;
|
||||
use app\common\service\assistantservice\AssistantServiceReminderRecipient;
|
||||
use app\common\service\wechat\WechatWorkAppMessageService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
@@ -26,7 +27,7 @@ use think\facade\Log;
|
||||
* 行为:
|
||||
* 1. 取出 status=0 且 remind_time<=now 的待办,按 remind_time asc,限 200 条
|
||||
* 2. 每条用乐观锁 (update set status=1 where id=? and status=0) 抢占,避免并发重复推送
|
||||
* 3. 找创建人 admin.work_wechat_userid,未绑定 → status=3 + error
|
||||
* 3. 普通提醒找创建人,医助服务跟进找当前有权访问患者的执行人;未绑定 → status=3 + error
|
||||
* 4. 调 WechatWorkAppMessageService::sendTextToUser,失败 → status=3 + error(终态,不重试)
|
||||
* 5. 整批不中断;输出 处理 N / 成功 X / 失败 Y / 跳过未绑定 Z
|
||||
*/
|
||||
@@ -38,7 +39,7 @@ class DiagnosisTodoNotify extends Command
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('tcm:diagnosis-todo-notify')
|
||||
->setDescription('诊单待办事项:扫描到点的待执行项并向创建人发送企业微信消息');
|
||||
->setDescription('诊单待办事项:普通提醒发给创建人,医助服务跟进发给执行人');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output): int
|
||||
@@ -52,7 +53,7 @@ class DiagnosisTodoNotify extends Command
|
||||
$totalSent = 0;
|
||||
$totalFailed = 0;
|
||||
$totalSkipped = 0; // 被并发抢占
|
||||
$totalUnbound = 0; // 创建人未绑定企微(计入 failed)
|
||||
$totalUnbound = 0; // 收件人未绑定企微(计入 failed)
|
||||
|
||||
try {
|
||||
$todoTable = (new DiagnosisTodo())->getTable();
|
||||
@@ -91,15 +92,15 @@ class DiagnosisTodoNotify extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
// 取创建人 work_wechat_userid
|
||||
$creatorId = (int) ($row['creator_id'] ?? 0);
|
||||
// 模块任务按执行人发送,并重检当前患者访问权限;保留真实创建人审计。
|
||||
$recipientId = AssistantServiceReminderRecipient::resolve($row);
|
||||
$wxId = '';
|
||||
if ($creatorId > 0) {
|
||||
$wxId = (string) Admin::where('id', $creatorId)->value('work_wechat_userid');
|
||||
if ($recipientId > 0) {
|
||||
$wxId = (string) Admin::where('id', $recipientId)->value('work_wechat_userid');
|
||||
}
|
||||
|
||||
if ($wxId === '') {
|
||||
$this->markFailed($todoTable, $todoId, '创建人未绑定企业微信 userid');
|
||||
$this->markFailed($todoTable, $todoId, '提醒收件人未绑定企业微信 userid');
|
||||
$totalUnbound++;
|
||||
$totalFailed++;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user