bios_basic/rbum/dto/
rbum_set_dto.rs

1use crate::rbum::dto::rbum_domain_dto::RbumDomainSummaryResp;
2use crate::rbum::dto::rbum_kind_dto::RbumKindSummaryResp;
3use crate::rbum::dto::rbum_set_item_dto::RbumSetItemRelInfoResp;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use tardis::basic::field::TrimString;
7use tardis::chrono::{DateTime, Utc};
8
9use tardis::db::sea_orm;
10
11use tardis::web::poem_openapi;
12
13use crate::rbum::rbum_enumeration::RbumScopeLevelKind;
14
15/// Add request for resource set
16///
17/// 资源集添加请求
18#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
19pub struct RbumSetAddReq {
20    /// Resource set code
21    ///
22    /// 资源集编码
23    #[oai(validator(min_length = "2", max_length = "255"))]
24    pub code: TrimString,
25    /// Resource set kind
26    ///
27    /// 资源集类型
28    #[oai(validator(min_length = "2", max_length = "255"))]
29    pub kind: TrimString,
30    /// Resource set name
31    ///
32    /// 资源集名称
33    #[oai(validator(min_length = "2", max_length = "255"))]
34    pub name: TrimString,
35    /// Resource set note
36    ///
37    /// 资源集备注
38    #[oai(validator(min_length = "2", max_length = "2000"))]
39    pub note: Option<String>,
40    /// Resource set icon
41    ///
42    /// 资源集图标
43    #[oai(validator(min_length = "2", max_length = "1000"))]
44    pub icon: Option<String>,
45    /// Resource set sort
46    ///
47    /// 资源集排序
48    pub sort: Option<i64>,
49    /// Resource set extension information
50    ///
51    /// 资源集扩展信息
52    #[oai(validator(min_length = "2", max_length = "1000"))]
53    pub ext: Option<String>,
54
55    pub scope_level: Option<RbumScopeLevelKind>,
56    pub disabled: Option<bool>,
57}
58
59/// Modify request for resource set
60///
61/// 资源集修改请求
62#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
63pub struct RbumSetModifyReq {
64    /// Resource set name
65    ///
66    /// 资源集名称
67    #[oai(validator(min_length = "2", max_length = "255"))]
68    pub name: Option<TrimString>,
69    /// Resource set note
70    ///
71    /// 资源集备注
72    #[oai(validator(min_length = "2", max_length = "2000"))]
73    pub note: Option<String>,
74    /// Resource set icon
75    ///
76    /// 资源集图标
77    #[oai(validator(min_length = "2", max_length = "1000"))]
78    pub icon: Option<String>,
79    /// Resource set sort
80    ///
81    /// 资源集排序
82    pub sort: Option<i64>,
83    /// Resource set extension information
84    ///
85    /// 资源集扩展信息
86    #[oai(validator(min_length = "2", max_length = "1000"))]
87    pub ext: Option<String>,
88
89    pub scope_level: Option<RbumScopeLevelKind>,
90    pub disabled: Option<bool>,
91}
92
93/// Resource set summary information
94///
95/// 资源集概要信息
96#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
97pub struct RbumSetSummaryResp {
98    /// Resource set id
99    ///
100    /// 资源集id
101    pub id: String,
102    /// Resource set code
103    ///
104    /// 资源集编码
105    pub code: String,
106    /// Resource set kind
107    ///
108    /// 资源集类型
109    pub kind: String,
110    /// Resource set name
111    ///
112    /// 资源集名称
113    pub name: String,
114    /// Resource set icon
115    ///
116    /// 资源集图标
117    pub icon: String,
118    /// Resource set sort
119    ///
120    /// 资源集排序
121    pub sort: i64,
122    /// Resource set extension information
123    ///
124    /// 资源集扩展信息
125    pub ext: String,
126
127    pub own_paths: String,
128    pub owner: String,
129    pub create_time: DateTime<Utc>,
130    pub update_time: DateTime<Utc>,
131
132    pub scope_level: RbumScopeLevelKind,
133    pub disabled: bool,
134}
135
136/// Resource set detail information
137///
138/// 资源集详细信息
139#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
140pub struct RbumSetDetailResp {
141    /// Resource set id
142    ///
143    /// 资源集id
144    pub id: String,
145    /// Resource set code
146    ///
147    /// 资源集编码
148    pub code: String,
149    /// Resource set kind
150    ///
151    /// 资源集类型
152    pub kind: String,
153    /// Resource set name
154    ///
155    /// 资源集名称
156    pub name: String,
157    /// Resource set note
158    ///
159    /// 资源集备注
160    pub note: String,
161    /// Resource set icon
162    ///
163    /// 资源集图标
164    pub icon: String,
165    /// Resource set sort
166    ///
167    /// 资源集排序
168    pub sort: i64,
169    /// Resource set extension information
170    ///
171    /// 资源集扩展信息
172    pub ext: String,
173
174    pub own_paths: String,
175    pub owner: String,
176    pub owner_name: Option<String>,
177    pub create_time: DateTime<Utc>,
178    pub update_time: DateTime<Utc>,
179
180    pub scope_level: RbumScopeLevelKind,
181    pub disabled: bool,
182}
183
184/// Resource set path information
185///
186/// 资源集路径信息
187#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
188pub struct RbumSetPathResp {
189    /// Node id
190    ///
191    /// 节点id
192    pub id: String,
193    /// Node name
194    ///
195    /// 节点名称
196    pub name: String,
197
198    pub own_paths: String,
199}
200
201/// Resource tree information
202///
203/// 资源树信息
204#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
205pub struct RbumSetTreeResp {
206    /// Resource tree node information
207    ///
208    /// 资源树节点信息
209    pub main: Vec<RbumSetTreeNodeResp>,
210    /// Resource tree extension information
211    ///
212    /// 资源树扩展信息
213    pub ext: Option<RbumSetTreeExtResp>,
214}
215
216impl RbumSetTreeResp {
217    pub fn to_trees(&self) -> RbumSetTreeCateResp {
218        let mut nodes_map: HashMap<String, RbumSetTreeCateNodeResp> = HashMap::new();
219        let mut child_map: HashMap<String, Vec<String>> = HashMap::new();
220        let mut roots: Vec<String> = Vec::new();
221
222        // 初始化所有节点
223        for node in &self.main {
224            nodes_map.insert(
225                node.id.clone(),
226                RbumSetTreeCateNodeResp {
227                    id: node.id.clone(),
228                    sys_code: node.sys_code.clone(),
229                    bus_code: node.bus_code.clone(),
230                    name: node.name.clone(),
231                    icon: node.icon.clone(),
232                    sort: node.sort,
233                    ext: node.ext.clone(),
234                    node: vec![],
235                    own_paths: node.own_paths.clone(),
236                    owner: node.owner.clone(),
237                    create_time: node.create_time,
238                    update_time: node.update_time,
239                    scope_level: node.scope_level.clone(),
240                },
241            );
242            if let Some(parent_id) = node.pid.as_ref() {
243                child_map.entry(parent_id.to_string()).or_default().push(node.id.clone());
244            } else {
245                roots.push(node.id.clone());
246            }
247        }
248        // 递归方法构建树
249        fn build_tree(node_id: String, nodes_map: &mut HashMap<String, RbumSetTreeCateNodeResp>, child_map: &HashMap<String, Vec<String>>) -> Option<RbumSetTreeCateNodeResp> {
250            if let Some(mut node) = nodes_map.remove(&node_id) {
251                if let Some(children) = child_map.get(&node_id) {
252                    for child_id in children.clone() {
253                        let child_node = build_tree(child_id, nodes_map, child_map);
254                        if let Some(child_node) = child_node {
255                            node.node.push(child_node);
256                        }
257                    }
258                }
259                Some(node)
260            } else {
261                None
262            }
263        }
264        // 构建根节点的树结构
265        let mut trees: Vec<RbumSetTreeCateNodeResp> = Vec::new();
266        for root_id in roots {
267            if let Some(root_node) = build_tree(root_id, &mut nodes_map, &child_map) {
268                trees.push(root_node);
269            }
270        }
271        RbumSetTreeCateResp {
272            cate_tree: trees,
273            ext: self.ext.clone(),
274        }
275    }
276}
277
278/// Resource tree node information
279///
280/// 资源树节点信息
281#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
282pub struct RbumSetTreeNodeResp {
283    /// Node id
284    ///
285    /// 节点id
286    pub id: String,
287    /// System (internal) code
288    ///
289    /// 系统(内部)编码
290    ///
291    /// using regular hierarchical code to avoid recursive tree queries.
292    ///
293    /// 使用规则的层级编码,避免递归树查询。
294    pub sys_code: String,
295    /// Business code for custom
296    ///
297    /// 自定义业务编码
298    pub bus_code: String,
299    /// Node name
300    ///
301    /// 节点名称
302    pub name: String,
303    /// Node icon
304    ///
305    /// 节点图标
306    pub icon: String,
307    /// Node sort
308    ///
309    /// 节点排序
310    pub sort: i64,
311    /// Node extension information
312    ///
313    /// 节点扩展信息
314    pub ext: String,
315    /// Parent node id
316    ///
317    /// 父节点Id
318    pub pid: Option<String>,
319    /// Associated object id
320    ///
321    /// 关联对象Id
322    ///
323    /// This association is set by the business layer, and the rbum model will not assign a value to it.
324    ///
325    /// 此关联由上层的业务设置,rbum模型不会为其赋值。
326    pub rel: Option<String>,
327
328    pub own_paths: String,
329    pub owner: String,
330    pub create_time: DateTime<Utc>,
331    pub update_time: DateTime<Utc>,
332
333    pub scope_level: RbumScopeLevelKind,
334}
335
336/// Resource tree extension information
337///
338/// 资源树扩展信息
339#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
340pub struct RbumSetTreeExtResp {
341    /// 节点与资源项的关联信息
342    ///
343    /// Node and resource item association information
344    ///
345    /// Format: ``node.id -> resource items``
346    pub items: HashMap<String, Vec<RbumSetItemRelInfoResp>>,
347    /// 节点关联资源项统计信息
348    ///
349    /// Node associated resource item statistics information
350    ///
351    /// Format: ``node.id -> [`crate::rbum::dto::rbum_set_item_dto::RbumSetItemInfoResp::rel_rbum_item_kind_id`] ->  resource item number``
352    pub item_number_agg: HashMap<String, HashMap<String, u64>>,
353    /// Resource kind information
354    ///
355    /// 资源类型信息
356    ///
357    /// Format: ``kind.id -> kind summary information``
358    pub item_kinds: HashMap<String, RbumKindSummaryResp>,
359    /// Resource domain information
360    ///
361    /// 资源域信息
362    ///
363    /// Format: ``domain.id -> domain summary info``
364    pub item_domains: HashMap<String, RbumDomainSummaryResp>,
365}
366
367/// Resource tree information
368///
369/// 资源目录树信息
370#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
371pub struct RbumSetTreeCateResp {
372    /// Resource cate tree node information
373    ///
374    /// 资源目录树节点信息
375    pub cate_tree: Vec<RbumSetTreeCateNodeResp>,
376    /// Resource tree extension information
377    ///
378    /// 资源树扩展信息
379    pub ext: Option<RbumSetTreeExtResp>,
380}
381
382#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object)]
383/// Resource tree cate structure information
384///
385/// 资源树目录结构信息
386pub struct RbumSetTreeCateNodeResp {
387    /// Node id
388    ///
389    /// 节点id
390    pub id: String,
391
392    /// System (internal) code
393    ///
394    /// 系统(内部)编码
395    ///
396    /// using regular hierarchical code to avoid recursive tree queries.
397    ///
398    /// 使用规则的层级编码,避免递归树查询。
399    pub sys_code: String,
400
401    /// Business code for custom
402    ///
403    /// 自定义业务编码
404    pub bus_code: String,
405
406    /// Node name
407    ///
408    /// 节点名称
409    pub name: String,
410
411    /// Node icon
412    ///
413    /// 节点图标
414    pub icon: String,
415
416    /// Node sort
417    ///
418    /// 节点排序
419    pub sort: i64,
420
421    /// Node extension information
422    ///
423    /// 节点扩展信息
424    pub ext: String,
425
426    pub node: Vec<RbumSetTreeCateNodeResp>,
427
428    pub own_paths: String,
429
430    pub owner: String,
431
432    pub create_time: DateTime<Utc>,
433
434    pub update_time: DateTime<Utc>,
435
436    pub scope_level: RbumScopeLevelKind,
437}