调整 音频合成, 头衔监测
This commit is contained in:
@@ -71,7 +71,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
LocalDateTime requestTime = LocalDateTime.now();
|
||||
|
||||
faceDetectLog.setRequestId(requestId);
|
||||
faceDetectLog.setModel("liveportrait-detect");
|
||||
faceDetectLog.setModel("liveportrait-detect"); //TODO 模型名称
|
||||
faceDetectLog.setImageUrl(imageUrl);
|
||||
faceDetectLog.setOwnerName(ownerName);
|
||||
faceDetectLog.setOwnerPhone(ownerPhone);
|
||||
@@ -261,7 +261,8 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
*/
|
||||
@Override
|
||||
public com.baomidou.mybatisplus.extension.plugins.pagination.Page<FaceDetectLog> getPageList(
|
||||
Integer current, Integer size, Boolean success, String startTime, String endTime) {
|
||||
Integer current, Integer size, Boolean success, String startTime, String endTime,
|
||||
String ownerName, String ownerPhone, String avatarName) {
|
||||
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<FaceDetectLog> page =
|
||||
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(current, size);
|
||||
@@ -279,6 +280,15 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
if (endTime != null && !endTime.trim().isEmpty()) {
|
||||
queryWrapper.le(FaceDetectLog::getRequestTime, endTime);
|
||||
}
|
||||
if (ownerName != null && !ownerName.trim().isEmpty()) {
|
||||
queryWrapper.like(FaceDetectLog::getOwnerName, ownerName);
|
||||
}
|
||||
if (ownerPhone != null && !ownerPhone.trim().isEmpty()) {
|
||||
queryWrapper.like(FaceDetectLog::getOwnerPhone, ownerPhone);
|
||||
}
|
||||
if (avatarName != null && !avatarName.trim().isEmpty()) {
|
||||
queryWrapper.like(FaceDetectLog::getAvatarName, avatarName);
|
||||
}
|
||||
|
||||
// 按请求时间倒序排列
|
||||
queryWrapper.orderByDesc(FaceDetectLog::getRequestTime);
|
||||
|
||||
151
src/main/java/com/rj/service/impl/VideoSynthesisServiceImpl.java
Normal file
151
src/main/java/com/rj/service/impl/VideoSynthesisServiceImpl.java
Normal file
@@ -0,0 +1,151 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.rj.dto.VideoSynthesisRequestDto;
|
||||
import com.rj.entity.VideoSynthesisLog;
|
||||
import com.rj.mapper.VideoSynthesisLogMapper;
|
||||
import com.rj.service.IVideoSynthesisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 视频合成服务实现类
|
||||
*
|
||||
* @author rj
|
||||
* @date 2025-01-02
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class VideoSynthesisServiceImpl implements IVideoSynthesisService {
|
||||
|
||||
@Autowired
|
||||
private VideoSynthesisLogMapper videoSynthesisLogMapper;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
@Value("${dashscope.api.key}")
|
||||
private String apiKey;
|
||||
|
||||
private static final String API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/";
|
||||
|
||||
@Override
|
||||
public VideoSynthesisLog synthesizeVideoAndSave(VideoSynthesisRequestDto request) {
|
||||
LocalDateTime startTime = LocalDateTime.now();
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
|
||||
VideoSynthesisLog synthesisLog = new VideoSynthesisLog();
|
||||
synthesisLog.setRequestId(requestId);
|
||||
synthesisLog.setRequestTime(startTime);
|
||||
synthesisLog.setSuccess(false);
|
||||
|
||||
// 使用BeanUtils复制相同名称的属性
|
||||
BeanUtils.copyProperties(request, synthesisLog);
|
||||
|
||||
try {
|
||||
log.info("开始视频合成,请求ID: {}, 图片URL: {}, 音频URL: {}",
|
||||
requestId, request.getImageUrl(), request.getAudioUrl());
|
||||
|
||||
// 构建请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("X-DashScope-Async", "enable");
|
||||
headers.set("Authorization", "Bearer " + apiKey);
|
||||
|
||||
// 构建请求体
|
||||
HttpEntity<VideoSynthesisRequestDto> entity = new HttpEntity<>(request, headers);
|
||||
|
||||
// 发送请求
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(API_URL, entity, String.class);
|
||||
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
synthesisLog.setResponseTime(endTime);
|
||||
synthesisLog.setProcessingTimeMs(java.time.Duration.between(startTime, endTime).toMillis());
|
||||
|
||||
// 解析响应
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
// 直接解析JSON响应
|
||||
String responseBody = response.getBody();
|
||||
log.info("API响应: {}", responseBody);
|
||||
|
||||
// 简单解析关键字段
|
||||
if (responseBody != null && responseBody.contains("task_id")) {
|
||||
// 这里可以添加更复杂的JSON解析逻辑
|
||||
// 暂时设置基本状态
|
||||
synthesisLog.setTaskStatus("PENDING");
|
||||
synthesisLog.setSuccess(true);
|
||||
} else {
|
||||
synthesisLog.setErrorMessage("API响应格式异常");
|
||||
synthesisLog.setSuccess(false);
|
||||
}
|
||||
|
||||
log.info("视频合成请求成功,任务ID: {}, 状态: {}",
|
||||
synthesisLog.getTaskId(), synthesisLog.getTaskStatus());
|
||||
} else {
|
||||
synthesisLog.setErrorMessage("HTTP请求失败,状态码: " + response.getStatusCode());
|
||||
log.error("视频合成请求失败,状态码: {}, 响应: {}", response.getStatusCode(), response.getBody());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
synthesisLog.setResponseTime(endTime);
|
||||
synthesisLog.setProcessingTimeMs(java.time.Duration.between(startTime, endTime).toMillis());
|
||||
synthesisLog.setErrorMessage("视频合成异常: " + e.getMessage());
|
||||
log.error("视频合成失败: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
// 保存日志
|
||||
saveVideoSynthesisLog(synthesisLog);
|
||||
return synthesisLog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveVideoSynthesisLog(VideoSynthesisLog synthesisLog) {
|
||||
try {
|
||||
synthesisLog.setCreatedAt(LocalDateTime.now());
|
||||
synthesisLog.setUpdatedAt(LocalDateTime.now());
|
||||
|
||||
int result = videoSynthesisLogMapper.insert(synthesisLog);
|
||||
log.info("视频合成日志保存{}: 请求ID={}, 任务ID={}, 成功={}",
|
||||
result > 0 ? "成功" : "失败", synthesisLog.getRequestId(), synthesisLog.getTaskId(), synthesisLog.getSuccess());
|
||||
return result > 0;
|
||||
} catch (Exception e) {
|
||||
log.error("保存视频合成日志失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoSynthesisLog getVideoSynthesisLogByRequestId(String requestId) {
|
||||
try {
|
||||
return videoSynthesisLogMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<VideoSynthesisLog>()
|
||||
.eq("request_id", requestId)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("根据请求ID查询视频合成日志失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoSynthesisLog getVideoSynthesisLogByTaskId(String taskId) {
|
||||
try {
|
||||
return videoSynthesisLogMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<VideoSynthesisLog>()
|
||||
.eq("task_id", taskId)
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("根据任务ID查询视频合成日志失败: {}", e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user