TASK: 数据迁移拆分;

This commit is contained in:
shahaibo
2025-06-27 09:59:08 +08:00
parent a7347c9dc0
commit b01f5f59d1
3 changed files with 174 additions and 145 deletions

View File

@@ -1418,150 +1418,22 @@ public class MyTaskScheduler {
@Transactional
public void projectDataCreate() {
// UserLikeGroup转project
// QueryWrapper<UserLikeGroup> qw = new QueryWrapper<>();
// qw.lambda().ne(UserLikeGroup::getAccountId, -1);
// List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(qw);
// for (UserLikeGroup userLikeGroup : userLikeGroups) {
// Project project = new Project();
// project.setAccountId(userLikeGroup.getAccountId());
// 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);
// if (Objects.isNull(design)) {
// System.out.println(userLikeGroup.getCollectionId());
// continue;
// }
// if (design.getSingleOverall().equals("overall")) {
// project.setProcess(DesignProcess.SERIES_DESIGN.name());
// }else {
// project.setProcess(DesignProcess.SINGLE_DESIGN.name());
// }
// projectMapper.insert(project);
// Long accountId = userLikeGroup.getAccountId();
// QueryWrapper<Workspace> workspaceQueryWrapper = new QueryWrapper<>();
// workspaceQueryWrapper.lambda().eq(Workspace::getAccountId, accountId);
// workspaceQueryWrapper.lambda().eq(Workspace::getIsLastIndex, 1);
// Workspace workspace = workspaceMapper.selectOne(workspaceQueryWrapper);
// if (Objects.isNull(workspace)) {
// System.out.println(accountId);
// continue;
// }
// workspace.setIsLastIndex(0);
// workspace.setProjectId(project.getId());
// workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
// if (!design.getSingleOverall().equals("overall")) {
// workspace.setPosition(design.getSwitchCategory());
// }
//
// workspace.setId(null);
// workspaceMapper.insert(workspace);
//
// QueryWrapper<CollectionElement> collectionElementQueryWrapper = new QueryWrapper<>();
// collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, userLikeGroup.getCollectionId());
// List<CollectionElement> collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper);
// for (CollectionElement collectionElement : collectionElements) {
// collectionElement.setProjectId(project.getId());
// collectionElementMapper.updateById(collectionElement);
// }
// Collection collection = collectionMapper.selectById(userLikeGroup.getCollectionId());
// if (collection.getMoodTemplateId() != null) {
// CollectionElement collectionElement = collectionElementMapper.selectById(collection.getMoodTemplateId());
// collectionElement.setProjectId(userLikeGroup.getProjectId());
// collectionElement.setIsCompositeImage(1);
// collectionElementMapper.updateById(collectionElement);
// }
//
// if (design.getModelType().equals("System")) {
// SysFile sysFile = sysFileMapper.selectById(design.getTemplateId());
//
// CollectionElement collectionElement = new CollectionElement();
// collectionElement.setAccountId(design.getAccountId());
// collectionElement.setProjectId(project.getId());
// collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
//// collectionElement.setLevel2Type(board.getLevel2Type());
// collectionElement.setName(sysFile.getName());
// collectionElement.setUrl(sysFile.getUrl());
//// collectionElement.setHasPin(board.getIsPin());
// 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);
// }else {
// Library library = libraryMapper.selectById(design.getTemplateId());
// CollectionElement collectionElement = new CollectionElement();
// collectionElement.setAccountId(design.getAccountId());
// collectionElement.setProjectId(project.getId());
// collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
//// collectionElement.setLevel2Type(board.getLevel2Type());
// collectionElement.setName(library.getName());
// collectionElement.setUrl(library.getUrl());
//// collectionElement.setHasPin(board.getIsPin());
// collectionElement.setMd5(library.getMd5());
// collectionElement.setCreateDate(new Date());
// collectionElement.setHasPin((byte) 0);
// collectionElementMapper.insert(collectionElement);
// CollectionElementRelModel collectionElementRelModel = new CollectionElementRelModel();
// collectionElementRelModel.setCollectionElementId(collectionElement.getId());
// collectionElementRelModel.setRelationId(library.getId());
// collectionElementRelModel.setRelationType("Library");
// collectionElementRelModelMapper.insert(collectionElementRelModel);
// }
//
// userLikeGroup.setProjectId(project.getId());
// userLikeGroupMapper.updateById(userLikeGroup);
// }
// // 必须先完成project数据新增后再执行 toProductImage relight数据关联project
// QueryWrapper<Project> projectQueryWrapper = new QueryWrapper<>();
// List<Project> projects = projectMapper.selectList(projectQueryWrapper);
// for (Project project : projects) {
// UserLikeGroup userLikeGroup = userLikeGroupService.getByProjectId(project.getId());
// if (Objects.nonNull(userLikeGroup)) {
// Long userLikeGroupId = userLikeGroup.getId();
// QueryWrapper<ToProductImageRecord> toProductImageRecordQueryWrapper = new QueryWrapper<>();
// toProductImageRecordQueryWrapper.lambda().eq(ToProductImageRecord::getUserLikeGroupId, userLikeGroupId);
// List<ToProductImageRecord> toProductImageRecords = toProductImageRecordMapper.selectList(toProductImageRecordQueryWrapper);
// for (ToProductImageRecord toProductImageRecord : toProductImageRecords) {
// toProductImageRecord.setProjectId(project.getId());
// toProductImageRecordMapper.updateById(toProductImageRecord);
// }
//
// QueryWrapper<ToProductImageResult> toProductImageResultQueryWrapper = new QueryWrapper<>();
// toProductImageResultQueryWrapper.lambda().eq(ToProductImageResult::getUserLikeGroupId, userLikeGroupId);
// List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(toProductImageResultQueryWrapper);
// for (ToProductImageResult toProductImageResult : toProductImageResults) {
// toProductImageResult.setProjectId(project.getId());
// toProductImageResultMapper.updateById(toProductImageResult);
// }
// }
// }
// // 画布数据
// 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);
// }
// }
userLikeGroupConvertProject();
// 必须先完成project数据新增后再执行 toProductImage relight数据关联project
toProductRelightRelationProject();
// 画布数据
canvasData();
// 作品关联数据转json数据
// 作品关联projectId
portfolioData();
}
private void portfolioData() {
QueryWrapper<Portfolio> updateQueryWrapper = new QueryWrapper<>();
updateQueryWrapper.lambda().eq(Portfolio::getOpenSource, 1);
List<Portfolio> portfolioListUpdate = portfolioMapper.selectList(updateQueryWrapper);
@@ -1692,6 +1564,153 @@ public class MyTaskScheduler {
}
}
}
}
private void canvasData() {
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);
}
}
}
private void toProductRelightRelationProject() {
QueryWrapper<Project> projectQueryWrapper = new QueryWrapper<>();
List<Project> projects = projectMapper.selectList(projectQueryWrapper);
for (Project project : projects) {
UserLikeGroup userLikeGroup = userLikeGroupService.getByProjectId(project.getId());
if (Objects.nonNull(userLikeGroup)) {
Long userLikeGroupId = userLikeGroup.getId();
QueryWrapper<ToProductImageRecord> toProductImageRecordQueryWrapper = new QueryWrapper<>();
toProductImageRecordQueryWrapper.lambda().eq(ToProductImageRecord::getUserLikeGroupId, userLikeGroupId);
List<ToProductImageRecord> toProductImageRecords = toProductImageRecordMapper.selectList(toProductImageRecordQueryWrapper);
for (ToProductImageRecord toProductImageRecord : toProductImageRecords) {
toProductImageRecord.setProjectId(project.getId());
toProductImageRecordMapper.updateById(toProductImageRecord);
}
QueryWrapper<ToProductImageResult> toProductImageResultQueryWrapper = new QueryWrapper<>();
toProductImageResultQueryWrapper.lambda().eq(ToProductImageResult::getUserLikeGroupId, userLikeGroupId);
List<ToProductImageResult> toProductImageResults = toProductImageResultMapper.selectList(toProductImageResultQueryWrapper);
for (ToProductImageResult toProductImageResult : toProductImageResults) {
toProductImageResult.setProjectId(project.getId());
toProductImageResultMapper.updateById(toProductImageResult);
}
}
}
}
private void userLikeGroupConvertProject() {
QueryWrapper<UserLikeGroup> qw = new QueryWrapper<>();
qw.lambda().ne(UserLikeGroup::getAccountId, -1);
List<UserLikeGroup> userLikeGroups = userLikeGroupMapper.selectList(qw);
for (UserLikeGroup userLikeGroup : userLikeGroups) {
Project project = new Project();
project.setAccountId(userLikeGroup.getAccountId());
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);
if (Objects.isNull(design)) {
System.out.println(userLikeGroup.getCollectionId());
continue;
}
if (design.getSingleOverall().equals("overall")) {
project.setProcess(DesignProcess.SERIES_DESIGN.name());
}else {
project.setProcess(DesignProcess.SINGLE_DESIGN.name());
}
projectMapper.insert(project);
Long accountId = userLikeGroup.getAccountId();
QueryWrapper<Workspace> workspaceQueryWrapper = new QueryWrapper<>();
workspaceQueryWrapper.lambda().eq(Workspace::getAccountId, accountId);
workspaceQueryWrapper.lambda().eq(Workspace::getIsLastIndex, 1);
Workspace workspace = workspaceMapper.selectOne(workspaceQueryWrapper);
if (Objects.isNull(workspace)) {
System.out.println(accountId);
continue;
}
workspace.setIsLastIndex(0);
workspace.setProjectId(project.getId());
workspace.setSystemDesignerPercentage(design.getSystemScale().multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).intValueExact());
if (!design.getSingleOverall().equals("overall")) {
workspace.setPosition(design.getSwitchCategory());
}
workspace.setId(null);
workspaceMapper.insert(workspace);
QueryWrapper<CollectionElement> collectionElementQueryWrapper = new QueryWrapper<>();
collectionElementQueryWrapper.lambda().eq(CollectionElement::getCollectionId, userLikeGroup.getCollectionId());
List<CollectionElement> collectionElements = collectionElementMapper.selectList(collectionElementQueryWrapper);
for (CollectionElement collectionElement : collectionElements) {
collectionElement.setProjectId(project.getId());
collectionElementMapper.updateById(collectionElement);
}
Collection collection = collectionMapper.selectById(userLikeGroup.getCollectionId());
if (collection.getMoodTemplateId() != null) {
CollectionElement collectionElement = collectionElementMapper.selectById(collection.getMoodTemplateId());
collectionElement.setProjectId(userLikeGroup.getProjectId());
collectionElement.setIsCompositeImage(1);
collectionElementMapper.updateById(collectionElement);
}
if (design.getModelType().equals("System")) {
SysFile sysFile = sysFileMapper.selectById(design.getTemplateId());
CollectionElement collectionElement = new CollectionElement();
collectionElement.setAccountId(design.getAccountId());
collectionElement.setProjectId(project.getId());
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
// collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setName(sysFile.getName());
collectionElement.setUrl(sysFile.getUrl());
// collectionElement.setHasPin(board.getIsPin());
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);
}else {
Library library = libraryMapper.selectById(design.getTemplateId());
CollectionElement collectionElement = new CollectionElement();
collectionElement.setAccountId(design.getAccountId());
collectionElement.setProjectId(project.getId());
collectionElement.setLevel1Type(CollectionLevel1TypeEnum.MODEL.getRealName());
// collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement.setName(library.getName());
collectionElement.setUrl(library.getUrl());
// collectionElement.setHasPin(board.getIsPin());
collectionElement.setMd5(library.getMd5());
collectionElement.setCreateDate(new Date());
collectionElement.setHasPin((byte) 0);
collectionElementMapper.insert(collectionElement);
CollectionElementRelModel collectionElementRelModel = new CollectionElementRelModel();
collectionElementRelModel.setCollectionElementId(collectionElement.getId());
collectionElementRelModel.setRelationId(library.getId());
collectionElementRelModel.setRelationType("Library");
collectionElementRelModelMapper.insert(collectionElementRelModel);
}
userLikeGroup.setProjectId(project.getId());
userLikeGroupMapper.updateById(userLikeGroup);
}
}
}

