package com.ruoyi.quartz.task; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.domain.CameraCmd; import com.ruoyi.device.camera.service.IArdCamerasService; import com.ruoyi.device.channel.domain.ArdChannel; import com.ruoyi.device.dhsdk.service.IDhClientService; import com.ruoyi.device.hiksdk.service.IHikClientService; import com.ruoyi.media.domain.Items; import com.ruoyi.media.domain.JsonsRoot; import com.ruoyi.media.domain.Vtdu; import com.ruoyi.media.service.IMediaService; import com.ruoyi.media.service.IVtduService; import com.ruoyi.rongcloud.service.RongCloudService; 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.List; /** * @Description: 同步任务 * @ClassName: syncDeviceStateTask * @Author: 刘苏义 * @Date: 2023年10月08日11:06:42 **/ @Component("SyncTask") @Slf4j public class SyncTask { @Resource ISysUserService sysUserService; @Resource RongCloudService rongCloudService; @Resource IArdCamerasService iArdCamerasService; @Resource IHikClientService hikClientService; @Resource IDhClientService dhClientService; @Resource IVtduService vtduService; @Resource IMediaService mediaService; /** * 同步相机在线状态 * 刘苏义 * 2023/10/8 14:54:41 */ public void cameraState() { try { ArdCameras ardCamera = new ArdCameras(); //调用查询方法 List ardCameras = iArdCamerasService.selectArdCamerasListNoDataScope(ardCamera); for (ArdCameras camera : ardCameras) { CameraCmd cmd = new CameraCmd(); cmd.setCameraId(camera.getId()); boolean onLineNew = false; // 判断是1还是2 if (camera.getFactory().equals("1")) { onLineNew = hikClientService.isOnLine(cmd); } else if (camera.getFactory().equals("2")) { onLineNew = dhClientService.isOnLine(cmd); } boolean onLineOld = "1".equals(camera.getState()); if (onLineNew != onLineOld) { if (onLineNew) { camera.setState("1"); } else { camera.setState("0"); } iArdCamerasService.updateArdCameras(camera); } } } catch (Exception ex) { log.error("同步相机在线状态异常:" + ex.getMessage()); } } /** * 定时获取app用户在线状态 * 刘苏义 * 2023/8/9 9:17:48 */ public void appUserState() { try { List SysUserList = sysUserService.selectAllAppUserList(new SysUser()); if (SysUserList.size() > 0) { for (SysUser sysUser : SysUserList) { String state = sysUser.getAppOnlineState();//获取当前用户的在线状态 Boolean online = rongCloudService.checkOnline(sysUser.getUserId());//从融云获取在线状态 if (state != null) { Boolean appOnlineState = state.equals("1"); if (appOnlineState == online) { continue; } } sysUser.setAppOnlineState(online ? "1" : "0"); sysUserService.updateUserProfile(sysUser); } } } catch (Exception ex) { log.error("融云在线接口异常:" + ex.getMessage()); } } /** * 同步流媒体 * 刘苏义 * 2023/10/13 14:13:53 */ public void vtdu() { List vtdus = vtduService.selectVtduList(new Vtdu()); for (Vtdu vtdu : vtdus) { boolean nameExist = mediaService.checkNameExist(vtdu.getName()); if (!nameExist) { mediaService.addPath(vtdu.getName(), vtdu.getRtspSource(), vtdu.getMode(), vtdu.getIsCode()); } } } }