调整 音频合成, 头衔监测

This commit is contained in:
spllzh
2025-10-06 23:16:59 +08:00
parent 20378e8115
commit 76dedb657a
36 changed files with 1732 additions and 12 deletions

View File

@@ -40,10 +40,14 @@ public interface IFaceDetectLogService extends IService<FaceDetectLog> {
* @param success 成功状态筛选
* @param startTime 开始时间
* @param endTime 结束时间
* @param ownerName 所有人姓名
* @param ownerPhone 所有人电话
* @param avatarName 头像名字
* @return 分页结果
*/
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);
/**
* 获取统计信息

View File

@@ -0,0 +1,45 @@
package com.rj.service;
import com.rj.dto.VideoSynthesisRequestDto;
import com.rj.entity.VideoSynthesisLog;
/**
* 视频合成服务接口
*
* @author rj
* @date 2025-01-02
*/
public interface IVideoSynthesisService {
/**
* 执行视频合成并保存日志
*
* @param request 视频合成请求
* @return 视频合成日志
*/
VideoSynthesisLog synthesizeVideoAndSave(VideoSynthesisRequestDto request);
/**
* 保存视频合成日志
*
* @param log 视频合成日志
* @return 是否保存成功
*/
boolean saveVideoSynthesisLog(VideoSynthesisLog log);
/**
* 根据请求ID查询视频合成日志
*
* @param requestId 请求ID
* @return 视频合成日志
*/
VideoSynthesisLog getVideoSynthesisLogByRequestId(String requestId);
/**
* 根据任务ID查询视频合成日志
*
* @param taskId 任务ID
* @return 视频合成日志
*/
VideoSynthesisLog getVideoSynthesisLogByTaskId(String taskId);
}

View File

@@ -63,6 +63,8 @@ public interface ICustomerProfileAnalysisService extends IService<CustomerProfil

View File

@@ -98,6 +98,8 @@ public class CustomerProfileAnalysisServiceImpl extends ServiceImpl<CustomerProf

View File

@@ -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);

View 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;
}
}
}

View File

@@ -65,6 +65,8 @@ public interface IMenuService extends IService<Menu> {

View File

@@ -65,6 +65,8 @@ public interface IUserRoleService extends IService<UserRole> {

View File

@@ -69,6 +69,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM

View File

@@ -69,6 +69,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR

View File

@@ -69,6 +69,8 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i