Merge branch 'master' of http://git.zhenyangtang.com.cn/ZYT/zyt
This commit is contained in:
@@ -19,6 +19,7 @@ use app\adminapi\lists\tcm\DiagnosisLists;
|
||||
use app\adminapi\logic\order\OrderActionLogLogic;
|
||||
use app\adminapi\logic\tcm\DiagnosisAiLogic;
|
||||
use app\adminapi\logic\tcm\DiagnosisLogic;
|
||||
use app\adminapi\logic\tcm\TongueScreenshotLogic;
|
||||
use app\adminapi\logic\tcm\PatientAiReportLogic;
|
||||
use app\adminapi\logic\tcm\TrackingNoteLogic;
|
||||
use app\adminapi\service\AssistantSseProtocol;
|
||||
@@ -913,8 +914,27 @@ class DiagnosisController extends BaseAdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 基于当前授权诊单向 AI 助手提问,不接收客户端上游配置
|
||||
* @notes 由指定模型临时分析本次视频截图的可见舌象及待核实辨证,不写入诊单
|
||||
*/
|
||||
public function aiTongueScreenshot()
|
||||
{
|
||||
if (!$this->request->isPost()) return $this->fail('请使用 POST 上传视频截图');
|
||||
try {
|
||||
$files = $this->request->file();
|
||||
if (!is_array($files) || array_keys($files) !== ['file']) {
|
||||
return $this->fail('请上传一张 JPEG 视频截图');
|
||||
}
|
||||
// Preserve exact enum/type values for the narrow multipart contract.
|
||||
$result = TongueScreenshotLogic::analyze($this->request->post(false), $files['file'],
|
||||
(int) $this->adminId, $this->adminInfo);
|
||||
return $result === null ? $this->fail(TongueScreenshotLogic::getError()) : $this->data($result);
|
||||
} catch (\Throwable $error) {
|
||||
// Framework upload exceptions can include private temporary paths.
|
||||
return $this->fail('截图上传失败,请重新截图后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/** 基于当前授权诊单向 AI 助手提问,不接收客户端上游配置。 */
|
||||
public function aiAssistant()
|
||||
{
|
||||
$params = (new DiagnosisValidate())->post()->goCheck('aiAssistant');
|
||||
|
||||
@@ -80,6 +80,14 @@ class AuthMiddleware
|
||||
// 当前访问路径
|
||||
$accessUri = strtolower($request->controller() . '/' . $request->action());
|
||||
|
||||
// Screenshot analysis shares the assistant grant and must never use the
|
||||
// unregistered-route bypass, even before menus have been synchronized.
|
||||
if ($accessUri === 'tcm.diagnosis/aitonguescreenshot') {
|
||||
$uris = $this->formatUrl($adminAuthCache->getAdminUri() ?? []);
|
||||
return in_array('tcm.diagnosis/aiassistant', $uris, true)
|
||||
? $next($request) : JsonService::fail('权限不足,无法使用诊单 AI 助手');
|
||||
}
|
||||
|
||||
// 面诊回放与文字共用读取权限;未登记该接口时也不能走历史放行分支。
|
||||
if ($accessUri === 'tcm.diagnosis/getcallrecords') {
|
||||
$uris = $this->formatUrl($adminAuthCache->getAdminUri() ?? []);
|
||||
|
||||
@@ -21,6 +21,12 @@ class OperationLog
|
||||
{
|
||||
$request = request();
|
||||
|
||||
// Temporary visual observations and rejected upload parameters must never
|
||||
// enter the generic request/response audit log if this listener is enabled.
|
||||
if (strtolower($request->controller() . '/' . $request->action()) === 'tcm.diagnosis/aitonguescreenshot') {
|
||||
return;
|
||||
}
|
||||
|
||||
//需要登录的接口,无效访问时不记录
|
||||
if (!$request->controllerObject->isNotNeedLogin() && empty($request->adminInfo)) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\logic\tcm;
|
||||
|
||||
use app\adminapi\logic\firstvisit\MyPatientLogic;
|
||||
use app\common\cache\AdminAuthCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\DifyTongueScreenshotService;
|
||||
use app\common\service\TongueScreenshotImage;
|
||||
|
||||
/** Read-only assistant operation: authorization + this upload, never a chart snapshot or persistence. */
|
||||
final class TongueScreenshotLogic extends BaseLogic
|
||||
{
|
||||
public static function analyze(array $params, $file, int $adminId, array $adminInfo): ?array
|
||||
{
|
||||
$image = null;
|
||||
try {
|
||||
if (array_diff(array_keys($params), ['id', 'request_id', 'model']) !== []) {
|
||||
throw new \DomainException('截图分析请求包含不支持的字段');
|
||||
}
|
||||
$model = array_key_exists('model', $params) ? $params['model'] : 'qwen';
|
||||
if (!is_string($model) || !in_array($model, ['qwen', 'openai'], true)) {
|
||||
throw new \DomainException('截图分析模型无效');
|
||||
}
|
||||
$rawId = $params['id'] ?? null;
|
||||
$id = (is_string($rawId) || is_int($rawId))
|
||||
? filter_var($rawId, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]) : false;
|
||||
if ($id === false) throw new \DomainException('诊单ID必须大于0');
|
||||
$requestId = $params['request_id'] ?? null;
|
||||
if (!is_string($requestId) || !preg_match('/\A[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\z/Di', $requestId)) {
|
||||
throw new \DomainException('截图请求标识无效');
|
||||
}
|
||||
if ($adminId < 1) throw new \DomainException('请先登录');
|
||||
if ((int) ($adminInfo['root'] ?? 0) !== 1) {
|
||||
$uris = (new AdminAuthCache($adminId))->getAdminUri() ?? [];
|
||||
$uris = array_map(static fn ($uri): string => strtolower(trim((string) $uri)), is_array($uris) ? $uris : []);
|
||||
if (!in_array('tcm.diagnosis/aiassistant', $uris, true)) {
|
||||
throw new \DomainException('权限不足,无法使用诊单 AI 助手');
|
||||
}
|
||||
}
|
||||
if (!MyPatientLogic::canAccessDiagnosis($id, $adminId, $adminInfo)) {
|
||||
throw new \DomainException('诊单不存在或无权访问');
|
||||
}
|
||||
$image = TongueScreenshotImage::fromUpload($file);
|
||||
$result = DifyTongueScreenshotService::analyze($image, $model);
|
||||
return ['request_id' => $requestId, 'diagnosis_id' => $id, 'image_sha256' => $image->sha256(),
|
||||
'analysis' => $result['analysis'], 'model' => $result['model'], 'model_label' => $result['model_label']];
|
||||
} catch (\DomainException $error) {
|
||||
self::setError($error->getMessage());
|
||||
return null;
|
||||
} catch (\Throwable $error) {
|
||||
// Never log image bytes, patient data, model text, transport details or exception messages.
|
||||
self::setError('截图分析暂不可用,请稍后重试');
|
||||
return null;
|
||||
} finally {
|
||||
if ($image !== null) $image->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user