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

This commit is contained in:
litianxiang
2025-11-12 13:50:14 +08:00
23 changed files with 119 additions and 45 deletions

View File

@@ -24,4 +24,5 @@ public interface WorkspaceMapper extends CommonMapper<Workspace> {
*/
List<WorkspaceVO> selectWorkspacePage(IPage page, WorkspaceVO workspace);
String getStyleByProjectId(Long projectId);
}

View File

@@ -30,4 +30,8 @@ public interface AttributeRetrievalMapper {
void updateStyleByFileName(String style, String fileName, String tableName);
String getStyleByUrl(String replace,String tableName);
Integer getCountByStyle(String tableName, String style);
String getOneSystemSketchRadom(String tableName, String style, Integer randomNum);
}

View File

@@ -13,7 +13,8 @@ public enum FemalePosition implements IEnumDisplay {
BLOUSE("Blouse"),
DRESS("Dress"),
TROUSERS("Trousers"),
SKIRT("Skirt");
SKIRT("Skirt"),
OTHERS("Others");
private String value;

View File

@@ -11,7 +11,8 @@ public enum MalePosition implements IEnumDisplay {
TOPS("Tops"),
BOTTOMS("Bottoms"),
OUTWEAR("Outwear");
OUTWEAR("Outwear"),
OTHERS("Others");
private String value;

View File

@@ -19,7 +19,8 @@ public enum Position implements IEnumDisplay {
SKIRT("Skirt"),
SLOGAN("Slogan"),
LOGO("Logo"),
PATTERN("Pattern");
PATTERN("Pattern"),
OTHERS("Others");
private String value;

View File

@@ -29,6 +29,7 @@ import com.google.common.collect.Maps;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -666,33 +667,24 @@ public class PythonService {
BigDecimal randomValue = generateRandomValue();
boolean useSystem = randomValue.compareTo(systemScale) <= 0;
if (useSystem) {
// 获取系统推荐sketch
String categoryParam = elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, styleCategory, elementVO);
}else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
}
}else {
if (CollectionUtil.isNotEmpty(collectionElements)) {
int collectionNoPinSize = collectionElements.size();
int randomNum = RandomsUtil.randomSysFile(collectionNoPinSize);
return coverSketchToDesignPythonItem(collectionElements.get(randomNum).getId(), collectionElements.get(randomNum), elementVO);
}else {
String categoryParam = elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, styleCategory, elementVO);
}else {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
}
}
// 用过存在用户上传,则优先使用用户上传
if (!useSystem && CollectionUtil.isNotEmpty(collectionElements)) {
int collectionNoPinSize = collectionElements.size();
int randomNum = RandomsUtil.randomSysFile(collectionNoPinSize);
return coverSketchToDesignPythonItem(collectionElements.get(randomNum).getId(), collectionElements.get(randomNum), elementVO);
}
// 其他所有情况,都回退到使用系统推荐
String categoryParam = elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, elementVO.getBrandId(), elementVO.getBrandScale(),elementVO.getStyle());
if (CollectionUtils.isEmpty(recommentdUrlList)) {
throw new BusinessException("failed.to.obtain.system.sketch.recommendation");
}
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, styleCategory, elementVO);
// int poolNum = 20;
// if (CollectionUtil.isNotEmpty(collectionElements)) {
// int collectionNoPinSize = collectionElements.size();
@@ -1039,7 +1031,7 @@ public class PythonService {
// 获取随机pin sketch的category
String category = element.getLevel2Type();
String categoryParam = validateElementVO.getModelSex().toLowerCase() + "_" + category.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale());
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale(), validateElementVO.getStyle());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
@@ -1062,7 +1054,7 @@ public class PythonService {
String category = dressings.get(randomNum).getStyleCategory();
String categoryParam = validateElementVO.getModelSex().toLowerCase() + "_" + category.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale());
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale(), validateElementVO.getStyle());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
@@ -1098,7 +1090,7 @@ public class PythonService {
String category = element.getLevel2Type();
String categoryParam = validateElementVO.getModelSex().toLowerCase() + "_" + category.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale());
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale(), validateElementVO.getStyle());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
@@ -1122,7 +1114,7 @@ public class PythonService {
String category = dressings.get(randomNum).getStyleCategory();
String categoryParam = validateElementVO.getModelSex().toLowerCase() + "_" + category.toLowerCase();
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale());
List<String> recommentdUrlList = getSystemSketchByCategory(categoryParam, validateElementVO.getBrandId(), validateElementVO.getBrandScale(), validateElementVO.getStyle());
if (!CollectionUtils.isEmpty(recommentdUrlList)) {
String recommendSystemSketch = recommentdUrlList.get(0);
return coverSystemSketchUrlToDesignPythonItem(recommendSystemSketch, category, validateElementVO);
@@ -3962,7 +3954,30 @@ public class PythonService {
throw new BusinessException("design.interface.exception");
}
public List<String> getSystemSketchByCategory(String category, Long brandId, Double brandScale) {
public List<String> getSystemSketchByCategory(String category, Long brandId, Double brandScale,String style) {
//******3.1.2版本临时使用java推荐方案去解决style未使用的问题**********
try {
//使用新库attribute_retrieval_style表命名修改为elementVO.getModelSex().toLowerCase() + "_" + styleCategory.toLowerCase()比如female_skirt,与传入的category保持一致
Integer countByStyle = attributeRetrievalMapper.getCountByStyle(category, style);
//根据数量随机获取一个系统sketch
if (countByStyle > 0) {
//获取一个不大于countByStyle的随机整数
Integer randomNum = RandomUtils.nextInt(0, countByStyle);
//返回格式为 dress/0902000649.jpg
String oneSystemSketchRadom = attributeRetrievalMapper.getOneSystemSketchRadom(category, style,randomNum);
String imgName = oneSystemSketchRadom.split("/")[1];
//补齐正确格式aida-sys-image/images/male/tops/mens_test_5689.png
//裁切category前半部分
String sex = category.split("_")[0];
String realCategory = category.split("_")[1];
String path = "aida-sys-image/images/" + sex + "/" +realCategory +"/" +imgName;
return Arrays.asList(path);
}
} catch (Exception e) {
log.info("推荐失败:{}",e.getMessage());
throw new BusinessException("system.error");
}
//**********************end***********************************
AuthPrincipalVo userHolder = UserContext.getUserHolder();
OkHttpClient client = new OkHttpClient().newBuilder()

View File

@@ -105,6 +105,9 @@ public class DesignPythonItem {
public static List<String> BOTTOMS = Arrays.asList(
"Bottoms");
public static List<String> OTHERS = Arrays.asList(
"Others");
public static List<String> SYS_HAIRSTYLE_SHOES_BODY = Arrays.asList(
SysFileLevel2TypeEnum.HAIRSTYLE.getRealName(), SysFileLevel2TypeEnum.SHOES.getRealName(),
SysFileLevel2TypeEnum.EARRINGS.getRealName(), SysFileLevel2TypeEnum.BODY.getRealName());

View File

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

View File

@@ -82,7 +82,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Resource
private MinioUtil minioUtil;
private WorkspaceService workspaceService;
private final WorkspaceService workspaceService;
@Value("${minio.bucketName.collectionElement}")
private String collectionElement;
@@ -644,7 +644,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
if (result) {
throw new BusinessException("sketchBoards.designType.cannot.be.empty");
}
List<CollectionElement> sketchBoardElements = new ArrayList<>();
// 提取类型为COLLECTION的sketchBoard ID列表
List<Long> sketchBoardIds = designDTO.getSketchBoards().stream()
.filter(f -> f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
@@ -652,12 +652,12 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sketchBoardIds)) {
// 从数据库查询验证sketchBoard元素是否存在
List<CollectionElement> sketchBoardElements = collectionElementMapper.selectBatchIds(sketchBoardIds);
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);
}
@@ -675,7 +675,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys, idToMap));
List<CollectionElement> librarysToCollections = covertLibrarysToCollections(librarys, idToMap);
libraryCollectionElements.addAll(librarysToCollections);
sketchBoardElements.addAll(librarysToCollections);
}
}
@@ -691,9 +693,13 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
Map<Long, CollectionSketchDTO> idToMap = designDTO.getSketchBoards()
.stream()
.collect(Collectors.toMap(CollectionSketchDTO::getSketchBoardId, v -> v));
generateCollectionElements.addAll(covertGeneratesToCollections(generateDetailList, idToMap));
List<CollectionElement> generatesToCollections = covertGeneratesToCollections(generateDetailList, idToMap);
generateCollectionElements.addAll(generatesToCollections);
sketchBoardElements.addAll(generatesToCollections);
}
}
// 设置验证通过的sketchBoard元素到结果对象
elementVO.setSketchBoardElements(sketchBoardElements);
}
}
//校验marketingSketch
@@ -796,7 +802,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
// 设置女性模特的风格类型
if (Objects.nonNull(byId) && !StringUtils.isEmpty(byId.getLevel3Type()) && byId.getLevel2Type().equals("Female")) {
elementVO.setStyle(byId.getLevel3Type());
// elementVO.setStyle(byId.getLevel3Type());
}
LibraryModelPoint modelPoint = libraryModelPointService.getByRelationId(byId.getId(), designDTO.getModelType());
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint, 700, 320, byId.getUrl()));
@@ -821,6 +827,10 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
elementVO.setBrandScale(designDTO.getBrandScale()); // 设置品牌比例
}
//设置风格
String style = workspaceService.getStyleByProjectId(designDTO.getProjectId());
elementVO.setStyle(style);
// 返回验证结果对象
return elementVO;
}

