bios_basic/rbum/
rbum_enumeration.rs

1use std::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4use strum::Display;
5use tardis::basic::error::TardisError;
6use tardis::basic::result::TardisResult;
7
8use tardis::db::sea_orm;
9
10use tardis::db::sea_orm::{DbErr, QueryResult, TryGetError, TryGetable};
11
12use tardis::web::poem_openapi;
13
14/// Scope level kind
15///
16/// 作用域层级类型
17#[derive(Display, Clone, Debug, PartialEq, Eq, Serialize, poem_openapi::Enum)]
18pub enum RbumScopeLevelKind {
19    /// Private
20    ///
21    /// 私有
22    ///
23    /// Only the current level is visible.
24    ///
25    /// 仅当前层级可见。
26    Private,
27    /// (全局)完全公开
28    ///
29    /// (Global)Fully open
30    Root,
31    /// The first level
32    ///
33    /// 第一层
34    ///
35    /// The current level and its descendants are visible.
36    ///
37    /// 当前层及其子孙层可见。
38    L1,
39    /// The second level
40    ///
41    /// 第二层
42    ///
43    /// The current level and its descendants are visible.
44    L2,
45    /// The third level
46    ///
47    /// 第三层
48    ///
49    /// The current level and its descendants are visible.
50    L3,
51}
52
53impl<'de> Deserialize<'de> for RbumScopeLevelKind {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55    where
56        D: serde::Deserializer<'de>,
57    {
58        String::deserialize(deserializer).and_then(|s| match s.to_lowercase().as_str() {
59            "private" => Ok(RbumScopeLevelKind::Private),
60            "root" => Ok(RbumScopeLevelKind::Root),
61            "l1" => Ok(RbumScopeLevelKind::L1),
62            "l2" => Ok(RbumScopeLevelKind::L2),
63            "l3" => Ok(RbumScopeLevelKind::L3),
64            _ => Err(serde::de::Error::custom(format!("invalid RbumScopeLevelKind: {s}"))),
65        })
66    }
67}
68
69impl RbumScopeLevelKind {
70    pub fn from_int(s: i16) -> TardisResult<RbumScopeLevelKind> {
71        match s {
72            -1 => Ok(RbumScopeLevelKind::Private),
73            0 => Ok(RbumScopeLevelKind::Root),
74            1 => Ok(RbumScopeLevelKind::L1),
75            2 => Ok(RbumScopeLevelKind::L2),
76            3 => Ok(RbumScopeLevelKind::L3),
77            _ => Err(TardisError::format_error(&format!("invalid RbumScopeLevelKind: {s}"), "406-rbum-*-enum-init-error")),
78        }
79    }
80
81    pub fn to_int(&self) -> i16 {
82        match self {
83            RbumScopeLevelKind::Private => -1,
84            RbumScopeLevelKind::Root => 0,
85            RbumScopeLevelKind::L1 => 1,
86            RbumScopeLevelKind::L2 => 2,
87            RbumScopeLevelKind::L3 => 3,
88        }
89    }
90}
91
92impl TryGetable for RbumScopeLevelKind {
93    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
94        let s = i16::try_get(res, pre, col)?;
95        RbumScopeLevelKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
96    }
97
98    fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError> {
99        i16::try_get_by(res, index).map(RbumScopeLevelKind::from_int)?.map_err(|e| TryGetError::DbErr(DbErr::Custom(format!("invalid scope level: {e}"))))
100    }
101}
102
103/// Certificate relationship kind
104///
105///
106/// 凭证关联的类型
107#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
108pub enum RbumCertRelKind {
109    /// Resource item
110    ///
111    /// 资源项
112    Item,
113    /// Resource set
114    ///
115    /// 资源集
116    Set,
117    /// Resource relation
118    ///
119    /// 资源关联
120    Rel,
121}
122
123impl RbumCertRelKind {
124    pub fn from_int(s: i16) -> TardisResult<RbumCertRelKind> {
125        match s {
126            0 => Ok(RbumCertRelKind::Item),
127            1 => Ok(RbumCertRelKind::Set),
128            2 => Ok(RbumCertRelKind::Rel),
129            _ => Err(TardisError::format_error(&format!("invalid RbumCertRelKind: {s}"), "406-rbum-*-enum-init-error")),
130        }
131    }
132
133    pub fn to_int(&self) -> i16 {
134        match self {
135            RbumCertRelKind::Item => 0,
136            RbumCertRelKind::Set => 1,
137            RbumCertRelKind::Rel => 2,
138        }
139    }
140}
141
142impl TryGetable for RbumCertRelKind {
143    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
144        let s = i16::try_get(res, pre, col)?;
145        RbumCertRelKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
146    }
147
148    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
149        panic!("not implemented")
150    }
151}
152
153/// Resource certificate configuration status kind
154///
155/// 资源凭证配置状态类型
156#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
157pub enum RbumCertConfStatusKind {
158    /// Disabled
159    ///
160    /// 禁用
161    Disabled,
162    /// Enabled
163    ///
164    /// 启用
165    Enabled,
166}
167
168impl RbumCertConfStatusKind {
169    pub fn from_int(s: i16) -> TardisResult<RbumCertConfStatusKind> {
170        match s {
171            0 => Ok(RbumCertConfStatusKind::Disabled),
172            1 => Ok(RbumCertConfStatusKind::Enabled),
173            _ => Err(TardisError::format_error(&format!("invalid RbumCertConfStatusKind: {s}"), "406-rbum-*-enum-init-error")),
174        }
175    }
176
177    pub fn to_int(&self) -> i16 {
178        match self {
179            RbumCertConfStatusKind::Disabled => 0,
180            RbumCertConfStatusKind::Enabled => 1,
181        }
182    }
183}
184
185/// Resource certificate status kind
186///
187/// 资源凭证状态类型
188#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
189pub enum RbumCertStatusKind {
190    /// Disabled
191    ///
192    /// 禁用
193    Disabled,
194    /// Enabled
195    ///
196    /// 启用
197    Enabled,
198    /// Pending
199    ///
200    /// 正在处理
201    Pending,
202}
203
204impl RbumCertStatusKind {
205    pub fn from_int(s: i16) -> TardisResult<RbumCertStatusKind> {
206        match s {
207            0 => Ok(RbumCertStatusKind::Disabled),
208            1 => Ok(RbumCertStatusKind::Enabled),
209            2 => Ok(RbumCertStatusKind::Pending),
210            _ => Err(TardisError::format_error(&format!("invalid RbumCertStatusKind: {s}"), "406-rbum-*-enum-init-error")),
211        }
212    }
213
214    pub fn to_int(&self) -> i16 {
215        match self {
216            RbumCertStatusKind::Disabled => 0,
217            RbumCertStatusKind::Enabled => 1,
218            RbumCertStatusKind::Pending => 2,
219        }
220    }
221}
222
223impl TryGetable for RbumCertStatusKind {
224    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
225        let s = i16::try_get(res, pre, col)?;
226        RbumCertStatusKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
227    }
228
229    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
230        panic!("not implemented")
231    }
232}
233
234/// Resource relation kind
235///
236/// 资源关联的类型
237#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
238pub enum RbumRelFromKind {
239    /// Resource item
240    ///
241    /// 资源项
242    Item,
243    /// Resource set
244    ///
245    /// 资源集
246    Set,
247    /// Resource set category(node)
248    ///
249    /// 资源集分类(节点)
250    SetCate,
251    /// Resource certificate
252    ///
253    /// 资源凭证
254    Cert,
255}
256
257impl RbumRelFromKind {
258    pub fn from_int(s: i16) -> TardisResult<RbumRelFromKind> {
259        match s {
260            0 => Ok(RbumRelFromKind::Item),
261            1 => Ok(RbumRelFromKind::Set),
262            2 => Ok(RbumRelFromKind::SetCate),
263            3 => Ok(RbumRelFromKind::Cert),
264            _ => Err(TardisError::format_error(&format!("invalid RbumRelFromKind: {s}"), "406-rbum-*-enum-init-error")),
265        }
266    }
267
268    pub fn to_int(&self) -> i16 {
269        match self {
270            RbumRelFromKind::Item => 0,
271            RbumRelFromKind::Set => 1,
272            RbumRelFromKind::SetCate => 2,
273            RbumRelFromKind::Cert => 3,
274        }
275    }
276}
277
278impl TryGetable for RbumRelFromKind {
279    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
280        let s = i16::try_get(res, pre, col)?;
281        RbumRelFromKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
282    }
283
284    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
285        panic!("not implemented")
286    }
287}
288
289/// Resource relation environment kind
290///
291/// 资源关联环境类型
292///
293/// Used to associate resources with restrictions.
294///
295/// 用于给资源关联加上限制条件。
296#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
297pub enum RbumRelEnvKind {
298    /// Datetime range
299    ///
300    /// 日期时间范围
301    ///
302    /// Format: ``UNIX timestamp``
303    DatetimeRange,
304    /// Time range
305    ///
306    /// 时间范围
307    ///
308    /// Format: ``hhmmss``.
309    ///
310    /// hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
311    /// mm   = two digits of minute (00 through 59)
312    /// ss   = two digits of second (00 through 59)
313    TimeRange,
314    /// IP list
315    ///
316    /// IP地址
317    ///
318    /// Format: ``ip1,ip2,ip3``
319    Ips,
320    /// Call frequency
321    ///
322    /// 调用频率
323    ///
324    /// Request value must be less than or equal to the set value.
325    ///
326    /// 请求的值要小于等于设置的值。
327    CallFrequency,
328    /// Call count
329    ///
330    /// 调用次数
331    ///
332    /// Request value must be less than or equal to the set value.
333    ///
334    /// 请求的值要小于等于设置的值。
335    CallCount,
336}
337
338impl RbumRelEnvKind {
339    pub fn from_int(s: i16) -> TardisResult<RbumRelEnvKind> {
340        match s {
341            0 => Ok(RbumRelEnvKind::DatetimeRange),
342            1 => Ok(RbumRelEnvKind::TimeRange),
343            2 => Ok(RbumRelEnvKind::Ips),
344            3 => Ok(RbumRelEnvKind::CallFrequency),
345            4 => Ok(RbumRelEnvKind::CallCount),
346            _ => Err(TardisError::format_error(&format!("invalid RbumRelEnvKind: {s}"), "406-rbum-*-enum-init-error")),
347        }
348    }
349
350    pub fn to_int(&self) -> i16 {
351        match self {
352            RbumRelEnvKind::DatetimeRange => 0,
353            RbumRelEnvKind::TimeRange => 1,
354            RbumRelEnvKind::Ips => 2,
355            RbumRelEnvKind::CallFrequency => 3,
356            RbumRelEnvKind::CallCount => 4,
357        }
358    }
359}
360
361impl TryGetable for RbumRelEnvKind {
362    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
363        let s = i16::try_get(res, pre, col)?;
364        RbumRelEnvKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
365    }
366
367    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
368        panic!("not implemented")
369    }
370}
371
372/// Resource set category(node) query kind
373///
374/// 资源集分类(节点)的查询类型
375#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
376pub enum RbumSetCateLevelQueryKind {
377    /// Current layer and descendant layer
378    ///
379    /// 当前层及子孙层
380    CurrentAndSub,
381    /// Current layer and grandfather layer
382    ///
383    /// 当前层及祖父层
384    CurrentAndParent,
385    /// Descendant layer
386    ///
387    /// 子孙层
388    Sub,
389    /// Grandfather layer
390    ///
391    /// 祖父层
392    Parent,
393    /// Current layer only
394    ///
395    /// 仅当前层
396    Current,
397}
398
399/// Data kind
400///
401/// 数据类型
402#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, strum::EnumString)]
403pub enum RbumDataTypeKind {
404    String,
405    Number,
406    Boolean,
407    Date,
408    DateTime,
409    Json,
410    Strings,
411    Numbers,
412    Booleans,
413    Dates,
414    DateTimes,
415    Array,
416    Label,
417}
418
419impl TryGetable for RbumDataTypeKind {
420    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
421        let s = String::try_get(res, pre, col)?;
422        RbumDataTypeKind::from_str(&s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
423    }
424
425    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
426        panic!("not implemented")
427    }
428}
429
430/// Widget kind
431///
432/// (前端)控件类型
433#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, strum::EnumString)]
434pub enum RbumWidgetTypeKind {
435    Input,
436    InputTxt,
437    InputNum,
438    Textarea,
439    Number,
440    Date,
441    DateTime,
442    Upload,
443    Radio,
444    Button,
445    Checkbox,
446    Switch,
447    Select,
448    MultiSelect,
449    Link,
450    CodeEditor,
451    /// Display group subtitles, ``datatype = String & value is empty``
452    ///
453    /// 显示组标题,``datatype = String & 值为空``
454    Container,
455    /// Json fields : ``datatype = Json && all parent_attr_name = current attribute``
456    ///
457    /// Json字段,``datatype = Json && 所有 parent_attr_name = 当前属性``
458    Control,
459    /// Sub fields :  ``datatype = Array && all parent_attr_name = current attribute``, The value of the json array is stored to the current field.
460    ///
461    /// 子字段,``datatype = Array && 所有 parent_attr_name = 当前属性``,将json数组的值存储到当前字段。
462    Group,
463}
464
465impl TryGetable for RbumWidgetTypeKind {
466    fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
467        let s = String::try_get(res, pre, col)?;
468        RbumWidgetTypeKind::from_str(&s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
469    }
470
471    fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
472        panic!("not implemented")
473    }
474}