Commit 6588593b by 姚冰

添加sendDataFromFile接口及相关实体

1 parent f2de590c
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,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.1.0-SNAPSHOT</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>tomcat-websocket</artifactId> <artifactId>tomcat-websocket</artifactId>
......
...@@ -26,6 +26,7 @@ public class VionConfig { ...@@ -26,6 +26,7 @@ public class VionConfig {
private String targetUrl; private String targetUrl;
private String keliuImageUrl; private String keliuImageUrl;
private String keliuImagePath; private String keliuImagePath;
private String featureUrl;
private static final ThreadPoolExecutor POOL_EXECUTOR = new ThreadPoolExecutor(20, 20, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(10000), new ThreadPoolExecutor.CallerRunsPolicy()); private static final ThreadPoolExecutor POOL_EXECUTOR = new ThreadPoolExecutor(20, 20, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(10000), new ThreadPoolExecutor.CallerRunsPolicy());
} }
...@@ -4,10 +4,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; ...@@ -4,10 +4,12 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.viontech.keliu.websocket.AlgApiClient;
import com.viontech.label.core.base.DateConverter; import com.viontech.label.core.base.DateConverter;
import com.viontech.label.tool.keliu.service.FileService; import com.viontech.label.tool.keliu.service.FileService;
import com.viontech.label.tool.keliu.service.LocalFileServiceImpl; import com.viontech.label.tool.keliu.service.LocalFileServiceImpl;
import com.viontech.label.tool.keliu.service.OnlineFileServiceImpl; import com.viontech.label.tool.keliu.service.OnlineFileServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -31,6 +33,9 @@ import java.util.Date; ...@@ -31,6 +33,9 @@ import java.util.Date;
*/ */
@Configuration @Configuration
public class WebConfig implements WebMvcConfigurer { public class WebConfig implements WebMvcConfigurer {
@Value("${vion.feature-url:}")
private String faceFeatureUrl;
@Bean @Bean
@Primary @Primary
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
...@@ -54,17 +59,23 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -54,17 +59,23 @@ public class WebConfig implements WebMvcConfigurer {
@Bean("fileService") @Bean("fileService")
@ConditionalOnProperty("vion.keliu-image-path") @ConditionalOnProperty(value = "vion.keliu-image-path")
public FileService localFileService() { public FileService localFileService() {
return new LocalFileServiceImpl(); return new LocalFileServiceImpl();
} }
@Bean("fileService") @Bean("fileService")
@ConditionalOnProperty("vion.keliu-image-url") @ConditionalOnProperty(value = "vion.keliu-image-url")
public FileService onlineFileService() { public FileService onlineFileService() {
return new OnlineFileServiceImpl(); return new OnlineFileServiceImpl();
} }
@Bean("algApiClientFeature")
@ConditionalOnProperty(value = "vion.feature-url")
public AlgApiClient algApiClientFeatureConfig() {
return new AlgApiClient(faceFeatureUrl);
}
@Configuration @Configuration
public static class CorsConfig { public static class CorsConfig {
@Bean @Bean
......
...@@ -3,9 +3,11 @@ package com.viontech.label.tool.keliu.controller; ...@@ -3,9 +3,11 @@ package com.viontech.label.tool.keliu.controller;
import com.viontech.keliu.util.DateUtil; import com.viontech.keliu.util.DateUtil;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import com.viontech.label.tool.keliu.config.VionConfig; import com.viontech.label.tool.keliu.config.VionConfig;
import com.viontech.label.tool.keliu.model.BodyRecognition;
import com.viontech.label.tool.keliu.model.FaceRecognition; import com.viontech.label.tool.keliu.model.FaceRecognition;
import com.viontech.label.tool.keliu.repository.KeliuRepository; import com.viontech.label.tool.keliu.repository.KeliuRepository;
import com.viontech.label.tool.keliu.service.FileService; import com.viontech.label.tool.keliu.service.FileService;
import com.viontech.label.tool.keliu.service.LocalFileServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.*; import org.springframework.http.*;
...@@ -18,6 +20,10 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -18,6 +20,10 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -59,7 +65,7 @@ public class KeliuController { ...@@ -59,7 +65,7 @@ public class KeliuController {
public Object sendData(@RequestParam Date date, @RequestParam Long mallId, @RequestParam Long packId, @RequestParam(required = false) Long taskId, public Object sendData(@RequestParam Date date, @RequestParam Long mallId, @RequestParam Long packId, @RequestParam(required = false) Long taskId,
@RequestParam(required = false, defaultValue = "-1,0,1") String direction, @RequestParam(required = false, defaultValue = "-1,0,1") String direction,
@RequestParam(required = false, defaultValue = "0,1") String personType, @RequestParam(required = false, defaultValue = "0,1") String personType,
@RequestParam(required = false,value = "deviceSerialNum") String deviceSerialNum, @RequestParam(required = false, value = "deviceSerialNum") String deviceSerialNum,
@RequestParam(required = false, value = "channelSerialNum") String channelSerialNum, @RequestParam(required = false, value = "channelSerialNum") String channelSerialNum,
@RequestParam(required = false, value = "startTime") Date startTime, @RequestParam(required = false, value = "startTime") Date startTime,
@RequestParam(required = false, value = "endTime") Date endTime @RequestParam(required = false, value = "endTime") Date endTime
...@@ -72,7 +78,7 @@ public class KeliuController { ...@@ -72,7 +78,7 @@ public class KeliuController {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(10000), new ThreadPoolExecutor.CallerRunsPolicy()); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(10000), new ThreadPoolExecutor.CallerRunsPolicy());
try { try {
AtomicLong count = new AtomicLong(); AtomicLong count = new AtomicLong();
List<FaceRecognition> faceRecognitions = keliuRepository.getFaceRecognitionsByDateAndMallId(date, mallId, direction, deviceSerialNum,personType, channelSerialNum, startTime, endTime); List<FaceRecognition> faceRecognitions = keliuRepository.getFaceRecognitionsByDateAndMallId(date, mallId, direction, deviceSerialNum, personType, channelSerialNum, startTime, endTime);
log.info("上传数据量:" + faceRecognitions.size()); log.info("上传数据量:" + faceRecognitions.size());
for (FaceRecognition faceRecognition : faceRecognitions) { for (FaceRecognition faceRecognition : faceRecognitions) {
Future<JsonMessageUtil.JsonMessage> submit = threadPoolExecutor.submit(() -> { Future<JsonMessageUtil.JsonMessage> submit = threadPoolExecutor.submit(() -> {
...@@ -149,4 +155,104 @@ public class KeliuController { ...@@ -149,4 +155,104 @@ public class KeliuController {
map.add("gateId", faceRecognition.getGateId()); map.add("gateId", faceRecognition.getGateId());
return new HttpEntity<>(map, headers); return new HttpEntity<>(map, headers);
} }
private HttpEntity<MultiValueMap<String, Object>> getBodyRequestEntity(BodyRecognition bodyRecognition, byte[] bodyPic, byte[] bodyFeature, Long packId, Long taskId, Date date) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
ByteArrayResource picResource = new ByteArrayResource(bodyPic) {
@Override
public String getFilename() {
return bodyRecognition.getBodyPic();
}
};
ByteArrayResource featureResource = new ByteArrayResource(bodyFeature) {
@Override
public String getFilename() {
return bodyRecognition.getBodyPic() + ".feature";
}
};
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("pic", picResource);
map.add("feature", featureResource);
map.add("unid", bodyRecognition.getUnid());
map.add("personUnid", bodyRecognition.getPersonUnid());
map.add("packId", packId);
map.add("taskId", taskId);
map.add("countTime", DateUtil.format("yyyy-MM-dd HH:mm:ss", date));
map.add("direction", bodyRecognition.getDirection());
map.add("gateId", bodyRecognition.getGateId());
return new HttpEntity<>(map, headers);
}
@GetMapping("/sendDataFromFile")
public Object sendDataFromFile(@RequestParam Date date, @RequestParam String pkgName, @RequestParam Long packId, @RequestParam(required = false) Long taskId,
@RequestParam(required = false, defaultValue = "-1,0,1") String direction,
@RequestParam(required = false, defaultValue = "0,1") String personType,
@RequestParam(required = false, value = "deviceSerialNum") String deviceSerialNum
) {
List<Future<JsonMessageUtil.JsonMessage>> responses = new LinkedList<>();
if (SEND_DATA) {
return JsonMessageUtil.getErrorJsonMsg("有数据传输任务正在进行");
} else {
SEND_DATA = true;
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(10000), new ThreadPoolExecutor.CallerRunsPolicy());
try {
AtomicLong count = new AtomicLong();
// List<FaceRecognition> faceRecognitions = keliuRepository.getFaceRecognitionsByDateAndMallId(date, mallId, direction, deviceSerialNum,personType, channelSerialNum, startTime, endTime);
List<BodyRecognition> bodyRecognitions = fileService.getFaceRecognition(pkgName, direction);
if (bodyRecognitions == null) {
return JsonMessageUtil.getSuccessJsonMsg("success:0;failed:0");
}
log.info("上传数据量:" + bodyRecognitions.size());
for (BodyRecognition bodyRecognition : bodyRecognitions) {
Future<JsonMessageUtil.JsonMessage> submit = threadPoolExecutor.submit(() -> {
try {
byte[] bodyPic = bodyRecognition.getBodyPicture();
byte[] bodyFeature = bodyRecognition.getBodyFeature();
HttpEntity<MultiValueMap<String, Object>> requestEntity = getBodyRequestEntity(bodyRecognition, bodyPic, bodyFeature, packId, taskId, date);
ResponseEntity<JsonMessageUtil.JsonMessage> exchange = restTemplate.exchange(vionConfig.getTargetUrl(), HttpMethod.POST, requestEntity, JsonMessageUtil.JsonMessage.class);
JsonMessageUtil.JsonMessage body = exchange.getBody();
log.info("unid:{},msg:{},count:{}/{}", bodyRecognition.getUnid(), body.getMsg(), count.incrementAndGet(), bodyRecognitions.size());
return body;
} catch (Exception e) {
log.info("", e);
return null;
}
});
responses.add(submit);
}
} finally {
while (threadPoolExecutor.getActiveCount() > 0) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
threadPoolExecutor.shutdown();
SEND_DATA = false;
}
}
long success = 0;
long failed = 0;
for (Future<JsonMessageUtil.JsonMessage> future : responses) {
try {
JsonMessageUtil.JsonMessage jsonMessage = future.get(20, TimeUnit.SECONDS);
if (jsonMessage == null || !jsonMessage.isSuccess()) {
failed++;
} else {
success++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return JsonMessageUtil.getSuccessJsonMsg("success:" + success + ";failed:" + failed);
}
} }
package com.viontech.label.tool.keliu.model;
import lombok.Data;
@Data
public class BodyRecognition {
private String personUnid;
private String unid;
private String direction;
private String bodyPic;
private String gateId;
byte[] bodyFeature;
byte[] bodyPicture;
}
package com.viontech.label.tool.keliu.model;
import lombok.Data;
@Data
public class ImageInfo {
private String imageName;
private Integer headX;
private Integer headY;
private Integer footX;
private Integer footY;
private Integer quadrant;
private Integer lefttopX;
private Integer lefttopY;
}
package com.viontech.label.tool.keliu.model;
import lombok.Data;
@Data
public class ROI {
int x;
int y;
int w;
int h;
}
package com.viontech.label.tool.keliu.service; package com.viontech.label.tool.keliu.service;
import com.viontech.label.tool.keliu.model.BodyRecognition;
import java.util.List;
/** /**
* . * .
* *
...@@ -10,4 +14,7 @@ public interface FileService { ...@@ -10,4 +14,7 @@ public interface FileService {
byte[] getFile(String filePath); byte[] getFile(String filePath);
List<String> getFileContent(String pkgName);
List<BodyRecognition> getFaceRecognition(String pkgName, String direction);
} }
package com.viontech.label.tool.keliu.service; package com.viontech.label.tool.keliu.service;
import com.viontech.label.tool.keliu.config.VionConfig; import com.viontech.label.tool.keliu.config.VionConfig;
import com.viontech.label.tool.keliu.model.BodyRecognition;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
/** /**
* . * .
...@@ -28,4 +30,14 @@ public class OnlineFileServiceImpl implements FileService { ...@@ -28,4 +30,14 @@ public class OnlineFileServiceImpl implements FileService {
public byte[] getFile(String filePath) { public byte[] getFile(String filePath) {
return restTemplate.getForObject(vionConfig.getKeliuImageUrl() + filePath, byte[].class); return restTemplate.getForObject(vionConfig.getKeliuImageUrl() + filePath, byte[].class);
} }
@Override
public List<String> getFileContent(String pkgName) {
return null;
}
@Override
public List<BodyRecognition> getFaceRecognition(String pkgName, String direction) {
return null;
}
} }
...@@ -9,14 +9,15 @@ spring.datasource.password=cdmqYwBq9uAdvLJb ...@@ -9,14 +9,15 @@ spring.datasource.password=cdmqYwBq9uAdvLJb
# redis # redis
spring.redis.host=127.0.0.1 spring.redis.host=127.0.0.1
spring.redis.port=6379 spring.redis.port=6379
spring.redis.password=vionredis spring.redis.password=
#temporary #temporary
logging.level.com.viontech.label.mapper=error logging.level.com.viontech.label.mapper=error
debug=false debug=false
vion.local-client=true vion.local-client=true
#vion.target-url=http://36.112.68.214:12100/reid/upload #vion.target-url=http://36.112.68.214:12100/reid/upload
vion.target-url=http://127.0.0.1:12100/reid/upload vion.target-url=http://127.0.0.1:12100/reid/upload
vion.keliu-image-url=https://vion-retail.oss-cn-beijing.aliyuncs.com/ #vion.keliu-image-url=https://vion-retail.oss-cn-beijing.aliyuncs.com/
#vion.keliu-image-path=/jason/VVAS/jingmao/ vion.keliu-image-path=/jason/VVAS/jingmao/
vion.keliu.dir=D:/Work/data
vion.feature-url=http://182.92.177.43:18500
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!