Merge remote-tracking branch 'origin/release/3.0' into release/3.0

This commit is contained in:
2025-02-17 10:19:17 +08:00
6 changed files with 150 additions and 23 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.vo.GenerateResultVO;
import com.ai.da.service.GenerateService;
import com.ai.da.service.UserLikeGroupService;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
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.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.IOException;
@@ -31,6 +33,9 @@ public class GenerateConsumer {
@Resource
private GenerateService generateService;
@Resource
private UserLikeGroupService userLikeGroupService;
@Autowired
private RabbitMQProperties rabbitMQProperties;
@@ -167,6 +172,9 @@ public class GenerateConsumer {
String taskId = generateResult.get("tasks_id");
String category = generateResult.get("category");
generateService.processToProductImageResult(taskId, url, category);
} else if (generateResult.get("status").equals("NO_FACE")) {
String taskId = generateResult.get("tasks_id");
userLikeGroupService.toProduct(taskId);
} else {
// 修改redis中的数据状态为exception
String key = toProductImageResultKey + ":" + generateResult.get("tasks_id");
@@ -214,6 +222,9 @@ public class GenerateConsumer {
String taskId = generateResult.get("tasks_id");
String category = generateResult.get("category");
generateService.processRelightResult(taskId, url, category);
} else if (generateResult.get("status").equals("NO_FACE")) {
String taskId = generateResult.get("tasks_id");
userLikeGroupService.relight(taskId);
} else {
// 修改redis中的数据状态为exception
String key = relightResultKey + ":" + generateResult.get("tasks_id");

View File

@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@@ -44,4 +45,8 @@ public class ToProductImageResult implements Serializable {
private String resultType;
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.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -44,6 +45,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO);
void toProduct(String taskId);
ToProductElementVO toProductImageElementUpload(MultipartFile file, Long userLikeGroupId);
Boolean productImageLike(ProductImageLikeDTO productImageLikeDTO);
@@ -58,6 +61,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
Boolean productImageUnLike(ProductImageLikeDTO productImageLikeDTO);
void relight(String taskId);
List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO);
List<MagicToolResultVO> getRelightResult(List<String> taskIdList);

View File

@@ -318,7 +318,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountExtendQW.lambda().eq(AccountExtend::getAccountId, userHolder.getId());
accountExtendQW.lambda().eq(AccountExtend::getAuthType, "Wechat");
List<AccountExtend> accountExtends = accountExtendMapper.selectList(accountExtendQW);
if (CollectionUtil.isNotEmpty(accountExtends)) {
if (CollectionUtil.isNotEmpty(accountExtends) && !Objects.equals(accountExtends.get(0).getAccountId(), accountOld.getId())) {
AccountExtend accountExtend = accountExtends.get(0);
accountExtend.setAccountId(accountOld.getId());
accountExtendMapper.updateById(accountExtend);
@@ -336,25 +336,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
Account accountNew = accountMapper.selectById(userHolder.getId());
if (StringUtils.isEmpty(accountNew.getUserEmail())) {
TrialOrder trialOrder = CopyUtil.copyObject(accountNew, TrialOrder.class);
trialOrder.setEmail(accountBindEmailDTO.getUserEmail());
trialOrder.setCreateTime(LocalDateTime.now());
trialOrder.setUpdateTime(LocalDateTime.now());
trialOrder.setStatus(1);
// 获取用户申请试用IP
String ipAddress = RequestInfoUtil.getIpAddress(request);
trialOrder.setIp(ipAddress);
trialOrderMapper.insert(trialOrder);
}
accountNew.setUserEmail(accountBindEmailDTO.getUserEmail());
// accountNew.setOccupation(accountBindEmailDTO.getOccupation());
// accountNew.setCountry(accountBindEmailDTO.getCountry());
// accountNew.setTitle(accountBindEmailDTO.getTitle());
// accountNew.setSurname(accountBindEmailDTO.getSurname());
// accountNew.setGivenName(accountBindEmailDTO.getGivenName());
accountMapper.updateById(accountNew);
TrialOrder trialOrder = CopyUtil.copyObject(accountNew, TrialOrder.class);
trialOrder.setEmail(accountNew.getUserEmail());
trialOrder.setCreateTime(LocalDateTime.now());
trialOrder.setUpdateTime(LocalDateTime.now());
trialOrder.setStatus(1);
// 获取用户申请试用IP
String ipAddress = RequestInfoUtil.getIpAddress(request);
trialOrder.setIp(ipAddress);
trialOrderMapper.insert(trialOrder);
return result;
}

View File

@@ -529,11 +529,14 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
vo.setLikeNum(redisUtil.getLikeCount(vo.getId()));
vo.setViewNums(redisUtil.getViewCount(vo.getId()));
Long accountId = vo.getAccountId();
vo.setUserName(accountMapper.selectById(accountId).getUserName());
if (vo.getOriginal() == 0) {
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
Account account = accountMapper.selectById(accountId);
if (!Objects.isNull(account)) {
vo.setUserName(account.getUserName());
if (vo.getOriginal() == 0) {
vo.setOriginalUserName(accountMapper.selectById(vo.getOriginalAccountId()).getUserName());
}
return vo;
}
return vo;
}
return null;
});

View File

@@ -36,13 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.*;
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.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -365,6 +363,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
toProductImageResult.setImageStrength(toProductImageDTO.getImageStrength());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -378,6 +378,66 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
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
private ToProductElementMapper toProductElementMapper;
@@ -535,6 +595,48 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
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
@Transactional(rollbackFor = Exception.class)
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) {
@@ -594,6 +696,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);
@@ -609,9 +712,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
// toProductImageResult.setUrl(productImageUrl);
toProductImageResult.setIsLike(0);
toProductImageResult.setTaskId(taskId);
toProductImageResult.setUserLikeGroupId(userLikeGroupId);
if (toProductImageDTO.getBrightenValue() != null) {
toProductImageResult.setBrightenValue(toProductImageDTO.getBrightenValue());
}
toProductImageResult.setDirection(toProductImageDTO.getDirection());
toProductImageResultMapper.insert(toProductImageResult);
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result.add(toProductImageResult);