bios-basic 0.2.0

An embeddable message queue system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
use crate::rbum::dto::rbum_domain_dto::RbumDomainSummaryResp;
use crate::rbum::dto::rbum_kind_dto::RbumKindSummaryResp;
use crate::rbum::dto::rbum_set_item_dto::RbumSetItemRelInfoResp;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tardis::basic::field::TrimString;
use tardis::chrono::{DateTime, Utc};

use tardis::db::sea_orm;

use tardis::web::poem_openapi;

use crate::rbum::rbum_enumeration::RbumScopeLevelKind;

/// Add request for resource set
///
/// 资源集添加请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumSetAddReq {
    /// Resource set code
    ///
    /// 资源集编码
    #[oai(validator(min_length = "2", max_length = "255"))]
    pub code: TrimString,
    /// Resource set kind
    ///
    /// 资源集类型
    #[oai(validator(min_length = "2", max_length = "255"))]
    pub kind: TrimString,
    /// Resource set name
    ///
    /// 资源集名称
    #[oai(validator(min_length = "2", max_length = "255"))]
    pub name: TrimString,
    /// Resource set note
    ///
    /// 资源集备注
    #[oai(validator(min_length = "2", max_length = "2000"))]
    pub note: Option<String>,
    /// Resource set icon
    ///
    /// 资源集图标
    #[oai(validator(min_length = "2", max_length = "1000"))]
    pub icon: Option<String>,
    /// Resource set sort
    ///
    /// 资源集排序
    pub sort: Option<i64>,
    /// Resource set extension information
    ///
    /// 资源集扩展信息
    #[oai(validator(min_length = "2", max_length = "1000"))]
    pub ext: Option<String>,

    pub scope_level: Option<RbumScopeLevelKind>,
    pub disabled: Option<bool>,
}

/// Modify request for resource set
///
/// 资源集修改请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
pub struct RbumSetModifyReq {
    /// Resource set name
    ///
    /// 资源集名称
    #[oai(validator(min_length = "2", max_length = "255"))]
    pub name: Option<TrimString>,
    /// Resource set note
    ///
    /// 资源集备注
    #[oai(validator(min_length = "2", max_length = "2000"))]
    pub note: Option<String>,
    /// Resource set icon
    ///
    /// 资源集图标
    #[oai(validator(min_length = "2", max_length = "1000"))]
    pub icon: Option<String>,
    /// Resource set sort
    ///
    /// 资源集排序
    pub sort: Option<i64>,
    /// Resource set extension information
    ///
    /// 资源集扩展信息
    #[oai(validator(min_length = "2", max_length = "1000"))]
    pub ext: Option<String>,

    pub scope_level: Option<RbumScopeLevelKind>,
    pub disabled: Option<bool>,
}

/// Resource set summary information
///
/// 资源集概要信息
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
pub struct RbumSetSummaryResp {
    /// Resource set id
    ///
    /// 资源集id
    pub id: String,
    /// Resource set code
    ///
    /// 资源集编码
    pub code: String,
    /// Resource set kind
    ///
    /// 资源集类型
    pub kind: String,
    /// Resource set name
    ///
    /// 资源集名称
    pub name: String,
    /// Resource set icon
    ///
    /// 资源集图标
    pub icon: String,
    /// Resource set sort
    ///
    /// 资源集排序
    pub sort: i64,
    /// Resource set extension information
    ///
    /// 资源集扩展信息
    pub ext: String,

    pub own_paths: String,
    pub owner: String,
    pub create_time: DateTime<Utc>,
    pub update_time: DateTime<Utc>,

    pub scope_level: RbumScopeLevelKind,
    pub disabled: bool,
}

/// Resource set detail information
///
/// 资源集详细信息
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
pub struct RbumSetDetailResp {
    /// Resource set id
    ///
    /// 资源集id
    pub id: String,
    /// Resource set code
    ///
    /// 资源集编码
    pub code: String,
    /// Resource set kind
    ///
    /// 资源集类型
    pub kind: String,
    /// Resource set name
    ///
    /// 资源集名称
    pub name: String,
    /// Resource set note
    ///
    /// 资源集备注
    pub note: String,
    /// Resource set icon
    ///
    /// 资源集图标
    pub icon: String,
    /// Resource set sort
    ///
    /// 资源集排序
    pub sort: i64,
    /// Resource set extension information
    ///
    /// 资源集扩展信息
    pub ext: String,

    pub own_paths: String,
    pub owner: String,
    pub owner_name: Option<String>,
    pub create_time: DateTime<Utc>,
    pub update_time: DateTime<Utc>,

    pub scope_level: RbumScopeLevelKind,
    pub disabled: bool,
}

/// Resource set path information
///
/// 资源集路径信息
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
pub struct RbumSetPathResp {
    /// Node id
    ///
    /// 节点id
    pub id: String,
    /// Node name
    ///
    /// 节点名称
    pub name: String,

    pub own_paths: String,
}

/// Resource tree information
///
/// 资源树信息
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct RbumSetTreeResp {
    /// Resource tree node information
    ///
    /// 资源树节点信息
    pub main: Vec<RbumSetTreeNodeResp>,
    /// Resource tree extension information
    ///
    /// 资源树扩展信息
    pub ext: Option<RbumSetTreeExtResp>,
}

