diff --git a/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrPracticeSeedService.java b/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrPracticeSeedService.java index 823919a3..c4458598 100644 --- a/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrPracticeSeedService.java +++ b/backend/ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrPracticeSeedService.java @@ -1650,6 +1650,35 @@ public class AihrPracticeSeedService { throw new ServiceException("录音不属于当前账号,请重新录音后提交"); } + /** + * Ownership check keyed by the login user id only. Staging always records the + * app login (owner_user_id + phone), while daily-drill submission carries the + * org extPartyId — comparing that against the staged phone can never match, + * so daily answers validate by the unforgeable server-side user id instead. + */ + private void validateAudioOwnershipByUser(Long ossId, Long ownerUserId) { + if (ossId == null) { + return; + } + if (ownerUserId == null || ownerUserId <= 0) { + throw new ServiceException("录音归属校验失败,请重新录音后提交"); + } + try { + Integer count = jdbcTemplate.queryForObject(""" + SELECT COUNT(*) + FROM aihr_practice_audio_upload + WHERE tenant_id = ? AND oss_id = ? AND owner_user_id = ? + AND status IN ('staged', 'bound') + """, Integer.class, tenantId(), ossId, ownerUserId); + if (count != null && count > 0) { + return; + } + } catch (DataAccessException ignored) { + // Keep the ownership failure generic; do not leak database details. + } + throw new ServiceException("录音不属于当前账号,请重新录音后提交"); + } + @Transactional(rollbackFor = Exception.class) public boolean markReviewed(Long id) { return markReviewed(id, null); @@ -2800,7 +2829,7 @@ public class AihrPracticeSeedService { String answer = maskSensitiveText(firstNonBlank(request == null ? null : request.answer(), "")); String audioUrl = exposedAudioUrl(request == null ? null : request.audioUrl()); Long audioOssId = request == null ? null : request.audioOssId(); - validateAudioOwnership(audioOssId, extPartyId, ownerUserId); + validateAudioOwnershipByUser(audioOssId, ownerUserId); DailyDrillScore score = scoreDailyDrill(parts.question(), answer, parts.referenceAnswer()); LocalDateTime now = LocalDateTime.now(); int updated = jdbcTemplate.update(""" diff --git a/mobile-uni/src/pages/candidate/interview/index.vue b/mobile-uni/src/pages/candidate/interview/index.vue index c07df3f1..5e4da634 100644 --- a/mobile-uni/src/pages/candidate/interview/index.vue +++ b/mobile-uni/src/pages/candidate/interview/index.vue @@ -156,6 +156,7 @@ import { resetPageScroll } from '@/services/navigation'; import { chooseSpeechAudio, createSpeechPlaybackController, + normalizeOssId, transcribeSpeechBlob, transcribeSpeechFile } from '@/services/speech'; @@ -164,7 +165,7 @@ const currentPath = '/pages/candidate/interview/index'; const records = ref([]); const interviewQuestions = ref([]); const interviewAnswers = ref>({}); -const interviewAudioOssIds = ref>({}); +const interviewAudioOssIds = ref>({}); const interviewResult = ref(null); const interviewSessionId = ref(''); const interviewStatus = ref<'idle' | 'starting' | 'active' | 'submitting' | 'finished'>('idle'); @@ -325,10 +326,10 @@ const applyQuestionAsrResult = (questionId: string, result: AsrResponse) => { const text = (result.text || '').trim(); if (!text) throw new Error('语音没有识别到文字'); interviewAnswers.value = { ...interviewAnswers.value, [questionId]: text }; - const ossId = Number(result.ossId); + const ossId = normalizeOssId(result.ossId); interviewAudioOssIds.value = { ...interviewAudioOssIds.value, - [questionId]: Number.isFinite(ossId) ? ossId : undefined + [questionId]: ossId }; message.value = '语音已转成文字,请确认后提交'; }; diff --git a/mobile-uni/src/pages/user/practice/index.vue b/mobile-uni/src/pages/user/practice/index.vue index 9773f8d1..3b9ba52c 100644 --- a/mobile-uni/src/pages/user/practice/index.vue +++ b/mobile-uni/src/pages/user/practice/index.vue @@ -323,7 +323,7 @@ import { getSelectedPosition, isLoggedIn, rememberLoginRedirect } from '@/servic import { searchKnowledge } from '@/services/knowledge'; import { resetPageScroll } from '@/services/navigation'; import { ensureEmployeePosition } from '@/services/position'; -import { chooseSpeechAudio, createSpeechPlaybackController, transcribeSpeechBlob, transcribeSpeechFile } from '@/services/speech'; +import { chooseSpeechAudio, createSpeechPlaybackController, normalizeOssId, transcribeSpeechBlob, transcribeSpeechFile } from '@/services/speech'; import { createPageRequestScope, currentAccountKey, type RequestScopeTicket } from '@/services/request-scope'; type PracticeStatus = 'idle' | 'starting' | 'active' | 'submitting' | 'finished'; @@ -370,7 +370,7 @@ const assignments = ref([]); const practiceHistory = ref([]); const drillAnswers = ref>({}); const dailyAudioUrls = ref>({}); -const dailyAudioOssIds = ref>({}); +const dailyAudioOssIds = ref>({}); const assignmentLoading = ref(false); const answeringId = ref(null); const activeAssignmentId = ref(); @@ -384,7 +384,7 @@ const recordingStarting = ref(false); const recordingAssignmentId = ref(null); const transcribing = ref(false); const draftAudioUrl = ref(''); -const draftAudioOssId = ref(); +const draftAudioOssId = ref(); const speechState = ref<{ key: string; status: SpeechPlaybackStatus }>({ key: '', status: 'idle' }); const mediaRecorder = ref(null); const mediaStream = ref(null); @@ -599,8 +599,7 @@ const applyAsrResult = (result: { text?: string; audioUrl?: string; ossId?: numb const current = draft.value.trim(); draft.value = current ? `${current}\n${text}` : text; draftAudioUrl.value = result.audioUrl || ''; - const ossId = Number(result.ossId); - draftAudioOssId.value = Number.isFinite(ossId) ? ossId : undefined; + draftAudioOssId.value = normalizeOssId(result.ossId); message.value = '语音已转成文字,请确认后提交'; }; @@ -616,10 +615,10 @@ const applyDailyAsrResult = (assignmentId: number, result: { text?: string; audi ...dailyAudioUrls.value, [assignmentId]: result.audioUrl || '' }; - const ossId = Number(result.ossId); + const ossId = normalizeOssId(result.ossId); dailyAudioOssIds.value = { ...dailyAudioOssIds.value, - [assignmentId]: Number.isFinite(ossId) ? ossId : undefined + [assignmentId]: ossId }; message.value = '每日一练语音已转成文字,请确认后提交'; }; @@ -784,7 +783,7 @@ const loadAssignments = async (request: RequestScopeTicket = requests.begin('ass dailyAudioOssIds.value = Object.fromEntries( nextAssignments .filter((item) => item.audioOssId !== undefined && item.audioOssId !== null) - .map((item) => [item.id, Number(item.audioOssId)]) + .map((item) => [item.id, normalizeOssId(item.audioOssId)]) ); consumePendingAssignment(); } catch (error) { diff --git a/mobile-uni/src/services/candidate.ts b/mobile-uni/src/services/candidate.ts index 68505716..f942b358 100644 --- a/mobile-uni/src/services/candidate.ts +++ b/mobile-uni/src/services/candidate.ts @@ -101,7 +101,7 @@ export const saveInterviewAnswer = ( sessionId: string, questionId: string, answerText: string, - answerAudioOssId?: number + answerAudioOssId?: number | string ) => apiRequest({ url: '/api/recruit/interview/answer', diff --git a/mobile-uni/src/services/practice.ts b/mobile-uni/src/services/practice.ts index 0a7879f0..c0e14f1f 100644 --- a/mobile-uni/src/services/practice.ts +++ b/mobile-uni/src/services/practice.ts @@ -68,7 +68,7 @@ export const submitPracticeTurn = (params: { roundIndex: number; traineeText: string; traineeAudioUrl?: string; - traineeAudioOssId?: number; + traineeAudioOssId?: number | string; regenerate?: boolean; style?: string; }) => @@ -218,7 +218,7 @@ export const createPracticeAssignmentsBatch = (data: PracticeAssignmentBatchRequ timeout: 30000 }); -export const answerDailyDrill = (id: number, answer: string, audioUrl?: string, audioOssId?: number) => +export const answerDailyDrill = (id: number, answer: string, audioUrl?: string, audioOssId?: number | string) => apiRequest({ url: `/api/aihr/mobile/practice/assignments/${id}/answer`, method: 'POST', diff --git a/mobile-uni/src/services/speech.ts b/mobile-uni/src/services/speech.ts index c98a4e96..9059cc4a 100644 --- a/mobile-uni/src/services/speech.ts +++ b/mobile-uni/src/services/speech.ts @@ -3,6 +3,12 @@ import { apiRequest, apiUrl, authHeaders, readTextPayload } from './api'; const audioExtensions = ['.mp3', '.wav', '.m4a', '.webm', '.aac', '.ogg']; +// OSS 编号是雪花 ID,超出 JS 安全整数范围,必须按字符串透传,禁止 Number() 强转。 +export const normalizeOssId = (value: unknown): string | undefined => { + const text = String(value ?? '').trim(); + return /^\d+$/.test(text) ? text : undefined; +}; + export const chooseSpeechAudio = () => new Promise((resolve, reject) => { uni.chooseFile({