2025-10-23 14:38:20 +08:00
|
|
|
|
package com.ruoyi.cms.util;
|
|
|
|
|
|
|
2025-10-23 17:07:02 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.entity.AppUser;
|
2025-10-23 14:38:20 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
2025-10-23 17:07:02 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginSiteUser;
|
2025-10-23 14:38:20 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
2025-10-23 17:07:02 +08:00
|
|
|
|
import com.ruoyi.common.utils.SiteSecurityUtils;
|
2025-10-23 14:38:20 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断是否企业用户
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class RoleUtils {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 验证用户角色是否是企业用户
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static boolean isCompanyAdmin() {
|
|
|
|
|
|
// 先判断用户是否登录
|
|
|
|
|
|
if (!SecurityUtils.isLogin()) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取当前登录用户的角色列表,判断是否包含企业管理员角色ID
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
return loginUser.getUser().getRoles().stream()
|
|
|
|
|
|
.anyMatch(role -> StringUtil.COMPANY_ADMIN_ROLE_KEY.equals(role.getRoleId()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-23 17:07:02 +08:00
|
|
|
|
* 获取身份证或统一信用代码
|
2025-10-23 14:38:20 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getCurrentUseridCard() {
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); // 已包含登录校验
|
|
|
|
|
|
SysUser sysUser = loginUser.getUser();
|
|
|
|
|
|
if (sysUser == null) {
|
|
|
|
|
|
throw new IllegalArgumentException("用户信息为空,无法获取身份证号");
|
|
|
|
|
|
}
|
|
|
|
|
|
return sysUser.getIdCard();
|
|
|
|
|
|
}
|
2025-10-23 17:07:02 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取App用户身份证或统一信用代码
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String getAppCurrentUseridCard(){
|
|
|
|
|
|
if (!SiteSecurityUtils.isLogin()) {
|
2025-10-24 11:58:31 +08:00
|
|
|
|
return null;
|
2025-10-23 17:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LoginSiteUser loginSiteUser = SiteSecurityUtils.getLoginUser();
|
|
|
|
|
|
AppUser appUser = loginSiteUser.getUser();
|
|
|
|
|
|
if (appUser == null) {
|
|
|
|
|
|
throw new IllegalArgumentException("用户信息为空,无法获取身份证号"); // 用户信息为空仍抛异常,避免空指针
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ("0".equals(appUser.getIsCompanyUser())) {
|
|
|
|
|
|
return appUser.getIdCard();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-23 14:38:20 +08:00
|
|
|
|
}
|