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 a481a9d8..80084555 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -1461,18 +1461,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl().lambda().eq(CollectionSort::getRelationId, toProductImageResult.getId()).orderByDesc(BaseEntity::getCreateTime).last("limit 1")); + sortRank(toProductImageResult); results.add(new MagicToolResultVO(taskId, "Fail")); } else if (fluxResult.equals("Fail") || fluxResult.equals("Pending")) { toProductImageResult.setStatus(fluxResult); toProductImageResultMapper.updateById(toProductImageResult); - collectionSortMapper.delete(new QueryWrapper().lambda().eq(CollectionSort::getRelationId, toProductImageResult.getId()).orderByDesc(BaseEntity::getCreateTime).last("limit 1")); + sortRank(toProductImageResult); results.add(new MagicToolResultVO(taskId, fluxResult)); } else { fluxResult="Fail"; toProductImageResult.setStatus(fluxResult); toProductImageResultMapper.updateById(toProductImageResult); - collectionSortMapper.delete(new QueryWrapper().lambda().eq(CollectionSort::getRelationId, toProductImageResult.getId()).orderByDesc(BaseEntity::getCreateTime).last("limit 1")); + sortRank(toProductImageResult); results.add(new MagicToolResultVO(taskId, fluxResult)); // results.add(processFluxResult(fluxResult, toProductImageResult, taskId, toProductImageRecord.getPrompt())); // // 扣积分 @@ -1522,6 +1522,31 @@ public class UserLikeGroupServiceImpl extends ServiceImpl collectionSortLambdaQueryWrapper = new LambdaQueryWrapper<>(); + collectionSortLambdaQueryWrapper.eq(CollectionSort::getRelationId, toProductImageResult.getId()); + + // 查询符合条件的CollectionSort集合 + List collectionSorts = collectionSortMapper.selectList(collectionSortLambdaQueryWrapper); + + if (!collectionSorts.isEmpty()) { + // 按照创建时间排序,找到最新的一条记录 + collectionSorts.sort((a, b) -> b.getCreateTime().compareTo(a.getCreateTime())); + + // 删除最新的一条记录 + CollectionSort latestSort = collectionSorts.remove(0); + collectionSortMapper.deleteById(latestSort.getId()); + + // 将其他记录的sort值减一并更新回数据库 + for (CollectionSort sort : collectionSorts) { + if (sort.getSort() != null && sort.getSort() > 0) { + sort.setSort(sort.getSort() - 1); + collectionSortMapper.updateById(sort); + } + } + } + } + public static String convert(InputStream inputStream) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { return reader.lines().collect(Collectors.joining("\n"));