Merge branch 'dev/dev_xp' into dev/dev

This commit is contained in:
2025-04-01 17:16:27 +08:00
6 changed files with 116 additions and 24 deletions

View File

@@ -203,4 +203,10 @@ public class LibraryController {
return Response.success(true);
}
@ApiOperation(value = "将系统模特添加到个人library")
@PostMapping("addSysModelToLib")
public Response<Long> addSysModelToLib(@ApiParam("系统模特id") @RequestPart("sysModelId")long sysModelId){
return Response.success(libraryService.addSysModelToLib(sysModelId));
}
}

View File

@@ -62,4 +62,10 @@ public class LibraryModelPointDTO implements Serializable {
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
private String timeZone;
@ApiModelProperty("模特路径 全路径即可")
private String modelPath;
@ApiModelProperty("是否覆盖保存还是另存为 true -> 保存false -> 另存为")
private Boolean isCovered;
}

View File

@@ -88,4 +88,6 @@ public interface LibraryService extends IService<Library> {
void deleteTrialData(Long id);
void moveLibraryDate() throws ParseException;
Long addSysModelToLib(long sysModelId);
}

View File

@@ -1070,7 +1070,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
model = libraryService.getById(proportionDTO.getId());
String url = model.getUrl();
name = url.substring(url.indexOf("/") + 1, url.lastIndexOf("/")) + "/" + uuid;
gender = model.getLevel2Type();
// gender = model.getLevel2Type();
}else {
SysFileVO sysModel = sysFileService.getById(proportionDTO.getId());
gender = sysModel.getLevel2Type();
@@ -1078,9 +1078,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
// 只需要将结果存入library
String modifiedModel = pythonService.modifyModelProportion(proportionDTO.getModelPath(), proportionDTO.getStretch(), name, proportionDTO.getTop(), proportionDTO.getBottom());
List<Integer> imagesWidthAndHeight = minioUtil.getImagesWidthAndHeight(modifiedModel);
// List<Integer> imagesWidthAndHeight = minioUtil.getImagesWidthAndHeight(modifiedModel);
// 存储修改后的模特到个人library
/*// 存储修改后的模特到个人library
model = new Library();
model.setAccountId(accountId);
model.setLevel1Type(LibraryLevel1TypeEnum.MODELS.getRealName());
@@ -1091,9 +1091,9 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
model.setWidth(imagesWidthAndHeight.get(0));
model.setHigh(imagesWidthAndHeight.get(1));
model.setCreateDate(new Date());
libraryService.save(model);
libraryService.save(model);*/
// 新建模特点位信息
/* // 新建模特点位信息
LibraryModelPoint libraryModelPoint = new LibraryModelPoint();
libraryModelPoint.setModelType("Library");
libraryModelPoint.setRelationId(model.getId());
@@ -1104,7 +1104,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
libraryModelPoint.setHandLeft(Arrays.toString(proportionDTO.getHandLeft()));
libraryModelPoint.setHandRight(Arrays.toString(proportionDTO.getHandRight()));
libraryModelPoint.setCreateDate(new Date());
libraryModelPointService.save(libraryModelPoint);
libraryModelPointService.save(libraryModelPoint);*/
return minioUtil.getPreSignedUrl(modifiedModel, CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
}

View File

@@ -5,12 +5,13 @@ import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.enums.SingleOverallEnum;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.primary.LibraryModelPointMapper;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.LibraryModelPointDTO;
import com.ai.da.model.dto.ModelsDotDTO;
import com.ai.da.model.enums.ModelType;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.LibraryModelPointVO;
import com.ai.da.python.PythonService;
import com.ai.da.python.vo.DesignPythonObjects;
@@ -21,13 +22,15 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -48,21 +51,86 @@ public class LibraryModelPointServiceImpl extends ServiceImpl<LibraryModelPointM
private PythonService pythonService;
@Resource
private DesignService designService;
@Autowired
private MinioUtil minioUtil;
@Override
public LibraryModelPointVO saveOrEditTemplatePoint(LibraryModelPointDTO libraryModelPointDTO) {
// Library library = libraryService.getById(libraryModelPointDTO.getLibraryId());
// Assert.notNull(library,"library does not exist!");
LibraryModelPointVO libraryModelPointVO = CopyUtil.copyObject(libraryModelPointDTO, LibraryModelPointVO.class);
if (Objects.isNull(libraryModelPointDTO.getTemplateId())) {
//新增
// 从url中截取出的模特minio地址
String targetPath = null;
// 标志是否有更改过模特比例
boolean flag = false;
// 只有修改了模特后才传modelPath字段
if (!StringUtil.isNullOrEmpty(libraryModelPointDTO.getModelPath())){
flag = true;
String url = libraryModelPointDTO.getModelPath();
// 找到路径的起始位置(从"://"之后查找第一个"/"
int pathStartIndex = url.indexOf("/", url.indexOf("://") + 3);
// 找到查询参数的起始位置("?" 的位置)
int queryStartIndex = url.indexOf("?");
// 截取目标部分
targetPath = url.substring(pathStartIndex + 1, queryStartIndex);
}
// 不管是保存还是另存为都需要传模特的libraryId
Library libModel = libraryService.getById(libraryModelPointDTO.getLibraryId());
if (Objects.isNull(libModel)){
throw new BusinessException("model.not.found");
}
if (libraryModelPointDTO.getIsCovered()){
// 覆盖保存,即更新原有数据(点位数据和模特图片)
LibraryModelPoint modelPoint = getById(libraryModelPointDTO.getTemplateId());
if (Objects.isNull(modelPoint)) {
throw new BusinessException("modelPoint.not.found");
}
// 更新点位信息
modelPoint = resolvePoint(libraryModelPointDTO);
modelPoint.setUpdateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
modelPoint.setId(libraryModelPointDTO.getTemplateId());
updateById(modelPoint);
libraryModelPointVO.setTemplateId(modelPoint.getId());
// 更新模特图片
if (flag){
libModel.setUrl(targetPath);
libModel.setMd5(MD5Utils.encryptFile(targetPath, false));
List<Integer> imagesWidthAndHeight = minioUtil.getImagesWidthAndHeight(targetPath);
libModel.setWidth(imagesWidthAndHeight.get(0));
libModel.setHigh(imagesWidthAndHeight.get(1));
libModel.setUpdateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
libraryService.updateById(libModel);
}
}else {
// 不覆盖,即另存为
// 新增模特library信息
if (flag){
Library saveAsModel = new Library();
saveAsModel.setAccountId(libModel.getAccountId());
saveAsModel.setLevel1Type(libModel.getLevel1Type());
saveAsModel.setLevel2Type(libModel.getLevel2Type());
saveAsModel.setName(DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD));
saveAsModel.setUrl(targetPath);
saveAsModel.setMd5(MD5Utils.encryptFile(targetPath, false));
List<Integer> imagesWidthAndHeight = minioUtil.getImagesWidthAndHeight(targetPath);
saveAsModel.setWidth(imagesWidthAndHeight.get(0));
saveAsModel.setHigh(imagesWidthAndHeight.get(1));
saveAsModel.setCreateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
libraryService.save(saveAsModel);
// 更新新的模特在library中的id,用于后面新建模特点位信息用
libraryModelPointDTO.setLibraryId(saveAsModel.getId());
}
// 新增模特点位信息
LibraryModelPoint libraryModelPoint = resolvePoint(libraryModelPointDTO);
libraryModelPoint.setCreateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
save(libraryModelPoint);
libraryModelPointVO.setTemplateId(libraryModelPoint.getId());
} else {
//编辑
if (!StringUtils.isEmpty(libraryModelPointDTO.getModelSex())) {
}
//编辑
/*if (!StringUtils.isEmpty(libraryModelPointDTO.getModelSex())) {
Library byId = libraryService.getById(libraryModelPointDTO.getLibraryId());
if (!byId.getLevel2Type().equals(libraryModelPointDTO.getModelSex())) {
if (byId.getLevel2Type().equals(Sex.FEMALE.getValue())) {
@@ -73,17 +141,7 @@ public class LibraryModelPointServiceImpl extends ServiceImpl<LibraryModelPointM
byId.setLevel2Type(libraryModelPointDTO.getModelSex());
libraryService.updateById(byId);
}
}
LibraryModelPoint modelPoint = getById(libraryModelPointDTO.getTemplateId());
if (Objects.isNull(modelPoint)) {
throw new BusinessException("modelPoint.not.found");
}
modelPoint = resolvePoint(libraryModelPointDTO);
modelPoint.setUpdateDate(DateUtil.getByTimeZone(libraryModelPointDTO.getTimeZone()));
modelPoint.setId(libraryModelPointDTO.getTemplateId());
updateById(modelPoint);
libraryModelPointVO.setTemplateId(modelPoint.getId());
}
}*/
return libraryModelPointVO;
}

View File

@@ -835,4 +835,24 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
return Boolean.TRUE;
}
@Override
public Long addSysModelToLib(long sysModelId) {
Long accountId = UserContext.getUserHolder().getId();
SysFile sysFile = sysFileMapper.selectById(sysModelId);
if (Objects.isNull(sysFile)) {
throw new BusinessException("model.not.found", ResultEnum.PROMPT.getCode());
}
Library library = CopyUtil.copyObject(sysFile, Library.class);
library.setAccountId(accountId);
library.setName(DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD));
List<Integer> imagesWidthAndHeight = minioUtil.getImagesWidthAndHeight(sysFile.getUrl());
library.setWidth(imagesWidthAndHeight.get(0));
library.setHigh(imagesWidthAndHeight.get(1));
library.setCreateDate(new Date());
libraryMapper.insert(library);
return library.getId();
}
}