BUGFIX:1、userLikeService中业务划分不清晰导致与generateService出现循环依赖问题。解决:将CollectionSort单独划分为一个Service

2、新建t_api_generate表用于补偿查询生成结果
This commit is contained in:
2025-07-25 17:13:06 +08:00
parent e2085190d1
commit 5287d83b82
13 changed files with 322 additions and 283 deletions

View File

@@ -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 {

View File

@@ -106,7 +106,7 @@ public class MyTaskScheduler {
List<ToProductImageResult> 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<ToProductImageResult> 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")

View File

@@ -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<APIGenerate> {
}

View File

@@ -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;
}

View File

@@ -5,4 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface CloudTaskService extends IService<CloudTask> {
CloudTask getByTaskId(String taskId);
void startTask(String batchTaskId);
void completeTask(String batchTaskId);
}

View File

@@ -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);
}

View File

@@ -61,12 +61,6 @@ public interface DesignService extends IService<Design> {
*/
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<Design> {
*/
Boolean dislike(DisDesignLikeDTO disDesignLikeDTO);
void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId);
CollectionSort getUserLikeSortByUserLikeId(Long userLikeId, String relationType, Long projectId);
/**
* generateHighDesign
*

View File

@@ -48,8 +48,6 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
List<ToProductImageResultVO> 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<UserLikeGroup> {
List<MagicToolResultVO> getToProductImageResultList(List<String> taskIdList);
Long getParentIdByElementIdAndElementType(Long elementId, String elementType);
JSONObject exportSearch(ExportSearchDTO exportSearchDTO);
CanvasElementUpload canvasElementUpload(MultipartFile file);
@@ -125,8 +121,4 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
Boolean toProductImageElementDelete(Long id);
ToProductElementVO convertRelightElement(Long id);
void startTask(String batchTaskId);
void completeTask(String batchTaskId);
}

View File

@@ -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<CloudTaskMapper, CloudTask> implements CloudTaskService {
@Resource
private CloudTaskMapper cloudTaskMapper;
private CreditsService creditsService;
@Override
public CloudTask getByTaskId(String taskId) {
QueryWrapper<CloudTask> qw = new QueryWrapper<>();
qw.lambda().eq(CloudTask::getTaskId, taskId);
return cloudTaskMapper.selectOne(qw);
return baseMapper.selectOne(qw);
}
@Override
public void startTask(String batchTaskId) {
QueryWrapper<CloudTask> 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<CloudTask> 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());
}
}

View File

@@ -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<CollectionSortMapper, CollectionSort> 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<CollectionSort> 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<CollectionSort> 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<CollectionSort> 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<CollectionSort> 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<CollectionSort> 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<CollectionSort> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionSort::getParentId, parentId);
baseMapper.delete(qw);
}
@Override
public CollectionSort getUserLikeSortByUserLikeId(Long relationId, String relationType, Long projectId) {
QueryWrapper<CollectionSort> 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_idrelation_type重复排序有脏数据
List<CollectionSort> childList = baseMapper.selectList(
new QueryWrapper<CollectionSort>().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<CollectionSort> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionSort::getRelationId, elementId);
elementType = transElementType(elementType);
qw.lambda().eq(CollectionSort::getRelationType, elementType);
List<CollectionSort> 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 "";
}
}
}

View File

@@ -111,9 +111,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> 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<DesignMapper, Design> impleme
@Resource
private DesignBatchMapper designBatchMapper;
@Resource
private CollectionSortMapper collectionSortMapper;
@Resource
private ProjectService projectService;
@Resource
@@ -1213,7 +1211,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> 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<DesignMapper, Design> 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<CollectionSort> 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<CollectionSort> 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<CollectionSort> userLikeSorts = collectionSortMapper.selectList(qw);
if (CollectionUtils.isEmpty(userLikeSorts)) {
return 1;
}
return userLikeSorts.size() + 1;
}
private List<Long> validateMergeElement(List<CollectionElement> oldElements, List<DesignItemDetail> designItemDetails) {
List<DesignItemDetail> hasCollections = designItemDetails.stream()
.filter(f -> Objects.nonNull(f.getCollectionElementId()))
@@ -1384,7 +1336,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> 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<DesignMapper, Design> impleme
return Boolean.TRUE;
}
@Override
public void deleteCollectionSort(Long relationId, String relationType, Long projectId, Long parentId) {
QueryWrapper<CollectionSort> 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<CollectionSort> 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<CollectionSort> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionSort::getParentId, parentId);
collectionSortMapper.delete(qw);
}
@Override
public CollectionSort getUserLikeSortByUserLikeId(Long relationId, String relationType, Long projectId) {
QueryWrapper<CollectionSort> 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<DesignMapper, Design> impleme
@Override
public Boolean sort(CollectionSortDTO userLikeSortDTO) {
// QueryWrapper<UserLikeSort> 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

View File

@@ -101,6 +101,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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<GenerateMapper, Generate> i
return "Invalid".equals(status) || "Fail".equals(status);
}
/* public List<PoseTransformationVO> getPoseTransformationResult(List<String> taskIdList) {
ArrayList<PoseTransformationVO> 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<PoseTransformation>().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<PoseTransformation>().eq("unique_id", taskId));
@@ -1830,12 +1794,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> 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<GenerateMapper, Generate> 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);
}
}
}

View File

@@ -137,6 +137,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private ProductImageService productImageService;
@Resource
private CollectionElementRelModelMapper collectionElementRelModelMapper;
@Resource
private CollectionSortService collectionSortService;
@Override
public void deleteUserGroup(Long userGroupId) {
@@ -496,7 +498,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// 满足条件情况下默认添加到like
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
@@ -551,7 +553,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// 满足条件情况下默认添加到like
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
@@ -583,43 +585,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return null;
}
/**
* 只有当使用子集中的元素进行生成时,才需要重新排序
* @param childId 生成元素的id
* @param parentId 父级id
* @param relationType 生成功能
* @param userLikeSortId 子集排序表中的id
*/
@Transactional
public Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId) {
// 对父级元素进行生成不需要重新排序
if (Objects.isNull(userLikeSortId) || parentId.equals(userLikeSortId)) {
return null;
}
// 相同的relation_idrelation_type重复排序有脏数据
List<CollectionSort> childList = collectionSortMapper.selectList(
new QueryWrapper<CollectionSort>().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<UserLikeGroupMapper, U
CollectionSort collectionSort = null;
if (toProductImageResult1.getResultType().equals("Relight")) {
if (null != productImageLikeDTO.getCollectionSortParentId()) {
collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSort = collectionSortService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
}
}else {
if (null != productImageLikeDTO.getCollectionSortParentId()) {
collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSort = collectionSortService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
}
}
// 更新项目更新时间
@@ -798,7 +763,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductElement.getUrl(), 24 * 60));
Long parentId = getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
Long parentId = collectionSortService.getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
magicToolResultVO.setParentId(parentId);
}else {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult.getElementId());
@@ -809,7 +774,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
List<UserLike> 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<UserLikeGroupMapper, U
return results;
}
public Long getParentIdByElementIdAndElementType(Long elementId, String elementType) {
QueryWrapper<CollectionSort> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionSort::getRelationId, elementId);
elementType = transElementType(elementType);
qw.lambda().eq(CollectionSort::getRelationType, elementType);
List<CollectionSort> 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<UserLikeGroupMapper, U
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResult.getElementId());
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductElement.getUrl(), 24 * 60));
Long parentId = getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
Long parentId = collectionSortService.getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
magicToolResultVO.setParentId(parentId);
} else if (toProductImageResult.getElementType().equals("DesignOutfit")){
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult.getElementId());
@@ -883,18 +818,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
List<UserLike> 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<UserLikeGroupMapper, U
toProductImageResultMapper.updateById(toProductImageResult);
if (toProductImageResult.getResultType().equals(CollectionType.RELIGHT.getValue())) {
if (null != productImageLikeDTO.getCollectionSortParentId()) {
designService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSortService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
}
}else {
if (null != productImageLikeDTO.getCollectionSortParentId()) {
designService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
collectionSortService.deleteCollectionSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
}
}
}
@@ -1200,7 +1135,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// 满足条件情况下默认添加到like
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
@@ -1245,7 +1180,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// 满足条件情况下默认添加到like
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
// 重新排序
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
Integer reSort = collectionSortService.rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
// 将生成结果的排序返回
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
@@ -1331,7 +1266,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResult.getElementId());
magicToolResultVO.setSourceUrl(minioUtil.getPreSignedUrl(toProductImageResult1.getUrl(), 24 * 60));
}
Long parentId = getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
Long parentId = collectionSortService.getParentIdByElementIdAndElementType(toProductImageResult.getElementId(), toProductImageResult.getElementType());
magicToolResultVO.setParentId(parentId);
}
} else if (Objects.isNull(magicToolResultVO)) {
@@ -3051,29 +2986,4 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductElementVO.setUrl(minioUtil.getPreSignedUrl(toProductElementVO.getUrl(), 24 * 60));
return toProductElementVO;
}
@Override
public void startTask(String batchTaskId) {
QueryWrapper<CloudTask> 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<CloudTask> 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());
}
}