Merge remote-tracking branch 'origin/dev-ltx' into dev/3.1_release_merge

# Conflicts:
#	src/main/java/com/ai/da/service/WorkspaceService.java
#	src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
#	src/main/java/com/ai/da/service/impl/WorkspaceServiceImpl.java
This commit is contained in:
litianxiang
2025-10-02 00:41:04 +08:00
14 changed files with 1157 additions and 231 deletions

View File

@@ -96,4 +96,6 @@ public interface GenerateService extends IService<Generate> {
String getFluxResult(String taskId, String objectName);
byte[] downloadVideoOrImage(String url);
String createGoogleAsyncTask(GenerateThroughImageTextDTO generateDTO, String useModel, String prompt);
}

View File

@@ -66,4 +66,6 @@ public interface WorkspaceService extends IService<Workspace> {
Workspace getWSByProjectId(Long projectId);
String getProjectSexById(Long projectId);
}

View File

@@ -23,6 +23,7 @@ import com.ai.da.python.vo.ImageSegmentation;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -30,6 +31,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import io.netty.util.internal.StringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
@@ -55,6 +57,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementMapper, CollectionElement> implements CollectionElementService {
@Resource
private CollectionElementMapper collectionElementMapper;
@@ -79,6 +82,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Resource
private MinioUtil minioUtil;
private WorkspaceService workspaceService;
@Value("${minio.bucketName.collectionElement}")
private String collectionElement;
@Value("${minio.bucketName.gradient}")
@@ -88,7 +93,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Resource
private RedisUtil redisUtil;
// @Resource
// @Resource
// private RedisUtil redisUtil;
@Resource
private EmailService emailService;
@@ -103,7 +108,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
String name;
if (Objects.isNull(level1TypeEnum) && !uploadDTO.getLevel1Type().equals(Module.deReconstruction.getValue())) {
throw new BusinessException("unknown.parameter.level1Type");
} else if (uploadDTO.getLevel1Type().equals(Module.deReconstruction.getValue())){
} else if (uploadDTO.getLevel1Type().equals(Module.deReconstruction.getValue())) {
name = "Construction";
} else {
name = level1TypeEnum.getRealName();
@@ -112,12 +117,12 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
String path = minioUtil.upload(collectionElement, objectName, uploadDTO.getFile());
String level2Type = null;
if (uploadDTO.getLevel1Type().equals(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName())){
if (uploadDTO.getLevel1Type().equals(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName())) {
if (StringUtil.isNullOrEmpty(uploadDTO.getGender())) {
throw new BusinessException("gender.cannot.be.empty");
}
level2Type = pythonService.getClothCategory(path,uploadDTO.getGender());
}else if (!StringUtil.isNullOrEmpty(uploadDTO.getLevel2Type())){
level2Type = pythonService.getClothCategory(path, uploadDTO.getGender());
} else if (!StringUtil.isNullOrEmpty(uploadDTO.getLevel2Type())) {
level2Type = uploadDTO.getLevel2Type();
}
@@ -199,8 +204,11 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
//按时区计算
element.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
element.setLevel2Type(level2Type);
if (Objects.nonNull(uploadDTO.getProjectId())){
if (Objects.nonNull(uploadDTO.getProjectId())) {
element.setProjectId(uploadDTO.getProjectId());
if (CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName().equals(element.getLevel1Type())) {
element.setLevel3Type(workspaceService.getProjectSexById(uploadDTO.getProjectId()));
}
}
// String linuxDomain = fileProperties.getLinuxDomain();
// if (!StringUtils.isEmpty(linuxDomain)) {
@@ -265,7 +273,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
List<String> printPath = Arrays.asList(url1, url2);
//调取python 接口
String generateUrl = pythonService.generatePrint(printPath,userId);
String generateUrl = pythonService.generatePrint(printPath, userId);
if (StringUtils.isEmpty(generateUrl)) {
throw new BusinessException("generate.interface.exception");
}
@@ -369,7 +377,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return Boolean.TRUE;
}
private CollectionElement resolveData(String path, String timeZone, Long userId){
private CollectionElement resolveData(String path, String timeZone, Long userId) {
// File file = new File(path);
String name = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
@@ -382,7 +390,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
element.setHasPin((byte) 0);
try {
element.setMd5(MD5Utils.encryptFile(minioUtil.download(path)));
}catch (Exception e){
} catch (Exception e) {
throw new RuntimeException(e);
}
/* catch (MinioException | IOException e) {
@@ -394,55 +402,82 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return element;
}
/**
* 验证和处理设计集合元素
* <p>
* 功能说明:
* - 验证设计集合DTO中的各种元素moodBoards、printBoards、sketchBoards等
* - 处理渐变色彩板的base64图片上传到MinIO
* - 校验PIN数量限制上衣、下衣、外套各不超过8个
* - 验证模特信息和模板点位
* - 转换并整合来自library和generate的元素数据
*
* @param designDTO 设计集合DTO包含所有设计元素信息
* @return ValidateElementVO 验证后的元素VO对象包含处理后的所有元素数据
* @throws BusinessException 当数据验证失败时抛出业务异常
*/
@Override
public ValidateElementVO validateElement(DesignCollectionDTO designDTO) {
// 将设计DTO转换为验证元素VO对象
ValidateElementVO elementVO = CopyUtil.copyObject(designDTO, ValidateElementVO.class);
// 处理颜色板中的渐变色彩
List<CollectionColorDTO> colorBoards = elementVO.getColorBoards();
for (CollectionColorDTO colorBoard : colorBoards) {
if (Objects.nonNull(colorBoard.getGradient())) {
// 解析base64格式的渐变图片数据
String colorImg = colorBoard.getGradient().getColorImg();
String[] parts = colorImg.split(",");
String imageType = parts[0].split("/")[1].split(";")[0];
String base64Data = parts[1];
String imageType = parts[0].split("/")[1].split(";")[0]; // 提取图片类型
String base64Data = parts[1]; // 提取base64数据
// 将base64图片上传到MinIO存储
String gradientMinioUrl = minioUtil.uploadImageFromBase64(gradientBucketName, base64Data, imageType);
colorBoard.setGradientMinioUrl(gradientMinioUrl);
colorBoard.getGradient().setColorImg(null);
colorBoard.setGradientString(JSON.toJSONString(colorBoard.getGradient()));
colorBoard.getGradient().setColorImg(null); // 清空原始base64数据
colorBoard.setGradientString(JSON.toJSONString(colorBoard.getGradient())); // 保存渐变配置JSON
}
}
elementVO.setColorBoards(colorBoards);
List<Long> usedElementIds = elementVO.getUsedElementIds();
List<CollectionElement> libraryCollectionElements = elementVO.getLibraryCollectionElements();
List<CollectionElement> generateCollectionElements = elementVO.getGenerateCollectionElements();
//校验moodboard
// 初始化用于收集各类元素的集合
List<Long> usedElementIds = elementVO.getUsedElementIds(); // 已使用的元素ID列表
List<CollectionElement> libraryCollectionElements = elementVO.getLibraryCollectionElements(); // 来自library的元素
List<CollectionElement> generateCollectionElements = elementVO.getGenerateCollectionElements(); // 来自generate的元素
// ========== 校验和处理moodBoards情绪板 ==========
if (CollectionUtil.isNotEmpty(designDTO.getMoodBoards())) {
//校验designType
// 校验designType字段是否有效
validateDesignType(designDTO.getMoodBoards(), "moodBoards");
// 提取类型为COLLECTION的moodBoard ID列表
List<Long> moodBoardIds = designDTO.getMoodBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
.map(DesignCollectionElementDTO::getId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(moodBoardIds)) {
// 从数据库批量查询moodBoard元素
List<CollectionElement> MoodBoardElements = collectionElementMapper.selectBatchIds(moodBoardIds);
// 验证查询结果的完整性
if (CollectionUtil.isEmpty(MoodBoardElements) || MoodBoardElements.size() != moodBoardIds.size()) {
throw new BusinessException("get.moodBoards.data.is.mismatch");
}
elementVO.setMoodBoardElements(MoodBoardElements);
usedElementIds.addAll(moodBoardIds);
usedElementIds.addAll(moodBoardIds); // 记录已使用的元素ID
}
//library
// 处理类型为LIBRARY的moodBoard元素
List<Long> libraryIds = designDTO.getMoodBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
.map(DesignCollectionElementDTO::getId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(libraryIds)) {
List<Library> librarys = libraryService.getByIds(libraryIds);
//校验防止用户在library删除 对应不上
// 不严格校验防止用户在library删除元素导致对应不上
if (CollectionUtil.isNotEmpty(librarys)) {
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys, null));
}
}
// generate
// 处理类型为GENERATE的moodBoard元素
List<Long> generateIds = designDTO.getMoodBoards().stream()
.filter(o -> o.getDesignType().equals((DesignTypeEnum.GENERATE.getRealName())))
.map(DesignCollectionElementDTO::getId)
@@ -454,38 +489,45 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
}
}
// ========== 校验和处理printBoards印花板 ==========
if (CollectionUtil.isNotEmpty(designDTO.getPrintBoards())) {
//校验designType
// 校验designType字段是否有效
validateDesignType(CopyUtil.copyList(designDTO.getPrintBoards(), DesignCollectionElementDTO.class), "printBoards");
// 提取类型为COLLECTION的printBoard ID列表
List<Long> printBoardIds = designDTO.getPrintBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
.map(DesignCollectionPrintElementDTO::getId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(printBoardIds)) {
//校验printboard
// 从数据库批量查询printBoard元素
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
// 验证查询结果的完整性
if (CollectionUtil.isEmpty(printBoardElements) || printBoardElements.size() != printBoardIds.size()) {
throw new BusinessException("get.printBoards.data.is.mismatch");
}
elementVO.setPrintBoardElements(printBoardElements);
usedElementIds.addAll(printBoardIds);
usedElementIds.addAll(printBoardIds); // 记录已使用的元素ID
}
//library
// 处理类型为LIBRARY的printBoard元素
List<Long> libraryIds = designDTO.getPrintBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
.map(DesignCollectionPrintElementDTO::getId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(libraryIds)) {
List<Library> librarys = libraryService.getByIds(libraryIds);
//校验防止用户在library删除 对应不上
// 不严格校验防止用户在library删除元素导致对应不上
if (CollectionUtil.isNotEmpty(librarys)) {
// 创建ID到printBoard元素的映射用于保持元素属性
Map<Long, DesignCollectionPrintElementDTO> idToMap = designDTO.getPrintBoards()
.stream()
.collect(Collectors.toMap(DesignCollectionPrintElementDTO::getId, v -> v));
libraryCollectionElements.addAll(covertLibrarysToPrintCollections(librarys, idToMap));
}
}
// generate
// 处理类型为GENERATE的printBoard元素
List<Long> generateIds = designDTO.getPrintBoards().stream()
.filter(o -> o.getDesignType().equals((DesignTypeEnum.GENERATE.getRealName())))
.map(DesignCollectionPrintElementDTO::getId)
@@ -493,6 +535,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
if (CollectionUtil.isNotEmpty(generateIds)) {
List<GenerateDetail> generateDetailList = generateDetailMapper.selectBatchIds(generateIds);
if (CollectionUtil.isNotEmpty(generateDetailList)) {
// 创建ID到printBoard元素的映射用于保持元素属性
Map<Long, DesignCollectionPrintElementDTO> idToMap = designDTO.getPrintBoards()
.stream()
.collect(Collectors.toMap(DesignCollectionPrintElementDTO::getId, v -> v));
@@ -500,80 +543,113 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
}
}
// ========== 校验和处理sketchBoards草图板 ==========
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
//校验PIN是否满足 上衣或者下衣必须不超过8
// 校验PIN数量限制:上衣、下衣、外套各不超过8
long topNum = 0;
long bottomNum = 0;
long outerwearNum = 0;
if (designDTO.getModelSex().equals(Sex.FEMALE.getValue())) {
topNum= designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
bottomNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
}else if (designDTO.getModelSex().equals(Sex.MALE.getValue())) {
topNum= designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.TOPS.contains(skecth.getLevel2Type())).count();
bottomNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.BOTTOMS.contains(skecth.getLevel2Type())).count();
}
outerwearNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.OUTWEAR.contains(skecth.getLevel2Type())).count();
if (topNum > 8 || bottomNum > 8 || outerwearNum > 8) {
throw new BusinessException("the.number.of.PIN.top.or.bottom.or.outerwear.sketchBoard.cannot.be.more.than.8", ResultEnum.PROMPT.getCode());
}
//校验designType
Boolean result = designDTO.getSketchBoards().stream()
.filter(mood -> StringUtils.isEmpty(mood.getDesignType()))
.findFirst().isPresent();
if (result) {
throw new BusinessException("sketchBoards.designType.cannot.be.empty");
//去掉与性别不符合的线稿元素 - 使用 Iterator 安全移除元素
Iterator<CollectionSketchDTO> sketchIterator = designDTO.getSketchBoards().iterator();
while (sketchIterator.hasNext()) {
CollectionSketchDTO sketchBoard = sketchIterator.next();
String level2Type = sketchBoard.getLevel2Type();
//判断性别和当前project性别是否一致不一致则移除
String level3Type = collectionElementMapper.selectOne(new LambdaQueryWrapper<CollectionElement>().eq(CollectionElement::getId, sketchBoard.getSketchBoardId()).select(CollectionElement::getLevel3Type)).getLevel3Type();
if (!level3Type.equalsIgnoreCase(designDTO.getModelSex())) {
sketchIterator.remove();
}
}
//再次判断草图板数量如果为null则跳出当前if
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
.map(CollectionSketchDTO::getSketchBoardId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sketchBoardIds)) {
//校验sketchBoard
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
if (CollectionUtil.isEmpty(sketchBoardElements) || sketchBoardElements.size() != sketchBoardIds.size()) {
throw new BusinessException("get.sketchBoards.data.is.mismatch");
// 根据模特性别统计不同类型的PIN数量
if (designDTO.getModelSex().equals(Sex.FEMALE.getValue())) {
// 女性模特统计连衣裙和上衣类PIN数量
topNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
// 女性模特统计裙子和裤子类PIN数量
bottomNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
} else if (designDTO.getModelSex().equals(Sex.MALE.getValue())) {
// 男性模特统计上衣类PIN数量
topNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.TOPS.contains(skecth.getLevel2Type())).count();
// 男性模特统计下装类PIN数量
bottomNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.BOTTOMS.contains(skecth.getLevel2Type())).count();
}
elementVO.setSketchBoardElements(sketchBoardElements);
usedElementIds.addAll(sketchBoardIds);
}
//library
List<Long> libraryIds = designDTO.getSketchBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
.map(CollectionSketchDTO::getSketchBoardId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(libraryIds)) {
List<Library> librarys = libraryService.getByIds(libraryIds);
//不校验了防止用户在library删除 对应不上
if (CollectionUtil.isNotEmpty(librarys)) {
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys, idToMap));
// 统计外套类PIN数量男女通用
outerwearNum = designDTO.getSketchBoards().stream()
.filter(skecth -> skecth.getIsPin() == 1
&& DesignPythonItem.OUTWEAR.contains(skecth.getLevel2Type())).count();
// 验证PIN数量限制每个类别不能超过8个
if (topNum > 8 || bottomNum > 8 || outerwearNum > 8) {
throw new BusinessException("the.number.of.PIN.top.or.bottom.or.outerwear.sketchBoard.cannot.be.more.than.8", ResultEnum.PROMPT.getCode());
}
}
// generate
List<Long> generateIds = designDTO.getSketchBoards().stream()
.filter(o -> o.getDesignType().equals((DesignTypeEnum.GENERATE.getRealName())))
.map(CollectionSketchDTO::getSketchBoardId)
.collect((Collectors.toList()));
if (CollectionUtil.isNotEmpty(generateIds)) {
List<GenerateDetail> generateDetailList = generateDetailMapper.selectBatchIds(generateIds);
if (CollectionUtil.isNotEmpty(generateDetailList)) {
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
generateCollectionElements.addAll(covertGeneratesToCollections(generateDetailList, idToMap));
// 校验designType字段不能为空
Boolean result = designDTO.getSketchBoards().stream()
.filter(mood -> StringUtils.isEmpty(mood.getDesignType()))
.findFirst().isPresent();
if (result) {
throw new BusinessException("sketchBoards.designType.cannot.be.empty");
}
// 提取类型为COLLECTION的sketchBoard ID列表
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
.map(CollectionSketchDTO::getSketchBoardId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sketchBoardIds)) {
// 从数据库查询验证sketchBoard元素是否存在
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
if (CollectionUtil.isEmpty(sketchBoardElements) || sketchBoardElements.size() != sketchBoardIds.size()) {
throw new BusinessException("get.sketchBoards.data.is.mismatch");
}
// 设置验证通过的sketchBoard元素到结果对象
elementVO.setSketchBoardElements(sketchBoardElements);
// 记录已使用的元素ID
usedElementIds.addAll(sketchBoardIds);
}
// 处理类型为LIBRARY的sketchBoard元素
List<Long> libraryIds = designDTO.getSketchBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
.map(CollectionSketchDTO::getSketchBoardId)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(libraryIds)) {
List<Library> librarys = libraryService.getByIds(libraryIds);
// 不严格校验防止用户在library中删除元素导致对应不上
if (CollectionUtil.isNotEmpty(librarys)) {
// 创建ID到sketchBoard元素的映射用于保持元素属性
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys, idToMap));
}
}
// 处理类型为GENERATE的sketchBoard元素
List<Long> generateIds = designDTO.getSketchBoards().stream()
.filter(o -> o.getDesignType().equals((DesignTypeEnum.GENERATE.getRealName())))
.map(CollectionSketchDTO::getSketchBoardId)
.collect((Collectors.toList()));
if (CollectionUtil.isNotEmpty(generateIds)) {
List<GenerateDetail> generateDetailList = generateDetailMapper.selectBatchIds(generateIds);
if (CollectionUtil.isNotEmpty(generateDetailList)) {
// 创建ID到sketchBoard元素的映射用于保持元素属性
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
generateCollectionElements.addAll(covertGeneratesToCollections(generateDetailList, idToMap));
}
}
}
}
@@ -606,13 +682,17 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
}
}*/
//校验控制生成类型
// ========== 校验控制生成类型参数 ==========
// 验证singleOverall参数单品/整体生成控制)
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
if (Objects.isNull(singleOverall)) {
log.error("未知singleOverall param{}", designDTO.getSingleOverall());
log.info("入参 designDTO => {}", designDTO);
throw new BusinessException("unknown.parameter.singleOverall");
}
// 如果是单品生成模式需要验证switchCategory参数
if (SingleOverallEnum.SINGLE.equals(singleOverall)) {
SwitchCategoryEnum switchCategory = SwitchCategoryEnum.of(designDTO.getSwitchCategory());
if (Objects.isNull(switchCategory)) {
@@ -621,36 +701,57 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
throw new BusinessException("unknown.parameter.switchCategory");
}
}
// 校验模特
// ========== 校验和处理模特信息 ==========
if (!CollectionUtils.isEmpty(designDTO.getMannequins())) {
// 处理多个模特的情况 - 使用 Iterator 安全移除元素
List<DesignLibraryModelPointVO> designLibraryModelPointVOList = new ArrayList<>();
for (MannequinDTO mannequin : designDTO.getMannequins()) {
Iterator<MannequinDTO> mannequinIterator = designDTO.getMannequins().iterator();
while (mannequinIterator.hasNext()) {
MannequinDTO mannequin = mannequinIterator.next();
if (mannequin.getType().equals("System")) {
// 处理系统模特
SysFileVO byId = sysFileService.getById(mannequin.getId());
if (Objects.isNull(byId)){
if (Objects.isNull(byId)) {
log.info("未知模特:{}{}", mannequin.getId(), "System");
throw new BusinessException("model.not.found");
}
if (!designDTO.getModelSex().equalsIgnoreCase(byId.getLevel2Type())) {
mannequinIterator.remove();
continue;
}
// 注释:女性模特的风格设置(已禁用)
// if (!StringUtils.isEmpty(byId.getLevel3Type()) && byId.getLevel2Type().equals("Female")) {
// elementVO.setStyle(byId.getLevel3Type());
// }
// 获取模特点位信息并计算模板点位
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), mannequin.getType());
designLibraryModelPointVOList.add(calculateTemplatePointTemplate(modelPoint, 700, 320, byId.getUrl()));
}else {
} else {
// 处理用户自定义模特
Library byId = libraryService.getById(mannequin.getId());
//如果当前模特性别和project模特性别不一致则为此模特进行design
if (!designDTO.getModelSex().equalsIgnoreCase(byId.getLevel2Type())) {
mannequinIterator.remove();
continue;
}
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), mannequin.getType());
designLibraryModelPointVOList.add(calculateTemplatePointTemplate(modelPoint, byId.getHigh(), byId.getWidth(), byId.getUrl()));
}
}
elementVO.setMannequins(designLibraryModelPointVOList);
}else {
} else {
// 处理单个模特的情况通过templateId指定
if (!StringUtils.isEmpty(designDTO.getModelType())) {
if (designDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
// 处理用户自定义模特
Library byId = libraryService.getById(designDTO.getTemplateId());
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, byId.getHigh(), byId.getWidth(), byId.getUrl()));
} else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
// 处理系统模特
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
// 设置女性模特的风格类型
if (Objects.nonNull(byId) && !StringUtils.isEmpty(byId.getLevel3Type()) && byId.getLevel2Type().equals("Female")) {
elementVO.setStyle(byId.getLevel3Type());
}
@@ -659,17 +760,25 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
}
}
// ========== 设置最终的验证结果参数 ==========
// 设置模特性别
elementVO.setModelSex(designDTO.getModelSex());
// 设置请求ID列表用于批量查询
elementVO.setRequestIdList(designDTO.getRequestIdList());
// 设置设计方案数量默认为8个
if (null != designDTO.getDesignNum()) {
elementVO.setDesignNum(designDTO.getDesignNum());
}else {
} else {
elementVO.setDesignNum(8);
}
// 设置品牌信息(如果存在)
if (null != designDTO.getBrandId()) {
elementVO.setBrandId(designDTO.getBrandId());
elementVO.setBrandScale(designDTO.getBrandScale());
elementVO.setBrandId(designDTO.getBrandId()); // 设置品牌ID
elementVO.setBrandScale(designDTO.getBrandScale()); // 设置品牌比例
}
// 返回验证结果对象
return elementVO;
}
@@ -786,7 +895,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
if (!CollectionUtils.isEmpty(sketchBoardIds)) {
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
elementVO.setSketchBoardElements(sketchBoardElements);
}else {
} else {
elementVO.setSketchBoardElements(new ArrayList<>());
}
}
@@ -806,7 +915,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
if (!CollectionUtils.isEmpty(printBoardIds)) {
List<CollectionElement> printBoardElements = collectionElementMapper.selectBatchIds(printBoardIds);
elementVO.setPrintBoardElements(printBoardElements);
}else {
} else {
elementVO.setPrintBoardElements(new ArrayList<>());
}
}
@@ -860,8 +969,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
//保存
List<TCollectionElementRelation> relations = list.stream().map(element ->
TCollectionElementRelation.builder().elementId(element.getId())
.collectionId(element.getCollectionId()).createDate(new Date()).build())
TCollectionElementRelation.builder().elementId(element.getId())
.collectionId(element.getCollectionId()).createDate(new Date()).build())
.collect(Collectors.toList());
tCollectionElementRelationService.saveBatch(relations);
pageQuery.setPage(pageQuery.getPage() + 1);
@@ -938,8 +1047,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
CollectionElement collectionElement = new CollectionElement();
if (!Objects.isNull(elementId)) {
if (!StringUtil.isNullOrEmpty(designType)){
switch (designType){
if (!StringUtil.isNullOrEmpty(designType)) {
switch (designType) {
case "collection":
collectionElement = collectionElementMapper.selectById(elementId);
if (StringUtil.isNullOrEmpty(collectionElement.getLevel2Type()) || !(collectionElement.getLevel2Type()).equals(level2Type)) {
@@ -950,11 +1059,11 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
case "library":
Library libraryElement = libraryService.getById(elementId);
if (!Objects.isNull(libraryElement)) {
if (StringUtil.isNullOrEmpty(libraryElement.getLevel2Type()) || !(libraryElement.getLevel2Type()).equals(level2Type)){
if (StringUtil.isNullOrEmpty(libraryElement.getLevel2Type()) || !(libraryElement.getLevel2Type()).equals(level2Type)) {
libraryElement.setLevel2Type(level2Type);
libraryService.updateById(libraryElement);
}
BeanUtils.copyProperties(libraryElement,collectionElement);
BeanUtils.copyProperties(libraryElement, collectionElement);
}
break;
}
@@ -962,7 +1071,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
log.error("designType cannot be empty");
throw new BusinessException("element source type cannot be empty!");
}
}else {
} else {
return null;
}
return collectionElement;
@@ -979,7 +1088,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return collectionElementList;
}
private Generate setGenerate(Long userId,String timeZone){
private Generate setGenerate(Long userId, String timeZone) {
Generate generate = new Generate();
generate.setAccountId(userId);
generate.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
@@ -989,23 +1098,23 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return generate;
}
private GenerateDetail setGenerateDetail(Long generateId, String url, String timeZone){
private GenerateDetail setGenerateDetail(Long generateId, String url, String timeZone) {
GenerateDetail generateDetail = new GenerateDetail();
generateDetail.setGenerateId(generateId);
generateDetail.setUrl(url);
String md5;
try {
md5 = MD5Utils.encryptFile(minioUtil.download(url));
} catch (Exception e){
} catch (Exception e) {
throw new RuntimeException(e);
}/*catch (MinioException | IOException e) {
throw new RuntimeException(e);
}*/
// 通过MD5来确认当前图片是否有被like过避免重复like
List<Map<String, Long>> libraryIds = generateDetailMapper.getLibraryIdThroughMD5(md5, CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
if (libraryIds.isEmpty()){
if (libraryIds.isEmpty()) {
generateDetail.setIsLike((byte) 0);
}else {
} else {
generateDetail.setIsLike((byte) 1);
generateDetail.setLibraryId(libraryIds.get(0).get("library_id"));
}
@@ -1089,14 +1198,14 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
(imageData.getImage_url(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME), false);
redisUtil.addToString(key, new Gson().toJson(imageData), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url()));
} else if (sourceType.equals("Library")){
} else if (sourceType.equals("Library")) {
// 从library中选择的图片需要更新数据库中对应图片的分割数据
String segmentedData = String.join(",", imageData.getClothing_url());
library.setSegmentedData(segmentedData);
library.setUpdateDate(new Date());
libraryService.updateById(library);
resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), imageData.getClothing_url()));
}else {
} else {
resp.add(createCollectionElementVO(accountId, id, collectionElement.getLevel1Type(), collectionElement.getUrl(), imageData.getClothing_url()));
}
}
@@ -1122,9 +1231,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return vo;
}
public void updateElementLevel2Type(Long elementId, String level2Type){
public void updateElementLevel2Type(Long elementId, String level2Type) {
CollectionElement collectionElement = baseMapper.selectById(elementId);
if (Objects.nonNull(collectionElement)){
if (Objects.nonNull(collectionElement)) {
collectionElement.setLevel2Type(level2Type);
collectionElement.setUpdateDate(new Date());
baseMapper.updateById(collectionElement);

View File

@@ -359,20 +359,25 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
Long designId = saveOne(designDTO, collectionId, userInfo.getId());
//计算library
// calculateLibraryAndSysFile(designDTO, elementVO, userInfo);
//组装design入参
// ========== AI设计生成阶段 ==========
// 组装design入参 - 将业务参数转换为Python AI服务所需的格式
long startTime = System.currentTimeMillis();
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId(), collectionIdParam);
long endTime = System.currentTimeMillis();
long totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("组装入参运行时间:" + totalTimeInSeconds + "");
// pythonObjects增加image_id关联
// pythonObjects增加image_id关联 - 建立设计元素与图片的关联关系
startTime = System.currentTimeMillis();
relationImageIds(pythonObjects);
endTime = System.currentTimeMillis();
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("增加image_id关联运行时间" + totalTimeInSeconds + "");
//design
// design - 调用Python AI服务进行设计生成
startTime = System.currentTimeMillis();
String requestId = UUID.randomUUID().toString();
pythonObjects.setRequestId(requestId);
@@ -380,7 +385,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
endTime = System.currentTimeMillis();
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("design python端运行时间" + totalTimeInSeconds + "");
//生成library
// ========== 后处理阶段 ==========
// 生成library - 根据设计元素生成设计库信息
startTime = System.currentTimeMillis();
String ageGroup = getAgeGroupByCollectionId(collectionId);
generateLibrary(elementVO, designDTO.getTimeZone(), ageGroup);
@@ -392,7 +399,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("处理关联关系运行时间:" + totalTimeInSeconds + "");
// 构建设计上下文信息 - 保存设计过程中的关键参数和状态
Map<String, Object> context = new HashMap<>();
context.put("pythonObjects", pythonObjects); // 转换后的 Python 请求参数
context.put("designId", designId); // 设计 ID
@@ -402,11 +409,14 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
context.put("singleOverall", designDTO.getSingleOverall()); // 其他设计参数
context.put("requestIdList", elementVO.getRequestIdList());
// 将上下文存入全局设计上下文中
// 将上下文存入全局设计上下文中 - 用于后续异步查询和处理
designContext.put(requestId, context);
//保存python返回信息;保存designItem和detail
// 保存python返回信息;保存designItem和detail(注释说明)
// 注意:实际的设计结果保存是通过异步回调方式处理的,这里只是准备阶段
// return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
// 返回请求ID - 客户端可以使用此ID查询设计进度和结果
return requestId;
}
@@ -2929,6 +2939,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
collectionElement.setAccountId(project.getAccountId());
collectionElement.setProjectId(project.getId());
collectionElement.setLevel2Type(receiveCollectionElement.getLevel2Type());
collectionElement.setLevel3Type(workspaceService.getProjectSexById(project.getId()));
collectionElement.setName(split1[0]);
collectionElement.setUrl(url);
collectionElement.setHasPin((byte) 0);

File diff suppressed because it is too large Load Diff

View File

@@ -742,10 +742,21 @@ public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio
.collect(Collectors.groupingBy(userLikeSnapshot -> userLikeSnapshot.getDesignItem().getDesignId()));
userLikeMapByDesignId.forEach((designId, userLikeListOld1) -> {
Design design = designMapper.selectById(designId);
//数据库中存在designId为-1的情况此处值从workspace里取
//数据库中存在designId为-1的情况
if (design == null) {
design = new Design();
//此处值从workspace里取
design.setSystemScale(BigDecimal.valueOf(workspaceOld.getSystemDesignerPercentage()).movePointLeft(2));
//根据CollectionElement存在model来判断是否是single
List<CollectionElement> modelTypeElements = collectionElementListOld.stream()
.filter(element -> element.getLevel1Type().equals(CollectionLevel1TypeEnum.MODEL.getRealName()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(modelTypeElements)){
design.setSingleOverall("overall");
}else {
design.setSingleOverall("single");
}
}
design.setId(null);
design.setCollectionId(collectionIdNew);

View File

@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.constant.CommonConstant;
import com.ai.da.common.constant.ModelConstants;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
import com.ai.da.common.enums.CreditsEventsEnum;
@@ -405,9 +406,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
@Transactional(rollbackFor = Exception.class)
public List<ToProductImageResultVO> toProduct(ToProductImageDTO toProductImageDTO) {
// 判断用户当前积分是否够本次生成消耗
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
&& toProductImageDTO.getModelName().equals("flux");
CreditsEventsEnum creditsEventsEnum = fluxTask ? CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX : CreditsEventsEnum.TO_PRODUCT_IMAGE;
boolean nanoBananaTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
&& toProductImageDTO.getModelName().equals(ModelConstants.ADVANCED)||toProductImageDTO.getModelName().equals(ModelConstants.HIGH);
CreditsEventsEnum creditsEventsEnum = nanoBananaTask ? CreditsEventsEnum.TO_PRODUCT_IMAGE_ADVANCED : CreditsEventsEnum.TO_PRODUCT_IMAGE;
Boolean preDeduction = creditsService.creditsPreDeduction(creditsEventsEnum, toProductImageDTO.getToProductImageVOList().size());
if (!preDeduction) {
throw new BusinessException("remaining.credits.insufficient", ResultEnum.WARNING.getCode());
@@ -487,12 +488,29 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
}
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
if (fluxTask){
if (nanoBananaTask){
if (childFlag){
sb.append(", Children's face");
}
taskId = generateService.flux(CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX, sb.toString(), tDesignPythonOutfit.getDesignUrl(), childFlag);
toProductImageResult.setModelName("flux");
// 使用Google nanobanana模型
GenerateThroughImageTextDTO generateDTO = new GenerateThroughImageTextDTO();
generateDTO.setUserId(userHolder.getId());
generateDTO.setLevel1Type("Product");
generateDTO.setLevel2Type("ToProduct");
generateDTO.setGender("unisex");
generateDTO.setCollectionElementId(tDesignPythonOutfit.getId());
generateDTO.setDesignType("DesignOutfit");
try {
//使用nano banana用这个提示词
String nanoPrompt = "Change the input image to the real image. Full length portrait, match the clothing size, clothing style, " +
"patterns, and fabric texture from the reference image, replicate garment design details precisely, " +
"maintain original color scheme, high fidelity to reference attire, realistic lighting, detailed fabric rendering.";
taskId = generateService.createGoogleAsyncTask(generateDTO, ModelConstants.NANO_BANANA, nanoPrompt);
} catch (Exception e) {
log.error("Google nanobanana generation failed", e);
throw new BusinessException("Generation failed, please try again");
}
toProductImageResult.setModelName("nanobanana");
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
} else {
// 走模型
@@ -547,9 +565,26 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
if (fluxTask){
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag);
toProductImageResult.setModelName("flux");
if (nanoBananaTask){
// 使用Google nanobanana模型
GenerateThroughImageTextDTO generateDTO = new GenerateThroughImageTextDTO();
generateDTO.setUserId(userHolder.getId());
generateDTO.setLevel1Type("Product");
generateDTO.setLevel2Type("ToProduct");
generateDTO.setGender("unisex");
generateDTO.setCollectionElementId(toProductElement.getId());
generateDTO.setDesignType("ProductElement");
try {
//使用nano banana用这个提示词
String nanoPrompt = "Change the input image to the real image. Full length portrait, match the clothing size, clothing style, " +
"patterns, and fabric texture from the reference image, replicate garment design details precisely, " +
"maintain original color scheme, high fidelity to reference attire, realistic lighting, detailed fabric rendering.";
taskId = generateService.createGoogleAsyncTask(generateDTO, ModelConstants.NANO_BANANA, nanoPrompt);
} catch (Exception e) {
log.error("Google nanobanana generation failed", e);
throw new BusinessException("Generation failed, please try again");
}
toProductImageResult.setModelName("nanobanana");
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
} else {
// 走模型
@@ -2507,6 +2542,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName());
collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setLevel3Type(workspaceService.getProjectSexById(projectId));
collectionElement.setName(library.getName());
collectionElement.setUrl(library.getUrl());
collectionElement.setHasPin(board.getIsPin());
@@ -2520,6 +2556,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName());
collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setLevel3Type(workspaceService.getProjectSexById(projectId));
// collectionElement.setName(generateDetail.get());
collectionElement.setUrl(generateDetail.getUrl());
collectionElement.setHasPin(board.getIsPin());
@@ -2540,6 +2577,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setHasPin(board.getIsPin());
collectionElement.setUpdateDate(new Date());
if (CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName().equals(collectionElement.getLevel1Type())){
collectionElement.setLevel3Type(workspaceService.getProjectSexById(project.getId()));
}
collectionElementMapper.updateById(collectionElement);
}
}
@@ -2649,6 +2689,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
collectionElement.setAccountId(accountId);
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
collectionElement.setLevel3Type(workspaceService.getProjectSexById(project.getId()));
// collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setName(sysFile.getName());
collectionElement.setUrl(sysFile.getUrl());
@@ -2669,6 +2710,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
collectionElement.setAccountId(accountId);
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
collectionElement.setLevel3Type(workspaceService.getProjectSexById(project.getId()));
// collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setName(library.getName());
collectionElement.setUrl(library.getUrl());

View File

@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
import com.ai.da.common.enums.CollectionLevel2TypeEnum;
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.ResultEnum;
@@ -16,6 +17,7 @@ import com.ai.da.model.enums.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.SysFileService;
import com.ai.da.service.WorkspaceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -722,30 +724,36 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
if (projectDTO.getProcess().equals(DesignProcess.SERIES_DESIGN.name()) || projectDTO.getProcess().equals(DesignProcess.SKETCH_COLLAGE_PROCESS.name())) {
if (!workspaceNew.getAgeGroup().equals(workspace.getAgeGroup()) || !workspaceNew.getSex().equals(workspace.getSex())) {
// 性别变更 清理sketch及模特
deleteMannequinByProjectId(projectId);
// deleteMannequinByProjectId(projectId);
if (!workspaceNew.getSex().equals(workspace.getSex())) {
deleteSketchByProjectId(projectId);
// deleteSketchByProjectId(projectId);
LambdaQueryWrapper<CollectionElement> queryWrapper = new LambdaQueryWrapper<CollectionElement>().eq(CollectionElement::getProjectId, projectId)
.eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.MODEL.getRealName())
.eq(CollectionElement::getLevel3Type, workspaceNew.getSex());
if (collectionElementMapper.selectCount(queryWrapper) == 0){
SysFile sysFile = sysFileService.getOneBySex(projectDTO.getStyleId(), projectDTO.getWorkspace().getSex(), projectDTO.getWorkspace().getAgeGroup());
CollectionElement collectionElement = new CollectionElement();
collectionElement.setAccountId(userInfo.getId());
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
collectionElement.setLevel3Type(projectDTO.getWorkspace().getSex());
collectionElement.setName(sysFile.getName());
collectionElement.setUrl(sysFile.getUrl());
collectionElement.setMd5(sysFile.getMd5());
collectionElement.setCreateDate(new Date());
collectionElement.setHasPin((byte) 0);
collectionElementMapper.insert(collectionElement);
CollectionElementRelModel collectionElementRelModel = new CollectionElementRelModel();
collectionElementRelModel.setCollectionElementId(collectionElement.getId());
collectionElementRelModel.setRelationId(sysFile.getId());
collectionElementRelModel.setRelationType("System");
collectionElementRelModelMapper.insert(collectionElementRelModel);
}
}
}
// 判断当前使用的模特风格与新的模特风格是否一致
SysFile sysFile = sysFileService.getOneBySex(projectDTO.getStyleId(), projectDTO.getWorkspace().getSex(), projectDTO.getWorkspace().getAgeGroup());
if (!checkIfModelExistsInProject(sysFile.getMd5(), projectId)){
CollectionElement collectionElement = new CollectionElement();
collectionElement.setAccountId(userInfo.getId());
collectionElement.setProjectId(projectId);
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
collectionElement.setName(sysFile.getName());
collectionElement.setUrl(sysFile.getUrl());
collectionElement.setMd5(sysFile.getMd5());
collectionElement.setCreateDate(new Date());
collectionElement.setHasPin((byte) 0);
collectionElementMapper.insert(collectionElement);
CollectionElementRelModel collectionElementRelModel = new CollectionElementRelModel();
collectionElementRelModel.setCollectionElementId(collectionElement.getId());
collectionElementRelModel.setRelationId(sysFile.getId());
collectionElementRelModel.setRelationType("System");
collectionElementRelModelMapper.insert(collectionElementRelModel);
}
}
workspaceNew.setId(workspace.getId());
workspace.setUpdateTime(LocalDateTime.now());
@@ -858,17 +866,6 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
collectionElementMapper.delete(qw);
}
// 由于在数据库中表设计问题,目前只能通过路径来判断项目中是否存在某一个模特
public Boolean checkIfModelExistsInProject(String md5, Long projectId){
QueryWrapper<CollectionElement> qw = new QueryWrapper<>();
qw.lambda().eq(CollectionElement::getProjectId, projectId)
.eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.MODEL.getRealName())
.eq(CollectionElement::getMd5, md5);
List<CollectionElement> collectionElements = collectionElementMapper.selectList(qw);
return collectionElements != null && !collectionElements.isEmpty();
}
@Override
public Long getByProjectId(Long projectId) {
QueryWrapper<Workspace> qw = new QueryWrapper<>();
@@ -890,6 +887,17 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
return workspaceList.get(0);
}
@Override
public String getProjectSexById(Long projectId) {
LambdaQueryWrapper<Workspace> workspaceLambdaQueryWrapper = new LambdaQueryWrapper<>();
workspaceLambdaQueryWrapper.eq(Workspace::getProjectId, projectId).select(Workspace::getSex);
Workspace workspace = workspaceMapper.selectOne(workspaceLambdaQueryWrapper);
if (workspace != null) {
return workspace.getSex();
}
return null;
}
public static List<File> getPNGFiles(String directoryPath) {
List<File> pngFiles = new ArrayList<>();
File directory = new File(directoryPath);