Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -67,7 +67,7 @@ public class ElementController {
|
|||||||
|
|
||||||
@ApiOperation(value = "生成印花")
|
@ApiOperation(value = "生成印花")
|
||||||
@PostMapping("/generatePrint")
|
@PostMapping("/generatePrint")
|
||||||
public Response<CollectionGeneratePrintVO> generatePrint(@Valid @RequestBody CollectionGeneratePrintDTO generatePrintDTO) {
|
public Response<GenerateCollectionItemVO> generatePrint(@Valid @RequestBody CollectionGeneratePrintDTO generatePrintDTO) {
|
||||||
return Response.success(collectionElementService.generatePrint(generatePrintDTO));
|
return Response.success(collectionElementService.generatePrint(generatePrintDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,4 +16,14 @@ public class GenerateCollectionItemVO {
|
|||||||
|
|
||||||
@ApiModelProperty("生成的图片是否已经被like")
|
@ApiModelProperty("生成的图片是否已经被like")
|
||||||
private Boolean isLiked = Boolean.FALSE;
|
private Boolean isLiked = Boolean.FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
public GenerateCollectionItemVO() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GenerateCollectionItemVO(Long generateItemId, String generateItemUrl, Boolean isLiked) {
|
||||||
|
this.generateItemId = generateItemId;
|
||||||
|
this.generateItemUrl = generateItemUrl;
|
||||||
|
this.isLiked = isLiked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ public class PythonService {
|
|||||||
* @param printPath
|
* @param printPath
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String generatePrint(List<String> printPath) {
|
public String generatePrint(List<String> printPath, Long userId) {
|
||||||
//限流校验
|
//限流校验
|
||||||
AccessLimitUtils.validate("generatePrint", 2);
|
// AccessLimitUtils.validate("generatePrint", 2);
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
.connectTimeout(30, TimeUnit.SECONDS)
|
.connectTimeout(30, TimeUnit.SECONDS)
|
||||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||||
@@ -75,33 +75,48 @@ public class PythonService {
|
|||||||
Map<String, String> content = Maps.newHashMap();
|
Map<String, String> content = Maps.newHashMap();
|
||||||
content.put("fusion_content_path", printPath.get(0));
|
content.put("fusion_content_path", printPath.get(0));
|
||||||
content.put("fusion_style_path", printPath.get(1));
|
content.put("fusion_style_path", printPath.get(1));
|
||||||
content.put("fusion_output_path", getPythonOutputPath(
|
content.put("userid", String.valueOf(userId));
|
||||||
printPath.get(0), PythonToJavaApiOperationTypeEnum.GENERATE_PRINT));
|
// content.put("fusion_output_path", getPythonOutputPath(
|
||||||
|
// printPath.get(0), PythonToJavaApiOperationTypeEnum.GENERATE_PRINT));
|
||||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(accessPythonIp + ":9999/aifda/api/v1.0/fusion_test")
|
// .url(accessPythonIp + ":9999/aifda/api/v1.0/fusion_test")
|
||||||
|
.url(accessPythonIp + ":9991/api/image_fusion")
|
||||||
.method("POST", body)
|
.method("POST", body)
|
||||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.build();
|
.build();
|
||||||
Response response = null;
|
Response response;
|
||||||
|
String responseBody;
|
||||||
try {
|
try {
|
||||||
log.info("生成印花请求入参content###{}", JSON.toJSONString(content));
|
log.info("moodboard与printboard图片合成 入参content###{}", JSON.toJSONString(content));
|
||||||
response = client.newCall(request).execute();
|
response = client.newCall(request).execute();
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
log.error("PythonService##generatePrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
log.error("PythonService## moodboard与printboard图片合成异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
throw new BusinessException("generate.interface.exception");
|
throw new BusinessException("image.synthesis.failed");
|
||||||
}
|
}
|
||||||
//去除限流
|
//去除限流
|
||||||
AccessLimitUtils.validateOut("generatePrint");
|
// AccessLimitUtils.validateOut("generatePrint");
|
||||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||||
Boolean result = jsonObject.getBoolean("successful");
|
if (jsonObject.getBoolean("successful")) {
|
||||||
if (result) {
|
try {
|
||||||
return content.get("fusion_output_path");
|
if (Objects.nonNull(response.body())) {
|
||||||
|
responseBody = response.body().string();
|
||||||
|
JSONObject responseObj = JSON.parseObject(responseBody);
|
||||||
|
log.info("moodboard与printboard图片合成 python返回###{}",responseObj);
|
||||||
|
return responseObj.get("data").toString();
|
||||||
|
}
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
log.error("Python moodboard与printboard图片合成异常 : {}", e.getMessage());
|
||||||
|
throw new BusinessException("image.synthesis.failed");
|
||||||
|
}
|
||||||
|
log.error("moodboard与printboard图片合成异常###{}", jsonObject);
|
||||||
|
throw new BusinessException("image.synthesis.failed");
|
||||||
|
// return content.get("fusion_output_path");
|
||||||
}
|
}
|
||||||
log.info("生成印花失败###{}", jsonObject);
|
log.info("moodboard与printboard图片合成异常###{}", jsonObject);
|
||||||
//生成失败
|
//生成失败
|
||||||
throw new BusinessException("generate.interface.exception");
|
throw new BusinessException("image.synthesis.failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2240,15 +2255,6 @@ public class PythonService {
|
|||||||
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
|
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
|
||||||
response = client.newCall(request).execute();
|
response = client.newCall(request).execute();
|
||||||
bodyString = response.body().string();
|
bodyString = response.body().string();
|
||||||
// bodyString = "{\n" +
|
|
||||||
// " \"code\": 200,\n" +
|
|
||||||
// " \"data\": {\n" +
|
|
||||||
// " \"list\": [\n" +
|
|
||||||
// " \"aida-users/12/print_1695088687_0.png\"\n" +
|
|
||||||
// " ]\n" +
|
|
||||||
// " },\n" +
|
|
||||||
// " \"msg\": \"OK!\"\n" +
|
|
||||||
// "}";
|
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public interface CollectionElementService extends IService<CollectionElement> {
|
|||||||
* @param generatePrintDTO
|
* @param generatePrintDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CollectionGeneratePrintVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO);
|
GenerateCollectionItemVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存印花图片
|
* 保存印花图片
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import io.minio.errors.MinioException;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -33,6 +34,7 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -173,7 +175,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CollectionGeneratePrintVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO) {
|
public GenerateCollectionItemVO generatePrint(CollectionGeneratePrintDTO generatePrintDTO) {
|
||||||
|
Long userId = UserContext.getUserHolder().getId();
|
||||||
String url1 = null;
|
String url1 = null;
|
||||||
String url2 = null;
|
String url2 = null;
|
||||||
CollectionElement element1 = selectById(generatePrintDTO.getSelect1Id());
|
CollectionElement element1 = selectById(generatePrintDTO.getSelect1Id());
|
||||||
@@ -198,19 +201,30 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
}
|
}
|
||||||
List<String> printPath = Arrays.asList(url1, url2);
|
List<String> printPath = Arrays.asList(url1, url2);
|
||||||
//调取python 接口
|
//调取python 接口
|
||||||
String generateUrl = pythonService.generatePrint(printPath);
|
String generateUrl = pythonService.generatePrint(printPath,userId);
|
||||||
if (StringUtils.isEmpty(generateUrl)) {
|
if (StringUtils.isEmpty(generateUrl)) {
|
||||||
throw new BusinessException("generate.interface.exception");
|
throw new BusinessException("generate.interface.exception");
|
||||||
}
|
}
|
||||||
//用户信息
|
|
||||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
// 保存合成信息到generate表
|
||||||
CollectionElement element = resolveData(generateUrl, generatePrintDTO.getTimeZone(), userInfo);
|
Generate generate = setGenerate(userId, generatePrintDTO.getTimeZone());
|
||||||
if (!this.save(element)) {
|
generateService.save(generate);
|
||||||
throw new BusinessException("save.collectionElement.failed");
|
|
||||||
}
|
// 保存合成后的信息到generateDetail
|
||||||
CollectionGeneratePrintVO collectionGeneratePrint = CopyUtil.copyObject(element, CollectionGeneratePrintVO.class);
|
GenerateDetail generateDetail = setGenerateDetail(generate.getId(), generateUrl, generatePrintDTO.getTimeZone());
|
||||||
collectionGeneratePrint.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
generateDetailMapper.insert(generateDetail);
|
||||||
return collectionGeneratePrint;
|
|
||||||
|
// CollectionElement element = resolveData(generateUrl, generatePrintDTO.getTimeZone(), userId);
|
||||||
|
// if (!this.save(element)) {
|
||||||
|
// throw new BusinessException("save.collectionElement.failed");
|
||||||
|
// }
|
||||||
|
// CollectionGeneratePrintVO collectionGeneratePrint = CopyUtil.copyObject(element, CollectionGeneratePrintVO.class);
|
||||||
|
// collectionGeneratePrint.setUrl(minioUtil.getPresignedUrl(generateUrl, 24 * 60));
|
||||||
|
// collectionGeneratePrint.setDesignType(DesignTypeEnum.COLLECTION.getRealName());
|
||||||
|
// return collectionGeneratePrint;
|
||||||
|
return new GenerateCollectionItemVO(generateDetail.getId(),
|
||||||
|
minioUtil.getPresignedUrl(generateUrl, 24 * 60),
|
||||||
|
generateDetail.getIsLike().equals((byte) 0) ? Boolean.FALSE : Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -284,16 +298,23 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollectionElement resolveData(String path, String timeZone, AuthPrincipalVo userInfo) {
|
private CollectionElement resolveData(String path, String timeZone, Long userId){
|
||||||
File file = new File(path);
|
// File file = new File(path);
|
||||||
|
|
||||||
|
String name = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
|
||||||
CollectionElement element = new CollectionElement();
|
CollectionElement element = new CollectionElement();
|
||||||
element.setAccountId(userInfo.getId());
|
element.setAccountId(userId);
|
||||||
element.setCollectionId(0L);
|
element.setCollectionId(0L);
|
||||||
element.setName(file.getName());
|
element.setName(name);
|
||||||
element.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
element.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||||
element.setUrl(path);
|
element.setUrl(path);
|
||||||
element.setHasPin((byte) 0);
|
element.setHasPin((byte) 0);
|
||||||
element.setMd5(MD5Utils.encryptFile(path, Boolean.FALSE));
|
try {
|
||||||
|
element.setMd5(MD5Utils.encryptFile(minioUtil.download(path)));
|
||||||
|
} catch (MinioException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
//按时区计算
|
//按时区计算
|
||||||
element.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
element.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||||
return element;
|
return element;
|
||||||
@@ -774,4 +795,38 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
|||||||
}
|
}
|
||||||
return collectionElement;
|
return collectionElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Generate setGenerate(Long userId,String timeZone){
|
||||||
|
Generate generate = new Generate();
|
||||||
|
generate.setAccountId(userId);
|
||||||
|
generate.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||||
|
generate.setGenerateType("synthesis");
|
||||||
|
generate.setModelName("Image Synthesis Model");
|
||||||
|
generate.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||||
|
return generate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GenerateDetail setGenerateDetail(Long generateId, String url, String timeZone){
|
||||||
|
GenerateDetail generateDetail = new GenerateDetail();
|
||||||
|
generateDetail.setGenerateId(generateId);
|
||||||
|
generateDetail.setUrl(url);
|
||||||
|
String md5;
|
||||||
|
try {
|
||||||
|
md5 = MD5Utils.encryptFile(minioUtil.download(url));
|
||||||
|
} catch (MinioException | IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// 通过MD5来确认当前图片是否有被like过,避免重复like
|
||||||
|
List<Map<String, Long>> libraryIds = generateDetailMapper.getLibraryIdThroughMD5(md5, CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||||
|
if (libraryIds.isEmpty()){
|
||||||
|
generateDetail.setIsLike((byte) 0);
|
||||||
|
}else {
|
||||||
|
generateDetail.setIsLike((byte) 1);
|
||||||
|
generateDetail.setLibraryId(libraryIds.get(0).get("library_id"));
|
||||||
|
}
|
||||||
|
generateDetail.setMd5(md5);
|
||||||
|
generateDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||||
|
|
||||||
|
return generateDetail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,11 +185,15 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
|
|
||||||
// 2、将like的图片信息存入library
|
// 2、将like的图片信息存入library
|
||||||
// 2.1、不能重复喜欢
|
// 2.1、不能重复喜欢
|
||||||
|
// 2.1.1 判断该图片是否被喜欢过
|
||||||
Library libraryDetail = libraryService.getById(generateDetail.getLibraryId());
|
Library libraryDetail = libraryService.getById(generateDetail.getLibraryId());
|
||||||
if ( (Objects.nonNull(generateDetail.getLibraryId()) && !generateDetail.getLibraryId().equals(0L))
|
if ( (Objects.nonNull(generateDetail.getLibraryId()) && !generateDetail.getLibraryId().equals(0L))
|
||||||
|| Objects.nonNull(libraryDetail)){
|
|| Objects.nonNull(libraryDetail)){
|
||||||
throw new BusinessException("duplicate.likes.are.not.allowed");
|
throw new BusinessException("duplicate.likes.are.not.allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo 2.1.2、判断library中是否有相同MD5的图片
|
||||||
|
|
||||||
// 2.2、添加到library
|
// 2.2、添加到library
|
||||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||||
Long accountId = userInfo.getId();
|
Long accountId = userInfo.getId();
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ layers.does.not.exists=layers does not exists.
|
|||||||
unknown.generate.type=unknown generate type.
|
unknown.generate.type=unknown generate type.
|
||||||
the.workspace.lastIndex.not.found=The workspace lastIndex not found.
|
the.workspace.lastIndex.not.found=The workspace lastIndex not found.
|
||||||
gender.cannot.be.empty=gender cannot be empty.
|
gender.cannot.be.empty=gender cannot be empty.
|
||||||
|
image.synthesis.failed=Image synthesis failed.
|
||||||
|
|
||||||
# 可能会报异常
|
# 可能会报异常
|
||||||
# Informative:
|
# Informative:
|
||||||
|
|||||||
Reference in New Issue
Block a user