Merge branch 'dev/dev' into release/3.0

This commit is contained in:
shahaibo
2025-02-13 12:57:37 +08:00
4 changed files with 129 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import com.ai.da.common.utils.RedisUtil;
import com.ai.da.model.dto.GenerateThroughImageTextDTO; import com.ai.da.model.dto.GenerateThroughImageTextDTO;
import com.ai.da.model.vo.GenerateResultVO; import com.ai.da.model.vo.GenerateResultVO;
import com.ai.da.service.GenerateService; import com.ai.da.service.GenerateService;
import com.ai.da.service.UserLikeGroupService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
@@ -17,6 +18,7 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
@@ -31,6 +33,9 @@ public class GenerateConsumer {
@Resource @Resource
private GenerateService generateService; private GenerateService generateService;
@Resource
private UserLikeGroupService userLikeGroupService;
@Autowired @Autowired
private RabbitMQProperties rabbitMQProperties; private RabbitMQProperties rabbitMQProperties;
@@ -167,6 +172,9 @@ public class GenerateConsumer {
String taskId = generateResult.get("tasks_id"); String taskId = generateResult.get("tasks_id");
String category = generateResult.get("category"); String category = generateResult.get("category");
generateService.processToProductImageResult(taskId, url, category); generateService.processToProductImageResult(taskId, url, category);
} else if (generateResult.get("status").equals("NO_FACE")) {
String taskId = generateResult.get("tasks_id");
userLikeGroupService.toProduct(taskId);
} else { } else {
// 修改redis中的数据状态为exception // 修改redis中的数据状态为exception
String key = toProductImageResultKey + ":" + generateResult.get("tasks_id"); String key = toProductImageResultKey + ":" + generateResult.get("tasks_id");
@@ -214,6 +222,9 @@ public class GenerateConsumer {
String taskId = generateResult.get("tasks_id"); String taskId = generateResult.get("tasks_id");
String category = generateResult.get("category"); String category = generateResult.get("category");
generateService.processRelightResult(taskId, url, category); generateService.processRelightResult(taskId, url, category);
} else if (generateResult.get("status").equals("NO_FACE")) {
String taskId = generateResult.get("tasks_id");
userLikeGroupService.relight(taskId);
} else { } else {
// 修改redis中的数据状态为exception // 修改redis中的数据状态为exception
String key = relightResultKey + ":" + generateResult.get("tasks_id"); String key = relightResultKey + ":" + generateResult.get("tasks_id");

View File

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Data @Data
@@ -44,4 +45,8 @@ public class ToProductImageResult implements Serializable {
private String resultType; private String resultType;
private Double brightenValue; private Double brightenValue;
private BigDecimal imageStrength;
private String direction;
} }

View File

@@ -10,6 +10,7 @@ import com.ai.da.model.dto.ToProductImageDTO;
import com.ai.da.model.vo.*; import com.ai.da.model.vo.*;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@@ -44,6 +45,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO); List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO);
void toProduct(String taskId);
ToProductElementVO toProductImageElementUpload(MultipartFile file, Long userLikeGroupId); ToProductElementVO toProductImageElementUpload(MultipartFile file, Long userLikeGroupId);
Boolean productImageLike(ProductImageLikeDTO productImageLikeDTO); Boolean productImageLike(ProductImageLikeDTO productImageLikeDTO);
@@ -58,6 +61,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
Boolean productImageUnLike(ProductImageLikeDTO productImageLikeDTO); Boolean productImageUnLike(ProductImageLikeDTO productImageLikeDTO);
void relight(String taskId);
List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO); List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO);
List<MagicToolResultVO> getRelightResult(List<String> taskIdList); List<MagicToolResultVO> getRelightResult(List<String> taskIdList);

View File

