Commit 06c5932e by xmh

为feature添加属性,提供下载接口

1 parent cca6ea2d
...@@ -7,9 +7,13 @@ import com.viontech.label.platform.model.Pic; ...@@ -7,9 +7,13 @@ import com.viontech.label.platform.model.Pic;
import com.viontech.label.platform.service.adapter.PicService; import com.viontech.label.platform.service.adapter.PicService;
import com.viontech.label.platform.service.main.ReidService; import com.viontech.label.platform.service.main.ReidService;
import com.viontech.label.platform.vo.ReidUploadData; import com.viontech.label.platform.vo.ReidUploadData;
import org.apache.commons.io.FileUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*; import java.util.*;
/** /**
...@@ -151,7 +155,7 @@ public class ReidController { ...@@ -151,7 +155,7 @@ public class ReidController {
*/ */
@GetMapping("/getSimilarPerson") @GetMapping("/getSimilarPerson")
public Object getSimilarPerson(@RequestParam Long[] picIdArr, @RequestParam Long packId, @RequestParam Long size, @RequestParam(required = false) Integer timeInterval) { public Object getSimilarPerson(@RequestParam Long[] picIdArr, @RequestParam Long packId, @RequestParam Long size, @RequestParam(required = false) Integer timeInterval) {
Map<String, List<Pic>> similarPerson = reidService.getSimilarPerson(picIdArr, packId, size,timeInterval); Map<String, List<Pic>> similarPerson = reidService.getSimilarPerson(picIdArr, packId, size, timeInterval);
return JsonMessageUtil.getSuccessJsonMsg("success", similarPerson); return JsonMessageUtil.getSuccessJsonMsg("success", similarPerson);
} }
...@@ -189,4 +193,19 @@ public class ReidController { ...@@ -189,4 +193,19 @@ public class ReidController {
reidService.exitLabeling(personUnid, packId); reidService.exitLabeling(personUnid, packId);
return JsonMessageUtil.getSuccessJsonMsg("success"); return JsonMessageUtil.getSuccessJsonMsg("success");
} }
@GetMapping("downloadLabeledPicAsZip")
public void downloadLabeledPicAsZip(@RequestParam Long packId, HttpServletResponse response) throws Exception {
File file = reidService.downloadLabeledPicAsZip(packId);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Content-Disposition",
"attachment;filename=" + packId + ".zip");
FileUtils.copyFile(file, response.getOutputStream());
Thread.sleep(1000L);
boolean delete = file.delete();
if (!delete) {
file.deleteOnExit();
}
}
} }
...@@ -29,10 +29,14 @@ import org.springframework.stereotype.Service; ...@@ -29,10 +29,14 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* . * .
...@@ -338,7 +342,7 @@ public class ReidService { ...@@ -338,7 +342,7 @@ public class ReidService {
CompletableFuture<AlgResult> future = matchClient.matchPerson(2, person, reidPoolName, Collections.emptyList(), options); CompletableFuture<AlgResult> future = matchClient.matchPerson(2, person, reidPoolName, Collections.emptyList(), options);
AlgResult result = future.get(); AlgResult result = future.get();
List<Person> matchBodies = result.getMatchBodies(); List<Person> matchBodies = result.getMatchBodies();
List<String> personUnidList = matchBodies.stream().map(Person::getPersonId).filter(x -> !personUnidSet.contains(x)).collect(Collectors.toList()); List<String> personUnidList = matchBodies.stream().filter(x -> x.getScore() > 60F).map(Person::getPersonId).filter(x -> !personUnidSet.contains(x)).collect(Collectors.toList());
PicExample picExample = new PicExample(); PicExample picExample = new PicExample();
picExample.createCriteria().andPersonUnidIn(personUnidList); picExample.createCriteria().andPersonUnidIn(personUnidList);
...@@ -540,4 +544,34 @@ public class ReidService { ...@@ -540,4 +544,34 @@ public class ReidService {
return labelingSet.get(personUnid); return labelingSet.get(personUnid);
} }
public File downloadLabeledPicAsZip(Long packId) throws Exception {
File tempFile = File.createTempFile("label-" + packId, ".zip");
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(tempFile))) {
PicExample picExample = new PicExample();
picExample.createCriteria().andPackIdEqualTo(packId).andStatusEqualTo(PicStatus.FINISH_LABELING.val);
List<Pic> allPic = picService.selectByExample(picExample);
Map<String, List<Pic>> collect = allPic.stream().collect(Collectors.groupingBy(Pic::getPersonUnid, Collectors.toList()));
byte[] bytes;
for (Map.Entry<String, List<Pic>> entry : collect.entrySet()) {
String personUnid = entry.getKey();
List<Pic> pics = entry.getValue();
for (Pic pic : pics) {
try {
bytes = storageUtils.getFile(packId, pic.getName());
} catch (Exception e) {
log.error("打包文件时出错,packId:{},picId:{}", packId, pic.getId());
log.error("", e);
continue;
}
if (bytes != null) {
zipOutputStream.putNextEntry(new ZipEntry(personUnid + "/" + pic.getName()));
zipOutputStream.write(bytes);
}
}
}
}
return tempFile;
}
} }
...@@ -126,6 +126,7 @@ public class StorageUtils { ...@@ -126,6 +126,7 @@ public class StorageUtils {
public BodyFeature getBodyFeature(Long picId) { public BodyFeature getBodyFeature(Long picId) {
Feature featureByPic = getFeatureByPic(picId); Feature featureByPic = getFeatureByPic(picId);
PicVo pic = getPic(picId);
List<Data> datas = featureByPic.getDatas(); List<Data> datas = featureByPic.getDatas();
if (datas == null || datas.size() == 0) { if (datas == null || datas.size() == 0) {
return null; return null;
...@@ -135,7 +136,7 @@ public class StorageUtils { ...@@ -135,7 +136,7 @@ public class StorageUtils {
return null; return null;
} }
Double[] featureData = data.getData(); Double[] featureData = data.getData();
return new BodyFeature().setFeature(featureData).setBid(featureByPic.getFilename()); return new BodyFeature().setFeature(featureData).setBid(featureByPic.getFilename()).setCounttime(pic.getCreateTime());
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!