‘liusuyi’
2023-05-25 c6eb731b0a70946e5ba265d9e5d427b8bb4537a6
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/SdkOperateAspect.java
@@ -4,14 +4,17 @@
import com.ruoyi.common.core.domain.model.LoginUser;
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 org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@@ -26,6 +29,8 @@
    @Resource
    IArdCamerasService ardCamerasService;
    @Resource
    ISysUserService sysUserService;
    @Pointcut("@annotation(com.ruoyi.common.annotation.SdkOperate)")
    public void dsPointCut() {
@@ -48,27 +53,74 @@
     * @param joinPoint 切点
     */
    public Boolean dataScopeFilter(ProceedingJoinPoint joinPoint) {
        //获取请求控制相机的信息
        //获取请求控制相机的命令信息
        CameraCmd cmd = (CameraCmd) joinPoint.getArgs()[0];
        String operator = cmd.getOperator();//申请者
        /*获取相机当前的被控信息*/
        ArdCameras ardCameras = ardCamerasService.selectArdCamerasById(cmd.getCameraId());
        if (StringUtils.isNull(ardCameras)) {
            return false;
        }
        //优先级比对
        Date operatorExpired = ardCameras.getOperatorExpired();
        Date now = new Date();
        if (now.before(operatorExpired)) {
            //未过期
        Date currentExpired = ardCameras.getOperatorExpired();//当前相机的过期时间
        String currentOperator = ardCameras.getOperatorId();//当前相机的操作者
            LoginUser loginUser = SecurityUtils.getLoginUser();
            if (StringUtils.isNull(loginUser)) {
                return false;//当前登录用户为空不可以控制
            }
            SysUser user = loginUser.getUser();
            if (!user.getUserId().equals(ardCameras.getOperatorId())) {
                return false;//未过期并且不是当前用户则不可控
        if (StringUtils.isEmpty(currentOperator)) {
            /*当前相机控制者为空时,直接更新控制者,并允许*/
            ardCameras.setOperatorId(operator);
            ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者
            return true;
        } else {
            if (operator.equals(currentOperator)) {
                /*判断申请者已经在控,直接允许*/
                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);//更新相机当前控制者
                    return true;
                } else {
                    /*如果申请者优先级低,则判断过期时间*/
                    Date now = new Date();
                    if (currentExpired == null) {
                        /*当前相机未配置过期时间,可控*/
                        ardCameras.setOperatorId(operator);
                        ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者
                        return true;
                    }
                    else {
                        if (now.before(currentExpired)) {
                            /*时间未过期,不可控*/
                            return false;
                        } else {
                            /*时间过期,可以控制,更新控制者*/
                            ardCameras.setOperatorId(operator);
                            ardCamerasService.updateArdCameras(ardCameras);//更新相机当前控制者
                            return true;
                        }
                    }
                }
            }
        }
        return true;
    }
}