@@ -36,13 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.*; import java.io.*;
import java.nio.file.Paths;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hutool.poi.excel.sax.AttributeName.s;
/** /**
* 服务实现类 * 服务实现类
* *
@@ -343,6 +340,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult.setIsLike(0); toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId); toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId); toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
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); result.add(toProductImageResult);
@@ -365,6 +363,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl); // toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0); toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId); toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
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); result.add(toProductImageResult);
@@ -378,6 +378,66 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return result; return result;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void toProduct(String taskId) {
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(toProductImageResults)) {
ToProductImageResult toProductImageResultOne = toProductImageResults.get(0);
ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResultOne.getToProductImageRecordId());
String prompt = toProductImageRecord.getPrompt();
StringBuilder sb = new StringBuilder("The best quality, masterpiece, real image.");
if (!StringUtil.isNullOrEmpty(prompt)) {
prompt = pythonService.promptTranslate(prompt);
}
String elementType = toProductImageResultOne.getElementType();
if (elementType.equals("DesignOutfit")) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultOne.getElementId());
Long designItemId = tDesignPythonOutfit.getDesignItemId();
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemId);
designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body");
List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
String collect = designItemDetails.stream().map(DesignItemDetail::getType).collect(Collectors.joining(","));
Long designId = tDesignPythonOutfit.getDesignId();
Design design = designMapper.selectById(designId);
String productType = "overall";
if (design.getSingleOverall().equals("single")) {
productType = "single";
sb.append(collect);
}else {
if (collect.contains("Tops")) {
sb.append("a handsome man,");
}else {
sb.append("a beautiful women,");
}
sb.append("wearing ").append(collect);
}
if (StringUtils.isEmpty(prompt)) {
sb.append(",high quality clothing details,8K realistic,HDR");
}else {
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
}
// 走模型
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, sb.toString(), toProductImageResultOne.getImageStrength(), "single");
}else {
if (StringUtils.isEmpty(prompt)) {
sb.append(",high quality clothing details,8K realistic,HDR");
}else {
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
}
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultOne.getElementId());
// 走模型
pythonService.toProductImage(toProductElement.getUrl(), taskId, sb.toString(), toProductImageResultOne.getImageStrength(), "single");
}
}
}
@Resource @Resource
private ToProductElementMapper toProductElementMapper; private ToProductElementMapper toProductElementMapper;
@@ -535,6 +595,48 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void relight(String taskId) {
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
qw.lambda().eq(ToProductImageResult::getTaskId, taskId);
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(toProductImageResults)) {
ToProductImageResult toProductImageResultOne = toProductImageResults.get(0);
ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResultOne.getToProductImageRecordId());
String prompt = toProductImageRecord.getPrompt();
// 翻译
String s = "";
if (!StringUtil.isNullOrEmpty(prompt)) {
s = pythonService.promptTranslate(prompt);
}else {
s = "Snow moutain, snowy day, natural light";
}
String elementType = toProductImageResultOne.getElementType();
if (elementType.equals("ToProductImage")) {
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultOne.getElementId());
String relightType = "overall";
if (toProductImageResult1.getElementType().equals("DesignOutfit")) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResult1.getElementId());
Long designId = tDesignPythonOutfit.getDesignId();
Design design = designMapper.selectById(designId);
if (design.getSingleOverall().equals("single")) {
relightType = "single";
}
}
// 走模型
pythonService.relight(toProductImageResult1.getUrl(), taskId, s, toProductImageResultOne.getDirection(), "single");
}else {
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultOne.getElementId());
// 走模型
pythonService.relight(toProductElement.getUrl(), taskId, s, toProductImageResultOne.getDirection(), "single");
}
}
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) { public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) {
@@ -594,6 +696,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if (toProductImageDTO.getBrightenValue() != null) { if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue()); toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
} }
toProductImageResult.setDirection(toProductImageDTO.getDirection());
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); result.add(toProductImageResult);
@@ -609,9 +712,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl); // toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0); toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId); toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
if (toProductImageDTO.getBrightenValue() != null) { if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue()); toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
} }
toProductImageResult.setDirection(toProductImageDTO.getDirection());
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); result.add(toProductImageResult);