更新
This commit is contained in:
@@ -736,8 +736,11 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
/**
|
||||
* @notes 拉取与本诊单相关的 IM 单聊记录:本地归档 + 腾讯云漫游合并(归档突破云端约 7 天限制)
|
||||
*
|
||||
* @param int $diagnosisId
|
||||
* @param bool $onlyArchived 只读取本地归档,不请求腾讯云(用于首次打开快速展示)
|
||||
*/
|
||||
public static function getImChatMessagesForDiagnosis(int $diagnosisId)
|
||||
public static function getImChatMessagesForDiagnosis(int $diagnosisId, bool $onlyArchived = false)
|
||||
{
|
||||
try {
|
||||
$diag = Diagnosis::where('id', $diagnosisId)->where('delete_time', null)->find();
|
||||
@@ -753,6 +756,17 @@ class DiagnosisLogic extends BaseLogic
|
||||
$patientImId = 'patient_' . $patientId;
|
||||
$archived = self::loadArchivedImChatRows($diagnosisId);
|
||||
|
||||
if ($onlyArchived) {
|
||||
$lists = self::enrichImMessagesWithStaffNames($archived);
|
||||
return [
|
||||
'lists' => $lists,
|
||||
'patient_im_id' => $patientImId,
|
||||
'patient_name' => $diag['patient_name'] ?? '',
|
||||
'doctor_accounts_queried' => [],
|
||||
'only_archived' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$config = self::getTrtcConfig();
|
||||
if (!$config) {
|
||||
if (empty($archived)) {
|
||||
@@ -780,10 +794,19 @@ class DiagnosisLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
$live = self::pullLiveImChatMessagesForDiagnosis($diag);
|
||||
$live = self::pullLiveImChatMessagesForDiagnosis($diag, $doctorAccounts);
|
||||
$merged = self::mergeImMessagesByMsgId($archived, $live);
|
||||
$merged = self::enrichImMessagesWithStaffNames($merged);
|
||||
|
||||
// 首次云端拉取后异步落库,下一次即可直接读归档,无需再全量扫描医生账号
|
||||
if (!empty($live)) {
|
||||
try {
|
||||
self::persistImChatArchiveRows($diagnosisId, $patientId, $live);
|
||||
} catch (\Throwable $e) {
|
||||
\think\facade\Log::warning('archive im chat on-the-fly failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'lists' => $merged,
|
||||
'patient_im_id' => $patientImId,
|
||||
@@ -814,7 +837,13 @@ class DiagnosisLogic extends BaseLogic
|
||||
$out['error'] = '诊单不存在';
|
||||
return $out;
|
||||
}
|
||||
$live = self::pullLiveImChatMessagesForDiagnosis($diag);
|
||||
$accounts = self::collectAllDoctorImPeerAccounts();
|
||||
$assistantId = isset($diag['assistant_id']) ? (int)$diag['assistant_id'] : 0;
|
||||
if ($assistantId > 0) {
|
||||
$accounts[] = 'doctor_' . $assistantId;
|
||||
$accounts = array_values(array_unique($accounts));
|
||||
}
|
||||
$live = self::pullLiveImChatMessagesForDiagnosis($diag, $accounts);
|
||||
if (empty($live)) {
|
||||
$out['skipped_live_empty'] = true;
|
||||
return $out;
|
||||
@@ -926,19 +955,16 @@ class DiagnosisLogic extends BaseLogic
|
||||
* @param Diagnosis|array<string, mixed> $diag
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private static function pullLiveImChatMessagesForDiagnosis($diag): array
|
||||
/**
|
||||
* @param array<int, string> $doctorAccounts 已筛选的医生 IM 账号列表
|
||||
*/
|
||||
private static function pullLiveImChatMessagesForDiagnosis($diag, array $doctorAccounts = []): array
|
||||
{
|
||||
$patientId = (int)$diag['patient_id'];
|
||||
if ($patientId <= 0) {
|
||||
return [];
|
||||
}
|
||||
$patientImId = 'patient_' . $patientId;
|
||||
$doctorAccounts = self::collectAllDoctorImPeerAccounts();
|
||||
$assistantId = isset($diag['assistant_id']) ? (int)$diag['assistant_id'] : 0;
|
||||
if ($assistantId > 0) {
|
||||
$doctorAccounts[] = 'doctor_' . $assistantId;
|
||||
}
|
||||
$doctorAccounts = array_values(array_unique($doctorAccounts));
|
||||
if (empty($doctorAccounts)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user