|
|
@@ -0,0 +1,90 @@
|
|
|
+package com.ruoyi.framework.web.service;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 绩效管理系统权限服务
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ */
|
|
|
+@Component("pps")
|
|
|
+public class PerfPermissionService
|
|
|
+{
|
|
|
+ /** 所有权限前缀 */
|
|
|
+ private static final String ALL_PERMISSION = "*:*:*";
|
|
|
+ private static final String DEPT_ADMIN_ROLE = "dept_admin";
|
|
|
+ private static final String REVIEWER_ROLE = "reviewer";
|
|
|
+ private static final String SUPER_ADMIN_ROLE = "admin";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前用户是否有指定权限
|
|
|
+ */
|
|
|
+ public boolean hasPermi(String permission)
|
|
|
+ {
|
|
|
+ return SecurityUtils.hasPermi(permission);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前用户是否为院班子审核员
|
|
|
+ */
|
|
|
+ public boolean isReviewer()
|
|
|
+ {
|
|
|
+ return hasRole(REVIEWER_ROLE) || isAdmin();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前用户是否为部门管理员
|
|
|
+ */
|
|
|
+ public boolean isDeptAdmin()
|
|
|
+ {
|
|
|
+ return hasRole(DEPT_ADMIN_ROLE) || isAdmin();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前用户是否为系统管理员
|
|
|
+ */
|
|
|
+ public boolean isAdmin()
|
|
|
+ {
|
|
|
+ return hasRole(SUPER_ADMIN_ROLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断当前用户是否有权访问指定部门的数据
|
|
|
+ * 部门管理员只能访问本部门数据,院班子和系统管理员可访问所有数据
|
|
|
+ */
|
|
|
+ public boolean hasDeptAccess(Long deptId)
|
|
|
+ {
|
|
|
+ if (isReviewer() || isAdmin())
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ return user.getDeptId() != null && user.getDeptId().equals(deptId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前用户可访问的部门ID
|
|
|
+ * 返回null表示可访问所有部门
|
|
|
+ */
|
|
|
+ public Long getAccessibleDeptId()
|
|
|
+ {
|
|
|
+ if (isReviewer() || isAdmin())
|
|
|
+ {
|
|
|
+ return null; // 所有部门
|
|
|
+ }
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ return user.getDeptId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证用户是否具有指定角色
|
|
|
+ */
|
|
|
+ private boolean hasRole(String roleKey)
|
|
|
+ {
|
|
|
+ return SecurityUtils.getLoginUser().getUser().getRoles().stream()
|
|
|
+ .anyMatch(role -> roleKey.equals(role.getRoleKey()));
|
|
|
+ }
|
|
|
+}
|