diff --git a/src/main/java/com/ai/da/mapper/primary/CollectionSortMapper.java b/src/main/java/com/ai/da/mapper/primary/CollectionSortMapper.java index be6f335b..d4f1a819 100644 --- a/src/main/java/com/ai/da/mapper/primary/CollectionSortMapper.java +++ b/src/main/java/com/ai/da/mapper/primary/CollectionSortMapper.java @@ -2,6 +2,28 @@ package com.ai.da.mapper.primary; import com.ai.da.common.config.mybatis.plus.CommonMapper; 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 { + @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 + ); } diff --git a/src/main/java/com/ai/da/mapper/primary/entity/CollectionSort.java b/src/main/java/com/ai/da/mapper/primary/entity/CollectionSort.java index 37f7eac9..b5d9a392 100644 --- a/src/main/java/com/ai/da/mapper/primary/entity/CollectionSort.java +++ b/src/main/java/com/ai/da/mapper/primary/entity/CollectionSort.java @@ -13,11 +13,9 @@ import java.util.Date; @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @TableName("collection_sort") -public class CollectionSort implements Serializable { +public class CollectionSort extends BaseEntity implements Serializable { private static final long serialVersionUID = 1L; - @TableId(value = "id", type = IdType.AUTO) - private Long id; private Long userLikeGroupId; private Long userLikeId; private Integer sort; diff --git a/src/main/java/com/ai/da/model/dto/PoseTransformDTO.java b/src/main/java/com/ai/da/model/dto/PoseTransformDTO.java index cef61e95..d48ecd06 100644 --- a/src/main/java/com/ai/da/model/dto/PoseTransformDTO.java +++ b/src/main/java/com/ai/da/model/dto/PoseTransformDTO.java @@ -22,5 +22,5 @@ public class PoseTransformDTO { private String modelName; - private Long userLikeSortId; + private Long parentId; } diff --git a/src/main/java/com/ai/da/model/vo/ToProductImageVO.java b/src/main/java/com/ai/da/model/vo/ToProductImageVO.java index 57b607be..a3a32754 100644 --- a/src/main/java/com/ai/da/model/vo/ToProductImageVO.java +++ b/src/main/java/com/ai/da/model/vo/ToProductImageVO.java @@ -1,9 +1,12 @@ package com.ai.da.model.vo; import com.ai.da.mapper.primary.entity.ToProductImageResult; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data public class ToProductImageVO extends ToProductImageResult { + @ApiModelProperty("collection sort中的parentId, 在这里是父级的userLikeSortId") + private Long parentId; } diff --git a/src/main/java/com/ai/da/service/UserLikeGroupService.java b/src/main/java/com/ai/da/service/UserLikeGroupService.java index bf05b1c3..19b49b04 100644 --- a/src/main/java/com/ai/da/service/UserLikeGroupService.java +++ b/src/main/java/com/ai/da/service/UserLikeGroupService.java @@ -48,6 +48,8 @@ public interface UserLikeGroupService extends IService { List toProduct(ToProductImageDTO toProductImageDTO); + void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId); + void toProduct(String taskId); ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId); diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index a32bb542..7b1f7b80 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1271,6 +1271,7 @@ public class DesignServiceImpl extends ServiceImpl impleme if (null != collectionSortParentId) { userLikeSort.setParentId(collectionSortParentId); } + userLikeSort.setCreateTime(LocalDateTime.now()); collectionSortMapper.insert(userLikeSort); return userLikeSort; } diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index c8afb5c3..c4dab989 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -37,7 +37,6 @@ import io.minio.errors.MinioException; import io.netty.util.internal.StringUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHost; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; @@ -1125,6 +1124,9 @@ public class GenerateServiceImpl extends ServiceImpl i return new GenerateResultVO(generateDetailId, minioUtil.getPreSignedUrl(minioPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME, true), "Success", category); } + @Resource + private UserLikeGroupService userLikeGroupService; + public String poseTransform(PoseTransformDTO poseTransformDTO){ Long accountId = UserContext.getUserHolder().getId(); Long projectId = poseTransformDTO.getProjectId(); @@ -1163,6 +1165,8 @@ public class GenerateServiceImpl extends ServiceImpl i poseTransformationMapper.insert(poseTransformation); // 满足条件下添加到like addPoseTransferLike(poseTransformDTO, poseTransformation.getId()); + userLikeGroupService.reArrangeSort(projectId, poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), poseTransformDTO.getParentId()); + if (flag){ // 6、添加预扣除积分到redis creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum); @@ -1174,10 +1178,10 @@ public class GenerateServiceImpl extends ServiceImpl i } private void addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){ - if (Objects.nonNull(poseTransformDTO.getUserLikeSortId()) - && !poseTransformDTO.getUserLikeSortId().equals(0L)){ + if (Objects.nonNull(poseTransformDTO.getParentId()) + && !poseTransformDTO.getParentId().equals(0L)){ disOrLikePose(poseTransformationId, "like", - poseTransformDTO.getProjectId(), poseTransformDTO.getUserLikeSortId()); + poseTransformDTO.getProjectId(), poseTransformDTO.getParentId()); } } diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 59cbbe44..4136223c 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -463,7 +463,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl().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 @Transactional(rollbackFor = Exception.class) public void toProduct(String taskId) { @@ -940,7 +989,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl