chimes_rust/entity/
chimes_company_info.rs

1use chimes_utils::i64_from_str;
2use rbatis::crud::{Skip, CRUD};
3use rbatis::crud_table;
4use rbatis::error::Error;
5use rbatis::rbatis::Rbatis;
6use rbatis::Page;
7use rbatis::PageRequest;
8use rbson::Bson;
9use serde_derive::{Deserialize, Serialize};
10/**
11 * Generate the file for chimes_company_info.rs,
12 */
13use std::fmt::Debug;
14
15#[crud_table(table_name:"chimes_company"|table_columns:"company_id,company_code,company_name,area_code,unform_code,address,legal_person,contact_no,full_city,contact_name,emails,brief,register_name,register_openid,register_unionid,create_time,update_time")]
16#[derive(Debug, Clone, Default, Deserialize, Serialize)]
17pub struct ChimesCompanyInfo {
18    #[serde(default)]
19    #[serde(deserialize_with = "i64_from_str")]
20    pub company_id: Option<i64>,
21    pub company_code: Option<String>,
22    pub company_name: Option<String>,
23    pub area_code: Option<String>,
24    pub unform_code: Option<String>,
25    pub address: Option<String>,
26    pub legal_person: Option<String>,
27    pub contact_no: Option<String>,
28    pub full_city: Option<String>,
29    pub contact_name: Option<String>,
30    pub emails: Option<String>,
31    pub brief: Option<String>,
32    pub register_name: Option<String>,
33    pub register_openid: Option<String>,
34    pub register_unionid: Option<String>,
35    pub create_time: Option<rbatis::DateTimeNative>,
36    pub update_time: Option<rbatis::DateTimeNative>,
37}
38
39impl ChimesCompanyInfo {
40    #[allow(dead_code)]
41    pub async fn from_id(rb: &Rbatis, company_id: &i64) -> Result<Option<Self>, Error> {
42        let wp = rb.new_wrapper().eq("company_id", company_id);
43        rb.fetch_by_wrapper::<Option<Self>>(wp).await
44    }
45
46    #[allow(dead_code)]
47    pub async fn save(&mut self, rb: &Rbatis) -> Result<u64, Error> {
48        match rb.save(self, &[Skip::Column("company_id")]).await {
49            Ok(ds) => {
50                self.company_id = ds.last_insert_id;
51                Ok(ds.rows_affected)
52            }
53            Err(err) => Err(err),
54        }
55    }
56
57    #[allow(dead_code)]
58    pub async fn update(&self, rb: &Rbatis) -> Result<u64, Error> {
59        let wp = rb.new_wrapper().eq("company_id", self.company_id);
60        rb.update_by_wrapper(self, wp, &[Skip::Column("company_id")])
61            .await
62    }
63
64    #[allow(dead_code)]
65    pub async fn update_selective(&self, rb: &Rbatis) -> Result<u64, Error> {
66        let wp = rb.new_wrapper().eq("company_id", self.company_id);
67        rb.update_by_wrapper(self, wp, &[Skip::Value(Bson::Null)])
68            .await
69    }
70
71    #[allow(dead_code)]
72    pub async fn remove_batch(&self, rb: &Rbatis) -> Result<u64, Error> {
73        let wp = rb
74            .new_wrapper()
75            .r#if(self.company_id.clone().is_some(), |w| {
76                w.and().eq("company_id", self.company_id.unwrap())
77            })
78            .r#if(self.company_code.clone().is_some(), |w| {
79                w.and()
80                    .eq("company_code", self.company_code.clone().unwrap())
81            })
82            .r#if(self.company_name.clone().is_some(), |w| {
83                w.and()
84                    .eq("company_name", self.company_name.clone().unwrap())
85            })
86            .r#if(self.area_code.clone().is_some(), |w| {
87                w.and().eq("area_code", self.area_code.clone().unwrap())
88            })
89            .r#if(self.unform_code.clone().is_some(), |w| {
90                w.and().eq("unform_code", self.unform_code.clone().unwrap())
91            })
92            .r#if(self.address.clone().is_some(), |w| {
93                w.and().eq("address", self.address.clone().unwrap())
94            })
95            .r#if(self.legal_person.clone().is_some(), |w| {
96                w.and()
97                    .eq("legal_person", self.legal_person.clone().unwrap())
98            })
99            .r#if(self.contact_no.clone().is_some(), |w| {
100                w.and().eq("contact_no", self.contact_no.clone().unwrap())
101            })
102            .r#if(self.full_city.clone().is_some(), |w| {
103                w.and().eq("full_city", self.full_city.clone().unwrap())
104            })
105            .r#if(self.contact_name.clone().is_some(), |w| {
106                w.and()
107                    .eq("contact_name", self.contact_name.clone().unwrap())
108            })
109            .r#if(self.emails.clone().is_some(), |w| {
110                w.and().eq("emails", self.emails.clone().unwrap())
111            })
112            .r#if(self.brief.clone().is_some(), |w| {
113                w.and().eq("brief", self.brief.clone().unwrap())
114            })
115            .r#if(self.register_name.clone().is_some(), |w| {
116                w.and()
117                    .eq("register_name", self.register_name.clone().unwrap())
118            })
119            .r#if(self.register_openid.clone().is_some(), |w| {
120                w.and()
121                    .eq("register_openid", self.register_openid.clone().unwrap())
122            })
123            .r#if(self.register_unionid.clone().is_some(), |w| {
124                w.and()
125                    .eq("register_unionid", self.register_unionid.clone().unwrap())
126            })
127            .r#if(self.create_time.clone().is_some(), |w| {
128                w.and().eq("create_time", self.create_time.unwrap())
129            })
130            .r#if(self.update_time.clone().is_some(), |w| {
131                w.and().eq("update_time", self.update_time.unwrap())
132            });
133        rb.remove_by_wrapper::<Self>(wp).await
134    }
135
136    #[allow(dead_code)]
137    pub async fn remove(&mut self, rb: &Rbatis) -> Result<u64, Error> {
138        let wp = rb.new_wrapper().eq("company_id", self.company_id);
139        rb.remove_by_wrapper::<Self>(wp).await
140    }
141
142    #[allow(dead_code)]
143    pub async fn remove_ids(rb: &Rbatis, ids: &[i64]) -> Result<u64, Error> {
144        let wp = rb.new_wrapper().r#in("company_id", ids);
145        rb.remove_by_wrapper::<Self>(wp).await
146    }
147
148    #[allow(dead_code)]
149    pub async fn query_paged(&self, rb: &Rbatis, curr: u64, ps: u64) -> Result<Page<Self>, Error> {
150        let wp = rb
151            .new_wrapper()
152            .r#if(self.company_id.clone().is_some(), |w| {
153                w.and().eq("company_id", self.company_id.unwrap())
154            })
155            .r#if(self.company_code.clone().is_some(), |w| {
156                w.and()
157                    .eq("company_code", self.company_code.clone().unwrap())
158            })
159            .r#if(self.company_name.clone().is_some(), |w| {
160                w.and()
161                    .eq("company_name", self.company_name.clone().unwrap())
162            })
163            .r#if(self.area_code.clone().is_some(), |w| {
164                w.and().eq("area_code", self.area_code.clone().unwrap())
165            })
166            .r#if(self.unform_code.clone().is_some(), |w| {
167                w.and().eq("unform_code", self.unform_code.clone().unwrap())
168            })
169            .r#if(self.address.clone().is_some(), |w| {
170                w.and().eq("address", self.address.clone().unwrap())
171            })
172            .r#if(self.legal_person.clone().is_some(), |w| {
173                w.and()
174                    .eq("legal_person", self.legal_person.clone().unwrap())
175            })
176            .r#if(self.contact_no.clone().is_some(), |w| {
177                w.and().eq("contact_no", self.contact_no.clone().unwrap())
178            })
179            .r#if(self.full_city.clone().is_some(), |w| {
180                w.and().eq("full_city", self.full_city.clone().unwrap())
181            })
182            .r#if(self.contact_name.clone().is_some(), |w| {
183                w.and()
184                    .eq("contact_name", self.contact_name.clone().unwrap())
185            })
186            .r#if(self.emails.clone().is_some(), |w| {
187                w.and().eq("emails", self.emails.clone().unwrap())
188            })
189            .r#if(self.brief.clone().is_some(), |w| {
190                w.and().eq("brief", self.brief.clone().unwrap())
191            })
192            .r#if(self.register_name.clone().is_some(), |w| {
193                w.and()
194                    .eq("register_name", self.register_name.clone().unwrap())
195            })
196            .r#if(self.register_openid.clone().is_some(), |w| {
197                w.and()
198                    .eq("register_openid", self.register_openid.clone().unwrap())
199            })
200            .r#if(self.register_unionid.clone().is_some(), |w| {
201                w.and()
202                    .eq("register_unionid", self.register_unionid.clone().unwrap())
203            })
204            .r#if(self.create_time.clone().is_some(), |w| {
205                w.and().eq("create_time", self.create_time.unwrap())
206            })
207            .r#if(self.update_time.clone().is_some(), |w| {
208                w.and().eq("update_time", self.update_time.unwrap())
209            });
210        rb.fetch_page_by_wrapper::<Self>(wp, &PageRequest::new(curr, ps))
211            .await
212    }
213
214    #[allow(dead_code)]
215    pub async fn query_list(&self, rb: &Rbatis) -> Result<Vec<Self>, Error> {
216        let wp = rb
217            .new_wrapper()
218            .r#if(self.company_id.clone().is_some(), |w| {
219                w.and().eq("company_id", self.company_id.unwrap())
220            })
221            .r#if(self.company_code.clone().is_some(), |w| {
222                w.and()
223                    .eq("company_code", self.company_code.clone().unwrap())
224            })
225            .r#if(self.company_name.clone().is_some(), |w| {
226                w.and()
227                    .eq("company_name", self.company_name.clone().unwrap())
228            })
229            .r#if(self.area_code.clone().is_some(), |w| {
230                w.and().eq("area_code", self.area_code.clone().unwrap())
231            })
232            .r#if(self.unform_code.clone().is_some(), |w| {
233                w.and().eq("unform_code", self.unform_code.clone().unwrap())
234            })
235            .r#if(self.address.clone().is_some(), |w| {
236                w.and().eq("address", self.address.clone().unwrap())
237            })
238            .r#if(self.legal_person.clone().is_some(), |w| {
239                w.and()
240                    .eq("legal_person", self.legal_person.clone().unwrap())
241            })
242            .r#if(self.contact_no.clone().is_some(), |w| {
243                w.and().eq("contact_no", self.contact_no.clone().unwrap())
244            })
245            .r#if(self.full_city.clone().is_some(), |w| {
246                w.and().eq("full_city", self.full_city.clone().unwrap())
247            })
248            .r#if(self.contact_name.clone().is_some(), |w| {
249                w.and()
250                    .eq("contact_name", self.contact_name.clone().unwrap())
251            })
252            .r#if(self.emails.clone().is_some(), |w| {
253                w.and().eq("emails", self.emails.clone().unwrap())
254            })
255            .r#if(self.brief.clone().is_some(), |w| {
256                w.and().eq("brief", self.brief.clone().unwrap())
257            })
258            .r#if(self.register_name.clone().is_some(), |w| {
259                w.and()
260                    .eq("register_name", self.register_name.clone().unwrap())
261            })
262            .r#if(self.register_openid.clone().is_some(), |w| {
263                w.and()
264                    .eq("register_openid", self.register_openid.clone().unwrap())
265            })
266            .r#if(self.register_unionid.clone().is_some(), |w| {
267                w.and()
268                    .eq("register_unionid", self.register_unionid.clone().unwrap())
269            })
270            .r#if(self.create_time.clone().is_some(), |w| {
271                w.and().eq("create_time", self.create_time.unwrap())
272            })
273            .r#if(self.update_time.clone().is_some(), |w| {
274                w.and().eq("update_time", self.update_time.unwrap())
275            });
276        rb.fetch_list_by_wrapper::<Self>(wp).await
277    }
278
279    #[allow(dead_code)]
280    pub async fn query_all(rb: &Rbatis) -> Result<Vec<Self>, Error> {
281        let wp = rb.new_wrapper();
282        rb.fetch_list_by_wrapper::<Self>(wp).await
283    }
284
285    /**
286     * 检测Code是否存在
287     */
288    #[allow(dead_code)]
289    pub async fn code_exist(rb: &Rbatis, code: &str) -> Result<Option<Self>, Error> {
290        let wp = rb
291            .new_wrapper()
292            .and()
293            .eq("company_code", code.to_owned())
294            .limit(1u64);
295        rb.fetch_by_wrapper(wp).await
296    }
297}