@@ -7,10 +7,8 @@ import com.ai.da.common.enums.*;
import com.ai.da.common.utils.* ;
import com.ai.da.mapper.primary.* ;
import com.ai.da.mapper.primary.entity.* ;
import com.ai.da.model.dto.GenerateLikeDTO ;
import com.ai.da.model.dto.GenerateModifyDTO ;
import com.ai.da.model.dto.GenerateThroughImageTextDTO ;
import com.ai.da.model.dto.GenerateToPythonDTO ;
import com.ai.da.model.dto.* ;
import com.ai.da.model.enums.SketchStyle ;
import com.ai.da.model.vo.* ;
import com.ai.da.python.PythonService ;
import com.ai.da.service.* ;
@@ -773,25 +771,28 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
@Override
@Transactional ( rollbackFor = Exception . class )
public String imageToSketch ( GenerateThroughImageTextDTO generateThroughImageText DTO) {
public GenerateResultVO imageToSketch ( ImageToSketchDTO imageToSketch DTO) {
String bucket = userBucket ;
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
String imagePath ;
if ( generateThroughImageTextDTO . getDesignType ( ) . equals ( " collection " ) ) {
CollectionElement collectionElement = collectionElementService . getById ( generateThroughImageTextDTO . getCollectionElementId ( ) ) ;
imagePath = collectionElement . getUrl ( ) ;
} else if ( generateThroughImageTextDTO . getDesignType ( ) . equals ( " productImage " ) ) {
ToProductImageResult productImage = toProductImageResultMapper . selectById ( generateThroughImageTextDTO . getCollectionElementId ( ) ) ;
imagePath = productImage . getUrl ( ) ;
} else {
log . error ( " unknown designType " ) ;
throw new BusinessException ( " unknown designType " ) ;
}
CollectionElement collectionElement = collectionElementService . getById ( imageToSketchDTO . getElementId ( ) ) ;
String imagePath = collectionElement . getUrl ( ) ;
log . info ( minioUtil . getPreSignedUrl ( imagePath , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
String imageName = imagePath . substring ( imagePath . lastIndexOf ( " / " ) + 1 ) ;
String objectName = accountId + " /imageToSketch/ " + imageName ;
String sketchPath = pythonService . imageToSketch ( imagePath , bucket , objectName ) ;
String style = imageToSketchDTO . getStyle ( ) ;
String styleCode = style . equals ( SketchStyle . THICK . getValue ( ) ) ? " 1 " :
style . equals ( SketchStyle . MEDIUM . getValue ( ) ) ? " 2 " :
style . equals ( SketchStyle . THIN . getValue ( ) ) ? " 3 " : " Custom " ;
String styleImage ;
if ( ! Objects . isNull ( imageToSketchDTO . getStyleImageId ( ) ) ) {
CollectionElement styleElement = collectionElementService . getById ( imageToSketchDTO . getElementId ( ) ) ;
styleImage = styleElement . getUrl ( ) ;
} else {
styleImage = null ;
}
String sketchPath = pythonService . imageToSketch ( imagePath , bucket , objectName , styleCode , styleImage ) ;
// 存DB
Generate generate = new Generate ( ) ;
@@ -799,21 +800,33 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generate . setUniqueId ( String . valueOf ( 0 ) ) ;
generate . setLevel1Type ( SKETCH_BOARD . getRealName ( ) ) ;
generate . setLevel2Type ( " ImageToSketch " ) ;
generate . setElementSource ( generateThroughImageTextDTO . getDesignType ( ) ) ;
generate . setElementId ( generateThroughImageText DTO. getCollection ElementId ( ) ) ;
generate . setElementSource ( " collection " ) ;
generate . setElementId ( imageToSketch DTO. getElementId ( ) ) ;
generate . setGenerateType ( " image " ) ;
generate . setSketchStyle ( styleCode ) ;
generate . setStyleImageElementId ( imageToSketchDTO . getElementId ( ) ) ;
generate . setCreateDate ( new Date ( ) ) ;
baseMapper . insert ( generate ) ;
// 返回
return minioUtil . getPreSignedUrl ( sketchPath , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ;
// 将生成结果存入DB
GenerateDetail generateDetail = new GenerateDetail ( ) ;
generateDetail . setGenerateId ( generate . getId ( ) ) ;
generateDetail . setUrl ( sketchPath ) ;
generateDetail . setIsLike ( ( byte ) 0 ) ;
generateDetail . setMd5 ( MD5Utils . encryptFile ( minioUtil . getPreSignedUrl ( sketchPath , 24 * 60 ) , Boolean . FALSE ) ) ;
generateDetail . setCreateDate ( LocalDateTime . now ( ) ) ;
generateDetailMapper . insert ( generateDetail ) ;
String clothCategory = pythonService . getClothCategory ( sketchPath , imageToSketchDTO . getGender ( ) ) ;
return new GenerateResultVO ( generateDetail . getId ( ) , minioUtil . getPreSignedUrl ( sketchPath , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) , " Success " , clothCategory ) ;
}
// 对提取出来的sketch做调整
// 输入 base64, 以及 性别 分类, 将图片添加到library
@Override
@Transactional ( rollbackFor = Exception . class )
public void modifySketch ( GenerateModifyDTO generateModifyDTO ) {
public CollectionElementVO modifySketch ( GenerateModifyDTO generateModifyDTO ) {
log . info ( " 修改提取出的sketch,并加入到library " ) ;
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
String base64 = generateModifyDTO . getBase64 ( ) ;
@@ -826,17 +839,23 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
log . info ( " 修改后的图片 : {} " , minioPath ) ;
// 存入db
Library library = new Library ( ) ;
library . setAccountId ( accountId ) ;
library . setLevel1Type ( SKETCH_BOARD . g etRealName ( ) ) ;
library . setLevel2 Type ( category ) ;
library . setLevel3 Type ( gend er ) ;
library . setName ( LocalDate . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyyMMdd " ) ) ) ;
library . setUrl ( minioPath ) ;
library . setMd5 ( MD5Utils . encryptFile ( minioUtil . g etPreSignedUrl ( minioPath , 24 * 60 ) , Boolean . FALSE ) ) ;
library . setCreateDate ( new Date ( ) ) ;
// 存入db 保存到t_collection_element
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . s etCollectionId ( 0L ) ;
collectionElement . setLevel1 Type ( SKETCH_BOARD . getRealName ( ) ) ;
collectionElement . setLevel2 Type ( generateModifyDTO . getCategory ( ) ) ;
collectionElement . setName ( LocalDateTime . now ( ) . format ( DateTimeFormatter . ofPattern ( " yyyyMMdd " ) ) ) ;
collectionElement . setUrl ( minioPath ) ;
collectionElement . s etHasPin ( ( byte ) 0 ) ;
collectionElement . setMd5 ( MD5Utils . encryptFile ( minioUtil . getPreSignedUrl ( minioPath , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) , Boolean . FALSE ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementService . save ( collectionElement ) ;
libraryService . save ( library ) ;
CollectionElementVO collectionElementVO = CopyUtil . copyObject ( collectionElement , CollectionElementVO . class ) ;
collectionElementVO . setMinIOPath ( collectionElementVO . getUrl ( ) ) ;
collectionElementVO . setUrl ( minioUtil . getPreSignedUrl ( collectionElementVO . getUrl ( ) , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
collectionElementVO . setDesignType ( DesignTypeEnum . COLLECTION . getRealName ( ) ) ;
return collectionElementVO ;
}
}