BUGFIX: 通过projectId获取pose transfer结果路径出错
This commit is contained in:
@@ -1316,7 +1316,130 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
if (flag) creditsService.updateChangedCredits(accountId, taskId);
|
if (flag) creditsService.updateChangedCredits(accountId, taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList) {
|
public List<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList, Long projectId, Boolean like) {
|
||||||
|
List<PoseTransformationVO> resultList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 处理按taskId列表查询的情况
|
||||||
|
if (taskIdList != null && !taskIdList.isEmpty()) {
|
||||||
|
for (String taskId : taskIdList) {
|
||||||
|
PoseTransformationVO vo = buildPoseTransformationVO(taskId, null);
|
||||||
|
if (vo != null) {
|
||||||
|
resultList.add(vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 处理按projectId和like查询的情况
|
||||||
|
else if (projectId != null) {
|
||||||
|
QueryWrapper<PoseTransformation> queryWrapper = new QueryWrapper<PoseTransformation>()
|
||||||
|
.eq("project_id", projectId)
|
||||||
|
.ne("task_status", "Fail");
|
||||||
|
|
||||||
|
if (like != null) {
|
||||||
|
queryWrapper.eq("is_liked", like ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PoseTransformation> poseTransformations = poseTransformationMapper.selectList(queryWrapper);
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(poseTransformations)) {
|
||||||
|
for (PoseTransformation item : poseTransformations) {
|
||||||
|
PoseTransformationVO vo = buildPoseTransformationVO(item.getUniqueId(), item);
|
||||||
|
if (vo != null && !isInvalidStatus(vo.getStatus())) {
|
||||||
|
resultList.add(vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PoseTransformationVO buildPoseTransformationVO(String taskId, PoseTransformation dbItem) {
|
||||||
|
String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue());
|
||||||
|
String key = generateResultKey + ":" + taskId;
|
||||||
|
String resultJson = redisUtil.getFromString(key);
|
||||||
|
|
||||||
|
PoseTransformationVO vo;
|
||||||
|
|
||||||
|
// 1. 优先从Redis获取数据
|
||||||
|
if (!StringUtil.isNullOrEmpty(resultJson)) {
|
||||||
|
vo = new Gson().fromJson(resultJson, PoseTransformationVO.class);
|
||||||
|
|
||||||
|
// 设置数据库中的额外字段
|
||||||
|
if (dbItem != null) {
|
||||||
|
vo.setId(dbItem.getId());
|
||||||
|
vo.setIsLiked(dbItem.getIsLiked());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理成功状态的数据
|
||||||
|
if ("Success".equals(vo.getStatus()) && !"wx".equals(type)) {
|
||||||
|
processAllUrls(vo, dbItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
vo.setResultType(CollectionType.POSE_TRANSFORM.getValue());
|
||||||
|
}
|
||||||
|
// 2. 处理wx类型的情况
|
||||||
|
else if ("wx".equals(type)) {
|
||||||
|
vo = getAnimateResult(taskId);
|
||||||
|
}
|
||||||
|
// 3. 处理既没有Redis数据也不是wx类型的情况
|
||||||
|
else {
|
||||||
|
// 如果有数据库记录
|
||||||
|
if (dbItem != null) {
|
||||||
|
vo = CopyUtil.copyObject(dbItem, PoseTransformationVO.class);
|
||||||
|
vo.setTaskId(taskId);
|
||||||
|
|
||||||
|
// 设置产品图片URL
|
||||||
|
if (dbItem.getProductImage() != null) {
|
||||||
|
vo.setProductImage(minioUtil.getPreSignedUrl(
|
||||||
|
dbItem.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果视频URL为空,直接返回
|
||||||
|
if (StringUtil.isNullOrEmpty(dbItem.getVideoUrl())) {
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
processAllUrls(vo, dbItem);
|
||||||
|
}
|
||||||
|
// 如果没有数据库记录
|
||||||
|
else {
|
||||||
|
vo = new PoseTransformationVO(taskId, "Executing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理父ID逻辑
|
||||||
|
processParentId(vo, dbItem != null ? dbItem :
|
||||||
|
poseTransformationMapper.selectOne(new QueryWrapper<PoseTransformation>().eq("unique_id", taskId)));
|
||||||
|
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processAllUrls(PoseTransformationVO vo, PoseTransformation dbItem) {
|
||||||
|
// 处理各种URL
|
||||||
|
processUrl(vo.getGifUrl(), url ->
|
||||||
|
vo.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME)));
|
||||||
|
processUrl(vo.getVideoUrl(), url ->
|
||||||
|
vo.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME)));
|
||||||
|
processUrl(vo.getFirstFrameUrl(), url ->
|
||||||
|
vo.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processParentId(PoseTransformationVO vo, PoseTransformation poseTransformation) {
|
||||||
|
if (poseTransformation != null) {
|
||||||
|
ToProductImageResult productResult = getProductResultByPath(poseTransformation.getProductImage());
|
||||||
|
if (productResult != null) {
|
||||||
|
Long parentId = userLikeGroupService.getParentIdByElementIdAndElementType(
|
||||||
|
productResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue());
|
||||||
|
vo.setParentId(parentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInvalidStatus(String status) {
|
||||||
|
return "Invalid".equals(status) || "Fail".equals(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public List<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList) {
|
||||||
ArrayList<PoseTransformationVO> poseTransformationVOS = new ArrayList<>();
|
ArrayList<PoseTransformationVO> poseTransformationVOS = new ArrayList<>();
|
||||||
for (String taskId : taskIdList) {
|
for (String taskId : taskIdList) {
|
||||||
String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue());
|
String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue());
|
||||||
@@ -1353,7 +1476,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
poseTransformationVOS.add(poseTransformationVO);
|
poseTransformationVOS.add(poseTransformationVO);
|
||||||
}
|
}
|
||||||
return poseTransformationVOS;
|
return poseTransformationVOS;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void updatePoseTransferStatus(String taskId, String status){
|
public void updatePoseTransferStatus(String taskId, String status){
|
||||||
PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper<PoseTransformation>().eq("unique_id", taskId));
|
PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper<PoseTransformation>().eq("unique_id", taskId));
|
||||||
@@ -1371,7 +1494,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
return toProductImageResultMapper.selectOne(qw);
|
return toProductImageResultMapper.selectOne(qw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PoseTransformationVO> getPoseTransformationResultList(Long projectId, boolean like) {
|
/*public List<PoseTransformationVO> getPoseTransformationResultList(Long projectId, boolean like) {
|
||||||
List<PoseTransformation> poseTransformations = poseTransformationMapper.selectList(new QueryWrapper<PoseTransformation>().eq("project_id", projectId)
|
List<PoseTransformation> poseTransformations = poseTransformationMapper.selectList(new QueryWrapper<PoseTransformation>().eq("project_id", projectId)
|
||||||
.eq("is_liked", like ? 1 : 0).ne("task_status", "Fail"));
|
.eq("is_liked", like ? 1 : 0).ne("task_status", "Fail"));
|
||||||
List<PoseTransformationVO> vos = new ArrayList<>();
|
List<PoseTransformationVO> vos = new ArrayList<>();
|
||||||
@@ -1434,7 +1557,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vos;
|
return vos;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// 辅助方法:处理URL
|
// 辅助方法:处理URL
|
||||||
private void processUrl(String url, Consumer<String> processor) {
|
private void processUrl(String url, Consumer<String> processor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user