1、接入超分功能
2、添加积分系统 3、新增订单查询,积分详细查询
This commit is contained in:
@@ -3082,4 +3082,64 @@ public class PythonService {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
public String superResolution(SuperResolutionDTO superResolutionDTO){
|
||||
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");
|
||||
|
||||
HashMap<String, String> content = new HashMap<>();
|
||||
content.put("image_url", superResolutionDTO.getImages());
|
||||
content.put("sr_xn", superResolutionDTO.getScale().toString());
|
||||
content.put("task_id", superResolutionDTO.getUniqueId());
|
||||
|
||||
String jsonString = JSON.toJSONString(content, SerializerFeature.WriteNullStringAsEmpty);
|
||||
RequestBody body = RequestBody.create(mediaType, jsonString);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + 9991 + "/super-resolution/")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyString;
|
||||
try {
|
||||
log.info("superResolution请求入参content###{}", JSON.toJSONString(superResolutionDTO, SerializerFeature.WriteMapNullValue));
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##superResolution异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException(ioException.getMessage());
|
||||
}
|
||||
|
||||
// 判断是否生成失败
|
||||
if (Objects.isNull(response.body())) {
|
||||
log.error("PythonService##superResolution异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("PythonService##superResolution异常###: response or body is empty!");
|
||||
} else if (response.code() != HttpURLConnection.HTTP_OK) {
|
||||
log.error("PythonService##superResolution异常###{}", "Response error!Response code ## " + response.code() + " ##");
|
||||
throw new BusinessException("PythonService##superResolution异常### 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");
|
||||
|
||||
// todo 返回数据的结构没对接好
|
||||
if (result && jsonObject.get("code").equals(200)) {
|
||||
log.info("superResolution##responseObject###{}", jsonObject);
|
||||
return jsonObject.getJSONObject("data").get("image").toString();
|
||||
}
|
||||
log.info("superResolution失败###{}", jsonObject);
|
||||
log.info("superResolution Exception! Code : " + jsonObject.get("code"));
|
||||
//生成失败
|
||||
throw new BusinessException("sr.interface.error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user