| | |
| | | package com.ruoyi.quartz.task; |
| | | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.common.websocket.util.WebSocketUtils; |
| | |
| | | import com.ruoyi.device.hiksdk.common.GlobalVariable; |
| | | import com.ruoyi.device.hiksdk.service.IHikClientService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | import static com.ruoyi.common.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Component("SdkTask") |
| | | @Slf4j(topic = "hikSdk") |
| | | public class SdkTask { |
| | | |
| | | /** |
| | |
| | | * @修改人和其它信息 |
| | | */ |
| | | public void ptzPush() { |
| | | ISysUserService sysUserService = SpringUtils.getBean(ISysUserService.class); |
| | | IArdCamerasService ardCamerasService = SpringUtils.getBean(IArdCamerasService.class); |
| | | IHikClientService hikClientService = SpringUtils.getBean(IHikClientService.class); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | ArdCameras ardCameras = new ArdCameras(); |
| | | ardCameras.setGdtype("1"); |
| | | List<ArdCameras> ardCamerasList = ardCamerasService.selectArdCamerasListNoDataScope(ardCameras); |
| | | for (ArdCameras camera : ardCamerasList) { |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(camera.getId()); |
| | | cmd.setChannelNum(1); |
| | | cmd.setOperator(camera.getOperatorId()); |
| | | if (!GlobalVariable.loginMap.containsKey(camera.getId()))//只推送登录成功的相机 |
| | | { |
| | | continue; |
| | | } |
| | | Map<String, Object> ptz = hikClientService.getPtz(cmd); |
| | | if (StringUtils.isNull(ptz)) { |
| | | continue; |
| | | } |
| | | SysUser sysUser = sysUserService.selectUserById(camera.getOperatorId()); |
| | | if(StringUtils.isNotNull(sysUser)) |
| | | { |
| | | cmd.setOperatorZh(sysUser.getNickName()); |
| | | } |
| | | else |
| | | { |
| | | cmd.setOperatorZh(cmd.getOperator()); |
| | | } |
| | | try { |
| | | ISysUserService sysUserService = SpringUtils.getBean(ISysUserService.class); |
| | | IArdCamerasService ardCamerasService = SpringUtils.getBean(IArdCamerasService.class); |
| | | IHikClientService hikClientService = SpringUtils.getBean(IHikClientService.class); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | ArdCameras ardCameras = new ArdCameras(); |
| | | ardCameras.setGdtype("1"); |
| | | List<ArdCameras> ardCamerasList = ardCamerasService.selectArdCamerasListNoDataScope(ardCameras); |
| | | for (ArdCameras camera : ardCamerasList) { |
| | | CameraCmd cmd = new CameraCmd(); |
| | | cmd.setCameraId(camera.getId()); |
| | | cmd.setChannelNum(1); |
| | | cmd.setOperator(camera.getOperatorId()); |
| | | if (!GlobalVariable.loginMap.containsKey(camera.getId()))//只推送登录成功的相机 |
| | | { |
| | | continue; |
| | | } |
| | | Map<String, Object> ptz = hikClientService.getPtz(cmd); |
| | | if (StringUtils.isNull(ptz)) { |
| | | continue; |
| | | } |
| | | SysUser sysUser = sysUserService.selectUserById(camera.getOperatorId()); |
| | | if (StringUtils.isNotNull(sysUser)) { |
| | | cmd.setOperatorZh(sysUser.getNickName()); |
| | | } else { |
| | | cmd.setOperatorZh(cmd.getOperator()); |
| | | } |
| | | |
| | | if (ptz.size() > 0) { |
| | | ptz.put("cameraId", cmd.getCameraId()); |
| | | ptz.put("usernameZh",cmd.getOperatorZh()); |
| | | ptz.put("operatorId", cmd.getOperator());//上锁用户id |
| | | ptz.put("operatorExpired",camera.getOperatorExpired()); |
| | | list.add(ptz); |
| | | //获取时间差 |
| | | 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); |
| | | list.add(ptz); |
| | | } |
| | | } |
| | | if (ONLINE_USER_SESSIONS.size() > 0) { |
| | | Map<String, Object> sendMap = new HashMap<>(); |
| | | sendMap.put("10000", list); |
| | | WebSocketUtils.sendMessageAll(sendMap); |
| | | } |
| | | } |
| | | 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()); |
| | | } |
| | | } |
| | | } |