View File

@@ -1456,7 +1456,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
response.setHighDesignUrl(designItem.getHighDesignUrl());
List<DesignItemDetail> filterDetail = designItemDetails.stream()
.filter(f -> OUTWEAR_DRESS_BLOUSE.contains(f.getType()) || SKIRT_TROUSERS.contains(f.getType())
|| TOPS.contains(f.getType()) || BOTTOMS.contains(f.getType()))
|| TOPS.contains(f.getType()) || BOTTOMS.contains(f.getType())|| OTHERS.contains(f.getType()))
.collect(Collectors.toList());
response.setClothes(CopyUtil.copyList(filterDetail, DesignItemClothesDetailVO.class, (o, d) -> {
d.setId(o.getId());

View File

@@ -867,6 +867,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
if (base64Data != null && !base64Data.isEmpty()) {
String resultPath = userId + "/product_image" + "/" + uuid;
String minioPath = minioUtil.base64UploadToPath("data:image/png;base64," + base64Data, userBucket, resultPath);
if (StringUtil.isNullOrEmpty(minioPath)){
log.warn("Google API调用成功但图片保存失败 for taskId: {}", taskId);
}
// 生成成功更新Redis状态和URL
GenerateResultVO successResultVO = new GenerateResultVO(taskId, null, minioPath, "Success");
redisUtil.addToString(key, new Gson().toJson(successResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
@@ -1495,9 +1498,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
GenerateResultVO successResultVO = new GenerateResultVO(taskId, null, imageUrl, "Success");
redisUtil.addToString(key, new Gson().toJson(successResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
// TODO: 处理积分扣除逻辑
} catch (Exception e) {
log.error("Doubao image generation failed for taskId: {}", taskId, e);
LambdaQueryWrapper<Account> select = new LambdaQueryWrapper<Account>().eq(Account::getId, userId).select(Account::getLanguage);

View File

@@ -898,6 +898,11 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
return null;
}
@Override
public String getStyleByProjectId(Long projectId) {
return workspaceMapper.getStyleByProjectId(projectId);
}
// 由于在数据库中表设计问题,目前只能通过路径来判断项目中是否存在某一个模特
public Boolean checkIfModelExistsInProject(String md5, Long projectId) {
QueryWrapper<CollectionElement> qw = new QueryWrapper<>();