初始化服务函数
This commit is contained in:
parent
3ab2c5aeca
commit
15529bf2a3
@ -1,7 +1,6 @@
|
||||
use crate::models::work_model::WorkModel;
|
||||
use crate::services::{serial_service::SerialService, sqlite_service::SqliteService, excel_service::ExcelService};
|
||||
|
||||
|
||||
pub struct WorkService {
|
||||
serial_service: SerialService,
|
||||
sqlite_service: SqliteService,
|
||||
@ -15,6 +14,34 @@ impl Default for WorkService {
|
||||
}
|
||||
|
||||
impl WorkService {
|
||||
|
||||
fn init_excel_service(&mut self, path: String)->Result<bool, String>{
|
||||
return if let Ok(excel_service) = ExcelService::new(&path) {
|
||||
self.excel_service = excel_service;
|
||||
Ok(true)
|
||||
} else {
|
||||
Err("Cant Init ExcelService".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn init_sqlite_service(&mut self, db_path: String)->Result<bool, String>{
|
||||
return if let Ok(sqlite_service) = SqliteService::new(db_path) {
|
||||
self.sqlite_service = sqlite_service;
|
||||
Ok(true)
|
||||
} else {
|
||||
Err("Cant Init SqliteService".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn init_serial_service(&mut self, port_name: String)->Result<bool, String>{
|
||||
return if let Ok(serial_service) = SerialService::new(&port_name) {
|
||||
self.serial_service = *serial_service;
|
||||
Ok(true)
|
||||
} else {
|
||||
Err("Cant Init SerialService".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn write_imei(&mut self, imei: String) -> Result<bool, String> {
|
||||
let write_imei_command = format!("AT+ECCGSN=\"IMEI\",\"{}\"", imei);
|
||||
return self.serial_service.send_command_with_target(write_imei_command, None, "OK".to_string());
|
||||
|
Loading…
Reference in New Issue
Block a user