添加第三方接口
This commit is contained in:
parent
51042138cf
commit
509bf73962
|
|
@ -32,7 +32,11 @@
|
|||
<version>1.6.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version> <!-- 使用最新版本 -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -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<ImageRecognize> getImageList(List<SysFile> fileList, String operaName) {
|
||||
List<ImageRecognize> list=new ArrayList<>();
|
||||
try{
|
||||
/**
|
||||
* 数据存储
|
||||
*/
|
||||
List<String> imageList=new ArrayList<>();
|
||||
for (SysFile sysFile : fileList) {
|
||||
imageList.add(sysFile.getUrl());
|
||||
}
|
||||
List<String> types= Arrays.asList(operaName.split(","));
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(URL+IMAGE_TYPE);
|
||||
Map<String ,Object> 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<ImageRecognize> getImageRecognizeList(List<SysFile> fileList, String operaName) {
|
||||
|
||||
try{
|
||||
List<String> imageList=new ArrayList<>();
|
||||
for (SysFile sysFile : fileList) {
|
||||
imageList.add(sysFile.getUrl());
|
||||
}
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(URL+IMAGE_RECOGNIZE);
|
||||
Map<String ,Object> 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<ImageRecognize> list=new ArrayList<>();
|
||||
for (SysFile sysFile : fileList) {
|
||||
ImageRecognize vo = new ImageRecognize();
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ public class ImageCaptionServiceImpl implements ImageCaptionService {
|
|||
if(result.isError()){
|
||||
return result;
|
||||
}
|
||||
//TODO 调用算法识别 ,然后进行图片更换
|
||||
List<ImageRecognize> list= algorithmService.getImageList(fileList,operaName);
|
||||
//更新标记的数量 和未标记的数量,同时更新 标记图片地址
|
||||
updateImage(list,vo);
|
||||
|
|
|
|||
Reference in New Issue