BUGFIX:design中的排序问题

This commit is contained in:
2025-07-04 17:20:35 +08:00
parent f3632f53e3
commit 1b7c2041be
8 changed files with 108 additions and 25 deletions

View File

@@ -2,6 +2,28 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper; import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.CollectionSort; import com.ai.da.mapper.primary.entity.CollectionSort;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
public interface CollectionSortMapper extends CommonMapper<CollectionSort> { public interface CollectionSortMapper extends CommonMapper<CollectionSort> {
@Update("UPDATE collection_sort SET sort = sort + 1 " +
"WHERE project_id = #{projectId} " +
"AND relation_type = #{relationType} " +
"AND sort < #{originalSort}")
void increaseDesignSortBelow(
@Param("projectId") Long projectId,
@Param("relationType") String relationType,
@Param("originalSort") int originalSort
);
@Update("UPDATE collection_sort SET sort = sort + 1 " +
"WHERE parent_id = #{parentId} " +
"AND relation_type != 'Design' " +
"AND sort < #{originalSort}")
void increaseGenerateSortBelow(
@Param("parentId") Long parentId,
@Param("relationType") String relationType,
@Param("originalSort") int originalSort
);
} }

View File

@@ -13,11 +13,9 @@ import java.util.Date;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) @Accessors(chain = true)
@TableName("collection_sort") @TableName("collection_sort")
public class CollectionSort implements Serializable { public class CollectionSort extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private Long userLikeGroupId; private Long userLikeGroupId;
private Long userLikeId; private Long userLikeId;
private Integer sort; private Integer sort;

View File

@@ -22,5 +22,5 @@ public class PoseTransformDTO {
private String modelName; private String modelName;
private Long userLikeSortId; private Long parentId;
} }

View File

@@ -1,9 +1,12 @@
package com.ai.da.model.vo; package com.ai.da.model.vo;
import com.ai.da.mapper.primary.entity.ToProductImageResult; import com.ai.da.mapper.primary.entity.ToProductImageResult;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
public class ToProductImageVO extends ToProductImageResult { public class ToProductImageVO extends ToProductImageResult {
@ApiModelProperty("collection sort中的parentId, 在这里是父级的userLikeSortId")
private Long parentId;
} }

View File

@@ -48,6 +48,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO); List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO);
void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId);
void toProduct(String taskId); void toProduct(String taskId);
ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId); ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId);

View File

@@ -1271,6 +1271,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
if (null != collectionSortParentId) { if (null != collectionSortParentId) {
userLikeSort.setParentId(collectionSortParentId); userLikeSort.setParentId(collectionSortParentId);
} }
userLikeSort.setCreateTime(LocalDateTime.now());
collectionSortMapper.insert(userLikeSort); collectionSortMapper.insert(userLikeSort);
return userLikeSort; return userLikeSort;
} }

View File

@@ -37,7 +37,6 @@ import io.minio.errors.MinioException;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
@@ -1125,6 +1124,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return new GenerateResultVO(generateDetailId, minioUtil.getPreSignedUrl(minioPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME, true), "Success", category); return new GenerateResultVO(generateDetailId, minioUtil.getPreSignedUrl(minioPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME, true), "Success", category);
} }
@Resource
private UserLikeGroupService userLikeGroupService;
public String poseTransform(PoseTransformDTO poseTransformDTO){ public String poseTransform(PoseTransformDTO poseTransformDTO){
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
Long projectId = poseTransformDTO.getProjectId(); Long projectId = poseTransformDTO.getProjectId();
@@ -1163,6 +1165,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
poseTransformationMapper.insert(poseTransformation); poseTransformationMapper.insert(poseTransformation);
// 满足条件下添加到like // 满足条件下添加到like
addPoseTransferLike(poseTransformDTO, poseTransformation.getId()); addPoseTransferLike(poseTransformDTO, poseTransformation.getId());
userLikeGroupService.reArrangeSort(projectId, poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), poseTransformDTO.getParentId());
if (flag){ if (flag){
// 6、添加预扣除积分到redis // 6、添加预扣除积分到redis
creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum); creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum);
@@ -1174,10 +1178,10 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} }
private void addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){ private void addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){
if (Objects.nonNull(poseTransformDTO.getUserLikeSortId()) if (Objects.nonNull(poseTransformDTO.getParentId())
&& !poseTransformDTO.getUserLikeSortId().equals(0L)){ && !poseTransformDTO.getParentId().equals(0L)){
disOrLikePose(poseTransformationId, "like", disOrLikePose(poseTransformationId, "like",
poseTransformDTO.getProjectId(), poseTransformDTO.getUserLikeSortId()); poseTransformDTO.getProjectId(), poseTransformDTO.getParentId());
} }
} }

View File

