完成在小程序端的功能
This commit is contained in:
@@ -8,6 +8,7 @@ import com.rj.dto.AsrResponse;
|
|||||||
import com.rj.entity.AudioManagementSegments;
|
import com.rj.entity.AudioManagementSegments;
|
||||||
import com.rj.service.IAudioManagementSegmentsService;
|
import com.rj.service.IAudioManagementSegmentsService;
|
||||||
import com.rj.service.ITtsRequestLogService;
|
import com.rj.service.ITtsRequestLogService;
|
||||||
|
import com.rj.tenant.TenantContextHolder;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -236,7 +237,7 @@ public class AudioManagementSegmentsController {
|
|||||||
LambdaUpdateWrapper<AudioManagementSegments> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<AudioManagementSegments> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
updateWrapper.eq(AudioManagementSegments::getId, id);
|
updateWrapper.eq(AudioManagementSegments::getId, id);
|
||||||
|
|
||||||
boolean success = audioManagementSegmentsService.update(updateEntity, updateWrapper);
|
boolean success = audioManagementSegmentsService.updateNoTenant(updateEntity, updateWrapper);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
result.put("success", false);
|
result.put("success", false);
|
||||||
@@ -263,15 +264,29 @@ public class AudioManagementSegmentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO 2: 启用异步线程处理转文本
|
// TODO 2: 启用异步线程处理转文本
|
||||||
|
// 获取租户ID:优先从segment对象获取,如果没有则从当前线程的租户上下文获取
|
||||||
|
final String tenantId = segment.getTenantId() != null
|
||||||
|
? segment.getTenantId()
|
||||||
|
: TenantContextHolder.getTenantId();
|
||||||
final String finalPresignedUrl = presignedUrl;
|
final String finalPresignedUrl = presignedUrl;
|
||||||
final String segmentId = id;
|
final String segmentId = id;
|
||||||
|
final String audioFileName = segment.getAudioFileOriginalName();
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
log.info("开始异步转文本处理,ID: {}", segmentId);
|
// 在异步线程中设置租户上下文
|
||||||
|
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||||
|
TenantContextHolder.setTenantId(tenantId);
|
||||||
|
log.info("异步线程中设置租户ID: {}, segmentId: {}", tenantId, segmentId);
|
||||||
|
} else {
|
||||||
|
log.warn("租户ID为空,segmentId: {}", segmentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("开始异步转文本处理,ID: {}, tenantId: {}", segmentId, tenantId);
|
||||||
|
|
||||||
AsrRequest asrRequest = new AsrRequest();
|
AsrRequest asrRequest = new AsrRequest();
|
||||||
asrRequest.setAudioUrl(finalPresignedUrl);
|
asrRequest.setAudioUrl(finalPresignedUrl);
|
||||||
asrRequest.setAudioName(segment.getAudioFileOriginalName());
|
asrRequest.setAudioName(audioFileName);
|
||||||
asrRequest.setModel("paraformer-v2"); // 使用默认模型
|
asrRequest.setModel("paraformer-v2"); // 使用默认模型
|
||||||
asrRequest.setFormat("wav"); // 默认格式
|
asrRequest.setFormat("wav"); // 默认格式
|
||||||
asrRequest.setSampleRate(16000); // 默认采样率
|
asrRequest.setSampleRate(16000); // 默认采样率
|
||||||
@@ -290,19 +305,26 @@ public class AudioManagementSegmentsController {
|
|||||||
|
|
||||||
LambdaUpdateWrapper<AudioManagementSegments> textUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<AudioManagementSegments> textUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
textUpdateWrapper.eq(AudioManagementSegments::getId, segmentId);
|
textUpdateWrapper.eq(AudioManagementSegments::getId, segmentId);
|
||||||
|
|
||||||
|
// 使用正常的update方法,因为已经设置了租户上下文
|
||||||
boolean updateSuccess = audioManagementSegmentsService.update(textUpdateEntity, textUpdateWrapper);
|
boolean updateSuccess = audioManagementSegmentsService.update(textUpdateEntity, textUpdateWrapper);
|
||||||
|
|
||||||
|
|
||||||
if (updateSuccess) {
|
if (updateSuccess) {
|
||||||
log.info("转文本结果保存成功,ID: {}, 文本长度: {}", segmentId, asrResponse.getText().length());
|
log.info("转文本结果保存成功,ID: {}, tenantId: {}, 文本长度: {}", segmentId, tenantId, asrResponse.getText().length());
|
||||||
} else {
|
} else {
|
||||||
log.error("转文本结果保存失败,ID: {}", segmentId);
|
log.error("转文本结果保存失败,ID: {}, tenantId: {}", segmentId, tenantId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = asrResponse != null ? asrResponse.getMessage() : "ASR响应为空";
|
String errorMsg = asrResponse != null ? asrResponse.getMessage() : "ASR响应为空";
|
||||||
log.error("转文本失败,ID: {}, error: {}", segmentId, errorMsg);
|
log.error("转文本失败,ID: {}, tenantId: {}, error: {}", segmentId, tenantId, errorMsg);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("异步转文本处理异常,ID: {}, error: {}", segmentId, e.getMessage(), e);
|
log.error("异步转文本处理异常,ID: {}, tenantId: {}, error: {}", segmentId, tenantId, e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
// 清理租户上下文,防止线程复用导致租户串用
|
||||||
|
TenantContextHolder.clear();
|
||||||
|
log.debug("清理异步线程租户上下文,segmentId: {}", segmentId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.rj.service;
|
package com.rj.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.rj.entity.AudioManagementSegments;
|
import com.rj.entity.AudioManagementSegments;
|
||||||
|
|
||||||
@@ -12,5 +14,8 @@ import com.rj.entity.AudioManagementSegments;
|
|||||||
*/
|
*/
|
||||||
public interface IAudioManagementSegmentsService extends IService<AudioManagementSegments> {
|
public interface IAudioManagementSegmentsService extends IService<AudioManagementSegments> {
|
||||||
|
|
||||||
|
@InterceptorIgnore(tenantLine = "true") // 禁用多租户拦截
|
||||||
|
public boolean updateNoTenant(AudioManagementSegments entity,
|
||||||
|
LambdaUpdateWrapper<AudioManagementSegments> updateWrapper) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.rj.service.impl;
|
package com.rj.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.rj.entity.AudioManagementSegments;
|
import com.rj.entity.AudioManagementSegments;
|
||||||
import com.rj.mapper.AudioManagementSegmentsMapper;
|
import com.rj.mapper.AudioManagementSegmentsMapper;
|
||||||
@@ -17,6 +19,12 @@ import org.springframework.stereotype.Service;
|
|||||||
public class AudioManagementSegmentsServiceImpl
|
public class AudioManagementSegmentsServiceImpl
|
||||||
extends ServiceImpl<AudioManagementSegmentsMapper, AudioManagementSegments>
|
extends ServiceImpl<AudioManagementSegmentsMapper, AudioManagementSegments>
|
||||||
implements IAudioManagementSegmentsService {
|
implements IAudioManagementSegmentsService {
|
||||||
|
@Override
|
||||||
|
@InterceptorIgnore(tenantLine = "true") // 禁用多租户拦截
|
||||||
|
public boolean updateNoTenant(AudioManagementSegments entity,
|
||||||
|
LambdaUpdateWrapper<AudioManagementSegments> updateWrapper) {
|
||||||
|
return super.update(entity, updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ public class TtsRequestLogServiceImpl implements ITtsRequestLogService {
|
|||||||
try {
|
try {
|
||||||
// 从transcriptionUrl下载识别结果
|
// 从transcriptionUrl下载识别结果
|
||||||
String transcriptionResult = downloadTranscriptionResult(taskResult.getTranscriptionUrl());
|
String transcriptionResult = downloadTranscriptionResult(taskResult.getTranscriptionUrl());
|
||||||
log.info("transcriptionResult: {}" , transcriptionResult);
|
// log.info("transcriptionResult: {}" , transcriptionResult);
|
||||||
|
|
||||||
if (transcriptionResult != null && !transcriptionResult.trim().isEmpty()) {
|
if (transcriptionResult != null && !transcriptionResult.trim().isEmpty()) {
|
||||||
// 解析transcription结果JSON
|
// 解析transcription结果JSON
|
||||||
|
|||||||
Reference in New Issue
Block a user