diff --git a/src/main/java/com/ai/da/common/RabbitMQ/GenerateConsumer.java b/src/main/java/com/ai/da/common/RabbitMQ/GenerateConsumer.java index 78788985..e9ca9d36 100644 --- a/src/main/java/com/ai/da/common/RabbitMQ/GenerateConsumer.java +++ b/src/main/java/com/ai/da/common/RabbitMQ/GenerateConsumer.java @@ -5,6 +5,7 @@ import com.ai.da.common.utils.RedisUtil; import com.ai.da.model.dto.GenerateThroughImageTextDTO; import com.ai.da.model.vo.GenerateResultVO; import com.ai.da.model.vo.PoseTransformationVO; +import com.ai.da.service.CloudTaskService; import com.ai.da.service.DesignService; import com.ai.da.service.GenerateService; import com.ai.da.service.UserLikeGroupService; @@ -46,6 +47,9 @@ public class GenerateConsumer { @Resource private DesignService designService; + @Resource + private CloudTaskService cloudTaskService; + @Autowired private RabbitMQProperties rabbitMQProperties; @@ -394,12 +398,12 @@ public class GenerateConsumer { } else if (progress.startsWith("0/")) { String batchTaskId = generateResult.getString("task_id"); if (!StringUtils.isEmpty(batchTaskId)) { - userLikeGroupService.startTask(batchTaskId); + cloudTaskService.startTask(batchTaskId); } } else if (progress.equals("OK")) { String batchTaskId = generateResult.getString("task_id"); if (!StringUtils.isEmpty(batchTaskId)) { - userLikeGroupService.completeTask(batchTaskId); + cloudTaskService.completeTask(batchTaskId); } } } else { @@ -458,12 +462,12 @@ public class GenerateConsumer { } else if (progress.startsWith("0/")) { String batchTaskId = generateResult.getString("task_id"); if (!StringUtils.isEmpty(batchTaskId)) { - userLikeGroupService.startTask(batchTaskId); + cloudTaskService.startTask(batchTaskId); } } else if (progress.equals("OK")) { String batchTaskId = generateResult.getString("task_id"); if (!StringUtils.isEmpty(batchTaskId)) { - userLikeGroupService.completeTask(batchTaskId); + cloudTaskService.completeTask(batchTaskId); } } } else { diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 8539c698..4e49a541 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -106,7 +106,7 @@ public class MyTaskScheduler { List toProductImageResultList1 = toProductImageResultMapper.selectList(toProductImageResultQueryWrapper1); if (!CollectionUtils.isEmpty(toProductImageResultList1)) { for (ToProductImageResult toProductImageResult : toProductImageResultList1) { - designService.addCollectionSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), collectionSort.getProjectId(), collectionSort.getId()); + collectionSortService.addCollectionSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), collectionSort.getProjectId(), collectionSort.getId()); QueryWrapper relightResultQueryWrapper = new QueryWrapper<>(); relightResultQueryWrapper.lambda().eq(ToProductImageResult::getElementId, toProductImageResult.getId()); @@ -115,7 +115,7 @@ public class MyTaskScheduler { if (!CollectionUtils.isEmpty(toProductImageResultList2)) { for (ToProductImageResult relight : toProductImageResultList2) { - designService.addCollectionSort(relight.getId(), CollectionType.RELIGHT.getValue(), collectionSort.getProjectId(), collectionSort.getId()); + collectionSortService.addCollectionSort(relight.getId(), CollectionType.RELIGHT.getValue(), collectionSort.getProjectId(), collectionSort.getId()); } } @@ -153,6 +153,8 @@ public class MyTaskScheduler { private ExportFileMapper exportFileMapper; @Resource private PortfolioMapper portfolioMapper; + @Resource + private CollectionSortService collectionSortService; // 定时任务,每十五天执行一次 // @Scheduled(cron = "0 0 0 ? * MON") diff --git a/src/main/java/com/ai/da/mapper/primary/APIGenerateMapper.java b/src/main/java/com/ai/da/mapper/primary/APIGenerateMapper.java new file mode 100644 index 00000000..62f16e83 --- /dev/null +++ b/src/main/java/com/ai/da/mapper/primary/APIGenerateMapper.java @@ -0,0 +1,7 @@ +package com.ai.da.mapper.primary; + +import com.ai.da.mapper.primary.entity.APIGenerate; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface APIGenerateMapper extends BaseMapper { +} diff --git a/src/main/java/com/ai/da/mapper/primary/entity/APIGenerate.java b/src/main/java/com/ai/da/mapper/primary/entity/APIGenerate.java new file mode 100644 index 00000000..a797c12f --- /dev/null +++ b/src/main/java/com/ai/da/mapper/primary/entity/APIGenerate.java @@ -0,0 +1,26 @@ +package com.ai.da.mapper.primary.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +@TableName("t_API_generate") +@ApiModel("调用第三方api的所有记录") +public class APIGenerate extends BaseEntity{ + + // 任务id 加唯一索引 + private String taskId; + // 什么功能调用的api + private String func; + // 第三方api的服务商 目前只有ali-万相 和 flux +// private String service; + // 模型名 + private String modelName; + // 任务状态 + private String status; + // 获取结果的重试次数 + private int retry_count; +} diff --git a/src/main/java/com/ai/da/service/CloudTaskService.java b/src/main/java/com/ai/da/service/CloudTaskService.java index 07975d49..c1514278 100644 --- a/src/main/java/com/ai/da/service/CloudTaskService.java +++ b/src/main/java/com/ai/da/service/CloudTaskService.java @@ -5,4 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService; public interface CloudTaskService extends IService { CloudTask getByTaskId(String taskId); + + void startTask(String batchTaskId); + + void completeTask(String batchTaskId); } diff --git a/src/main/java/com/ai/da/service/CollectionSortService.java b/src/main/java/com/ai/da/service/CollectionSortService.java new file mode 100644 index 00000000..2b91126f --- /dev/null +++ b/src/main/java/com/ai/da/service/CollectionSortService.java @@ -0,0 +1,21 @@ +package com.ai.da.service; + +import com.ai.da.mapper.primary.entity.CollectionSort; +import com.ai.da.model.dto.CollectionSortDTO; + +public interface CollectionSortService { + + CollectionSort addCollectionSort(Long relationId, String relationType, Long projectId, Long collectionSortParentId); + + int getNextSort(Long projectId, Long parentId); + + void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId); + + CollectionSort getUserLikeSortByUserLikeId(Long relationId, String relationType, Long projectId); + + Boolean sort(CollectionSortDTO userLikeSortDTO); + + Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId); + + Long getParentIdByElementIdAndElementType(Long elementId, String elementType); +} diff --git a/src/main/java/com/ai/da/service/DesignService.java b/src/main/java/com/ai/da/service/DesignService.java index 32723fd5..3b55f1a4 100644 --- a/src/main/java/com/ai/da/service/DesignService.java +++ b/src/main/java/com/ai/da/service/DesignService.java @@ -61,12 +61,6 @@ public interface DesignService extends IService { */ DesignLikeVO like(DesignLikeDTO designLikeDTO); - CollectionSort addCollectionSort(Long relationId, String relationType, Long projectId, Long parentId); - - CollectionSort queryCollectionSortByRelation(Long relationId, String relationType, Long projectId); - - int getNextSort(Long projectId, Long parentId); - /** * dislike * @@ -75,10 +69,6 @@ public interface DesignService extends IService { */ Boolean dislike(DisDesignLikeDTO disDesignLikeDTO); - void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId); - - CollectionSort getUserLikeSortByUserLikeId(Long userLikeId, String relationType, Long projectId); - /** * generateHighDesign * diff --git a/src/main/java/com/ai/da/service/UserLikeGroupService.java b/src/main/java/com/ai/da/service/UserLikeGroupService.java index 4eb2a257..774ef7ae 100644 --- a/src/main/java/com/ai/da/service/UserLikeGroupService.java +++ b/src/main/java/com/ai/da/service/UserLikeGroupService.java @@ -48,8 +48,6 @@ public interface UserLikeGroupService extends IService { List toProduct(ToProductImageDTO toProductImageDTO); - Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId); - void toProduct(String taskId); ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId); @@ -58,8 +56,6 @@ public interface UserLikeGroupService extends IService { List getToProductImageResultList(List taskIdList); - Long getParentIdByElementIdAndElementType(Long elementId, String elementType); - JSONObject exportSearch(ExportSearchDTO exportSearchDTO); CanvasElementUpload canvasElementUpload(MultipartFile file); @@ -125,8 +121,4 @@ public interface UserLikeGroupService extends IService { Boolean toProductImageElementDelete(Long id); ToProductElementVO convertRelightElement(Long id); - - void startTask(String batchTaskId); - - void completeTask(String batchTaskId); } diff --git a/src/main/java/com/ai/da/service/impl/CloudTaskServiceImpl.java b/src/main/java/com/ai/da/service/impl/CloudTaskServiceImpl.java index efc3b86f..51f848aa 100644 --- a/src/main/java/com/ai/da/service/impl/CloudTaskServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CloudTaskServiceImpl.java @@ -6,23 +6,51 @@ import com.ai.da.mapper.primary.entity.Account; import com.ai.da.mapper.primary.entity.CloudTask; import com.ai.da.service.ClassificationService; import com.ai.da.service.CloudTaskService; +import com.ai.da.service.CreditsService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.LocalDateTime; @Slf4j @Service public class CloudTaskServiceImpl extends ServiceImpl implements CloudTaskService { + @Resource - private CloudTaskMapper cloudTaskMapper; + private CreditsService creditsService; @Override public CloudTask getByTaskId(String taskId) { QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(CloudTask::getTaskId, taskId); - return cloudTaskMapper.selectOne(qw); + return baseMapper.selectOne(qw); + } + + @Override + public void startTask(String batchTaskId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CloudTask::getTaskId, batchTaskId); + CloudTask cloudTask = baseMapper.selectOne(qw); + cloudTask.setStartTime(LocalDateTime.now()); + baseMapper.updateById(cloudTask); + } + + @Override + public void completeTask(String batchTaskId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CloudTask::getTaskId, batchTaskId); + CloudTask cloudTask = baseMapper.selectOne(qw); + cloudTask.setStatus(1); +// cloudTask.setCompletedNum(cloudTask.getNums()); + cloudTask.setUpdateTime(LocalDateTime.now()); + baseMapper.updateById(cloudTask); + + // 扣除积分 + Boolean b = creditsService.taskCreditsDeduction(cloudTask.getAccountId(), cloudTask.getTaskId()); + // 记录积分变更 + if (b) creditsService.updateChangedCredits(String.valueOf(cloudTask.getAccountId()), cloudTask.getTaskId()); } } diff --git a/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java new file mode 100644 index 00000000..b970201b --- /dev/null +++ b/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java @@ -0,0 +1,188 @@ +package com.ai.da.service.impl; + +import com.ai.da.mapper.primary.CollectionSortMapper; +import com.ai.da.mapper.primary.entity.CollectionSort; +import com.ai.da.model.dto.CollectionSortDTO; +import com.ai.da.model.enums.CollectionType; +import com.ai.da.service.CollectionSortService; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Objects; + +@Slf4j +@Service +public class CollectionSortServiceImpl extends ServiceImpl implements CollectionSortService { + + @Override + public CollectionSort addCollectionSort(Long relationId, String relationType, Long projectId, Long collectionSortParentId) { + CollectionSort collectionSort = queryCollectionSortByRelation(relationId, relationType, projectId); + if (Objects.nonNull(collectionSort)){ + return collectionSort; + } + int sort = getNextSort(projectId, collectionSortParentId); + CollectionSort userLikeSort = new CollectionSort(); +// userLikeSort.setUserLikeGroupId(userGroupId); +// userLikeSort.setUserLikeId(relationId); + userLikeSort.setProjectId(projectId); + userLikeSort.setRelationId(relationId); + userLikeSort.setRelationType(relationType); + userLikeSort.setSort(sort); + if (null != collectionSortParentId) { + userLikeSort.setParentId(collectionSortParentId); + } + userLikeSort.setCreateTime(LocalDateTime.now()); + baseMapper.insert(userLikeSort); + return userLikeSort; + } + + public CollectionSort queryCollectionSortByRelation(Long relationId, String relationType, Long projectId){ + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getProjectId, projectId). + eq(CollectionSort::getRelationId, relationId). + eq(CollectionSort::getRelationType, relationType); + return baseMapper.selectOne(qw); + } + + @Override + public int getNextSort(Long projectId, Long parentId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getProjectId, projectId); + if (null != parentId) { + qw.lambda().eq(CollectionSort::getParentId, parentId); + }else { + qw.lambda().isNull(CollectionSort::getParentId); + } + List userLikeSorts = baseMapper.selectList(qw); + if (CollectionUtils.isEmpty(userLikeSorts)) { + return 1; + } + return userLikeSorts.size() + 1; + } + + @Override + public void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getProjectId, projectId); + if (null != parentId) { + qw.lambda().eq(CollectionSort::getParentId, parentId); + }else { + qw.lambda().isNull(CollectionSort::getParentId); + } + qw.lambda().orderByDesc(CollectionSort::getSort); + List userLikeSorts = baseMapper.selectList(qw); + CollectionSort userLikeSort = getUserLikeSortByUserLikeId(relationId, relationType, projectId); + if (Objects.nonNull(userLikeSort)) { + Long userLikeSortId = userLikeSort.getId(); + for (CollectionSort likeSort : userLikeSorts) { + if (Objects.equals(likeSort.getId(), userLikeSortId)) { + baseMapper.deleteById(likeSort); + deleteByParentId(likeSort.getId()); + break; + }else { + likeSort.setSort(likeSort.getSort() - 1); + baseMapper.updateById(likeSort); + } + } + } + } + + private void deleteByParentId(Long parentId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getParentId, parentId); + baseMapper.delete(qw); + } + + @Override + public CollectionSort getUserLikeSortByUserLikeId(Long relationId, String relationType, Long projectId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getRelationId, relationId); + qw.lambda().eq(CollectionSort::getRelationType, relationType); + qw.lambda().eq(CollectionSort::getProjectId, projectId); + CollectionSort userLikeSort = baseMapper.selectOne(qw); + return userLikeSort; + } + + @Override + public Boolean sort(CollectionSortDTO userLikeSortDTO) { + for (CollectionSort userLikeSort : userLikeSortDTO.getUserLikeSortList()) { + baseMapper.updateById(userLikeSort); + } + return Boolean.TRUE; + } + + /** + * 只有当使用子集中的元素进行生成时,才需要重新排序 + * @param childId 生成元素的id + * @param parentId 父级id + * @param relationType 生成功能 + * @param userLikeSortId 子集排序表中的id + */ + @Transactional + @Override + public Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId) { + // 对父级元素进行生成不需要重新排序 + if (Objects.isNull(userLikeSortId) || parentId.equals(userLikeSortId)) { + return null; + } + + // 相同的relation_id,relation_type重复排序,有脏数据 + List childList = baseMapper.selectList( + new QueryWrapper().eq("relation_id", childId) + .eq("relation_type", relationType).orderByDesc("id")); + if (childList.isEmpty()) { + return null; + }else if (childList.size() > 1){ + log.error("CollectionSort表中,relation_id为{},relation_type为{}的记录有 {} 条,", childId, relationType, childList.size()); + } + CollectionSort child = childList.get(0); + CollectionSort collectionSort = baseMapper.selectById(userLikeSortId); + if (Objects.isNull(collectionSort)){ + return null; + } + child.setSort(collectionSort.getSort()); + // 原来排序的大于等于userLikeSortId的排序的,都要+1 + baseMapper.increaseGenerateSortAbove(parentId, relationType, collectionSort.getSort() - 1); + // 当前的生成结果则填入userLikeSortId的排序位置 + child.setUpdateTime(LocalDateTime.now()); + baseMapper.updateById(child); + return collectionSort.getSort(); + } + + @Override + public Long getParentIdByElementIdAndElementType(Long elementId, String elementType) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(CollectionSort::getRelationId, elementId); + + elementType = transElementType(elementType); + qw.lambda().eq(CollectionSort::getRelationType, elementType); + List collectionSortList = baseMapper.selectList(qw); + if (CollectionUtils.isEmpty(collectionSortList)) { + return null; + } + CollectionSort collectionSort = collectionSortList.get(0); + Long parentId = collectionSort.getParentId(); + if (parentId == null) { + return collectionSort.getId(); + } + return collectionSort.getParentId(); + } + + private String transElementType(String elementType) { + if (elementType.equals("DesignOutfit")) { + return CollectionType.DESIGN.getValue(); + }else if (elementType.equals("ToProductImage")) { + return CollectionType.TO_PRODUCT_IMAGE.getValue(); + }else if (elementType.equals("PoseTransfer")) { + return CollectionType.POSE_TRANSFORM.getValue(); + }else { + return ""; + } + } +} 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 e7f84c23..f737ecd4 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -111,9 +111,10 @@ public class DesignServiceImpl extends ServiceImpl impleme private ToProductImageResultMapper toProductImageResultMapper; @Resource private ToProductElementMapper toProductElementMapper; - @Resource private MoodboardPositionMapper moodboardPositionMapper; + @Resource + private CollectionSortService collectionSortService; @Value("${minio.endpoint}") private String endpoint; @@ -133,9 +134,6 @@ public class DesignServiceImpl extends ServiceImpl impleme @Resource private DesignBatchMapper designBatchMapper; - - @Resource - private CollectionSortMapper collectionSortMapper; @Resource private ProjectService projectService; @Resource @@ -1213,7 +1211,7 @@ public class DesignServiceImpl extends ServiceImpl impleme } userLikeService.save(userLike); Long userLikeSortId; - CollectionSort userLikeSort = addCollectionSort(userLike.getId(), CollectionType.DESIGN.getValue(), designLikeDTO.getProjectId(), null); + CollectionSort userLikeSort = collectionSortService.addCollectionSort(userLike.getId(), CollectionType.DESIGN.getValue(), designLikeDTO.getProjectId(), null); userLikeSortId = userLikeSort.getId(); groupDetailId = userLike.getId(); String designUrl = designPythonOutfitMapper.selectById(userLike.getDesignOutfitId()).getDesignUrl(); @@ -1260,52 +1258,6 @@ public class DesignServiceImpl extends ServiceImpl impleme } } - @Override - public CollectionSort addCollectionSort(Long relationId, String relationType, Long projectId, Long collectionSortParentId) { - CollectionSort collectionSort = queryCollectionSortByRelation(relationId, relationType, projectId); - if (Objects.nonNull(collectionSort)){ - return collectionSort; - } - int sort = getNextSort(projectId, collectionSortParentId); - CollectionSort userLikeSort = new CollectionSort(); -// userLikeSort.setUserLikeGroupId(userGroupId); -// userLikeSort.setUserLikeId(relationId); - userLikeSort.setProjectId(projectId); - userLikeSort.setRelationId(relationId); - userLikeSort.setRelationType(relationType); - userLikeSort.setSort(sort); - if (null != collectionSortParentId) { - userLikeSort.setParentId(collectionSortParentId); - } - userLikeSort.setCreateTime(LocalDateTime.now()); - collectionSortMapper.insert(userLikeSort); - return userLikeSort; - } - - public CollectionSort queryCollectionSortByRelation(Long relationId, String relationType, Long projectId){ - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getProjectId, projectId). - eq(CollectionSort::getRelationId, relationId). - eq(CollectionSort::getRelationType, relationType); - return collectionSortMapper.selectOne(qw); - } - - @Override - public int getNextSort(Long projectId, Long parentId) { - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getProjectId, projectId); - if (null != parentId) { - qw.lambda().eq(CollectionSort::getParentId, parentId); - }else { - qw.lambda().isNull(CollectionSort::getParentId); - } - List userLikeSorts = collectionSortMapper.selectList(qw); - if (CollectionUtils.isEmpty(userLikeSorts)) { - return 1; - } - return userLikeSorts.size() + 1; - } - private List validateMergeElement(List oldElements, List designItemDetails) { List hasCollections = designItemDetails.stream() .filter(f -> Objects.nonNull(f.getCollectionElementId())) @@ -1384,7 +1336,7 @@ public class DesignServiceImpl extends ServiceImpl impleme // userLikeGroupService.removeById(userLike.getUserLikeGroupId()); } - deleteCollectionSort(userLike.getId(), CollectionType.DESIGN.getValue(), disDesignLikeDTO.getProjectId(), null); + collectionSortService.deleteCollectionSort(userLike.getId(), CollectionType.DESIGN.getValue(), disDesignLikeDTO.getProjectId(), null); //删除对应的history userLikeService.removeById(disDesignLikeDTO.getGroupDetailId()); // 更新项目更新时间 @@ -1392,49 +1344,6 @@ public class DesignServiceImpl extends ServiceImpl impleme return Boolean.TRUE; } - @Override - public void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId) { - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getProjectId, projectId); - if (null != parentId) { - qw.lambda().eq(CollectionSort::getParentId, parentId); - }else { - qw.lambda().isNull(CollectionSort::getParentId); - } - qw.lambda().orderByDesc(CollectionSort::getSort); - List userLikeSorts = collectionSortMapper.selectList(qw); - CollectionSort userLikeSort = getUserLikeSortByUserLikeId(relationId, relationType, projectId); - if (Objects.nonNull(userLikeSort)) { - Long userLikeSortId = userLikeSort.getId(); - for (CollectionSort likeSort : userLikeSorts) { - if (Objects.equals(likeSort.getId(), userLikeSortId)) { - collectionSortMapper.deleteById(likeSort); - deleteByParentId(likeSort.getId()); - break; - }else { - likeSort.setSort(likeSort.getSort() - 1); - collectionSortMapper.updateById(likeSort); - } - } - } - } - - private void deleteByParentId(Long parentId) { - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getParentId, parentId); - collectionSortMapper.delete(qw); - } - - @Override - public CollectionSort getUserLikeSortByUserLikeId(Long relationId, String relationType, Long projectId) { - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getRelationId, relationId); - qw.lambda().eq(CollectionSort::getRelationType, relationType); - qw.lambda().eq(CollectionSort::getProjectId, projectId); - CollectionSort userLikeSort = collectionSortMapper.selectOne(qw); - return userLikeSort; - } - @Override public String generateHighDesign(GenerateHighDesignDTO generateHighDesignDTO) { DesignItem designItem = designItemService.getById(generateHighDesignDTO.getDesignItemId()); @@ -2763,13 +2672,7 @@ public class DesignServiceImpl extends ServiceImpl impleme @Override public Boolean sort(CollectionSortDTO userLikeSortDTO) { -// QueryWrapper qw = new QueryWrapper<>(); -// qw.lambda().eq(UserLikeSort::getUserLikeGroupId, userLikeSortDTO.getUserLikeGroupId()); -// userLikeSortMapper.delete(qw); - for (CollectionSort userLikeSort : userLikeSortDTO.getUserLikeSortList()) { - collectionSortMapper.updateById(userLikeSort); - } - return Boolean.TRUE; + return collectionSortService.sort(userLikeSortDTO); } @Override 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 fe2efcb8..4b0740bf 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -101,6 +101,12 @@ public class GenerateServiceImpl extends ServiceImpl i private SendRequestUtil sendRequestUtil; @Resource private ProjectService projectService; + @Resource + private CollectionSortService collectionSortService; + @Resource + private CloudTaskService cloudTaskService; + @Resource + private APIGenerateMapper apiGenerateMapper; @Value("${redis.key.orderForGenerate}") private String consumptionOrderKey; @@ -1440,9 +1446,6 @@ public class GenerateServiceImpl extends ServiceImpl i return new GenerateResultVO(id, url, "Success", category); } - @Resource - private UserLikeGroupService userLikeGroupService; - public ToProductImageResultVO poseTransform(PoseTransformDTO poseTransformDTO) { Long accountId = UserContext.getUserHolder().getId(); Long projectId = poseTransformDTO.getProjectId(); @@ -1497,7 +1500,7 @@ public class GenerateServiceImpl extends ServiceImpl i poseTransformation.setUpdateTime(LocalDateTime.now()); poseTransformationMapper.updateById(poseTransformation); Integer sort = addPoseTransferLike(poseTransformDTO, poseTransformation.getId()); - Integer reSort = userLikeGroupService.rearrangeChildSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), + Integer reSort = collectionSortService.rearrangeChildSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), poseTransformDTO.getParentId(), poseTransformDTO.getUserLikeSortId()); toProductImageResultVO.setSort(Objects.isNull(reSort) ? sort : reSort); } else if (Objects.nonNull(poseTransformDTO.getIsDefaultLike()) && Objects.nonNull(poseTransformDTO.getParentId())) { @@ -1681,7 +1684,7 @@ public class GenerateServiceImpl extends ServiceImpl i if (poseTransformation != null) { ToProductImageResult productResult = getProductResultByPath(poseTransformation.getProductImage()); if (productResult != null) { - Long parentId = userLikeGroupService.getParentIdByElementIdAndElementType( + Long parentId = collectionSortService.getParentIdByElementIdAndElementType( productResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue()); vo.setParentId(parentId); vo.setId(poseTransformation.getId()); @@ -1696,45 +1699,6 @@ public class GenerateServiceImpl extends ServiceImpl i return "Invalid".equals(status) || "Fail".equals(status); } - /* public List getPoseTransformationResult(List taskIdList) { - ArrayList poseTransformationVOS = new ArrayList<>(); - for (String taskId : taskIdList) { - String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue()); - - String key = generateResultKey + ":" + taskId; - String resultJson = redisUtil.getFromString(key); - PoseTransformationVO poseTransformationVO; - if (!StringUtil.isNullOrEmpty(resultJson)) { - poseTransformationVO = new Gson().fromJson(redisUtil.getFromString(key), PoseTransformationVO.class); - if (poseTransformationVO.getStatus().equals("Success") && !type.equals("wx")) { - // 处理各种URL - processUrl(poseTransformationVO.getGifUrl(), url -> - poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); - processUrl(poseTransformationVO.getVideoUrl(), url -> - poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); - processUrl(poseTransformationVO.getFirstFrameUrl(), url -> - poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); - } - poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); - } else if (type.equals("wx")) { - poseTransformationVO = getAnimateResult(taskId); - } else { - poseTransformationVO = new PoseTransformationVO(taskId, "Executing"); - } - - PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper().eq("unique_id", taskId)); - if (Objects.nonNull(poseTransformation)) { - ToProductImageResult productResultByPath = getProductResultByPath(poseTransformation.getProductImage()); - if (Objects.nonNull(productResultByPath)) { - Long parentId = userLikeGroupService.getParentIdByElementIdAndElementType(productResultByPath.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue()); - poseTransformationVO.setParentId(parentId); - } - } - poseTransformationVOS.add(poseTransformationVO); - } - return poseTransformationVOS; - }*/ - public void updatePoseTransferStatus(String taskId, String status){ PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper().eq("unique_id", taskId)); @@ -1830,12 +1794,12 @@ public class GenerateServiceImpl extends ServiceImpl i if (likeOrDislike.equals("like")) { poseTransformation.setIsLiked((byte) 1); if (null != collectionSortParentId) { - collectionSort = designService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId); + collectionSort = collectionSortService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId); } } else if (likeOrDislike.equals("dislike")) { poseTransformation.setIsLiked((byte) 0); if (null != collectionSortParentId) { - designService.deleteCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId); + collectionSortService.deleteCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId); } } poseTransformation.setUpdateTime(LocalDateTime.now()); @@ -2070,11 +2034,11 @@ public class GenerateServiceImpl extends ServiceImpl i log.info("taskIdBatch:{}", taskIdBatch); if (progress.equals("OK")) { if (!StringUtils.isEmpty(taskIdBatch)) { - userLikeGroupService.completeTask(taskIdBatch); + cloudTaskService.completeTask(taskIdBatch); } }else if (progress.startsWith("0/")) { if (!StringUtils.isEmpty(taskIdBatch)) { - userLikeGroupService.startTask(taskIdBatch); + cloudTaskService.startTask(taskIdBatch); } } } 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 42aadcf2..9b6c2951 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -137,6 +137,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl childList = collectionSortMapper.selectList( - new QueryWrapper().eq("relation_id", childId) - .eq("relation_type", relationType).orderByDesc("id")); - if (childList.isEmpty()) { - return null; - }else if (childList.size() > 1){ - log.error("CollectionSort表中,relation_id为{},relation_type为{}的记录有 {} 条,", childId, relationType, childList.size()); - } - CollectionSort child = childList.get(0); - CollectionSort collectionSort = collectionSortMapper.selectById(userLikeSortId); - if (Objects.isNull(collectionSort)){ - return null; - } - child.setSort(collectionSort.getSort()); - // 原来排序的大于等于userLikeSortId的排序的,都要+1 - collectionSortMapper.increaseGenerateSortAbove(parentId, relationType, collectionSort.getSort() - 1); - // 当前的生成结果则填入userLikeSortId的排序位置 - child.setUpdateTime(LocalDateTime.now()); - collectionSortMapper.updateById(child); - return collectionSort.getSort(); - } - @Override @Transactional(rollbackFor = Exception.class) public void toProduct(String taskId) { @@ -720,11 +685,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl userLikeList = userLikeMapper.selectList(userLikeQueryWrapper); if (!CollectionUtils.isEmpty(userLikeList)) { UserLike userLike = userLikeList.get(0); - Long parentId = getParentIdByElementIdAndElementType(userLike.getId(), toProductImageResult.getElementType()); + Long parentId = collectionSortService.getParentIdByElementIdAndElementType(userLike.getId(), toProductImageResult.getElementType()); magicToolResultVO.setParentId(parentId); } } @@ -823,36 +788,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionSort::getRelationId, elementId); - - elementType = transElementType(elementType); - qw.lambda().eq(CollectionSort::getRelationType, elementType); - List collectionSortList = collectionSortMapper.selectList(qw); - if (CollectionUtils.isEmpty(collectionSortList)) { - return null; - } - CollectionSort collectionSort = collectionSortList.get(0); - Long parentId = collectionSort.getParentId(); - if (parentId == null) { - return collectionSort.getId(); - } - return collectionSort.getParentId(); - } - - private String transElementType(String elementType) { - if (elementType.equals("DesignOutfit")) { - return CollectionType.DESIGN.getValue(); - }else if (elementType.equals("ToProductImage")) { - return CollectionType.TO_PRODUCT_IMAGE.getValue(); - }else if (elementType.equals("PoseTransfer")) { - return CollectionType.POSE_TRANSFORM.getValue(); - }else { - return ""; - } - } - private MagicToolResultVO processFluxResult(String fluxImgMinioPath, ToProductImageResult toProductImageResult, String taskId, String prompt){ toProductImageResult.setTaskStatus("Success"); toProductImageResult.setUrl(fluxImgMinioPath); @@ -872,7 +807,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl userLikeList = userLikeMapper.selectList(userLikeQueryWrapper); if (!CollectionUtils.isEmpty(userLikeList)) { UserLike userLike = userLikeList.get(0); - Long parentId = getParentIdByElementIdAndElementType(userLike.getId(), toProductImageResult.getElementType()); + Long parentId = collectionSortService.getParentIdByElementIdAndElementType(userLike.getId(), toProductImageResult.getElementType()); magicToolResultVO.setParentId(parentId); } } else if (toProductImageResult.getElementType().equals("ToProductImage")){ ToProductImageResult toProductImage = toProductImageResultMapper.selectById(toProductImageResult.getElementId()); magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductImage.getUrl(), 24 * 60)); - Long parentId = getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType()); + Long parentId = collectionSortService.getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType()); magicToolResultVO.setParentId(parentId); } -// Long parentId = getParentIdByElementIdAndElementType(toProductImageResult.getId(), toProductImageResult.getResultType()); +// Long parentId = collectionSortService.getParentIdByElementIdAndElementType(toProductImageResult.getId(), toProductImageResult.getResultType()); // magicToolResultVO.setParentId(parentId); return magicToolResultVO; } @@ -1048,11 +983,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); - qw.lambda().eq(CloudTask::getTaskId, batchTaskId); - CloudTask cloudTask = cloudTaskMapper.selectOne(qw); - cloudTask.setStartTime(LocalDateTime.now()); - cloudTaskMapper.updateById(cloudTask); - } - - @Override - public void completeTask(String batchTaskId) { - QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(CloudTask::getTaskId, batchTaskId); - CloudTask cloudTask = cloudTaskMapper.selectOne(qw); - cloudTask.setStatus(1); -// cloudTask.setCompletedNum(cloudTask.getNums()); - cloudTask.setUpdateTime(LocalDateTime.now()); - cloudTaskMapper.updateById(cloudTask); - - // 扣除积分 - Boolean b = creditsService.taskCreditsDeduction(cloudTask.getAccountId(), cloudTask.getTaskId()); - // 记录积分变更 - if (b) creditsService.updateChangedCredits(String.valueOf(cloudTask.getAccountId()), cloudTask.getTaskId()); - } }