| | |
| | | package com.ruoyi.quartz.task; |
| | | |
| | | import com.ruoyi.alarm.global.service.IGlobalAlarmService; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.device.camera.domain.ArdCameras; |
| | | import com.ruoyi.device.camera.domain.CameraCmd; |
| | | import com.ruoyi.device.hiksdk.common.GlobalVariable; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | import java.util.*; |
| | | import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | | /** |
| | | * @ClassName: AlarmTask |
| | | * @Description: 推送任务 |
| | | * @Author: Administrator |
| | | * @Date: 2023年03月06日 11:13 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Component("PushTask") |
| | | @Slf4j |
| | | public class PushTask { |
| | | |
| | | /** |
| | | * @描述 定时推送所有报警的点位数量 |
| | | * @参数 [] |
| | | * @返回值 void |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 15:43 |
| | | * @修改人和其它信息 |
| | | */ |
| | | public void globalAlarmCountPush() { |
| | | try { |
| | | IGlobalAlarmService globalAlarmService = SpringUtils.getBean(IGlobalAlarmService.class); |
| | | Map<String, Object> stringIntegerMap = globalAlarmService.selectAlarmLogsCount(); |
| | | if (ONLINE_USER_SESSIONS.size() > 0) { |
| | | WebSocketUtils.sendMessageAll(stringIntegerMap); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("推送报警的点位数量异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @描述 定时推送ptz |
| | | * @参数 [] |
| | | * @返回值 void |
| | | * @创建人 刘苏义 |
| | | * @创建时间 2023/6/15 15:43 |
| | | * @修改人和其它信息 |
| | | */ |
| | | public void ptzPush() { |
| | | try { |
| | | RedisCache redisCache = SpringUtils.getBean(RedisCache.class); |
| | | IHikClientService hikClientService = SpringUtils.getBean(IHikClientService.class); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | List<Object> Objects = redisCache.getListKey(CacheConstants.CAMERA_LIST_KEY); |
| | | if (Objects.size() > 0) { |
| | | for (Object obj : Objects) { |
| | | ArdCameras camera = (ArdCameras) obj; |
| | | if (!GlobalVariable.loginMap.containsKey(camera.getId()))//只推送首次登录成功的相机 |
| | | { |
| | | continue; |
| | | } |
| | | //推送大光电 |
| | | if(!"1".equals(camera.getGdtype())) |
| | | { |
| | | continue; |
| | | } |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(camera.getId()); |
| | | cmd.setChanNo(1); |
| | | cmd.setOperator(camera.getOperatorId()); |
| | | //推送在线的相机 |
| | | boolean onLine = hikClientService.isOnLine(cmd); |
| | | if(!onLine) |
| | | { |
| | | continue; |
| | | } |
| | | Map<String, Object> ptz = hikClientService.getGisInfo(cmd); |
| | | if (StringUtils.isNull(ptz)) { |
| | | continue; |
| | | } |
| | | SysUser sysUser = redisCache.getCacheObject(CacheConstants.USER_LIST_KEY + camera.getOperatorId()); |
| | | if (StringUtils.isNotNull(sysUser)) { |
| | | cmd.setOperatorZh(sysUser.getNickName()); |
| | | } else { |
| | | cmd.setOperatorZh(cmd.getOperator()); |
| | | } |
| | | |
| | | //获取时间差 |
| | | long secDatePoor = 0; |
| | | if (StringUtils.isNotNull(camera.getOperatorExpired())) { |
| | | secDatePoor = DateUtils.getSecDatePoor(camera.getOperatorExpired(), new Date()); |
| | | if (secDatePoor < 0) { |
| | | secDatePoor = 0; |
| | | } |
| | | } |
| | | |
| | | if (ptz.size() > 0) { |
| | | ptz.put("cameraId", cmd.getCameraId()); |
| | | ptz.put("usernameZh", cmd.getOperatorZh()); |
| | | ptz.put("operatorId", cmd.getOperator());//上锁用户id |
| | | ptz.put("expirationRemainingSecond", secDatePoor); |
| | | ptz.put("longitude",camera.getLongitude()); |
| | | ptz.put("latitude",camera.getLatitude()); |
| | | ptz.put("altitude",camera.getAltitude()); |
| | | list.add(ptz); |
| | | } |
| | | } |
| | | if (ONLINE_USER_SESSIONS.size() > 0) { |
| | | Map<String, Object> sendMap = new HashMap<>(); |
| | | sendMap.put("10000", list); |
| | | WebSocketUtils.sendMessageAll(sendMap); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("推送ptz异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | package com.ruoyi.quartz.task;
|
| | |
|
| | | import com.ruoyi.alarm.global.service.IGlobalAlarmService;
|
| | | import com.ruoyi.common.constant.CacheConstants;
|
| | | import com.ruoyi.common.core.domain.AjaxResult;
|
| | | import com.ruoyi.common.core.domain.entity.SysUser;
|
| | | import com.ruoyi.common.core.redis.RedisCache;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.device.camera.domain.ArdCameras;
|
| | | import com.ruoyi.device.camera.domain.CameraCmd;
|
| | | import com.ruoyi.device.camera.service.ICameraSdkService;
|
| | | import com.ruoyi.utils.sdk.common.GlobalVariable;
|
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils;
|
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import java.util.*;
|
| | |
|
| | | import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS;
|
| | |
|
| | | /**
|
| | | * @ClassName: AlarmTask
|
| | | * @Description: 推送任务
|
| | | * @Author: Administrator
|
| | | * @Date: 2023年03月06日 11:13
|
| | | * @Version: 1.0
|
| | | **/
|
| | | @Component("PushTask")
|
| | | @Slf4j
|
| | | public class PushTask {
|
| | |
|
| | | @Resource
|
| | | RedisCache redisCache;
|
| | | @Resource
|
| | | ICameraSdkService cameraSdkService;
|
| | | @Resource
|
| | | IGlobalAlarmService globalAlarmService;
|
| | |
|
| | | /**
|
| | | * @描述 定时推送所有报警的点位数量
|
| | | * @参数 []
|
| | | * @返回值 void
|
| | | * @创建人 刘苏义
|
| | | * @创建时间 2023/6/15 15:43
|
| | | * @修改人和其它信息
|
| | | */
|
| | | public void globalAlarmCountPush() {
|
| | | try {
|
| | | Map<String, Object> stringIntegerMap = globalAlarmService.selectAlarmLogsCount();
|
| | | if (ONLINE_USER_SESSIONS.size() > 0) {
|
| | | WebSocketUtils.sendMessageAll(stringIntegerMap);
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | log.error("推送报警的点位数量异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * @描述 定时推送ptz
|
| | | * @参数 []
|
| | | * @返回值 void
|
| | | * @创建人 刘苏义
|
| | | * @创建时间 2023/6/15 15:43
|
| | | * @修改人和其它信息
|
| | | */
|
| | | public void ptzPush() {
|
| | | try {
|
| | | if (ONLINE_USER_SESSIONS.size() > 0) {
|
| | | List<Map<String, Object>> list = new ArrayList<>();
|
| | | List<Object> Objects = redisCache.getListKey(CacheConstants.CAMERA_LIST_KEY);
|
| | | if (Objects.size() > 0) {
|
| | | for (Object obj : Objects) {
|
| | | ArdCameras camera = (ArdCameras) obj;
|
| | | if (!GlobalVariable.loginMap.containsKey(camera.getId()))//只推送首次登录成功的相机
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (!"1".equals(camera.getGdtype())) {
|
| | | continue;
|
| | | }
|
| | | CameraCmd cmd = new CameraCmd();
|
| | | cmd.setCameraId(camera.getId());
|
| | | cmd.setChanNo(1);
|
| | | cmd.setOperator(camera.getOperatorId());
|
| | | //推送在线的相机
|
| | | boolean onLine = cameraSdkService.isOnLine(cmd);
|
| | | if (!onLine) {
|
| | | continue;
|
| | | }
|
| | | AjaxResult ajaxResult = cameraSdkService.getGisInfo(cmd);
|
| | | Map<String, Object> ptz = (Map<String, Object>) ajaxResult.get("data");
|
| | | if (StringUtils.isNull(ptz)) {
|
| | | continue;
|
| | | }
|
| | | SysUser sysUser = redisCache.getCacheObject(CacheConstants.USER_LIST_KEY + camera.getOperatorId());
|
| | | if (StringUtils.isNotNull(sysUser)) {
|
| | | cmd.setOperatorZh(sysUser.getNickName());
|
| | | } else {
|
| | | cmd.setOperatorZh(cmd.getOperator());
|
| | | }
|
| | |
|
| | | //获取时间差
|
| | | long secDatePoor = 0;
|
| | | if (StringUtils.isNotNull(camera.getOperatorExpired())) {
|
| | | secDatePoor = DateUtils.getSecDatePoor(camera.getOperatorExpired(), new Date());
|
| | | if (secDatePoor < 0) {
|
| | | secDatePoor = 0;
|
| | | }
|
| | | }
|
| | |
|
| | | if (ptz.size() > 0) {
|
| | | ptz.put("cameraId", cmd.getCameraId());
|
| | | ptz.put("usernameZh", cmd.getOperatorZh());
|
| | | ptz.put("operatorId", cmd.getOperator());//上锁用户id
|
| | | ptz.put("expirationRemainingSecond", secDatePoor);
|
| | | ptz.put("longitude", camera.getLongitude());
|
| | | ptz.put("latitude", camera.getLatitude());
|
| | | ptz.put("altitude", camera.getAltitude());
|
| | | list.add(ptz);
|
| | | }
|
| | | }
|
| | | Map<String, Object> sendMap = new HashMap<>();
|
| | | sendMap.put("10000", list);
|
| | | WebSocketUtils.sendMessageAll(sendMap);
|
| | | }
|
| | | }
|
| | | } catch (Exception ex) {
|
| | | log.error("推送ptz异常:" + ex.getMessage());
|
| | | }
|
| | | }
|
| | | } |