TASK:moodboard与printboard 图片合成
This commit is contained in:
@@ -61,9 +61,9 @@ public class PythonService {
|
||||
* @param printPath
|
||||
* @return
|
||||
*/
|
||||
public String generatePrint(List<String> printPath) {
|
||||
public String generatePrint(List<String> printPath, Long userId) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("generatePrint", 2);
|
||||
// AccessLimitUtils.validate("generatePrint", 2);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
@@ -74,33 +74,48 @@ public class PythonService {
|
||||
Map<String, String> content = Maps.newHashMap();
|
||||
content.put("fusion_content_path", printPath.get(0));
|
||||
content.put("fusion_style_path", printPath.get(1));
|
||||
content.put("fusion_output_path", getPythonOutputPath(
|
||||
printPath.get(0), PythonToJavaApiOperationTypeEnum.GENERATE_PRINT));
|
||||
content.put("userid", String.valueOf(userId));
|
||||
// content.put("fusion_output_path", getPythonOutputPath(
|
||||
// printPath.get(0), PythonToJavaApiOperationTypeEnum.GENERATE_PRINT));
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":9999/aifda/api/v1.0/fusion_test")
|
||||
// .url(accessPythonIp + ":9999/aifda/api/v1.0/fusion_test")
|
||||
.url(accessPythonIp + ":9991/api/image_fusion")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
log.info("生成印花请求入参content###{}", JSON.toJSONString(content));
|
||||
log.info("moodboard与printboard图片合成 入参content###{}", JSON.toJSONString(content));
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##generatePrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("generate.interface.exception");
|
||||
log.error("PythonService## moodboard与printboard图片合成异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("image.synthesis.failed");
|
||||
}
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("generatePrint");
|
||||
// AccessLimitUtils.validateOut("generatePrint");
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
if (result) {
|
||||
return content.get("fusion_output_path");
|
||||
if (jsonObject.getBoolean("successful")) {
|
||||
try {
|
||||
if (Objects.nonNull(response.body())) {
|
||||
responseBody = response.body().string();
|
||||
JSONObject responseObj = JSON.parseObject(responseBody);
|
||||
log.info("moodboard与printboard图片合成 python返回###{}",responseObj);
|
||||
return responseObj.get("data").toString();
|
||||
}
|
||||
} catch (IOException | JSONException e) {
|
||||
log.error("Python moodboard与printboard图片合成异常 : {}", e.getMessage());
|
||||
throw new BusinessException("image.synthesis.failed");
|
||||
}
|
||||
log.error("moodboard与printboard图片合成异常###{}", jsonObject);
|
||||
throw new BusinessException("image.synthesis.failed");
|
||||
// return content.get("fusion_output_path");
|
||||
}
|
||||
log.info("生成印花失败###{}", jsonObject);
|
||||
log.info("moodboard与printboard图片合成异常###{}", jsonObject);
|
||||
//生成失败
|
||||
throw new BusinessException("generate.interface.exception");
|
||||
throw new BusinessException("image.synthesis.failed");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2219,15 +2234,6 @@ public class PythonService {
|
||||
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
|
||||
response = client.newCall(request).execute();
|
||||
bodyString = response.body().string();
|
||||
// bodyString = "{\n" +
|
||||
// " \"code\": 200,\n" +
|
||||
// " \"data\": {\n" +
|
||||
// " \"list\": [\n" +
|
||||
// " \"aida-users/12/print_1695088687_0.png\"\n" +
|
||||
// " ]\n" +
|
||||
// " },\n" +
|
||||
// " \"msg\": \"OK!\"\n" +
|
||||
// "}";
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user