|
@@ -1,20 +1,25 @@
|
|
|
package com.fdkankan.scene.aop;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.SceneStatus;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.scene.annotation.CheckCurrentUser;
|
|
|
-import com.fdkankan.scene.entity.Camera;
|
|
|
-import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
-import com.fdkankan.scene.entity.ScenePro;
|
|
|
-import com.fdkankan.scene.service.ICameraService;
|
|
|
-import com.fdkankan.scene.service.ISceneCooperationService;
|
|
|
-import com.fdkankan.scene.service.ISceneProService;
|
|
|
+import com.fdkankan.scene.entity.*;
|
|
|
+import com.fdkankan.scene.service.*;
|
|
|
import com.fdkankan.web.user.SSOLoginHelper;
|
|
|
import com.fdkankan.web.user.SSOUser;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import com.fdkankan.web.util.WebUtil;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
@@ -44,6 +49,10 @@ public class CheckCurrenUserAspect {
|
|
|
|
|
|
@Autowired
|
|
|
private ISceneCooperationService sceneCooperationService;
|
|
|
+ @Autowired
|
|
|
+ private IUserRoleService userRoleService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
|
|
|
// Service层切点
|
|
|
@Pointcut("@annotation(com.fdkankan.scene.annotation.CheckCurrentUser)")
|
|
@@ -59,51 +68,110 @@ public class CheckCurrenUserAspect {
|
|
|
*/
|
|
|
@Before("checkUserAspect()")
|
|
|
public void doBefore(JoinPoint joinPoint) throws Exception {
|
|
|
- HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
|
|
- .getRequest();
|
|
|
+
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
// 读取session中的用户
|
|
|
- SSOUser user = ssoLoginHelper.loginCheckV3(request.getHeader("token"));
|
|
|
- String sceneNum = request.getParameter("sceneNum");
|
|
|
-
|
|
|
- ScenePro entity = sceneProService.findBySceneNum(sceneNum);
|
|
|
- if(user == null){
|
|
|
- log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
- log.info("不是当前用户的方法:"
|
|
|
- + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
- if("18750226207".equals(user.getUserName())){
|
|
|
- log.info("18750226207该账号默认超级管理员,可以操作所有场景");
|
|
|
+ ScenePro scenePro= sceneProService.findBySceneNum(num);
|
|
|
+ if(Objects.isNull(scenePro)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ //如果是计算中或者计算出错,返回计算中
|
|
|
+ if(SceneStatus.wait.code().equals(scenePro.getStatus())
|
|
|
+ || SceneStatus.FAILD.code().equals(scenePro.getStatus())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验场景用户是否与当前登录用户相同,相同则跳出
|
|
|
+ if(Objects.isNull(scenePro.getUserId())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
+ if(scenePro.getUserId().equals(user.getId())){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(user.getId() == null){
|
|
|
- Camera cameraEntity = cameraService.findByChildName(user.getUserName());
|
|
|
- if((cameraEntity != null && entity != null) && (cameraEntity.getId().longValue() != entity.getCameraId().longValue())){
|
|
|
- log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
- log.info("不是当前用户的方法:"
|
|
|
- + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
+ //如果上面场景用户与当前用户不匹配,需要校验当前用户是否拥有某些角色,从而可以访问此场景
|
|
|
+ List<UserRole> list = userRoleService.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
|
|
|
+ Set<Long> roleIdSet = null;
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ roleIdSet = list.stream().map(ur -> ur.getRoleId()).collect(Collectors.toSet());
|
|
|
}
|
|
|
- else if((user != null && entity != null) && entity.getUserId() != null && (user.getId().longValue() != entity.getUserId().longValue())){
|
|
|
- SceneCooperation sceneCooperation = sceneCooperationService.getByNum(sceneNum);
|
|
|
- if(Objects.nonNull(sceneCooperation)){
|
|
|
- if(sceneCooperation.getUserId().longValue() != user.getId().longValue()){
|
|
|
- log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
- log.info("不是当前用户的方法:"
|
|
|
- + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }
|
|
|
- }else {
|
|
|
- log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
- log.info("不是当前用户的方法:"
|
|
|
- + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
+ if(CollUtil.isEmpty(roleIdSet)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
+ //平台管理员拥有最高权限
|
|
|
+ if(roleIdSet.contains(5L)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断是否有公司管理者权限,有则放开
|
|
|
+ if(roleIdSet.contains(6L)){
|
|
|
+ //当前登录用户user
|
|
|
+ User currentUser = userService.getById(user.getId());
|
|
|
+ User sceneUser = userService.getById(scenePro.getUserId());
|
|
|
+ if(Objects.isNull(currentUser) || Objects.isNull(currentUser.getCompanyId())
|
|
|
+ || Objects.isNull(sceneUser) || Objects.isNull(sceneUser.getCompanyId())
|
|
|
+ || !currentUser.getCompanyId().equals(sceneUser.getCompanyId())){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
|
|
+// .getRequest();
|
|
|
+// // 读取session中的用户
|
|
|
+// SSOUser user = ssoLoginHelper.loginCheckV3(request.getHeader("token"));
|
|
|
+// String sceneNum = request.getParameter("sceneNum");
|
|
|
+//
|
|
|
+// ScenePro entity = sceneProService.findBySceneNum(sceneNum);
|
|
|
+// if(user == null){
|
|
|
+// log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
+// log.info("不是当前用户的方法:"
|
|
|
+// + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if("18750226207".equals(user.getUserName())){
|
|
|
+// log.info("18750226207该账号默认超级管理员,可以操作所有场景");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(user.getId() == null){
|
|
|
+// Camera cameraEntity = cameraService.findByChildName(user.getUserName());
|
|
|
+// if((cameraEntity != null && entity != null) && (cameraEntity.getId().longValue() != entity.getCameraId().longValue())){
|
|
|
+// log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
+// log.info("不是当前用户的方法:"
|
|
|
+// + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// else if((user != null && entity != null) && entity.getUserId() != null && (user.getId().longValue() != entity.getUserId().longValue())){
|
|
|
+// SceneCooperation sceneCooperation = sceneCooperationService.getByNum(sceneNum);
|
|
|
+// if(Objects.nonNull(sceneCooperation)){
|
|
|
+// if(sceneCooperation.getUserId().longValue() != user.getId().longValue()){
|
|
|
+// log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
+// log.info("不是当前用户的方法:"
|
|
|
+// + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// log.info(getCheckUserMthodDescription(joinPoint));
|
|
|
+// log.info("不是当前用户的方法:"
|
|
|
+// + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|