|
|
@@ -8,6 +8,7 @@ import com.zd.alg.face.service.FaceService;
|
|
|
import com.zd.alg.face.utils.FileUtil;
|
|
|
import com.zd.algorithm.api.face.feign.FaceCompare;
|
|
|
import com.zd.common.core.utils.DateUtils;
|
|
|
+import com.zd.common.core.utils.SpringUtils;
|
|
|
import com.zd.common.core.utils.StringUtils;
|
|
|
import com.zd.common.swagger.config.Knife4jConfiguration;
|
|
|
import com.zd.laboratory.api.entity.LabStudentsInfo;
|
|
|
@@ -43,21 +44,18 @@ import java.util.stream.Collectors;
|
|
|
@RequestMapping("/faceApi")
|
|
|
public class FaceApi {
|
|
|
|
|
|
- private static final int taskSize = 50;
|
|
|
+ private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
|
|
|
|
|
|
- private static ExecutorService pool = Executors.newFixedThreadPool(taskSize);
|
|
|
-
|
|
|
-
|
|
|
- Logger logger = LoggerFactory.getLogger(FaceApi.class);
|
|
|
+ private Logger logger = LoggerFactory.getLogger(FaceApi.class);
|
|
|
|
|
|
@Autowired
|
|
|
- FaceService faceService;
|
|
|
+ private FaceService faceService;
|
|
|
|
|
|
@Autowired
|
|
|
- RemoteStudentsService remoteStudentsService;
|
|
|
+ private RemoteStudentsService remoteStudentsService;
|
|
|
|
|
|
@Autowired
|
|
|
- RemoteDutyService remoteDutyService;
|
|
|
+ private RemoteDutyService remoteDutyService;
|
|
|
|
|
|
|
|
|
@ApiOperation("根据照片文件获取特征码")
|
|
|
@@ -177,15 +175,16 @@ public class FaceApi {
|
|
|
@PostMapping("/multiCompare")
|
|
|
public ResultData multiFaceDetection(@RequestBody FaceCompare faceCompare) throws ExecutionException, InterruptedException {
|
|
|
logger.info("====人脸比较====");
|
|
|
- long time=System.currentTimeMillis();
|
|
|
ResultData<List<LabSysUserInfo>> infoList = remoteStudentsService.getFaceBySecuritySubjectId(faceCompare.getLabId());
|
|
|
+ long time=System.currentTimeMillis();
|
|
|
if(infoList.getCode() == 200 && infoList.getData() != null){
|
|
|
List<Future> list = Optional.ofNullable(infoList.getData()).orElseGet(Collections::emptyList)
|
|
|
.stream()
|
|
|
.map(a->{
|
|
|
- Future f = pool.submit(new Callable<Object>() {
|
|
|
+ Future f = scheduledExecutorService.submit(new Callable<Object>() {
|
|
|
@Override
|
|
|
public Object call() throws Exception {
|
|
|
+ logger.info("执行线程名称:"+Thread.currentThread().getName());
|
|
|
return getMultiFaceDetection(a,faceCompare);
|
|
|
}
|
|
|
});
|
|
|
@@ -196,11 +195,10 @@ public class FaceApi {
|
|
|
ResultData r=(ResultData)future.get();
|
|
|
if(r.getCode()==200){
|
|
|
long time2=System.currentTimeMillis();
|
|
|
- System.out.println("执行时间:"+(time2-time));
|
|
|
+ logger.info("多线程人脸对比执行时间:"+(time2-time));
|
|
|
return r;
|
|
|
}
|
|
|
}
|
|
|
- //pool.shutdown();
|
|
|
}
|
|
|
return ResultData.fail("未获取实验室安全准入人脸数据!");
|
|
|
}
|