|
@@ -6,10 +6,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.PayStatus;
|
|
|
import com.fdkankan.common.constant.SceneStatus;
|
|
|
+import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.scene.annotation.CheckCurrentUser;
|
|
|
import com.fdkankan.scene.entity.*;
|
|
|
+import com.fdkankan.scene.httpclient.MyClient;
|
|
|
import com.fdkankan.scene.service.*;
|
|
|
+import com.fdkankan.web.response.Result;
|
|
|
import com.fdkankan.web.user.SSOLoginHelper;
|
|
|
import com.fdkankan.web.user.SSOUser;
|
|
|
import java.io.IOException;
|
|
@@ -18,6 +21,7 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import com.fdkankan.web.util.WebUtil;
|
|
@@ -27,6 +31,7 @@ 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.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
@@ -41,6 +46,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
@Order(2)
|
|
|
public class CheckCurrenUserAspect {
|
|
|
|
|
|
+ @Value("${4dkk.manageService.basePath}")
|
|
|
+ private String manageServiceUrl;
|
|
|
+
|
|
|
+ @Value("${4dkk.manageService.api.checkEditPermission}")
|
|
|
+ private String checkEditPermissionApi;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ISceneProService sceneProService;
|
|
|
@Autowired
|
|
@@ -56,6 +67,8 @@ public class CheckCurrenUserAspect {
|
|
|
private IUserService userService;
|
|
|
@Autowired
|
|
|
private ICameraDetailService cameraDetailService;
|
|
|
+ @Resource
|
|
|
+ private MyClient myClient;
|
|
|
|
|
|
// Service层切点
|
|
|
@Pointcut("@annotation(com.fdkankan.scene.annotation.CheckCurrentUser)")
|
|
@@ -99,38 +112,50 @@ public class CheckCurrenUserAspect {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
|
|
|
}
|
|
|
|
|
|
- //如果上面场景用户与当前用户不匹配,需要校验当前用户是否拥有某些角色,从而可以访问此场景
|
|
|
- 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());
|
|
|
+ String url = this.manageServiceUrl.concat(this.checkEditPermissionApi);
|
|
|
+ String params = "sceneNum=" + num;
|
|
|
+ Result result = myClient.checkEditPermission(url, request.getHeader("token"), params);
|
|
|
+ int code = result.getCode();
|
|
|
+ if(code != 0){
|
|
|
+ throw new RuntimeException(ServerCode.SYSTEM_ERROR.message());
|
|
|
}
|
|
|
- if(CollUtil.isEmpty(roleIdSet)){
|
|
|
+ boolean permission = (boolean) result.getData();
|
|
|
+ if(!permission){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
}
|
|
|
- //平台管理员拥有最高权限
|
|
|
- if(roleIdSet.contains(5L)){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否有公司管理者权限,有则放开
|
|
|
- if(roleIdSet.contains(6L)){
|
|
|
- //当前登录用户user
|
|
|
- User currentUser = userService.getById(user.getId());
|
|
|
- CameraDetail cameraDetail = cameraDetailService.findByCameraId(scenePro.getCameraId());
|
|
|
- if(Objects.isNull(currentUser) || Objects.isNull(currentUser.getCompanyId())
|
|
|
- || Objects.isNull(cameraDetail) || Objects.isNull(cameraDetail.getCompanyId())
|
|
|
- || !currentUser.getCompanyId().equals(cameraDetail.getCompanyId())){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
- }else{
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- //校验场景用户是否与当前登录用户相同,相同则跳出
|
|
|
- if(Objects.isNull(scenePro.getUserId()) || !scenePro.getUserId().equals(user.getId())){
|
|
|
- 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());
|
|
|
+// }
|
|
|
+// 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());
|
|
|
+// CameraDetail cameraDetail = cameraDetailService.findByCameraId(scenePro.getCameraId());
|
|
|
+// if(Objects.isNull(currentUser) || Objects.isNull(currentUser.getCompanyId())
|
|
|
+// || Objects.isNull(cameraDetail) || Objects.isNull(cameraDetail.getCompanyId())
|
|
|
+// || !currentUser.getCompanyId().equals(cameraDetail.getCompanyId())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }else{
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //校验场景用户是否与当前登录用户相同,相同则跳出
|
|
|
+// if(Objects.isNull(scenePro.getUserId()) || !scenePro.getUserId().equals(user.getId())){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
/**
|