prod_cc/include/user_manager.hpp

213 lines
6.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IMS_USER_MANAGER_HPP
#define IMS_USER_MANAGER_HPP
#include "ims_types.hpp"
#include <memory>
#include <unordered_map>
#include <unordered_set>
namespace ims {
/// @brief 用户、角色、部门、权限、字典、参数统一管理类。
///
/// 负责组织架构与权限体系的核心逻辑,包括用户/角色/部门 CRUD、
/// 角色权限分配、菜单/按钮权限控制、数据权限过滤,
/// 以及数据字典和系统参数配置的维护。
class UserManager {
public:
UserManager();
~UserManager();
// ==================== 用户管理 (SRS-IMS_F-001) ====================
/**
* @brief 新增用户。
*
* @requirement(name="用户管理", id="SRS-IMS_F-001")
* 创建用户记录,密码需使用 BCrypt 加密存储。
*/
int64_t addUser(const User& user);
/**
* @brief 编辑用户信息。
*
* @requirement(name="用户管理", id="SRS-IMS_F-001")
* 根据 user_id 更新用户信息。
*/
bool updateUser(const User& user);
/**
* @brief 删除用户(逻辑删除)。
*
* @requirement(name="用户管理", id="SRS-IMS_F-001")
* 将用户状态标记为 DELETED。
*/
bool deleteUser(int64_t user_id);
/**
* @brief 查询用户(分页,支持模糊查询)。
*
* @requirement(name="用户管理", id="SRS-IMS_F-001")
* 支持按用户名、姓名、部门等条件组合查询。
*/
PageResult<User> findUsers(const std::string& keyword,
int64_t dept_id,
const PageRequest& page);
// ==================== 角色管理 (SRS-IMS_F-002) ====================
/**
* @brief 新增角色。
*
* @requirement(name="角色管理", id="SRS-IMS_F-002")
*/
int64_t addRole(const Role& role);
/**
* @brief 编辑角色。
*
* @requirement(name="角色管理", id="SRS-IMS_F-002")
*/
bool updateRole(const Role& role);
/**
* @brief 删除角色。
*
* @requirement(name="角色管理", id="SRS-IMS_F-002")
*/
bool deleteRole(int64_t role_id);
/**
* @brief 查询角色列表。
*
* @requirement(name="角色管理", id="SRS-IMS_F-002")
*/
std::vector<Role> findAllRoles();
// ==================== 部门管理 (SRS-IMS_F-003) ====================
/**
* @brief 新增部门。
*
* @requirement(name="部门管理", id="SRS-IMS_F-003")
*/
int64_t addDepartment(const Department& dept);
/**
* @brief 编辑部门。
*
* @requirement(name="部门管理", id="SRS-IMS_F-003")
*/
bool updateDepartment(const Department& dept);
/**
* @brief 删除部门。
*
* @requirement(name="部门管理", id="SRS-IMS_F-003")
*/
bool deleteDepartment(int64_t dept_id);
/**
* @brief 获取部门树形结构。
*
* @requirement(name="部门管理", id="SRS-IMS_F-003")
* 递归构建以 parent_id 为关联的树形结构。
*/
std::vector<Department> getDepartmentTree(int64_t parent_id);
// ==================== 字典管理 (SRS-IMS_F-004) ====================
/**
* @brief 添加字典项。
*
* @requirement(name="字典管理", id="SRS-IMS_F-004")
*/
void addDictItem(const DictItem& item);
/**
* @brief 根据字典类型获取字典列表。
*
* @requirement(name="字典管理", id="SRS-IMS_F-004")
*/
std::vector<DictItem> getDictByType(const std::string& dict_type);
/**
* @brief 删除字典项。
*
* @requirement(name="字典管理", id="SRS-IMS_F-004")
*/
bool removeDictItem(const std::string& dict_type, const std::string& item_key);
// ==================== 参数配置 (SRS-IMS_F-005) ====================
/**
* @brief 设置系统参数。
*
* @requirement(name="参数配置", id="SRS-IMS_F-005")
*/
void setParameter(const SysParam& param);
/**
* @brief 获取系统参数值。
*
* @requirement(name="参数配置", id="SRS-IMS_F-005")
*/
std::string getParameter(const std::string& param_key);
// ==================== 角色权限分配 (SRS-IMS_F-006) ====================
/**
* @brief 为角色分配权限(树形选择)。
*
* @requirement(name="角色权限分配", id="SRS-IMS_F-006")
* 将一组权限 ID 关联到指定的角色。
*/
bool assignPermissionsToRole(int64_t role_id,
const std::vector<int64_t>& perm_ids);
/**
* @brief 查询角色已拥有的权限。
*
* @requirement(name="角色权限分配", id="SRS-IMS_F-006")
*/
std::vector<Permission> getPermissionsByRole(int64_t role_id);
// ==================== 菜单权限管理 (SRS-IMS_F-007) ====================
/**
* @brief 根据用户角色获取动态菜单。
*
* @requirement(name="菜单权限管理", id="SRS-IMS_F-007")
* 返回该用户角色下所有 is_menu=true 的权限。
*/
std::vector<Permission> getMenuByUserId(int64_t user_id);
// ==================== 按钮权限管理 (SRS-IMS_F-008) ====================
/**
* @brief 检查用户是否拥有指定按钮权限。
*
* @requirement(name="按钮权限管理", id="SRS-IMS_F-008")
* 验证用户在所属角色下是否包含 perm_code按钮级
*/
bool hasButtonPermission(int64_t user_id, const std::string& perm_code);
// ==================== 数据权限分级管控 (SRS-IMS_F-009) ====================
/**
* @brief 根据用户数据权限范围过滤数据集。
*
* @requirement(name="数据权限分级管控", id="SRS-IMS_F-009")
* 根据用户所在部门及角色配置的数据范围,返回允许访问的部门 ID 集合。
*/
std::unordered_set<int64_t> getAccessibleDeptIds(int64_t user_id);
private:
struct Impl;
std::unique_ptr<Impl> pImpl_;
};
} // namespace ims
#endif // IMS_USER_MANAGER_HPP