This commit is contained in:
2026-04-10 22:51:00 +08:00
parent 983d53268d
commit 72602eb245
2 changed files with 2 additions and 116 deletions

View File

@@ -1305,7 +1305,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageRecord.setPrompt(toProductImageDTO.getPrompt());
}
toProductImageRecordMapper.insert(toProductImageRecord);
log.info("【relight方法】插入to_product_image_record记录, recordId={}", toProductImageRecord.getId());
List<ToProductImageResultVO> result = new ArrayList<>();
@@ -1353,30 +1352,20 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
toProductImageResult.setStatus("Pending");
toProductImageResultMapper.insert(toProductImageResult);
log.info("【relight方法】插入to_product_image_result记录, resultId={}, taskId={}, elementType={}, elementId={}, isDefaultLike={}, parentId={}",
toProductImageResult.getId(), taskId, toProductImageResult.getElementType(),
toProductImageResult.getElementId(), toProductImageDTO.getIsDefaultLike(), toProductImageVO.getParentId());
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
// 先判断是否需要默认like
if (Objects.nonNull(toProductImageDTO.getIsDefaultLike()) && toProductImageDTO.getIsDefaultLike()) {
// 满足条件情况下默认添加到like
log.info("【relight方法】isDefaultLike=true准备添加collection_sort记录, resultId={}, parentId={}, projectId={}",
toProductImageResult.getId(), toProductImageVO.getParentId(), toProductImageDTO.getProjectId());
CollectionSort collectionSort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
log.info("【relight方法】addToProductLike返回结果, resultId={}, collectionSort={}",
toProductImageResult.getId(), collectionSort != null ? "id=" + collectionSort.getId() + ", sort=" + collectionSort.getSort() : "null");
// 重新排序
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
log.info("【relight方法】rearrangeChildSort返回结果, resultId={}, reSort={}", toProductImageResult.getId(), reSort);
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? Objects.isNull(collectionSort) ? null : collectionSort.getSort() : reSort);
toProductImageResult.setParentId(toProductImageVO.getParentId());
toProductImageResult.setUserLikeSortId(Objects.isNull(collectionSort) ? null : collectionSort.getId());
} else if (Objects.nonNull(toProductImageDTO.getIsDefaultLike()) && Objects.nonNull(toProductImageVO.getParentId())) {
toProductImageResult.setParentId(toProductImageVO.getParentId());
log.info("【relight方法】isDefaultLike存在但不为true不添加collection_sort记录, resultId={}, isDefaultLike={}, parentId={}",
toProductImageResult.getId(), toProductImageDTO.getIsDefaultLike(), toProductImageVO.getParentId());
// 默认不添加到like,但是需要有parentId,所以这里添加到collectionSort表中
// designService.addCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageDTO.getProjectId(), toProductImageVO.getParentId());
}
@@ -1410,30 +1399,20 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
toProductImageResult.setStatus("Pending");
toProductImageResultMapper.insert(toProductImageResult);
log.info("【relight方法】插入to_product_image_result记录, resultId={}, taskId={}, elementType={}, elementId={}, isDefaultLike={}, parentId={}",
toProductImageResult.getId(), taskId, toProductImageResult.getElementType(),
toProductImageResult.getElementId(), toProductImageDTO.getIsDefaultLike(), toProductImageVO.getParentId());
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
// 先判断是否需要默认like
if (Objects.nonNull(toProductImageDTO.getIsDefaultLike()) && toProductImageDTO.getIsDefaultLike()) {
// 满足条件情况下默认添加到like
log.info("【relight方法】isDefaultLike=true准备添加collection_sort记录, resultId={}, parentId={}, projectId={}",
toProductImageResult.getId(), toProductImageVO.getParentId(), toProductImageDTO.getProjectId());
CollectionSort collectionSort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
log.info("【relight方法】addToProductLike返回结果, resultId={}, collectionSort={}",
toProductImageResult.getId(), collectionSort != null ? "id=" + collectionSort.getId() + ", sort=" + collectionSort.getSort() : "null");
// 重新排序
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
log.info("【relight方法】rearrangeChildSort返回结果, resultId={}, reSort={}", toProductImageResult.getId(), reSort);
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? Objects.isNull(collectionSort) ? null : collectionSort.getSort() : reSort);
toProductImageResult.setParentId(toProductImageVO.getParentId());
toProductImageResult.setUserLikeSortId(Objects.isNull(collectionSort) ? null : collectionSort.getId());
} else if (Objects.nonNull(toProductImageDTO.getIsDefaultLike()) && Objects.nonNull(toProductImageVO.getParentId())) {
toProductImageResult.setParentId(toProductImageVO.getParentId());
log.info("【relight方法】isDefaultLike存在但不为true不添加collection_sort记录, resultId={}, isDefaultLike={}, parentId={}",
toProductImageResult.getId(), toProductImageDTO.getIsDefaultLike(), toProductImageVO.getParentId());
// 默认不添加到like,但是需要有parentId,所以这里添加到collectionSort表中
// designService.addCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageDTO.getProjectId(), toProductImageVO.getParentId());
}
@@ -1446,7 +1425,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
// 更新项目更新时间
projectService.modifyProjectUpdateTime(toProductImageDTO.getProjectId());
log.info("【relight方法】relight方法执行完成, projectId={}, 生成结果数量={}", projectId, result.size());
return result;
}
@@ -1455,79 +1433,46 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
List<MagicToolResultVO> results = new ArrayList<>();
Set<String> collect = new HashSet<>();
taskIdList.forEach(taskId -> {
log.info("【getRelightResult方法】开始处理taskId={}", taskId);
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
ToProductImageResult toProductImageResult = toProductImageResultMapper.selectOne(qw);
if (Objects.isNull(toProductImageResult)) {
log.error("【getRelightResult方法】未找到toProductImageResult记录, taskId={}", taskId);
throw new BusinessException("source.image.does.not.exist");
}
log.info("【getRelightResult方法】找到toProductImageResult记录, id={}, taskId={}, status={}, modelName={}, isLike={}",
toProductImageResult.getId(), taskId, toProductImageResult.getStatus(),
toProductImageResult.getModelName(), toProductImageResult.getIsLike());
// 查询collection_sort记录用于追踪
QueryWrapper<CollectionSort> sortQw = new QueryWrapper<>();
sortQw.lambda().eq(CollectionSort::getRelationId, toProductImageResult.getId())
.eq(CollectionSort::getRelationType, CollectionType.RELIGHT.getValue());
List<CollectionSort> beforeSorts = collectionSortMapper.selectList(sortQw);
log.info("【getRelightResult方法】处理前collection_sort记录数={}, resultId={}", beforeSorts.size(), toProductImageResult.getId());
if (!beforeSorts.isEmpty()) {
for (CollectionSort cs : beforeSorts) {
log.info("【getRelightResult方法】处理前collection_sort记录: id={}, relationId={}, sort={}", cs.getId(), cs.getRelationId(), cs.getSort());
}
}
ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId());
if (Objects.isNull(toProductImageRecord)) {
log.error("【getRelightResult方法】未找到toProductImageRecord记录, recordId={}", toProductImageResult.getToProductImageRecordId());
throw new BusinessException("This task does not exist.");
}
// 判断当任务从哪个模型获取结果
if (!StringUtil.isNullOrEmpty(toProductImageResult.getModelName())
&& toProductImageResult.getModelName().equals("flux")) {
log.info("【getRelightResult方法】使用flux模型处理, resultId={}", toProductImageResult.getId());
Project project = projectService.getById(toProductImageResult.getProjectId());
if (Objects.isNull(project)) {
log.error("【getRelightResult方法】未找到project记录, projectId={}", toProductImageResult.getProjectId());
throw new BusinessException("unknown project");
}
String fluxResult;
if (toProductImageResult.getStatus().equals("Success") && !StringUtil.isNullOrEmpty(toProductImageResult.getUrl())) {
log.info("【getRelightResult方法】数据库中已有成功结果直接使用, resultId={}", toProductImageResult.getId());
fluxResult = toProductImageResult.getUrl();
} else {
String objectName = project.getAccountId() + "/relight_image/" + taskId + ".png";
log.info("【getRelightResult方法】调用getFluxResult获取结果, resultId={}, objectName={}", toProductImageResult.getId(), objectName);
fluxResult = generateService.getFluxResult(taskId, objectName);
log.info("【getRelightResult方法】getFluxResult返回结果, resultId={}, fluxResult={}", toProductImageResult.getId(), fluxResult);
}
if (StringUtil.isNullOrEmpty(fluxResult)) {
log.warn("【getRelightResult方法】fluxResult为null判定为失败, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike());
toProductImageResult.setStatus("Fail");
toProductImageResultMapper.updateById(toProductImageResult);
if (toProductImageResult.getIsLike() != null && toProductImageResult.getIsLike() == 1) {
log.info("【getRelightResult方法】isLike=1准备调用sortRank删除collection_sort记录, resultId={}", toProductImageResult.getId());
sortRank(toProductImageResult);
} else {
log.info("【getRelightResult方法】isLike不等于1不删除collection_sort记录, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike());
}
results.add(new MagicToolResultVO(taskId, "Fail"));
} else if (fluxResult.equals("Fail") || fluxResult.equals("Pending")) {
log.warn("【getRelightResult方法】fluxResult为{},判定为失败/待处理, resultId={}, isLike={}", fluxResult, toProductImageResult.getId(), toProductImageResult.getIsLike());
toProductImageResult.setStatus(fluxResult);
toProductImageResultMapper.updateById(toProductImageResult);
if (fluxResult.equals("Fail") && toProductImageResult.getIsLike() != null && toProductImageResult.getIsLike() == 1) {
log.info("【getRelightResult方法】isLike=1准备调用sortRank删除collection_sort记录, resultId={}", toProductImageResult.getId());
if (toProductImageResult.getIsLike() != null && toProductImageResult.getIsLike() == 1) {
sortRank(toProductImageResult);
} else {
log.info("【getRelightResult方法】isLike不等于1不删除collection_sort记录, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike());
}
results.add(new MagicToolResultVO(taskId, fluxResult));
} else {
log.info("【getRelightResult方法】fluxResult有效调用processFluxResult处理成功结果, resultId={}", toProductImageResult.getId());
results.add(processFluxResult(fluxResult, toProductImageResult, taskId, toProductImageRecord.getPrompt()));
// 扣积分
Boolean flag = creditsService.taskCreditsDeduction(project.getAccountId(), taskId);
@@ -1538,21 +1483,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
creditsService.deleteCreditsDeduction(project.getAccountId(), taskId);
}
// 处理后查询collection_sort记录用于追踪
List<CollectionSort> afterSorts = collectionSortMapper.selectList(sortQw);
log.info("【getRelightResult方法】处理后collection_sort记录数={}, resultId={}", afterSorts.size(), toProductImageResult.getId());
if (!afterSorts.isEmpty()) {
for (CollectionSort cs : afterSorts) {
log.info("【getRelightResult方法】处理后collection_sort记录: id={}, relationId={}, sort={}", cs.getId(), cs.getRelationId(), cs.getSort());
}
} else if (!beforeSorts.isEmpty()) {
log.warn("【getRelightResult方法】collection_sort记录被删除了! resultId={}, 处理前记录数={}, 处理后记录数=0", toProductImageResult.getId(), beforeSorts.size());
}
return;
}
log.info("【getRelightResult方法】非flux模型从Redis获取结果, resultId={}", toProductImageResult.getId());
String key = relightResultKey + ":" + taskId;
MagicToolResultVO magicToolResultVO = new Gson().fromJson(redisUtil.getFromString(key), MagicToolResultVO.class);
if (!Objects.isNull(magicToolResultVO) && !StringUtil.isNullOrEmpty(magicToolResultVO.getUrl())) {
@@ -1584,9 +1517,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
if (!StringUtil.isNullOrEmpty(magicToolResultVO.getStatus())) collect.add(magicToolResultVO.getStatus());
results.add(magicToolResultVO);
log.info("【getRelightResult方法】taskId处理完成, taskId={}, 返回结果status={}", taskId, magicToolResultVO.getStatus());
});
log.info("【getRelightResult方法】所有taskId处理完成, 返回结果数={}", results.size());
return results;
}