TASK:模块化;

This commit is contained in:
shahaibo
2025-05-06 17:30:01 +08:00
parent a84fe12a28
commit 6d6768e6cb
5 changed files with 302 additions and 21 deletions

View File

@@ -5,14 +5,16 @@ import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.mapper.primary.entity.Collection;
import com.ai.da.mapper.secondary.AttributeRetrievalMapper;
import com.ai.da.model.dto.CollectionSketchDTO;
import com.ai.da.model.dto.DesignCollectionDTO;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.DesignProcess;
import com.ai.da.model.vo.ValidateElementVO;
import com.ai.da.python.PythonService;
import com.ai.da.python.vo.DesignPythonObjects;
import com.ai.da.service.CollectionElementService;
import com.ai.da.service.UserLikeGroupService;
import com.ai.da.service.UserLikeService;
import com.ai.da.service.WorkspaceService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -72,11 +74,14 @@ public class MyTaskScheduler {
private ProjectMapper projectMapper;
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private WorkspaceService workspaceService;
@Resource
private UserLikeGroupService userLikeGroupService;
@Resource
private ExportFileMapper exportFileMapper;
@Resource
private PortfolioMapper portfolioMapper;
// 定时任务,每十五天执行一次
// @Scheduled(cron = "0 0 0 ? * MON")
@@ -220,6 +225,8 @@ public class MyTaskScheduler {
@Resource
private MinioUtil minioUtil;
@Resource
private UserLikeService userLikeService;
public void clearMinio() {
List<CollectionElement> collectionElements = collectionElementMapper.selectDeleteList();
for (CollectionElement collectionElement : collectionElements) {
@@ -1337,6 +1344,7 @@ public class MyTaskScheduler {
@Transactional
public void projectDataCreate() {
// TODO:UserLikeGroup转project待完善
// QueryWrapper<UserLikeGroup> qw = new QueryWrapper<>();
// qw.lambda().ne(UserLikeGroup::getAccountId, -1);
// List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(qw);
@@ -1346,6 +1354,10 @@ public class MyTaskScheduler {
// project.setName(userLikeGroup.getName());
// project.setCreateTime(LocalDateTime.ofInstant(userLikeGroup.getCreateDate().toInstant(), ZoneId.systemDefault()));
// project.setUpdateTime(LocalDateTime.ofInstant(userLikeGroup.getUpdateDate().toInstant(), ZoneId.systemDefault()));
// project.setOriginal(userLikeGroup.getOriginal());
// project.setOriginalAccountId(userLikeGroup.getOriginalAccountId());
// project.setOriginalPortfolioId(userLikeGroup.getOriginalPortfolioId());
//
// QueryWrapper<Design> designQueryWrapper = new QueryWrapper<>();
// designQueryWrapper.lambda().eq(Design::getCollectionId, userLikeGroup.getCollectionId());
// Design design = designMapper.selectOne(designQueryWrapper);
@@ -1370,7 +1382,7 @@ public class MyTaskScheduler {
// }
// workspace.setIsLastIndex(0);
// workspace.setProjectId(project.getId());
//// workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
// workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
// if (!design.getSingleOverall().equals("overall")) {
// workspace.setPosition(design.getSwitchCategory());
// }
@@ -1388,11 +1400,13 @@ public class MyTaskScheduler {
// if (collection.getMoodTemplateId() != null) {
// CollectionElement collectionElement = collectionElementMapper.selectById(collection.getMoodTemplateId());
// collectionElement.setProjectId(userLikeGroup.getProjectId());
// collectionElement.setIsCompositeImage(1);
// collectionElementMapper.updateById(collectionElement);
// }
// userLikeGroup.setProjectId(project.getId());
// userLikeGroupMapper.updateById(userLikeGroup);
// }
// // toProductImage relight数据
// QueryWrapper<Project> projectQueryWrapper = new QueryWrapper<>();
// List<Project> projects = projectMapper.selectList(projectQueryWrapper);
// for (Project project : projects) {
@@ -1416,17 +1430,136 @@ public class MyTaskScheduler {
// }
// }
// }
QueryWrapper<ExportFile> exportFileQueryWrapper = new QueryWrapper<>();
exportFileQueryWrapper.lambda().ge(ExportFile::getId, 10);
exportFileQueryWrapper.lambda().le(ExportFile::getId, 86);
List<ExportFile> exportFiles = exportFileMapper.selectList(exportFileQueryWrapper);
for (ExportFile exportFile : exportFiles) {
Long userLikeGroupId = exportFile.getProjectId();
UserLikeGroup userLikeGroup = userLikeGroupMapper.selectById(userLikeGroupId);
if (Objects.nonNull(userLikeGroup)) {
exportFile.setProjectId(userLikeGroup.getProjectId());
exportFileMapper.updateById(exportFile);
// // 画布数据
// QueryWrapper<ExportFile> exportFileQueryWrapper = new QueryWrapper<>();
// exportFileQueryWrapper.lambda().ge(ExportFile::getId, 10);
// exportFileQueryWrapper.lambda().le(ExportFile::getId, 86);
// List<ExportFile> exportFiles = exportFileMapper.selectList(exportFileQueryWrapper);
// for (ExportFile exportFile : exportFiles) {
// Long userLikeGroupId = exportFile.getProjectId();
// UserLikeGroup userLikeGroup = userLikeGroupMapper.selectById(userLikeGroupId);
// if (Objects.nonNull(userLikeGroup)) {
// exportFile.setProjectId(userLikeGroup.getProjectId());
// exportFileMapper.updateById(exportFile);
// }
// }
// TODO:作品关联数据转json数据
// 查询作品
QueryWrapper<Portfolio> portfolioQueryWrapper = new QueryWrapper<>();
portfolioQueryWrapper.lambda().eq(Portfolio::getOpenSource, 1);
List<Portfolio> portfolioList = portfolioMapper.selectList(portfolioQueryWrapper);
for (Portfolio portfolio : portfolioList) {
if (portfolio.getCollectionId() != null) {
QueryWrapper<UserLikeGroup> userLikeGroupQueryWrapper = new QueryWrapper<>();
userLikeGroupQueryWrapper.lambda().eq(UserLikeGroup::getCollectionId, portfolio.getCollectionId());
UserLikeGroup userLikeGroup = userLikeGroupMapper.selectOne(userLikeGroupQueryWrapper);
if (Objects.nonNull(userLikeGroup)) {
// 副本存储对象
ProjectSnapshot projectSnapshot = new ProjectSnapshot();
// Long projectId = userLikeGroup.getProjectId();
// Project project = projectMapper.selectById(projectId);
// 根据项目ID获取项目设置
Long collectionId = userLikeGroup.getCollectionId();
QueryWrapper<Design> designQueryWrapper = new QueryWrapper<>();
designQueryWrapper.lambda().eq(Design::getCollectionId, collectionId);
Design design = designMapper.selectOne(designQueryWrapper);
// Collection collection = collectionMapper.selectById(collectionId);
Project project = new Project();
Workspace workspace = new Workspace();
workspace.setAgeGroup("Adult");
if (null != design.getTemplateId()) {
project.setProcess(DesignProcess.SERIES_DESIGN.getValue());
workspace.setPosition("Overall");
if (design.getModelType().equals("System")) {
SysFile sysFile = sysFileMapper.selectById(design.getTemplateId());
if (sysFile.getLevel2Type().equals("Male")) {
workspace.setSex("Male");
workspace.setMannequinMaleId(design.getTemplateId());
workspace.setMannequinMaleType("System");
}else {
workspace.setSex("Female");
workspace.setMannequinFemaleId(design.getTemplateId());
workspace.setMannequinFemaleType("System");
}
}else {
Library library = libraryMapper.selectById(design.getTemplateId());
if (library.getLevel2Type().equals("Male")) {
workspace.setSex("Male");
workspace.setMannequinMaleId(design.getTemplateId());
workspace.setMannequinMaleType("Library");
}else {
workspace.setSex("Female");
workspace.setMannequinFemaleId(design.getTemplateId());
workspace.setMannequinFemaleType("Library");
}
}
}else {
project.setProcess(DesignProcess.SINGLE_DESIGN.getValue());
workspace.setPosition(design.getSwitchCategory());
}
workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
project.setName(userLikeGroup.getName());
project.setOriginal(portfolio.getOriginal());
project.setOriginalPortfolioId(portfolio.getOriginalPortfolioId());
project.setOriginalAccountId(portfolio.getOriginalAccountId());
projectSnapshot.setProject(project);
projectSnapshot.setWorkspace(workspace);
List<CollectionElement> collectionElementListOld = collectionElementService.getByCollectionId(collectionId);
projectSnapshot.setCollectionElementList(collectionElementListOld);
projectSnapshot.setUserLikeGroup(userLikeGroup);
List<UserLike> userLikeList = userLikeService.getByUserLikeGroupId(userLikeGroup.getId());
List<UserLikeSnapshot> list = new ArrayList<>();
for (UserLike userLike : userLikeList) {
UserLikeSnapshot userLikeSnapshot = CopyUtil.copyObject(userLike, UserLikeSnapshot.class);
Long designOutfitIdOld = userLike.getDesignOutfitId();
TDesignPythonOutfit designPythonOutfit = designPythonOutfitMapper.selectById(designOutfitIdOld);
Long designItemIdOld = userLike.getDesignItemId();
DesignItem designItemOld = designItemMapper.selectById(designItemIdOld);
userLikeSnapshot.setDesignItem(designItemOld);
userLikeSnapshot.setDesignPythonOutfit(designPythonOutfit);
QueryWrapper<TDesignPythonOutfitDetail> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, designOutfitIdOld);
List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetailList = designPythonOutfitDetailMapper.selectList(qw);
userLikeSnapshot.setTDesignPythonOutfitDetailList(tDesignPythonOutfitDetailList);
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemIdOld);
List<DesignItemDetail> designItemDetailListOld = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
List<DesignItemDetailSnapshot> designItemDetailSnapshotList = new ArrayList<>();
for (DesignItemDetail designItemDetailOld : designItemDetailListOld) {
DesignItemDetailSnapshot designItemDetailSnapshot = CopyUtil.copyObject(designItemDetailOld, DesignItemDetailSnapshot.class);
Long designItemDetailIdOld = designItemDetailOld.getId();
QueryWrapper<DesignItemDetailPrint> designItemDetailPrintQueryWrapper = new QueryWrapper<>();
designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetailIdOld);
List<DesignItemDetailPrint> designItemDetailPrintList = designItemDetailPrintMapper.selectList(designItemDetailPrintQueryWrapper);
designItemDetailSnapshot.setDesignItemDetailPrintList(designItemDetailPrintList);
designItemDetailSnapshotList.add(designItemDetailSnapshot);
}
userLikeSnapshot.setDesignItemDetailList(designItemDetailSnapshotList);
list.add(userLikeSnapshot);
}
projectSnapshot.setUserLikeList(list);
String snapshotJson = JSONObject.toJSONString(projectSnapshot);
portfolio.setSnapshot(snapshotJson);
portfolioMapper.updateById(portfolio);
}
}
}
}
}

View File

@@ -2,8 +2,12 @@ package com.ai.da.common.config;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.primary.ThreeDDetailMapper;
import com.ai.da.mapper.primary.ThreeDLayoutMapper;
import com.ai.da.mapper.primary.ThreeDPatternLayoutMapper;
import com.ai.da.mapper.primary.ThreeDSimpleMapper;
import com.ai.da.mapper.primary.entity.ThreeDDetail;
import com.ai.da.mapper.primary.entity.ThreeDLayout;
import com.ai.da.mapper.primary.entity.ThreeDPatternLayout;
import com.ai.da.mapper.primary.entity.ThreeDSimple;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
@@ -14,7 +18,12 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Slf4j
@Component
@@ -26,9 +35,133 @@ public class ThreeDSave {
private ThreeDSimpleMapper threeDSimpleMapper;
@Resource
private MinioUtil minioUtil;
@Resource
private ThreeDLayoutMapper threeDLayoutMapper;
@Resource
private ThreeDPatternLayoutMapper threeDPatternLayoutMapper;
@PostConstruct
public void test() {
// minioSave();
// frontBackDataCreate();
// patternDataCreate();
}
private void patternDataCreate() {
QueryWrapper<ThreeDSimple> qw = new QueryWrapper<>();
qw.lambda().eq(ThreeDSimple::getGender, "female");
qw.lambda().ne(ThreeDSimple::getId, 1);
List<ThreeDSimple> threeDSimpleList = threeDSimpleMapper.selectList(qw);
List<Integer> numbers = new ArrayList<>();
String patternPath = "C:\\workspace\\3D\\3D虚拟 1-7\\6.版文件、dxf文件\\女装系列(1)\\女装系列\\56款打版截图";
File directory = new File(patternPath);
if (directory.exists() && directory.isDirectory()) {
// 获取目录下的所有文件名,并建立编号 -> 文件名的映射
Map<Integer, String> fileMap = Arrays.stream(directory.listFiles())
.filter(File::isFile) // 只获取文件
.map(File::getName) // 获取文件名
.collect(Collectors.toMap(
name -> {
Matcher matcher = Pattern.compile("^\\d+").matcher(name);
return matcher.find() ? Integer.parseInt(matcher.group()) : -1;
},
name -> name,
(existing, replacement) -> existing // 处理重复情况,保留原有值
));
for (ThreeDSimple threeDSimple : threeDSimpleList) {
String name = threeDSimple.getName();
Pattern pattern = Pattern.compile("^\\d+"); // 匹配开头的数字
Matcher matcher = pattern.matcher(name);
if (matcher.find()) {
int number = Integer.parseInt(matcher.group());
numbers.add(number);
// 匹配对应文件夹,并获取文件
if (fileMap.containsKey(number)) {
String matchedFolder = fileMap.get(number);
File folder = new File(directory, matchedFolder);
ThreeDPatternLayout threeDPatternLayout = new ThreeDPatternLayout();
threeDPatternLayout.setThreeDSimpleId(threeDSimple.getId());
threeDPatternLayout.setName(matchedFolder);
String minioUrl = "aida-threed/female/pattern-layout/" + matchedFolder;
minioUtil.upload(minioUrl, folder);
threeDPatternLayout.setUrl(minioUrl);
// threeDPatternLayoutMapper.insert(threeDPatternLayout);
}
}
}
System.out.println("文件编号映射:" + fileMap);
}
}
private void frontBackDataCreate() {
QueryWrapper<ThreeDSimple> qw = new QueryWrapper<>();
qw.lambda().eq(ThreeDSimple::getGender, "female");
// qw.lambda().ne(ThreeDSimple::getId, 1);
List<ThreeDSimple> threeDSimpleList = threeDSimpleMapper.selectList(qw);
List<Integer> numbers = new ArrayList<>();
// 文件夹名列表
String path = "C:\\workspace\\3D\\3D虚拟 1-7\\3D服装真反面整理\\female"; // 目标路径
File directory = new File(path);
if (directory.exists() && directory.isDirectory()) {
// 获取文件夹名列表,并建立编号 -> 文件夹名的映射
Map<Integer, String> folderMap = Arrays.stream(directory.listFiles())
.filter(File::isDirectory)
.map(File::getName)
.collect(Collectors.toMap(
name -> {
Matcher matcher = Pattern.compile("^\\d+").matcher(name);
return matcher.find() ? Integer.parseInt(matcher.group()) : -1;
},
name -> name,
(existing, replacement) -> existing // 处理重复情况,保留原有值
));
System.out.println("文件夹编号映射:" + folderMap);
for (ThreeDSimple threeDSimple : threeDSimpleList) {
String name = threeDSimple.getName();
Pattern pattern = Pattern.compile("^\\d+"); // 匹配开头的数字
Matcher matcher = pattern.matcher(name);
if (matcher.find()) {
int number = Integer.parseInt(matcher.group());
numbers.add(number);
// 匹配对应文件夹,并获取文件
if (folderMap.containsKey(number)) {
String matchedFolder = folderMap.get(number);
File folder = new File(directory, matchedFolder);
if (folder.exists() && folder.isDirectory()) {
for (File file : folder.listFiles()) {
String fileName = file.getName(); // 去掉后缀
ThreeDLayout threeDLayout = new ThreeDLayout();
threeDLayout.setGender("female");
threeDLayout.setThreeDSimpleId(threeDSimple.getId());
threeDLayout.setName(file.getName());
if (fileName.startsWith("")) {
threeDLayout.setType("front");
}else if (fileName.startsWith("")) {
threeDLayout.setType("back");
}
String minioUrl = "aida-threed/female/layout/" + folderMap.get(number) + " " + file.getName();
minioUtil.upload(minioUrl, file);
threeDLayout.setUrl(minioUrl);
// threeDLayoutMapper.insert(threeDLayout);
}
}
}
}
}
System.out.println(numbers);
} else {
System.out.println("路径不存在或不是文件夹");
}
}
private void minioSave() {
@@ -70,7 +203,7 @@ public class ThreeDSave {
threeDDetail.setSizeType(prefix);
threeDDetail.setSize(suffix);
threeDDetail.setUrl(url);
threeDDetailMapper.insert(threeDDetail);
// threeDDetailMapper.insert(threeDDetail);
minioUtil.upload(url, file);
QueryWrapper<ThreeDSimple> qw = new QueryWrapper<>();
@@ -102,7 +235,7 @@ public class ThreeDSave {
} else {
System.out.println("GLB 文件夹不存在: " + glbPath);
}
threeDSimpleMapper.insert(threeDSimple);
// threeDSimpleMapper.insert(threeDSimple);
threeDDetail.setThreeDSimpleId(threeDSimple.getId());
threeDDetailMapper.updateById(threeDDetail);
}else {

View File

@@ -18,7 +18,7 @@ public class ProductImageAttribute implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
// private String imgName;
private String imgUrl;
private String length;
private String sleeveLength;
private String sleeveShape;
@@ -34,4 +34,7 @@ public class ProductImageAttribute implements Serializable {
private String style;
private Long libraryId;
private String gender;
private String category;
}

View File

@@ -3986,7 +3986,7 @@ public class PythonService {
//关闭FastJson的引用检测 防止出现$ref 现象
Map<String, Object> map = new HashMap<>();
map.put("image_url", url);
map.put("is_brand_dna", Boolean.TRUE);
map.put("is_brand_dna", Boolean.FALSE);
log.info("bright请求python 参数:####{}", map);
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
log.info(param);

View File

@@ -73,9 +73,21 @@ public class ProductImageServiceImpl implements ProductImageService {
JSONArray data = result.getJSONArray("data");
for (int i = 0; i < data.size(); i++) {
JSONObject obj = data.getJSONObject(i);
JSONObject attribute = obj.getJSONObject("attribute");
AttributeRecognitionJSON attrJSON = attribute.toJavaObject(AttributeRecognitionJSON.class);
ProductImageAttribute attr = toAttrDict(attrJSON);
String gender = library.getLevel2Type();
String category = null;
if (gender.equals("Female")) {
category = obj.getString("category_female");
}else if (gender.equals("Male")) {
category = obj.getString("category_male");
}
String imgUrl = obj.getString("img_url");
// JSONObject attribute = obj.getJSONObject("attribute");
// AttributeRecognitionJSON attrJSON = attribute.toJavaObject(AttributeRecognitionJSON.class);
// ProductImageAttribute attr = toAttrDict(attrJSON);
ProductImageAttribute attr = new ProductImageAttribute();
attr.setGender(gender);
attr.setCategory(category);
attr.setImgUrl(imgUrl);
attr.setLibraryId(libraryId);
productImageAttributeMapper.insert(attr);
}