|
@@ -50,260 +50,260 @@ import java.util.stream.Collectors;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class ShotPictureTaskExecutors {
|
|
public class ShotPictureTaskExecutors {
|
|
|
|
|
|
- @Value("${shot.storeAddress}")
|
|
|
|
- private String storeAddress;
|
|
|
|
-
|
|
|
|
- @Value("${shot.isMaster}")
|
|
|
|
- private Boolean isMaster;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Redis 缓存服务提供类
|
|
|
|
- */
|
|
|
|
- @Resource
|
|
|
|
- private RedisService redisService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- public RedisTemplate<String, String> redisTemplate;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private ISysDictTypeService iSysDictTypeService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private RedisPushService redisPushService;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private MsgAlarmMapper msgAlarmMapper;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private BaseCameraManagementMapper baseCameraManagementMapper;
|
|
|
|
-
|
|
|
|
- @Resource
|
|
|
|
- private BaseRailwayManagementMapper baseRailwayManagementMapper;
|
|
|
|
- @Autowired
|
|
|
|
- RedisCache redisCache;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * REDIS 抓拍摄像头分布式锁
|
|
|
|
- */
|
|
|
|
- private final static String LOCK_CAMELA_NORMAL_KEY = "lock_camela_normal";
|
|
|
|
-
|
|
|
|
- public static final String CAMERA_ALARM_HASH = "camera_alarm_hash";
|
|
|
|
- public static final String CAMERA_NORMAL_HASH = "camera_normal_hash";
|
|
|
|
-
|
|
|
|
- public final static AtomicInteger RUNNING_ATOMIC_INT = new AtomicInteger(0);
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 处理非预警摄像头截图, 间隔: 60s
|
|
|
|
- */
|
|
|
|
- @Async
|
|
|
|
- @Scheduled(fixedDelay = 60 * 1000, initialDelay = 3 * 1000)
|
|
|
|
- public synchronized void initCameraConfig() {
|
|
|
|
- if (!isMaster) return;
|
|
|
|
- // 获取分布式锁
|
|
|
|
- boolean lockSuccess = redisTemplate.opsForValue().setIfAbsent(LOCK_CAMELA_NORMAL_KEY, "execute", Duration.ofSeconds(60));
|
|
|
|
- if (lockSuccess) {
|
|
|
|
- // 查询未解除的报警摄像头(报警摄像头逻辑沿用wangyy代码)
|
|
|
|
- List<String> lockedMsgAlarmCameraCodes = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2))
|
|
|
|
- .stream().map(f -> f.getCameraCode()).distinct().collect(Collectors.toList());
|
|
|
|
- try {
|
|
|
|
- QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.select("distinct camera_code, channel,railway_code,install_mile");
|
|
|
|
- // 获取数据库中最新摄像头相关内容
|
|
|
|
- List<BaseCameraManagement> dbAlarms = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toList());
|
|
|
|
- List<BaseRailwayManagement> dbRailways = baseRailwayManagementMapper.selectList(null);
|
|
|
|
- //如果相机表不为空
|
|
|
|
- if (!CollectionUtils.isEmpty(dbAlarms)) {
|
|
|
|
- //循环线路集合
|
|
|
|
- for(BaseRailwayManagement dbRailway:dbRailways){
|
|
|
|
- //把线路名称和编码放入缓存
|
|
|
|
- redisCache.setCacheObject(dbRailway.getRailwayCode(),dbRailway.getRailwayName());
|
|
|
|
- }
|
|
|
|
- //获取缓存中的报警的相机数据
|
|
|
|
- Set<Object> hashAlarmKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_ALARM_HASH);
|
|
|
|
- //获取缓存中的非报警的相机数据
|
|
|
|
- Set<Object> hashNormalKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_NORMAL_HASH);
|
|
|
|
- // 数据库中存在的数据, 但是缓存中不存在, 则进行补全
|
|
|
|
- for (BaseCameraManagement dbAlarm : dbAlarms) {
|
|
|
|
- BaseCameraVO vo = new BaseCameraVO();
|
|
|
|
- vo.setCameraCode(dbAlarm.getCameraCode());
|
|
|
|
- vo.setChannel(dbAlarm.getChannel());
|
|
|
|
- vo.setInstallMiles(AppendUtils.stringAppend(dbAlarm.getInstallMile()));
|
|
|
|
- vo.setRailwayName(redisCache.getCacheObject(dbAlarm.getRailwayCode()));
|
|
|
|
- vo.setNextExecuteTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
- //如果未解除的报警摄像头集合包含该相机编码 且 缓存中的报警的相机数据不包含该相机
|
|
|
|
- if (lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashAlarmKeys.contains(vo.getCameraCode())) {
|
|
|
|
- vo.setIsAlarm(true);
|
|
|
|
- //把该相机相机信息放入报警相机缓存中
|
|
|
|
- redisService.addToHash(CAMERA_ALARM_HASH, vo.getCameraCode(), vo);
|
|
|
|
- //如果未解除的报警摄像头集合不包含该相机编码 且 缓存中的非报警的相机数据不包含该相机
|
|
|
|
- } else if (!lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashNormalKeys.contains(vo.getCameraCode())) {
|
|
|
|
- vo.setIsAlarm(false);
|
|
|
|
- //把该相机相机信息放入未报警相机缓存中
|
|
|
|
- redisService.addToHash(CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 循环redis缓存中获取的报警集合 排除缓存中未删除, 但是系统中删除的情况
|
|
|
|
- for (Object hashAlarmKey : hashAlarmKeys) {
|
|
|
|
- //如果报警信息数据库不存在但报警缓存中存在, 则进行删除
|
|
|
|
- if(!lockedMsgAlarmCameraCodes.contains(hashAlarmKey)){
|
|
|
|
- redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
|
|
|
|
- }
|
|
|
|
- // 如果在数据库和缓存中都不存在, 则进行删除删除
|
|
|
|
- if (!hashAlarmKeys.contains(hashAlarmKey) && !hashNormalKeys.contains(hashAlarmKey)) {
|
|
|
|
- redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
|
|
|
|
- redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
|
|
|
|
- } else if (hashAlarmKeys.contains(hashAlarmKey) && hashNormalKeys.contains(hashAlarmKey)) { // 如果两个缓存中都存在, 则删除正常摄像头
|
|
|
|
- redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- // 如果未找到数据库数据, 则清空抓图摄像头集合
|
|
|
|
- redisService.redisTemplate.delete(CAMERA_ALARM_HASH);
|
|
|
|
- redisService.redisTemplate.delete(CAMERA_NORMAL_HASH);
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("缓存 [摄像头抓图] 调度任务配置出现异常, ", e);
|
|
|
|
- } finally {
|
|
|
|
- redisTemplate.delete(LOCK_CAMELA_NORMAL_KEY);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 处理非预警摄像头截图, 间隔: 5s
|
|
|
|
- */
|
|
|
|
- @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
|
|
|
|
- public void batchProcess() {
|
|
|
|
- //如果截图开关是false直接返回
|
|
|
|
- if (!isMaster) return;
|
|
|
|
- // 填充默认路径
|
|
|
|
- String address = storeAddress;
|
|
|
|
- //获取截图开关
|
|
|
|
- Integer status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- //如果截图开关为空
|
|
|
|
- if(status == null){
|
|
|
|
- //从字典中获取
|
|
|
|
- List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
|
- if(CollectionUtils.isEmpty(dataList)){
|
|
|
|
- //不执行
|
|
|
|
- redisCache.setCacheObject("shot_switch",2);
|
|
|
|
- status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- }else{
|
|
|
|
- redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
|
|
|
|
- status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 判断开关是否执行
|
|
|
|
- if (status != 1) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- // 获取字典值: 截图存放路径
|
|
|
|
- List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
|
- //如果 截图存放路径为空
|
|
|
|
- if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
|
- //把截图存放路径放入缓存
|
|
|
|
- DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
|
|
|
|
- }
|
|
|
|
- //如果 截图存放路径不为空
|
|
|
|
- if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
|
- //截图存放路径赋值
|
|
|
|
- address = addressDataList.get(0).getDictLabel();
|
|
|
|
- }
|
|
|
|
- // 设置路径地址为字典表最终值 获取缓存中的非报警的相机数据
|
|
|
|
- Map<Object, Object> entries = redisService.redisTemplate.opsForHash().entries(CAMERA_NORMAL_HASH);
|
|
|
|
- //如果不为空
|
|
|
|
- if (!CollectionUtils.isEmpty(entries)) {
|
|
|
|
- //赋值截图存放路径
|
|
|
|
- final String finalAddress = address;
|
|
|
|
- //循环非报警的相机数据
|
|
|
|
- for (Map.Entry<Object, Object> entry : entries.entrySet()) {
|
|
|
|
- BaseCameraVO item = (BaseCameraVO) entry.getValue();
|
|
|
|
- //获取下次执行时间
|
|
|
|
- DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
- //如果下一个执行时间是否为null 或 当前时间大于或等于下一个执行时间 或 下次执行时间是否距离当前时间超过5分钟 并且 状态是否为 "running"
|
|
|
|
- boolean after = item.getNextExecuteTime() == null ||
|
|
|
|
- DateTime.now().isAfterOrEquals(nextExecuteTime) ||
|
|
|
|
- (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
|
|
|
|
- //下次执行时间 距离当前时间超过 5 分钟 并且
|
|
|
|
- //确保 item 的状态是 "running"。
|
|
|
|
- if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
- //把状态设置成空
|
|
|
|
- item.setStatus("");
|
|
|
|
- }
|
|
|
|
- // after是真并且状态是空 或者 状态等于complete
|
|
|
|
- if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
- Dict dict = new Dict();
|
|
|
|
- dict.put("cameraCode", item.getCameraCode());
|
|
|
|
- dict.put("channel", item.getChannel());
|
|
|
|
- dict.put("address", finalAddress);
|
|
|
|
- dict.put("railwayName", item.getRailwayName());
|
|
|
|
- dict.put("installMiles", item.getInstallMiles());
|
|
|
|
- dict.put("isAlarm", false);
|
|
|
|
- dict.put("nextExecuteTime", item.getNextExecuteTime());
|
|
|
|
- //调用方法
|
|
|
|
- redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 处理预警摄像头截图, 间隔: 1s
|
|
|
|
- */
|
|
|
|
- @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
|
|
|
|
- public void batchAlarmProcess() {
|
|
|
|
- if (!isMaster) return;
|
|
|
|
- // 填充默认路径
|
|
|
|
- String address = storeAddress;
|
|
|
|
- //获取截图开关
|
|
|
|
- Integer status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- if(status == null){
|
|
|
|
- List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
|
- if(CollectionUtils.isEmpty(dataList)){
|
|
|
|
- redisCache.setCacheObject("shot_switch",2);
|
|
|
|
- status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- }else{
|
|
|
|
- redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
|
|
|
|
- status = redisCache.getCacheObject("shot_switch");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 判断开关是否执行
|
|
|
|
- if (status != 1) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- // 获取字典值: 截图存放路径
|
|
|
|
- List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
|
- if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
|
- DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
|
|
|
|
- }
|
|
|
|
- if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
|
- address = addressDataList.get(0).getDictLabel();
|
|
|
|
- }
|
|
|
|
- Map<Object, Object> alarmEntries = redisService.redisTemplate.opsForHash().entries(CAMERA_ALARM_HASH);
|
|
|
|
- if (!CollectionUtils.isEmpty(alarmEntries)) {
|
|
|
|
- final String finalAddress = address;
|
|
|
|
- for (Map.Entry<Object, Object> entry : alarmEntries.entrySet()) {
|
|
|
|
- BaseCameraVO item = (BaseCameraVO) entry.getValue();
|
|
|
|
- DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
- boolean after = item.getNextExecuteTime() == null ||
|
|
|
|
- DateTime.now().isAfterOrEquals(nextExecuteTime) ||
|
|
|
|
- (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
|
|
|
|
- if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
- item.setStatus("");
|
|
|
|
- }
|
|
|
|
- if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
- Dict dict = new Dict();
|
|
|
|
- dict.put("cameraCode", item.getCameraCode());
|
|
|
|
- dict.put("channel", item.getChannel());
|
|
|
|
- dict.put("address", finalAddress);
|
|
|
|
- dict.put("railwayName", item.getRailwayName());
|
|
|
|
- dict.put("installMiles", item.getInstallMiles());
|
|
|
|
- dict.put("isAlarm", true);
|
|
|
|
- dict.put("nextExecuteTime", item.getNextExecuteTime());
|
|
|
|
- redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// @Value("${shot.storeAddress}")
|
|
|
|
+// private String storeAddress;
|
|
|
|
+//
|
|
|
|
+// @Value("${shot.isMaster}")
|
|
|
|
+// private Boolean isMaster;
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * Redis 缓存服务提供类
|
|
|
|
+// */
|
|
|
|
+// @Resource
|
|
|
|
+// private RedisService redisService;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// public RedisTemplate<String, String> redisTemplate;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private ISysDictTypeService iSysDictTypeService;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private RedisPushService redisPushService;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private MsgAlarmMapper msgAlarmMapper;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private BaseCameraManagementMapper baseCameraManagementMapper;
|
|
|
|
+//
|
|
|
|
+// @Resource
|
|
|
|
+// private BaseRailwayManagementMapper baseRailwayManagementMapper;
|
|
|
|
+// @Autowired
|
|
|
|
+// RedisCache redisCache;
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * REDIS 抓拍摄像头分布式锁
|
|
|
|
+// */
|
|
|
|
+// private final static String LOCK_CAMELA_NORMAL_KEY = "lock_camela_normal";
|
|
|
|
+//
|
|
|
|
+// public static final String CAMERA_ALARM_HASH = "camera_alarm_hash";
|
|
|
|
+// public static final String CAMERA_NORMAL_HASH = "camera_normal_hash";
|
|
|
|
+//
|
|
|
|
+// public final static AtomicInteger RUNNING_ATOMIC_INT = new AtomicInteger(0);
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 处理非预警摄像头截图, 间隔: 60s
|
|
|
|
+// */
|
|
|
|
+// @Async
|
|
|
|
+// @Scheduled(fixedDelay = 60 * 1000, initialDelay = 3 * 1000)
|
|
|
|
+// public synchronized void initCameraConfig() {
|
|
|
|
+// if (!isMaster) return;
|
|
|
|
+// // 获取分布式锁
|
|
|
|
+// boolean lockSuccess = redisTemplate.opsForValue().setIfAbsent(LOCK_CAMELA_NORMAL_KEY, "execute", Duration.ofSeconds(60));
|
|
|
|
+// if (lockSuccess) {
|
|
|
|
+// // 查询未解除的报警摄像头(报警摄像头逻辑沿用wangyy代码)
|
|
|
|
+// List<String> lockedMsgAlarmCameraCodes = msgAlarmMapper.selectList(new QueryWrapper<MsgAlarm>().eq("is_lock", 2))
|
|
|
|
+// .stream().map(f -> f.getCameraCode()).distinct().collect(Collectors.toList());
|
|
|
|
+// try {
|
|
|
|
+// QueryWrapper<BaseCameraManagement> queryWrapper = new QueryWrapper<>();
|
|
|
|
+// queryWrapper.select("distinct camera_code, channel,railway_code,install_mile");
|
|
|
|
+// // 获取数据库中最新摄像头相关内容
|
|
|
|
+// List<BaseCameraManagement> dbAlarms = baseCameraManagementMapper.selectList(queryWrapper).stream().collect(Collectors.toList());
|
|
|
|
+// List<BaseRailwayManagement> dbRailways = baseRailwayManagementMapper.selectList(null);
|
|
|
|
+// //如果相机表不为空
|
|
|
|
+// if (!CollectionUtils.isEmpty(dbAlarms)) {
|
|
|
|
+// //循环线路集合
|
|
|
|
+// for(BaseRailwayManagement dbRailway:dbRailways){
|
|
|
|
+// //把线路名称和编码放入缓存
|
|
|
|
+// redisCache.setCacheObject(dbRailway.getRailwayCode(),dbRailway.getRailwayName());
|
|
|
|
+// }
|
|
|
|
+// //获取缓存中的报警的相机数据
|
|
|
|
+// Set<Object> hashAlarmKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_ALARM_HASH);
|
|
|
|
+// //获取缓存中的非报警的相机数据
|
|
|
|
+// Set<Object> hashNormalKeys = redisService.redisTemplate.opsForHash().keys(CAMERA_NORMAL_HASH);
|
|
|
|
+// // 数据库中存在的数据, 但是缓存中不存在, 则进行补全
|
|
|
|
+// for (BaseCameraManagement dbAlarm : dbAlarms) {
|
|
|
|
+// BaseCameraVO vo = new BaseCameraVO();
|
|
|
|
+// vo.setCameraCode(dbAlarm.getCameraCode());
|
|
|
|
+// vo.setChannel(dbAlarm.getChannel());
|
|
|
|
+// vo.setInstallMiles(AppendUtils.stringAppend(dbAlarm.getInstallMile()));
|
|
|
|
+// vo.setRailwayName(redisCache.getCacheObject(dbAlarm.getRailwayCode()));
|
|
|
|
+// vo.setNextExecuteTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+// //如果未解除的报警摄像头集合包含该相机编码 且 缓存中的报警的相机数据不包含该相机
|
|
|
|
+// if (lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashAlarmKeys.contains(vo.getCameraCode())) {
|
|
|
|
+// vo.setIsAlarm(true);
|
|
|
|
+// //把该相机相机信息放入报警相机缓存中
|
|
|
|
+// redisService.addToHash(CAMERA_ALARM_HASH, vo.getCameraCode(), vo);
|
|
|
|
+// //如果未解除的报警摄像头集合不包含该相机编码 且 缓存中的非报警的相机数据不包含该相机
|
|
|
|
+// } else if (!lockedMsgAlarmCameraCodes.contains(vo.getCameraCode()) && !hashNormalKeys.contains(vo.getCameraCode())) {
|
|
|
|
+// vo.setIsAlarm(false);
|
|
|
|
+// //把该相机相机信息放入未报警相机缓存中
|
|
|
|
+// redisService.addToHash(CAMERA_NORMAL_HASH, vo.getCameraCode(), vo);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // 循环redis缓存中获取的报警集合 排除缓存中未删除, 但是系统中删除的情况
|
|
|
|
+// for (Object hashAlarmKey : hashAlarmKeys) {
|
|
|
|
+// //如果报警信息数据库不存在但报警缓存中存在, 则进行删除
|
|
|
|
+// if(!lockedMsgAlarmCameraCodes.contains(hashAlarmKey)){
|
|
|
|
+// redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
|
|
|
|
+// }
|
|
|
|
+// // 如果在数据库和缓存中都不存在, 则进行删除删除
|
|
|
|
+// if (!hashAlarmKeys.contains(hashAlarmKey) && !hashNormalKeys.contains(hashAlarmKey)) {
|
|
|
|
+// redisService.redisTemplate.opsForHash().delete(CAMERA_ALARM_HASH, hashAlarmKey);
|
|
|
|
+// redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
|
|
|
|
+// } else if (hashAlarmKeys.contains(hashAlarmKey) && hashNormalKeys.contains(hashAlarmKey)) { // 如果两个缓存中都存在, 则删除正常摄像头
|
|
|
|
+// redisService.redisTemplate.opsForHash().delete(CAMERA_NORMAL_HASH, hashAlarmKey);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// // 如果未找到数据库数据, 则清空抓图摄像头集合
|
|
|
|
+// redisService.redisTemplate.delete(CAMERA_ALARM_HASH);
|
|
|
|
+// redisService.redisTemplate.delete(CAMERA_NORMAL_HASH);
|
|
|
|
+// }
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
+// log.error("缓存 [摄像头抓图] 调度任务配置出现异常, ", e);
|
|
|
|
+// } finally {
|
|
|
|
+// redisTemplate.delete(LOCK_CAMELA_NORMAL_KEY);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 处理非预警摄像头截图, 间隔: 5s
|
|
|
|
+// */
|
|
|
|
+// @Scheduled(fixedDelay = 5 * 1000, initialDelay = 10 * 1000)
|
|
|
|
+// public void batchProcess() {
|
|
|
|
+// //如果截图开关是false直接返回
|
|
|
|
+// if (!isMaster) return;
|
|
|
|
+// // 填充默认路径
|
|
|
|
+// String address = storeAddress;
|
|
|
|
+// //获取截图开关
|
|
|
|
+// Integer status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// //如果截图开关为空
|
|
|
|
+// if(status == null){
|
|
|
|
+// //从字典中获取
|
|
|
|
+// List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
|
+// if(CollectionUtils.isEmpty(dataList)){
|
|
|
|
+// //不执行
|
|
|
|
+// redisCache.setCacheObject("shot_switch",2);
|
|
|
|
+// status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// }else{
|
|
|
|
+// redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
|
|
|
|
+// status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // 判断开关是否执行
|
|
|
|
+// if (status != 1) {
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+// // 获取字典值: 截图存放路径
|
|
|
|
+// List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
|
+// //如果 截图存放路径为空
|
|
|
|
+// if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
|
+// //把截图存放路径放入缓存
|
|
|
|
+// DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
|
|
|
|
+// }
|
|
|
|
+// //如果 截图存放路径不为空
|
|
|
|
+// if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
|
+// //截图存放路径赋值
|
|
|
|
+// address = addressDataList.get(0).getDictLabel();
|
|
|
|
+// }
|
|
|
|
+// // 设置路径地址为字典表最终值 获取缓存中的非报警的相机数据
|
|
|
|
+// Map<Object, Object> entries = redisService.redisTemplate.opsForHash().entries(CAMERA_NORMAL_HASH);
|
|
|
|
+// //如果不为空
|
|
|
|
+// if (!CollectionUtils.isEmpty(entries)) {
|
|
|
|
+// //赋值截图存放路径
|
|
|
|
+// final String finalAddress = address;
|
|
|
|
+// //循环非报警的相机数据
|
|
|
|
+// for (Map.Entry<Object, Object> entry : entries.entrySet()) {
|
|
|
|
+// BaseCameraVO item = (BaseCameraVO) entry.getValue();
|
|
|
|
+// //获取下次执行时间
|
|
|
|
+// DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
+// //如果下一个执行时间是否为null 或 当前时间大于或等于下一个执行时间 或 下次执行时间是否距离当前时间超过5分钟 并且 状态是否为 "running"
|
|
|
|
+// boolean after = item.getNextExecuteTime() == null ||
|
|
|
|
+// DateTime.now().isAfterOrEquals(nextExecuteTime) ||
|
|
|
|
+// (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
|
|
|
|
+// //下次执行时间 距离当前时间超过 5 分钟 并且
|
|
|
|
+// //确保 item 的状态是 "running"。
|
|
|
|
+// if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
+// //把状态设置成空
|
|
|
|
+// item.setStatus("");
|
|
|
|
+// }
|
|
|
|
+// // after是真并且状态是空 或者 状态等于complete
|
|
|
|
+// if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
+// Dict dict = new Dict();
|
|
|
|
+// dict.put("cameraCode", item.getCameraCode());
|
|
|
|
+// dict.put("channel", item.getChannel());
|
|
|
|
+// dict.put("address", finalAddress);
|
|
|
|
+// dict.put("railwayName", item.getRailwayName());
|
|
|
|
+// dict.put("installMiles", item.getInstallMiles());
|
|
|
|
+// dict.put("isAlarm", false);
|
|
|
|
+// dict.put("nextExecuteTime", item.getNextExecuteTime());
|
|
|
|
+// //调用方法
|
|
|
|
+// redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 处理预警摄像头截图, 间隔: 1s
|
|
|
|
+// */
|
|
|
|
+// @Scheduled(fixedDelay = 1 * 1000, initialDelay = 10 * 1000)
|
|
|
|
+// public void batchAlarmProcess() {
|
|
|
|
+// if (!isMaster) return;
|
|
|
|
+// // 填充默认路径
|
|
|
|
+// String address = storeAddress;
|
|
|
|
+// //获取截图开关
|
|
|
|
+// Integer status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// if(status == null){
|
|
|
|
+// List<SysDictData> dataList = iSysDictTypeService.selectDictDataByType("shot_switch");
|
|
|
|
+// if(CollectionUtils.isEmpty(dataList)){
|
|
|
|
+// redisCache.setCacheObject("shot_switch",2);
|
|
|
|
+// status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// }else{
|
|
|
|
+// redisCache.setCacheObject("shot_switch",dataList.get(0).getStatus());
|
|
|
|
+// status = redisCache.getCacheObject("shot_switch");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // 判断开关是否执行
|
|
|
|
+// if (status != 1) {
|
|
|
|
+// return;
|
|
|
|
+// }
|
|
|
|
+// // 获取字典值: 截图存放路径
|
|
|
|
+// List<SysDictData> addressDataList = DictUtils.getDictCache("shot_address");
|
|
|
|
+// if(CollectionUtils.isEmpty(addressDataList) || Objects.isNull(addressDataList.get(0))){
|
|
|
|
+// DictUtils.setDictCache("shot_address", addressDataList = iSysDictTypeService.selectDictDataByType("shot_address"));
|
|
|
|
+// }
|
|
|
|
+// if(!CollectionUtils.isEmpty(addressDataList) && Objects.nonNull(addressDataList.get(0))){
|
|
|
|
+// address = addressDataList.get(0).getDictLabel();
|
|
|
|
+// }
|
|
|
|
+// Map<Object, Object> alarmEntries = redisService.redisTemplate.opsForHash().entries(CAMERA_ALARM_HASH);
|
|
|
|
+// if (!CollectionUtils.isEmpty(alarmEntries)) {
|
|
|
|
+// final String finalAddress = address;
|
|
|
|
+// for (Map.Entry<Object, Object> entry : alarmEntries.entrySet()) {
|
|
|
|
+// BaseCameraVO item = (BaseCameraVO) entry.getValue();
|
|
|
|
+// DateTime nextExecuteTime = DateTime.of(item.getNextExecuteTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
|
+// boolean after = item.getNextExecuteTime() == null ||
|
|
|
|
+// DateTime.now().isAfterOrEquals(nextExecuteTime) ||
|
|
|
|
+// (nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()));
|
|
|
|
+// if ((nextExecuteTime.between(DateTime.now(), DateUnit.MINUTE) > 5 && "running".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
+// item.setStatus("");
|
|
|
|
+// }
|
|
|
|
+// if (after && (StringUtils.isBlank(item.getStatus()) || "complete".equalsIgnoreCase(item.getStatus()))) {
|
|
|
|
+// Dict dict = new Dict();
|
|
|
|
+// dict.put("cameraCode", item.getCameraCode());
|
|
|
|
+// dict.put("channel", item.getChannel());
|
|
|
|
+// dict.put("address", finalAddress);
|
|
|
|
+// dict.put("railwayName", item.getRailwayName());
|
|
|
|
+// dict.put("installMiles", item.getInstallMiles());
|
|
|
|
+// dict.put("isAlarm", true);
|
|
|
|
+// dict.put("nextExecuteTime", item.getNextExecuteTime());
|
|
|
|
+// redisPushService.pushMsg(JSONUtil.toJsonStr(dict));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
}
|
|
}
|