BUGFIX:模特;
This commit is contained in:
8
src/main/java/com/ai/da/python/vo/ModelPathObject.java
Normal file
8
src/main/java/com/ai/da/python/vo/ModelPathObject.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.ai.da.python.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ModelPathObject {
|
||||
private String model_path;
|
||||
}
|
||||
@@ -458,7 +458,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
if (Objects.isNull(modelPoint)) {
|
||||
throw new BusinessException("error modelPoint get");
|
||||
}
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint,1654,1170,byId.getUrl()));
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint,byId.getHigh(),byId.getWidth(),byId.getUrl()));
|
||||
}else if (designDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
||||
SysFileVO byId = sysFileService.getById(designDTO.getTemplateId());
|
||||
QueryWrapper<LibraryModelPoint> qw = new QueryWrapper<>();
|
||||
@@ -468,12 +468,11 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
if (Objects.isNull(modelPoint)) {
|
||||
throw new BusinessException("error modelPoint get");
|
||||
}
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint,1654,1170,byId.getUrl()));
|
||||
elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(modelPoint,1810,1280,byId.getUrl()));
|
||||
}
|
||||
}else {
|
||||
throw new BusinessException("templateId or modelType can't be null");
|
||||
}
|
||||
// elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(null,null,null,null));
|
||||
return elementVO;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
@@ -15,14 +16,19 @@ import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.ModelType;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.vo.ModelPathObject;
|
||||
import com.ai.da.service.LibraryModelPointService;
|
||||
import com.ai.da.service.LibraryService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Function;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -31,7 +37,9 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -165,24 +173,76 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
default:
|
||||
throw new BusinessException("unknown level1_type");
|
||||
}
|
||||
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
||||
//保存element元素
|
||||
if (libraryUploadDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, filePath);
|
||||
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
||||
String newFilePath = bucketName + "/" + processMannequins(filePath);
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, newFilePath);
|
||||
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
|
||||
libraryUpdateVo.setMinIOPath(libraryUpdateVo.getUrl());
|
||||
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(filePath, 480));
|
||||
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 480));
|
||||
return libraryUpdateVo;
|
||||
}else if (libraryUploadDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, filePath);
|
||||
bucketName = "aida-sys-image";
|
||||
path = "models/" + libraryUploadDTO.getModelSex();
|
||||
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
|
||||
String newFilePath = bucketName + "/" + processMannequins(filePath);
|
||||
Library library = resolveData(libraryUploadDTO, userInfo, newFilePath);
|
||||
LibraryUpdateVo libraryUpdateVo = CopyUtil.copyObject(library, LibraryUpdateVo.class);
|
||||
libraryUpdateVo.setMinIOPath(libraryUpdateVo.getUrl());
|
||||
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(filePath, 480));
|
||||
libraryUpdateVo.setUrl(minioUtil.getPresignedUrl(newFilePath, 480));
|
||||
return libraryUpdateVo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String processMannequins(String filePath) {
|
||||
ModelPathObject modelPathObject = new ModelPathObject();
|
||||
modelPathObject.setModel_path(filePath);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
String param = JSON.toJSONString(modelPathObject, SerializerFeature.DisableCircularReferenceDetect);
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url("http://18.167.251.121:9991/api/model_process")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
//去除限流
|
||||
// AccessLimitUtils.validateOut("design");
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("PythonService##design异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
}
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
String newMinioPath = responseObject.getString("data");
|
||||
return newMinioPath;
|
||||
}catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
//生成失败
|
||||
throw new BusinessException("generate design exception!");
|
||||
}
|
||||
|
||||
private Library resolveData(LibraryUploadDTO uploadDTO, AuthPrincipalVo userInfo, String filePath) {
|
||||
if (uploadDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
|
||||
Library library = CopyUtil.copyObject(uploadDTO, Library.class);
|
||||
|
||||
Reference in New Issue
Block a user