|
@@ -1,6 +1,8 @@
|
|
|
package com.iden.bms.face;
|
|
|
|
|
|
|
|
|
+import com.iden.common.cache.RedisKeyConstant;
|
|
|
+import com.iden.common.cache.RedisUtil;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
@@ -8,6 +10,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 定时读取目录下图片,调用人脸识别引擎,把特征码入库
|
|
@@ -19,7 +22,8 @@ public class FaceIdenSchedule {
|
|
|
|
|
|
@Resource
|
|
|
private FaceIdenService faceIdenService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
/**
|
|
|
* 处理摄像头上传的图像
|
|
@@ -27,10 +31,17 @@ public class FaceIdenSchedule {
|
|
|
@Async
|
|
|
@Scheduled(cron = "10 0/5 * * * ?")
|
|
|
public void handleCameraImage() {
|
|
|
+ String key = RedisKeyConstant.HANDLE_CAMERA_IMAGE;
|
|
|
+ String requestId = UUID.randomUUID().toString();
|
|
|
+ boolean result = redisUtil.tryLock(key,requestId,5 * 60);
|
|
|
try {
|
|
|
- faceIdenService.handleCameraImage();
|
|
|
+ if (result) {
|
|
|
+ faceIdenService.handleCameraImage();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.getMessage();
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(key,requestId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -41,11 +52,19 @@ public class FaceIdenSchedule {
|
|
|
@Async
|
|
|
@Scheduled(cron = "20 0/5 * * * ?")
|
|
|
public void handleCameraVideo() {
|
|
|
+ String key = RedisKeyConstant.HANDLE_CAMERA_VIDEO;
|
|
|
+ String requestId = UUID.randomUUID().toString();
|
|
|
+ boolean result = redisUtil.tryLock(key,requestId,5 * 60);
|
|
|
try {
|
|
|
- faceIdenService.handleCameraVideo();
|
|
|
+ if (result) {
|
|
|
+ faceIdenService.handleCameraVideo();
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.getMessage();
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(key,requestId);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|