BUGFIX:design中的排序问题 倒序问题 再次修改

This commit is contained in:
2025-07-04 19:08:59 +08:00
parent 1b7c2041be
commit 4379b9cff1
10 changed files with 103 additions and 102 deletions

View File

@@ -2,6 +2,7 @@ package com.ai.da.controller;
import com.ai.da.common.enums.CreditsEventsEnum; import com.ai.da.common.enums.CreditsEventsEnum;
import com.ai.da.common.response.Response; import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.entity.CollectionSort;
import com.ai.da.model.dto.*; import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*; import com.ai.da.model.vo.*;
import com.ai.da.service.GenerateService; import com.ai.da.service.GenerateService;
@@ -101,7 +102,7 @@ public class GenerateController {
@ApiOperation(value = "请求进行姿势变换") @ApiOperation(value = "请求进行姿势变换")
@PostMapping("/poseTransform") @PostMapping("/poseTransform")
public Response<String> poseTransform(@Valid @RequestBody PoseTransformDTO poseTransformDTO) { public Response<ToProductImageResultVO> poseTransform(@Valid @RequestBody PoseTransformDTO poseTransformDTO) {
return Response.success(generateService.poseTransform(poseTransformDTO)); return Response.success(generateService.poseTransform(poseTransformDTO));
} }
@@ -115,7 +116,12 @@ public class GenerateController {
@ApiOperation("喜欢或取消喜欢姿势变换生成的图片") @ApiOperation("喜欢或取消喜欢姿势变换生成的图片")
@PostMapping("/likeOrDislike") @PostMapping("/likeOrDislike")
public Response<Object> likeOrDislike(@ApiParam("id") @RequestParam Long transformedId, @ApiParam("like || dislike") @RequestParam String likeOrDislike, @RequestParam("projectId") Long projectId, @RequestParam(value = "collectionSortParentId", required = false) Long collectionSortParentId) { public Response<Object> likeOrDislike(@ApiParam("id") @RequestParam Long transformedId, @ApiParam("like || dislike") @RequestParam String likeOrDislike, @RequestParam("projectId") Long projectId, @RequestParam(value = "collectionSortParentId", required = false) Long collectionSortParentId) {
return Response.success(generateService.disOrLikePose(transformedId, likeOrDislike, projectId, collectionSortParentId)); Object obj = generateService.disOrLikePose(transformedId, likeOrDislike, projectId, collectionSortParentId);
if (obj instanceof CollectionSort){
return Response.success(((CollectionSort) obj).getId());
}else {
return Response.success(obj);
}
} }
@ApiOperation(value = "修改模特比例") @ApiOperation(value = "修改模特比例")

View File

@@ -187,7 +187,7 @@ public class SavedCollectionController {
@ApiOperation(value = "toProduct") @ApiOperation(value = "toProduct")
@PostMapping("/toProduct") @PostMapping("/toProduct")
public Response<List<ToProductImageResult>> toProduct(@Valid @RequestBody ToProductImageDTO toProductImageDTO) { public Response<List<ToProductImageResultVO>> toProduct(@Valid @RequestBody ToProductImageDTO toProductImageDTO) {
return Response.success(userLikeGroupService.toProduct(toProductImageDTO)); return Response.success(userLikeGroupService.toProduct(toProductImageDTO));
} }
@@ -206,7 +206,8 @@ public class SavedCollectionController {
@ApiOperation(value = "productImageLike") @ApiOperation(value = "productImageLike")
@PostMapping("/productImageLike") @PostMapping("/productImageLike")
public Response<Long> productImageLike(@Valid @RequestBody ProductImageLikeDTO productImageLikeDTO) { public Response<Long> productImageLike(@Valid @RequestBody ProductImageLikeDTO productImageLikeDTO) {
return Response.success(userLikeGroupService.productImageLike(productImageLikeDTO)); CollectionSort collectionSort = userLikeGroupService.productImageLike(productImageLikeDTO);
return Response.success(Objects.nonNull(collectionSort) ? collectionSort.getId() : null);
} }
@ApiOperation(value = "collectionLikeUpdate") @ApiOperation(value = "collectionLikeUpdate")
@@ -242,7 +243,7 @@ public class SavedCollectionController {
@ApiOperation(value = "relight") @ApiOperation(value = "relight")
@PostMapping("/relight") @PostMapping("/relight")
public Response<List<ToProductImageResult>> relight(@Valid @RequestBody ToProductImageDTO toProductImageDTO) { public Response<List<ToProductImageResultVO>> relight(@Valid @RequestBody ToProductImageDTO toProductImageDTO) {
return Response.success(userLikeGroupService.relight(toProductImageDTO)); return Response.success(userLikeGroupService.relight(toProductImageDTO));
} }

View File

@@ -3,25 +3,14 @@ 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.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update; 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 " + @Update("UPDATE collection_sort SET sort = sort + 1 " +
"WHERE parent_id = #{parentId} " + "WHERE parent_id = #{parentId} " +
"AND relation_type != 'Design' " + "AND relation_type != 'Design' " +
"AND sort < #{originalSort}") "AND sort > #{originalSort}")
void increaseGenerateSortBelow( void increaseGenerateSortAbove(
@Param("parentId") Long parentId, @Param("parentId") Long parentId,
@Param("relationType") String relationType, @Param("relationType") String relationType,
@Param("originalSort") int originalSort @Param("originalSort") int originalSort

View File

@@ -18,6 +18,7 @@ public class CollectionSort extends BaseEntity implements Serializable {
private Long userLikeGroupId; private Long userLikeGroupId;
private Long userLikeId; private Long userLikeId;
// 页面排序采用倒序,最新的元素序号最大
private Integer sort; private Integer sort;
private Long projectId; private Long projectId;
private Long relationId; private Long relationId;

View File

@@ -23,4 +23,6 @@ public class PoseTransformDTO {
private String modelName; private String modelName;
private Long parentId; private Long parentId;
private Long userLikeSortId;
} }

View File

@@ -8,5 +8,7 @@ import lombok.Data;
public class ToProductImageVO extends ToProductImageResult { public class ToProductImageVO extends ToProductImageResult {
@ApiModelProperty("collection sort中的parentId, 在这里是父级的userLikeSortId") @ApiModelProperty("collection sort中的parentId, 在这里是父级的userLikeSortId")
private Long parentId; private Long parentId;
@ApiModelProperty("collection sort中的id, 在这里是用的子集里元素的userLikeSortId")
private Long userLikeSortId;
} }

View File

@@ -49,7 +49,7 @@ public interface GenerateService extends IService<Generate> {
GenerateResultVO modifySketch(GenerateModifyDTO generateModifyDTO); GenerateResultVO modifySketch(GenerateModifyDTO generateModifyDTO);
String poseTransform(PoseTransformDTO poseTransformDTO); ToProductImageResultVO poseTransform(PoseTransformDTO poseTransformDTO);
void processPoseTransformResult(String taskId, String gifUrl, String videoUrl, String imageUrl); void processPoseTransformResult(String taskId, String gifUrl, String videoUrl, String imageUrl);

View File

@@ -46,15 +46,15 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
Boolean exportSave(MultipartFile file, Long projectId, String module); Boolean exportSave(MultipartFile file, Long projectId, String module);
List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO); List<ToProductImageResultVO> toProduct(ToProductImageDTO toProductImageDTO);
void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId); Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId);
void toProduct(String taskId); void toProduct(String taskId);
ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId); ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId);
Long productImageLike(ProductImageLikeDTO productImageLikeDTO); CollectionSort productImageLike(ProductImageLikeDTO productImageLikeDTO);
List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList); List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList);
@@ -68,7 +68,7 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
void relight(String taskId); void relight(String taskId);
List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO); List<ToProductImageResultVO> relight(ToProductImageDTO toProductImageDTO);
List<MagicToolResultVO> getRelightResult(List<String> taskIdList); List<MagicToolResultVO> getRelightResult(List<String> taskIdList);

