|
|
|
|
@@ -15,8 +15,10 @@ import com.ai.da.model.dto.ToProductImageDTO;
|
|
|
|
|
import com.ai.da.model.vo.*;
|
|
|
|
|
import com.ai.da.python.PythonService;
|
|
|
|
|
import com.ai.da.service.*;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
@@ -30,13 +32,14 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 服务实现类
|
|
|
|
|
*
|
|
|
|
|
@@ -258,25 +261,47 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|
|
|
|
int i = 0;
|
|
|
|
|
// 翻译
|
|
|
|
|
String prompt = toProductImageDTO.getPrompt();
|
|
|
|
|
String s = "";
|
|
|
|
|
StringBuilder sb = new StringBuilder("The best quality, masterpiece, real image.");
|
|
|
|
|
if (!StringUtil.isNullOrEmpty(prompt)) {
|
|
|
|
|
s = pythonService.promptTranslate(prompt);
|
|
|
|
|
}else {
|
|
|
|
|
s = "best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting";
|
|
|
|
|
prompt = pythonService.promptTranslate(prompt);
|
|
|
|
|
}
|
|
|
|
|
// else {
|
|
|
|
|
// s = "best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting";
|
|
|
|
|
// }
|
|
|
|
|
for (ToProductImageVO toProductImageVO : toProductImageDTO.getToProductImageVOList()) {
|
|
|
|
|
String taskId;
|
|
|
|
|
if (toProductImageVO.getElementType().equals("DesignOutfit")) {
|
|
|
|
|
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
|
|
|
|
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageVO.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(",8K realistic,HDR");
|
|
|
|
|
}else {
|
|
|
|
|
sb.append(",").append(prompt).append(",8K realistic,HDR");
|
|
|
|
|
}
|
|
|
|
|
// 走模型
|
|
|
|
|
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, s, toProductImageDTO.getImageStrength(), productType);
|
|
|
|
|
pythonService.toProductImage(tDesignPythonOutfit.getDesignUrl(), taskId, sb.toString(), toProductImageDTO.getImageStrength(), productType);
|
|
|
|
|
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
|
|
|
|
toProductImageResult.setElementId(tDesignPythonOutfit.getId());
|
|
|
|
|
toProductImageResult.setElementType("DesignOutfit");
|
|
|
|
|
@@ -290,10 +315,16 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|
|
|
|
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
|
|
|
|
result.add(toProductImageResult);
|
|
|
|
|
}else {
|
|
|
|
|
if (StringUtils.isEmpty(prompt)) {
|
|
|
|
|
sb.append(",8K realistic,HDR");
|
|
|
|
|
}else {
|
|
|
|
|
sb.append(",").append(prompt).append(",8K realistic,HDR");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
|
|
|
|
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
|
|
|
|
|
// 走模型
|
|
|
|
|
pythonService.toProductImage(toProductElement.getUrl(), taskId, s, toProductImageDTO.getImageStrength(), "overall");
|
|
|
|
|
pythonService.toProductImage(toProductElement.getUrl(), taskId, sb.toString(), toProductImageDTO.getImageStrength(), "overall");
|
|
|
|
|
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
|
|
|
|
toProductImageResult.setElementId(toProductElement.getId());
|
|
|
|
|
toProductImageResult.setElementType("ProductElement");
|
|
|
|
|
@@ -611,67 +642,150 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
|
|
|
|
public String likeHistoryRelSketch() {
|
|
|
|
|
QueryWrapper<UserLikeGroup> qw = new QueryWrapper<>();
|
|
|
|
|
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(qw);
|
|
|
|
|
Map<Long, List<List<Map<String, Object>>>> result = new HashMap<>();
|
|
|
|
|
List<List<Map<String, Object>>> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (UserLikeGroup userLikeGroup : userLikeGroups) {
|
|
|
|
|
Long accountId = userLikeGroup.getAccountId();
|
|
|
|
|
Long collectionId = userLikeGroup.getCollectionId();
|
|
|
|
|
|
|
|
|
|
QueryWrapper<CollectionElement> collectionElementQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, collectionId);
|
|
|
|
|
collectionElementQueryWrapper.lambda().eq(CollectionElement::getLevel1Type, "Sketchboard");
|
|
|
|
|
List<CollectionElement> collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper);
|
|
|
|
|
List<String> urlList = collectionElements.stream().map(CollectionElement::getUrl).collect(Collectors.toList());
|
|
|
|
|
// 提前转换为Set以提高contains的效率
|
|
|
|
|
List<CollectionElement> collectionElements = getCollectionElementsByCollectionId(collectionId);
|
|
|
|
|
Set<String> urlSet = collectionElements.stream()
|
|
|
|
|
.map(CollectionElement::getUrl)
|
|
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
|
|
|
|
QueryWrapper<UserLike> userLikeQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
userLikeQueryWrapper.lambda().eq(UserLike::getUserLikeGroupId, userLikeGroup.getId());
|
|
|
|
|
List<UserLike> userLikes = userLikeMapper.selectList(userLikeQueryWrapper);
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
List<UserLike> userLikes = getUserLikesByGroupId(userLikeGroup.getId());
|
|
|
|
|
|
|
|
|
|
for (UserLike userLike : userLikes) {
|
|
|
|
|
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
|
|
|
|
|
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, userLike.getDesignItemId());
|
|
|
|
|
designItemDetailQueryWrapper.lambda().ne(DesignItemDetail::getType, "Body");
|
|
|
|
|
List<DesignItemDetail> designItemDetails = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
|
|
|
|
|
Map<String, Object> sketch = new HashMap<>();
|
|
|
|
|
List<Map<String, Object>> userLikeSketchList = new ArrayList<>();
|
|
|
|
|
List<DesignItemDetail> designItemDetails = getDesignItemDetails(userLike.getDesignItemId());
|
|
|
|
|
|
|
|
|
|
for (DesignItemDetail designItemDetail : designItemDetails) {
|
|
|
|
|
Map<String, Object> sketch = new HashMap<>();
|
|
|
|
|
String path = designItemDetail.getPath();
|
|
|
|
|
|
|
|
|
|
// 下载路径到本地
|
|
|
|
|
// if (!StringUtils.isEmpty(path)) {
|
|
|
|
|
// String bucketName = minioUtil.getBucketNameFromPath(path);
|
|
|
|
|
// String objectName = minioUtil.getObjectNameFromPath(path);
|
|
|
|
|
// String localBasePath = "C:\\workspace\\fileData\\minio";
|
|
|
|
|
// String localFilePath = Paths.get(localBasePath, path).toString();
|
|
|
|
|
//
|
|
|
|
|
// // 检查文件是否已经存在,避免重复下载
|
|
|
|
|
// File localFile = new File(localFilePath);
|
|
|
|
|
// if (!localFile.exists()) {
|
|
|
|
|
// minioUtil.downloadMinioObjectToLocal(bucketName, objectName, localFilePath);
|
|
|
|
|
// } else {
|
|
|
|
|
// log.info("File already exists, skipping download: {}", localFilePath);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Long designId = designItemDetail.getDesignId();
|
|
|
|
|
Design design = designMapper.selectById(designId);
|
|
|
|
|
if (null == design) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (design.getSingleOverall().equals("single")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (design.getModelType().equals("System")) {
|
|
|
|
|
SysFile sysFile = sysFileMapper.selectById(design.getTemplateId());
|
|
|
|
|
if (null == sysFile) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sketch.put("sex", sysFile.getLevel2Type().equals("Male") ? "Male" : "Female");
|
|
|
|
|
} else {
|
|
|
|
|
Library library = libraryMapper.selectById(design.getTemplateId());
|
|
|
|
|
if (null == library) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sketch.put("sex", library.getLevel2Type().equals("Female") ? "Female" : "Male");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sketch.put("type", designItemDetail.getType());
|
|
|
|
|
sketch.put("path", path);
|
|
|
|
|
if (urlList.contains(path)) {
|
|
|
|
|
sketch.put("beSelected", true);
|
|
|
|
|
}else {
|
|
|
|
|
sketch.put("beSelected", false);
|
|
|
|
|
}
|
|
|
|
|
sketch.put("beSelected", urlSet.contains(path));
|
|
|
|
|
sketch.put("accountId", accountId);
|
|
|
|
|
|
|
|
|
|
if (path.contains("aida-sys-image/images/")) {
|
|
|
|
|
String searchPath = new String(path);
|
|
|
|
|
String replace = searchPath.replace("aida-sys-image/images/", "");
|
|
|
|
|
String replace = path.replace("aida-sys-image/images/", "");
|
|
|
|
|
String style = getStyleByUrl(replace);
|
|
|
|
|
if (!StringUtils.isEmpty(style)) {
|
|
|
|
|
sketch.put("style", style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
userLikeSketchList.add(sketch);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtil.isNotEmpty(userLikeSketchList)) {
|
|
|
|
|
result.add(userLikeSketchList);
|
|
|
|
|
}
|
|
|
|
|
list.add(sketch);
|
|
|
|
|
}
|
|
|
|
|
if (result.containsKey(accountId)) {
|
|
|
|
|
result.get(accountId).add(list);
|
|
|
|
|
}else {
|
|
|
|
|
List<List<Map<String, Object>>> lists = new ArrayList<>();
|
|
|
|
|
lists.add(list);
|
|
|
|
|
result.put(accountId, lists);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println(JSONObject.toJSONString(result));
|
|
|
|
|
|
|
|
|
|
// 将结果以美观的JSON形式保存到文件中
|
|
|
|
|
saveResultAsPrettyJson(result, "C:\\Users\\10233\\Desktop\\result.json");
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String download() {
|
|
|
|
|
// 下载 aida-collection-element bucket 下所有 Sketchboard 文件夹内容
|
|
|
|
|
// String sketchboardLocalPath = "C:\\workspace\\fileData\\minio";
|
|
|
|
|
// minioUtil.downloadSketchboardDirectories(sketchboardLocalPath);
|
|
|
|
|
//
|
|
|
|
|
// // 下载整个 aida-users bucket
|
|
|
|
|
// String aidaUsersLocalPath = "C:\\workspace\\fileData\\minio";
|
|
|
|
|
// minioUtil.downloadEntireBucket("aida-users", aidaUsersLocalPath);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提取公共方法
|
|
|
|
|
private List<CollectionElement> getCollectionElementsByCollectionId(Long collectionId) {
|
|
|
|
|
QueryWrapper<CollectionElement> qw = new QueryWrapper<>();
|
|
|
|
|
qw.lambda().eq(CollectionElement::getCollectionId, collectionId)
|
|
|
|
|
.eq(CollectionElement::getLevel1Type, "Sketchboard");
|
|
|
|
|
return collectionElementMapper.selectList(qw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<UserLike> getUserLikesByGroupId(Long groupId) {
|
|
|
|
|
QueryWrapper<UserLike> qw = new QueryWrapper<>();
|
|
|
|
|
qw.lambda().eq(UserLike::getUserLikeGroupId, groupId);
|
|
|
|
|
return userLikeMapper.selectList(qw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<DesignItemDetail> getDesignItemDetails(Long designItemId) {
|
|
|
|
|
QueryWrapper<DesignItemDetail> qw = new QueryWrapper<>();
|
|
|
|
|
qw.lambda().eq(DesignItemDetail::getDesignItemId, designItemId)
|
|
|
|
|
.ne(DesignItemDetail::getType, "Body");
|
|
|
|
|
return designItemDetailMapper.selectList(qw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveResultAsPrettyJson(List<List<Map<String, Object>>> result, String filePath) {
|
|
|
|
|
// 使用一个 Map<String, Object> 将结果存储为字符串键
|
|
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
resultMap.put("data", result);
|
|
|
|
|
|
|
|
|
|
try (FileWriter file = new FileWriter(filePath)) {
|
|
|
|
|
// 使用 JSONObject 将转换后的 Map 转为 JSON
|
|
|
|
|
JSONObject jsonObject = new JSONObject(resultMap);
|
|
|
|
|
// 格式化输出为美观的 JSON
|
|
|
|
|
file.write(JSON.toJSONString(jsonObject, SerializerFeature.PrettyFormat));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getStyleByUrl(String replace) {
|
|
|
|
|
String[] split = replace.split("/");
|
|
|
|
|
String tableName = getTableName(split);
|
|
|
|
|
if (StringUtils.isEmpty(tableName)) {
|
|
|
|
|
return null;
|
|
|
|
|
}else {
|
|
|
|
|
replace = split[1] + "/" + split[2];
|
|
|
|
|
return attributeRetrievalMapper.getStyleByUrl(replace, tableName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|