|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.entity.SysUser; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.model.LoginUser; | 
|---|
|  |  |  | import com.ruoyi.common.core.redis.RedisCache; | 
|---|
|  |  |  | import com.ruoyi.common.utils.DictUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.SecurityUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.StringUtils; | 
|---|
|  |  |  | import com.ruoyi.constant.sdkPriority; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.ArdCameras; | 
|---|
|  |  |  | import com.ruoyi.device.camera.domain.CameraCmd; | 
|---|
|  |  |  | import com.ruoyi.device.camera.service.IArdCamerasService; | 
|---|
|  |  |  | import com.ruoyi.system.service.ISysUserService; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.aspectj.lang.ProceedingJoinPoint; | 
|---|
|  |  |  | import org.aspectj.lang.annotation.Around; | 
|---|
|  |  |  | import org.aspectj.lang.annotation.Aspect; | 
|---|
|  |  |  | import org.aspectj.lang.annotation.Pointcut; | 
|---|
|  |  |  | import org.aspectj.lang.reflect.MethodSignature; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.lang.reflect.Method; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * SDK控制处理 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Aspect | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | @Slf4j(topic = "hikSdk") | 
|---|
|  |  |  | public class SdkOperateAspect { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Around("dsPointCut()") | 
|---|
|  |  |  | public Object around(ProceedingJoinPoint point) throws Throwable { | 
|---|
|  |  |  | Boolean resultMap = dataScopeFilter(point); | 
|---|
|  |  |  | if (resultMap) { | 
|---|
|  |  |  | MethodSignature signature = (MethodSignature) point.getSignature(); | 
|---|
|  |  |  | Method method = signature.getMethod(); | 
|---|
|  |  |  | Boolean result = controlScopeFilter(point); | 
|---|
|  |  |  | if (result) { | 
|---|
|  |  |  | log.debug("已获取相机控制权--" + method.getName()); | 
|---|
|  |  |  | return point.proceed(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.debug("未获取相机控制权--" + method.getName()); | 
|---|
|  |  |  | return false;//代替目标方法的返回值 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param joinPoint 切点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean dataScopeFilter(ProceedingJoinPoint joinPoint) { | 
|---|
|  |  |  | public Boolean controlScopeFilter(ProceedingJoinPoint joinPoint) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取请求控制相机的命令信息 | 
|---|
|  |  |  | CameraCmd cmd = (CameraCmd) joinPoint.getArgs()[0]; | 
|---|
|  |  |  | String operator = cmd.getOperator();//申请者 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Date currentExpired = ardCameras.getOperatorExpired();//当前相机的过期时间 | 
|---|
|  |  |  | String currentOperator = ardCameras.getOperatorId();//当前相机的操作者 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isEmpty(currentOperator)) { | 
|---|
|  |  |  | /*当前相机控制者为空时,直接更新控制者,并允许*/ | 
|---|
|  |  |  | /*先判断锁定时间*/ | 
|---|
|  |  |  | if (currentExpired == null) { | 
|---|
|  |  |  | /*如果未配置锁定时间,任何人可控制*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (operator.equals(currentOperator)) { | 
|---|
|  |  |  | /*判断申请者已经在控,直接允许*/ | 
|---|
|  |  |  | /*锁定时间配置了,判断当前操作者*/ | 
|---|
|  |  |  | if (StringUtils.isEmpty(currentOperator)) { | 
|---|
|  |  |  | /*当前相机控制者为空时,任何人可控*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Integer currentLevel = 0;//当前相机的操作者的优先级 | 
|---|
|  |  |  | if (sdkPriority.priorityMap.containsKey(currentOperator)) { | 
|---|
|  |  |  | /*当前控制者为系统报警用户*/ | 
|---|
|  |  |  | currentLevel = (Integer) sdkPriority.priorityMap.get(currentOperator); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*当前控制者为普通用户*/ | 
|---|
|  |  |  | SysUser sysUser = sysUserService.selectUserById(currentOperator); | 
|---|
|  |  |  | currentLevel = sysUser.getCameraPriority(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer operatorLevel = 0;//获取申请者的优先级 | 
|---|
|  |  |  | if (sdkPriority.priorityMap.containsKey(operator)) { | 
|---|
|  |  |  | /*包含说明当前申请控制者为系统报警用户*/ | 
|---|
|  |  |  | operatorLevel = (Integer) sdkPriority.priorityMap.get(operator); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*否则申请控制者为当前登录用户*/ | 
|---|
|  |  |  | LoginUser loginUser = SecurityUtils.getLoginUser(); | 
|---|
|  |  |  | SysUser user = loginUser.getUser();//获取登录用户的信息 | 
|---|
|  |  |  | operatorLevel = user.getCameraPriority(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*申请者未控则判断优先级*/ | 
|---|
|  |  |  | if (operatorLevel > currentLevel) { | 
|---|
|  |  |  | /*如果申请者优先级高,允许控制*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | /*判断是否本人继续控制*/ | 
|---|
|  |  |  | if (currentOperator.equals(operator)) { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*如果申请者优先级低,则判断过期时间*/ | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | if (currentExpired == null) { | 
|---|
|  |  |  | /*当前相机未配置过期时间,可控*/ | 
|---|
|  |  |  | /*当前相机有人控制并且配置了过期时间,先判断优先级,优先级高允许控制*/ | 
|---|
|  |  |  | Integer currentLevel = 0;//当前相机的操作者的优先级 | 
|---|
|  |  |  | String camerasPriority = DictUtils.getDictValue("cameras_priority", currentOperator); | 
|---|
|  |  |  | if(StringUtils.isNotEmpty(camerasPriority)) { | 
|---|
|  |  |  | /*当前控制者为系统报警用户*/ | 
|---|
|  |  |  | currentLevel = Integer.valueOf(camerasPriority); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*当前控制者为普通用户*/ | 
|---|
|  |  |  | SysUser sysUser = sysUserService.selectUserById(currentOperator); | 
|---|
|  |  |  | if(StringUtils.isNull(sysUser)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | currentLevel = Integer.valueOf(sysUser.getCameraPriority()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer operatorLevel = 0;//获取申请者的优先级 | 
|---|
|  |  |  | String operatorPriority = DictUtils.getDictValue("cameras_priority", operator); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(operatorPriority)) { | 
|---|
|  |  |  | /*包含说明当前申请控制者为系统报警用户*/ | 
|---|
|  |  |  | operatorLevel = Integer.valueOf(operatorPriority); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*否则申请控制者为当前登录用户*/ | 
|---|
|  |  |  | LoginUser loginUser = SecurityUtils.getLoginUser(); | 
|---|
|  |  |  | SysUser user = loginUser.getUser();//获取登录用户的信息 | 
|---|
|  |  |  | operatorLevel = Integer.valueOf(user.getCameraPriority()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*申请者未控则判断优先级*/ | 
|---|
|  |  |  | if (operatorLevel > currentLevel) { | 
|---|
|  |  |  | /*如果申请者优先级高,允许控制*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCameras.setOperatorExpired(null); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else { | 
|---|
|  |  |  | if (now.before(currentExpired)) { | 
|---|
|  |  |  | /*时间未过期,不可控*/ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*时间过期,可以控制,更新控制者*/ | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*如果申请者优先级低,则判断过期时间*/ | 
|---|
|  |  |  | if (currentExpired == null) { | 
|---|
|  |  |  | /*当前相机未配置过期时间,可控*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCameras.setOperatorExpired(null); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (new Date().before(currentExpired)) { | 
|---|
|  |  |  | /*时间未过期,不可控*/ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | /*时间过期,可以控制,更新控制者*/ | 
|---|
|  |  |  | ardCameras.setOperatorId(operator); | 
|---|
|  |  |  | ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者 | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|