Commit 2ab9c72a by xmh

添加特征时携带unid字段

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