@@ -463,7 +463,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl(), childFlag); taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl(), childFlag);
toProductImageResult.setModelName("flux"); toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("ToProductImage"); toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
} else { } else {
// 走模型 // 走模型
if (childFlag){ if (childFlag){
@@ -485,12 +485,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setUserLikeGroupId(userLikeGroupId); toProductImageResult.setUserLikeGroupId(userLikeGroupId);
} }
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength()); toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResult.setResultType("ToProductImage"); toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
toProductImageResultMapper.insert(toProductImageResult); toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60)); // toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult); result.add(toProductImageResult);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageDTO, toProductImageResult.getId()); addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId());
}else { }else {
if (StringUtils.isEmpty(prompt)) { if (StringUtils.isEmpty(prompt)) {
sb.append(",high quality clothing details,8K realistic,HDR"); sb.append(",high quality clothing details,8K realistic,HDR");
@@ -505,7 +507,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if (fluxTask){ if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag); taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag);
toProductImageResult.setModelName("flux"); toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("ToProductImage"); toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
} else { } else {
// 走模型 // 走模型
if (childFlag){ if (childFlag){
@@ -527,12 +529,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setUserLikeGroupId(userLikeGroupId); toProductImageResult.setUserLikeGroupId(userLikeGroupId);
} }
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength()); toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResult.setResultType("ToProductImage"); toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
toProductImageResultMapper.insert(toProductImageResult); toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60)); // toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult); result.add(toProductImageResult);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageDTO, toProductImageResult.getId()); addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId());
} }
i ++; i ++;
sb = new StringBuilder("The best quality, masterpiece, real image."); sb = new StringBuilder("The best quality, masterpiece, real image.");
@@ -544,14 +548,59 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return result; return result;
} }
private void addToProductLike(ToProductImageDTO toProductImageDTO, Long toProductImageResultId){ private void addToProductLike(Long parentId, Long toProductImageResultId, Long projectId){
if (Objects.nonNull(toProductImageDTO.getUserLikeSortId()) if (Objects.nonNull(parentId)
&& !toProductImageDTO.getUserLikeSortId().equals(0L)){ && !parentId.equals(0L)){
productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId), productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId),
toProductImageDTO.getProjectId(), toProductImageDTO.getUserLikeSortId())); projectId, parentId));
} }
} }
@Transactional
public void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId) {
// 1. 处理子集排序
rearrangeChildSort(generateResultId, parentId, relationType);
// 2. 处理父级排序
rearrangeParentSort(projectId, parentId);
}
private void rearrangeChildSort(Long childId, Long parentId, String relationType) {
if (Objects.isNull(childId)) {
return;
}
CollectionSort child = collectionSortMapper.selectOne(new QueryWrapper<CollectionSort>().eq("relation_id", childId));
if (child == null || !child.getRelationType().equals(relationType)) {
return;
}
if (child.getSort() == 1) {
return; // 已经是第一位,无需处理
}
// 更新其他子集的排序
if (!"Design".equals(relationType)) {
collectionSortMapper.increaseGenerateSortBelow(parentId, relationType, child.getSort());
}
// 更新当前子集为第一位
child.setSort(1);
child.setUpdateTime(LocalDateTime.now());
collectionSortMapper.updateById(child);
}
private void rearrangeParentSort(Long projectId, Long parentId) {
CollectionSort parent = collectionSortMapper.selectById(parentId);
if (parent == null || !"Design".equals(parent.getRelationType())) {
return;
}
if (parent.getSort() == 1) {
return; // 已经是第一位,无需处理
}
// 更新其他父级的排序
collectionSortMapper.increaseDesignSortBelow(projectId, "Design", parent.getSort());
// 更新当前父级为第一位
parent.setSort(1);
parent.setUpdateTime(LocalDateTime.now());
collectionSortMapper.updateById(parent);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void toProduct(String taskId) { public void toProduct(String taskId) {
@@ -940,7 +989,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(toProductImageId); ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(toProductImageId);
toProductImageResult.setIsLike(0); toProductImageResult.setIsLike(0);
toProductImageResultMapper.updateById(toProductImageResult); toProductImageResultMapper.updateById(toProductImageResult);
if (toProductImageResult.getResultType().equals("Relight")) { if (toProductImageResult.getResultType().equals(CollectionType.RELIGHT.getValue())) {
if (null != productImageLikeDTO.getCollectionSortParentId()) { if (null != productImageLikeDTO.getCollectionSortParentId()) {
designService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId()); designService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
} }
@@ -1063,7 +1112,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if (fluxTask){ if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, s, toProductImageResult1.getUrl(), false); taskId = generateService.flux(creditsEventsEnum, s, toProductImageResult1.getUrl(), false);
toProductImageResult.setModelName("flux"); toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("Relight"); toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
} else { } else {
// 走模型 // 走模型
pythonService.relight(toProductImageResult1.getUrl(), taskId, s, toProductImageDTO.getDirection(), relightType); pythonService.relight(toProductImageResult1.getUrl(), taskId, s, toProductImageDTO.getDirection(), relightType);
@@ -1083,19 +1132,21 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue()); toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
} }
toProductImageResult.setDirection(toProductImageDTO.getDirection()); toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResult.setResultType("Relight"); toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
toProductImageResultMapper.insert(toProductImageResult); toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60)); // toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult); result.add(toProductImageResult);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageDTO, toProductImageResult.getId()); addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId());
}else { }else {
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId()); ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
ToProductImageResult toProductImageResult = new ToProductImageResult(); ToProductImageResult toProductImageResult = new ToProductImageResult();
if (fluxTask){ if (fluxTask){
taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductElement.getUrl(), false); taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductElement.getUrl(), false);
toProductImageResult.setModelName("flux"); toProductImageResult.setModelName("flux");
toProductImageResult.setResultType("Relight"); toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
} else { } else {
// 走模型 // 走模型
pythonService.relight(toProductElement.getUrl(), taskId, s, toProductImageDTO.getDirection(), "overall"); pythonService.relight(toProductElement.getUrl(), taskId, s, toProductImageDTO.getDirection(), "overall");
@@ -1115,12 +1166,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue()); toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
} }
toProductImageResult.setDirection(toProductImageDTO.getDirection()); toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResult.setResultType("Relight"); toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
toProductImageResultMapper.insert(toProductImageResult); toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60)); // toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult); result.add(toProductImageResult);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageDTO, toProductImageResult.getId()); addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId());
} }
// 添加需要扣除的积分到预扣除区 // 添加需要扣除的积分到预扣除区
creditsService.addRecordToCreditsDeduction(userHolder.getId(), taskId, creditsEventsEnum); creditsService.addRecordToCreditsDeduction(userHolder.getId(), taskId, creditsEventsEnum);