Commit 2ab9c72a by xmh

添加特征时携带unid字段

1 parent 1bcd0c83
......@@ -118,7 +118,7 @@
<dependency>
<groupId>com.viontech.keliu</groupId>
<artifactId>AlgApiClient</artifactId>
<version>6.0.6</version>
<version>6.0.8-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>tomcat-websocket</artifactId>
......
......@@ -133,7 +133,7 @@ public class ReidService {
}
Feature feature = objectMapper.readValue(featureFileBytes, Feature.class);
Person person = new Person().setPersonId(data.getPersonUnid()).setBodyFeatures(getBodyFeatures(feature)).setCounttime(data.getCountTime());
Person person = new Person().setPersonId(data.getPersonUnid()).setBodyFeatures(getBodyFeatures(feature, data.getUnid())).setCounttime(data.getCountTime());
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.addPerson(poolName, Lists.newArrayList(person));
AlgResult result1 = future.get(20, TimeUnit.SECONDS);
log.info(result1.toString());
......@@ -188,6 +188,7 @@ public class ReidService {
if (bodyFeature == null) {
continue;
}
bodyFeature.setUnid(item.getUnid());
bodyFeatures.add(bodyFeature);
ids.add(item.getId());
}
......@@ -218,7 +219,7 @@ public class ReidService {
subTaskExample.createCriteria().andIdIn(Arrays.asList(subTaskIds));
List<SubTask> subTasks = subTaskService.selectByExample(subTaskExample);
Set<Long> picIdSet = subTasks.stream().map(SubTask::getPicId).collect(Collectors.toSet());
Map<Long, SubTask> map = subTasks.stream().collect(Collectors.toMap(SubTask::getPicId, x -> x, (a, b) -> a));
Set<String> originalPersonUnidSet = subTasks.stream().map(SubTask::getPersonUnid).collect(Collectors.toSet());
// 更新被合并的人的personUnid,然后添加到特征池中
......@@ -230,9 +231,14 @@ public class ReidService {
ArrayList<BodyFeature> bodyFeatures = new ArrayList<>();
Person person = new Person().setPersonId(newPersonUnid).setBodyFeatures(bodyFeatures);
for (Long picId : picIdSet) {
for (Map.Entry<Long, SubTask> entry : map.entrySet()) {
Long picId = entry.getKey();
BodyFeature bodyFeature = storageUtils.getBodyFeature(picId);
bodyFeatures.add(bodyFeature);
if (bodyFeature != null) {
bodyFeature.setUnid(entry.getValue().getUnid());
bodyFeatures.add(bodyFeature);
}
}
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.addPerson(poolName, Collections.singletonList(person));
future.get();
......@@ -255,13 +261,16 @@ public class ReidService {
person = new Person().setPersonId(personUnid).setBodyFeatures(bodyFeatures);
for (SubTask item : entry.getValue()) {
BodyFeature bodyFeature = storageUtils.getBodyFeature(item.getPicId());
bodyFeatures.add(bodyFeature);
if (bodyFeature != null) {
bodyFeature.setUnid(item.getUnid());
bodyFeatures.add(bodyFeature);
}
}
future = matchClient.EASY_PERSON_API.updatePerson(poolName, person);
future.get();
}
storageUtils.removePicCache(picIdSet.toArray(new Long[0]));
storageUtils.removePicCache(map.keySet().toArray(new Long[0]));
HashMap<String, Object> message = new HashMap<>(2);
message.put("personUnid", newPersonUnid);
......@@ -288,7 +297,7 @@ public class ReidService {
List<Long> subTaskIdList = Arrays.asList(subTaskIdArr);
List<SubTask> subTasks = subTaskService.getDataByIds(subTaskIdList);
Set<Long> picIdSet = subTasks.stream().map(SubTask::getPicId).collect(Collectors.toSet());
Map<Long, SubTask> map = subTasks.stream().collect(Collectors.toMap(SubTask::getPicId, x -> x, (a, b) -> a));
Set<String> originalPersonUnidSet = subTasks.stream().map(SubTask::getPersonUnid).collect(Collectors.toSet());
// 合并操作
......@@ -296,18 +305,23 @@ public class ReidService {
subTaskMapper.mergeTo(subTaskIdList, personUnid);
// 将对应 pic 的特征加入到特征池中
for (Long picId : picIdSet) {
List<BodyFeature> bodyFeatures = Collections.singletonList(storageUtils.getBodyFeature(picId));
Person person = new Person().setPersonId(personUnid).setBodyFeatures(bodyFeatures);
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.addPerson(poolName, Collections.singletonList(person));
future.get();
for (Map.Entry<Long, SubTask> entry : map.entrySet()) {
Long picId = entry.getKey();
BodyFeature bodyFeature = storageUtils.getBodyFeature(picId);
if (bodyFeature != null) {
bodyFeature.setUnid(entry.getValue().getUnid());
Person person = new Person().setPersonId(personUnid).setBodyFeatures(Collections.singletonList(bodyFeature));
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.addPerson(poolName, Collections.singletonList(person));
future.get();
}
}
// 更新pic对应的原来的person
for (String originalPersonUnid : originalPersonUnidSet) {
updatePoolByPersonUnid(originalPersonUnid, packId, poolName);
}
// 移除缓存
for (Long picId : picIdSet) {
for (Long picId : map.keySet()) {
storageUtils.removePicCache(picId);
}
// 合并后将 personUnid 放入到redis 的过滤列表中
......@@ -748,7 +762,7 @@ public class ReidService {
}
private List<BodyFeature> getBodyFeatures(Feature feature) {
private List<BodyFeature> getBodyFeatures(Feature feature, String unid) {
List<Data> datas = feature.getDatas();
if (datas == null || datas.size() == 0) {
return null;
......@@ -758,7 +772,7 @@ public class ReidService {
return null;
}
Double[] featureData = data.getData();
BodyFeature bodyFeature = new BodyFeature().setFeature(featureData).setBid(feature.getFilename());
BodyFeature bodyFeature = new BodyFeature().setFeature(featureData).setBid(feature.getFilename()).setUnid(unid);
return Collections.singletonList(bodyFeature);
}
......@@ -775,7 +789,10 @@ public class ReidService {
Person person = new Person().setPersonUnid(personUnid).setBodyFeatures(bodyFeatures);
for (SubTask item : subTasks) {
BodyFeature bodyFeature = storageUtils.getBodyFeature(item.getPicId());
bodyFeatures.add(bodyFeature);
if (bodyFeature != null) {
bodyFeature.setUnid(item.getUnid());
bodyFeatures.add(bodyFeature);
}
}
CompletableFuture<AlgResult> future = matchClient.EASY_PERSON_API.updatePerson(poolName, person);
future.get();
......@@ -911,7 +928,7 @@ public class ReidService {
if (featureByPic == null) {
continue;
}
Person person = new Person().setPersonId(personUnid).setCounttime(item.getCreateTime()).setBodyFeatures(getBodyFeatures(featureByPic));
Person person = new Person().setPersonId(personUnid).setCounttime(item.getCreateTime()).setBodyFeatures(getBodyFeatures(featureByPic, item.getUnid()));
people.add(person);
}
try {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!