视频模板代码框架
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.DetectVideoTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 检测视频模板日志服务接口
|
||||
*/
|
||||
public interface IDetectVideoTemplateService extends IService<DetectVideoTemplate> {
|
||||
|
||||
/**
|
||||
* 保存检测视频模板日志
|
||||
*
|
||||
* @param detectVideoTemplate 检测视频模板日志
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
boolean saveDetectVideoTemplateLog(DetectVideoTemplate detectVideoTemplate);
|
||||
|
||||
/**
|
||||
* 执行视频模板检测并保存日志
|
||||
*
|
||||
* @param videoUrl 视频URL
|
||||
* @param ownerName 所属人姓名
|
||||
* @param ownerPhone 所属人电话
|
||||
* @param avatarName 头像名称
|
||||
* @param model 模型名称
|
||||
* @return 检测结果日志
|
||||
*/
|
||||
DetectVideoTemplate detectVideoTemplateAndSave(String videoUrl, String ownerName, String ownerPhone, String avatarName, String model);
|
||||
|
||||
/**
|
||||
* 分页查询检测视频模板日志
|
||||
*
|
||||
* @param current 当前页
|
||||
* @param size 每页大小
|
||||
* @param success 是否成功
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param ownerName 所属人姓名
|
||||
* @param ownerPhone 所属人电话
|
||||
* @param avatarName 头像名称
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<DetectVideoTemplate> getPageList(Integer current, Integer size, Boolean success, String startTime, String endTime,
|
||||
String ownerName, String ownerPhone, String avatarName);
|
||||
|
||||
/**
|
||||
* 获取统计信息
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 统计信息
|
||||
*/
|
||||
Map<String, Object> getStatistics(String startTime, String endTime);
|
||||
}
|
||||
@@ -5,47 +5,47 @@ import com.rj.entity.FaceDetectLog;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 人脸检测日志服务接口
|
||||
* 图像检测日志服务接口
|
||||
*/
|
||||
public interface IFaceDetectLogService extends IService<FaceDetectLog> {
|
||||
|
||||
/**
|
||||
* 保存人脸检测日志
|
||||
* 保存图像检测日志
|
||||
* @param faceDetectLog 日志对象
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
boolean saveFaceDetectLog(FaceDetectLog faceDetectLog);
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志
|
||||
* 执行图像检测并保存日志
|
||||
* @param imageUrl 图片URL
|
||||
* @return 人脸检测日志对象
|
||||
* @return 图像检测日志对象
|
||||
*/
|
||||
FaceDetectLog detectFaceAndSave(String imageUrl);
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息)
|
||||
* 执行图像检测并保存日志(带扩展信息)
|
||||
* @param imageUrl 图片URL
|
||||
* @param ownerName 所属人姓名
|
||||
* @param ownerPhone 所属人电话
|
||||
* @param avatarName 头像名称
|
||||
* @return 人脸检测日志对象
|
||||
* @return 图像检测日志对象
|
||||
*/
|
||||
FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName);
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息和模型名)
|
||||
* 执行图像检测并保存日志(带扩展信息和模型名)
|
||||
* @param imageUrl 图片URL
|
||||
* @param ownerName 所属人姓名
|
||||
* @param ownerPhone 所属人电话
|
||||
* @param avatarName 头像名称
|
||||
* @param model 模型名称
|
||||
* @return 人脸检测日志对象
|
||||
* @return 图像检测日志对象
|
||||
*/
|
||||
FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName, String model);
|
||||
|
||||
/**
|
||||
* 分页查询人脸检测日志
|
||||
* 分页查询图像检测日志
|
||||
* @param current 当前页
|
||||
* @param size 每页大小
|
||||
* @param success 成功状态筛选
|
||||
|
||||
@@ -73,6 +73,8 @@ public interface ICustomerProfileAnalysisService extends IService<CustomerProfil
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ public class CustomerProfileAnalysisServiceImpl extends ServiceImpl<CustomerProf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.DetectVideoTemplate;
|
||||
import com.rj.mapper.DetectVideoTemplateMapper;
|
||||
import com.rj.service.IDetectVideoTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 检测视频模板日志服务实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DetectVideoTemplateServiceImpl extends ServiceImpl<DetectVideoTemplateMapper, DetectVideoTemplate> implements IDetectVideoTemplateService {
|
||||
|
||||
private static final String API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/aa-template-generation";
|
||||
|
||||
@Value("${dashscope.api.key:}")
|
||||
private String apiKey;
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public DetectVideoTemplateServiceImpl() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
this.objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveDetectVideoTemplateLog(DetectVideoTemplate detectVideoTemplate) {
|
||||
try {
|
||||
return save(detectVideoTemplate);
|
||||
} catch (Exception e) {
|
||||
log.error("保存检测视频模板日志失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行视频模板检测并保存日志
|
||||
*/
|
||||
public DetectVideoTemplate detectVideoTemplateAndSave(String videoUrl, String ownerName, String ownerPhone, String avatarName, String model) {
|
||||
if (apiKey == null || apiKey.trim().isEmpty()) {
|
||||
log.error("DASHSCOPE_API_KEY未配置");
|
||||
return createErrorLog(videoUrl, "DASHSCOPE_API_KEY未配置", ownerName, ownerPhone, avatarName);
|
||||
}
|
||||
|
||||
// 创建日志记录
|
||||
DetectVideoTemplate detectVideoTemplate = new DetectVideoTemplate();
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
LocalDateTime requestTime = LocalDateTime.now();
|
||||
|
||||
detectVideoTemplate.setRequestId(requestId);
|
||||
// 设置模型名称,如果未提供则使用默认值
|
||||
String modelName = (model != null && !model.trim().isEmpty()) ? model : "video-template-detect";
|
||||
detectVideoTemplate.setModel(modelName);
|
||||
log.info("使用模型: {}", modelName);
|
||||
detectVideoTemplate.setVideoUrl(videoUrl);
|
||||
detectVideoTemplate.setOwnerName(ownerName);
|
||||
detectVideoTemplate.setOwnerPhone(ownerPhone);
|
||||
detectVideoTemplate.setAvatarName(avatarName);
|
||||
detectVideoTemplate.setRequestTime(requestTime);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
// 创建请求体
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
requestBody.put("model", modelName);
|
||||
|
||||
Map<String, String> input = new HashMap<>();
|
||||
input.put("video_url", videoUrl);
|
||||
requestBody.put("input", input);
|
||||
|
||||
// 设置请求头
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(apiKey);
|
||||
log.info("发送视频模板检测请求,requestBody : {}, 请求参数headers: {}", requestBody , headers);
|
||||
|
||||
// 创建请求实体
|
||||
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||
|
||||
// 发送请求
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
API_URL,
|
||||
HttpMethod.POST,
|
||||
requestEntity,
|
||||
String.class
|
||||
);
|
||||
|
||||
log.info("发送视频模板检测请求,请求ID: {}, 视频URL: {}", requestId, videoUrl);
|
||||
|
||||
// 计算处理时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
long processingTime = endTime - startTime;
|
||||
|
||||
// 更新日志记录
|
||||
detectVideoTemplate.setResponseTime(LocalDateTime.now());
|
||||
detectVideoTemplate.setStatusCode(response.getStatusCode().value());
|
||||
detectVideoTemplate.setProcessingTimeMs(processingTime);
|
||||
detectVideoTemplate.setResponseData(response.getBody());
|
||||
|
||||
// 处理响应
|
||||
log.info("视频模板检测响应,状态码: {}, 处理时间: {}ms", response.getStatusCode(), processingTime);
|
||||
|
||||
// 解析JSON响应
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
JsonNode jsonResponse = objectMapper.readTree(response.getBody());
|
||||
|
||||
// 根据success字段判断是否成功
|
||||
boolean isSuccess = false;
|
||||
if (jsonResponse.has("output") && jsonResponse.get("output").has("success")) {
|
||||
isSuccess = jsonResponse.get("output").get("success").asBoolean();
|
||||
detectVideoTemplate.setSuccess(isSuccess);
|
||||
|
||||
log.info("视频模板检测结果 - success: {}", isSuccess);
|
||||
} else {
|
||||
// 如果没有success字段,则根据HTTP状态码判断
|
||||
isSuccess = response.getStatusCode().is2xxSuccessful();
|
||||
detectVideoTemplate.setSuccess(isSuccess);
|
||||
}
|
||||
|
||||
// 检查是否有检测到模板
|
||||
if (jsonResponse.has("output")) {
|
||||
JsonNode output = jsonResponse.get("output");
|
||||
|
||||
// 解析模板ID
|
||||
if (output.has("template_id")) {
|
||||
String templateId = output.get("template_id").asText();
|
||||
detectVideoTemplate.setTemplateId(templateId);
|
||||
log.info("检测到的模板ID: {}", templateId);
|
||||
}
|
||||
|
||||
// 记录message信息
|
||||
if (output.has("message")) {
|
||||
String message = output.get("message").asText();
|
||||
log.info("检测消息: {}", message);
|
||||
}
|
||||
}
|
||||
|
||||
// 记录请求ID
|
||||
if (jsonResponse.has("request_id")) {
|
||||
String apiRequestId = jsonResponse.get("request_id").asText();
|
||||
log.info("API请求ID: {}", apiRequestId);
|
||||
}
|
||||
|
||||
// 记录使用情况
|
||||
if (jsonResponse.has("usage")) {
|
||||
JsonNode usage = jsonResponse.get("usage");
|
||||
log.info("使用情况: {}", usage.toString());
|
||||
}
|
||||
} else {
|
||||
// HTTP状态码不是200,直接标记为失败
|
||||
detectVideoTemplate.setSuccess(false);
|
||||
}
|
||||
|
||||
// 保存到数据库
|
||||
boolean saved = saveDetectVideoTemplateLog(detectVideoTemplate);
|
||||
if (saved) {
|
||||
log.info("视频模板检测日志已保存,请求ID: {}", requestId);
|
||||
} else {
|
||||
log.error("保存视频模板检测日志失败,请求ID: {}", requestId);
|
||||
}
|
||||
|
||||
return detectVideoTemplate;
|
||||
|
||||
} catch (HttpClientErrorException e) {
|
||||
return handleError(detectVideoTemplate, e, "客户端错误 (4xx): " + e.getStatusCode(), startTime);
|
||||
} catch (HttpServerErrorException e) {
|
||||
return handleError(detectVideoTemplate, e, "服务器错误 (5xx): " + e.getStatusCode(), startTime);
|
||||
} catch (Exception e) {
|
||||
return handleError(detectVideoTemplate, e, "视频模板检测请求失败: " + e.getMessage(), startTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理错误并保存到数据库
|
||||
*/
|
||||
private DetectVideoTemplate handleError(DetectVideoTemplate detectVideoTemplate, Exception e, String errorMessage, long startTime) {
|
||||
long endTime = System.currentTimeMillis();
|
||||
long processingTime = endTime - startTime;
|
||||
|
||||
detectVideoTemplate.setResponseTime(LocalDateTime.now());
|
||||
detectVideoTemplate.setSuccess(false);
|
||||
detectVideoTemplate.setProcessingTimeMs(processingTime);
|
||||
detectVideoTemplate.setErrorMessage(errorMessage);
|
||||
|
||||
if (e instanceof HttpClientErrorException) {
|
||||
detectVideoTemplate.setStatusCode(((HttpClientErrorException) e).getStatusCode().value());
|
||||
detectVideoTemplate.setResponseData(((HttpClientErrorException) e).getResponseBodyAsString());
|
||||
} else if (e instanceof HttpServerErrorException) {
|
||||
detectVideoTemplate.setStatusCode(((HttpServerErrorException) e).getStatusCode().value());
|
||||
detectVideoTemplate.setResponseData(((HttpServerErrorException) e).getResponseBodyAsString());
|
||||
}
|
||||
|
||||
log.error("视频模板检测失败: {}", errorMessage);
|
||||
log.error("错误详情: {}", e.getMessage());
|
||||
|
||||
// 保存错误日志到数据库
|
||||
try {
|
||||
saveDetectVideoTemplateLog(detectVideoTemplate);
|
||||
log.info("错误日志已保存,请求ID: {}", detectVideoTemplate.getRequestId());
|
||||
} catch (Exception saveException) {
|
||||
log.error("保存错误日志失败: {}", saveException.getMessage());
|
||||
}
|
||||
|
||||
return detectVideoTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建错误日志
|
||||
*/
|
||||
private DetectVideoTemplate createErrorLog(String videoUrl, String errorMessage, String ownerName, String ownerPhone, String avatarName) {
|
||||
DetectVideoTemplate detectVideoTemplate = new DetectVideoTemplate();
|
||||
detectVideoTemplate.setRequestId(UUID.randomUUID().toString());
|
||||
detectVideoTemplate.setModel("video-template-detect");
|
||||
detectVideoTemplate.setVideoUrl(videoUrl);
|
||||
detectVideoTemplate.setOwnerName(ownerName);
|
||||
detectVideoTemplate.setOwnerPhone(ownerPhone);
|
||||
detectVideoTemplate.setAvatarName(avatarName);
|
||||
detectVideoTemplate.setRequestTime(LocalDateTime.now());
|
||||
detectVideoTemplate.setResponseTime(LocalDateTime.now());
|
||||
detectVideoTemplate.setSuccess(false);
|
||||
detectVideoTemplate.setErrorMessage(errorMessage);
|
||||
|
||||
try {
|
||||
saveDetectVideoTemplateLog(detectVideoTemplate);
|
||||
} catch (Exception e) {
|
||||
log.error("保存错误日志失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return detectVideoTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询检测视频模板日志
|
||||
*/
|
||||
@Override
|
||||
public com.baomidou.mybatisplus.extension.plugins.pagination.Page<DetectVideoTemplate> getPageList(
|
||||
Integer current, Integer size, Boolean success, String startTime, String endTime,
|
||||
String ownerName, String ownerPhone, String avatarName) {
|
||||
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<DetectVideoTemplate> page =
|
||||
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(current, size);
|
||||
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<DetectVideoTemplate> queryWrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (success != null) {
|
||||
queryWrapper.eq(DetectVideoTemplate::getSuccess, success);
|
||||
}
|
||||
if (startTime != null && !startTime.trim().isEmpty()) {
|
||||
queryWrapper.ge(DetectVideoTemplate::getRequestTime, startTime);
|
||||
}
|
||||
if (endTime != null && !endTime.trim().isEmpty()) {
|
||||
queryWrapper.le(DetectVideoTemplate::getRequestTime, endTime);
|
||||
}
|
||||
if (ownerName != null && !ownerName.trim().isEmpty()) {
|
||||
queryWrapper.like(DetectVideoTemplate::getOwnerName, ownerName);
|
||||
}
|
||||
if (ownerPhone != null && !ownerPhone.trim().isEmpty()) {
|
||||
queryWrapper.like(DetectVideoTemplate::getOwnerPhone, ownerPhone);
|
||||
}
|
||||
if (avatarName != null && !avatarName.trim().isEmpty()) {
|
||||
queryWrapper.like(DetectVideoTemplate::getAvatarName, avatarName);
|
||||
}
|
||||
|
||||
// 按请求时间倒序排列
|
||||
queryWrapper.orderByDesc(DetectVideoTemplate::getRequestTime);
|
||||
|
||||
return page(page, queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统计信息
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getStatistics(String startTime, String endTime) {
|
||||
Map<String, Object> statistics = new HashMap<>();
|
||||
|
||||
// 构建查询条件
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<DetectVideoTemplate> queryWrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
|
||||
// 时间范围筛选
|
||||
if (startTime != null && !startTime.trim().isEmpty()) {
|
||||
queryWrapper.ge(DetectVideoTemplate::getRequestTime, startTime);
|
||||
}
|
||||
if (endTime != null && !endTime.trim().isEmpty()) {
|
||||
queryWrapper.le(DetectVideoTemplate::getRequestTime, endTime);
|
||||
}
|
||||
|
||||
// 查询总数
|
||||
long totalCount = count(queryWrapper);
|
||||
|
||||
// 查询成功数
|
||||
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<DetectVideoTemplate> successWrapper =
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
|
||||
|
||||
// 时间范围筛选
|
||||
if (startTime != null && !startTime.trim().isEmpty()) {
|
||||
successWrapper.ge(DetectVideoTemplate::getRequestTime, startTime);
|
||||
}
|
||||
if (endTime != null && !endTime.trim().isEmpty()) {
|
||||
successWrapper.le(DetectVideoTemplate::getRequestTime, endTime);
|
||||
}
|
||||
successWrapper.eq(DetectVideoTemplate::getSuccess, true);
|
||||
long successCount = count(successWrapper);
|
||||
|
||||
// 查询失败数
|
||||
long failureCount = totalCount - successCount;
|
||||
|
||||
// 计算成功率
|
||||
double successRate = totalCount > 0 ? (double) successCount / totalCount * 100 : 0;
|
||||
|
||||
// 查询平均处理时间
|
||||
java.util.List<DetectVideoTemplate> logs = list(queryWrapper);
|
||||
double avgProcessingTime = logs.stream()
|
||||
.filter(log -> log.getProcessingTimeMs() != null)
|
||||
.mapToLong(DetectVideoTemplate::getProcessingTimeMs)
|
||||
.average()
|
||||
.orElse(0.0);
|
||||
|
||||
// 构建统计结果
|
||||
statistics.put("totalCount", totalCount);
|
||||
statistics.put("successCount", successCount);
|
||||
statistics.put("failureCount", failureCount);
|
||||
statistics.put("successRate", Math.round(successRate * 100.0) / 100.0);
|
||||
statistics.put("avgProcessingTimeMs", Math.round(avgProcessingTime));
|
||||
|
||||
log.info("统计信息查询完成,总数: {}, 成功数: {}, 失败数: {}, 成功率: {}%",
|
||||
totalCount, successCount, failureCount, successRate);
|
||||
|
||||
return statistics;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,15 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 人脸检测日志服务实现
|
||||
* 图像检测日志服务实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, FaceDetectLog> implements IFaceDetectLogService {
|
||||
|
||||
private static final String API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/face-detect";
|
||||
|
||||
private static final String API_URL_AA = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/aa-detect";
|
||||
|
||||
@Value("${dashscope.api.key:}")
|
||||
private String apiKey;
|
||||
|
||||
@@ -44,27 +45,27 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
try {
|
||||
return save(faceDetectLog);
|
||||
} catch (Exception e) {
|
||||
log.error("保存人脸检测日志失败: {}", e.getMessage(), e);
|
||||
log.error("保存图像检测日志失败: {}", e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志
|
||||
* 执行图像检测并保存日志
|
||||
*/
|
||||
public FaceDetectLog detectFaceAndSave(String imageUrl) {
|
||||
return detectFaceAndSave(imageUrl, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息)
|
||||
* 执行图像检测并保存日志(带扩展信息)
|
||||
*/
|
||||
public FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName) {
|
||||
return detectFaceAndSave(imageUrl, ownerName, ownerPhone, avatarName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行人脸检测并保存日志(带扩展信息和模型名)
|
||||
* 执行图像检测并保存日志(带扩展信息和模型名)
|
||||
*/
|
||||
public FaceDetectLog detectFaceAndSave(String imageUrl, String ownerName, String ownerPhone, String avatarName, String model) {
|
||||
if (apiKey == null || apiKey.trim().isEmpty()) {
|
||||
@@ -109,20 +110,29 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setBearerAuth(apiKey);
|
||||
log.info("发送人脸检测请求,requestBody : {}, 请求参数headers: {}", requestBody , headers);
|
||||
log.info("发送图像检测请求,requestBody : {}, 请求参数headers: {}", requestBody , headers);
|
||||
// 创建请求实体 parameters.ratio 希望检测确认的画幅,可选 "1:1"或"3:4"。默认值为"1:1"。
|
||||
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
|
||||
|
||||
ResponseEntity<String> response = null;
|
||||
if ( modelName.equals("animate-anyone-detect-gen2")){
|
||||
response = restTemplate.exchange(
|
||||
API_URL_AA,
|
||||
HttpMethod.POST,
|
||||
requestEntity,
|
||||
String.class
|
||||
);
|
||||
}else {
|
||||
response = restTemplate.exchange(
|
||||
API_URL,
|
||||
HttpMethod.POST,
|
||||
requestEntity,
|
||||
String.class
|
||||
);
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
log.info("发送人脸检测请求,请求ID: {}, 图片URL: {}", requestId, imageUrl);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
API_URL,
|
||||
HttpMethod.POST,
|
||||
requestEntity,
|
||||
String.class
|
||||
);
|
||||
|
||||
log.info("发送图像检测请求,请求ID: {}, 图片URL: {}", requestId, imageUrl);
|
||||
|
||||
// 计算处理时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
long processingTime = endTime - startTime;
|
||||
@@ -134,7 +144,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
faceDetectLog.setResponseData(response.getBody());
|
||||
|
||||
// 处理响应
|
||||
log.info("人脸检测响应,状态码: {}, 处理时间: {}ms", response.getStatusCode(), processingTime);
|
||||
log.info("图像检测响应,response: {}, 处理时间: {}ms", response.toString(), processingTime);
|
||||
|
||||
// 解析JSON响应
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
@@ -146,25 +156,34 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
isSuccess = jsonResponse.get("output").get("pass").asBoolean();
|
||||
faceDetectLog.setSuccess(isSuccess);
|
||||
|
||||
log.info("人脸检测结果 - pass: {}", isSuccess);
|
||||
log.info("图像检测结果 - 头像 pass: {}", isSuccess);
|
||||
}
|
||||
|
||||
if (jsonResponse.has("output") && jsonResponse.get("output").has("check_pass")) {
|
||||
isSuccess = jsonResponse.get("output").get("check_pass").asBoolean();
|
||||
faceDetectLog.setSuccess(isSuccess);
|
||||
|
||||
log.info("图像检测结果 (animate-anyone-detect-gen2 舞动人像 )- check_pass: {}", isSuccess);
|
||||
}
|
||||
|
||||
|
||||
// else {
|
||||
// // 如果没有pass字段,则根据HTTP状态码判断
|
||||
// isSuccess = response.getStatusCode().is2xxSuccessful();
|
||||
// faceDetectLog.setSuccess(isSuccess);
|
||||
// }
|
||||
|
||||
// 检查是否有检测到人脸
|
||||
// 检查是否有检测到图像
|
||||
int faceCount = 0;
|
||||
if (jsonResponse.has("output")) {
|
||||
JsonNode output = jsonResponse.get("output");
|
||||
|
||||
// 根据pass字段判断是否检测到人脸
|
||||
// 根据pass字段判断是否检测到图像
|
||||
if (output.has("pass")) {
|
||||
boolean pass = output.get("pass").asBoolean();
|
||||
faceDetectLog.setFaceCount(1);
|
||||
|
||||
log.info("人脸检测结果 - pass: {}, 检测到人脸数量: {}", pass, faceDetectLog.getFaceCount());
|
||||
log.info("图像检测结果 - pass: {}, 检测到图像数量: {}", pass, faceDetectLog.getFaceCount());
|
||||
|
||||
// 记录message信息
|
||||
if (output.has("message")) {
|
||||
@@ -173,13 +192,13 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
}
|
||||
}
|
||||
|
||||
// 解析人脸区域坐标(如果API返回中包含)
|
||||
// 解析图像区域坐标(如果API返回中包含)
|
||||
if (output.has("face_bbox")) {
|
||||
JsonNode faceBbox = output.get("face_bbox");
|
||||
if (faceBbox.isArray()) {
|
||||
String faceBboxStr = faceBbox.toString();
|
||||
faceDetectLog.setFaceBbox(faceBboxStr);
|
||||
log.info("人脸区域坐标: {}", faceBboxStr);
|
||||
log.info("图像区域坐标: {}", faceBboxStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,9 +240,9 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
// 保存到数据库
|
||||
boolean saved = saveFaceDetectLog(faceDetectLog);
|
||||
if (saved) {
|
||||
log.info("人脸检测日志已保存,请求ID: {}", requestId);
|
||||
log.info("图像检测日志已保存,请求ID: {}", requestId);
|
||||
} else {
|
||||
log.error("保存人脸检测日志失败,请求ID: {}", requestId);
|
||||
log.error("保存图像检测日志失败,请求ID: {}", requestId);
|
||||
}
|
||||
|
||||
return faceDetectLog;
|
||||
@@ -233,7 +252,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
} catch (HttpServerErrorException e) {
|
||||
return handleError(faceDetectLog, e, "服务器错误 (5xx): " + e.getStatusCode(), startTime);
|
||||
} catch (Exception e) {
|
||||
return handleError(faceDetectLog, e, "人脸检测请求失败: " + e.getMessage(), startTime);
|
||||
return handleError(faceDetectLog, e, "图像检测请求失败: " + e.getMessage(), startTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +276,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
faceDetectLog.setResponseData(((HttpServerErrorException) e).getResponseBodyAsString());
|
||||
}
|
||||
|
||||
log.error("人脸检测失败: {}", errorMessage);
|
||||
log.error("图像检测失败: {}", errorMessage);
|
||||
log.error("错误详情: {}", e.getMessage());
|
||||
|
||||
// 保存错误日志到数据库
|
||||
@@ -305,7 +324,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询人脸检测日志
|
||||
* 分页查询图像检测日志
|
||||
*/
|
||||
@Override
|
||||
public com.baomidou.mybatisplus.extension.plugins.pagination.Page<FaceDetectLog> getPageList(
|
||||
@@ -394,7 +413,7 @@ public class FaceDetectLogServiceImpl extends ServiceImpl<FaceDetectLogMapper, F
|
||||
.average()
|
||||
.orElse(0.0);
|
||||
|
||||
// 查询总人脸数量
|
||||
// 查询总图像数量
|
||||
int totalFaceCount = logs.stream()
|
||||
.filter(log -> log.getFaceCount() != null)
|
||||
.mapToInt(FaceDetectLog::getFaceCount)
|
||||
|
||||
@@ -66,10 +66,10 @@ public class VideoSynthesisServiceImpl implements IVideoSynthesisService {
|
||||
log.info("使用默认视频名称: {}", synthesisLog.getVideoName());
|
||||
}
|
||||
|
||||
// 设置人脸区域坐标(如果请求中有提供)
|
||||
// 设置图像区域坐标(如果请求中有提供)
|
||||
if (request.getFaceBbox() != null && !request.getFaceBbox().trim().isEmpty()) {
|
||||
synthesisLog.setFaceBbox(request.getFaceBbox());
|
||||
log.info("设置人脸区域坐标: {}", request.getFaceBbox());
|
||||
log.info("设置图像区域坐标: {}", request.getFaceBbox());
|
||||
}
|
||||
|
||||
// 设置动态区域坐标(如果请求中有提供)
|
||||
|
||||
@@ -76,6 +76,8 @@ public interface IMenuService extends IService<Menu> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> i
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user