Commit 8f403de7 by jiang'yun

Merge remote-tracking branch 'origin/master'

parents 0f2803ec 1c2252dd
......@@ -121,4 +121,14 @@ public class HyjyxxController extends BaseController
return AjaxResult.success("会议转录任务已启动,请稍后查看结果");
}
/**
* 获取会议信息详细信息
*/
@GetMapping(value = "hyxx/{id}")
public AjaxResult hyxx(@PathVariable("id") Long id)
{
return success(hyjyxxService.selectHyjyxxById_xq(id));
}
}
......@@ -33,7 +33,7 @@ public class HyjyxxFile extends BaseEntity
private String fileName;
/** 附件时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "附件时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date fileTime;
......
......@@ -60,4 +60,6 @@ public interface IHyjyxxService
public int deleteHyjyxxById(Long id);
public int hyzl(Long id);
public Hyjyxx selectHyjyxxById_xq(Long id);
}
package com.ruoyi.project.ys.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.project.ys.domain.HyjyxxFile;
import com.ruoyi.project.ys.mapper.HyjyxxFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.ys.mapper.HyjyxxMapper;
......@@ -20,6 +24,13 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.ZoneId;
import static com.ruoyi.common.utils.SecurityUtils.getUserId;
......@@ -209,6 +220,127 @@ public class HyjyxxServiceImpl implements IHyjyxxService
}
}
@Autowired
private HyjyxxFileMapper hyjyxxFileMapper;
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS");
// 修正:最后一个说话人的区间结束时间(用一个远大于实际可能的时间,等效于“无穷大”)
private static final LocalDateTime MAX_TIME = LocalDateTime.of(2100, 1, 1, 0, 0, 0); // 2100年1月1日
@Override
public Hyjyxx selectHyjyxxById_xq(Long id)
{
Hyjyxx hyxx = hyjyxxMapper.selectHyjyxxById(id);
HyjyxxFile file = new HyjyxxFile();
file.setHyid(id);
List<HyjyxxFile> fileList = hyjyxxFileMapper.selectHyjyxxFileList(file);
String originalJson = hyxx.getYwBzh();
Date hysj =hyxx.getJxwcsj();
try {
// 初始化ObjectMapper
ObjectMapper objectMapper = new ObjectMapper();
// 解析JSON为ObjectNode列表(便于修改)
List<ObjectNode> speakerList = objectMapper.readValue(
originalJson,
new TypeReference<List<ObjectNode>>() {}
);
// 解析录音开始时间
LocalDateTime startTime = hysj.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDateTime();
// 遍历每个说话人,计算并添加真实时间
for (ObjectNode speakerNode : speakerList) {
// 获取timestamp字段
String timestamp = speakerNode.get("timestamp").asText();
// 计算真实时间
LocalDateTime realTime = calculateRealTime(startTime, timestamp); // 这个人说话开始
// 新增realTime字段
speakerNode.put("realTime", realTime.format(TIME_FORMATTER));
}
// 遍历每个说话人,计算并添加真实时间
for (int i = 0; i < speakerList.size(); i++){
ObjectNode speakerNode= speakerList.get(i);
String realTime = speakerNode.get("realTime").asText();
LocalDateTime currentStartTime = parseStringToLocalDateTime(realTime);
LocalDateTime intervalEnd; // 区间结束时间
// 构建区间:当前说话人开始时间 → 下一个说话人开始时间(最后一个说话人特殊处理)
if (i < speakerList.size() - 1) {
// 非最后一个说话人:区间结束 = 下一个说话人开始时间
intervalEnd = parseStringToLocalDateTime(speakerList.get(i + 1).get("realTime").asText());
} else {
// 最后一个说话人:区间结束 = 当前开始时间 + 延长时间
intervalEnd = MAX_TIME;
}
List<String> matchedScreenshots = new ArrayList<>();
for (HyjyxxFile hyjyxxFile : fileList) {
Date fileTime = hyjyxxFile.getFileTime();
LocalDateTime screenTime = fileTime.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDateTime();
if (screenTime.isAfter(currentStartTime) || screenTime.isEqual(currentStartTime)) {
if (screenTime.isBefore(intervalEnd)) {
matchedScreenshots.add(hyjyxxFile.getFileUrl());
}
}
}
speakerNode.putPOJO("file",matchedScreenshots);
}
// 输出处理后的JSON(可写入文件或返回)
String resultJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(speakerList);
/* System.out.println("处理后带真实时间的JSON:");
System.out.println(resultJson);*/
hyxx.setYwBzh(resultJson);
} catch (Exception e) {
e.printStackTrace();
}
return hyxx;
}
/**
* 计算真实时间:开始时间 + timestamp偏移量
*/
private static LocalDateTime calculateRealTime(LocalDateTime startTime, String timestamp) {
try {
// 拆分timestamp为 时:分:秒.毫秒(如"00:00:25.86" → 0时0分25秒86毫秒)
String[] timeParts = timestamp.split(":");
int hours = Integer.parseInt(timeParts[0]);
int minutes = Integer.parseInt(timeParts[1]);
String[] secAndMs = timeParts[2].split("\\.");
int seconds = Integer.parseInt(secAndMs[0]);
int millis = secAndMs.length > 1 ? Integer.parseInt(secAndMs[1]) : 0;
// 计算总偏移量(毫秒)
long totalMillis = hours * 3600000L + minutes * 60000L + seconds * 1000L + millis;
// 开始时间 + 偏移量
return startTime.plus(Duration.ofMillis(totalMillis));
} catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
throw new DateTimeParseException("解析timestamp失败:" + timestamp, timestamp, 0);
}
}
/**
* 工具方法:将String时间解析为LocalDateTime(处理解析异常)
*/
private static LocalDateTime parseStringToLocalDateTime(String timeStr) {
try {
return LocalDateTime.parse(timeStr, TIME_FORMATTER);
} catch (DateTimeParseException e) {
System.err.println("时间解析失败:" + timeStr + ",格式需为" + TIME_FORMATTER);
return null; // 解析失败返回null,后续跳过该数据
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment