Skip to main content

bios_basic/rbum/dto/
rbum_rel_dto.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::default::Default;
4use tardis::chrono::{DateTime, Utc};
5
6use tardis::db::sea_orm;
7
8use tardis::web::poem_openapi;
9
10use crate::rbum::rbum_enumeration::{RbumRelEnvKind, RbumRelFromKind};
11
12/// Add request for resource relationship
13///
14/// 资源关联添加请求
15#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
16pub struct RbumRelAddReq {
17    /// Relationship tag
18    ///
19    /// 关联标签
20    ///
21    /// Used to distinguish different relationships.
22    ///
23    /// 用于区分不同的关联关系。
24    #[oai(validator(min_length = "2", max_length = "255"))]
25    pub tag: String,
26    /// Relationship note
27    ///
28    /// 关联备注
29    #[oai(validator(min_length = "2", max_length = "1000"))]
30    pub note: Option<String>,
31    /// Relationship source type
32    ///
33    /// 关联来源方的类型
34    pub from_rbum_kind: RbumRelFromKind,
35    /// Relationship source id
36    ///
37    /// 关联来源方的id
38    #[oai(validator(min_length = "2", max_length = "255"))]
39    pub from_rbum_id: String,
40    /// Relationship target id
41    ///
42    /// 关联目标方的id
43    #[oai(validator(min_length = "2", max_length = "255"))]
44    pub to_rbum_item_id: String,
45    /// Relationship target ownership path
46    ///
47    /// 关联目标方的所有权路径
48    #[oai(validator(min_length = "2", max_length = "255"))]
49    pub to_own_paths: String,
50    /// Relationship extension information
51    ///
52    /// 关联扩展信息
53    ///
54    /// E.g. the record from or to is in another service, to avoid remote calls,
55    /// you can redundantly add the required information to this field.
56    ///
57    /// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
58    #[oai(validator(min_length = "2", max_length = "1000"))]
59    pub ext: Option<String>,
60    /// Whether the target is an external object
61    ///
62    /// 关联目标方是否是外部对象
63    ///
64    /// If ``true``, the validity of the associated target will not be verified.
65    ///
66    /// 当为 ``true`` 不会校验关联目标方的合法性。
67    pub to_is_outside: bool,
68}
69
70/// Modify request for resource relationship
71///
72/// 资源关联修改请求
73#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
74pub struct RbumRelModifyReq {
75    /// Relationship tag
76    ///
77    /// 关联标签
78    ///
79    /// Used to distinguish different relationships.
80    ///
81    /// 用于区分不同的关联关系。
82    #[oai(validator(min_length = "2", max_length = "255"))]
83    pub tag: Option<String>,
84    /// Relationship note
85    ///
86    /// 关联备注
87    #[oai(validator(min_length = "2", max_length = "1000"))]
88    pub note: Option<String>,
89    /// Relationship extension information
90    ///
91    /// 关联扩展信息
92    ///
93    /// E.g. the record from or to is in another service, to avoid remote calls,
94    /// you can redundantly add the required information to this field.
95    ///
96    /// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
97    #[oai(validator(min_length = "2", max_length = "1000"))]
98    pub ext: Option<String>,
99}
100
101/// Simple find request for resource relationship
102///
103/// 资源关联简单查找请求
104#[derive(Serialize, Deserialize, Debug, Clone, Default, poem_openapi::Object)]
105#[serde(default)]
106pub struct RbumRelSimpleFindReq {
107    /// Relationship tag
108    ///
109    /// 关联标签
110    ///
111    /// Used to distinguish different relationships.
112    ///
113    /// 用于区分不同的关联关系。
114    #[oai(validator(min_length = "2", max_length = "255"))]
115    pub tag: Option<String>,
116    /// Relationship source type
117    ///
118    /// 关联来源方的类型
119    pub from_rbum_kind: Option<RbumRelFromKind>,
120    /// Relationship source id
121    ///
122    /// 关联来源方的id
123    #[oai(validator(min_length = "2", max_length = "255"))]
124    pub from_rbum_id: Option<String>,
125    /// Relationship target id
126    ///
127    /// 关联目标方的id
128    #[oai(validator(min_length = "2", max_length = "255"))]
129    pub to_rbum_item_id: Option<String>,
130    /// Relationship source ownership path
131    ///
132    /// 关联来源方的所有权路径
133    #[oai(validator(min_length = "2", max_length = "255"))]
134    pub from_own_paths: Option<String>,
135    /// Relationship target ownership path
136    ///
137    /// 关联目标方的所有权路径
138    #[oai(validator(min_length = "2", max_length = "255"))]
139    pub to_rbum_own_paths: Option<String>,
140}
141
142/// Check request for resource relationship
143///
144/// 资源关联检查请求
145#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
146pub struct RbumRelCheckReq {
147    /// Relationship tag
148    ///
149    /// 关联标签
150    ///
151    /// Used to distinguish different relationships.
152    ///
153    /// 用于区分不同的关联关系。
154    #[oai(validator(min_length = "2", max_length = "255"))]
155    pub tag: String,
156    /// Relationship source type
157    ///
158    /// 关联来源方的类型
159    pub from_rbum_kind: RbumRelFromKind,
160    /// Relationship source id
161    ///
162    /// 关联来源方的id
163    #[oai(validator(min_length = "2", max_length = "255"))]
164    pub from_rbum_id: String,
165    /// Relationship target id
166    ///
167    /// 关联目标方的id
168    #[oai(validator(min_length = "2", max_length = "255"))]
169    pub to_rbum_item_id: String,
170    /// Limit the attributes of the relationship source
171    ///
172    /// 关联来源方的限定属性集合
173    ///
174    /// Format: ``{"Attribute name": "Input value"}``
175    ///
176    /// 格式: ``{"属性名称": "传入的值"}``
177    pub from_attrs: HashMap<String, String>,
178    /// Limit the attributes of the relationship target
179    ///
180    /// 关联目标方的限定属性集合
181    ///
182    /// Format: ``{"Attribute name": "Input value"}``
183    ///
184    /// 格式: ``{"属性名称": "传入的值"}``
185    pub to_attrs: HashMap<String, String>,
186    /// Limit the environment of the relationship
187    ///
188    /// 关联目标方的限定环境集合
189    pub envs: Vec<RbumRelEnvCheckReq>,
190}
191
192/// Check request for resource relationship environment
193///
194/// 资源关联环境检查请求
195#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
196pub struct RbumRelEnvCheckReq {
197    /// Relationship environment type
198    ///
199    /// 关联的环境类型
200    pub kind: RbumRelEnvKind,
201    /// Input value
202    ///
203    /// 传入的关联环境值
204    pub value: String,
205}
206
207/// Resource relationship bone information
208///
209/// 资源关联骨干信息
210#[derive(Serialize, Deserialize, Debug, Clone, poem_openapi::Object, sea_orm::FromQueryResult)]
211pub struct RbumRelBoneResp {
212    /// Relationship tag
213    ///
214    /// 关联标签
215    pub tag: String,
216    /// Relationship note
217    ///
218    /// 关联备注
219    pub note: String,
220    /// Relationship source type
221    ///
222    /// 关联来源方的类型
223    pub from_rbum_kind: RbumRelFromKind,
224    /// Relationship source or target id
225    ///
226    /// 关联来源方或目标方的id
227    pub rel_id: String,
228    /// Relationship source or target name
229    ///
230    /// 关联来源方或目标方的名称
231    ///
232    /// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] is the name of the resource item,
233    /// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] is the name of the resource set,
234    /// When `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] is the name of the resource set category(node).
235    ///
236    /// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] 时是资源项的名称,
237    /// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] 时是资源集的名称,
238    /// 当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] 时是资源集分类(节点)的名称。
239    pub rel_name: String,
240    /// Relationship source or target ownership path
241    ///
242    /// 关联来源方或目标方的所有权路径
243    pub rel_own_paths: String,
244    /// Relationship extension information
245    ///
246    /// 关联扩展信息
247    ///
248    /// E.g. the record from or to is in another service, to avoid remote calls,
249    /// you can redundantly add the required information to this field.
250    ///
251    /// 例如:记录来源或目标在另一个服务中,为避免远程调用,可以将所需信息冗余添加到此字段。
252    pub ext: String,
253}
254
255impl RbumRelBoneResp {
256    /// According to the relationship detail information, generate the relationship summary information
257    ///
258    /// 根据关联详细信息生成关联概要信息
259    ///
260    /// # Arguments
261    ///
262    /// * `detail` - Relationship detail information
263    /// * `package_to_info` - If ``true``, generate the summary information of the relationship source side, if ``false``, generate the summary information of the relationship target side
264    pub fn new(detail: RbumRelDetailResp, package_to_info: bool) -> RbumRelBoneResp {
265        if package_to_info {
266            RbumRelBoneResp {
267                tag: detail.tag,
268                note: detail.note,
269                from_rbum_kind: detail.from_rbum_kind,
270                rel_id: detail.to_rbum_item_id,
271                rel_name: detail.to_rbum_item_name,
272                rel_own_paths: detail.to_own_paths,
273                ext: detail.ext,
274            }
275        } else {
276            RbumRelBoneResp {
277                rel_name: match &detail.from_rbum_kind {
278                    RbumRelFromKind::Item => detail.from_rbum_item_name,
279                    RbumRelFromKind::Set => detail.from_rbum_set_name,
280                    RbumRelFromKind::SetCate => detail.from_rbum_set_cate_name,
281                    RbumRelFromKind::Cert => "".to_string(),
282                },
283                tag: detail.tag,
284                note: detail.note,
285                from_rbum_kind: detail.from_rbum_kind,
286                rel_id: detail.from_rbum_id,
287                rel_own_paths: detail.own_paths,
288                ext: detail.ext,
289            }
290        }
291    }
292}
293
294/// Resource relationship detail information
295///
296/// 资源关联详细信息
297#[derive(Serialize, Deserialize, Clone, Debug, poem_openapi::Object, sea_orm::FromQueryResult)]
298pub struct RbumRelDetailResp {
299    /// Relationship id
300    ///
301    /// 关联id
302    pub id: String,
303    /// Relationship tag
304    ///
305    /// 关联标签
306    pub tag: String,
307    /// Relationship note
308    ///
309    /// 关联备注
310    pub note: String,
311    /// Relationship source type
312    ///
313    /// 关联来源方的类型
314    pub from_rbum_kind: RbumRelFromKind,
315    /// Relationship source id
316    ///
317    /// 关联来源方的id
318    pub from_rbum_id: String,
319    /// Relationship source resource item name
320    ///
321    /// 关联来源方的资源项名称
322    ///
323    /// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`].
324    ///
325    /// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Item`] 时有值。
326    pub from_rbum_item_name: String,
327    /// Relationship source resource set name
328    ///
329    /// 关联来源方的资源集名称
330    ///
331    /// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`].
332    ///
333    /// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::Set`] 时有值。
334    pub from_rbum_set_name: String,
335    /// Relationship source resource set category(node) name
336    ///
337    /// 关联来源方的资源集分类(节点)名称
338    ///
339    /// Only valid when `from_rbum_kind` is [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`].
340    ///
341    /// 仅当 `from_rbum_kind` 为 [`crate::rbum::rbum_enumeration::RbumRelFromKind::SetCate`] 时有值。
342    pub from_rbum_set_cate_name: String,
343    /// Relationship target id
344    ///
345    /// 关联目标方的id
346    pub to_rbum_item_id: String,
347    /// Relationship target name
348    ///
349    /// 关联目标方的name
350    pub to_rbum_item_name: String,
351    /// Relationship target ownership path
352    ///
353    /// 关联目标方的所有权路径
354    pub to_own_paths: String,
355    /// Relationship extension information
356    ///
357    /// 关联扩展信息
358    pub ext: String,
359
360    pub own_paths: String,
361    pub owner: String,
362    pub owner_name: Option<String>,
363    pub create_time: DateTime<Utc>,
364    pub update_time: DateTime<Utc>,
365}