From 509bf7396289b8694ded7a4035cab559361a1bbd Mon Sep 17 00:00:00 2001 From: haozq <1611483981@qq.com> Date: Mon, 20 Oct 2025 10:13:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bonus-business/pom.xml | 6 +- .../service/impl/AlgorithmService.java | 82 ++++++++++++++++++- .../service/impl/ImageCaptionServiceImpl.java | 1 - 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/bonus-business/pom.xml b/bonus-business/pom.xml index d2d6d26..494fb0c 100644 --- a/bonus-business/pom.xml +++ b/bonus-business/pom.xml @@ -32,7 +32,11 @@ 1.6.2 compile - + + org.apache.httpcomponents + httpclient + 4.5.13 + \ No newline at end of file diff --git a/bonus-business/src/main/java/com/bonus/business/service/impl/AlgorithmService.java b/bonus-business/src/main/java/com/bonus/business/service/impl/AlgorithmService.java index bded767..0e5c8c6 100644 --- a/bonus-business/src/main/java/com/bonus/business/service/impl/AlgorithmService.java +++ b/bonus-business/src/main/java/com/bonus/business/service/impl/AlgorithmService.java @@ -1,17 +1,63 @@ package com.bonus.business.service.impl; +import com.alibaba.fastjson2.JSON; import com.bonus.business.domain.ImageRecognize; import com.bonus.file.config.SysFile; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; +import java.util.*; @Service +@Slf4j public class AlgorithmService { + /** + * 请求路径 + */ + public static final String URL="http://127.0.0.1:8000"; + /** + * 图片识别 + */ + public static final String IMAGE_TYPE="/api/auto_annotation"; + /** + * 图像评估 + */ + public static final String IMAGE_RECOGNIZE="/api/image_scoring"; + //调用api //图片进行标注 public List getImageList(List fileList, String operaName) { List list=new ArrayList<>(); + try{ + /** + * 数据存储 + */ + List imageList=new ArrayList<>(); + for (SysFile sysFile : fileList) { + imageList.add(sysFile.getUrl()); + } + List types= Arrays.asList(operaName.split(",")); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(URL+IMAGE_TYPE); + Map map=new HashMap<>(); + map.put("images",imageList); + map.put("types",types); + map.put("return_image",true); + String json= JSON.toJSONString(map); + String responseBody = client.execute(httpPost, httpResponse -> EntityUtils.toString(httpResponse.getEntity())); + log.info("数据回调返回-->"); + log.info(responseBody); + StringEntity entity = new StringEntity(json); + httpPost.setEntity(entity); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + }catch (Exception e){ + log.error(e.getMessage(),e); + } + //SHUJU for (SysFile sysFile : fileList) { ImageRecognize vo = new ImageRecognize(); sysFile.setType(operaName); @@ -24,7 +70,37 @@ public class AlgorithmService { return list; } + /** + * + * @param fileList + * @param operaName + * @return + */ public List getImageRecognizeList(List fileList, String operaName) { + + try{ + List imageList=new ArrayList<>(); + for (SysFile sysFile : fileList) { + imageList.add(sysFile.getUrl()); + } + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(URL+IMAGE_RECOGNIZE); + Map map=new HashMap<>(); + map.put("images",imageList); + String json= JSON.toJSONString(map); + String responseBody = client.execute(httpPost, httpResponse -> EntityUtils.toString(httpResponse.getEntity())); + log.info("图像评估识别接口调用范湖-->"); + log.info(responseBody); + StringEntity entity = new StringEntity(json); + httpPost.setEntity(entity); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-type", "application/json"); + }catch (Exception e){ + log.error(e.getMessage(),e); + } + + + // List list=new ArrayList<>(); for (SysFile sysFile : fileList) { ImageRecognize vo = new ImageRecognize(); diff --git a/bonus-business/src/main/java/com/bonus/business/service/impl/ImageCaptionServiceImpl.java b/bonus-business/src/main/java/com/bonus/business/service/impl/ImageCaptionServiceImpl.java index 6be3a75..26fd5e9 100644 --- a/bonus-business/src/main/java/com/bonus/business/service/impl/ImageCaptionServiceImpl.java +++ b/bonus-business/src/main/java/com/bonus/business/service/impl/ImageCaptionServiceImpl.java @@ -71,7 +71,6 @@ public class ImageCaptionServiceImpl implements ImageCaptionService { if(result.isError()){ return result; } - //TODO 调用算法识别 ,然后进行图片更换 List list= algorithmService.getImageList(fileList,operaName); //更新标记的数量 和未标记的数量,同时更新 标记图片地址 updateImage(list,vo);