diff --git a/backend/design/db_schema.md b/backend/design/db_schema.md index 17b122a..5e60470 100644 --- a/backend/design/db_schema.md +++ b/backend/design/db_schema.md @@ -312,25 +312,27 @@ - `uk_asr_model_default_enabled_tenant`锛歚(tenant_id) WHERE is_deleted = 0 AND status = 1 AND is_default = 1` ### 5.6 `biz_llm_models`锛圠LM 妯″瀷閰嶇疆琛級 -| 瀛楁 | 绫诲瀷 | 绾︽潫 | 璇存槑 | -| --- | --- | --- | --- | -| id | BIGSERIAL | PK | 涓婚敭ID | -| tenant_id | BIGINT | NOT NULL, DEFAULT 0 | 绉熸埛ID | -| model_name | VARCHAR(100) | NOT NULL | 妯″瀷鏄剧ず鍚嶇О | -| provider | VARCHAR(50) | | 鎻愪緵鍟?| -| base_url | VARCHAR(255) | | 鎺ュ彛鍩虹鍦板潃 | -| api_path | VARCHAR(100) | | API 璺緞 | -| api_key | VARCHAR(255) | | API 瀵嗛挜 | -| model_code | VARCHAR(100) | | 妯″瀷浠g爜 | -| temperature | DECIMAL(3,2) | DEFAULT 0.7 | 娓╁害鍙傛暟 | -| top_p | DECIMAL(3,2) | DEFAULT 0.9 | Top P 鍙傛暟 | -| is_default | SMALLINT | DEFAULT 0 | 榛樿妯″瀷鏍囪 | -| sort_order | INTEGER | NOT NULL, DEFAULT 0 | 鎺掑簭鍊硷紝瓒婂皬瓒婇潬鍓?| -| status | SMALLINT | DEFAULT 1 | 鐘舵€?| -| remark | VARCHAR(255) | | 澶囨敞 | -| created_at | TIMESTAMP(6) | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 | -| updated_at | TIMESTAMP(6) | NOT NULL, DEFAULT now() | 鏇存柊鏃堕棿 | -| is_deleted | SMALLINT | NOT NULL, DEFAULT 0 | 閫昏緫鍒犻櫎 | +| 瀛楁 | 绫诲瀷 | 绾︽潫 | 璇存槑 | +|------------------|--------------|-------------------------|--------------------------------------| +| id | BIGSERIAL | PK | 涓婚敭ID | +| tenant_id | BIGINT | NOT NULL, DEFAULT 0 | 绉熸埛ID | +| model_name | VARCHAR(100) | NOT NULL | 妯″瀷鏄剧ず鍚嶇О | +| provider | VARCHAR(50) | | 鎻愪緵鍟? | +| base_url | VARCHAR(255) | | 鎺ュ彛鍩虹鍦板潃 | +| api_path | VARCHAR(100) | | API 璺緞 | +| api_key | VARCHAR(255) | | API 瀵嗛挜 | +| model_code | VARCHAR(100) | | 妯″瀷浠g爜 | +| temperature | DECIMAL(3,2) | DEFAULT 0.7 | 娓╁害鍙傛暟 | +| top_p | DECIMAL(3,2) | DEFAULT 0.9 | Top P 鍙傛暟 | +| reasoning_effort | VARCHAR(32) | | 推理强度: minimal/low/medium/high,空表示不下发 | +| thinking_mode | VARCHAR(16) | DEFAULT 'auto' | 思考模式: auto/enabled/disabled | +| is_default | SMALLINT | DEFAULT 0 | 榛樿妯″瀷鏍囪 | +| sort_order | INTEGER | NOT NULL, DEFAULT 0 | 鎺掑簭鍊硷紝瓒婂皬瓒婇潬鍓? | +| status | SMALLINT | DEFAULT 1 | 鐘舵€? | +| remark | VARCHAR(255) | | 澶囨敞 | +| created_at | TIMESTAMP(6) | NOT NULL, DEFAULT now() | 鍒涘缓鏃堕棿 | +| updated_at | TIMESTAMP(6) | NOT NULL, DEFAULT now() | 鏇存柊鏃堕棿 | +| is_deleted | SMALLINT | NOT NULL, DEFAULT 0 | 閫昏緫鍒犻櫎 | 绱㈠紩锛?- `idx_llm_model_tenant`锛歚(tenant_id)` - `idx_llm_model_default`锛歚(is_default) WHERE is_deleted = 0` diff --git a/backend/design/db_schema_pgsql.sql b/backend/design/db_schema_pgsql.sql index cea75aa..a84410c 100644 --- a/backend/design/db_schema_pgsql.sql +++ b/backend/design/db_schema_pgsql.sql @@ -413,6 +413,8 @@ CREATE TABLE biz_llm_models ( temperature DECIMAL(3,2) DEFAULT 0.7, top_p DECIMAL(3,2) DEFAULT 0.9, max_tokens BIGINT NOT NULL DEFAULT 30000, + reasoning_effort VARCHAR(32), + thinking_mode VARCHAR(16) DEFAULT 'auto', is_default SMALLINT DEFAULT 0, sort_order INTEGER NOT NULL DEFAULT 0, status SMALLINT DEFAULT 1, diff --git a/backend/src/main/java/com/imeeting/controller/android/AndroidAuthController.java b/backend/src/main/java/com/imeeting/controller/android/AndroidAuthController.java index 79d1939..227f089 100644 --- a/backend/src/main/java/com/imeeting/controller/android/AndroidAuthController.java +++ b/backend/src/main/java/com/imeeting/controller/android/AndroidAuthController.java @@ -1,10 +1,12 @@ package com.imeeting.controller.android; +import cn.hutool.core.util.StrUtil; import com.imeeting.service.android.AndroidDeviceBindingService; import com.imeeting.service.android.AndroidDeviceRegistrationService; import com.imeeting.support.AndroidRequestLogHelper; import com.unisbase.auth.JwtTokenProvider; import com.unisbase.common.ApiResponse; +import com.unisbase.common.exception.BusinessException; import com.unisbase.common.exception.UnAuthException; import com.unisbase.dto.LoginRequest; import com.unisbase.dto.RefreshRequest; @@ -50,14 +52,16 @@ public class AndroidAuthController { public ApiResponse login(@Valid @RequestBody LoginRequest request, @RequestHeader(value = "X-Android-Device-Id", required = false) String deviceId, @RequestHeader(value = "X-Android-App-Version", required = false) String appVersion, - @RequestHeader(value = "X-Android-Platform", required = false) String platform) { + @RequestHeader(value = "X-Android-Platform", required = false) String platform, + @RequestHeader(value = "X-Android-Tenant-Code", required = false) String tenantCode + ) { AndroidRequestLogHelper.logRequest(log, "Android认证", "登录接口", "request", request, "deviceId", deviceId, "appVersion", appVersion, "platform", platform); if (!StringUtils.hasText(deviceId)) { - throw new IllegalArgumentException("X-Android-Device-Id不能为空"); + throw new BusinessException("X-Android-Device-Id不能为空"); } androidDeviceRegistrationService.requireRegistered(deviceId.trim()); TokenResponse response = authService.login(request, true); @@ -67,6 +71,12 @@ public class AndroidAuthController { response.getCurrentTenantId(), response.getUser().getUserId() ); + if (tenantCode != null) { + boolean b = response.getAvailableTenants().stream().anyMatch(tenant -> tenant.getTenantCode().equals(tenantCode)); + if (!b) { + throw new BusinessException(StrUtil.format("当前登录人不属于[{}]租户", tenantCode)); + } + } } return ApiResponse.ok(response); } diff --git a/backend/src/main/java/com/imeeting/controller/biz/ClientDownloadController.java b/backend/src/main/java/com/imeeting/controller/biz/ClientDownloadController.java index 185e938..20cb5fc 100644 --- a/backend/src/main/java/com/imeeting/controller/biz/ClientDownloadController.java +++ b/backend/src/main/java/com/imeeting/controller/biz/ClientDownloadController.java @@ -1,8 +1,10 @@ package com.imeeting.controller.biz; import com.imeeting.dto.biz.ClientDownloadDTO; +import com.imeeting.dto.biz.ClientDownloadLatestVO; import com.imeeting.entity.biz.ClientDownload; import com.imeeting.service.biz.ClientDownloadService; +import com.unisbase.annotation.Anonymous; import com.unisbase.common.ApiResponse; import com.unisbase.common.annotation.Log; import com.unisbase.security.LoginUser; @@ -51,6 +53,13 @@ public class ClientDownloadController { return ApiResponse.ok(data); } + @Operation(summary = "查询各平台最新客户端安装包,登录页免登录下载") + @GetMapping("/public/latest") + @Anonymous + public ApiResponse> latestByPlatform(@RequestParam(value = "platformCode", required = false) String platformCode) { + return ApiResponse.ok(clientDownloadService.listLatestForDownload(platformCode)); + } + @Operation(summary = "新增客户端下载包") @PostMapping @PreAuthorize("isAuthenticated()") diff --git a/backend/src/main/java/com/imeeting/dto/biz/AiModelDTO.java b/backend/src/main/java/com/imeeting/dto/biz/AiModelDTO.java index 310e143..89255b9 100644 --- a/backend/src/main/java/com/imeeting/dto/biz/AiModelDTO.java +++ b/backend/src/main/java/com/imeeting/dto/biz/AiModelDTO.java @@ -36,6 +36,13 @@ public class AiModelDTO { @JsonProperty("max_tokens") @Schema(description = "最大输出 token 数") private Long maxTokens; + + @Schema(description = "推理强度: minimal/low/medium/high,空表示不下发") + private String reasoningEffort; + + @Schema(description = "思考模式: auto/enabled/disabled,auto 表示跟随模型默认") + private String thinkingMode; + @Schema(description = "媒体配置") private Map mediaConfig; @Schema(description = "是否默认") diff --git a/backend/src/main/java/com/imeeting/dto/biz/AiModelVO.java b/backend/src/main/java/com/imeeting/dto/biz/AiModelVO.java index d39f16b..9e0776d 100644 --- a/backend/src/main/java/com/imeeting/dto/biz/AiModelVO.java +++ b/backend/src/main/java/com/imeeting/dto/biz/AiModelVO.java @@ -37,6 +37,10 @@ public class AiModelVO { @JsonProperty("max_tokens") @Schema(description = "最大输出 token 数") private Long maxTokens; + @Schema(description = "推理强度: minimal/low/medium/high,空表示不下发") + private String reasoningEffort; + @Schema(description = "思考模式: auto/enabled/disabled,auto 表示跟随模型默认") + private String thinkingMode; @Schema(description = "多媒体配置") private Map mediaConfig; @Schema(description = "是否为默认模型") diff --git a/backend/src/main/java/com/imeeting/dto/biz/ClientDownloadLatestVO.java b/backend/src/main/java/com/imeeting/dto/biz/ClientDownloadLatestVO.java new file mode 100644 index 0000000..47fafad --- /dev/null +++ b/backend/src/main/java/com/imeeting/dto/biz/ClientDownloadLatestVO.java @@ -0,0 +1,25 @@ +package com.imeeting.dto.biz; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "登录页客户端下载项,平台列表以数据字典为准") +@Data +public class ClientDownloadLatestVO { + @Schema(description = "平台编码,取自数据字典 client_platform 下级字典项值") + private String platformCode; + @Schema(description = "平台名称,取自数据字典字典项标签") + private String platformName; + @Schema(description = "平台类型,固定为桌面端 DESKTOP") + private String platformType; + @Schema(description = "最新版本号,无安装包时为空") + private String version; + @Schema(description = "最新版本编码,无安装包时为空") + private Long versionCode; + @Schema(description = "下载地址,无安装包时为空") + private String downloadUrl; + @Schema(description = "安装包大小,单位字节,无安装包时为空") + private Long fileSize; + @Schema(description = "是否存在可下载安装包,false 时前端提示暂无安装包") + private Boolean hasPackage; +} diff --git a/backend/src/main/java/com/imeeting/entity/biz/LlmModel.java b/backend/src/main/java/com/imeeting/entity/biz/LlmModel.java index c8b50b2..ac47388 100644 --- a/backend/src/main/java/com/imeeting/entity/biz/LlmModel.java +++ b/backend/src/main/java/com/imeeting/entity/biz/LlmModel.java @@ -48,6 +48,12 @@ public class LlmModel extends BaseEntity { @Schema(description = "最大输出 token 数") private Long maxTokens; + @Schema(description = "推理强度: minimal/low/medium/high,空表示不下发") + private String reasoningEffort; + + @Schema(description = "思考模式: auto/enabled/disabled,auto 表示跟随模型默认") + private String thinkingMode; + @Schema(description = "是否默认模型") private Integer isDefault; diff --git a/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionActivatedEvent.java b/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionActivatedEvent.java new file mode 100644 index 0000000..d7ca554 --- /dev/null +++ b/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionActivatedEvent.java @@ -0,0 +1,10 @@ +package com.imeeting.event; + +/** + * 实时会议发布端激活事件。 + * + *

实时会话状态服务在发布端连接激活时发布本事件,推送订阅等下游能力通过监听事件接入, + * 会话状态服务不再直接依赖推送订阅管理器,避免 Spring Bean 循环依赖。 + */ +public record RealtimeMeetingSessionActivatedEvent(Long meetingId) { +} \ No newline at end of file diff --git a/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionClosedEvent.java b/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionClosedEvent.java new file mode 100644 index 0000000..c546ae9 --- /dev/null +++ b/backend/src/main/java/com/imeeting/event/RealtimeMeetingSessionClosedEvent.java @@ -0,0 +1,10 @@ +package com.imeeting.event; + +/** + * 实时会话结束事件。 + * + *

实时会话状态服务清理会话状态时发布本事件,推送订阅等下游能力通过监听事件回收资源, + * 会话状态服务不再直接依赖推送订阅管理器,避免 Spring Bean 循环依赖。 + */ +public record RealtimeMeetingSessionClosedEvent(Long meetingId) { +} \ No newline at end of file diff --git a/backend/src/main/java/com/imeeting/listener/RealtimeMeetingPushSubscriptionListener.java b/backend/src/main/java/com/imeeting/listener/RealtimeMeetingPushSubscriptionListener.java new file mode 100644 index 0000000..4d553fc --- /dev/null +++ b/backend/src/main/java/com/imeeting/listener/RealtimeMeetingPushSubscriptionListener.java @@ -0,0 +1,47 @@ +package com.imeeting.listener; + +import com.imeeting.event.RealtimeMeetingSessionActivatedEvent; +import com.imeeting.event.RealtimeMeetingSessionClosedEvent; +import com.imeeting.service.realtime.RealtimeMeetingPushSubscriptionManager; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +/** + * 实时会议推送订阅生命周期监听器。 + * + *

把实时会话状态事件翻译成推送订阅的挂载与回收。Spring 事件默认同步执行, + * 时序与原先会话状态服务直接调用推送订阅管理器一致;异常只记录日志,不阻断会议状态流转。 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class RealtimeMeetingPushSubscriptionListener { + + private final RealtimeMeetingPushSubscriptionManager realtimeMeetingPushSubscriptionManager; + + /** + * 发布端激活会话后,把该会议参会人当前在线的推送长连接挂载为订阅者。 + */ + @EventListener + public void onSessionActivated(RealtimeMeetingSessionActivatedEvent event) { + try { + realtimeMeetingPushSubscriptionManager.onMeetingActivated(event.meetingId()); + } catch (Exception ex) { + log.warn("Failed to attach realtime push subscriptions, meetingId={}", event.meetingId(), ex); + } + } + + /** + * 实时会话结束后,回收该会议的全部推送订阅与配额。 + */ + @EventListener + public void onSessionClosed(RealtimeMeetingSessionClosedEvent event) { + try { + realtimeMeetingPushSubscriptionManager.onMeetingClosed(event.meetingId()); + } catch (Exception ex) { + log.warn("Failed to release realtime push subscriptions, meetingId={}", event.meetingId(), ex); + } + } +} diff --git a/backend/src/main/java/com/imeeting/service/biz/ClientDownloadService.java b/backend/src/main/java/com/imeeting/service/biz/ClientDownloadService.java index a456aa7..3eed278 100644 --- a/backend/src/main/java/com/imeeting/service/biz/ClientDownloadService.java +++ b/backend/src/main/java/com/imeeting/service/biz/ClientDownloadService.java @@ -2,6 +2,7 @@ package com.imeeting.service.biz; import com.baomidou.mybatisplus.extension.service.IService; import com.imeeting.dto.biz.ClientDownloadDTO; +import com.imeeting.dto.biz.ClientDownloadLatestVO; import com.imeeting.entity.biz.ClientDownload; import com.unisbase.security.LoginUser; import org.springframework.web.multipart.MultipartFile; @@ -13,6 +14,11 @@ import java.util.Map; public interface ClientDownloadService extends IService { List listForAdmin(LoginUser loginUser, String platformCode, Integer status); + /** + * 查询登录页桌面端下载列表,平台项来自数据字典,无安装包时 hasPackage 为 false。 + */ + List listLatestForDownload(String platformCode); + ClientDownload create(ClientDownloadDTO dto, LoginUser loginUser); ClientDownload update(Long id, ClientDownloadDTO dto, LoginUser loginUser); @@ -20,4 +26,4 @@ public interface ClientDownloadService extends IService { void removeClient(Long id, LoginUser loginUser); Map uploadPackage(String platformCode, MultipartFile file) throws IOException; -} \ No newline at end of file +} diff --git a/backend/src/main/java/com/imeeting/service/biz/impl/AiModelServiceImpl.java b/backend/src/main/java/com/imeeting/service/biz/impl/AiModelServiceImpl.java index 93db1d8..d8f97d1 100644 --- a/backend/src/main/java/com/imeeting/service/biz/impl/AiModelServiceImpl.java +++ b/backend/src/main/java/com/imeeting/service/biz/impl/AiModelServiceImpl.java @@ -17,6 +17,7 @@ import com.imeeting.mapper.biz.LlmModelMapper; import com.imeeting.service.biz.AiModelService; import com.imeeting.service.biz.SpeakerAsrSyncService; import com.imeeting.service.biz.TenantModelActivationService; +import com.imeeting.support.LlmReasoningThinkingSupport; import com.unisbase.dto.PageResult; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -405,6 +406,7 @@ public class AiModelServiceImpl implements AiModelService { if (dto.getTopP() != null) { body.put("top_p", dto.getTopP()); } + LlmReasoningThinkingSupport.applyChatCompletionParams(body, dto.getReasoningEffort(), dto.getThinkingMode()); body.put("response_format", Map.of("type", "json_object")); body.put("messages", buildConnectivityTestMessages(dto.getTestMessage())); @@ -1188,6 +1190,8 @@ public class AiModelServiceImpl implements AiModelService { entity.setTemperature(dto.getTemperature() == null ? BigDecimal.valueOf(0.2) : dto.getTemperature()); entity.setTopP(dto.getTopP() == null ? BigDecimal.valueOf(0.9) : dto.getTopP()); entity.setMaxTokens(resolveMaxTokens(dto.getMaxTokens())); + entity.setReasoningEffort(LlmReasoningThinkingSupport.normalizeReasoningEffort(dto.getReasoningEffort())); + entity.setThinkingMode(LlmReasoningThinkingSupport.normalizeThinkingMode(dto.getThinkingMode())); entity.setIsDefault(dto.getIsDefault()); entity.setStatus(dto.getStatus()); entity.setSortOrder(normalizeSortOrder(dto.getSortOrder())); @@ -1300,6 +1304,8 @@ public class AiModelServiceImpl implements AiModelService { vo.setTemperature(entity.getTemperature()); vo.setTopP(entity.getTopP()); vo.setMaxTokens(resolveMaxTokens(entity.getMaxTokens())); + vo.setReasoningEffort(entity.getReasoningEffort()); + vo.setThinkingMode(entity.getThinkingMode()); vo.setIsDefault(entity.getIsDefault()); vo.setStatus(entity.getStatus()); vo.setScope(Long.valueOf(0L).equals(entity.getTenantId()) ? "PLATFORM" : "TENANT"); diff --git a/backend/src/main/java/com/imeeting/service/biz/impl/AiTaskServiceImpl.java b/backend/src/main/java/com/imeeting/service/biz/impl/AiTaskServiceImpl.java index 2b535e5..fda5299 100644 --- a/backend/src/main/java/com/imeeting/service/biz/impl/AiTaskServiceImpl.java +++ b/backend/src/main/java/com/imeeting/service/biz/impl/AiTaskServiceImpl.java @@ -21,6 +21,7 @@ import com.imeeting.mapper.biz.MeetingMapper; import com.imeeting.mapper.biz.MeetingTranscriptMapper; import com.imeeting.service.android.AndroidMeetingPushService; import com.imeeting.service.biz.*; +import com.imeeting.support.LlmReasoningThinkingSupport; import com.imeeting.support.TaskSecurityContextRunner; import com.imeeting.support.redis.MeetingAsrPermitCache; import com.imeeting.support.redis.MeetingLockCache; @@ -1310,6 +1311,7 @@ public class AiTaskServiceImpl extends ServiceImpl impleme req.put("model", llmModel.getModelCode()); req.put("temperature", llmModel.getTemperature()); req.put("max_tokens", llmModel.getMaxTokens() == null ? 30000L : llmModel.getMaxTokens()); + LlmReasoningThinkingSupport.applyChatCompletionParams(req, llmModel.getReasoningEffort(), llmModel.getThinkingMode()); req.put("messages", List.of( Map.of("role", "system", "content", meetingSummaryPromptAssembler.buildSystemMessage(taskRecord.getTaskConfig())), Map.of("role", "user", "content", meetingSummaryPromptAssembler.buildUserMessage(taskRecord.getTaskConfig(), meeting, summarySource, userPrompt)) diff --git a/backend/src/main/java/com/imeeting/service/biz/impl/ClientDownloadServiceImpl.java b/backend/src/main/java/com/imeeting/service/biz/impl/ClientDownloadServiceImpl.java index 0539f59..a41a162 100644 --- a/backend/src/main/java/com/imeeting/service/biz/impl/ClientDownloadServiceImpl.java +++ b/backend/src/main/java/com/imeeting/service/biz/impl/ClientDownloadServiceImpl.java @@ -4,12 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.imeeting.dto.biz.ClientDownloadDTO; +import com.imeeting.dto.biz.ClientDownloadLatestVO; import com.imeeting.entity.biz.ClientDownload; import com.imeeting.mapper.biz.ClientDownloadMapper; import com.imeeting.service.biz.ClientDownloadService; import com.imeeting.support.ApkManifestParser; +import com.unisbase.dto.SysDictItemDTO; import com.unisbase.security.LoginUser; +import com.unisbase.service.SysDictItemService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,17 +24,39 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.UUID; +@Slf4j @Service @RequiredArgsConstructor public class ClientDownloadServiceImpl extends ServiceImpl implements ClientDownloadService { private static final long GLOBAL_TENANT_ID = 0L; + /** + * 数据字典 client_platform 桌面端子项值,同时作为下级字典的 type_code + */ + private static final String DESKTOP_PLATFORM_TYPE = "DESKTOP"; + + private static final String FAMILY_WINDOWS = "WINDOWS"; + + private static final String FAMILY_MACOS = "MACOS"; + + private static final String FAMILY_HARMONYOS = "HARMONYOS"; + + private static final String FAMILY_LINUX = "LINUX"; + + private final SysDictItemService sysDictItemService; + @Value("${unisbase.app.upload-path}") private String uploadPath; @@ -52,6 +78,62 @@ public class ClientDownloadServiceImpl extends ServiceImpl listLatestForDownload(String platformCode) { + return buildLatestDownloadList(listLatestDesktopPackages(platformCode)); + } + + /** + * 按数据字典顺序组装桌面端最新下载项,与数据库查询解耦便于单元测试校验匹配规则。 + */ + List buildLatestDownloadList(List packages) { + // 版本号倒序在内存中完成,避免不同数据库对 NULL 版本号的排序差异影响最新版本判定 + List ordered = new ArrayList<>(packages); + ordered.sort(latestVersionOrder()); + Map latestByFamily = new HashMap<>(); + for (ClientDownload item : ordered) { + latestByFamily.putIfAbsent(platformFamily(item.getPlatformCode()), item); + } + + // 平台按钮以数据字典为准,字典里存在但暂无安装包的平台同样返回,由前端提示暂无安装包 + List result = new ArrayList<>(); + Set dictFamilies = new HashSet<>(); + for (SysDictItemDTO dictItem : desktopDictItems()) { + String family = platformFamily(dictItem.getItemValue()); + if (!dictFamilies.add(family)) { + continue; + } + ClientDownload latest = latestByFamily.get(family); + ClientDownloadLatestVO vo = new ClientDownloadLatestVO(); + vo.setPlatformCode(dictItem.getItemValue()); + vo.setPlatformName(dictItem.getItemLabel()); + vo.setPlatformType(DESKTOP_PLATFORM_TYPE); + vo.setHasPackage(latest != null && !isBlank(latest.getDownloadUrl())); + if (latest != null) { + vo.setVersion(latest.getVersion()); + vo.setVersionCode(latest.getVersionCode()); + vo.setDownloadUrl(latest.getDownloadUrl()); + vo.setFileSize(latest.getFileSize()); + } + result.add(vo); + } + + if (!dictFamilies.isEmpty()) { + return result; + } + + // 字典不可用时才回退为按安装包渲染;字典正常时以字典为准,停用字典项即可隐藏平台 + Set appendedFamilies = new HashSet<>(); + for (ClientDownload item : ordered) { + String family = platformFamily(item.getPlatformCode()); + if (!appendedFamilies.add(family)) { + continue; + } + result.add(toLatestVO(item, item.getPlatformName())); + } + return result; + } + @Override @Transactional(rollbackFor = Exception.class) public ClientDownload create(ClientDownloadDTO dto, LoginUser loginUser) { @@ -224,4 +306,119 @@ public class ClientDownloadServiceImpl extends ServiceImpl listLatestDesktopPackages(String platformCode) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper() + .eq(ClientDownload::getStatus, 1) + .eq(ClientDownload::getIsLatest, 1) + .eq(ClientDownload::getTenantId, GLOBAL_TENANT_ID); + + // 平台编码按平台族匹配,兼容调用方与库内混用 WIN/WINDOWS 等写法 + String wantedFamily = isBlank(platformCode) ? null : platformFamily(platformCode); + List desktopPackages = new ArrayList<>(); + for (ClientDownload item : this.list(wrapper)) { + if (!isDesktopPlatformType(item.getPlatformType(), item.getPlatformCode())) { + continue; + } + if (wantedFamily != null && !wantedFamily.equals(platformFamily(item.getPlatformCode()))) { + continue; + } + desktopPackages.add(item); + } + return desktopPackages; + } + + /** + * platform_type 为空时按平台编码兜底判定,避免编码无法识别的移动端、终端包混入桌面端下载列表。 + */ + boolean isDesktopPlatformType(String platformType, String platformCode) { + if (!isBlank(platformType)) { + return DESKTOP_PLATFORM_TYPE.equalsIgnoreCase(platformType.trim()); + } + return isKnownDesktopFamily(platformCode); + } + + private boolean isKnownDesktopFamily(String platformCode) { + String family = platformFamily(platformCode); + return FAMILY_WINDOWS.equals(family) || FAMILY_MACOS.equals(family) + || FAMILY_HARMONYOS.equals(family) || FAMILY_LINUX.equals(family); + } + + /** + * 读取桌面端平台字典项,字典异常时返回空列表,登录页回退为按安装包渲染。 + */ + private List desktopDictItems() { + try { + List items = sysDictItemService.getItemsByTypeCode(DESKTOP_PLATFORM_TYPE); + return items == null ? Collections.emptyList() : items; + } catch (Exception e) { + log.warn("读取桌面端平台字典 {} 失败,登录页下载列表回退为安装包数据: {}", + DESKTOP_PLATFORM_TYPE, e.getMessage()); + return Collections.emptyList(); + } + } + + /** + * 版本号倒序且空版本号排在最后,同版本号按主键倒序,用于判定同一平台族的最新记录。 + */ + private Comparator latestVersionOrder() { + return (left, right) -> { + int byVersion = compareVersionDesc(left.getVersionCode(), right.getVersionCode()); + return byVersion != 0 ? byVersion : compareVersionDesc(left.getId(), right.getId()); + }; + } + + private int compareVersionDesc(Long value, Long other) { + if (value == null) { + return other == null ? 0 : 1; + } + if (other == null) { + return -1; + } + return Long.compare(other, value); + } + + /** + * 归一化平台编码,兼容不同环境字典与安装包混用 WIN/WINDOWS、MAC/MACOS 等写法。 + */ + private String platformFamily(String platformCode) { + if (isBlank(platformCode)) { + return ""; + } + String code = platformCode.trim().toUpperCase(Locale.ROOT); + if (code.contains("WINDOW") || "WIN".equals(code) || "PC".equals(code)) { + return FAMILY_WINDOWS; + } + if ("MAC".equals(code) || "MACOS".equals(code) || "OSX".equals(code) + || code.contains("MACOS") || code.contains("DARWIN")) { + return FAMILY_MACOS; + } + if (code.contains("HARMONY") || code.contains("HMOS")) { + return FAMILY_HARMONYOS; + } + if (isLinuxFamily(code)) { + return FAMILY_LINUX; + } + return code; + } + + private boolean isLinuxFamily(String code) { + return code.contains("LINUX") || code.contains("UBUNTU") || code.contains("DEBIAN"); + } + + private ClientDownloadLatestVO toLatestVO(ClientDownload entity, String platformName) { + ClientDownloadLatestVO vo = new ClientDownloadLatestVO(); + vo.setPlatformCode(entity.getPlatformCode()); + vo.setPlatformName(isBlank(platformName) ? entity.getPlatformCode() : platformName); + vo.setPlatformType(DESKTOP_PLATFORM_TYPE); + vo.setVersion(entity.getVersion()); + vo.setVersionCode(entity.getVersionCode()); + vo.setDownloadUrl(entity.getDownloadUrl()); + vo.setFileSize(entity.getFileSize()); + vo.setHasPackage(!isBlank(entity.getDownloadUrl())); + return vo; + } } diff --git a/backend/src/main/java/com/imeeting/service/biz/impl/MeetingExternalSummaryWebhookTrigger.java b/backend/src/main/java/com/imeeting/service/biz/impl/MeetingExternalSummaryWebhookTrigger.java index da75506..48de8ee 100644 --- a/backend/src/main/java/com/imeeting/service/biz/impl/MeetingExternalSummaryWebhookTrigger.java +++ b/backend/src/main/java/com/imeeting/service/biz/impl/MeetingExternalSummaryWebhookTrigger.java @@ -6,6 +6,7 @@ import com.imeeting.dto.biz.MeetingSummaryOrchestrationTriggerResultVO; import com.imeeting.entity.biz.AiTask; import com.imeeting.entity.biz.Meeting; import com.imeeting.service.biz.AiModelService; +import com.imeeting.support.LlmReasoningThinkingSupport; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -201,6 +202,8 @@ public class MeetingExternalSummaryWebhookTrigger { config.put("temperature", model.getTemperature()); config.put("topP", model.getTopP()); config.put("max_tokens", model.getMaxTokens() == null ? 30000L : model.getMaxTokens()); + config.put("reasoning_effort", LlmReasoningThinkingSupport.resolveReasoningEffort(model.getReasoningEffort())); + config.put("enable_thinking", LlmReasoningThinkingSupport.resolveEnableThinking(model.getThinkingMode())); return config; } diff --git a/backend/src/main/java/com/imeeting/service/biz/impl/MeetingTranscriptChapterServiceImpl.java b/backend/src/main/java/com/imeeting/service/biz/impl/MeetingTranscriptChapterServiceImpl.java index 30f53e9..cf5a6db 100644 --- a/backend/src/main/java/com/imeeting/service/biz/impl/MeetingTranscriptChapterServiceImpl.java +++ b/backend/src/main/java/com/imeeting/service/biz/impl/MeetingTranscriptChapterServiceImpl.java @@ -22,6 +22,7 @@ import com.imeeting.mapper.biz.MeetingTranscriptChapterVersionMapper; import com.imeeting.mapper.biz.MeetingTranscriptMapper; import com.imeeting.service.biz.AiModelService; import com.imeeting.service.biz.MeetingTranscriptChapterService; +import com.imeeting.support.LlmReasoningThinkingSupport; import com.unisbase.service.SysParamService; import com.unisbase.service.SysParamService; import lombok.RequiredArgsConstructor; @@ -336,6 +337,7 @@ public class MeetingTranscriptChapterServiceImpl implements MeetingTranscriptCha requestBody.put("model", llmModel.getModelCode()); requestBody.put("temperature", llmModel.getTemperature()); requestBody.put("max_tokens", llmModel.getMaxTokens() == null ? 30000L : llmModel.getMaxTokens()); + LlmReasoningThinkingSupport.applyChatCompletionParams(requestBody, llmModel.getReasoningEffort(), llmModel.getThinkingMode()); requestBody.put("messages", List.of( Map.of("role", "system", "content", renderChapterSystemPrompt()), Map.of("role", "user", "content", renderChapterUserPrompt(transcripts)) @@ -1016,6 +1018,7 @@ public class MeetingTranscriptChapterServiceImpl implements MeetingTranscriptCha requestBody.put("model", llmModel.getModelCode()); requestBody.put("temperature", llmModel.getTemperature()); requestBody.put("max_tokens", llmModel.getMaxTokens() == null ? 30000L : llmModel.getMaxTokens()); + LlmReasoningThinkingSupport.applyChatCompletionParams(requestBody, llmModel.getReasoningEffort(), llmModel.getThinkingMode()); requestBody.put("messages", List.of( Map.of("role", "system", "content", renderChapterSystemPrompt()), Map.of("role", "user", "content", renderChapterUserPrompt(transcripts)) diff --git a/backend/src/main/java/com/imeeting/service/realtime/RealtimeMeetingPushSubscriptionManager.java b/backend/src/main/java/com/imeeting/service/realtime/RealtimeMeetingPushSubscriptionManager.java new file mode 100644 index 0000000..25c7244 --- /dev/null +++ b/backend/src/main/java/com/imeeting/service/realtime/RealtimeMeetingPushSubscriptionManager.java @@ -0,0 +1,538 @@ +package com.imeeting.service.realtime; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.imeeting.common.MeetingConstants; +import com.imeeting.dto.android.AndroidGrpcConnectionDetailVO; +import com.imeeting.dto.biz.RealtimeMeetingSessionState; +import com.imeeting.entity.biz.Meeting; +import com.imeeting.enums.MeetingPushTypeEnum; +import com.imeeting.grpc.push.PushMessage; +import com.imeeting.service.android.AndroidGatewayPushService; +import com.imeeting.service.biz.MeetingAccessService; +import com.imeeting.service.realtime.impl.LocalRealtimeAsrChannel; +import com.imeeting.support.redis.RealtimeMeetingSessionCache; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.Duration; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Consumer; + +/** + * 实时会议转写推送订阅管理。 + * + *

订阅通道只有一条:push.proto 的设备推送长连接。长连接建立即视为尝试订阅,是否下发按 user_id 判定, + * 只有会议创建人、主持人以及 biz_meetings.participants 命中的用户才会收到推送;判定只看 user_id 是否命中 + * 参会人集合,不要求推送连接的授权租户与会议租户一致。realtime gRPC 只承载发布端音频,不再承担订阅职责。 + * + *

同一用户在不同设备上的推送长连接互相独立、全部保留并各自下发;正在发布音频的设备经 realtime gRPC + * 自行收流,不再重复下发推送。 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class RealtimeMeetingPushSubscriptionManager { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final String DEFAULT_TITLE = "实时转写"; + private static final long INFO_REFRESH_MILLIS = 15_000L; + private static final Duration LIVE_MEETING_TTL = Duration.ofSeconds(120); + + private final AndroidGatewayPushService androidGatewayPushService; + private final RealtimeMeetingEventHub eventHub; + private final RealtimeMeetingSubscriptionQuota subscriptionQuota; + private final RealtimeMeetingTranscriptCacheService transcriptCacheService; + private final MeetingAccessService meetingAccessService; + private final RealtimeMeetingSessionCache sessionCache; + + @Value("${imeeting.realtime.max-subscribers-per-meeting:200}") + private int maxSubscribersPerMeeting = 200; + + private final ConcurrentMap liveMeetings = new ConcurrentHashMap<>(); + + /** + * 发布端激活会议时写入跨实例活跃索引,并把该会议参会人当前在线的推送长连接挂接为订阅者。 + */ + public void onMeetingActivated(Long meetingId) { + if (meetingId == null) { + return; + } + sessionCache.markLive(meetingId, LIVE_MEETING_TTL); + LiveMeeting live = ensureLocalLive(meetingId); + if (live == null) { + return; + } + int attached = attachUserConnections(live, null); + log.info("Realtime meeting marked live for push, meetingId={}, eligibleUsers={}, attached={}", + meetingId, live.userIds.size(), attached); + } + + /** + * 会议实时会话结束时回收该会议的全部推送订阅。 + */ + public void onMeetingClosed(Long meetingId) { + if (meetingId == null) { + return; + } + sessionCache.clearLive(meetingId); + LiveMeeting live = liveMeetings.remove(meetingId); + if (live == null) { + return; + } + int released; + synchronized (live) { + released = live.byConnectionId.size(); + for (Subscription subscription : live.byConnectionId.values()) { + subscriptionQuota.release(meetingId, subscription.member()); + } + live.byConnectionId.clear(); + detachHub(live); + } + log.info("Realtime meeting closed, push subscriptions released, meetingId={}, released={}", meetingId, released); + } + + /** + * 推送长连接建立即尝试订阅:只挂接该用户作为创建人、主持人或参会人的进行中实时会议。 + * + *

下发资格只按 user_id 是否命中参会人集合判定。推送连接的授权租户可能来自设备授权而非登录租户, + * 因此不能拿租户相等作为前置条件,否则会漏掉合法参会人;租户只用于日志定位。 + */ + public void onPushConnectionOpened(Long tenantId, Long userId, String deviceId, String connectionId) { + if (userId == null || isBlank(deviceId) || isBlank(connectionId)) { + log.info("Skip realtime push subscription for push connection without user, deviceId={}, connectionId={}", + deviceId, connectionId); + return; + } + Set liveMeetingIds = resolveLiveMeetingIds(); + int attached = 0; + for (Long meetingId : liveMeetingIds) { + LiveMeeting live = ensureLocalLive(meetingId); + if (live == null) { + continue; + } + if (!live.userIds.contains(userId)) { + log.info("Realtime push subscription skipped for non-participant, meetingId={}, userId={}, deviceId={}, connectionTenantId={}, meetingTenantId={}", + meetingId, userId, deviceId, tenantId, live.tenantId); + continue; + } + Subscription subscription = attach(live, deviceId, userId, connectionId); + if (subscription != null) { + attached++; + replayHistory(live, subscription); + } + } + log.info("Realtime push subscription attempt finished, userId={}, deviceId={}, connectionId={}, connectionTenantId={}, liveMeetings={}, attached={}", + userId, deviceId, connectionId, tenantId, liveMeetingIds.size(), attached); + } + + /** + * 推送长连接关闭时释放它承载的全部订阅;其他设备与其他连接不受影响。 + */ + public void onPushConnectionClosed(String connectionId) { + if (isBlank(connectionId)) { + return; + } + for (LiveMeeting live : liveMeetings.values()) { + Subscription subscription; + synchronized (live) { + subscription = live.byConnectionId.get(connectionId); + } + if (subscription != null) { + detach(live, subscription, "connection-closed"); + } + } + } + + /** + * 本实例需要跟踪的实时会议:Redis 活跃索引(跨实例)与本机已登记的会议。 + */ + private Set resolveLiveMeetingIds() { + Set meetingIds = new LinkedHashSet<>(sessionCache.listLiveMeetingIds()); + meetingIds.addAll(liveMeetings.keySet()); + return meetingIds; + } + + /** + * 确保本实例跟踪该会议的推送订阅;会话已结束或已回收时清理本机状态并返回 null。 + */ + private LiveMeeting ensureLocalLive(Long meetingId) { + RealtimeMeetingSessionState state = sessionCache.getState(meetingId); + String status = state == null ? null : state.getStatus(); + if (state == null || "COMPLETED".equals(status)) { + onMeetingClosed(meetingId); + return null; + } + LiveMeeting live = liveMeetings.computeIfAbsent(meetingId, LiveMeeting::new); + live.status = status; + synchronized (live) { + refreshInfoLocked(live); + refreshPublisherDeviceLocked(live); + } + return live; + } + + /** + * 记录正在发布音频的设备,写入 Redis 供其它实例共享,发布端自身不再重复收推送。 + */ + public void markPublisherDevice(Long meetingId, String deviceId) { + if (meetingId == null || isBlank(deviceId)) { + return; + } + String publisherDeviceId = deviceId.trim(); + LiveMeeting live = liveMeetings.get(meetingId); + if (live != null) { + live.publisherDeviceId = publisherDeviceId; + } + sessionCache.savePublisherDevice(meetingId, publisherDeviceId, LIVE_MEETING_TTL); + log.info("Realtime publisher device recorded, meetingId={}, deviceId={}", meetingId, publisherDeviceId); + } + + /** + * 发布设备断开后清除标记,让它重新按参会人身份接收推送。 + */ + public void clearPublisherDevice(Long meetingId, String deviceId) { + if (meetingId == null || isBlank(deviceId)) { + return; + } + String publisherDeviceId = deviceId.trim(); + LiveMeeting live = liveMeetings.get(meetingId); + if (live != null && publisherDeviceId.equals(live.publisherDeviceId)) { + live.publisherDeviceId = null; + } + sessionCache.clearPublisherDevice(meetingId, publisherDeviceId); + log.info("Realtime publisher device cleared, meetingId={}, deviceId={}", meetingId, publisherDeviceId); + } + + /** + * 发布设备以 Redis 为准,让不承载发布连接的实例也能抑制发布端重复收流;调用方持有会议锁。 + */ + private void refreshPublisherDeviceLocked(LiveMeeting live) { + String publisherDeviceId = sessionCache.getPublisherDevice(live.meetingId); + if (isBlank(publisherDeviceId)) { + live.publisherDeviceId = null; + return; + } + live.publisherDeviceId = publisherDeviceId.trim(); + sessionCache.savePublisherDevice(live.meetingId, live.publisherDeviceId, LIVE_MEETING_TTL); + } + + /** + * 续约配额槽位、刷新参会人、回收已结束会议与不再具备资格的订阅。 + */ + @Scheduled(fixedDelayString = "${imeeting.realtime.push-subscription-sweep-millis:15000}") + public void sweepLiveMeetings() { + for (Long meetingId : resolveLiveMeetingIds()) { + try { + LiveMeeting live = ensureLocalLive(meetingId); + if (live == null) { + continue; + } + sessionCache.markLive(meetingId, LIVE_MEETING_TTL); + sweepMeeting(live); + } catch (Exception ex) { + log.warn("Failed to sweep realtime push subscriptions, meetingId={}", meetingId, ex); + } + } + } + + private void sweepMeeting(LiveMeeting live) { + synchronized (live) { + live.byConnectionId.values().forEach(subscription -> + subscriptionQuota.renew(live.meetingId, subscription.member())); + } + int detached = 0; + for (Subscription subscription : live.byConnectionId.values()) { + if (!live.userIds.contains(subscription.userId())) { + detach(live, subscription, "not-participant"); + detached++; + } + } + int attached = attachUserConnections(live, null); + if (attached > 0 || detached > 0) { + log.info("Realtime push subscriptions reconciled, meetingId={}, attached={}, detached={}", + live.meetingId, attached, detached); + } + // 判空与移除必须与 attach 持有同一把会议锁,否则刚挂上的订阅会被误回收成不在册状态(配额不再释放)。 + synchronized (live) { + if (live.byConnectionId.isEmpty() && !"ACTIVE".equals(live.status)) { + liveMeetings.remove(live.meetingId, live); + } + } + } + + /** + * 把用户当前在线的推送长连接挂到该会议;onlyUserId 为空表示全部参会人。 + */ + private int attachUserConnections(LiveMeeting live, Long onlyUserId) { + int attached = 0; + for (Long userId : live.userIds) { + if (onlyUserId != null && !onlyUserId.equals(userId)) { + continue; + } + for (AndroidGrpcConnectionDetailVO connection : androidGatewayPushService.listUserConnections(userId)) { + Subscription subscription = attach(live, connection.getDeviceId(), userId, connection.getConnectionId()); + if (subscription == null) { + continue; + } + attached++; + replayHistory(live, subscription); + } + } + return attached; + } + + private Subscription attach(LiveMeeting live, String deviceId, Long userId, String connectionId) { + if (isBlank(deviceId) || isBlank(connectionId)) { + return null; + } + synchronized (live) { + if (liveMeetings.get(live.meetingId) != live) { + // 会议已被回收(sweep / close),拒绝新订阅,避免产生不在册的无主订阅占位。 + return null; + } + if (live.byConnectionId.containsKey(connectionId)) { + return null; + } + if (live.byConnectionId.size() >= maxSubscribersPerMeeting) { + RealtimeMeetingMetrics.subscriberRejected("push"); + log.warn("Realtime push subscription rejected by per-meeting cap, meetingId={}, deviceId={}, cap={}", + live.meetingId, deviceId, maxSubscribersPerMeeting); + return null; + } + String member = subscriptionQuota.member(connectionId); + if (!subscriptionQuota.tryAcquire(live.meetingId, member)) { + RealtimeMeetingMetrics.subscriberRejected("push"); + log.warn("Realtime push subscription rejected by subscriber quota, meetingId={}, deviceId={}", + live.meetingId, deviceId); + return null; + } + if (live.consumer == null && !attachHub(live)) { + subscriptionQuota.release(live.meetingId, member); + RealtimeMeetingMetrics.subscriberRejected("push"); + log.warn("Realtime push subscription rejected by event hub, meetingId={}, deviceId={}", + live.meetingId, deviceId); + return null; + } + Subscription subscription = new Subscription(connectionId, deviceId.trim(), userId, member); + live.byConnectionId.put(connectionId, subscription); + RealtimeMeetingMetrics.subscriberOpened("push"); + log.info("Realtime push subscription attached, meetingId={}, deviceId={}, userId={}, connectionId={}", + live.meetingId, deviceId, userId, connectionId); + return subscription; + } + } + + private void detach(LiveMeeting live, Subscription subscription, String reason) { + synchronized (live) { + if (!live.byConnectionId.remove(subscription.connectionId(), subscription)) { + return; + } + subscriptionQuota.release(live.meetingId, subscription.member()); + if (live.byConnectionId.isEmpty()) { + detachHub(live); + } + } + RealtimeMeetingMetrics.subscriberClosed("push"); + log.info("Realtime push subscription detached, meetingId={}, deviceId={}, userId={}, connectionId={}, reason={}", + live.meetingId, subscription.deviceId(), subscription.userId(), subscription.connectionId(), reason); + } + + /** + * 每个会议只挂一个事件总线消费者,扇出到该会议在本实例上的推送连接;调用方持有会议锁。 + */ + private boolean attachHub(LiveMeeting live) { + Consumer consumer = payload -> deliverAll(live, payload); + if (!eventHub.trySubscribe(live.meetingId, consumer, Math.max(maxSubscribersPerMeeting, 1))) { + return false; + } + live.consumer = consumer; + return true; + } + + private void detachHub(LiveMeeting live) { + if (live.consumer != null) { + eventHub.unsubscribe(live.meetingId, live.consumer); + live.consumer = null; + } + } + + private void deliverAll(LiveMeeting live, String payload) { + if (live.byConnectionId.isEmpty()) { + return; + } + PushMessage message = buildPushMessage(live.meetingId, live.title, payload); + String publisherDeviceId = live.publisherDeviceId; + for (Subscription subscription : live.byConnectionId.values()) { + if (publisherDeviceId != null && publisherDeviceId.equals(subscription.deviceId())) { + // 发布设备正在 realtime gRPC 上收流,避免同一转写重复下发。 + continue; + } + push(live.meetingId, subscription, message, false); + } + } + + private void replayHistory(LiveMeeting live, Subscription subscription) { + try { + var items = transcriptCacheService.listOrderedItems(live.meetingId); + for (var item : items) { + push(live.meetingId, subscription, + buildPushMessage(live.meetingId, live.title, LocalRealtimeAsrChannel.buildFrontendTranscriptMessage(item)), true); + } + log.info("Realtime transcripts replayed over push, meetingId={}, deviceId={}, connectionId={}, count={}", + live.meetingId, subscription.deviceId(), subscription.connectionId(), items.size()); + } catch (Exception ex) { + log.warn("Failed to replay realtime transcripts over push, meetingId={}, deviceId={}", + live.meetingId, subscription.deviceId(), ex); + } + } + + private void push(Long meetingId, Subscription subscription, PushMessage message, boolean replay) { + if (!androidGatewayPushService.pushToConnection(subscription.connectionId(), message)) { + RealtimeMeetingMetrics.pushDeliveryMissed(); + log.warn("Realtime transcript push has no live connection, meetingId={}, deviceId={}, connectionId={}, replay={}", + meetingId, subscription.deviceId(), subscription.connectionId(), replay); + return; + } + if (log.isDebugEnabled()) { + log.debug("Realtime transcript pushed, meetingId={}, deviceId={}, connectionId={}, replay={}, messageId={}", + meetingId, subscription.deviceId(), subscription.connectionId(), replay, message.getMessageId()); + } + } + + private void refreshInfoLocked(LiveMeeting live) { + if (live.infoLoadedAt > 0 && System.currentTimeMillis() - live.infoLoadedAt < INFO_REFRESH_MILLIS) { + return; + } + Meeting meeting = loadRealtimeMeeting(live.meetingId); + if (meeting != null) { + applyMeetingInfo(live, meeting); + } + } + + private void applyMeetingInfo(LiveMeeting live, Meeting meeting) { + live.tenantId = meeting.getTenantId(); + live.title = isBlank(meeting.getTitle()) ? DEFAULT_TITLE : meeting.getTitle().trim(); + Set userIds = new LinkedHashSet<>(); + if (meeting.getCreatorId() != null) { + userIds.add(meeting.getCreatorId()); + } + if (meeting.getHostUserId() != null) { + userIds.add(meeting.getHostUserId()); + } + if (!isBlank(meeting.getParticipants())) { + for (String token : meeting.getParticipants().split(",")) { + Long userId = parseUserId(token); + if (userId != null) { + userIds.add(userId); + } + } + } + live.userIds = userIds; + live.infoLoadedAt = System.currentTimeMillis(); + } + + private Meeting loadRealtimeMeeting(Long meetingId) { + try { + Meeting meeting = meetingAccessService.requireMeetingIgnoreTenant(meetingId); + if (meeting == null) { + log.warn("Realtime meeting not found, meetingId={}", meetingId); + return null; + } + if (!MeetingConstants.TYPE_REALTIME.equalsIgnoreCase(meeting.getMeetingType())) { + log.warn("Meeting is not a realtime meeting, meetingId={}, meetingType={}", meetingId, meeting.getMeetingType()); + return null; + } + return meeting; + } catch (Exception ex) { + log.warn("Failed to load meeting for realtime push subscription, meetingId={}", meetingId, ex); + return null; + } + } + + private PushMessage buildPushMessage(Long meetingId, String meetingTitle, String payload) { + return PushMessage.newBuilder() + .setMessageId("realtime_transcript:" + meetingId + ":" + UUID.randomUUID()) + .setTimestamp(System.currentTimeMillis()) + .setType(MeetingPushTypeEnum.MEETING_REALTIME_TRANSCRIPT.getCode()) + .setTitle(isBlank(meetingTitle) ? DEFAULT_TITLE : meetingTitle.trim()) + .setContent(buildContent(meetingId, payload)) + .setNeedAck(false) + .build(); + } + + /** + * 转写报文保持与实时通道一致,只在顶层补 meetingId 供客户端按会议分流。 + */ + private String buildContent(Long meetingId, String payload) { + String text = payload == null ? "" : payload; + if (meetingId == null) { + return text; + } + try { + JsonNode node = OBJECT_MAPPER.readTree(text); + if (node instanceof ObjectNode objectNode) { + objectNode.put("meetingId", meetingId); + return OBJECT_MAPPER.writeValueAsString(objectNode); + } + } catch (JsonProcessingException ex) { + log.debug("Realtime transcript payload is not a json object, wrap as text"); + } + ObjectNode wrapper = OBJECT_MAPPER.createObjectNode(); + wrapper.put("meetingId", meetingId); + wrapper.put("text", text); + return wrapper.toString(); + } + + private boolean isBlank(String value) { + return value == null || value.isBlank(); + } + + /** + * 参会人按逗号分隔的用户 ID 解析,兼容残留引号与中括号,非法值只忽略不中断。 + */ + private Long parseUserId(String token) { + if (token == null) { + return null; + } + String value = token.trim().replace("\"", "").replace("[", "").replace("]", "").trim(); + if (value.isEmpty()) { + return null; + } + try { + return Long.valueOf(value); + } catch (NumberFormatException ex) { + log.debug("Ignore non numeric participant id, value={}", value); + return null; + } + } + + private record Subscription(String connectionId, String deviceId, Long userId, String member) { + } + + private final class LiveMeeting { + + private final Long meetingId; + private final ConcurrentMap byConnectionId = new ConcurrentHashMap<>(); + private volatile Long tenantId; + private volatile String title = DEFAULT_TITLE; + private volatile Set userIds = Set.of(); + private volatile String status; + private volatile String publisherDeviceId; + private volatile long infoLoadedAt; + private Consumer consumer; + + private LiveMeeting(Long meetingId) { + this.meetingId = meetingId; + } + } +} diff --git a/backend/src/main/java/com/imeeting/support/LlmReasoningThinkingSupport.java b/backend/src/main/java/com/imeeting/support/LlmReasoningThinkingSupport.java new file mode 100644 index 0000000..db61d32 --- /dev/null +++ b/backend/src/main/java/com/imeeting/support/LlmReasoningThinkingSupport.java @@ -0,0 +1,112 @@ +package com.imeeting.support; + +import cn.hutool.core.util.StrUtil; + +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * LLM 推理强度与思考模式的取值约束与请求参数下发。 + * + *

业务约定:推理强度按 OpenAI 兼容协议下发 reasoning_effort;思考模式下发 enable_thinking 布尔值。 + * 推理强度为空、或思考模式为 auto 时不写入请求体,保证历史模型配置的调用行为完全不变。

+ */ +public final class LlmReasoningThinkingSupport { + + /** + * 允许的推理强度取值,直接作为请求体 reasoning_effort + */ + public static final List REASONING_EFFORTS = List.of("minimal", "low", "medium", "high"); + /** + * 思考模式:跟随模型默认,不下发 enable_thinking + */ + public static final String THINKING_MODE_AUTO = "auto"; + /** + * 思考模式:显式开启,下发 enable_thinking=true + */ + public static final String THINKING_MODE_ENABLED = "enabled"; + /** + * 思考模式:显式关闭,下发 enable_thinking=false + */ + public static final String THINKING_MODE_DISABLED = "disabled"; + /** + * 允许的思考模式取值 + */ + public static final List THINKING_MODES = + List.of(THINKING_MODE_AUTO, THINKING_MODE_ENABLED, THINKING_MODE_DISABLED); + + private LlmReasoningThinkingSupport() { + } + + /** + * 保存配置时归一化推理强度,空值表示不下发,非法取值直接拒绝。 + */ + public static String normalizeReasoningEffort(String reasoningEffort) { + String normalized = trimToLowerCase(reasoningEffort); + if (normalized == null) { + return null; + } + if (!REASONING_EFFORTS.contains(normalized)) { + throw new RuntimeException("推理强度仅支持:" + String.join("/", REASONING_EFFORTS)); + } + return normalized; + } + + /** + * 保存配置时归一化思考模式,空值按 auto 处理,非法取值直接拒绝。 + */ + public static String normalizeThinkingMode(String thinkingMode) { + String normalized = trimToLowerCase(thinkingMode); + if (normalized == null) { + return THINKING_MODE_AUTO; + } + if (!THINKING_MODES.contains(normalized)) { + throw new RuntimeException("思考模式仅支持:" + String.join("/", THINKING_MODES)); + } + return normalized; + } + + /** + * 把模型配置的推理强度与思考模式附加到 chat/completions 请求体。 + */ + public static void applyChatCompletionParams(Map body, String reasoningEffort, String thinkingMode) { + if (body == null) { + return; + } + String resolvedReasoningEffort = resolveReasoningEffort(reasoningEffort); + if (resolvedReasoningEffort != null) { + body.put("reasoning_effort", resolvedReasoningEffort); + } + Boolean enableThinking = resolveEnableThinking(thinkingMode); + if (enableThinking != null) { + body.put("enable_thinking", enableThinking); + } + } + + /** + * 请求体 reasoning_effort 取值,未配置返回 null。 + */ + public static String resolveReasoningEffort(String reasoningEffort) { + return trimToLowerCase(reasoningEffort); + } + + /** + * 请求体 enable_thinking 取值,auto 或空返回 null 表示不下发。 + */ + public static Boolean resolveEnableThinking(String thinkingMode) { + String normalized = trimToLowerCase(thinkingMode); + if (THINKING_MODE_ENABLED.equals(normalized)) { + return Boolean.TRUE; + } + if (THINKING_MODE_DISABLED.equals(normalized)) { + return Boolean.FALSE; + } + return null; + } + + private static String trimToLowerCase(String value) { + String trimmed = StrUtil.trimToNull(value); + return trimmed == null ? null : trimmed.toLowerCase(Locale.ROOT); + } +} diff --git a/frontend/public/static/login/login-bg.png b/frontend/public/static/login/login-bg.png new file mode 100644 index 0000000..b618982 Binary files /dev/null and b/frontend/public/static/login/login-bg.png differ diff --git a/frontend/public/static/login/platform-harmony.svg b/frontend/public/static/login/platform-harmony.svg new file mode 100644 index 0000000..85ba535 --- /dev/null +++ b/frontend/public/static/login/platform-harmony.svg @@ -0,0 +1,8 @@ + + + + + diff --git a/frontend/public/static/login/platform-linux.svg b/frontend/public/static/login/platform-linux.svg new file mode 100644 index 0000000..3081efe --- /dev/null +++ b/frontend/public/static/login/platform-linux.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/frontend/public/static/login/platform-macos.svg b/frontend/public/static/login/platform-macos.svg new file mode 100644 index 0000000..59f694b --- /dev/null +++ b/frontend/public/static/login/platform-macos.svg @@ -0,0 +1,8 @@ + + + + + diff --git a/frontend/public/static/login/platform-windows.svg b/frontend/public/static/login/platform-windows.svg new file mode 100644 index 0000000..1df3e29 --- /dev/null +++ b/frontend/public/static/login/platform-windows.svg @@ -0,0 +1,8 @@ + + + + + diff --git a/frontend/src/api/business/aimodel.ts b/frontend/src/api/business/aimodel.ts index 5af1cc1..7bceab3 100644 --- a/frontend/src/api/business/aimodel.ts +++ b/frontend/src/api/business/aimodel.ts @@ -14,6 +14,8 @@ export interface AiModelVO { temperature?: number; topP?: number; max_tokens?: number; + reasoningEffort?: string; + thinkingMode?: string; mediaConfig?: Record; isDefault: number; status: number; @@ -49,6 +51,8 @@ export interface AiModelDTO { temperature?: number; topP?: number; max_tokens?: number; + reasoningEffort?: string; + thinkingMode?: string; mediaConfig?: Record; isDefault: number; status: number; @@ -160,6 +164,8 @@ export const testLlmModelConnectivity = (data: { temperature?: number; topP?: number; max_tokens?: number; + reasoningEffort?: string; + thinkingMode?: string; testMessage: string; }) => { return http.post<{ code: string; data: boolean; msg: string }>( diff --git a/frontend/src/api/business/client.ts b/frontend/src/api/business/client.ts index 42f16ed..51d0a52 100644 --- a/frontend/src/api/business/client.ts +++ b/frontend/src/api/business/client.ts @@ -76,3 +76,24 @@ export async function uploadClientPackage(platformCode: string, file: File) { }); return resp.data.data as ClientUploadResult; } + +/** 登录页桌面端下载项,平台列表由后端数据字典驱动 */ +export interface ClientLatestDownload { + platformCode: string; + platformName?: string; + platformType?: string; + version?: string; + versionCode?: number; + downloadUrl?: string; + fileSize?: number; + hasPackage?: boolean; +} + +/** 查询各平台最新可下载安装包(登录页免登录),平台项来自数据字典 */ +export async function fetchLatestClientDownloads(platformCode?: string) { + const resp = await http.get("/api/clients/public/latest", { + params: platformCode ? {platformCode} : undefined, + suppressErrorToast: true + }); + return (resp.data?.data || []) as ClientLatestDownload[]; +} diff --git a/frontend/src/api/http.ts b/frontend/src/api/http.ts index aaee066..8a6f0dd 100644 --- a/frontend/src/api/http.ts +++ b/frontend/src/api/http.ts @@ -28,7 +28,8 @@ const AUTH_WHITELIST = [ "/sys/auth/device-code", "/sys/auth/password-policy/public", "/sys/auth/password-recovery/send-code", - "/sys/auth/password-recovery/reset" + "/sys/auth/password-recovery/reset", + "/api/clients/public/latest" ]; const API_SUCCESS_CODE = "200"; const REFRESH_AHEAD_MS = 60 * 1000; @@ -85,7 +86,8 @@ function persistTokens(data: { accessToken: string; refreshToken: string }) { } function isAuthWhitelistRequest(url?: string) { - return AUTH_WHITELIST.some((path) => (url || "").includes(path)); + const path = (url || "").split("?")[0]; + return AUTH_WHITELIST.some((item) => path === item || path.endsWith(item)); } async function refreshAccessToken(): Promise { @@ -167,9 +169,14 @@ http.interceptors.response.use( } if (error.response && (error.response.status === 401 || error.response.status === 403)) { - clearAuthStorage(); - window.location.href = "/login?timeout=1"; - return Promise.reject(error); + // 免登录白名单接口失败时不能清除已存在的登录态,也不跳转登录页 + if (!isAuthWhitelistRequest(originalRequest.url)) { + clearAuthStorage(); + if (!window.location.pathname.startsWith("/login")) { + window.location.href = "/login?timeout=1"; + } + return Promise.reject(error); + } } const body = error.response?.data; diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json index 9ea44bc..43cda13 100644 --- a/frontend/src/locales/en-US.json +++ b/frontend/src/locales/en-US.json @@ -109,12 +109,18 @@ "submit": "Login Now", "loggingIn": "Logging in...", "demoAccount": "Demo Account", - "heroTitle1": "Intelligent Meeting", + "heroTitle1": "Intelligent Meeting ", "heroTitle2": "Real-time Voice", - "heroTitle3": "System", + "heroTitle3": " System", "heroDesc": "Full-process automated meeting records, voiceprint recognition, and smart summaries. Next-gen solution for team collaboration efficiency.", "enterpriseSecurity": "Enterprise Security", "multiLang": "Multi-language Support", + "downloadClient": "Download Desktop Client", + "platformWindows": "Windows", + "platformMacos": "macOS", + "platformHarmony": "HarmonyOS", + "platformLinux": "Linux", + "noPackage": "No installation package available", "loginTimeout": "Login timeout, please log in again" }, "devices": { diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json index 0c958f2..d290af9 100644 --- a/frontend/src/locales/zh-CN.json +++ b/frontend/src/locales/zh-CN.json @@ -115,6 +115,12 @@ "heroDesc": "全流程自动化会议记录,声纹识别与智能摘要。提升团队协作效率的新一代解决方案。", "enterpriseSecurity": "企业级安全", "multiLang": "多语言支持", + "downloadClient": "下载桌面客户端", + "platformWindows": "Windows", + "platformMacos": "macOS", + "platformHarmony": "鸿蒙", + "platformLinux": "Linux", + "noPackage": "暂无安装包", "loginTimeout": "登录超时,请重新登录" }, "devices": { diff --git a/frontend/src/pages/auth/login/index.less b/frontend/src/pages/auth/login/index.less index 5351b8a..60ea026 100644 --- a/frontend/src/pages/auth/login/index.less +++ b/frontend/src/pages/auth/login/index.less @@ -5,16 +5,26 @@ } .login-left { - flex: 1.1; + flex: 0 0 60.42%; background: #f9fafe; - padding: 56px 64px; + padding: 59px 67px; display: flex; flex-direction: column; - justify-content: space-between; position: relative; overflow: hidden; } +.login-left-bg { + position: absolute; + top: 50%; + left: 50%; + width: 110vh; + height: 110vw; + transform: translate(-50%, -50%) rotate(90deg); + background: url("/static/login/login-bg.png") center / cover no-repeat; + pointer-events: none; +} + .login-brand { display: flex; align-items: center; @@ -35,18 +45,18 @@ } .login-hero { - margin-top: -40px; + margin-top: 171px; z-index: 1; } .hero-title { - font-size: 36px; + font-size: 50px; font-weight: 700; - line-height: 1.2; + line-height: 46px; color: #333; - margin-bottom: 24px; + margin-bottom: 16px; + max-width: 605px; letter-spacing: 0; - text-wrap: balance; } .hero-accent { @@ -56,9 +66,75 @@ .hero-desc { font-size: 16px; - line-height: 1.8; + line-height: 30px; color: #596275; - max-width: 440px; + max-width: 605px; +} + +.login-download { + margin-top: 150px; + z-index: 1; +} + +.download-title { + font-size: 21px; + line-height: 30px; + letter-spacing: -0.33px; + color: #000; + margin-bottom: 24px; +} + +.download-list { + display: flex; + flex-wrap: wrap; + gap: 24px; +} + +.download-item { + display: inline-flex; + align-items: center; + gap: 16px; + padding: 16px 24px; + border: 1px solid #fff; + border-radius: 8px; + background: #fff; + cursor: pointer; + transition: background-image 0.2s ease, box-shadow 0.2s ease; +} + +.download-icon { + width: 32px; + height: 32px; + display: block; +} + +.download-name { + font-size: 20px; + line-height: 30px; + letter-spacing: -0.33px; + color: #000; + white-space: nowrap; +} + +.download-item:hover, +.download-item.is-active { + background-image: linear-gradient(124.68deg, #5cbbff 1.57%, #1677ff 59.96%); + box-shadow: 0 6px 16px rgba(22, 119, 255, 0.2); +} + +.download-item:hover .download-name, +.download-item.is-active .download-name { + color: #fff; +} + +.download-item:hover .download-icon, +.download-item.is-active .download-icon { + filter: brightness(0) invert(1); +} + +.download-item:focus-visible { + outline: 2px solid #1677ff; + outline-offset: 2px; } .login-left-footer { @@ -66,7 +142,8 @@ align-items: center; gap: 12px; color: #8c97a8; - font-size: 13px; + font-size: 14px; + margin-top: auto; z-index: 1; } @@ -88,7 +165,7 @@ .login-container { width: 100%; - max-width: 400px; + max-width: 420px; } .login-header { @@ -113,7 +190,8 @@ } .login-form .ant-input-affix-wrapper-lg { - padding: 10px 16px; + padding: 11px 16px; + border-color: #e6e6e6; border-radius: 4px; } @@ -125,7 +203,7 @@ .captcha-image-btn { padding: 0; width: 120px; - height: 46px; + height: 48px; flex-shrink: 0; border-radius: 4px; overflow: hidden; @@ -160,7 +238,7 @@ } .login-submit-btn { - height: 48px; + height: 50px; font-size: 16px; font-weight: 600; border-radius: 4px; @@ -179,12 +257,41 @@ font-variant-numeric: tabular-nums; } +@media (max-width: 1360px) { + .download-list { + gap: 16px; + } + + .download-item { + padding: 16px 20px; + } +} + @media (max-width: 1024px) { .login-left { padding: 48px; } .hero-title { font-size: 36px; + line-height: 44px; + } + + .login-hero { + margin-top: 96px; + } + + .login-download { + margin-top: 88px; + } +} + +@media (max-height: 760px) { + .login-hero { + margin-top: 64px; + } + + .login-download { + margin-top: 56px; } } diff --git a/frontend/src/pages/auth/login/index.tsx b/frontend/src/pages/auth/login/index.tsx index d78e830..24eaf81 100644 --- a/frontend/src/pages/auth/login/index.tsx +++ b/frontend/src/pages/auth/login/index.tsx @@ -1,15 +1,78 @@ import { Button, Checkbox, Form, Input, Typography, message } from "antd"; import { LockOutlined, ReloadOutlined, SafetyOutlined, UserOutlined } from "@ant-design/icons"; -import { useCallback, useEffect, useState } from "react"; +import {useCallback, useEffect, useMemo, useState} from "react"; import {Link as RouterLink} from "react-router-dom"; import { useTranslation } from "react-i18next"; import { getCurrentUser, getOpenPlatformConfig, getSystemParamValue } from "@/api"; import { fetchCaptcha, login, type CaptchaResponse } from "@/api/auth"; +import {fetchLatestClientDownloads, type ClientLatestDownload} from "@/api/business/client"; import type { SysPlatformConfig } from "@/types"; import "./index.less"; const {Title, Text} = Typography; +type PlatformStyle = { + /** 样式编码,仅用于图标与文案映射 */ + code: string; + nameKey: string; + icon: string; + /** 字典项编码匹配规则,兼容各环境 WIN/WINDOWS 等写法 */ + codePattern: RegExp; + /** 浏览器 UA 匹配规则,用于高亮当前设备对应的下载项 */ + uaPattern: RegExp; +}; + +const PLATFORM_STYLES: PlatformStyle[] = [ + { + code: "windows", + nameKey: "login.platformWindows", + icon: "/static/login/platform-windows.svg", + codePattern: /windows|win32|win64|^win$|^pc$/i, + uaPattern: /windows|win32|win64/i + }, + { + code: "macos", + nameKey: "login.platformMacos", + icon: "/static/login/platform-macos.svg", + codePattern: /mac|darwin|osx/i, + uaPattern: /macintosh|mac os x/i + }, + { + code: "harmonyos", + nameKey: "login.platformHarmony", + icon: "/static/login/platform-harmony.svg", + codePattern: /harmony|hmos/i, + uaPattern: /harmonyos|openharmony/i + }, + { + code: "linux", + nameKey: "login.platformLinux", + icon: "/static/login/platform-linux.svg", + codePattern: /linux|ubuntu|debian|deepin|kylin|uos|nfs/i, + uaPattern: /linux|ubuntu|debian|fedora/i + } +]; + +/** 字典未维护对应图标时的兜底图标 */ +const DEFAULT_PLATFORM_ICON = "/static/login/platform-linux.svg"; + +function platformStyleOf(platformCode?: string): PlatformStyle | undefined { + const code = (platformCode || "").trim(); + if (!code) { + return undefined; + } + return PLATFORM_STYLES.find((style) => style.codePattern.test(code)); +} + +function detectStyleCode() { + const source = `${navigator.userAgent} ${navigator.platform || ""}`; + if (/android|iphone|ipad|mobile/i.test(source)) { + return ""; + } + const matched = PLATFORM_STYLES.find((style) => style.uaPattern.test(source)); + return matched?.code || ""; +} + type LoginFormValues = { username: string; password: string; @@ -24,6 +87,9 @@ export default function Login() { const [captchaEnabled, setCaptchaEnabled] = useState(true); const [loading, setLoading] = useState(false); const [platformConfig, setPlatformConfig] = useState(null); + const [clientPackages, setClientPackages] = useState([]); + const [loginBgFailed, setLoginBgFailed] = useState(false); + const [logoFailed, setLogoFailed] = useState(false); const [form] = Form.useForm(); const loadCaptcha = useCallback(async () => { @@ -63,6 +129,66 @@ export default function Login() { } }, [t]); + useEffect(() => { + let active = true; + fetchLatestClientDownloads() + .then((list) => { + if (active) { + setClientPackages(list); + } + }) + .catch(() => { + if (active) { + setClientPackages([]); + } + }); + return () => { + active = false; + }; + }, []); + + useEffect(() => { + const url = platformConfig?.loginBgUrl; + if (!url) { + return; + } + const image = new Image(); + image.onload = () => setLoginBgFailed(false); + image.onerror = () => setLoginBgFailed(true); + image.src = url; + return () => { + image.onload = null; + image.onerror = null; + }; + }, [platformConfig?.loginBgUrl]); + + const activeStyleCode = useMemo(() => detectStyleCode(), []); + + // 字典项与当前访问设备匹配时高亮对应按钮,避免用户下载错平台 + const activePlatformCode = useMemo(() => { + if (!activeStyleCode) { + return ""; + } + const matched = clientPackages.find((item) => platformStyleOf(item.platformCode)?.code === activeStyleCode); + return matched?.platformCode || ""; + }, [activeStyleCode, clientPackages]); + + const handleDownloadClient = (item: ClientLatestDownload) => { + const downloadUrl = item.downloadUrl; + // 兼容未返回 hasPackage 的旧版后端:有下载地址即视为有安装包 + if (!downloadUrl || item.hasPackage === false) { + message.warning(t("login.noPackage")); + return; + } + const link = document.createElement("a"); + link.href = downloadUrl; + link.target = "_blank"; + link.rel = "noopener noreferrer"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }; + const onFinish = async (values: LoginFormValues) => { setLoading(true); try { @@ -112,16 +238,19 @@ export default function Login() { } }; - const loginStyle = platformConfig?.loginBgUrl + const loginBgUrl = platformConfig?.loginBgUrl && !loginBgFailed ? platformConfig.loginBgUrl : ""; + const logoUrl = platformConfig?.logoUrl && !logoFailed ? platformConfig.logoUrl : "/logo.svg"; + + const loginStyle = loginBgUrl ? { - backgroundImage: `url(${platformConfig.loginBgUrl})`, + backgroundImage: `url(${loginBgUrl})`, backgroundSize: "cover", backgroundPosition: "center", position: "relative" as const } : {}; - const leftStyle = platformConfig?.loginBgUrl + const leftStyle = loginBgUrl ? { ...loginStyle, background: "rgba(255, 255, 255, 0.2)", @@ -129,7 +258,7 @@ export default function Login() { } : {}; - const rightStyle = platformConfig?.loginBgUrl + const rightStyle = loginBgUrl ? { background: "rgba(255, 255, 255, 0.85)", backdropFilter: "blur(20px)" @@ -139,22 +268,51 @@ export default function Login() { return (
+ {!loginBgUrl ?