|
@@ -3,8 +3,6 @@ package com.rshy.project.hy.server;
|
|
|
import cn.hutool.cache.CacheUtil;
|
|
|
import cn.hutool.cache.impl.TimedCache;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
-import cn.hutool.core.date.DateUnit;
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
@@ -56,9 +54,10 @@ public class FaceRetrievaServer {
|
|
|
|
|
|
/**
|
|
|
* 创建缓存,默认15分钟过期
|
|
|
+ *
|
|
|
* @see <a href="https://www.hutool.cn/docs/#/cache/TimedCache">定时缓存</a>
|
|
|
*/
|
|
|
- private static TimedCache<String, String> timedCache = CacheUtil.newTimedCache(15 * 60 *1000);
|
|
|
+ private static TimedCache<String, String> timedCache = CacheUtil.newTimedCache(15 * 60 * 1000);
|
|
|
|
|
|
/**
|
|
|
* 登录接口
|
|
@@ -69,7 +68,7 @@ public class FaceRetrievaServer {
|
|
|
public RetrievaResultVO login(RetrievaLoginParam retrievaLoginParam) {
|
|
|
String body = timedCache.get(HEADERS_KEY, false);
|
|
|
|
|
|
- if(StrUtil.isEmpty(body)) {
|
|
|
+ if (StrUtil.isEmpty(body)) {
|
|
|
body = HttpUtil.post(loginUrl, JSON.toJSONString(retrievaLoginParam));
|
|
|
timedCache.put(HEADERS_KEY, body);
|
|
|
}
|
|
@@ -84,7 +83,7 @@ public class FaceRetrievaServer {
|
|
|
*/
|
|
|
public RetrievaResultVO repository(String sessionId) {
|
|
|
String body = timedCache.get(REPOSITORY_KEY, false);
|
|
|
- if(StrUtil.isEmpty(body)){
|
|
|
+ if (StrUtil.isEmpty(body)) {
|
|
|
body = HttpRequest.get(repositoryUrl).header(HEADERS_KEY, sessionId).execute().body();
|
|
|
//缓存一天失效
|
|
|
timedCache.put(REPOSITORY_KEY, body, 24 * 60 * 60 * 1000);
|
|
@@ -101,18 +100,21 @@ public class FaceRetrievaServer {
|
|
|
public RetrievaResultVO retrieval(String photo) {
|
|
|
RetrievaResultVO login = this.login(new RetrievaLoginParam().setName(name).setPassword(password));
|
|
|
log.info("依图 login: {}", login.toString());
|
|
|
- if(login.getRtn() != null && !login.getRtn().equals(0)){
|
|
|
+ if (login.getRtn() != null && !login.getRtn().equals(0)) {
|
|
|
throw new BaseException(login.getMessage());
|
|
|
}
|
|
|
|
|
|
RetrievaResultVO repository = this.repository(login.getSession_id());
|
|
|
- if(repository != null && !repository.getRtn().equals(0)){
|
|
|
+ if (repository != null && !repository.getRtn().equals(0)) {
|
|
|
throw new BaseException(repository.getMessage());
|
|
|
}
|
|
|
|
|
|
List<RepositoryVO> voList = Convert.toList(RepositoryVO.class, repository.getResults());
|
|
|
- RetrievalRepositoryParam param = new RetrievalRepositoryParam().setExtra_fields(Lists.newArrayList("custom_field_1")).setOrder(new OrderDTO().setSimilarity(-1))
|
|
|
- .setStart(0).setLimit(1).setRetrieval_query_id("1").setRetrieval(new RetrievalDTO().setPicture_image_content_base64(photo).setFast(true).setThreshold(threshold)
|
|
|
+ RetrievalRepositoryParam param = new RetrievalRepositoryParam() //.setExtra_fields(Lists.newArrayList("custom_field_1"))
|
|
|
+ .setOrder(new OrderDTO().setSimilarity(-1))
|
|
|
+ .setStart(0).setLimit(1)
|
|
|
+ //.setRetrieval_query_id("1")
|
|
|
+ .setRetrieval(new RetrievalDTO().setPicture_image_content_base64(photo).setFast(true).setThreshold(threshold)
|
|
|
.setRepository_ids(voList.stream().map(RepositoryVO::getId).collect(Collectors.toList())));
|
|
|
log.info("依图调用参数: {}", JSON.toJSONString(param));
|
|
|
String body = HttpRequest.post(retrievalUrl).header(HEADERS_KEY, login.getSession_id()).body(JSON.toJSONString(param)).execute().body();
|