impl RbumSetTreeResp {
    pub fn to_trees(&self) -> RbumSetTreeCateResp {
        let mut nodes_map: HashMap<String, RbumSetTreeCateNodeResp> = HashMap::new();
        let mut child_map: HashMap<String, Vec<String>> = HashMap::new();
        let mut roots: Vec<String> = Vec::new();

        // 初始化所有节点
        for node in &self.main {
            nodes_map.insert(
                node.id.clone(),
                RbumSetTreeCateNodeResp {
                    id: node.id.clone(),
                    sys_code: node.sys_code.clone(),
                    bus_code: node.bus_code.clone(),
                    name: node.name.clone(),
                    icon: node.icon.clone(),
                    sort: node.sort,
                    ext: node.ext.clone(),
                    node: vec![],
                    own_paths: node.own_paths.clone(),
                    owner: node.owner.clone(),
                    create_time: node.create_time,
                    update_time: node.update_time,
                    scope_level: node.scope_level.clone(),
                },
            );
            if let Some(parent_id) = node.pid.as_ref() {
                child_map.entry(parent_id.to_string()).or_default().push(node.id.clone());
            } else {
                roots.push(node.id.clone());
            }
        }
        // 递归方法构建树
        fn build_tree(node_id: String, nodes_map: &mut HashMap<String, RbumSetTreeCateNodeResp>, child_map: &HashMap<String, Vec<String>>) -> Option<RbumSetTreeCateNodeResp> {
            if let Some(mut node) = nodes_map.remove(&node_id) {
                if let Some(children) = child_map.get(&node_id) {
                    for child_id in children.clone() {
                        let child_node = build_tree(child_id, nodes_map, child_map);
                        if let Some(child_node) = child_node {
                            node.node.push(child_node);
                        }
                    }
                }
                Some(node)
            } else {
                None
            }
        }
        // 构建根节点的树结构
        let mut trees: Vec<RbumSetTreeCateNodeResp> = Vec::new();
        for root_id in roots {
            if let Some(root_node) = build_tree(root_id, &mut nodes_map, &child_map) {
                trees.push(root_node);
            }
        }
        RbumSetTreeCateResp {
            cate_tree: trees,
            ext: self.ext.clone(),
        }
    }
}

/// Resource tree node information
///
/// 资源树节点信息
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct RbumSetTreeNodeResp {
    /// Node id
    ///
    /// 节点id
    pub id: String,
    /// System (internal) code
    ///
    /// 系统(内部)编码
    ///
    /// using regular hierarchical code to avoid recursive tree queries.
    ///
    /// 使用规则的层级编码,避免递归树查询。
    pub sys_code: String,
    /// Business code for custom
    ///
    /// 自定义业务编码
    pub bus_code: String,
    /// Node name
    ///
    /// 节点名称
    pub name: String,
    /// Node icon
    ///
    /// 节点图标
    pub icon: String,
    /// Node sort
    ///
    /// 节点排序
    pub sort: i64,
    /// Node extension information
    ///
    /// 节点扩展信息
    pub ext: String,
    /// Parent node id
    ///
    /// 父节点Id
    pub pid: Option<String>,
    /// Associated object id
    ///
    /// 关联对象Id
    ///
    /// This association is set by the business layer, and the rbum model will not assign a value to it.
    ///
    /// 此关联由上层的业务设置,rbum模型不会为其赋值。
    pub rel: Option<String>,

    pub own_paths: String,
    pub owner: String,
    pub create_time: DateTime<Utc>,
    pub update_time: DateTime<Utc>,

    pub scope_level: RbumScopeLevelKind,
}

/// Resource tree extension information
///
/// 资源树扩展信息
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct RbumSetTreeExtResp {
    /// 节点与资源项的关联信息
    ///
    /// Node and resource item association information
    ///
    /// Format: ``node.id -> resource items``
    pub items: HashMap<String, Vec<RbumSetItemRelInfoResp>>,
    /// 节点关联资源项统计信息
    ///
    /// Node associated resource item statistics information
    ///
    /// Format: ``node.id -> [`crate::rbum::dto::rbum_set_item_dto::RbumSetItemInfoResp::rel_rbum_item_kind_id`] ->  resource item number``
    pub item_number_agg: HashMap<String, HashMap<String, u64>>,
    /// Resource kind information
    ///
    /// 资源类型信息
    ///
    /// Format: ``kind.id -> kind summary information``
    pub item_kinds: HashMap<String, RbumKindSummaryResp>,
    /// Resource domain information
    ///
    /// 资源域信息
    ///
    /// Format: ``domain.id -> domain summary info``
    pub item_domains: HashMap<String, RbumDomainSummaryResp>,
}

/// Resource tree information
///
/// 资源目录树信息
#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
pub struct RbumSetTreeCateResp {
    /// Resource cate tree node information
    ///
    /// 资源目录树节点信息
    pub cate_tree: Vec<RbumSetTreeCateNodeResp>,
    /// Resource tree extension information
    ///
    /// 资源树扩展信息
    pub ext: Option<RbumSetTreeExtResp>,
}

#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
/// Resource tree cate structure information
///
/// 资源树目录结构信息
pub struct RbumSetTreeCateNodeResp {
    /// Node id
    ///
    /// 节点id
    pub id: String,

    /// System (internal) code
    ///
    /// 系统(内部)编码
    ///
    /// using regular hierarchical code to avoid recursive tree queries.
    ///
    /// 使用规则的层级编码,避免递归树查询。
    pub sys_code: String,

    /// Business code for custom
    ///
    /// 自定义业务编码
    pub bus_code: String,

    /// Node name
    ///
    /// 节点名称
    pub name: String,

    /// Node icon
    ///
    /// 节点图标
    pub icon: String,

    /// Node sort
    ///
    /// 节点排序
    pub sort: i64,

    /// Node extension information
    ///
    /// 节点扩展信息
    pub ext: String,

    pub node: Vec<RbumSetTreeCateNodeResp>,

    pub own_paths: String,

    pub owner: String,

    pub create_time: DateTime<Utc>,

    pub update_time: DateTime<Utc>,

    pub scope_level: RbumScopeLevelKind,
}