View File

@@ -3,6 +3,7 @@ package com.ai.da.mapper.primary.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@@ -21,17 +22,24 @@ public class ChatMessage implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty("项目ID")
private Long projectId;
@ApiModelProperty("角色system/user")
private String role;
@ApiModelProperty("排序")
private Integer seq;
@ApiModelProperty("内容")
private String content;
@ApiModelProperty("用户ID")
private Long accountId;
@ApiModelProperty("0对话内容1颜色2图片")
private Integer isImage;
@ApiModelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@@ -2250,6 +2250,12 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
return batchTaskId;
} else if (cloudTaskDTO.getBuildType().equals(BuildType.POSE_TRANSFORM.getValue())) {
Boolean preDeduction = creditsService.creditsPreDeduction(CreditsEventsEnum.POSE_TRANSFORMATION, cloudTaskDTO.getNums());
if (!preDeduction) {
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
}
Long projectId = cloudTaskDTO.getProjectId();
AuthPrincipalVo userHolder = UserContext.getUserHolder();
if (null == projectId) {
@@ -2283,10 +2289,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
cloudTask.setStatus(0);
cloudTaskMapper.insert(cloudTask);
Boolean preDeduction = creditsService.creditsPreDeduction(CreditsEventsEnum.POSE_TRANSFORMATION, cloudTaskDTO.getNums());
if (!preDeduction) {
throw new BusinessException("Your remaining credits are insufficient for this generation. Please recharge.", ResultEnum.WARNING.getCode());
}
List<PoseTransformBatchDTO> poseTransformList = cloudTaskDTO.getPoseTransform();
if (CollectionUtil.isNotEmpty(poseTransformList)) {
for (PoseTransformBatchDTO poseTransformBatchDTO : poseTransformList) {