计算录音结束
This commit is contained in:
@@ -14,6 +14,9 @@ public class AudioManagementConstants {
|
||||
public static final String SERVICE_STATUS_IN_SERVICE = "服务中";
|
||||
public static final String SERVICE_STATUS_SERVICE_FINISH = "服务结束";
|
||||
|
||||
public static final String TEXT_MERGED_STATUS_FINISH = "文本合并完成";
|
||||
public static final String TEXT_MERGED_STATUS_UNFINISH = "文本未合并";
|
||||
|
||||
/**
|
||||
* 私有构造函数,防止实例化
|
||||
*/
|
||||
|
||||
@@ -1242,11 +1242,20 @@ public class AudioFileController {
|
||||
AudioManagement audioManagement = new AudioManagement();
|
||||
audioManagement.setId(segment.getParentId());
|
||||
|
||||
// 如果文件名包含结束标志,修改主记录为结束状态
|
||||
if(segment.getAudioFileOriginalName().contains("-Z")){
|
||||
audioManagement.setServiceStatus(AudioManagementConstants.SERVICE_STATUS_SERVICE_FINISH);
|
||||
}
|
||||
// 根据 parentId 查询所有 audio_management_segments 记录
|
||||
LambdaQueryWrapper<AudioManagementSegments> parentQueryWrapper = new LambdaQueryWrapper<>();
|
||||
parentQueryWrapper.eq(AudioManagementSegments::getParentId, segment.getParentId())
|
||||
.orderByAsc(AudioManagementSegments::getChunkIndex); // 按 chunkIndex 排序
|
||||
List<AudioManagementSegments> allSegments = audioManagementSegmentsService.list(parentQueryWrapper);
|
||||
|
||||
// 检查是否满足设置服务状态为"服务结束"的条件
|
||||
if (checkServiceFinishConditions(allSegments)) {
|
||||
audioManagement.setServiceStatus(AudioManagementConstants.SERVICE_STATUS_SERVICE_FINISH);
|
||||
log.info("满足两个条件,设置服务状态为服务结束,parentId: {}", segment.getParentId());
|
||||
} else {
|
||||
log.debug("未满足条件,不设置服务结束状态,parentId: {}", segment.getParentId());
|
||||
}
|
||||
|
||||
AudioManagement byId = serviceManager.getAudioManagementService().getById(segment.getParentId());
|
||||
if (byId != null) {
|
||||
// 累加时长
|
||||
@@ -2082,6 +2091,113 @@ public class AudioFileController {
|
||||
return extractStringField(fallbackMap, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 audioFileOriginalName 中提取特数字字符串A
|
||||
* 截取规则:
|
||||
* 1. 找到 "-Z0" 或 "-A0" 之后的字符串B
|
||||
* 2. 从字符串B中截取 "-00" 之前的字符串,这就是特数字字符串A
|
||||
*
|
||||
* @param originalName 原始文件名
|
||||
* @return 特数字字符串A,如果无法提取则返回null
|
||||
*/
|
||||
private String extractSpecialNumberA(String originalName) {
|
||||
if (originalName == null || originalName.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 查找 "-Z0" 或 "-A0" 的位置
|
||||
int z0Index = originalName.indexOf("-Z0");
|
||||
int a0Index = originalName.indexOf("-A0");
|
||||
|
||||
int startIndex = -1;
|
||||
if (z0Index != -1) {
|
||||
startIndex = z0Index + 3; // "-Z0" 长度为3
|
||||
} else if (a0Index != -1) {
|
||||
startIndex = a0Index + 3; // "-A0" 长度为3
|
||||
}
|
||||
|
||||
if (startIndex == -1 || startIndex >= originalName.length()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取 "-Z0" 或 "-A0" 之后的字符串B
|
||||
String stringB = originalName.substring(startIndex);
|
||||
|
||||
// 从字符串B中截取 "-00" 之前的字符串
|
||||
int dash00Index = stringB.indexOf("-00");
|
||||
if (dash00Index == -1) {
|
||||
// 如果没有找到 "-00",返回整个字符串B
|
||||
return stringB.trim().isEmpty() ? null : stringB.trim();
|
||||
}
|
||||
|
||||
String specialNumberA = stringB.substring(0, dash00Index);
|
||||
return specialNumberA.trim().isEmpty() ? null : specialNumberA.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否满足设置服务状态为"服务结束"的条件
|
||||
* 需要同时满足两个条件:
|
||||
* 1. 所有 audioFileOriginalName 拼接后同时包含 "-Z0" 和 "-A0"
|
||||
* 2. 从所有 audioFileOriginalName 中提取的特数字字符串A转换为数字后,排序后相邻数字相差1
|
||||
*
|
||||
* @param allSegments 所有音频分段记录列表
|
||||
* @return 如果两个条件都满足返回true,否则返回false
|
||||
*/
|
||||
private boolean checkServiceFinishConditions(List<AudioManagementSegments> allSegments) {
|
||||
if (allSegments == null || allSegments.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (allSegments.size()==1){
|
||||
String audioFileOriginalName = allSegments.get(0).getAudioFileOriginalName();
|
||||
if (audioFileOriginalName.contains("-Z0")){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 条件1:将所有 audioFileOriginalName 拼接,检查是否同时包含 "-Z0" 和 "-A0"
|
||||
StringBuilder concatenatedNames = new StringBuilder();
|
||||
for (AudioManagementSegments seg : allSegments) {
|
||||
if (seg.getAudioFileOriginalName() != null) {
|
||||
concatenatedNames.append(seg.getAudioFileOriginalName());
|
||||
}
|
||||
}
|
||||
String allNames = concatenatedNames.toString();
|
||||
boolean condition1 = allNames.contains("-Z0") && allNames.contains("-A0");
|
||||
|
||||
if (!condition1) {
|
||||
log.debug("条件1不满足:未同时包含 '-Z0' 和 '-A0'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 条件2:提取特数字字符串A,转换为数字后排序,检查相邻数字是否相差1
|
||||
List<Integer> numberList = new ArrayList<>();
|
||||
for (AudioManagementSegments seg : allSegments) {
|
||||
String originalName = seg.getAudioFileOriginalName();
|
||||
if (originalName != null && !originalName.trim().isEmpty()) {
|
||||
String specialNumberA = extractSpecialNumberA(originalName);
|
||||
if (specialNumberA != null && !specialNumberA.trim().isEmpty()) {
|
||||
try {
|
||||
int number = Integer.parseInt(specialNumberA);
|
||||
numberList.add(number);
|
||||
} catch (NumberFormatException e) {
|
||||
log.debug("无法将特数字字符串转换为数字: {}", specialNumberA);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(numberList);
|
||||
for (int i = 1; i < numberList.size(); i++) {
|
||||
if (numberList.get(i) - numberList.get(i - 1) != 1) {
|
||||
log.debug("条件2不满足:相邻数字相差不为1,数字列表: {}", numberList);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("两个条件都满足,可以设置服务状态为服务结束");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理Gps数据类型(GPS日志)
|
||||
*/
|
||||
@@ -2201,11 +2317,63 @@ public class AudioFileController {
|
||||
|
||||
LambdaUpdateWrapper<AudioManagementSegments> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(AudioManagementSegments::getAudioFileOriginalName, filename);
|
||||
|
||||
|
||||
boolean updateResult = audioManagementSegmentsService.update(updateEntity, updateWrapper);
|
||||
|
||||
if (updateResult) {
|
||||
log.info("成功更新录音文本,deviceNo: {}, filename: {}", deviceNo, filename);
|
||||
|
||||
// 根据 audioFileOriginalName 查询记录,获取 parentId
|
||||
LambdaQueryWrapper<AudioManagementSegments> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(AudioManagementSegments::getAudioFileOriginalName, filename);
|
||||
List<AudioManagementSegments> segmentsByFilename = audioManagementSegmentsService.list(queryWrapper);
|
||||
|
||||
if (!segmentsByFilename.isEmpty() && segmentsByFilename.get(0).getParentId() != null) {
|
||||
String parentId = segmentsByFilename.get(0).getParentId();
|
||||
|
||||
// 根据 parentId 查询所有 audio_management_segments 记录
|
||||
LambdaQueryWrapper<AudioManagementSegments> parentQueryWrapper = new LambdaQueryWrapper<>();
|
||||
parentQueryWrapper.eq(AudioManagementSegments::getParentId, parentId)
|
||||
.orderByAsc(AudioManagementSegments::getChunkIndex); // 按 chunkIndex 排序
|
||||
List<AudioManagementSegments> allSegments = audioManagementSegmentsService.list(parentQueryWrapper);
|
||||
|
||||
// 检查每条记录的 recordingText 是否都不为空,并拼接
|
||||
boolean allHaveText = true;
|
||||
StringBuilder concatenatedText = new StringBuilder();
|
||||
|
||||
for (AudioManagementSegments segment : allSegments) {
|
||||
String segmentText = segment.getRecordingText();
|
||||
if (segmentText == null || segmentText.trim().isEmpty()) {
|
||||
allHaveText = false;
|
||||
break;
|
||||
}
|
||||
if (concatenatedText.length() > 0) {
|
||||
concatenatedText.append(" ======");
|
||||
}
|
||||
concatenatedText.append(segmentText);
|
||||
}
|
||||
|
||||
// 如果每条记录的 recordingText 都不为空,更新 audio_management 的 recording_text
|
||||
if (allHaveText && concatenatedText.length() > 0) {
|
||||
AudioManagement audioManagement = new AudioManagement();
|
||||
audioManagement.setId(parentId);
|
||||
audioManagement.setRecordingText(concatenatedText.toString());
|
||||
audioManagement.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
boolean updateAudioManagementResult = serviceManager.getAudioManagementService().updateById(audioManagement);
|
||||
if (updateAudioManagementResult) {
|
||||
log.info("成功更新AudioManagement的recordingText,parentId: {}, 拼接文本长度: {}",
|
||||
parentId, concatenatedText.length());
|
||||
} else {
|
||||
log.warn("更新AudioManagement的recordingText失败,parentId: {}", parentId);
|
||||
}
|
||||
} else {
|
||||
log.info("部分segment的recordingText为空,暂不更新AudioManagement的recordingText,parentId: {}", parentId);
|
||||
}
|
||||
} else {
|
||||
log.warn("未找到匹配的AudioManagementSegments记录或parentId为空,filename: {}", filename);
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("success", true);
|
||||
result.put("message", "语音转写数据更新成功");
|
||||
|
||||
@@ -458,6 +458,8 @@ public class AudioManagementController {
|
||||
audio.setServiceStatus(AudioManagementConstants.SERVICE_STATUS_SERVICE_FINISH);
|
||||
audio.setId(audioManagement.getId());
|
||||
audio.setDuration(total);
|
||||
audio.setEndTime( LocalDateTime.now());
|
||||
|
||||
boolean success = audioManagementService.updateById(audio);
|
||||
|
||||
if (success) {
|
||||
|
||||
@@ -143,6 +143,11 @@ public class AudioManagement implements Serializable {
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@TableField("end_time")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@TableField("update_time")
|
||||
private LocalDateTime updateTime;
|
||||
@@ -171,6 +176,11 @@ public class AudioManagement implements Serializable {
|
||||
@TableField("recording_text")
|
||||
private String recordingText;
|
||||
|
||||
|
||||
@Schema(description = "合并状态,录音文本内容")
|
||||
@TableField("text_merged_status")
|
||||
private String textMergedStatus;
|
||||
|
||||
@Schema(description = "概要总结")
|
||||
@TableField("summary")
|
||||
private String summary;
|
||||
|
||||
Reference in New Issue
Block a user