|
@@ -1,119 +1,119 @@
|
|
|
-package com.fdkankan.scene.Interceptor;
|
|
|
-
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.fdkankan.common.constant.CommonStatus;
|
|
|
-import com.fdkankan.common.constant.ErrorCode;
|
|
|
-import com.fdkankan.common.constant.PayStatus;
|
|
|
-import com.fdkankan.common.constant.SceneStatus;
|
|
|
-import com.fdkankan.common.exception.BusinessException;
|
|
|
-import com.fdkankan.redis.constant.RedisKey;
|
|
|
-import com.fdkankan.redis.util.RedisUtil;
|
|
|
-import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
-import com.fdkankan.scene.entity.ScenePlus;
|
|
|
-import com.fdkankan.scene.service.ISceneCooperationService;
|
|
|
-import com.fdkankan.scene.service.IScenePlusService;
|
|
|
-import com.fdkankan.web.user.SSOLoginHelper;
|
|
|
-import com.fdkankan.web.user.SSOUser;
|
|
|
-import com.fdkankan.web.util.WebUtil;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Objects;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import lombok.extern.log4j.Log4j2;
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.aspectj.lang.annotation.Before;
|
|
|
-import org.aspectj.lang.annotation.Pointcut;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.annotation.Order;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.context.request.RequestContextHolder;
|
|
|
-import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
-
|
|
|
-@Log4j2
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-@Order(101)
|
|
|
-public class CheckPermitAspect {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SSOLoginHelper ssoLoginHelper;
|
|
|
- @Autowired
|
|
|
- private RedisUtil redisUtil;
|
|
|
- @Autowired
|
|
|
- private IScenePlusService scenePlusService;
|
|
|
- @Autowired
|
|
|
- private ISceneCooperationService sceneCooperationService;
|
|
|
-
|
|
|
-
|
|
|
- @Pointcut("@annotation(com.fdkankan.scene.annotation.CheckPermit)")
|
|
|
- public void checkCooperationPermit() {
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 前置通知 用于判断用户协作场景是否有协作权限
|
|
|
- *
|
|
|
- * @param joinPoint
|
|
|
- * 切点
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- @Before("checkCooperationPermit()")
|
|
|
- public void doBefore(JoinPoint joinPoint) throws Exception {
|
|
|
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
- // 读取session中的用户
|
|
|
- SSOUser user = ssoLoginHelper.getSsoUser(request.getHeader("token"));
|
|
|
- if(Objects.isNull(user)){
|
|
|
- throw new BusinessException(ErrorCode.TOKEN_NOT_FOUND);
|
|
|
- }
|
|
|
- String num = WebUtil.getParameter("num", joinPoint, request);
|
|
|
- if(StrUtil.isEmpty(num)){
|
|
|
- throw new BusinessException(ErrorCode.PARAM_REQUIRED);
|
|
|
- }
|
|
|
-
|
|
|
- ScenePlus scenePlus= scenePlusService.getScenePlusByNum(num);
|
|
|
- if(Objects.isNull(scenePlus)){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
- }
|
|
|
- //如果是计算中或者计算出错,返回计算中
|
|
|
- if(SceneStatus.wait.code().equals(scenePlus.getSceneStatus())
|
|
|
- || SceneStatus.FAILD.code().equals(scenePlus.getSceneStatus())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
- }
|
|
|
- if(!PayStatus.PAY.code().equals(scenePlus.getPayStatus())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否相机登录,是否场景的相机id和相机登录的相机id是否相等,如果都满足,则放行,否则判定为用户登录
|
|
|
- if(Objects.nonNull(user.getCameraLogin())
|
|
|
- && CommonStatus.YES.code().byteValue() == user.getCameraLogin().intValue()){
|
|
|
- if(scenePlus.getCameraId().equals(user.getCameraId())){
|
|
|
- return;
|
|
|
- }else{
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //走到这里代表是用户账号密码登录,如果查到的场景的userid是空,证明相机解绑了,需要返回无权操作
|
|
|
- if(Objects.isNull(scenePlus.getUserId())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
-
|
|
|
- if(scenePlus.getUserId().equals(user.getId())){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //如果不是用户自己的场景,判断是否有协作权限
|
|
|
- Long userId = null;
|
|
|
- SceneCooperation sceneCooperation = sceneCooperationService.getByNum(num);
|
|
|
- if(Objects.nonNull(sceneCooperation)){
|
|
|
- userId = sceneCooperation.getUserId();
|
|
|
- }
|
|
|
-
|
|
|
- if(Objects.isNull(userId)){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
- if(!userId.equals(user.getId())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.fdkankan.scene.Interceptor;
|
|
|
+//
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import com.fdkankan.common.constant.CommonStatus;
|
|
|
+//import com.fdkankan.common.constant.ErrorCode;
|
|
|
+//import com.fdkankan.common.constant.PayStatus;
|
|
|
+//import com.fdkankan.common.constant.SceneStatus;
|
|
|
+//import com.fdkankan.common.exception.BusinessException;
|
|
|
+//import com.fdkankan.redis.constant.RedisKey;
|
|
|
+//import com.fdkankan.redis.util.RedisUtil;
|
|
|
+//import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
+//import com.fdkankan.scene.entity.ScenePlus;
|
|
|
+//import com.fdkankan.scene.service.ISceneCooperationService;
|
|
|
+//import com.fdkankan.scene.service.IScenePlusService;
|
|
|
+//import com.fdkankan.web.user.SSOLoginHelper;
|
|
|
+//import com.fdkankan.web.user.SSOUser;
|
|
|
+//import com.fdkankan.web.util.WebUtil;
|
|
|
+//import java.io.IOException;
|
|
|
+//import java.util.Objects;
|
|
|
+//import javax.servlet.http.HttpServletRequest;
|
|
|
+//import lombok.extern.log4j.Log4j2;
|
|
|
+//import org.aspectj.lang.JoinPoint;
|
|
|
+//import org.aspectj.lang.annotation.Aspect;
|
|
|
+//import org.aspectj.lang.annotation.Before;
|
|
|
+//import org.aspectj.lang.annotation.Pointcut;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.core.annotation.Order;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+//import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+//
|
|
|
+//@Log4j2
|
|
|
+//@Aspect
|
|
|
+//@Component
|
|
|
+//@Order(101)
|
|
|
+//public class CheckPermitAspect {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private SSOLoginHelper ssoLoginHelper;
|
|
|
+// @Autowired
|
|
|
+// private RedisUtil redisUtil;
|
|
|
+// @Autowired
|
|
|
+// private IScenePlusService scenePlusService;
|
|
|
+// @Autowired
|
|
|
+// private ISceneCooperationService sceneCooperationService;
|
|
|
+//
|
|
|
+//
|
|
|
+// @Pointcut("@annotation(com.fdkankan.scene.annotation.CheckPermit)")
|
|
|
+// public void checkCooperationPermit() {
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 前置通知 用于判断用户协作场景是否有协作权限
|
|
|
+// *
|
|
|
+// * @param joinPoint
|
|
|
+// * 切点
|
|
|
+// * @throws IOException
|
|
|
+// */
|
|
|
+// @Before("checkCooperationPermit()")
|
|
|
+// public void doBefore(JoinPoint joinPoint) throws Exception {
|
|
|
+// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+// // 读取session中的用户
|
|
|
+// SSOUser user = ssoLoginHelper.getSsoUser(request.getHeader("token"));
|
|
|
+// if(Objects.isNull(user)){
|
|
|
+// throw new BusinessException(ErrorCode.TOKEN_NOT_FOUND);
|
|
|
+// }
|
|
|
+// String num = WebUtil.getParameter("num", joinPoint, request);
|
|
|
+// if(StrUtil.isEmpty(num)){
|
|
|
+// throw new BusinessException(ErrorCode.PARAM_REQUIRED);
|
|
|
+// }
|
|
|
+//
|
|
|
+// ScenePlus scenePlus= scenePlusService.getScenePlusByNum(num);
|
|
|
+// if(Objects.isNull(scenePlus)){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+// }
|
|
|
+// //如果是计算中或者计算出错,返回计算中
|
|
|
+// if(SceneStatus.wait.code().equals(scenePlus.getSceneStatus())
|
|
|
+// || SceneStatus.FAILD.code().equals(scenePlus.getSceneStatus())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
+// }
|
|
|
+// if(!PayStatus.PAY.code().equals(scenePlus.getPayStatus())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //判断是否相机登录,是否场景的相机id和相机登录的相机id是否相等,如果都满足,则放行,否则判定为用户登录
|
|
|
+// if(Objects.nonNull(user.getCameraLogin())
|
|
|
+// && CommonStatus.YES.code().byteValue() == user.getCameraLogin().intValue()){
|
|
|
+// if(scenePlus.getCameraId().equals(user.getCameraId())){
|
|
|
+// return;
|
|
|
+// }else{
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //走到这里代表是用户账号密码登录,如果查到的场景的userid是空,证明相机解绑了,需要返回无权操作
|
|
|
+// if(Objects.isNull(scenePlus.getUserId())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(scenePlus.getUserId().equals(user.getId())){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //如果不是用户自己的场景,判断是否有协作权限
|
|
|
+// Long userId = null;
|
|
|
+// SceneCooperation sceneCooperation = sceneCooperationService.getByNum(num);
|
|
|
+// if(Objects.nonNull(sceneCooperation)){
|
|
|
+// userId = sceneCooperation.getUserId();
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(Objects.isNull(userId)){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// if(!userId.equals(user.getId())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|