added use command
parent
814d7d5abc
commit
49e1b2044a
|
|
@ -6,8 +6,8 @@ Object-oriented design concept tested.
|
||||||
|
|
||||||
Location: .config/rcc/env
|
Location: .config/rcc/env
|
||||||
```
|
```
|
||||||
USERNAME=root
|
DB_USERNAME=root
|
||||||
PASSWORD=cidb
|
DB_PASSWORD=cidb
|
||||||
DB=cidb
|
DB=cidb
|
||||||
PORT=3306
|
PORT=3306
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,7 @@ pub enum Commands {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
log: bool,
|
log: bool,
|
||||||
},
|
},
|
||||||
|
Use {
|
||||||
|
file_name: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,10 @@ pub fn process_args(args: Cli, db: Db) -> Result<(), Box<dyn std::error::Error>>
|
||||||
job_service.get_job_by_id(&job_id)?;
|
job_service.get_job_by_id(&job_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Commands::Use { file_name } => {
|
||||||
|
let mut filter_service: FilterService = container::get_filter_service(db);
|
||||||
|
filter_service.get_filter_uses(&file_name)?;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct FilterUses {
|
||||||
|
pub filter_module_id: usize,
|
||||||
|
pub description: String,
|
||||||
|
pub filter_module_no: String,
|
||||||
|
pub filter_user: usize,
|
||||||
|
pub filter_id: usize,
|
||||||
|
pub active: String,
|
||||||
|
pub merchant: String,
|
||||||
|
pub ep_id: usize,
|
||||||
|
pub ep_no: String,
|
||||||
|
pub filter_no: String,
|
||||||
|
}
|
||||||
|
|
@ -5,3 +5,4 @@ pub mod filter_log;
|
||||||
pub mod filter_config;
|
pub mod filter_config;
|
||||||
pub mod file;
|
pub mod file;
|
||||||
pub mod job;
|
pub mod job;
|
||||||
|
pub mod filter_uses;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
|
use core::result::Result;
|
||||||
|
|
||||||
use mysql::{params, prelude::Queryable, PooledConn};
|
use mysql::{params, prelude::Queryable, PooledConn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::db::Db,
|
database::db::Db,
|
||||||
entity::{filter::Filter, filter_config::FilterConfig, filter_log::FilterLog},
|
entity::{
|
||||||
|
filter::Filter, filter_config::FilterConfig, filter_log::FilterLog, filter_uses::FilterUses,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -87,4 +91,64 @@ impl FilterRepo {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_filter_uses(&mut self, filter_file: &str) -> Result<Vec<FilterUses>, mysql::Error> {
|
||||||
|
let mut connection: PooledConn = self.db.get_connection()?;
|
||||||
|
let stat = connection.prep(
|
||||||
|
"
|
||||||
|
SELECT
|
||||||
|
t1.filter_module_id,
|
||||||
|
t2.description,
|
||||||
|
t1.filter_module_no,
|
||||||
|
t1.filter_user,
|
||||||
|
t2.filter_id,
|
||||||
|
t2.filter_is_active,
|
||||||
|
t3.ep_id,
|
||||||
|
t4.m_name as merchant,
|
||||||
|
t2.filter_no,
|
||||||
|
t3.ep_no,
|
||||||
|
t2.filter_is_active as active
|
||||||
|
FROM global_data.filter_modules t1
|
||||||
|
JOIN filter t2 ON t1.filter_module_id = t2.filter_module_id
|
||||||
|
JOIN exchange_point t3 ON t3.ep_id = t2.ep_id
|
||||||
|
JOIN global_data.merchant t4 ON t4.m_id = t3.m_id
|
||||||
|
WHERE
|
||||||
|
t4.is_deleted = 0
|
||||||
|
AND t2.is_deleted = 0
|
||||||
|
AND t1.file_name LIKE :search_like
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let search_like = format!("%{}%", filter_file);
|
||||||
|
|
||||||
|
let params = params! {"search_like" => search_like};
|
||||||
|
|
||||||
|
connection.exec_map(
|
||||||
|
stat,
|
||||||
|
params,
|
||||||
|
|(
|
||||||
|
filter_module_id,
|
||||||
|
description,
|
||||||
|
filter_module_no,
|
||||||
|
filter_user,
|
||||||
|
filter_id,
|
||||||
|
active,
|
||||||
|
ep_id,
|
||||||
|
merchant,
|
||||||
|
filter_no,
|
||||||
|
ep_no,
|
||||||
|
)| FilterUses {
|
||||||
|
filter_module_id,
|
||||||
|
description,
|
||||||
|
filter_module_no,
|
||||||
|
filter_user,
|
||||||
|
filter_id,
|
||||||
|
active,
|
||||||
|
ep_id,
|
||||||
|
merchant,
|
||||||
|
filter_no,
|
||||||
|
ep_no,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use colored::Colorize;
|
||||||
use rcc::TerminalSize;
|
use rcc::TerminalSize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
entity::{filter::Filter, filter_config::FilterConfig, filter_log::FilterLog},
|
entity::{filter::Filter, filter_config::FilterConfig, filter_log::FilterLog, filter_uses::FilterUses},
|
||||||
repository::filter_repo::FilterRepo,
|
repository::filter_repo::FilterRepo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -17,6 +17,35 @@ impl FilterService {
|
||||||
Self { repo }
|
Self { repo }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_filter_uses(&mut self, file_name: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let uses = self.repo.find_filter_uses(file_name)?;
|
||||||
|
|
||||||
|
if uses.is_empty() {
|
||||||
|
println!("No use for file/module found!");
|
||||||
|
} else {
|
||||||
|
uses.into_iter().for_each(|filter_use: FilterUses| {
|
||||||
|
let is_active = if filter_use.active.eq("1") {
|
||||||
|
"true".to_string()
|
||||||
|
} else {
|
||||||
|
"false".to_string()
|
||||||
|
};
|
||||||
|
println!("{}", "-".repeat(self.get_width()));
|
||||||
|
|
||||||
|
println!("Module ID: {}", filter_use.filter_module_id);
|
||||||
|
println!("ModuleNo: {}", filter_use.filter_module_no);
|
||||||
|
println!("FilterUser: {}", filter_use.filter_user);
|
||||||
|
println!("Description: {}", filter_use.description);
|
||||||
|
println!("FilterId: {}", filter_use.filter_id);
|
||||||
|
println!("FilterNo: {}", filter_use.filter_no);
|
||||||
|
println!("Merchant: {}", filter_use.merchant);
|
||||||
|
println!("Active: {}", is_active);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_filter(
|
pub fn get_filter(
|
||||||
&mut self,
|
&mut self,
|
||||||
filter_id: &usize,
|
filter_id: &usize,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue