use crate::rubase::{BaseEntity, ruentity};
use heck::ToSnakeCase;
use rbatis::rbatis_codegen::ops::AsProxy;
use rbatis::rbdc::Uuid;
use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct StructInfo {
pub structName: String,
pub pathPkg: String,
pub pathFile: String,
pub ifSingle: bool,
pub structIniFile: String,
pub existIniFile: bool,
pub single_bean_name: String,
}
impl BaseEntity for StructInfo {}
impl StructInfo {
pub fn new() -> Self {
Self {
structName: String::new(),
pathPkg: String::new(),
pathFile: String::new(),
ifSingle: false,
structIniFile: String::new(),
existIniFile: false,
single_bean_name: String::new(),
}
}
pub fn default(structName: String, pathPkg: String, pathFile: String, ifSingle: bool) -> Self {
Self {
structName,
pathPkg,
pathFile,
ifSingle,
structIniFile: String::new(),
existIniFile: false,
single_bean_name: String::new(),
}
}
pub fn set_struct_name(&mut self, name: String) {
self.structName = name;
self.single_bean_name = self.build_single_bean_name();
}
pub fn set_path_pkg(&mut self, pkg: String) {
self.pathPkg = pkg;
}
pub fn set_path_file(&mut self, file: String) {
self.pathFile = file;
}
pub fn set_if_single(&mut self, single: bool) {
self.ifSingle = single;
}
pub fn build_struct_ini_file(&self) -> String {
let mut ret = String::new();
ret.push_str(self.structName.to_lowercase().as_str());
ret.push_str("_init.rs");
ret
}
pub fn set_struct_ini_file(&mut self, ini: String) {
self.structIniFile = ini;
self.existIniFile=self.check_ini_file_exist();
}
pub fn get_struct_ini_file(&self) -> &str {
&self.structIniFile
}
pub fn check_ini_file_exist(&self) -> bool {
let ini_path = self.build_struct_ini_pathfile(); println!("ini_path:{}", ini_path);
Path::new(&ini_path).exists() }
pub fn build_struct_ini_pathfile(&self) -> String {
let mut p = self.get_ini_path() + "/";
p.push_str(self.structIniFile.as_str());
p
}
pub fn get_ini_path(&self) -> String {
let p = Path::new(self.pathFile.as_str());
let dir = p.parent(); let stem = p.file_stem(); let ext = p.extension(); dir.unwrap().to_string_lossy().to_string()
}
pub fn set_ini_file_exist(&mut self, exist: bool) {
self.existIniFile = exist;
}
pub fn build_single_bean_name(&self) -> String {
let mut ret = String::new();
ret.push_str(self.structName.as_str());
let uuid = Uuid::new();
ret.push_str(":");
ret.push_str(&uuid.to_string());
if self.ifSingle {
ret.push_str(":single");
}
ret
}
}