|
@@ -2,14 +2,17 @@ package com.ruoyi.common.utils;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.ruoyi.common.constant.HttpStatus;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 安全服务工具类
|
|
@@ -42,6 +45,31 @@ public class SecurityUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取关联公司列表
|
|
|
+ **/
|
|
|
+ public static List<Long> getCompanyIds() {
|
|
|
+ try {
|
|
|
+ SysUser user = getLoginUser().getUser();
|
|
|
+
|
|
|
+ List<Long> companySetArr;
|
|
|
+
|
|
|
+ //处理关联归属公司
|
|
|
+ String companySet = user.getCompanySet();
|
|
|
+ if (ObjectUtil.isEmpty(companySet)) {
|
|
|
+ companySetArr = new ArrayList<>();
|
|
|
+ } else {
|
|
|
+ companySetArr = Arrays.asList(companySet.split(","))
|
|
|
+ .stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ companySetArr.add(user.getCompanyId());//添加当前用户公司
|
|
|
+
|
|
|
+ return companySetArr;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("获取用户关联公司列表异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取部门ID
|
|
|
**/
|
|
|
public static Long getDeptId() {
|
|
@@ -69,7 +97,7 @@ public class SecurityUtils {
|
|
|
public static String getTenantId() {
|
|
|
try {
|
|
|
String tenantId = HOLDER_TENANT_ID.get();
|
|
|
- if(ObjectUtil.isNotEmpty(tenantId)){
|
|
|
+ if (ObjectUtil.isNotEmpty(tenantId)) {
|
|
|
return tenantId;
|
|
|
}
|
|
|
return getLoginUser().getUser().getTenantId();
|