From ae484c9e6ce7b2915f8fef8425ab9ba00d63c0a9 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 24 Mar 2025 15:59:46 +0800 Subject: [PATCH] =?UTF-8?q?TASK:=E6=A8=A1=E5=9D=97=E5=8C=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/python/PythonService.java | 50 +++++++++++++++++++ .../impl/UserLikeGroupServiceImpl.java | 4 +- .../da/service/impl/WorkspaceServiceImpl.java | 20 +++++--- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 298f114c..02c9a245 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -3966,4 +3966,54 @@ public class PythonService { } } + public JSONObject segProduct(String url) { + 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 map = new HashMap<>(); + map.put("image_url", url); + map.put("is_brand_dna", Boolean.TRUE); + log.info("bright请求python 参数:####{}", map); + String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty); + log.info(param); + 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") + .url(accessPythonIp + ":" + accessPythonPort + "/api/seg_product") + .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##bright异常###{}", ExceptionUtil.getThrowableList(ioException)); + throw new BusinessException("segProduct.interface.exception"); + } + if (response.isSuccessful()) { + try { + if (Objects.nonNull(response.body())) { + responseBody = response.body().string(); + JSONObject responseObject = JSON.parseObject(responseBody); + log.info("PythonService##responseObject###{}", responseObject); + return responseObject; + } + throw new BusinessException("segProduct.interface.exception"); + } catch (IOException | JSONException e) { + log.error("PythonService##segProduct异常###{}", e.getMessage()); + throw new BusinessException("segProduct.interface.exception"); + } + } + log.error("PythonService##segProduct异常response###{}", response); + //生成失败 + throw new BusinessException("segProduct.interface.exception"); + } } diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 74c06109..9e6a5d36 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -1140,8 +1140,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); qw.lambda().eq(WorkspaceRelStyle::getWorkspaceId, vo.getId()); List workspaceRelStyles = workspaceRelStyleMapper.selectList(qw); @@ -698,7 +703,8 @@ public class WorkspaceServiceImpl extends ServiceImpl