Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -31,6 +31,12 @@ public class DesignController {
|
||||
return Response.success(designService.designCollection(designDTO));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "design进度条")
|
||||
@GetMapping("/designProcess")
|
||||
public Response<Integer> designProcess(@RequestParam("processId") String processId) {
|
||||
return Response.success(designService.designProcess(processId));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "重新设计 Collection")
|
||||
@PostMapping("/reDesignCollection")
|
||||
public Response<DesignCollectionVO> reDesignCollection(@Valid @RequestBody ReDesignCollectionDTO reDesignDTO) {
|
||||
|
||||
@@ -51,6 +51,10 @@ public class SysFile implements Serializable {
|
||||
*
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
private Integer high;
|
||||
|
||||
private Integer width;
|
||||
/**
|
||||
* 路径 绝对路径
|
||||
*
|
||||
|
||||
@@ -21,6 +21,8 @@ public class DesignCollectionVO {
|
||||
@ApiModelProperty("design生成的图片 数组")
|
||||
private List<DesignCollectionItemVO> designCollectionItems;
|
||||
|
||||
private String processId;
|
||||
|
||||
public DesignCollectionVO() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,4 +34,8 @@ public class SysFileVO implements Serializable {
|
||||
*/
|
||||
private String md5;
|
||||
|
||||
private Integer high;
|
||||
|
||||
private Integer width;
|
||||
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public class PythonService {
|
||||
DesignPythonObjects designPythonObjects = new DesignPythonObjects();
|
||||
List<DesignPythonObject> objects = Lists.newArrayList();
|
||||
designPythonObjects.setObjects(objects);
|
||||
designPythonObjects.setProcess_id("1234");
|
||||
designPythonObjects.setProcess_id(UUID.randomUUID().toString());
|
||||
long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements());
|
||||
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements());
|
||||
//没有print的
|
||||
|
||||
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;
|
||||
}
|
||||
8
src/main/java/com/ai/da/python/vo/ProcessIdObject.java
Normal file
8
src/main/java/com/ai/da/python/vo/ProcessIdObject.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.ai.da.python.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ProcessIdObject {
|
||||
private String process_id;
|
||||
}
|
||||
@@ -76,4 +76,6 @@ public interface DesignService extends IService<Design> {
|
||||
* @return
|
||||
*/
|
||||
DesignItemDetailVO detail(Long designPythonOutfitId,Long designItemId);
|
||||
|
||||
Integer designProcess(String processId);
|
||||
}
|
||||
|
||||
@@ -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,byId.getHigh(),byId.getWidth(),byId.getUrl()));
|
||||
}
|
||||
}else {
|
||||
throw new BusinessException("templateId or modelType can't be null");
|
||||
}
|
||||
// elementVO.setDesignLibraryModelPoint(calculateTemplatePointTemplate(null,null,null,null));
|
||||
return elementVO;
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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,19 +16,18 @@ import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
import com.ai.da.python.vo.DesignPythonItemPrint;
|
||||
import com.ai.da.python.vo.DesignPythonObject;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.python.vo.*;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -37,9 +37,11 @@ import org.springframework.util.StringUtils;
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ai.da.python.vo.DesignPythonItem.*;
|
||||
@@ -511,7 +513,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.setProcessId(pythonObjects.getProcess_id());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -627,9 +629,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
Assert.notNull(design, "design does not exist!");
|
||||
List<DesignItem> designItems = designItemService.getByDesignId(designId);
|
||||
if (CollectionUtils.isEmpty(designItems)) {
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), null);
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), null, null);
|
||||
}
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), coverDesignItemToVO(designItems));
|
||||
return new DesignCollectionVO(designId, design.getCollectionId(), coverDesignItemToVO(designItems), null);
|
||||
}
|
||||
|
||||
private List<DesignCollectionItemVO> coverDesignItemToVO(List<DesignItem> designItems) {
|
||||
@@ -857,6 +859,54 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
editResponseColor(designItemDetails,response));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer designProcess(String processId) {
|
||||
ProcessIdObject object = new ProcessIdObject();
|
||||
object.setProcess_id(processId);
|
||||
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(object, 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 num = responseObject.getString("data");
|
||||
return Integer.valueOf(num);
|
||||
}catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
//生成失败
|
||||
throw new BusinessException("generate design exception!");
|
||||
}
|
||||
|
||||
private String converTypeToLevel1(String type) {
|
||||
if (StringUtils.isEmpty(type)) {
|
||||
return null;
|
||||
|
||||
@@ -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);
|
||||
@@ -207,6 +267,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
sysFile.setUrl(filePath);
|
||||
sysFile.setMd5(uploadDTO.getMd5());
|
||||
sysFile.setCreateDate(new Date());
|
||||
sysFile.setHigh(uploadDTO.getHigh());
|
||||
sysFile.setWidth(uploadDTO.getWidth());
|
||||
sysFileMapper.insert(sysFile);
|
||||
Library library = new Library();
|
||||
library.setId(sysFile.getId());
|
||||
|
||||
Reference in New Issue
Block a user