|
|
|
|
@@ -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;
|
|
|
|
|
|