TASK:aida;

This commit is contained in:
shahaibo
2024-06-12 09:47:55 +08:00
parent b1b4b4147c
commit 3a29d25060
51 changed files with 1114 additions and 193 deletions

View File

@@ -8,10 +8,7 @@ import com.ai.da.common.enums.*;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.primary.CollocationMapper;
import com.ai.da.mapper.primary.DressingMapper;
import com.ai.da.mapper.primary.entity.CollectionElement;
import com.ai.da.mapper.primary.entity.Collocation;
import com.ai.da.mapper.primary.entity.DesignHistory;
import com.ai.da.mapper.primary.entity.Dressing;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.mapper.secondary.AttributeRetrievalMapper;
import com.ai.da.mapper.secondary.entity.AttributeRetrieval;
import com.ai.da.mapper.secondary.entity.AttributeRecognitionJSON;
@@ -165,7 +162,7 @@ public class PythonService {
* @param operateType
* @return
*/
@Transactional
@Transactional(rollbackFor = Exception.class)
public String upload(MultipartFile file, String operateType) {
//用户信息
PythonToJavaApiOperationTypeEnum operationType = PythonToJavaApiOperationTypeEnum.uploadOf(operateType);
@@ -3254,4 +3251,44 @@ public class PythonService {
return text;
}
public Boolean toProductImage(String url, String taskId, String prompt) {
// todo 限流校验
// AccessLimitUtils.validate("design",5);
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 现象
Map<String, String> map = new HashMap<>();
map.put("tasks_id", taskId);
map.put("image_url", url);
map.put("prompt", prompt);
log.info("toProductImage请求python 参数:####{}", map);
String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty);
RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder()
// .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_product_image")
.url(accessPythonIp + ":9996/api/generate_product_image")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response;
String responseBody;
try {
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##toProductImage异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("toProductImage.interface.exception");
}
if (response.isSuccessful()) {
return Boolean.TRUE;
}
log.error("PythonService##toProductImage异常response###{}", response);
//生成失败
throw new BusinessException("toProductImage.interface.exception");
}
}