bmbp_auth/
bean.rs

1use bmbp_marco_bean::*;
2use crate::err::BmbpAuthResp;
3use serde::Deserialize;
4use serde::Serialize;
5use async_trait::async_trait;
6
7// 应用信息
8#[bean_option]
9pub struct BmbpApp {
10    id: Option<String>,
11    code: Option<String>,
12    name: Option<String>,
13    group: Option<String>,
14    status: Option<String>,
15    menus: Option<Vec<BmbpMenu>>,
16}
17
18// 应用目录
19#[bean_option]
20pub struct BmbpMenu {
21    app_code: Option<String>,
22    id: Option<String>,
23    code: Option<String>,
24    name: Option<String>,
25    name_path: Option<String>,
26    parent_code: Option<String>,
27    children: Option<Vec<BmbpMenu>>,
28    // 打开功能地址
29    open_url: Option<String>,
30    // 打开功能位置:
31    open_position: Option<String>,
32    // 打开功能的方式
33    open_type: Option<String>,
34    status: Option<String>,
35    extend_json: Option<String>,
36}
37
38// 组织信息
39#[bean_option]
40pub struct BmbpOrgan {
41    id: Option<String>,
42    code: Option<String>,
43    code_path: Option<String>,
44    name: Option<String>,
45    name_path: Option<String>,
46    parent_code: Option<String>,
47
48    typ_: Option<String>,
49    grade: Option<u32>,
50    children: Vec<BmbpOrgan>,
51
52    region_code: Option<String>,
53    region_name: Option<String>,
54}
55
56// 用户信息
57#[bean_option]
58pub struct BmbpUser {
59    id: Option<String>,
60    code: Option<String>,
61    name: Option<String>,
62    nick_name: Option<String>,
63    mobile: Option<String>,
64    email: Option<String>,
65
66    // 所属组织
67    organ: Option<BmbpOrgan>,
68    // 分配的应用
69    apps: Option<Vec<BmbpApp>>,
70    // 包含的菜单
71    menus: Option<Vec<BmbpMenu>>,
72    // 资源角色
73    res_roles: Option<Vec<BmbpRole>>,
74    // 数据权限
75    data_roles: Option<Vec<BmbpRole>>,
76}
77
78// 角色信息
79#[bean_option]
80pub struct BmbpRole {
81    code: Option<String>,
82    name: Option<String>,
83}
84
85#[bean_option]
86pub struct BmbpToken {
87    token: Option<String>,
88    refresh_token: Option<String>,
89    expire_at: Option<u32>,
90}
91
92#[async_trait]
93pub trait BmbpAuthUser: Sync + Send {
94    async fn get_current_info(&self) -> BmbpAuthResp<Option<BmbpUser>>;
95    async fn get_current_organ(&self) -> BmbpAuthResp<Option<BmbpOrgan>>;
96    async fn get_current_apps(&self) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
97    async fn get_current_menus(&self) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
98    async fn get_current_res_roles(&self) -> BmbpAuthResp<Option<Vec<BmbpRole>>>;
99    async fn get_current_data_roles(&self) -> BmbpAuthResp<Option<Vec<BmbpRole>>>;
100}
101#[async_trait]
102pub trait BmbpAuthToken: Sync + Send{
103    async fn create_token(&self, username: String, password: String) -> BmbpAuthResp<Option<BmbpToken>>;
104    async fn check_token(&self, token: String) -> BmbpAuthResp<Option<bool>>;
105    async fn refresh_token(&self, token: String) -> BmbpAuthResp<Option<BmbpToken>>;
106    async fn invalid_token(&self, token: String) -> BmbpAuthResp<Option<bool>>;
107    async fn remove_token(&self, token: String) -> BmbpAuthResp<Option<bool>>;
108    async fn get_token_info(&self, token: String) -> BmbpAuthResp<Option<BmbpToken>>;
109    async fn get_token_user(&self, token: String) -> BmbpAuthResp<Option<BmbpUser>>;
110}
111#[async_trait]
112pub trait BmbpAuth :Sync + Send{
113    async fn get_user_by_id(&self, id: String) -> BmbpAuthResp<Option<BmbpUser>>;
114    async fn get_user_by_name(&self, name: String) -> BmbpAuthResp<Option<BmbpUser>>;
115    async fn get_user_by_mobile(&self, mobile: String) -> BmbpAuthResp<Option<BmbpUser>>;
116    async fn get_users_by_organ_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpUser>>>;
117    async fn get_users_by_res_role_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpUser>>>;
118    async fn get_users_by_data_role_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpUser>>>;
119    async fn get_organ_organ_by_id(&self, id: String) -> BmbpAuthResp<Option<BmbpOrgan>>;
120    async fn get_organ_organ_by_code(&self, code: String) -> BmbpAuthResp<Option<BmbpOrgan>>;
121    async fn get_organ_organ_by_path(&self, path: String) -> BmbpAuthResp<Option<BmbpOrgan>>;
122    async fn get_organ_organs_by_parent_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
123    async fn get_organ_organs_by_parent_path(&self, path: String) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
124    async fn get_organ_organs_by_role_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
125    async fn get_organ_organ_tree(&self) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
126    async fn get_organ_organ_tree_by_start_id(&self, id: String) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
127    async fn get_organ_organ_tree_by_start_code(&self,
128                                                code: String,
129    ) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
130    async fn get_organ_organ_tree_by_start_path(&self,
131                                                path: String,
132    ) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
133    async fn get_organ_organ_tree_by_start_parent_id(&self,
134                                                     id: String,
135    ) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
136    async fn get_organ_organ_tree_by_start_parent_code(&self,
137                                                       code: String,
138    ) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
139    async fn get_organ_organ_tree_by_start_parent_path(&self,
140                                                       path: String,
141    ) -> BmbpAuthResp<Option<Vec<BmbpOrgan>>>;
142
143    async fn get_app_by_id(&self, id: String) -> BmbpAuthResp<Option<BmbpApp>>;
144    async fn get_app_by_code(&self, code: String) -> BmbpAuthResp<Option<BmbpApp>>;
145    async fn get_apps_by_user_id(&self, id: String) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
146    async fn get_apps_by_user_name(&self, name: String) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
147    async fn get_apps_by_user_mobile(&self, mobile: String) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
148    async fn get_apps_by_role_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
149    async fn get_apps_by_role_codes(&self, code: &[String]) -> BmbpAuthResp<Option<Vec<BmbpApp>>>;
150    async fn get_menu_by_id(&self, id: String) -> BmbpAuthResp<Option<BmbpMenu>>;
151    async fn get_menu_by_code(&self, code: String) -> BmbpAuthResp<Option<BmbpMenu>>;
152    async fn get_menu_by_path(&self, path: String) -> BmbpAuthResp<Option<BmbpMenu>>;
153    async fn get_menus_by_app_id(&self, id: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
154    async fn get_menus_by_app_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
155    async fn get_menus_by_app_ids(&self, id: &[String]) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
156    async fn get_menus_by_app_codes(&self, code: &[String]) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
157    async fn get_menus_by_user_id(&self, id: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
158    async fn get_menus_by_user_name(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
159    async fn get_menus_by_user_mobile(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
160    async fn get_menus_by_role_id(&self, id: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
161    async fn get_menus_by_role_code(&self, code: String) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
162    async fn get_menus_by_role_ids(&self, id: &[String]) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
163    async fn get_menus_by_role_codes(&self, code: &[String]) -> BmbpAuthResp<Option<Vec<BmbpMenu>>>;
164}