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