View File

@@ -1127,7 +1127,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
@Resource @Resource
private UserLikeGroupService userLikeGroupService; private UserLikeGroupService userLikeGroupService;
public String poseTransform(PoseTransformDTO poseTransformDTO){ public ToProductImageResultVO poseTransform(PoseTransformDTO poseTransformDTO){
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
Long projectId = poseTransformDTO.getProjectId(); Long projectId = poseTransformDTO.getProjectId();
String productImage = poseTransformDTO.getProductImage(); String productImage = poseTransformDTO.getProductImage();
@@ -1164,25 +1164,33 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
poseTransformation.setCreateTime(LocalDateTime.now()); poseTransformation.setCreateTime(LocalDateTime.now());
poseTransformationMapper.insert(poseTransformation); poseTransformationMapper.insert(poseTransformation);
// 满足条件下添加到like // 满足条件下添加到like
addPoseTransferLike(poseTransformDTO, poseTransformation.getId()); Integer sort = addPoseTransferLike(poseTransformDTO, poseTransformation.getId());
userLikeGroupService.reArrangeSort(projectId, poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), poseTransformDTO.getParentId()); Integer reSort = userLikeGroupService.rearrangeChildSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(),
poseTransformDTO.getParentId(), poseTransformDTO.getUserLikeSortId());
if (flag){ if (flag){
// 6、添加预扣除积分到redis // 6、添加预扣除积分到redis
creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum); creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum);
// 6.1 添加积分扣除记录到db // 6.1 添加积分扣除记录到db
creditsService.preInsert(accountId, creditsEventsEnum.getName(), taskId, Boolean.TRUE, null); creditsService.preInsert(accountId, creditsEventsEnum.getName(), taskId, Boolean.TRUE, null);
return taskId; ToProductImageResultVO toProductImageResultVO = new ToProductImageResultVO();
toProductImageResultVO.setTaskId(taskId);
toProductImageResultVO.setSort(Objects.isNull(reSort) ? sort : reSort);
return toProductImageResultVO;
} }
throw new BusinessException("pose transformation error", ResultEnum.ERROR.getCode()); throw new BusinessException("pose transformation error", ResultEnum.ERROR.getCode());
} }
private void addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){ private Integer addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){
if (Objects.nonNull(poseTransformDTO.getParentId()) if (Objects.nonNull(poseTransformDTO.getParentId())
&& !poseTransformDTO.getParentId().equals(0L)){ && !poseTransformDTO.getParentId().equals(0L)){
disOrLikePose(poseTransformationId, "like", Object object = disOrLikePose(poseTransformationId, "like",
poseTransformDTO.getProjectId(), poseTransformDTO.getParentId()); poseTransformDTO.getProjectId(), poseTransformDTO.getParentId());
if (object instanceof CollectionSort){
return ((CollectionSort) object).getSort();
}
} }
return null;
} }
@Resource @Resource
@@ -1324,13 +1332,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
public Object disOrLikePose(Long transformedId, String likeOrDislike, Long projectId, Long collectionSortParentId){ public Object disOrLikePose(Long transformedId, String likeOrDislike, Long projectId, Long collectionSortParentId){
PoseTransformation poseTransformation = poseTransformationMapper.selectById(transformedId); PoseTransformation poseTransformation = poseTransformationMapper.selectById(transformedId);
Long collectionSortId = null; CollectionSort collectionSort = null;
if (Objects.nonNull(poseTransformation)){ if (Objects.nonNull(poseTransformation)){
if (likeOrDislike.equals("like")){ if (likeOrDislike.equals("like")){
poseTransformation.setIsLiked((byte)1); poseTransformation.setIsLiked((byte)1);
if (null != collectionSortParentId) { if (null != collectionSortParentId) {
CollectionSort collectionSort = designService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId); collectionSort = designService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId);
collectionSortId = collectionSort.getId();
} }
}else if (likeOrDislike.equals("dislike")){ }else if (likeOrDislike.equals("dislike")){
poseTransformation.setIsLiked((byte)0); poseTransformation.setIsLiked((byte)0);
@@ -1343,8 +1350,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}else { }else {
return false; return false;
} }
if (null != collectionSortId) { if (Objects.nonNull(collectionSort)) {
return collectionSortId; return collectionSort;
} }
return true; return true;
} }

