chimes_rust/entity/
chimes_dict_info.rs

1use rbatis::crud::{Skip, CRUD};
2use rbatis::crud_table;
3use rbatis::error::Error;
4use rbatis::rbatis::Rbatis;
5use rbatis::Page;
6use rbatis::PageRequest;
7use rbson::Bson;
8use serde_derive::{Deserialize, Serialize};
9/**
10 * Generate the file for chimes_dict_info.rs,
11 */
12use std::fmt::Debug;
13
14#[crud_table(table_name:"chimes_dict"|table_columns:"dict_id,name,description,create_by,update_by,create_time,update_time")]
15#[derive(Debug, Clone, Default, Deserialize, Serialize)]
16pub struct ChimesDictInfo {
17    pub dict_id: Option<i64>,
18    pub name: Option<String>,
19    pub description: Option<String>,
20    pub create_by: Option<String>,
21    pub update_by: Option<String>,
22    pub create_time: Option<rbatis::DateTimeNative>,
23    pub update_time: Option<rbatis::DateTimeNative>,
24}
25
26impl ChimesDictInfo {
27    #[allow(dead_code)]
28    pub async fn from_id(rb: &Rbatis, dict_id: &i64) -> Result<Option<Self>, Error> {
29        let wp = rb.new_wrapper().eq("dict_id", dict_id);
30        rb.fetch_by_wrapper::<Option<Self>>(wp).await
31    }
32
33    #[allow(dead_code)]
34    pub async fn save(&mut self, rb: &Rbatis) -> Result<u64, Error> {
35        match rb.save(self, &[Skip::Column("dict_id")]).await {
36            Ok(ds) => {
37                self.dict_id = ds.last_insert_id;
38                Ok(ds.rows_affected)
39            }
40            Err(err) => Err(err),
41        }
42    }
43
44    #[allow(dead_code)]
45    pub async fn update(&self, rb: &Rbatis) -> Result<u64, Error> {
46        let wp = rb.new_wrapper().eq("dict_id", self.dict_id);
47        rb.update_by_wrapper(self, wp, &[Skip::Column("dict_id")])
48            .await
49    }
50
51    #[allow(dead_code)]
52    pub async fn update_selective(&self, rb: &Rbatis) -> Result<u64, Error> {
53        let wp = rb.new_wrapper().eq("dict_id", self.dict_id);
54        rb.update_by_wrapper(self, wp, &[Skip::Value(Bson::Null)])
55            .await
56    }
57
58    #[allow(dead_code)]
59    pub async fn remove_batch(&self, rb: &Rbatis) -> Result<u64, Error> {
60        let wp = rb
61            .new_wrapper()
62            .r#if(self.dict_id.clone().is_some(), |w| {
63                w.and().eq("dict_id", self.dict_id.unwrap())
64            })
65            .r#if(self.name.clone().is_some(), |w| {
66                w.and().eq("name", self.name.clone().unwrap())
67            })
68            .r#if(self.description.clone().is_some(), |w| {
69                w.and().eq("description", self.description.clone().unwrap())
70            })
71            .r#if(self.create_by.clone().is_some(), |w| {
72                w.and().eq("create_by", self.create_by.clone().unwrap())
73            })
74            .r#if(self.update_by.clone().is_some(), |w| {
75                w.and().eq("update_by", self.update_by.clone().unwrap())
76            })
77            .r#if(self.create_time.clone().is_some(), |w| {
78                w.and().eq("create_time", self.create_time.unwrap())
79            })
80            .r#if(self.update_time.clone().is_some(), |w| {
81                w.and().eq("update_time", self.update_time.unwrap())
82            });
83        rb.remove_by_wrapper::<Self>(wp).await
84    }
85
86    #[allow(dead_code)]
87    pub async fn remove(&mut self, rb: &Rbatis) -> Result<u64, Error> {
88        let wp = rb.new_wrapper().eq("dict_id", self.dict_id);
89        rb.remove_by_wrapper::<Self>(wp).await
90    }
91
92    #[allow(dead_code)]
93    pub async fn query_paged(&self, rb: &Rbatis, curr: u64, ps: u64) -> Result<Page<Self>, Error> {
94        let wp = rb
95            .new_wrapper()
96            .r#if(self.dict_id.clone().is_some(), |w| {
97                w.and().eq("dict_id", self.dict_id.unwrap())
98            })
99            .r#if(self.name.clone().is_some(), |w| {
100                w.and().eq("name", self.name.clone().unwrap())
101            })
102            .r#if(self.description.clone().is_some(), |w| {
103                w.and().eq("description", self.description.clone().unwrap())
104            })
105            .r#if(self.create_by.clone().is_some(), |w| {
106                w.and().eq("create_by", self.create_by.clone().unwrap())
107            })
108            .r#if(self.update_by.clone().is_some(), |w| {
109                w.and().eq("update_by", self.update_by.clone().unwrap())
110            })
111            .r#if(self.create_time.clone().is_some(), |w| {
112                w.and().eq("create_time", self.create_time.unwrap())
113            })
114            .r#if(self.update_time.clone().is_some(), |w| {
115                w.and().eq("update_time", self.update_time.unwrap())
116            });
117        rb.fetch_page_by_wrapper::<Self>(wp, &PageRequest::new(curr, ps))
118            .await
119    }
120
121    #[allow(dead_code)]
122    pub async fn query_list(&self, rb: &Rbatis) -> Result<Vec<Self>, Error> {
123        let wp = rb
124            .new_wrapper()
125            .r#if(self.dict_id.clone().is_some(), |w| {
126                w.and().eq("dict_id", self.dict_id.unwrap())
127            })
128            .r#if(self.name.clone().is_some(), |w| {
129                w.and().eq("name", self.name.clone().unwrap())
130            })
131            .r#if(self.description.clone().is_some(), |w| {
132                w.and().eq("description", self.description.clone().unwrap())
133            })
134            .r#if(self.create_by.clone().is_some(), |w| {
135                w.and().eq("create_by", self.create_by.clone().unwrap())
136            })
137            .r#if(self.update_by.clone().is_some(), |w| {
138                w.and().eq("update_by", self.update_by.clone().unwrap())
139            })
140            .r#if(self.create_time.clone().is_some(), |w| {
141                w.and().eq("create_time", self.create_time.unwrap())
142            })
143            .r#if(self.update_time.clone().is_some(), |w| {
144                w.and().eq("update_time", self.update_time.unwrap())
145            });
146        rb.fetch_list_by_wrapper::<Self>(wp).await
147    }
148
149    #[allow(dead_code)]
150    pub async fn remove_ids(rb: &Rbatis, ids: &[i64]) -> Result<u64, Error> {
151        let wp = rb.new_wrapper().r#in("dict_id", ids);
152        rb.remove_by_wrapper::<Self>(wp).await
153    }
154}