chimes_rust/entity/
chimes_holiday.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_holiday"|table_columns:"id,physical_year,holiday_date,date_type,remark,create_date,update_date")]
15#[derive(Debug, Clone, Default, Deserialize, Serialize)]
16pub struct ChimesHolidayInfo {
17    pub id: Option<i64>,
18    pub physical_year: Option<i32>,
19    pub holiday_date: Option<String>,
20    pub date_type: Option<i32>,
21    pub remark: Option<String>,
22    pub create_date: Option<rbatis::DateTimeNative>,
23    pub update_date: Option<rbatis::DateTimeNative>,
24}
25
26impl ChimesHolidayInfo {
27    #[allow(dead_code)]
28    pub async fn from_id(rb: &Rbatis, id: &i64) -> Result<Option<Self>, Error> {
29        let wp = rb.new_wrapper().eq("id", 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("id")]).await {
36            Ok(ds) => {
37                self.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("id", self.id);
47        rb.update_by_wrapper(self, wp, &[Skip::Column("id")]).await
48    }
49
50    #[allow(dead_code)]
51    pub async fn update_selective(&self, rb: &Rbatis) -> Result<u64, Error> {
52        let wp = rb.new_wrapper().eq("id", self.id);
53        rb.update_by_wrapper(self, wp, &[Skip::Value(Bson::Null)])
54            .await
55    }
56
57    #[allow(dead_code)]
58    pub async fn remove_batch(&self, rb: &Rbatis) -> Result<u64, Error> {
59        let wp = rb
60            .new_wrapper()
61            .r#if(self.id.clone().is_some(), |w| {
62                w.and().eq("id", self.id.unwrap())
63            })
64            .r#if(self.physical_year.clone().is_some(), |w| {
65                w.and().eq("physical_year", self.physical_year.unwrap())
66            })
67            .r#if(self.holiday_date.clone().is_some(), |w| {
68                w.and()
69                    .eq("holiday_date", self.holiday_date.clone().unwrap())
70            })
71            .r#if(self.date_type.clone().is_some(), |w| {
72                w.and().eq("date_type", self.date_type.unwrap())
73            })
74            .r#if(self.remark.clone().is_some(), |w| {
75                w.and().eq("remark", self.remark.clone().unwrap())
76            })
77            .r#if(self.create_date.clone().is_some(), |w| {
78                w.and().eq("create_date", self.create_date.unwrap())
79            })
80            .r#if(self.update_date.clone().is_some(), |w| {
81                w.and().eq("update_date", self.update_date.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("id", self.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.id.clone().is_some(), |w| {
97                w.and().eq("id", self.id.unwrap())
98            })
99            .r#if(self.physical_year.clone().is_some(), |w| {
100                w.and().eq("physical_year", self.physical_year.unwrap())
101            })
102            .r#if(self.holiday_date.clone().is_some(), |w| {
103                w.and()
104                    .eq("holiday_date", self.holiday_date.clone().unwrap())
105            })
106            .r#if(self.date_type.clone().is_some(), |w| {
107                w.and().eq("date_type", self.date_type.unwrap())
108            })
109            .r#if(self.remark.clone().is_some(), |w| {
110                w.and().eq("remark", self.remark.clone().unwrap())
111            })
112            .r#if(self.create_date.clone().is_some(), |w| {
113                w.and().eq("create_date", self.create_date.unwrap())
114            })
115            .r#if(self.update_date.clone().is_some(), |w| {
116                w.and().eq("update_date", self.update_date.unwrap())
117            });
118        rb.fetch_page_by_wrapper::<Self>(wp, &PageRequest::new(curr, ps))
119            .await
120    }
121
122    #[allow(dead_code)]
123    pub async fn query_list(&self, rb: &Rbatis) -> Result<Vec<Self>, Error> {
124        let wp = rb
125            .new_wrapper()
126            .r#if(self.id.clone().is_some(), |w| {
127                w.and().eq("id", self.id.unwrap())
128            })
129            .r#if(self.physical_year.clone().is_some(), |w| {
130                w.and().eq("physical_year", self.physical_year.unwrap())
131            })
132            .r#if(self.holiday_date.clone().is_some(), |w| {
133                w.and()
134                    .eq("holiday_date", self.holiday_date.clone().unwrap())
135            })
136            .r#if(self.date_type.clone().is_some(), |w| {
137                w.and().eq("date_type", self.date_type.unwrap())
138            })
139            .r#if(self.remark.clone().is_some(), |w| {
140                w.and().eq("remark", self.remark.clone().unwrap())
141            })
142            .r#if(self.create_date.clone().is_some(), |w| {
143                w.and().eq("create_date", self.create_date.unwrap())
144            })
145            .r#if(self.update_date.clone().is_some(), |w| {
146                w.and().eq("update_date", self.update_date.unwrap())
147            });
148        rb.fetch_list_by_wrapper::<Self>(wp).await
149    }
150
151    #[allow(dead_code)]
152    pub async fn remove_ids(rb: &Rbatis, ids: &[i64]) -> Result<u64, Error> {
153        let wp = rb.new_wrapper().r#in("id", ids);
154        rb.remove_by_wrapper::<Self>(wp).await
155    }
156
157    #[allow(dead_code)]
158    pub async fn remove_physical_year(rb: &Rbatis, fy: i64) -> Result<u64, Error> {
159        let wp = rb.new_wrapper().r#eq("physical_year", fy);
160        rb.remove_by_wrapper::<Self>(wp).await
161    }
162
163    #[allow(dead_code)]
164    pub async fn find_holiday_info(&self, rb: &Rbatis) -> Result<Option<Self>, Error> {
165        let wp = rb
166            .new_wrapper()
167            .r#eq("holiday_date", self.holiday_date.clone().unwrap());
168        match rb.fetch_list_by_wrapper::<Self>(wp).await {
169            Ok(lst) => {
170                if lst.is_empty() {
171                    Ok(None)
172                } else {
173                    Ok(Some(lst[0].clone()))
174                }
175            }
176            Err(err) => Err(err),
177        }
178    }
179
180    #[allow(dead_code)]
181    pub async fn find_holiday_range(rb: &Rbatis, begin: &rbatis::DateNative, end: &rbatis::DateNative) -> Result<Vec<Self>, Error> {
182        let wp = rb
183            .new_wrapper()
184            .between("holiday_date", begin, end);
185
186        rb.fetch_list_by_wrapper::<Self>(wp).await
187    }
188}