Commit 48d1399f by 李乾广

[chg]更新特征库时,判断是否存在,不存在则新建特征库

1 parent 5f7a0854
...@@ -45,7 +45,14 @@ import org.springframework.stereotype.Service; ...@@ -45,7 +45,14 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -149,9 +156,12 @@ public class PersonService { ...@@ -149,9 +156,12 @@ public class PersonService {
String poolId = requestVo.getPoolId(); String poolId = requestVo.getPoolId();
log.info("人员修改操作开始,poolId:[{}],personId:[{}]", poolId, personId); log.info("人员修改操作开始,poolId:[{}],personId:[{}]", poolId, personId);
try { try {
if (!poolService.existPool(poolId)) {
poolService.createPool(requestVo, false);
}
BulkByScrollResponse bulkByScrollResponse = deletePerson(poolId, personId); BulkByScrollResponse bulkByScrollResponse = deletePerson(poolId, personId);
BulkResponse bulkItemResponses = addPerson(poolId, Collections.singletonList(person)); BulkResponse bulkItemResponses = addPerson(poolId, Collections.singletonList(person));
} catch (IOException e) { } catch (Exception e) {
log.error("人员修改操作异常", e); log.error("人员修改操作异常", e);
return ResponseVo.error(rid, "update failed"); return ResponseVo.error(rid, "update failed");
} }
......
...@@ -15,7 +15,11 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; ...@@ -15,7 +15,11 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.*; import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse; import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest; import org.elasticsearch.client.indices.GetIndexRequest;
...@@ -63,6 +67,10 @@ public class PoolService { ...@@ -63,6 +67,10 @@ public class PoolService {
* @throws Exception -- * @throws Exception --
*/ */
public ResponseVo createPool(RequestVo requestVo) throws Exception { public ResponseVo createPool(RequestVo requestVo) throws Exception {
return createPool(requestVo, true);
}
public ResponseVo createPool(RequestVo requestVo, boolean addPerson) throws Exception {
String rid = requestVo.getRid(); String rid = requestVo.getRid();
String poolId = requestVo.getPoolId(); String poolId = requestVo.getPoolId();
log.info("特征池创建操作开始:[{}}", poolId); log.info("特征池创建操作开始:[{}}", poolId);
...@@ -76,11 +84,13 @@ public class PoolService { ...@@ -76,11 +84,13 @@ public class PoolService {
createIndexRequest.settings(setting); createIndexRequest.settings(setting);
CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
List<Person> personPool = requestVo.getPersonPool(); if (addPerson) {
if (CollectionUtils.isNotEmpty(personPool)) { List<Person> personPool = requestVo.getPersonPool();
BulkResponse bulkItemResponses = personService.addPerson(poolId, personPool); if (CollectionUtils.isNotEmpty(personPool)) {
if (bulkItemResponses != null) { BulkResponse bulkItemResponses = personService.addPerson(poolId, personPool);
log.info(bulkItemResponses.buildFailureMessage()); if (bulkItemResponses != null) {
log.info(bulkItemResponses.buildFailureMessage());
}
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!