123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.iden.bms.schedule;
- import com.iden.bms.face.FaceIdenService;
- 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;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import javax.annotation.Resource;
- import java.util.UUID;
- /**
- * 定时读取目录下图片,调用人脸识别引擎,把特征码入库
- */
- @Configuration
- @EnableScheduling
- @EnableAsync
- public class FaceIdenSchedule {
- @Resource
- private FaceIdenService faceIdenService;
- @Resource
- private RedisUtil redisUtil;
- /**
- * 处理摄像头上传的图像
- */
- @Async
- @Scheduled(cron = "0 0/5 * * * ?")
- public void handleCameraImage() {
- String key = RedisKeyConstant.HANDLE_CAMERA_IMAGE;
- String requestId = UUID.randomUUID().toString();
- boolean result = redisUtil.tryLock(key,requestId,10 * 60);
- try {
- if (result) {
- faceIdenService.handleCameraImage();
- }
- } catch (Exception e) {
- e.getMessage();
- } finally {
- redisUtil.releaseLock(key,requestId);
- }
- }
- /**
- * 处理摄像头上传的视频
- */
- @Async
- @Scheduled(cron = "30 2/5 * * * ?")
- public void handleCameraVideo() {
- String key = RedisKeyConstant.HANDLE_CAMERA_VIDEO;
- String requestId = UUID.randomUUID().toString();
- boolean result = redisUtil.tryLock(key,requestId,10 * 60);
- try {
- if (result) {
- faceIdenService.handleCameraVideo();
- }
- } catch (Exception e) {
- e.getMessage();
- } finally {
- redisUtil.releaseLock(key,requestId);
- }
- }
- }
|