Merge branch 'dev/dev_xp' into dev/dev

# Conflicts:
#	src/main/java/com/ai/da/python/PythonService.java
This commit is contained in:
2025-03-25 11:25:22 +08:00
30 changed files with 1847 additions and 19 deletions

View File

@@ -3966,4 +3966,124 @@ public class PythonService {
}
}
public Boolean poseTransformation(String productImage, int poseId, String taskId) {
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");
Map<String, String> content = Maps.newHashMap();
content.put("image_url", productImage);
content.put("tasks_id", taskId);
content.put("pose_id", String.valueOf(poseId));
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
log.info("poseTransformation 请求地址: {}", accessPythonIp + ":" + accessPythonPort + "/api/pose_transform");
Request request = new Request.Builder()
.url(accessPythonIp + ":" + accessPythonPort + "/api/pose_transform")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyString;
try {
log.info("poseTransformation请求入参content###{}", JSON.toJSONString(content));
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##poseTransformation异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException(ioException.getMessage());
}
// 判断是否生成失败
if (Objects.isNull(response.body())) {
log.error("PythonService##poseTransformation异常###{}", "response or body is empty!");
throw new BusinessException("PythonService##poseTransformation异常###: response or body is empty!");
} else if (response.code() != HttpURLConnection.HTTP_OK) {
log.error("PythonService##poseTransformation异常###{}", "Response error!Response code ## " + response.code() + " ##");
throw new BusinessException("PythonService##poseTransformation异常### Response error!Response code ## " + response.code() + " ##");
} else {
try {
bodyString = response.body().string();
} catch (IOException e) {
log.error(e.getMessage());
throw new BusinessException(e.getMessage());
}
}
JSONObject jsonObject = JSON.parseObject(bodyString);
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
if (result && jsonObject.get("code").equals(200)) {
log.info("poseTransformation##responseObject###{}", jsonObject);
return Boolean.TRUE;
} else {
log.info("poseTransformation失败###{}", jsonObject);
log.info("poseTransformation Exception! Code : {}", jsonObject.get("code"));
return Boolean.FALSE;
}
}
public String modifyModelProportion(String mannequinPath, Float scale, String name, int top, int bottom) {
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");
Map<String, String> content = Maps.newHashMap();
// 模特的minio地址
content.put("mannequins", mannequinPath);
// 缩放比
content.put("scale", scale.toString());
// 结果存放桶名
content.put("bucket_name", "aida-users");
// 模特名uuid
content.put("mannequin_name", name);
content.put("top", String.valueOf(top));
content.put("bottom", String.valueOf(bottom));
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
log.info("modifyModelProportion 请求地址: {}\n 参数:{}", accessPythonIp + ":" + accessPythonPort + "/api/mannequins_edit", JSON.toJSONString(content));
Request request = new Request.Builder()
.url(accessPythonIp + ":" + accessPythonPort + "/api/mannequins_edit")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##modifyModelProportion异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("generate.interface.error");
}
int responseCode = response.code();
String bodyString;
try {
bodyString = response.body().string();
if (responseCode != HttpURLConnection.HTTP_OK) {
// 基本不会有除200以外的code
log.info("modifyModelProportion 失败。 Response code {}", responseCode);
throw new BusinessException("modifyModelProportion 失败。 Response code " + responseCode);
}
JSONObject jsonObject = JSON.parseObject(bodyString);
if (response.isSuccessful() && jsonObject.get("msg").equals("OK!")) {
String modifiedModel = jsonObject.get("data").toString();
log.info("modifyModelProportion 结果 {}", modifiedModel);
return modifiedModel;
}else {
log.info("modifyModelProportion 失败。 Response code {}", responseCode);
throw new BusinessException("modifyModelProportion 失败。 Response code " + responseCode);
}
} catch (IOException e) {
log.error("modifyModelProportion 失败; error message => {}", e.getMessage());
response.close();
throw new BusinessException("generate.interface.error");
} finally {
response.close();
}
}
}