View File

@@ -373,7 +373,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private PoseTransformationMapper poseTransformationMapper; private PoseTransformationMapper poseTransformationMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO) { public List<ToProductImageResultVO> toProduct(ToProductImageDTO toProductImageDTO) {
// 判断用户当前积分是否够本次生成消耗 // 判断用户当前积分是否够本次生成消耗
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName()) boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
&& toProductImageDTO.getModelName().equals("flux"); && toProductImageDTO.getModelName().equals("flux");
@@ -412,7 +412,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
toProductImageRecordMapper.insert(toProductImageRecord); toProductImageRecordMapper.insert(toProductImageRecord);
List<ToProductImageResult> result = new ArrayList<>(); List<ToProductImageResultVO> result = new ArrayList<>();
boolean childFlag = !StringUtil.isNullOrEmpty(toProductImageDTO.getAgeGroup()) boolean childFlag = !StringUtil.isNullOrEmpty(toProductImageDTO.getAgeGroup())
&& toProductImageDTO.getAgeGroup().equals("Child"); && toProductImageDTO.getAgeGroup().equals("Child");
int i = 0; int i = 0;
@@ -456,7 +456,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}else { }else {
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR"); sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
} }
ToProductImageResult toProductImageResult = new ToProductImageResult(); ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
if (fluxTask){ if (fluxTask){
if (childFlag){ if (childFlag){
sb.append(", Children's face"); sb.append(", Children's face");
@@ -488,11 +488,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue()); 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);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId()); Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序 // 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId()); Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
result.add(toProductImageResult);
}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");
@@ -502,7 +505,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId(); taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId()); ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
ToProductImageResult toProductImageResult = new ToProductImageResult(); ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
if (fluxTask){ if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag); taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag);
@@ -532,11 +535,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue()); 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);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId()); Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序 // 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId()); Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
result.add(toProductImageResult);
} }
i ++; i ++;
sb = new StringBuilder("The best quality, masterpiece, real image."); sb = new StringBuilder("The best quality, masterpiece, real image.");
@@ -548,57 +554,39 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return result; return result;
} }
private void addToProductLike(Long parentId, Long toProductImageResultId, Long projectId){ private Integer addToProductLike(Long parentId, Long toProductImageResultId, Long projectId){
if (Objects.nonNull(parentId) if (Objects.nonNull(parentId) && !parentId.equals(0L)){
&& !parentId.equals(0L)){ CollectionSort collectionSort = productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId),
productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId),
projectId, parentId)); projectId, parentId));
return Objects.nonNull(collectionSort) ? collectionSort.getSort() : null;
} }
return null;
} }
/**
* 只有当使用子集中的元素进行生成时,才需要重新排序
* @param childId 生成元素的id
* @param parentId 父级id
* @param relationType 生成功能
* @param userLikeSortId 子集排序表中的id
*/
@Transactional @Transactional
public void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId) { public Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId) {
// 1. 处理子集排序 if (Objects.isNull(userLikeSortId)) {
rearrangeChildSort(generateResultId, parentId, relationType); return null;
// 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)); CollectionSort child = collectionSortMapper.selectOne(new QueryWrapper<CollectionSort>().eq("relation_id", childId));
if (child == null || !child.getRelationType().equals(relationType)) { if (!child.getRelationType().equals(relationType)) {
return; return null;
} }
if (child.getSort() == 1) { CollectionSort collectionSort = collectionSortMapper.selectById(userLikeSortId);
return; // 已经是第一位,无需处理 child.setSort(collectionSort.getSort());
} // 原来排序的大于等于userLikeSortId的排序的都要1
// 更新其他子集的排序 collectionSortMapper.increaseGenerateSortAbove(parentId, relationType, collectionSort.getSort() - 1);
if (!"Design".equals(relationType)) { // 当前的生成结果则填入userLikeSortId的排序位置
collectionSortMapper.increaseGenerateSortBelow(parentId, relationType, child.getSort());
}
// 更新当前子集为第一位
child.setSort(1);
child.setUpdateTime(LocalDateTime.now()); child.setUpdateTime(LocalDateTime.now());
collectionSortMapper.updateById(child); collectionSortMapper.updateById(child);
} return collectionSort.getSort();
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
@@ -690,7 +678,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
@Override @Override
public Long productImageLike(ProductImageLikeDTO productImageLikeDTO) { public CollectionSort productImageLike(ProductImageLikeDTO productImageLikeDTO) {
List<Long> toProductImageResultId = productImageLikeDTO.getToProductImageResultId(); List<Long> toProductImageResultId = productImageLikeDTO.getToProductImageResultId();
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>(); QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().in(ToProductImageResult::getId, toProductImageResultId); qw.lambda().in(ToProductImageResult::getId, toProductImageResultId);
@@ -698,19 +686,17 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setIsLike(1); toProductImageResult.setIsLike(1);
toProductImageResultMapper.update(toProductImageResult, qw); toProductImageResultMapper.update(toProductImageResult, qw);
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultId.get(0)); ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultId.get(0));
Long collectionSortId = null; CollectionSort collectionSort = null;
if (toProductImageResult1.getResultType().equals("Relight")) { if (toProductImageResult1.getResultType().equals("Relight")) {
if (null != productImageLikeDTO.getCollectionSortParentId()) { if (null != productImageLikeDTO.getCollectionSortParentId()) {
CollectionSort collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId()); collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSortId = collectionSort.getId();
} }
}else { }else {
if (null != productImageLikeDTO.getCollectionSortParentId()) { if (null != productImageLikeDTO.getCollectionSortParentId()) {
CollectionSort collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId()); collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSortId = collectionSort.getId();
} }
} }
return collectionSortId; return collectionSort;
} }
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
@@ -1046,7 +1032,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) { public List<ToProductImageResultVO> relight(ToProductImageDTO toProductImageDTO) {
// 判断用户当前积分是否够本次生成消耗 // 判断用户当前积分是否够本次生成消耗
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName()) boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
&& toProductImageDTO.getModelName().equals("flux"); && toProductImageDTO.getModelName().equals("flux");
@@ -1089,7 +1075,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
toProductImageRecordMapper.insert(toProductImageRecord); toProductImageRecordMapper.insert(toProductImageRecord);
List<ToProductImageResult> result = new ArrayList<>(); List<ToProductImageResultVO> result = new ArrayList<>();
int i = 0; int i = 0;
@@ -1108,7 +1094,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} }
} }
ToProductImageResult toProductImageResult = new ToProductImageResult(); ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
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");
@@ -1135,14 +1121,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue()); 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);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId()); Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序 // 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId()); Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
result.add(toProductImageResult);
}else { }else {
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId()); ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
ToProductImageResult toProductImageResult = new ToProductImageResult(); ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
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");
@@ -1169,11 +1159,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue()); 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);
// 满足条件情况下默认添加到like // 满足条件情况下默认添加到like
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId()); Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序 // 重新排序
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId()); Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
result.add(toProductImageResult);
} }
// 添加需要扣除的积分到预扣除区 // 添加需要扣除的积分到预扣除区
creditsService.addRecordToCreditsDeduction(userHolder.getId(), taskId, creditsEventsEnum); creditsService.addRecordToCreditsDeduction(userHolder.getId(), taskId, creditsEventsEnum);